1 """
2 SQLQuery.py -- Copyright 2004 William Waites
3
4 This program is Free Software and is released
5 under the terms of the GNU General Public License.
6 Please see http://www.gnu.org/licenses/gpl for
7 the full text of the terms and conditions.
8
9 This is an example macro that uses
10 the results of the SQLConnect macro.
11
12 Please see the accompanying
13 SQLConnect macro for documentation.
14 """
15
16 def execute(macro, args):
17 if not hasattr(macro.request, "sql_cursor") or not macro.request.sql_cursor:
18 print "Absent database connection"
19 return
20
21 cursor = macro.request.sql_cursor
22 cursor.execute(args)
23
24 print '<TABLE BORDER=1>'
25 row = cursor.fetchone()
26 while row:
27 print '<TR>'
28 for col in row:
29 print '<TD>' + str(col) + '</TD>'
30 print '</TR>'
31 row = cursor.fetchone()
32 print '</TABLE>'
MoinMoin: macro/SQLQuery.py (last edited 2007-10-29 19:09:20 by localhost)