]> git.nbdom.net Git - nb.git/commitdiff
postgres regexp
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 16 Aug 2016 14:27:33 +0000 (16:27 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 16 Aug 2016 14:27:33 +0000 (16:27 +0200)
lib/php/db/table.php
lib/php/db/types/pgsql.php

index 08d098c4d2a71cefba67437668bb0a144d871da1..dd221e6722ac8042c206e0f2c26315f12f68f4a7 100644 (file)
@@ -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('').")";
       }
 
index 1a6e31e3f86177f8964382444ffc3bb45296f57b..e5623185e7b392bd2f78ff06239ab534d0083aa5 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 $DB_TYPES['pgsql'] = array (
 'extra_where' => 'denorm',
+'regexp' => '~',
 
 'localFile' => array (getenv('HOME').'/.pgpass','^[^:]+:[^:]+:<NAME>:(?P<user>[^:]+):(?<password>[^:]+)'),