index d5775bd26f0be7cd0d2e11c6fa6381391f433b01..d4297aac1f26d5f5158e2f7a69c0cee9b77e175e 100644 (file)
use GOSA::GosaSupportDaemon;
use threads;
use Time::HiRes qw(usleep);
-
+use utf8;
my $col_names = {};
my $class = shift;
my $db_name = shift;
- my $lock='/tmp/gosa_si_lock';
- my $_lock = $db_name;
- $_lock =~ tr/\//_/;
- $lock.=$_lock;
+ my $lock = $db_name.".lock";
+ # delete existing lock - instance should be running only once
+ if(stat($lock)) {
+ unlink($lock);
+ }
my $self = {dbh=>undef,db_name=>undef,db_lock=>undef,db_lock_handle=>undef};
my $dbh = DBI->connect("dbi:SQLite:dbname=$db_name");
$self->{dbh} = $dbh;
my $lock = $self->{db_lock};
my $result=(-f $lock);
if($result) {
- #&main::daemon_log("(".((defined $funcname)?$funcname:"").") Lock (PID ".$$.") $lock gefunden", 8);
+ #&main::daemon_log("(".((defined $funcname)?$funcname:"").") Lock (PID ".$$.") $lock found", 8);
usleep 100;
}
return $result;
sub create_lock : locked {
my $self=shift;
my $funcname=shift;
-# &main::daemon_log("(".((defined $funcname)?$funcname:"").") Erzeuge Lock (PID ".$$.") ".($self->{db_lock}),8);
+ #&main::daemon_log("(".((defined $funcname)?$funcname:"").") Creating Lock (PID ".$$.") ".($self->{db_lock}),8);
my $lock = $self->{db_lock};
while( -f $lock ) {
- #print STDERR "(".((defined $funcname)?$funcname:"").") Lock (PID ".$$.") $lock gefunden\n";
+ #&main::daemon_log("(".((defined $funcname)?$funcname:"").") Lock (PID ".$$.") $lock found",8);
sleep 1;
}
sub remove_lock : locked {
my $self=shift;
my $funcname=shift;
-# &main::daemon_log("(".((defined $funcname)?$funcname:"").") Entferne Lock (PID ".$$.") ".$self->{db_lock}, 8);
+ #&main::daemon_log("(".((defined $funcname)?$funcname:"").") Removing Lock (PID ".$$.") ".$self->{db_lock}, 8);
close($self->{db_lock_handle});
unlink($self->{db_lock});
}
my $self = shift;
my $table_name = shift;
my $col_names_ref = shift;
+ my @col_names;
+ foreach my $col_name (@$col_names_ref) {
+ my @t = split(" ", $col_name);
+ $col_name = $t[0];
+ push(@col_names, $col_name);
+ }
+
$col_names->{ $table_name } = $col_names_ref;
- my $col_names_string = join(', ', @{$col_names_ref});
+ my $col_names_string = join(', ', @col_names);
my $sql_statement = "CREATE TABLE IF NOT EXISTS $table_name ( $col_names_string )";
&create_lock($self,'create_table');
$self->{dbh}->do($sql_statement);
# primekey is unique
# fetch column names of table
- my $col_names = &get_table_columns("",$table);
+ my $col_names = &get_table_columns($self, $table);
# assign values to column name variables
my @add_list;
foreach my $col_name (@{$col_names}) {
- # use function parameter for column values
+ # use function parameter for column values
+
if (exists $arg->{$col_name}) {
push(@add_list, $arg->{$col_name});
}
}
my $sql_statement = "INSERT INTO $table VALUES ('".join("', '", @add_list)."')";
-
&create_lock($self,'add_dbentry');
my $db_res = $self->{dbh}->do($sql_statement);
&remove_lock($self,'add_dbentry');
&create_lock($self,'get_table_columns');
my @res = @{$self->{dbh}->selectall_arrayref("pragma table_info('$table')")};
&remove_lock($self,'get_table_columns');
+
foreach my $column (@res) {
push(@column_names, @$column[1]);
}