I have Perl 5.8.8 built for Windows x64 from Activestate (version 822)
installed on a Windows 2003 x64 bit server (Xeon processor).

I have installed version 1.59 of DBI and version 1.14 of DBD::ODBC compiled
for x64 bit, using the freely available Microsoft SDK.

The ODBC-ODBC bridge used is supposed to be for 64 bit, as described by
Microsoft.

I ran the attached test script and get an error:
DBD::ODBC::st execute failed:
[Microsoft][ODBC SQL Server Driver]Invalid string or buffer length
(SQL-HY090)(DBD: st_execute/SQLExecute err=-1) at test_dbd-odbc.pl line 48.

This seems to be due to passing an undef value as an argument in the
DBI->execute() call.

The same script runs flawlessly on a in32.
The script also runs flawlessly if I use the DBD::mysql driver built for
Windows x64 bit.

Is this a bug in DBD::ODBC or in the Microsoft ODBC driver?

Attached script:
#!/usr/bin/perl
#
# Test script for DBD::ODBC for 64/32 bit Windows

use DBI;


# define $user and $password for your database
my $dsn = "dbi:ODBC:my_database_schema";


my $dbh;
eval {
    $dbh = DBI->connect($dsn, $user, $password,
                        { AutoCommit => 0, RaiseError => 0});

    if (! defined $dbh) {
        print "Cannot connect to database with DSN = $dsn";
        exit(0);
    } else {
        print "Connected to SQL Server with parameters:\n",
              "    DSN         = $dsn\n",
              "    User        = $user\n",
              "    Password    = ******\n";
    }

    my $drop_stmt = "if object_id(N'my_test',N'U') is not null " .
                    "drop table my_test";
    $sth = $dbh->prepare($drop_stmt);
    $sth->execute();

    # create a table with one key and all other columns optional
    my $create_stmt =
        'create table my_test ' .
        '   (col        nvarchar(80) not null,' .
        '    str        nvarchar(20))';
    my $sth = $dbh->prepare($create_stmt);
    $sth->execute();

    # insert a simple row with three nulls
    my $value = undef;
    my $insert_one =
        'insert into my_test (col, str) values (?, ?)';
    $sth = $dbh->prepare($insert_one);
    $sth->execute('This is my key!', $value);

    # on Windows x64 the above statement fails because of the last argument
    $dbh->commit();

    my $key;
    my $str;
    my $select = 'select col, str from my_test';
    $sth = $dbh->prepare($select);
    $sth->execute();

    $sth->bind_col(1, \$key);
    $sth->bind_col(2, \$str);
    while ($sth->fetch) {
        print "Retrieved ";
        if (! defined $str) {
            $str = "<null>";
        }
        print "($key, $str) ";
        print " from database table\n";
    }


    $dbh->commit();

    $dbh->disconnect;
};
if ($@) {
    print "Error in connecting to the database DSN: $dsn\n";
    if (defined $dbh) {
        $dbh->rollback();
        print "with error " . $dbh->errstr() . "\n";
    }
}

1;

Reply via email to