本文整理汇总了C++中Ndb::getNdbError方法的典型用法代码示例。如果您正苦于以下问题:C++ Ndb::getNdbError方法的具体用法?C++ Ndb::getNdbError怎么用?C++ Ndb::getNdbError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ndb
的用法示例。
在下文中一共展示了Ndb::getNdbError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: do_update
/*****************************************************************
* Update the second attribute in half of the tuples (adding 10) *
*****************************************************************/
static void do_update(Ndb &myNdb, const char* table)
{
const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable(table);
if (myTable == NULL)
APIERROR(myDict->getNdbError());
for (int i = 0; i < 10; i+=2) {
NdbTransaction *myTransaction= myNdb.startTransaction();
if (myTransaction == NULL) APIERROR(myNdb.getNdbError());
NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->updateTuple();
myOperation->equal( "ATTR1", i );
myOperation->setValue( "ATTR2", i+10);
if( myTransaction->execute( NdbTransaction::Commit ) == -1 )
APIERROR(myTransaction->getNdbError());
myNdb.closeTransaction(myTransaction);
}
}
示例2: do_insert
/**************************************************************************
* Using 5 transactions, insert 10 tuples in table: (0,0),(1,1),...,(9,9) *
**************************************************************************/
static void do_insert(Ndb &myNdb)
{
const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("MYTABLENAME");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
for (int i = 0; i < 5; i++) {
NdbTransaction *myTransaction= myNdb.startTransaction();
if (myTransaction == NULL) APIERROR(myNdb.getNdbError());
NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->insertTuple();
myOperation->equal("ATTR1", i);
myOperation->setValue("ATTR2", i);
myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->insertTuple();
myOperation->equal("ATTR1", i+5);
myOperation->setValue("ATTR2", i+5);
if (myTransaction->execute( NdbTransaction::Commit ) == -1)
APIERROR(myTransaction->getNdbError());
myNdb.closeTransaction(myTransaction);
}
}
示例3: run_master_update
static void run_master_update(struct Xxx &xxx, struct XxxR &xxxr)
{
Ndb *ndb = xxx.ndb;
const NdbDictionary::Table *myTable = xxx.table;
int retry_sleep= 10; /* 10 milliseconds */
int retries= 100;
while (1)
{
Uint32 val;
NdbTransaction *trans = ndb->startTransaction();
if (trans == NULL)
goto err;
{
NdbOperation *op = trans->getNdbOperation(myTable);
if (op == NULL)
APIERROR(trans->getNdbError());
op->readTupleExclusive();
op->equal(xxx.pk_col, xxxr.pk_val);
op->getValue(xxx.col, (char *)&val);
}
if (trans->execute(NdbTransaction::NoCommit))
goto err;
//fprintf(stderr, "read %u\n", val);
xxxr.val = val + 1;
{
NdbOperation *op = trans->getNdbOperation(myTable);
if (op == NULL)
APIERROR(trans->getNdbError());
op->updateTuple();
op->equal(xxx.pk_col, xxxr.pk_val);
op->setValue(xxx.col, xxxr.val);
}
if (trans->execute(NdbTransaction::Commit))
goto err;
ndb->closeTransaction(trans);
//fprintf(stderr, "updated to %u\n", xxxr.val);
break;
err:
const NdbError this_error= trans ?
trans->getNdbError() : ndb->getNdbError();
if (this_error.status == NdbError::TemporaryError)
{
if (retries--)
{
if (trans)
ndb->closeTransaction(trans);
NdbSleep_MilliSleep(retry_sleep);
continue; // retry
}
}
if (trans)
ndb->closeTransaction(trans);
APIERROR(this_error);
}
/* update done start timer */
gettimeofday(&xxxr.start_time, 0);
}
示例4: create_ndb_connection
Ndb* JniNdbEventStreamingImp::create_ndb_connection(const char* database) {
Ndb* ndb = new Ndb(mClusterConnection, database);
if (ndb->init() == -1) {
LOG_NDB_API_ERROR(ndb->getNdbError());
}
return ndb;
}
示例5: GETNDB
static int
runFullScan(NDBT_Context* ctx, NDBT_Step* step)
{
NDBT_Table* pTab = ctx->getTab();
Ndb* pNdb = GETNDB(step);
unsigned cntIndex = getTableProperty(ctx, pTab, "numIndex");
for (unsigned numIndex = 0; numIndex < cntIndex; numIndex++) {
char buf[200];
sprintf(buf, "%s_X%03d", pTab->getName(), numIndex);
NDBT_Index* pInd = NDBT_Index::discoverIndexFromDb(pNdb, buf, pTab->getName());
assert(pInd != 0);
g_info << "Scan index:" << pInd->getName() << endl << *pInd;
NdbConnection* pCon = pNdb->startTransaction();
if (pCon == 0) {
ERR(pNdb->getNdbError());
return NDBT_FAILED;
}
NdbOperation* pOp = pCon->getNdbOperation(pInd->getName(),
pTab->getName());
if (pOp == 0) {
ERR(pCon->getNdbError());
pNdb->closeTransaction(pCon);
return NDBT_FAILED;
}
if (pOp->openScanRead() != 0) {
ERR(pCon->getNdbError());
pNdb->closeTransaction(pCon);
return NDBT_FAILED;
}
if (pCon->executeScan() != 0) {
ERR(pCon->getNdbError());
pNdb->closeTransaction(pCon);
return NDBT_FAILED;
}
unsigned rows = 0;
while (1) {
int ret = pCon->nextScanResult();
if (ret == 0) {
rows++;
} else if (ret == 1) {
break;
} else {
ERR(pCon->getNdbError());
pNdb->closeTransaction(pCon);
return NDBT_FAILED;
}
}
pNdb->closeTransaction(pCon);
g_info << "Scanned " << rows << " rows" << endl;
}
return NDBT_OK;
}
示例6: APIERROR
static int
prepare_master_or_slave(Ndb &myNdb,
const char* table,
const char* pk,
Uint32 pk_val,
const char* col,
struct Xxx &xxx,
struct XxxR &xxxr)
{
if (myNdb.init())
APIERROR(myNdb.getNdbError());
const NdbDictionary::Dictionary* myDict = myNdb.getDictionary();
const NdbDictionary::Table *myTable = myDict->getTable(table);
if (myTable == NULL)
APIERROR(myDict->getNdbError());
const NdbDictionary::Column *myPkCol = myTable->getColumn(pk);
if (myPkCol == NULL)
APIERROR(myDict->getNdbError());
if (myPkCol->getType() != NdbDictionary::Column::Unsigned)
{
PRINT_ERROR(0, "Primary key column not of type unsigned");
exit(-1);
}
const NdbDictionary::Column *myCol = myTable->getColumn(col);
if (myCol == NULL)
APIERROR(myDict->getNdbError());
if (myCol->getType() != NdbDictionary::Column::Unsigned)
{
PRINT_ERROR(0, "Update column not of type unsigned");
exit(-1);
}
xxx.ndb = &myNdb;
xxx.table = myTable;
xxx.pk_col = myPkCol->getColumnNo();
xxx.col = myCol->getColumnNo();
xxxr.pk_val = pk_val;
return 0;
}
示例7:
/**
* Transaction 1 - T1
*
* Update location and changed by/time on a subscriber
*
* Input:
* SubscriberNumber,
* Location,
* ChangedBy,
* ChangedTime
*
* Output:
*/
void
userTransaction_T1(UserHandle * uh,
SubscriberNumber number,
Location new_location,
ChangedBy changed_by,
ChangedTime changed_time){
Ndb * pNDB = uh->pNDB;
DEBUG2("T1(%.*s):\n", SUBSCRIBER_NUMBER_LENGTH, number);
int check;
NdbRecAttr * check2;
NdbConnection * MyTransaction = pNDB->startTransaction();
if (MyTransaction != NULL) {
NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
if (MyOperation != NULL) {
MyOperation->updateTuple();
MyOperation->equal(IND_SUBSCRIBER_NUMBER,
number);
MyOperation->setValue(IND_SUBSCRIBER_LOCATION,
(char *)&new_location);
MyOperation->setValue(IND_SUBSCRIBER_CHANGED_BY,
changed_by);
MyOperation->setValue(IND_SUBSCRIBER_CHANGED_TIME,
changed_time);
check = MyTransaction->execute( Commit );
if (check != -1) {
pNDB->closeTransaction(MyTransaction);
return;
} else {
CHECK_MINUS_ONE(check, "T1: Commit",
MyTransaction);
}//if
} else {
CHECK_NULL(MyOperation, "T1: getNdbOperation", MyTransaction);
}//if
} else {
error_handler("T1-1: startTranscation", pNDB->getNdbErrorString(), pNDB->getNdbError());
}//if
}
示例8: do_delete
/*************************************************
* Delete one tuple (the one with primary key 3) *
*************************************************/
static void do_delete(Ndb &myNdb, const char* table)
{
const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable(table);
if (myTable == NULL)
APIERROR(myDict->getNdbError());
NdbTransaction *myTransaction= myNdb.startTransaction();
if (myTransaction == NULL) APIERROR(myNdb.getNdbError());
NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->deleteTuple();
myOperation->equal( "ATTR1", 3 );
if (myTransaction->execute(NdbTransaction::Commit) == -1)
APIERROR(myTransaction->getNdbError());
myNdb.closeTransaction(myTransaction);
}
示例9: do_read
/*****************************
* Read and print all tuples *
*****************************/
static void do_read(Ndb &myNdb, const char* table)
{
const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable(table);
if (myTable == NULL)
APIERROR(myDict->getNdbError());
std::cout << "ATTR1 ATTR2" << std::endl;
for (int i = 0; i < 10; i++) {
NdbTransaction *myTransaction= myNdb.startTransaction();
if (myTransaction == NULL) APIERROR(myNdb.getNdbError());
NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->readTuple(NdbOperation::LM_Read);
myOperation->equal("ATTR1", i);
NdbRecAttr *myRecAttr= myOperation->getValue("ATTR2", NULL);
if (myRecAttr == NULL) APIERROR(myTransaction->getNdbError());
if(myTransaction->execute( NdbTransaction::Commit ) == -1)
{
if (i == 3) {
std::cout << "Detected that deleted tuple doesn't exist!" << std::endl;
} else {
APIERROR(myTransaction->getNdbError());
}
}
if (i != 3) {
printf(" %2d %2d\n", i, myRecAttr->u_32_value());
}
myNdb.closeTransaction(myTransaction);
}
}
示例10: startTransaction
/**
* Transaction 3 - T3
*
* Read session details
*
* Input:
* SubscriberNumber
* ServerId
* ServerBit
*
* Output:
* BranchExecuted
* SessionDetails
* ChangedBy
* ChangedTime
* Location
*/
void
userTransaction_T3(UserHandle * uh,
SubscriberNumber inNumber,
ServerId inServerId,
ServerBit inServerBit,
SessionDetails outSessionDetails,
BranchExecuted * outBranchExecuted){
Ndb * pNDB = uh->pNDB;
char outChangedBy [sizeof(ChangedBy) +(4-(sizeof(ChangedBy) & 3))];
char outChangedTime [sizeof(ChangedTime)+(4-(sizeof(ChangedTime) & 3))];
Location outLocation;
GroupId groupId;
ActiveSessions sessions;
Permission permission;
SubscriberSuffix inSuffix;
DEBUG3("T3(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
int check;
NdbRecAttr * check2;
NdbConnection * MyTransaction = startTransaction(pNDB, inServerId, inNumber);
if (MyTransaction == NULL)
error_handler("T3-1: startTranscation", pNDB->getNdbErrorString(), pNDB->getNdbError());
NdbOperation *MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
CHECK_NULL(MyOperation, "T3-1: getNdbOperation",
MyTransaction);
MyOperation->readTuple();
MyOperation->equal(IND_SUBSCRIBER_NUMBER,
inNumber);
MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
(char *)&outLocation);
MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
outChangedBy);
MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
outChangedTime);
MyOperation->getValue(IND_SUBSCRIBER_GROUP,
(char *)&groupId);
MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
(char *)&sessions);
check = MyTransaction->execute( NoCommit );
CHECK_MINUS_ONE(check, "T3-1: NoCommit",
MyTransaction);
/* Operation 2 */
MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
CHECK_NULL(MyOperation, "T3-2: getNdbOperation",
MyTransaction);
MyOperation->readTuple();
MyOperation->equal(IND_GROUP_ID,
(char*)&groupId);
MyOperation->getValue(IND_GROUP_ALLOW_READ,
(char *)&permission);
check = MyTransaction->execute( NoCommit );
CHECK_MINUS_ONE(check, "T3-2: NoCommit",
MyTransaction);
if(((permission & inServerBit) == inServerBit) &&
((sessions & inServerBit) == inServerBit)){
memcpy(inSuffix,
&inNumber[SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH], SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
DEBUG2("reading(%.*s) - ", SUBSCRIBER_NUMBER_SUFFIX_LENGTH, inSuffix);
/* Operation 3 */
MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
CHECK_NULL(MyOperation, "T3-3: getNdbOperation",
MyTransaction);
MyOperation->simpleRead();
MyOperation->equal(IND_SESSION_SUBSCRIBER,
(char*)inNumber);
MyOperation->equal(IND_SESSION_SERVER,
(char*)&inServerId);
MyOperation->getValue(IND_SESSION_DATA,
(char *)outSessionDetails);
//.........这里部分代码省略.........
示例11: main
int main(int argc, char** argv)
{
if (argc != 3)
{
std::cout << "Arguments are <socket mysqld> <connect_string cluster>.\n";
exit(-1);
}
char * mysqld_sock = argv[1];
const char *connectstring = argv[2];
ndb_init();
Ndb_cluster_connection *cluster_connection=
new Ndb_cluster_connection(connectstring); // Object representing the cluster
int r= cluster_connection->connect(5 /* retries */,
3 /* delay between retries */,
1 /* verbose */);
if (r > 0)
{
std::cout
<< "Cluster connect failed, possibly resolved with more retries.\n";
exit(-1);
}
else if (r < 0)
{
std::cout
<< "Cluster connect failed.\n";
exit(-1);
}
if (cluster_connection->wait_until_ready(30,0) < 0)
{
std::cout << "Cluster was not ready within 30 secs." << std::endl;
exit(-1);
}
// connect to mysql server
MYSQL mysql;
if ( !mysql_init(&mysql) ) {
std::cout << "mysql_init failed\n";
exit(-1);
}
if ( !mysql_real_connect(&mysql, "localhost", "root", "", "",
0, mysqld_sock, 0) )
MYSQLERROR(mysql);
/********************************************
* Connect to database via mysql-c *
********************************************/
mysql_query(&mysql, "CREATE DATABASE TEST_DB_1");
if (mysql_query(&mysql, "USE TEST_DB_1") != 0) MYSQLERROR(mysql);
create_table(mysql);
Ndb* myNdb = new Ndb( cluster_connection,
"TEST_DB_1" ); // Object representing the database
NdbTransaction* myNdbTransaction[2]; // For transactions
NdbOperation* myNdbOperation; // For operations
if (myNdb->init(2) == -1) { // Want two parallel insert transactions
APIERROR(myNdb->getNdbError());
exit(-1);
}
/******************************************************
* Insert (we do two insert transactions in parallel) *
******************************************************/
const NdbDictionary::Dictionary* myDict= myNdb->getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("MYTABLENAME");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
for (int i = 0; i < 2; i++) {
myNdbTransaction[i] = myNdb->startTransaction();
if (myNdbTransaction[i] == NULL) APIERROR(myNdb->getNdbError());
myNdbOperation = myNdbTransaction[i]->getNdbOperation(myTable);
if (myNdbOperation == NULL) APIERROR(myNdbTransaction[i]->getNdbError());
myNdbOperation->insertTuple();
myNdbOperation->equal("ATTR1", 20 + i);
myNdbOperation->setValue("ATTR2", 20 + i);
// Prepare transaction (the transaction is NOT yet sent to NDB)
myNdbTransaction[i]->executeAsynchPrepare(NdbTransaction::Commit,
&callback, NULL);
}
// Send all transactions to NDB
myNdb->sendPreparedTransactions(0);
// Poll all transactions
myNdb->pollNdb(3000, 2);
// Close all transactions
for (int i = 0; i < 2; i++)
myNdb->closeTransaction(myNdbTransaction[i]);
delete myNdb;
delete cluster_connection;
//.........这里部分代码省略.........
示例12: runTestBug34107
int runTestBug34107(NDBT_Context* ctx, NDBT_Step* step){
const NdbDictionary::Table * pTab = ctx->getTab();
Ndb* pNdb = GETNDB(step);
const Uint32 okSize= 10000;
const Uint32 tooBig= 30000;
Uint32 codeBuff[tooBig];
int i;
for (i = 0; i <= 1; i++) {
g_info << "bug34107:" << (i == 0 ? " small" : " too big") << endl;
NdbConnection* pTrans = pNdb->startTransaction();
if (pTrans == NULL){
ERR(pNdb->getNdbError());
return NDBT_FAILED;
}
NdbScanOperation* pOp = pTrans->getNdbScanOperation(pTab->getName());
if (pOp == NULL) {
ERR(pTrans->getNdbError());
pNdb->closeTransaction(pTrans);
return NDBT_FAILED;
}
if (pOp->readTuples() == -1) {
ERR(pOp->getNdbError());
pNdb->closeTransaction(pTrans);
return NDBT_FAILED;
}
/* Test kernel mechanism for dealing with too large program
* We need to provide our own program buffer as default
* NdbInterpretedCode buffer will not grow larger than
* NDB_MAX_SCANFILTER_SIZE
*/
NdbInterpretedCode code(NULL, // Table is irrelevant
codeBuff,
tooBig); // Size of codeBuff
int n = i == 0 ? okSize : tooBig;
int k;
for (k = 0; k < n; k++) {
// inserts 1 word ATTRINFO
if (code.interpret_exit_ok() == -1) {
ERR(code.getNdbError());
pNdb->closeTransaction(pTrans);
return NDBT_FAILED;
}
}
if (code.finalise() != 0)
{
ERR(code.getNdbError());
pNdb->closeTransaction(pTrans);
return NDBT_FAILED;
}
if (pOp->setInterpretedCode(&code) != 0)
{
ERR(pOp->getNdbError());
pNdb->closeTransaction(pTrans);
return NDBT_FAILED;
}
if (pTrans->execute(NoCommit) == -1) {
ERR(pTrans->getNdbError());
pNdb->closeTransaction(pTrans);
return NDBT_FAILED;
}
int ret;
while ((ret = pOp->nextResult()) == 0)
;
g_info << "ret=" << ret << " err=" << pOp->getNdbError().code << endl;
if (i == 0 && ret != 1) {
ERR(pTrans->getNdbError());
pNdb->closeTransaction(pTrans);
return NDBT_FAILED;
}
if (i == 1 && ret != -1) {
g_err << "unexpected big filter success" << endl;
pNdb->closeTransaction(pTrans);
return NDBT_FAILED;
}
if (i == 1 && pOp->getNdbError().code != 874) {
g_err << "unexpected big filter error code, wanted 874" << endl;
ERR(pTrans->getNdbError());
pNdb->closeTransaction(pTrans);
return NDBT_FAILED;
}
pNdb->closeTransaction(pTrans);
}
//.........这里部分代码省略.........
示例13: main
int main(int argc, char** argv)
{
if (argc != 3)
{
std::cout << "Arguments are <socket mysqld> <connect_string cluster>.\n";
exit(-1);
}
char * mysqld_sock = argv[1];
const char *connectstring = argv[2];
ndb_init();
MYSQL mysql;
/**************************************************************
* Connect to mysql server and create table *
**************************************************************/
{
if ( !mysql_init(&mysql) ) {
std::cout << "mysql_init failed\n";
exit(-1);
}
if ( !mysql_real_connect(&mysql, "localhost", "root", "", "",
0, mysqld_sock, 0) )
MYSQLERROR(mysql);
mysql_query(&mysql, "CREATE DATABASE ndb_examples_1");
if (mysql_query(&mysql, "USE ndb_examples") != 0) MYSQLERROR(mysql);
while (mysql_query(&mysql,
"CREATE TABLE"
" api_simple_index"
" (ATTR1 INT UNSIGNED,"
" ATTR2 INT UNSIGNED NOT NULL,"
" PRIMARY KEY USING HASH (ATTR1),"
" UNIQUE MYINDEXNAME USING HASH (ATTR2))"
" ENGINE=NDB"))
{
if (mysql_errno(&mysql) == ER_TABLE_EXISTS_ERROR)
{
std::cout << "MySQL Cluster already has example table: api_scan. "
<< "Dropping it..." << std::endl;
mysql_query(&mysql, "DROP TABLE api_simple_index");
}
else MYSQLERROR(mysql);
}
}
/**************************************************************
* Connect to ndb cluster *
**************************************************************/
Ndb_cluster_connection *cluster_connection=
new Ndb_cluster_connection(connectstring); // Object representing the cluster
if (cluster_connection->connect(5,3,1))
{
std::cout << "Connect to cluster management server failed.\n";
exit(-1);
}
if (cluster_connection->wait_until_ready(30,30))
{
std::cout << "Cluster was not ready within 30 secs.\n";
exit(-1);
}
Ndb* myNdb = new Ndb( cluster_connection,
"ndb_examples" ); // Object representing the database
if (myNdb->init() == -1) {
APIERROR(myNdb->getNdbError());
exit(-1);
}
const NdbDictionary::Dictionary* myDict= myNdb->getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("api_simple_index");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
const NdbDictionary::Index *myIndex= myDict->getIndex("MYINDEXNAME$unique","api_simple_index");
if (myIndex == NULL)
APIERROR(myDict->getNdbError());
/**************************************************************************
* Using 5 transactions, insert 10 tuples in table: (0,0),(1,1),...,(9,9) *
**************************************************************************/
for (int i = 0; i < 5; i++) {
NdbTransaction *myTransaction= myNdb->startTransaction();
if (myTransaction == NULL) APIERROR(myNdb->getNdbError());
NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->insertTuple();
myOperation->equal("ATTR1", i);
myOperation->setValue("ATTR2", i);
myOperation = myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->insertTuple();
myOperation->equal("ATTR1", i+5);
myOperation->setValue("ATTR2", i+5);
//.........这里部分代码省略.........
示例14: main
int main(int argc, char** argv)
{
if (argc != 3)
{
std::cout << "Arguments are <socket mysqld> <connect_string cluster>.\n";
exit(-1);
}
char * mysqld_sock = argv[1];
const char *connectstring = argv[2];
ndb_init();
MYSQL mysql;
/**************************************************************
* Connect to mysql server and create table *
**************************************************************/
{
if ( !mysql_init(&mysql) ) {
std::cout << "mysql_init failed\n";
exit(-1);
}
if ( !mysql_real_connect(&mysql, "localhost", "root", "", "",
0, mysqld_sock, 0) )
MYSQLERROR(mysql);
mysql_query(&mysql, "CREATE DATABASE ndb_examples");
if (mysql_query(&mysql, "USE ndb_examples") != 0) MYSQLERROR(mysql);
create_table(mysql);
}
/**************************************************************
* Connect to ndb cluster *
**************************************************************/
Ndb_cluster_connection cluster_connection(connectstring);
if (cluster_connection.connect(4, 5, 1))
{
std::cout << "Unable to connect to cluster within 30 secs." << std::endl;
exit(-1);
}
// Optionally connect and wait for the storage nodes (ndbd's)
if (cluster_connection.wait_until_ready(30,0) < 0)
{
std::cout << "Cluster was not ready within 30 secs.\n";
exit(-1);
}
Ndb* myNdb = new Ndb( &cluster_connection,
"ndb_examples" ); // Object representing the database
if (myNdb->init(1024) == -1) { // Set max 1024 parallel transactions
APIERROR(myNdb->getNdbError());
}
/**
* Initialise transaction array
*/
for(int i = 0 ; i < 10 ; i++)
{
transaction[i].used = 0;
transaction[i].conn = 0;
}
int i=0;
/**
* Do 10 insert transactions.
*/
while(i < 10)
{
while(populate(myNdb,i,0)<0) // <0, no space on free list. Sleep and try again.
milliSleep(10);
i++;
}
std::cout << "Number of temporary errors: " << tempErrors << std::endl;
delete myNdb;
}
示例15: updateTable
static void updateTable(Ndb &myNdb, unsigned int noOfTuples, unsigned int noOfOperations, bool oneTrans, bool twoKey, bool longKey)
{
Uint64 tbefore, tafter, before, after;
NdbConnection *myTrans;
NdbOperation *myOp;
char name[] = "Kalle0000000";
tbefore = NdbTick_CurrentMillisecond();
if (oneTrans) myTrans = myNdb.startTransaction();
for (unsigned int i = 0; i<noOfTuples; i++) {
if (!oneTrans) myTrans = myNdb.startTransaction();
for(unsigned int j = 1;
((j<=noOfOperations)&&(i<noOfTuples));
(++j<=noOfOperations)?i++:i) {
if (myTrans == NULL)
error_handler4(__LINE__, myNdb.getNdbError());
myOp = myTrans->getNdbOperation("PERSON");
if (myOp == NULL)
error_handler4(__LINE__, myTrans->getNdbError());
myOp->updateTuple();
sprintf(name, "Kalle%.7i", i);
if (longKey)
memcpy(longName, name, strlen(name));
if (myOp->equal("NAME", (longKey)?longName:name) == -1) {
error_handler4(__LINE__, myTrans->getNdbError());
myNdb.closeTransaction(myTrans);
break;
}
if (twoKey)
if (myOp->equal("KEY2", i) == -1) {
error_handler4(__LINE__, myTrans->getNdbError());
myNdb.closeTransaction(myTrans);
break;
}
if (myOp->setValue("PNUM1", 77) == -1) {
error_handler4(__LINE__, myTrans->getNdbError());
myNdb.closeTransaction(myTrans);
break;
}
if (myOp->setValue("PNUM2", 88)) {
error_handler4(__LINE__, myTrans->getNdbError());
myNdb.closeTransaction(myTrans);
break;
}
if (myOp->setValue("PNUM4", 99)) {
error_handler4(__LINE__, myTrans->getNdbError());
myNdb.closeTransaction(myTrans);
break;
}
if (myOp->setValue("AGE", 100) == -1) {
error_handler4(__LINE__, myTrans->getNdbError());
myNdb.closeTransaction(myTrans);
break;
}
if (myOp->setValue("STRING_AGE", hundred) == -1) {
error_handler4(__LINE__, myTrans->getNdbError());
myNdb.closeTransaction(myTrans);
break;
}
}
if (noOfOperations == 1)
printf("Trying to update person %s\n", name);
else
printf("Trying to update %u persons\n", noOfOperations);
before = NdbTick_CurrentMillisecond();
if (myTrans->execute( (oneTrans) ? NoCommit : Commit ) == -1)
{
error_handler4(__LINE__, myTrans->getNdbError());
myNdb.closeTransaction(myTrans);
break;
}
after = NdbTick_CurrentMillisecond();
if (noOfOperations == 1)
printf("Updated person %s, %u msec\n", name, (Uint32) after - before);
else
printf("Update %u persons, %u msec\n", noOfOperations, (Uint32) after - before);
if (!oneTrans) myNdb.closeTransaction(myTrans);
}
if (oneTrans) {
if (myTrans->execute( Commit ) == -1) {
error_handler4(__LINE__, myTrans->getNdbError());
}
myNdb.closeTransaction(myTrans);
}
tafter = NdbTick_CurrentMillisecond();
ndbout << "Updated "<< noOfTuples << " tuples in " << ((oneTrans) ? 1 : noOfTuples) << " transaction(s), " << tafter - tbefore << " msec" << endl;
}