Fix last pieces of retardation and UNtodo the quick cycle
[dbsrgits/DBIx-Class.git] / t / cdbi / testlib / MyBase.pm
1 package # hide from PAUSE
2     MyBase;
3
4 use strict;
5 use base qw(DBIx::Class::CDBICompat);
6
7 use DBI;
8
9 use vars qw/$dbh/;
10
11 my @connect = (@ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}, { PrintError => 0});
12 $dbh = DBI->connect(@connect) or die DBI->errstr;
13 my @table;
14
15 END { $dbh->do("DROP TABLE $_") foreach @table }
16
17 __PACKAGE__->connection(@connect);
18
19 sub set_table {
20         my $class = shift;
21         $class->table($class->create_test_table);
22 }
23
24 sub create_test_table {
25         my $self   = shift;
26         my $table  = $self->next_available_table;
27         my $create = sprintf "CREATE TABLE $table ( %s )", $self->create_sql;
28         push @table, $table;
29         $dbh->do($create);
30         return $table;
31 }
32
33 sub next_available_table {
34         my $self   = shift;
35         my @tables = sort @{
36                 $dbh->selectcol_arrayref(
37                         qq{
38     SHOW TABLES
39   }
40                 )
41                 };
42         my $table = $tables[-1] || "aaa";
43         return "z$table";
44 }
45
46 1;