ZF-10858: limit()'s workaround for pdo_mssql generates invalid query when sorting by columns not selected


i guess it's a very specific need of mine. for avoiding data overload at some point i query only for records' ids sorted by other descriptive field. all that in a pagination context. the code can be summarized as follows:

$table = new My_Table(); $select = $table->select(false); $select->from($table, 'id_field'); $select->order('description_field'); $select->limit(20, 10); $statement = $select->query(); # crashes here

as i'm using pdo_mssql adapter and it has a workaround for the limit() method, the generated query is this:

SELECT * FROM ( __SELECT TOP 20 * FROM ( ____SELECT TOP 30 "my_table"."id_field" FROM "my_table" ORDER BY "description_fied" ASC __) AS inner_tbl __ORDER BY "my_table" DESC ) AS outer_tbl ORDER BY "description_field" ASC

the inner_tbl has only "id_field" and the outermost select tries to order by "description_field".

the simplest workaround is to select both id and description fields but it would be great to see this bug fixed in the framework.

thanks in advance.


No comments to display