DBDriver: when an empty database url is provided, an empty database "in memory" is used by default. Tango: fixed second database not recorded in Data Recorder mode (now creating a new one on save). Mapping parameters are saved in database instead of the one used to record data (Data Recorder mode).

This commit is contained in:
matlabbe
2016-11-23 15:13:09 -05:00
parent 639896b309
commit 23bb5d5147
9 changed files with 77 additions and 47 deletions

View File

@@ -314,24 +314,29 @@ bool DBDriverSqlite3::connectDatabaseQuery(const std::string & url, bool overwri
// Open a database connection
_ppDb = 0;
if(url.empty())
{
UERROR("url is empty...");
return false;
}
int rc = SQLITE_OK;
bool dbFileExist = UFile::exists(url.c_str());
if(dbFileExist && overwritten)
bool dbFileExist = false;
if(!url.empty())
{
UINFO("Deleting database %s...", url.c_str());
UASSERT(UFile::erase(url.c_str()) == 0);
dbFileExist = false;
dbFileExist = UFile::exists(url.c_str());
if(dbFileExist && overwritten)
{
UINFO("Deleting database %s...", url.c_str());
UASSERT(UFile::erase(url.c_str()) == 0);
dbFileExist = false;
}
}
if(_dbInMemory)
if(_dbInMemory || url.empty())
{
ULOGGER_INFO("Using database \"%s\" in the memory.", url.c_str());
if(!url.empty())
{
ULOGGER_INFO("Using database \"%s\" in the memory.", url.c_str());
}
else
{
ULOGGER_INFO("Using empty database in the memory.");
}
rc = sqlite3_open_v2(":memory:", &_ppDb, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
}
else
@@ -364,7 +369,10 @@ bool DBDriverSqlite3::connectDatabaseQuery(const std::string & url, bool overwri
if(!dbFileExist)
{
ULOGGER_INFO("Database \"%s\" doesn't exist, creating a new one...", url.c_str());
if(!url.empty())
{
ULOGGER_INFO("Database \"%s\" doesn't exist, creating a new one...", url.c_str());
}
// Create the database
std::string schema = DATABASESCHEMA_SQL;
schema = uHex2Str(schema);
@@ -407,7 +415,7 @@ void DBDriverSqlite3::disconnectDatabaseQuery(bool save, const std::string & out
}
}
if(save && _dbInMemory)
if(save && (_dbInMemory || this->getUrl().empty()))
{
UTimer timer;
timer.start();
@@ -416,10 +424,18 @@ void DBDriverSqlite3::disconnectDatabaseQuery(bool save, const std::string & out
{
outputFile = outputUrl;
}
UINFO("Saving database to %s ...", outputFile.c_str());
rc = loadOrSaveDb(_ppDb, outputFile, 1); // Save memory to file
UASSERT_MSG(rc == SQLITE_OK, uFormat("DB error (%s): %s", _version.c_str(), sqlite3_errmsg(_ppDb)).c_str());
ULOGGER_DEBUG("Saving DB time = %fs", timer.ticks());
if(outputFile.empty())
{
UERROR("Database was initialized with an empty url (in memory). To save it "
"the output url should not be empty. The database is thus closed without being saved!");
}
else
{
UINFO("Saving database to %s ...", outputFile.c_str());
rc = loadOrSaveDb(_ppDb, outputFile, 1); // Save memory to file
UASSERT_MSG(rc == SQLITE_OK, uFormat("DB error (%s): %s", _version.c_str(), sqlite3_errmsg(_ppDb)).c_str());
ULOGGER_DEBUG("Saving DB time = %fs", timer.ticks());
}
}
else if(save && !outputUrl.empty() && outputUrl.compare(this->getUrl()) != 0)
{

View File

@@ -151,7 +151,7 @@ bool Memory::init(const std::string & dbUrl, bool dbOverwritten, const Parameter
if(postInitClosingEvents) UEventsManager::post(new RtabmapEventInit("Closing database connection, done!"));
}
if(_dbDriver == 0 && !dbUrl.empty())
if(_dbDriver == 0)
{
_dbDriver = DBDriver::create(parameters);
}
@@ -161,11 +161,11 @@ bool Memory::init(const std::string & dbUrl, bool dbOverwritten, const Parameter
{
_dbDriver->setTimestampUpdateEnabled(true); // make sure that timestamp update is enabled (may be disabled above)
success = false;
if(postInitClosingEvents) UEventsManager::post(new RtabmapEventInit(std::string("Connecting to database ") + dbUrl + "..."));
if(postInitClosingEvents) UEventsManager::post(new RtabmapEventInit(std::string("Connecting to database \"") + dbUrl + "\"..."));
if(_dbDriver->openConnection(dbUrl, dbOverwritten))
{
success = true;
if(postInitClosingEvents) UEventsManager::post(new RtabmapEventInit(std::string("Connecting to database ") + dbUrl + ", done!"));
if(postInitClosingEvents) UEventsManager::post(new RtabmapEventInit(std::string("Connecting to database \"") + dbUrl + "\", done!"));
// Load the last working memory...
std::list<Signature*> dbSignatures;

View File

@@ -284,7 +284,7 @@ void Rtabmap::init(const ParametersMap & parameters, const std::string & databas
}
else
{
UWARN("Using empty database. Mapping session will not be saved.");
UWARN("Using empty database. Mapping session will not be saved unless it is closed with an output database path.");
}
bool newDatabase = _databasePath.empty() || !UFile::exists(_databasePath);