I have code that need to do a mysql replace instead of an insert.
The quick hack to just create a string and execute has problems with
quoting things, sql injection ...
If a table.replace() is not easy to do is there a way to create a statement
that works that way. If I could do a conn.execute(statement, [list of
dict]) that
would be great.
The current code look like:
table = mappings.TableForTag(setName)
keys = sorted([str(k) for k in records[0].keys() if
table.c.has_key((str(k)))])
statement = 'REPLACE INTO %s(%s) VALUES ' %(table.name,
','.join(["`%s`" % k for k in keys]))
values = []
for record in records:
values.append('(%s)' % ','.join(["'%s'" % str(record.get(k))
for k in keys]))
values = ','.join(values)
conn = engine.connect()
conn.execute(statement + values)
I would like to be able to do something like:
table = mappings.TableForTag(setName)
conn = engine.connect()
conn.execute(table.replace(), records)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---