Mike Bayer avatar Mike Bayer committed 034f80e

- 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

Comments (0)

Files changed (5)

lib/sqlalchemy/engine/default.py

 
     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 \

lib/sqlalchemy/testing/assertions.py

 
 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
                 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:

lib/sqlalchemy/testing/fixtures.py

 
 
 class _ORMTest(object):
-    __requires__ = ('subqueries',)
 
     @classmethod
     def teardown_class(cls):

lib/sqlalchemy/testing/requirements.py

         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."""
     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"

test/sql/test_returning.py

 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'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.