Remove uses of REPLACE and ON CONFLICT IGNORE to make the SQL more portable.
This commit is contained in:
parent
9a7f496298
commit
6e7131f02f
|
@ -341,26 +341,21 @@ class SQLBaseStore(object):
|
||||||
# "Simple" SQL API methods that operate on a single table with no JOINs,
|
# "Simple" SQL API methods that operate on a single table with no JOINs,
|
||||||
# no complex WHERE clauses, just a dict of values for columns.
|
# no complex WHERE clauses, just a dict of values for columns.
|
||||||
|
|
||||||
def _simple_insert(self, table, values, or_replace=False, or_ignore=False,
|
def _simple_insert(self, table, values, desc="_simple_insert"):
|
||||||
desc="_simple_insert"):
|
|
||||||
"""Executes an INSERT query on the named table.
|
"""Executes an INSERT query on the named table.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
table : string giving the table name
|
table : string giving the table name
|
||||||
values : dict of new column names and values for them
|
values : dict of new column names and values for them
|
||||||
or_replace : bool; if True performs an INSERT OR REPLACE
|
|
||||||
"""
|
"""
|
||||||
return self.runInteraction(
|
return self.runInteraction(
|
||||||
desc,
|
desc,
|
||||||
self._simple_insert_txn, table, values, or_replace=or_replace,
|
self._simple_insert_txn, table, values,
|
||||||
or_ignore=or_ignore,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@log_function
|
@log_function
|
||||||
def _simple_insert_txn(self, txn, table, values, or_replace=False,
|
def _simple_insert_txn(self, txn, table, values):
|
||||||
or_ignore=False):
|
sql = "INSERT INTO %s (%s) VALUES(%s)" % (
|
||||||
sql = "%s INTO %s (%s) VALUES(%s)" % (
|
|
||||||
("REPLACE" if or_replace else "INSERT"),
|
|
||||||
table,
|
table,
|
||||||
", ".join(k for k in values),
|
", ".join(k for k in values),
|
||||||
", ".join("?" for k in values)
|
", ".join("?" for k in values)
|
||||||
|
|
|
@ -66,7 +66,6 @@ class KeyStore(SQLBaseStore):
|
||||||
"ts_added_ms": time_now_ms,
|
"ts_added_ms": time_now_ms,
|
||||||
"tls_certificate": buffer(tls_certificate_bytes),
|
"tls_certificate": buffer(tls_certificate_bytes),
|
||||||
},
|
},
|
||||||
or_ignore=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
@ -116,5 +115,4 @@ class KeyStore(SQLBaseStore):
|
||||||
"ts_added_ms": time_now_ms,
|
"ts_added_ms": time_now_ms,
|
||||||
"verify_key": buffer(verify_key.encode()),
|
"verify_key": buffer(verify_key.encode()),
|
||||||
},
|
},
|
||||||
or_ignore=True,
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -56,7 +56,6 @@ class SignatureStore(SQLBaseStore):
|
||||||
"algorithm": algorithm,
|
"algorithm": algorithm,
|
||||||
"hash": buffer(hash_bytes),
|
"hash": buffer(hash_bytes),
|
||||||
},
|
},
|
||||||
or_ignore=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_event_reference_hashes(self, event_ids):
|
def get_event_reference_hashes(self, event_ids):
|
||||||
|
@ -119,7 +118,6 @@ class SignatureStore(SQLBaseStore):
|
||||||
"algorithm": algorithm,
|
"algorithm": algorithm,
|
||||||
"hash": buffer(hash_bytes),
|
"hash": buffer(hash_bytes),
|
||||||
},
|
},
|
||||||
or_ignore=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def _get_event_signatures_txn(self, txn, event_id):
|
def _get_event_signatures_txn(self, txn, event_id):
|
||||||
|
@ -164,7 +162,6 @@ class SignatureStore(SQLBaseStore):
|
||||||
"key_id": key_id,
|
"key_id": key_id,
|
||||||
"signature": buffer(signature_bytes),
|
"signature": buffer(signature_bytes),
|
||||||
},
|
},
|
||||||
or_ignore=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def _get_prev_event_hashes_txn(self, txn, event_id):
|
def _get_prev_event_hashes_txn(self, txn, event_id):
|
||||||
|
@ -198,5 +195,4 @@ class SignatureStore(SQLBaseStore):
|
||||||
"algorithm": algorithm,
|
"algorithm": algorithm,
|
||||||
"hash": buffer(hash_bytes),
|
"hash": buffer(hash_bytes),
|
||||||
},
|
},
|
||||||
or_ignore=True,
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -124,7 +124,6 @@ class StateStore(SQLBaseStore):
|
||||||
"state_group": state_group,
|
"state_group": state_group,
|
||||||
"event_id": event.event_id,
|
"event_id": event.event_id,
|
||||||
},
|
},
|
||||||
or_replace=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
|
Loading…
Reference in New Issue