MSSQL Error When Reflecting Table With Capital Letters
Issue #892
resolved
I'm using sqlalchemy 0.4.1 and the pymssql library.
When I try to autoload a table it fails if I specify the table name in mixed case.
Fail:
Table('pc_Categories', meta, autoload=True)
Succeed:
Table('pc_categories', meta, autoload=True)
I am using MS SQL 2000. Below is the entire traceback along with the log statements
>>> t = Table('pc_Categories', meta, autoload=True)
2007-12-06 01:37:16,034 INFO sqlalchemy.engine.base.Engine.0x..b4 SELECT [COLUMNS_1](COLUMNS_1).[TABLE_SCHEMA](TABLE_SCHEMA), [COLUMNS_1](COLUMNS_1).[TABLE_NAME](TABLE_NAME), [COLUMNS_1](COLUMNS_1).[COLUMN_NAME](COLUMN_NAME), [COLUMNS_1](COLUMNS_1).[IS_NULLABLE](IS_NULLABLE), [COLUMNS_1](COLUMNS_1).[DATA_TYPE](DATA_TYPE), [COLUMNS_1](COLUMNS_1).[ORDINAL_POSITION](ORDINAL_POSITION)
, [COLUMNS_1](COLUMNS_1).[CHARACTER_MAXIMUM_LENGTH](CHARACTER_MAXIMUM_LENGTH), [COLUMNS_1](COLUMNS_1).[NUMERIC_PRECISION](NUMERIC_PRECISION), [COLUMNS_1](COLUMNS_1).[NUMERIC_SCALE](NUMERIC_SCALE), [COLUMNS_1](COLUMNS_1).[COLUMN_DEFAULT](COLUMN_DEFAULT)
FROM [INFORMATION_SCHEMA](INFORMATION_SCHEMA).[COLUMNS](COLUMNS) AS [COLUMNS_1](COLUMNS_1)
WHERE [COLUMNS_1](COLUMNS_1).[TABLE_NAME](TABLE_NAME) = %(COLUMNS_TABLE_NAME)s AND [COLUMNS_1](COLUMNS_1).[TABLE_SCHEMA](TABLE_SCHEMA) = %(COLUMNS_TABLE_SCHEMA)s ORDER BY [COLUMNS_1](COLUMNS_1).[ORDINAL_POSITION](ORDINAL_POSITION)
2007-12-06 01:37:16,035 INFO sqlalchemy.engine.base.Engine.0x..b4 {'COLUMNS_TABLE_NAME': 'pc_Categories', 'COLUMNS_TABLE_SCHEMA': 'dbo'}
2007-12-06 01:37:16,037 INFO sqlalchemy.engine.base.Engine.0x..b4 sp_columns [[pc_Categories]([pc_Categories)]
2007-12-06 01:37:16,037 INFO sqlalchemy.engine.base.Engine.0x..b4 {}
2007-12-06 01:37:16,038 INFO sqlalchemy.engine.base.Engine.0x..b4 ROLLBACK
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/site-packages/SQLAlchemy-0.4.1-py2.4.egg/sqlalchemy/schema.py", line 109, in __call__
return type.__call__(self, name, metadata, *args, **kwargs)
File "/usr/lib/python2.4/site-packages/SQLAlchemy-0.4.1-py2.4.egg/sqlalchemy/schema.py", line 234, in __init__
metadata._get_bind(raiseerr=True).reflecttable(self, include_columns=include_columns) File "/usr/lib/python2.4/site-packages/SQLAlchemy-0.4.1-py2.4.egg/sqlalchemy/engine/base.py", line 1189, in reflecttable
self.dialect.reflecttable(conn, table, include_columns) File "/usr/lib/python2.4/site-packages/SQLAlchemy-0.4.1-py2.4.egg/sqlalchemy/databases/mssql.py", line 596, in reflecttable cursor = connection.execute("sp_columns [%s](%s)" % self.identifier_preparer.format_table(table)) File "/usr/lib/python2.4/site-packages/SQLAlchemy-0.4.1-py2.4.egg/sqlalchemy/engine/base.py", line 789, in execute return Connection.executors[c](c)(self, object, multiparams, params) File "/usr/lib/python2.4/site-packages/SQLAlchemy-0.4.1-py2.4.egg/sqlalchemy/engine/base.py", line 799, in _execute_text
self.__execute_raw(context)
File "/usr/lib/python2.4/site-packages/SQLAlchemy-0.4.1-py2.4.egg/sqlalchemy/engine/base.py", line 864, in __execute_raw self._cursor_execute(context.cursor, context.statement, context.parameters[0](0), context=context)
File "/usr/lib/python2.4/site-packages/SQLAlchemy-0.4.1-py2.4.egg/sqlalchemy/engine/base.py", line 880, in _cursor_execute raise exceptions.DBAPIError.instance(statement, parameters, e)sqlalchemy.exceptions.DatabaseError: (DatabaseError) internal error: SQL Server message 105, severity 15, state 1, line 1:Unclosed quotation mark before the character string '[pc_Categories](pc_Categories)'.DB-Lib error message 20018, severity 5:General SQL Server error: Check messages from the SQL Server.
'sp_columns [[pc_Categories]([pc_Categories)]' {}
Comments (2)
-
Account Deleted -
Account Deleted - changed status to wontfix
(original author: ram)
- Log in to comment
(original author: ram) Can't reproduce here with SQL2005:
DDL:
Python:
What collation are you using?