330 |
def getSequence(self, name): |
def getSequence(self, name): |
331 |
return self.__singleQuery("select nextval('%s')" % name) |
return self.__singleQuery("select nextval('%s')" % name) |
332 |
|
|
333 |
def atomicModify(self, func, field, dataObject, record): |
def atomicModify(self, func, field, dataObject, record, cond=None): |
334 |
if string.count(dataObject.table,',') == 0: |
if string.count(dataObject.table,',') == 0: |
335 |
table = dataObject.table |
table = dataObject.table |
336 |
elif field.count('.'): |
elif field.count('.'): |
363 |
where.append ("%s IS NULL" % auxField) |
where.append ("%s IS NULL" % auxField) |
364 |
else: |
else: |
365 |
where.append ("%s=%s" % (auxField, dataObject._toSqlString(record._initialData[field]))) |
where.append ("%s=%s" % (auxField, dataObject._toSqlString(record._initialData[field]))) |
366 |
|
if cond: |
367 |
|
where.append(cond) |
368 |
|
|
369 |
cursor = self.__connection.cursor() |
cursor = self.__connection.cursor() |
370 |
|
|
371 |
getValueStmt = "BEGIN; SELECT %s FROM %s WHERE %s FOR UPDATE; " % \ |
getValueStmt = "BEGIN; SELECT %s FROM %s WHERE %s FOR UPDATE; " % \ |
385 |
try: |
try: |
386 |
lAux = rv[0] |
lAux = rv[0] |
387 |
except: |
except: |
388 |
return None |
try: |
389 |
|
cursor.execute("COMMIT") |
390 |
|
cursor.close() |
391 |
|
except: |
392 |
|
print "DBdriver.py", "error!" |
393 |
|
GDebug.printMesg(1,"**** Unable to execute extension query") |
394 |
|
GDebug.printMesg(1,"**** %s" % sys.exc_info()[1]) |
395 |
|
cursor.close() |
396 |
|
return None |
397 |
|
|
398 |
if field.count('.') > 0: |
if field.count('.') > 0: |
399 |
auxField = field.split('.')[1] |
auxField = field.split('.')[1] |
400 |
else: |
else: |
401 |
auxField = field |
auxField = field |
402 |
|
|
403 |
|
if str(type(func)).count("'function'") > 0: |
404 |
|
value = func(rv[0]) |
405 |
|
else: |
406 |
|
value = func |
407 |
|
|
408 |
updateStmt = "UPDATE %s SET %s WHERE %s" % \ |
updateStmt = "UPDATE %s SET %s WHERE %s" % \ |
409 |
(table, " %s = %s " % (auxField, str(func(rv[0]))), \ |
(table, " %s = %s " % (auxField, str(value)), \ |
410 |
string.join(where,' AND ') ) + "; COMMIT;" |
string.join(where,' AND ') ) + "; COMMIT" |
411 |
|
|
412 |
try: |
try: |
413 |
cursor.execute(updateStmt) |
cursor.execute(updateStmt) |
419 |
cursor.close() |
cursor.close() |
420 |
return None |
return None |
421 |
|
|
422 |
|
return 1 |
423 |
|
|
424 |
# Run the SQL statement 'statement' |
# Run the SQL statement 'statement' |
425 |
def sql(self, statement): |
def sql(self, statement): |
426 |
cursor = self.__connection.cursor() |
cursor = self.__connection.cursor() |