|
Packit |
723767 |
#!/usr/bin/perl
|
|
Packit |
723767 |
|
|
Packit |
723767 |
# This is a test for correctly handling NULL values.
|
|
Packit |
723767 |
|
|
Packit |
723767 |
use strict;
|
|
Packit |
723767 |
BEGIN {
|
|
Packit |
723767 |
$| = 1;
|
|
Packit |
723767 |
$^W = 1;
|
|
Packit |
723767 |
}
|
|
Packit |
723767 |
|
|
Packit |
723767 |
use lib "t/lib";
|
|
Packit |
723767 |
use SQLiteTest;
|
|
Packit |
723767 |
use Test::More tests => 9;
|
|
Packit |
723767 |
|
|
Packit |
723767 |
# Create a database
|
|
Packit |
723767 |
my $dbh = connect_ok();
|
|
Packit |
723767 |
|
|
Packit |
723767 |
# Create the table
|
|
Packit |
723767 |
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
|
|
Packit |
723767 |
CREATE TABLE one (
|
|
Packit |
723767 |
id INTEGER,
|
|
Packit |
723767 |
name CHAR (64)
|
|
Packit |
723767 |
)
|
|
Packit |
723767 |
END_SQL
|
|
Packit |
723767 |
|
|
Packit |
723767 |
# Test whether or not a field containing a NULL is returned correctly
|
|
Packit |
723767 |
# as undef, or something much more bizarre.
|
|
Packit |
723767 |
ok(
|
|
Packit |
723767 |
$dbh->do('INSERT INTO one VALUES ( NULL, ? )', {}, 'NULL-valued id' ),
|
|
Packit |
723767 |
'INSERT',
|
|
Packit |
723767 |
);
|
|
Packit |
723767 |
|
|
Packit |
723767 |
SCOPE: {
|
|
Packit |
723767 |
my $sth = $dbh->prepare('SELECT * FROM one WHERE id IS NULL');
|
|
Packit |
723767 |
isa_ok( $sth, 'DBI::st' );
|
|
Packit |
723767 |
ok( $sth->execute, '->execute ok' );
|
|
Packit |
723767 |
my $row = $sth->fetchrow_arrayref;
|
|
Packit |
723767 |
is( scalar(@$row), 2, 'Two values in the row' );
|
|
Packit |
723767 |
is( $row->[0], undef, 'First column is undef' );
|
|
Packit |
723767 |
is( $row->[1], 'NULL-valued id', 'Second column is defined' );
|
|
Packit |
723767 |
ok( $sth->finish, '->finish' );
|
|
Packit |
723767 |
}
|