From fce26f676fe589e66ece75c294d3514905eaec98 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 5 Jul 2016 10:15:37 +0100 Subject: [PATCH] fix bug with virtuals --- bin/dbq | 5 ++--- lib/php/db.php | 6 +++--- lib/php/db/table.php | 10 ++++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/bin/dbq b/bin/dbq index 6078e1fd..c87a723d 100755 --- a/bin/dbq +++ b/bin/dbq @@ -241,14 +241,11 @@ sub csv2txt { my @lines = (); my $l; - #open(STDOUT,">&2"); # # Store lines and lengths in memory # while (<>) { - #print $_; next; chomp($_); - #warn $_; my @F = split($sep,$_); for (my $i=0;$i<@F;$i++) { @@ -286,6 +283,8 @@ sub csv2txt { my $format = "| ".join(" | ",map {$t+=$_+3; "\%-".$_."s"} @len)." |".chr(10); my $sep_line = "+".join("+",map {("-"x($_+2))} @len)."+".chr(10); my $tot = @lines - ($noheader ? 0 : 1); + #use Data::Dumper; warn Dumper(\@lines); + exit unless $tot; print $sep_line; diff --git a/lib/php/db.php b/lib/php/db.php index b7a41823..99c5ae01 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -81,10 +81,10 @@ class Db extends nb { # Virtual - NB 04.07.16 foreach ($tables as $name => $t) { if (empty($t['sql'])) continue; - $sql = $t['sql']; unset($t['sql']); + #$sql = $t['sql']; unset($t['sql']); $t = $this->table($name,$t); - $t->sql = $sql; - $this->tables[] = $t; + #$t->sql = $sql; + $this->tables[$name] = $t; } } diff --git a/lib/php/db/table.php b/lib/php/db/table.php index a44e5279..ebf2b599 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -55,9 +55,10 @@ Class Table extends nb { // Extras - We dont want to affect $this // Type + $sql = ''; if (isset($opt['sql'])) { - unset($opt['type']); - $this->type = 'sql'; + $sql = $opt['sql']; unset($opt['sql']); + $this->type = 'sql'; unset($opt['type']); } // Extras @@ -103,6 +104,7 @@ Class Table extends nb { bye("Query not Allowed !"); } + if ($sql) $this->sql = $sql; # from $opt['sql'] # NB 29.03.16 return $this->fields(); } @@ -255,7 +257,7 @@ Class Table extends nb { public function fields($name=null) { #if (!empty($this->sql)) return []; # Virtual - NB 04.07.16 - if ($this->type == 'sql') return []; # Virtual - NB 04.07.16 + #if ($this->type == 'sql') return []; # Virtual - NB 04.07.16 if (!isset($this->fields)) { $this->fields = array(); @@ -303,7 +305,7 @@ Class Table extends nb { } - if (empty($this->fields)) bye("Table `".$this->name."` does not exists"); + #if (empty($this->fields)) bye("Table `".$this->name."` does not exists"); } # < $this->fields -- 2.47.3