From: Andrew Rodland Date: Fri, 19 Feb 2010 09:18:13 +0000 (-0600) Subject: Improve SQLite parsing when column defs span lines X-Git-Tag: 0.05003~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=68d650df6256cb303df2839e760e6bee594671d1;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Improve SQLite parsing when column defs span lines --- diff --git a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm index fd8c203..0a2e09c 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm @@ -119,7 +119,7 @@ sub _sqlite_parse_table { $auto_inc{lc $1} = 1; } - next if $col !~ /^(.*\S)\s+REFERENCES\s+(\w+) (?: \s* \( (.*) \) )? /ix; + next if $col !~ /^(.*\S)\s+REFERENCES\s+(\w+) (?: \s* \( (.*) \) )? /six; my ($cols, $f_table, $f_cols) = ($1, $2, $3); @@ -128,7 +128,7 @@ sub _sqlite_parse_table { $cols =~ s/\s*\)$//; } else { # Inline - $cols =~ s/\s+.*$//; + $cols =~ s/\s+.*$//s; } my @cols = map { s/\s*//g; lc $_ } split(/\s*,\s*/,$cols); diff --git a/t/10sqlite_common.t b/t/10sqlite_common.t index 6ccea1b..e521a1e 100644 --- a/t/10sqlite_common.t +++ b/t/10sqlite_common.t @@ -20,10 +20,32 @@ my $tester = dbixcsl_common_tests->new( "id" NOT NULL PRIMARY KEY, "value" VARCHAR(100) ) - } + }, + q{ + CREATE TABLE extra_loader_test2 ( + event_id INTEGER PRIMARY KEY + ) + }, + q{ + CREATE TABLE extra_loader_test3 ( + person_id INTEGER PRIMARY KEY + ) + }, + # Wordy, newline-heavy SQL to stress the regexes + q{ + CREATE TABLE extra_loader_test4 ( + event_id INTEGER NOT NULL + CONSTRAINT fk_event_id + REFERENCES extra_loader_test2(event_id), + person_id INTEGER NOT NULL + CONSTRAINT fk_person_id + REFERENCES extra_loader_test3 (person_id), + PRIMARY KEY (event_id, person_id) + ) + }, ], - drop => [ 'extra_loader_test1' ], - count => 2, + drop => [ qw/extra_loader_test1 extra_loader_test2 extra_loader_test3 extra_loader_test4 / ], + count => 5, run => sub { my ($schema, $monikers, $classes) = @_; @@ -32,6 +54,17 @@ my $tester = dbixcsl_common_tests->new( is_deeply [ $rs->result_source->columns ], [ qw/id value/ ], 'retrieved quoted column names from quoted table'; + + ok ((my $source = $schema->source($monikers->{extra_loader_test4})), + 'verbose table'); + + is_deeply [ $source->primary_columns ], [ qw/event_id person_id/ ], + 'composite primary key'; + + warn "@{[ $source->relationships ]}\n"; + is ($source->relationships, 2, + '2 foreign key constraints found'); + }, }, );