modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-07-09 12:00:08 +04:00
parent 584b7883a7
commit 007913ef86
1 changed files with 10 additions and 4 deletions

View File

@ -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