ldo...@users.adullact.net
unread,Feb 27, 2026, 8:25:09 AM (6 days ago) Feb 27Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to openmairie...@googlegroups.com
Author: ldorner
Date: 2026-02-27 14:25:06 +0100 (Fri, 27 Feb 2026)
New Revision: 5494
Modified:
openmairie_exemple/branches/4.11.0-compatibilite-php8.1_WIP3/core/om_application_pdo.trait.php
Log:
fix: build_query_columns_metadata_map revu pour eviter get_inst__om_db_form
Modified: openmairie_exemple/branches/4.11.0-compatibilite-php8.1_WIP3/core/om_application_pdo.trait.php
===================================================================
--- openmairie_exemple/branches/4.11.0-compatibilite-php8.1_WIP3/core/om_application_pdo.trait.php 2026-02-27 11:11:24 UTC (rev 5493)
+++ openmairie_exemple/branches/4.11.0-compatibilite-php8.1_WIP3/core/om_application_pdo.trait.php 2026-02-27 13:25:06 UTC (rev 5494)
@@ -526,6 +526,10 @@
*/
protected function build_query_columns_metadata_map($query) {
$map = array();
+ // Colonnes dont le type est ambigu (même nom, types différents
+ // entre deux tables) : exclues du map pour que le fallback
+ // getColumnMeta() tranche avec le type réel de la colonne.
+ $ambiguous = array();
if (preg_match_all('/(?:FROM|JOIN)\s+(?:[\w]+\.)?(\w+)/i', $query, $matches)) {
foreach (array_unique($matches[1]) as $table_name) {
$class_name = $this->resolve_class_name_from_table($table_name);
@@ -534,18 +538,16 @@
}
if (method_exists($class_name, 'get_columns_metadata')) {
foreach ($class_name::get_columns_metadata() as $col_name => $col_info) {
- $map[strtolower($col_name)] = $col_info;
- }
- }
- if (isset($GLOBALS['f'])) {
- $inst = $this->get_inst__om_dbform(array(
- 'obj' => $table_name,
- 'idx' => 0,
- ));
- if ($inst !== null && method_exists($inst, 'get_additional_columns')) {
- foreach ($inst->get_additional_columns() as $col_name => $col_info) {
- $map[strtolower($col_name)] = $col_info;
+ $lower = strtolower($col_name);
+ if (isset($ambiguous[$lower])) {
+ continue;
}
+ if (isset($map[$lower]) && $map[$lower]['type'] !== $col_info['type']) {
+ unset($map[$lower]);
+ $ambiguous[$lower] = true;
+ continue;
+ }
+ $map[$lower] = $col_info;
}
}
}
@@ -1487,32 +1489,25 @@
if (!$get_columns_name && ($value === true || $value === false)) {
$boolean_columns[$key] = true;
} else if (!$get_columns_name && ($value === 1 || $value === "1" || $value === "t" || $value === 0 || $value === "0" || $value === "f" || $value === null)) {
- if ($value !== null) {
- // Construire la map des métadonnées une seule fois
- // à partir des tables de la requête (get_columns_metadata
- // + get_additional_columns), évite getColumnMeta()
- if (!isset($query_metadata_map)) {
- $query_metadata_map = $this->build_query_columns_metadata_map($query);
+ // Construire la map des métadonnées une seule fois
+ // à partir des tables de la requête (get_columns_metadata
+ // + get_additional_columns), évite getColumnMeta()
+ if (!isset($query_metadata_map)) {
+ $query_metadata_map = $this->build_query_columns_metadata_map($query);
+ }
+ $lower_key_check = strtolower($key);
+ if (isset($query_metadata_map[$lower_key_check])) {
+ if ($query_metadata_map[$lower_key_check]['type'] === 'bool') {
+ $boolean_columns[$lower_key_check] = true;
+ $boolean_columns[$i] = true;
}
- $column_found = false;
- $lower_key_check = strtolower($key);
- if (isset($query_metadata_map[$lower_key_check])) {
- $column_found = true;
- if ($query_metadata_map[$lower_key_check]['type'] === 'bool') {
- $boolean_columns[$lower_key_check] = true;
- $boolean_columns[$i] = true;
- }
- }
- }
- if ($value === null || !$column_found) {
- // NULL ne renseigne pas sur le type : on interroge
- // directement le driver pour éviter que
- // build_query_columns_metadata_map() ne crée des
- // instances dbform en cascade via get_inst__om_dbform()
+ } else {
+ // Fallback : getColumnMeta() pour les colonnes
+ // non trouvées dans les métadonnées des classes
$meta = $stmt->getColumnMeta($i);
+ $column_name = strtolower($meta['name']);
$native_type = isset($meta['native_type']) ? $meta['native_type'] : '';
if ($native_type === 'bool') {
- $column_name = strtolower($meta['name']);
$boolean_columns[$column_name] = true;
$boolean_columns[$i] = true;
}