Shows some common cursor types and operations.
#include <stdio.h>
#include <string.h>
#include <wiredtiger.h>
const char *home = NULL;
int
{
const char *key, *value;
int ret;
while ((ret = cursor->
next(cursor)) == 0) {
ret = cursor->
get_key(cursor, &key);
}
return (ret);
}
int
{
const char *key, *value;
int ret;
while ((ret = cursor->
prev(cursor)) == 0) {
ret = cursor->
get_key(cursor, &key);
}
return (ret);
}
int
{
return (cursor->
reset(cursor));
}
int
{
const char *value;
int ret;
if ((ret = cursor->
search(cursor)) != 0)
return (ret);
}
int
{
const char *key, *value;
int exact, ret;
if ((ret = cursor->
search_near(cursor, &exact)) == 0) {
switch (exact) {
case -1:
ret = cursor->
get_key(cursor, &key);
break;
case 0:
break;
case 1:
ret = cursor->
get_key(cursor, &key);
break;
}
}
return (ret);
}
int
{
return (cursor->
insert(cursor));
}
int
{
return (cursor->
update(cursor));
}
int
{
return (cursor->
remove(cursor));
}
int main(void)
{
int ret;
home, NULL, "create,statistics=(fast)", &conn)) != 0)
fprintf(stderr, "Error connecting to %s: %s\n",
if ((ret = conn->
open_session(conn, NULL, NULL, &session)) != 0)
fprintf(stderr, "Error opening a session on %s: %s\n",
ret = session->
create(session,
"table:world",
"key_format=r,value_format=5sii,"
"columns=(id,country,population,area)");
ret = session->
open_cursor(session,
"table:world", NULL, NULL, &cursor);
"table:world(country,population)", NULL, NULL, &cursor);
ret = session->
open_cursor(session,
"statistics:", NULL, NULL, &cursor);
ret = session->
create(session,
"table:map",
"key_format=S,value_format=S");
ret = session->
open_cursor(session,
"table:map", NULL, NULL, &cursor);
ret = cursor_insert(cursor);
ret = cursor_reset(cursor);
ret = cursor_forward_scan(cursor);
ret = cursor_reset(cursor);
ret = cursor_reverse_scan(cursor);
ret = cursor_search_near(cursor);
ret = cursor_update(cursor);
ret = cursor_remove(cursor);
ret = cursor->
close(cursor);
if ((ret = conn->
close(conn, NULL)) != 0)
fprintf(stderr, "Error connecting to %s: %s\n",
return (ret);
}