Merge 'trunk' into 'sqla_1.50_compat'
[dbsrgits/DBIx-Class-Historic.git] / t / testlib / MyBase.pm
CommitLineData
c6d74d3e 1package # hide from PAUSE
2 MyBase;
ea2e61bf 3
4use strict;
d2cee1fa 5use base qw(DBIx::Class::CDBICompat);
6
7use DBI;
ea2e61bf 8
9use vars qw/$dbh/;
10
dec1bfe0 11# temporary, might get switched to the new test framework someday
12my @connect = ("dbi:mysql:test", "", "", { PrintError => 0});
ea2e61bf 13
14$dbh = DBI->connect(@connect) or die DBI->errstr;
15my @table;
16
17END { $dbh->do("DROP TABLE $_") foreach @table }
18
19__PACKAGE__->connection(@connect);
20
21sub set_table {
22 my $class = shift;
23 $class->table($class->create_test_table);
24}
25
26sub create_test_table {
27 my $self = shift;
28 my $table = $self->next_available_table;
29 my $create = sprintf "CREATE TABLE $table ( %s )", $self->create_sql;
30 push @table, $table;
31 $dbh->do($create);
32 return $table;
33}
34
35sub next_available_table {
36 my $self = shift;
37 my @tables = sort @{
38 $dbh->selectcol_arrayref(
39 qq{
40 SHOW TABLES
41 }
42 )
43 };
44 my $table = $tables[-1] || "aaa";
45 return "z$table";
46}
47
481;