From: Nicolas Boisselier Date: Mon, 15 Aug 2016 21:30:33 +0000 (+0200) Subject: replace X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=aea02ef42bcc4de72d6fcc9bbc5f5064a3ea559e;p=nb.git replace --- diff --git a/lib/php/db/table.php b/lib/php/db/table.php index e8932f99..edf0a008 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -1178,7 +1178,11 @@ Class Table extends nb { return $this->db()->sql_name($value === null ? $this->name : $value); } - public function insert($hvalues,&$info=array()) { + public function replace($hvalues,&$info=array()) { + return $this->insert($hvalues,$info,'REPLACE'); + } + + public function insert($hvalues,&$info=array(),$insert_word='INSERT') { if (empty($info['values'])) $info['values'] = array(); $info['values'] = $hvalues; @@ -1194,7 +1198,7 @@ Class Table extends nb { } $sql = - 'INSERT INTO '. $this->sql_name() . ' (' . join(',',array_values($sql_names)).')' + $insert_word.' INTO '. $this->sql_name() . ' (' . join(',',array_values($sql_names)).')' #.' VALUES (' . join(',',$values).')' .' VALUES (' . join(',',ar_map('":$a"',array_keys($fields))) . ')' ; @@ -1393,6 +1397,12 @@ Class Table extends nb { header('Location: '.$this->url_referer(str_replace('&','&',$this->url_list()))); return true; + } elseif ($action == 'table.replace' or $action == 'replace') { + if (!$this->replace($this->p(),$e)) bye($e); + header('Location: '.$this->url_referer()); + $this->out($e); + return true; + } elseif ($action == 'table.insert' or $action == 'insert') { if (!$this->insert($this->p(),$e)) bye($e); header('Location: '.$this->url_referer());