summaryrefslogtreecommitdiff
path: root/sandbox/misc_dbapi_test.py
blob: 64637d988396f608c90fe75b223396a082f4c6bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
"""
Test if the arguments object can be used with both positional and keyword
arguments.
"""

class O(object):

    def __init__(self, *args, **kwds):
        self.args = args
        self.kwds = kwds

    def __getitem__(self, k):
        if isinstance(k, int):
            return self.args[k]
        else:
            return self.kwds[k]

o = O('R%', second='S%')

print o[0]
print o['second']


#-------------------------------------------------------------------------------

import psycopg2 as dbapi


conn = dbapi.connect(database='test')
                    
                   

cursor = conn.cursor()
cursor.execute("""

  SELECT * FROM location_pretty
    WHERE keyname LIKE %s OR keyname LIKE %(second)s

  """, (o,))

for row in cursor:
    print row