Bug #30737 ndbapi_scan example does not work
Submitted: 30 Aug 2007 23:24 Modified: 13 Apr 2010 22:34
Reporter: John David Duncan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: NDB API Severity:S3 (Non-critical)
Version:mysql-5.1 OS:Any
Assigned to: John David Duncan CPU Architecture:Any
Tags: 5.0, 5.1

[30 Aug 2007 23:24] John David Duncan
Description:
The ndbapi_scan example does not really work.

(See also: bug 30552)

Here's the output you *should* see.  Note how the pink cars are deleted and the blue cars turn black.

-bash-3.00$ ./ndbapi_scan /tmp/mysql.sock localhost 
populate: Success!
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!
No error
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!

How to repeat:
cd storage/ndb/ndbapi-examples 
make
cd ndbapi_scan 
./ndbapi_scan /tmp/mysql.sock localhost 

Suggested fix:
The problem is the NdbScanFilter::cmp() requires a length argument when used with strings.  

Here is a fix:

-bash-3.00$ rcsdiff ndbapi_scan.cpp
===================================================================
RCS file: ndbapi_scan.cpp,v
retrieving revision 1.1
diff -r1.1 ndbapi_scan.cpp
295c295
<        filter.cmp(NdbScanFilter::COND_EQ, column, color) < 0 ||
---
>        filter.cmp(NdbScanFilter::COND_EQ, column, color, 20) < 0 ||
474c474
<        filter.cmp(NdbScanFilter::COND_EQ, update_column, before_color) <0||
---
>        filter.cmp(NdbScanFilter::COND_EQ, update_column, before_color, 20) <0||
[3 Sep 2007 14:47] Hartmut Holzgraefe
Verified wrong behavior on both 5.0 and 5.1,
the patch only fixes 5.1 though, 5.0 still
produces the same wrong results after it.

I also don't think the patch is the right
solution to this, the way i read

  http://dev.mysql.com/doc/ndbapi/en/class-ndbscanfilter-cmp.html

it implies that not passing in a length
information makes it auto detect a sensible
default

if that doesn't work then making this an optional
parameter only seems to be a wrong choice
[7 Sep 2007 4:17] John David Duncan
I agree -- either the documentation is incorrect, or there is a bug in the NDB API.

For what it's worth, mysqld sets the length parameter when calling cmp()
[7 Mar 2008 7:42] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/43560

ChangeSet@1.2586, 2008-03-07 15:40:50+08:00, gni@dev3-221.dev.cn.tlan +1 -0
  BUG#30737 ndbapi_scan doesn't work
[10 Apr 2008 6:50] Guangbao Ni
pushed into mysql-5.0-ndb-bj and mysql-5.1-new-ndb-bj
[31 May 2008 10:27] Jon Stephens
See also my note in Bug #30553.
[2 Jun 2008 1:02] Guangbao Ni
See also my note in Bug #30553. :-)
[24 Feb 2010 17:42] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/101359

3103 John David Duncan	2010-02-24
      Fix for bug#30552 and bug#30737 
      Use lowercase table names so that the example will run on Mac & Windows.
[5 Mar 2010 23:06] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/102483

3131 John David Duncan	2010-03-05 [merge]
      Fix for bug#30552 and bug#30737 plus cleanup of NDB API examples
[5 Mar 2010 23:07] Bugs System
Pushed into 5.1.41-ndb-6.3.33 (revid:jdd@sun.com-20100305230516-oxekqu0eov1i32ur) (version source revid:jdd@sun.com-20100305230516-oxekqu0eov1i32ur) (merge vers: 5.1.41-ndb-6.3.33) (pib:16)
[6 Mar 2010 0:26] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/102485

3429 John David Duncan	2010-03-05
           Fix for bug#30552 and bug#30737 plus cleanup of NDB API examples
[9 Mar 2010 12:32] Bugs System
Pushed into 5.1.41-ndb-7.0.14 (revid:jonas@mysql.com-20100309122618-bqu4zub69rlky588) (version source revid:jonas@mysql.com-20100309122618-bqu4zub69rlky588) (merge vers: 5.1.41-ndb-7.0.14) (pib:16)
[12 Apr 2010 16:11] Jon Stephens
Updated status.
[13 Apr 2010 22:34] Jon Stephens
Documented together with BUG#30552 -- see that bug report for changelog entry.

Closed.