diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2012-09-24 10:15:50 +0000 |
---|---|---|
committer | Lorry <lorry@roadtrain.codethink.co.uk> | 2012-09-26 13:46:46 +0000 |
commit | 485b97be9f2f2abf5a40923b5fd85f75714a8c02 (patch) | |
tree | ca05cb0ecf3828d909a898c3e5805804a0aff5f8 /t/19_bindparam.t | |
download | perl-dbd-sqlite-tarball-master.tar.gz |
Imported from /srv/lorry/lorry-area/perl-dbd-sqlite-tarball/DBD-SQLite-1.38_01.tar.gz.HEADDBD-SQLite-1.38_01masterbaserock/morph
Diffstat (limited to 't/19_bindparam.t')
-rw-r--r-- | t/19_bindparam.t | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/t/19_bindparam.t b/t/19_bindparam.t new file mode 100644 index 0000000..025f8af --- /dev/null +++ b/t/19_bindparam.t @@ -0,0 +1,88 @@ +#!/usr/bin/perl + +use strict; +BEGIN { + $| = 1; + $^W = 1; +} + +use t::lib::Test; +use Test::More tests => 39; +use Test::NoWarnings; +use DBI ':sql_types'; + +# Create a database +my $dbh = connect_ok( dbfile => 'foo', RaiseError => 1, PrintError => 1, PrintWarn => 1 ); + +# Create the table +ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' ); +CREATE TABLE one ( + id INTEGER NOT NULL, + name CHAR (64) NULL +) +END_SQL + +my $konig = "Andreas K\xf6nig"; + +SCOPE: { + my $sth = $dbh->prepare("INSERT INTO one VALUES ( ?, ? )"); + isa_ok( $sth, 'DBI::st' ); + + # Automatic type detection + my $number = 1; + my $char = "A"; + ok( $sth->execute($number, $char), 'EXECUTE 1' ); + + # Does the driver remember the automatically detected type? + ok( $sth->execute("3", "Jochen Wiedmann"), 'EXECUTE 2' ); + $number = 2; + $char = "Tim Bunce"; + ok( $sth->execute($number, $char), 'EXECUTE 3'); + + # Now try the explicit type settings + ok( $sth->bind_param(1, " 4", SQL_INTEGER), 'bind 1' ); + ok( $sth->bind_param(2, $konig), 'bind 2' ); + ok( $sth->execute, '->execute' ); + + # Works undef -> NULL? + ok( $sth->bind_param(1, 5, SQL_INTEGER), 'bind 3' ); + ok( $sth->bind_param(2, undef), 'bind 4' ); + ok( $sth->execute, '->execute' ); + + # Works with PADTMPs? + my @values = (6, "Larry"); + for (my $i=0; $i<2; $i++) { + ok( $sth->bind_param($i+1, "$values[$i]"), 'bind '.($i+5) ); + } + ok( $sth->execute, '->execute' ); +} + +# Reconnect +ok( $dbh->disconnect, '->disconnect' ); +$dbh = connect_ok( dbfile => 'foo' ); +SCOPE: { + my $sth = $dbh->prepare("SELECT * FROM one ORDER BY id"); + isa_ok( $sth, 'DBI::st' ); + ok( $sth->execute, '->execute' ); + my $id = undef; + my $name = undef; + ok( $sth->bind_columns(undef, \$id, \$name), '->bind_columns' ); + ok( $sth->fetch, '->fetch' ); + is( $id, 1, 'id = 1' ); + is( $name, 'A', 'name = A' ); + ok( $sth->fetch, '->fetch' ); + is( $id, 2, 'id = 2' ); + is( $name, 'Tim Bunce', 'name = Tim Bunce' ); + ok( $sth->fetch, '->fetch' ); + is( $id, 3, 'id = 3' ); + is( $name, 'Jochen Wiedmann', 'name = Jochen Wiedmann' ); + ok( $sth->fetch, '->fetch' ); + is( $id, 4, 'id = 4' ); + is( $name, $konig, 'name = $konig' ); + ok( $sth->fetch, '->fetch' ); + is( $id, 5, 'id = 5' ); + is( $name, undef, 'name = undef' ); + ok( $sth->fetch, '->fetch' ); + is( $id, 6, 'id = 6' ); + is( $name, 'Larry', 'name = Larry' ); +} |