]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed concatenation of constraints when "PRIMARY KEY"
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 27 May 2010 18:46:44 +0000 (14:46 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 27 May 2010 18:46:44 +0000 (14:46 -0400)
constraint gets moved to column level due to SQLite
AUTOINCREMENT keyword being rendered.  [ticket:1812]
- remove some extra space in between constraint DDL
- added alias() to binary comparison test, fixing pg + mysql failures

CHANGES
lib/sqlalchemy/dialects/sqlite/base.py
lib/sqlalchemy/sql/compiler.py
test/dialect/test_sqlite.py
test/sql/test_constraints.py
test/sql/test_types.py

diff --git a/CHANGES b/CHANGES
index e27dde05974bf385410a1e8b9f5909efd3702ded..18691e0376b29fd9cfd8e713d2407bc9de62c537 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -70,6 +70,11 @@ CHANGES
   - func.sysdate() emits "SYSDATE()", i.e. with the ending
     parenthesis, on MySQL.  [ticket:1794]
 
+- sqlite
+  - Fixed concatenation of constraints when "PRIMARY KEY" 
+    constraint gets moved to column level due to SQLite
+    AUTOINCREMENT keyword being rendered.  [ticket:1812]
+    
 - oracle
   - Added a check for cx_oracle versions lower than version 5,
     in which case the incompatible "output type handler" won't 
index ec3d7b8ac65770b6d1d56213b9adf7fc06420be8..030b45afff6f161521d1f1ea30b3b5103d796a24 100644 (file)
@@ -266,7 +266,7 @@ class SQLiteDDLCompiler(compiler.DDLCompiler):
                 c.table.kwargs.get('sqlite_autoincrement', False) and \
                 isinstance(c.type, sqltypes.Integer) and \
                 not c.foreign_keys:
-                return ''
+                return None
  
         return super(SQLiteDDLCompiler, self).\
                     visit_primary_key_constraint(constraint)
index 0e5f3499ec1e276752f6c63a2b0f93bd1c93a8cd..b4992eec330685844448d7711fb1ef34c8e4b005 100644 (file)
@@ -1177,7 +1177,7 @@ class DDLCompiler(engine.Compiled):
         preparer = self.preparer
         text = "CREATE "
         if index.unique:
-            text += "UNIQUE "
+            text += "UNIQUE "   
         text += "INDEX %s ON %s (%s)" \
                     % (preparer.quote(self._validate_identifier(index.name, True), index.quote),
                        preparer.format_table(index.table),
@@ -1262,7 +1262,7 @@ class DDLCompiler(engine.Compiled):
         return text
 
     def visit_column_check_constraint(self, constraint):
-        text = " CHECK (%s)" % constraint.sqltext
+        text = "CHECK (%s)" % constraint.sqltext
         text += self.define_constraint_deferrability(constraint)
         return text
 
@@ -1299,8 +1299,8 @@ class DDLCompiler(engine.Compiled):
     def visit_unique_constraint(self, constraint):
         text = ""
         if constraint.name is not None:
-            text += "CONSTRAINT %s" % self.preparer.format_constraint(constraint)
-        text += " UNIQUE (%s)" % (', '.join(self.preparer.quote(c.name, c.quote) for c in constraint))
+            text += "CONSTRAINT %s " % self.preparer.format_constraint(constraint)
+        text += "UNIQUE (%s)" % (', '.join(self.preparer.quote(c.name, c.quote) for c in constraint))
         text += self.define_constraint_deferrability(constraint)
         return text
 
index 7f5f553bd99ec4d0defe282132f130cd92a8e34b..c06fcc2c3dbc3fbc8ed2e1cf8f6d74acf235eb41 100644 (file)
@@ -566,6 +566,19 @@ class TestAutoIncrement(TestBase, AssertsCompiledSQL):
             dialect=sqlite.dialect()
         )
 
+    def test_sqlite_autoincrement_constraint(self):
+        table = Table('autoinctable', MetaData(),
+                      Column('id', Integer, primary_key=True),
+                      Column('x', Integer, default=None),
+                      UniqueConstraint('x'),
+                      sqlite_autoincrement=True)
+        self.assert_compile(
+            schema.CreateTable(table),
+            "CREATE TABLE autoinctable (id INTEGER NOT NULL "
+            "PRIMARY KEY AUTOINCREMENT, x INTEGER, UNIQUE (x))",
+            dialect=sqlite.dialect()
+        )
+
     def test_sqlite_no_autoincrement(self):
         table = Table('noautoinctable', MetaData(),
                       Column('id', Integer, primary_key=True),
index eed77ed83932a5de8b8908a13fee55afaec32a9d..33e4b8d764cff473d8d3701726ec2be55810027f 100644 (file)
@@ -275,7 +275,7 @@ class ConstraintCompilationTest(TestBase, AssertsCompiledSQL):
         
         self.assert_compile(
             schema.CreateTable(t),
-            "CREATE TABLE tbl (a INTEGER, b INTEGER  CHECK (a < b) DEFERRABLE INITIALLY DEFERRED)"
+            "CREATE TABLE tbl (a INTEGER, b INTEGER CHECK (a < b) DEFERRABLE INITIALLY DEFERRED)"
         )
     
     def test_use_alter(self):
index 3bf46568a082148259230eb9596321798dbc5d6e..4e02d3db8dc4c18f7e9afcd51bcc2a4bc967c6d7 100644 (file)
@@ -674,7 +674,7 @@ class BinaryTest(TestBase, AssertsExecutionResults):
         
         data = os.urandom(32)
         binary_table.insert().execute(data=data)
-        eq_(binary_table.select().where(binary_table.c.data==data).count().scalar(), 1)
+        eq_(binary_table.select().where(binary_table.c.data==data).alias().count().scalar(), 1)
         
         
     def load_stream(self, name):