From 2a3d979650333d937c8bde4a19c80073fa39f5f7 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 31 May 2009 22:03:44 +0000 Subject: [PATCH] fixes for MySQL --- lib/sqlalchemy/dialects/mysql/base.py | 10 +++++++--- test/engine/ddlevents.py | 2 +- test/testlib/engines.py | 6 +++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index cec9ade928..47ce09a866 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -1466,10 +1466,12 @@ class MySQLDDLCompiler(compiler.DDLCompiler): (self.preparer.quote(self._validate_identifier(index.name, False), index.quote), self.preparer.format_table(index.table)) - def visit_drop_foreignkey(self, drop): + def visit_drop_constraint(self, drop): constraint = drop.element - return "ALTER TABLE %s DROP FOREIGN KEY %s" % \ + is_fk = isinstance(constraint, sa_schema.ForeignKeyConstraint) + return "ALTER TABLE %s DROP %s%s" % \ (self.preparer.format_table(constraint.table), + is_fk and "FOREIGN KEY " or "", self.preparer.format_constraint(constraint)) class MySQLTypeCompiler(compiler.GenericTypeCompiler): @@ -1832,6 +1834,7 @@ class MySQLDialect(default.DefaultDialect): self._server_casing = self._detect_casing(connection) self._server_collations = self._detect_collations(connection) self._server_ansiquotes = self._detect_ansiquotes(connection) + if self._server_ansiquotes: self.preparer = MySQLANSIIdentifierPreparer else: @@ -2068,6 +2071,7 @@ class MySQLDialect(default.DefaultDialect): row = self._compat_fetchone( connection.execute("SHOW VARIABLES LIKE 'sql_mode'"), charset=self._connection_charset) + if not row: mode = '' else: @@ -2609,7 +2613,7 @@ class MySQLIdentifierPreparer(_MySQLIdentifierPreparer): def __init__(self, dialect): super(MySQLIdentifierPreparer, self).__init__(dialect, initial_quote="`") - + def _escape_identifier(self, value): return value.replace('`', '``') diff --git a/test/engine/ddlevents.py b/test/engine/ddlevents.py index dcb16c194e..f5613f5a92 100644 --- a/test/engine/ddlevents.py +++ b/test/engine/ddlevents.py @@ -328,7 +328,7 @@ class DDLTest(TestBase, AssertsCompiledSQL): ddl = DDL('%(schema)s-%(table)s-%(fullname)s') - dialect = testing.db.dialect + dialect = self.mock_engine().dialect self.assert_compile(ddl.against(sane_alone), '-t-t', dialect=dialect) self.assert_compile(ddl.against(sane_schema), 's-t-s.t', dialect=dialect) self.assert_compile(ddl.against(insane_alone), '-"t t"-"t t"', dialect=dialect) diff --git a/test/testlib/engines.py b/test/testlib/engines.py index 358b9db5f9..8a3acb6a9a 100644 --- a/test/testlib/engines.py +++ b/test/testlib/engines.py @@ -131,7 +131,11 @@ def testing_engine(url=None, options=None): listeners.append(testing_reaper) engine = create_engine(url, **options) - + + # may want to call this, results + # in first-connect initializers + #engine.connect() + return engine def utf8_engine(url=None, options=None): -- 2.47.3