Discussions
Categories
- 197.1K All Categories
- 2.5K Data
- 546 Big Data Appliance
- 1.9K Data Science
- 450.7K Databases
- 221.9K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 552 MySQL Community Space
- 479 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.1K ORDS, SODA & JSON in the Database
- 555 SQLcl
- 4K SQL Developer Data Modeler
- 187.2K SQL & PL/SQL
- 21.3K SQL Developer
- 296.3K Development
- 17 Developer Projects
- 139 Programming Languages
- 293K Development Tools
- 110 DevOps
- 3.1K QA/Testing
- 646.1K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 158 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.2K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 19 Java Essentials
- 162 Java 8 Questions
- 86K Java Programming
- 81 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 205 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 466 LiveLabs
- 39 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 175 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 233 Portuguese
Dbc::get() has no need to commit ?

529558
Member Posts: 8
m_pEvironment->txn_begin (NULL,&m_pTransaction,0);
nRes=m_pDb->cursor (m_pTransaction,&m_pCursor,0);
try
{
Dbt dbKey;
Dbt dbData;
int nRes;
dbKey.set_flags (DB_DBT_MALLOC);
dbData.set_flags (DB_DBT_MALLOC);
nRes=m_pCursor->get (&dbKey,&dbData,DB_NEXT);
m_pTransaction->commit (0); // <---------exception catched ,jump to catch() block.
// Dbc::get() is one of a access operation ,in theory it need a commitment.
}
catch (DbException &dbe)
{
}
sorry to disturb you as I really have no information to refer to.
nRes=m_pDb->cursor (m_pTransaction,&m_pCursor,0);
try
{
Dbt dbKey;
Dbt dbData;
int nRes;
dbKey.set_flags (DB_DBT_MALLOC);
dbData.set_flags (DB_DBT_MALLOC);
nRes=m_pCursor->get (&dbKey,&dbData,DB_NEXT);
m_pTransaction->commit (0); // <---------exception catched ,jump to catch() block.
// Dbc::get() is one of a access operation ,in theory it need a commitment.
}
catch (DbException &dbe)
{
}
sorry to disturb you as I really have no information to refer to.
Comments
-
First, you need to close the cursor before commiting or aborting the transaction. Here is a sample used in the Berkeley DB Transaction Guide:
#include <stdio.h>
#include <stdlib.h>
#include "db.h"
int
main(void)
{
DBT key, data;
DBC *cursorp;
DB_TXN *txn = NULL;
int ret, c_ret;
char *replacementString = "new string";
...
/* environment and db handle creation omitted */
...
/* Get the txn handle */
txn = NULL;
ret = envp->txn_begin(envp, NULL, &txn, 0);
if (ret != 0) {
envp->err(envp, ret, "Transaction begin failed.");
goto err;
}
/* Get the cursor, supply the txn handle at that time */
ret = dbp->cursor(dbp, txn, &cursorp, 0);
if (ret != 0) {
envp->err(envp, ret, "Cursor open failed.");
txn->abort(txn);
goto err;
}
/*
* Now use the cursor. Note that we do not supply any txn handles to these
* methods.
*/
/* Prepare the DBTs */
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
while (cursor->c_get(&key, &data, DB_NEXT) == 0) {
data->data = (void *)replacementString;
data->size = (strlen(replacementString) + 1) * sizeof(char);
c_ret = cursor->c_put(cursor, &key, &data, DB_CURRENT);
if (c_ret != 0) {
/* abort the transaction and goto error */
envp->err(envp, ret, "Cursor put failed.");
cursorp->c_close(cursorp);
cursorp = NULL;
txn->abort(txn);
goto err;
}
}
/*
* Commit the transaction. Note that the transaction handle
* can no longer be used.
*/
ret = cursorp->c_close(cursorp);
if (ret != 0) {
envp->err(envp, ret, "Cursor close failed.");
txn->abort(txn);
goto err;
}
ret = txn->commit(txn, 0);
if (ret != 0) {
envp->err(envp, ret, "Transaction commit failed.");
goto err;
}
err:
/* Close the cursor (if the handle is not NULL)
* and perform whatever other cleanup is required */
/* Close the database */
/* Close the environment */
...
if (c_ret != 0)
ret = c_ret;
return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
Ron
This discussion has been closed.