modifs.mineures sans commentaires
This commit is contained in:
parent
81a7f91e65
commit
14ce2e3107
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace nur\m\pgsql;
|
namespace nur\m\pgsql;
|
||||||
|
|
||||||
|
use nur\base;
|
||||||
use nur\config;
|
use nur\config;
|
||||||
use nur\debug;
|
use nur\debug;
|
||||||
use nur\m\base\AbstractConn;
|
use nur\m\base\AbstractConn;
|
||||||
|
@ -8,6 +9,7 @@ use nur\m\base\QueryException;
|
||||||
use nur\m\IQuery;
|
use nur\m\IQuery;
|
||||||
use nur\m\IRowIncarnation;
|
use nur\m\IRowIncarnation;
|
||||||
use nur\md;
|
use nur\md;
|
||||||
|
use nur\SV;
|
||||||
|
|
||||||
class PgsqlConn extends AbstractConn {
|
class PgsqlConn extends AbstractConn {
|
||||||
static function query_exception($res=null, ?string $cause=null): QueryException {
|
static function query_exception($res=null, ?string $cause=null): QueryException {
|
||||||
|
@ -89,11 +91,16 @@ class PgsqlConn extends AbstractConn {
|
||||||
if (!$bindings) {
|
if (!$bindings) {
|
||||||
$stmt = pg_query($this->conn, $sql);
|
$stmt = pg_query($this->conn, $sql);
|
||||||
} else {
|
} 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 = [];
|
$bparams = [];
|
||||||
$number = 1;
|
$number = 1;
|
||||||
foreach ($bindings as $name => $value) {
|
foreach ($names as $name) {
|
||||||
$sql = str_replace(":$name", "\$$number", $sql);
|
$sql = str_replace(":$name", "\$$number", $sql);
|
||||||
$bparams[] = $value;
|
$bparams[] = $bindings[$name];
|
||||||
$number++;
|
$number++;
|
||||||
}
|
}
|
||||||
$stmt = pg_query_params($this->conn, $sql, $bparams);
|
$stmt = pg_query_params($this->conn, $sql, $bparams);
|
||||||
|
|
14
src/cl.php
14
src/cl.php
|
@ -28,6 +28,20 @@ class cl {
|
||||||
return $array;
|
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
|
* retourner la première valeur de $array ou $default si le tableau est null
|
||||||
* ou vide
|
* ou vide
|
||||||
|
|
Loading…
Reference in New Issue