Commit | Line | Data |
c6d74d3e |
1 | package # hide from PAUSE |
2 | MyBase; |
ea2e61bf |
3 | |
4 | use strict; |
d2cee1fa |
5 | use base qw(DBIx::Class::CDBICompat); |
6 | |
7 | use DBI; |
ea2e61bf |
8 | |
9 | use vars qw/$dbh/; |
10 | |
dec1bfe0 |
11 | # temporary, might get switched to the new test framework someday |
12 | my @connect = ("dbi:mysql:test", "", "", { PrintError => 0}); |
ea2e61bf |
13 | |
14 | $dbh = DBI->connect(@connect) or die DBI->errstr; |
15 | my @table; |
16 | |
17 | END { $dbh->do("DROP TABLE $_") foreach @table } |
18 | |
19 | __PACKAGE__->connection(@connect); |
20 | |
21 | sub set_table { |
22 | my $class = shift; |
23 | $class->table($class->create_test_table); |
24 | } |
25 | |
26 | sub create_test_table { |
27 | my $self = shift; |
28 | my $table = $self->next_available_table; |
29 | my $create = sprintf "CREATE TABLE $table ( %s )", $self->create_sql; |
30 | push @table, $table; |
31 | $dbh->do($create); |
32 | return $table; |
33 | } |
34 | |
35 | sub next_available_table { |
36 | my $self = shift; |
37 | my @tables = sort @{ |
38 | $dbh->selectcol_arrayref( |
39 | qq{ |
40 | SHOW TABLES |
41 | } |
42 | ) |
43 | }; |
44 | my $table = $tables[-1] || "aaa"; |
45 | return "z$table"; |
46 | } |
47 | |
48 | 1; |