|
| 1 | +#! /usr/bin/env perl |
| 2 | + |
| 3 | +# vim: noet ts=2 sw=2: |
| 4 | + |
| 5 | +use strict; |
| 6 | +use warnings; |
| 7 | +use Test::More tests => 17; |
| 8 | + |
| 9 | +use Storable qw(dclone); |
| 10 | +use DBI qw(:sql_types); |
| 11 | + |
| 12 | +our @ROWS = (['foo', undef, 'bazooka'], |
| 13 | + ['foolery', 'bar', undef ], |
| 14 | + [undef, 'barrowman', 'baz' ]); |
| 15 | + |
| 16 | +my $dbh = DBI->connect("dbi:Sponge:", '', ''); |
| 17 | +ok($dbh, "connect(dbi:Sponge:) succeeds"); |
| 18 | + |
| 19 | +my $sth = $dbh->prepare("simple, correct sponge", { |
| 20 | + rows => dclone( \@ROWS ), |
| 21 | + NAME => [ qw(A0 B1 C2) ], |
| 22 | + }); |
| 23 | + |
| 24 | +ok($sth, "prepare() of 3x3 result succeeded"); |
| 25 | +is_deeply($sth->{NAME}, ['A0', 'B1', 'C2'], "column NAMEs as expected"); |
| 26 | +is_deeply($sth->{TYPE}, [SQL_VARCHAR, SQL_VARCHAR, SQL_VARCHAR], |
| 27 | + "column TYPEs default to SQL_VARCHAR"); |
| 28 | +is_deeply($sth->{PRECISION}, [7, 9, 7], |
| 29 | + "column PRECISION matches lengths of longest field data"); |
| 30 | +is_deeply($sth->fetch(), $ROWS[0], "first row fetch as expected"); |
| 31 | +is_deeply($sth->fetch(), $ROWS[1], "second row fetch as expected"); |
| 32 | +is_deeply($sth->fetch(), $ROWS[2], "third row fetch as expected"); |
| 33 | +ok(!defined($sth->fetch()), "fourth fetch returns undef"); |
| 34 | + |
| 35 | + |
| 36 | +$sth = $dbh->prepare('user-supplied silly TYPE and PRECISION', { |
| 37 | + rows => dclone( \@ROWS ), |
| 38 | + NAME => [qw( first_col second_col third_col )], |
| 39 | + TYPE => [SQL_INTEGER, SQL_DATETIME, SQL_CHAR], |
| 40 | + PRECISION => [1, 100_000, 0], |
| 41 | + }); |
| 42 | +ok($sth, "prepare() 3x3 result with TYPE and PRECISION succeeded"); |
| 43 | +is_deeply($sth->{NAME}, ['first_col','second_col','third_col'], |
| 44 | + "column NAMEs again as expected"); |
| 45 | +is_deeply($sth->{TYPE}, [SQL_INTEGER, SQL_DATETIME, SQL_CHAR], |
| 46 | + "column TYPEs not overwritten"); |
| 47 | +is_deeply($sth->{PRECISION}, [1, 100_000, 0], |
| 48 | + "column PRECISION not overwritten"); |
| 49 | +is_deeply($sth->fetch(), $ROWS[0], "first row fetch as expected, despite bogus attributes"); |
| 50 | +is_deeply($sth->fetch(), $ROWS[1], "second row fetch as expected, despite bogus attributes"); |
| 51 | +is_deeply($sth->fetch(), $ROWS[2], "third row fetch as expected, despite bogus attributes"); |
| 52 | +ok(!defined($sth->fetch()), "fourth fetch returns undef, despite bogus attributes"); |
0 commit comments