From b76b8f87a52ea855b70d777a4315582a0343d32c Mon Sep 17 00:00:00 2001 From: lissav Date: Tue, 31 Aug 2010 13:57:24 +0000 Subject: [PATCH] fix add columns for db2 git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@7320 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/Table.pm | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/perl-xCAT/xCAT/Table.pm b/perl-xCAT/xCAT/Table.pm index 3cb77f182..e2ef78ca9 100644 --- a/perl-xCAT/xCAT/Table.pm +++ b/perl-xCAT/xCAT/Table.pm @@ -862,7 +862,11 @@ sub new =head3 updateschema - Description: Alters table schema + Description: Alters table info in the database based on Schema changes + Handles adding attributes + Handles removing attributes but does not really remove them + from the database. + Handles adding keys Arguments: Hash containing Database and Table Handle and schema @@ -976,18 +980,27 @@ sub updateschema } else{ $datatype=get_datatype_string($dcol, $xcatcfg, $types); } - if ($datatype eq "TEXT") { - if (isAKey(\@{$descr->{keys}}, $dcol)) { # keys - $datatype = "VARCHAR(128) "; - } + if ($datatype eq "TEXT") { # keys cannot be TEXT + if (isAKey(\@{$descr->{keys}}, $dcol)) { # keys + $datatype = "VARCHAR(128) "; + } } if (grep /^$dcol$/, @{$descr->{required}}) { $datatype .= " NOT NULL"; } + my $tmpcol=$dcol; # for sqlite + if ($xcatcfg =~ /^DB2:/){ + $tmpcol="\"$dcol\""; + + } else { + if ($xcatcfg =~ /^mysql:/) { + $tmpcol="\`$dcol\`"; + } + } my $stmt = - "ALTER TABLE " . $self->{tabname} . " ADD $dcol $datatype"; + "ALTER TABLE " . $self->{tabname} . " ADD $tmpcol $datatype"; $self->{dbh}->do($stmt); } }