Stop shipping world writeable files in our tarball
[dbsrgits/DBIx-Class.git] / t / cdbi / testlib / MyBase.pm
CommitLineData
c6d74d3e 1package # hide from PAUSE
2 MyBase;
ea2e61bf 3
4use strict;
d2cee1fa 5use DBI;
ea2e61bf 6
8d6b1478 7use lib 't/lib';
8use DBICTest;
9
10use base qw(DBIx::Class::CDBICompat);
11
f9cc85ce 12our $dbh;
ea2e61bf 13
49b3a264 14my $err;
15if (! $ENV{DBICTEST_MYSQL_DSN} ) {
16 $err = 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test';
17}
18elsif ( ! DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_mysql') ) {
19 $err = 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_mysql')
20}
21
22if ($err) {
23 my $t = eval { Test::Builder->new };
24 if ($t and ! $t->current_test) {
25 $t->skip_all ($err);
26 }
27 else {
28 die "$err\n";
29 }
30}
31
9381840d 32my @connect = (@ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/}, { PrintError => 0});
8d6b1478 33# this is only so we grab a lock on mysql
34{
35 my $x = DBICTest::Schema->connect(@connect);
36}
37
ea2e61bf 38$dbh = DBI->connect(@connect) or die DBI->errstr;
39my @table;
40
41END { $dbh->do("DROP TABLE $_") foreach @table }
42
43__PACKAGE__->connection(@connect);
44
45sub set_table {
6a3bf251 46 my $class = shift;
47 $class->table($class->create_test_table);
ea2e61bf 48}
49
50sub create_test_table {
6a3bf251 51 my $self = shift;
52 my $table = $self->next_available_table;
53 my $create = sprintf "CREATE TABLE $table ( %s )", $self->create_sql;
54 push @table, $table;
55 $dbh->do($create);
56 return $table;
ea2e61bf 57}
58
59sub next_available_table {
6a3bf251 60 my $self = shift;
61 my @tables = sort @{
62 $dbh->selectcol_arrayref(
63 qq{
ea2e61bf 64 SHOW TABLES
65 }
6a3bf251 66 )
67 };
68 my $table = $tables[-1] || "aaa";
69 return "z$table";
ea2e61bf 70}
71
721;