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 | |
9381840d |
11 | my @connect = (@ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}, { PrintError => 0}); |
ea2e61bf |
12 | $dbh = DBI->connect(@connect) or die DBI->errstr; |
13 | my @table; |
14 | |
15 | END { $dbh->do("DROP TABLE $_") foreach @table } |
16 | |
17 | __PACKAGE__->connection(@connect); |
18 | |
19 | sub set_table { |
6a3bf251 |
20 | my $class = shift; |
21 | $class->table($class->create_test_table); |
ea2e61bf |
22 | } |
23 | |
24 | sub create_test_table { |
6a3bf251 |
25 | my $self = shift; |
26 | my $table = $self->next_available_table; |
27 | my $create = sprintf "CREATE TABLE $table ( %s )", $self->create_sql; |
28 | push @table, $table; |
29 | $dbh->do($create); |
30 | return $table; |
ea2e61bf |
31 | } |
32 | |
33 | sub next_available_table { |
6a3bf251 |
34 | my $self = shift; |
35 | my @tables = sort @{ |
36 | $dbh->selectcol_arrayref( |
37 | qq{ |
ea2e61bf |
38 | SHOW TABLES |
39 | } |
6a3bf251 |
40 | ) |
41 | }; |
42 | my $table = $tables[-1] || "aaa"; |
43 | return "z$table"; |
ea2e61bf |
44 | } |
45 | |
46 | 1; |