| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package TSQL::SplitStatement; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 2 |  |  | 2 |  | 75882 | use 5.010; | 
|  | 2 |  |  |  |  | 7 |  | 
|  | 2 |  |  |  |  | 72 |  | 
| 4 | 2 |  |  | 2 |  | 11 | use strict; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 59 |  | 
| 5 | 2 |  |  | 2 |  | 11 | use warnings; | 
|  | 2 |  |  |  |  | 18 |  | 
|  | 2 |  |  |  |  | 63 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 2 |  |  | 2 |  | 1663 | use English ; | 
|  | 2 |  |  |  |  | 8539 |  | 
|  | 2 |  |  |  |  | 13 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 2 |  |  | 2 |  | 1185 | use List::Util      qw(first max maxstr min minstr reduce shuffle sum); | 
|  | 2 |  |  |  |  | 6 |  | 
|  | 2 |  |  |  |  | 293 |  | 
| 10 | 2 |  |  | 2 |  | 46055 | use List::MoreUtils qw(indexes all any); | 
|  | 2 |  |  |  |  | 36671 |  | 
|  | 2 |  |  |  |  | 244 |  | 
| 11 |  |  |  |  |  |  | #use Data::Dumper; | 
| 12 |  |  |  |  |  |  | #use Data::Dump 'pp'; | 
| 13 | 2 |  |  | 2 |  | 3116 | use autodie qw(:all); | 
|  | 2 |  |  |  |  | 46756 |  | 
|  | 2 |  |  |  |  | 13 |  | 
| 14 | 2 |  |  | 2 |  | 54291 | use Clone; | 
|  | 2 |  |  |  |  | 19131 |  | 
|  | 2 |  |  |  |  | 133 |  | 
| 15 | 2 |  |  | 2 |  | 20 | use base qw(Clone) ; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 244 |  | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 2 |  |  | 2 |  | 2244 | use TSQL::Common::Regexp; | 
|  | 2 |  |  |  |  | 1124 |  | 
|  | 2 |  |  |  |  | 3100 |  | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | ## TODO :- 1 stop this warning Variable "$NestedBracketsRE" will not stay shared at (re_eval 215) line 2. | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | =head1 NAME | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | TSQL::SplitStatement - Implements similar functionality to SQL::SplitStatement, but for TSQL. | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | =head1 VERSION | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | Version 0.15 | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | =cut | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | our $VERSION = '0.15'; | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | # -- ********************************************************** | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | sub new { | 
| 38 | 1 |  |  | 1 | 1 | 985 | local $_             = undef ; | 
| 39 | 1 |  |  |  |  | 2 | my $invocant         = shift ; | 
| 40 | 1 |  | 33 |  |  | 8 | my $class            = ref($invocant) || $invocant ; | 
| 41 | 1 |  |  |  |  | 4 | my $self             = bless {}, $class ; | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 1 |  |  |  |  | 3 | return $self ; | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | sub splitSQL { | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 1 |  |  | 1 | 1 | 7 | local $_             = undef ; | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 1 |  |  |  |  | 2 | my $invocant         = shift ; | 
| 52 | 1 |  | 33 |  |  | 4 | my $class            = ref($invocant) || $invocant ; | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 1 |  |  |  |  | 2 | my $input            = shift ; | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 1 |  |  |  |  | 3 | my $CommentIndex            = -1 ; | 
| 59 |  |  |  |  |  |  |  | 
| 60 | 1 |  |  |  |  | 2 | my $QIndex                  = -1 ; | 
| 61 | 1 |  |  |  |  | 3 | my $SIndex                  = -1 ; | 
| 62 | 1 |  |  |  |  | 3 | my $UnionIndex              = -1 ; | 
| 63 | 1 |  |  |  |  | 2 | my $SubqueryIndex           = -1 ; | 
| 64 | 1 |  |  |  |  | 2 | my $BracketsIndex           = -1 ; | 
| 65 | 1 |  |  |  |  | 2 | my $CaseEndIndex            = -1 ; | 
| 66 | 1 |  |  |  |  | 2 | my $InsertsIndex            = -1 ; | 
| 67 | 1 |  |  |  |  | 1 | my $UpdatesIndex            = -1 ; | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 1 |  |  |  |  | 2 | my $GrantOptionsIndex       = -1 ; | 
| 70 | 1 |  |  |  |  | 1 | my $GrantsIndex             = -1 ; | 
| 71 | 1 |  |  |  |  | 26 | my $DenysIndex              = -1 ; | 
| 72 | 1 |  |  |  |  | 2 | my $RevokesIndex            = -1 ; | 
| 73 |  |  |  |  |  |  |  | 
| 74 | 1 |  |  |  |  | 1 | my $CursorSelectsIndex      = -1 ; | 
| 75 | 1 |  |  |  |  | 2 | my $CursorForUpdatesIndex   = -1 ; | 
| 76 |  |  |  |  |  |  |  | 
| 77 | 1 |  |  |  |  | 1 | my $TerminatorIndex         = -1 ; | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  |  | 
| 80 | 1 |  |  |  |  | 2 | my $CommentRepl           = '____COMMENT_'; | 
| 81 |  |  |  |  |  |  |  | 
| 82 | 1 |  |  |  |  | 1 | my $QRepl                 = '____QUOTEDID_'; | 
| 83 | 1 |  |  |  |  | 2 | my $SRepl                 = '____STRING_'; | 
| 84 | 1 |  |  |  |  | 1 | my $UnionRepl             = '____UNION_'; | 
| 85 | 1 |  |  |  |  | 3 | my $SubqueryRepl          = '____SUBQUERY_'; | 
| 86 | 1 |  |  |  |  | 1 | my $BracketsRepl          = '____BRACKETS_'; | 
| 87 | 1 |  |  |  |  | 1 | my $CaseEndRepl           = '____CASE_END_'; | 
| 88 | 1 |  |  |  |  | 1 | my $InsertsRepl           = '____INSERTS_SELECT_'; | 
| 89 | 1 |  |  |  |  | 2 | my $UpdatesRepl           = '____UPDATES_SET_'; | 
| 90 |  |  |  |  |  |  |  | 
| 91 | 1 |  |  |  |  | 1 | my $GrantOptionsRepl      = '____GRANT_OPTION_'; | 
| 92 | 1 |  |  |  |  | 2 | my $GrantsRepl            = '____GRANT_SET_'; | 
| 93 | 1 |  |  |  |  | 2 | my $DenysRepl             = '____DENY_SET_'; | 
| 94 | 1 |  |  |  |  | 1 | my $RevokesRepl           = '____REVOKE_SET_'; | 
| 95 |  |  |  |  |  |  |  | 
| 96 | 1 |  |  |  |  | 2 | my $CursorSelectsRepl     = '____CURSOR_FOR_SELECT_'; | 
| 97 | 1 |  |  |  |  | 2 | my $CursorForUpdatesRepl  = '____CURSOR_FOR_UPDATES_'; | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  |  | 
| 100 | 1 |  |  |  |  | 2 | my $TerminatorRepl        = '____SEPARATOR_TOKEN_'; | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  |  | 
| 103 | 1 |  |  |  |  | 1 | my @Comment_positions     = (); | 
| 104 | 1 |  |  |  |  | 2 | my @Comment_replaces      = (); | 
| 105 |  |  |  |  |  |  |  | 
| 106 | 1 |  |  |  |  | 3 | my @Q_replaces            = (); | 
| 107 | 1 |  |  |  |  | 2 | my @S_replaces            = (); | 
| 108 | 1 |  |  |  |  | 2 | my @Union_replaces        = (); | 
| 109 | 1 |  |  |  |  | 1 | my @Subquery_replaces     = (); | 
| 110 | 1 |  |  |  |  | 8 | my @Brackets_replaces     = (); | 
| 111 | 1 |  |  |  |  | 7 | my @CaseEnd_replaces      = (); | 
| 112 | 1 |  |  |  |  | 3 | my @Inserts_replaces      = (); | 
| 113 | 1 |  |  |  |  | 1 | my @Updates_replaces      = (); | 
| 114 |  |  |  |  |  |  |  | 
| 115 | 1 |  |  |  |  | 2 | my @GrantOptions_replaces = (); | 
| 116 | 1 |  |  |  |  | 2 | my @Grants_replaces       = (); | 
| 117 | 1 |  |  |  |  | 2 | my @Denys_replaces        = (); | 
| 118 | 1 |  |  |  |  | 2 | my @Revokes_replaces      = (); | 
| 119 |  |  |  |  |  |  |  | 
| 120 | 1 |  |  |  |  | 2 | my @CursorSelects_replaces      = (); | 
| 121 | 1 |  |  |  |  | 2 | my @CursorForUpdates_replaces   = (); | 
| 122 | 1 |  |  |  |  | 1 | my @Terminator_replaces         = (); | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | #my $qr_Id = qr{[#_\w$@][#$:_.\w]*}x ; | 
| 127 | 1 |  |  |  |  | 9 | my $qr_Id = TSQL::Common::Regexp->qr_id(); | 
| 128 |  |  |  |  |  |  |  | 
| 129 | 1 |  |  |  |  | 4 | my $s = $input ; | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | # replace comments only ............. | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | ## Beware this is a valid name [abc[]]def] | 
| 134 |  |  |  |  |  |  |  | 
| 135 | 1 |  |  |  |  | 15 | $s =~ s!(? [N]?'(?:(?:[^']) | (?:''))*' ) | 
| 136 |  |  |  |  |  |  | | | 
| 137 |  |  |  |  |  |  | (?"(?:(?:[^"])     | (?:""))*" ) | 
| 138 |  |  |  |  |  |  | | | 
| 139 |  |  |  |  |  |  | (?\[  .*? \]  ) | 
| 140 |  |  |  |  |  |  | | | 
| 141 |  |  |  |  |  |  | (?(?:(?:--.*?$) | 
| 142 |  |  |  |  |  |  | | | 
| 143 |  |  |  |  |  |  | (?:/[*].*?[*]/)\s*)+ | 
| 144 |  |  |  |  |  |  | ) | 
| 145 | 3 | 50 |  |  |  | 51 | ! if (defined($+{string})) {"$+{string}"} elsif (defined($+{doublequoted})) {"$+{doublequoted}"} elsif (defined($+{bracketquoted})) {"$+{bracketquoted}"}   elsif (defined($+{comment})) {${CommentIndex}++; $Comment_replaces[${CommentIndex}] = $+{comment} ; " ${CommentRepl}${CommentIndex} "} else {'z'} | 
|  | 0 | 50 |  |  |  | 0 |  | 
|  | 0 | 50 |  |  |  | 0 |  | 
|  | 0 | 50 |  |  |  | 0 |  | 
|  | 3 |  |  |  |  | 4 |  | 
|  | 3 |  |  |  |  | 13 |  | 
|  | 3 |  |  |  |  | 210 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 146 |  |  |  |  |  |  | !xigems ; | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | #print $s ; | 
| 149 |  |  |  |  |  |  | #exit; | 
| 150 |  |  |  |  |  |  | # ' | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  |  | 
| 153 | 1 |  |  |  |  | 6 | $CommentIndex         = -1 ; | 
| 154 | 1 |  |  |  |  | 2 | $QIndex               = -1 ; | 
| 155 | 1 |  |  |  |  | 2 | $SIndex               = -1 ; | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | # replace everything else .............. | 
| 158 |  |  |  |  |  |  | #' | 
| 159 |  |  |  |  |  |  | # hack around broken ? ^PREMATCH handling in 5.17 | 
| 160 |  |  |  |  |  |  | # and fixed $` handling | 
| 161 | 1 | 50 |  |  |  | 20 | if ( $PERL_VERSION >= v5.17.0 ) { | 
| 162 | 1 |  |  |  |  | 6 | $s =~ s!(?(?p) [N]?'(?:(?:[^']) | (?:''))*' ) | 
| 163 |  |  |  |  |  |  | | | 
| 164 |  |  |  |  |  |  | (?"(?:(?:[^"])     | (?:""))*" ) | 
| 165 |  |  |  |  |  |  | | | 
| 166 |  |  |  |  |  |  | (?\[  .*? \]  ) | 
| 167 |  |  |  |  |  |  | | | 
| 168 |  |  |  |  |  |  | (? \s____COMMENT_(?:\d)+\s | 
| 169 |  |  |  |  |  |  | ) | 
| 170 | 3 | 50 |  |  |  | 46 | ! if (defined($+{string})) {${SIndex}++; $S_replaces[${SIndex}] = $+{string} ; " ${SRepl}${SIndex} "} elsif (defined($+{doublequoted})) {${QIndex}++; $Q_replaces[${QIndex}] = $+{doublequoted}; " ${QRepl}${QIndex} "} elsif (defined($+{bracketquoted})) {${QIndex}++; $Q_replaces[${QIndex}] = $+{bracketquoted}; " ${QRepl}${QIndex} "}  elsif (defined($+{comment})) {$CommentIndex++; $Comment_positions[$CommentIndex]=length($`); ' ';} else {'z'} | 
|  | 0 | 50 |  |  |  | 0 |  | 
|  | 0 | 50 |  |  |  | 0 |  | 
|  | 0 | 50 |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 3 |  |  |  |  | 3 |  | 
|  | 3 |  |  |  |  | 10 |  | 
|  | 3 |  |  |  |  | 139 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 171 |  |  |  |  |  |  | !xigems ; | 
| 172 |  |  |  |  |  |  | } | 
| 173 |  |  |  |  |  |  | else { | 
| 174 | 0 |  |  |  |  | 0 | $s =~ s!(?(?p) [N]?'(?:(?:[^']) | (?:''))*' ) | 
| 175 |  |  |  |  |  |  | | | 
| 176 |  |  |  |  |  |  | (?"(?:(?:[^"])     | (?:""))*" ) | 
| 177 |  |  |  |  |  |  | | | 
| 178 |  |  |  |  |  |  | (?\[  .*? \]  ) | 
| 179 |  |  |  |  |  |  | | | 
| 180 |  |  |  |  |  |  | (? \s____COMMENT_(?:\d)+\s | 
| 181 |  |  |  |  |  |  | ) | 
| 182 | 0 | 0 |  |  |  | 0 | ! if (defined($+{string})) {${SIndex}++; $S_replaces[${SIndex}] = $+{string} ; " ${SRepl}${SIndex} "} elsif (defined($+{doublequoted})) {${QIndex}++; $Q_replaces[${QIndex}] = $+{doublequoted}; " ${QRepl}${QIndex} "} elsif (defined($+{bracketquoted})) {${QIndex}++; $Q_replaces[${QIndex}] = $+{bracketquoted}; " ${QRepl}${QIndex} "}  elsif (defined($+{comment})) {$CommentIndex++; $Comment_positions[$CommentIndex]=length(${^PREMATCH}); ' ';} else {'z'} | 
|  | 0 | 0 |  |  |  | 0 |  | 
|  | 0 | 0 |  |  |  | 0 |  | 
|  | 0 | 0 |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 183 |  |  |  |  |  |  | !xigems ; | 
| 184 |  |  |  |  |  |  | } | 
| 185 |  |  |  |  |  |  |  | 
| 186 |  |  |  |  |  |  | # ! if (defined($1)) {${SIndex}++; $S_replaces[${SIndex}] = $1 ; " ${SRepl}${SIndex} "} elsif (defined($2)) {${QIndex}++; $Q_replaces[${QIndex}] = $2; " ${QRepl}${QIndex} "} elsif (defined($3)) {${QIndex}++; $Q_replaces[${QIndex}] = $3; " ${QRepl}${QIndex} "}  elsif (defined($4)) {$CommentIndex++; $Comment_positions[$CommentIndex]=length(${^PREMATCH}); ' ';} else {'z'} | 
| 187 |  |  |  |  |  |  | # ' | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  | #$s =~ s!([N]?'(?:(?:[^'])|(?:''))*') | 
| 190 |  |  |  |  |  |  | # ! if (defined($1)) {'a'} else {'z'} | 
| 191 |  |  |  |  |  |  | # !xgei ; | 
| 192 |  |  |  |  |  |  |  | 
| 193 |  |  |  |  |  |  | #pp @Comment_replaces ; | 
| 194 |  |  |  |  |  |  |  | 
| 195 |  |  |  |  |  |  | #print $s ; | 
| 196 |  |  |  |  |  |  | #exit; | 
| 197 |  |  |  |  |  |  |  | 
| 198 |  |  |  |  |  |  |  | 
| 199 | 1 |  |  |  |  | 37 | $s =~ s!(\b(?:union|intersect|minus)(?:\s+all)?\s+select\b) | 
| 200 | 1 |  |  |  |  | 2 | ! ${UnionIndex}++; $Union_replaces[${UnionIndex}] = $1 ; " ${UnionRepl}${UnionIndex} "; | 
|  | 1 |  |  |  |  | 5 |  | 
|  | 1 |  |  |  |  | 17 |  | 
| 201 |  |  |  |  |  |  | !xigems ; | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | #warn Dumper @Union_replaces ; | 
| 204 |  |  |  |  |  |  |  | 
| 205 | 2 |  |  | 2 |  | 16 | no warnings ; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 395 |  | 
| 206 | 1 |  |  |  |  | 7 | my $NestedBracketsRE = qr{ | 
| 207 |  |  |  |  |  |  | (                       # start of capture buffer 1 | 
| 208 |  |  |  |  |  |  | \(                  # match an opening bracket | 
| 209 |  |  |  |  |  |  | (?: | 
| 210 |  |  |  |  |  |  | [^()]++     # one or more non brackets, non back+tracking | 
| 211 |  |  |  |  |  |  | | | 
| 212 |  |  |  |  |  |  | (?1)        # found ( or ), so recurse to capture buffer 1 | 
| 213 |  |  |  |  |  |  | )* | 
| 214 |  |  |  |  |  |  | \)                  # match a closing bracket | 
| 215 |  |  |  |  |  |  | )                      # end of capture buffer 1 | 
| 216 |  |  |  |  |  |  | }ixms; | 
| 217 |  |  |  |  |  |  | my $OuterSubQueryRE = qr{ | 
| 218 |  |  |  |  |  |  | (?:                     # start of capture buffer 1 | 
| 219 |  |  |  |  |  |  | \(                  # match an opening bracket | 
| 220 |  |  |  |  |  |  | \s*select\b         # match select | 
| 221 |  |  |  |  |  |  | (?: | 
| 222 |  |  |  |  |  |  | [^()]++     # one or more non brackets, non back+tracking | 
| 223 |  |  |  |  |  |  | | | 
| 224 |  |  |  |  |  |  | (??{$NestedBracketsRE})        # found ( or ), so recurse to $NestedBracketsRE | 
| 225 |  |  |  |  |  |  | )* | 
| 226 |  |  |  |  |  |  | \)                  # match a closing bracket | 
| 227 |  |  |  |  |  |  | )                      # end of capture buffer 1 | 
| 228 | 1 |  |  |  |  | 15 | }ixms; | 
| 229 |  |  |  |  |  |  |  | 
| 230 | 2 |  |  | 2 |  | 17 | use warnings ; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 13083 |  | 
| 231 |  |  |  |  |  |  |  | 
| 232 | 1 |  |  |  |  | 65 | $s =~ s!(${OuterSubQueryRE}) | 
| 233 | 2 |  |  |  |  | 3 | ! ${SubqueryIndex}++; $Subquery_replaces[${SubqueryIndex}] = $1 ; " ${SubqueryRepl}${SubqueryIndex} "; | 
|  | 2 |  |  |  |  | 6 |  | 
|  | 2 |  |  |  |  | 12 |  | 
| 234 |  |  |  |  |  |  | !xigems ; | 
| 235 |  |  |  |  |  |  |  | 
| 236 | 1 |  |  |  |  | 45 | $s =~ s!(${NestedBracketsRE}) | 
| 237 | 0 |  |  |  |  | 0 | ! ${BracketsIndex}++; $Brackets_replaces[${BracketsIndex}] = $1 ; " ${BracketsRepl}${BracketsIndex} "; | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 238 |  |  |  |  |  |  | !xigems ; | 
| 239 |  |  |  |  |  |  |  | 
| 240 | 1 |  |  |  |  | 5 | my $CaseEndRE = qr{ | 
| 241 |  |  |  |  |  |  | (                      # start of capture buffer 1 | 
| 242 |  |  |  |  |  |  | (?: \b case \b)     # match an opening case | 
| 243 |  |  |  |  |  |  | (?: | 
| 244 |  |  |  |  |  |  | .*? (?= \b (?:case|end) \b )     # minimal match up to case or end | 
| 245 |  |  |  |  |  |  | | | 
| 246 |  |  |  |  |  |  | (?1)        # found case or end, so recurse to capture buffer 1 | 
| 247 |  |  |  |  |  |  | )* | 
| 248 |  |  |  |  |  |  | (?: \b end \b)      # match a closing end | 
| 249 |  |  |  |  |  |  | )                      # end of capture buffer 1 | 
| 250 |  |  |  |  |  |  | }ixms; | 
| 251 |  |  |  |  |  |  |  | 
| 252 | 1 |  |  |  |  | 63 | $s =~ s!(${CaseEndRE}) | 
| 253 | 1 |  |  |  |  | 2 | ! ${CaseEndIndex}++; $CaseEnd_replaces[${CaseEndIndex}] = $1 ; " ${CaseEndRepl}${CaseEndIndex} "; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 22 |  | 
| 254 |  |  |  |  |  |  | !xigems ; | 
| 255 |  |  |  |  |  |  |  | 
| 256 | 1 |  |  |  |  | 132 | $s =~ s!\b | 
| 257 |  |  |  |  |  |  | ( DECLARE\s+ (?:${qr_Id}) (?:\s+ (?: (?:(?:INSENSITIVE|SCROLL) \s+ CURSOR) | 
| 258 |  |  |  |  |  |  | | | 
| 259 |  |  |  |  |  |  | (?:CURSOR \s+ (?: (?:LOCAL|GLOBAL) \s+)? ) | 
| 260 |  |  |  |  |  |  | (?:\w+) | 
| 261 |  |  |  |  |  |  | ) | 
| 262 |  |  |  |  |  |  | ) | 
| 263 |  |  |  |  |  |  | ) | 
| 264 |  |  |  |  |  |  | \s+(for\s+select) | 
| 265 |  |  |  |  |  |  | \b | 
| 266 | 0 |  |  |  |  | 0 | ! ${CursorSelectsIndex}++; $CursorSelects_replaces[${CursorSelectsIndex}] = $2 ; "${1} ${CursorSelectsRepl}${CursorSelectsIndex} "; | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 267 |  |  |  |  |  |  | !xigems ; | 
| 268 |  |  |  |  |  |  |  | 
| 269 | 1 |  |  |  |  | 15 | $s =~ s!\b(FOR\s+UPDATE(?:\s+OF\b)?) | 
| 270 | 0 |  |  |  |  | 0 | ! ${CursorForUpdatesIndex}++; $CursorForUpdates_replaces[${CursorForUpdatesIndex}] = $1 ; " ${CursorForUpdatesRepl}${CursorForUpdatesIndex} "; | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 271 |  |  |  |  |  |  | !xigems ; | 
| 272 |  |  |  |  |  |  |  | 
| 273 | 1 |  |  |  |  | 16 | $s =~ s!  \b( insert (?:\s+into)? \s+ \S+ \s* (?: with \s* ____BRACKETS_\d+ )? \s* (?: ____BRACKETS_\d+ )? \s* ) | 
| 274 |  |  |  |  |  |  | ( | 
| 275 |  |  |  |  |  |  | (?:select) | 
| 276 |  |  |  |  |  |  | | | 
| 277 |  |  |  |  |  |  | (?:values) | 
| 278 |  |  |  |  |  |  | | | 
| 279 |  |  |  |  |  |  | (?:exec(?:ute)?) | 
| 280 |  |  |  |  |  |  | ) | 
| 281 | 0 |  |  |  |  | 0 | ! ${InsertsIndex}++; $Inserts_replaces[${InsertsIndex}] = $2 ; "${1} ${InsertsRepl}${InsertsIndex} "; | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 282 |  |  |  |  |  |  | !xigems ; | 
| 283 |  |  |  |  |  |  |  | 
| 284 | 1 |  |  |  |  | 14 | $s =~ s!(\bupdate\b.*?)\b(set)\b | 
| 285 | 0 |  |  |  |  | 0 | ! ${UpdatesIndex}++; $Updates_replaces[${UpdatesIndex}] = $2 ; "${1} ${UpdatesRepl}${UpdatesIndex} "; | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 286 |  |  |  |  |  |  | !xigems ; | 
| 287 |  |  |  |  |  |  |  | 
| 288 |  |  |  |  |  |  | # do grant option first as it contains the word grant then .............. | 
| 289 | 1 |  |  |  |  | 19 | $s =~ s!\b((?:(?:WITH\s+GRANT\s+OPTION)|(?:GRANT\s+OPTION\s+FOR)))\b | 
| 290 | 0 |  |  |  |  | 0 | ! ${GrantOptionsIndex}++; $GrantOptions_replaces[${GrantOptionsIndex}] = $2 ; "${1} ${GrantOptionsRepl}${GrantOptionsIndex} "; | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 291 |  |  |  |  |  |  | !xigems ; | 
| 292 |  |  |  |  |  |  | # do revoke next as it contains the word grant | 
| 293 | 1 |  |  |  |  | 18 | $s =~ s!(\brevoke\b)( .*? \b (?:to|from) \b) | 
| 294 | 0 |  |  |  |  | 0 | ! ${RevokesIndex}++; $Revokes_replaces[${RevokesIndex}] = $2 ; "${1} ${RevokesRepl}${RevokesIndex} "; | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 295 |  |  |  |  |  |  | !xigems ; | 
| 296 |  |  |  |  |  |  |  | 
| 297 | 1 |  |  |  |  | 15 | $s =~ s!(\bdeny\b)( .*? \b on \b) | 
| 298 | 0 |  |  |  |  | 0 | ! ${DenysIndex}++; $Denys_replaces[${DenysIndex}] = $2 ; "${1} ${DenysRepl}${DenysIndex} "; | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 299 |  |  |  |  |  |  | !xigems ; | 
| 300 |  |  |  |  |  |  |  | 
| 301 | 1 |  |  |  |  | 15 | $s =~ s!(\bgrant\b)( .*? \b to \b) | 
| 302 | 0 |  |  |  |  | 0 | ! ${GrantsIndex}++; $Grants_replaces[${GrantsIndex}] = $2 ; "${1} ${GrantsRepl}${GrantsIndex} "; | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 0 |  |  |  |  | 0 |  | 
| 303 |  |  |  |  |  |  | !xigems ; | 
| 304 |  |  |  |  |  |  |  | 
| 305 |  |  |  |  |  |  | #print $s ; | 
| 306 |  |  |  |  |  |  |  | 
| 307 |  |  |  |  |  |  | #print "!!\n"; | 
| 308 |  |  |  |  |  |  |  | 
| 309 |  |  |  |  |  |  | #warn Dumper @S_replaces ; | 
| 310 |  |  |  |  |  |  | #warn Dumper @Q_replaces ; | 
| 311 |  |  |  |  |  |  | #warn Dumper @Subquery_replaces ; | 
| 312 |  |  |  |  |  |  | #warn Dumper @Brackets_replaces ; | 
| 313 |  |  |  |  |  |  | #warn Dumper @Inserts_replaces ; | 
| 314 |  |  |  |  |  |  | #warn Dumper @Updates_replaces ; | 
| 315 |  |  |  |  |  |  | #warn Dumper @CursorForUpdates_replaces ; | 
| 316 |  |  |  |  |  |  | #warn Dumper @CursorSelects_replaces ; | 
| 317 |  |  |  |  |  |  | #warn Dumper @GrantOptions_replaces ; | 
| 318 |  |  |  |  |  |  | #warn Dumper @Revokes_replaces ; | 
| 319 |  |  |  |  |  |  | #warn Dumper @Denys_replaces ; | 
| 320 |  |  |  |  |  |  | #warn Dumper @Grants_replaces ; | 
| 321 |  |  |  |  |  |  |  | 
| 322 |  |  |  |  |  |  | #my ($TokeniserPos,$TokeniserNext) = TSQL::SplitStatement->tokeniser() ; | 
| 323 |  |  |  |  |  |  | # cache this variable for efficiency | 
| 324 | 1 |  |  |  |  | 2 | state $TokeniserPos ; | 
| 325 | 1 | 50 |  |  |  | 6 | if ( ! defined $TokeniserPos ) { $TokeniserPos = TSQL::SplitStatement->tokeniser() ; } | 
|  | 1 |  |  |  |  | 5 |  | 
| 326 |  |  |  |  |  |  |  | 
| 327 | 1 |  |  |  |  | 6 | my @TokenPositions = () ; | 
| 328 |  |  |  |  |  |  | #$s =~ s!( ${Tokeniser} ) | 
| 329 |  |  |  |  |  |  | # ! ${TerminatorIndex}++; $Terminator_replaces[${TerminatorIndex}] = $2 ; "${1} ${TerminatorRepl}${TerminatorIndex} \n"; | 
| 330 |  |  |  |  |  |  | # !xigems ; | 
| 331 |  |  |  |  |  |  |  | 
| 332 |  |  |  |  |  |  | #need to  find places, in sweep 1 and replace backwards in sweep2 | 
| 333 |  |  |  |  |  |  | #$s =~ s! ( ${Tokeniser} ) | 
| 334 |  |  |  |  |  |  | # ! " ____SEPARATOR_TOKEN\n $1 " | 
| 335 |  |  |  |  |  |  | # !xigems ; | 
| 336 |  |  |  |  |  |  |  | 
| 337 |  |  |  |  |  |  | # hack around broken ? ^PREMATCH handling in 5.17 | 
| 338 |  |  |  |  |  |  | # and fixed $` handling | 
| 339 | 1 | 50 |  |  |  | 28 | if ( $PERL_VERSION >= v5.17.0 ) { | 
| 340 | 1 |  |  |  |  | 92 | while ( $s =~ m{${TokeniserPos}}xigms ) { | 
| 341 | 33 |  |  |  |  | 2380 | push @TokenPositions, length($`) ; | 
| 342 |  |  |  |  |  |  | } | 
| 343 | 1 |  |  |  |  | 5 | foreach my $tokPos ( reverse @TokenPositions ) { | 
| 344 | 33 |  |  |  |  | 89 | substr($s, $tokPos, 0) = " ____SEPARATOR_TOKEN\n " ; | 
| 345 |  |  |  |  |  |  | } | 
| 346 |  |  |  |  |  |  | } | 
| 347 |  |  |  |  |  |  | else { | 
| 348 | 0 |  |  |  |  | 0 | while ( $s =~ m{${TokeniserPos}}xigms ) { | 
| 349 | 0 |  |  |  |  | 0 | push @TokenPositions, length(${^PREMATCH}) ; | 
| 350 |  |  |  |  |  |  | } | 
| 351 | 0 |  |  |  |  | 0 | foreach my $tokPos ( reverse @TokenPositions ) { | 
| 352 | 0 |  |  |  |  | 0 | substr($s, $tokPos, 0) = " ____SEPARATOR_TOKEN\n " ; | 
| 353 |  |  |  |  |  |  | } | 
| 354 |  |  |  |  |  |  | } | 
| 355 |  |  |  |  |  |  |  | 
| 356 |  |  |  |  |  |  | #print $s ; | 
| 357 |  |  |  |  |  |  |  | 
| 358 |  |  |  |  |  |  |  | 
| 359 | 1 |  |  |  |  | 10 | $s =~ s!\s____GRANT_SET_([\d]+)\s!$Grants_replaces[$1]!gx ; | 
| 360 | 1 |  |  |  |  | 6 | $s =~ s!\s____DENY_SET_([\d]+)\s!$Denys_replaces[$1]!gx ; | 
| 361 | 1 |  |  |  |  | 5 | $s =~ s!\s____REVOKE_SET_([\d]+)\s!$Revokes_replaces[$1]!gx ; | 
| 362 | 1 |  |  |  |  | 4 | $s =~ s!\s____GRANT_OPTION_([\d]+)\s!$GrantOptions_replaces[$1]!gx ; | 
| 363 |  |  |  |  |  |  |  | 
| 364 | 1 |  |  |  |  | 4 | $s =~ s!\s____UPDATES_SET_([\d]+)\s!$Updates_replaces[$1]!gx ; | 
| 365 | 1 |  |  |  |  | 4 | $s =~ s!\s____INSERTS_SELECT_([\d]+)\s!$Inserts_replaces[$1]!gx ; | 
| 366 |  |  |  |  |  |  |  | 
| 367 | 1 |  |  |  |  | 3 | $s =~ s!\s____CURSOR_FOR_UPDATES_([\d]+)\s!$CursorForUpdates_replaces[$1]!gx ; | 
| 368 | 1 |  |  |  |  | 3 | $s =~ s!\s____CURSOR_FOR_SELECT_([\d]+)\s!$CursorSelects_replaces[$1]!gx ; | 
| 369 |  |  |  |  |  |  |  | 
| 370 | 1 |  |  |  |  | 16 | $s =~ s!\s____CASE_END_([\d]+)\s!$CaseEnd_replaces[$1]!gx ; | 
| 371 |  |  |  |  |  |  |  | 
| 372 | 1 |  |  |  |  | 4 | $s =~ s!\s____BRACKETS_([\d]+)\s!$Brackets_replaces[$1]!gx ; | 
| 373 | 1 |  |  |  |  | 11 | $s =~ s!\s____SUBQUERY_([\d]+)\s!$Subquery_replaces[$1]!gx ; | 
| 374 | 1 |  |  |  |  | 8 | $s =~ s!\s____UNION_([\d]+)\s!$Union_replaces[$1]!gx ; | 
| 375 | 1 |  |  |  |  | 4 | $s =~ s!\s____STRING_([\d]+)\s!$S_replaces[$1]!gx ; | 
| 376 | 1 |  |  |  |  | 3 | $s =~ s!\s____QUOTEDID_([\d]+)\s!$Q_replaces[$1]!gx ; | 
| 377 |  |  |  |  |  |  |  | 
| 378 |  |  |  |  |  |  |  | 
| 379 |  |  |  |  |  |  | #print $s; | 
| 380 |  |  |  |  |  |  |  | 
| 381 |  |  |  |  |  |  | #my $idx = 0 ; | 
| 382 |  |  |  |  |  |  | #for my $comment_pos ( @Comment_positions ) { | 
| 383 |  |  |  |  |  |  | #    substr($s, $comment_pos, 1," ____COMMENT_${idx} ")  ; | 
| 384 |  |  |  |  |  |  | #    $idx++; | 
| 385 |  |  |  |  |  |  | #} | 
| 386 |  |  |  |  |  |  | # | 
| 387 |  |  |  |  |  |  | #$s =~ s!\s____COMMENT_([\d]+)\s!$Comment_replaces[$1]!gx ; | 
| 388 |  |  |  |  |  |  |  | 
| 389 |  |  |  |  |  |  | #print $s; | 
| 390 |  |  |  |  |  |  |  | 
| 391 | 1 |  |  |  |  | 40 | my @parsedInput = grep { $_ !~ /\A\s*\z/msx } split /\s*____SEPARATOR_TOKEN\s*/x,$s; | 
|  | 33 |  |  |  |  | 76 |  | 
| 392 |  |  |  |  |  |  |  | 
| 393 |  |  |  |  |  |  | #pp @parsedInput ; | 
| 394 |  |  |  |  |  |  | # | 
| 395 |  |  |  |  |  |  | #my @tryblocks   = () ; | 
| 396 |  |  |  |  |  |  | #my @blocks      = () ; | 
| 397 |  |  |  |  |  |  | #my @ifs         = () ; | 
| 398 |  |  |  |  |  |  | #my @whiles      = () ; | 
| 399 |  |  |  |  |  |  | # | 
| 400 |  |  |  |  |  |  | # | 
| 401 |  |  |  |  |  |  | #my @begintryblocks          = indexes {/\Abegin\s+try\z/ims}    @parsedInput ; | 
| 402 |  |  |  |  |  |  | #my @endtryblocks            = indexes {/\Aend\s+try\z/ims}      @parsedInput ; | 
| 403 |  |  |  |  |  |  | # | 
| 404 |  |  |  |  |  |  | #my @beginblocks             = indexes {/\Abegin\z/ims}    @parsedInput ; | 
| 405 |  |  |  |  |  |  | #my @endblocks               = indexes {/\Aend\z/ims}      @parsedInput ; | 
| 406 |  |  |  |  |  |  | #my @begincatchblocks        = indexes {/\Abegin\s+catch\z/ims}  @parsedInput ; | 
| 407 |  |  |  |  |  |  | #my @endcatchblocks          = indexes {/\Aend\s+catch\z/ims}    @parsedInput ; | 
| 408 |  |  |  |  |  |  | #my @ifstatements            = indexes {/\Aif\b/ims}  @parsedInput ; | 
| 409 |  |  |  |  |  |  | #my @elsestatements          = indexes {/\Aelse\z/ims}  @parsedInput ; | 
| 410 |  |  |  |  |  |  | #my @whilestatements         = indexes {/\Awhile\b/ims}    @parsedInput ; | 
| 411 |  |  |  |  |  |  | # | 
| 412 |  |  |  |  |  |  | #pp 'begin', @beginblocks ; | 
| 413 |  |  |  |  |  |  | #pp 'end', @endblocks ; | 
| 414 |  |  |  |  |  |  | #pp 'begin try', @begintryblocks ; | 
| 415 |  |  |  |  |  |  | #pp 'end try', @endtryblocks ; | 
| 416 |  |  |  |  |  |  | #pp 'begin catch', @begincatchblocks ; | 
| 417 |  |  |  |  |  |  | #pp 'end catch', @endcatchblocks ; | 
| 418 |  |  |  |  |  |  | # | 
| 419 |  |  |  |  |  |  | #pp 'ifstatements',@ifstatements ; | 
| 420 |  |  |  |  |  |  | #pp 'elsestatements',@elsestatements ; | 
| 421 |  |  |  |  |  |  | #pp 'whilestatements',@whilestatements ; | 
| 422 |  |  |  |  |  |  |  | 
| 423 | 1 |  |  |  |  | 9 | my @cp_parsedInput = @parsedInput; | 
| 424 |  |  |  |  |  |  |  | 
| 425 |  |  |  |  |  |  | #my $blockCount = scalar @beginblocks ; | 
| 426 |  |  |  |  |  |  | #my @bl = () ; | 
| 427 |  |  |  |  |  |  | #while ( $blockCount > 0 ) { | 
| 428 |  |  |  |  |  |  | #     foreach my $i (@beginblocks) { | 
| 429 |  |  |  |  |  |  | #     } | 
| 430 |  |  |  |  |  |  | #} | 
| 431 |  |  |  |  |  |  | #my $done = 0 ; | 
| 432 |  |  |  |  |  |  | ##while (! $done ) { | 
| 433 |  |  |  |  |  |  | #    my @blocks  = grep { my $b = $_; #my $e = first { my $e = $_ ; $e > $b and none { my $b2 = $_; $b2 > $b and $b2 < $e | 
| 434 |  |  |  |  |  |  | #                                    #                                      } @beginblocks | 
| 435 |  |  |  |  |  |  | #                                    #      } @endblocks | 
| 436 |  |  |  |  |  |  | #                      ; [$b] ; #,$e] | 
| 437 |  |  |  |  |  |  | #                      } @beginblocks ; | 
| 438 |  |  |  |  |  |  | #    $done = 1; | 
| 439 |  |  |  |  |  |  | ##} | 
| 440 |  |  |  |  |  |  | # | 
| 441 |  |  |  |  |  |  | #pp @blocks; | 
| 442 |  |  |  |  |  |  |  | 
| 443 | 1 |  |  |  |  | 33 | return @parsedInput ; | 
| 444 |  |  |  |  |  |  | } | 
| 445 |  |  |  |  |  |  |  | 
| 446 |  |  |  |  |  |  |  | 
| 447 |  |  |  |  |  |  | sub tokeniser { | 
| 448 |  |  |  |  |  |  | # | 
| 449 |  |  |  |  |  |  | #my $qr_Id = q{(?:[#_\w$@][#$:_.\w]*)} ; | 
| 450 | 1 |  |  | 1 | 1 | 5 | my $qr_Id = TSQL::Common::Regexp->qr_id(); | 
| 451 |  |  |  |  |  |  | #my $qr_label = q{(?:[#_\w$@][#$:_.\w]*[:])}; | 
| 452 | 1 |  |  |  |  | 6 | my $qr_label = TSQL::Common::Regexp->qr_label(); | 
| 453 |  |  |  |  |  |  |  | 
| 454 |  |  |  |  |  |  | ## add a backup create/drop/alter generic statement | 
| 455 |  |  |  |  |  |  | ## to cater for create xml index ??? | 
| 456 |  |  |  |  |  |  |  | 
| 457 | 1 |  |  |  |  | 195 | my @Phrases = | 
| 458 |  |  |  |  |  |  | (       [q{(?:\b(? | 
| 459 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 460 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 461 |  |  |  |  |  |  | ,       [qq{(?:\\b(? | 
| 462 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 463 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 464 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 465 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 466 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 467 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 468 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 469 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 470 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 471 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 472 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 473 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 474 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 475 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 476 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 477 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 478 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 479 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 480 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 481 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 482 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 483 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 484 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 485 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 486 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 487 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 488 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 489 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 490 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 491 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 492 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 493 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 494 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 495 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 496 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 497 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 498 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 499 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 500 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 501 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 502 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 503 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 504 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 505 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 506 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 507 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 508 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 509 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 510 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 511 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 512 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 513 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 514 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 515 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 516 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 517 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 518 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 519 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 520 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 521 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 522 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 523 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 524 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 525 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 526 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 527 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 528 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 529 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 530 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 531 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 532 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 533 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 534 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 535 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 536 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 537 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 538 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 539 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 540 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 541 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 542 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 543 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 544 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 545 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 546 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 547 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 548 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 549 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 550 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 551 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 552 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 553 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 554 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 555 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 556 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 557 |  |  |  |  |  |  |  | 
| 558 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 559 |  |  |  |  |  |  |  | 
| 560 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 561 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 562 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 563 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 564 |  |  |  |  |  |  |  | 
| 565 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 566 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 567 |  |  |  |  |  |  | ,       [qq{(?:\\b(? | 
| 568 |  |  |  |  |  |  | , q{DECLARE_CURSOR}                         ] | 
| 569 |  |  |  |  |  |  |  | 
| 570 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 571 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 572 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 573 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 574 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 575 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 576 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 577 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 578 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 579 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 580 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 581 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 582 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 583 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 584 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 585 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 586 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 587 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 588 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 589 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 590 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 591 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 592 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 593 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 594 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 595 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 596 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 597 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 598 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 599 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 600 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 601 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 602 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 603 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 604 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 605 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 606 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 607 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 608 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 609 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 610 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 611 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 612 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 613 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 614 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 615 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 616 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 617 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 618 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 619 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 620 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 621 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 622 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 623 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 624 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 625 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 626 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 627 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 628 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 629 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 630 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 631 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 632 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 633 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 634 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 635 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 636 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 637 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 638 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 639 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 640 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 641 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 642 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 643 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 644 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 645 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 646 |  |  |  |  |  |  | ,       [qq{(?:\\b(? | 
| 647 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 648 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 649 |  |  |  |  |  |  | ,       [qq{(?:\\b(? | 
| 650 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 651 |  |  |  |  |  |  | ,                                     , q{SET_TRANSACTION_ISOLATION_LEVEL}        ] | 
| 652 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 653 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 654 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 655 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 656 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 657 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 658 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 659 |  |  |  |  |  |  |  | 
| 660 |  |  |  |  |  |  | #,       [qq{(?:\\b(? | 
| 661 |  |  |  |  |  |  | #                                                                      , q{WITH} ] | 
| 662 |  |  |  |  |  |  |  | 
| 663 |  |  |  |  |  |  | ,       [qq{(?:\\b(? | 
| 664 |  |  |  |  |  |  | , q{WITH} ] | 
| 665 |  |  |  |  |  |  |  | 
| 666 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 667 |  |  |  |  |  |  | , q{WITH_XMLNAMESPACES} ] | 
| 668 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 669 |  |  |  |  |  |  | , q{OPEN__KEY} ] | 
| 670 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 671 |  |  |  |  |  |  | , q{OPEN_SYMMETRIC_KEY} ] | 
| 672 |  |  |  |  |  |  | ,       [q{(?:\b(? | 
| 673 |  |  |  |  |  |  | ,       [q{\z}                                                        , q{} ] | 
| 674 |  |  |  |  |  |  | )   ; | 
| 675 |  |  |  |  |  |  |  | 
| 676 | 1 |  |  |  |  | 6 | my %TERM_RE     = () ; | 
| 677 | 1 |  |  |  |  | 2 | %TERM_RE        = map { my $key = $_->[0]; | 
|  | 201 |  |  |  |  | 186 |  | 
| 678 | 201 |  |  |  |  | 166 | my $val = $_->[0] ; | 
| 679 | 201 |  |  |  |  | 408 | $key =~ s{^[^A-Z]*}{}x; | 
| 680 | 201 |  |  |  |  | 579 | ($key => $val); | 
| 681 |  |  |  |  |  |  | } @Phrases ; | 
| 682 |  |  |  |  |  |  |  | 
| 683 |  |  |  |  |  |  | #my $TERM_RE     = join '|', map { qr{$TERM_RE{$_}}xmsi} reverse sort keys %TERM_RE ; | 
| 684 | 1 |  |  |  |  | 236 | my $TERM_RE     = qr{${qr_label}}xmsi . '|' . join '|', map { qr{$TERM_RE{$_}}xmsi} reverse sort keys %TERM_RE ; | 
|  | 201 |  |  |  |  | 3546 |  | 
| 685 |  |  |  |  |  |  |  | 
| 686 |  |  |  |  |  |  |  | 
| 687 |  |  |  |  |  |  |  | 
| 688 |  |  |  |  |  |  | #patch these in first - nasty hack on top of a hack | 
| 689 |  |  |  |  |  |  | #with .......... infect everything, is there any other DDL it can find its way into ? | 
| 690 |  |  |  |  |  |  | #also need to patch trigger creation so as not let the main parser incorrectly parse things before the AS | 
| 691 |  |  |  |  |  |  |  | 
| 692 | 1 |  |  |  |  | 203 | $TERM_RE = qr{(?: \b(?:ALTER|CREATE)\b \s+ \bVIEW\b  \s+ \b(?:${qr_Id})\b (?:\s*____BRACKETS_\\d+)? (?: \s*  \bAS\b \s+(?: \bSELECT\b | (?: \bWITH\b .*? \bSELECT\b )))) }xmsi . "|" . | 
| 693 |  |  |  |  |  |  | qr{(?: \b(?:ALTER|CREATE)\b \s+ \bTRIGGER\b (?:.*?) \bAS\b ) }xmsi . "|" . | 
| 694 |  |  |  |  |  |  | qr{(?: \b(?:ALTER|CREATE)\b \s+ \bPROC(?:EDURE)?\b (?:.*?) \bAS\b ) }xmsi . "|" . | 
| 695 |  |  |  |  |  |  | "${TERM_RE}" ; | 
| 696 |  |  |  |  |  |  |  | 
| 697 |  |  |  |  |  |  |  | 
| 698 |  |  |  |  |  |  |  | 
| 699 | 1 |  |  |  |  | 7147 | my $LBL_TERM_RE         = qr{ (?: (?: ${TERM_RE} ) .*?) (?= (?: (?: \b ${qr_label} \s+ )? (?: ${TERM_RE} ) ) ) }xmsi; | 
| 700 |  |  |  |  |  |  |  | 
| 701 | 1 |  |  |  |  | 2822 | my $LBL_TERM_RE_OTHER   = qr{ \G (?: (?: \b ${qr_label} \s+ )? (?: ${TERM_RE} ) ) }xmsi; | 
| 702 |  |  |  |  |  |  |  | 
| 703 |  |  |  |  |  |  | #warn $LBL_TERM_RE  ; | 
| 704 |  |  |  |  |  |  |  | 
| 705 |  |  |  |  |  |  | #return ($LBL_TERM_RE,$LBL_TERM_RE_OTHER) ; | 
| 706 | 1 |  |  |  |  | 256 | return $LBL_TERM_RE ; | 
| 707 |  |  |  |  |  |  |  | 
| 708 |  |  |  |  |  |  | } | 
| 709 |  |  |  |  |  |  |  | 
| 710 |  |  |  |  |  |  | 1; | 
| 711 |  |  |  |  |  |  |  | 
| 712 |  |  |  |  |  |  | __DATA__ |