octicon-rss(16/)
You've already forked yii2
mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-10 23:50:38 +08:00
fixed limit/offset for sqlite,mysql and cubrid
tests for this are on elasticsearch branch (due to huge refactoring there) and will come later by merge
This commit is contained in:
octicon-git-branch(16/)
octicon-tag(16/)
octicon-diff(16/tw-mr-1) 3 changed files with 59 additions and 0 deletions
@@ -67,4 +67,24 @@ class QueryBuilder extends \yii\db\QueryBuilder
|
||||
throw new InvalidParamException("There is not sequence associated with table '$tableName'.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDocs
|
||||
*/
|
||||
public function buildLimit($limit, $offset)
|
||||
{
|
||||
$sql = '';
|
||||
// limit is not optional in CUBRID
|
||||
// http://www.cubrid.org/manual/90/en/LIMIT%20Clause
|
||||
// "You can specify a very big integer for row_count to display to the last row, starting from a specific row."
|
||||
if ($limit !== null && $limit >= 0) {
|
||||
$sql = 'LIMIT ' . (int)$limit;
|
||||
if ($offset > 0) {
|
||||
$sql .= ' OFFSET ' . (int)$offset;
|
||||
}
|
||||
} elseif ($offset > 0) {
|
||||
$sql = 'LIMIT ' . (int)$offset . ', 18446744073709551615'; // 2^64-1
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,4 +140,24 @@ class QueryBuilder extends \yii\db\QueryBuilder
|
||||
{
|
||||
return 'SET FOREIGN_KEY_CHECKS = ' . ($check ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDocs
|
||||
*/
|
||||
public function buildLimit($limit, $offset)
|
||||
{
|
||||
$sql = '';
|
||||
// limit is not optional in MySQL
|
||||
// http://stackoverflow.com/a/271650/1106908
|
||||
// http://dev.mysql.com/doc/refman/5.0/en/select.html#idm47619502796240
|
||||
if ($limit !== null && $limit >= 0) {
|
||||
$sql = 'LIMIT ' . (int)$limit;
|
||||
if ($offset > 0) {
|
||||
$sql .= ' OFFSET ' . (int)$offset;
|
||||
}
|
||||
} elseif ($offset > 0) {
|
||||
$sql = 'LIMIT ' . (int)$offset . ', 18446744073709551615'; // 2^64-1
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,4 +206,23 @@ class QueryBuilder extends \yii\db\QueryBuilder
|
||||
{
|
||||
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDocs
|
||||
*/
|
||||
public function buildLimit($limit, $offset)
|
||||
{
|
||||
$sql = '';
|
||||
// limit is not optional in SQLite
|
||||
// http://www.sqlite.org/syntaxdiagrams.html#select-stmt
|
||||
if ($limit !== null && $limit >= 0) {
|
||||
$sql = 'LIMIT ' . (int)$limit;
|
||||
if ($offset > 0) {
|
||||
$sql .= ' OFFSET ' . (int)$offset;
|
||||
}
|
||||
} elseif ($offset > 0) {
|
||||
$sql = 'LIMIT 9223372036854775807 OFFSET ' . (int)$offset; // 2^63-1
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user