[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r7248 - trunk/gnue-common/src/datasources/drivers/Base
From: |
reinhard |
Subject: |
[gnue] r7248 - trunk/gnue-common/src/datasources/drivers/Base |
Date: |
Mon, 21 Mar 2005 15:50:05 -0600 (CST) |
Author: reinhard
Date: 2005-03-21 15:50:04 -0600 (Mon, 21 Mar 2005)
New Revision: 7248
Modified:
trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
Log:
When requerying the master before posting the details (to update generated
primary keys), only requery those fields needed for details, and only requery
for newly inserted masters.
Modified: trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-03-21
19:18:46 UTC (rev 7247)
+++ trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-03-21
21:50:04 UTC (rev 7248)
@@ -64,6 +64,10 @@
# The detail ResultSets where this record is the master
self._cachedDetailResultSets = {}
+ # All field names that are used to link detail records (i.e. all fieldnames
+ # that appear as masterfield in any of my detail result sets)
+ self.__detailLinkFlags = {}
+
# Dictionary with field:value pairs of initial data
self._initialData = initialData
@@ -107,7 +111,7 @@
break
if primarykeyIsComplete:
self._initialData = self._fields.copy ()
- self.__requery ()
+ 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.
@@ -331,19 +335,15 @@
# Requery this record
# ---------------------------------------------------------------------------
- def __requery (self):
+ def __requery (self, fields):
do = self._parent._dataObject
+ newfields = do._connection.requery (do.table, self.__wherefields (),
+ fields)
+ self._initialData.update (newfields)
+ self._fields.update (newfields)
- 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 (),
- fields)
- self._initialData.update (newfields)
- self._fields.update (newfields)
-
# ---------------------------------------------------------------------------
# Post changes to database
# ---------------------------------------------------------------------------
@@ -408,26 +408,16 @@
self._postChanges (recordNumber)
# Post all detail records
- if self._cachedDetailResultSets:
+ for child in (self._cachedDetailResultSets.values ()):
+ do = child._dataObject
+ # Set the primary key for any new child records
+ fk = {}
+ for i in range(len(do._masterfields)):
+ fk[do._detailfields[i]] = self.getField(do._masterfields[i])
- # First, requery the master record because some backend side trigger code
- # could have changed the primary key. We will have to requery again after
- # the commit, as the detail posts and the commit could change stuff, too.
- # FIXME: actually, we wouldn't have to requery the complete record, but
- # only the fields used as masterfields for any of the details.
- if self.__rowidField:
- self.__requery ()
+ child.post (foreign_keys = fk)
- for child in (self._cachedDetailResultSets.values ()):
- do = child._dataObject
- # Set the primary key for any new child records
- fk = {}
- for i in range(len(do._masterfields)):
- fk[do._detailfields[i]] = self.getField(do._masterfields[i])
- child.post (foreign_keys = fk)
-
-
# ---------------------------------------------------------------------------
# Requery the record data from the backend
# ---------------------------------------------------------------------------
@@ -447,7 +437,10 @@
# Now requery ourselves
ds = self._parent._dataObject._dataSource
if ds and ds.requery:
- self.__requery ()
+ if self.__rowidField or self.__primarykeyFields:
+ fields = [field for field in self._fields.keys ()
+ if self._parent.isFieldBound (field)]
+ self.__requery (fields)
# ---------------------------------------------------------------------------
@@ -528,6 +521,8 @@
@param resultSet: the ResultSet object to add
"""
self._cachedDetailResultSets [resultSet._dataObject] = resultSet
+ for field in resultSet._dataObject._masterfields:
+ self.__detailLinkFlags [field.lower ()] = True
# ---------------------------------------------------------------------------
@@ -600,6 +595,12 @@
rowid = do._connection.insert (do.table, modifiedFields, recno)
if self.__rowidField:
self._fields [self.__rowidField] = rowid
+ self._initialData [self.__rowidField] = rowid
+ # Requery all the fields that are important for inserting details.
+ # A backend trigger could have e.g. generated a primary key.
+ if self.__detailLinkFlags:
+ self.__requery (self.__detailLinkFlags.keys ())
+
else:
do._connection.update (do.table, self.__wherefields (), modifiedFields,
recno)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r7248 - trunk/gnue-common/src/datasources/drivers/Base,
reinhard <=