File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11231,4 +11231,18 @@ public function testVersionFunction(): void {
1123111231 $ result = $ this ->engine ->query ( 'SELECT VERSION() ' );
1123211232 $ this ->assertSame ( '8.0.38 ' , $ result [0 ]->{'VERSION() ' } );
1123311233 }
11234+
11235+ public function testSubstringFunction (): void {
11236+ $ result = $ this ->assertQuery ( "SELECT SUBSTRING('abcdef', 1, 3) AS s " );
11237+ $ this ->assertSame ( 'abc ' , $ result [0 ]->s );
11238+
11239+ $ result = $ this ->assertQuery ( "SELECT SUBSTRING('abcdef', 4) AS s " );
11240+ $ this ->assertSame ( 'def ' , $ result [0 ]->s );
11241+
11242+ $ result = $ this ->assertQuery ( "SELECT SUBSTRING('abcdef' FROM 1 FOR 3) AS s " );
11243+ $ this ->assertSame ( 'abc ' , $ result [0 ]->s );
11244+
11245+ $ result = $ this ->assertQuery ( "SELECT SUBSTRING('abcdef' FROM 4) AS s " );
11246+ $ this ->assertSame ( 'def ' , $ result [0 ]->s );
11247+ }
1123411248}
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