| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Test::More; |
| 6 |
|
| 7 |
BEGIN { use_ok ("DBI") } |
| 8 |
do "./t/lib.pl"; |
| 9 |
|
| 10 |
my @tbl_def = ( |
| 11 |
[ "id", "INTEGER", 4, 0 ], |
| 12 |
[ "name", "CHAR", 64, 0 ], |
| 13 |
); |
| 14 |
|
| 15 |
ok (my $dbh = Connect (), "connect"); |
| 16 |
|
| 17 |
ok (my $tbl = FindNewTable ($dbh), "find new test table"); |
| 18 |
|
| 19 |
like (my $def = TableDefinition ($tbl, @tbl_def), |
| 20 |
qr{^create table $tbl}i, "table definition"); |
| 21 |
ok ($dbh->do ($def), "create table"); |
| 22 |
my $tbl_file = DbFile ($tbl); |
| 23 |
ok (-s $tbl_file, "file exists"); |
| 24 |
ok ($dbh->disconnect, "disconnect"); |
| 25 |
|
| 26 |
ok (-f $tbl_file, "file still there"); |
| 27 |
open my $fh, ">>", $tbl_file; |
| 28 |
print $fh qq{1, "p0wnd",",""",0\n}; # Very bad content |
| 29 |
close $fh; |
| 30 |
|
| 31 |
ok ($dbh = Connect (), "connect"); |
| 32 |
{ local $dbh->{PrintError} = 0; |
| 33 |
local $dbh->{RaiseError} = 0; |
| 34 |
ok (my $sth = $dbh->prepare ("select * from $tbl"), "prepare"); |
| 35 |
is ($sth->execute, undef, "execute should fail"); |
| 36 |
# It is safe to regex on this text, as it is NOT local dependent |
| 37 |
like ($dbh->errstr, qr{\w+ \@ line [0-9?]+ pos [0-9?]+}, "error message"); |
| 38 |
}; |
| 39 |
ok ($dbh->do ("drop table $tbl"), "drop"); |
| 40 |
ok ($dbh->disconnect, "disconnect"); |
| 41 |
|
| 42 |
done_testing (); |