diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-01-15 16:42:29 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-01-15 16:42:29 -0500 |
commit | dff5a404e489d5215da5aa30870b78aca8423de5 (patch) | |
tree | 39f6ae1949762d269f6a73e0315f0fa6910ceacd /lib/sqlalchemy/engine | |
parent | fc0ffac24155931c2db10d1a469e1f7898268e45 (diff) | |
download | sqlalchemy-dff5a404e489d5215da5aa30870b78aca8423de5.tar.gz |
- getting slightly more consistent behavior for the edge case of pk columns
with server default - autoincrement is now false with any server_default,
so these all return None, applies consistency to [ticket:2020], [ticket:2021].
if prefetch is desired a "default" should be used instead of server_default.
Diffstat (limited to 'lib/sqlalchemy/engine')
-rw-r--r-- | lib/sqlalchemy/engine/base.py | 20 | ||||
-rw-r--r-- | lib/sqlalchemy/engine/default.py | 5 | ||||
-rw-r--r-- | lib/sqlalchemy/engine/reflection.py | 6 |
3 files changed, 25 insertions, 6 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 3bdcad2ac..9eb1b8b40 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -2460,9 +2460,23 @@ class ResultProxy(object): @util.memoized_property def inserted_primary_key(self): """Return the primary key for the row just inserted. - - This only applies to single row insert() constructs which - did not explicitly specify returning(). + + The return value is a list of scalar values + corresponding to the list of primary key columns + in the target table. + + This only applies to single row :func:`.insert` + constructs which did not explicitly specify + :meth:`.Insert.returning`. + + Note that primary key columns which specify a + server_default clause, + or otherwise do not qualify as "autoincrement" + columns (see the notes at :class:`.Column`), and were + generated using the database-side default, will + appear in this list as ``None`` unless the backend + supports "returning" and the insert statement executed + with the "implicit returning" enabled. """ diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index e21ec1c40..da6ed12a6 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -101,7 +101,7 @@ class DefaultDialect(base.Dialect): if not getattr(self, 'ported_sqla_06', True): util.warn( - "The %s dialect is not yet ported to SQLAlchemy 0.6" % + "The %s dialect is not yet ported to SQLAlchemy 0.6/0.7" % self.name) self.convert_unicode = convert_unicode @@ -625,7 +625,8 @@ class DefaultExecutionContext(base.ExecutionContext): return self.dialect.supports_sane_multi_rowcount def post_insert(self): - if self.dialect.postfetch_lastrowid and \ + if not self._is_implicit_returning and \ + self.dialect.postfetch_lastrowid and \ (not self.inserted_primary_key or \ None in self.inserted_primary_key): diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py index cf254cba6..00b2fd1bf 100644 --- a/lib/sqlalchemy/engine/reflection.py +++ b/lib/sqlalchemy/engine/reflection.py @@ -398,7 +398,11 @@ class Inspector(object): if col_d.get('default') is not None: # the "default" value is assumed to be a literal SQL expression, # so is wrapped in text() so that no quoting occurs on re-issuance. - colargs.append(sa_schema.DefaultClause(sql.text(col_d['default']))) + colargs.append( + sa_schema.DefaultClause( + sql.text(col_d['default']), _reflected=True + ) + ) if 'sequence' in col_d: # TODO: mssql, maxdb and sybase are using this. |