from sqlalchemy import testing
from sqlalchemy.testing.schema import Table, Column
from sqlalchemy.types import TypeDecorator
-from sqlalchemy.testing import fixtures, AssertsExecutionResults, engines
+from sqlalchemy.testing import fixtures, AssertsExecutionResults, engines, \
+ assert_raises_message
+from sqlalchemy import exc as sa_exc
class ReturningTest(fixtures.TestBase, AssertsExecutionResults):
__requires__ = 'returning',
def teardown(self):
table.drop()
- @testing.exclude('firebird', '<', (2, 0), '2.0+ feature')
- @testing.exclude('postgresql', '<', (8, 2), '8.2+ feature')
def test_column_targeting(self):
result = table.insert().returning(table.c.id, table.c.full).execute({'persons': 1, 'full': False})
eq_(row['goofy'], "FOOsomegoofyBAR")
@testing.fails_on('firebird', "fb can't handle returning x AS y")
- @testing.exclude('firebird', '<', (2, 0), '2.0+ feature')
- @testing.exclude('postgresql', '<', (8, 2), '8.2+ feature')
def test_labeling(self):
result = table.insert().values(persons=6).\
returning(table.c.persons.label('lala')).execute()
@testing.fails_on('firebird', "fb/kintersbasdb can't handle the bind params")
@testing.fails_on('oracle+zxjdbc', "JDBC driver bug")
- @testing.exclude('firebird', '<', (2, 0), '2.0+ feature')
- @testing.exclude('postgresql', '<', (8, 2), '8.2+ feature')
def test_anon_expressions(self):
result = table.insert().values(goofy="someOTHERgoofy").\
returning(func.lower(table.c.goofy, type_=GoofyType)).execute()
row = result.first()
eq_(row[0], 30)
- @testing.exclude('firebird', '<', (2, 1), '2.1+ feature')
- @testing.exclude('postgresql', '<', (8, 2), '8.2+ feature')
def test_update_returning(self):
table.insert().execute([{'persons': 5, 'full': False}, {'persons': 3, 'full': False}])
eq_(result.fetchall(), [(1,)])
result2 = select([table.c.id, table.c.full]).order_by(table.c.id).execute()
- eq_(result2.fetchall(), [(1,True),(2,False)])
+ eq_(result2.fetchall(), [(1, True), (2, False)])
- @testing.exclude('firebird', '<', (2, 0), '2.0+ feature')
- @testing.exclude('postgresql', '<', (8, 2), '8.2+ feature')
def test_insert_returning(self):
result = table.insert().returning(table.c.id).execute({'persons': 1, 'full': False})
test_executemany()
+ def test_no_ipk_on_returning(self):
+ result = testing.db.execute(
+ table.insert().returning(table.c.id),
+ {'persons': 1, 'full': False}
+ )
+ assert_raises_message(
+ sa_exc.InvalidRequestError,
+ "Can't call inserted_primary_key when returning\(\) is used.",
+ getattr, result, "inserted_primary_key"
+ )
-
- @testing.exclude('firebird', '<', (2, 1), '2.1+ feature')
- @testing.exclude('postgresql', '<', (8, 2), '8.2+ feature')
@testing.fails_on_everything_except('postgresql', 'firebird')
def test_literal_returning(self):
if testing.against("postgresql"):
'values (5, 10, %s) returning persons' % literal_true)
eq_([dict(row) for row in result4], [{'persons': 10}])
- @testing.exclude('firebird', '<', (2, 1), '2.1+ feature')
- @testing.exclude('postgresql', '<', (8, 2), '8.2+ feature')
def test_delete_returning(self):
table.insert().execute([{'persons': 5, 'full': False}, {'persons': 3, 'full': False}])
eq_(result.fetchall(), [(1,)])
result2 = select([table.c.id, table.c.full]).order_by(table.c.id).execute()
- eq_(result2.fetchall(), [(2,False),])
+ eq_(result2.fetchall(), [(2, False),])
class SequenceReturningTest(fixtures.TestBase):
__requires__ = 'returning', 'sequences'