From 2b396bf6d3c7a349f5c43a7a17cf73171130dd8c Mon Sep 17 00:00:00 2001 From: Devops Date: Mon, 29 May 2017 19:17:41 +0100 Subject: [PATCH] lib/php/db.php --- lib/php/db.php | 1 + lib/php/db/table.php | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/php/db.php b/lib/php/db.php index 488a24ca..6bb2c40f 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -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'); diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 96c1e91e..beef87e5 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -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 !"); -- 2.47.3