| 1 | package Pg::SQL::PrettyPrinter::Node::SelectStmt; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | # UTF8 boilerplace, per http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/ | ||||||||||||||||||||
| 4 | 11 | ▶ | use v5.26; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 11 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 11 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 11 | ▶ | use warnings qw( FATAL utf8 ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 11 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 11 | ▶ | use open qw( :std :utf8 ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 11 | ▶ | use Unicode::Normalize qw( NFC ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 11 | ▶ | use Unicode::Collate; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 11 | ▶ | use Encode qw( decode ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 11 | ▶ | if ( grep /\P{ASCII}/ => @ARGV ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 15 | 0 | @ARGV = map { decode( 'UTF-8', $_ ) } @ARGV; | |||||||||||||||||||
| 16 | } | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | # If there is __DATA__,then uncomment next line: | ||||||||||||||||||||
| 19 | # binmode( DATA, ':encoding(UTF-8)' ); | ||||||||||||||||||||
| 20 | # UTF8 boilerplace, per http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/ | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | # Useful common code | ||||||||||||||||||||
| 23 | 11 | ▶ | use autodie; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | 11 | ▶ | use Carp qw( carp croak confess cluck ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | 11 | ▶ | use English qw( -no_match_vars ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 26 | 11 | ▶ | use Data::Dumper qw( Dumper ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | # give a full stack dump on any untrapped exceptions | ||||||||||||||||||||
| 29 | 0 | ▶ | local $SIG{ __DIE__ } = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 30 | 0 | ▶ | confess "Uncaught exception: @_" unless $^S; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | 11 | }; | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | # now promote run-time warnings into stackdumped exceptions | ||||||||||||||||||||
| 34 | # *unless* we're in an try block, in which | ||||||||||||||||||||
| 35 | # case just generate a clucking stackdump instead | ||||||||||||||||||||
| 36 | 0 | ▶ | local $SIG{ __WARN__ } = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 37 | 0 | ▶ | if ( $^S ) { cluck "Trapped warning: @_" } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 38 | 0 | else { confess "Deadly warning: @_" } | |||||||||||||||||||
| 39 | 11 | }; | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | # Useful common code | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 11 | ▶ | use parent qw( Pg::SQL::PrettyPrinter::Node ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 119 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 46 | 119 | my $class = shift; | |||||||||||||||||||
| 47 | 119 | my $self = $class->SUPER::new( @_ ); | |||||||||||||||||||
| 48 | 119 | bless $self, $class; | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 119 | $self->objectify( | |||||||||||||||||||
| 51 | 'valuesLists', | ||||||||||||||||||||
| 52 | [ 'withClause', 'ctes' ], | ||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||
| 54 | 119 | ▶ | if ( $self->setop ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | 5 | $self->init_setop; | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | else { | ||||||||||||||||||||
| 58 | 114 | $self->init_plain; | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 119 | return $self; | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 169 | ▶ | sub setop { | ||||||||||||||||||
|
Subroutine
setop: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 65 | 169 | my $self = shift; | |||||||||||||||||||
| 66 | 169 | ▶ | return if $self->{ 'op' } eq 'SETOP_NONE'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 67 | 41 | my $op = $self->{ 'op' }; | |||||||||||||||||||
| 68 | 41 | $op =~ s/^SETOP_//; | |||||||||||||||||||
| 69 | 41 | ▶ | $op .= ' ALL' if $self->{ 'all' }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | 41 | return $op; | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 5 | ▶ | sub init_setop { | ||||||||||||||||||
|
Subroutine
init_setop: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 74 | 5 | my $self = shift; | |||||||||||||||||||
| 75 | 5 | for my $element ( qw( rarg larg ) ) { | |||||||||||||||||||
| 76 | 10 | $self->{ $element } = $self->make_from( { 'SelectStmt' => $self->{ $element } } ); | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 114 | ▶ | sub init_plain { | ||||||||||||||||||
|
Subroutine
init_plain: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 81 | 114 | my $self = shift; | |||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 114 | $self->objectify( qw( targetList fromClause whereClause groupClause havingClause sortClause limitCount limitOffset distinctClause lockingClause ) ); | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 122 | ▶ | sub as_text { | ||||||||||||||||||
|
Subroutine
as_text: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||
| 87 | 122 | my $self = shift; | |||||||||||||||||||
| 88 | 122 | ▶ | if ( exists $self->{ 'valuesLists' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | 16 | return sprintf( 'VALUES %s', join( ', ', map { $_->as_text } @{ $self->{ 'valuesLists' } } ) ); | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | 106 | my $prefix = ''; | |||||||||||||||||||
| 92 | 106 | ▶ | if ( exists $self->{ 'withClause' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | 2 | $prefix = 'WITH '; | |||||||||||||||||||
| 94 | 2 | ▶ | $prefix .= 'RECURSIVE ' if $self->{ 'withClause' }->{ 'recursive' }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 95 | 2 | $prefix .= join( ', ', map { $_->as_text } @{ $self->{ 'withClause' }->{ 'ctes' } } ) . ' '; | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | 106 | ▶ | return $prefix . ( $self->{ 'op' } eq 'SETOP_NONE' ? $self->as_text_plain : $self->as_text_setop ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 5 | ▶ | sub as_text_setop { | ||||||||||||||||||
|
Subroutine
as_text_setop: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||
| 101 | 5 | my $self = shift; | |||||||||||||||||||
| 102 | 5 | my @elements = (); | |||||||||||||||||||
| 103 | 5 | ▶ | if ( ( $self->{ 'larg' }->setop // '' ) eq $self->setop ) { | ||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{"larg"}->setop // ""
MC/DC100%1/1
$self->{"larg"}->setop // ""
$self->{"larg"}->setop
Truth table100%2/2
A
A= $self->{"larg"}->setop
| |||||||||||||||||||||
| 104 | 1 | push @elements, $self->{ 'larg' }->as_text; | |||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | else { | ||||||||||||||||||||
| 107 | 4 | push @elements, '(', $self->{ 'larg' }->as_text, ')'; | |||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | 5 | push @elements, $self->setop; | |||||||||||||||||||
| 110 | 5 | ▶ | if ( ( $self->{ 'rarg' }->setop // '' ) eq $self->setop ) { | ||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{"rarg"}->setop // ""
MC/DC100%1/1
$self->{"rarg"}->setop // ""
$self->{"rarg"}->setop
Truth table100%2/2
A
A= $self->{"rarg"}->setop
| |||||||||||||||||||||
| 111 | 0 | push @elements, $self->{ 'rarg' }->as_text; | |||||||||||||||||||
| 112 | } | ||||||||||||||||||||
| 113 | else { | ||||||||||||||||||||
| 114 | 5 | push @elements, '(', $self->{ 'rarg' }->as_text, ')'; | |||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | 5 | return join( " ", @elements ); | |||||||||||||||||||
| 117 | } | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | 101 | ▶ | sub as_text_plain { | ||||||||||||||||||
|
Subroutine
as_text_plain: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||
| 120 | 101 | my $self = shift; | |||||||||||||||||||
| 121 | 101 | my $query = 'SELECT '; | |||||||||||||||||||
| 122 | 101 | ▶ | if ( exists $self->{ 'distinctClause' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 123 | 2 | ▶ | if ( 0 == scalar @{ $self->{ 'distinctClause' } } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 124 | 1 | $query .= 'DISTINCT '; | |||||||||||||||||||
| 125 | } | ||||||||||||||||||||
| 126 | else { | ||||||||||||||||||||
| 127 | $query .= sprintf( | ||||||||||||||||||||
| 128 | 'DISTINCT ON ( %s ) ', | ||||||||||||||||||||
| 129 | 1 | join( ', ', map { $_->as_text } @{ $self->{ 'distinctClause' } } ) | |||||||||||||||||||
| 130 | ); | ||||||||||||||||||||
| 131 | } | ||||||||||||||||||||
| 132 | } | ||||||||||||||||||||
| 133 | 101 | $query .= join( ', ', map { $_->as_text } @{ $self->{ 'targetList' } } ); | |||||||||||||||||||
| 134 | 101 | ▶ | if ( exists $self->{ 'fromClause' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 135 | 63 | $query .= ' FROM ' . join( ', ', map { $_->as_text } @{ $self->{ 'fromClause' } } ); | |||||||||||||||||||
| 136 | } | ||||||||||||||||||||
| 137 | 101 | ▶ | if ( exists $self->{ 'whereClause' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 138 | 11 | $query .= ' WHERE ' . $self->{ 'whereClause' }->as_text; | |||||||||||||||||||
| 139 | } | ||||||||||||||||||||
| 140 | 101 | ▶ | if ( exists $self->{ 'groupClause' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 141 | 5 | $query .= ' GROUP BY ' . join( ', ', map { $_->as_text } @{ $self->{ 'groupClause' } } ); | |||||||||||||||||||
| 142 | } | ||||||||||||||||||||
| 143 | 101 | ▶ | if ( exists $self->{ 'havingClause' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 144 | 1 | $query .= ' HAVING ' . $self->{ 'havingClause' }->as_text; | |||||||||||||||||||
| 145 | } | ||||||||||||||||||||
| 146 | 101 | ▶ | if ( exists $self->{ 'sortClause' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 147 | 12 | $query .= ' ORDER BY ' . join( ', ', map { $_->as_text } @{ $self->{ 'sortClause' } } ); | |||||||||||||||||||
| 148 | } | ||||||||||||||||||||
| 149 | 101 | ▶ | if ( exists $self->{ 'limitCount' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 150 | 10 | $query .= ' LIMIT ' . $self->{ 'limitCount' }->as_text; | |||||||||||||||||||
| 151 | } | ||||||||||||||||||||
| 152 | 101 | ▶ | if ( exists $self->{ 'limitOffset' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 153 | 1 | $query .= ' OFFSET ' . $self->{ 'limitOffset' }->as_text; | |||||||||||||||||||
| 154 | } | ||||||||||||||||||||
| 155 | 101 | ▶ | if ( exists $self->{ 'lockingClause' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 156 | $query .= ' ' . join( | ||||||||||||||||||||
| 157 | ' ', | ||||||||||||||||||||
| 158 | 9 | map { $_->as_text } @{ $self->{ 'lockingClause' } } | |||||||||||||||||||
| 159 | ); | ||||||||||||||||||||
| 160 | } | ||||||||||||||||||||
| 161 | 101 | return $query; | |||||||||||||||||||
| 162 | } | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | 117 | ▶ | sub pretty_print { | ||||||||||||||||||
|
Subroutine
pretty_print: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||
| 165 | 117 | my $self = shift; | |||||||||||||||||||
| 166 | 117 | ▶ | if ( exists $self->{ 'valuesLists' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 167 | 16 | my @lines = (); | |||||||||||||||||||
| 168 | 16 | push @lines, 'VALUES'; | |||||||||||||||||||
| 169 | 16 | push @lines, map { $self->increase_indent( $_->as_text ) . ',' } @{ $self->{ 'valuesLists' } }; | |||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | # Remove unnecessary trailing , in last element | ||||||||||||||||||||
| 172 | 16 | $lines[ -1 ] =~ s/,\z//; | |||||||||||||||||||
| 173 | 16 | return join( "\n", @lines ); | |||||||||||||||||||
| 174 | } | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | 101 | ▶ | my $main_body = $self->{ 'op' } eq 'SETOP_NONE' ? $self->pretty_print_plain : $self->pretty_print_setop; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 177 | 101 | ▶ | return $main_body unless exists $self->{ 'withClause' }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | 2 | my @cte_def = (); | |||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | 2 | push @cte_def, map { $_->pretty_print . ',' } @{ $self->{ 'withClause' }->{ 'ctes' } }; | |||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | # Remove unnecessary trailing , in last element | ||||||||||||||||||||
| 184 | 2 | $cte_def[ -1 ] =~ s/,\z//; | |||||||||||||||||||
| 185 | 2 | ▶ | if ( $self->{ 'withClause' }->{ 'recursive' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 186 | 1 | $cte_def[ 0 ] = 'WITH RECURSIVE ' . $cte_def[ 0 ]; | |||||||||||||||||||
| 187 | } | ||||||||||||||||||||
| 188 | else { | ||||||||||||||||||||
| 189 | 1 | $cte_def[ 0 ] = 'WITH ' . $cte_def[ 0 ]; | |||||||||||||||||||
| 190 | } | ||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | 2 | my @lines = (); | |||||||||||||||||||
| 193 | 2 | push @lines, join( ' ', @cte_def ); | |||||||||||||||||||
| 194 | 2 | push @lines, $main_body; | |||||||||||||||||||
| 195 | 2 | return join( "\n", @lines ); | |||||||||||||||||||
| 196 | } | ||||||||||||||||||||
| 197 | |||||||||||||||||||||
| 198 | 5 | ▶ | sub pretty_print_setop { | ||||||||||||||||||
|
Subroutine
pretty_print_setop: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||
| 199 | 5 | my $self = shift; | |||||||||||||||||||
| 200 | 5 | my @elements = (); | |||||||||||||||||||
| 201 | 5 | ▶ | if ( ( $self->{ 'larg' }->setop // '' ) eq $self->setop ) { | ||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{"larg"}->setop // ""
MC/DC100%1/1
$self->{"larg"}->setop // ""
$self->{"larg"}->setop
Truth table100%2/2
A
A= $self->{"larg"}->setop
| |||||||||||||||||||||
| 202 | 1 | push @elements, $self->{ 'larg' }->pretty_print; | |||||||||||||||||||
| 203 | } | ||||||||||||||||||||
| 204 | else { | ||||||||||||||||||||
| 205 | 4 | push @elements, '('; | |||||||||||||||||||
| 206 | 4 | push @elements, $self->increase_indent( $self->{ 'larg' }->pretty_print ); | |||||||||||||||||||
| 207 | 4 | push @elements, ')'; | |||||||||||||||||||
| 208 | } | ||||||||||||||||||||
| 209 | 5 | push @elements, $self->setop; | |||||||||||||||||||
| 210 | 5 | ▶ | if ( ( $self->{ 'rarg' }->setop // '' ) eq $self->setop ) { | ||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{"rarg"}->setop // ""
MC/DC100%1/1
$self->{"rarg"}->setop // ""
$self->{"rarg"}->setop
Truth table100%2/2
A
A= $self->{"rarg"}->setop
| |||||||||||||||||||||
| 211 | 0 | push @elements, $self->{ 'rarg' }->pretty_print; | |||||||||||||||||||
| 212 | } | ||||||||||||||||||||
| 213 | else { | ||||||||||||||||||||
| 214 | 5 | push @elements, '('; | |||||||||||||||||||
| 215 | 5 | push @elements, $self->increase_indent( $self->{ 'rarg' }->pretty_print ); | |||||||||||||||||||
| 216 | 5 | push @elements, ')'; | |||||||||||||||||||
| 217 | } | ||||||||||||||||||||
| 218 | 5 | return join( "\n", @elements ); | |||||||||||||||||||
| 219 | } | ||||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | 96 | ▶ | sub pretty_print_plain { | ||||||||||||||||||
|
Subroutine
pretty_print_plain: called CC=13 SCAR=25.6
Pod
documented
| |||||||||||||||||||||
| 222 | 96 | my $self = shift; | |||||||||||||||||||
| 223 | 96 | my @lines = ( 'SELECT' ); | |||||||||||||||||||
| 224 | |||||||||||||||||||||
| 225 | 96 | ▶ | if ( exists $self->{ 'distinctClause' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 226 | 2 | ▶ | if ( 0 == scalar @{ $self->{ 'distinctClause' } } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 227 | 1 | $lines[ 0 ] .= ' DISTINCT'; | |||||||||||||||||||
| 228 | } | ||||||||||||||||||||
| 229 | else { | ||||||||||||||||||||
| 230 | push @lines, sprintf( | ||||||||||||||||||||
| 231 | $self->increase_indent( 'DISTINCT ON ( %s )' ), | ||||||||||||||||||||
| 232 | 1 | join( ', ', map { $_->pretty_print } @{ $self->{ 'distinctClause' } } ) | |||||||||||||||||||
| 233 | ); | ||||||||||||||||||||
| 234 | } | ||||||||||||||||||||
| 235 | } | ||||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | 96 | for my $i ( 0 .. $#{ $self->{ 'targetList' } } ) { | |||||||||||||||||||
| 238 | 235 | my $is_last = $i == $#{ $self->{ 'targetList' } }; | |||||||||||||||||||
| 239 | 235 | my $target = $self->{ 'targetList' }->[ $i ]; | |||||||||||||||||||
| 240 | 235 | my $pretty = $self->increase_indent( $target->pretty_print() ); | |||||||||||||||||||
| 241 | 235 | ▶ | $pretty .= ',' unless $is_last; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 242 | 235 | push @lines, $pretty; | |||||||||||||||||||
| 243 | } | ||||||||||||||||||||
| 244 | 96 | ▶ | if ( exists $self->{ 'fromClause' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 245 | 58 | push @lines, 'FROM'; | |||||||||||||||||||
| 246 | 58 | push @lines, map { $self->increase_indent( $_->pretty_print ) . ',' } @{ $self->{ 'fromClause' } }; | |||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | # Remove unnecessary trailing , in last element | ||||||||||||||||||||
| 249 | 58 | $lines[ -1 ] =~ s/,\z//; | |||||||||||||||||||
| 250 | } | ||||||||||||||||||||
| 251 | 96 | ▶ | if ( exists $self->{ 'whereClause' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 252 | 10 | push @lines, 'WHERE'; | |||||||||||||||||||
| 253 | 10 | push @lines, $self->increase_indent( $self->{ 'whereClause' }->pretty_print ); | |||||||||||||||||||
| 254 | } | ||||||||||||||||||||
| 255 | 96 | ▶ | if ( exists $self->{ 'groupClause' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 256 | 5 | push @lines, 'GROUP BY'; | |||||||||||||||||||
| 257 | 5 | push @lines, map { $self->increase_indent( $_->pretty_print ) . ',' } @{ $self->{ 'groupClause' } }; | |||||||||||||||||||
| 258 | |||||||||||||||||||||
| 259 | # Remove unnecessary trailing , in last element | ||||||||||||||||||||
| 260 | 5 | $lines[ -1 ] =~ s/,\z//; | |||||||||||||||||||
| 261 | } | ||||||||||||||||||||
| 262 | 96 | ▶ | if ( exists $self->{ 'havingClause' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 263 | 1 | push @lines, 'HAVING'; | |||||||||||||||||||
| 264 | 1 | push @lines, $self->increase_indent( $self->{ 'havingClause' }->pretty_print ); | |||||||||||||||||||
| 265 | } | ||||||||||||||||||||
| 266 | 96 | ▶ | if ( exists $self->{ 'sortClause' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 267 | 12 | push @lines, 'ORDER BY'; | |||||||||||||||||||
| 268 | 12 | push @lines, map { $self->increase_indent( $_->pretty_print ) . ',' } @{ $self->{ 'sortClause' } }; | |||||||||||||||||||
| 269 | |||||||||||||||||||||
| 270 | # Remove unnecessary trailing , in last element | ||||||||||||||||||||
| 271 | 12 | $lines[ -1 ] =~ s/,\z//; | |||||||||||||||||||
| 272 | } | ||||||||||||||||||||
| 273 | |||||||||||||||||||||
| 274 | 96 | ▶ | if ( exists $self->{ 'limitCount' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 275 | 10 | push @lines, 'LIMIT ' . $self->{ 'limitCount' }->pretty_print; | |||||||||||||||||||
| 276 | } | ||||||||||||||||||||
| 277 | 96 | ▶ | if ( exists $self->{ 'limitOffset' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 278 | 1 | push @lines, 'OFFSET ' . $self->{ 'limitOffset' }->pretty_print; | |||||||||||||||||||
| 279 | } | ||||||||||||||||||||
| 280 | 96 | ▶ | if ( exists $self->{ 'lockingClause' } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 281 | 9 | push @lines, map { $_->pretty_print } @{ $self->{ 'lockingClause' } }; | |||||||||||||||||||
| 282 | } | ||||||||||||||||||||
| 283 | |||||||||||||||||||||
| 284 | 96 | return join( "\n", @lines ); | |||||||||||||||||||
| 285 | } | ||||||||||||||||||||
| 286 | |||||||||||||||||||||
| 287 | 11 | 1; | |||||||||||||||||||