From 9f54d4eba1f92d054071dc5ae58c6e5218df05d0 Mon Sep 17 00:00:00 2001 From: Ed J Date: Sun, 26 Aug 2018 22:17:30 +0100 Subject: [PATCH] refactor for DRY --- lib/DBD/SQLite.pm | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/lib/DBD/SQLite.pm b/lib/DBD/SQLite.pm index f40fce4..006dd26 100644 --- a/lib/DBD/SQLite.pm +++ b/lib/DBD/SQLite.pm @@ -640,7 +640,7 @@ sub foreign_key_info { # cribbed from DBIx::Class::Schema::Loader::DBI::SQLite REL: for my $relid (keys %relid2rels) { my $rel = $rels[$relid]; - my $deferrable; + my $deferrable = $DBI_code_for_rule{'NOT DEFERRABLE'}; my $local_cols = '"?' . (join '"? \s* , \s* "?', map quotemeta, @{ $rel->{local_columns} }) . '"?'; my $remote_cols = '"?' . (join '"? \s* , \s* "?', map quotemeta, @{ $rel->{remote_columns} || [] }) . '"?'; my ($deferrable_clause) = $ddl =~ / @@ -648,33 +648,24 @@ sub foreign_key_info { (?:\( \s* $remote_cols \s* \) \s*)? $DEFERRABLE_RE /sxi; - if ($deferrable_clause) { - $deferrable = $deferrable_clause =~ /not/i - ? $DBI_code_for_rule{'NOT DEFERRABLE'} - : $DBI_code_for_rule{'INITIALLY IMMEDIATE'}; - } else { + if (!$deferrable_clause) { # check for inline constraint if 1 local column if (@{ $rel->{local_columns} } == 1) { my ($local_col) = @{ $rel->{local_columns} }; my ($remote_col) = @{ $rel->{remote_columns} || [] }; $remote_col ||= ''; - my ($deferrable_clause) = $ddl =~ / + ($deferrable_clause) = $ddl =~ / "?\Q$local_col\E"? \s* (?:\w+\s*)* (?: \( \s* \d\+ (?:\s*,\s*\d+)* \s* \) )? \s* references \s+ (?:\S+|".+?(?{DEFERRABILITY} = $deferrable for @{ $relid2rels{$relid} }; } }