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/)
Carsten Brandt
2013-11-24 19:22:51 +01:00
gitea-unlock(16/)
parent e4e376ba28
commit 6920da4a80
octicon-diff(16/tw-mr-1) 3 changed files with 59 additions and 0 deletions

20
framework/yii/db/cubrid/QueryBuilder.php
View File

@@ -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;
}
}

20
framework/yii/db/mysql/QueryBuilder.php
View File

@@ -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;
}
}

19
framework/yii/db/sqlite/QueryBuilder.php
View File

@@ -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;
}
}