31.07.2013 Views

MySQL Cluster Tutorial - cdn.oreillystatic.com

MySQL Cluster Tutorial - cdn.oreillystatic.com

MySQL Cluster Tutorial - cdn.oreillystatic.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

const NdbDictionary::Index *myPIndex= myDict->getIndex("PRIMARY", "COUNTRY");<br />

if (myPIndex == NULL)<br />

APIERROR(myDict->getNdbError());<br />

std::cout getNdbError());<br />

Uint32 scanFlags=<br />

NdbScanOperation::SF_OrderBy |<br />

NdbScanOperation::SF_MultiRange |<br />

NdbScanOperation::SF_ReadRangeNo;<br />

if (psop->readTuples(NdbOperation::LM_Read,<br />

scanFlags,<br />

(Uint32) 0, // batch<br />

(Uint32) 0) != 0) // parallel<br />

APIERROR (myTransaction->getNdbError());<br />

/* Add a bound<br />

* Tuples where SUB_ID >=2 and < 4<br />

*/<br />

Uint32 low=2;<br />

Uint32 high=4;<br />

Uint32 match=13;<br />

if (psop->setBound("SUB_ID", NdbIndexScanOperation::BoundLE, (char*)&low))<br />

APIERROR(myTransaction->getNdbError());<br />

if (psop->setBound("SUB_ID", NdbIndexScanOperation::BoundGT, (char*)&high))<br />

APIERROR(myTransaction->getNdbError());<br />

if (psop->end_of_bound(0))<br />

APIERROR(psop->getNdbError());<br />

/* Second bound<br />

* Tuples where SUB_ID > 5 and setBound("SUB_ID", NdbIndexScanOperation::BoundLT, (char*)&low))<br />

APIERROR(myTransaction->getNdbError());<br />

if (psop->setBound("SUB_ID", NdbIndexScanOperation::BoundGE, (char*)&high))<br />

APIERROR(myTransaction->getNdbError());<br />

if (psop->end_of_bound(1))<br />

APIERROR(psop->getNdbError());<br />

/* Third bound<br />

* Tuples where SUB_ID == 13<br />

*/<br />

if (psop->setBound("SUB_ID", NdbIndexScanOperation::BoundEQ, (char*)&match))<br />

APIERROR(myTransaction->getNdbError());<br />

if (psop->end_of_bound(2))<br />

APIERROR(psop->getNdbError());<br />

/* Read all columns */<br />

recAttrAttr1=psop->getValue("SUB_ID");<br />

recAttrAttr2=psop->getValue("COUNTRY_CODE");<br />

if(myTransaction->execute( NdbTransaction::Commit ) != 0)<br />

APIERROR(myTransaction->getNdbError());<br />

if (myTransaction->getNdbError().code != 0)<br />

APIERROR(myTransaction->getNdbError());<br />

Copyright © 2010, Oracle and/or its affiliates. All rights reserved. 47/81

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!