Introduction

Often it is nice to throw data into a wiki in tabular form so that it can be used as a reference. It is a logical progression that it would be nice to search, filter and present the stored information in other forms. SQL presents a fairly clear industry standard for querying and modifying data so I have used this as a rough outline for a MoinMoin macro.

Installation

  1. strptime is missing from Python, (more details). You need to put this file in your Python path somewhere.

  2. If you are running Python 2.3.x, you do not need the above fix. You will have to make the following changes to the /SourceCode. Comment out lines 40 - 43. Change line 118 (self.timestruct = wdbtime.strptime(str, format)) to self.timestruct = time.strptime(str, format). That should do it. JosYule.

  3. Copy the following file into your plugins macro directory: /SourceCode

<!>

Because of the nature of the queries, i.e. we are evaluating Python code, this macro is open to abuse. It is therefore not safe to put on a public wiki site. You use it entirely at your own risk.

:)

If you're not the type of person who can go through the code of the macro and work out how this works then this macro may not be for you. I don't intend to fully document and support this macro.

{i}

If you have any trouble with installation I can't promise to help you. I welcome any constructive feedback. Please see this macro as work in progress. -- NickTrout

Usage

Build a wiki page containing some data. Note:

Create a query on another wiki page. Read about SQL for more info on the syntax. Each query is in its own section e.g. (please note the double curly braces should be triple curly braces but I can't add them for obvious reasons).

Query has the form :-

This will give you:

Notes :-

Functions

Functions are can be used to create virtual columns, where the data is created via the function. Lets use an example to illustrate. Here is the table, lets say its on a page named ProjectDataTable:

<!> Very important to note the date format. it is <day>-<abbr. month>-<2 digit year>.

Now lets setup a query. Lets say this query is on a page called ProjectQueryData (please note the double curly braces should be triple curly braces but I can't add them for obvious reasons).

Now, on the page that you want to see the output of this query, you would add the following line...

{i} Note that you have to have a trailing comma in the args list for the macro.

The output of this query would be something like this, assuming that the current date is the 1st of January:

Project

Days till Due

BanzaiProject

24

ZooperProject

25

Functions can also be used in the where part of a query. Here is an example which would show projects due in the next 24 days:

{i} Note that in the line where $(days_until:due) < 25, we are not using quotes around the function ($(days_until:due)). This is because we want to do a numerical comparison. With the quotes, it would treat the values as a string.

This should output a table like so:

Project

Employees

BanzaiProject

JosYule NickTrout

List of Functions that are available:

Arguments to WikiDb Macro

Another interesting thing you can do with the querys is to have arguments in the query which are replaced by data given in the WikiDb macro call.

Here is an example of a query, assuming the page naming scheme from the functions example.

== argreplacement ==
{{
select || $(project) || $(client) ||
titles ||<#eeeeee> '''Project''' ||<#eeeeee> '''Client''' ||
from ProjectDataTable
where "$(1)" in "$(workers)"
}}

Now, on the page that you want to display the results of the query, you could have something like...

Note the 3rd argument, JosYule. This gets filled in to the "$(1)" in the query. The output of this query would be:

Project

Client

BanzaiProject

ClientBig

ZooperProject

ClientSmall

You could also simply change the macro to show projects that have a different user involved:

Would result in:

Project

Client

BanzaiProject

ClientBig

See Also

Discusssion

Do not forget to look at virtual pages. It is a plugin system that allows you to serve wiki pages e.g. from a DB. See MoinMoinPatch and http://gauss.ffii.org for an example.

MoinMoin: WikiDb (last edited 2009-02-18 15:17:00 by DennisBenzinger)