From e3f9deb011c0a51d8117ac8098cd9030061494d8 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 8 Aug 2007 15:01:09 +0000 Subject: [PATCH] Weitere Tabelle angelegt git-svn-id: http://svn.brehm-online.com/svn/cookbook/trunk@10 191103c4-1d37-0410-b3e5-d8c2315c0aac --- sbin/initial_import.pl | 77 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/sbin/initial_import.pl b/sbin/initial_import.pl index ceaa743..de3a9df 100755 --- a/sbin/initial_import.pl +++ b/sbin/initial_import.pl @@ -29,6 +29,7 @@ $| = 1; my @target_tables = qw( users + authors ); my $admin_data = { @@ -134,6 +135,8 @@ print "\n"; exit 7 unless drop_target_tables(); exit 8 unless create_target_tables(); +exit 99 unless optimize_target_tables(); + exit 0; ############################################################### @@ -317,6 +320,32 @@ sub drop_target_tables { #------------------------------------------------------------- +=head2 optimize_target_tables( ) + +=cut + +sub optimize_target_tables { + + print green_star() . " Optimiere alle Zieltabellen ...\n"; + for my $table ( @target_tables ) { + my $sql = "OPTIMIZE TABLE `" . $table . "`"; + print " - " . $table . " "; + eval { die "Nicht optimiert.\n" unless $target_dbh->do($sql); }; + if ($@) { + print not_ok() . "\n"; + warn "$@\n"; + return undef; + } + print ok() . "\n"; + } ## end for my $table ( reverse(@target_tables) ) + print "\n"; + + return 1; + +} + +#------------------------------------------------------------- + =head2 create_target_tables( ) Erstellt alle notwendigen Ziel-Tabellen ... @@ -325,7 +354,10 @@ Erstellt alle notwendigen Ziel-Tabellen ... sub create_target_tables { - my %create_method = ( 'users' => \&create_user_table, ); + my %create_method = ( + 'users' => \&create_user_table, + 'authors' => \&create_author_table, + ); print green_star() . " Erstelle Ziel-Tabellen ...\n"; @@ -350,6 +382,47 @@ sub create_target_tables { #------------------------------------------------------------- +=head2 create_author_table( ) + +Erstellt die Tabelle 'authors' ... + +=cut + +sub create_author_table { + + my $sql = <do($sql); + + $sql = <quote( $admin_data->{'vorname'} . " " . $admin_data->{'nachname'} ) ); + + return undef unless $target_dbh->do($sql); + + return 1; +} + +#------------------------------------------------------------- + =head2 create_user_table( ) Erstellt die Tabelle 'users' ... @@ -392,7 +465,7 @@ END_SQL $sql = <