41 |
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 |
42 |
|
|
43 |
class PGSQL_RecordSet(DBSIG_RecordSet): |
class PGSQL_RecordSet(DBSIG_RecordSet): |
44 |
def _buildUpdateStatement(self, table): |
pass |
45 |
updates = [] |
# def _buildUpdateStatement(self, table): |
46 |
for field in self._modifiedFlags.keys(): |
# updates = [] |
47 |
a = len (field.split ('.')) |
# for field in self._modifiedFlags.keys(): |
48 |
if (a == 2): |
# a = len (field.split ('.')) |
49 |
[auxTable, auxField]= field.split ('.') |
# if (a == 2): |
50 |
if string.count(self._parent._dataObject.table,',') and (auxTable != table): |
# [auxTable, auxField]= field.split ('.') |
51 |
continue |
# if string.count(self._parent._dataObject.table,',') and (auxTable != table): |
52 |
elif (a == 1): |
# continue |
53 |
auxField= field |
# elif (a == 1): |
54 |
else: |
# auxField= field |
55 |
# raise |
# else: |
56 |
pass |
# # raise |
57 |
|
# pass |
58 |
|
|
59 |
updates.append ("%s=%s" % (auxField, |
# updates.append ("%s=%s" % (auxField, |
60 |
self._parent._dataObject._toSqlString(self._fields[field]))) |
# self._parent._dataObject._toSqlString(self._fields[field]))) |
61 |
|
|
62 |
where = [] |
# where = [] |
63 |
|
|
64 |
if updates: |
# if updates: |
65 |
if self._parent._dataObject._primaryKeys: |
# if self._parent._dataObject._primaryKeys: |
66 |
for iterTable in self._parent._dataObject._primaryKeys.keys(): |
# for iterTable in self._parent._dataObject._primaryKeys.keys(): |
67 |
if iterTable != table: continue |
# if iterTable != table: continue |
68 |
for iterField in self._parent._dataObject._primaryKeys[iterTable]: |
# for iterField in self._parent._dataObject._primaryKeys[iterTable]: |
69 |
auxWhere = "%s = '%s'" |
# auxWhere = "%s = '%s'" |
70 |
where.append(auxWhere % (iterField,self._initialData[table+"."+iterField])) |
# where.append(auxWhere % (iterField,self._initialData[table+"."+iterField])) |
71 |
else: |
# else: |
72 |
for field in self._initialData.keys(): |
# for field in self._initialData.keys(): |
73 |
a = len (field.split ('.')) |
# a = len (field.split ('.')) |
74 |
if (a == 2): |
# if (a == 2): |
75 |
[auxTable, auxField]= field.split ('.') |
# [auxTable, auxField]= field.split ('.') |
76 |
if string.count(self._parent._dataObject.table,',') and (auxTable != table): |
# if string.count(self._parent._dataObject.table,',') and (auxTable != table): |
77 |
continue |
# continue |
78 |
elif (a == 1): |
# elif (a == 1): |
79 |
auxField= field |
# auxField= field |
80 |
else: |
# else: |
81 |
# raise |
# # raise |
82 |
pass |
# pass |
83 |
|
|
84 |
if self._initialData[field] == None: |
# if self._initialData[field] == None: |
85 |
where.append ("%s IS NULL" % auxField) |
# where.append ("%s IS NULL" % auxField) |
86 |
else: |
# else: |
87 |
where.append ("%s=%s" % (auxField, self._parent._dataObject._toSqlString(self._initialData[field]))) |
# where.append ("%s=%s" % (auxField, self._parent._dataObject._toSqlString(self._initialData[field]))) |
88 |
|
|
89 |
updateStmt = "BEGIN; SELECT %s FROM %s WHERE %s FOR UPDATE; " % \ |
# updateStmt = "BEGIN; SELECT %s FROM %s WHERE %s FOR UPDATE; " % \ |
90 |
(string.join(updates,','), table, \ |
# (string.join(updates,','), table, \ |
91 |
string.join(where,' AND ') ) + \ |
# string.join(where,' AND ') ) + \ |
92 |
"UPDATE %s SET %s WHERE %s" % \ |
# "UPDATE %s SET %s WHERE %s" % \ |
93 |
(table, string.join(updates,','), \ |
# (table, string.join(updates,','), \ |
94 |
string.join(where,' AND ') ) + "; COMMIT;" |
# string.join(where,' AND ') ) + "; COMMIT;" |
95 |
|
|
96 |
return updateStmt |
# return updateStmt |
97 |
|
|
98 |
class PGSQL_ResultSet(DBSIG_ResultSet): |
class PGSQL_ResultSet(DBSIG_ResultSet): |
99 |
def __init__(self, dataObject, cursor=None, defaultValues={}, masterRecordSet=None, fieldNames=None): |
def __init__(self, dataObject, cursor=None, defaultValues={}, masterRecordSet=None, fieldNames=None): |