296 |
qTable = self.table |
qTable = self.table |
297 |
return DBSIG_DataObject_Object._buildQuery(self, conditions, qTable) |
return DBSIG_DataObject_Object._buildQuery(self, conditions, qTable) |
298 |
|
|
299 |
|
#def _haveHistory(self, table=None): |
300 |
|
# if not table: |
301 |
|
# auxTable = string.split(string.replace(self.table,' ',''),',') |
302 |
|
# else: |
303 |
|
# auxTable = string.split(string.replace(table,' ',''),',') |
304 |
|
# for table in auxTable: |
305 |
|
# statement = "select a.attname from pg_class c, pg_attribute a " |
306 |
|
# statement += "where c.relname = '%s' and a.attnum > 0 and a.attrelid = c.oid and a.attname = '_table' " % table |
307 |
|
# try: |
308 |
|
# cursor = self._dataConnection.cursor() |
309 |
|
# cursor.execute(statement) |
310 |
|
# rowCount = cursor.rowcount |
311 |
|
# cursor.close() |
312 |
|
# if rowCount > 0: |
313 |
|
# return rowCount |
314 |
|
# except self._DatabaseError, err: |
315 |
|
# print "DBSIG_RecordSet._haveHistory ERROR %s " % err |
316 |
|
# pass |
317 |
|
# return 0 |
318 |
|
|
319 |
|
|
320 |
def _checkForPrimaryId(self): |
def _checkForPrimaryId(self): |
321 |
self._primaryIdChecked = 1 |
self._primaryIdChecked = 1 |
322 |
|
|
335 |
try: |
try: |
336 |
rsets = cursor.fetchmany() |
rsets = cursor.fetchmany() |
337 |
except self._DatabaseError, err: |
except self._DatabaseError, err: |
338 |
raise GDataObjects.ConnectionError, err |
raise GDataObjects.ConnectionError(str(err)) |
339 |
if rsets and len(rsets): |
if rsets and len(rsets): |
340 |
for rs in (rsets): |
for rs in (rsets): |
341 |
if rs: |
if rs: |
354 |
try: |
try: |
355 |
rsets = cursor.fetchmany() |
rsets = cursor.fetchmany() |
356 |
except self._DatabaseError, err: |
except self._DatabaseError, err: |
357 |
raise GDataObjects.ConnectionError, err |
raise GDataObjects.ConnectionError(str(err)) |
358 |
if rsets and len(rsets): |
if rsets and len(rsets): |
359 |
for rs in (rsets): |
for rs in (rsets): |
360 |
if rs: |
if rs: |
379 |
def getSequence(self, name): |
def getSequence(self, name): |
380 |
return self.__singleQuery("select nextval('%s')" % name) |
return self.__singleQuery("select nextval('%s')" % name) |
381 |
|
|
382 |
def atomicModify(self, func, field, dataObject, record, cond=None): |
def atomicModify(self, func, field, dataObject, record, cond=None, autoCommit=1): |
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('.'): |
417 |
|
|
418 |
cursor = self.__connection.cursor() |
cursor = self.__connection.cursor() |
419 |
|
|
420 |
getValueStmt = "BEGIN; SELECT %s FROM %s WHERE %s FOR UPDATE; " % \ |
getValueStmt = "SELECT %s FROM %s WHERE %s FOR UPDATE; " % \ |
421 |
(field, table, \ |
(field, table, \ |
422 |
string.join(where,' AND ') ) |
string.join(where,' AND ') ) |
423 |
|
|
425 |
cursor.execute(getValueStmt) |
cursor.execute(getValueStmt) |
426 |
rv = cursor.fetchone() |
rv = cursor.fetchone() |
427 |
except: |
except: |
428 |
print "DBdriver.py", "error!" |
print >> sys.stderr, "DBdriver.py", "error! %s" % sys.exc_info()[1] |
429 |
GDebug.printMesg(1,"**** Unable to execute extension query") |
GDebug.printMesg(1,"**** Unable to execute extension query") |
430 |
GDebug.printMesg(1,"**** %s" % sys.exc_info()[1]) |
GDebug.printMesg(1,"**** %s" % sys.exc_info()[1]) |
431 |
cursor.close() |
cursor.close() |
432 |
return None |
raise |
433 |
|
|
434 |
try: |
try: |
435 |
lAux = rv[0] |
lAux = rv[0] |
436 |
except: |
except: |
437 |
try: |
try: |
438 |
cursor.execute("COMMIT") |
if autoCommit: |
439 |
|
self.__connection.rollback() |
440 |
cursor.close() |
cursor.close() |
441 |
except: |
except: |
442 |
print "DBdriver.py", "error!" |
print >> sys.stderr, "DBdriver.py", "error! %s" % sys.exc_info()[1] |
443 |
GDebug.printMesg(1,"**** Unable to execute extension query") |
GDebug.printMesg(1,"**** Unable to execute extension query") |
444 |
GDebug.printMesg(1,"**** %s" % sys.exc_info()[1]) |
GDebug.printMesg(1,"**** %s" % sys.exc_info()[1]) |
445 |
cursor.close() |
cursor.close() |
446 |
return None |
raise |
447 |
|
|
448 |
if field.count('.') > 0: |
if field.count('.') > 0: |
449 |
auxField = field.split('.')[1] |
auxField = field.split('.')[1] |
457 |
|
|
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 ') ) |
461 |
|
|
462 |
try: |
try: |
463 |
cursor.execute(updateStmt) |
cursor.execute(updateStmt) |
464 |
cursor.close() |
if autoCommit: |
465 |
|
self.__connection.commit() |
466 |
|
#cursor.close() |
467 |
except: |
except: |
468 |
print "DBdriver.py", "error!" |
print >> sys.stderr, "DBdriver.py", "error! %s" % sys.exc_info()[1] |
469 |
GDebug.printMesg(1,"**** Unable to execute extension query") |
GDebug.printMesg(1,"**** Unable to execute extension query") |
470 |
GDebug.printMesg(1,"**** %s" % sys.exc_info()[1]) |
GDebug.printMesg(1,"**** %s" % sys.exc_info()[1]) |
471 |
cursor.close() |
cursor.close() |
472 |
return None |
raise |
473 |
|
|
474 |
return 1 |
return 1 |
475 |
|
|
476 |
def atomicModifyForEntry(self, func, field, dataObject, record, cond=None): |
def atomicModifyForEntry(self, func, field, dataObject, record, cond=None,autoCommit=1): |
477 |
if string.count(dataObject.table,',') == 0: |
if string.count(dataObject.table,',') == 0: |
478 |
table = dataObject.table |
table = dataObject.table |
479 |
elif field.count('.'): |
elif field.count('.'): |
514 |
|
|
515 |
cursor = self.__connection.cursor() |
cursor = self.__connection.cursor() |
516 |
|
|
517 |
getValueStmt = "BEGIN; SELECT %s FROM %s WHERE %s FOR UPDATE; " % \ |
getValueStmt = "SELECT %s FROM %s WHERE %s FOR UPDATE; " % \ |
518 |
(field, table, \ |
(field, table, \ |
519 |
string.join(where,' AND ') ) |
string.join(where,' AND ') ) |
520 |
|
|
522 |
cursor.execute(getValueStmt) |
cursor.execute(getValueStmt) |
523 |
rv = cursor.fetchone() |
rv = cursor.fetchone() |
524 |
except: |
except: |
525 |
print "DBdriver.py", "error!" |
print >> sys.stderr, "DBdriver.py", "error! %s" % sys.exc_info()[1] |
526 |
GDebug.printMesg(1,"**** Unable to execute extension query") |
GDebug.printMesg(1,"**** Unable to execute extension query") |
527 |
GDebug.printMesg(1,"**** %s" % sys.exc_info()[1]) |
GDebug.printMesg(1,"**** %s" % sys.exc_info()[1]) |
528 |
cursor.close() |
cursor.close() |
529 |
return None |
raise |
530 |
|
|
531 |
try: |
try: |
532 |
lAux = rv[0] |
lAux = rv[0] |
533 |
except: |
except: |
534 |
try: |
try: |
535 |
cursor.execute("COMMIT") |
if autoCommit: |
536 |
cursor.close() |
self.__connection.rollback() |
537 |
|
#cursor.close() |
538 |
except: |
except: |
539 |
print "DBdriver.py", "error!" |
print >> sys.stderr, "DBdriver.py", "error! %s" % sys.exc_info()[1] |
540 |
GDebug.printMesg(1,"**** Unable to execute extension query") |
GDebug.printMesg(1,"**** Unable to execute extension query") |
541 |
GDebug.printMesg(1,"**** %s" % sys.exc_info()[1]) |
GDebug.printMesg(1,"**** %s" % sys.exc_info()[1]) |
542 |
cursor.close() |
cursor.close() |
543 |
return None |
raise |
544 |
|
|
545 |
if field.count('.') > 0: |
if field.count('.') > 0: |
546 |
auxField = field.split('.')[1] |
auxField = field.split('.')[1] |
553 |
value = func |
value = func |
554 |
|
|
555 |
if record._haveHistory(table): |
if record._haveHistory(table): |
556 |
updateStmt = "BEGIN; UPDATE %s SET _end_t = '%s' WHERE %s" % \ |
updateStmt = "UPDATE %s SET _end_t = '%s' WHERE %s" % \ |
557 |
(table, dataObject.triggerExtensions.getTimeStamp(), \ |
(table, dataObject.triggerExtensions.getTimeStamp(), \ |
558 |
string.join(where,' AND ') ) + "; COMMIT" |
string.join(where,' AND ') ) |
559 |
statementElement = record._buildInsertStatementWHist(table,field) |
statementElement = record._buildInsertStatementWHist(table,field) |
560 |
statementElement[1].append(field) |
statementElement[1].append(field) |
561 |
statementElement[2].append(str(value)) |
statementElement[2].append(str(value)) |
565 |
string.join(statementElement[2],',') ) |
string.join(statementElement[2],',') ) |
566 |
|
|
567 |
else: |
else: |
568 |
updateStmt = "BEGIN; UPDATE %s SET %s WHERE %s" % \ |
updateStmt = "UPDATE %s SET %s WHERE %s" % \ |
569 |
(table, " %s = %s " % (auxField, str(value)), \ |
(table, " %s = %s " % (auxField, str(value)), \ |
570 |
string.join(where,' AND ') ) + "; COMMIT" |
string.join(where,' AND ') ) |
571 |
|
|
572 |
|
|
573 |
try: |
try: |
574 |
cursor.execute(updateStmt) |
cursor.execute(updateStmt) |
575 |
cursor.execute(insertStmt) |
if record._haveHistory(table): |
576 |
cursor.close() |
cursor.execute(insertStmt) |
577 |
|
#cursor.close() |
578 |
except: |
except: |
579 |
print "DBdriver.py", "error!" |
print >> sys.stderr, "DBdriver.py", "error! %s" % sys.exc_info()[1] |
580 |
GDebug.printMesg(1,"**** Unable to execute extension query") |
GDebug.printMesg(1,"**** Unable to execute extension query") |
581 |
GDebug.printMesg(1,"**** %s" % sys.exc_info()[1]) |
GDebug.printMesg(1,"**** %s" % sys.exc_info()[1]) |
582 |
cursor.close() |
cursor.close() |
583 |
return None |
raise |
584 |
|
|
585 |
|
if autoCommit: |
586 |
|
self.__connection.commit() |
587 |
|
|
588 |
return 1 |
return 1 |
589 |
|
|
605 |
rv = cursor.fetchone() |
rv = cursor.fetchone() |
606 |
cursor.close() |
cursor.close() |
607 |
except: |
except: |
608 |
print "DBdriver.py", "You've got your bar in my foo! And you've got your foo on my bar! Two great reams that ream well together!" |
print >> sys.stderr, "DBdriver.py", "You've got your bar in my foo! And you've got your foo on my bar! Two great reams that ream well together!" |
609 |
GDebug.printMesg(1,"**** Unable to execute extension query") |
GDebug.printMesg(1,"**** Unable to execute extension query") |
610 |
GDebug.printMesg(1,"**** %s" % sys.exc_info()[1]) |
GDebug.printMesg(1,"**** %s" % sys.exc_info()[1]) |
611 |
cursor.close() |
cursor.close() |