diff options
Diffstat (limited to 'examples/c/ex_all.c')
-rw-r--r-- | examples/c/ex_all.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/examples/c/ex_all.c b/examples/c/ex_all.c index 82620673fe1..5e1fa4bbcc5 100644 --- a/examples/c/ex_all.c +++ b/examples/c/ex_all.c @@ -1,5 +1,5 @@ /*- - * Public Domain 2014-2016 MongoDB, Inc. + * Public Domain 2014-2017 MongoDB, Inc. * Public Domain 2008-2014 WiredTiger, Inc. * * This is free and unencumbered software released into the public domain. @@ -299,6 +299,49 @@ cursor_ops(WT_SESSION *session) } { + /*! [Reserve a record] */ + const char *key = "some key"; + ret = session->open_cursor( + session, "table:mytable", NULL, NULL, &cursor); + cursor->set_key(cursor, key); + ret = cursor->reserve(cursor); + /*! [Reserve a record] */ + } + + { + /*! [Modify an existing record] */ + WT_MODIFY entries[3]; + const char *key = "some key"; + ret = session->open_cursor( + session, "table:mytable", NULL, NULL, &cursor); + + /* Position the cursor. */ + cursor->set_key(cursor, key); + ret = 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; + + ret = cursor->modify(cursor, entries, 3); + /*! [Modify an existing record] */ + } + + { /*! [Update an existing record or insert a new record] */ const char *key = "some key", *value = "some value"; ret = session->open_cursor( |