| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
31
|
|
|
31
|
|
164678
|
use strict; |
|
|
31
|
|
|
|
|
248
|
|
|
|
31
|
|
|
|
|
951
|
|
|
2
|
31
|
|
|
31
|
|
163
|
use warnings; |
|
|
31
|
|
|
|
|
54
|
|
|
|
31
|
|
|
|
|
1603
|
|
|
3
|
|
|
|
|
|
|
package SQL::SplitStatement; |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.00021'; # TRIAL |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
31
|
|
|
31
|
|
178
|
use base 'Class::Accessor::Fast'; |
|
|
31
|
|
|
|
|
58
|
|
|
|
31
|
|
|
|
|
16449
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
31
|
|
|
31
|
|
96851
|
use Carp qw(croak); |
|
|
31
|
|
|
|
|
85
|
|
|
|
31
|
|
|
|
|
2370
|
|
|
11
|
31
|
|
|
31
|
|
16565
|
use SQL::Tokenizer 0.22 qw(tokenize_sql); |
|
|
31
|
|
|
|
|
23913
|
|
|
|
31
|
|
|
|
|
2028
|
|
|
12
|
31
|
|
|
31
|
|
19154
|
use List::MoreUtils qw(firstval firstidx each_array); |
|
|
31
|
|
|
|
|
458844
|
|
|
|
31
|
|
|
|
|
227
|
|
|
13
|
31
|
|
|
31
|
|
60382
|
use Regexp::Common qw(delimited); |
|
|
31
|
|
|
|
|
221832
|
|
|
|
31
|
|
|
|
|
157
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use constant { |
|
16
|
31
|
|
|
|
|
146326
|
NEWLINE => "\n", |
|
17
|
|
|
|
|
|
|
SEMICOLON => ';', |
|
18
|
|
|
|
|
|
|
DOT => '.', |
|
19
|
|
|
|
|
|
|
FORWARD_SLASH => '/', |
|
20
|
|
|
|
|
|
|
QUESTION_MARK => '?', |
|
21
|
|
|
|
|
|
|
SINGLE_DOLLAR => '$', |
|
22
|
|
|
|
|
|
|
DOUBLE_DOLLAR => '$$', |
|
23
|
|
|
|
|
|
|
OPEN_BRACKET => '(', |
|
24
|
|
|
|
|
|
|
CLOSED_BRACKET => ')', |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
SEMICOLON_TERMINATOR => 1, |
|
27
|
|
|
|
|
|
|
SLASH_TERMINATOR => 2, |
|
28
|
|
|
|
|
|
|
CUSTOM_DELIMITER => 3 |
|
29
|
31
|
|
|
31
|
|
3173098
|
}; |
|
|
31
|
|
|
|
|
92
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $transaction_RE = qr[^(?: |
|
32
|
|
|
|
|
|
|
; |
|
33
|
|
|
|
|
|
|
|/ |
|
34
|
|
|
|
|
|
|
|WORK |
|
35
|
|
|
|
|
|
|
|TRAN |
|
36
|
|
|
|
|
|
|
|TRANSACTION |
|
37
|
|
|
|
|
|
|
|ISOLATION |
|
38
|
|
|
|
|
|
|
|READ |
|
39
|
|
|
|
|
|
|
)$]xi; |
|
40
|
|
|
|
|
|
|
my $procedural_END_RE = qr/^(?:IF|CASE|LOOP)$/i; |
|
41
|
|
|
|
|
|
|
my $terminator_RE = qr[ |
|
42
|
|
|
|
|
|
|
;\s*\n\s*\.\s*\n\s*/\s*\n? |
|
43
|
|
|
|
|
|
|
|;\s*\n\s*/\s*\n? |
|
44
|
|
|
|
|
|
|
|\.\s*\n\s*/\s*\n? |
|
45
|
|
|
|
|
|
|
|\n\s*/\s*\n? |
|
46
|
|
|
|
|
|
|
|; |
|
47
|
|
|
|
|
|
|
]x; |
|
48
|
|
|
|
|
|
|
my $begin_comment_RE = qr/^(?:--|\/\*)/; |
|
49
|
|
|
|
|
|
|
my $quoted_RE = $RE{delimited}{ -delim=>q{"'`} }; |
|
50
|
|
|
|
|
|
|
my $dollar_placeholder_RE = qr/^\$\d+$/; |
|
51
|
|
|
|
|
|
|
my $inner_identifier_RE = qr/[_a-zA-Z][_a-zA-Z0-9]*/; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $CURSOR_RE = qr/^CURSOR$/i; |
|
54
|
|
|
|
|
|
|
my $DELIMITER_RE = qr/^DELIMITER$/i; |
|
55
|
|
|
|
|
|
|
my $DECLARE_RE = qr/^DECLARE$/i; |
|
56
|
|
|
|
|
|
|
my $PROCEDURE_FUNCTION_RE = qr/^(?:FUNCTION|PROCEDURE)$/i; |
|
57
|
|
|
|
|
|
|
my $PACKAGE_RE = qr/^PACKAGE$/i; |
|
58
|
|
|
|
|
|
|
my $BEGIN_RE = qr/^BEGIN$/i; |
|
59
|
|
|
|
|
|
|
my $END_RE = qr/^END$/i; |
|
60
|
|
|
|
|
|
|
my $AS_RE = qr/^AS$/i; |
|
61
|
|
|
|
|
|
|
my $IS_RE = qr/^IS$/i; |
|
62
|
|
|
|
|
|
|
my $TYPE_RE = qr/^TYPE$/i; |
|
63
|
|
|
|
|
|
|
my $BODY_RE = qr/^BODY$/i; |
|
64
|
|
|
|
|
|
|
my $DROP_RE = qr/^DROP$/i; |
|
65
|
|
|
|
|
|
|
my $CRUD_RE = qr/^(?:DELETE|INSERT|SELECT|UPDATE)$/i; |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $GRANT_REVOKE_RE = qr/^(?:GRANT|REVOKE)$/i;; |
|
68
|
|
|
|
|
|
|
my $CREATE_ALTER_RE = qr/^(?:CREATE|ALTER)$/i; |
|
69
|
|
|
|
|
|
|
my $CREATE_REPLACE_RE = qr/^(?:CREATE|REPLACE)$/i; |
|
70
|
|
|
|
|
|
|
my $OR_REPLACE_RE = qr/^(?:OR|REPLACE)$/i; |
|
71
|
|
|
|
|
|
|
my $OR_REPLACE_PACKAGE_RE = qr/^(?:OR|REPLACE|PACKAGE)$/i; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $pre_identifier_RE = qr/^(?: |
|
74
|
|
|
|
|
|
|
BODY |
|
75
|
|
|
|
|
|
|
|CONSTRAINT |
|
76
|
|
|
|
|
|
|
|CURSOR |
|
77
|
|
|
|
|
|
|
|DECLARE |
|
78
|
|
|
|
|
|
|
|FUNCTION |
|
79
|
|
|
|
|
|
|
|INDEX |
|
80
|
|
|
|
|
|
|
|PACKAGE |
|
81
|
|
|
|
|
|
|
|PROCEDURE |
|
82
|
|
|
|
|
|
|
|REFERENCES |
|
83
|
|
|
|
|
|
|
|TABLE |
|
84
|
|
|
|
|
|
|
|[.,(] |
|
85
|
|
|
|
|
|
|
)$/xi; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
SQL::SplitStatement->mk_accessors( qw/ |
|
88
|
|
|
|
|
|
|
keep_terminators |
|
89
|
|
|
|
|
|
|
keep_extra_spaces |
|
90
|
|
|
|
|
|
|
keep_empty_statements |
|
91
|
|
|
|
|
|
|
keep_comments |
|
92
|
|
|
|
|
|
|
slash_terminates |
|
93
|
|
|
|
|
|
|
_tokens |
|
94
|
|
|
|
|
|
|
_current_statement |
|
95
|
|
|
|
|
|
|
_custom_delimiter |
|
96
|
|
|
|
|
|
|
_terminators |
|
97
|
|
|
|
|
|
|
_tokens_in_custom_delimiter |
|
98
|
|
|
|
|
|
|
/); |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# keep_terminators alias |
|
101
|
14
|
|
|
14
|
1
|
60123
|
sub keep_terminator { shift->keep_terminators(@_) } |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub new { |
|
104
|
53
|
|
|
53
|
1
|
28342
|
my $class = shift; |
|
105
|
53
|
100
|
100
|
|
|
463
|
my $parameters = @_ > 1 ? { @_ } : $_[0] || {}; |
|
106
|
53
|
100
|
|
|
|
297
|
if ( exists $parameters->{keep_terminators} ) { |
|
|
|
100
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
croak( q[keep_terminator and keep_terminators can't be both assigned'] ) |
|
108
|
|
|
|
|
|
|
if exists $parameters->{keep_terminator} |
|
109
|
3
|
100
|
|
|
|
29
|
} |
|
110
|
|
|
|
|
|
|
elsif ( exists $parameters->{keep_terminator} ) { |
|
111
|
|
|
|
|
|
|
$parameters->{keep_terminators} = delete $parameters->{keep_terminator} |
|
112
|
15
|
|
|
|
|
55
|
} |
|
113
|
|
|
|
|
|
|
$parameters->{slash_terminates} = 1 |
|
114
|
52
|
100
|
|
|
|
250
|
unless exists $parameters->{slash_terminates}; |
|
115
|
52
|
|
|
|
|
549
|
$class->SUPER::new( $parameters ) |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub split { |
|
119
|
71
|
|
|
71
|
1
|
16615
|
my ($self, $code) = @_; |
|
120
|
71
|
|
|
|
|
324
|
my ($statements, undef) = $self->split_with_placeholders($code); |
|
121
|
71
|
|
|
|
|
185
|
return @{ $statements } |
|
|
71
|
|
|
|
|
716
|
|
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub split_with_placeholders { |
|
125
|
75
|
|
|
75
|
1
|
1001
|
my ($self, $code) = @_; |
|
126
|
|
|
|
|
|
|
|
|
127
|
75
|
|
|
|
|
173
|
my @placeholders = (); |
|
128
|
75
|
|
|
|
|
150
|
my @statements = (); |
|
129
|
75
|
|
|
|
|
136
|
my $statement_placeholders = 0; |
|
130
|
|
|
|
|
|
|
|
|
131
|
75
|
|
|
|
|
126
|
my $inside_block = 0; |
|
132
|
75
|
|
|
|
|
129
|
my $inside_brackets = 0; |
|
133
|
75
|
|
|
|
|
124
|
my $inside_sub = 0; |
|
134
|
75
|
|
|
|
|
162
|
my $inside_is_as = 0; |
|
135
|
75
|
|
|
|
|
144
|
my $inside_cursor = 0; |
|
136
|
75
|
|
|
|
|
136
|
my $inside_is_cursor = 0; |
|
137
|
75
|
|
|
|
|
121
|
my $inside_declare = 0; |
|
138
|
75
|
|
|
|
|
138
|
my $inside_package = 0; |
|
139
|
75
|
|
|
|
|
120
|
my $inside_grant_revoke = 0; |
|
140
|
75
|
|
|
|
|
138
|
my $inside_crud = 0; |
|
141
|
75
|
|
|
|
|
121
|
my $extra_end_found = 0; |
|
142
|
|
|
|
|
|
|
|
|
143
|
75
|
|
|
|
|
139
|
my @sub_names = (); |
|
144
|
75
|
|
|
|
|
167
|
my $package_name = ''; |
|
145
|
|
|
|
|
|
|
|
|
146
|
75
|
|
|
|
|
162
|
my $dollar_quote; |
|
147
|
|
|
|
|
|
|
my $dollar_quote_to_add; |
|
148
|
|
|
|
|
|
|
|
|
149
|
75
|
|
|
|
|
141
|
my $prev_token = ''; |
|
150
|
75
|
|
|
|
|
145
|
my $prev_keyword = ''; |
|
151
|
|
|
|
|
|
|
|
|
152
|
75
|
|
|
|
|
133
|
my $custom_delimiter_def_found = 0; |
|
153
|
|
|
|
|
|
|
|
|
154
|
75
|
50
|
|
|
|
241
|
if ( !defined $code ) { |
|
155
|
0
|
|
|
|
|
0
|
$code = "\n" |
|
156
|
|
|
|
|
|
|
} else { |
|
157
|
75
|
|
|
|
|
425
|
$code .= "\n" |
|
158
|
|
|
|
|
|
|
}; |
|
159
|
75
|
|
|
|
|
393
|
$self->_tokens( [ tokenize_sql($code) ] ); |
|
160
|
75
|
|
|
|
|
87998
|
$self->_terminators( [] ); # Needed (only) to remove them afterwards |
|
161
|
|
|
|
|
|
|
# when keep_terminators is false. |
|
162
|
|
|
|
|
|
|
|
|
163
|
75
|
|
|
|
|
2150
|
$self->_current_statement(''); |
|
164
|
|
|
|
|
|
|
|
|
165
|
75
|
|
|
|
|
661
|
while ( defined( my $token = shift @{ $self->_tokens } ) ) { |
|
|
58169
|
|
|
|
|
1018440
|
|
|
166
|
58094
|
|
|
|
|
299647
|
my $terminator_found = 0; |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# Skip this token if it's a comment and we don't want to keep it. |
|
169
|
58094
|
100
|
100
|
|
|
104167
|
next if $self->_is_comment($token) && ! $self->keep_comments; |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
# Append the token to the current statement; |
|
172
|
57336
|
|
|
|
|
151114
|
$self->_add_to_current_statement($token); |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
# The token is gathered even if it was a space-only token, |
|
175
|
|
|
|
|
|
|
# but in this case we can skip any further analysis. |
|
176
|
57336
|
100
|
|
|
|
587737
|
next if $token =~ /^\s+$/; |
|
177
|
|
|
|
|
|
|
|
|
178
|
30450
|
100
|
|
|
|
58459
|
if ( $dollar_quote ) { |
|
179
|
2423
|
100
|
|
|
|
4907
|
if ( $self->_dollar_quote_close_found($token, $dollar_quote) ) { |
|
180
|
40
|
|
|
|
|
164
|
$self->_add_to_current_statement($dollar_quote_to_add); |
|
181
|
40
|
|
|
|
|
368
|
undef $dollar_quote; |
|
182
|
|
|
|
|
|
|
# Saving $prev_token not necessary in this case. |
|
183
|
|
|
|
|
|
|
|
|
184
|
40
|
|
|
|
|
73
|
$inside_sub = 0; # Silence sub opening before dollar quote. |
|
185
|
40
|
|
|
|
|
103
|
@sub_names = (); |
|
186
|
40
|
|
|
|
|
66
|
$inside_is_as = 0; # Silence is_as opening before dollar quote. |
|
187
|
40
|
|
|
|
|
61
|
$inside_declare = 0; |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
next |
|
190
|
40
|
|
|
|
|
88
|
} |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
|
|
193
|
30410
|
100
|
100
|
|
|
206238
|
if ( |
|
|
|
100
|
100
|
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
$prev_token =~ $AS_RE |
|
195
|
|
|
|
|
|
|
and !$dollar_quote |
|
196
|
|
|
|
|
|
|
and $dollar_quote = $self->_dollar_quote_open_found($token) |
|
197
|
|
|
|
|
|
|
) { |
|
198
|
40
|
|
|
|
|
547
|
( $dollar_quote_to_add = $dollar_quote ) =~ s/^\Q$token//; |
|
199
|
40
|
|
|
|
|
124
|
$self->_add_to_current_statement($dollar_quote_to_add) |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
elsif ( $token =~ $DELIMITER_RE && !$prev_token ) { |
|
202
|
41
|
|
|
|
|
191
|
my $tokens_to_shift = $self->_custom_delimiter_def_found; |
|
203
|
|
|
|
|
|
|
$self->_add_to_current_statement( |
|
204
|
41
|
|
|
|
|
79
|
join '', splice @{ $self->_tokens }, 0, $tokens_to_shift |
|
|
41
|
|
|
|
|
677
|
|
|
205
|
|
|
|
|
|
|
); |
|
206
|
41
|
|
|
|
|
411
|
$custom_delimiter_def_found = 1; |
|
207
|
41
|
100
|
|
|
|
681
|
$self->_custom_delimiter(undef) |
|
208
|
|
|
|
|
|
|
if $self->_custom_delimiter eq SEMICOLON |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
elsif ( $token eq OPEN_BRACKET ) { |
|
211
|
2108
|
|
|
|
|
3652
|
$inside_brackets++ |
|
212
|
|
|
|
|
|
|
} |
|
213
|
|
|
|
|
|
|
elsif ( $token eq CLOSED_BRACKET ) { |
|
214
|
2108
|
|
|
|
|
3608
|
$inside_brackets-- |
|
215
|
|
|
|
|
|
|
} |
|
216
|
|
|
|
|
|
|
elsif ( $self->_is_BEGIN_of_block($token, $prev_token) ) { |
|
217
|
216
|
50
|
|
|
|
627
|
$extra_end_found = 0 if $extra_end_found; |
|
218
|
216
|
|
|
|
|
427
|
$inside_block++ |
|
219
|
|
|
|
|
|
|
} |
|
220
|
|
|
|
|
|
|
elsif ( $token =~ $CREATE_ALTER_RE ) { |
|
221
|
716
|
|
|
|
|
2088
|
my $next_token = $self->_peek_at_next_significant_token( |
|
222
|
|
|
|
|
|
|
$OR_REPLACE_RE |
|
223
|
|
|
|
|
|
|
); |
|
224
|
716
|
100
|
|
|
|
3732
|
if ( $next_token =~ $PACKAGE_RE ) { |
|
225
|
39
|
|
|
|
|
74
|
$inside_package = 1; |
|
226
|
39
|
|
|
|
|
159
|
$package_name = $self->_peek_at_package_name |
|
227
|
|
|
|
|
|
|
} |
|
228
|
|
|
|
|
|
|
} |
|
229
|
|
|
|
|
|
|
elsif ( |
|
230
|
|
|
|
|
|
|
$token =~ $PROCEDURE_FUNCTION_RE |
|
231
|
|
|
|
|
|
|
|| $token =~ $BODY_RE && $prev_token =~ $TYPE_RE |
|
232
|
|
|
|
|
|
|
) { |
|
233
|
255
|
100
|
66
|
|
|
3964
|
if ( |
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
234
|
|
|
|
|
|
|
!$inside_block && !$inside_brackets |
|
235
|
|
|
|
|
|
|
&& $prev_token !~ $DROP_RE |
|
236
|
|
|
|
|
|
|
&& $prev_token !~ $pre_identifier_RE |
|
237
|
|
|
|
|
|
|
) { |
|
238
|
226
|
|
|
|
|
474
|
$inside_sub++; |
|
239
|
226
|
|
|
|
|
431
|
$prev_keyword = $token; |
|
240
|
226
|
|
|
|
|
636
|
push @sub_names, $self->_peek_at_next_significant_token |
|
241
|
|
|
|
|
|
|
} |
|
242
|
|
|
|
|
|
|
} |
|
243
|
|
|
|
|
|
|
elsif ( $token =~ /$IS_RE|$AS_RE/ ) { |
|
244
|
472
|
100
|
100
|
|
|
5187
|
if ( |
|
|
|
|
66
|
|
|
|
|
|
245
|
|
|
|
|
|
|
$prev_keyword =~ /$PROCEDURE_FUNCTION_RE|$BODY_RE/ |
|
246
|
|
|
|
|
|
|
&& !$inside_block && $prev_token !~ $pre_identifier_RE |
|
247
|
|
|
|
|
|
|
) { |
|
248
|
139
|
|
|
|
|
300
|
$inside_is_as++; |
|
249
|
139
|
|
|
|
|
299
|
$prev_keyword = '' |
|
250
|
|
|
|
|
|
|
} |
|
251
|
|
|
|
|
|
|
|
|
252
|
472
|
100
|
100
|
|
|
1602
|
$inside_is_cursor = 1 |
|
253
|
|
|
|
|
|
|
if $inside_declare && $inside_cursor |
|
254
|
|
|
|
|
|
|
} |
|
255
|
|
|
|
|
|
|
elsif ( $token =~ $DECLARE_RE ) { |
|
256
|
|
|
|
|
|
|
# In MySQL a declare can only appear inside a BEGIN ... END block. |
|
257
|
102
|
100
|
100
|
|
|
958
|
$inside_declare = 1 |
|
258
|
|
|
|
|
|
|
if !$inside_block |
|
259
|
|
|
|
|
|
|
&& $prev_token !~ $pre_identifier_RE |
|
260
|
|
|
|
|
|
|
} |
|
261
|
|
|
|
|
|
|
elsif ( $token =~ $CURSOR_RE ) { |
|
262
|
33
|
50
|
66
|
|
|
330
|
$inside_cursor = 1 |
|
|
|
|
66
|
|
|
|
|
|
263
|
|
|
|
|
|
|
if $inside_declare |
|
264
|
|
|
|
|
|
|
&& $prev_token !~ $DROP_RE |
|
265
|
|
|
|
|
|
|
&& $prev_token !~ $pre_identifier_RE |
|
266
|
|
|
|
|
|
|
} |
|
267
|
|
|
|
|
|
|
elsif ( $token =~ /$GRANT_REVOKE_RE/ ) { |
|
268
|
8
|
50
|
|
|
|
32
|
$inside_grant_revoke = 1 unless $prev_token |
|
269
|
|
|
|
|
|
|
} |
|
270
|
|
|
|
|
|
|
elsif ( |
|
271
|
|
|
|
|
|
|
defined ( my $name = $self->_is_END_of_block($token) ) |
|
272
|
|
|
|
|
|
|
) { |
|
273
|
252
|
100
|
|
|
|
673
|
$extra_end_found = 1 if !$inside_block; |
|
274
|
|
|
|
|
|
|
|
|
275
|
252
|
100
|
|
|
|
607
|
$inside_block-- if $inside_block; |
|
276
|
|
|
|
|
|
|
|
|
277
|
252
|
100
|
|
|
|
698
|
if ( !$inside_block ) { |
|
278
|
|
|
|
|
|
|
# $name contains the next (significant) token. |
|
279
|
238
|
100
|
|
|
|
670
|
if ( $name eq SEMICOLON ) { |
|
280
|
|
|
|
|
|
|
# Keep this order! |
|
281
|
91
|
100
|
66
|
|
|
432
|
if ( $inside_sub && $inside_is_as ) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
282
|
35
|
|
|
|
|
59
|
$inside_sub--; |
|
283
|
35
|
|
|
|
|
61
|
$inside_is_as--; |
|
284
|
35
|
50
|
|
|
|
139
|
pop @sub_names if $inside_sub < @sub_names |
|
285
|
|
|
|
|
|
|
} elsif ( $inside_declare ) { |
|
286
|
32
|
|
|
|
|
65
|
$inside_declare = 0 |
|
287
|
|
|
|
|
|
|
} elsif ( $inside_package ) { |
|
288
|
10
|
|
|
|
|
22
|
$inside_package = 0; |
|
289
|
10
|
|
|
|
|
20
|
$package_name = '' |
|
290
|
|
|
|
|
|
|
} |
|
291
|
|
|
|
|
|
|
} |
|
292
|
|
|
|
|
|
|
|
|
293
|
238
|
100
|
66
|
|
|
1211
|
if ( $inside_sub && @sub_names && $name eq $sub_names[-1] ) { |
|
|
|
|
100
|
|
|
|
|
|
294
|
76
|
|
|
|
|
135
|
$inside_sub--; |
|
295
|
76
|
50
|
|
|
|
267
|
pop @sub_names if $inside_sub < @sub_names |
|
296
|
|
|
|
|
|
|
} |
|
297
|
|
|
|
|
|
|
|
|
298
|
238
|
100
|
100
|
|
|
826
|
if ( $inside_package && $name eq $package_name ) { |
|
299
|
29
|
|
|
|
|
55
|
$inside_package = 0; |
|
300
|
29
|
|
|
|
|
63
|
$package_name = '' |
|
301
|
|
|
|
|
|
|
} |
|
302
|
|
|
|
|
|
|
} |
|
303
|
|
|
|
|
|
|
} |
|
304
|
|
|
|
|
|
|
elsif ( $token =~ $CRUD_RE ) { |
|
305
|
638
|
|
|
|
|
1363
|
$inside_crud = 1 |
|
306
|
|
|
|
|
|
|
} |
|
307
|
|
|
|
|
|
|
elsif ( |
|
308
|
|
|
|
|
|
|
$inside_crud && ( |
|
309
|
|
|
|
|
|
|
my $placeholder_token |
|
310
|
|
|
|
|
|
|
= $self->_questionmark_placeholder_found($token) |
|
311
|
|
|
|
|
|
|
|| $self->_named_placeholder_found($token) |
|
312
|
|
|
|
|
|
|
|| $self->_dollar_placeholder_found($token) |
|
313
|
|
|
|
|
|
|
) |
|
314
|
|
|
|
|
|
|
) { |
|
315
|
98
|
50
|
33
|
|
|
1904
|
$statement_placeholders++ |
|
316
|
|
|
|
|
|
|
if !$self->_custom_delimiter |
|
317
|
|
|
|
|
|
|
|| $self->_custom_delimiter ne $placeholder_token; |
|
318
|
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
# Needed by SQL::Tokenizer pre-0.21 |
|
320
|
|
|
|
|
|
|
# The only multi-token placeholder is a dollar placeholder. |
|
321
|
|
|
|
|
|
|
# if ( ( my $token_to_add = $placeholder_token ) =~ s[^\$][] ) { |
|
322
|
|
|
|
|
|
|
# $self->_add_to_current_statement($token_to_add) |
|
323
|
|
|
|
|
|
|
# } |
|
324
|
|
|
|
|
|
|
} |
|
325
|
|
|
|
|
|
|
else { |
|
326
|
23323
|
|
|
|
|
51500
|
$terminator_found = $self->_is_terminator($token); |
|
327
|
|
|
|
|
|
|
|
|
328
|
23323
|
100
|
100
|
|
|
58039
|
if ( |
|
|
|
|
66
|
|
|
|
|
|
329
|
|
|
|
|
|
|
$terminator_found && $terminator_found == SEMICOLON_TERMINATOR |
|
330
|
|
|
|
|
|
|
&& !$inside_brackets |
|
331
|
|
|
|
|
|
|
) { |
|
332
|
1811
|
100
|
100
|
|
|
5651
|
if ( $inside_sub && !$inside_is_as && !$inside_block ) { |
|
|
|
|
66
|
|
|
|
|
|
333
|
|
|
|
|
|
|
# Needed to close PL/SQL sub forward declarations such as: |
|
334
|
|
|
|
|
|
|
# PROCEDURE proc(number1 NUMBER); |
|
335
|
73
|
|
|
|
|
182
|
$inside_sub-- |
|
336
|
|
|
|
|
|
|
} |
|
337
|
|
|
|
|
|
|
|
|
338
|
1811
|
100
|
100
|
|
|
4719
|
if ( $inside_declare && $inside_cursor && !$inside_is_cursor ) { |
|
|
|
|
100
|
|
|
|
|
|
339
|
|
|
|
|
|
|
# Needed to close CURSOR decl. other than those in PL/SQL |
|
340
|
|
|
|
|
|
|
# inside a DECLARE; |
|
341
|
9
|
|
|
|
|
16
|
$inside_declare = 0 |
|
342
|
|
|
|
|
|
|
} |
|
343
|
|
|
|
|
|
|
|
|
344
|
1811
|
100
|
|
|
|
3764
|
$inside_crud = 0 if $inside_crud |
|
345
|
|
|
|
|
|
|
} |
|
346
|
|
|
|
|
|
|
} |
|
347
|
|
|
|
|
|
|
|
|
348
|
30410
|
100
|
66
|
|
|
111823
|
$prev_token = $token |
|
349
|
|
|
|
|
|
|
if $token =~ /\S/ && ! $self->_is_comment($token); |
|
350
|
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
# If we've just found a new custom DELIMITER definition, we certainly |
|
352
|
|
|
|
|
|
|
# have a new statement (and no terminator). |
|
353
|
30410
|
100
|
100
|
|
|
101368
|
unless ( |
|
|
|
|
100
|
|
|
|
|
|
354
|
|
|
|
|
|
|
$custom_delimiter_def_found |
|
355
|
|
|
|
|
|
|
|| $terminator_found && $terminator_found == CUSTOM_DELIMITER |
|
356
|
|
|
|
|
|
|
) { |
|
357
|
|
|
|
|
|
|
# Let's examine any condition that can make us remain in the |
|
358
|
|
|
|
|
|
|
# current statement. |
|
359
|
|
|
|
|
|
|
next if |
|
360
|
30337
|
50
|
100
|
|
|
115511
|
!$terminator_found || $dollar_quote || $inside_brackets |
|
|
|
|
66
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
361
|
|
|
|
|
|
|
|| $self->_custom_delimiter; |
|
362
|
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
next if |
|
364
|
1601
|
50
|
66
|
|
|
23062
|
$terminator_found |
|
|
|
|
66
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
365
|
|
|
|
|
|
|
&& $terminator_found == SEMICOLON_TERMINATOR |
|
366
|
|
|
|
|
|
|
&& ( |
|
367
|
|
|
|
|
|
|
$inside_block || $inside_sub |
|
368
|
|
|
|
|
|
|
|| $inside_declare || $inside_package || $inside_crud |
|
369
|
|
|
|
|
|
|
) && !$inside_grant_revoke && !$extra_end_found |
|
370
|
|
|
|
|
|
|
} |
|
371
|
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
# Whenever we get this far, we have a new statement. |
|
373
|
|
|
|
|
|
|
|
|
374
|
1001
|
|
|
|
|
18767
|
push @statements, $self->_current_statement; |
|
375
|
1001
|
|
|
|
|
5873
|
push @placeholders, $statement_placeholders; |
|
376
|
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
# If $terminator_found == CUSTOM_DELIMITER |
|
378
|
|
|
|
|
|
|
# @{ $self->_terminators } element has already been pushed, |
|
379
|
|
|
|
|
|
|
# so we have to set it only in the case tested below. |
|
380
|
1001
|
100
|
100
|
|
|
3461
|
push @{ $self->_terminators }, [ $terminator_found, undef ] |
|
|
928
|
|
|
|
|
17313
|
|
|
381
|
|
|
|
|
|
|
if ( |
|
382
|
|
|
|
|
|
|
$terminator_found == SEMICOLON_TERMINATOR |
|
383
|
|
|
|
|
|
|
|| $terminator_found == SLASH_TERMINATOR |
|
384
|
|
|
|
|
|
|
); |
|
385
|
|
|
|
|
|
|
|
|
386
|
1001
|
|
|
|
|
22666
|
$self->_current_statement(''); |
|
387
|
1001
|
|
|
|
|
6187
|
$statement_placeholders = 0; |
|
388
|
|
|
|
|
|
|
|
|
389
|
1001
|
|
|
|
|
1663
|
$prev_token = ''; |
|
390
|
1001
|
|
|
|
|
1677
|
$prev_keyword = ''; |
|
391
|
|
|
|
|
|
|
|
|
392
|
1001
|
|
|
|
|
1630
|
$inside_brackets = 0; |
|
393
|
1001
|
|
|
|
|
1686
|
$inside_block = 0; |
|
394
|
1001
|
|
|
|
|
1573
|
$inside_cursor = 0; |
|
395
|
1001
|
|
|
|
|
1461
|
$inside_is_cursor = 0; |
|
396
|
1001
|
|
|
|
|
1460
|
$inside_sub = 0; |
|
397
|
1001
|
|
|
|
|
1973
|
$inside_is_as = 0; |
|
398
|
1001
|
|
|
|
|
1506
|
$inside_declare = 0; |
|
399
|
1001
|
|
|
|
|
1397
|
$inside_package = 0; |
|
400
|
1001
|
|
|
|
|
1355
|
$inside_grant_revoke = 0; |
|
401
|
1001
|
|
|
|
|
1463
|
$inside_crud = 0; |
|
402
|
1001
|
|
|
|
|
1448
|
$extra_end_found = 0; |
|
403
|
1001
|
|
|
|
|
1676
|
@sub_names = (); |
|
404
|
|
|
|
|
|
|
|
|
405
|
1001
|
|
|
|
|
2196
|
$custom_delimiter_def_found = 0 |
|
406
|
|
|
|
|
|
|
} |
|
407
|
|
|
|
|
|
|
|
|
408
|
|
|
|
|
|
|
# Last statement. |
|
409
|
75
|
|
|
|
|
1678
|
chomp( my $last_statement = $self->_current_statement ); |
|
410
|
75
|
|
|
|
|
514
|
push @statements, $last_statement; |
|
411
|
75
|
|
|
|
|
150
|
push @{ $self->_terminators }, [undef, undef]; |
|
|
75
|
|
|
|
|
1337
|
|
|
412
|
75
|
|
|
|
|
513
|
push @placeholders, $statement_placeholders; |
|
413
|
|
|
|
|
|
|
|
|
414
|
75
|
|
|
|
|
380
|
my @filtered_statements; |
|
415
|
|
|
|
|
|
|
my @filtered_terminators; |
|
416
|
75
|
|
|
|
|
0
|
my @filtered_placeholders; |
|
417
|
|
|
|
|
|
|
|
|
418
|
75
|
100
|
|
|
|
1571
|
if ( $self->keep_empty_statements ) { |
|
419
|
37
|
|
|
|
|
589
|
@filtered_statements = @statements; |
|
420
|
37
|
|
|
|
|
124
|
@filtered_terminators = @{ $self->_terminators }; |
|
|
37
|
|
|
|
|
697
|
|
|
421
|
37
|
|
|
|
|
551
|
@filtered_placeholders = @placeholders |
|
422
|
|
|
|
|
|
|
} else { |
|
423
|
|
|
|
|
|
|
my $sp = each_array( |
|
424
|
38
|
|
|
|
|
369
|
@statements, @{ $self->_terminators }, @placeholders |
|
|
38
|
|
|
|
|
772
|
|
|
425
|
|
|
|
|
|
|
); |
|
426
|
38
|
|
|
|
|
1300
|
while ( my ($statement, $terminator, $placeholder_num) = $sp->() ) { |
|
427
|
557
|
100
|
100
|
|
|
6354
|
my $only_terminator_RE |
|
428
|
|
|
|
|
|
|
= $terminator->[0] && $terminator->[0] == CUSTOM_DELIMITER |
|
429
|
|
|
|
|
|
|
? qr/^\s*\Q$terminator->[1]\E?\s*$/ |
|
430
|
|
|
|
|
|
|
: qr/^\s*$terminator_RE?\z/; |
|
431
|
557
|
100
|
|
|
|
3663
|
unless ( $statement =~ $only_terminator_RE ) { |
|
432
|
528
|
|
|
|
|
1105
|
push @filtered_statements, $statement; |
|
433
|
528
|
|
|
|
|
768
|
push @filtered_terminators, $terminator; |
|
434
|
528
|
|
|
|
|
2779
|
push @filtered_placeholders, $placeholder_num |
|
435
|
|
|
|
|
|
|
} |
|
436
|
|
|
|
|
|
|
} |
|
437
|
|
|
|
|
|
|
} |
|
438
|
|
|
|
|
|
|
|
|
439
|
75
|
100
|
|
|
|
1793
|
unless ( $self->keep_terminators ) { |
|
440
|
41
|
|
|
|
|
469
|
for ( my $i = 0; $i < @filtered_statements; $i++ ) { |
|
441
|
544
|
|
|
|
|
1007
|
my $terminator = $filtered_terminators[$i]; |
|
442
|
544
|
100
|
|
|
|
1060
|
if ( $terminator->[0] ) { |
|
443
|
508
|
100
|
|
|
|
884
|
if ( $terminator->[0] == CUSTOM_DELIMITER ) { |
|
444
|
16
|
|
|
|
|
270
|
$filtered_statements[$i] =~ s/\Q$terminator->[1]\E$// |
|
445
|
|
|
|
|
|
|
} else { |
|
446
|
492
|
|
|
|
|
6097
|
$filtered_statements[$i] =~ s/$terminator_RE$// |
|
447
|
|
|
|
|
|
|
} |
|
448
|
|
|
|
|
|
|
} |
|
449
|
|
|
|
|
|
|
} |
|
450
|
|
|
|
|
|
|
} |
|
451
|
|
|
|
|
|
|
|
|
452
|
75
|
100
|
|
|
|
1858
|
unless ( $self->keep_extra_spaces ) { |
|
453
|
40
|
|
|
|
|
12105
|
s/^\s+|\s+$//g foreach @filtered_statements |
|
454
|
|
|
|
|
|
|
} |
|
455
|
|
|
|
|
|
|
|
|
456
|
75
|
|
|
|
|
811
|
return ( \@filtered_statements, \@filtered_placeholders ) |
|
457
|
|
|
|
|
|
|
} |
|
458
|
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
sub _add_to_current_statement { |
|
460
|
57489
|
|
|
57489
|
|
97484
|
my ($self, $token) = @_; |
|
461
|
57489
|
|
|
|
|
964537
|
$self->_current_statement( $self->_current_statement() . $token ) |
|
462
|
|
|
|
|
|
|
} |
|
463
|
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
sub _is_comment { |
|
465
|
116210
|
|
|
116210
|
|
222421
|
my ($self, $token) = @_; |
|
466
|
116210
|
|
|
|
|
533272
|
return $token =~ $begin_comment_RE |
|
467
|
|
|
|
|
|
|
} |
|
468
|
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
sub _is_BEGIN_of_block { |
|
470
|
26113
|
|
|
26113
|
|
57729
|
my ($self, $token, $prev_token) = @_; |
|
471
|
|
|
|
|
|
|
return |
|
472
|
26113
|
|
100
|
|
|
384687
|
$token =~ $BEGIN_RE |
|
473
|
|
|
|
|
|
|
&& $prev_token !~ $pre_identifier_RE |
|
474
|
|
|
|
|
|
|
&& $self->_peek_at_next_significant_token !~ $transaction_RE |
|
475
|
|
|
|
|
|
|
} |
|
476
|
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
sub _is_END_of_block { |
|
478
|
24311
|
|
|
24311
|
|
51583
|
my ($self, $token) = @_; |
|
479
|
24311
|
|
|
|
|
48368
|
my $next_token = $self->_peek_at_next_significant_token; |
|
480
|
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
# Return possible package name. |
|
482
|
24311
|
100
|
66
|
|
|
93846
|
if ( |
|
|
|
|
100
|
|
|
|
|
|
483
|
|
|
|
|
|
|
$token =~ $END_RE && ( |
|
484
|
|
|
|
|
|
|
!defined($next_token) |
|
485
|
|
|
|
|
|
|
|| $next_token !~ $procedural_END_RE |
|
486
|
|
|
|
|
|
|
) |
|
487
|
252
|
50
|
|
|
|
1038
|
) { return defined $next_token ? $next_token : '' } |
|
488
|
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
return |
|
490
|
24059
|
|
|
|
|
117293
|
} |
|
491
|
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
sub _dollar_placeholder_found { |
|
493
|
8372
|
|
|
8372
|
|
15462
|
my ($self, $token) = @_; |
|
494
|
|
|
|
|
|
|
|
|
495
|
8372
|
100
|
|
|
|
40857
|
return $token =~ $dollar_placeholder_RE ? $token : ''; |
|
496
|
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
# Needed by SQL::Tokenizer pre-0.21 |
|
498
|
|
|
|
|
|
|
# return '' if $token ne SINGLE_DOLLAR; |
|
499
|
|
|
|
|
|
|
# |
|
500
|
|
|
|
|
|
|
# # $token must be: '$' |
|
501
|
|
|
|
|
|
|
# my $tokens = $self->_tokens; |
|
502
|
|
|
|
|
|
|
# |
|
503
|
|
|
|
|
|
|
# return $tokens->[0] =~ /^\d+$/ && $tokens->[1] !~ /^\$/ |
|
504
|
|
|
|
|
|
|
# ? $token . shift( @$tokens ) : '' |
|
505
|
|
|
|
|
|
|
} |
|
506
|
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
sub _named_placeholder_found { |
|
508
|
8381
|
|
|
8381
|
|
15171
|
my ($self, $token) = @_; |
|
509
|
|
|
|
|
|
|
|
|
510
|
8381
|
100
|
|
|
|
32720
|
return $token =~ /^:(?:\d+|[_a-z][_a-z\d]*)$/ ? $token : '' |
|
511
|
|
|
|
|
|
|
} |
|
512
|
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
sub _questionmark_placeholder_found { |
|
514
|
8404
|
|
|
8404
|
|
17680
|
my ($self, $token) = @_; |
|
515
|
|
|
|
|
|
|
|
|
516
|
8404
|
100
|
|
|
|
29129
|
return $token eq QUESTION_MARK ? $token : '' |
|
517
|
|
|
|
|
|
|
} |
|
518
|
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
sub _dollar_quote_open_found { |
|
520
|
335
|
|
|
335
|
|
906
|
my ($self, $token) = @_; |
|
521
|
|
|
|
|
|
|
|
|
522
|
335
|
100
|
|
|
|
2489
|
return '' if $token !~ /^\$/; |
|
523
|
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
# Includes the DOUBLE_DOLLAR case |
|
525
|
40
|
100
|
|
|
|
577
|
return $token if $token =~ /^\$$inner_identifier_RE?\$$/; |
|
526
|
|
|
|
|
|
|
# Used with SQL::Tokenizer pre-0.21 |
|
527
|
|
|
|
|
|
|
# return $token if $token eq DOUBLE_DOLLAR; |
|
528
|
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
# $token must be: '$' or '$1', '$2' etc. |
|
530
|
4
|
50
|
|
|
|
82
|
return '' if $token =~ $dollar_placeholder_RE; |
|
531
|
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
# $token must be: '$' |
|
533
|
4
|
|
|
|
|
84
|
my $tokens = $self->_tokens; |
|
534
|
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
# False alarm! |
|
536
|
4
|
50
|
|
|
|
34
|
return '' if $tokens->[1] !~ /^\$/; |
|
537
|
|
|
|
|
|
|
|
|
538
|
4
|
50
|
33
|
|
|
112
|
return $token . shift( @$tokens ) . shift( @$tokens ) |
|
539
|
|
|
|
|
|
|
if $tokens->[0] =~ /^$inner_identifier_RE$/ |
|
540
|
|
|
|
|
|
|
&& $tokens->[1] eq SINGLE_DOLLAR; |
|
541
|
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
# $tokens->[1] must match: /$.+/ |
|
543
|
0
|
|
|
|
|
0
|
my $quote = $token . shift( @$tokens ) . '$'; |
|
544
|
0
|
|
|
|
|
0
|
$tokens->[0] = substr $tokens->[0], 1; |
|
545
|
0
|
|
|
|
|
0
|
return $quote |
|
546
|
|
|
|
|
|
|
} |
|
547
|
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
sub _dollar_quote_close_found { |
|
549
|
2423
|
|
|
2423
|
|
4628
|
my ($self, $token, $dollar_quote) = @_; |
|
550
|
|
|
|
|
|
|
|
|
551
|
2423
|
100
|
|
|
|
6877
|
return if $token !~ /^\$/; |
|
552
|
96
|
100
|
|
|
|
270
|
return 1 if $token eq $dollar_quote; # $token matches /$.*$/ |
|
553
|
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
# $token must be: '$' or '$1', '$2' etc. |
|
555
|
60
|
100
|
|
|
|
436
|
return if $token =~ $dollar_placeholder_RE; |
|
556
|
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
# $token must be: '$' |
|
558
|
4
|
|
|
|
|
71
|
my $tokens = $self->_tokens; |
|
559
|
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
# False alarm! |
|
561
|
4
|
50
|
|
|
|
32
|
return if $tokens->[1] !~ /^\$/; |
|
562
|
|
|
|
|
|
|
|
|
563
|
4
|
50
|
|
|
|
19
|
if ( $dollar_quote eq $token . $tokens->[0] . $tokens->[1] ) { |
|
564
|
4
|
|
|
|
|
7
|
shift( @$tokens ); shift( @$tokens ); |
|
|
4
|
|
|
|
|
9
|
|
|
565
|
4
|
|
|
|
|
13
|
return 1 |
|
566
|
|
|
|
|
|
|
} |
|
567
|
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
# $tokens->[1] must match: /$.+/ |
|
569
|
0
|
0
|
|
|
|
0
|
if ( $dollar_quote eq $token . $tokens->[0] . '$' ) { |
|
570
|
0
|
|
|
|
|
0
|
shift( @$tokens ); |
|
571
|
0
|
|
|
|
|
0
|
$tokens->[0] = substr $tokens->[0], 1; |
|
572
|
0
|
|
|
|
|
0
|
return 1 |
|
573
|
|
|
|
|
|
|
} |
|
574
|
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
return |
|
576
|
0
|
|
|
|
|
0
|
} |
|
577
|
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
sub _peek_at_package_name { |
|
579
|
|
|
|
|
|
|
shift->_peek_at_next_significant_token( |
|
580
|
39
|
|
|
39
|
|
686
|
qr/$OR_REPLACE_PACKAGE_RE|$BODY_RE/ |
|
581
|
|
|
|
|
|
|
) |
|
582
|
|
|
|
|
|
|
} |
|
583
|
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
sub _custom_delimiter_def_found { |
|
585
|
41
|
|
|
41
|
|
75
|
my $self = shift; |
|
586
|
|
|
|
|
|
|
|
|
587
|
41
|
|
|
|
|
761
|
my $tokens = $self->_tokens; |
|
588
|
|
|
|
|
|
|
|
|
589
|
41
|
|
|
|
|
242
|
my $base_index = 0; |
|
590
|
41
|
|
|
|
|
311
|
$base_index++ while $tokens->[$base_index] =~ /^\s$/; |
|
591
|
|
|
|
|
|
|
|
|
592
|
41
|
|
|
|
|
99
|
my $first_token_in_delimiter = $tokens->[$base_index]; |
|
593
|
41
|
|
|
|
|
77
|
my $delimiter = ''; |
|
594
|
41
|
|
|
|
|
103
|
my $tokens_in_delimiter; |
|
595
|
|
|
|
|
|
|
my $tokens_to_shift; |
|
596
|
|
|
|
|
|
|
|
|
597
|
41
|
100
|
|
|
|
593
|
if ( $first_token_in_delimiter =~ $quoted_RE ) { |
|
598
|
|
|
|
|
|
|
# Quoted custom delimiter: it's just a single token (to shift)... |
|
599
|
1
|
|
|
|
|
133
|
$tokens_to_shift = $base_index + 1; |
|
600
|
|
|
|
|
|
|
# ... However it can be composed by several tokens |
|
601
|
|
|
|
|
|
|
# (according to SQL::Tokenizer), once removed the quotes. |
|
602
|
1
|
|
|
|
|
3
|
$delimiter = substr $first_token_in_delimiter, 1, -1; |
|
603
|
1
|
|
|
|
|
4
|
$tokens_in_delimiter =()= tokenize_sql($delimiter) |
|
604
|
|
|
|
|
|
|
} else { |
|
605
|
|
|
|
|
|
|
# Gather an unquoted custom delimiter, which could be composed |
|
606
|
|
|
|
|
|
|
# by several tokens (that's the SQL::Tokenizer behaviour). |
|
607
|
40
|
|
|
|
|
6833
|
foreach ( $base_index .. $#{ $tokens } ) { |
|
|
40
|
|
|
|
|
166
|
|
|
608
|
99
|
100
|
|
|
|
368
|
last if $tokens->[$_] =~ /^\s+$/; |
|
609
|
59
|
|
|
|
|
115
|
$delimiter .= $tokens->[$_]; |
|
610
|
59
|
|
|
|
|
141
|
$tokens_in_delimiter++ |
|
611
|
|
|
|
|
|
|
} |
|
612
|
40
|
|
|
|
|
105
|
$tokens_to_shift = $base_index + $tokens_in_delimiter |
|
613
|
|
|
|
|
|
|
} |
|
614
|
|
|
|
|
|
|
|
|
615
|
41
|
|
|
|
|
1139
|
$self->_custom_delimiter($delimiter); |
|
616
|
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
# We've just found a custom delimiter definition, |
|
618
|
|
|
|
|
|
|
# which means that this statement has no (additional) terminator, |
|
619
|
|
|
|
|
|
|
# therefore we won't have to delete anything. |
|
620
|
41
|
|
|
|
|
304
|
push @{ $self->_terminators }, [undef, undef]; |
|
|
41
|
|
|
|
|
720
|
|
|
621
|
|
|
|
|
|
|
|
|
622
|
41
|
|
|
|
|
910
|
$self->_tokens_in_custom_delimiter($tokens_in_delimiter); |
|
623
|
|
|
|
|
|
|
|
|
624
|
41
|
|
|
|
|
301
|
return $tokens_to_shift |
|
625
|
|
|
|
|
|
|
} |
|
626
|
|
|
|
|
|
|
|
|
627
|
|
|
|
|
|
|
sub _is_custom_delimiter { |
|
628
|
1439
|
|
|
1439
|
|
2541
|
my ($self, $token) = @_; |
|
629
|
|
|
|
|
|
|
|
|
630
|
1439
|
|
|
|
|
24200
|
my $tokens = $self->_tokens; |
|
631
|
|
|
|
|
|
|
my @delimiter_tokens |
|
632
|
1439
|
|
|
|
|
6195
|
= splice @{$tokens}, 0, $self->_tokens_in_custom_delimiter() - 1; |
|
|
1439
|
|
|
|
|
24749
|
|
|
633
|
1439
|
|
|
|
|
8002
|
my $lookahead_delimiter = join '', @delimiter_tokens; |
|
634
|
1439
|
100
|
|
|
|
24617
|
if ( $self->_custom_delimiter eq $token . $lookahead_delimiter ) { |
|
635
|
32
|
|
|
|
|
214
|
$self->_add_to_current_statement($lookahead_delimiter); |
|
636
|
32
|
|
|
|
|
298
|
push @{ $self->_terminators }, |
|
|
32
|
|
|
|
|
574
|
|
|
637
|
|
|
|
|
|
|
[ CUSTOM_DELIMITER, $self->_custom_delimiter ]; |
|
638
|
32
|
|
|
|
|
815
|
return 1 |
|
639
|
|
|
|
|
|
|
} else { |
|
640
|
1407
|
|
|
|
|
7512
|
unshift @{$tokens}, @delimiter_tokens; |
|
|
1407
|
|
|
|
|
3025
|
|
|
641
|
|
|
|
|
|
|
return |
|
642
|
1407
|
|
|
|
|
3984
|
} |
|
643
|
|
|
|
|
|
|
} |
|
644
|
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
sub _is_terminator { |
|
646
|
23323
|
|
|
23323
|
|
43037
|
my ($self, $token) = @_; |
|
647
|
|
|
|
|
|
|
|
|
648
|
|
|
|
|
|
|
# This is the first test to perform! |
|
649
|
23323
|
100
|
|
|
|
457300
|
if ( $self->_custom_delimiter ) { |
|
650
|
|
|
|
|
|
|
# If a custom delimiter is currently defined, |
|
651
|
|
|
|
|
|
|
# no other token can terminate a statement. |
|
652
|
1439
|
100
|
|
|
|
8599
|
return CUSTOM_DELIMITER if $self->_is_custom_delimiter($token); |
|
653
|
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
return |
|
655
|
1407
|
|
|
|
|
2742
|
} |
|
656
|
|
|
|
|
|
|
|
|
657
|
21884
|
100
|
100
|
|
|
161107
|
return if $token ne FORWARD_SLASH && $token ne SEMICOLON; |
|
658
|
|
|
|
|
|
|
|
|
659
|
1967
|
|
|
|
|
34106
|
my $tokens = $self->_tokens; |
|
660
|
|
|
|
|
|
|
|
|
661
|
1967
|
100
|
|
|
|
10706
|
if ( $token eq FORWARD_SLASH ) { |
|
662
|
|
|
|
|
|
|
# Remove the trailing FORWARD_SLASH from the current statement |
|
663
|
125
|
|
|
|
|
2246
|
chop( my $current_statement = $self->_current_statement ); |
|
664
|
|
|
|
|
|
|
|
|
665
|
125
|
|
|
|
|
812
|
my $next_token = $tokens->[0]; |
|
666
|
125
|
|
|
|
|
285
|
my $next_next_token = $tokens->[1]; |
|
667
|
|
|
|
|
|
|
|
|
668
|
125
|
100
|
66
|
|
|
862
|
if ( |
|
|
|
|
33
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
669
|
|
|
|
|
|
|
!defined($next_token) |
|
670
|
|
|
|
|
|
|
|| $next_token eq NEWLINE |
|
671
|
|
|
|
|
|
|
|| $next_token =~ /^\s+$/ && $next_next_token eq NEWLINE |
|
672
|
|
|
|
|
|
|
) { |
|
673
|
97
|
100
|
100
|
|
|
879
|
return SLASH_TERMINATOR |
|
674
|
|
|
|
|
|
|
if $current_statement =~ /;\s*\n\s*\z/ |
|
675
|
|
|
|
|
|
|
|| $current_statement =~ /\n\s*\.\s*\n\s*\z/; |
|
676
|
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
# Slash with no preceding semicolon or period: |
|
678
|
|
|
|
|
|
|
# this is to be treated as a semicolon terminator... |
|
679
|
39
|
|
|
|
|
171
|
my $next_significant_token_idx |
|
680
|
|
|
|
|
|
|
= $self->_next_significant_token_idx; |
|
681
|
|
|
|
|
|
|
# ... provided that it's not a division operator |
|
682
|
|
|
|
|
|
|
# (at least not a blatant one ;-) |
|
683
|
39
|
100
|
66
|
|
|
870
|
return SEMICOLON_TERMINATOR |
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
684
|
|
|
|
|
|
|
if $self->slash_terminates |
|
685
|
|
|
|
|
|
|
&& $current_statement =~ /\n\s*\z/ |
|
686
|
|
|
|
|
|
|
&& ( |
|
687
|
|
|
|
|
|
|
$next_significant_token_idx == -1 |
|
688
|
|
|
|
|
|
|
|| |
|
689
|
|
|
|
|
|
|
$tokens->[$next_significant_token_idx] ne OPEN_BRACKET |
|
690
|
|
|
|
|
|
|
&& $tokens->[$next_significant_token_idx] !~ /^\d/ |
|
691
|
|
|
|
|
|
|
&& !( |
|
692
|
|
|
|
|
|
|
$tokens->[$next_significant_token_idx] eq DOT |
|
693
|
|
|
|
|
|
|
&& $tokens->[$next_significant_token_idx + 1] =~ /^\d/ |
|
694
|
|
|
|
|
|
|
) |
|
695
|
|
|
|
|
|
|
) |
|
696
|
|
|
|
|
|
|
} |
|
697
|
|
|
|
|
|
|
|
|
698
|
|
|
|
|
|
|
return |
|
699
|
40
|
|
|
|
|
322
|
} |
|
700
|
|
|
|
|
|
|
|
|
701
|
|
|
|
|
|
|
# $token eq SEMICOLON. |
|
702
|
|
|
|
|
|
|
|
|
703
|
1842
|
|
|
|
|
3294
|
my $next_code_portion = ''; |
|
704
|
1842
|
|
|
|
|
2753
|
my $i = 0; |
|
705
|
1842
|
|
100
|
|
|
32141
|
$next_code_portion .= $tokens->[$i++] |
|
706
|
|
|
|
|
|
|
while $i <= 8 && defined $tokens->[$i]; |
|
707
|
|
|
|
|
|
|
|
|
708
|
1842
|
100
|
66
|
|
|
16709
|
return SEMICOLON_TERMINATOR |
|
|
|
|
100
|
|
|
|
|
|
709
|
|
|
|
|
|
|
if $token eq SEMICOLON |
|
710
|
|
|
|
|
|
|
&& $next_code_portion !~ m#\A\s*\n\s*/\s*$#m |
|
711
|
|
|
|
|
|
|
&& $next_code_portion !~ m#\A\s*\n\s*\.\s*\n\s*/\s*$#m; |
|
712
|
|
|
|
|
|
|
|
|
713
|
|
|
|
|
|
|
# there is a FORWARD_SLASH next: let's wait for it to terminate. |
|
714
|
|
|
|
|
|
|
return |
|
715
|
58
|
|
|
|
|
170
|
} |
|
716
|
|
|
|
|
|
|
|
|
717
|
|
|
|
|
|
|
sub _peek_at_next_significant_token { |
|
718
|
25526
|
|
|
25526
|
|
42400
|
my ($self, $skiptoken_RE) = @_; |
|
719
|
|
|
|
|
|
|
|
|
720
|
25526
|
|
|
|
|
461186
|
my $tokens = $self->_tokens; |
|
721
|
|
|
|
|
|
|
my $next_significant_token = $skiptoken_RE |
|
722
|
|
|
|
|
|
|
? firstval { |
|
723
|
1851
|
100
|
100
|
1851
|
|
7199
|
/\S/ && ! $self->_is_comment($_) && ! /$skiptoken_RE/ |
|
724
|
755
|
|
|
|
|
12323
|
} @{ $tokens } |
|
725
|
|
|
|
|
|
|
: firstval { |
|
726
|
52418
|
100
|
|
52418
|
|
174099
|
/\S/ && ! $self->_is_comment($_) |
|
727
|
25526
|
100
|
|
|
|
176266
|
} @{ $tokens }; |
|
|
24771
|
|
|
|
|
304949
|
|
|
728
|
|
|
|
|
|
|
|
|
729
|
25526
|
100
|
|
|
|
107778
|
return $next_significant_token if defined $next_significant_token; |
|
730
|
71
|
|
|
|
|
241
|
return '' |
|
731
|
|
|
|
|
|
|
} |
|
732
|
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
sub _next_significant_token_idx { |
|
734
|
39
|
|
|
39
|
|
84
|
my ($self, $skiptoken_RE) = @_; |
|
735
|
|
|
|
|
|
|
|
|
736
|
39
|
|
|
|
|
716
|
my $tokens = $self->_tokens; |
|
737
|
|
|
|
|
|
|
return $skiptoken_RE |
|
738
|
|
|
|
|
|
|
? firstidx { |
|
739
|
0
|
0
|
0
|
0
|
|
0
|
/\S/ && ! $self->_is_comment($_) && ! /$skiptoken_RE/ |
|
740
|
0
|
|
|
|
|
0
|
} @{ $tokens } |
|
741
|
|
|
|
|
|
|
: firstidx { |
|
742
|
108
|
100
|
|
108
|
|
380
|
/\S/ && ! $self->_is_comment($_) |
|
743
|
39
|
50
|
|
|
|
303
|
} @{ $tokens } |
|
|
39
|
|
|
|
|
245
|
|
|
744
|
|
|
|
|
|
|
} |
|
745
|
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
1; |
|
747
|
|
|
|
|
|
|
|
|
748
|
|
|
|
|
|
|
__END__ |