Skip to content

Commit 5b437c2

Browse files
committed
Simple Sponge and PRECISION tests
1 parent dea97d1 commit 5b437c2

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

t/xx_sponge.t

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
 (0)