]> git.nbdom.net Git - nb.git/commitdiff
replace
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 15 Aug 2016 21:30:33 +0000 (23:30 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 15 Aug 2016 21:30:33 +0000 (23:30 +0200)
lib/php/db/table.php

index e8932f992e6b5b97162ee22f9f2e7d81be117550..edf0a0081a57dd4f0ffc64d03789fcbe107d006b 100644 (file)
@@ -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('&amp;','&',$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());