Allow for tests to run in parallel (simultaneously from multiple checkouts)
[dbsrgits/DBIx-Class.git] / t / cdbi / testlib / DBIC / Test / SQLite.pm
CommitLineData
2f1d53c5 1package # hide from PAUSE
93b52b2c 2 DBIC::Test::SQLite;
ea2e61bf 3
4=head1 NAME
5
b8e1e21f 6DBIx::Class::Test::SQLite - Base class for running Class::DBI tests against DBIx::Class compat layer, shamelessly ripped from Class::DBI::Test::SQLite
ea2e61bf 7
8=head1 SYNOPSIS
9
75d07914 10 use base 'DBIx::Class::Test::SQLite';
11
12 __PACKAGE__->set_table('test');
13 __PACKAGE__->columns(All => qw/id name film salary/);
14
15 sub create_sql {
16 return q{
17 id INTEGER PRIMARY KEY,
18 name CHAR(40),
19 film VARCHAR(255),
20 salary INT
21 }
22 }
8273e845 23
ea2e61bf 24=head1 DESCRIPTION
25
c7ce65e6 26This provides a simple base class for DBIx::Class::CDBICompat tests using
27SQLite. Each class for the test should inherit from this, provide a
28create_sql() method which returns a string representing the SQL used to
29create the table for the class, and then call set_table() to create the
30table, and tie it to the class.
ea2e61bf 31
32=cut
33
34use strict;
bf5ecff9 35use warnings;
ea2e61bf 36
d9bd5195 37use Test::More;
38
39use lib 't/lib';
40use DBICTest;
41
42BEGIN {
43 eval { require DBIx::Class::CDBICompat }
44 or plan skip_all => 'Class::DBI required for this test';
45}
46
126042ee 47use base qw/DBIx::Class/;
48
eb47985e 49__PACKAGE__->load_components(qw/CDBICompat Core DB/);
126042ee 50
8d6b1478 51my $DB = DBICTest->_sqlite_dbfilename;
126042ee 52my @DSN = ("dbi:SQLite:dbname=$DB", '', '', { AutoCommit => 1, RaiseError => 1 });
ea2e61bf 53
54__PACKAGE__->connection(@DSN);
a3018bd3 55__PACKAGE__->set_sql(_table_pragma => 'PRAGMA table_info(__TABLE__)');
56__PACKAGE__->set_sql(_create_me => 'CREATE TABLE __TABLE__ (%s)');
bfb2bd4f 57__PACKAGE__->storage->dbh->do("PRAGMA synchronous = OFF");
ea2e61bf 58
59=head1 METHODS
60
61=head2 set_table
62
75d07914 63 __PACKAGE__->set_table('test');
ea2e61bf 64
65This combines creating the table with the normal DBIx::Class table()
66call.
67
68=cut
69
70sub set_table {
75d07914 71 my ($class, $table) = @_;
72 $class->table($table);
73 $class->_create_test_table;
ea2e61bf 74}
75
76sub _create_test_table {
75d07914 77 my $class = shift;
78 my @vals = $class->sql__table_pragma->select_row;
79 $class->sql__create_me($class->create_sql)->execute unless @vals;
ea2e61bf 80}
81
87c4e602 82=head2 create_sql
83
84This is an abstract method you must override.
ea2e61bf 85
75d07914 86 sub create_sql {
87 return q{
88 id INTEGER PRIMARY KEY,
89 name CHAR(40),
90 film VARCHAR(255),
91 salary INT
92 }
93 }
ea2e61bf 94
95This should return, as a text string, the schema for the table represented
96by this class.
97
98=cut
99
100sub create_sql { die "create_sql() not implemented by $_[0]\n" }
101
1021;