diff --git a/src/db/_private/Tselect.php b/src/db/_private/Tselect.php index 5f70171..a8304aa 100644 --- a/src/db/_private/Tselect.php +++ b/src/db/_private/Tselect.php @@ -10,6 +10,12 @@ trait Tselect { return preg_match("/^select\b/i", $sql); } + private static function add_prefix(string $col, ?string $prefix): string { + if ($prefix === null) return $col; + if (strpos($col, ".") !== false) return $col; + return "$prefix$col"; + } + /** * parser une chaine de la forme * "select [COLS] [from TABLE] [where CONDS] [order by ORDERS] [group by GROUPS] [having CONDS]" @@ -44,10 +50,10 @@ trait Tselect { if ($key === $index) { $index++; $cols[] = $col; - $usercols[] = "${colPrefix}$col"; + $usercols[] = self::add_prefix($col, $colPrefix); } else { $cols[] = $key; - $usercols[] = "${colPrefix}$col as $key"; + $usercols[] = self::add_prefix($col, $colPrefix)." as $key"; } } } else { @@ -55,11 +61,11 @@ trait Tselect { if ($schema && is_array($schema) && !in_array("*", $usercols)) { $cols = array_keys($schema); foreach ($cols as $col) { - $usercols[] = "${colPrefix}$col"; + $usercols[] = self::add_prefix($col, $colPrefix); } } } - if (!$usercols && !$cols) $usercols = ["${colPrefix}*"]; + if (!$usercols && !$cols) $usercols = [self::add_prefix("*", $colPrefix)]; $sql[] = implode(", ", $usercols); ## from