Version 1.4.2
wiredtiger.Cursor Class Reference

Python wrapper around C WT_CURSOR. More...

Inherits object.

Public Member Functions

def __init__
 
def next
 next(self) -> int
 
def prev
 prev(self) -> int
 
def reset
 reset(self) -> int
 
def search
 search(self) -> int
 
def insert
 insert(self) -> int
 
def update
 update(self) -> int
 
def remove
 remove(self) -> int
 
def close
 close(self, config) -> int
 
def compare
 compare(self, other) -> int
 
def search_near
 search_near(self) -> int
 
def get_key
 get_key(self) -> object
 
def get_keys
 get_keys(self) -> (object, ...)
 
def get_value
 get_value(self) -> object
 
def get_values
 get_values(self) -> (object, ...)
 
def set_key
 set_key(self) -> None
 
def set_value
 set_value(self) -> None
 
def __iter__
 Cursor objects support iteration, equivalent to calling WT_CURSOR::next until it returns WT_NOTFOUND.
 
def __getitem__
 Python convenience for searching.
 

Public Attributes

 this
 

Static Public Attributes

tuple thisown
 
tuple session
 
tuple uri
 

Detailed Description

Python wrapper around C WT_CURSOR.

Member Function Documentation

def wiredtiger.Cursor.__iter__ (   self)

Cursor objects support iteration, equivalent to calling WT_CURSOR::next until it returns WT_NOTFOUND.

def wiredtiger.Cursor.close (   self,
  args 
)

close(self, config) -> int

Close the cursor. This releases the resources associated with the cursor handle. Cursors are closed implicitly by ending the enclosing connection or closing the session in which they were opened.

ret = cursor->close(cursor);
Parameters
cursorthe cursor handle
Returns
zero on success and a non-zero error code on failure. See Error Returns for details.

def wiredtiger.Cursor.get_key (   self)

get_key(self) -> object

Get the key for the current record.

const char *key; /* Get the cursor's string key. */
ret = cursor->get_key(cursor, &key);
uint64_t recno; /* Get the cursor's record number key. */
ret = cursor->get_key(cursor, &recno);
Parameters
cursorthe cursor handle
...pointers to hold key fields corresponding to WT_CURSOR::key_format.
Returns
zero on success and a non-zero error code on failure. See Error Returns for details.
Returns only the first column.

def wiredtiger.Cursor.get_keys (   self)

get_keys(self) -> (object, ...)

Get the key for the current record.

const char *key; /* Get the cursor's string key. */
ret = cursor->get_key(cursor, &key);
uint64_t recno; /* Get the cursor's record number key. */
ret = cursor->get_key(cursor, &recno);
Parameters
cursorthe cursor handle
...pointers to hold key fields corresponding to WT_CURSOR::key_format.
Returns
zero on success and a non-zero error code on failure. See Error Returns for details.

def wiredtiger.Cursor.get_value (   self)

get_value(self) -> object

Get the value for the current record.

const char *value; /* Get the cursor's string value. */
ret = cursor->get_value(cursor, &value);
WT_ITEM value; /* Get the cursor's raw value. */
ret = cursor->get_value(cursor, &value);
Parameters
cursorthe cursor handle
...pointers to hold value fields corresponding to WT_CURSOR::value_format.
Returns
zero on success and a non-zero error code on failure. See Error Returns for details.
Returns only the first column.

def wiredtiger.Cursor.get_values (   self)

get_values(self) -> (object, ...)

Get the value for the current record.

const char *value; /* Get the cursor's string value. */
ret = cursor->get_value(cursor, &value);
WT_ITEM value; /* Get the cursor's raw value. */
ret = cursor->get_value(cursor, &value);
Parameters
cursorthe cursor handle
...pointers to hold value fields corresponding to WT_CURSOR::value_format.
Returns
zero on success and a non-zero error code on failure. See Error Returns for details.

def wiredtiger.Cursor.insert (   self,
  args 
)

insert(self) -> int

Insert a record, and optionally overwrite an existing record. If the cursor was not configured with "append" or "overwrite", both the key and value must be set and the record must not already exist; the record will be inserted.If the cursor was configured with "overwrite", both the key and value must be set; if the record already exists, the key's value will be updated, otherwise, the record will be inserted.If a cursor with record number keys was configured with "append", the value must be set; a new record will be appended and the record number set as the cursor key value.Inserting a new record after the current maximum record in a fixed-length bit field column-store (that is, a store with an 'r' type key and 't' type value) implicitly creates the missing records as records with a value of 0.

/* Insert a new record. */
const char *key = "some key", *value = "some value";
cursor->set_key(cursor, key);
cursor->set_value(cursor, value);
ret = cursor->insert(cursor);
/* Insert a new record or overwrite an existing record. */
ret = session->open_cursor(
session, "table:mytable", NULL, "overwrite", &cursor);
cursor->set_key(cursor, key);
cursor->set_value(cursor, value);
ret = cursor->insert(cursor);
/* Insert a new record and assign a record number. */
uint64_t recno;
const char *value = "some value";
ret = session->open_cursor(
session, "table:mytable", NULL, "append", &cursor);
cursor->set_value(cursor, value);
ret = cursor->insert(cursor);
if (ret == 0)
ret = cursor->get_key(cursor, &recno);
Parameters
cursorthe cursor handle
Returns
zero on success and a non-zero error code on failure. See Error Returns for details.

def wiredtiger.Cursor.next (   self,
  args 
)

next(self) -> int

Return the next record.

ret = cursor->next(cursor);
Parameters
cursorthe cursor handle
Returns
zero on success and a non-zero error code on failure. See Error Returns for details.

def wiredtiger.Cursor.prev (   self,
  args 
)

prev(self) -> int

Return the previous record.

ret = cursor->prev(cursor);
Parameters
cursorthe cursor handle
Returns
zero on success and a non-zero error code on failure. See Error Returns for details.

def wiredtiger.Cursor.remove (   self,
  args 
)

remove(self) -> int

Remove a record. The key must be set, and the key's record will be removed.Removing a record in a fixed-length bit field column-store (that is, a store with an 'r' type key and 't' type value) is identical to setting the record's value to 0.

const char *key = "some key";
cursor->set_key(cursor, key);
ret = cursor->remove(cursor);
Parameters
cursorthe cursor handle
Returns
zero on success and a non-zero error code on failure. See Error Returns for details. In particular, if no record with the specified key exists, WT_NOTFOUND is returned.

def wiredtiger.Cursor.reset (   self,
  args 
)

reset(self) -> int

Reset the position of the cursor. Any resources held by the cursor are released, and the cursor's key and position are no longer valid. A subsequent iteration with WT_CURSOR::next will move to the first record, or with WT_CURSOR::prev will move to the last record.

ret = cursor->reset(cursor);
Parameters
cursorthe cursor handle
Returns
zero on success and a non-zero error code on failure. See Error Returns for details.

def wiredtiger.Cursor.search (   self,
  args 
)

search(self) -> int

Move to the record matching the key. The key must first be set.

const char *key = "some key";
cursor->set_key(cursor, key);
ret = cursor->search(cursor);
Parameters
cursorthe cursor handle
Returns
zero on success and a non-zero error code on failure. See Error Returns for details.

def wiredtiger.Cursor.set_key (   self,
  args 
)

set_key(self) -> None

Set the key for the next operation.

/* Set the cursor's string key. */
const char *key = "another key";
cursor->set_key(cursor, key);
uint64_t recno = 37; /* Set the cursor's record number key. */
cursor->set_key(cursor, recno);
Parameters
cursorthe cursor handle
...key fields corresponding to WT_CURSOR::key_format.

If an error occurs during this operation, a flag will be set in the cursor, and the next operation to access the key will fail. This simplifies error handling in applications.

def wiredtiger.Cursor.set_value (   self,
  args 
)

set_value(self) -> None

Set the value for the next operation.

/* Set the cursor's string value. */
const char *value = "another value";
cursor->set_value(cursor, value);
WT_ITEM value; /* Set the cursor's raw value. */
value.data = "another value";
value.size = strlen("another value");
cursor->set_value(cursor, &value);
Parameters
cursorthe cursor handle
...value fields corresponding to WT_CURSOR::value_format.

If an error occurs during this operation, a flag will be set in the cursor, and the next operation to access the value will fail. This simplifies error handling in applications.

def wiredtiger.Cursor.update (   self,
  args 
)

update(self) -> int

Update a record. Both key and value must be set, the key must exist, and the value of the key's record will be updated.

const char *key = "some key", *value = "some value";
cursor->set_key(cursor, key);
cursor->set_value(cursor, value);
ret = cursor->update(cursor);
Parameters
cursorthe cursor handle
Returns
zero on success and a non-zero error code on failure. See Error Returns for details. In particular, if no record with the specified key exists, WT_NOTFOUND is returned.