summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4ada5ec)
raw | patch | inline | side by side (parent: 4ada5ec)
author | janw <janw@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 1 Apr 2008 13:07:09 +0000 (13:07 +0000) | ||
committer | janw <janw@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 1 Apr 2008 13:07:09 +0000 (13:07 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10100 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-si/modules/DBsqlite.pm | patch | blob | history |
index 8d5ff4705c0764b5b89c4a4e599f11724d20b3bd..aef43265d366aff3845d9862a0c2eb858f4eb3da 100644 (file)
use DBI;
use Data::Dumper;
use GOSA::GosaSupportDaemon;
-use threads;
use Time::HiRes qw(usleep);
return($self);
}
-sub lock_exists : locked {
- my $self=shift;
- my $funcname=shift;
- my $lock = $self->{db_lock};
- my $result=(-f $lock);
- my $i=0;
- if($result) {
- if($i>10) {
- &main::daemon_log("WARNING: (".((defined $funcname)?$funcname:"").") Lock (PID ".$$.") $lock found. Waiting time: ".($i*500)." us", 8);
- }
- usleep 500;
- $i++;
- }
- return $result;
-}
-
-sub create_lock : locked {
- my $self=shift;
- my $funcname=shift;
- #&main::daemon_log("(".((defined $funcname)?$funcname:"").") Creating Lock (PID ".$$.") ".($self->{db_lock}),8);
-
- my $lock = $self->{db_lock};
- while( -f $lock ) {
- #&main::daemon_log("(".((defined $funcname)?$funcname:"").") Lock (PID ".$$.") $lock found",8);
- usleep 100;
- }
-
- open($self->{db_lock_handle},'>',$self->{db_lock});
-}
-
-sub remove_lock : locked {
- my $self=shift;
- my $funcname=shift;
- #&main::daemon_log("(".((defined $funcname)?$funcname:"").") Removing Lock (PID ".$$.") ".$self->{db_lock}, 8);
- close($self->{db_lock_handle});
- unlink($self->{db_lock});
-}
-
-
sub create_table {
my $self = shift;
my $table_name = shift;
$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' )";
- &create_lock($self,'create_table');
$self->{dbh}->do($sql_statement);
- &remove_lock($self,'create_table');
return 0;
}
if($primkey eq 'id') {
# if primkey is id, fetch max id from table and give new job id= max(id)+1
my $sql_statement = "SELECT MAX(CAST(id AS INTEGER)) FROM $table";
- &create_lock($self,'add_dbentry');
my $max_id = @{ @{ $self->{dbh}->selectall_arrayref($sql_statement) }[0] }[0];
- &remove_lock($self,'add_dbentry');
my $id;
if( defined $max_id) {
$id = $max_id + 1;
# check wether primkey is unique in table, otherwise return errorflag
my $sql_statement = "SELECT * FROM $table $prim_statement";
- &create_lock($self,'add_dbentry');
my $res = @{ $self->{dbh}->selectall_arrayref($sql_statement) };
- &remove_lock($self,'add_dbentry');
if ($res == 0) {
# primekey is unique
}
my $sql_statement = "INSERT INTO $table (".join(", ", @col_list).") VALUES ('".join("', '", @val_list)."')";
- &create_lock($self,'add_dbentry');
my $db_res = $self->{dbh}->do($sql_statement);
- &remove_lock($self,'add_dbentry');
if( $db_res != 1 ) {
return (4, $sql_statement);
}
if(exists $col_names->{$table}) {
@column_names = @{$col_names->{$table}};
} else {
- &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]);
my $self = shift;
my $sql_statement = shift;
- &create_lock($self,'exec_statement');
my @db_answer = @{$self->{dbh}->selectall_arrayref($sql_statement)};
- &remove_lock($self, 'exec_statement');
return \@db_answer;
}
my $sql_list = shift;
my @db_answer;
- &create_lock($self,'exec_statement');
foreach my $sql (@$sql_list) {
@db_answer = @{$self->{dbh}->selectall_arrayref($sql)};
}
- &remove_lock($self, 'exec_statement');
return \@db_answer;
}
my $sql_statement_drop = "DROP TABLE IF EXISTS $to";
my $sql_statement_alter = "ALTER TABLE $from RENAME TO $to";
- &create_lock($self,'move_table');
- my $db_res = $self->{dbh}->do($sql_statement_drop);
- $db_res = $self->{dbh}->do($sql_statement_alter);
- &remove_lock($self,'move_table');
return;
}