示例#1
0
 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
示例#2
0
 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
示例#3
0
 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()
示例#4
0
文件: wt.py 项目: pombredanne/AjguDB
 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
示例#5
0
文件: wt.py 项目: pombredanne/AjguDB
    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
示例#6
0
 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())
示例#7
0
 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())
示例#8
0
 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())
示例#9
0
 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())
示例#10
0
 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())
示例#11
0
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
示例#12
0
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
示例#13
0
    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
示例#14
0
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)
示例#15
0
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)
示例#16
0
文件: wt.py 项目: pombredanne/AjguDB
 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
示例#17
0
 def get_values(self):
 	'''get_values(self) -> (object, ...)
 	
 	@copydoc WT_ASYNC_OP::get_value'''
 	return unpack(self.value_format, self._get_value())
示例#18
0
 def get_values(self):
 	'''get_values(self) -> (object, ...)
 	
 	@copydoc WT_CURSOR::get_value'''
 	return unpack(self.value_format, self._get_value())
示例#19
0
 def debug(self):
     for key, value in self.tuples.iterator():
         uid, key = unpack(key)
         value = unpack(value)[0]
         print(uid, key, value)