Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Add support for empty values set with IN predicate #223

Merged
merged 3 commits into from
Feb 28, 2017

Conversation

nanawel
Copy link
Contributor

@nanawel nanawel commented Feb 27, 2017

(Original PR #196)

It should be possible to construct a IN predicate with empty values set.

$select->where('mycolumn IN ?', []);

Of course this code will most likely never be written as is but the content of the set can instead be the result of a calculation.

It's not possible with the current code because of the if ($valueSet) in the constructor and the missing default value in the field definition above, which leads to the following error on line 122 when predicate is built:

Invalid argument supplied for foreach()

Empty sets are supported by some DBMS (SQLite for example) and in that case are the equivalent of WHERE FALSE (since no result can be part of an empty set...).

@@ -122,9 +122,10 @@ public function getExpressionData()
foreach ($values as $argument) {
list($replacements[], $types[]) = $this->normalizeArgument($argument, self::TYPE_VALUE);
}
$values = count($values) > 0 ? array_fill(0, count($values), '%s') : [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this? array_fill() returns [] if $values === []. Please remove this change, the previous code is ok.

@nanawel
Copy link
Contributor Author

nanawel commented Feb 28, 2017

@ezimuel Not with versions of PHP < 5.6. My code is here to avoid a warning with those older versions of PHP.
Refer to History section at https://secure.php.net/manual/fr/function.array-fill.php

@ezimuel
Copy link
Contributor

ezimuel commented Feb 28, 2017

@nanawel ok, I see the point. Makes no sense to add a check for PHP < 5.6. The code looks good to me. I'm going to merge in a while. Thanks for your contribution!

@nanawel
Copy link
Contributor Author

nanawel commented Feb 28, 2017

And thanks to you!

@ezimuel ezimuel merged commit 699a7cf into zendframework:develop Feb 28, 2017
@nanawel nanawel deleted the in-predicate-empty-set branch December 27, 2017 20:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants