Hi, 
I'm using SQLAlchemy 0.7b4 on Python 2.6 and MySQL 5.1 and MySQLdb 1.2.3 
beta 2

I tried to import data from SQL file into database, by simply reading file 
line by line and executing SQL commands found.

Program created successfully following table:

create table ATTRIBUTE_TYPE (
    ID   INTEGER PRIMARY KEY,
    NAME VARCHAR(250),
    METADATA_GROUP_ID INTEGER,
    CREATED_DATE DATETIME,
    RECORD_LAST_UPDATED_DATE DATETIME
)

But failed on inserting data into it:
insert into ATTRIBUTE_TYPE (CREATED_DATE, ID, METADATA_GROUP_ID, NAME, 
RECORD_LAST_UPDATED_DATE) values (str_to_date('20110510T10:23:27', 
'%Y%m%dT%H:%i:%S'), 2, NULL, 'Do not use for concept mapping', 
str_to_date('20110510T10:23:27', '%Y%m%dT%H:%i:%S'))

I tried to execute this statement using Connection.execute() method (module 
sqlalchemy.engine.base) without any parameters. It turned out that while it 
processes params and multiparams, it ends up with empty tuple of parameters, 
which is then passed to BaseCursor.execute() in (MySQLdb.cursors) as the 
'args' parameter.
BaseCursor.execute() checks if *args is None*, and if it's not - it does:

query = query % db.literal(args)

Which fails of course, because query contains % characters and args is 
empty. 

I think that either MySQL dialect should pass None as 'args' instead of an 
empty tuple to be consistent with what BaseCursor expects, or even default 
dialect could behave that way - if only it won't break compatibility with 
other engines.

If there is some workaround for this case - please let me know. Note that 
I'm processing external file, so constructing Query object from raw SQL 
query, is not a workaround I'd like to implement.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
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