From 420fbc718d49d69f5a5d10152189f1a436fda27b Mon Sep 17 00:00:00 2001 From: linggao Date: Fri, 25 Sep 2009 13:44:48 +0000 Subject: [PATCH] fixed Table.pm to get the primary key info in a different way for mysql git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4227 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/Table.pm | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/perl-xCAT/xCAT/Table.pm b/perl-xCAT/xCAT/Table.pm index 1c033b0c0..e69dfe4ee 100644 --- a/perl-xCAT/xCAT/Table.pm +++ b/perl-xCAT/xCAT/Table.pm @@ -29,6 +29,7 @@ use xCAT::MsgUtils; use Sys::Syslog; use Storable qw/freeze thaw/; use IO::Socket; +use Data::Dumper; BEGIN { $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; @@ -681,6 +682,13 @@ sub updateschema while (my $cd = $sth->fetchrow_hashref) { #print Dumper($cd); push @columns,$cd->{'COLUMN_NAME'}; + + #special code for old version of perl-DBD-mysql + if (exists($cd->{mysql_is_pri_key}) && ($cd->{mysql_is_pri_key}==1)) { + my $tmp_col=$cd->{'COLUMN_NAME'}; + $tmp_col =~ s/"//g; + $dbkeys{$tmp_col}=1; + } } foreach (@columns) { #Column names may end up quoted by database engin s/"//g; @@ -688,13 +696,15 @@ sub updateschema #get primary keys $sth = $self->{dbh}->primary_key_info(undef,undef,$self->{tabname}); - my $data = $sth->fetchall_arrayref; - #print "data=". Dumper($data); - foreach my $cd (@$data) { - my $tmp_col=$cd->[3]; - $tmp_col =~ s/"//g; - $dbkeys{$tmp_col}=1; - } + if ($sth) { + my $data = $sth->fetchall_arrayref; + #print "data=". Dumper($data); + foreach my $cd (@$data) { + my $tmp_col=$cd->[3]; + $tmp_col =~ s/"//g; + $dbkeys{$tmp_col}=1; + } + } } #Now @columns reflects the *actual* columns in the database