SQL Table in Wiki Page

Description

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.

Usage

Use the SQLTable macro:

    {{{
    #!SQLTable
        SELECT count(id) as 'Number of Tickets'
        FROM ticket
    }}}

The result will be a table.

Use the SQLScalar macro:

    {{{
    #!SQLScalar
        SELECT count(id) as 'Number of Tickets'
        FROM ticket
    }}}

The result will be a single number.

Installation

  1. Install globally with:
      sudo easy_install https://trac-hacks.org/svn/wikitablemacro/0.11/
    
  2. Enable the plugin by updating TracIni file (..../trac.ini) as follows:
      [components]
      wikitable.* = enabled
    
  3. Restart web server on command line:
        $ sudo /etc/init.d/apache2 restart
    

Bugs/Feature Requests

Existing bugs and feature requests for WikiTableMacro are here.

If you have any issues, create a new ticket.

Known issues

  1. Issue: If incorrect SQL sentences are entered, auto preview (Trac 0.12) isn´t updated, neither any error message is shown until you submit / save your changes. When you save changes Trac will rise error message. You will not be able to edit that wiki page anymore.
    1. Workaround / Tip: You can still delete incorrect wiki entry by going into Timeline and locating diff link.

Source & Download

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

Download the zipped source from here.

Recent Changes

[10997] by rjollos on 12/03/11 01:17:23

Fixes #9520: Fixed incorrect URL in setup.py. Thanks to AdrianFritz for the report.

[10442] by rjollos on 07/12/11 07:53:47

Show plugin's svn revision on webadmin plugin panel.

[7526] by rjollos on 02/09/10 08:39:04

Add repository URL to setup.py. Fixes #6462

[7523] by rjollos on 02/09/10 08:08:16

Add new maintainer to setup.py. Fixes #6594.

Author/Contributors

Author: optilude
Maintainer: rjollos
Contributors:


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

    {{{
    #!SQLTable
        SELECT "a", count($id) as 'Number of Tickets' 
        FROM ticket
        UNION
        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.