本文整理汇总了C++中NdbOperation::deleteTuple方法的典型用法代码示例。如果您正苦于以下问题:C++ NdbOperation::deleteTuple方法的具体用法?C++ NdbOperation::deleteTuple怎么用?C++ NdbOperation::deleteTuple使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NdbOperation
的用法示例。
在下文中一共展示了NdbOperation::deleteTuple方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DeleteTransaction
int DeleteTransaction(Ndb* pNdb, long iContextId, NdbError& err)
{
int iRes = -1;
NdbConnection* pNdbConnection = pNdb->startTransaction(0, (const char*)&iContextId, 4);
if(pNdbConnection)
{
NdbOperation* pNdbOperation = pNdbConnection->getNdbOperation(g_szTableName);
if(pNdbOperation)
{
if(!pNdbOperation->deleteTuple()
&& !pNdbOperation->equal(c_szContextId, (Int32)iContextId))
{
if(pNdbConnection->execute(Commit) == 0)
iRes = 0;
else
err = pNdbConnection->getNdbError();
}
else
err = pNdbOperation->getNdbError();
}
else
err = pNdbConnection->getNdbError();
pNdb->closeTransaction(pNdbConnection);
}
else
err = pNdb->getNdbError();
return iRes;
}
示例2: pkDeleteRecord
int HugoOperations::pkDeleteRecord(Ndb* pNdb,
int recordNo,
int numRecords){
int check;
for(int r=0; r < numRecords; r++){
NdbOperation* pOp = getOperation(pTrans, NdbOperation::DeleteRequest);
if (pOp == NULL) {
ERR(pTrans->getNdbError());
setNdbError(pTrans->getNdbError());
return NDBT_FAILED;
}
check = pOp->deleteTuple();
if( check == -1 ) {
ERR(pTrans->getNdbError());
setNdbError(pTrans->getNdbError());
return NDBT_FAILED;
}
// Define primary keys
if (equalForRow(pOp, r+recordNo) != 0)
return NDBT_FAILED;
Uint32 partId;
if(getPartIdForRow(pOp, r+recordNo, partId))
pOp->setPartitionId(partId);
}
return NDBT_OK;
}
示例3: removeLogs
void FsMutationsTableTailer::removeLogs(const NdbDictionary::Dictionary* database, NdbTransaction* transaction, Fmq* rows) {
const NdbDictionary::Table* log_table = getTable(database, TABLE.mTableName);
for(Fmq::iterator it=rows->begin(); it != rows->end() ; ++it){
FsMutationRow row = *it;
NdbOperation* op = getNdbOperation(transaction, log_table);
op->deleteTuple();
op->equal(_mutation_cols[0].c_str(), row.mDatasetId);
op->equal(_mutation_cols[1].c_str(), row.mInodeId);
op->equal(_mutation_cols[2].c_str(), (Int64)row.mTimestamp);
LOG_TRACE("Delete log row: Dataset[" << row.mDatasetId << "], INode["
<< row.mInodeId << "], Timestamp[" << row.mTimestamp << "]");
}
}
示例4: do_delete
static void do_delete(struct Trans_arg &trans_arg, NdbEventOperation *pOp)
{
if (!trans_arg.trans)
return;
NdbOperation *op =
trans_arg.trans->getNdbOperation(pOp->getEvent()->getTableName());
op->deleteTuple();
do_equal(op, pOp);
trans_arg.bytes_batched++;
if (trans_arg.bytes_batched > BATCH_SIZE)
{
trans_arg.trans->execute(NdbTransaction::NoCommit);
trans_arg.bytes_batched = 0;
}
}
示例5: exit
void
BackupRestore::logEntry(const LogEntry & tup)
{
if (!m_restore)
return;
NdbTransaction * trans = m_ndb->startTransaction();
if (trans == NULL)
{
// TODO: handle the error
ndbout << "Cannot start transaction" << endl;
exit(-1);
} // if
const TableS * table = tup.m_table;
NdbOperation * op = trans->getNdbOperation(table->getTableName());
if (op == NULL)
{
ndbout << "Cannot get operation: ";
ndbout << trans->getNdbError() << endl;
exit(-1);
} // if
int check = 0;
switch(tup.m_type)
{
case LogEntry::LE_INSERT:
check = op->insertTuple();
break;
case LogEntry::LE_UPDATE:
check = op->updateTuple();
break;
case LogEntry::LE_DELETE:
check = op->deleteTuple();
break;
default:
ndbout << "Log entry has wrong operation type."
<< " Exiting...";
exit(-1);
}
for (int i = 0; i < tup.m_values.size(); i++)
{
const AttributeS * attr = tup.m_values[i];
int size = attr->Desc->size;
int arraySize = attr->Desc->arraySize;
const char * dataPtr = attr->Data.string_value;
const Uint32 length = (size / 8) * arraySize;
if (attr->Desc->m_column->getPrimaryKey())
op->equal(attr->Desc->attrId, dataPtr, length);
else
op->setValue(attr->Desc->attrId, dataPtr, length);
}
#if 1
trans->execute(Commit);
#else
const int ret = trans->execute(Commit);
// Both insert update and delete can fail during log running
// and it's ok
if (ret != 0)
{
ndbout << "execute failed: ";
ndbout << trans->getNdbError() << endl;
exit(-1);
}
#endif
m_ndb->closeTransaction(trans);
m_logCount++;
}
示例6: DEBUG
//.........这里部分代码省略.........
MyTransaction);
check = MyOperation->readTuple();
CHECK_MINUS_ONE(check, "T5-2: readTuple",
MyTransaction);
check = MyOperation->equal(IND_GROUP_ID,
(char*)&groupId);
CHECK_MINUS_ONE(check, "T5-2: equal group",
MyTransaction);
check2 = MyOperation->getValue(IND_GROUP_ALLOW_DELETE,
(char *)&permission);
CHECK_NULL(check2, "T5-2: getValue allow_delete",
MyTransaction);
check = MyTransaction->execute( NoCommit );
CHECK_MINUS_ONE(check, "T5-2: NoCommit",
MyTransaction);
DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
if(((permission & inServerBit) == inServerBit) &&
((sessions & inServerBit) == inServerBit)) {
DEBUG("deleting - ");
/* Operation 3 */
MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
CHECK_NULL(MyOperation, "T5-3: getNdbOperation",
MyTransaction);
check = MyOperation->deleteTuple();
CHECK_MINUS_ONE(check, "T5-3: deleteTuple",
MyTransaction);
check = MyOperation->equal(IND_SESSION_SUBSCRIBER,
(char*)inNumber);
CHECK_MINUS_ONE(check, "T5-3: equal number",
MyTransaction);
check = MyOperation->equal(IND_SESSION_SERVER,
(char*)&inServerId);
CHECK_MINUS_ONE(check, "T5-3: equal server id",
MyTransaction);
check = MyTransaction->execute( NoCommit );
CHECK_MINUS_ONE(check, "T5-3: NoCommit",
MyTransaction);
/* Operation 4 */
MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
CHECK_NULL(MyOperation, "T5-4: getNdbOperation",
MyTransaction);
check = MyOperation->interpretedUpdateTuple();
CHECK_MINUS_ONE(check, "T5-4: interpretedUpdateTuple",
MyTransaction);
check = MyOperation->equal(IND_SUBSCRIBER_NUMBER,
(char*)inNumber);
CHECK_MINUS_ONE(check, "T5-4: equal number",
MyTransaction);
check = MyOperation->subValue(IND_SUBSCRIBER_SESSIONS,
示例7: memcpy
void
T5_Callback_2(int result, NdbConnection * pCON, void * threadData){
CHECK_MINUS_ONE(result, "T5-2: NoCommit", pCON);
ThreadData * td = (ThreadData *)threadData;
Uint32 permission = td->transactionData.permission;
Uint32 sessions = td->transactionData.sessions;
Uint32 server_bit = td->transactionData.server_bit;
if(((permission & server_bit) == server_bit) &&
((sessions & server_bit) == server_bit)){
memcpy(td->transactionData.suffix,
&td->transactionData.number
[SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH],
SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
DEBUG5("T5(%.*s, %.2d): - Callback 2 - deleting(%.*s)\n",
SUBSCRIBER_NUMBER_LENGTH,
td->transactionData.number,
td->transactionData.server_id,
SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
td->transactionData.suffix);
/* Operation 3 */
NdbOperation * MyOp = pCON->getNdbOperation(SESSION_TABLE);
CHECK_NULL(MyOp, "T5-3: getNdbOperation",
pCON);
MyOp->deleteTuple();
MyOp->equal(IND_SESSION_SUBSCRIBER,
(char*)td->transactionData.number);
MyOp->equal(IND_SESSION_SERVER,
(char*)&td->transactionData.server_id);
/* Operation 4 */
/* Operation 5 */
MyOp = pCON->getNdbOperation(SERVER_TABLE);
CHECK_NULL(MyOp, "T5-5: getNdbOperation",
pCON);
MyOp->interpretedUpdateTuple();
MyOp->equal(IND_SERVER_ID,
(char*)&td->transactionData.server_id);
MyOp->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
(char*)td->transactionData.suffix);
MyOp->incValue(IND_SERVER_DELETES, (uint32)1);
td->transactionData.branchExecuted = 1;
} else {
td->transactionData.branchExecuted = 0;
DEBUG5("T5(%.*s, %.2d): - Callback 2 - no delete - %s %s\n",
SUBSCRIBER_NUMBER_LENGTH,
td->transactionData.number,
td->transactionData.server_id,
((permission & server_bit) ?
"permission - " : "no permission - "),
((sessions & server_bit) ?
"in session - " : "no in session - "));
}
if(!td->transactionData.do_rollback && td->transactionData.branchExecuted){
pCON->executeAsynchPrepare(Commit, T5_Callback_3, td);
} else {
pCON->executeAsynchPrepare(Rollback, T5_Callback_3, td);
}
}
示例8: memcpy
void
T5_Callback_2(int result, NdbConnection * pCON, void * threadData){
ThreadData * td = (ThreadData *)threadData;
if (result == -1) {
CHECK_ALLOWED_ERROR("T5-2: execute", td, pCON->getNdbError());
td->pNDB->closeTransaction(pCON);
start_T5(td->pNDB, td, stat_async);
return;
}//if
Uint32 permission = td->transactionData.permission;
Uint32 sessions = td->transactionData.sessions;
Uint32 server_bit = td->transactionData.server_bit;
if(((permission & server_bit) == server_bit) &&
((sessions & server_bit) == server_bit)){
memcpy(td->transactionData.suffix,
&td->transactionData.number[SFX_START],
SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
DEBUG5("T5(%.*s, %.2d): - Callback 2 - deleting(%.*s)",
SUBSCRIBER_NUMBER_LENGTH,
td->transactionData.number,
td->transactionData.server_id,
SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
td->transactionData.suffix);
/* Operation 3 */
NdbOperation * MyOp = pCON->getNdbOperation(SESSION_TABLE);
CHECK_NULL(MyOp, "T5-3: getNdbOperation", td,
pCON->getNdbError());
MyOp->deleteTuple();
MyOp->equal(IND_SESSION_SUBSCRIBER,
(char*)td->transactionData.number);
MyOp->equal(IND_SESSION_SERVER,
(char*)&td->transactionData.server_id);
/* Operation 4 */
/* Operation 5 */
MyOp = pCON->getNdbOperation(SERVER_TABLE);
CHECK_NULL(MyOp, "T5-5: getNdbOperation", td,
pCON->getNdbError());
MyOp->interpretedUpdateTuple();
MyOp->equal(IND_SERVER_ID,
(char*)&td->transactionData.server_id);
MyOp->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
(char*)td->transactionData.suffix);
MyOp->incValue(IND_SERVER_DELETES, (uint32)1);
td->transactionData.branchExecuted = 1;
} else {
td->transactionData.branchExecuted = 0;
DEBUG5("T5(%.*s, %.2d): - Callback 2 - no delete - %s %s",
SUBSCRIBER_NUMBER_LENGTH,
td->transactionData.number,
td->transactionData.server_id,
((permission & server_bit) ?
"permission - " : "no permission - "),
((sessions & server_bit) ?
"in session - " : "no in session - "));
}
if(!td->transactionData.do_rollback && td->transactionData.branchExecuted){
if (stat_async == 1) {
pCON->executeAsynchPrepare( Commit , T5_Callback_3, td);
} else {
int result = pCON->execute( Commit );
T5_Callback_3(result, pCON, (void*)td);
return;
}//if
} else {
if (stat_async == 1) {
pCON->executeAsynchPrepare( Rollback , T5_Callback_3, td);
} else {
int result = pCON->execute( Rollback );
T5_Callback_3(result, pCON, (void*)td);
return;
}//if
}
}
示例9: memcpy
/**
* Transaction 5 - T5
*
* Delete session
*
* Input:
* SubscriberNumber
* ServerId
* ServerBit
* DoRollback
* Output:
* ChangedBy
* ChangedTime
* Location
* BranchExecuted
*/
void
userTransaction_T5(UserHandle * uh,
SubscriberNumber inNumber,
ServerId inServerId,
ServerBit inServerBit,
DoRollback inDoRollback,
BranchExecuted * outBranchExecuted){
Ndb * pNDB = uh->pNDB;
DEBUG3("T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
NdbConnection * MyTransaction = 0;
NdbOperation * MyOperation = 0;
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;
int check;
NdbRecAttr * check2;
MyTransaction = pNDB->startTransaction();
if (MyTransaction == NULL)
error_handler("T5-1: startTranscation", pNDB->getNdbErrorString(), pNDB->getNdbError());
MyOperation= MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
CHECK_NULL(MyOperation, "T5-1: getNdbOperation",
MyTransaction);
MyOperation->interpretedUpdateTuple();
MyOperation->equal(IND_SUBSCRIBER_NUMBER,
inNumber);
MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
(char *)&outLocation);
MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
&outChangedBy[0]);
MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
&outChangedTime[0]);
MyOperation->getValue(IND_SUBSCRIBER_GROUP,
(char *)&groupId);
MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
(char *)&sessions);
MyOperation->subValue(IND_SUBSCRIBER_SESSIONS,
(uint32)inServerBit);
MyTransaction->execute( NoCommit );
/* Operation 2 */
MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
CHECK_NULL(MyOperation, "T5-2: getNdbOperation",
MyTransaction);
MyOperation->readTuple();
MyOperation->equal(IND_GROUP_ID,
(char*)&groupId);
MyOperation->getValue(IND_GROUP_ALLOW_DELETE,
(char *)&permission);
check = MyTransaction->execute( NoCommit );
CHECK_MINUS_ONE(check, "T5-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("deleting(%.*s) - ", SUBSCRIBER_NUMBER_SUFFIX_LENGTH, inSuffix);
/* Operation 3 */
MyOperation = MyTransaction->getNdbOperation(SESSION_TABLE);
CHECK_NULL(MyOperation, "T5-3: getNdbOperation",
MyTransaction);
MyOperation->deleteTuple();
MyOperation->equal(IND_SESSION_SUBSCRIBER,
(char*)inNumber);
MyOperation->equal(IND_SESSION_SERVER,
(char*)&inServerId);
/* Operation 4 */
//.........这里部分代码省略.........
示例10: memcpy
void
T5_Callback_2(int result, NdbConnection * pCON, void * threadData) {
ThreadData * td = (ThreadData *)threadData;
if (result == -1) {
CHECK_ALLOWED_ERROR("T5-2: execute", td, pCON->getNdbError());
td->pNDB->closeTransaction(pCON);
start_T5(td->pNDB, td, stat_async);
return;
}//if
Uint32 permission = td->transactionData.permission;
Uint32 sessions = td->transactionData.sessions;
Uint32 server_bit = td->transactionData.server_bit;
if(((permission & server_bit) == server_bit) &&
((sessions & server_bit) == server_bit)) {
memcpy(td->transactionData.suffix,
&td->transactionData.number[SFX_START],
SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
DEBUG5("T5(%.*s, %.2d): - Callback 2 - deleting(%.*s)",
SUBSCRIBER_NUMBER_LENGTH,
td->transactionData.number,
td->transactionData.server_id,
SUBSCRIBER_NUMBER_SUFFIX_LENGTH,
td->transactionData.suffix);
if (td->ndbRecordSharedData)
{
char* rowPtr= (char*) &td->transactionData;
const NdbRecord* record= td->ndbRecordSharedData->
sessionTableNdbRecord;
Uint32 m=0;
unsigned char* mask= (unsigned char*) &m;
const NdbOperation* MyOp= pCON->deleteTuple(record, rowPtr, record);
CHECK_NULL((void*) MyOp, "T5-3: deleteTuple", td,
pCON->getNdbError());
record= td->ndbRecordSharedData->
serverTableNdbRecord;
m= 0;
NdbOperation::OperationOptions opts;
opts.optionsPresent= NdbOperation::OperationOptions::OO_INTERPRETED;
opts.interpretedCode= td->ndbRecordSharedData->incrServerDeletesProg;
MyOp= pCON->updateTuple(record, rowPtr, record, rowPtr, mask,
&opts, sizeof(opts));
CHECK_NULL((void*)MyOp, "T5-2: updateTuple", td,
pCON->getNdbError());
}
else
{
/* Operation 3 */
NdbOperation * MyOp = pCON->getNdbOperation(SESSION_TABLE);
CHECK_NULL(MyOp, "T5-3: getNdbOperation", td,
pCON->getNdbError());
MyOp->deleteTuple();
MyOp->equal(IND_SESSION_SUBSCRIBER,
(char*)td->transactionData.number);
MyOp->equal(IND_SESSION_SERVER,
(char*)&td->transactionData.server_id);
/* Operation 4 */
/* Operation 5 */
MyOp = pCON->getNdbOperation(SERVER_TABLE);
CHECK_NULL(MyOp, "T5-5: getNdbOperation", td,
pCON->getNdbError());
MyOp->interpretedUpdateTuple();
MyOp->equal(IND_SERVER_ID,
(char*)&td->transactionData.server_id);
MyOp->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
(char*)td->transactionData.suffix);
MyOp->incValue(IND_SERVER_DELETES, (uint32)1);
}
td->transactionData.branchExecuted = 1;
} else {
td->transactionData.branchExecuted = 0;
DEBUG5("T5(%.*s, %.2d): - Callback 2 - no delete - %s %s",
SUBSCRIBER_NUMBER_LENGTH,
td->transactionData.number,
td->transactionData.server_id,
((permission & server_bit) ?
"permission - " : "no permission - "),
((sessions & server_bit) ?
"in session - " : "no in session - "));
}
if(!td->transactionData.do_rollback && td->transactionData.branchExecuted) {
if (stat_async == 1) {
pCON->executeAsynchPrepare( Commit , T5_Callback_3, td);
} else {
int result = pCON->execute( Commit );
T5_Callback_3(result, pCON, (void*)td);
//.........这里部分代码省略.........
示例11: allocTransactions
int
HugoAsynchTransactions::executeAsynchOperation(Ndb* pNdb,
int records,
int batch,
int trans,
int operations,
NDB_OPERATION theOperation,
ExecType theType) {
int check = 0;
// int retryAttempt = 0; // Not used at the moment
// int retryMax = 5; // Not used at the moment
int cTrans = 0;
int cRecords = 0;
int cIndex = 0;
int a,t,r;
transactionsCompleted = 0;
allocTransactions(trans);
for (int i = 0; i < batch; i++) { // For each batch
while (cRecords < records*batch) {
cTrans = 0;
cIndex = 0;
for (t = 0; t < trans; t++) { // For each transaction
transactions[t] = pNdb->startTransaction();
if (transactions[t] == NULL) {
ERR(pNdb->getNdbError());
return NDBT_FAILED;
}
for (int k = 0; k < operations; k++) { // For each operation
NdbOperation* pOp = transactions[t]->getNdbOperation(tab.getName());
if (pOp == NULL) {
ERR(transactions[t]->getNdbError());
pNdb->closeTransaction(transactions[t]);
return NDBT_FAILED;
}
switch (theOperation) {
case NO_INSERT:
// Insert
check = pOp->insertTuple();
if (check == -1) {
ERR(transactions[t]->getNdbError());
pNdb->closeTransaction(transactions[t]);
return NDBT_FAILED;
}
// Set a calculated value for each attribute in this table
for (a = 0; a < tab.getNoOfColumns(); a++) {
if (setValueForAttr(pOp, a, cRecords, 0 ) != 0) {
ERR(transactions[t]->getNdbError());
pNdb->closeTransaction(transactions[t]);
return NDBT_FAILED;
}
} // For each attribute
break;
case NO_UPDATE:
// This is a special case and is handled in the calling client...
break;
break;
case NO_READ:
// Define primary keys
check = pOp->readTuple();
for (a = 0; a < tab.getNoOfColumns(); a++) {
if (tab.getColumn(a)->getPrimaryKey() == true) {
if (equalForAttr(pOp, a, cRecords) != 0){
ERR(transactions[t]->getNdbError());
pNdb->closeTransaction(transactions[t]);
return NDBT_FAILED;
}
}
}
// Define attributes to read
for (a = 0; a < tab.getNoOfColumns(); a++) {
if ((rows[cIndex]->attributeStore(a) =
pOp->getValue(tab.getColumn(a)->getName())) == 0) {
ERR(transactions[t]->getNdbError());
pNdb->closeTransaction(transactions[t]);
return NDBT_FAILED;
}
}
break;
case NO_DELETE:
// Delete
check = pOp->deleteTuple();
if (check == -1) {
ERR(transactions[t]->getNdbError());
pNdb->closeTransaction(transactions[t]);
return NDBT_FAILED;
}
// Define primary keys
for (a = 0; a < tab.getNoOfColumns(); a++) {
if (tab.getColumn(a)->getPrimaryKey() == true){
if (equalForAttr(pOp, a, cRecords) != 0) {
ERR(transactions[t]->getNdbError());
pNdb->closeTransaction(transactions[t]);
return NDBT_FAILED;
}
//.........这里部分代码省略.........
示例12: deleteTable
static void deleteTable(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->deleteTuple();
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 (noOfOperations == 1)
printf("Trying to delete person %s\n", name);
else
printf("Trying to delete %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("Deleted person %s, %u msec\n", name, (Uint32) after - before);
else
printf("Deleted %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 << "Deleted "<< noOfTuples << " tuples in " << ((oneTrans) ? 1 : noOfTuples) << " transaction(s), " << tafter - tbefore << " msec" << endl;
}
示例13: exitHandler
void
BackupRestore::logEntry(const LogEntry & tup)
{
if (!m_restore)
return;
NdbTransaction * trans = m_ndb->startTransaction();
if (trans == NULL)
{
// Deep shit, TODO: handle the error
err << "Cannot start transaction" << endl;
exitHandler();
} // if
const NdbDictionary::Table * table = get_table(tup.m_table->m_dictTable);
NdbOperation * op = trans->getNdbOperation(table);
if (op == NULL)
{
err << "Cannot get operation: " << trans->getNdbError() << endl;
exitHandler();
} // if
int check = 0;
switch(tup.m_type)
{
case LogEntry::LE_INSERT:
check = op->insertTuple();
break;
case LogEntry::LE_UPDATE:
check = op->updateTuple();
break;
case LogEntry::LE_DELETE:
check = op->deleteTuple();
break;
default:
err << "Log entry has wrong operation type."
<< " Exiting...";
exitHandler();
}
if (check != 0)
{
err << "Error defining op: " << trans->getNdbError() << endl;
exitHandler();
} // if
Bitmask<4096> keys;
for (Uint32 i= 0; i < tup.size(); i++)
{
const AttributeS * attr = tup[i];
int size = attr->Desc->size;
int arraySize = attr->Desc->arraySize;
const char * dataPtr = attr->Data.string_value;
if (tup.m_table->have_auto_inc(attr->Desc->attrId))
tup.m_table->update_max_auto_val(dataPtr,size*arraySize);
const Uint32 length = (size / 8) * arraySize;
if (attr->Desc->m_column->getPrimaryKey())
{
if(!keys.get(attr->Desc->attrId))
{
keys.set(attr->Desc->attrId);
check= op->equal(attr->Desc->attrId, dataPtr, length);
}
}
else
check= op->setValue(attr->Desc->attrId, dataPtr, length);
if (check != 0)
{
err << "Error defining op: " << trans->getNdbError() << endl;
exitHandler();
} // if
}
const int ret = trans->execute(NdbTransaction::Commit);
if (ret != 0)
{
// Both insert update and delete can fail during log running
// and it's ok
// TODO: check that the error is either tuple exists or tuple does not exist?
bool ok= false;
NdbError errobj= trans->getNdbError();
switch(tup.m_type)
{
case LogEntry::LE_INSERT:
if(errobj.status == NdbError::PermanentError &&
errobj.classification == NdbError::ConstraintViolation)
ok= true;
break;
case LogEntry::LE_UPDATE:
case LogEntry::LE_DELETE:
if(errobj.status == NdbError::PermanentError &&
errobj.classification == NdbError::NoDataFound)
ok= true;
break;
}
if (!ok)
{
//.........这里部分代码省略.........