Browse Source

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
tags/2.0.0-beta
Carsten Brandt 11 years ago
parent
commit
6920da4a80
  1. 20
      framework/yii/db/cubrid/QueryBuilder.php
  2. 20
      framework/yii/db/mysql/QueryBuilder.php
  3. 19
      framework/yii/db/sqlite/QueryBuilder.php

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

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

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

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

Loading…
Cancel
Save