Add support for LIMIT OFFSET for db2 #275
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,13 @@ class SelectDecorator extends Select implements PlatformDecoratorInterface | |
*/ | ||
protected $subject = null; | ||
|
||
/** | ||
/** | ||
* @var bool | ||
*/ | ||
protected $supportsLimitOffset = false; | ||
|
||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function getIsSelectContainDistinct() | ||
|
@@ -51,6 +57,22 @@ public function setSubject($select) | |
$this->subject = $select; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function getSupportsLimitOffset() | ||
{ | ||
return $this->supportsLimitOffset; | ||
} | ||
|
||
/** | ||
* @param bool $supportsLimitOffset | ||
*/ | ||
public function setSupportsLimitOffset($supportsLimitOffset) | ||
{ | ||
$this->supportsLimitOffset = $supportsLimitOffset; | ||
} | ||
|
||
/** | ||
* @see Select::renderTable | ||
*/ | ||
|
@@ -82,6 +104,23 @@ protected function processLimitOffset(PlatformInterface $platform, DriverInterfa | |
return; | ||
} | ||
|
||
if ($this->supportsLimitOffset) { | ||
// Note: db2_prepare/db2_execute fails with positional parameters, for LIMIT & OFFSET | ||
$limit = (int)$this->limit; | ||
if (! $limit) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no space after the ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. most of zf code has space after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mwillbanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mwillbanks |
||
return; | ||
} | ||
|
||
$offset = (int)$this->offset; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space after the cast. |
||
if ($offset) { | ||
array_push($sqls, sprintf("LIMIT %s OFFSET %s", $limit, $offset)); | ||
return; | ||
} | ||
|
||
array_push($sqls, sprintf("LIMIT %s", $limit)); | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think deep if can be simplified with return early: if (! $this->limit) {
return;
}
if ($this->offset) {
array_push($sqls, sprintf("LIMIT %s OFFSET %s", $limit, $offset));
return;
}
array_push($sqls, sprintf("LIMIT %s", $limit));
return; |
||
} | ||
|
||
$selectParameters = $parameters[self::SELECT]; | ||
|
||
$starSuffix = $platform->getIdentifierSeparator() . self::SQL_STAR; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after the cast.