Skip to content

Commit

Permalink
Fixed issue #18102: Export Duplicate entries in the Excel Form (#2673)
Browse files Browse the repository at this point in the history
Dev: replace rewriteLimitOffsetSql for SQL SERVER up to 11
Dev: inspiration by Yii2
  • Loading branch information
Shnoulle committed Oct 24, 2022
1 parent 9cd57df commit 5f7030c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
36 changes: 36 additions & 0 deletions application/core/db/MssqlCommandBuilder.php
@@ -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;
}
}
10 changes: 10 additions & 0 deletions application/core/db/MssqlSchema.php
Expand Up @@ -84,4 +84,14 @@ function ($column) {
implode(', ', $columns)
);
}

/**
* @inheritdoc
* replace by own to fix new MSSQL issue
* @see https://github.com/yiisoft/yii2/blob/364e907875fd57ee218085cca796ac5d1c3c8d51/framework/db/mssql/QueryBuilder.php#L73
*/
protected function createCommandBuilder()
{
return new MssqlCommandBuilder($this);
}
}

0 comments on commit 5f7030c

Please sign in to comment.