@@ -301,6 +301,7 @@ class WP_SQLite_Translator {
301301 /**
302302 * 0 if no LIKE is in progress, otherwise counts nested parentheses.
303303 *
304+ * @todo A generic stack of expression would scale better. There's already a call_stack in WP_SQLite_Query_Rewriter.
304305 * @var int
305306 */
306307 private $ like_expression_nesting = 0 ;
@@ -1676,7 +1677,7 @@ private function preprocess_like_expr( &$token ) {
16761677 * This code handles escaped wildcards in LIKE clauses.
16771678 * If we are within a LIKE experession, we look for \_ and \%, the
16781679 * escaped LIKE wildcards, the ones where we want a literal, not a
1679- * wildcard match. We change the \ escape for a ~ character,
1680+ * wildcard match. We change the \ escape for an ASCII \x1a (SUB) character,
16801681 * so the \ characters won't get munged.
16811682 * These \_ and \% escape sequences are in the token name, because
16821683 * the lexer has already done stripcslashes on the value.
@@ -1956,11 +1957,12 @@ private function translate_date_add_sub( $token ) {
19561957 * @todo LENGTH and CHAR_LENGTH aren't always the same in MySQL for utf8 characters. They are in SQLite.
19571958 */
19581959 private function translate_function_aliases ( $ token ) {
1959- if ( ! $ token ->matches (
1960- WP_SQLite_Token::TYPE_KEYWORD ,
1961- WP_SQLite_Token::FLAG_KEYWORD_FUNCTION ,
1962- array ( 'SUBSTRING ' , 'CHAR_LENGTH ' )
1963- )
1960+ if ( ! $ token ->matches
1961+ (
1962+ WP_SQLite_Token::TYPE_KEYWORD ,
1963+ WP_SQLite_Token::FLAG_KEYWORD_FUNCTION ,
1964+ array ( 'SUBSTRING ' , 'CHAR_LENGTH ' )
1965+ )
19641966 ) {
19651967 return false ;
19661968 }
@@ -2236,6 +2238,8 @@ private function translate_regexp_functions( $token ) {
22362238 /**
22372239 * Detect GROUP BY.
22382240 *
2241+ * @todo edgecase Fails on a statement with GROUP BY nested in an outer HAVING without GROUP BY.
2242+ *
22392243 * @param WP_SQLite_Token $token The token to translate.
22402244 *
22412245 * @return bool
@@ -2299,9 +2303,9 @@ private function translate_ungrouped_having( $token ) {
22992303 private function translate_like_escape ( $ token ) {
23002304
23012305 if ( 0 === $ this ->like_expression_nesting ) {
2302- $ match = $ token ->matches ( WP_SQLite_Token::TYPE_KEYWORD , null , array ( 'LIKE ' ) );
2306+ $ is_like = $ token ->matches ( WP_SQLite_Token::TYPE_KEYWORD , null , array ( 'LIKE ' ) );
23032307 /* is this the LIKE keyword? If so set the flag. */
2304- if ( $ match ) {
2308+ if ( $ is_like ) {
23052309 $ this ->like_expression_nesting = 1 ;
23062310 }
23072311 } else {
@@ -2320,21 +2324,21 @@ private function translate_like_escape( $token ) {
23202324 }
23212325
23222326 /* a keyword, a commo, a semicolon, the end of the statement, or a close parenthesis */
2323- $ match = $ token ->matches ( WP_SQLite_Token::TYPE_KEYWORD )
2327+ $ is_like_finished = $ token ->matches ( WP_SQLite_Token::TYPE_KEYWORD )
23242328 || $ token ->matches ( WP_SQLite_Token::TYPE_DELIMITER , null , array ( '; ' ) ) || ( WP_SQLite_Token::TYPE_DELIMITER === $ token ->type && null === $ token ->value )
23252329 || $ token ->matches ( WP_SQLite_Token::TYPE_OPERATOR , null , array ( ') ' , ', ' ) );
23262330
2327- if ( $ match ) {
2331+ if ( $ is_like_finished ) {
23282332 /* Here we have another keyword encountered with the LIKE in progress.
23292333 * Emit the ESCAPE clause.
23302334 */
23312335 if ( $ this ->like_escape_count > 0 ) {
23322336 /* If we need the ESCAPE clause emit it. */
2333- $ this ->rewriter ->add ( new WP_SQLite_Token ( ' ' , WP_SQLite_Token::TYPE_DELIMITER ) );
2334- $ this ->rewriter ->add ( new WP_SQLite_Token ( 'ESCAPE ' , WP_SQLite_Token::TYPE_KEYWORD ) );
2335- $ this ->rewriter ->add ( new WP_SQLite_Token ( ' ' , WP_SQLite_Token::TYPE_DELIMITER ) );
2337+ $ this ->rewriter ->add ( new WP_SQLite_Token ( ' ' , WP_SQLite_Token::TYPE_DELIMITER ) );
2338+ $ this ->rewriter ->add ( new WP_SQLite_Token ( 'ESCAPE ' , WP_SQLite_Token::TYPE_KEYWORD ) );
2339+ $ this ->rewriter ->add ( new WP_SQLite_Token ( ' ' , WP_SQLite_Token::TYPE_DELIMITER ) );
23362340 $ this ->rewriter ->add ( new WP_SQLite_Token ( "' " . self ::LIKE_ESCAPE_CHAR . "' " , WP_SQLite_Token::TYPE_STRING ) );
2337- $ this ->rewriter ->add ( new WP_SQLite_Token ( ' ' , WP_SQLite_Token::TYPE_DELIMITER ) );
2341+ $ this ->rewriter ->add ( new WP_SQLite_Token ( ' ' , WP_SQLite_Token::TYPE_DELIMITER ) );
23382342 }
23392343 $ this ->like_escape_count = 0 ;
23402344 $ this ->like_expression_nesting = 0 ;
0 commit comments