// Extras - We dont want to affect $this
// Type
- $sql = '';
if (isset($opt['sql'])) {
- $this->sql = $opt['sql']; unset($opt['sql']);
$this->type = 'sql'; unset($opt['type']);
+ $this->sql = $opt['sql']; unset($opt['sql']);
}
// Extras
// Add others
foreach ($opt as $k => $v) { $this->$k = $v; }
+ }
+
+ /*
+ * Function create_temporary
+ *
+ * Create temporary if needed
+ *
+ */
+ public function create_temporary() {
+ if (!empty($this->_create_temporary)) return;
+ $this->_create_temporary = 1;
+
// Name, could be a select
if (DB_TABLE_QUERY_NAME and stripos($this->name,'SELECT ')===0) {
- $GLOBALS['DB_TABLE_QUERY_ID']++; $name = DB_TABLE_QUERY_NAME . $GLOBALS['DB_TABLE_QUERY_ID'];
- $this->db()->conn->query("CREATE TEMPORARY TABLE $name AS $this->name");
+ #$GLOBALS['DB_TABLE_QUERY_ID']++; $name = DB_TABLE_QUERY_NAME . $GLOBALS['DB_TABLE_QUERY_ID'];
+ $this->db()->conn->query("CREATE TEMPORARY TABLE ".DB_TABLE_QUERY_NAME." AS $this->name");
$this->name = $name;
// Virtual Table
} elseif (DB_TABLE_QUERY_NAME and !empty($this->sql)) {
- $name = $this->name;
- $this->db()->conn->query("CREATE TEMPORARY TABLE $name AS $this->sql");
+ $this->db()->conn->query("CREATE 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 !");
+ } else {
+ return false;
}
+ return true;
}
/*
*/
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
+ $this->create_temporary();
+
if (!isset($this->fields)) {
$this->fields = array();
Html Output
******************************************************************/
public function rows_sql(&$opt=array()) {
+
if (isset($this->orderby)) self::pdef('orderby',$this->orderby);
if (self::p('order')) self::pset('orderby',self::p('orderby').' '.self::p('order')); # from Wordpress
if (self::p('paged')) {
public function rows(&$opt=array(),$opt_by_val=null) {
+ $this->create_temporary();
+
if (empty($this->type) or $this->type != 'table') $this->pset('buttons','0');;
if ($opt_by_val !== null) $opt = $opt_by_val;