From f75ff8b56ca98efe86be24a0c993ffbdfe21b1c1 Mon Sep 17 00:00:00 2001 From: janw Date: Mon, 21 Apr 2008 12:29:19 +0000 Subject: [PATCH] Reverted add_dbentry to include changes from before. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10585 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/modules/DBsqlite.pm | 47 ++++++++++--------------------------- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/gosa-si/modules/DBsqlite.pm b/gosa-si/modules/DBsqlite.pm index ea0f31f54..62cd8a6dc 100644 --- a/gosa-si/modules/DBsqlite.pm +++ b/gosa-si/modules/DBsqlite.pm @@ -85,30 +85,6 @@ sub add_dbentry { 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; - eval { - $max_id = @{ @{ $self->{dbh}->selectall_arrayref($sql_statement) }[0] }[0]; - }; - if($@) { - $self->{dbh}->do("ANALYZE"); - eval { - $max_id = @{ @{ $self->{dbh}->selectall_arrayref($sql_statement) }[0] }[0]; - }; - if($@) { - &main::daemon_log("ERROR: $sql_statement failed with $@", 1); - } - } - 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"); } @@ -116,21 +92,22 @@ sub add_dbentry { } $prim_statement = "WHERE ".join(" AND ", @prim_list); - # check wether primkey is unique in table, otherwise return errorflag - my $sql_statement = "SELECT * FROM $table $prim_statement"; - my $res; - eval { - $res = @{ $self->{dbh}->selectall_arrayref($sql_statement) }; - }; - if($@) { - $self->{dbh}->do("ANALYZE"); + # check wether primkey is unique in table, otherwise return errorflag + my $sql_statement = "SELECT * FROM $table $prim_statement"; eval { - $res = @{ $self->{dbh}->selectall_arrayref($sql_statement) }; + $res = @{ $self->{dbh}->selectall_arrayref($sql_statement) }; }; if($@) { - &main::daemon_log("ERROR: $sql_statement failed with $@", 1); + $self->{dbh}->do("ANALYZE"); + eval { + $res = @{ $self->{dbh}->selectall_arrayref($sql_statement) }; + }; + if($@) { + &main::daemon_log("ERROR: $sql_statement failed with $@", 1); + } } - } + + } # primekey is unique or no primkey specified -> run insert if ($res == 0) { -- 2.30.2