Merge remote-tracking branch 'origin/pycurl' into planetlab-4_0-branch
[plcapi.git] / trunk / psycopg2 / examples / mogrify.py
1 # mogrify.py - test all possible simple type mogrifications
2 # -*- encoding: latin1 -*-
3 #
4 # Copyright (C) 2004 Federico Di Gregorio  <fog@debian.org>
5 #
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
9 # version.
10 #
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
14 # for more details.
15
16 ## put in DSN your DSN string
17
18 DSN = 'dbname=test'
19
20 ## don't modify anything below this line (except for experimenting)
21
22 import sys, psycopg2
23
24 if len(sys.argv) > 1:
25     DSN = sys.argv[1]
26
27 print "Opening connection using dns:", DSN
28
29 conn = psycopg2.connect(DSN)
30 print "Encoding for this connection is", conn.encoding
31
32 curs = conn.cursor()
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'})
39
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'})
46
47 conn.rollback()