1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 from osh.external.pg8000 import dbapi
19
20 import osh.command.sql
21
22 CURSOR_ARRAYSIZE = 20
23
26
27 -class _Postgres(osh.command.sql._DBType):
28
29 - def connect(self, db, host, user, password):
30 try:
31 return _Connection(dbapi.connect(host = host, database = db, user = user, password = password))
32 except dbapi.Error, e:
33 raise Exception('Unable to connect to %s: %s' % (db, str(e)))
34
35 - def run_query(self, connection, query, inputs):
36 cursor = connection.cursor
37 try:
38 cursor.execute(query, inputs)
39 rows = cursor.fetchmany()
40 while len(rows) > 0:
41 for row in rows:
42 yield row
43 rows = cursor.fetchmany()
44 except dbapi.Error, e:
45 raise Exception('Error during execution of query %s: %s' % (query, str(e)))
46
47 - def run_update(self, connection, query, inputs):
48 try:
49 cursor = connection.cursor
50 cursor.execute(query, inputs)
51 rowcount = cursor.rowcount
52 connection.commit()
53 return rowcount
54 except dbapi.Error, e:
55 raise Exception('Error during execution of update %s: %s' % (query, str(e)))
56
57
70