Switch the main dev branch back to 'master'
[dbsrgits/DBIx-Class.git] / t / cdbi / testlib / MyBase.pm
CommitLineData
c6d74d3e 1package # hide from PAUSE
2 MyBase;
ea2e61bf 3
4a233f30 4use warnings;
ea2e61bf 5use strict;
4a233f30 6
d2cee1fa 7use DBI;
ea2e61bf 8
8d6b1478 9use lib 't/lib';
10use DBICTest;
11
12use base qw(DBIx::Class::CDBICompat);
13
9381840d 14my @connect = (@ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}, { PrintError => 0});
8d6b1478 15# this is only so we grab a lock on mysql
16{
17 my $x = DBICTest::Schema->connect(@connect);
18}
19
83eef562 20our $dbh = DBI->connect(@connect) or die DBI->errstr;
ea2e61bf 21my @table;
22
961d79db 23END {
24 $dbh->do("DROP TABLE $_") for @table;
25 undef $dbh;
26}
ea2e61bf 27
28__PACKAGE__->connection(@connect);
29
30sub set_table {
6a3bf251 31 my $class = shift;
32 $class->table($class->create_test_table);
ea2e61bf 33}
34
35sub create_test_table {
6a3bf251 36 my $self = shift;
37 my $table = $self->next_available_table;
38 my $create = sprintf "CREATE TABLE $table ( %s )", $self->create_sql;
39 push @table, $table;
40 $dbh->do($create);
41 return $table;
ea2e61bf 42}
43
44sub next_available_table {
6a3bf251 45 my $self = shift;
46 my @tables = sort @{
47 $dbh->selectcol_arrayref(
48 qq{
ea2e61bf 49 SHOW TABLES
50 }
6a3bf251 51 )
52 };
53 my $table = $tables[-1] || "aaa";
54 return "z$table";
ea2e61bf 55}
56
571;