static int cursor_ops(WT_SESSION *session) { WT_CURSOR *cursor; int ret; /*! [Open a cursor] */ error_check(session->open_cursor( session, "table:mytable", NULL, NULL, &cursor)); /*! [Open a cursor] */ /*! [Open a cursor on the metadata] */ error_check(session->open_cursor( session, "metadata:", NULL, NULL, &cursor)); /*! [Open a cursor on the metadata] */ { const char *key = "some key", *value = "some value"; /*! [Reconfigure a cursor] */ error_check(session->open_cursor( session, "table:mytable", NULL, "overwrite=false", &cursor)); /* Reconfigure the cursor to overwrite the record. */ error_check(cursor->reconfigure(cursor, "overwrite=true")); cursor->set_key(cursor, key); cursor->set_value(cursor, value); error_check(cursor->insert(cursor)); /*! [Reconfigure a cursor] */ } { WT_CURSOR *duplicate; const char *key = "some key"; /*! [Duplicate a cursor] */ error_check(session->open_cursor( session, "table:mytable", NULL, NULL, &cursor)); cursor->set_key(cursor, key); error_check(cursor->search(cursor)); /* Duplicate the cursor. */ error_check( session->open_cursor(session, NULL, cursor, NULL, &duplicate)); /*! [Duplicate a cursor] */ } { /*! [boolean configuration string example] */ error_check(session->open_cursor( session, "table:mytable", NULL, "overwrite", &cursor)); error_check(session->open_cursor( session, "table:mytable", NULL, "overwrite=true", &cursor)); error_check(session->open_cursor( session, "table:mytable", NULL, "overwrite=1", &cursor)); /*! [boolean configuration string example] */ } error_check(session->checkpoint(session, "name=midnight")); { /*! [open a named checkpoint] */ error_check(session->open_cursor(session, "table:mytable", NULL, "checkpoint=midnight", &cursor)); /*! [open a named checkpoint] */ } { /*! [open the default checkpoint] */ error_check(session->open_cursor(session, "table:mytable", NULL, "checkpoint=WiredTigerCheckpoint", &cursor)); /*! [open the default checkpoint] */ } { /*! [Set the cursor's string key] */ /* Set the cursor's string key. */ const char *key = "another key"; cursor->set_key(cursor, key); /*! [Set the cursor's string key] */ } { /*! [Get the cursor's string key] */ const char *key; /* Get the cursor's string key. */ error_check(cursor->get_key(cursor, &key)); /*! [Get the cursor's string key] */ } /* Switch to a recno table. */ error_check(session->create( session, "table:recno", "key_format=r,value_format=S")); error_check(session->open_cursor( session, "table:recno", NULL, NULL, &cursor)); { /*! [Set the cursor's record number key] */ uint64_t recno = 37; /* Set the cursor's record number key. */ cursor->set_key(cursor, recno); /*! [Set the cursor's record number key] */ } { /*! [Get the cursor's record number key] */ uint64_t recno; /* Get the cursor's record number key. */ error_check(cursor->get_key(cursor, &recno)); /*! [Get the cursor's record number key] */ } /* Switch to a composite table. */ error_check(session->create( session, "table:composite", "key_format=SiH,value_format=S")); error_check(session->open_cursor( session, "table:recno", NULL, NULL, &cursor)); { /*! [Set the cursor's composite key] */ /* Set the cursor's "SiH" format composite key. */ cursor->set_key(cursor, "first", (int32_t)5, (uint16_t)7); /*! [Set the cursor's composite key] */ } { /*! [Get the cursor's composite key] */ /* Get the cursor's "SiH" format composite key. */ const char *first; int32_t second; uint16_t third; error_check(cursor->get_key(cursor, &first, &second, &third)); /*! [Get the cursor's composite key] */ } { /*! [Set the cursor's string value] */ /* Set the cursor's string value. */ const char *value = "another value"; cursor->set_value(cursor, value); /*! [Set the cursor's string value] */ } { /*! [Get the cursor's string value] */ const char *value; /* Get the cursor's string value. */ error_check(cursor->get_value(cursor, &value)); /*! [Get the cursor's string value] */ } { /*! [Get the cursor's raw value] */ WT_ITEM value; /* Get the cursor's raw value. */ error_check(cursor->get_value(cursor, &value)); /*! [Get the cursor's raw value] */ } { /*! [Set the cursor's raw value] */ WT_ITEM value; /* Set the cursor's raw value. */ value.data = "another value"; value.size = strlen("another value"); cursor->set_value(cursor, &value); /*! [Set the cursor's raw value] */ error_check(cursor->insert(cursor)); } /*! [Return the next record] */ error_check(cursor->next(cursor)); /*! [Return the next record] */ /*! [Reset the cursor] */ error_check(cursor->reset(cursor)); /*! [Reset the cursor] */ /*! [Return the previous record] */ error_check(cursor->prev(cursor)); /*! [Return the previous record] */ { WT_CURSOR *other = NULL; error_check( session->open_cursor(session, NULL, cursor, NULL, &other)); { /*! [Cursor comparison] */ int compare; error_check(cursor->compare(cursor, other, &compare)); if (compare == 0) { /* Cursors reference the same key */ } else if (compare < 0) { /* Cursor key less than other key */ } else if (compare > 0) { /* Cursor key greater than other key */ } /*! [Cursor comparison] */ } { /*! [Cursor equality] */ int equal; error_check(cursor->equals(cursor, other, &equal)); if (equal) { /* Cursors reference the same key */ } /*! [Cursor equality] */ } } { /*! [Insert a new record or overwrite an existing record] */ /* Insert a new record or overwrite an existing record. */ const char *key = "some key", *value = "some value"; error_check(session->open_cursor( session, "table:mytable", NULL, NULL, &cursor)); cursor->set_key(cursor, key); cursor->set_value(cursor, value); error_check(cursor->insert(cursor)); /*! [Insert a new record or overwrite an existing record] */ } { /*! [Search for an exact match] */ const char *key = "some key"; cursor->set_key(cursor, key); error_check(cursor->search(cursor)); /*! [Search for an exact match] */ } cursor_search_near(cursor); { /*! [Insert a new record and fail if the record exists] */ /* Insert a new record and fail if the record exists. */ const char *key = "new key", *value = "some value"; error_check(session->open_cursor( session, "table:mytable", NULL, "overwrite=false", &cursor)); cursor->set_key(cursor, key); cursor->set_value(cursor, value); error_check(cursor->insert(cursor)); /*! [Insert a new record and fail if the record exists] */ } error_check(session->open_cursor( session, "table:recno", NULL, "append", &cursor)); { /*! [Insert a new record and assign a record number] */ /* Insert a new record and assign a record number. */ uint64_t recno; const char *value = "some value"; cursor->set_value(cursor, value); error_check(cursor->insert(cursor)); error_check(cursor->get_key(cursor, &recno)); /*! [Insert a new record and assign a record number] */ } error_check(session->open_cursor( session, "table:mytable", NULL, NULL, &cursor)); { /*! [Reserve a record] */ const char *key = "some key"; error_check(session->begin_transaction(session, NULL)); cursor->set_key(cursor, key); error_check(cursor->reserve(cursor)); error_check(session->commit_transaction(session, NULL)); /*! [Reserve a record] */ } error_check(session->create( session, "table:blob", "key_format=S,value_format=u")); error_check(session->open_cursor( session, "table:blob", NULL, NULL, &cursor)); { WT_ITEM value; value.data = "abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz"; value.size = strlen(value.data); cursor->set_key(cursor, "some key"); cursor->set_value(cursor, &value); error_check(cursor->insert(cursor)); } /* Modify requires an explicit transaction. */ error_check(session->begin_transaction(session, NULL)); { /*! [Modify an existing record] */ WT_MODIFY entries[3]; const char *key = "some key"; /* Position the cursor. */ cursor->set_key(cursor, key); error_check(cursor->search(cursor)); /* Replace 20 bytes starting at byte offset 5. */ entries[0].data.data = "some data"; entries[0].data.size = strlen(entries[0].data.data); entries[0].offset = 5; entries[0].size = 20; /* Insert data at byte offset 40. */ entries[1].data.data = "and more data"; entries[1].data.size = strlen(entries[1].data.data); entries[1].offset = 40; entries[1].size = 0; /* Replace 2 bytes starting at byte offset 10. */ entries[2].data.data = "and more data"; entries[2].data.size = strlen(entries[2].data.data); entries[2].offset = 10; entries[2].size = 2; error_check(cursor->modify(cursor, entries, 3)); /*! [Modify an existing record] */ } error_check(session->commit_transaction(session, NULL)); { /*! [Update an existing record or insert a new record] */ const char *key = "some key", *value = "some value"; error_check(session->open_cursor( session, "table:mytable", NULL, NULL, &cursor)); cursor->set_key(cursor, key); cursor->set_value(cursor, value); error_check(cursor->update(cursor)); /*! [Update an existing record or insert a new record] */ } { /*! [Update an existing record and fail if DNE] */ const char *key = "some key", *value = "some value"; error_check(session->open_cursor( session, "table:mytable", NULL, "overwrite=false", &cursor)); cursor->set_key(cursor, key); cursor->set_value(cursor, value); error_check(cursor->update(cursor)); /*! [Update an existing record and fail if DNE] */ } { /*! [Remove a record and fail if DNE] */ const char *key = "some key"; error_check(session->open_cursor( session, "table:mytable", NULL, "overwrite=false", &cursor)); cursor->set_key(cursor, key); error_check(cursor->remove(cursor)); /*! [Remove a record and fail if DNE] */ } { /*! [Remove a record] */ const char *key = "some key"; error_check(session->open_cursor( session, "table:mytable", NULL, NULL, &cursor)); cursor->set_key(cursor, key); error_check(cursor->remove(cursor)); /*! [Remove a record] */ } { /*! [Display an error] */ const char *key = "non-existent key"; cursor->set_key(cursor, key); if ((ret = cursor->remove(cursor)) != 0) { fprintf(stderr, "cursor.remove: %s\n", wiredtiger_strerror(ret)); return (ret); } /*! [Display an error] */ } { /*! [Display an error thread safe] */ const char *key = "non-existent key"; cursor->set_key(cursor, key); if ((ret = cursor->remove(cursor)) != 0) { fprintf(stderr, "cursor.remove: %s\n", cursor->session->strerror(cursor->session, ret)); return (ret); } /*! [Display an error thread safe] */ } /*! [Close the cursor] */ error_check(cursor->close(cursor)); /*! [Close the cursor] */ return (0); }
static void session_ops(WT_SESSION *session) { WT_CONNECTION *conn; conn = session->connection; /*! [Reconfigure a session] */ error_check(session->reconfigure(session, "isolation=snapshot")); /*! [Reconfigure a session] */ /*! [Create a table] */ error_check(session->create(session, "table:mytable", "key_format=S,value_format=S")); /*! [Create a table] */ error_check(session->drop(session, "table:mytable", NULL)); /*! [Create a column-store table] */ error_check(session->create(session, "table:mytable", "key_format=r,value_format=S")); /*! [Alter a table] */ error_check(session->alter(session, "table:mytable", "access_pattern_hint=random")); /*! [Alter a table] */ /*! [Create a column-store table] */ error_check(session->drop(session, "table:mytable", NULL)); /*! [Create a table with columns] */ /* * Create a table with columns: keys are record numbers, values are * (string, signed 32-bit integer, unsigned 16-bit integer). */ error_check(session->create(session, "table:mytable", "key_format=r,value_format=SiH," "columns=(id,department,salary,year-started)")); /*! [Create a table with columns] */ error_check(session->drop(session, "table:mytable", NULL)); /*! [Create a table and configure the page size] */ error_check(session->create(session, "table:mytable", "key_format=S,value_format=S," "internal_page_max=16KB,leaf_page_max=1MB,leaf_value_max=64KB")); /*! [Create a table and configure the page size] */ error_check(session->drop(session, "table:mytable", NULL)); /*! [Create a table and configure a large leaf value max] */ error_check(session->create(session, "table:mytable", "key_format=S,value_format=S," "leaf_page_max=16KB,leaf_value_max=256KB")); /*! [Create a table and configure a large leaf value max] */ error_check(session->drop(session, "table:mytable", NULL)); /* * This example code gets run, and the compression libraries might not * be loaded, causing the create to fail. The documentation requires * the code snippets, use #ifdef's to avoid running it. */ #ifdef MIGHT_NOT_RUN /*! [Create a lz4 compressed table] */ error_check(session->create(session, "table:mytable", "block_compressor=lz4,key_format=S,value_format=S")); /*! [Create a lz4 compressed table] */ error_check(session->drop(session, "table:mytable", NULL)); /*! [Create a snappy compressed table] */ error_check(session->create(session, "table:mytable", "block_compressor=snappy,key_format=S,value_format=S")); /*! [Create a snappy compressed table] */ error_check(session->drop(session, "table:mytable", NULL)); /*! [Create a zlib compressed table] */ error_check(session->create(session, "table:mytable", "block_compressor=zlib,key_format=S,value_format=S")); /*! [Create a zlib compressed table] */ error_check(session->drop(session, "table:mytable", NULL)); /*! [Create a zstd compressed table] */ error_check(session->create(session, "table:mytable", "block_compressor=zstd,key_format=S,value_format=S")); /*! [Create a zstd compressed table] */ error_check(session->drop(session, "table:mytable", NULL)); #endif /*! [Configure checksums to uncompressed] */ error_check(session->create(session, "table:mytable", "key_format=S,value_format=S,checksum=uncompressed")); /*! [Configure checksums to uncompressed] */ error_check(session->drop(session, "table:mytable", NULL)); /*! [Configure dictionary compression on] */ error_check(session->create(session, "table:mytable", "key_format=S,value_format=S,dictionary=1000")); /*! [Configure dictionary compression on] */ error_check(session->drop(session, "table:mytable", NULL)); /*! [Configure key prefix compression on] */ error_check(session->create(session, "table:mytable", "key_format=S,value_format=S,prefix_compression=true")); /*! [Configure key prefix compression on] */ error_check(session->drop(session, "table:mytable", NULL)); #ifdef MIGHT_NOT_RUN /* Requires sync_file_range */ /*! [os_cache_dirty_max configuration] */ error_check(session->create( session, "table:mytable", "os_cache_dirty_max=500MB")); /*! [os_cache_dirty_max configuration] */ error_check(session->drop(session, "table:mytable", NULL)); /* Requires posix_fadvise */ /*! [os_cache_max configuration] */ error_check(session->create( session, "table:mytable", "os_cache_max=1GB")); /*! [os_cache_max configuration] */ error_check(session->drop(session, "table:mytable", NULL)); #endif /*! [Configure block_allocation] */ error_check(session->create(session, "table:mytable", "key_format=S,value_format=S,block_allocation=first")); /*! [Configure block_allocation] */ error_check(session->drop(session, "table:mytable", NULL)); /*! [Create a cache-resident object] */ error_check(session->create( session, "table:mytable", "key_format=r,value_format=S,cache_resident=true")); /*! [Create a cache-resident object] */ error_check(session->drop(session, "table:mytable", NULL)); { /* Create a table for the session operations. */ error_check(session->create( session, "table:mytable", "key_format=S,value_format=S")); /*! [Compact a table] */ error_check(session->compact(session, "table:mytable", NULL)); /*! [Compact a table] */ /*! [Rebalance a table] */ error_check(session->rebalance(session, "table:mytable", NULL)); /*! [Rebalance a table] */ error_check(session->create( session, "table:old", "key_format=r,value_format=S,cache_resident=true")); /*! [Rename a table] */ error_check(session->rename(session, "table:old", "table:new", NULL)); /*! [Rename a table] */ /*! [Salvage a table] */ error_check(session->salvage(session, "table:mytable", NULL)); /*! [Salvage a table] */ /*! [Truncate a table] */ error_check(session->truncate( session, "table:mytable", NULL, NULL, NULL)); /*! [Truncate a table] */ /*! [Transaction sync] */ error_check(session->transaction_sync(session, NULL)); /*! [Transaction sync] */ /*! [Reset the session] */ error_check(session->reset(session)); /*! [Reset the session] */ { /* * Insert a pair of keys so we can truncate a range. */ WT_CURSOR *cursor; error_check(session->open_cursor( session, "table:mytable", NULL, NULL, &cursor)); cursor->set_key(cursor, "June01"); cursor->set_value(cursor, "value"); error_check(cursor->update(cursor)); cursor->set_key(cursor, "June30"); cursor->set_value(cursor, "value"); error_check(cursor->update(cursor)); error_check(cursor->close(cursor)); { /*! [Truncate a range] */ WT_CURSOR *start, *stop; error_check(session->open_cursor( session, "table:mytable", NULL, NULL, &start)); start->set_key(start, "June01"); error_check(start->search(start)); error_check(session->open_cursor( session, "table:mytable", NULL, NULL, &stop)); stop->set_key(stop, "June30"); error_check(stop->search(stop)); error_check(session->truncate(session, NULL, start, stop, NULL)); /*! [Truncate a range] */ error_check(stop->close(stop)); error_check(start->close(start)); } } /*! [Upgrade a table] */ error_check(session->upgrade(session, "table:mytable", NULL)); /*! [Upgrade a table] */ /*! [Verify a table] */ error_check(session->verify(session, "table:mytable", NULL)); /*! [Verify a table] */ /* * We can't call the backup function because it includes absolute paths * for documentation purposes that don't exist on test systems. That * said, we have to reference the function to avoid build warnings * about unused static code. */ (void)backup; /* Call other functions, where possible. */ checkpoint_ops(session); error_check(cursor_ops(session)); cursor_statistics(session); named_snapshot_ops(session); pack_ops(session); transaction_ops(session); /*! [Close a session] */ error_check(session->close(session, NULL)); /*! [Close a session] */ /* * We close the old session first to close all cursors, open a new one * for the drop. */ error_check(conn->open_session(conn, NULL, NULL, &session)); /*! [Drop a table] */ error_check(session->drop(session, "table:mytable", NULL)); /*! [Drop a table] */ } }
static void checkpoint_ops(WT_SESSION *session) { error_check(session->create(session, "table:table1", NULL)); error_check(session->create(session, "table:table2", NULL)); /*! [Checkpoint examples] */ /* Checkpoint the database. */ error_check(session->checkpoint(session, NULL)); /* Checkpoint of the database, creating a named snapshot. */ error_check(session->checkpoint(session, "name=June01")); /* * Checkpoint a list of objects. * JSON parsing requires quoting the list of target URIs. */ error_check(session->checkpoint( session, "target=(\"table:table1\",\"table:table2\")")); /* * Checkpoint a list of objects, creating a named snapshot. * JSON parsing requires quoting the list of target URIs. */ error_check(session->checkpoint( session, "target=(\"table:mytable\"),name=midnight")); /* Checkpoint the database, discarding all previous snapshots. */ error_check(session->checkpoint(session, "drop=(from=all)")); /* Checkpoint the database, discarding the "midnight" snapshot. */ error_check(session->checkpoint(session, "drop=(midnight)")); /* * Checkpoint the database, discarding all snapshots after and * including "noon". */ error_check(session->checkpoint(session, "drop=(from=noon)")); /* * Checkpoint the database, discarding all snapshots before and * including "midnight". */ error_check(session->checkpoint(session, "drop=(to=midnight)")); /* * Create a checkpoint of a table, creating the "July01" snapshot and * discarding the "May01" and "June01" snapshots. * JSON parsing requires quoting the list of target URIs. */ error_check(session->checkpoint(session, "target=(\"table:mytable\"),name=July01,drop=(May01,June01)")); /*! [Checkpoint examples] */ /*! [JSON quoting example] */ /* * Checkpoint a list of objects. * JSON parsing requires quoting the list of target URIs. */ error_check(session->checkpoint( session, "target=(\"table:table1\",\"table:table2\")")); /*! [JSON quoting example] */ }
int main(int argc, char *argv[]) { WT_CONNECTION *conn; home = example_setup(argc, argv); /*! [Open a connection] */ error_check(wiredtiger_open(home, NULL, "create,cache_size=5GB,log=(enabled,recover=on),statistics=(all)", &conn)); /*! [Open a connection] */ connection_ops(conn); /* * The connection has been closed. */ #ifdef MIGHT_NOT_RUN /* * This example code gets run, and the compression libraries might not * be installed, causing the open to fail. The documentation requires * the code snippets, use #ifdef's to avoid running it. */ /*! [Configure lz4 extension] */ error_check(wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/libwiredtiger_lz4.so]", &conn)); /*! [Configure lz4 extension] */ error_check(conn->close(conn, NULL)); /*! [Configure snappy extension] */ error_check(wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/libwiredtiger_snappy.so]", &conn)); /*! [Configure snappy extension] */ error_check(conn->close(conn, NULL)); /*! [Configure zlib extension] */ error_check(wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/libwiredtiger_zlib.so]", &conn)); /*! [Configure zlib extension] */ error_check(conn->close(conn, NULL)); /*! [Configure zlib extension with compression level] */ error_check(wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/" "libwiredtiger_zlib.so=[config=[compression_level=3]]]", &conn)); /*! [Configure zlib extension with compression level] */ error_check(conn->close(conn, NULL)); /*! [Configure zstd extension] */ error_check(wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/libwiredtiger_zstd.so]", &conn)); /*! [Configure zstd extension] */ error_check(conn->close(conn, NULL)); /*! [Configure zstd extension with compression level] */ error_check(wiredtiger_open(home, NULL, "create," "extensions=[/usr/local/lib/" "libwiredtiger_zstd.so=[config=[compression_level=9]]]", &conn)); /*! [Configure zstd extension with compression level] */ error_check(conn->close(conn, NULL)); /* * This example code gets run, and direct I/O might not be available, * causing the open to fail. The documentation requires code snippets, * use #ifdef's to avoid running it. */ /* Might Not Run: direct I/O may not be available. */ /*! [Configure direct_io for data files] */ error_check(wiredtiger_open( home, NULL, "create,direct_io=[data]", &conn)); /*! [Configure direct_io for data files] */ error_check(conn->close(conn, NULL)); #endif /*! [Configure file_extend] */ error_check(wiredtiger_open( home, NULL, "create,file_extend=(data=16MB)", &conn)); /*! [Configure file_extend] */ error_check(conn->close(conn, NULL)); /*! [Eviction configuration] */ /* * Configure eviction to begin at 90% full, and run until the cache * is only 75% dirty. */ error_check(wiredtiger_open(home, NULL, "create,eviction_trigger=90,eviction_dirty_target=75", &conn)); /*! [Eviction configuration] */ error_check(conn->close(conn, NULL)); /*! [Eviction worker configuration] */ /* Configure up to four eviction threads */ error_check(wiredtiger_open(home, NULL, "create,eviction_trigger=90,eviction=(threads_max=4)", &conn)); /*! [Eviction worker configuration] */ error_check(conn->close(conn, NULL)); /*! [Statistics configuration] */ error_check(wiredtiger_open( home, NULL, "create,statistics=(all)", &conn)); /*! [Statistics configuration] */ error_check(conn->close(conn, NULL)); /*! [Statistics logging] */ error_check(wiredtiger_open( home, NULL, "create,statistics_log=(wait=30)", &conn)); /*! [Statistics logging] */ error_check(conn->close(conn, NULL)); #ifdef MIGHT_NOT_RUN /* * Don't run this code, statistics logging doesn't yet support tables. */ /*! [Statistics logging with a table] */ error_check(wiredtiger_open(home, NULL, "create, statistics_log=(" "sources=(\"table:table1\",\"table:table2\"), wait=5)", &conn)); /*! [Statistics logging with a table] */ error_check(conn->close(conn, NULL)); /* * Don't run this code, statistics logging doesn't yet support indexes. */ /*! [Statistics logging with a source type] */ error_check(wiredtiger_open(home, NULL, "create, statistics_log=(sources=(\"index:\"), wait=5)", &conn)); /*! [Statistics logging with a source type] */ error_check(conn->close(conn, NULL)); /* * Don't run this code, because memory checkers get very upset when we * leak memory. */ error_check(wiredtiger_open(home, NULL, "create", &conn)); /*! [Connection close leaking memory] */ error_check(conn->close(conn, "leak_memory=true")); /*! [Connection close leaking memory] */ #endif /*! [Get the WiredTiger library version #1] */ printf("WiredTiger version %s\n", wiredtiger_version(NULL, NULL, NULL)); /*! [Get the WiredTiger library version #1] */ { /*! [Get the WiredTiger library version #2] */ int major_v, minor_v, patch; (void)wiredtiger_version(&major_v, &minor_v, &patch); printf("WiredTiger version is %d, %d (patch %d)\n", major_v, minor_v, patch); /*! [Get the WiredTiger library version #2] */ } { /*! [Calculate a modify operation] */ WT_MODIFY mod[3]; int nmod = 3; WT_ITEM prev, newv; prev.data = "the quick brown fox jumped over the lazy dog. " \ "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. " \ "the quick brown fox jumped over the lazy dog. " \ "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. "; prev.size = strlen(prev.data); newv.data = "A quick brown fox jumped over the lazy dog. " \ "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. " \ "then a quick brown fox jumped over the lazy dog. " \ "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. " \ "then what?"; newv.size = strlen(newv.data); error_check(wiredtiger_calc_modify(NULL, &prev, &newv, 20, mod, &nmod)); /*! [Calculate a modify operation] */ } { const char *buffer = "some string"; size_t len = strlen(buffer); /*! [Checksum a buffer] */ uint32_t crc32c, (*func)(const void *, size_t); func = wiredtiger_crc32c_func(); crc32c = func(buffer, len); /*! [Checksum a buffer] */ (void)crc32c; } return (EXIT_SUCCESS); }
static void connection_ops(WT_CONNECTION *conn) { #ifdef MIGHT_NOT_RUN /*! [Load an extension] */ error_check(conn->load_extension(conn, "my_extension.dll", NULL)); error_check(conn->load_extension(conn, "datasource/libdatasource.so", "config=[device=/dev/sd1,alignment=64]")); /*! [Load an extension] */ #endif add_collator(conn); add_extractor(conn); /*! [Reconfigure a connection] */ error_check(conn->reconfigure(conn, "eviction_target=75")); /*! [Reconfigure a connection] */ /*! [Get the database home directory] */ printf("The database home is %s\n", conn->get_home(conn)); /*! [Get the database home directory] */ /*! [Check if the database is newly created] */ if (conn->is_new(conn)) { /* First time initialization. */ } /*! [Check if the database is newly created] */ /*! [Validate a configuration string] */ /* * Validate a configuration string for a WiredTiger function or method. * * Functions are specified by name (for example, "wiredtiger_open"). * * Methods are specified using a concatenation of the handle name, a * period and the method name (for example, session create would be * "WT_SESSION.create" and cursor close would be WT_CURSOR.close"). */ error_check(wiredtiger_config_validate( NULL, NULL, "WT_SESSION.create", "allocation_size=32KB")); /*! [Validate a configuration string] */ { /*! [Open a session] */ WT_SESSION *session; error_check(conn->open_session(conn, NULL, NULL, &session)); /*! [Open a session] */ session_ops(session); } /*! [Configure method configuration] */ /* * Applications opening a cursor for the data-source object "my_data" * have an additional configuration option "entries", which is an * integer type, defaults to 5, and must be an integer between 1 and 10. * * The method being configured is specified using a concatenation of the * handle name, a period and the method name. */ error_check(conn->configure_method(conn, "WT_SESSION.open_cursor", "my_data:", "entries=5", "int", "min=1,max=10")); /* * Applications opening a cursor for the data-source object "my_data" * have an additional configuration option "devices", which is a list * of strings. */ error_check(conn->configure_method(conn, "WT_SESSION.open_cursor", "my_data:", "devices", "list", NULL)); /*! [Configure method configuration] */ /*! [Close a connection] */ error_check(conn->close(conn, NULL)); /*! [Close a connection] */ }
/*-------------------------------------------------------------------*/ int ProfileSQL (const unsigned char *sql_token, const unsigned char *sql_message, const unsigned char *sql_qualifiers, unsigned char *profile_reply, unsigned char *retry, int time_out) { STR_DESCRIPTOR request, reply; char request_buffer[MAX_MSG_SIZE], reply_buffer[MAX_MSG_SIZE]; int aa, i, j, k, num_size, error_code, error_code2, offset; unsigned char *(header_and_message[6]); unsigned char *(header_strings[6]); unsigned char *(message_strings1[1000]); unsigned char *(message_strings2[1000]); char buffer[MAX_MSG_SIZE]; char *pszSql = NULL,*new_sql_message = NULL, *new_using_clause; long len_new_sql_message, len_new_using_clause; unsigned char *col_attributes= NULL, *new_sql_qualifiers = NULL; char *lpsSelect; char *tokens; int nLen = 0; struct tm *curTime; time_t ltime; char tmpBuf[128]; if(sql_message == NULL) { strcpy((char *)profile_reply,"MSG_8564|Invalid SQL Command"); strcat((char *)profile_reply,(char *)sql_message); return 1; } memset (request_buffer,0,sizeof(request_buffer)); memset (reply_buffer,0,sizeof(reply_buffer)); request.str = request_buffer; reply.str = reply_buffer; /* Get time as number */ time(<ime); curTime = localtime( <ime ); /* Use strftime to build a customized time string. */ strftime( tmpBuf, 128,"OPEN CURSOR CUR%H%M%S AS \n", curTime ); /* For SELECT add open cursor */ tokens = (char *)strstr((char *)sql_message, " "); nLen = tokens - (char *)sql_message; lpsSelect = (char *) calloc(nLen + 1,1); if(NULL == lpsSelect) return -1; strncpy(lpsSelect,(char *)sql_message,nLen); pszSql = (char *)calloc(MAX_MSG_SIZE,1); if(strcasecmp(lpsSelect,"SELECT") == 0) { strcpy(pszSql,tmpBuf); strcat(pszSql,(char *)sql_message); } else strcpy(pszSql,(char *)sql_message); free(lpsSelect); new_sql_message = (char *) calloc(MAX_MSG_SIZE,1); new_using_clause = (char *) calloc(MAX_MSG_SIZE,1); len_new_sql_message = MAX_MSG_SIZE; len_new_using_clause = MAX_MSG_SIZE; error_code = ParseHostSQL(pszSql, strlen(pszSql), NULL ,0 ,new_sql_message, &len_new_sql_message, new_using_clause, &len_new_using_clause ); free(pszSql); logging (NULL, "\nSQL MESSAGE\n"); logging (NULL,(char*) sql_message); logging (NULL, "\nCLEANED SQL MESSAGE\n"); logging (NULL,(char*) new_sql_message); if(len_new_using_clause) { nLen = strlen((char *)sql_qualifiers)+ len_new_using_clause + 1; new_sql_qualifiers = (unsigned char *)calloc(nLen + 1, 1); strcpy((char *)new_sql_qualifiers, (char *)sql_qualifiers); strcat((char *)new_sql_qualifiers,new_using_clause); pack_sql(&request,(unsigned char *)new_sql_message, new_sql_qualifiers,sql_token,retry); } else { pack_sql(&request,(unsigned char *)new_sql_message, sql_qualifiers,sql_token,retry); } /* thoniyim 09/21/2001 memory leak fix */ free(new_sql_message); free(new_using_clause); k=0; logging (&request, "\nSQL MESSAGE SENT TO SERVER\n"); ClExchmsg(4, &request, &reply, time_out, &k); logging (&reply, "\nSERVER RESPONSE TO SQL MESSAGE\n"); error_code = error_check (k,CLSQL,&reply,profile_reply); if (error_code == OK_BUT_EMPTY_MESSAGE_BODY) { profile_reply[0] = 0; return OK; } if (error_code != OK && error_code != SQL_OK) { if (error_code == 4) { total_time_outs++; conseg_time_outs++; if (total_time_outs > 50000 || conseg_time_outs > 5000) { printf ("\nValue of total_time_outs and conseg_time_outs: %d %d\n", total_time_outs, conseg_time_outs); exit (1); } ClDisconnect(2, buffer); ClConnect(2, passed_mtm_address, &k); error_code2 = error_check (k,CLCONNECT,(unsigned char*)0,profile_reply); if (error_code2 != OK) { i = get_message_id (retry,FALSE); return error_code2; } } i = get_message_id (retry,FALSE); return error_code; } conseg_time_outs = 0; i = move_number(reply_buffer, reply.length-2); memcpy(reply_buffer+i,reply.str+1,reply.length-2); reply.str = reply_buffer; parse_string(reply.str,header_and_message); /* * thoniyim - CR 7426 - 01/16/2004 * Check the data from the host for message id. * Check if the message id of request and reply matches. */ parse_string(header_and_message[1],header_strings); i = memcmp(header_array[2].field, header_strings[2]+1, header_array[2].field_size); if (i != 0) { strcpy(profile_reply,"Message Ids for the request and reply does n't match. Disconnect and connect again."); return -1001; }
void i2c_read( uint8_t adres, uint8_t reg_adres, uint8_t * dane, uint8_t len ) { uint32_t dummy; while(I2C2->SR2 & I2C_SR2_BUSY) { if(error_check()) { i2c_config(); return; } } I2C2->CR1 |= I2C_CR1_START; while( !( I2C2->SR1 & I2C_SR1_SB )) { if(error_check()) { i2c_config(); return; } } I2C2->DR = adres; while( !( I2C2->SR1 & I2C_SR1_ADDR )) { if(error_check()) { i2c_config(); return; } } dummy = I2C2->SR2; while( !( I2C2->SR1 & I2C_SR1_TXE )) { if(error_check()) { i2c_config(); return; } } I2C2->DR = reg_adres; while( !( I2C2->SR1 & I2C_SR1_BTF )) { if(error_check()) { i2c_config(); return; } } I2C2->CR1 |= I2C_CR1_START; while( !( I2C2->SR1 & I2C_SR1_SB )) { if(error_check()) { i2c_config(); return; } } I2C2->DR = adres | 0x01; while( !( I2C2->SR1 & I2C_SR1_ADDR )) { if(error_check()) { i2c_config(); return; } } dummy = I2C2->SR2; I2C2->CR1 |= I2C_CR1_ACK; while( len ) { if( len == 1 ) I2C2->CR1 &= ~I2C_CR1_ACK; while( !( I2C2->SR1 & I2C_SR1_RXNE )) { if(error_check()) { i2c_config(); return; } } *( dane++ ) = I2C2->DR; len--; } I2C2->CR1 |= I2C_CR1_STOP; }