Overview

MioinMoin - QueryPg macro

PURPOSE : To show the result of some queries on a postgresql db.

REQUISITES : Install the psycopg2 module. Your postgresql must be UTF-8

CONNECTION : Look inside the QueryPg file and change connvars to suit your needs

INPUTS : receives a valid query as a single argument.

OUTPUT : If the query returns one column with one row, just outputs the result, if it returns many columns or many rows, it prints a table. The headers of the tables will show spaces replacing underscores.

EXAMPLES:

<<QueryDb(SELECT name FROM countries)>>

would fetch every name of the table country ;) and if there are results it will present the results in a table.:

There are <<QueryDb(SELECT count(*) from queries)>> query records

will inline the result on your html code

RECOMMENDATIONS :Create a reading user on your database, people looking with ?action=raw could deduce your database schema, if you are not concerned about security don't bother.Remember that anyone with write access to your wiki could do a nasty sql query to slow down you or D.O.S. attack your system.

IMPROVEMENTS : If you plan to use multiple wikis or multiple databases, you could create a separate file with dictionaries of identifiers and string connections, as a first input you would receive the key of the dictionary that will let you connect to the desired database, the second argument would be the query.