From: Rafael Kitover Date: Sat, 13 Feb 2010 20:39:47 +0000 (-0500) Subject: fix picking up quoted tables for SQLite, patch from schwern X-Git-Tag: 0.05002~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8763ffdab92908d1a424dc68087ff051a2991b6e;p=dbsrgits%2FDBIx-Class-Schema-Loader.git fix picking up quoted tables for SQLite, patch from schwern --- diff --git a/Changes b/Changes index f1278a4..9b8934d 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ Revision history for Perl extension DBIx::Class::Schema::Loader + - fix picking up quoted tables for SQLite, patch from schwern - validate class/component loader_options to make sure classes are available before generating the schema diff --git a/lib/DBIx/Class/Schema/Loader.pm b/lib/DBIx/Class/Schema/Loader.pm index 8073fe8..37333a3 100644 --- a/lib/DBIx/Class/Schema/Loader.pm +++ b/lib/DBIx/Class/Schema/Loader.pm @@ -495,6 +495,8 @@ acmoore: Andrew Moore bphillips: Brian Phillips +schwern: Michael G. Schwern + ... and lots of other folks. If we forgot you, please write the current maintainer or RT. diff --git a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm index cbe9ae0..d141258 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm @@ -66,7 +66,7 @@ sub _sqlite_parse_table { $sth->finish; # Cut "CREATE TABLE ( )" blabla... - $sql =~ /^[\w\s']+\((.*)\)$/si; + $sql =~ /^[\w\s"]+\((.*)\)$/si; my $cols = $1; # strip single-line comments diff --git a/t/10sqlite_common.t b/t/10sqlite_common.t index 13bb045..6ccea1b 100644 --- a/t/10sqlite_common.t +++ b/t/10sqlite_common.t @@ -1,21 +1,42 @@ use strict; +use Test::More; use lib qw(t/lib); use dbixcsl_common_tests; eval { require DBD::SQLite }; my $class = $@ ? 'SQLite2' : 'SQLite'; -{ - my $tester = dbixcsl_common_tests->new( - vendor => 'SQLite', - auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT', - dsn => "dbi:$class:dbname=./t/sqlite_test", - user => '', - password => '', - ); +my $tester = dbixcsl_common_tests->new( + vendor => 'SQLite', + auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT', + dsn => "dbi:$class:dbname=./t/sqlite_test", + user => '', + password => '', + extra => { + create => [ + # 'sqlite_' is reserved, so we use 'extra_' + q{ + CREATE TABLE "extra_loader_test1" ( + "id" NOT NULL PRIMARY KEY, + "value" VARCHAR(100) + ) + } + ], + drop => [ 'extra_loader_test1' ], + count => 2, + run => sub { + my ($schema, $monikers, $classes) = @_; - $tester->run_tests(); -} + ok ((my $rs = $schema->resultset($monikers->{extra_loader_test1})), + 'resultset for quoted table'); + + is_deeply [ $rs->result_source->columns ], [ qw/id value/ ], + 'retrieved quoted column names from quoted table'; + }, + }, +); + +$tester->run_tests(); END { unlink './t/sqlite_test'; diff --git a/t/lib/dbixcsl_common_tests.pm b/t/lib/dbixcsl_common_tests.pm index 31bd90e..57f64f7 100644 --- a/t/lib/dbixcsl_common_tests.pm +++ b/t/lib/dbixcsl_common_tests.pm @@ -92,7 +92,7 @@ sub setup_schema { my %loader_opts = ( constraint => - qr/^(?:\S+\.)?(?:$self->{vendor}_)?loader_test[0-9]+(?!.*_)/i, + qr/^(?:\S+\.)?(?:(?:$self->{vendor}|extra)_)?loader_test[0-9]+(?!.*_)/i, relationships => 1, additional_classes => 'TestAdditional', additional_base_classes => 'TestAdditionalBase',