summaryrefslogtreecommitdiff
path: root/examples/c
diff options
context:
space:
mode:
authorKeith Bostic <keith@wiredtiger.com>2012-08-13 14:55:31 +0000
committerKeith Bostic <keith@wiredtiger.com>2012-08-13 14:55:31 +0000
commitd41dd40709bedb19950c1aa43ea25ae9bb0b01f9 (patch)
tree9607db11024014e521bec01148ae407d3dacdf3e /examples/c
parentb3236229a726ecd7bdf232b60466ff28d0aabf93 (diff)
downloadmongo-d41dd40709bedb19950c1aa43ea25ae9bb0b01f9.tar.gz
Make cursors long-lived objects: instead of txn_commit and txn_rollback
closing cursors, txn_commit, txn_rollback and txn_begin all reset any open cursors. Ref #291. If txn_commit fails, document the transaction was rolled-back. Ref #294.
Diffstat (limited to 'examples/c')
-rw-r--r--examples/c/ex_all.c15
1 files changed, 3 insertions, 12 deletions
diff --git a/examples/c/ex_all.c b/examples/c/ex_all.c
index 9b883a66879..232bb587418 100644
--- a/examples/c/ex_all.c
+++ b/examples/c/ex_all.c
@@ -473,28 +473,22 @@ transaction_ops(WT_CONNECTION *conn, WT_SESSION *session)
int ret;
/*! [simple transaction] */
- ret = session->begin_transaction(session, NULL);
-
ret =
session->open_cursor(session, "table:mytable", NULL, NULL, &cursor);
+ ret = session->begin_transaction(session, NULL);
cursor->set_key(cursor, "some-key");
cursor->set_value(cursor, "some-value");
ret = cursor->update(cursor);
-
- /* Resolving the transaction closes the open cursors. */
ret = session->commit_transaction(session, NULL);
/*! [simple transaction] */
/*! [simple rollback transaction] */
- ret = session->begin_transaction(session, NULL);
-
ret =
session->open_cursor(session, "table:mytable", NULL, NULL, &cursor);
+ ret = session->begin_transaction(session, NULL);
cursor->set_key(cursor, "some-key");
cursor->set_value(cursor, "some-value");
ret = cursor->update(cursor);
-
- /* Resolving the transaction closes the open cursors. */
switch (ret) {
case 0:
ret = session->commit_transaction(session, NULL);
@@ -508,15 +502,12 @@ transaction_ops(WT_CONNECTION *conn, WT_SESSION *session)
/*! [simple transaction isolation] */
/* A single transaction configured for snapshot isolation. */
- ret = session->begin_transaction(session, "isolation=snapshot");
-
ret =
session->open_cursor(session, "table:mytable", NULL, NULL, &cursor);
+ ret = session->begin_transaction(session, "isolation=snapshot");
cursor->set_key(cursor, "some-key");
cursor->set_value(cursor, "some-value");
ret = cursor->update(cursor);
-
- /* Resolving the transaction closes the open cursors. */
ret = session->commit_transaction(session, NULL);
/*! [simple transaction isolation] */