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. The macro uses SQLAlchemy, the Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL.

This macro can be used in one of two ways:



[[SQL(SELECT * FROM foo)]]

A previous version of this module is known as SqlQueryMacro.

See also: TracSqlAlchemyBridgeIntegration, WikiTableMacro

Bugs/Feature Requests

Existing bugs and feature requests for SqlAlchemyQueryMacro are here.

If you have any issues, create a new ticket.


0 / 1


1 / 1


Download the zipped source from here.


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

SqlAlchemyQueryMacro comes with sortable tables using the sorttable library, written in Javascript.


General instructions on installing Trac plugins can be found on the TracPlugins page.

This macro requires the pypi:sqlalchemy ​library and makes use of its database and table modules. Please install python-sqlalchemy first. After getting the source you will have to edit install_sqlalchemyquery.bash to suit your needs, so you can change:

TRAC_PATH_REPLACE = "/path/to/your-trac-environment" # absolute path to your trac environment
TRAC_REPLACE = "your_trac_environment"               # name of your trac environment (relative path without slashes)
MAX_ROW_COUNT_REPLACE = "1000"                       # maximum numbers of rows for the query result to display
TABLE_BORDER_REPLACE = "border=\"1\""                # set the border width of the table 

To install the macro:

$ tar -zxvf SqlAlchemyQuery.tar.gz
$ cd SqlAlchemyQuery
--- edit install_sqlalchemyquery.bash ---
$ ./install_sqlalchemyquery.bash

or with svn:

$ svn checkout
$ cd sqlalchemyquerymacro/1.0/
--- edit install_sqlalchemyquery.bash ---
$ ./install_sqlalchemyquery.bash

To enable this plugin add the following to your trac.ini file:

sqlalchemyquery.* = enabled


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

In trac.ini for MySQL:

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

You can also use Oracle:

uri = oracle://user:password@tns

or SQLite:

uri = sqlite:///path/to/database

Restart tracd after making these changes.

Recent Changes

16394 by rjollos on 2017-03-25 09:20:58
Remove eggs
14472 by fvdberg on 2015-03-01 12:19:24
added license file
14469 by fvdberg on 2015-02-27 21:24:23
bugfix: use relative path for sorttable.js (2)


Author: fvdberg
Maintainer: fvdberg

Last modified 6 years ago Last modified on Aug 9, 2018, 7:30:38 PM