Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public static function register_for( $pdo ): self {
'utc_time' => 'utc_time',
'utc_timestamp' => 'utc_timestamp',
'version' => 'version',
'reverse' => 'reverse',

// Internal helper functions.
'_helper_like_to_glob_pattern' => '_helper_like_to_glob_pattern',
Expand Down Expand Up @@ -929,6 +930,22 @@ public function version() {
return '5.5';
}

/**
* Method to emulate MySQL REVERSE() function.
*
* Takes a string and returns the reverse of it.
*
* @param string|null $str The string to reverse.
*
* @return string|null reversed string, or NULL.
*/
public function reverse( $str ) {
if ( null === $str ) {
return null;
}
return strrev( $str );
}

/**
* A helper to covert LIKE pattern to a GLOB pattern for "LIKE BINARY" support.

Expand Down
14 changes: 14 additions & 0 deletions packages/mysql-on-sqlite/tests/WP_SQLite_Driver_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -12483,4 +12483,18 @@ public function testCreateTableWithDefaultExpressions(): void {
$this->assertSame( "DATETIME(CURRENT_TIMESTAMP, '+' || 1 || ' YEAR')", $result[2]['dflt_value'] );
$this->assertSame( "('a' || 'b')", $result[3]['dflt_value'] );
}

public function testReverseFunction(): void {
// Normal reverse.
$result = $this->assertQuery( "SELECT REVERSE('aoeuidhtns') AS reversed" );
$this->assertSame( 'snthdiueoa', $result[0]->reversed );

// Empty string.
$result = $this->assertQuery( "SELECT REVERSE('') AS reversed" );
$this->assertSame( '', $result[0]->reversed );

// NULL input returns NULL.
$result = $this->assertQuery( 'SELECT REVERSE(NULL) AS reversed' );
$this->assertNull( $result[0]->reversed );
}
}
Loading