def __get(): for key, value in self.tuples.iterator(start=pack(uid)): other, key = unpack(key) if other == uid: value = unpack(value)[0] yield key, value else: break
def ref(self, uid, key): match = [uid, key] for key, value in self.tuples.iterator(start=pack(uid, key)): other = unpack(key) if other == match: value = unpack(value)[0] return value else: return None
def delete(self, uid): tuples = self.tuples.write_batch(transaction=True) index = self.index.write_batch(transaction=True) for key, value in self.tuples.iterator(start=pack(uid)): other, name = unpack(key) if uid == other: tuples.delete(key) value = unpack(value)[0] index.delete(pack(name, value, uid)) else: break tuples.write() index.write()
def ref(self, uid, key): with self.tuples() as cursor: cursor.set_key(uid, key) if cursor.search() != WT_NOT_FOUND: value = cursor.get_value() value = unpack(value)[0] return value
def query(self, key, value=''): with self.index() as cursor: match = (key, value) if value else (key,) cursor.set_key(key, pack(value), 0) code = cursor.search_near() if code == WT_NOT_FOUND: return if code == -1: if cursor.next() == WT_NOT_FOUND: return while True: key, value, uid = cursor.get_key() value = unpack(value)[0] other = (key, value) ok = reduce( lambda previous, x: (cmp(*x) == 0) and previous, zip(match, other), True ) if ok: yield [key, value, uid] if cursor.next() == WT_NOT_FOUND: break else: break
def get_keys(self): '''get_keys(self) -> (object, ...) @copydoc WT_CURSOR::get_key''' if self.is_column: return [self._get_recno(),] else: return unpack(self.key_format, self._get_key())
def get_keys(self): '''get_keys(self) -> (object, ...) @copydoc WT_ASYNC_OP::get_key''' if self.is_column: return [self._get_recno(),] else: return unpack(self.key_format, self._get_key())
def get_values(self): '''get_values(self) -> (object, ...) @copydoc WT_CURSOR::get_value''' if self.is_json: return [self._get_json_value()] else: return unpack(self.value_format, self._get_value())
def get_keys(self): '''get_keys(self) -> (object, ...) @copydoc WT_CURSOR::get_key''' if self.is_json: return [self._get_json_key()] elif self.is_column: return [self._get_recno(),] else: return unpack(self.key_format, self._get_key())
def check_common(fmt, verbose, *v): v = list(v) packed = pack(fmt, *v) unpacked = unpack(fmt, packed) if unpacked == v: result = 'ok' else: result = '** FAIL!' print '* %s as %s: %s' % (repr(v), fmt, result) if verbose or unpacked != v: print '** packed: ', ''.join('%02x' % ord(c) for c in packed) print '** unpacked: ', unpacked
def query(self, key, value=''): match = (key, value) if value else (key,) iterator = self.index.iterator(start=pack(key, value)) for key, value in iterator: other = unpack(key) ok = reduce( lambda previous, x: (cmp(*x) == 0) and previous, zip(match, other), True ) if ok: yield other else: break
def decode_arg(arg, allocsize): addr = arg.decode("hex") version = ord(addr[0]) print arg + ': ' if version != 1: print '**** ERROR: unknown version ' + str(version) addr = addr[1:] result = unpack('iiiiiiiiiiiiii', addr) if len(result) != 14: print '**** ERROR: result len unexpected: ' + str(len(result)) show_triple(result[0:3], 'root', allocsize) show_triple(result[3:6], 'alloc', allocsize) show_triple(result[6:9], 'avail', allocsize) show_triple(result[9:12], 'discard', allocsize) file_size = result[12] ckpt_size = result[13] show_one('file size', file_size) show_one('checkpoint size', ckpt_size)
def decode_arg(arg, allocsize): addr = arg.decode("hex") version = ord(addr[0]) print arg + ': ' if version != 1: print '**** ERROR: unknown version ' + str(version) addr = addr[1:] result = unpack('iiiiiiiiiiiiii',addr) if len(result) != 14: print '**** ERROR: result len unexpected: ' + str(len(result)) show_triple(result[0:3], 'root', allocsize) show_triple(result[3:6], 'alloc', allocsize) show_triple(result[6:9], 'avail', allocsize) show_triple(result[9:12], 'discard', allocsize) file_size = result[12] ckpt_size = result[13] show_one('file size', file_size) show_one('checkpoint size', ckpt_size)
def __get(): with self.tuples() as cursor: cursor.set_key(uid, '') code = cursor.search_near() if code == WT_NOT_FOUND: return if code == -1: if cursor.next() == WT_NOT_FOUND: return while True: other, key = cursor.get_key() value = cursor.get_value() if other == uid: value = unpack(value)[0] yield key, value if cursor.next() == WT_NOT_FOUND: break else: break
def get_values(self): '''get_values(self) -> (object, ...) @copydoc WT_ASYNC_OP::get_value''' return unpack(self.value_format, self._get_value())
def get_values(self): '''get_values(self) -> (object, ...) @copydoc WT_CURSOR::get_value''' return unpack(self.value_format, self._get_value())
def debug(self): for key, value in self.tuples.iterator(): uid, key = unpack(key) value = unpack(value)[0] print(uid, key, value)