Skip to content
Snippets Groups Projects
Commit b5e8a642 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

- [Fix] Test de comparaison des float & doubles tenant compte des problématiques d'arrondis de PHP

- Dans le Table->merge, possibilité de définir une requête personnalisée pour les cas complexes
parent ebed2076
No related branches found
No related tags found
No related merge requests found
Pipeline #30186 passed
branche modernisation-gestion-donnees
-------------------------------------
- [Fix] Test de comparaison des float & doubles tenant compte des problématiques d'arrondis de PHP
- Dans le Table->merge, possibilité de définir une requête personnalisée pour les cas complexes
0.9.8 (22/08/2024)
------------------
......
......@@ -3,7 +3,6 @@
namespace Unicaen\BddAdmin;
class Table
{
......@@ -105,6 +104,7 @@ class Table
{
/* Initialisation des entrées */
$defaultOptions = [
'custom-select' => null,
'fetch' => Bdd::FETCH_ALL,
'types' => $this->makeTypesOptions(),
'key' => null,
......@@ -120,7 +120,12 @@ class Table
if ($cols != '') $cols .= ', ';
$cols .= $colDdl['name'] ?? $cname;
}
$sql = "SELECT $cols FROM ".$this->name;
$sql = "SELECT $cols FROM ";
if ($options['custom-select']) {
$sql .= "(" . $options['custom-select'] . ") t";
} else {
$sql .= $this->name;
}
$params = [];
$sql .= $this->makeWhere($where, $options, $params);
......@@ -385,6 +390,7 @@ class Table
/* Initialisation */
$defaultOptions = [
'custom-select' => null,
'where' => null,
'key' => $key,
'delete' => true,
......@@ -475,10 +481,17 @@ class Table
if (in_array($c, $options['update-only-null']) && $oldc !== null) $ok = false;
if ($ok) {
if ((is_float($newc) || is_double($newc))
&& (is_float($oldc) || is_double($oldc))
&& abs($newc - $oldc) > 0.0000000001
) {
// nécessaire à cause des pb de précision des float/doubles en PHP :
// dans ce cas, on considère quand même que les 2 chiffres sont identiques
$toUpdate[$c] = $n[$c];
}
}
}
}
if (!empty($toUpdate)) {
$this->update($toUpdate, $this->makeKeyArray($o, $key), ['ddl' => $ddl]);
$result['update']++;
......@@ -492,7 +505,15 @@ class Table
$this->insert($n);
$result['insert']++;
if ($options['return-insert-data']) {
$result['insert-data'][] = $n;
$insertedData = [];
if (isset($n['ID'])) {
$insertedData['ID'] = $n['ID'];
}
foreach ($key as $null => $kc) {
$insertedData[$kc] = $n[$kc];
}
$result['insert-data'][$k] = $insertedData;
}
}
}
......@@ -504,7 +525,7 @@ class Table
private function makeKeyArray(array $data, $key): array
private function makeKeyArray(array $data, array|string|null $key = null): array
{
if (!$key && $this->hasId()) {
$key = 'ID';
......@@ -521,7 +542,7 @@ class Table
private function makeKey(array $data, $key): string
public function makeKey(array $data, array|string|null $key): string
{
$keyArray = $this->makeKeyArray($data, $key);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment