1 package DBIx::Class::Test::SQLite;
5 DBIx::Class::Test::SQLite - Base class for DBIx::Class tests, shamelessly ripped from Class::DBI::Test::SQLite
9 use base 'DBIx::Class::Test::SQLite';
11 __PACKAGE__->set_table('test');
12 __PACKAGE__->columns(All => qw/id name film salary/);
16 id INTEGER PRIMARY KEY,
25 This provides a simple base class for DBIx::Class tests using SQLite.
26 Each class for the test should inherit from this, provide a create_sql()
27 method which returns a string representing the SQL used to create the
28 table for the class, and then call set_table() to create the table, and
35 use base 'DBIx::Class';
36 use File::Temp qw/tempfile/;
37 my (undef, $DB) = tempfile();
38 END { unlink $DB if -e $DB }
40 my @DSN = ("dbi:SQLite:dbname=$DB", '', '', { AutoCommit => 1 });
42 __PACKAGE__->connection(@DSN);
43 #__PACKAGE__->set_sql(_table_pragma => 'PRAGMA table_info(__TABLE__)');
44 #__PACKAGE__->set_sql(_create_me => 'CREATE TABLE __TABLE__ (%s)');
50 __PACKAGE__->set_table('test');
52 This combines creating the table with the normal DBIx::Class table()
58 my ($class, $table) = @_;
59 $class->table($table);
60 $class->_create_test_table;
63 sub _create_test_table {
65 my @vals = $class->_sql_to_sth(
66 'PRAGMA table_info(__TABLE__)')->select_row;
68 'CREATE TABLE '.$class->table.' ('.$class->create_sql.')'
69 )->execute unless @vals;
72 =head2 create_sql (abstract)
76 id INTEGER PRIMARY KEY,
83 This should return, as a text string, the schema for the table represented
88 sub create_sql { die "create_sql() not implemented by $_[0]\n" }