From eb37190fbe14944f34fe7d722dfbfc0985000e38 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Mon, 19 Dec 2016 16:14:32 +0000 Subject: [PATCH] update not working, using replace --- lib/php/db.php | 5 ++++- lib/php/db/table.php | 9 +++++++-- www/dbq/dbq.php | 9 +++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/php/db.php b/lib/php/db.php index 7aabfe23..3f614c1b 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -298,7 +298,7 @@ class Db extends nb { } #try { - foreach ($this->sql_pre() as $s) { $this->conn->exec($s); } + #foreach ($this->sql_pre() as $s) { $this->conn->exec($s); } $this->method('connect'); #} catch (PDOException $e) { #return false; @@ -309,6 +309,9 @@ class Db extends nb { public function disconnect() { if (empty($this->conn)) return null; +# NB 19.12.16 foreach ((array)$this->method('sql.post') as $s) { +# NB 19.12.16 $r = $this->conn->exec($s); +# NB 19.12.16 } $this->method('disconnect'); # NB 09.09.16 return $this->conn->close(); } diff --git a/lib/php/db/table.php b/lib/php/db/table.php index f9451f0c..188902bd 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -1446,6 +1446,7 @@ Class Table extends nb { return $this->db()->exec($sql,$values); return $this->db()->exec($sql); } + # dbq t=nb.mime_type a=table.update type=application/rss+xml name='RSS - Really Simple Syndication' ext=rss debug=2 public function update($hvalues,&$info=[]) { if (empty($info['values'])) $info['values'] = []; @@ -1479,9 +1480,11 @@ Class Table extends nb { } } + $info['keys'] = array_combine($keys,$keys_values); if (empty($fields)) $this->bye("Missing keys!"); + if (empty($keys)) { $this->bye("Missing keys!"); $keys = $fields; @@ -1504,6 +1507,7 @@ Class Table extends nb { #debug("$name: ".$hvalues[$name]); $row = [ $name => $hvalues[$name] ]; $this->db()->table_row_encrypt($this,$row); + #debug($this->db()->status()); $field->bindParam($query,$row[$name],":$name"); } @@ -1513,7 +1517,7 @@ Class Table extends nb { } #return $sql; - #bye($sql); + #bye($info); if (self::p('debug')) { $this->debug($info,1); return false; @@ -1525,8 +1529,9 @@ Class Table extends nb { } $info['rowCount'] = $query->rowCount(); + #bye($this->db()->row("SELECT value FROM crypt WHERE id='zaza'")); #bye($info); - return true; + #return true; #debug($execute); return $query->rowCount(); diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index 50e09e25..90fbbe2b 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -518,15 +518,16 @@ table.rows th, table.rows td { border-color: '.$this->colors['body-border'].'; } $this->page($this,'table_html_edit'); } elseif ($action == 'insert' and $this->perm >= self::WRITE) { - if (!$this->table->insert($_POST)) $this->error('insert'); + if (!$this->table->insert($_POST,$info)) $this->error('insert: '.print_r($info,true)); header('Location: '.$this->table->base); } elseif ($action == 'update' and $this->perm >= self::WRITE) { - if (!$this->table->update($_POST)) $this->error('update'); + # NB 19.12.16: TODO NOT WORKING using replace + if (!$this->table->replace($_POST,$info)) $this->error('update: '.print_r($info,true)); header('Location: '.$this->table->base); } elseif ($action == 'rm' and $this->perm >= self::DELETE) { - if (!$this->table->delete($_POST)) $this->error('rm'); + if (!$this->table->delete($_POST,$info)) $this->error('rm: '.print_r($info,true)); header('Location: '.$this->table->base); @@ -535,7 +536,7 @@ table.rows th, table.rows td { border-color: '.$this->colors['body-border'].'; } } - return false; + return true; } } -- 2.47.3