comparison src/memory/sqlite.py @ 1962:a45235d8dc93

memory (sqlite): fixed handling of extra (pickled data) by using sqlite3.Binary
author Goffi <goffi@goffi.org>
date Sun, 19 Jun 2016 22:22:13 +0200
parents c73e08094a95
children b536dd121da1
comparison
equal deleted inserted replaced
1961:c73e08094a95 1962:a45235d8dc93
331 """ 331 """
332 extra = pickle.dumps({k: v for k, v in data['extra'].iteritems() if k not in NOT_IN_EXTRA}, 0) 332 extra = pickle.dumps({k: v for k, v in data['extra'].iteritems() if k not in NOT_IN_EXTRA}, 0)
333 from_jid = data['from'] 333 from_jid = data['from']
334 to_jid = data['to'] 334 to_jid = data['to']
335 d = self.dbpool.runQuery("INSERT INTO history(uid, update_uid, profile_id, source, dest, source_res, dest_res, timestamp, received_timestamp, type, extra) VALUES (?,?,?,?,?,?,?,?,?,?,?)", 335 d = self.dbpool.runQuery("INSERT INTO history(uid, update_uid, profile_id, source, dest, source_res, dest_res, timestamp, received_timestamp, type, extra) VALUES (?,?,?,?,?,?,?,?,?,?,?)",
336 (data['uid'], data['extra'].get('update_uid'), self.profiles[profile], data['from'].userhost(), to_jid.userhost(), from_jid.resource, to_jid.resource, data['timestamp'], data.get('received_timestamp'), data['type'], extra)) 336 (data['uid'], data['extra'].get('update_uid'), self.profiles[profile], data['from'].userhost(), to_jid.userhost(), from_jid.resource, to_jid.resource, data['timestamp'], data.get('received_timestamp'), data['type'], sqlite3.Binary(extra)))
337 d.addCallbacks(self._addToHistoryCb, self._addToHistoryEb, callbackArgs=[data], errbackArgs=[data]) 337 d.addCallbacks(self._addToHistoryCb, self._addToHistoryEb, callbackArgs=[data], errbackArgs=[data])
338 d.addErrback(self._logHistoryError, from_jid, to_jid, data) 338 d.addErrback(self._logHistoryError, from_jid, to_jid, data)
339 return d 339 return d
340 340
341 def sqliteHistoryToList(self, query_result): 341 def sqliteHistoryToList(self, query_result):
557 """Save the general private binary value in database 557 """Save the general private binary value in database
558 @param category: category of the privateeter 558 @param category: category of the privateeter
559 @param key: key of the private value 559 @param key: key of the private value
560 @param value: value to set 560 @param value: value to set
561 @return: deferred""" 561 @return: deferred"""
562 d = self.dbpool.runQuery("REPLACE INTO private_gen_bin(namespace,key,value) VALUES (?,?,?)", (namespace, key, pickle.dumps(value, 0))) 562 d = self.dbpool.runQuery("REPLACE INTO private_gen_bin(namespace,key,value) VALUES (?,?,?)", (namespace, key, sqlite3.Binary(pickle.dumps(value, 0))))
563 d.addErrback(lambda ignore: log.error(_(u"Can't set general private binary value (%(key)s) [namespace:%(namespace)s] in database" % 563 d.addErrback(lambda ignore: log.error(_(u"Can't set general private binary value (%(key)s) [namespace:%(namespace)s] in database" %
564 {"namespace": namespace, "key": key}))) 564 {"namespace": namespace, "key": key})))
565 return d 565 return d
566 566
567 def setIndPrivateBinary(self, namespace, key, value, profile): 567 def setIndPrivateBinary(self, namespace, key, value, profile):
569 @param namespace: namespace of the value 569 @param namespace: namespace of the value
570 @param key: key of the private value 570 @param key: key of the private value
571 @param value: value to set 571 @param value: value to set
572 @param profile: a profile which *must* exist 572 @param profile: a profile which *must* exist
573 @return: deferred""" 573 @return: deferred"""
574 d = self.dbpool.runQuery("REPLACE INTO private_ind_bin(namespace,key,profile_id,value) VALUES (?,?,?,?)", (namespace, key, self.profiles[profile], pickle.dumps(value, 0))) 574 d = self.dbpool.runQuery("REPLACE INTO private_ind_bin(namespace,key,profile_id,value) VALUES (?,?,?,?)", (namespace, key, self.profiles[profile], sqlite3.Binary(pickle.dumps(value, 0))))
575 d.addErrback(lambda ignore: log.error(_(u"Can't set individual binary private value (%(key)s) [namespace: %(namespace)s] for [%(profile)s] in database" % 575 d.addErrback(lambda ignore: log.error(_(u"Can't set individual binary private value (%(key)s) [namespace: %(namespace)s] for [%(profile)s] in database" %
576 {"namespace": namespace, "key": key, "profile": profile}))) 576 {"namespace": namespace, "key": key, "profile": profile})))
577 return d 577 return d
578 578
579 def delGenPrivateBinary(self, namespace, key): 579 def delGenPrivateBinary(self, namespace, key):
968 del extra['archive'] 968 del extra['archive']
969 except KeyError: 969 except KeyError:
970 # archive was not used 970 # archive was not used
971 pass 971 pass
972 972
973 queries.append(("UPDATE history SET received_timestamp=?,extra=? WHERE uid=?",(id_, received_timestamp, pickle.dumps(extra, 0)))) 973 queries.append(("UPDATE history SET received_timestamp=?,extra=? WHERE uid=?",(id_, received_timestamp, sqlite3.Binary(pickle.dumps(extra, 0)))))
974 974
975 yield self.dbpool.runInteraction(updateHistory, queries) 975 yield self.dbpool.runInteraction(updateHistory, queries)
976 976
977 log.info("Dropping temporary table") 977 log.info("Dropping temporary table")
978 yield self.dbpool.runQuery("DROP TABLE tmp_sat_update") 978 yield self.dbpool.runQuery("DROP TABLE tmp_sat_update")