summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 85d8706)
raw | patch | inline | side by side (parent: 85d8706)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 17 Apr 2008 10:56:54 +0000 (10:56 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 17 Apr 2008 10:56:54 +0000 (10:56 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10534 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-si/gosa-si-server | patch | blob | history | |
gosa-si/modules/DBsqlite.pm | patch | blob | history | |
gosa-si/modules/GosaPackages.pm | patch | blob | history | |
gosa-si/tests/client.php | patch | blob | history |
diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index 4ce75e95791d3b7d15d4053d72dd0003cb262506..b70ec8430ed2214638cb9570b85dbd4116db05c6 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
our $job_db;
our $job_queue_tn = 'jobs';
my $job_queue_file_name;
-my @job_queue_col_names = ("id INTEGER",
- "timestamp",
+my @job_queue_col_names = ("id INTEGER PRIMARY KEY",
+ "timestamp DEFAULT 'none'",
"status DEFAULT 'none'",
"result DEFAULT 'none'",
"progress DEFAULT 'none'",
- "headertag DEFAULT 'none'",
+ "headertag DEFAULT 'none'",
"targettag DEFAULT 'none'",
"xmlmessage DEFAULT 'none'",
"macaddress DEFAULT 'none'",
index a629320a15f7e412eb5ef911657f35b49659525a..2b260dac148b7a28bc586f5b7fa402264971d12b 100644 (file)
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");
+ my $dbh = DBI->connect("dbi:SQLite:dbname=$db_name", "", "", {RaiseError => 1, AutoCommit => 1});
$self->{dbh} = $dbh;
$self->{db_name} = $db_name;
$self->{db_lock} = $lock;
return($self);
}
+
sub create_table {
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);
- }
+ my $col_names_string = join(", ", @{$col_names_ref});
+ my $sql_statement = "CREATE TABLE IF NOT EXISTS $table_name ($col_names_string )";
- $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' )";
$self->{dbh}->do($sql_statement);
return 0;
}
sub add_dbentry {
my $self = shift;
my $arg = shift;
+ my $res = 0; # default value
# if dbh not specified, return errorflag 1
my $table = $arg->{table};
return 1 ;
}
- # specify primary key in table
- if (not exists $arg->{primkey}) {
- return (2, "a hash key 'primkey' with at least an empty list as value is necessary for add_dbentry");
+ # if timestamp is not provided, add timestamp
+ if( not exists $arg->{timestamp} ) {
+ $arg->{timestamp} = &get_time;
}
+
+ # check primkey and run insert or update
my $primkeys = $arg->{'primkey'};
my $prim_statement="";
if( 0 != @$primkeys ) { # more than one primkey exist in list
my @prim_list;
foreach my $primkey (@$primkeys) {
- 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";
- my $max_id = @{ @{ $self->{dbh}->selectall_arrayref($sql_statement) }[0] }[0];
- my $id;
- if( defined $max_id) {
- $id = $max_id + 1;
- } else {
- $id = 1;
- }
- $arg->{id} = $id;
- }
if( not exists $arg->{$primkey} ) {
return (3, "primkey '$primkey' has no value for add_dbentry");
}
push(@prim_list, "$primkey='".$arg->{$primkey}."'");
}
$prim_statement = "WHERE ".join(" AND ", @prim_list);
- }
-
- # if timestamp is not provided, add timestamp
- if( not exists $arg->{timestamp} ) {
- $arg->{timestamp} = &get_time;
- }
- # check wether primkey is unique in table, otherwise return errorflag
- my $sql_statement = "SELECT * FROM $table $prim_statement";
- my $res = @{ $self->{dbh}->selectall_arrayref($sql_statement) };
+ # check wether primkey is unique in table, otherwise return errorflag
+ my $sql_statement = "SELECT * FROM $table $prim_statement";
+ $res = @{ $self->{dbh}->selectall_arrayref($sql_statement) };
+ }
- # primekey is unique
+ # primekey is unique or no primkey specified -> run insert
if ($res == 0) {
# fetch column names of table
my $col_names = &get_table_columns($self, $table);
foreach my $col_name (@{$col_names}) {
# use function parameter for column values
if (exists $arg->{$col_name}) {
- push(@col_list, $col_name);
- push(@val_list, $arg->{$col_name});
- }
+ push(@col_list, "'".$col_name."'");
+ push(@val_list, "'".$arg->{$col_name}."'");
+ }
}
- my $sql_statement = "INSERT INTO $table (".join(", ", @col_list).") VALUES ('".join("', '", @val_list)."')";
+ my $sql_statement = "INSERT INTO $table (".join(", ", @col_list).") VALUES (".join(", ", @val_list).")";
my $db_res = $self->{dbh}->do($sql_statement);
if( $db_res != 1 ) {
return (4, $sql_statement);
}
- # entry already exists, so update it
+ # entry already exists -> run update
} else {
my @update_l;
while( my ($pram, $val) = each %{$arg} ) {
my $sql_statement= "SELECT * FROM $table_name ORDER BY timestamp";
my $res= &exec_statement($self, $sql_statement);
-
my @answer;
foreach my $hit (@{$res}) {
push(@answer, "hit: ".join(', ', @{$hit}));
index 1141a1d59822ab2eaa3b8a1f3dc6640d0a6d0b05..f03074b18c8fe398cf610294445317ab981cd73c 100644 (file)
if( $error == 0 ) {
# add job to job queue
my $func_dic = {table=>$main::job_queue_tn,
- primkey=>['id'],
+ primkey=>[],
timestamp=>$timestamp,
status=>'waiting',
result=>'none',
macaddress=>$macaddress,
plainname=>$plain_name,
};
-
my $res = $main::job_db->add_dbentry($func_dic);
if (not $res == 0) {
&main::daemon_log("$session_id ERROR: GosaPackages: process_job_msg: $res", 1);
index 7609df6a9abc70bc5c9d5de21b674f050674a35f..f21fa09d1c1e88e5203f7a1db98ef41b4d5fef12 100755 (executable)
--- a/gosa-si/tests/client.php
+++ b/gosa-si/tests/client.php
# jobdb add
#$data = "<xml> <header>gosa_network_completition</header> <source>GOSA</source><target>GOSA</target><hostname>ws-muc-2</hostname></xml>";
-#$data = "<xml> <header>job_sayHello</header> <source>10.89.1.155:20083</source><target>00:01:6c:9d:b9:fa</target><mac>00:1B:77:04:8A:6C</mac> <timestamp>20130102133900</timestamp> </xml>";
+$data = "<xml> <header>job_sayHello</header> <source>10.89.1.155:20083</source><target>00:01:6c:9d:b9:fa</target><mac>00:1B:77:04:8A:6C</mac> <timestamp>20130102133908</timestamp> </xml>";
#$data = "<xml> <header>job_ping</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:01:6c:9d:b9:fa</macaddress><timestamp>19700101000000</timestamp> </xml>";
# get_client_for_login_usr
#$data = "<xml> <header>gosa_get_client_for_login_usr</header> <target>GOSA</target> <source>GOSA</source> <usr>harald</usr></xml>";
-# recreate_fai_server_db
+##################
+# recreate fai dbs
#$data = "<xml> <header>gosa_recreate_fai_server_db</header> <target>GOSA</target> <source>GOSA</source></xml>";
-$data = "<xml> <header>gosa_recreate_fai_release_db</header> <target>GOSA</target> <source>GOSA</source></xml>";
+#$data = "<xml> <header>gosa_recreate_fai_release_db</header> <target>GOSA</target> <source>GOSA</source></xml>";
+#$data = "<xml> <header>gosa_recreate_packages_list_db</header> <target>GOSA</target> <source>GOSA</source></xml>";
###########
# messaging