Skip to content

Zend_Db_Adapter_Db2 limit does not work #1

@ushiday

Description

@ushiday

In the IBM i DB2 environment, when using "order by", the limit method of Zend_Db_Adapter_Db2 does not work in the following code section.(I can't try it with DB2 LUW in my environment)

        /**
         * DB2 does not implement the LIMIT clause as some RDBMS do.
         * We have to simulate it with subqueries and ROWNUM.
         * Unfortunately because we use the column wildcard "*",
         * this puts an extra column into the query result set.
         */
        return "SELECT z2.*
            FROM (
                SELECT ROW_NUMBER() OVER() AS \"ZEND_DB_ROWNUM\", z1.*
                FROM (
                    " . $sql . "
                ) z1
            ) z2
            WHERE z2.zend_db_rownum BETWEEN " . ($offset+1) . " AND " . ($offset+$count);

I think the problem is that ORDER BY is not included in OVER(). I also think this method is especially complicated because the LIMIT,OFFSET function was not implemented in previous versions of DB2, and the method was to emulate it.
Modern versions implement LIMIT,OFFSET, so it may be possible to write it simply. However, this method comes at the expense of some older version users...
Therefore, I will be posting two proposed code patterns in a pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions