421 |
|
|
422 |
return 1 |
return 1 |
423 |
|
|
424 |
|
def atomicModifyForEntry(self, func, field, dataObject, record, cond=None): |
425 |
|
if string.count(dataObject.table,',') == 0: |
426 |
|
table = dataObject.table |
427 |
|
elif field.count('.'): |
428 |
|
table = field.split('.')[0] |
429 |
|
else: |
430 |
|
raise |
431 |
|
|
432 |
|
if field and field.count('.') > 0: |
433 |
|
field = field.split('.')[1] |
434 |
|
|
435 |
|
where = [] |
436 |
|
|
437 |
|
if dataObject._primaryKeys: |
438 |
|
for iterTable in dataObject._primaryKeys.keys(): |
439 |
|
if iterTable != table: continue |
440 |
|
for iterField in dataObject._primaryKeys[iterTable]: |
441 |
|
auxWhere = "%s = '%s'" |
442 |
|
where.append(auxWhere % (iterField,record._initialData[table+"."+iterField])) |
443 |
|
else: |
444 |
|
for iterField in record._initialData.keys(): |
445 |
|
a = len (iterField.split ('.')) |
446 |
|
if (a == 2): |
447 |
|
[auxTable, auxField]= iterField.split ('.') |
448 |
|
if string.count(dataObject.table,',') and (auxTable != table): |
449 |
|
continue |
450 |
|
elif (a == 1): |
451 |
|
auxField= iterField |
452 |
|
else: |
453 |
|
# raise |
454 |
|
pass |
455 |
|
|
456 |
|
if record._initialData[iterField] == None: |
457 |
|
where.append ("%s IS NULL" % auxField) |
458 |
|
else: |
459 |
|
where.append ("%s=%s" % (auxField, dataObject._toSqlString(record._initialData[iterField]))) |
460 |
|
if cond: |
461 |
|
where.append(cond) |
462 |
|
|
463 |
|
cursor = self.__connection.cursor() |
464 |
|
|
465 |
|
getValueStmt = "BEGIN; SELECT %s FROM %s WHERE %s FOR UPDATE; " % \ |
466 |
|
(field, table, \ |
467 |
|
string.join(where,' AND ') ) |
468 |
|
|
469 |
|
try: |
470 |
|
cursor.execute(getValueStmt) |
471 |
|
rv = cursor.fetchone() |
472 |
|
except: |
473 |
|
print "DBdriver.py", "error!" |
474 |
|
GDebug.printMesg(1,"**** Unable to execute extension query") |
475 |
|
GDebug.printMesg(1,"**** %s" % sys.exc_info()[1]) |
476 |
|
cursor.close() |
477 |
|
return None |
478 |
|
|
479 |
|
try: |
480 |
|
lAux = rv[0] |
481 |
|
except: |
482 |
|
try: |
483 |
|
cursor.execute("COMMIT") |
484 |
|
cursor.close() |
485 |
|
except: |
486 |
|
print "DBdriver.py", "error!" |
487 |
|
GDebug.printMesg(1,"**** Unable to execute extension query") |
488 |
|
GDebug.printMesg(1,"**** %s" % sys.exc_info()[1]) |
489 |
|
cursor.close() |
490 |
|
return None |
491 |
|
|
492 |
|
if field.count('.') > 0: |
493 |
|
auxField = field.split('.')[1] |
494 |
|
else: |
495 |
|
auxField = field |
496 |
|
|
497 |
|
if str(type(func)).count("'function'") > 0: |
498 |
|
value = func(rv[0]) |
499 |
|
else: |
500 |
|
value = func |
501 |
|
|
502 |
|
if record._haveHistory(table): |
503 |
|
updateStmt = "BEGIN; UPDATE %s SET _end_t = '%s' WHERE %s" % \ |
504 |
|
(table, dataObject.triggerExtensions.getTimeStamp(), \ |
505 |
|
string.join(where,' AND ') ) + "; COMMIT" |
506 |
|
statementElement = record._buildInsertStatementWHist(table,field) |
507 |
|
statementElement[1].append(field) |
508 |
|
statementElement[2].append(str(value)) |
509 |
|
|
510 |
|
insertStmt = "INSERT INTO %s (%s) VALUES (%s)" % \ |
511 |
|
(statementElement[0], string.join(statementElement[1],','), \ |
512 |
|
string.join(statementElement[2],',') ) |
513 |
|
|
514 |
|
else: |
515 |
|
updateStmt = "BEGIN; UPDATE %s SET %s WHERE %s" % \ |
516 |
|
(table, " %s = %s " % (auxField, str(value)), \ |
517 |
|
string.join(where,' AND ') ) + "; COMMIT" |
518 |
|
|
519 |
|
|
520 |
|
try: |
521 |
|
cursor.execute(updateStmt) |
522 |
|
cursor.execute(insertStmt) |
523 |
|
cursor.close() |
524 |
|
except: |
525 |
|
print "DBdriver.py", "error!" |
526 |
|
GDebug.printMesg(1,"**** Unable to execute extension query") |
527 |
|
GDebug.printMesg(1,"**** %s" % sys.exc_info()[1]) |
528 |
|
cursor.close() |
529 |
|
return None |
530 |
|
|
531 |
|
return 1 |
532 |
|
|
533 |
# Run the SQL statement 'statement' |
# Run the SQL statement 'statement' |
534 |
def sql(self, statement): |
def sql(self, statement): |
535 |
cursor = self.__connection.cursor() |
cursor = self.__connection.cursor() |