From d64ca37e4030f445754678542c15e9e3274c9cd5 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Wed, 22 Jun 2016 17:51:26 +0200 Subject: [PATCH] table as sql --- etc/dbs/rent.php | 6 +++++- lib/php/db.php | 4 ---- lib/php/db/table.php | 12 +++++++----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/etc/dbs/rent.php b/etc/dbs/rent.php index e95fff81..9d2c81e3 100644 --- a/etc/dbs/rent.php +++ b/etc/dbs/rent.php @@ -18,6 +18,10 @@ $CONF['_rent'] = array( 'row_parse_post' => 'tenant_doc', ), + 'test' => array( + 'sql' => 'SELECT 1', + ), + 'rent' => array( 'orderby' => 'start desc, end desc', #'replace' => [ 'idtenant' => 'tenant.name', 'idplace' => 'addr.addr' ], @@ -58,7 +62,7 @@ $CONF['_rent'] = array( $CONF['rent'] = array ( 'order' => 5, 'pdo' => 'sqlite:/opt/rent/rent.db', - #'_import' => '_nb', + '_import' => '_rent', ); return 1; diff --git a/lib/php/db.php b/lib/php/db.php index b0f7ab4c..05596e46 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -527,9 +527,6 @@ class Db extends nb { } if (!$dbs) return false; - #if (! ($dbs = $Db->conf_dbs($conf)) ) return false; - #bye($dbs['nb']); - #die (nb::p('db')); # Param - Default base on order hight num value if (!$Db->p('db')) { @@ -545,7 +542,6 @@ class Db extends nb { 'dbs'=>array_keys($dbs), 'conf'=>$dbs, )); - #bye($Db->p('db')); $Db->__construct($db); diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 862de71e..086ecd21 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -84,11 +84,13 @@ Class Table extends nb { // Name, could be a select if (DB_TABLE_QUERY_NAME and stripos($this->name,'SELECT ')===0) { - #$temp = '_'.substr(md5($this->name),0,6); - $temp = DB_TABLE_QUERY_NAME; - #bye("CREATE TEMPORARY VIEW $temp AS $this->name"); - $this->db()->conn->query("CREATE TEMPORARY TABLE $temp AS $this->name"); - $this->name = $temp; + $this->db()->conn->query("CREATE 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)) { + $this->db()->conn->query("CREATE TEMPORARY TABLE ".DB_TABLE_QUERY_NAME." AS $this->sql"); + $this->name = DB_TABLE_QUERY_NAME; } 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