Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Sql\Predicate\Operator.php #991

Closed
wants to merge 2 commits into from

3 participants

@rsandrea

Regarding commit 164ccc3: $left and $right should be compared to null while validating, because if you try to create a sentence like : where field = 0, $right will be equal to 0 which will make line 80 evaluate to false, never calling $this->setRight($right)

Regarding commit f6d40d0: I don't know if this is the best way to do it, but this kind of validation is necessary because on some RDBMS (like PostgreSQL) you can't compare an integer field to a string value, it will generate an error, as it can't compare different data types.

rsandrea added some commits
@rsandrea rsandrea $left and $right should be compared to null while validating, because…
… if you try to create a sentence like : where field = 0, $right will be equal to 0 which will make line 80 evaluate to false, never calling $this->setRight($right)
164ccc3
@rsandrea rsandrea I don't know if this is the best way to do it, but this kind of valid…
…ation is necessary because on some RDBMS (like PostgreSQL) you can't compare an integer field to a string value, it will generate an error, as it can't compare different data types.
f6d40d0
@Freeaqingme
Collaborator

Hi rsandrea,

Could you perhaps add a test or two for these changes?

Thanks.

@ralphschindler
Collaborator

I'll take 164ccc3, but not f6d40d0. Basically, on the latter, unquoted values are considered constants, which is generally not something you'd ever want inside Operator literal. To be in a situation where you're not quoting something, then you should be using the new (not yet in master) functionality of using a "expression", see: #934

I can create tests for your former commit though, I'll likely merge it into my bigger pull request noted above first.

@rsandrea

Hello ralphschindler, I wasn't aware of this new "expression" functionality and I do agree on rejecting f6d40d0, it made the creation of statements fail anyway.

@ralphschindler
Collaborator

This was fixed in a6ac879, thanks for the heads up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 1, 2012
  1. @rsandrea

    $left and $right should be compared to null while validating, because…

    rsandrea authored
    … if you try to create a sentence like : where field = 0, $right will be equal to 0 which will make line 80 evaluate to false, never calling $this->setRight($right)
  2. @rsandrea

    I don't know if this is the best way to do it, but this kind of valid…

    rsandrea authored
    …ation is necessary because on some RDBMS (like PostgreSQL) you can't compare an integer field to a string value, it will generate an error, as it can't compare different data types.
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 3 deletions.
  1. +3 −3 library/Zend/Db/Sql/Predicate/Operator.php
View
6 library/Zend/Db/Sql/Predicate/Operator.php
@@ -71,13 +71,13 @@ class Operator implements PredicateInterface
*/
public function __construct($left = null, $operator = self::OPERATOR_EQUAL_TO, $right = null, $leftType = self::TYPE_IDENTIFIER, $rightType = self::TYPE_VALUE)
{
- if ($left) {
+ if (null !== $left) {
$this->setLeft($left);
}
if ($operator) {
$this->setOperator($operator);
}
- if ($right) {
+ if (null !== $right) {
$this->setRight($right);
}
if ($leftType) {
@@ -222,7 +222,7 @@ public function getRightType()
public function getWhereParts()
{
return array(array(
- '%s ' . $this->operator . ' %s',
+ (is_int($this->left)? '%d ':'%s ') . $this->operator . (is_int($this->right)? ' %d':' %s'),
array($this->left, $this->right),
array($this->leftType, $this->rightType)
));
Something went wrong with that request. Please try again.