mirror of
https://github.com/PostgreSQL-For-Wordpress/postgresql-for-wordpress.git
synced 2025-06-25 09:21:44 +02:00
replace regexp with its postgres version
This commit is contained in:
@ -65,6 +65,9 @@ class SelectSQLRewriter extends AbstractSQLRewriter
|
||||
// Handle COUNT(*)...ORDER BY...
|
||||
$sql = preg_replace('/COUNT(.+)ORDER BY.+/s', 'COUNT$1', $sql);
|
||||
|
||||
// HANDLE REGEXP
|
||||
$sql = preg_replace('/REGEXP/', '~', $sql);
|
||||
|
||||
// In order for users counting to work...
|
||||
$matches = array();
|
||||
if(preg_match_all('/COUNT[^C]+\),/', $sql, $matches)) {
|
||||
|
@ -743,8 +743,19 @@ final class rewriteTest extends TestCase
|
||||
$this->assertSame(trim($expected), trim($postgresql));
|
||||
}
|
||||
|
||||
public function test_it_rewrites_regexp()
|
||||
{
|
||||
$sql = <<<SQL
|
||||
SELECT DISTINCT meta_key FROM wp_gf_entry_meta WHERE form_id=2 AND meta_key REGEXP '^[0-9]+(\.[0-9]+)?$'
|
||||
SQL;
|
||||
|
||||
$expected = <<<SQL
|
||||
SELECT DISTINCT meta_key FROM wp_gf_entry_meta WHERE form_id=2 AND meta_key ~ '^[0-9]+(\.[0-9]+)?$'
|
||||
SQL;
|
||||
|
||||
$postgresql = pg4wp_rewrite($sql);
|
||||
$this->assertSame(trim($expected), trim($postgresql));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user