From: miker Date: Thu, 6 May 2010 19:49:25 +0000 (+0000) Subject: add explicit nesting parens in SQL; protect against empty class specifiers (throw... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=040c11c044da30ed312453ac7e1da0cb41e3922a;p=evergreen%2Ftadl.git add explicit nesting parens in SQL; protect against empty class specifiers (throw them away) git-svn-id: svn://svn.open-ils.org/ILS/trunk@16400 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm index 7c9d85d522..062ae64c8e 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm @@ -376,6 +376,8 @@ __PACKAGE__->add_search_modifier( 'staff' ); #------------------------------- package OpenILS::Application::Storage::Driver::Pg::QueryParser::query_plan; use base 'QueryParser::query_plan'; +use OpenSRF::Utils::Logger qw($logger); +use Data::Dumper; sub toSQL { my $self = shift; @@ -401,6 +403,8 @@ sub toSQL { $self->QueryParser->superpage_size($filters{superpage_size}) if ($filters{superpage_size}); $self->QueryParser->core_limit($filters{core_limit}) if ($filters{core_limit}); + $logger->debug("Query plan:\n".Dumper($self)); + my $flat_plan = $self->flatten; # generate the relevance ranking @@ -586,7 +590,7 @@ sub flatten { my $self = shift; my $from = shift || ''; - my $where = shift || ''; + my $where = shift || '('; my @rank_list; for my $node ( @{$self->query_nodes} ) { @@ -676,7 +680,7 @@ sub flatten { } } - return { rank_list => \@rank_list, from => $from, where => $where }; + return { rank_list => \@rank_list, from => $from, where => $where.')' }; } diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/QueryParser.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/QueryParser.pm index 948346b1cc..05ff6befee 100755 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/QueryParser.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/QueryParser.pm @@ -586,13 +586,19 @@ sub decompose { $last_type = ''; } elsif ($self->search_class_count && /$search_class_re/) { # changing current class + + if ($last_type eq 'CLASS') { + $struct->remove_last_node( $current_class ); + warn "Encountered class change with no searches!\n" if $self->debug; + } + warn "Encountered class change: $1\n" if $self->debug; $current_class = $1; $struct->classed_node( $current_class ); $_ = $'; - $last_type = ''; + $last_type = 'CLASS'; } elsif (/^\s*"([^"]+)"/) { # phrase, always anded warn "Encountered phrase: $1\n" if $self->debug; @@ -776,6 +782,16 @@ sub classed_node { return $node; } +sub remove_last_node { + my $self = shift; + my $requested_class = shift; + + my $old = pop(@{$self->query_nodes}); + pop(@{$self->query_nodes}) if (@{$self->query_nodes}); + + return $old; +} + sub query_nodes { my $self = shift; return $self->{query};