-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issue #18102: Export Duplicate entries in the Excel Form (#2673)
Dev: replace rewriteLimitOffsetSql for SQL SERVER up to 11 Dev: inspiration by Yii2
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
/** | ||
* @inheritdoc | ||
* Replace rewriteLimitOffsetSql for SQL server up to 11 | ||
* @version 0.1.0 | ||
*/ | ||
|
||
class MssqlCommandBuilder extends CMssqlCommandBuilder | ||
{ | ||
|
||
/** | ||
* @inheritdoc | ||
* Fixed for new version of MSSQL, issue #18102 | ||
* @see https://github.com/yiisoft/yii2/blob/364e907875fd57ee218085cca796ac5d1c3c8d51/framework/db/mssql/QueryBuilder.php#L73 | ||
*/ | ||
protected function rewriteLimitOffsetSql($sql, $limit, $offset) | ||
{ | ||
if (version_compare(App()->db->getServerVersion(), '11', '<')) { | ||
return parent::rewriteLimitOffsetSql($sql, $limit, $offset); | ||
} | ||
|
||
$ordering = $this->findOrdering($sql); | ||
$orderFix = ""; | ||
if ($ordering === '') { | ||
// ORDER BY clause is required when FETCH and OFFSET are in the SQL | ||
$orderFix = 'ORDER BY (SELECT NULL)'; | ||
} | ||
$sql .= " " . $orderFix; | ||
/* $limit and $offset must be integer > 0 (see CMssqlCommandBuilder->rewriteLimitOffsetSql) | ||
* FETCH need OFFSET >= 0 */ | ||
$sql .= " " . "OFFSET $offset ROWS"; | ||
$sql .= " " . "FETCH NEXT $limit ROWS ONLY"; | ||
return $sql; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters