Contents
QueryDb
Purpose
The purpose of this macro is to query a postgresql database.
Download & Release Notes
Download |
Release Version |
Moin Version |
Release Notes |
|
1.3 and Above |
First release on MacroMarket -- IgorTamara 2006-04-08 05:19:27 |
|
|
1.9 |
UTF-8 support -- IgorTamara 2013-05-12 05:19:27 |
You can grab the most recent version from BitBucket
Requisites
- psycopg2 module
- a user with permissions to read on postgresql (look at your pg_hba.conf)
Inputs
Receives as a single argument the query.
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
- would inline the result on your wiki code.
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.
Recommendations
Create a reading user on your database, people looking with ?action=raw could deduce your database, 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.
Copyright
IgorTamara - <igor AT tamarapatino DOT org>
License
GNU GPL version 2
Bugs