ajout any, all

This commit is contained in:
Jephté Clain 2025-01-24 13:19:21 +04:00
parent 741c8ab9b2
commit 213ace1cbf
2 changed files with 45 additions and 0 deletions

View File

@ -103,6 +103,29 @@ abstract class _base {
$condkey++;
}
break;
case "any":
case "all":
case "not any":
case "not all":
# ["list", $values]
if ($op === "any" || $op === "all") {
$condprefix = $op;
$op = "=";
} elseif ($op === "not any" || $op === "not all") {
$condprefix = substr($op, strlen("not "));
$op = "<>";
}
$condprefix .= "(array[";
$condsep = ", ";
$condsuffix = "])";
$condvalues = null;
if (array_key_exists("values", $cond)) {
$condvalues = cl::with($cond["values"]);
} elseif (array_key_exists($condkey, $condkeys)) {
$condvalues = cl::with($cond[$condkeys[$condkey]]);
$condkey++;
}
break;
case "in":
# ["in", $values]
$condprefix = "(";

View File

@ -0,0 +1,22 @@
<?php
namespace nulib\db\_private;
use nulib\tests\TestCase;
class _baseTest extends TestCase {
function testParse_conds() {
$values = [1, "string"];
$sql = null;
$bindings = null;
_base::parse_conds([
"value" => ["any", $values],
], $sql, $bindings);
self::assertSame([
"value = any(array[:value, :value2])",
], $sql);
self::assertSame([
"value" => 1,
"value2" => "string",
], $bindings);
}
}