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