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