예제 #1
0
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;
}
예제 #2
0
void scan_rows(Ndb* pMyNdb, int opType, int tupleType, int scanType) {

    int           check = -1 ;
    int           loop_count_ops = nRecords ;
    int           eOf = -1 ;
    int           readValue = 0 ;
    int           readValue2 = 0 ;
    int           scanCount = 0 ;
    TTYPE         fail = NO_FAIL ;

    for (int count=0 ; count < loop_count_ops ; count++)    {
        NdbConnection* MyTransaction = pMyNdb->startTransaction();
        if (!MyTransaction) error_handler(pMyNdb->getNdbError(), NO_FAIL);

        NdbOperation*  MyOperation = MyTransaction->getNdbOperation(tableName);
        if (!MyOperation) error_handler(pMyNdb->getNdbError(), NO_FAIL);

        if (opType == 1)
            // Open for scan read, Creates the SCAN_TABREQ and if needed
            // SCAN_TABINFO signals.
            check = MyOperation->openScanRead(1);
        else if (opType == 2)
            // Open for scan with update of rows.
            check = MyOperation->openScanExclusive(1);

        // Create ATTRINFO signal(s) for interpreted program used for
        // defining search criteria and column values that should be returned.

        scanCount = count+1 ;

        switch(tupleType) {
        case 1:
            fail = t_exitMethods(scanCount, MyOperation,  opType);
            break;
        case 2:
            fail = t_incValue(scanCount, MyOperation);
            break;
        case 3:
            fail = t_subValue(scanCount, MyOperation);
            break;
        case 4:
            fail = t_readAttr(scanCount, MyOperation);
            break;
        case 5:
            fail = t_writeAttr(scanCount, MyOperation);
            break;
        case 6:
            fail = t_loadConst(scanCount, MyOperation,  opType);
            break;
        case 7:
            fail = t_branch(scanCount, MyOperation);
            break;
        case 8:
            fail = t_branchIfNull(scanCount, MyOperation);
            break;
        case 9:
            fail = t_addReg(scanCount, MyOperation);
            break;
        case 10:
            fail = t_subReg(scanCount, MyOperation);
            break;
        case 11:
            fail = t_subroutineWithBranchLabel(scanCount, MyOperation);
            break;
        default:
            break ;
        }

        if(11 != tupleType) MyOperation->getValue(attrName[1], (char*)&readValue);

        // Sends the SCAN_TABREQ, (SCAN_TABINFO) and ATTRINFO signals and then
        // reads the answer in TRANSID_AI. Confirmation is received through SCAN_TABCONF or
        // SCAN_TABREF if failure.
        check = MyTransaction->executeScan();
        if (check == -1) {
            //ndbout << endl << "executeScan returned: " << MyTransaction->getNdbError() << endl;
            error_handler(MyTransaction->getNdbError(), fail) ;
            pMyNdb->closeTransaction(MyTransaction);
        } else {
            // Sends the SCAN_NEXTREQ signal(s) and reads the answer in TRANS_ID signals.
            // SCAN_TABCONF or SCAN_TABREF is the confirmation.
            while ((eOf = MyTransaction->nextScanResult()) == 0) {
                ndbout << readValue <<"; ";
                // Here we call takeOverScanOp for update of the tuple.
            }
            ndbout << endl ;

            pMyNdb->closeTransaction(MyTransaction);
            if (eOf == -1) {
                ndbout << endl << "nextScanResult returned: "<< MyTransaction->getNdbError() << endl;
            } else {
                ndbout << "OK" << endl;
            }
        }
    }
    return;

};