]> git.nbdom.net Git - nb.git/commitdiff
lib/php/db/types/pgsql.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 7 Jan 2018 05:48:50 +0000 (05:48 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 7 Jan 2018 05:48:50 +0000 (05:48 +0000)
lib/php/db.php
lib/php/db/table.php
lib/php/db/types/pgsql.php

index 0369108689ce47017ad1115beaba6fc131e6794c..4fd3535f96eded261818d34c40aa9c3f6b511ec9 100644 (file)
@@ -1347,6 +1347,11 @@ class Db extends nb {
                return $str;
   }
 
+  public function like_nocase() {
+    if ($v = $this->conf_type('like_nocase')) return $v;
+               return 'LIKE';
+  }
+
 } # < Class
 
 ?>
index ec53ca03101374d5da2d2d0d3883da29cdc2de5d..6e1f819f944fcc3dc10af8094940b1fe79d02182 100644 (file)
@@ -752,8 +752,11 @@ Class Table extends nb {
         $equal = $m[1];
       }
 
+                       $match = '';
+
       // Regex
       if (strpos($v,'~')===0) {
+                               $match = 'regexp';
         $v = substr($v,1);
         $v = $this->db()->quote($v);
         $equal = ' '.($not ? 'NOT ' : '').$regexp.' ';
@@ -767,7 +770,9 @@ Class Table extends nb {
 
         $v = $this->db()->quote($v);
         if (preg_match('/[_%]/',$v)) {
+                                       $match = 'like';
           $equal = ' '.($not ? 'NOT ' : '').'LIKE ';
+          $equal = ' '.($not ? 'NOT ' : '').$this->db()->like_nocase().' ';
         } else {
           $equal = ($not ? '<> ' : $equal);
         }
@@ -795,7 +800,8 @@ Class Table extends nb {
 # NB 04.01.18       if (preg_match("/(LIKE|$regexp) ..$/","$equal$v") and $field->null) {
 #bye("$equal$v");
       #if (preg_match("/(LIKE|$regexp) ..$/","$equal$v")) {
-      if (preg_match("/^(LIKE|$regexp)$/",trim($equal))) {
+# NB 07.01.18       if (preg_match("/^(LIKE|$regexp)$/",trim($equal))) {
+                       if ($match) {
         if ($field->null) $k = 'COALESCE('.$name.','.$this->db()->quote('').")";
 
       } elseif ($field->extras) {
index f4437970f0c1bf0675a07b43ec790511df6269d2..67166255ccbae7536363df4a9079760fd48e9f39 100644 (file)
@@ -33,6 +33,8 @@ $DB_TYPES['pgsql'] = array (
        return "$name::text";
 },
 
+'like_nocase' => 'ILIKE',
+
 'localFile' => array (getenv('HOME').'/.pgpass','^[^:]+:[^:]+:<D.NAME>:(?P<user>[^:]+):(?<password>[^:]+)'),
 
 'databases' => 'SELECT datname as name,pg_catalog.pg_get_userbyid(datdba) as owner,pg_catalog.pg_encoding_encoding) as encoding, datcollate as "collate",datctype as "Ctype" FROM pg_catalog.pg_database',