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