File tree 2 files changed +27
-17
lines changed 2 files changed +27
-17
lines changed Original file line number Diff line number Diff line change @@ -1764,6 +1764,32 @@ public function parse_keyword() {
1764
1764
1765
1765
$ this ->last = $ i_end ;
1766
1766
1767
+ // SQLite does not support CURRENT_TIMESTAMP() function calls with parentheses,
1768
+ // but it does support the equivalent CURRENT_TIMESTAMP variant without them.
1769
+ // Let's remove the parentheses and surrounding spaces.
1770
+ if ( $ ret && 'CURRENT_TIMESTAMP ' === $ ret ->value ) {
1771
+ $ end = $ this ->last + 1 ;
1772
+ $ open_paren = false ;
1773
+ $ close_paren = false ;
1774
+ while ( static ::is_whitespace ( $ this ->str [ $ end ] ) ) {
1775
+ $ end += 1 ;
1776
+ }
1777
+ if ( '( ' === $ this ->str [ $ end ] ?? '' ) {
1778
+ $ open_paren = true ;
1779
+ $ end += 1 ;
1780
+ }
1781
+ while ( static ::is_whitespace ( $ this ->str [ $ end ] ) ) {
1782
+ $ end += 1 ;
1783
+ }
1784
+ if ( ') ' === $ this ->str [ $ end ] ?? '' ) {
1785
+ $ close_paren = true ;
1786
+ }
1787
+
1788
+ if ( $ open_paren && $ close_paren ) {
1789
+ $ this ->last = $ end ;
1790
+ }
1791
+ }
1792
+
1767
1793
return $ ret ;
1768
1794
}
1769
1795
Original file line number Diff line number Diff line change @@ -772,23 +772,7 @@ public function get_return_value() {
772
772
* @throws Exception If the query is not supported.
773
773
*/
774
774
private function execute_mysql_query ( $ query ) {
775
- $ tokens = ( new WP_SQLite_Lexer ( $ query ) )->tokens ;
776
-
777
- // SQLite does not support CURRENT_TIMESTAMP() calls with parentheses.
778
- // Since CURRENT_TIMESTAMP() can appear in most types of SQL queries,
779
- // let's remove the parentheses globally before further processing.
780
- foreach ( $ tokens as $ i => $ token ) {
781
- if ( WP_SQLite_Token::TYPE_KEYWORD === $ token ->type && 'CURRENT_TIMESTAMP ' === $ token ->keyword ) {
782
- $ paren_open = $ tokens [ $ i + 1 ] ?? null ;
783
- $ paren_close = $ tokens [ $ i + 2 ] ?? null ;
784
- if ( WP_SQLite_Token::TYPE_OPERATOR === $ paren_open ->type && '( ' === $ paren_open ->value
785
- && WP_SQLite_Token::TYPE_OPERATOR === $ paren_close ->type && ') ' === $ paren_close ->value ) {
786
- unset( $ tokens [ $ i + 1 ], $ tokens [ $ i + 2 ] );
787
- }
788
- }
789
- }
790
- $ tokens = array_values ( $ tokens );
791
-
775
+ $ tokens = ( new WP_SQLite_Lexer ( $ query ) )->tokens ;
792
776
$ this ->rewriter = new WP_SQLite_Query_Rewriter ( $ tokens );
793
777
$ this ->query_type = $ this ->rewriter ->peek ()->value ;
794
778
You can’t perform that action at this time.
0 commit comments