]> git.nbdom.net Git - nb.git/commitdiff
lib/php/db.php
authorDevops <sys@15gifts.com>
Mon, 29 May 2017 18:17:41 +0000 (19:17 +0100)
committerDevops <sys@15gifts.com>
Mon, 29 May 2017 18:17:41 +0000 (19:17 +0100)
lib/php/db.php
lib/php/db/table.php

index 488a24ca3aadd0329b49aaaffff708b6febeca92..6bb2c40fdfa54373146e7e62a50fcfd68df82094 100644 (file)
@@ -374,6 +374,7 @@ class Db extends nb {
   * Return a table instance
   */
   public function table($name='',$params=[]) {
+    if ( !is_array($params) ) bye('[type=>, sql=>, ...]');
     if (!$name and !empty($this->default_table)) $name = $this->default_table;
     if (!$name) $this->bye('table(): Missing table');
 
index 96c1e91e6490ec57e93766af917cace0ca2a7abc..beef87e5923daf392c8454b5767142917a05efb9 100644 (file)
@@ -125,7 +125,7 @@ Class Table extends nb {
     $fields = array_keys($this->rows[0]);
     $sql_names = $this->sql_names($fields);
 
-    $this->db()->conn->query("CREATE TEMPORARY TABLE $this->name ("
+    $this->db()->conn->query("CREATE ".$this->sql_temporary()." TABLE $this->name ("
       .join(',',$this->ar_map('"$a text"',$sql_names))
     .')');
     $sql = 'INSERT INTO '. $this->sql_name("$this->name")
@@ -165,6 +165,11 @@ Class Table extends nb {
     return true;
   }
 
+  private function sql_temporary() {
+    if ($this->type == 'sqlite') return 'TEMP';
+    return 'TEMPORARY';
+  }
+
   /*
    * Function create_temporary
    *
@@ -179,13 +184,13 @@ Class Table extends nb {
 
     // Name, could be a select
     if (DB_TABLE_QUERY_NAME and stripos($this->name,'SELECT ')===0) {
-      $this->db()->conn->query("CREATE TEMPORARY TABLE ".DB_TABLE_QUERY_NAME." AS $this->name");
+      $this->db()->conn->query("CREATE ".$this->sql_temporary()." TABLE ".DB_TABLE_QUERY_NAME." AS $this->name");
       $this->name = DB_TABLE_QUERY_NAME;
 
     // Virtual Table
     } elseif (DB_TABLE_QUERY_NAME and !empty($this->sql)) {
 # NB 29.12.16 table already exists !!!      if ($this->name) $this->name = DB_TABLE_QUERY_NAME;
-      $this->db()->conn->query("CREATE TEMPORARY TABLE $this->name AS $this->sql");
+      $this->db()->conn->query("CREATE ".$this->sql_temporary()." TABLE $this->name AS $this->sql");
 
     } elseif (preg_match('/\b(\.import|LOAD DATA|COPY|INSERT|REPLACE|DELETE|TRUNCATE|CREATE|DROP|ALERT)\b/',$this->name)) {
       bye("Query not Allowed !");