From: janw Date: Wed, 4 Mar 2009 09:49:36 +0000 (+0000) Subject: Copy changeset:13490 from gosa-lhm. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=842fe7ed7b96851f1ec8acbccdc2cf7eef54e0f1;p=gosa.git Copy changeset:13490 from gosa-lhm. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13491 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 514e8b1bd..0b00e52bc 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -127,7 +127,7 @@ my $watch_for_new_jobs_in_progress = 0; our $incoming_db; our $incoming_tn = 'incoming'; my $incoming_file_name; -my @incoming_col_names = ("id INTEGER PRIMARY KEY auto_increment", +my @incoming_col_names = ("id INTEGER PRIMARY KEY", "timestamp VARCHAR(14) DEFAULT 'none'", "headertag VARCHAR(255) DEFAULT 'none'", "targettag VARCHAR(255) DEFAULT 'none'", @@ -140,7 +140,7 @@ my @incoming_col_names = ("id INTEGER PRIMARY KEY auto_increment", our $job_db; our $job_queue_tn = 'jobs'; my $job_queue_file_name; -my @job_queue_col_names = ("id INTEGER PRIMARY KEY auto_increment", +my @job_queue_col_names = ("id INTEGER PRIMARY KEY", "timestamp VARCHAR(14) DEFAULT 'none'", "status VARCHAR(255) DEFAULT 'none'", "result TEXT", diff --git a/gosa-si/modules/DBsqlite.pm b/gosa-si/modules/DBsqlite.pm index 0e1da74f6..65d289615 100644 --- a/gosa-si/modules/DBsqlite.pm +++ b/gosa-si/modules/DBsqlite.pm @@ -18,6 +18,18 @@ sub new { my $lock = $db_name.".si.lock"; my $self = {dbh=>undef,db_name=>undef,db_lock=>undef,db_lock_handle=>undef}; my $dbh = DBI->connect("dbi:SQLite:dbname=$db_name", "", "", {RaiseError => 1, AutoCommit => 1}); + my $sth = $dbh->prepare("pragma integrity_check"); + $sth->execute(); + my @ret = $sth->fetchall_arrayref(); + if(length(@ret)==1 && $ret[0][0][0] eq 'ok') { + &main::daemon_log("DEBUG: Database image $db_name is ok", 7); + } else { + &main::daemon_log("ERROR: Database image $db_name is malformed, creating new database.", 1); + $sth->finish(); + $dbh->disconnect(); + unlink($db_name); + $dbh = DBI->connect("dbi:SQLite:dbname=$db_name", "", "", {RaiseError => 1, AutoCommit => 1}); + } $self->{dbh} = $dbh; $self->{db_name} = $db_name; $self->{db_lock} = $lock; @@ -45,15 +57,19 @@ sub create_table { my $table_name = shift; my $col_names_ref = shift; my @col_names; + my @col_names_creation; foreach my $col_name (@$col_names_ref) { + # Save full column description for creation of database + push(@col_names_creation, $col_name); my @t = split(" ", $col_name); $col_name = $t[0]; + # Save column name internally for select_dbentry push(@col_names, $col_name); } - + $col_names->{ $table_name } = $col_names_ref; - my $col_names_string = join("', '", @col_names); - my $sql_statement = "CREATE TABLE IF NOT EXISTS $table_name ( '$col_names_string' )"; + my $col_names_string = join(", ", @col_names_creation); + my $sql_statement = "CREATE TABLE IF NOT EXISTS $table_name ( $col_names_string )"; $self->lock(); eval { my $res = $self->{dbh}->do($sql_statement); @@ -147,7 +163,7 @@ sub add_dbentry { my $sql_statement; if($create_id==1) { - $sql_statement = "INSERT INTO $table ('id', ".join(", ", @col_list).") VALUES ((select coalesce(max(id), 0)+1 from $table), ".join(", ", @val_list).")"; + $sql_statement = "INSERT INTO $table (id, ".join(", ", @col_list).") VALUES (null, ".join(", ", @val_list).")"; } else { $sql_statement = "INSERT INTO $table (".join(", ", @col_list).") VALUES (".join(", ", @val_list).")"; }