db = $db; parent::__construct(); } /** * * @param \Phacil\Framework\MagiQL\Api\QueryInterface $obj * @return \Phacil\Framework\Databases\Api\Object\ResultInterface|true * @throws \Phacil\Framework\MagiQL\Builder\BuilderException * @throws \Phacil\Framework\Exception */ public function execute(\Phacil\Framework\MagiQL\Api\QueryInterface $obj) { $query = $this->write($obj); $values = $this->getValues(); return $this->db->execute($query, $values); } /** * * @return \Phacil\Framework\Api\Database */ public function getDb() { return $this->db; } /** * @param string $tableName * @return bool * @throws \Phacil\Framework\Exception */ public function isTableExists($tableName) { switch ($this->db->getDBTypeId()) { case DatabaseDriverInterface::LIST_DB_TYPE_ID['MYSQL']: $sql = 'SELECT (1) AS tbl_exists FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = :v1 AND TABLE_SCHEMA = :v2'; $result = $this->db->execute($sql, [ ':v1' => $tableName, ':v2' => \Phacil\Framework\Config::DB_DATABASE() ]); break; case DatabaseDriverInterface::LIST_DB_TYPE_ID['MSSQL']: $sql = "SELECT OBJECT_ID(:v1, 'U') AS table_id"; $result = $this->db->execute($sql, [ ':v1' => $tableName ]); break; case DatabaseDriverInterface::LIST_DB_TYPE_ID['POSTGRE']: $sql = "SELECT 1 FROM information_schema.tables WHERE table_name = :v1"; $result = $this->db->execute($sql, [ ':v1' => $tableName ]); break; case DatabaseDriverInterface::LIST_DB_TYPE_ID['SQLLITE3']: $sql = "SELECT 1 FROM information_schema.tables WHERE table_name = :v1"; $result = $this->db->execute($sql, [ ':v1' => $tableName ]); break; case DatabaseDriverInterface::LIST_DB_TYPE_ID['ORACLE']: $sql = "SELECT table_name FROM all_tables WHERE table_name = :v1 AND owner = :v2"; $result = $this->db->execute($sql, [ ':v1' => $tableName, ':v2' => \Phacil\Framework\Config::DB_DATABASE() ]); break; default: $sql = 'SELECT (1) AS tbl_exists FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = :v1 AND TABLE_SCHEMA = :v2'; $result = $this->db->execute($sql, [ ':v1' => $tableName, ':v2' => \Phacil\Framework\Config::DB_DATABASE() ]); break; } if($result && $result instanceof \Phacil\Framework\Databases\Api\Object\ResultInterface && $result->getNumRows() > 0){ return true; } return false; } }