Hi,
I probably hit bug in DBD::ODBC when it is compiled with unicode support.
I found that when I have table with NVARCHAR() column and try to write
NULL (undef) value by placeholder, perl write 'Use of uninitialized
value in subroutine entry at xxx.pl line xx.', where xxx.pl and xx are
name of my code and line with execute().
I tested it on MS Windows 2k, 2k3 and 2k8 with multiple versions of
MS-SQL server and its ODBC driver. I used ActivePerl 5.10 with DBD::ODBC
1.16.
Later I found that when I'm trying insert NULL to other types of
column, no message is shown.
Sample sequence:
# table
# CREATE TABLE test (
# c1 NVARCHAR(100)
# );
# connect to db...
# do prepare and execute
$dbh=$db->prepare('INSERT INTO test VALUES (?)');
$dbh->execute(undef); # Message is shown
Then I searched for source of message and I found that problem is in
dbdimp.c. Nonunicode branch checks if value is undef and handles it
different way than defined values. Same code is missing on unicode branch.
I tested attached patch with DBD::ODBC 1.20 and it works. I would like
to report it as bug.
May someone check patch and my finding before I will try to contribute
patch to current version of DBD::ODBC?
Yours,
Jirka Novak
diff -r DBD-ODBC-1.20.orig/dbdimp.c DBD-ODBC-1.20/dbdimp.c
3151c3151,3157
< phs->sv_buf=SvPV(phs->sv,value_len);
---
> if (SvOK(phs->sv)) {
> phs->sv_buf=SvPV(phs->sv,value_len);
> }else{ /* it's undef but if it was inout param it would point to a
> * valid buffer, at least */
> phs->sv_buf = SvPVX(phs->sv);
> value_len = 0;
> }