summaryrefslogtreecommitdiffstats
path: root/config-db
diff options
context:
space:
mode:
authorOliver Tappe2008-07-17 21:45:41 +0200
committerOliver Tappe2008-07-17 21:45:41 +0200
commit2fafa45b1661a1200399983489d5dc153d69f2e4 (patch)
tree1d9b9c929bc6fb5c7c96a6352d2250a635229f72 /config-db
parent* Sync of changeset 1929 (diff)
downloadcore-2fafa45b1661a1200399983489d5dc153d69f2e4.tar.gz
core-2fafa45b1661a1200399983489d5dc153d69f2e4.tar.xz
core-2fafa45b1661a1200399983489d5dc153d69f2e4.zip
* fixed problem a least one database server (mysql) not being able to start
with an auto-increment value of 0 (for "<<<default>>>" entries) git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@1932 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'config-db')
-rw-r--r--config-db/OpenSLX/MetaDB/DBI.pm23
1 files changed, 18 insertions, 5 deletions
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;