From: Mike Bayer Date: Thu, 27 May 2010 18:46:44 +0000 (-0400) Subject: - Fixed concatenation of constraints when "PRIMARY KEY" X-Git-Tag: rel_0_6_1~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=035ec314f63bd03de11eeac7c52c852674c7ce29;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - 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 --- diff --git a/CHANGES b/CHANGES index e27dde0597..18691e0376 100644 --- 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 diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index ec3d7b8ac6..030b45afff 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -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) diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 0e5f3499ec..b4992eec33 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -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 diff --git a/test/dialect/test_sqlite.py b/test/dialect/test_sqlite.py index 7f5f553bd9..c06fcc2c3d 100644 --- a/test/dialect/test_sqlite.py +++ b/test/dialect/test_sqlite.py @@ -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), diff --git a/test/sql/test_constraints.py b/test/sql/test_constraints.py index eed77ed839..33e4b8d764 100644 --- a/test/sql/test_constraints.py +++ b/test/sql/test_constraints.py @@ -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): diff --git a/test/sql/test_types.py b/test/sql/test_types.py index 3bf46568a0..4e02d3db8d 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -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):