Hi,

I tried to migrate to SQLAlchemy 0.4 but unfortunately, 0.4 does
not seem to work with the "weird" table and column names I have
in my legacy database.

I believe this behavior is a regression because the script below
worked for me with 0.3.10. I got something horribly wrong (still
learning ;-) but I'm very confident somebody can show me the
correct solution if it is my fault :-))

----------------------------------------------------------------
#!/usr/bin/env python

import sqlalchemy

from sqlalchemy import *
from sqlalchemy.orm import *

myengine = create_engine('sqlite:///:memory:', echo=False)
metadata = MetaData(myengine)

table_name = 'tbl-Foo+ID'

users_table = Table(table_name, metadata,
        Column('id-Foo+ID', Integer, primary_key=True),
        Column('name', String(40)))
        
metadata.create_all()

fooid_table = Table(table_name, metadata, autoload=True)
id_column = fooid_table.c.get('id-Foo+ID')
result = fooid_table.select(id_column==42).execute()
----------------------------------------------------------------

Traceback (most recent call last):
   File "./regression.py", line 21, in ?
     result = fooid_table.select(id_column==42).execute()
   File "/usr/lib/python2.4/site-packages/sqlalchemy/sql/expression.py", line 
971, in execute
     return e._execute_clauseelement(self, multiparams, params)
   File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 
1122, in _execute_clauseelement
     return connection._execute_clauseelement(elem, multiparams, params)
   File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 829, 
in _execute_clauseelement
     return self._execute_compiled(elem.compile(dialect=self.dialect, 
column_keys=keys, inline=len(params) > 1), distilled_params=params)
   File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 840, 
in _execute_compiled
     context.pre_execution()
   File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/default.py", line 
202, in pre_execution
     self.pre_exec()
   File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/default.py", line 
215, in pre_exec
     self.parameters = self.__convert_compiled_params(self.compiled_parameters)
   File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/default.py", line 
187, in __convert_compiled_params
     parameters = [p.get_raw_list(processors) for p in parameters]
   File "/usr/lib/python2.4/site-packages/sqlalchemy/sql/util.py", line 83, in 
get_raw_list
     res.append(binds[key][2])
KeyError: 'tbl'


I think the problem is in sqlalchemy/sql/compiler.py with the
regular expression in BIND_PARAMS. The regex extracts the value 'tbl'
in the first match group from the generated query
    SELECT "tbl-Foo+ID"."id-Foo+ID", "tbl-Foo+ID".name
    FROM "tbl-Foo+ID"
    WHERE "tbl-Foo+ID"."id-Foo+ID" = :tbl-Foo+ID_id-Foo+ID
(see DefaultCompiler.after_compile())

I suspect that the regex
     BIND_PARAMS = re.compile(r'(?<![:\w\$\x5c]):([\w\$]+)(?![:\w\$])', 
re.UNICODE)
should be extended so that it accepts '-', '+' and other unusual #
characters.

So after all, it looks like a bug to me but if someone knows a
workaround, that would be fine, too :-)

fs

PS: Thank you all very much for the first-class support here!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to