Skip to content

Instantly share code, notes, and snippets.

@daniel-garcia
Created May 25, 2012 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save daniel-garcia/2790549 to your computer and use it in GitHub Desktop.
Save daniel-garcia/2790549 to your computer and use it in GitHub Desktop.
Patch restorage to use INSERT ON DUPLICATE KEY UPDATE
--- relstorage/adapters/mover.py.orig 2012-05-25 16:56:17.000000000 -0400
+++ relstorage/adapters/mover.py 2012-05-25 16:57:16.000000000 -0400
@@ -864,11 +864,23 @@ class ObjectMover(object):
else:
if self.database_name == 'mysql':
stmt = """
- REPLACE INTO object_state (zoid, tid, state_size, state)
- SELECT zoid, %s, COALESCE(LENGTH(state), 0), state
- FROM temp_store
+ INSERT INTO object_state (zoid, tid, state_size, state)
+ SELECT zoid, %s, COALESCE(LENGTH(state), 0), state
+ FROM temp_store
+ ON DUPLICATE KEY UPDATE
+ tid=%s,
+ state_size=COALESCE(LENGTH(temp_store.state), 0),
+ state=temp_store.state
"""
- cursor.execute(stmt, (tid,))
+ cursor.execute(stmt, (tid,tid,))
+
+ # Do not use replace into, dgarcia@zenoss.com
+ #stmt = """
+ #REPLACE INTO object_state (zoid, tid, state_size, state)
+ #SELECT zoid, %s, COALESCE(LENGTH(state), 0), state
+ #FROM temp_store
+ #"""
+ #cursor.execute(stmt, (tid,))
else:
stmt = """
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment