From: root Date: Mon, 7 Aug 2017 23:24:56 +0000 (+0100) Subject: lib/php/db/table.php X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=5c0b504955f7a42ca20214dc702b8659d95dfa02;p=nb.git lib/php/db/table.php --- diff --git a/lib/php/db.php b/lib/php/db.php index 019560ea..9fb9f064 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -330,6 +330,7 @@ class Db extends nb { public function row($sql,$sep=' ') { $query = $this->query($sql); +#bye($sql); $result = $query->fetch(PDO::FETCH_NUM); if (!is_array($result)) return $result; return join($sep,$result); diff --git a/lib/php/db/table.php b/lib/php/db/table.php index a5cf2aad..2f376b4f 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -1888,7 +1888,20 @@ Class Table extends nb { if (isset($this->count)) return $this->count; $sql_count = $this->name; - if (preg_match('/^[\w_-]+$/',$sql_count)) { + + # We could use it instead of query, but wont be cached ! $this->create_temporary(); + if ($this->type == 'sql' and $this->name !== DB_TABLE_QUERY_NAME) { + if (!$this->sql) return; + + $sql_count = "SELECT COUNT(*) FROM ($this->sql) _table_count" ; +# NB 08.08.17 if (preg_match('/SELECT.*SELECT|UNION/i',$this->sql)) { +# NB 08.08.17 $sql_count = "SELECT COUNT(*) FROM ($this->sql) _table_count" ; +# NB 08.08.17 } else { +# NB 08.08.17 $sql_count = "SELECT COUNT(*) FROM ".preg_replace('/^SELECT .*?\s+FROM\s+/','',$this->sql); +# NB 08.08.17 bye($sql_count); +# NB 08.08.17 } + + } elseif (preg_match('/^[\w_-]+$/',$sql_count)) { $sql_count = "SELECT count(*) FROM ".$this->sql_name($sql_count); } else { @@ -2100,7 +2113,7 @@ Class Table extends nb { $sth = $this->db()->conn->query($sql,PDO::FETCH_ASSOC); if (!empty($sth)) $this->status = $sth->fetch(); - } + } # if ($this->type == 'sql') if (empty($this->status)) $this->status = []; @@ -2128,7 +2141,8 @@ Class Table extends nb { 'fields', 'sql', ] as $k) { - if (!empty($this->status[$k])) continue; + if (isset($this->status[$k])) continue; +# NB 08.08.17 if (!empty($this->status[$k])) continue; if (empty($key)) { if (!self::p($k)) continue;