/[papo]/gnue/common/src/dbdrivers/_pgsql/DBdriver.py
ViewVC logotype

Diff of /gnue/common/src/dbdrivers/_pgsql/DBdriver.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.11 by apronotti, Fri Sep 13 23:59:06 2002 UTC revision 1.12 by apronotti, Wed Sep 25 17:23:28 2002 UTC
# Line 330  class PGSQL_TriggerExtensions: Line 330  class PGSQL_TriggerExtensions:
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('.'):
# Line 363  class PGSQL_TriggerExtensions: Line 363  class PGSQL_TriggerExtensions:
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; " % \
# Line 383  class PGSQL_TriggerExtensions: Line 385  class PGSQL_TriggerExtensions:
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)
# Line 404  class PGSQL_TriggerExtensions: Line 419  class PGSQL_TriggerExtensions:
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()

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26