self.cursor.execute("SELECT @@identity AS lastrowid")
row = self.cursor.fetchall()[0] # fetchall() ensures the cursor is consumed without closing it
self._lastrowid = int(row[0])
-
- if self._enable_identity_insert:
- self.cursor.execute("SET IDENTITY_INSERT %s OFF" % self.dialect.identifier_preparer.format_table(self.compiled.statement.table))
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 get_lastrowid(self):
return self._lastrowid
class MSDialect_pyodbc(PyODBCConnector, MSDialect):
- supports_sane_rowcount = False
+ supports_sane_rowcount = True
supports_sane_multi_rowcount = False
execution_ctx_cls = MSExecutionContext_pyodbc
tbl.drop()
con.execute('drop schema paj')
+ def test_returning_no_autoinc(self):
+ meta = MetaData(testing.db)
+
+ table = Table('t1', meta, Column('id', Integer, primary_key=True), Column('data', String(50)))
+ table.create()
+ try:
+ result = table.insert().values(id=1, data=func.lower("SomeString")).returning(table.c.id, table.c.data).execute()
+ eq_(result.fetchall(), [(1, 'somestring',)])
+ finally:
+ # this will hang if the "SET IDENTITY_INSERT t1 OFF" occurs before the
+ # result is fetched
+ table.drop()
+
def test_delete_schema(self):
meta = MetaData(testing.db)
con = testing.db.connect()
not testing.db.dialect.implicit_returning))
def test_empty_insert(self):
"""test that execute() interprets [] as a list with no params"""
+
result = testing.db.execute(users.insert().values(user_name=bindparam('name')), [])
- eq_(result.rowcount, 1)
+ eq_(testing.db.execute(users.select()).fetchall(), [
+ (1, None)
+ ])
class ProxyConnectionTest(TestBase):
@testing.fails_on('firebird', 'Data type unknown')
break
for engine in (
- engines.testing_engine(options=dict(proxy=MyProxy())),
- engines.testing_engine(options=dict(proxy=MyProxy(), strategy='threadlocal'))
+ engines.testing_engine(options=dict(implicit_returning=False, proxy=MyProxy())),
+ engines.testing_engine(options=dict(implicit_returning=False, proxy=MyProxy(), strategy='threadlocal'))
):
m = MetaData(engine)
t1.insert().execute(c1=6)
assert engine.execute("select * from t1").fetchall() == [(5, 'some data'), (6, 'foo')]
finally:
+ pass
m.drop_all()
engine.dispose()
result3 = table.insert().returning(table.c.id).execute({'persons': 4, 'full': False})
eq_([dict(row) for row in result3], [{'id': 4}])
-
+
+
@testing.exclude('firebird', '<', (2, 1), '2.1+ feature')
@testing.exclude('postgresql', '<', (8, 2), '8.3+ feature')
@testing.fails_on_everything_except('postgresql', 'firebird')