1 # simple.py - very simple example of plain DBAPI-2.0 usage
2 # currently used as test-me-stress-me script for psycopg 2.0
4 # Copyright (C) 2001-2003 Federico Di Gregorio <fog@debian.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by the
8 # Free Software Foundation; either version 2, or (at your option) any later
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
13 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 ## put in DSN your DSN string
20 ## don't modify anything below this line (except for experimenting)
22 class SimpleQuoter(object):
32 print "Opening connection using dns:", DSN
33 conn = psycopg2.connect(DSN)
34 print "Encoding for this connection is", conn.encoding
37 curs.execute("SELECT 1 AS foo")
39 curs.execute("SELECT 1 AS foo")
40 print curs.fetchmany()
41 curs.execute("SELECT 1 AS foo")
48 curs.execute("SELECT 1 AS foo", async=1)
50 curs.execute("SELECT %(foo)s AS foo", {'foo':'bar'})
51 curs.execute("SELECT %(foo)s AS foo", {'foo':None})
52 curs.execute("SELECT %(foo)f AS foo", {'foo':42})
53 curs.execute("SELECT %(foo)s AS foo", {'foo':SimpleQuoter()})