1package MyBase;
2
3use strict;
4use base qw(Class::DBI);
5
6use vars qw/$dbh/;
7
8my @connect = ("dbi:mysql:test", "", "");
9
10$dbh = DBI->connect(@connect) or die DBI->errstr;
11my @table;
12
13END { $dbh->do("DROP TABLE $_") foreach @table }
14
15__PACKAGE__->connection(@connect);
16
17sub set_table {
18	my $class = shift;
19	$class->table($class->create_test_table);
20}
21
22sub 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
31sub 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
441;
45