summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-07-27 18:57:02 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-07-27 18:57:02 +0000
commit2f8ebfef1d096dd5e012ca67b775cfde8778ba13 (patch)
tree7da9875174e57af2ee8d4b73142e040c40171d77 /lib/sqlalchemy/engine
parent8db97dad9845b8d405412abbf713d2d22538b9cc (diff)
downloadsqlalchemy-2f8ebfef1d096dd5e012ca67b775cfde8778ba13.tar.gz
- clarified LoaderStrategy implementations, centralized deferred column loading
into DeferredColumnLoader (i.e. deferred polymorphic loader) - added generic deferred_load(instance, props) method, will set up "deferred" or "lazy" loads across a set of properties. - mapper post-fetch now uses all deferreds, no more post-selects inside a flush() [ticket:652]
Diffstat (limited to 'lib/sqlalchemy/engine')
-rw-r--r--lib/sqlalchemy/engine/base.py12
-rw-r--r--lib/sqlalchemy/engine/default.py22
2 files changed, 25 insertions, 9 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py
index fc4433a47..ca602b58c 100644
--- a/lib/sqlalchemy/engine/base.py
+++ b/lib/sqlalchemy/engine/base.py
@@ -300,6 +300,11 @@ class ExecutionContext(object):
(i.e. dict or list of dicts for non positional,
list or list of lists/tuples for positional).
+ isinsert
+ True if the statement is an INSERT
+
+ isupdate
+ True if the statement is an UPDATE
The Dialect should provide an ExecutionContext via the
create_execution_context() method. The `pre_exec` and `post_exec`
@@ -388,6 +393,12 @@ class ExecutionContext(object):
raise NotImplementedError()
+ def postfetch_cols(self):
+ """return a list of Column objects for which a 'passive' server-side default
+ value was fired off"""
+
+ raise NotImplementedError()
+
class Compiled(object):
"""Represent a compiled SQL expression.
@@ -1215,6 +1226,7 @@ class ResultProxy(object):
return self.context.lastrow_has_defaults()
+
def supports_sane_rowcount(self):
"""Return ``supports_sane_rowcount()`` from the underlying ExecutionContext.
diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py
index 962e2ab60..a2e159639 100644
--- a/lib/sqlalchemy/engine/default.py
+++ b/lib/sqlalchemy/engine/default.py
@@ -6,7 +6,7 @@
"""Provide default implementations of per-dialect sqlalchemy.engine classes"""
-from sqlalchemy import schema, exceptions, sql, types
+from sqlalchemy import schema, exceptions, sql, types, util
import sys, re
from sqlalchemy.engine import base
@@ -147,6 +147,7 @@ class DefaultExecutionContext(base.ExecutionContext):
self.dialect = dialect
self.connection = connection
self.compiled = compiled
+ self._postfetch_cols = util.Set()
if compiled is not None:
self.typemap = compiled.typemap
@@ -173,6 +174,8 @@ class DefaultExecutionContext(base.ExecutionContext):
self.cursor = self.create_cursor()
engine = property(lambda s:s.connection.engine)
+ isinsert = property(lambda s:s.compiled and s.compiled.isinsert)
+ isupdate = property(lambda s:s.compiled and s.compiled.isupdate)
def __encode_param_keys(self, params):
"""apply string encoding to the keys of dictionary-based bind parameters"""
@@ -255,8 +258,11 @@ class DefaultExecutionContext(base.ExecutionContext):
return self._last_updated_params
def lastrow_has_defaults(self):
- return self._lastrow_has_defaults
+ return len(self._postfetch_cols)
+ def postfetch_cols(self):
+ return self._postfetch_cols
+
def set_input_sizes(self):
"""Given a cursor and ClauseParameters, call the appropriate
style of ``setinputsizes()`` on the cursor, using DBAPI types
@@ -291,13 +297,12 @@ class DefaultExecutionContext(base.ExecutionContext):
and generate last_inserted_ids() collection."""
# TODO: cleanup
- if self.compiled.isinsert:
+ if self.isinsert:
if isinstance(self.compiled_parameters, list):
plist = self.compiled_parameters
else:
plist = [self.compiled_parameters]
drunner = self.dialect.defaultrunner(self)
- self._lastrow_has_defaults = False
for param in plist:
last_inserted_ids = []
# check the "default" status of each column in the table
@@ -305,7 +310,7 @@ class DefaultExecutionContext(base.ExecutionContext):
# check if it will be populated by a SQL clause - we'll need that
# after execution.
if c in self.compiled.inline_params:
- self._lastrow_has_defaults = True
+ self._postfetch_cols.add(c)
if c.primary_key:
last_inserted_ids.append(None)
# check if its not present at all. see if theres a default
@@ -315,7 +320,7 @@ class DefaultExecutionContext(base.ExecutionContext):
# the SQL-generated value after execution.
elif not c.key in param or param.get_original(c.key) is None:
if isinstance(c.default, schema.PassiveDefault):
- self._lastrow_has_defaults = True
+ self._postfetch_cols.add(c)
newid = drunner.get_column_default(c)
if newid is not None:
param.set_value(c.key, newid)
@@ -331,20 +336,19 @@ class DefaultExecutionContext(base.ExecutionContext):
# here (hard to do since lastrowid doesnt support it either)
self._last_inserted_ids = last_inserted_ids
self._last_inserted_params = param
- elif self.compiled.isupdate:
+ elif self.isupdate:
if isinstance(self.compiled_parameters, list):
plist = self.compiled_parameters
else:
plist = [self.compiled_parameters]
drunner = self.dialect.defaultrunner(self)
- self._lastrow_has_defaults = False
for param in plist:
# check the "onupdate" status of each column in the table
for c in self.compiled.statement.table.c:
# it will be populated by a SQL clause - we'll need that
# after execution.
if c in self.compiled.inline_params:
- pass
+ self._postfetch_cols.add(c)
# its not in the bind parameters, and theres an "onupdate" defined for the column;
# execute it and add to bind params
elif c.onupdate is not None and (not c.key in param or param.get_original(c.key) is None):