16 |
# write to the Free Software Foundation, Inc., 59 Temple Place |
# write to the Free Software Foundation, Inc., 59 Temple Place |
17 |
# - Suite 330, Boston, MA 02111-1307, USA. |
# - Suite 330, Boston, MA 02111-1307, USA. |
18 |
# |
# |
19 |
# Copyright 2000-2002 Free Software Foundation |
# Copyright 2000-2003 Free Software Foundation |
20 |
# |
# |
21 |
# FILE: |
# FILE: |
22 |
# _pgsql/DBdriver.py |
# _pgsql/DBdriver.py |
33 |
import sys |
import sys |
34 |
from gnue.common import GDebug, GDataObjects |
from gnue.common import GDebug, GDataObjects |
35 |
from gnue.common.dbdrivers._dbsig.DBdriver \ |
from gnue.common.dbdrivers._dbsig.DBdriver \ |
36 |
import DBSIG_RecordSet, DBSIG_ResultSet, DBSIG_DataObject |
import DBSIG_RecordSet, DBSIG_ResultSet, DBSIG_DataObject, DBSIG_DataObject_Object |
37 |
|
|
38 |
from gnue.common.dbdrivers._dbsig.DBdriver import DBSIG_DataObject_Object as PGSQL_DataObject_Object |
#from gnue.common.dbdrivers._dbsig.DBdriver import DBSIG_DataObject_Object as PGSQL_DataObject_Object |
39 |
from gnue.common.dbdrivers._dbsig.DBdriver import DBSIG_DataObject_SQL as PGSQL_DataObject_SQL |
from gnue.common.dbdrivers._dbsig.DBdriver import DBSIG_DataObject_SQL as PGSQL_DataObject_SQL |
40 |
|
|
41 |
|
|
153 |
except: |
except: |
154 |
pass |
pass |
155 |
|
|
156 |
if encoding!="": |
if encoding.upper() not in ("",'DEFAULT'): |
157 |
GDebug.printMesg(1,'Setting postgresql client_encoding to %s' % encoding) |
GDebug.printMesg(1,'Setting postgresql client_encoding to %s' % encoding) |
158 |
cursor = self._dataConnection.cursor() |
cursor = self._dataConnection.cursor() |
159 |
cursor.execute("SET CLIENT_ENCODING TO '%s'" % encoding) |
cursor.execute("SET CLIENT_ENCODING TO '%s'" % encoding) |
307 |
return list |
return list |
308 |
|
|
309 |
class PGSQL_DataObject_Object(PGSQL_DataObject, \ |
class PGSQL_DataObject_Object(PGSQL_DataObject, \ |
310 |
PGSQL_DataObject_Object): |
DBSIG_DataObject_Object): |
311 |
|
|
312 |
def __init__(self): |
def __init__(self): |
313 |
PGSQL_DataObject.__init__(self) |
PGSQL_DataObject.__init__(self) |
360 |
cursor.close() |
cursor.close() |
361 |
self._primaryKeys[table] = fields |
self._primaryKeys[table] = fields |
362 |
|
|
363 |
|
|
364 |
# |
# |
365 |
# Extensions to Trigger Namespaces |
# Extensions to Trigger Namespaces |
366 |
# |
# |
377 |
def getSequence(self, name): |
def getSequence(self, name): |
378 |
return self.__singleQuery("select nextval('%s')" % name) |
return self.__singleQuery("select nextval('%s')" % name) |
379 |
|
|
380 |
|
|
381 |
def atomicModify(self, func, field, dataObject, record, cond=None): |
def atomicModify(self, func, field, dataObject, record, cond=None): |
382 |
|
print "in atomic Modify" |
383 |
if string.count(dataObject.table,',') == 0: |
if string.count(dataObject.table,',') == 0: |
384 |
table = dataObject.table |
table = dataObject.table |
385 |
elif field.count('.'): |
elif field.count('.'): |
420 |
getValueStmt = "BEGIN; SELECT %s FROM %s WHERE %s FOR UPDATE; " % \ |
getValueStmt = "BEGIN; SELECT %s FROM %s WHERE %s FOR UPDATE; " % \ |
421 |
(field, table, \ |
(field, table, \ |
422 |
string.join(where,' AND ') ) |
string.join(where,' AND ') ) |
423 |
|
print getValueStmt |
424 |
|
|
425 |
try: |
try: |
426 |
cursor.execute(getValueStmt) |
cursor.execute(getValueStmt) |
458 |
updateStmt = "UPDATE %s SET %s WHERE %s" % \ |
updateStmt = "UPDATE %s SET %s WHERE %s" % \ |
459 |
(table, " %s = %s " % (auxField, str(value)), \ |
(table, " %s = %s " % (auxField, str(value)), \ |
460 |
string.join(where,' AND ') ) + "; COMMIT" |
string.join(where,' AND ') ) + "; COMMIT" |
461 |
|
print updateStmt |
462 |
try: |
try: |
463 |
cursor.execute(updateStmt) |
cursor.execute(updateStmt) |
464 |
cursor.close() |
cursor.close() |