@@ -84,17 +84,71 @@ public static void parse(String sqlString, Recognizer recognizer) throws QueryEx
84
84
boolean foundMainOutputParam = false ;
85
85
86
86
final int stringLength = sqlString .length ();
87
- boolean inQuote = false ;
87
+
88
+ boolean inSingleQuotes = false ;
89
+ boolean inDoubleQuotes = false ;
90
+ boolean inLineComment = false ;
91
+ boolean inDelimitedComment = false ;
92
+
88
93
for ( int indx = 0 ; indx < stringLength ; indx ++ ) {
89
94
final char c = sqlString .charAt ( indx );
90
- if ( inQuote ) {
95
+ final boolean lastCharacter = indx == stringLength -1 ;
96
+
97
+ if ( inLineComment ) {
98
+ // see if the character ends the line
99
+ if ( '\n' == c ) {
100
+ inLineComment = false ;
101
+ recognizer .other ( c );
102
+ }
103
+ else if ( '\r' == c ) {
104
+ inLineComment = false ;
105
+ recognizer .other ( c );
106
+ if ( !lastCharacter && '\n' == sqlString .charAt ( indx +1 ) ) {
107
+ recognizer .other ( sqlString .charAt ( indx +1 ) );
108
+ indx ++;
109
+ }
110
+ }
111
+ }
112
+ else if ( '-' == c ) {
113
+ recognizer .other ( c );
114
+ if ( !lastCharacter && '-' == sqlString .charAt ( indx +1 ) ) {
115
+ inLineComment = true ;
116
+ recognizer .other ( sqlString .charAt ( indx +1 ) );
117
+ indx ++;
118
+ }
119
+ }
120
+ else if ( inDelimitedComment ) {
121
+ recognizer .other ( c );
122
+ if ( !lastCharacter && '*' == c && '/' == sqlString .charAt ( indx +1 ) ) {
123
+ inDelimitedComment = true ;
124
+ recognizer .other ( sqlString .charAt ( indx +1 ) );
125
+ indx ++;
126
+ }
127
+ }
128
+ else if ( !lastCharacter && '/' == c && '*' == sqlString .charAt ( indx +1 ) ) {
129
+ inDelimitedComment = true ;
130
+ recognizer .other ( c );
131
+ recognizer .other ( sqlString .charAt ( indx +1 ) );
132
+ indx ++;
133
+ }
134
+ else if ( inDoubleQuotes ) {
135
+ if ( '\"' == c ) {
136
+ inDoubleQuotes = false ;
137
+ }
138
+ recognizer .other ( c );
139
+ }
140
+ else if ( '\"' == c ) {
141
+ inDoubleQuotes = true ;
142
+ recognizer .other ( c );
143
+ }
144
+ else if ( inSingleQuotes ) {
91
145
if ( '\'' == c ) {
92
- inQuote = false ;
146
+ inSingleQuotes = false ;
93
147
}
94
148
recognizer .other ( c );
95
149
}
96
150
else if ( '\'' == c ) {
97
- inQuote = true ;
151
+ inSingleQuotes = true ;
98
152
recognizer .other ( c );
99
153
}
100
154
else if ( '\\' == c ) {
0 commit comments