int main(int argc, char *argv[]) { WT_CONNECTION *conn; WT_CURSOR *cursor; WT_SESSION *session; home = example_setup(argc, argv); /* Open a connection to the database, creating it if necessary. */ error_check(wiredtiger_open( home, NULL, "create,statistics=(fast)", &conn)); /* Open a session for the current thread's work. */ error_check(conn->open_session(conn, NULL, NULL, &session)); error_check(session->create(session, "table:world", "key_format=r,value_format=5sii," "columns=(id,country,population,area)")); /*! [open cursor #1] */ error_check(session->open_cursor( session, "table:world", NULL, NULL, &cursor)); /*! [open cursor #1] */ /*! [open cursor #2] */ error_check(session->open_cursor(session, "table:world(country,population)", NULL, NULL, &cursor)); /*! [open cursor #2] */ /*! [open cursor #3] */ error_check(session->open_cursor( session, "statistics:", NULL, NULL, &cursor)); /*! [open cursor #3] */ /* Create a simple string table to illustrate basic operations. */ error_check(session->create( session, "table:map", "key_format=S,value_format=S")); error_check(session->open_cursor( session, "table:map", NULL, NULL, &cursor)); error_check(cursor_insert(cursor)); error_check(cursor_reset(cursor)); error_check(cursor_forward_scan(cursor)); error_check(cursor_reset(cursor)); error_check(cursor_reverse_scan(cursor)); error_check(cursor_search_near(cursor)); error_check(cursor_update(cursor)); error_check(cursor_remove(cursor)); error_check(cursor->close(cursor)); /* Note: closing the connection implicitly closes open session(s). */ error_check(conn->close(conn, NULL)); return (EXIT_SUCCESS); }
int main(void) { WT_CONNECTION *conn; WT_CURSOR *cursor; WT_SESSION *session; int ret; /* Open a connection to the database, creating it if necessary. */ if ((ret = wiredtiger_open(home, NULL, "create", &conn)) != 0) fprintf(stderr, "Error connecting to %s: %s\n", home, wiredtiger_strerror(ret)); /* Open a session for the current thread's work. */ if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) fprintf(stderr, "Error opening a session on %s: %s\n", home, wiredtiger_strerror(ret)); ret = session->create(session, "table:world", "key_format=r,value_format=5sii," "columns=(id,country,population,area)"); /*! [open cursor #1] */ ret = session->open_cursor(session, "table:world", NULL, NULL, &cursor); /*! [open cursor #1] */ /*! [open cursor #2] */ ret = session->open_cursor(session, "table:world(country,population)", NULL, NULL, &cursor); /*! [open cursor #2] */ /*! [open cursor #3] */ ret = session->open_cursor(session, "statistics:", NULL, NULL, &cursor); /*! [open cursor #3] */ /* Create a simple string table to illustrate basic operations. */ 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_update(cursor); ret = cursor_remove(cursor); ret = cursor->close(cursor); /* Note: closing the connection implicitly closes open session(s). */ if ((ret = conn->close(conn, NULL)) != 0) fprintf(stderr, "Error connecting to %s: %s\n", home, wiredtiger_strerror(ret)); return (ret); }
/* * move_data_ahead -- * Update the tables with new data and take a checkpoint twice. * WiredTiger keeps the previous checkpoint so we do it twice so that * the old checkpoint address no longer exists. */ static void move_data_ahead(TABLE_INFO *table_data) { TABLE_INFO *t; uint64_t i; i = 0; while (i < CKPT_DISTANCE) { ++data_val; for (t = table_data; t->name != NULL; t++) cursor_insert(t->name, data_val); ++i; fprintf(stderr, "MOVE DATA: inserted %" PRIu64 ". CKPT.\n", data_val); testutil_check(wt_session->checkpoint(wt_session, NULL)); } }
/* * create_data -- * Create a table and insert a piece of data. */ static void create_data(TABLE_INFO *t) { size_t len; uint64_t i; char buf[APP_BUF_SIZE], cfg[APP_MD_SIZE]; memset(buf, 0, sizeof(buf)); memset(cfg, 0, sizeof(cfg)); /* * Create an app-specific metadata string that fills most of page * so that each table in the metadata has its own page. */ len = strlen(APP_STR); for (i = 0; i + len < APP_BUF_SIZE; i += len) testutil_check(__wt_snprintf( &buf[i], APP_BUF_SIZE - i, "%s", APP_STR)); testutil_check(__wt_snprintf(cfg, sizeof(cfg), "%s,app_metadata=\"%s\"", t->kvformat, buf)); testutil_check(wt_session->create(wt_session, t->name, cfg)); data_val = 1; cursor_insert(t->name, data_val); }
int main(void) { WT_CONNECTION *conn; WT_CURSOR *cursor; WT_SESSION *session; int ret; /* * Create a clean test directory for this run of the test program if the * environment variable isn't already set (as is done by make check). */ if (getenv("WIREDTIGER_HOME") == NULL) { home = "WT_HOME"; ret = system("rm -rf WT_HOME && mkdir WT_HOME"); } else home = NULL; /* Open a connection to the database, creating it if necessary. */ if ((ret = wiredtiger_open( home, NULL, "create,statistics=(fast)", &conn)) != 0) fprintf(stderr, "Error connecting to %s: %s\n", home == NULL ? "." : home, wiredtiger_strerror(ret)); /* Open a session for the current thread's work. */ if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) fprintf(stderr, "Error opening a session on %s: %s\n", home == NULL ? "." : home, wiredtiger_strerror(ret)); ret = session->create(session, "table:world", "key_format=r,value_format=5sii," "columns=(id,country,population,area)"); /*! [open cursor #1] */ ret = session->open_cursor(session, "table:world", NULL, NULL, &cursor); /*! [open cursor #1] */ /*! [open cursor #2] */ ret = session->open_cursor(session, "table:world(country,population)", NULL, NULL, &cursor); /*! [open cursor #2] */ /*! [open cursor #3] */ ret = session->open_cursor(session, "statistics:", NULL, NULL, &cursor); /*! [open cursor #3] */ /* Create a simple string table to illustrate basic operations. */ 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); /* Note: closing the connection implicitly closes open session(s). */ if ((ret = conn->close(conn, NULL)) != 0) { fprintf(stderr, "Error closing %s: %s\n", home == NULL ? "." : home, wiredtiger_strerror(ret)); return (EXIT_FAILURE); } return (EXIT_SUCCESS); }