seq#
Move the database’s cursor and read the key and value it lands on: walk the database in order, or find the first key at or after a given one.
Synopsis#
my ($key, $value) = ('', '');
my $status = $db->seq($key, $value, R_FIRST);
What you get back#
0 with $key and $value set to where the cursor landed, 1 when there is nothing there (past either end, or no such key), -1 for an error. On 1 the cursor stays where it was. For an array, $key is an index.
Flags#
R_FIRST,R_LAST- the first or last key.R_NEXT,R_PREV- the key after or before the cursor; from no cursor yet, the first or the last.R_CURSOR- in a$DB_BTREEdatabase the first key at or after$key; in a$DB_HASHdatabase$keyitself; in an array element$key.
Examples#
Walk a database in order:
my ($k, $v) = ('', '');
for (my $st = $db->seq($k, $v, R_FIRST); $st == 0; $st = $db->seq($k, $v, R_NEXT)) {
print "$k=$v\n";
}
Find the first key starting with Wa in a $DB_BTREE database:
@h{qw(Smith Wall Walls)} = (1, 2, 3);
my ($k, $v) = ('Wa', '');
print "$k\n" if $db->seq($k, $v, R_CURSOR) == 0 and $k =~ /^Wa/; # Wall
Edge cases#
$keyand$valuemust be variables: the method writes them.Array elements created empty are passed over;
R_CURSORon one returns-30995(Berkeley DB’sDB_KEYEMPTY).In an
R_DUPdatabaseR_NEXTandR_PREVstep through a key’s values one by one, in the order they were stored.The tie interface (
keys,each) moves the same cursor.
Differences from upstream#
Fully compatible with upstream. Covered by t/81-xs-native/DB_File/010-phenotype.t.
See also#
get- looks up one key without moving the cursordelandput- act at the cursor withR_CURSORget_dup- all the values of a key