public function getSubScope(int $num = null)
    {
        // Resolve an existing scope
        if ($num !== null)
        {
            if (!isset($this->scopes[$num]))
                throw new QueryException("Invalid scope number: $num");
            return $this->scopes[$num];
        }

        $scope = new Parameters($this->driver);

        // Alias most fields
        $scope->params = &$this->params;
        $scope->param_types = &$this->param_types;
        $scope->column_counter = &$this->column_counter;
        $scope->table_counter = &$this->table_counter;
        $scope->scope_counter = &$this->scope_counter;
        $scope->scopes = &$this->scopes;

        // Assign a scope number
        $id = ++$this->scope_counter;
        $scope->parent_scope = $this;
        $scope->scope_id = $id;

        // Store the scope reference
        $this->scopes[$id] = $scope;

        return $scope;
    }