| 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 |
my $dir = DbDir (); |
| 16 |
|
| 17 |
ok (my $dbh = DBI->connect ("dbi:CSV:", "", "", { |
| 18 |
f_dir => $dir, |
| 19 |
}), "connect"); |
| 20 |
|
| 21 |
ok (my $tbl = FindNewTable ($dbh), "find new test table"); |
| 22 |
like (my $def = TableDefinition ($tbl, @tbl_def), |
| 23 |
qr{^create table $tbl}i, "table definition"); |
| 24 |
ok ($dbh->do ($def), "create table"); |
| 25 |
|
| 26 |
my @tbl = $dbh->tables (); |
| 27 |
if (my $usr = eval { getpwuid $< }) { |
| 28 |
s/^(['"`])(.+)\1\./$2./ for @tbl; |
| 29 |
is_deeply (\@tbl, [ qq{$usr.$tbl} ], "tables"); |
| 30 |
} |
| 31 |
else { |
| 32 |
is_deeply (\@tbl, [ qq{$tbl} ], "tables"); |
| 33 |
} |
| 34 |
|
| 35 |
ok ($dbh->disconnect, "disconnect"); |
| 36 |
undef $dbh; |
| 37 |
|
| 38 |
ok ($dbh = DBI->connect ("dbi:CSV:", "", "", { |
| 39 |
f_schema => undef, |
| 40 |
f_dir => $dir, |
| 41 |
}), "connect (f_schema => undef)"); |
| 42 |
is_deeply ([ $dbh->tables () ], [ $tbl ], "tables"); |
| 43 |
|
| 44 |
ok ($dbh->do ("drop table $tbl"), "drop table"); |
| 45 |
|
| 46 |
ok ($dbh->disconnect, "disconnect"); |
| 47 |
undef $dbh; |
| 48 |
|
| 49 |
ok (rmdir $dir, "no files left"); |
| 50 |
|
| 51 |
done_testing (); |