summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 21a4139)
raw | patch | inline | side by side (parent: 21a4139)
author | janw <janw@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 4 Mar 2009 09:49:36 +0000 (09:49 +0000) | ||
committer | janw <janw@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 4 Mar 2009 09:49:36 +0000 (09:49 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13491 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-si/gosa-si-server | patch | blob | history | |
gosa-si/modules/DBsqlite.pm | patch | blob | history |
diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index 514e8b1bde1f54442d4e053c6c7d3d9025959613..0b00e52bcbfedbf579ae4dbdc19c6da77edc9ed1 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
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'",
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",
index 0e1da74f6c5ea6b8ad8f4d500ee0e6f28d8b0f19..65d2896155e2878c0e0c3b7e01b56f9a68fea991 100644 (file)
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;
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);
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).")";
}