summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/c/ex_all.c10
-rw-r--r--src/cursor/cur_bulk.c4
-rw-r--r--src/cursor/cur_config.c1
-rw-r--r--src/cursor/cur_file.c1
-rw-r--r--src/cursor/cur_index.c1
-rw-r--r--src/cursor/cur_stat.c1
-rw-r--r--src/cursor/cur_std.c32
-rw-r--r--src/cursor/cur_table.c1
-rw-r--r--src/include/wiredtiger.in13
9 files changed, 61 insertions, 3 deletions
diff --git a/examples/c/ex_all.c b/examples/c/ex_all.c
index 35a505ff752..cc1aa784c94 100644
--- a/examples/c/ex_all.c
+++ b/examples/c/ex_all.c
@@ -51,9 +51,11 @@ int session_ops(WT_SESSION *session);
int
cursor_ops(WT_SESSION *session)
{
- WT_CURSOR *cursor;
+ WT_CURSOR *cursor, *other;
int ret;
+ other = NULL;
+
/*! [Open a cursor] */
ret = session->open_cursor(
session, "table:mytable", NULL, NULL, &cursor);
@@ -130,6 +132,12 @@ cursor_ops(WT_SESSION *session)
ret = cursor->reset(cursor);
/*! [Reset the cursor] */
+ /*! [Test cursor equality] */
+ if (cursor->equals(cursor, other)) {
+ /* Take some action. */
+ }
+ /*! [Test cursor equality] */
+
{
/*! [Search for an exact match] */
const char *key = "some key";
diff --git a/src/cursor/cur_bulk.c b/src/cursor/cur_bulk.c
index af7ba6e20bb..05b5e7bf5b2 100644
--- a/src/cursor/cur_bulk.c
+++ b/src/cursor/cur_bulk.c
@@ -51,8 +51,8 @@ __curbulk_close(WT_CURSOR *cursor, const char *config)
WT_TRET(__wt_bulk_end(cbulk));
if (session->btree != NULL)
WT_TRET(__wt_session_release_btree(session));
- /* The URI is owned by the btree handle. */
- cursor->uri = NULL;
+ /* The URI is owned by the btree handle. */
+ cursor->uri = NULL;
WT_TRET(__wt_cursor_close(cursor, config));
err: API_END(session);
diff --git a/src/cursor/cur_config.c b/src/cursor/cur_config.c
index 0a811479ec4..eadbfa3ed5d 100644
--- a/src/cursor/cur_config.c
+++ b/src/cursor/cur_config.c
@@ -34,6 +34,7 @@ __wt_curconfig_open(WT_SESSION_IMPL *session,
NULL,
NULL,
NULL,
+ NULL, /* equals */
__wt_cursor_notsup, /* next */
__wt_cursor_notsup, /* prev */
__wt_cursor_notsup, /* reset */
diff --git a/src/cursor/cur_file.c b/src/cursor/cur_file.c
index 40da148f795..1c7f30cefbf 100644
--- a/src/cursor/cur_file.c
+++ b/src/cursor/cur_file.c
@@ -208,6 +208,7 @@ __wt_curfile_create(WT_SESSION_IMPL *session,
NULL,
NULL,
NULL,
+ NULL,
__curfile_next,
__curfile_prev,
__curfile_reset,
diff --git a/src/cursor/cur_index.c b/src/cursor/cur_index.c
index 59c4f42c13e..ee38018e1db 100644
--- a/src/cursor/cur_index.c
+++ b/src/cursor/cur_index.c
@@ -346,6 +346,7 @@ __wt_curindex_open(WT_SESSION_IMPL *session,
__curindex_get_value,
NULL,
__curindex_set_value,
+ NULL,
__curindex_next,
__curindex_prev,
__curindex_reset,
diff --git a/src/cursor/cur_stat.c b/src/cursor/cur_stat.c
index b7a3a03fe36..33eaffd5908 100644
--- a/src/cursor/cur_stat.c
+++ b/src/cursor/cur_stat.c
@@ -316,6 +316,7 @@ __wt_curstat_open(WT_SESSION_IMPL *session,
NULL,
NULL,
NULL,
+ NULL,
__curstat_next,
__curstat_prev,
__curstat_reset,
diff --git a/src/cursor/cur_std.c b/src/cursor/cur_std.c
index 948de5c32c8..2db33394842 100644
--- a/src/cursor/cur_std.c
+++ b/src/cursor/cur_std.c
@@ -249,6 +249,36 @@ __cursor_search(WT_CURSOR *cursor)
}
/*
+ * __cursor_equals --
+ * WT_CURSOR->equals default implementation.
+ */
+static int
+__cursor_equals(WT_CURSOR *cursor, WT_CURSOR *other)
+{
+ WT_SESSION_IMPL *session;
+ int ret;
+
+ CURSOR_API_CALL(cursor, session, equals, NULL);
+
+ /* Both cursors must refer to the same source. */
+ if (other == NULL || strcmp(cursor->uri, other->uri) != 0)
+ goto done;
+
+ /* Check that both have keys set and the keys match. */
+ if (F_ISSET(cursor, WT_CURSTD_KEY_SET) &&
+ F_ISSET(other, WT_CURSTD_KEY_SET)) {
+ if (WT_CURSOR_RECNO(cursor))
+ ret = (cursor->recno == other->recno);
+ else if (cursor->key.size == other->key.size)
+ ret = (memcmp(cursor->key.data, other->key.data,
+ cursor->key.size) == 0);
+ }
+
+done: API_END(session);
+ return (ret);
+}
+
+/*
* __wt_cursor_close --
* WT_CURSOR->close default implementation.
*/
@@ -304,6 +334,8 @@ __wt_cursor_init(WT_CURSOR *cursor,
cursor->set_key = __wt_cursor_set_key;
if (cursor->set_value == NULL)
cursor->set_value = __wt_cursor_set_value;
+ if (cursor->equals == NULL)
+ cursor->equals = __cursor_equals;
if (cursor->search == NULL)
cursor->search = __cursor_search;
diff --git a/src/cursor/cur_table.c b/src/cursor/cur_table.c
index 4d49036c849..d2ad1238a7b 100644
--- a/src/cursor/cur_table.c
+++ b/src/cursor/cur_table.c
@@ -516,6 +516,7 @@ __wt_curtable_open(WT_SESSION_IMPL *session,
__wt_curtable_get_value,
__wt_curtable_set_key,
__wt_curtable_set_value,
+ NULL,
__curtable_next,
__curtable_prev,
__curtable_reset,
diff --git a/src/include/wiredtiger.in b/src/include/wiredtiger.in
index 5ed4e5f132a..2baae5a25ea 100644
--- a/src/include/wiredtiger.in
+++ b/src/include/wiredtiger.in
@@ -226,6 +226,19 @@ struct __wt_cursor {
/*! @name Cursor positioning
* @{
*/
+ /*! Test whether two cursors refer to the same item. To be equal,
+ * both cursors must have the same data source, have valid keys, and
+ * the keys must be equal.
+ *
+ * @snippet ex_all.c Test cursor equality
+ *
+ * @param cursor the cursor handle
+ * @param other another cursor handle
+ * @returns true (non-zero) if both cursors reference the same item,
+ * false (zero) otherwise
+ */
+ int __F(equals)(WT_CURSOR *cursor, WT_CURSOR *other);
+
/*! Return the next record.
*
* @snippet ex_all.c Return the next record