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