From 8490ba2f8fd099fd3b5482680db65ceb47f792e5 Mon Sep 17 00:00:00 2001 From: lissav Date: Tue, 23 Mar 2010 16:18:40 +0000 Subject: [PATCH] fix db2 eventlog/auditlog creattion git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@5562 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/Table.pm | 65 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/perl-xCAT/xCAT/Table.pm b/perl-xCAT/xCAT/Table.pm index a3056b1e2..854f056b3 100644 --- a/perl-xCAT/xCAT/Table.pm +++ b/perl-xCAT/xCAT/Table.pm @@ -543,7 +543,7 @@ sub get_datatype_string_db2 { my $types=shift; #types field (eventlog) my $tablename=shift; # tablename my $descr=shift; # table schema - + my $typedefined=0; my $ret = "varchar(512)"; # default for most attributes if (($types) && ($types->{$col})) { if ($types->{$col} =~ /INTEGER AUTO_INCREMENT/) { @@ -551,6 +551,7 @@ sub get_datatype_string_db2 { } else { $ret = $types->{$col}; } + $typedefined=1; } if ($col eq "disable") { @@ -560,10 +561,11 @@ sub get_datatype_string_db2 { $ret = "varchar(4098)"; } - # if the column is a key + # if the column is a key and not already defined if (isAKey(\@{$descr->{keys}}, $col)) { - + if ($typedefined == 0) { $ret = "VARCHAR(128) NOT NULL "; + } } return $ret; } @@ -3228,6 +3230,63 @@ sub getAutoIncrementColumns { return @ret; } +#-------------------------------------------------------------------------- +=head3 truncate + + Description:truncates the input table ( removes all entries, but does + not drop the table) + + + Arguments: + Table Handle + Returns: + + Globals: + + Error: + + Example: + my $table=xCAT::Table->new("eventlog"); + $table->truncate(); + Comments: + TODO : NEED to add code for CSV and test + +=cut + +#-------------------------------------------------------------------------------- +sub truncate +{ + #takes table handle + my $self = shift; + my $xcatcfg =get_xcatcfg(); + my $notif = xCAT::NotifHandler->needToNotify($self->{tabname}, 'd'); + # TODO add notification + # truncate the table + my $trunstring; + if ($xcatcfg =~ /^SQLite:/) { + $trunstring = 'DROP Table ' . $self->{tabname}; + my $stmt = $self->{dbh}->prepare($trunstring); + $stmt->execute; + $stmt->finish; + if (!$self->{dbh}->{AutoCommit}) { + $self->{dbh}->commit; + } + my $self=xCAT::Table->new($self->{tabname}); # create table + return ; + } else { + if ($xcatcfg =~ /^DB2:/){ # does not support TRUNCATE + $self->{tabname} =~ tr/a-z/A-Z/; + $trunstring = 'DROP TABLE ' . q(") . $self->{tabname} . q("); + } else { # mysql/postgresql/CVS + $trunstring = 'TRUNCATE TABLE ' . $self->{tabname}; + } + my $stmt = $self->{dbh}->prepare($trunstring); + $stmt->execute; + $stmt->finish; + $self->commit; + } + return ; +} 1;