From 66e5de30f2e01593182058091075780b41411a78 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 10 Dec 2010 21:38:46 -0500 Subject: - initial stab at using executemany() for inserts in the ORM when possible --- lib/sqlalchemy/engine/base.py | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) (limited to 'lib/sqlalchemy/engine/base.py') diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index dad075b34..4a00ebda2 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -629,24 +629,6 @@ class ExecutionContext(object): raise NotImplementedError() - def last_inserted_params(self): - """Return a dictionary of the full parameter dictionary for the last - compiled INSERT statement. - - Includes any ColumnDefaults or Sequences that were pre-executed. - """ - - raise NotImplementedError() - - def last_updated_params(self): - """Return a dictionary of the full parameter dictionary for the last - compiled UPDATE statement. - - Includes any ColumnDefaults that were pre-executed. - """ - - raise NotImplementedError() - def lastrow_has_defaults(self): """Return True if the last INSERT or UPDATE row contained inlined or database-side defaults. @@ -2466,13 +2448,6 @@ class ResultProxy(object): did not explicitly specify returning(). """ - if not self.context.isinsert: - raise exc.InvalidRequestError( - "Statement is not an insert() expression construct.") - elif self.context._is_explicit_returning: - raise exc.InvalidRequestError( - "Can't call inserted_primary_key when returning() " - "is used.") return self.context._inserted_primary_key @@ -2481,15 +2456,15 @@ class ResultProxy(object): """Return the primary key for the row just inserted.""" return self.inserted_primary_key - + def last_updated_params(self): """Return ``last_updated_params()`` from the underlying ExecutionContext. See ExecutionContext for details. """ - - return self.context.last_updated_params() + + return self.context.last_updated_params def last_inserted_params(self): """Return ``last_inserted_params()`` from the underlying @@ -2498,7 +2473,7 @@ class ResultProxy(object): See ExecutionContext for details. """ - return self.context.last_inserted_params() + return self.context.last_inserted_params def lastrow_has_defaults(self): """Return ``lastrow_has_defaults()`` from the underlying -- cgit v1.2.1 From 9c0755640c5f1d45596ff7234d2d42f1c92d09e0 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 11 Dec 2010 03:05:03 -0500 Subject: - clean up the batch insert thing - add a test for batch inserts - don't need elaborate _inserted_primary_key thing - take some cruft out of ExecutionContext, ResultProxy, EC members can be non-underscored, have mapper just call the EC members for now. - simplify "connection_callable", no need for a "flush_opts" dictionary since this point of expansion is not needed --- lib/sqlalchemy/engine/base.py | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'lib/sqlalchemy/engine/base.py') diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 4a00ebda2..d58460fb8 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -2448,8 +2448,16 @@ class ResultProxy(object): did not explicitly specify returning(). """ + + if not self.context.isinsert: + raise exc.InvalidRequestError( + "Statement is not an insert() expression construct.") + elif self.context._is_explicit_returning: + raise exc.InvalidRequestError( + "Can't call inserted_primary_key when returning() " + "is used.") - return self.context._inserted_primary_key + return self.context.inserted_primary_key @util.deprecated("0.6", "Use :attr:`.ResultProxy.inserted_primary_key`") def last_inserted_ids(self): @@ -2458,22 +2466,24 @@ class ResultProxy(object): return self.inserted_primary_key def last_updated_params(self): - """Return ``last_updated_params()`` from the underlying - ExecutionContext. - - See ExecutionContext for details. - """ + """Return the collection of updated parameters from this + execution. - return self.context.last_updated_params + """ + if self.context.executemany: + return self.context.compiled_parameters + else: + return self.context.compiled_parameters[0] def last_inserted_params(self): - """Return ``last_inserted_params()`` from the underlying - ExecutionContext. - - See ExecutionContext for details. + """Return the collection of inserted parameters from this + execution. + """ - - return self.context.last_inserted_params + if self.context.executemany: + return self.context.compiled_parameters + else: + return self.context.compiled_parameters[0] def lastrow_has_defaults(self): """Return ``lastrow_has_defaults()`` from the underlying -- cgit v1.2.1