Re: MsSQL IsNull and undef



Wow that post really got messed up, lost my additional info and used
older test script. Anyway here is correct stuff...

This is :
EasySoft
unixODBC-2.2.11
DBD-ODBC-1.13 (with test script below)
DBI-1.48

Latest test script:
#!perl -w -I./t

use Test::More;
$| = 1;

use_ok('DBI', qw(:sql_types));
use_ok('ODBCTEST');

# to help ActiveState's build process along by behaving (somewhat) if a
dsn is not provided
BEGIN {
if (!defined $ENV{DBI_DSN}) {
plan skip_all => "DBI_DSN is undefined";
} else {
plan tests =>4;
}
}


#DBI->trace(2);
my $dbh = DBI->connect();
unless($dbh) {
# BAILOUT("Unable to connect to the database ($DBI::errstr)\nTests
skipped.\n");
exit 0;
}

$dbh->{AutoCommit} = 1;

#### testing a simple select

my $rc = 0;
my $CustomerID;
my $sql="
Declare \@CustomerID varchar(20)
SET \@CustomerID=?
select * from ORders where CustomerID =
isnull(\@CustomerID,'VINET')
";
my $sth = $dbh->prepare(qq{$sql});
$sth->bind_param(1,$CustomerID);
$sth->execute();
my $RowCount=0;
while(my $row = $sth->fetchrow_hashref())
{
$RowCount++;
}
is($RowCount,5, "bind nulls");

my $sql2="
select * from ORders where CustomerID = isnull(?,'VINET')
";
my $sth2 = $dbh->prepare($sql2);
$sth2->bind_param(1,$CustomerID);
$sth2->execute();
$RowCount=0;
while(my $row = $sth2->fetchrow_hashref())
{
$RowCount++;
}
is($RowCount,5, "bind nulls");
# Test(1);
# clean up
$sth->finish;
exit(0);

__END__

.



Relevant Pages

  • MsSQL IsNull and undef
    ... I am having a problem trying to bind an undefined value directly into ... an IsNull statement. ... together (sorry just learning this whole test script stuff). ... This is done against SQL 2000 Northwind database. ...
    (perl.dbi.users)
  • RE: MsSQL DBD::ODBC IsNull and undef
    ... I presume by "Easysoft" you mean Easysoft ODBC-ODBC Bridge? ... can you run your test script again but creating an OOB log file which ... > if I create a SQL variable, bind the undef to that, and then use the SQL ... I have created a test script that duplicates ...
    (perl.dbi.users)