From: Nicolas Boisselier Date: Tue, 16 Aug 2016 14:27:33 +0000 (+0200) Subject: postgres regexp X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=a7f4d3bfbb01dc7789cd83b285b7bc5c8f3a9842;p=nb.git postgres regexp --- diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 08d098c4..dd221e67 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -539,6 +539,9 @@ Class Table extends nb { $having = $where = array(); if (empty($logic)) $logic = 'AND'; + $regexp = $this->db()->type('regexp'); + if (empty($regexp)) $regexp = 'REGEXP'; + foreach ($this->fields() as $k => $field) { // No empty values @@ -561,7 +564,7 @@ Class Table extends nb { if (strpos($v,'~')===0) { $v = substr($v,1); $v = $this->db()->quote($v); - $equal = ' '.($not ? 'NOT ' : '').'REGEXP '; + $equal = ' '.($not ? 'NOT ' : '').$regexp.' '; // Text } elseif (preg_match('/text|char|blob/',$field->type) @@ -597,7 +600,7 @@ Class Table extends nb { } - if (preg_match('/(LIKE|REGEXP) ..$/',"$equal$v")) { + if (preg_match("/(LIKE|$regexp) ..$/","$equal$v")) { $k = "COALESCE($k,".$this->db()->quote('').")"; } diff --git a/lib/php/db/types/pgsql.php b/lib/php/db/types/pgsql.php index 1a6e31e3..e5623185 100644 --- a/lib/php/db/types/pgsql.php +++ b/lib/php/db/types/pgsql.php @@ -1,6 +1,7 @@ 'denorm', +'regexp' => '~', 'localFile' => array (getenv('HOME').'/.pgpass','^[^:]+:[^:]+::(?P[^:]+):(?[^:]+)'),