From 2fafa45b1661a1200399983489d5dc153d69f2e4 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Thu, 17 Jul 2008 19:45:41 +0000 Subject: * fixed problem a least one database server (mysql) not being able to start with an auto-increment value of 0 (for "<<>>" entries) git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@1932 95ad53e4-c205-0410-b2fa-d234c58c8868 --- config-db/OpenSLX/MetaDB/DBI.pm | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'config-db') diff --git a/config-db/OpenSLX/MetaDB/DBI.pm b/config-db/OpenSLX/MetaDB/DBI.pm index c4606f0c..4bb8ce88 100644 --- a/config-db/OpenSLX/MetaDB/DBI.pm +++ b/config-db/OpenSLX/MetaDB/DBI.pm @@ -552,10 +552,23 @@ sub _doInsert $sth->execute() or croak _tr(q[Can't insert into table <%s> (%s)], $table, $dbh->errstr); - if (!$ignoreIDs && !defined $valRow->{id}) { - # id has not been pre-specified, we need to fetch it from DB: - $valRow->{'id'} = $dbh->last_insert_id(undef, undef, $table, 'id'); - vlog(3, "DB-generated id for <$table> is <$valRow->{id}>"); + if (!$ignoreIDs) { + my $lastID = $dbh->last_insert_id(undef, undef, $table, 'id'); + if (!defined $valRow->{id}) { + # id has not been pre-specified, we need to fetch it from DB: + $valRow->{'id'} = $lastID; + vlog(3, "DB-generated id for <$table> is <$valRow->{id}>"); + } + elsif ($valRow->{'id'} != $lastID) { + # id has been pre-specified, but DB changed it, so we update + # it with the pre-specified value + my $sql2 + = "UPDATE $table SET id=$valRow->{'id'} WHERE id=$lastID"; + vlog(3, $sql2); + $dbh->do($sql2) or croak _tr( + q[Can't update table <%s> (%s)], $table, $dbh->errstr + ); + } } push @ids, $valRow->{'id'}; } @@ -1332,8 +1345,8 @@ sub schemaAddTable $dbh->do($sql) or croak _tr(q[Can't create table <%s> (%s)], $table, $dbh->errstr); if (defined $initialVals) { - my $ignoreIDs = ($colDescrString !~ m[\bid\b]); # don't care about IDs if there's no 'id' column in this table + my $ignoreIDs = ($colDescrString !~ m[\bid\b]); $self->_doInsert($table, $initialVals, $ignoreIDs); } return; -- cgit v1.2.3-55-g7522