public function attachDatabase($filename, $database = null)
    {
        if ($this->mode != "sqlite") {
            throw new \Exception("You can only attach databases when in sqlite mode");
        }

        if (!$database) {
            $database = pathinfo($filename, PATHINFO_FILENAME);
        }

        $query = "ATTACH DATABASE '" . $filename . "' AS " . $this->quoteTable($database);
        $result = $this->query($query);

        if (!$result) {
            $this->error();
        }

        $this->attached[$database] = $filename;

        return $result;
    }