From: Nicolas Boisselier Date: Mon, 4 Dec 2017 18:12:28 +0000 (+0000) Subject: lib/php/db.php X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=ec33a2ee121be29c4919165c018e1803c08d1c54;p=nb.git lib/php/db.php --- diff --git a/lib/php/db.php b/lib/php/db.php index a6222a36..b65d3caa 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -1016,6 +1016,7 @@ class Db extends nb { } #bye($this->db()->type); + if ($type_from == 'mysql') $views = []; # Mysql store sql create view in mysql format wich only works with mysql foreach (array_merge($tables,$views) as $t) { # DROP / CREATE diff --git a/lib/php/db/field.php b/lib/php/db/field.php index 95316907..4424078c 100644 --- a/lib/php/db/field.php +++ b/lib/php/db/field.php @@ -215,7 +215,9 @@ class field extends nb { if (strpos($this->type,'date') !== false) return 'NULL'; } - if (!($db = $this->db())) return "'".preg_replace("/'/","''",$value)."'"; + if (!($db = $this->db())) return "'".str_replace("'","''",$value)."'"; + + if ($fct=$db->conf_type('quote_field')) return $fct($value); return $db->quote($value); } else { diff --git a/lib/php/db/types/pgsql.php b/lib/php/db/types/pgsql.php index ff74038b..703df8d9 100644 --- a/lib/php/db/types/pgsql.php +++ b/lib/php/db/types/pgsql.php @@ -2,13 +2,19 @@ $DB_TYPES['pgsql'] = array ( 'extra_where' => 'denorm', 'regexp' => '~', -# NB 04.12.17 'quote_name' => '"', +# 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; +}, 'localFile' => array (getenv('HOME').'/.pgpass','^[^:]+:[^:]+::(?P[^:]+):(?[^:]+)'),