Commit 6920da4a by Carsten Brandt

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
parent e4e376ba
...@@ -67,4 +67,24 @@ class QueryBuilder extends \yii\db\QueryBuilder ...@@ -67,4 +67,24 @@ class QueryBuilder extends \yii\db\QueryBuilder
throw new InvalidParamException("There is not sequence associated with table '$tableName'."); 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 ...@@ -140,4 +140,24 @@ class QueryBuilder extends \yii\db\QueryBuilder
{ {
return 'SET FOREIGN_KEY_CHECKS = ' . ($check ? 1 : 0); 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 ...@@ -206,4 +206,23 @@ class QueryBuilder extends \yii\db\QueryBuilder
{ {
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); 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;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment