]> git.nbdom.net Git - nb.git/commitdiff
update, add, delete
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 14 Jul 2015 15:16:13 +0000 (16:16 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 14 Jul 2015 15:16:13 +0000 (16:16 +0100)
lib/php/db.php
lib/php/db/table.php

index 07692b939a05533f4ff6e9b2f1314036e6899813..f53e35d84f366b49dede2d5cd45f2bc7f85fbaea 100644 (file)
@@ -11,9 +11,9 @@ require_once(dirname(__FILE__).'/db/table.php');
 require_once(dirname(__FILE__).'/db/field.php');
 if (!defined('DB_ERR_PRINT')) define('DB_ERR_PRINT',false);
 if (!defined('DB_HTML_FORM_BUTTONS')) define('DB_HTML_FORM_BUTTONS',''
-  .'<input type="submit" class="button" value="GO"/>'
-  .'<a class="button" href="#" onclick="return nb.form_clear(this.parentElement)">X</a>'
   .'<input type="submit" class="button" name="edit" value="Add"/>'
+  .'<a class="button" href="#" onclick="return nb.form_clear(this.parentElement)">X</a>'
+  .'<input type="submit" class="button" value="GO"/>'
 );
 if (!defined('DB_HTML_BUTTON_ADD'))    define('DB_HTML_BUTTON_ADD','<input type="submit" class="button" name="edit" value="Add"/>');
 if (!defined('DB_HTML_BUTTON_SUBMIT')) define('DB_HTML_BUTTON_SUBMIT','<input type="submit" class="button" value="GO"/>');
@@ -43,8 +43,8 @@ class db {
       $this->conn = new PDO($db['conn']);
       if (DB_ERR_PRINT) $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     } catch (PDOException $e) {
-      err($e->getMessage(), "connecthrsedb");
-      return $e;
+      err($e->getMessage(), "Db.new()");
+      return false;
     }
 
     #if (empty($this->name)) $this->name = preg_replace('/^(?:(?:sqlite:.*(.*?)(\.\w+)?)|(?:.*?dbname=([^;]+).*?))$/','\1',$db['conn']);
index 5e721ba51afcf001173ad011c67f948f5059e9a1..c30ac2929825f6a124890bcb788928dba5832bee 100644 (file)
@@ -81,10 +81,11 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
       foreach ($rows as $row) {
 
         $this->fields[$row['name']] = array(
-          'extra' => null,
-          'type' => null,
-          'default' => null,
-          'key' => null,
+          'extra'         => null,
+          'type'          => null,
+          'default'       => null,
+          'key'           => null,
+          'autoincrement' => false,
         );
 
         $this->fields[$row['name']]['type'] = $row['type'];
@@ -771,9 +772,12 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
     if (!$where) return 0;
     $sql = 'DELETE FROM ' . $this->sql_name() . $where;
     debug($sql);
-    $execute = $this->db->query($sql);
-    if (!$execute) return err('PDO::errorInfo(): ' .join(' ', $this->db->conn->errorInfo()) .PHP_EOL);
-    return $execute;
+    try {
+      $this->db->query($sql);
+    } catch (PDOException $e) {
+      return err($e->getMessage(), "Table.delete()");
+    }
+    return true;
   }
 
 }