@@ -229,93 +229,96 @@ else if ( quotedIdentifier && dialect.closeQuote()==token.charAt(0) ) {
229229 final boolean wasAfterCurrent = afterCurrent ;
230230 afterCurrent = afterCurrent && isWhitespace ;
231231
232+ final String processedToken ;
232233 final boolean isQuoted =
233234 quoted || quotedIdentifier || isQuoteCharacter ;
234235 if ( isQuoted || isWhitespace ) {
235- result . append ( token ) ;
236+ processedToken = token ;
236237 }
237238 else if ( beforeTable ) {
238- result . append ( token ) ;
239+ processedToken = token ;
239240 beforeTable = false ;
240241 afterFromTable = true ;
241242 }
242243 else if ( afterFromTable ) {
243244 afterFromTable = "as" .equals (lcToken );
244- result . append ( token ) ;
245+ processedToken = token ;
245246 }
246247 else if ( "(" .equals (lcToken ) ) {
247- result . append ( token ) ;
248+ processedToken = token ;
248249 }
249250 else if ( ")" .equals (lcToken ) ) {
250251 inExtractOrTrim = false ;
251252 inCast = false ;
252253 afterCastAs = false ;
253- result . append ( token ) ;
254+ processedToken = token ;
254255 }
255256 else if ( "," .equals (lcToken ) ) {
256257 if ( inFromClause ) {
257258 beforeTable = true ;
258259 }
259- result . append ( token ) ;
260+ processedToken = token ;
260261 }
261262 else if ( lcToken .length ()==1 && symbols .contains (lcToken ) ) {
262- result . append ( token ) ;
263+ processedToken = token ;
263264 }
264265 else if ( BEFORE_TABLE_KEYWORDS .contains (lcToken ) ) {
265266 if ( !inExtractOrTrim ) {
266267 beforeTable = true ;
267268 inFromClause = true ;
268269 }
269- result . append ( token ) ;
270+ processedToken = token ;
270271 }
271272 else if ( inFromClause || afterCastAs ) {
272273 // Don't want to append alias to:
273274 // 1. tokens inside the FROM clause
274275 // 2. type names after 'CAST(expression AS'
275- result . append ( token ) ;
276+ processedToken = token ;
276277 }
277278 else if ( isNamedParameter (token ) ) {
278- result . append ( token ) ;
279+ processedToken = token ;
279280 }
280281 else if ( "as" .equals ( lcToken ) ) {
281- result . append ( token ) ;
282+ processedToken = token ;
282283 afterCastAs = inCast ;
283284 }
284285 else if ( isFetch ( dialect , lcToken ) ) {
285- result . append ( token ) ;
286+ processedToken = token ;
286287 afterFetch = true ;
287288 }
288289 else if ( wasAfterFetch && FETCH_BIGRAMS .contains ( lcToken ) ) {
289- result . append ( token ) ;
290+ processedToken = token ;
290291 }
291292 else if ( isCurrent ( lcToken , nextToken , sql , symbols , tokens ) ) {
292- result . append ( token ) ;
293+ processedToken = token ;
293294 afterCurrent = true ;
294295 }
295296 else if ( isBoolean ( lcToken ) ) {
296- result . append ( dialect .toBooleanValueString ( parseBoolean ( token ) ) );
297+ processedToken = dialect .toBooleanValueString ( parseBoolean ( token ) );
297298 }
298299 else if ( isFunctionCall ( nextToken , sql , symbols , tokens ) ) {
299- result .append (token );
300300 if ( FUNCTION_WITH_FROM_KEYWORDS .contains ( lcToken ) ) {
301301 inExtractOrTrim = true ;
302302 }
303303 if ( "cast" .equals ( lcToken ) ) {
304304 inCast = true ;
305305 }
306+ processedToken = token ;
306307 }
307308 else if ( isAliasableIdentifier ( token , lcToken , nextToken ,
308309 sql , symbols , tokens , wasAfterCurrent ,
309310 dialect , typeConfiguration ) ) {
310- result . append ( alias ). append ( '.' ). append ( dialect .quote (token ) );
311+ processedToken = alias + '.' + dialect .quote (token );
311312 }
312313 else {
313- result . append ( token ) ;
314+ processedToken = token ;
314315 }
315316
317+ result .append ( processedToken );
318+
316319 //Yuck:
317320 if ( inFromClause
318- && KEYWORDS .contains ( lcToken ) //"as" is not in KEYWORDS
321+ && KEYWORDS .contains ( lcToken ) // "as" is not in KEYWORDS
319322 && !BEFORE_TABLE_KEYWORDS .contains ( lcToken ) ) {
320323 inFromClause = false ;
321324 }
0 commit comments