[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r7243 - trunk/gnue-common/src/datasources/drivers/Base
From: |
reinhard |
Subject: |
[gnue] r7243 - trunk/gnue-common/src/datasources/drivers/Base |
Date: |
Mon, 21 Mar 2005 11:17:08 -0600 (CST) |
Author: reinhard
Date: 2005-03-21 11:17:07 -0600 (Mon, 21 Mar 2005)
New Revision: 7243
Modified:
trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
Log:
Requery master before posting any details in case a backend side trigger
changed any of the primary key fields.
Modified: trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-03-21
15:53:35 UTC (rev 7242)
+++ trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-03-21
17:17:07 UTC (rev 7243)
@@ -107,7 +107,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.
@@ -328,6 +328,23 @@
# ---------------------------------------------------------------------------
+ # Requery this record
+ # ---------------------------------------------------------------------------
+
+ def __requery (self):
+
+ do = self._parent._dataObject
+
+ 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
# ---------------------------------------------------------------------------
@@ -391,16 +408,25 @@
self._postChanges (recordNumber)
# Post all detail records
- 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])
+ if self._cachedDetailResultSets:
- child.post (foreign_keys = fk)
+ # 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.
+ self.__requery ()
+ 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
# ---------------------------------------------------------------------------
@@ -411,24 +437,14 @@
This method may not be called if the record has unsaved changes; they would
get lost!
-
- This method does nothing if no primary key is available.
"""
- do = self._parent._dataObject
-
# Requery detail resultsets
for child in (self._cachedDetailResultSets.values ()):
child.requery ()
# Now requery ourselves
- 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)
+ self.__requery ()
# ---------------------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r7243 - trunk/gnue-common/src/datasources/drivers/Base,
reinhard <=