fix tabrestore to handle columns that are auto increment.
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@2698 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
71d2f81fa5
commit
37db64b1e8
@ -1964,7 +1964,6 @@ sub DESTROY
|
||||
undef $self->{nodelist}; #Could be circular
|
||||
}
|
||||
|
||||
|
||||
=head3 getTableList
|
||||
Description: Returns a list of the table names in the xCAT database.
|
||||
=cut
|
||||
@ -1991,10 +1990,9 @@ sub getDescriptions {
|
||||
foreach my $t (keys %xCAT::Schema::tabspec) { $ret->{$t} = $xCAT::Schema::tabspec{$t}->{table_desc}; }
|
||||
return $ret;
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
|
||||
=head3 isAKey
|
||||
|
||||
Description: Checks to see if table field is a table key
|
||||
|
||||
Arguments:
|
||||
@ -2011,7 +2009,6 @@ sub getDescriptions {
|
||||
if(isaKey($key_list, $col));
|
||||
|
||||
=cut
|
||||
|
||||
#--------------------------------------------------------------------------------
|
||||
sub isAKey
|
||||
{
|
||||
@ -2026,5 +2023,29 @@ sub isAKey
|
||||
return 0;
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
=head3 getAutoIncrementColumns
|
||||
get a list of column names that are of type "INTEGER AUTO_INCREMENT".
|
||||
|
||||
Returns:
|
||||
an array of column names that are auto increment.
|
||||
=cut
|
||||
#--------------------------------------------------------------------------------
|
||||
sub getAutoIncrementColumns {
|
||||
my $self=shift;
|
||||
my $descr=$xCAT::Schema::tabspec{$self->{tabname}};
|
||||
my $types=$descr->{types};
|
||||
my @ret=();
|
||||
|
||||
foreach my $col (@{$descr->{cols}})
|
||||
{
|
||||
if (($types) && ($types->{$col})) {
|
||||
if ($types->{$col} =~ /INTEGER AUTO_INCREMENT/) { push(@ret,$col); }
|
||||
}
|
||||
}
|
||||
return @ret;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
@ -276,6 +276,11 @@ sub tabrestore
|
||||
my @colns = split(/,/, $header);
|
||||
my $line;
|
||||
my $rollback = 0;
|
||||
|
||||
my @tmp=$tab->getAutoIncrementColumns(); #get the columns that are auto increment by DB.
|
||||
my %auto_cols=();
|
||||
foreach (@tmp) { $auto_cols{$_}=1;}
|
||||
|
||||
LINE: foreach $line (@{$request->{data}})
|
||||
{
|
||||
$linenumber++;
|
||||
@ -288,7 +293,9 @@ sub tabrestore
|
||||
if ($line =~ /^,/ or $line eq "")
|
||||
{ #Match empty, or end of line that is empty
|
||||
#TODO: should we detect when there weren't enough CSV fields on a line to match colums?
|
||||
$record{$col} = undef;
|
||||
if (!exists($auto_cols{$col})) {
|
||||
$record{$col} = undef;
|
||||
}
|
||||
$line =~ s/^,//;
|
||||
}
|
||||
elsif ($line =~ /^[^,]*"/)
|
||||
@ -339,7 +346,9 @@ sub tabrestore
|
||||
chop $ent;
|
||||
$ent = substr($ent, 1);
|
||||
$ent =~ s/""/"/g;
|
||||
$record{$col} = $ent;
|
||||
if (!exists($auto_cols{$col})) {
|
||||
$record{$col} = $ent;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -357,7 +366,9 @@ sub tabrestore
|
||||
}
|
||||
elsif ($line =~ /^([^,]+)/)
|
||||
{ #easiest case, no Text::Balanced needed..
|
||||
$record{$col} = $1;
|
||||
if (!exists($auto_cols{$col})) {
|
||||
$record{$col} = $1;
|
||||
}
|
||||
$line =~ s/^([^,]+)(,|$)//;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user