Execute an SQL Query from within Trac


This plugin allows you to execute an SQL Query against a configured database displaying a formatted table of results from within Trac.

This macro can be used in one of two ways:

SELECT * FROM component


[[SQL(SELECT * FROM component)]]

See also:

Bugs/Feature Requests

Existing bugs and feature requests for SqlQueryMacro are here.

If you have any issues, create a new ticket.


Download the zipped source from here.


You can check out SqlQueryMacro from here using Subversion, or browse the source with Trac.


To install the macro:

$ pip install svn+


$ pip install svn+

To enable in your trac.ini file:

sqlquery.* = enabled


Configuration is only needed for the 0.11 branch of the plugin, or if using a datasource other than Trac's database.

To configure this plugin, you must tell SQLQuery what database to connect to.

In trac.ini or via the WebAdmin menu:

uri = mysql://user:password@hostname/database

You can also use Oracle or SQLite:

uri = oracle://user:password@tns


uri = sqlite:///path/to/db

Recent Changes

17555 by rjollos on 2019-11-15 15:28:06
TracSqlQueryMacro 0.2: Fix incorrectly chained methods

Refs #13646.

17554 by rjollos on 2019-11-14 12:17:52
TracSqlQueryMacro 0.2: Use Trac's database API when querying Trac database

Refs #13646.

14239 by rjollos on 2014-11-04 12:21:22
Import of Connection fails, at least in the most recent version of pymills. Refs #12023.

Patch by paresh138@….



Author: JamesMills
Maintainer: Ryan J Ollos

Last modified 9 months ago Last modified on Apr 26, 2020, 9:57:46 PM