Skip to content

Commit

Permalink
Checking is_numeric() and returning Exception if not
Browse files Browse the repository at this point in the history
Cating values on processLimit() and processOffset()
  • Loading branch information
pauloelr committed Jun 10, 2013
1 parent 1cc6c4e commit 1f75b69
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions library/Zend/Db/Sql/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,11 @@ public function order($order)
*/
public function limit($limit)
{
$this->limit = (int) $limit;
if(is_numeric($limit)){
$this->limit = $limit;
}else{
throw new Exception\InvalidArgumentException('Invalid value for Limit.');
}
return $this;
}

Expand All @@ -406,7 +410,11 @@ public function limit($limit)
*/
public function offset($offset)
{
$this->offset = (int) $offset;
if(is_numeric($offset)){
$this->offset = $offset;
}else{
throw new Exception\InvalidArgumentException('Invalid value for Offset.');
}
return $this;
}

Expand Down Expand Up @@ -845,11 +853,14 @@ protected function processLimit(PlatformInterface $platform, DriverInterface $dr
if ($this->limit === null) {
return null;
}

$limit = (int) $this->limit;

if ($driver) {
$sql = $driver->formatParameterName('limit');
$parameterContainer->offsetSet('limit', $this->limit, ParameterContainer::TYPE_INTEGER);
$parameterContainer->offsetSet('limit', $limit, ParameterContainer::TYPE_INTEGER);
} else {
$sql = $platform->quoteValue($this->limit);
$sql = $platform->quoteValue($limit);
}

return array($sql);
Expand All @@ -860,12 +871,15 @@ protected function processOffset(PlatformInterface $platform, DriverInterface $d
if ($this->offset === null) {
return null;
}

$offset = (int) $this->offset;

if ($driver) {
$parameterContainer->offsetSet('offset', $this->offset, ParameterContainer::TYPE_INTEGER);
$parameterContainer->offsetSet('offset', $offset, ParameterContainer::TYPE_INTEGER);
return array($driver->formatParameterName('offset'));
}

return array($platform->quoteValue($this->offset));
return array($platform->quoteValue($offset));
}

/**
Expand Down

0 comments on commit 1f75b69

Please sign in to comment.