I am trying to implement a generic REPLACE INTO as shown below.  The
code works fine if REPLACE INTO is changed to INSERT INTO.  There
really should not be any difference between REPLACE and INSERT if the
table is empty to start with.  Also, the REPLACE command works fine
when issued manually from a MySQL client.

Using a packet sniffer, it looks as though SQLAlchemy is issuing a
ROLLBACK command when REPLACE INTO is used -- which explains why the
table never gets updated with the data.

What is causing the ROLLBACK to get issued at the end of the REPLACE
INTO statement?  Rollback doesn't appear to happen when INSERT INTO is
used?

TCP/IP Traffic:
'Records: 75  Duplicates: 0  Warnings: 0
192.168.001.004.33832-068.019.174.024.03306: .....rollback
068.019.174.024.03306-192.168.001.004.33832: ...........
192.168.001.004.33827-068.019.174.024.03306: .....commit

Code:
def mysqlreplace(cls,keysdct,fixedparams,datadct):
        statement1 = "REPLACE INTO %s (%s , %s) VALUES ('%s' , :%s) "
%        (cls.table.name,
        ','.join([key for key in fixedparams.keys()]),
        ','.join([key for key in keysdct.keys()]),
        ", :".join([key for key in fixedparams.values()]),
        ", :".join([key for key in keysdct.values()]) )

        statement2 = text(statement1, bindparams=[bindparam(key) for
key in keysdct.values()])

        trans = cls.table.engine.connect().begin()
        cls.table.engine.connect().execute(statement2,datadct)
        trans.commit()

--~--~---------~--~----~------------~-------~--~----~
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