public function count()
    {

        switch ($this->mode) {

            case "mysql":
                $rows = $this->result->num_rows;
                break;

            case "postgres":
            case "redshift":
                $rows = pg_num_rows($this->result);
                break;

            case "odbc":
                $rows = odbc_num_rows($this->result);

                # The above function is unreliable, so if we got a zero count then double check it
                if ($rows < 1) {
                    $rows = 0;

                    /**
                     * If it is an update/delete then we just have to trust the odbc_num_rows() result,
                     * however it is some kind of select, then we can manually count the rows returned.
                     */
                    if (odbc_num_fields($this->result) > 0) {
                        $position = $this->position;
                        $this->seek(0);
                        while ($this->getNextRow()) {
                            ++$rows;
                        }
                        $this->seek($position);
                    }
                }
                break;

            case "sqlite":
                $rows = 0;
                while ($this->result->fetchArray()) {
                    $rows++;
                }
                $this->seek($this->position);
                break;

            case "mssql":
                $rows = mssql_num_rows($this->result);
                break;

            case "mssqlsrv":
                $rows = sqlsrv_num_rows($this->result);
                break;
        }

        if ($rows === false || $rows < 0) {
            throw new \Exception("Failed to get the row count from the result set");
        }

        return $rows;
    }