From 30b195a1a34556941020bfed9f203cee9bd9fefb Mon Sep 17 00:00:00 2001 From: janw Date: Tue, 12 May 2009 09:11:27 +0000 Subject: [PATCH] Delete most databases on startup, avoid need of ALTER TABLE (not reliable with SQLite). References 658 git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13647 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-server | 7 ++--- gosa-si/modules/DBsqlite.pm | 53 ++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index aa6f576d7..af76ab68c 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -1812,8 +1812,7 @@ sub watch_for_new_jobs { my $res_2 = $job_db->exec_statement( $sql_statement_2 ); if(defined($res_2) and defined @{$res_2}[0]) { # Set status from goto-activation to 'waiting' and update timestamp - $job_db->exec_statement("UPDATE $job_queue_tn SET status='waiting' WHERE macaddress LIKE '$macaddress' AND headertag = 'trigger_action_reinstall'"); - $job_db->exec_statement("UPDATE $job_queue_tn SET timestamp='".&calc_timestamp(&get_time(), 'plus', 30)."' WHERE macaddress LIKE '$macaddress' AND headertag = 'trigger_action_reinstall'"); + $job_db->exec_statement("UPDATE $job_queue_tn SET status='waiting', timestamp='".&calc_timestamp(&get_time(), 'plus', 30)."' WHERE macaddress LIKE '$macaddress' AND headertag = 'trigger_action_reinstall'"); } } next; @@ -3354,6 +3353,8 @@ daemon_log($server_status_hash->{$server_status}.": $server_revision", 1); # connect to incoming_db unlink($incoming_file_name); $incoming_db = GOSA::DBsqlite->new($incoming_file_name); + chmod(0640, $incoming_file_name); + chown($root_uid, $adm_gid, $incoming_file_name); # connect to gosa-si job queue $job_db = GOSA::DBsqlite->new($job_queue_file_name); @@ -3361,6 +3362,7 @@ daemon_log($server_status_hash->{$server_status}.": $server_revision", 1); chown($root_uid, $adm_gid, $job_queue_file_name); # connect to known_clients_db + unlink($known_clients_file_name); $known_clients_db = GOSA::DBsqlite->new($known_clients_file_name); chmod(0640, $known_clients_file_name); chown($root_uid, $adm_gid, $known_clients_file_name); @@ -3396,7 +3398,6 @@ daemon_log($server_status_hash->{$server_status}.": $server_revision", 1); chown($root_uid, $adm_gid, $fai_release_file_name); # connect to packages_list_db - #unlink($packages_list_file_name); unlink($packages_list_under_construction); $packages_list_db = GOSA::DBsqlite->new($packages_list_file_name); chmod(0640, $packages_list_file_name); diff --git a/gosa-si/modules/DBsqlite.pm b/gosa-si/modules/DBsqlite.pm index e6ec1048c..21ad1f752 100644 --- a/gosa-si/modules/DBsqlite.pm +++ b/gosa-si/modules/DBsqlite.pm @@ -6,6 +6,7 @@ use Carp; use DBI; use GOSA::GosaSupportDaemon; use Time::HiRes qw(usleep); +use Data::Dumper; use Fcntl qw/:DEFAULT :flock/; # import LOCK_* constants our $col_names = {}; @@ -128,8 +129,15 @@ sub create_table { foreach my $col_name (@$col_names_ref) { push(@col_names, $col_name); } - $col_names->{ $table_name } = \@col_names; + + # Not activated yet + # Check schema + # if($self->check_schema($table_name)) { + # $self->exec_statement("DROP TABLE $table_name"); + # &main::daemon_log("WARNING: Schema of table $table_name has changed! Table will be recreated!", 3); + # } + my $col_names_string = join(", ", @col_names); my $sql_statement = "CREATE TABLE IF NOT EXISTS $table_name ( $col_names_string )"; my $res = $self->exec_statement($sql_statement); @@ -145,6 +153,49 @@ sub create_table { } +# sub check_schema { +# my $self = shift; +# my $result = 1; +# if(not defined($self) or ref($self) ne 'GOSA::DBsqlite') { +# &main::daemon_log("0 ERROR: GOSA::DBsqlite::check_schema was called static! Argument was '$self'!", 1); +# return $result; +# } +# +# my $table_name = shift || undef; +# my $table_columns; +# +# if($table_name and $col_names->{$table_name}) { +# # Query the table_info from database +# foreach my $column ( @{ $self->exec_statement ( "pragma table_info('$table_name')" ) } ) { +# my $column_name = @$column[1]; +# my $data_type = @$column[2]; +# $table_columns->{$column_name}= $data_type; +# } +# +# foreach my $column (@{$col_names->{$table_name}}) { +# my ($column_name, $datatype) = split(/\s/, $column); +# if(exists($table_columns->{$column_name})) { +# if(lc $datatype eq lc $table_columns->{$column_name}) { +# next; +# } else { +# &main::daemon_log("WARNING: Column '$column_name' has wrong datatype!", 1); +# $result = 0; +# } +# } else { +# $result = 0; +# &main::daemon_log("WARNING: Column '$column_name' is missing!", 1); +# #&main::daemon_log("DEBUG Columns are not equal! Column '".$self->{db_name}.".$column_name' is missing!", 0); +# #my $sql_statement = "ALTER TABLE $table_name ADD COLUMN $column_name $datatype"; +# #$self->exec_statement($sql_statement); +# # The ALTER TABLE statement sucks completely in SQLite, so just recreate the table +# } +# } +# } +# +# return $result; +# } + + sub add_dbentry { my $self = shift; my $arg = shift; -- 2.30.2