1 package DBIx::Class::Test::SQLite;
5 DBIx::Class::Test::SQLite - Base class for running Class::DBI tests against DBIx::Class compat layer, 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::CDBICompat tests using
26 SQLite. Each class for the test should inherit from this, provide a
27 create_sql() method which returns a string representing the SQL used to
28 create the table for the class, and then call set_table() to create the
29 table, and tie it to the class.
35 use base qw/DBIx::Class/;
37 __PACKAGE__->load_components(qw/PK::Auto::SQLite CDBICompat Core DB/);
39 use File::Temp qw/tempfile/;
40 my (undef, $DB) = tempfile();
41 END { unlink $DB if -e $DB }
43 my @DSN = ("dbi:SQLite:dbname=$DB", '', '', { AutoCommit => 1, RaiseError => 1 });
45 __PACKAGE__->connection(@DSN);
46 __PACKAGE__->set_sql(_table_pragma => 'PRAGMA table_info(__TABLE__)');
47 __PACKAGE__->set_sql(_create_me => 'CREATE TABLE __TABLE__ (%s)');
53 __PACKAGE__->set_table('test');
55 This combines creating the table with the normal DBIx::Class table()
61 my ($class, $table) = @_;
62 $class->table($table);
63 $class->_create_test_table;
66 sub _create_test_table {
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;
77 =head2 create_sql (abstract)
81 id INTEGER PRIMARY KEY,
88 This should return, as a text string, the schema for the table represented
93 sub create_sql { die "create_sql() not implemented by $_[0]\n" }