diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-10-04 17:36:02 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-10-04 17:36:02 -0400 |
commit | ef7c2f359dcb88577a9aa37256d5060c2c87d2af (patch) | |
tree | 5c5ff37246d4808818bf9ab939f2e8a9124f3aad | |
parent | 1c3e3225521647cc843a633e34ed84e1ca4e797a (diff) | |
download | sqlalchemy-ef7c2f359dcb88577a9aa37256d5060c2c87d2af.tar.gz |
- don't call get_lastrowid() on explicit returning
- don't hardwire "subqueries" requirement in the base, mysql < 4.1 isn't working anyway
- don't need explicit FB/PG exclusions in test_returning
- hit db.connect() for the returning requirement
-rw-r--r-- | lib/sqlalchemy/engine/default.py | 1 | ||||
-rw-r--r-- | lib/sqlalchemy/testing/assertions.py | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/testing/fixtures.py | 1 | ||||
-rw-r--r-- | lib/sqlalchemy/testing/requirements.py | 7 | ||||
-rw-r--r-- | test/sql/test_returning.py | 33 |
5 files changed, 26 insertions, 20 deletions
diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index 4bb2427c7..778ec6be6 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -671,6 +671,7 @@ class DefaultExecutionContext(interfaces.ExecutionContext): def post_insert(self): if not self._is_implicit_returning and \ + not self._is_explicit_returning and \ not self.compiled.inline and \ self.dialect.postfetch_lastrowid and \ (not self.inserted_primary_key or \ diff --git a/lib/sqlalchemy/testing/assertions.py b/lib/sqlalchemy/testing/assertions.py index 1e8559c1a..2b305b98a 100644 --- a/lib/sqlalchemy/testing/assertions.py +++ b/lib/sqlalchemy/testing/assertions.py @@ -2,7 +2,7 @@ from __future__ import absolute_import from . import util as testutil from sqlalchemy import pool, orm, util -from sqlalchemy.engine import default +from sqlalchemy.engine import default, create_engine from sqlalchemy import exc as sa_exc from sqlalchemy.util import decorator from sqlalchemy import types as sqltypes, schema @@ -183,6 +183,8 @@ class AssertsCompiledSQL(object): dialect = default.DefaultDialect() elif dialect is None: dialect = config.db.dialect + elif isinstance(dialect, basestring): + dialect = create_engine("%s://" % dialect).dialect kw = {} if params is not None: diff --git a/lib/sqlalchemy/testing/fixtures.py b/lib/sqlalchemy/testing/fixtures.py index 018276d4d..1a1204898 100644 --- a/lib/sqlalchemy/testing/fixtures.py +++ b/lib/sqlalchemy/testing/fixtures.py @@ -202,7 +202,6 @@ class TablesTest(TestBase): class _ORMTest(object): - __requires__ = ('subqueries',) @classmethod def teardown_class(cls): diff --git a/lib/sqlalchemy/testing/requirements.py b/lib/sqlalchemy/testing/requirements.py index 4df2163b7..fa617025f 100644 --- a/lib/sqlalchemy/testing/requirements.py +++ b/lib/sqlalchemy/testing/requirements.py @@ -55,6 +55,12 @@ class SuiteRequirements(Requirements): return exclusions.open() @property + def subqueries(self): + """Target database must support subqueries.""" + + return exclusions.open() + + @property def autoincrement_insert(self): """target platform generates new surrogate integer primary key values when insert() is executed, excluding the pk column.""" @@ -65,6 +71,7 @@ class SuiteRequirements(Requirements): def returning(self): """target platform supports RETURNING.""" + self.config.db.connect() return exclusions.only_if( lambda: self.config.db.dialect.implicit_returning, "'returning' not supported by database" diff --git a/test/sql/test_returning.py b/test/sql/test_returning.py index 55f4f7926..013f5cfaa 100644 --- a/test/sql/test_returning.py +++ b/test/sql/test_returning.py @@ -3,7 +3,9 @@ from sqlalchemy import * 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', @@ -36,8 +38,6 @@ class ReturningTest(fixtures.TestBase, AssertsExecutionResults): 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}) @@ -55,8 +55,6 @@ class ReturningTest(fixtures.TestBase, AssertsExecutionResults): 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() @@ -65,8 +63,6 @@ class ReturningTest(fixtures.TestBase, AssertsExecutionResults): @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() @@ -78,8 +74,6 @@ class ReturningTest(fixtures.TestBase, AssertsExecutionResults): 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}]) @@ -87,10 +81,8 @@ class ReturningTest(fixtures.TestBase, AssertsExecutionResults): 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}) @@ -116,10 +108,17 @@ class ReturningTest(fixtures.TestBase, AssertsExecutionResults): 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"): @@ -131,8 +130,6 @@ class ReturningTest(fixtures.TestBase, AssertsExecutionResults): '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}]) @@ -140,7 +137,7 @@ class ReturningTest(fixtures.TestBase, AssertsExecutionResults): 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' |