Commit | Line | Data |
---|---|---|
c6d74d3e | 1 | package # hide from PAUSE |
2 | MyBase; | |
ea2e61bf | 3 | |
4a233f30 | 4 | use warnings; |
ea2e61bf | 5 | use strict; |
4a233f30 | 6 | |
d2cee1fa | 7 | use DBI; |
ea2e61bf | 8 | |
8d6b1478 | 9 | use lib 't/lib'; |
10 | use DBICTest; | |
11 | ||
12 | use base qw(DBIx::Class::CDBICompat); | |
13 | ||
9381840d | 14 | my @connect = (@ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}, { PrintError => 0}); |
8d6b1478 | 15 | # this is only so we grab a lock on mysql |
16 | { | |
17 | my $x = DBICTest::Schema->connect(@connect); | |
18 | } | |
19 | ||
83eef562 | 20 | our $dbh = DBI->connect(@connect) or die DBI->errstr; |
ea2e61bf | 21 | my @table; |
22 | ||
961d79db | 23 | END { |
24 | $dbh->do("DROP TABLE $_") for @table; | |
25 | undef $dbh; | |
26 | } | |
ea2e61bf | 27 | |
28 | __PACKAGE__->connection(@connect); | |
29 | ||
30 | sub set_table { | |
6a3bf251 | 31 | my $class = shift; |
32 | $class->table($class->create_test_table); | |
ea2e61bf | 33 | } |
34 | ||
35 | sub create_test_table { | |
6a3bf251 | 36 | my $self = shift; |
37 | my $table = $self->next_available_table; | |
38 | my $create = sprintf "CREATE TABLE $table ( %s )", $self->create_sql; | |
39 | push @table, $table; | |
40 | $dbh->do($create); | |
41 | return $table; | |
ea2e61bf | 42 | } |
43 | ||
44 | sub next_available_table { | |
6a3bf251 | 45 | my $self = shift; |
46 | my @tables = sort @{ | |
47 | $dbh->selectcol_arrayref( | |
48 | qq{ | |
ea2e61bf | 49 | SHOW TABLES |
50 | } | |
6a3bf251 | 51 | ) |
52 | }; | |
53 | my $table = $tables[-1] || "aaa"; | |
54 | return "z$table"; | |
ea2e61bf | 55 | } |
56 | ||
57 | 1; |