Skip to content

Commit b4a2476

Browse files
committed
IN conditions with empty arrays will always return false
1 parent f185e68 commit b4a2476

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/PHPFUI/ORM/Condition.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,16 @@ public function __toString() : string
6969

7070
if (\is_array($value) || $value instanceof \PHPFUI\ORM\Table)
7171
{
72-
$retVal .= '(' . \implode(',', \array_fill(0, \count($value), '?')) . ')';
72+
$count = \count($value);
73+
74+
if ($count)
75+
{
76+
$retVal .= '(' . \implode(',', \array_fill(0, $count, '?')) . ')';
77+
}
78+
else // in clause with empty set, can not be a match, return false
79+
{
80+
$retVal = 'FALSE';
81+
}
7382
}
7483
elseif (null !== $value)
7584
{

src/PHPFUI/ORM/Record.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ public function loadFromSQL(string $sql, array $input = []) : bool
474474
// cast to correct values as ints, floats, etc are read in from PDO as strings
475475
foreach (static::$fields as $field => $row)
476476
{
477-
if (null !== $this->current[$field]) // @phpstan-ignore-line
477+
if (null !== $this->current[$field])
478478
{
479479
switch ($row[1])
480480
{

src/PHPFUI/ORM/Schema/Field.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class Field
88

99
public readonly ?string $defaultValue;
1010

11+
public readonly string $extra;
12+
1113
public readonly string $name;
1214

1315
public readonly bool $nullable;
@@ -16,8 +18,6 @@ class Field
1618

1719
public readonly string $type;
1820

19-
public readonly string $extra;
20-
2121
/**
2222
* @param array<string,mixed> $fields
2323
*/
@@ -31,7 +31,8 @@ public function __construct(\PHPFUI\ORM\PDOInstance $pdo, array $fields, bool $a
3131
$this->defaultValue = $fields['Default'];
3232
$this->primaryKey = false; // use indexes to find primary keys
3333
$this->autoIncrement = \str_contains($fields['Extra'], 'auto_increment');
34-
$this->extra = str_replace('auto_increment', '', $fields['Extra']);
34+
$this->extra = \str_replace('auto_increment', '', $fields['Extra']);
35+
3536
return;
3637
}
3738
// SQLite

0 commit comments

Comments
 (0)