File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11181,6 +11181,20 @@ public function testVersionFunction(): void {
1118111181 $ this ->assertSame ( '8.0.38 ' , $ result [0 ]->{'VERSION() ' } );
1118211182 }
1118311183
11184+ public function testSubstringFunction (): void {
11185+ $ result = $ this ->assertQuery ( "SELECT SUBSTRING('abcdef', 1, 3) AS s " );
11186+ $ this ->assertSame ( 'abc ' , $ result [0 ]->s );
11187+
11188+ $ result = $ this ->assertQuery ( "SELECT SUBSTRING('abcdef', 4) AS s " );
11189+ $ this ->assertSame ( 'def ' , $ result [0 ]->s );
11190+
11191+ $ result = $ this ->assertQuery ( "SELECT SUBSTRING('abcdef' FROM 1 FOR 3) AS s " );
11192+ $ this ->assertSame ( 'abc ' , $ result [0 ]->s );
11193+
11194+ $ result = $ this ->assertQuery ( "SELECT SUBSTRING('abcdef' FROM 4) AS s " );
11195+ $ this ->assertSame ( 'def ' , $ result [0 ]->s );
11196+ }
11197+
1118411198 public function testAsdf (): void {
1118511199 $ this ->assertQuery ( 'CREATE TABLE t (key1 INT, key2 INT) ' );
1118611200 $ this ->assertQuery ( 'CREATE UNIQUE INDEX idx_key1_key2 ON t (key1, key2) ' );
Original file line number Diff line number Diff line change @@ -3496,6 +3496,22 @@ private function translate( $node ): ?string {
34963496 return $ this ->translate_runtime_function_call ( $ node );
34973497 case 'functionCall ' :
34983498 return $ this ->translate_function_call ( $ node );
3499+ case 'substringFunction ' :
3500+ $ nodes = $ node ->get_child_nodes ();
3501+ if ( count ( $ nodes ) === 2 ) {
3502+ return sprintf (
3503+ 'SUBSTR(%s, %s) ' ,
3504+ $ this ->translate ( $ nodes [0 ] ),
3505+ $ this ->translate ( $ nodes [1 ] )
3506+ );
3507+ } else {
3508+ return sprintf (
3509+ 'SUBSTR(%s, %s, %s) ' ,
3510+ $ this ->translate ( $ nodes [0 ] ),
3511+ $ this ->translate ( $ nodes [1 ] ),
3512+ $ this ->translate ( $ nodes [2 ] )
3513+ );
3514+ }
34993515 case 'systemVariable ' :
35003516 $ var_ident_type = $ node ->get_first_child_node ( 'varIdentType ' );
35013517 $ type_token = $ var_ident_type ? $ var_ident_type ->get_first_child_token () : null ;
@@ -4116,7 +4132,7 @@ private function translate_runtime_function_call( WP_Parser_Node $node ): string
41164132 case WP_MySQL_Lexer::LEFT_SYMBOL :
41174133 $ nodes = $ node ->get_child_nodes ();
41184134 return sprintf (
4119- 'SUBSTRING (%s, 1, %s) ' ,
4135+ 'SUBSTR (%s, 1, %s) ' ,
41204136 $ this ->translate ( $ nodes [0 ] ),
41214137 $ this ->translate ( $ nodes [1 ] )
41224138 );
You can’t perform that action at this time.
0 commit comments