]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- add an event to testing so that other dialects can intercept "test_needs_autoincrement"
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 24 Mar 2013 18:31:48 +0000 (14:31 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 24 Mar 2013 18:31:48 +0000 (14:31 -0400)
- get the assumption of "1" for "first sequence item" to be dialect configured

lib/sqlalchemy/engine/default.py
lib/sqlalchemy/testing/schema.py
lib/sqlalchemy/testing/suite/test_insert.py

index 4c49e58f6b6336fe94a28c62248ede844cd765dc..abb9f0fc3dc293a62ebb937174889154c0a03291 100644 (file)
@@ -34,6 +34,10 @@ class DefaultDialect(interfaces.Dialect):
     preparer = compiler.IdentifierPreparer
     supports_alter = True
 
+    # the first value we'd get for an autoincrement
+    # column.
+    default_sequence_base = 1
+
     # most DBAPIs happy with this for execute().
     # not cx_oracle.
     execute_sequence_format = tuple
index ad233ec22a2e2bca6b88d3c100793914c901fc6e..325d74f1ea635ca3240ea4a0a7867189ed00abb3 100644 (file)
@@ -66,18 +66,27 @@ def Column(*args, **kw):
 
     col = schema.Column(*args, **kw)
     if 'test_needs_autoincrement' in test_opts and \
-        kw.get('primary_key', False) and \
-        exclusions.against('firebird', 'oracle'):
-        def add_seq(c, tbl):
-            c._init_items(
-                schema.Sequence(_truncate_name(
-                        config.db.dialect, tbl.name + '_' + c.name + '_seq'),
-                    optional=True)
-            )
-        event.listen(col, 'after_parent_attach', add_seq, propagate=True)
+        kw.get('primary_key', False):
+
+        # allow any test suite to pick up on this
+        col.info['test_needs_autoincrement'] = True
+
+        # hardcoded rule for firebird, oracle; this should
+        # be moved out
+        if exclusions.against('firebird', 'oracle'):
+            def add_seq(c, tbl):
+                c._init_items(
+                    schema.Sequence(_truncate_name(
+                            config.db.dialect, tbl.name + '_' + c.name + '_seq'),
+                        optional=True)
+                )
+            event.listen(col, 'after_parent_attach', add_seq, propagate=True)
     return col
 
 
+
+
+
 def _truncate_name(dialect, name):
     if len(name) > dialect.max_identifier_length:
         return name[0:max(dialect.max_identifier_length - 6, 0)] + \
index 66aa1ecfa6e36d8ff586530ed8a779e3189dd4b0..a00fde312e5103cd1f8127e8ad364efefb7ed3d7 100644 (file)
@@ -33,7 +33,7 @@ class LastrowidTest(fixtures.TablesTest):
         row = conn.execute(table.select()).first()
         eq_(
             row,
-            (1, "some data")
+            (config.db.dialect.default_sequence_base, "some data")
         )
 
     def test_autoincrement_on_insert(self):
@@ -132,7 +132,7 @@ class ReturningTest(fixtures.TablesTest):
         row = conn.execute(table.select()).first()
         eq_(
             row,
-            (1, "some data")
+            (config.db.dialect.default_sequence_base, "some data")
         )
 
     @classmethod