Bug #24306 SQLBulkOperations always uses indicator varables' values from the first record
Submitted: 14 Nov 2006 16:58 Modified: 30 Apr 2007 14:01
Reporter: Alessio Biasutto Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / ODBC Severity:S1 (Critical)
Version:3.51.12 OS:Microsoft Windows (Windows XP)
Assigned to: Jim Winstead CPU Architecture:Any

[14 Nov 2006 16:58] Alessio Biasutto
Description:
SQLBulkOperations always uses indicator varables' values from the first record. This implies that if the indicator for a column is set to SQL_NULL_DATA in the first record then that column will assume NULL value in all the added records, if the indicator is 0 or grater the column will always have not null value in all the added records.

Looking to the code of batch_insert you can notice that the indicator is extracted from the bind->pcbValue field without any displacement. On the countrary the column value is extracted using a displacement: 
bind->rgbValue+count*(stmt->stmt_options.bind_type)

How to repeat:
Normal usage of SQLBulkOperations adding more than one record and using different values for the indicators 

Suggested fix:
Indicator has to be extrated using 
bind->pcbValue+count*(stmt->stmt_options.bind_type)
[21 Nov 2006 16:06] Bogdan Degtyariov
Alessio,

Do you have any test case for your bug report?
It would hasten the diagnostic of the problem and bug fix.
Thank you.
[22 Nov 2006 11:48] Alessio Biasutto
The Use case is quite easy:
1) Create a table with one integer field only 
2) Try to insert 10 records using SQLBulkOperations
  2a) the indicator for the first record is set to SQL_NULL_DATA, the indicator for the others is not set to SQL_NULL_DATA. In this case ALL the inserted records are NULL
  2b) the indicator for the first record is not set to SQL_NULL_DATA, the indicator for the others is set to SQL_NULL_DATA. In this case ALL the inserted records are NOT NULL

BTW, I had a look to the code and provided a proposal for fixing the bug.
[22 Nov 2006 12:09] Bogdan Degtyariov
Alessio,

thanks for your response. Could you provide any URL or bug report where you suggested the bug fix so our developers could look at it?
Thanks.
[22 Nov 2006 15:23] Alessio Biasutto
It is already in this bug report, within my description of the bug (at least I can read it within this thread)
[22 Nov 2006 16:10] Bogdan Degtyariov
Ok, thanks for comments. I'll upload a C test case after it is finished and try to apply your fix to batch_insert() function.
[22 Nov 2006 22:17] Bogdan Degtyariov
test case

Attachment: my_bulk.c (text/x-csrc), 2.07 KiB.

[22 Nov 2006 22:18] Bogdan Degtyariov
header file included by the test case

Attachment: mytest3.h (text/plain), 17.65 KiB.

[23 Nov 2006 20:59] Bogdan Degtyariov
Alessio,

please try the test case below and check whether it reflects the problem as you described. I checked your suggestion and it really fixes the work of this test case.
Thanks.
[23 Nov 2006 21:01] Bogdan Degtyariov
Updated test case

Attachment: my_bulk.c (text/x-csrc), 2.07 KiB.

[12 Mar 2007 21:21] Jim Winstead
patch to fix problems with indicators during batch insert

Attachment: bug24306.diff (application/octet-stream, text), 13.29 KiB.

[12 Mar 2007 21:31] Jim Winstead
The patch I just attached fixes this problem, which basically meant that we were not handling SQL_NULL_DATA and SQL_COLUMN_IGNORE for batch insert operations.
[21 Mar 2007 22:33] Jim Winstead
updated patch that also handles bind offsets and row-wise binding (plus more tests)

Attachment: bug24306.diff (application/octet-stream, text), 16.83 KiB.

[27 Apr 2007 18:08] Jim Winstead
The fix for this bug has been committed to the repository, and will be in the next release (3.51.15).

Thanks for the bug report.
[30 Apr 2007 14:01] MC Brown
A note has been added to the 3.51.15 changelog.