diff --git a/perl-xCAT/xCAT/Table.pm b/perl-xCAT/xCAT/Table.pm index a44147ead..665a31d89 100644 --- a/perl-xCAT/xCAT/Table.pm +++ b/perl-xCAT/xCAT/Table.pm @@ -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; diff --git a/xCAT-server/lib/xcat/plugins/tabutils.pm b/xCAT-server/lib/xcat/plugins/tabutils.pm index 35df020db..d1f8a5c6e 100644 --- a/xCAT-server/lib/xcat/plugins/tabutils.pm +++ b/xCAT-server/lib/xcat/plugins/tabutils.pm @@ -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/^([^,]+)(,|$)//; } }