if (self.isinsert or self.isupdate or self.isdelete) and self.compiled.returning:
self._result_proxy = base.FullyBufferedResultProxy(self)
-
+
if self._enable_identity_insert:
self.cursor.execute("SET IDENTITY_INSERT %s OFF" % self.dialect.identifier_preparer.format_table(self.compiled.statement.table))
def __execute_context(self, context):
if context.compiled:
context.pre_exec()
+
if context.executemany:
self._cursor_executemany(context.cursor, context.statement, context.parameters, context=context)
else:
return self.cursor.description
def _autoclose(self):
- if self._metadata is None:
+ if self.context.isinsert:
+ if self.context._is_implicit_returning:
+ self.context._fetch_implicit_returning(self)
+ self.close()
+ elif not self.context._is_explicit_returning:
+ self.close()
+ elif self._metadata is None:
# no results, get rowcount
# (which requires open cursor on some DB's such as firebird),
self.rowcount
self.close() # autoclose
- elif self.context.isinsert and \
- not self.context.executemany and \
- not self.context._is_explicit_returning:
- # an insert, no explicit returning(), may need
- # to fetch rows which were created via implicit
- # returning, then close
- self.context._fetch_implicit_returning(self)
- self.close()
return self
+
def _init_metadata(self):
self._metadata = metadata = self._cursor_description()
def _is_explicit_returning(self):
return self.compiled and \
getattr(self.compiled.statement, '_returning', False)
-
+
+ @util.memoized_property
+ def _is_implicit_returning(self):
+ return self.compiled and \
+ bool(self.compiled.returning) and \
+ not self.compiled.statement._returning
+
@property
def connection(self):
return self._connection._branch()
]
def _fetch_implicit_returning(self, resultproxy):
-
- if self.dialect.implicit_returning and \
- not self.compiled.statement._returning and \
- not resultproxy.closed:
-
- table = self.compiled.statement.table
- row = resultproxy.first()
+ table = self.compiled.statement.table
+ row = resultproxy.first()
- self._inserted_primary_key = [v is not None and v or row[c]
- for c, v in zip(table.primary_key, self._inserted_primary_key)
- ]
+ self._inserted_primary_key = [v is not None and v or row[c]
+ for c, v in zip(table.primary_key, self._inserted_primary_key)
+ ]
def last_inserted_params(self):
return self._last_inserted_params
metadata.create_all()
- ins = table.insert(values={'data':bindparam('x')}).compile()
+ ins = table.insert(inline=True, values={'data':bindparam('x')}).compile()
ins.execute({'x':"five"}, {'x':"seven"})
assert table.select().execute().fetchall() == [(1, 'five'), (2, 'seven')]