1
# Copyright (C) 2008-2009 Sun Microsystems, Inc. All rights reserved.
2
# Use is subject to license terms.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18
package GenTest::Transform::InlineSubqueries;
21
@ISA = qw(GenTest GenTest::Transform);
26
use GenTest::Transform;
27
use GenTest::Constants;
29
# This is a regexp to match nested brackets, taken from
30
# here http://www.perlmonks.org/?node_id=547596
36
\((??{$paren_rx})\) # either match another paren-set
37
| [^()]+ # or match non-parens (or escaped parens
42
my ($class, $query, $executor) = @_;
44
my $inline_successful = 0;
45
$query =~ s{(\(\s*SELECT\s+(??{$paren_rx})\))}{
46
my $result = $executor->execute($1, 1);
49
($result->status() != STATUS_OK) ||
52
$1; # return original query
54
$inline_successful = 1; # return inlined literals
55
" ( ".join(', ', map {
56
if (not defined $_->[0]) {
58
} elsif ($_->[0] =~ m{^\d+$}sio){
63
} @{$result->data()})." ) ";
67
my $final_result = $executor->execute($query, 1);
70
($inline_successful) &&
71
($final_result->status() == STATUS_OK)
73
return $query." /* TRANSFORM_OUTCOME_UNORDERED_MATCH */";
75
return STATUS_WONT_HANDLE;