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 | |
f9cc85ce |
9 | our $dbh; |
ea2e61bf |
10 | |
49b3a264 |
11 | my $err; |
12 | if (! $ENV{DBICTEST_MYSQL_DSN} ) { |
13 | $err = 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test'; |
14 | } |
15 | elsif ( ! DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_mysql') ) { |
16 | $err = 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_mysql') |
17 | } |
18 | |
19 | if ($err) { |
20 | my $t = eval { Test::Builder->new }; |
21 | if ($t and ! $t->current_test) { |
22 | $t->skip_all ($err); |
23 | } |
24 | else { |
25 | die "$err\n"; |
26 | } |
27 | } |
28 | |
9381840d |
29 | my @connect = (@ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}, { PrintError => 0}); |
ea2e61bf |
30 | $dbh = DBI->connect(@connect) or die DBI->errstr; |
31 | my @table; |
32 | |
33 | END { $dbh->do("DROP TABLE $_") foreach @table } |
34 | |
35 | __PACKAGE__->connection(@connect); |
36 | |
37 | sub set_table { |
6a3bf251 |
38 | my $class = shift; |
39 | $class->table($class->create_test_table); |
ea2e61bf |
40 | } |
41 | |
42 | sub create_test_table { |
6a3bf251 |
43 | my $self = shift; |
44 | my $table = $self->next_available_table; |
45 | my $create = sprintf "CREATE TABLE $table ( %s )", $self->create_sql; |
46 | push @table, $table; |
47 | $dbh->do($create); |
48 | return $table; |
ea2e61bf |
49 | } |
50 | |
51 | sub next_available_table { |
6a3bf251 |
52 | my $self = shift; |
53 | my @tables = sort @{ |
54 | $dbh->selectcol_arrayref( |
55 | qq{ |
ea2e61bf |
56 | SHOW TABLES |
57 | } |
6a3bf251 |
58 | ) |
59 | }; |
60 | my $table = $tables[-1] || "aaa"; |
61 | return "z$table"; |
ea2e61bf |
62 | } |
63 | |
64 | 1; |