public static boolean isRewritableBatch(String queryString,boolean noBackslashEscapes){
  LexState state=LexState.Normal;
  char lastChar='\0';
  boolean singleQuotes=false;
  boolean endingSemicolon=false;
  char[] query=queryString.toCharArray();
  int queryLength=query.length;
  for (int i=0; i < queryLength; i++) {
    if (state == LexState.Escape)     state=LexState.String;
    char car=query[i];
switch (car) {
case '*':
      if (state == LexState.Normal && lastChar == '/')       state=LexState.SlashStarComment;
    break;
case '/':
  if (state == LexState.SlashStarComment && lastChar == '*') {
    state=LexState.Normal;
  }
 else   if (state == LexState.Normal && lastChar == '/') {
    state=LexState.EOLComment;
  }
break;
case '#':
if (state == LexState.Normal) state=LexState.EOLComment;
break;
case '-':
if (state == LexState.Normal && lastChar == '-') {
state=LexState.EOLComment;
}
break;
case ';':
if (state == LexState.Normal) {
endingSemicolon=true;
}
break;
case '\n':
if (state == LexState.EOLComment) {
state=LexState.Normal;
}
break;
case '"':
if (state == LexState.Normal) {
state=LexState.String;
singleQuotes=false;
}
 else if (state == LexState.String && !singleQuotes) {
state=LexState.Normal;
}
break;
case '\'':
if (state == LexState.Normal) {
state=LexState.String;
singleQuotes=true;
}
 else if (state == LexState.String && singleQuotes) {
state=LexState.Normal;
}
break;
case '\\':
if (noBackslashEscapes) {
break;
}
if (state == LexState.String) state=LexState.Escape;
break;
case '`':
if (state == LexState.Backtick) {
state=LexState.Normal;
}
 else if (state == LexState.Normal) {
state=LexState.Backtick;
}
break;
default :
if (state == LexState.Normal && endingSemicolon && ((byte)car >= 40)) {
endingSemicolon=false;
}
break;
}
lastChar=car;
}
return state != LexState.EOLComment && !endingSemicolon;
}

public static boolean isRewritableBatch ( String queryString , boolean noBackslashEscapes ) { LexState state = LexState . Normal ; char lastChar = '\0' ; boolean singleQuotes = false ; boolean endingSemicolon = false ; char [ ] query = queryString . toCharArray ( ) ; int queryLength = query . length ; for ( int i = 0 ; i < queryLength ; i ++ ) { if ( state == LexState . Escape ) state = LexState . String ; char car = query [ i ] ; switch ( car ) { case '*' : if ( state == LexState . Normal && lastChar == '/' ) state = LexState . SlashStarComment ; break ; case '/' : if ( state == LexState . SlashStarComment && lastChar == '*' ) { state = LexState . Normal ; } else if ( state == LexState . Normal && lastChar == '/' ) { state = LexState . EOLComment ; } break ; case '#' : if ( state == LexState . Normal ) state = LexState . EOLComment ; break ; case '-' : if ( state == LexState . Normal && lastChar == '-' ) { state = LexState . EOLComment ; } break ; case ';' : if ( state == LexState . Normal ) { endingSemicolon = true ; } break ; case '\n' : if ( state == LexState . EOLComment ) { state = LexState . Normal ; } break ; case '"' : if ( state == LexState . Normal ) { state = LexState . String ; singleQuotes = false ; } else if ( state == LexState . String && ! singleQuotes ) { state = LexState . Normal ; } break ; case '\'' : if ( state == LexState . Normal ) { state = LexState . String ; singleQuotes = true ; } else if ( state == LexState . String && singleQuotes ) { state = LexState . Normal ; } break ; case '\\' : if ( noBackslashEscapes ) { break ; } if ( state == LexState . String ) state = LexState . Escape ; break ; case '`' : if ( state == LexState . Backtick ) { state = LexState . Normal ; } else if ( state == LexState . Normal ) { state = LexState . Backtick ; } break ; default : if ( state == LexState . Normal && endingSemicolon && ( ( byte ) car >= 40 ) ) { endingSemicolon = false ; } break ; } lastChar = car ; } return state != LexState . EOLComment && ! endingSemicolon ; }
valid that query is valid ( no ending semi colon , or end - of line comment ) .
