mssql 分页错误 #166

Closed
qiangxue opened this Issue Feb 15, 2012 · 0 comments

Comments

Projects
None yet
2 participants
Owner

qiangxue commented Feb 15, 2012

共4条,每页3条,第2页应该只显示第4条才对,但是会显示3条。

经过查找发现源码是错误的,谁修正,mssql这样写最后一页有问题的 永远会取limit条
framework\db\schema\mssql\CMssqlCommandBuilder.php
protected function rewriteLimitOffsetSql($sql, $limit, $offset)
{
$fetch = $limit+$offset;
$sql = preg_replace('/^([\s(])_SELECT( DISTINCT)?(?!\s_TOP\s*()/i',"\1SELECT\2 TOP $fetch", $sql);
$ordering = $this->findOrdering($sql);
$orginalOrdering = $this->joinOrdering($ordering, '[outer]');
$reverseOrdering = $this->joinOrdering($this->reverseDirection($ordering), '[inner]');
$sql = "SELECT * FROM (SELECT TOP {$limit} * FROM ($sql) as [inner] {$reverseOrdering}) as [outer] {$orginalOrdering}";
return $sql;
}

Migrated from http://code.google.com/p/yii/issues/detail?id=2864


earlier comments

qiang.xue said, at 2012-01-01T03:36:54.000Z:

set for 1.1.10 milestone

@ghost ghost assigned qiangxue Mar 9, 2012

@samdark samdark closed this Nov 17, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment