modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-08-21 17:14:08 +04:00
parent 81a7f91e65
commit 14ce2e3107
2 changed files with 23 additions and 2 deletions

View File

@ -1,6 +1,7 @@
<?php
namespace nur\m\pgsql;
use nur\base;
use nur\config;
use nur\debug;
use nur\m\base\AbstractConn;
@ -8,6 +9,7 @@ use nur\m\base\QueryException;
use nur\m\IQuery;
use nur\m\IRowIncarnation;
use nur\md;
use nur\SV;
class PgsqlConn extends AbstractConn {
static function query_exception($res=null, ?string $cause=null): QueryException {
@ -89,11 +91,16 @@ class PgsqlConn extends AbstractConn {
if (!$bindings) {
$stmt = pg_query($this->conn, $sql);
} else {
# trier d'abord les champ par ordre de longueur, pour éviter les overlaps
$names = array_keys($bindings);
usort($names, function ($a, $b) {
return -SV::compare(strlen(strval($a)), strlen(strval($b)));
});
$bparams = [];
$number = 1;
foreach ($bindings as $name => $value) {
foreach ($names as $name) {
$sql = str_replace(":$name", "\$$number", $sql);
$bparams[] = $value;
$bparams[] = $bindings[$name];
$number++;
}
$stmt = pg_query_params($this->conn, $sql, $bparams);

View File

@ -28,6 +28,20 @@ class cl {
return $array;
}
/**
* construire un tableau avec le résultat de $row[$key] pour chaque élément
* de $rows
*/
static function all_get($key, ?iterable $rows): array {
$array = [];
if ($rows !== null) {
foreach ($rows as $row) {
$array[] = self::get($row, $key);
}
}
return $array;
}
/**
* retourner la première valeur de $array ou $default si le tableau est null
* ou vide