préfixe de colonne
This commit is contained in:
parent
dbb67bc3bc
commit
584b7883a7
|
@ -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
|
||||
|
|
|
@ -6,6 +6,7 @@ class _select {
|
|||
"prefix" => "?string",
|
||||
"schema" => "?array",
|
||||
"cols" => "?array",
|
||||
"col_prefix" => "?string",
|
||||
"from" => "?string",
|
||||
"where" => "?array",
|
||||
"order by" => "?array",
|
||||
|
|
Loading…
Reference in New Issue