* add stubs for statistics cursors * more configuration checking * remove "_table" suffix from WT_SESSION methods, make "table:" part of the object name so the same methods can work on indices or column sets in the future refs #28 --HG-- rename : src/api/cur_btree.c => src/api/cur_stat.c
56 lines
1.3 KiB
C
56 lines
1.3 KiB
C
/*-
|
|
* See the file LICENSE for redistribution information.
|
|
*
|
|
* Copyright (c) 2008-2011 WiredTiger, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* ex_access.c
|
|
* demonstrates how to create and access a simple table.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include <wiredtiger.h>
|
|
|
|
const char *home = "WT_TEST";
|
|
|
|
int main(void)
|
|
{
|
|
int ret;
|
|
WT_CONNECTION *conn;
|
|
WT_SESSION *session;
|
|
WT_CURSOR *cursor;
|
|
const char *key, *value;
|
|
|
|
if ((ret = wiredtiger_open(home, NULL, "create", &conn)) != 0 ||
|
|
(ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
|
|
fprintf(stderr, "Error connecting to %s: %s\n",
|
|
home, wiredtiger_strerror(ret));
|
|
/* Note: further error checking omitted for clarity. */
|
|
|
|
ret = session->create(session, "table:access",
|
|
"key_format=S,value_format=S");
|
|
|
|
ret = session->open_cursor(session, "table:access",
|
|
NULL, NULL, &cursor);
|
|
|
|
/* Insert a record. */
|
|
cursor->set_key(cursor, "key1");
|
|
cursor->set_value(cursor, "value1");
|
|
ret = cursor->insert(cursor);
|
|
|
|
/* Show all records. */
|
|
for (ret = cursor->first(cursor);
|
|
ret == 0;
|
|
ret = cursor->next(cursor)) {
|
|
ret = cursor->get_key(cursor, &key);
|
|
ret = cursor->get_value(cursor, &value);
|
|
|
|
printf("Got record: %s : %s\n", key, value);
|
|
}
|
|
|
|
ret = conn->close(conn, NULL);
|
|
|
|
return (ret);
|
|
}
|