Commit | Line | Data |
2f1d53c5 |
1 | package # hide from PAUSE |
93b52b2c |
2 | DBIC::Test::SQLite; |
ea2e61bf |
3 | |
4 | =head1 NAME |
5 | |
b8e1e21f |
6 | DBIx::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 |
26 | This provides a simple base class for DBIx::Class::CDBICompat tests using |
27 | SQLite. Each class for the test should inherit from this, provide a |
28 | create_sql() method which returns a string representing the SQL used to |
29 | create the table for the class, and then call set_table() to create the |
30 | table, and tie it to the class. |
ea2e61bf |
31 | |
32 | =cut |
33 | |
34 | use strict; |
bf5ecff9 |
35 | use warnings; |
ea2e61bf |
36 | |
d9bd5195 |
37 | use Test::More; |
38 | |
1b658919 |
39 | # adding implicit search criteria to the iterator will alter the test |
40 | # mechanics - leave everything as-is instead, and hope SQLite won't |
41 | # change too much |
42 | BEGIN { $ENV{DBIC_SHUFFLE_UNORDERED_RESULTSETS} = 0 } |
43 | |
c8dc7d33 |
44 | use lib 't/lib'; |
45 | use DBICTest; |
46 | |
3225bc71 |
47 | BEGIN { |
48 | eval { require DBIx::Class::CDBICompat } |
49 | or plan skip_all => 'Class::DBI required for this test'; |
50 | } |
51 | |
126042ee |
52 | use base qw/DBIx::Class/; |
53 | |
eb47985e |
54 | __PACKAGE__->load_components(qw/CDBICompat Core DB/); |
126042ee |
55 | |
8d6b1478 |
56 | my $DB = DBICTest->_sqlite_dbfilename; |
126042ee |
57 | my @DSN = ("dbi:SQLite:dbname=$DB", '', '', { AutoCommit => 1, RaiseError => 1 }); |
ea2e61bf |
58 | |
59 | __PACKAGE__->connection(@DSN); |
a3018bd3 |
60 | __PACKAGE__->set_sql(_table_pragma => 'PRAGMA table_info(__TABLE__)'); |
61 | __PACKAGE__->set_sql(_create_me => 'CREATE TABLE __TABLE__ (%s)'); |
bfb2bd4f |
62 | __PACKAGE__->storage->dbh->do("PRAGMA synchronous = OFF"); |
ea2e61bf |
63 | |
64 | =head1 METHODS |
65 | |
66 | =head2 set_table |
67 | |
75d07914 |
68 | __PACKAGE__->set_table('test'); |
ea2e61bf |
69 | |
70 | This combines creating the table with the normal DBIx::Class table() |
71 | call. |
72 | |
73 | =cut |
74 | |
75 | sub set_table { |
75d07914 |
76 | my ($class, $table) = @_; |
77 | $class->table($table); |
78 | $class->_create_test_table; |
ea2e61bf |
79 | } |
80 | |
81 | sub _create_test_table { |
75d07914 |
82 | my $class = shift; |
83 | my @vals = $class->sql__table_pragma->select_row; |
84 | $class->sql__create_me($class->create_sql)->execute unless @vals; |
ea2e61bf |
85 | } |
86 | |
87c4e602 |
87 | =head2 create_sql |
88 | |
89 | This is an abstract method you must override. |
ea2e61bf |
90 | |
75d07914 |
91 | sub create_sql { |
92 | return q{ |
93 | id INTEGER PRIMARY KEY, |
94 | name CHAR(40), |
95 | film VARCHAR(255), |
96 | salary INT |
97 | } |
98 | } |
ea2e61bf |
99 | |
100 | This should return, as a text string, the schema for the table represented |
101 | by this class. |
102 | |
103 | =cut |
104 | |
105 | sub create_sql { die "create_sql() not implemented by $_[0]\n" } |
106 | |
107 | 1; |