NDB API examples, the trivia to make ndbapi_scan works!

PREVIOUS POST
NEXT POST

When I did NDB Cluster engagements, it happened a few time that I had to cover the NDB API. Once, a customer asked an example on how to perform a simple scan. Remembering that some examples are within the NDB source tree, under ./storage/ndb/ndbapi-examples/ and I decided to take a look, why writing something when a good example already exists… I was not expecting what I found!

1. Missing headers

Hmmm, some header files are missing, let’s add them

2. The clean up code

With the added header files, the program compiles flawlessly. Let’s try it!

My bad…. I did a typo in the IP of the MGM server. Easy to correct…

What’s that? Wow… look at the create_table code…

That one is sweet, no need to be a C guru to catch it… it is fairly obvious where the problem is isn’t it? Let’s remove the recursive “create_table” call.

3. Success

$ LD_LIBRARY_PATH=/usr/local/mysql-cluster-gpl-7.0.8a/lib/mysql ./ndbapi_scan /usr/local/mysql-cluster-gpl-7.0.8a/mysql.sock 127.0.0.1
Connecting…Connected!
Initializing NDB…Done
Looking for table GARAGE…Got it! = GARAGE
Getting the columns…
Done
Populating…populate: Success!
Scanning and printing…0 Mercedes Blue
12 Toyota Pink
5 BMW Black
7 BMW Black
3 Mercedes Blue
9 BMW Black
10 Toyota Pink
14 Toyota Pink
11 Toyota Pink
1 Mercedes Blue
13 Toyota Pink
6 BMW Black
2 Mercedes Blue
4 Mercedes Blue
8 BMW Black
scan_print: Success!

Going to delete all pink cars!
Deleting pink cars…No error
Done
0 Mercedes Blue
5 BMW Black
7 BMW Black
3 Mercedes Blue
9 BMW Black
1 Mercedes Blue
6 BMW Black
2 Mercedes Blue
4 Mercedes Blue
8 BMW Black
scan_print: Success!

Going to update all Blue cars to Black cars!
No error
0 Mercedes Black
5 BMW Black
7 BMW Black
3 Mercedes Black
9 BMW Black
1 Mercedes Black
6 BMW Black
2 Mercedes Black
4 Mercedes Black
8 BMW Black
scan_print: Success!

I know that these programs are just examples. But yet, they are in some way part of the documentation and the quality is, let’s say, subject to questions.

PREVIOUS POST
NEXT POST

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *