Skip to content

Commit

Permalink
Fixed issue #18420: Different behaviour on grid between MSSQL and Mar…
Browse files Browse the repository at this point in the history
…iaDB (#3158)
  • Loading branch information
Shnoulle committed May 23, 2023
1 parent 5ad41fe commit f2116bf
Show file tree
Hide file tree
Showing 85 changed files with 8,628 additions and 8,627 deletions.
2 changes: 1 addition & 1 deletion framework/.htaccess
Original file line number Diff line number Diff line change
@@ -1 +1 @@
deny from all
deny from all
2 changes: 1 addition & 1 deletion framework/YiiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class YiiBase
*/
public static function getVersion()
{
return '1.1.26';
return '1.1.28';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion framework/caching/CFileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected function getValue($key)
{
$cacheFile=$this->getCacheFile($key);
if(($time=$this->filemtime($cacheFile))>time())
return @file_get_contents($cacheFile,false,null,$this->embedExpiry ? 10 : null);
return @file_get_contents($cacheFile,false,null,$this->embedExpiry ? 10 : 0);
elseif($time>0)
@unlink($cacheFile);
return false;
Expand Down
5 changes: 4 additions & 1 deletion framework/caching/CRedisCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ private function byteLength($str)
*/
protected function getValue($key)
{
return $this->executeCommand('GET',array($key));
$value=$this->executeCommand('GET',array($key));
if ($value===null)
return false;
return $value;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion framework/cli/views/webapp/assets/git-gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*
*
!.gitignore
14 changes: 7 additions & 7 deletions framework/cli/views/webapp/hg-hgignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax: glob
syntax: regexp
# ignore all except .hgkeep
^assets/(?!.*\.hgkeep$).+
^protected/runtime/(?!.*\.hgkeep$).+
^protected/tests/report/(?!.*\.hgkeep$).+
syntax: glob

syntax: regexp
# ignore all except .hgkeep
^assets/(?!.*\.hgkeep$).+
^protected/runtime/(?!.*\.hgkeep$).+
^protected/tests/report/(?!.*\.hgkeep$).+
2 changes: 1 addition & 1 deletion framework/cli/views/webapp/protected/.htaccess
Original file line number Diff line number Diff line change
@@ -1 +1 @@
deny from all
deny from all
2 changes: 1 addition & 1 deletion framework/cli/views/webapp/protected/runtime/git-gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*
*
!.gitignore
2 changes: 1 addition & 1 deletion framework/cli/views/webapp/protected/tests/WebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class WebTestCase extends CWebTestCase
* Sets up before each test method runs.
* This mainly sets the base URL for the test application.
*/
protected function setUp(): void
protected function setUp()
{
parent::setUp();
$this->setBrowserUrl(TEST_BASE_URL);
Expand Down
2 changes: 1 addition & 1 deletion framework/cli/views/webapp/protected/views/site/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
</ul>

<p>For more details on how to further develop this application, please read
the <a href="httpss://www.yiiframework.com/doc/">documentation</a>.
the <a href="https://www.yiiframework.com/doc/">documentation</a>.
Feel free to ask in the <a href="https://www.yiiframework.com/forum/">forum</a>,
should you have any questions.</p>
8 changes: 4 additions & 4 deletions framework/cli/views/webapp/protected/yiic
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env php
<?php

require_once(dirname(__FILE__).'/yiic.php');
#!/usr/bin/env php
<?php

require_once(dirname(__FILE__).'/yiic.php');
30 changes: 15 additions & 15 deletions framework/cli/views/webapp/protected/yiic.bat
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
@echo off

rem -------------------------------------------------------------
rem Yii command line script for Windows.
rem This is the bootstrap script for running yiic on Windows.
rem -------------------------------------------------------------

@setlocal

set BIN_PATH=%~dp0

if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe

"%PHP_COMMAND%" "%BIN_PATH%yiic.php" %*

@echo off

rem -------------------------------------------------------------
rem Yii command line script for Windows.
rem This is the bootstrap script for running yiic on Windows.
rem -------------------------------------------------------------

@setlocal

set BIN_PATH=%~dp0

if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe

"%PHP_COMMAND%" "%BIN_PATH%yiic.php" %*

@endlocal
2 changes: 1 addition & 1 deletion framework/cli/views/webapp/themes/classic/views/.htaccess
Original file line number Diff line number Diff line change
@@ -1 +1 @@
deny from all
deny from all
21 changes: 12 additions & 9 deletions framework/db/schema/CDbCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,21 @@ public function __wakeup()
{
$map=array();
$params=array();
foreach($this->params as $name=>$value)
if(is_array($this->params))
{
if(strpos($name,self::PARAM_PREFIX)===0)
foreach($this->params as $name=>$value)
{
$newName=self::PARAM_PREFIX.self::$paramCount++;
$map[$name]=$newName;
}
else
{
$newName=$name;
if(strpos($name,self::PARAM_PREFIX)===0)
{
$newName=self::PARAM_PREFIX.self::$paramCount++;
$map[$name]=$newName;
}
else
{
$newName=$name;
}
$params[$newName]=$value;
}
$params[$newName]=$value;
}
if (!empty($map))
{
Expand Down
83 changes: 57 additions & 26 deletions framework/db/schema/mssql/CMssqlCommandBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,32 @@ public function applyJoin($sql,$join)
}

/**
* Apply limit and offset to sql query
* @param string $sql SQL query string.
* @param integer $limit maximum number of rows, -1 to ignore limit.
* @param integer $offset row offset, -1 to ignore offset.
* @return string SQL with limit and offset.
* @see https://github.com/yiisoft/yii/issues/4491
*/
public function applyLimit($sql, $limit, $offset)
{
$limit = $limit!==null ? (int)$limit : -1;
$offset = $offset!==null ? (int)$offset : -1;

if($limit <= 0 && $offset <=0) // no limit, no offset
return $sql;
if($limit > 0 && $offset <= 0) // only limit
return preg_replace('/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i',"\\1SELECT\\2 TOP $limit", $sql);

if(version_compare($this->dbConnection->getServerVersion(), '11', '<'))
return $this->oldRewriteLimitOffsetSql($sql, $limit, $offset);
else
return $this->newRewriteLimitOffsetSql($sql, $limit, $offset);
}

/**
* Rewrite sql to apply $limit and $offset for MSSQL database version 10 (2008) and lower.
*
* This is a port from Prado Framework.
*
* Overrides parent implementation. Alters the sql to apply $limit and $offset.
Expand Down Expand Up @@ -185,36 +211,18 @@ public function applyJoin($sql,$join)
* </li>
* </ul>
*
* @param string $sql SQL query string.
* @param integer $limit maximum number of rows, -1 to ignore limit.
* @param integer $offset row offset, -1 to ignore offset.
* @return string SQL with limit and offset.
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
*/
public function applyLimit($sql, $limit, $offset)
{
$limit = $limit!==null ? (int)$limit : -1;
$offset = $offset!==null ? (int)$offset : -1;
if ($limit > 0 && $offset <= 0) //just limit
$sql = preg_replace('/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i',"\\1SELECT\\2 TOP $limit", $sql);
elseif($limit > 0 && $offset > 0)
$sql = $this->rewriteLimitOffsetSql($sql, $limit,$offset);
return $sql;
}

/**
* Rewrite sql to apply $limit > and $offset > 0 for MSSQL database.
* See https://troels.arvin.dk/db/rdbms/#select-limit-offset
* @param string $sql sql query
* @param integer $limit $limit > 0
* @param integer $offset $offset > 0
* @param integer $limit $limit
* @param integer $offset $offset
* @return string modified sql query applied with limit and offset.
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @see https://troels.arvin.dk/db/rdbms/#select-limit-offset
* @see https://github.com/yiisoft/yii/issues/4491
*/
protected function rewriteLimitOffsetSql($sql, $limit, $offset)
protected function oldRewriteLimitOffsetSql($sql, $limit, $offset)
{
if ($limit <= 0) // Offset without limit has never worked for MSSQL 10 and older, see https://github.com/yiisoft/yii/pull/4501
return $sql;

$fetch = $limit+$offset;
$sql = preg_replace('/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i',"\\1SELECT\\2 TOP $fetch", $sql);
$ordering = $this->findOrdering($sql);
Expand All @@ -224,6 +232,29 @@ protected function rewriteLimitOffsetSql($sql, $limit, $offset)
return $sql;
}

/**
* Rewrite SQL to apply $limit and $offset for MSSQL database version 11 (2012) and newer.
* @see https://learn.microsoft.com/en-us/sql/t-sql/queries/select-order-by-clause-transact-sql?view=sql-server-ver15#using-offset-and-fetch-to-limit-the-rows-returned
* @see https://github.com/yiisoft/yii/issues/4491
* @param string $sql sql query
* @param integer $limit $limit
* @param integer $offset $offset
* @return string modified sql query applied w th limit and offset.
*/
protected function newRewriteLimitOffsetSql($sql, $limit, $offset)
{
// ORDER BY is required when using OFFSET and FETCH
if(count($this->findOrdering($sql)) === 0)
$sql .= " ORDER BY (SELECT NULL)";

$sql .= sprintf(" OFFSET %d ROWS", $offset);

if($limit > 0)
$sql .= sprintf(' FETCH NEXT %d ROWS ONLY', $limit);

return $sql;
}

/**
* Base on simplified syntax https://msdn2.microsoft.com/en-us/library/aa259187(SQL.80).aspx
*
Expand Down
4 changes: 4 additions & 0 deletions framework/db/schema/mssql/CMssqlPdoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CMssqlPdoAdapter extends PDO
* @param string|null sequence name. Defaults to null
* @return integer last inserted id
*/
#[ReturnTypeWillChange]
public function lastInsertId ($sequence=NULL)
{
return $this->query('SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS bigint)')->fetchColumn();
Expand All @@ -36,6 +37,7 @@ public function lastInsertId ($sequence=NULL)
*
* @return boolean
*/
#[ReturnTypeWillChange]
public function beginTransaction ()
{
$this->exec('BEGIN TRANSACTION');
Expand All @@ -50,6 +52,7 @@ public function beginTransaction ()
*
* @return boolean
*/
#[ReturnTypeWillChange]
public function commit ()
{
$this->exec('COMMIT TRANSACTION');
Expand All @@ -64,6 +67,7 @@ public function commit ()
*
* @return boolean
*/
#[ReturnTypeWillChange]
public function rollBack ()
{
$this->exec('ROLLBACK TRANSACTION');
Expand Down
1 change: 1 addition & 0 deletions framework/db/schema/mssql/CMssqlSqlsrvPdoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class CMssqlSqlsrvPdoAdapter extends PDO
* @param string|null $sequence the sequence/table name. Defaults to null.
* @return integer last inserted ID value.
*/
#[ReturnTypeWillChange]
public function lastInsertId($sequence=null)
{
$parts = explode('.', phpversion('pdo_sqlsrv'));
Expand Down
2 changes: 1 addition & 1 deletion framework/db/schema/oci/COciSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ protected function createColumn($column)
$c->name=$column['COLUMN_NAME'];
$c->rawName=$this->quoteColumnName($c->name);
$c->allowNull=$column['NULLABLE']==='Y';
$c->isPrimaryKey=strpos($column['KEY'],'P')!==false;
$c->isPrimaryKey=strpos((string)$column['KEY'],'P')!==false;
$c->isForeignKey=false;
$c->init($column['DATA_TYPE'],$column['DATA_DEFAULT']);
$c->comment=$column['COLUMN_COMMENT']===null ? '' : $column['COLUMN_COMMENT'];
Expand Down
2 changes: 1 addition & 1 deletion framework/db/schema/pgsql/CPgsqlSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ protected function findConstraints($table)
SELECT
conname,
pg_catalog.pg_get_constraintdef(oid) AS consrc,
contype,
contype::char,
conrelid AS relid,
NULL AS indkey
FROM
Expand Down
2 changes: 1 addition & 1 deletion framework/i18n/CLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public function getTerritoryID($id)
*/
public function getLocaleDisplayName($id=null, $category='languages')
{
$id = $this->getCanonicalID($id);
$id = $this->getCanonicalID((string)$id);
if (($category == 'languages') && (isset($this->_data[$category][$id])))
{
return $this->_data[$category][$id];
Expand Down
2 changes: 1 addition & 1 deletion framework/utils/CFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class CFormatter extends CApplicationComponent
* They correspond to the number of digits after the decimal point, the character displayed as the decimal point
* and the thousands separator character.
*/
public $numberFormat=array('decimals'=>null, 'decimalSeparator'=>null, 'thousandSeparator'=>null);
public $numberFormat=array('decimals'=>0, 'decimalSeparator'=>null, 'thousandSeparator'=>null);
/**
* @var array the text to be displayed when formatting a boolean value. The first element corresponds
* to the text display for false, the second element for true. Defaults to <code>array('No', 'Yes')</code>.
Expand Down
3 changes: 2 additions & 1 deletion framework/validators/CDateValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ protected function validateAttribute($object,$attribute)
$valid=false;

// reason of array checking is explained here: https://github.com/yiisoft/yii/issues/1955
if(!is_array($value))
// checking for `null` as passing `null` to CDateTimeParser::parse will throw a deprecation error in PHP >= 8.1
if(!is_array($value) && $value !== null)
{
$formats=is_string($this->format) ? array($this->format) : $this->format;
foreach($formats as $format)
Expand Down
4 changes: 2 additions & 2 deletions framework/validators/CStringValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ protected function validateAttribute($object,$attribute)
}

if(function_exists('mb_strlen') && $this->encoding!==false)
$length=mb_strlen($value, $this->encoding ? $this->encoding : Yii::app()->charset);
$length=mb_strlen((string)$value, $this->encoding ? $this->encoding : Yii::app()->charset);
else
$length=strlen($value);
$length=strlen((string)$value);

if($this->min!==null && $length<$this->min)
{
Expand Down
2 changes: 1 addition & 1 deletion framework/vendors/TextHighlighter/Text/Highlighter.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
* @package Text_Highlighter
* @access public
*/

#[AllowDynamicProperties]
class Text_Highlighter
{
// {{{ members
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* @link https://pear.php.net/package/Text_Highlighter
* @abstract
*/

#[AllowDynamicProperties]
class Text_Highlighter_Renderer
{
/**
Expand Down
Loading

0 comments on commit f2116bf

Please sign in to comment.