summaryrefslogtreecommitdiff
path: root/examples/c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/c')
-rw-r--r--examples/c/ex_access.c2
-rw-r--r--examples/c/ex_all.c45
-rw-r--r--examples/c/ex_async.c2
-rw-r--r--examples/c/ex_backup.c2
-rw-r--r--examples/c/ex_call_center.c2
-rw-r--r--examples/c/ex_config_parse.c2
-rw-r--r--examples/c/ex_cursor.c2
-rw-r--r--examples/c/ex_data_source.c2
-rw-r--r--examples/c/ex_encrypt.c2
-rw-r--r--examples/c/ex_event_handler.c6
-rw-r--r--examples/c/ex_extending.c2
-rw-r--r--examples/c/ex_extractor.c2
-rw-r--r--examples/c/ex_file_system.c6
-rw-r--r--examples/c/ex_hello.c2
-rw-r--r--examples/c/ex_log.c2
-rw-r--r--examples/c/ex_pack.c2
-rw-r--r--examples/c/ex_process.c2
-rw-r--r--examples/c/ex_schema.c2
-rw-r--r--examples/c/ex_stat.c2
-rw-r--r--examples/c/ex_sync.c4
-rw-r--r--examples/c/ex_thread.c22
21 files changed, 77 insertions, 38 deletions
diff --git a/examples/c/ex_access.c b/examples/c/ex_access.c
index d7f3cc557ad..6f24139182d 100644
--- a/examples/c/ex_access.c
+++ b/examples/c/ex_access.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.
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(
diff --git a/examples/c/ex_async.c b/examples/c/ex_async.c
index 5cfafca0418..83cddc2824d 100644
--- a/examples/c/ex_async.c
+++ b/examples/c/ex_async.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.
diff --git a/examples/c/ex_backup.c b/examples/c/ex_backup.c
index 83cc9b22ecc..ff7d979f286 100644
--- a/examples/c/ex_backup.c
+++ b/examples/c/ex_backup.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.
diff --git a/examples/c/ex_call_center.c b/examples/c/ex_call_center.c
index cd53a1cdaf9..4483e8b1603 100644
--- a/examples/c/ex_call_center.c
+++ b/examples/c/ex_call_center.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.
diff --git a/examples/c/ex_config_parse.c b/examples/c/ex_config_parse.c
index 40508b38204..c9720325129 100644
--- a/examples/c/ex_config_parse.c
+++ b/examples/c/ex_config_parse.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.
diff --git a/examples/c/ex_cursor.c b/examples/c/ex_cursor.c
index b8ed6ab169d..0982aa43073 100644
--- a/examples/c/ex_cursor.c
+++ b/examples/c/ex_cursor.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.
diff --git a/examples/c/ex_data_source.c b/examples/c/ex_data_source.c
index 387248f6ae2..d40008e0a0e 100644
--- a/examples/c/ex_data_source.c
+++ b/examples/c/ex_data_source.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.
diff --git a/examples/c/ex_encrypt.c b/examples/c/ex_encrypt.c
index 1520bd286cd..1710d5af16f 100644
--- a/examples/c/ex_encrypt.c
+++ b/examples/c/ex_encrypt.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.
diff --git a/examples/c/ex_event_handler.c b/examples/c/ex_event_handler.c
index 03809cae7c8..acd9d9beecc 100644
--- a/examples/c/ex_event_handler.c
+++ b/examples/c/ex_event_handler.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.
@@ -70,6 +70,10 @@ handle_wiredtiger_error(WT_EVENT_HANDLER *handler,
"app_id %s, thread context %p, error %d, message %s\n",
custom_handler->app_id, (void *)session, error, message);
+ /* Exit if the database has a fatal error. */
+ if (error == WT_PANIC)
+ exit (1);
+
return (0);
}
diff --git a/examples/c/ex_extending.c b/examples/c/ex_extending.c
index f276cdd3e1e..7364fa4bc9e 100644
--- a/examples/c/ex_extending.c
+++ b/examples/c/ex_extending.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.
diff --git a/examples/c/ex_extractor.c b/examples/c/ex_extractor.c
index f9d7af4af0f..3aaaf90ac90 100644
--- a/examples/c/ex_extractor.c
+++ b/examples/c/ex_extractor.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.
diff --git a/examples/c/ex_file_system.c b/examples/c/ex_file_system.c
index e807ac54d3b..e454d228c39 100644
--- a/examples/c/ex_file_system.c
+++ b/examples/c/ex_file_system.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.
@@ -583,13 +583,13 @@ demo_fs_size(WT_FILE_SYSTEM *file_system,
static int
demo_fs_terminate(WT_FILE_SYSTEM *file_system, WT_SESSION *session)
{
- DEMO_FILE_HANDLE *demo_fh;
+ DEMO_FILE_HANDLE *demo_fh, *demo_fh_tmp;
DEMO_FILE_SYSTEM *demo_fs;
int ret = 0, tret;
demo_fs = (DEMO_FILE_SYSTEM *)file_system;
- while ((demo_fh = TAILQ_FIRST(&demo_fs->fileq)) != NULL)
+ TAILQ_FOREACH_SAFE(demo_fh, &demo_fs->fileq, q, demo_fh_tmp)
if ((tret =
demo_handle_remove(session, demo_fh)) != 0 && ret == 0)
ret = tret;
diff --git a/examples/c/ex_hello.c b/examples/c/ex_hello.c
index 99534ee8868..616049aaddb 100644
--- a/examples/c/ex_hello.c
+++ b/examples/c/ex_hello.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.
diff --git a/examples/c/ex_log.c b/examples/c/ex_log.c
index 0d8fbf97233..d4de195ddee 100644
--- a/examples/c/ex_log.c
+++ b/examples/c/ex_log.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.
diff --git a/examples/c/ex_pack.c b/examples/c/ex_pack.c
index 86725123f55..37b864e62a4 100644
--- a/examples/c/ex_pack.c
+++ b/examples/c/ex_pack.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.
diff --git a/examples/c/ex_process.c b/examples/c/ex_process.c
index 217730c4288..4bab6a1cd70 100644
--- a/examples/c/ex_process.c
+++ b/examples/c/ex_process.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.
diff --git a/examples/c/ex_schema.c b/examples/c/ex_schema.c
index a59d9480780..9249ecc1e1a 100644
--- a/examples/c/ex_schema.c
+++ b/examples/c/ex_schema.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.
diff --git a/examples/c/ex_stat.c b/examples/c/ex_stat.c
index cf9e8fb97d1..7097b53a060 100644
--- a/examples/c/ex_stat.c
+++ b/examples/c/ex_stat.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.
diff --git a/examples/c/ex_sync.c b/examples/c/ex_sync.c
index b2d74b52f7f..c333ac42e1e 100644
--- a/examples/c/ex_sync.c
+++ b/examples/c/ex_sync.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.
diff --git a/examples/c/ex_thread.c b/examples/c/ex_thread.c
index fa82bd5f113..ad2ff7f68a0 100644
--- a/examples/c/ex_thread.c
+++ b/examples/c/ex_thread.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.
@@ -34,22 +34,14 @@
#include <stdlib.h>
#include <string.h>
-#ifndef _WIN32
-#include <pthread.h>
-#else
-#include "windows_shim.h"
-#endif
-
-#include <wiredtiger.h>
+#include "wt_internal.h"
static const char *home;
-void *scan_thread(void *arg);
-
#define NUM_THREADS 10
/*! [thread scan] */
-void *
+static WT_THREAD_RET
scan_thread(void *conn_arg)
{
WT_CONNECTION *conn;
@@ -74,7 +66,7 @@ scan_thread(void *conn_arg)
fprintf(stderr,
"WT_CURSOR.next: %s\n", session->strerror(session, ret));
- return (NULL);
+ return (WT_THREAD_RET_VALUE);
}
/*! [thread scan] */
@@ -85,7 +77,7 @@ main(void)
WT_CONNECTION *conn;
WT_SESSION *session;
WT_CURSOR *cursor;
- pthread_t threads[NUM_THREADS];
+ wt_thread_t threads[NUM_THREADS];
int i, ret;
/*
@@ -114,10 +106,10 @@ main(void)
ret = session->close(session, NULL);
for (i = 0; i < NUM_THREADS; i++)
- ret = pthread_create(&threads[i], NULL, scan_thread, conn);
+ ret = __wt_thread_create(NULL, &threads[i], scan_thread, conn);
for (i = 0; i < NUM_THREADS; i++)
- ret = pthread_join(threads[i], NULL);
+ ret = __wt_thread_join(NULL, threads[i]);
ret = conn->close(conn, NULL);