I have a use case where I need to execute a MySQL LOAD DATA INFILE
statement on an SQLAlchemy connection.
I've tried this is with an engine using a threadlocal strategy, using
engine.scalar() and passing a string that contains the (generated)
DATA INFILE statement.
The statement works if typed manually into the MySQL console, so I'm
pretty sure it's right. I don't get any errors either (and I'm able
make it error by deliberately introducing a syntax error, so it must
reach MySQL) but no data ever ends up in the table.
Can anyone think of what I'm doing wrong?
I'm guessing you're using a transactional storage engine like InnoDB for
this table? It looks like LOAD DATA INFILE isn't autocommiting at the
moment, and that seems like the most likely explanation. For the time
being, you can workaround this by using an explicit transaction for your
from sqlalchemy import create_engine
engine = create_engine('mysql:///test')
con = engine.connect()
trans = con.begin()
con.execute("LOAD DATA INFILE '/var/tmp/data.csv' "
"INTO TABLE testtable "
"FIELDS TERMINATED BY ','")
print list(engine.execute('SELECT * FROM testtable'))
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to sqla...@googlegroups.com
To unsubscribe from this group, send email to sqla...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en