commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r7236 - in trunk/gnue-common/src/datasources: . drivers/Base driv


From: reinhard
Subject: [gnue] r7236 - in trunk/gnue-common/src/datasources: . drivers/Base drivers/DBSIG2 drivers/adodbapi/adodbapi drivers/appserver/appserver drivers/interbase/interbase drivers/oracle/Base drivers/postgresql/Base
Date: Sun, 20 Mar 2005 18:09:18 -0600 (CST)

Author: reinhard
Date: 2005-03-20 18:09:16 -0600 (Sun, 20 Mar 2005)
New Revision: 7236

Modified:
   trunk/gnue-common/src/datasources/GDataSource.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/Base/ResultSet.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/ResultSet.py
   trunk/gnue-common/src/datasources/drivers/adodbapi/adodbapi/DataObject.py
   trunk/gnue-common/src/datasources/drivers/appserver/appserver/DataObject.py
   trunk/gnue-common/src/datasources/drivers/appserver/appserver/ResultSet.py
   trunk/gnue-common/src/datasources/drivers/interbase/interbase/DataObject.py
   trunk/gnue-common/src/datasources/drivers/oracle/Base/DataObject.py
   trunk/gnue-common/src/datasources/drivers/postgresql/Base/Connection.py
Log:
Added support for rowid and primarykey (with single part and multi part
primarykey) for where clause of insert, update, and delete statements and for
requery.  Added new function sql0 for DBSIG2 Connection object for SQL commands
that don't return a resultset.  Do not eat exceptions when executing SQL
commands.  Added debugging output in level 3 for DBSIG2 connect, close, commit,
and rollback.


Modified: trunk/gnue-common/src/datasources/GDataSource.py
===================================================================
--- trunk/gnue-common/src/datasources/GDataSource.py    2005-03-20 14:24:43 UTC 
(rev 7235)
+++ trunk/gnue-common/src/datasources/GDataSource.py    2005-03-21 00:09:16 UTC 
(rev 7236)
@@ -56,6 +56,8 @@
     self._fieldReferences = {}
     self._unboundFieldReferences = {}
     self._defaultValues = {}
+    self._rowidField = None
+    self._primarykeyFields = []
     self._ignoreDispatchEvent = None
 
     self._inits =[self.primaryInit, self.secondaryInit, self.tertiaryInit]
@@ -131,6 +133,14 @@
       for field in [item ['name'] for item in self.sorting]:
         self._fieldReferences [field] = True
 
+    # Primary key support
+    if hasattr (self, 'primarykey'):
+      self._primarykeyFields = self.primarykey.split (',')
+
+    # Make sure the primary key is included in the field references
+    for field in self._primarykeyFields:
+      self._fieldReferences [field] = True
+
     return GObjects.GObj._buildObject(self)
 
   def triggerGetOrderBy(self):
@@ -250,6 +260,16 @@
       dataObject = \
          self._connections.getDataObject(self.connection, self.type)
       gDebug (7, "GDataSource.py bound to %s " % dataObject)
+      
+      # Include the rowid in list of field references
+      rowidField = dataObject._connection._rowidField
+      if rowidField:
+        # TODO: checks if the rowid is available and should be used go here:
+        # 1. if primary key should be prefered, don't set self._rowidField
+        # 2. try if rowidField is available in current table/view
+        if not self._primarykeyFields:
+          self._rowidField = rowidField
+          self._fieldReferences [self._rowidField] = True
 
     self.name = string.lower(self.name)
     self._topObject._datasourceDictionary[self.name]=self
@@ -259,18 +279,6 @@
     dataObject._defaultValues = self._defaultValues
     dataObject._dataSource = self
 
-    # TODO: Short-term hack to allow primary key support
-    try:
-      dataObject._primaryIdField = self.primarykey
-      dataObject._primaryIdFormat = "%s = '%%s'" % self.primarykey
-      dataObject._primaryIdChecked = True
-    except AttributeError:
-      pass
-
-    # Make sure the primary key is included in the field references
-    if dataObject._primaryIdField:
-      self._fieldReferences [dataObject._primaryIdField] = True
-
     hasRaw = False
     for child in self._children:
       if isinstance(child, GConditions.GCondition):

Modified: trunk/gnue-common/src/datasources/drivers/Base/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/Connection.py        
2005-03-20 14:24:43 UTC (rev 7235)
+++ trunk/gnue-common/src/datasources/drivers/Base/Connection.py        
2005-03-21 00:09:16 UTC (rev 7236)
@@ -38,13 +38,15 @@
   This class must be subclassed by all database drivers. It represents a
   connection to the backend.
 
-  @cvar defaultBehaviour: standard schema introspector class for this type of
-    connection.  Must be overwritten by descendants
-  @cvar defaultCreator: standard schema creator class for this type of
-    connection.  Must be overwritten by descendants
-  @cvar supportedDataObjects: dictionary of dataObject classes available for
+  @cvar defaultBehaviour: Standard schema introspector class for this type of
+    connection.  Must be overwritten by descendants.
+  @cvar defaultCreator: Standard schema creator class for this type of
+    connection.  Must be overwritten by descendants.
+  @cvar supportedDataObjects: Dictionary of dataObject classes available for
     this connection type, where the key is the type of the dataObject (can be
-    'object' or 'sql').  Must be overwritten by descendants
+    'object' or 'sql').  Must be overwritten by descendants.
+  @cvar _rowidField: Field name of the rowid generated by the backend.  Can be
+    overwritten by descendants if the backend supports rowids.
 
   @ivar name: Name of the connection from connections.conf.
   @ivar parameters: Parameters from connections.conf.
@@ -56,7 +58,9 @@
   defaultCreator   = None
   supportedDataObjects = {}
 
+  _rowidField = None
 
+
   # ---------------------------------------------------------------------------
   # Constructor
   # ---------------------------------------------------------------------------
@@ -144,11 +148,12 @@
     @param table: Table name.
     @param newfields: Fieldname/Value dictionary of data to insert.
     @param recno: Record number to be used in error messages.
+    @return: The rowid of the newly inserted record, or None if no rowid's are
+    supported.
     """
 
     gEnter (8)
-    self._insert (table, newfields, recno)
-    gLeave (8)
+    return gLeave (8, self._insert (table, newfields, recno))
 
   # ---------------------------------------------------------------------------
   # Update an existing record in the backend
@@ -498,13 +503,16 @@
     Insert a new record in the backend (to be implemented by descendants).
 
     Database drivers can overwrite this method to send new data records to the
-    backend.
+    backend.  If the backend supports rowids, the rowid of the newly inserted
+    record must be returned from this method.
 
     @param table: Table name.
     @param newfields: Fieldname/Value dictionary of data to insert.
     @param recno: Record number to be used in error messages.
+    @return: The rowid of the newly inserted record, or None if no rowid's are
+    supported.
     """
-    pass
+    return None
 
   # ---------------------------------------------------------------------------
 

Modified: trunk/gnue-common/src/datasources/drivers/Base/DataObject.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/DataObject.py        
2005-03-20 14:24:43 UTC (rev 7235)
+++ trunk/gnue-common/src/datasources/drivers/Base/DataObject.py        
2005-03-21 00:09:16 UTC (rev 7236)
@@ -45,7 +45,6 @@
 class DataObject:
 
   _resultSetClass = ResultSet
-  _primaryIdField = None
 
   def __init__(self, connection):
     self._connection = connection

Modified: trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-03-20 
14:24:43 UTC (rev 7235)
+++ trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-03-21 
00:09:16 UTC (rev 7236)
@@ -37,8 +37,12 @@
   # Constructor
   # ---------------------------------------------------------------------------
 
-  def __init__ (self, parent, initialData = {}, defaultData = {}):
+  def __init__ (self, parent, initialData = {}, defaultData = {},
+      rowidField = None, primarykeyFields = []):
 
+    self.__rowidField = rowidField              # Field name of the rowid
+    self.__primarykeyFields = primarykeyFields  # Field names of the primarykey
+
     # Status information - FIXME: should be private, others should use
     # isEmpty(), isInserted(), isModified() and isDeleted()
     self._emptyFlag  = False
@@ -91,12 +95,19 @@
           self._fields [field.lower ()] = value
           # Make sure the default values are included in the insert field list
           self._modifiedFlags [field.lower ()] = True
-      self._initialData = self._fields.copy ()
 
-      # 4. Query current data from the backend.  The requery function only does
-      #    something if the primary key was initialized above.  This is used
-      #    for appserver to retrieve the result of OnInit.
-      self.requery ()
+      # 4. Query current data from the backend, if the primary key was
+      #    initialized above.  This is used for appserver to retrieve the
+      #    result of OnInit.
+      if self.__primarykeyFields:
+        primarykeyIsComplete = True
+        for field in self.__primarykeyFields:
+          if self._fields [field] is None:
+            primarykeyIsComplete = False
+            break
+        if primarykeyIsComplete:
+          self._initialData = self._fields.copy ()
+          self.requery ()
 
       # 5. Get default values from DataSource.  This has to be done at the very
       #    end, as these changes remain local until the first post.
@@ -296,19 +307,26 @@
 
   def __wherefields (self):
 
-    do = self._parent._dataObject
+    result = {}
 
-    # Do we have a primary key?
-    if self._initialData.has_key (do._primaryIdField):
-      return {do._primaryIdField: self._initialData [do._primaryIdField]}
+    # First priority: row id
+    if self._initialData.has_key (self.__rowidField):
+      result [self.__rowidField] = self._initialData [self.__rowidField]
+
+    # Second priority: primary key
+    elif self.__primarykeyFields:
+      for field in self.__primarykeyFields:
+        result [field] = self._initialData [field]
+
+    # If all else fails, use all fields in the where clause
     else:
-      result = {}
       for field in self._initialData.keys ():
         if self._parent.isFieldBound (field):
           result [field] = self._initialData [field]
-      return result
 
+    return result
 
+
   # ---------------------------------------------------------------------------
   # Post changes to database
   # ---------------------------------------------------------------------------
@@ -367,8 +385,6 @@
             raise exceptions.InvalidDatasourceDefintion, \
                 errors.getException () [2]
 
-    deleting = self.isDeleted ()
-
     # If we have a connection (i.e. we aren't static or unbound), do the post
     if self._parent._dataObject._connection:
       gDebug (8, 'Posting datasource %s' % self._parent._dataObject.name)
@@ -406,9 +422,7 @@
       child.requery ()
 
     # Now requery ourselves
-    if self._initialData.has_key (do._primaryIdField) and \
-       self._initialData [do._primaryIdField] is not None:
-
+    if self.__rowidField or self.__primarykeyFields:
       fields = [field for field in self._fields.keys ()
                 if self._parent.isFieldBound (field)]
       newfields = do._connection.requery (do.table, self.__wherefields (),
@@ -564,7 +578,9 @@
           modifiedFields [field] = self._fields [field]
 
       if self._insertFlag:
-        do._connection.insert (do.table, modifiedFields, recno)
+        rowid = do._connection.insert (do.table, modifiedFields, recno)
+        if self.__rowidField:
+          self._fields [self.__rowidField] = rowid
       else:
         do._connection.update (do.table, self.__wherefields (), modifiedFields,
                                recno)

Modified: trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py 2005-03-20 
14:24:43 UTC (rev 7235)
+++ trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py 2005-03-21 
00:09:16 UTC (rev 7236)
@@ -56,6 +56,13 @@
      self._defaultValues = {}
      self._defaultValues.update(defaultValues)
 
+     if self._dataObject._dataSource:
+       self.__rowidField       = self._dataObject._dataSource._rowidField
+       self.__primarykeyFields = self._dataObject._dataSource._primarykeyFields
+     else:
+       self.__rowidField       = None
+       self.__primarykeyFields = []
+
      self.__listeners = []
 
      self.__recordsToRequery = []
@@ -322,29 +329,25 @@
     # If include= is specified, then that is our base list.
     # Otherwise, get the base list as the fields in the table
     if include:
-      fields = list(include)
+      fields = list (include)
     else:
-      fields = list(current._fields.keys())
+      fields = current._fields.keys ()
 
     # Exclude all the fields in exclude=
     for field in exclude:
-      try:
-        fields.pop(exclude)
-      except:
-        pass
+      fields.remove (field)
 
-    # Do not duplicate the primary key field,
+    # Do not duplicate the primary key fields,
     # unless it was named in the include= parameter
-    try:
-      for field in self._dataObject._primaryIdField:
-        if field not in include:
-          try:
-            fields.pop(field)
-          except:
-            pass
-    except AttributeError:
-      pass
+    for field in self.__primarykeyFields:
+      if field not in include and field in fields:
+        fields.remove (field)
 
+    # Never include the rowid
+    field = self.__rowidField
+    if field and field in fields:
+      fields.remove (field)
+
     # Copy the fields over
     for field in fields:
       inserted[field] = current[field]
@@ -516,8 +519,10 @@
     return False
 
   # Create an empty recordset
-  def _createEmptyRecord(self):
-    return self._recordSetClass(self)
+  def _createEmptyRecord (self):
+    return self._recordSetClass (parent = self,
+        rowidField = self.__rowidField,
+        primarykeyFields = self.__primarykeyFields)
 
   # Iterator support (Python 2.2+)
   def __iter__(self):

Modified: trunk/gnue-common/src/datasources/drivers/DBSIG2/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/DBSIG2/Connection.py      
2005-03-20 14:24:43 UTC (rev 7235)
+++ trunk/gnue-common/src/datasources/drivers/DBSIG2/Connection.py      
2005-03-21 00:09:16 UTC (rev 7236)
@@ -261,20 +261,15 @@
     gDebug (3, "DBSIG2 Parameters: %s" % p)
 
     # Create DBSIG2 cursor and execute statement
+    cursor = self.native.cursor ()
     try:
-      cursor = self.native.cursor ()
       if p is not None:
         cursor.execute (s, p)
       else:
         cursor.execute (s)
-
     except:
-      (exc_type, exc_value, exc_traceback) = sys.exc_info ()
-      try:
-        cursor.close ()
-      except:
-        pass
-      raise exc_type, exc_value, exc_traceback
+      cursor.close ()
+      raise
 
     return cursor
 
@@ -294,26 +289,14 @@
       point numbers, booleans or mx.DateTime values.
     @return: A 2-dimensional matrix holding the complete result of the query.
     """
-    result = None
     cursor = self.makecursor (statement, parameters)
     try:
-      # This generates an exception if the statement didn't generate a
-      # resultset
       result = cursor.fetchall ()
-    except:
-      pass
-
-    try:
+    finally:
       cursor.close ()
-    except:
-      pass
+    return result
 
-    if result:
-      return result
-    else:
-      return []
 
-
   # ---------------------------------------------------------------------------
   # Execute the given SQL statement that is expected to return a single value
   # ---------------------------------------------------------------------------
@@ -337,11 +320,35 @@
       result = cursor.fetchone ()
     finally:
       cursor.close ()
+    return result [0]
 
-    if result:
-      return result [0]
+
+  # ---------------------------------------------------------------------------
+  # Execute the given SQL statement that is expected to return nothing
+  # ---------------------------------------------------------------------------
+
+  def sql0 (self, statement, parameters = None):
+    """
+    Execute the given SQL statement and return the rowid of the affected row
+    (in case the statement was an insert).
+
+    @param statement: The SQL statement as either 8-bit or unicode string. Can
+      contain %(name)s style placeholders for parameters.
+    @param parameters: A dictionary with the parameter values. The values of
+      the dictionary can be 8-bit strings, unicode strings, integer or floating
+      point numbers, booleans or mx.DateTime values.
+    @return: For INSERT statements, the rowid of the newly inserted record, if
+      the database supports rowids and the DBSIG2 module supports the
+      cursor.lastrowid extension, and None otherwise. For other statements,
+      undefined.
+    """
+    cursor = self.makecursor (statement, parameters)
+    if hasattr (cursor, 'lastrowid'):
+      result = cursor.lastrowid
     else:
-      return None
+      result = None
+    cursor.close ()
+    return result
 
 
   # ---------------------------------------------------------------------------
@@ -370,7 +377,7 @@
   def __execute (self, statement, parameters, recno):
 
     try:
-      self.sql (statement, parameters)
+      return self.sql0 (statement, parameters)
     except self._driver.DatabaseError:
       if recno:
         raise Exceptions.ConnectionError, \
@@ -406,6 +413,7 @@
 
   def _connect (self, connectData):
     (params, kwargs) = self._getConnectParams (connectData)
+    gDebug (3, 'DBSIG2 Connect')
     try:
       self.native = self._driver.connect (*params, **kwargs)
     except self._driver.DatabaseError:
@@ -425,7 +433,7 @@
     statement = "INSERT INTO %s (%s) VALUES (%s)" % (table,
                                                      string.join (fields,', '),
                                                      string.join (values,', '))
-    self.__execute (statement, parameters, recno)
+    return self.__execute (statement, parameters, recno)
 
   # ---------------------------------------------------------------------------
 
@@ -466,6 +474,7 @@
   # ---------------------------------------------------------------------------
 
   def _commit (self):
+    gDebug (3, 'DBSIG2 Commit')
     try:
       self.native.commit ()
     except self._driver.DatabaseError:
@@ -474,6 +483,7 @@
   # ---------------------------------------------------------------------------
 
   def _rollback (self):
+    gDebug (3, 'DBSIG2 Rollback')
     try:
       self.native.rollback ()
     except:
@@ -483,5 +493,6 @@
   # ---------------------------------------------------------------------------
 
   def _close (self):
+    gDebug (3, 'DBSIG2 Close')
     if self.native:
       self.native.close ()

Modified: trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py      
2005-03-20 14:24:43 UTC (rev 7235)
+++ trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py      
2005-03-21 00:09:16 UTC (rev 7236)
@@ -60,18 +60,6 @@
   _dateTimeFormat = "'%c'"
   _timeFormat = "'%X'"
 
-  # If a DB driver supports a unique identifier for rows,
-  # list it here.  _primaryIdField is the field name (lower case)
-  # that would appear in the recordset (note that this can be
-  # a system generated format). If a primary id is supported,
-  # _primaryIdFormat is the WHERE clause to be used. It will have
-  # the string  % (fieldvalue) format applied to it.
-  #
-  # See Oracle drivers for example
-  _primaryIdField = None         # Internal recordset field name (lowercase!!!)
-  _primaryIdSelect = ""  # Select clause
-  _primaryIdFormat = "__gnue__ = '%s'"         # Where clause format
-
   conditionElements = {
        'add':             (2, 999, '(%s)',                   '+'       ),
        'sub':             (2, 999, '(%s)',                   '-'       ),
@@ -116,12 +104,7 @@
     # in the same order used in the SELECT statement.
     self._fieldOrder = []
 
-    # Internal flag to avoid consistently doing the same check
-    # If this is set to 1 initially, then the
-    self._primaryIdChecked = False  # Internal flag
 
-
-
   def _toSqlString(self, value):
     if isinstance (value, mx.DateTime.DateTimeType):
       if (value.year, value.month, value.day) == (1, 1, 1):
@@ -175,17 +158,9 @@
                                        "%s'" % self._escapeSingleQuote)
 
 
-  # Used by drivers with a unique id (like rowid) (see Oracle for example)
-  def _checkForPrimaryId(self):
-    self._primaryIdChecked = True
-
-
   def _createResultSet(self, conditions={}, readOnly=False,
                        masterRecordSet=None,sql=""):
 
-    # Used by drivers with a unique id (like rowid)
-    if not self._primaryIdChecked: self._checkForPrimaryId()
-
     try:
       query = self._buildQuery(conditions, additionalSQL = sql)
       cursor = self._connection.makecursor(query)
@@ -309,11 +284,6 @@
     else:
       distinct = ""
 
-    if self._primaryIdSelect:
-      pis = "%s," % self._primaryIdSelect
-    else:
-      pis = ""
-
     whereClause = self._conditionToSQL(conditions)
     if additionalSQL:
       if len(whereClause):
@@ -328,14 +298,11 @@
                       self.table, whereClause)
     elif self._fieldReferences:
       self._fieldOrder = fields = self._fieldReferences.keys()
-      q = "SELECT %s%s%s FROM %s%s" % \
-           (distinct, pis, join(fields,","), self.table,
+      q = "SELECT %s%s FROM %s%s" % \
+           (distinct, join(fields,","), self.table,
             whereClause)
-      if pis:
-        self._fieldOrder.insert(0,None)
     else:
       self._fieldOrder = []
-      self._primaryIdSelect = None
       q = "SELECT %s* FROM %s%s" % (distinct, self.table,
                         whereClause)
 

Modified: trunk/gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py       
2005-03-20 14:24:43 UTC (rev 7235)
+++ trunk/gnue-common/src/datasources/drivers/DBSIG2/ResultSet.py       
2005-03-21 00:09:16 UTC (rev 7236)
@@ -102,8 +102,10 @@
                   name = string.lower(self._fieldNames[i])
               dict[name] = f
               i += 1
-            self._cachedRecords.append (self._recordSetClass(parent=self,
-                                                             initialData=dict))
+            self._cachedRecords.append (self._recordSetClass (parent = self,
+                initialData = dict,
+                rowidField = self._dataObject._dataSource._rowidField,
+                primarykeyFields = 
self._dataObject._dataSource._primarykeyFields))
           else:
             return False
         return True

Modified: 
trunk/gnue-common/src/datasources/drivers/adodbapi/adodbapi/DataObject.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/adodbapi/adodbapi/DataObject.py   
2005-03-20 14:24:43 UTC (rev 7235)
+++ trunk/gnue-common/src/datasources/drivers/adodbapi/adodbapi/DataObject.py   
2005-03-21 00:09:16 UTC (rev 7236)
@@ -38,9 +38,6 @@
 
   def _createResultSet(self, conditions={}, readOnly=0, 
masterRecordSet=None,sql=""):
 
-    # Used by drivers with a unique id (like rowid)
-    if not self._primaryIdChecked: self._checkForPrimaryId()
-
     try:
       cursor = self._dataConnection.cursor()
 

Modified: 
trunk/gnue-common/src/datasources/drivers/appserver/appserver/DataObject.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/appserver/appserver/DataObject.py 
2005-03-20 14:24:43 UTC (rev 7235)
+++ trunk/gnue-common/src/datasources/drivers/appserver/appserver/DataObject.py 
2005-03-21 00:09:16 UTC (rev 7236)
@@ -42,9 +42,6 @@
   # This is actually never used
   _resultSetClass = ResultSet.ResultSet
 
-  # Our primary key is always the gnue_id
-  _primaryIdField = 'gnue_id'
-
   # ---------------------------------------------------------------------------
   # Build query in prefix notation
   # ---------------------------------------------------------------------------

Modified: 
trunk/gnue-common/src/datasources/drivers/appserver/appserver/ResultSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/appserver/appserver/ResultSet.py  
2005-03-20 14:24:43 UTC (rev 7235)
+++ trunk/gnue-common/src/datasources/drivers/appserver/appserver/ResultSet.py  
2005-03-21 00:09:16 UTC (rev 7236)
@@ -87,7 +87,8 @@
         dict [fieldName] = record [j]
         j += 1
 
-      r = self._recordSetClass (parent = self, initialData = dict)
+      r = self._recordSetClass (parent = self, initialData = dict,
+          primarykeyFields = ['gnue_id'])
       self._cachedRecords.append (r)
 
     return True

Modified: 
trunk/gnue-common/src/datasources/drivers/interbase/interbase/DataObject.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/interbase/interbase/DataObject.py 
2005-03-20 14:24:43 UTC (rev 7235)
+++ trunk/gnue-common/src/datasources/drivers/interbase/interbase/DataObject.py 
2005-03-21 00:09:16 UTC (rev 7236)
@@ -50,10 +50,6 @@
   def _createResultSet (self, conditions = {}, readOnly = 0,
                         masterRecordSet = None, sql = ""):
 
-    # Used by drivers with a unique id (like rowid)
-    if not self._primaryIdChecked:
-      self._checkForPrimaryId()
-
     try:
       query = self._buildQuery (conditions, additionalSQL = sql)
       cursor = self._connection.makecursor (query)

Modified: trunk/gnue-common/src/datasources/drivers/oracle/Base/DataObject.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/oracle/Base/DataObject.py 
2005-03-20 14:24:43 UTC (rev 7235)
+++ trunk/gnue-common/src/datasources/drivers/oracle/Base/DataObject.py 
2005-03-21 00:09:16 UTC (rev 7236)
@@ -38,27 +38,7 @@
 class _Base:
   _escapeSingleQuote = '\'\''
   _dateTimeFormat = "'%Y-%m-%d %H:%M:%S'"
-  _primaryIdChecked = False
 
-  def _checkForPrimaryId(self):
-
-    self._primaryIdChecked = True
-    return # TODO: This is broken :(
-
-    try:
-      statement =  "select rowidtochar(rowid) from %s where 1=2" % self.table
-      cursor = self._connection.native.cursor()
-      cursor.execute(str(statement))
-      cursor.close()
-
-      self._primaryIdSelect = "ROWIDTOCHAR(ROWID) as GNUE__ROWID__"
-      self._primaryIdField = "gnue__rowid__"  # Keep this lowercase!!!
-      self._primaryIdFormat = "ROWID = CHARTOROWID('%s')"
-      gDebug(9,'View %s is using ROWID identifier' % self.table)
-
-    except self._DatabaseError:
-      gDebug (1, 'View %s has no internal ROWID' % self.table)
-
 class DataObject_SQL(_Base, DBSIG2.DataObject_SQL):
   pass
 

Modified: 
trunk/gnue-common/src/datasources/drivers/postgresql/Base/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/postgresql/Base/Connection.py     
2005-03-20 14:24:43 UTC (rev 7235)
+++ trunk/gnue-common/src/datasources/drivers/postgresql/Base/Connection.py     
2005-03-21 00:09:16 UTC (rev 7236)
@@ -45,7 +45,9 @@
   supportedDataObjects = {'object': DataObject.DataObject_Object,
                           'sql':    DataObject.DataObject_SQL}
 
+  _rowidField = 'oid'
 
+
   # ---------------------------------------------------------------------------
   # Constructor
   # ---------------------------------------------------------------------------
@@ -98,7 +100,7 @@
     # ROLLBACK.
 
     if self._pg_encoding not in ['', 'DEFAULT']:
-      self.sql ("SET CLIENT_ENCODING TO '%s'" % self._pg_encoding)
+      self.sql0 ("SET CLIENT_ENCODING TO '%s'" % self._pg_encoding)
 
 
   # ---------------------------------------------------------------------------





reply via email to

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