Initial commit of DBIx::Class (experimental Class::DBI-inspired ORM)
[dbsrgits/DBIx-Class.git] / t / testlib / MyBase.pm
1 package MyBase;
2
3 use strict;
4 use base qw(DBIx::Class);
5
6 use vars qw/$dbh/;
7
8 my @connect = ("dbi:mysql:test", "", "");
9
10 $dbh = DBI->connect(@connect) or die DBI->errstr;
11 my @table;
12
13 END { $dbh->do("DROP TABLE $_") foreach @table }
14
15 __PACKAGE__->connection(@connect);
16
17 sub set_table {
18         my $class = shift;
19         $class->table($class->create_test_table);
20 }
21
22 sub create_test_table {
23         my $self   = shift;
24         my $table  = $self->next_available_table;
25         my $create = sprintf "CREATE TABLE $table ( %s )", $self->create_sql;
26         push @table, $table;
27         $dbh->do($create);
28         return $table;
29 }
30
31 sub next_available_table {
32         my $self   = shift;
33         my @tables = sort @{
34                 $dbh->selectcol_arrayref(
35                         qq{
36     SHOW TABLES
37   }
38                 )
39                 };
40         my $table = $tables[-1] || "aaa";
41         return "z$table";
42 }
43
44 1;