From 3703c26eed172a34be49329107d7f4cdc1ad15fb Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Sun, 7 Jan 2018 05:58:28 +0000 Subject: [PATCH] www/dbq/dbq.php --- lib/php/db.php | 6 ++++++ lib/php/db/table.php | 14 +++++--------- lib/php/db/types/pgsql.php | 22 +++------------------- 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/lib/php/db.php b/lib/php/db.php index 4fd3535f..5d706db4 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -762,6 +762,12 @@ class Db extends nb { if (empty($params['name'])) $dbs[$db]['name'] = $db; if (empty($params['id'])) $dbs[$db]['id'] = $db; + # Ignore incomplete + if (empty($params['type'])) { + unset($dbs[$db]); + continue; + } + foreach ($default as $k=>$v) if (!isset($params[$k])) $dbs[$db][$k] = $v; } diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 6e1f819f..96aae863 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -771,7 +771,7 @@ Class Table extends nb { $v = $this->db()->quote($v); if (preg_match('/[_%]/',$v)) { $match = 'like'; - $equal = ' '.($not ? 'NOT ' : '').'LIKE '; +# NB 07.01.18 $equal = ' '.($not ? 'NOT ' : '').'LIKE '; $equal = ' '.($not ? 'NOT ' : '').$this->db()->like_nocase().' '; } else { $equal = ($not ? '<> ' : $equal); @@ -797,17 +797,13 @@ Class Table extends nb { $name = $field->sql_name(); if (!preg_match('/^(char|varchar|text|blog)/i',$field->type)) $name = $field->sql_name_cast_text(); -# NB 04.01.18 if (preg_match("/(LIKE|$regexp) ..$/","$equal$v") and $field->null) { -#bye("$equal$v"); - #if (preg_match("/(LIKE|$regexp) ..$/","$equal$v")) { -# 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) { + if ($field->extras) { $k = $this->extras[$k]->sql_name(); # NB 04.01.18 } elseif ($field->numeric() and $field->null) { + } elseif ($match) { + if ($field->null) $k = 'COALESCE('.$name.','.$this->db()->quote('').")"; + } elseif ($field->numeric()) { $name = $field->sql_name(); if ($field->null) $k = 'COALESCE('.$name.",0)"; diff --git a/lib/php/db/types/pgsql.php b/lib/php/db/types/pgsql.php index 67166255..0837a2e0 100644 --- a/lib/php/db/types/pgsql.php +++ b/lib/php/db/types/pgsql.php @@ -13,27 +13,11 @@ $DB_TYPES['pgsql'] = array ( $sql .= ' SET ' . join(',',$table->ar_map('"$a=:$a"',array_keys($others))); #$info['debug'] = [$keys,$others]; }, +'like_nocase' => 'ILIKE', +'cast_text' => function($name) { return "$name::text"; }, 'extra_where' => 'denorm', 'regexp' => '~', -# NB 04.12.17: Overwrite db->quote because of bugs with INSERT INTO -# NB 04.12.17 'quote_name' => '"', -# NB 04.12.17 'quote' => function($str) { -# NB 04.12.17 global $DB_TYPES; -# NB 04.12.17 $chr = $DB_TYPES['pgsql']['quote_name']; -# NB 04.12.17 str_replace($chr,$chr.$chr,$str); -# NB 04.12.17 return $chr . $str . $chr; -# NB 04.12.17 }, -'quote_field' => function($str) { - $chr = "'"; - $str = str_replace($chr,$chr.$chr,$str); - return $chr . $str . $chr; -}, - -'cast_text' => function($name) { - return "$name::text"; -}, - -'like_nocase' => 'ILIKE', +'quote_field' => function($str) { $chr = "'"; $str = str_replace($chr,$chr.$chr,$str); return $chr . $str . $chr; }, 'localFile' => array (getenv('HOME').'/.pgpass','^[^:]+:[^:]+::(?P[^:]+):(?[^:]+)'), -- 2.47.3