From 9e0b45e27a348f05629af81ddf730f869244590b Mon Sep 17 00:00:00 2001 From: matlabbe Date: Sat, 29 Oct 2016 18:12:27 -0400 Subject: [PATCH] Fixed "UNIQUE constraint failed: Statistics.id" error when loading a previous map with last id saved in Statistics not in Node table (this happened when ignored locations are not saved to database). --- corelib/src/DBDriver.cpp | 9 +++++++++ corelib/src/DBDriverSqlite3.cpp | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/corelib/src/DBDriver.cpp b/corelib/src/DBDriver.cpp index f5666e95..1dbf4f56 100644 --- a/corelib/src/DBDriver.cpp +++ b/corelib/src/DBDriver.cpp @@ -783,6 +783,15 @@ void DBDriver::getLastNodeId(int & id) const _dbSafeAccessMutex.lock(); this->getLastIdQuery("Node", id); + int statisticsId = 0; + if(uStrNumCmp(this->getDatabaseVersion(), "0.11.11") >= 0) + { + this->getLastIdQuery("Statistics", statisticsId); + if(statisticsId > id) + { + id = statisticsId; + } + } _dbSafeAccessMutex.unlock(); } diff --git a/corelib/src/DBDriverSqlite3.cpp b/corelib/src/DBDriverSqlite3.cpp index bb3208ad..384d836c 100644 --- a/corelib/src/DBDriverSqlite3.cpp +++ b/corelib/src/DBDriverSqlite3.cpp @@ -3163,7 +3163,7 @@ void DBDriverSqlite3::updateOccupancyGridQuery( void DBDriverSqlite3::addStatisticsQuery(const Statistics & statistics) const { - UDEBUG(""); + UDEBUG("Ref ID = %d", statistics.refImageId()); if(_ppDb) { std::string type;