mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-06-14 02:10:23 +00:00
Fix issue 5150: tabch and tabdump commands can not deal with invalid attribute names (#5846)
* Fix issue 5150: tabch and tabdump commands can not deal with invalid attribute names * reuse buildWhereClause for key retriving
This commit is contained in:
@ -4330,8 +4330,10 @@ sub delimitcol {
|
||||
#--------------------------------------------------------------------------------
|
||||
sub buildWhereClause {
|
||||
my $attrvalstr = shift; # array of atr<op>val strings
|
||||
my $getkeysonly = shift;
|
||||
my $whereclause; # Where Clause
|
||||
my $firstpass = 1;
|
||||
my @gotkeys = ();
|
||||
foreach my $m (@{$attrvalstr})
|
||||
{
|
||||
my $attr;
|
||||
@ -4372,6 +4374,9 @@ sub buildWhereClause {
|
||||
($attr, $val) = split />/, $m, 2;
|
||||
$operator = ' > ';
|
||||
} else {
|
||||
if (defined($getkeysonly)) {
|
||||
return "Unsupported operator:$m on -w flag input";
|
||||
}
|
||||
xCAT::MsgUtils->message("S", "Unsupported operator:$m on -w flag input, could not build a Where Clause.");
|
||||
$whereclause = "";
|
||||
return $whereclause;
|
||||
@ -4386,7 +4391,12 @@ sub buildWhereClause {
|
||||
|
||||
#$whereclause .="\')";
|
||||
$whereclause .= "\'";
|
||||
|
||||
if (defined($getkeysonly)) {
|
||||
push @gotkeys, $attr;
|
||||
}
|
||||
}
|
||||
if (defined($getkeysonly)) {
|
||||
return \@gotkeys;
|
||||
}
|
||||
return $whereclause;
|
||||
|
||||
|
@ -732,6 +732,18 @@ sub tabdump
|
||||
foreach my $w (@{$OPTW}) { # get each attr=val
|
||||
push @attrarray, $w;
|
||||
}
|
||||
my $keys = xCAT::Table::buildWhereClause(\@attrarray, "1");
|
||||
if (ref($keys) ne 'ARRAY') {
|
||||
$cb->({ error => ["$keys"], errorcode => [1] });
|
||||
return;
|
||||
} else {
|
||||
foreach my $k (@$keys) {
|
||||
unless (grep /$k/, @{ $xCAT::Schema::tabspec{$table}->{cols} }) {
|
||||
$cb->({ error => ["No column \"$k\" in table \"$table\""], errorcode => [1] });
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ents = $tabh->getAllAttribsWhere(\@attrarray, 'ALL');
|
||||
@$recs = ();
|
||||
foreach my $e (@ents) {
|
||||
@ -2370,6 +2382,16 @@ sub tabch {
|
||||
|
||||
}
|
||||
}
|
||||
my $err_found = 0;
|
||||
for my $k (keys %keyhash) {
|
||||
unless (grep /$k/, @{ $xCAT::Schema::tabspec{$table}->{cols} }) {
|
||||
$callback->({ error => ["No column \"$k\" in table \"$table\""], errorcode => [1] });
|
||||
$err_found = 1;
|
||||
}
|
||||
}
|
||||
if ($err_found) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
#splice assignment
|
||||
if (grep /\+=/, $temp) {
|
||||
|
Reference in New Issue
Block a user