commit-gnue
[Top][All Lists]
Advanced

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

gnue-common/src/datasources GDataObjects.py dri...


From: Jan Ischebeck
Subject: gnue-common/src/datasources GDataObjects.py dri...
Date: Tue, 07 Oct 2003 09:02:55 -0400

CVSROOT:        /cvsroot/gnue
Module name:    gnue-common
Branch:         
Changes by:     Jan Ischebeck <address@hidden>  03/10/07 09:02:53

Modified files:
        src/datasources: GDataObjects.py 
        src/datasources/drivers/DBSIG2: Driver.py 
        src/datasources/drivers/postgresql/Base: Driver.py 

Log message:
        make unicode access to dbdriver possible:
        - add unicodeMode variable to GDataObject
        - fix postgres encoding stuff
        - add type check to DBSIG2 driver (type for fixedpoint number possibly 
missing)
        - show warning if unknown type is passed to dbdriver (should be 
replaced by error after some transition time)

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/datasources/GDataObjects.py.diff?tr1=1.71&tr2=1.72&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/datasources/drivers/DBSIG2/Driver.py.diff?tr1=1.72&tr2=1.73&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/datasources/drivers/postgresql/Base/Driver.py.diff?tr1=1.36&tr2=1.37&r1=text&r2=text

Patches:
Index: gnue-common/src/datasources/GDataObjects.py
diff -c gnue-common/src/datasources/GDataObjects.py:1.71 
gnue-common/src/datasources/GDataObjects.py:1.72
*** gnue-common/src/datasources/GDataObjects.py:1.71    Mon Oct  6 16:25:43 2003
--- gnue-common/src/datasources/GDataObjects.py Tue Oct  7 09:02:51 2003
***************
*** 85,90 ****
--- 85,93 ----
    # writing Schema to datasource
    pass
  
+ class UnknownDataType(Error):
+   # raised when an unknown datatype is passed to the database
+   pass
  
  
  ###########################################################
***************
*** 119,124 ****
--- 122,129 ----
        self._databaseEncoding = gConfig('textEncoding')
      except:
        pass
+ 
+     self._unicodeMode = 0
  
      self._defaultValues = {}
      self.triggerExtensions = None
Index: gnue-common/src/datasources/drivers/DBSIG2/Driver.py
diff -c gnue-common/src/datasources/drivers/DBSIG2/Driver.py:1.72 
gnue-common/src/datasources/drivers/DBSIG2/Driver.py:1.73
*** gnue-common/src/datasources/drivers/DBSIG2/Driver.py:1.72   Mon Oct  6 
16:25:43 2003
--- gnue-common/src/datasources/drivers/DBSIG2/Driver.py        Tue Oct  7 
09:02:52 2003
***************
*** 159,165 ****
              i = 0
              dict = {}
              for f in (rs):
!               #f = f.decode(self._dataObject._databaseEncoding)
                dict[string.lower(self._fieldNames[i])] = f
                i += 1
              self._cachedRecords.append (self._recordSetClass(parent=self, \
--- 159,167 ----
              i = 0
              dict = {}
              for f in (rs):
!               if self._dataObject._unicodeMode:
!                 f = f.decode(self._dataObject._databaseEncoding)
!                 
                dict[string.lower(self._fieldNames[i])] = f
                i += 1
              self._cachedRecords.append (self._recordSetClass(parent=self, \
***************
*** 246,273 ****
      try:
        return value.strftime(self._dateTimeFormat)
      except AttributeError:
        if value == None:
          return "NULL"
        elif type(value) == types.FloatType:
          if value==int(value):
            return "%d" % value
          else:
            return str(value)
  
        elif type(value) == types.UnicodeType:
          return "'%s'" % string.replace(value.encode(self._databaseEncoding),
                                         "'",
                                         "%s'" % self._escapeSingleQuote)
-       else:
-         try:
-           return "'%s'" % string.replace(str(value),
-                                          "'",
-                                          "%s'" % self._escapeSingleQuote)
-         except:
-           return "'%s'" % string.replace(value,
-                                          "'",
-                                          "%s'" % self._escapeSingleQuote)
  
  
    # This should be over-ridden only if driver needs more than user/pass
    def getLoginFields(self):
--- 248,298 ----
      try:
        return value.strftime(self._dateTimeFormat)
      except AttributeError:
+       
        if value == None:
          return "NULL"
+ 
+       elif type(value) == types.BooleanType:
+         if value:
+           return 'TRUE'
+         else:
+           return 'FALSE'
+         
+       elif type(value) == types.IntType:
+         return str(value)
+ 
+       elif type(value) == types.LongType:
+         return str(value)
+ 
        elif type(value) == types.FloatType:
          if value==int(value):
            return "%d" % value
          else:
            return str(value)
  
+       elif type(value) == types.StringType:
+ 
+         if self._unicodeMode:
+           print 'WARNING: non-unicode passed to the dbdriver (%s)' % 
str(value)
+           
+         return "'%s'" % string.replace(value,
+                                        "'",
+                                        "%s'" % self._escapeSingleQuote)      
+ 
        elif type(value) == types.UnicodeType:
          return "'%s'" % string.replace(value.encode(self._databaseEncoding),
                                         "'",
                                         "%s'" % self._escapeSingleQuote)
  
+       else:
+         err = _("Object of unknown type (%s) passed to DBSIG2 based 
dbdriver.") % type(value)
+         # FIXME: raise an error instead of just printing a warning, after 
some transition time
+         #raise GDataObjects.UnknownDataType, err
+         GDebug.printMesg (0,err)
+         return "'%s'" % string.replace(str(value),
+                                        "'",
+                                        "%s'" % self._escapeSingleQuote)
+         
  
    # This should be over-ridden only if driver needs more than user/pass
    def getLoginFields(self):
Index: gnue-common/src/datasources/drivers/postgresql/Base/Driver.py
diff -c gnue-common/src/datasources/drivers/postgresql/Base/Driver.py:1.36 
gnue-common/src/datasources/drivers/postgresql/Base/Driver.py:1.37
*** gnue-common/src/datasources/drivers/postgresql/Base/Driver.py:1.36  Mon Oct 
 6 17:28:11 2003
--- gnue-common/src/datasources/drivers/postgresql/Base/Driver.py       Tue Oct 
 7 09:02:53 2003
***************
*** 143,150 ****
        except KeyError:
          pass
  
!       encoding = self.encodingList(self._databaseEncoding)
! 
        if encoding.upper() not in ("",'DEFAULT'):
          GDebug.printMesg(1,'Setting postgresql client_encoding to %s (%s)' % 
(encoding,
                                                                                
self._databaseEncoding))
--- 143,155 ----
        except KeyError:
          pass
  
!       try:
!         encoding = self.encodingList[self._databaseEncoding]
!       except KeyError:
!         GDebug.printMesg(1,_("Encoding '%s' is not supported by postgresql 
dbdriver.") % \
!                          self._databaseEncoding)
!         encoding = ''
!         
        if encoding.upper() not in ("",'DEFAULT'):
          GDebug.printMesg(1,'Setting postgresql client_encoding to %s (%s)' % 
(encoding,
                                                                                
self._databaseEncoding))




reply via email to

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