@@ -9,30 +9,44 @@ use Test::More tests => 17;
99use Storable qw( dclone) ;
1010use DBI qw( :sql_types) ;
1111
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' ]);
1525
1626my $dbh = DBI-> connect (" dbi:Sponge:" , ' ' , ' ' );
1727ok($dbh , " connect(dbi:Sponge:) succeeds" );
1828
1929my $sth = $dbh -> prepare(" simple, correct sponge" , {
2030 rows => dclone( \@ROWS ),
21- NAME => [ qw( A0 B1 C2 ) ],
31+ NAME => [ @NAMES ],
2232 });
2333
2434ok($sth , " prepare() of 3x3 result succeeded" );
2535is_deeply($sth -> {NAME }, [' A0' , ' B1' , ' C2' ], " column NAMEs as expected" );
2636is_deeply($sth -> {TYPE }, [SQL_VARCHAR, SQL_VARCHAR, SQL_VARCHAR],
2737 " 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+ #
2842is_deeply($sth -> {PRECISION }, [7, 9, 7],
2943 " column PRECISION matches lengths of longest field data" );
3044is_deeply($sth -> fetch(), $ROWS [0], " first row fetch as expected" );
3145is_deeply($sth -> fetch(), $ROWS [1], " second row fetch as expected" );
3246is_deeply($sth -> fetch(), $ROWS [2], " third row fetch as expected" );
3347ok(!defined ($sth -> fetch()), " fourth fetch returns undef" );
3448
35-
49+ # Test that DBD-Sponge preserves bogus user-supplied attributes
3650$sth = $dbh -> prepare(' user-supplied silly TYPE and PRECISION' , {
3751 rows => dclone( \@ROWS ),
3852 NAME => [qw( first_col second_col third_col ) ],
0 commit comments