commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Jason Cater
Subject: gnue/common/src/dbdrivers/_pgsql DBdriver.py
Date: Mon, 22 Jul 2002 00:08:51 -0400

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    02/07/22 00:08:51

Modified files:
        common/src/dbdrivers/_pgsql: DBdriver.py 

Log message:
        commented out misplaced date support in pgsql driver; fixed support for 
primary keys in pgsql driver

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/dbdrivers/_pgsql/DBdriver.py.diff?cvsroot=OldCVS&tr1=1.21&tr2=1.22&r1=text&r2=text

Patches:
Index: gnue/common/src/dbdrivers/_pgsql/DBdriver.py
diff -c gnue/common/src/dbdrivers/_pgsql/DBdriver.py:1.21 
gnue/common/src/dbdrivers/_pgsql/DBdriver.py:1.22
*** gnue/common/src/dbdrivers/_pgsql/DBdriver.py:1.21   Fri Jul 19 09:22:39 2002
--- gnue/common/src/dbdrivers/_pgsql/DBdriver.py        Mon Jul 22 00:08:50 2002
***************
*** 43,62 ****
    def _buildUpdateStatement(self):
      updates = []
      for field in self._modifiedFlags.keys():
!     # To convert date from format '2002-12-31 23:59:59,99'
!     # into '2002-12-31 23:59:59' format.
!     # We have to determine whether given string is date\time
!     # maybe it's the most stupid way, but it should work.
!     # TODO: if in ANY other field data of this format and comma in
!     # place will exist, the remaining string from first ',' will be
!     # eaten.
!     # If you know better decision - please, modify this code.
!       tmpDate = self._fields[field]
!       if ((len(tmpDate)==22) and (tmpDate[-3]==',')):
!         tmpDate = tmpDate.split(',')
!         tmpDate = tmpDate[0]
        updates.append ("%s=%s" % (field,
!         self._parent._dataObject._toSqlString(tmpDate)))
  
      if self._parent._dataObject._primaryIdField:
        where = [self._parent._dataObject._primaryIdFormat % \
--- 43,71 ----
    def _buildUpdateStatement(self):
      updates = []
      for field in self._modifiedFlags.keys():
! ##    # To convert date from format '2002-12-31 23:59:59,99'
! ##    # into '2002-12-31 23:59:59' format.
! ##    # We have to determine whether given string is date\time
! ##    # maybe it's the most stupid way, but it should work.
! ##    # TODO: if in ANY other field data of this format and comma in
! ##    # place will exist, the remaining string from first ',' will be
! ##    # eaten.
! ##    # If you know better decision - please, modify this code.
! ##
! ## This should have been submitted as a patch for peer review.
! ## For starters, it can break non-date fields w/commas.
! ## Secondly, such checks belong in _toSqlString!
! ## -- jcater
! ##
! ##      tmpDate = self._fields[field]
! ##      if ((len(tmpDate)==22) and (tmpDate[-3]==',')):
! ##        tmpDate = tmpDate.split(',')
! ##        tmpDate = tmpDate[0]
! ##      updates.append ("%s=%s" % (field,
! ##        self._parent._dataObject._toSqlString(tmpDate)))
! 
        updates.append ("%s=%s" % (field,
!         self._parent._dataObject._toSqlString(self._fields[field])))
  
      if self._parent._dataObject._primaryIdField:
        where = [self._parent._dataObject._primaryIdFormat % \
***************
*** 127,143 ****
          try:
            encoding = gConfig('encoding')
          except:
!           pass 
        if encoding!="":
-         
          GDebug.printMesg(1,'Setting postgresql client_encoding to %s' % 
encoding)
          cursor = self._dataConnection.cursor()
          cursor.execute("SET CLIENT_ENCODING TO '%s'" % encoding)
          cursor.close()
!     except self._DatabaseError: 
!       try: 
          cursor.close()
!       except: 
          pass
  
      self._postConnect()
--- 136,153 ----
          try:
            encoding = gConfig('encoding')
          except:
!           pass
! 
        if encoding!="":
          GDebug.printMesg(1,'Setting postgresql client_encoding to %s' % 
encoding)
          cursor = self._dataConnection.cursor()
          cursor.execute("SET CLIENT_ENCODING TO '%s'" % encoding)
          cursor.close()
! 
!     except self._DatabaseError:
!       try:
          cursor.close()
!       except:
          pass
  
      self._postConnect()
***************
*** 205,219 ****
      return schema
  
    def __getPrimaryKey(self, cursor, oid):
!     rs = cursor.execute("select indkey from pg_index where indrelid=%d" % oid)
      statement = "select attname from pg_attribute " \
                  "where attrelid = %d and attnum = %%d" % oid
      if rs:
        pks = []
!       for indpos in rs[0]:
!         pks.append(cursor.execute(statement % indpos).fetchone()[0])
        return tuple(pks)
      else:
        return None
  
    # Get fields for a table
--- 215,234 ----
      return schema
  
    def __getPrimaryKey(self, cursor, oid):
!     cursor = self._dataConnection.cursor()
!     cursor.execute("select indkey from pg_index where indrelid=%d" % oid)
!     rs = cursor.fetchone()
      statement = "select attname from pg_attribute " \
                  "where attrelid = %d and attnum = %%d" % oid
      if rs:
        pks = []
!       for indpos in string.split(rs[0]):
!         cursor.execute(statement % int(indpos))
!         pks.append(cursor.fetchone()[0])
!       cursor.close()
        return tuple(pks)
      else:
+       cursor.close()
        return None
  
    # Get fields for a table



reply via email to

[Prev in Thread] Current Thread [Next in Thread]