mirror of
https://github.com/PostgreSQL-For-Wordpress/postgresql-for-wordpress.git
synced 2025-07-29 17:27:13 +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...
|
// Handle COUNT(*)...ORDER BY...
|
||||||
$sql = preg_replace('/COUNT(.+)ORDER BY.+/s', 'COUNT$1', $sql);
|
$sql = preg_replace('/COUNT(.+)ORDER BY.+/s', 'COUNT$1', $sql);
|
||||||
|
|
||||||
|
// HANDLE REGEXP
|
||||||
|
$sql = preg_replace('/REGEXP/', '~', $sql);
|
||||||
|
|
||||||
// In order for users counting to work...
|
// In order for users counting to work...
|
||||||
$matches = array();
|
$matches = array();
|
||||||
if(preg_match_all('/COUNT[^C]+\),/', $sql, $matches)) {
|
if(preg_match_all('/COUNT[^C]+\),/', $sql, $matches)) {
|
||||||
|
@ -743,8 +743,19 @@ final class rewriteTest extends TestCase
|
|||||||
$this->assertSame(trim($expected), trim($postgresql));
|
$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