Commits

Mike Bayer committed 3de9ffc

- Fixed concatenation of constraints when "PRIMARY KEY"
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

Comments (0)

Files changed (6)

   - 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 

lib/sqlalchemy/dialects/sqlite/base.py

                 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)

lib/sqlalchemy/sql/compiler.py

         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),
         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
 
     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
 

test/dialect/test_sqlite.py

             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),

test/sql/test_constraints.py

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

test/sql/test_types.py

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