diff --git a/perl-xCAT/xCAT/Table.pm b/perl-xCAT/xCAT/Table.pm index 2b3d50fc1..9dc46944b 100644 --- a/perl-xCAT/xCAT/Table.pm +++ b/perl-xCAT/xCAT/Table.pm @@ -4330,8 +4330,10 @@ sub delimitcol { #-------------------------------------------------------------------------------- sub buildWhereClause { my $attrvalstr = shift; # array of atrval 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; diff --git a/xCAT-server/lib/xcat/plugins/tabutils.pm b/xCAT-server/lib/xcat/plugins/tabutils.pm index 0d428a5d9..64f3933f8 100644 --- a/xCAT-server/lib/xcat/plugins/tabutils.pm +++ b/xCAT-server/lib/xcat/plugins/tabutils.pm @@ -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) {