@@ -9,30 +9,44 @@ use Test::More tests => 17;
9
9
use Storable qw( dclone) ;
10
10
use DBI qw( :sql_types) ;
11
11
12
- our @ROWS = ([' foo' , undef , ' bazooka' ],
13
- [' foolery' , ' bar' , undef ],
14
- [undef , ' barrowman' , ' baz' ]);
12
+ # our reference table:
13
+ #
14
+ # A1 B1 C2
15
+ # ------- --------- -------
16
+ # foo NULL bazooka
17
+ # foolery bar NULL
18
+ # NULL barrowman baz
19
+ #
20
+
21
+ our @NAMES = ( ' A0' , ' B1' , ' C2' );
22
+ our @ROWS = ([' foo' , undef , ' bazooka' ],
23
+ [' foolery' , ' bar' , undef ],
24
+ [undef , ' barrowman' , ' baz' ]);
15
25
16
26
my $dbh = DBI-> connect (" dbi:Sponge:" , ' ' , ' ' );
17
27
ok($dbh , " connect(dbi:Sponge:) succeeds" );
18
28
19
29
my $sth = $dbh -> prepare(" simple, correct sponge" , {
20
30
rows => dclone( \@ROWS ),
21
- NAME => [ qw( A0 B1 C2 ) ],
31
+ NAME => [ @NAMES ],
22
32
});
23
33
24
34
ok($sth , " prepare() of 3x3 result succeeded" );
25
35
is_deeply($sth -> {NAME }, [' A0' , ' B1' , ' C2' ], " column NAMEs as expected" );
26
36
is_deeply($sth -> {TYPE }, [SQL_VARCHAR, SQL_VARCHAR, SQL_VARCHAR],
27
37
" column TYPEs default to SQL_VARCHAR" );
38
+ #
39
+ # Old versions of DBD-Sponge defaulted PRECISION (data "length") to
40
+ # length of the field _names_ rather than the length of the _data_.
41
+ #
28
42
is_deeply($sth -> {PRECISION }, [7, 9, 7],
29
43
" column PRECISION matches lengths of longest field data" );
30
44
is_deeply($sth -> fetch(), $ROWS [0], " first row fetch as expected" );
31
45
is_deeply($sth -> fetch(), $ROWS [1], " second row fetch as expected" );
32
46
is_deeply($sth -> fetch(), $ROWS [2], " third row fetch as expected" );
33
47
ok(!defined ($sth -> fetch()), " fourth fetch returns undef" );
34
48
35
-
49
+ # Test that DBD-Sponge preserves bogus user-supplied attributes
36
50
$sth = $dbh -> prepare(' user-supplied silly TYPE and PRECISION' , {
37
51
rows => dclone( \@ROWS ),
38
52
NAME => [qw( first_col second_col third_col ) ],
0 commit comments