préfixe de colonne

This commit is contained in:
Jephté Clain 2024-07-09 11:56:28 +04:00
parent dbb67bc3bc
commit 584b7883a7
2 changed files with 10 additions and 4 deletions

View File

@ -2,6 +2,7 @@
namespace nur\sery\db\_private;
use nur\sery\cl;
use nur\sery\str;
use nur\sery\ValueException;
trait Tselect {
@ -32,6 +33,8 @@ trait Tselect {
if (self::consume('(.*?)\s*(?=$|\bfrom\b)', $tmpsql, $ms)) {
if ($ms[1]) $usercols[] = $ms[1];
}
$colPrefix = $query["col_prefix"] ?? null;
if ($colPrefix !== null) str::add_suffix($colPrefix, ".");
$tmpcols = cl::withn($query["cols"] ?? null);
$schema = $query["schema"] ?? null;
if ($tmpcols !== null) {
@ -41,20 +44,22 @@ trait Tselect {
if ($key === $index) {
$index++;
$cols[] = $col;
$usercols[] = $col;
$usercols[] = "${colPrefix}$col";
} else {
$cols[] = $key;
$usercols[] = "$col as $key";
$usercols[] = "${colPrefix}$col as $key";
}
}
} else {
$cols = null;
if ($schema && is_array($schema) && !in_array("*", $usercols)) {
$cols = array_keys($schema);
$usercols = array_merge($usercols, $cols);
foreach ($cols as $col) {
$usercols[] = "${colPrefix}$col";
}
}
}
if (!$usercols && !$cols) $usercols = ["*"];
if (!$usercols && !$cols) $usercols = ["${colPrefix}*"];
$sql[] = implode(", ", $usercols);
## from

View File

@ -6,6 +6,7 @@ class _select {
"prefix" => "?string",
"schema" => "?array",
"cols" => "?array",
"col_prefix" => "?string",
"from" => "?string",
"where" => "?array",
"order by" => "?array",