1 # mogrify.py - test all possible simple type mogrifications
2 # -*- encoding: latin1 -*-
4 # Copyright (C) 2004 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)
27 print "Opening connection using dns:", DSN
29 conn = psycopg2.connect(DSN)
30 print "Encoding for this connection is", conn.encoding
33 curs.execute("SELECT %(foo)s AS foo", {'foo':'bar'})
34 curs.execute("SELECT %(foo)s AS foo", {'foo':None})
35 curs.execute("SELECT %(foo)s AS foo", {'foo':True})
36 curs.execute("SELECT %(foo)s AS foo", {'foo':42})
37 curs.execute("SELECT %(foo)s AS foo", {'foo':u'yatt�!'})
38 curs.execute("SELECT %(foo)s AS foo", {'foo':u'bar'})
40 print curs.mogrify("SELECT %(foo)s AS foo", {'foo':'bar'})
41 print curs.mogrify("SELECT %(foo)s AS foo", {'foo':None})
42 print curs.mogrify("SELECT %(foo)s AS foo", {'foo':True})
43 print curs.mogrify("SELECT %(foo)s AS foo", {'foo':42})
44 print curs.mogrify("SELECT %(foo)s AS foo", {'foo':u'yatt�!'})
45 print curs.mogrify("SELECT %(foo)s AS foo", {'foo':u'bar'})