X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FTest%2FSQLite.pm;h=3302289dc4444e6979919916af592f6294c69dec;hb=35a2ad468ae7e957cd24cdf6579c92a889baf6cc;hp=b6b22fa940b0534ed2cb90b4074cd488495c2948;hpb=126042ee4b9394c4eecc6ece49469da6fce23ba3;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Test/SQLite.pm b/lib/DBIx/Class/Test/SQLite.pm index b6b22fa..3302289 100644 --- a/lib/DBIx/Class/Test/SQLite.pm +++ b/lib/DBIx/Class/Test/SQLite.pm @@ -6,35 +6,36 @@ DBIx::Class::Test::SQLite - Base class for running Class::DBI tests against DBIx =head1 SYNOPSIS - use base 'DBIx::Class::Test::SQLite'; - - __PACKAGE__->set_table('test'); - __PACKAGE__->columns(All => qw/id name film salary/); - - sub create_sql { - return q{ - id INTEGER PRIMARY KEY, - name CHAR(40), - film VARCHAR(255), - salary INT - } - } - + use base 'DBIx::Class::Test::SQLite'; + + __PACKAGE__->set_table('test'); + __PACKAGE__->columns(All => qw/id name film salary/); + + sub create_sql { + return q{ + id INTEGER PRIMARY KEY, + name CHAR(40), + film VARCHAR(255), + salary INT + } + } + =head1 DESCRIPTION -This provides a simple base class for DBIx::Class tests using SQLite. -Each class for the test should inherit from this, provide a create_sql() -method which returns a string representing the SQL used to create the -table for the class, and then call set_table() to create the table, and -tie it to the class. +This provides a simple base class for DBIx::Class::CDBICompat tests using +SQLite. Each class for the test should inherit from this, provide a +create_sql() method which returns a string representing the SQL used to +create the table for the class, and then call set_table() to create the +table, and tie it to the class. =cut use strict; +use warnings; use base qw/DBIx::Class/; -__PACKAGE__->load_components(qw/CDBICompat PK::Auto::SQLite Core/); +__PACKAGE__->load_components(qw/CDBICompat Core DB/); use File::Temp qw/tempfile/; my (undef, $DB) = tempfile(); @@ -45,12 +46,13 @@ my @DSN = ("dbi:SQLite:dbname=$DB", '', '', { AutoCommit => 1, RaiseError => 1 } __PACKAGE__->connection(@DSN); __PACKAGE__->set_sql(_table_pragma => 'PRAGMA table_info(__TABLE__)'); __PACKAGE__->set_sql(_create_me => 'CREATE TABLE __TABLE__ (%s)'); +__PACKAGE__->storage->dbh->do("PRAGMA synchronous = OFF"); =head1 METHODS =head2 set_table - __PACKAGE__->set_table('test'); + __PACKAGE__->set_table('test'); This combines creating the table with the normal DBIx::Class table() call. @@ -58,32 +60,29 @@ call. =cut sub set_table { - my ($class, $table) = @_; - $class->table($table); - $class->_create_test_table; + my ($class, $table) = @_; + $class->table($table); + $class->_create_test_table; } sub _create_test_table { - my $class = shift; - my @vals = $class->sql__table_pragma->select_row; - $class->sql__create_me($class->create_sql)->execute unless @vals; -# my @vals = $class->_sql_to_sth( -# 'PRAGMA table_info(__TABLE__)')->select_row; -# $class->_sql_to_sth( -# 'CREATE TABLE '.$class->table.' ('.$class->create_sql.')' -# )->execute unless @vals; + my $class = shift; + my @vals = $class->sql__table_pragma->select_row; + $class->sql__create_me($class->create_sql)->execute unless @vals; } -=head2 create_sql (abstract) +=head2 create_sql - sub create_sql { - return q{ - id INTEGER PRIMARY KEY, - name CHAR(40), - film VARCHAR(255), - salary INT - } - } +This is an abstract method you must override. + + sub create_sql { + return q{ + id INTEGER PRIMARY KEY, + name CHAR(40), + film VARCHAR(255), + salary INT + } + } This should return, as a text string, the schema for the table represented by this class.