commit-gnue
[Top][All Lists]
Advanced

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

r6404 - in trunk/gnue-common/src/datasources: . drivers/Base drivers/DBS


From: johannes
Subject: r6404 - in trunk/gnue-common/src/datasources: . drivers/Base drivers/DBSIG2 drivers/interbase/Schema/Discovery drivers/interbase/interbase drivers/postgresql/Schema/Discovery
Date: Mon, 27 Sep 2004 14:04:23 -0500 (CDT)

Author: johannes
Date: 2004-09-27 14:04:22 -0500 (Mon, 27 Sep 2004)
New Revision: 6404

Modified:
   trunk/gnue-common/src/datasources/Exceptions.py
   trunk/gnue-common/src/datasources/drivers/Base/Connection.py
   trunk/gnue-common/src/datasources/drivers/Base/DataObject.py
   trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
   trunk/gnue-common/src/datasources/drivers/DBSIG2/Connection.py
   trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py
   trunk/gnue-common/src/datasources/drivers/DBSIG2/RecordSet.py
   trunk/gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py
   
trunk/gnue-common/src/datasources/drivers/interbase/Schema/Discovery/Introspection.py
   trunk/gnue-common/src/datasources/drivers/interbase/interbase/Connection.py
   
trunk/gnue-common/src/datasources/drivers/postgresql/Schema/Discovery/Introspection.py
Log:
Remove obsolete indentifier () functions, fixed some exceptions


Modified: trunk/gnue-common/src/datasources/Exceptions.py
===================================================================
--- trunk/gnue-common/src/datasources/Exceptions.py     2004-09-27 19:00:20 UTC 
(rev 6403)
+++ trunk/gnue-common/src/datasources/Exceptions.py     2004-09-27 19:04:22 UTC 
(rev 6404)
@@ -66,7 +66,7 @@
   # and detaillink="id" would be a problem; must be 1:1)
   pass
 
-class ConnectionError(Error):
+class ConnectionError(errors.AdminError):
   # Generic error reading from the database connection
   pass
 

Modified: trunk/gnue-common/src/datasources/drivers/Base/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/Connection.py        
2004-09-27 19:00:20 UTC (rev 6403)
+++ trunk/gnue-common/src/datasources/drivers/Base/Connection.py        
2004-09-27 19:04:22 UTC (rev 6404)
@@ -75,22 +75,6 @@
 
 
   # ---------------------------------------------------------------------------
-  # Return an identifier usable by the connection
-  # ---------------------------------------------------------------------------
-
-  def identifier (self, identifier):
-    """
-    This function transforms an identifier to be safely used by the connection.
-    Descendants can override this function to do their stuff like switching
-    case and so on.
-
-    @param identifier: the identifier to be processed
-    @return: string with a safe identifier
-    """
-    return identifier
-
-
-  # ---------------------------------------------------------------------------
   # update the schema definition 
   # ---------------------------------------------------------------------------
 
@@ -125,16 +109,17 @@
     # occurence.
     for table in workingSet:
       # Do we have already a table with that name?
-      res = self.introspector.find (name = self.identifier (table ['name']))
+      res = self.introspector.find (name = table ['name'])
 
       if res is not None:
         method = self.schemaCreator.modifyTable
-        existingFields = [f.name for f in res [0].fields ()]
+        # Please note: we keep existingFields sequence in all lowercase
+        existingFields = [f.name.lower () for f in res [0].fields ()]
 
         # keep only new fields
         keep = []
         for field in table ['fields']:
-          if not self.identifier (field ['name']) in existingFields:
+          if not field ['name'].lower () in existingFields:
             keep.append (field)
 
         table ['fields'] = keep
@@ -148,7 +133,7 @@
           keep = []
           for index in table ['indices']:
             for field in index ['fields']:
-              if not self.identifier (field) in existingFields:
+              if not field.lower () in existingFields:
                 keep.append (index)
                 break
 
@@ -161,7 +146,7 @@
 
           for constraint in table ['constraints']:
             for field in constraint ['fields']:
-              if not self.identifier (field) in existingFields:
+              if not field.lower () in existingFields:
                 keep.append (constraint)
                 break
 

Modified: trunk/gnue-common/src/datasources/drivers/Base/DataObject.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/DataObject.py        
2004-09-27 19:00:20 UTC (rev 6403)
+++ trunk/gnue-common/src/datasources/drivers/Base/DataObject.py        
2004-09-27 19:04:22 UTC (rev 6404)
@@ -126,11 +126,11 @@
 
     dataObject._masterfields = string.split (  \
         hasattr (dataObject, 'masterlink') and \
-          self._connection.identifier (dataObject.masterlink) or "", ',')
+          dataObject.masterlink or "", ',')
 
     dataObject._detailfields = string.split (  \
         hasattr (dataObject, 'detaillink') and \
-          self._connection.identifier (dataObject.detaillink) or "", ',')
+          dataObject.detaillink or "", ',')
 
     if len(dataObject._masterfields) != len(dataObject._detailfields):
       tmsg = u_("master=%s; detail=%s") % (dataObject._masterfields, 
dataObject._detailfields)

Modified: trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2004-09-27 
19:00:20 UTC (rev 6403)
+++ trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2004-09-27 
19:04:22 UTC (rev 6404)
@@ -153,14 +153,20 @@
       # old code:
       # fn = string.lower(field)
       # self._fields[fn] = value
-      # new code:
-      self._fields[field] = value
+
+      # Until appserver is case insensitive we have to keep this workaround
+      if do._connection.parameters.get ('provider') == 'appserver':
+        fn = field
+      else:
+        fn = string.lower (field)
+
+      self._fields [fn] = value
       if trackMod:
         if self._parent.isFieldBound(field):
           self._emptyFlag = False
           self._updateFlag = True
-          # self._modifiedFlags[fn] = 1
-          self._modifiedFlags[field] = True
+          self._modifiedFlags [fn] = True
+          # self._modifiedFlags[field] = True
 
           try:
             do._dataSource._onModification(self)

Modified: trunk/gnue-common/src/datasources/drivers/DBSIG2/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/DBSIG2/Connection.py      
2004-09-27 19:00:20 UTC (rev 6403)
+++ trunk/gnue-common/src/datasources/drivers/DBSIG2/Connection.py      
2004-09-27 19:04:22 UTC (rev 6404)
@@ -38,7 +38,7 @@
 
 from gnue.common.datasources import Exceptions
 from gnue.common.datasources.drivers.Base.Connection import Connection as 
BaseConnection
-from gnue.common.apps import GDebug
+from gnue.common.apps import errors
 import string
 import sys
 import mx.DateTime
@@ -72,18 +72,18 @@
     return [['_username', _('User Name'),0],['_password', _('Password'),1]]
 
   def commit(self):
-    GDebug.printMesg (5,"DB-SIG database driver: commit()")
+    gDebug (5,"DB-SIG database driver: commit()")
 
     try:
       self.native.commit()
       
     except self._DatabaseError, value:
-      raise Exceptions.ConnectionError, value
+      raise Exceptions.ConnectionError, errors.getException () [2]
 
     self._beginTransaction()
 
   def rollback(self):
-    GDebug.printMesg (5,"DB-SIG database driver: rollback()")
+    gDebug (5,"DB-SIG database driver: rollback()")
 
     try:
       self.native.rollback()
@@ -108,20 +108,6 @@
     pass
 
 
-  # ---------------------------------------------------------------------------
-  # SQL databases usually are case insensitive
-  # ---------------------------------------------------------------------------
-
-  def identifier (self, identifier):
-    """
-    This function converts an identifier to lowercase letters only
-
-    @param identifier: identifier to be converted
-    @return: lowercase string
-    """
-
-    return identifier.lower ()
-
   # ===========================================================================
   # SQL statement handling
   # ===========================================================================

Modified: trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py      
2004-09-27 19:00:20 UTC (rev 6403)
+++ trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py      
2004-09-27 19:04:22 UTC (rev 6404)
@@ -37,7 +37,7 @@
 
 from gnue.common.datasources import GConditions, Exceptions
 from gnue.common.datasources.drivers.Base import DataObject as BaseDataObject
-from gnue.common.apps import GDebug
+from gnue.common.apps import errors
 import string
 import types
 import mx.DateTime
@@ -102,7 +102,7 @@
   def __init__(self, *args, **params):
     BaseDataObject.__init__(self, *args, **params)
 
-    GDebug.printMesg (1,"DB-SIG database driver backend initializing")
+    gDebug (1, "DB-SIG database driver backend initializing")
 
 
     # TODO: uh, hmm..
@@ -145,7 +145,7 @@
       elif type(value) == types.StringType:
 
         if self._unicodeMode:
-          GDebug.printMesg(0,'WARNING: non-unicode passed to the dbdriver 
(%s)' % value)
+          gDebug (0, 'WARNING: non-unicode passed to the dbdriver (%s)' % 
value)
 
         return "'%s'" % replace(value,
                                        "'",
@@ -167,7 +167,7 @@
         err = u_("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)
+        gDebug (0, err)
         return "'%s'" % replace(str(value),
                                        "'",
                                        "%s'" % self._escapeSingleQuote)
@@ -196,8 +196,8 @@
         #recordCount = self._getQueryCount(conditions,sql)
         #  ARGH!!!! Oh, the agony... the agony....
 
-    except self._DatabaseError, err:
-      raise Exceptions.ConnectionError, err
+    except self._DatabaseError:
+      raise Exceptions.ConnectionError, errors.getException () [2]
 
     rs = self._resultSetClass(self, cursor=cursor, 
masterRecordSet=masterRecordSet,
        fieldOrder=self._fieldOrder)
@@ -231,7 +231,7 @@
       _and._children = chillun
 
     where = " WHERE (%s)" % (self.__conditionToSQL (cond._children[0]))
-    GDebug.printMesg(5, where)
+    gDebug (5, where)
     return where
 
   #
@@ -301,7 +301,7 @@
 class DataObject_Object(DataObject):
 
   def _buildQuery(self, conditions={}, forDetail=None, additionalSQL=""):
-    GDebug.printMesg(7,'Implicit Fields: %s' % self._fieldReferences)
+    gDebug (7, 'Implicit Fields: %s' % self._fieldReferences)
     if self.distinct:
       distinct = "distinct "
     else:
@@ -340,7 +340,7 @@
     if hasattr(self,'order_by') and not forDetail:
      q = "%s ORDER BY %s " % (q, self.order_by)
 
-    GDebug.printMesg(5,q)
+    gDebug (5, q)
 
     return q
 
@@ -355,7 +355,7 @@
 
     q = "SELECT count(*) FROM %s%s" % (self.table, whereClause)
 
-    GDebug.printMesg(5,q)
+    gDebug (5, q)
 
     return q
 

Modified: trunk/gnue-common/src/datasources/drivers/DBSIG2/RecordSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/DBSIG2/RecordSet.py       
2004-09-27 19:00:20 UTC (rev 6403)
+++ trunk/gnue-common/src/datasources/drivers/DBSIG2/RecordSet.py       
2004-09-27 19:04:22 UTC (rev 6404)
@@ -37,7 +37,7 @@
 
 from gnue.common.datasources import GConditions, Exceptions
 from gnue.common.datasources.drivers.Base import RecordSet as BaseRecordSet
-from gnue.common.apps import GDebug
+from gnue.common.apps import errors
 from string import join
 
 
@@ -63,8 +63,9 @@
            self.getField(do.primarykey) is None:
           try:
             
self.setField(do.primarykey,do._connection.getsequence(do.primarykeyseq))
-          except do._connection._DatabaseError, err:
-            raise exceptions.InvalidDatasourceDefintion, err
+          except do._connection._DatabaseError:
+            raise exceptions.InvalidDatasourceDefintion, \
+                errors.getException () [2]
       s = self._buildInsertStatement()
     elif self._updateFlag:
       s = self._buildUpdateStatement()
@@ -76,7 +77,7 @@
       # when useParameters is set
       (statement, parameters) = (s, None)
 
-    GDebug.printMesg(5, "_postChanges: statement=%s" % statement)
+    gDebug (5, "_postChanges: statement=%s" % statement)
 
     try:
       do._connection.sql (statement, parameters)
@@ -86,7 +87,7 @@
         self._initialData = {}.update(self._fields)
 
     except do._connection._DatabaseError, err:
-      raise Exceptions.ConnectionError, err
+      raise Exceptions.ConnectionError, errors.getException () [2]
 
     self._updateFlag = False
     self._insertFlag = False
@@ -241,5 +242,5 @@
       for i in range(len(f)):
         self.setField(fields[i], f[i], False)
     except do._connection._DatabaseError, err:
-      raise Exceptions.ConnectionError, err
+      raise Exceptions.ConnectionError, errors.getException () [2]
     return True

Modified: trunk/gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py       
2004-09-27 19:00:20 UTC (rev 6403)
+++ trunk/gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py       
2004-09-27 19:04:22 UTC (rev 6404)
@@ -35,7 +35,7 @@
 
 from gnue.common.datasources import GConditions, Exceptions
 from gnue.common.datasources.drivers.Base import ResultSet as BaseResultSet
-from gnue.common.apps import GDebug
+from gnue.common.apps import errors
 import string
 import types
 
@@ -55,16 +55,16 @@
 
     if self._cursor:
       for t in(self._cursor.description):
-        if type(t[0])==types.UnicodeType:
-          self._fieldNames.append(t[0])
-        else:
-          self._fieldNames.append(unicode(t[0], 
self._dataObject._connection._encoding))
+        if type(t[0])==types.UnicodeType:
+          self._fieldNames.append(t[0])
+        else:
+          self._fieldNames.append(unicode(t[0], 
self._dataObject._connection._encoding))
         self._dataObject._fieldReferences[t[0]] = ""
-      GDebug.printMesg(5, "Field names set to %s" % self._fieldNames)
+      gDebug (5, "Field names set to %s" % self._fieldNames)
 
     self._recordCount = self._cursor.rowcount or 0
 
-    GDebug.printMesg(5, 'ResultSet created')
+    gDebug (5, 'ResultSet created')
 
   def _loadNextRecord(self):
     if self._cursor:
@@ -80,7 +80,7 @@
           # Pass arraysize because of mysql fetchmany bug in MySQLdb < 0.9.2
           rsets = self._cursor.fetchmany (self._cursor.arraysize)
         except self._dataObject._connection._DatabaseError, err:
-          raise Exceptions.ConnectionError, err
+          raise Exceptions.ConnectionError, errors.getException () [2]
 
       if rsets and len(rsets):
         for rs in(rsets):

Modified: 
trunk/gnue-common/src/datasources/drivers/interbase/Schema/Discovery/Introspection.py
===================================================================
--- 
trunk/gnue-common/src/datasources/drivers/interbase/Schema/Discovery/Introspection.py
       2004-09-27 19:00:20 UTC (rev 6403)
+++ 
trunk/gnue-common/src/datasources/drivers/interbase/Schema/Discovery/Introspection.py
       2004-09-27 19:04:22 UTC (rev 6404)
@@ -24,6 +24,7 @@
 
 import string
 import re
+import kinterbasdb
 
 from gnue.common.datasources import GIntrospection
 
@@ -31,7 +32,7 @@
 # This class implements schema introspection for Interbase / Firebird
 # =============================================================================
 
-class Introspection(GIntrospection.Introspection):
+class Introspection (GIntrospection.Introspection):
 
   # list of the types of Schema objects this driver provides
   types = [('table', _('Tables'), 1),
@@ -55,12 +56,13 @@
         no element could be found.
     """
 
+    gDebug (3, "Looking for '%s' of type '%s'" % (name, type))
+
     result = []
     cond   = ["rdb$system_flag = 0"]
 
     if name is not None:
-      cond.append (u"rdb$relation_name = '%s'" \
-                   % self._connection.identifier (name))
+      cond.append (u"rdb$relation_name = '%s'" % self.__identifier (name))
 
     if type == 'table':
       cond.append (u"rdb$view_source IS NULL")
@@ -74,7 +76,7 @@
 
     try:
       for rs in cursor.fetchall ():
-        relname = self._connection.identifier (string.strip (rs [0]))
+        relname = string.strip (rs [0])
 
         attrs = {'id'        : relname,
                  'name'      : relname,
@@ -114,7 +116,7 @@
              "fs.rdb$field_name = rf.rdb$field_source AND " \
              "tp.rdb$type = fs.rdb$field_type AND " \
              "tp.rdb$field_name = 'RDB$FIELD_TYPE'" \
-           "ORDER BY rf.rdb$field_name" % parent.name
+           "ORDER BY rf.rdb$field_name" % self.__identifier (parent.name)
 
     cursor = self._connection.makecursor (cmd)
 
@@ -122,7 +124,7 @@
       for rs in cursor.fetchall ():
         nativetype = rs [1].strip ()
         attrs = {'id'        : "%s.%s" % (parent.name, rs [0].strip ()),
-                 'name'      : self._connection.identifier (rs [0].strip ()),
+                 'name'      : rs [0].strip (),
                  'type'      : 'field',
                  'nativetype': nativetype,
                  'required'  : rs [2] is not None}
@@ -174,7 +176,7 @@
            "WHERE ri.rdb$index_name = rc.rdb$index_name " \
               "AND rc.rdb$constraint_type = 'PRIMARY KEY' " \
               "AND rc.rdb$relation_name = '%s'" \
-           "ORDER BY ri.rdb$field_position" % relname
+           "ORDER BY ri.rdb$field_position" % self.__identifier (relname)
 
     cursor = self._connection.makecursor (cmd)
     
@@ -185,3 +187,14 @@
       cursor.close ()
 
     return len (result) and result or None
+
+
+  # ---------------------------------------------------------------------------
+  # Prepare an identifier for matching against rdb$-values
+  # ---------------------------------------------------------------------------
+
+  def __identifier (self, name):
+    if kinterbasdb.__version__ [:3] == (3, 0, 1):
+      return name.upper ()
+    else:
+      return name

Modified: 
trunk/gnue-common/src/datasources/drivers/interbase/interbase/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/interbase/interbase/Connection.py 
2004-09-27 19:00:20 UTC (rev 6403)
+++ trunk/gnue-common/src/datasources/drivers/interbase/interbase/Connection.py 
2004-09-27 19:04:22 UTC (rev 6404)
@@ -169,14 +169,6 @@
       return None
 
 
-  # ---------------------------------------------------------------------------
-  # Interbase really needs uppercase identifiers
-  # ---------------------------------------------------------------------------
-
-  def identifier (self, identifier):
-    return identifier.upper ()
-
-
 # RDB$CHARACTER_SETS.RDB$CHARACTER_SET_NAME
 ib_encTable =  {'ascii'     :  'ASCII',
                 ''          :  'BIG_5',

Modified: 
trunk/gnue-common/src/datasources/drivers/postgresql/Schema/Discovery/Introspection.py
===================================================================
--- 
trunk/gnue-common/src/datasources/drivers/postgresql/Schema/Discovery/Introspection.py
      2004-09-27 19:00:20 UTC (rev 6403)
+++ 
trunk/gnue-common/src/datasources/drivers/postgresql/Schema/Discovery/Introspection.py
      2004-09-27 19:04:22 UTC (rev 6404)
@@ -18,7 +18,7 @@
 #
 # Copyright 2000-2004 Free Software Foundation
 #
-# $Id: $
+# $Id$
 
 __all__ = ['Introspection']
 
@@ -57,7 +57,7 @@
     cond   = ["relname NOT LIKE 'pg_%'"]
 
     if name is not None:
-      cond = [u"relname = '%s'" % self._connection.identifier (name)]
+      cond = [u"relname = '%s'" % name]
 
     reltypes = []
     if type in ('table', 'sources', None):
@@ -75,7 +75,7 @@
     try:
       for rs in cursor.fetchall ():
         attrs = {'id'  : rs [0],
-                 'name': self._connection.identifier (rs [1]),
+                 'name': rs [1],
                  'type': rs [2] == 'v' and 'view' or 'table',
                  'primarykey': self.__getPrimaryKey (rs [0])}
 
@@ -115,7 +115,7 @@
     try:
       for rs in cursor.fetchall ():
         attrs = {'id'        : "%s.%s" % (rs [0], rs [7]),
-                 'name'      : self._connection.identifier (rs [1]),
+                 'name'      : rs [1],
                  'type'      : 'field',
                  'nativetype': rs [3],
                  'required'  : rs [4] and not rs [5]}





reply via email to

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