def postgresql_load_current(self, cursor, oid): """Returns the current pickle and integer tid for an object. oid is an integer. Returns (None, None) if object does not exist. """ if self.keep_history: stmt = """ SELECT encode(state, 'base64'), tid FROM current_object JOIN object_state USING(zoid, tid) WHERE zoid = %s """ else: stmt = """ SELECT encode(state, 'base64'), tid FROM object_state WHERE zoid = %s """ cursor.execute(stmt, (oid,)) if cursor.rowcount: assert cursor.rowcount == 1 state64, tid = cursor.fetchone() if state64 is not None: state = decodestring(state64) else: # This object's creation has been undone state = None return state, tid else: return None, None
def postgresql_load_before(self, cursor, oid, tid): """Returns the pickle and tid of an object before transaction tid. Returns (None, None) if no earlier state exists. """ stmt = """ SELECT encode(state, 'base64'), tid FROM object_state WHERE zoid = %s AND tid < %s ORDER BY tid DESC LIMIT 1 """ cursor.execute(stmt, (oid, tid)) if cursor.rowcount: assert cursor.rowcount == 1 state64, tid = cursor.fetchone() if state64 is not None: state = decodestring(state64) else: # The object's creation has been undone state = None return state, tid else: return None, None
def postgresql_detect_conflict(self, cursor): """Find one conflict in the data about to be committed. If there is a conflict, returns (oid, prev_tid, attempted_prev_tid, attempted_data). If there is no conflict, returns None. """ if self.keep_history: stmt = """ SELECT temp_store.zoid, current_object.tid, temp_store.prev_tid, encode(temp_store.state, 'base64') FROM temp_store JOIN current_object ON (temp_store.zoid = current_object.zoid) WHERE temp_store.prev_tid != current_object.tid LIMIT 1 """ else: stmt = """ SELECT temp_store.zoid, object_state.tid, temp_store.prev_tid, encode(temp_store.state, 'base64') FROM temp_store JOIN object_state ON (temp_store.zoid = object_state.zoid) WHERE temp_store.prev_tid != object_state.tid LIMIT 1 """ cursor.execute(stmt) if cursor.rowcount: oid, prev_tid, attempted_prev_tid, data = cursor.fetchone() return oid, prev_tid, attempted_prev_tid, decodestring(data) return None
def postgresql_load_current(self, cursor, oid): """Returns the current pickle and integer tid for an object. oid is an integer. Returns (None, None) if object does not exist. """ if self.keep_history: stmt = """ SELECT encode(state, 'base64'), tid FROM current_object JOIN object_state USING(zoid, tid) WHERE zoid = %s """ else: stmt = """ SELECT encode(state, 'base64'), tid FROM object_state WHERE zoid = %s """ cursor.execute(stmt, (oid, )) if cursor.rowcount: assert cursor.rowcount == 1 state64, tid = cursor.fetchone() if state64 is not None: state = decodestring(state64) else: # This object's creation has been undone state = None return state, tid else: return None, None
def decode_bytes_param(value, use_base64): if not isinstance(value, bytes): value = value.encode('latin1') if use_base64: value = decodestring(value) return value
def postgresql_load_revision(self, cursor, oid, tid): """Returns the pickle for an object on a particular transaction. Returns None if no such state exists. """ stmt = """ SELECT encode(state, 'base64') FROM object_state WHERE zoid = %s AND tid = %s """ cursor.execute(stmt, (oid, tid)) if cursor.rowcount: assert cursor.rowcount == 1 (state64,) = cursor.fetchone() if state64 is not None: return decodestring(state64) return None
def postgresql_load_revision(self, cursor, oid, tid): """Returns the pickle for an object on a particular transaction. Returns None if no such state exists. """ stmt = """ SELECT encode(state, 'base64') FROM object_state WHERE zoid = %s AND tid = %s """ cursor.execute(stmt, (oid, tid)) if cursor.rowcount: assert cursor.rowcount == 1 (state64, ) = cursor.fetchone() if state64 is not None: return decodestring(state64) return None
def decode_bytes_param(value, use_base64): value = str(value) if use_base64: value = decodestring(value) return value