From 435fe41d588540566f75b71ef43d3e54524e4cba Mon Sep 17 00:00:00 2001 From: Niklas Brandt Date: Mon, 26 Apr 2010 11:59:06 +0200 Subject: [PATCH] $self->{id} was not updated when the id in the database was automatically incremented when a new subnet was inserted. --- HOSTDB/Object/Subnet.pm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/HOSTDB/Object/Subnet.pm b/HOSTDB/Object/Subnet.pm index dfd25c1..197ee1e 100644 --- a/HOSTDB/Object/Subnet.pm +++ b/HOSTDB/Object/Subnet.pm @@ -98,6 +98,9 @@ sub init or die "$DBI::errstr"; $self->{_delete_subnet} = $hostdb->{_dbh}->prepare ("DELETE FROM $hostdb->{db}.subnet WHERE id = ?") or die "$DBI::errstr"; + + $self->{_get_last_id} = $hostdb->{_dbh}->prepare ("SELECT LAST_INSERT_ID()") + or die "$DBI::errstr"; } else { $hostdb->_debug_print ("NOT preparing database stuff (since my HOSTDB has no DBH)"); } @@ -171,6 +174,13 @@ sub commit $sth->execute (@db_values) or die "$DBI::errstr"; $sth->finish (); + + # fill in $self->{id} + $sth = $self->{_get_last_id}; + $sth->execute () or die "$DBI::errstr"; + my @t = $sth->fetchrow_array (); + $self->{id} = $t[0]; + $sth->finish (); } return 1;