From bbebcdf8f526226d2d64a91dfc306086fc9873f4 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 28 Oct 2007 21:28:53 +0000 Subject: - fixed INSERT statements w.r.t. primary key columns that have SQL-expression based default generators on them; SQL expression executes inline as normal but will not trigger a "postfetch" condition for the column, for those DB's who provide it via cursor.lastrowid --- lib/sqlalchemy/sql/compiler.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index e662f8e99..43b6fb15b 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -664,8 +664,7 @@ class DefaultCompiler(engine.Compiled, visitors.ClauseVisitor): values.append((c, value)) elif isinstance(c, schema.Column): if self.isinsert: - if (c.primary_key and self.dialect.preexecute_pk_sequences - and not self.inline): + if (c.primary_key and self.dialect.preexecute_pk_sequences and not self.inline): if (((isinstance(c.default, schema.Sequence) and not c.default.optional) or not self.dialect.supports_pk_autoincrement) or @@ -676,17 +675,21 @@ class DefaultCompiler(engine.Compiled, visitors.ClauseVisitor): elif isinstance(c.default, schema.ColumnDefault): if isinstance(c.default.arg, sql.ClauseElement): values.append((c, self.process(c.default.arg.self_group()))) - self.postfetch.add(c) + if not c.primary_key: + # dont add primary key column to postfetch + self.postfetch.add(c) else: values.append((c, create_bind_param(c, None))) self.prefetch.add(c) elif isinstance(c.default, schema.PassiveDefault): - self.postfetch.add(c) + if not c.primary_key: + self.postfetch.add(c) elif isinstance(c.default, schema.Sequence): proc = self.process(c.default) if proc is not None: values.append((c, proc)) - self.postfetch.add(c) + if not c.primary_key: + self.postfetch.add(c) elif self.isupdate: if isinstance(c.onupdate, schema.ColumnDefault): if isinstance(c.onupdate.arg, sql.ClauseElement): -- cgit v1.2.1