mysql.py fails to escape certain identifiers

Issue #482 resolved
Former user created an issue

When reflecting tables, mysql.py fails to escape the table name if necessary, sometimes resulting in invalid queries.

Here is a diff against mysql.py as of SQLAlchemy 0.3.4.

346c346
<             c = connection.execute("describe " + table.fullname, {})
---
>             c = connection.execute("describe " + self.identifier_preparer.format_table(table), {})
407c407
<         c = connection.execute("SHOW CREATE TABLE " + table.fullname, {})
---
>         c = connection.execute("SHOW CREATE TABLE " + self.identifier_preparer.format_table(table), {})

Comments (7)

  1. Former user Account Deleted

    By the way, this also affects has_table. This is harder to fix because it is only passed the table's name, without the schema (if any). A simple fix would be to change has_table so it takes a Table object instead of a string; it would still only have the task of checking for the existence of a table with that name, but it could access other information (table.schema, etc.) when necessary.

  2. Mike Bayer repo owner

    passing the full table in to has_table() still does not eliminate the complexity that some dialects need to query the schema name and tablename as separate columns, so the format_table() method is not flexible enough. a new method "foramt_schema_and_tablename" or similar should be added to ANSIIdentifierPreparer which returns the two names separately, and is called by the generic create/drop methods in ansisql.py to get the quoted names, which then get passed to has_table (also has_table has a "schema" kw arg in the trunk, though only supported on postgres).

  3. Log in to comment