From 2a052cd59327adfac9b68a806a2abb6b2865245f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 11 Jun 2007 22:39:03 +0000 Subject: [PATCH] - result.last_inserted_ids() should return a list that is identically sized to the primary key constraint of the table. values that were "passively" created and not available via cursor.lastrowid will be None. --- CHANGES | 3 +++ lib/sqlalchemy/databases/mysql.py | 2 +- lib/sqlalchemy/databases/sqlite.py | 2 +- lib/sqlalchemy/engine/default.py | 9 +++------ 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index 1c2cc8d604..dab2fd67aa 100644 --- a/CHANGES +++ b/CHANGES @@ -28,6 +28,9 @@ - added undefer_group() MapperOption, sets a set of "deferred" columns joined by a "group" to load as "undeferred". - sql + - result.last_inserted_ids() should return a list that is identically + sized to the primary key constraint of the table. values that were + "passively" created and not available via cursor.lastrowid will be None. - long-identifier detection fixed to use > rather than >= for max ident length [ticket:589] - fixed bug where selectable.corresponding_column(selectable.c.col) diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py index db03ce04a7..8b4b89d508 100644 --- a/lib/sqlalchemy/databases/mysql.py +++ b/lib/sqlalchemy/databases/mysql.py @@ -951,7 +951,7 @@ def descriptor(): class MySQLExecutionContext(default.DefaultExecutionContext): def post_exec(self): if self.compiled.isinsert: - self._last_inserted_ids = [self.cursor.lastrowid] + self._last_inserted_ids = [self.cursor.lastrowid] + self._last_inserted_ids[1:] class MySQLDialect(ansisql.ANSIDialect): def __init__(self, **kwargs): diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py index 1876305235..425009f6dc 100644 --- a/lib/sqlalchemy/databases/sqlite.py +++ b/lib/sqlalchemy/databases/sqlite.py @@ -139,7 +139,7 @@ def descriptor(): class SQLiteExecutionContext(default.DefaultExecutionContext): def post_exec(self): if self.compiled.isinsert: - self._last_inserted_ids = [self.cursor.lastrowid] + self._last_inserted_ids = [self.cursor.lastrowid] + self._last_inserted_ids[1:] super(SQLiteExecutionContext, self).post_exec() class SQLiteDialect(ansisql.ANSIDialect): diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index 976da1a73b..19dd623bfe 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -291,7 +291,7 @@ class DefaultExecutionContext(base.ExecutionContext): if c in self.compiled.inline_params: self._lastrow_has_defaults = True if c.primary_key: - need_lastrowid = True + last_inserted_ids.append(None) # check if its not present at all. see if theres a default # and fire it off, and add to bind parameters. if # its a pk, add the value to our last_inserted_ids list, @@ -306,15 +306,12 @@ class DefaultExecutionContext(base.ExecutionContext): if c.primary_key: last_inserted_ids.append(param.get_processed(c.key)) elif c.primary_key: - need_lastrowid = True + last_inserted_ids.append(None) # its an explicitly passed pk value - add it to # our last_inserted_ids list. elif c.primary_key: last_inserted_ids.append(param.get_processed(c.key)) - if need_lastrowid: - self._last_inserted_ids = None - else: - self._last_inserted_ids = last_inserted_ids + self._last_inserted_ids = last_inserted_ids self._last_inserted_params = param elif self.compiled.isupdate: if isinstance(self.compiled_parameters, list): -- 2.47.3