mirror of
https://github.com/silverstripe/silverstripe-sqlite3
synced 2024-10-22 17:05:37 +02:00
Merge pull request #8 from kinglozzer/pulls/orm-null-limit
NEW: Allow 'null' limit in database queries
This commit is contained in:
commit
e4960193b8
@ -7,6 +7,11 @@
|
|||||||
*/
|
*/
|
||||||
class SQLite3QueryBuilder extends DBQueryBuilder {
|
class SQLite3QueryBuilder extends DBQueryBuilder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param SQLInsert $query
|
||||||
|
* @param array $parameters
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
protected function buildInsertQuery(SQLInsert $query, array &$parameters) {
|
protected function buildInsertQuery(SQLInsert $query, array &$parameters) {
|
||||||
// Multi-row insert requires SQLite specific syntax prior to 3.7.11
|
// Multi-row insert requires SQLite specific syntax prior to 3.7.11
|
||||||
// For backwards compatibility reasons include the "union all select" syntax
|
// For backwards compatibility reasons include the "union all select" syntax
|
||||||
@ -46,4 +51,42 @@ class SQLite3QueryBuilder extends DBQueryBuilder {
|
|||||||
|
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the LIMIT clause ready for inserting into a query.
|
||||||
|
*
|
||||||
|
* @param SQLSelect $query The expression object to build from
|
||||||
|
* @param array $parameters Out parameter for the resulting query parameters
|
||||||
|
* @return string The finalised limit SQL fragment
|
||||||
|
*/
|
||||||
|
public function buildLimitFragment(SQLSelect $query, array &$parameters) {
|
||||||
|
$nl = $this->getSeparator();
|
||||||
|
|
||||||
|
// Ensure limit is given
|
||||||
|
$limit = $query->getLimit();
|
||||||
|
if(empty($limit)) return '';
|
||||||
|
|
||||||
|
// For literal values return this as the limit SQL
|
||||||
|
if( ! is_array($limit)) {
|
||||||
|
return "{$nl}LIMIT $limit";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assert that the array version provides the 'limit' key
|
||||||
|
if( ! array_key_exists('limit', $limit) || ($limit['limit'] !== null && ! is_numeric($limit['limit']))) {
|
||||||
|
throw new InvalidArgumentException(
|
||||||
|
'SQLite3QueryBuilder::buildLimitSQL(): Wrong format for $limit: '. var_export($limit, true)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$clause = "{$nl}";
|
||||||
|
if($limit['limit'] !== null) {
|
||||||
|
$clause .= "LIMIT {$limit['limit']} ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($limit['start']) && is_numeric($limit['start']) && $limit['start'] !== 0) {
|
||||||
|
$clause .= "OFFSET {$limit['start']}";
|
||||||
|
}
|
||||||
|
return $clause;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user