diff --git a/framework/yii/db/cubrid/QueryBuilder.php b/framework/yii/db/cubrid/QueryBuilder.php index 727cb2d..7682516 100644 --- a/framework/yii/db/cubrid/QueryBuilder.php +++ b/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; + } } diff --git a/framework/yii/db/mysql/QueryBuilder.php b/framework/yii/db/mysql/QueryBuilder.php index 27df567..93a06e3 100644 --- a/framework/yii/db/mysql/QueryBuilder.php +++ b/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; + } } diff --git a/framework/yii/db/sqlite/QueryBuilder.php b/framework/yii/db/sqlite/QueryBuilder.php index 4a5407f..d138176 100644 --- a/framework/yii/db/sqlite/QueryBuilder.php +++ b/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; + } }