} else {
# insert
+ # check if it exists first
+ if (my $id = PMG::Utils::get_existing_object_id(
+ $ruledb->{dbh},
+ $self->{ogroup},
+ $self->otype(),
+ $confdata
+ )) {
+ return $id;
+ }
+
my $sth = $ruledb->{dbh}->prepare(
"INSERT INTO Object (Objectgroup_ID, ObjectType, Value) " .
"VALUES (?, ?, ?);");
} else {
# insert
+ # check if it exists first
+ if (my $id = PMG::Utils::get_existing_object_id(
+ $ruledb->{dbh},
+ $self->{ogroup},
+ $self->otype(),
+ $confdata
+ )) {
+ return $id;
+ }
+
my $sth = $ruledb->{dbh}->prepare(
"INSERT INTO Object (Objectgroup_ID, ObjectType, Value) " .
"VALUES (?, ?, ?);");
} else {
# insert
+ # check if it exists first
+ if (my $id = PMG::Utils::get_existing_object_id(
+ $ruledb->{dbh},
+ $self->{ogroup},
+ $self->otype(),
+ $adr
+ )) {
+ return $id;
+ }
+
my $sth = $ruledb->{dbh}->prepare (
"INSERT INTO Object (Objectgroup_ID, ObjectType, Value) " .
"VALUES (?, ?, ?);");
return $fresh_updates
}
+sub get_existing_object_id {
+ my ($dbh, $obj_id, $obj_type, $value) = @_;
+
+ my $sth = $dbh->prepare("SELECT id FROM Object WHERE ".
+ "Objectgroup_ID = ? AND ".
+ "ObjectType = ? AND ".
+ "Value = ?"
+ );
+ $sth->execute($obj_id, $obj_type, $value);
+
+ if (my $ref = $sth->fetchrow_hashref()) {
+ return $ref->{id};
+ }
+
+ return;
+}
+
1;