Loading CHANGELOG.md +7 Changes for CHANGELOG.md: 7 added lines, 0 removed lines. Original line number Diff line number Diff line 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) ------------------ Loading src/Table.php +26 −5 Changes for src/Table.php: 26 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ namespace Unicaen\BddAdmin; class Table { Loading Loading @@ -105,6 +104,7 @@ class Table { /* Initialisation des entrées */ $defaultOptions = [ 'custom-select' => null, 'fetch' => Bdd::FETCH_ALL, 'types' => $this->makeTypesOptions(), 'key' => null, Loading @@ -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); Loading Loading @@ -385,6 +390,7 @@ class Table /* Initialisation */ $defaultOptions = [ 'custom-select' => null, 'where' => null, 'key' => $key, 'delete' => true, Loading Loading @@ -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']++; Loading @@ -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; } } } Loading @@ -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'; Loading @@ -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); Loading Loading
CHANGELOG.md +7 Changes for CHANGELOG.md: 7 added lines, 0 removed lines. Original line number Diff line number Diff line 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) ------------------ Loading
src/Table.php +26 −5 Changes for src/Table.php: 26 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ namespace Unicaen\BddAdmin; class Table { Loading Loading @@ -105,6 +104,7 @@ class Table { /* Initialisation des entrées */ $defaultOptions = [ 'custom-select' => null, 'fetch' => Bdd::FETCH_ALL, 'types' => $this->makeTypesOptions(), 'key' => null, Loading @@ -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); Loading Loading @@ -385,6 +390,7 @@ class Table /* Initialisation */ $defaultOptions = [ 'custom-select' => null, 'where' => null, 'key' => $key, 'delete' => true, Loading Loading @@ -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']++; Loading @@ -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; } } } Loading @@ -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'; Loading @@ -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); Loading