NULLs are not sent or received correctly with prepared stmt api

Bug #1150195 reported by Wim Lewis
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Drizzle Client & Protocol Library
Fix Released
High
Andrew Hutchings

Bug Description

Setting a parameter of a prepared statement to NULL using drizzle_stmt_set_null() doesn't result in a NULL being inserted in the database.
Retrieving a row containing a NULL doesn't result in drizzle_stmt_get_is_null() returning true for that column.

The problem is probably the null-bitmap manipulation code in statement.cc, which looks really dubious:

        /* Toggle the bit for this column in the bitmap */
        *stmt->null_bitmap |= (current_param ^ 2);

and

    /* if this row is null in the result bitmap */
    if (*stmt->execute_result->null_bitmap & ((column_counter^2) << 2))

in both cases, it's using an XOR where a shift was probably meant, and also not indexing into null_bitmap properly (so it'll fail for more than 8 columns/parameters). Probably want to use something like the FD_SET/FD_ISSET macros that select provides, or the bitstring.h macros that the BSDs have, but modified for the 8-bit element size, e.g.:

#define null_bitmap_setbit(null_bitmap, bit) null_bitmap[bit / 8] |= (1 << (bit & 0x7))
#define null_bitmap_isset(null_bitmap, bit) (null_bitmap[bit / 8] & (1 << (bit & 0x7)))

The nulls.c unit test in my unit-tests branch tests this code path.

Related branches

Changed in libdrizzle:
milestone: none → 5.1.4
Revision history for this message
Andrew Hutchings (linuxjedi) wrote :

oh wow! I must have been really tired when coding that logic :(

You are completely correct, I intended them to be shifts. Now that it is multi-byte your approach seems good to me.

Changed in libdrizzle:
importance: Undecided → High
assignee: nobody → Andrew Hutchings (linuxjedi)
status: New → Triaged
Changed in libdrizzle:
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.