protected int findWhereKeyword ( String sql ) { char [ ] chars = sql . toLowerCase ( ) . toCharArray ( ) ; char [ ] whereChars = "where" . toCharArray ( ) ; int i = 0 ; boolean inString = false ; //TODO: Cater for comments? int inWhere = 0 ; while ( i < chars . length ) { switch ( chars [ i ] ) { case ' ' : inString = ! inString ; break ; default : if ( ! inString && chars [ i ] == whereChars [ inWhere ] ) { inWhere ++ ; if ( inWhere == whereChars . length ) { return i ; } } else { inWhere = 0 ; } } i ++ ; } return - 1 ; }
Hook to allow derived classes to override where clause sniffing . Default behavior is to find the first where keyword in the sql doing simple avoidance of the word where within quotes .