Blame t/19_bindparam.t

Packit 723767
#!/usr/bin/perl
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 => 39;
Packit 723767
use Test::NoWarnings;
Packit 723767
use DBI ':sql_types';
Packit 723767
Packit 723767
# Create a database
Packit 723767
my $dbh = connect_ok( dbfile => 'foo', RaiseError => 1, PrintError => 1, PrintWarn => 1 );
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 NOT NULL,
Packit 723767
    name CHAR (64) NULL
Packit 723767
)
Packit 723767
END_SQL
Packit 723767
Packit 723767
my $konig = "Andreas K\xf6nig";
Packit 723767
Packit 723767
SCOPE: {
Packit 723767
	my $sth = $dbh->prepare("INSERT INTO one VALUES ( ?, ? )");
Packit 723767
	isa_ok( $sth, 'DBI::st' );
Packit 723767
	
Packit 723767
	# Automatic type detection
Packit 723767
	my $number = 1;
Packit 723767
	my $char   = "A";
Packit 723767
	ok( $sth->execute($number, $char), 'EXECUTE 1' );
Packit 723767
Packit 723767
	# Does the driver remember the automatically detected type?
Packit 723767
	ok( $sth->execute("3", "Jochen Wiedmann"), 'EXECUTE 2' );
Packit 723767
	$number = 2;
Packit 723767
	$char   = "Tim Bunce";
Packit 723767
	ok( $sth->execute($number, $char), 'EXECUTE 3');
Packit 723767
Packit 723767
	# Now try the explicit type settings
Packit 723767
	ok( $sth->bind_param(1, " 4", SQL_INTEGER), 'bind 1' );
Packit 723767
	ok( $sth->bind_param(2, $konig), 'bind 2' );
Packit 723767
	ok( $sth->execute, '->execute' );
Packit 723767
Packit 723767
	# Works undef -> NULL?
Packit 723767
	ok( $sth->bind_param(1, 5, SQL_INTEGER), 'bind 3' );
Packit 723767
	ok( $sth->bind_param(2, undef), 'bind 4' );
Packit 723767
	ok( $sth->execute, '->execute' );
Packit 723767
Packit 723767
	# Works with PADTMPs?
Packit 723767
	my @values = (6, "Larry");
Packit 723767
	for (my $i=0; $i<2; $i++) {
Packit 723767
		ok( $sth->bind_param($i+1, "$values[$i]"), 'bind '.($i+5) );
Packit 723767
	}
Packit 723767
	ok( $sth->execute, '->execute' );
Packit 723767
}
Packit 723767
Packit 723767
# Reconnect
Packit 723767
ok( $dbh->disconnect, '->disconnect' );
Packit 723767
$dbh = connect_ok( dbfile => 'foo' );
Packit 723767
SCOPE: {
Packit 723767
	my $sth = $dbh->prepare("SELECT * FROM one ORDER BY id");
Packit 723767
	isa_ok( $sth, 'DBI::st' );
Packit 723767
	ok( $sth->execute, '->execute' );
Packit 723767
	my $id   = undef;
Packit 723767
	my $name = undef;
Packit 723767
	ok( $sth->bind_columns(undef, \$id, \$name), '->bind_columns' );
Packit 723767
	ok( $sth->fetch, '->fetch' );
Packit 723767
	is( $id,   1,   'id = 1'   );
Packit 723767
	is( $name, 'A', 'name = A' );
Packit 723767
	ok( $sth->fetch, '->fetch' );
Packit 723767
	is( $id,   2,   'id = 2'   );
Packit 723767
	is( $name, 'Tim Bunce', 'name = Tim Bunce' );
Packit 723767
	ok( $sth->fetch, '->fetch' );
Packit 723767
	is( $id,   3,   'id = 3'   );
Packit 723767
	is( $name, 'Jochen Wiedmann', 'name = Jochen Wiedmann' );
Packit 723767
	ok( $sth->fetch, '->fetch' );
Packit 723767
	is( $id,   4,   'id = 4'   );
Packit 723767
	is( $name, $konig, 'name = $konig' );
Packit 723767
	ok( $sth->fetch, '->fetch' );
Packit 723767
	is( $id,   5,   'id = 5'   );
Packit 723767
	is( $name, undef, 'name = undef' );
Packit 723767
	ok( $sth->fetch, '->fetch' );
Packit 723767
	is( $id,   6,   'id = 6'   );
Packit 723767
	is( $name, 'Larry', 'name = Larry' );
Packit 723767
}