Version 9 (modified by pekcheey@…, 6 years ago) (diff)


SQL Table in Wiki Page


This is a simple macro that enables you to place tables resulting from SQL queries into a wiki page.

It is similar to, but simpler than, SqlQueryMacro. The main differences are that it has fewer dependencies and always queries the Trac database, rather than letting you set up a separate data connection.

Bugs/Feature Requests

Existing bugs and feature requests for WikiTableMacro are here.

If you have any issues, create a new ticket.


Download the zipped source from [download:wikitablemacro here].


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


Use the SQLTable macro:

        SELECT count(id) as 'Number of Tickets'
        FROM ticket

The result will be a table.

Use the SQLScalar macro:

        SELECT count(id) as 'Number of Tickets'
        FROM ticket

The result will be a single number.

Recent Changes

14734 by rjollos on 2015-06-23 00:53:59
0.3dev: Partial revert of [14524]. Refs #11708.

Reverts to format_to_html but adds CSS to shrink the cell margins.

14531 by rjollos on 2015-04-13 21:24:22
0.3dev: Fix issue fetching from cursor on MySQL.

Patch by theYT <dev@…>. Fixes #12269.

14524 by rjollos on 2015-04-09 02:08:20
0.3dev: Use Trac 1.0 DB API.

  • Macro now requires Trac 1.0 and later.
  • Genshi is used to construct the table.
  • Queries can use non-ASCII table names. Fixes #11708.
  • Read-only database connection is used.

Please report any issues with the latest changes.



Author: optilude
Maintainer: rjollos

Some Patches

I added below to render_macro to provide a rudimentary sort of variable function.

    def render_macro(self, req, name, content):
+        c = content.split("|")
+        content = c[0]
+        if len(c) > 1 :
+                for i in c[1:] :
+                        v = i.split("=")
+                        if len(v) > 1 :
+                                k = v[0]
+                                v = v[1]
+                                content = content.replace(k,v)

i.e. you can do something like this

        SELECT "a", count($id) as 'Number of Tickets' 
        FROM ticket
        SELECT "b", count($id) as 'Number of Tickets' 
        FROM ticket|$id=id

Useful when you have the same id that you don't want to keep on retyping over.