本文整理汇总了C++中NdbOperation::writeTuple方法的典型用法代码示例。如果您正苦于以下问题:C++ NdbOperation::writeTuple方法的具体用法?C++ NdbOperation::writeTuple怎么用?C++ NdbOperation::writeTuple使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NdbOperation
的用法示例。
在下文中一共展示了NdbOperation::writeTuple方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
void
BackupRestore::tuple(const TupleS & tup)
{
if (!m_restore)
return;
while (1)
{
NdbTransaction * trans = m_ndb->startTransaction();
if (trans == NULL)
{
// Deep shit, TODO: handle the error
ndbout << "Cannot start transaction" << endl;
exitHandler();
} // if
const TableS * table = tup.getTable();
NdbOperation * op = trans->getNdbOperation(table->getTableName());
if (op == NULL)
{
ndbout << "Cannot get operation: ";
ndbout << trans->getNdbError() << endl;
exitHandler();
} // if
// TODO: check return value and handle error
if (op->writeTuple() == -1)
{
ndbout << "writeTuple call failed: ";
ndbout << trans->getNdbError() << endl;
exitHandler();
} // if
for (int i = 0; i < tup.getNoOfAttributes(); i++)
{
const AttributeS * attr = tup[i];
int size = attr->Desc->size;
int arraySize = attr->Desc->arraySize;
const char * dataPtr = attr->Data.string_value;
const Uint32 length = (size * arraySize) / 8;
if (attr->Desc->m_column->getPrimaryKey())
op->equal(i, dataPtr, length);
}
for (int i = 0; i < tup.getNoOfAttributes(); i++)
{
const AttributeS * attr = tup[i];
int size = attr->Desc->size;
int arraySize = attr->Desc->arraySize;
const char * dataPtr = attr->Data.string_value;
const Uint32 length = (size * arraySize) / 8;
if (!attr->Desc->m_column->getPrimaryKey())
if (attr->Data.null)
op->setValue(i, NULL, 0);
else
op->setValue(i, dataPtr, length);
}
int ret = trans->execute(NdbTransaction::Commit);
if (ret != 0)
{
ndbout << "execute failed: ";
ndbout << trans->getNdbError() << endl;
exitHandler();
}
m_ndb->closeTransaction(trans);
if (ret == 0)
break;
}
m_dataCount++;
}
示例2: sizeof
/* set all the unique attrs of this objectclass into the table
*/
extern "C" int
ndb_oc_attrs(
NdbTransaction *txn,
const NdbDictionary::Table *myTable,
Entry *e,
NdbOcInfo *no,
NdbAttrInfo **attrs,
int nattrs,
Attribute *old
)
{
char buf[65538], *ptr;
Attribute **an, **ao, *a;
NdbOperation *myop;
int i, j, max = 0;
int changed, rc;
Uint64 eid = e->e_id;
if ( !nattrs )
return 0;
an = (Attribute **)ch_malloc( 2 * nattrs * sizeof(Attribute *));
ao = an + nattrs;
/* Turn lists of attrs into arrays for easier access */
for ( i=0; i<nattrs; i++ ) {
if ( attrs[i]->na_oi != no ) {
an[i] = NULL;
ao[i] = NULL;
continue;
}
for ( a=e->e_attrs; a; a=a->a_next ) {
if ( a->a_desc == slap_schema.si_ad_objectClass )
continue;
if ( a->a_desc->ad_type == attrs[i]->na_attr ) {
/* Don't process same attr twice */
if ( a->a_flags & SLAP_ATTR_IXADD )
a = NULL;
else
a->a_flags |= SLAP_ATTR_IXADD;
break;
}
}
an[i] = a;
if ( a && a->a_numvals > max )
max = a->a_numvals;
for ( a=old; a; a=a->a_next ) {
if ( a->a_desc == slap_schema.si_ad_objectClass )
continue;
if ( a->a_desc->ad_type == attrs[i]->na_attr )
break;
}
ao[i] = a;
if ( a && a->a_numvals > max )
max = a->a_numvals;
}
for ( i=0; i<max; i++ ) {
myop = NULL;
for ( j=0; j<nattrs; j++ ) {
if ( !an[j] && !ao[j] )
continue;
changed = 0;
if ( an[j] && an[j]->a_numvals > i ) {
/* both old and new are present, compare for changes */
if ( ao[j] && ao[j]->a_numvals > i ) {
if ( ber_bvcmp( &ao[j]->a_nvals[i], &an[j]->a_nvals[i] ))
changed = V_REP;
} else {
changed = V_INS;
}
} else {
if ( ao[j] && ao[j]->a_numvals > i )
changed = V_DEL;
}
if ( changed ) {
if ( !myop ) {
rc = LDAP_OTHER;
myop = txn->getNdbOperation( myTable );
if ( !myop ) {
goto done;
}
if ( old ) {
if ( myop->writeTuple()) {
goto done;
}
} else {
if ( myop->insertTuple()) {
goto done;
}
}
if ( myop->equal( EID_COLUMN, eid )) {
goto done;
}
if ( myop->equal( VID_COLUMN, i )) {
goto done;
}
}
//.........这里部分代码省略.........
示例3: tuple_a
void BackupRestore::tuple_a(restore_callback_t *cb)
{
while (cb->retries < 10)
{
/**
* start transactions
*/
cb->connection = m_ndb->startTransaction();
if (cb->connection == NULL)
{
if (errorHandler(cb))
{
m_ndb->sendPollNdb(3000, 1);
continue;
}
exitHandler();
} // if
const TupleS &tup = cb->tup;
const NdbDictionary::Table * table = get_table(tup.getTable()->m_dictTable);
NdbOperation * op = cb->connection->getNdbOperation(table);
if (op == NULL)
{
if (errorHandler(cb))
continue;
exitHandler();
} // if
if (op->writeTuple() == -1)
{
if (errorHandler(cb))
continue;
exitHandler();
} // if
int ret = 0;
for (int j = 0; j < 2; j++)
{
for (int i = 0; i < tup.getNoOfAttributes(); i++)
{
const AttributeDesc * attr_desc = tup.getDesc(i);
const AttributeData * attr_data = tup.getData(i);
int size = attr_desc->size;
int arraySize = attr_desc->arraySize;
char * dataPtr = attr_data->string_value;
Uint32 length = (size * arraySize) / 8;
if (j == 0 && tup.getTable()->have_auto_inc(i))
tup.getTable()->update_max_auto_val(dataPtr,size*arraySize);
if (attr_desc->m_column->getPrimaryKey())
{
if (j == 1) continue;
ret = op->equal(i, dataPtr, length);
}
else
{
if (j == 0) continue;
if (attr_data->null)
ret = op->setValue(i, NULL, 0);
else
ret = op->setValue(i, dataPtr, length);
}
if (ret < 0) {
ndbout_c("Column: %d type %d %d %d %d",i,
attr_desc->m_column->getType(),
size, arraySize, attr_data->size);
break;
}
}
if (ret < 0)
break;
}
if (ret < 0)
{
if (errorHandler(cb))
continue;
exitHandler();
}
// Prepare transaction (the transaction is NOT yet sent to NDB)
cb->connection->executeAsynchPrepare(NdbTransaction::Commit,
&callback, cb);
m_transactions++;
return;
}
err << "Retried transaction " << cb->retries << " times.\nLast error"
<< m_ndb->getNdbError(cb->error_code) << endl
<< "...Unable to recover from errors. Exiting..." << endl;
exitHandler();
}