From: Nicolas Boisselier Date: Sun, 7 Jan 2018 05:48:50 +0000 (+0000) Subject: lib/php/db/types/pgsql.php X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=060957f2ab29d2df9a7bd32e1bd8166aa51cfe19;p=nb.git lib/php/db/types/pgsql.php --- diff --git a/lib/php/db.php b/lib/php/db.php index 03691086..4fd3535f 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -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 ?> diff --git a/lib/php/db/table.php b/lib/php/db/table.php index ec53ca03..6e1f819f 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -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) { diff --git a/lib/php/db/types/pgsql.php b/lib/php/db/types/pgsql.php index f4437970..67166255 100644 --- a/lib/php/db/types/pgsql.php +++ b/lib/php/db/types/pgsql.php @@ -33,6 +33,8 @@ $DB_TYPES['pgsql'] = array ( return "$name::text"; }, +'like_nocase' => 'ILIKE', + 'localFile' => array (getenv('HOME').'/.pgpass','^[^:]+:[^:]+::(?P[^:]+):(?[^:]+)'), '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',