Disabled 'Use of uninitialized value in subroutine entry' warning
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Test / SQLite.pm
CommitLineData
ea2e61bf 1package DBIx::Class::Test::SQLite;
2
3=head1 NAME
4
b8e1e21f 5DBIx::Class::Test::SQLite - Base class for running Class::DBI tests against DBIx::Class compat layer, shamelessly ripped from Class::DBI::Test::SQLite
ea2e61bf 6
7=head1 SYNOPSIS
8
9 use base 'DBIx::Class::Test::SQLite';
10
11 __PACKAGE__->set_table('test');
12 __PACKAGE__->columns(All => qw/id name film salary/);
13
14 sub create_sql {
15 return q{
16 id INTEGER PRIMARY KEY,
17 name CHAR(40),
18 film VARCHAR(255),
19 salary INT
20 }
21 }
22
23=head1 DESCRIPTION
24
25This provides a simple base class for DBIx::Class tests using SQLite.
26Each class for the test should inherit from this, provide a create_sql()
27method which returns a string representing the SQL used to create the
28table for the class, and then call set_table() to create the table, and
29tie it to the class.
30
31=cut
32
33use strict;
34
126042ee 35use base qw/DBIx::Class/;
36
37__PACKAGE__->load_components(qw/CDBICompat PK::Auto::SQLite Core/);
38
ea2e61bf 39use File::Temp qw/tempfile/;
40my (undef, $DB) = tempfile();
41END { unlink $DB if -e $DB }
42
126042ee 43my @DSN = ("dbi:SQLite:dbname=$DB", '', '', { AutoCommit => 1, RaiseError => 1 });
ea2e61bf 44
45__PACKAGE__->connection(@DSN);
a3018bd3 46__PACKAGE__->set_sql(_table_pragma => 'PRAGMA table_info(__TABLE__)');
47__PACKAGE__->set_sql(_create_me => 'CREATE TABLE __TABLE__ (%s)');
ea2e61bf 48
49=head1 METHODS
50
51=head2 set_table
52
53 __PACKAGE__->set_table('test');
54
55This combines creating the table with the normal DBIx::Class table()
56call.
57
58=cut
59
60sub set_table {
61 my ($class, $table) = @_;
62 $class->table($table);
63 $class->_create_test_table;
64}
65
66sub _create_test_table {
67 my $class = shift;
a3018bd3 68 my @vals = $class->sql__table_pragma->select_row;
69 $class->sql__create_me($class->create_sql)->execute unless @vals;
70# my @vals = $class->_sql_to_sth(
71# 'PRAGMA table_info(__TABLE__)')->select_row;
72# $class->_sql_to_sth(
73# 'CREATE TABLE '.$class->table.' ('.$class->create_sql.')'
74# )->execute unless @vals;
ea2e61bf 75}
76
77=head2 create_sql (abstract)
78
79 sub create_sql {
80 return q{
81 id INTEGER PRIMARY KEY,
82 name CHAR(40),
83 film VARCHAR(255),
84 salary INT
85 }
86 }
87
88This should return, as a text string, the schema for the table represented
89by this class.
90
91=cut
92
93sub create_sql { die "create_sql() not implemented by $_[0]\n" }
94
951;