]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
correct / test the autoincrement reflection policy
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 2 Aug 2009 19:00:59 +0000 (19:00 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 2 Aug 2009 19:00:59 +0000 (19:00 +0000)
lib/sqlalchemy/dialects/sqlite/base.py
lib/sqlalchemy/engine/default.py
lib/sqlalchemy/engine/reflection.py
test/engine/test_reflection.py

index b644c7bf80b35c4617681bc9356770bbc05cafeb..8dea91d0abf316be4b9a650da455702d893a0057 100644 (file)
@@ -270,6 +270,7 @@ class SQLiteDialect(default.DefaultDialect):
     supports_default_values = True
     supports_empty_insert = False
     supports_cast = True
+
     default_paramstyle = 'qmark'
     statement_compiler = SQLiteCompiler
     ddl_compiler = SQLiteDDLCompiler
index 45918618d4fb6a8e2bdc717c130e19935fb43eda..bede3b701876718ae8248750e203e66bb5a7f5c5 100644 (file)
@@ -386,7 +386,7 @@ class DefaultExecutionContext(base.ExecutionContext):
         if self.dialect.postfetch_lastrowid and \
             (not len(self._last_inserted_ids) or \
                         None in self._last_inserted_ids):
-
+            
             table = self.compiled.statement.table
             lastrowid = self.get_lastrowid()
             self._last_inserted_ids = [c is table._autoincrement_column and lastrowid or v
index 5ac4756beec4f57612778dc3088aac8ce5f8e3ba..173e0fab0070498823a800709ae2b9dd5599942b 100644 (file)
@@ -282,8 +282,9 @@ class Inspector(object):
             coltype = col_d['type']
             col_kw = {
                 'nullable':col_d['nullable'],
-                'autoincrement':col_d.get('autoincrement', False)
             }
+            if 'autoincrement' in col_d:
+                col_kw['autoincrement'] = col_d['autoincrement']
             
             colargs = []
             if col_d.get('default') is not None:
index bcf0de67e45f16265545dabd2c6e4a4a77e1a071..dff9fa1bb6fcf4f51c5bafb71f87c151b6c0bcf9 100644 (file)
@@ -138,6 +138,37 @@ class ReflectionTest(TestBase, ComparesTables):
         finally:
             m.drop_all()
 
+    def test_autoincrement_col(self):
+        """test that 'autoincrement' is reflected according to sqla's policy.
+        
+        Don't mark this test as unsupported for any backend !
+        
+        (technically it fails with MySQL InnoDB since "id" comes before "id2")
+        
+        """
+        
+        meta = MetaData(testing.db)
+        t1 = Table('test', meta,
+            Column('id', sa.Integer, primary_key=True),
+            Column('data', sa.String(50)),
+        )
+        t2 = Table('test2', meta,
+            Column('id', sa.Integer, sa.ForeignKey('test.id'), primary_key=True),
+            Column('id2', sa.Integer, primary_key=True),
+            Column('data', sa.String(50)),
+        )
+        meta.create_all()
+        try:
+            m2 = MetaData(testing.db)
+            t1a = Table('test', m2, autoload=True)
+            assert t1a._autoincrement_column is t1a.c.id
+            
+            t2a = Table('test2', m2, autoload=True)
+            assert t2a._autoincrement_column is t2a.c.id2
+            
+        finally:
+            meta.drop_all()
+            
     def test_unknown_types(self):
         meta = MetaData(testing.db)
         t = Table("test", meta,