public function execute($query) { // Selects if ($query->type == 'select') { $data = $this->db->query(DingoSQL::build_select($query, $this->db->driver), $this->_orm); // Combos if (!empty($query->_combos)) { $r = 0; foreach ($data as $row) { foreach ($query->_combos as $combo) { // No Limit if (!$combo['limit']) { $data[$r][$combo['key']] = $this->db->table($combo['table'])->select($combo['where'][0], $combo['where'][1], $row[$combo['where'][2]]); } else { $data[$r][$combo['key']] = $this->db->table($combo['table'])->select('*')->where($combo['where'][0], $combo['where'][1], $row[$combo['where'][2]])->limit($combo['limit'])->execute(); } } $r++; } } } elseif ($query->type == 'count') { $tmp = $this->db->query(DingoSQL::build_count($query, $this->db->driver)); $data = $tmp[0]->num; } elseif ($query->type == 'update') { $data = $this->db->query(DingoSQL::build_update($query, $this->db->driver)); } elseif ($query->type == 'delete') { $data = $this->db->query(DingoSQL::build_delete($query, $this->db->driver)); } return $data; }
static function build_distinct($cols, $table, $driver) { $tick = DingoSQL::backtick($driver); if ($cols[0] == '*') { return "SELECT DISTINCT * FROM {$tick}{$table}{$tick}"; } else { return "SELECT DISTINCT {$tick}" . implode("{$tick},{$tick}", $cols) . "{$tick} FROM {$tick}{$table}{$tick}"; } }