
Originally Posted by
codeman
Thank you very much for sharing your experiences. But what in detail means this:
Here:
MyDatabase::getDatabase (const string & name)
throw (FlowException)
{
if ( _db.isValid() && _db.isOpen()) {
DB_NAME_MAP::iterator dItr = _dbCountMap.find (name);
if (dItr != _dbCountMap.end()) {
bool refRet = dItr->second.ref();
} else {
QAtomicInt newCounter;
newCounter.ref();
_dbCountMap[name] = newCounter;
}
return _db;
}
throw DataAccessLayerException("database '" + name + "' not open or valid");
}
void
MyDatabase::close(const string & name)
{
// only close if reference counter is 0.
bool derefRet = false;
DB_NAME_MAP::iterator dItr = _dbCountMap.find (name);
if (dItr != _dbCountMap.end()) {
derefRet = dItr->second.deref();
} else {
throw DataAccessLayerException ("Unknown database");
}
if (! derefRet) {
_db.close();
_dbCountMap.erase (name);
}
}
QSqlDatabase
MyDatabase::getDatabase (const string & name)
throw (FlowException)
{
QSqlDatabase _db = QSqlDatabase::database(QString::fromStdString(name), true);
if ( _db.isValid() && _db.isOpen()) {
DB_NAME_MAP::iterator dItr = _dbCountMap.find (name);
if (dItr != _dbCountMap.end()) {
bool refRet = dItr->second.ref();
} else {
QAtomicInt newCounter;
newCounter.ref();
_dbCountMap[name] = newCounter;
}
return _db;
}
throw DataAccessLayerException("database '" + name + "' not open or valid");
}
void
MyDatabase::close(const string & name)
{
QSqlDatabase _db = QSqlDatabase::database(QString::fromStdString(name), false);
// only close if reference counter is 0.
bool derefRet = false;
DB_NAME_MAP::iterator dItr = _dbCountMap.find (name);
if (dItr != _dbCountMap.end()) {
derefRet = dItr->second.deref();
} else {
throw DataAccessLayerException ("Unknown database");
}
if (! derefRet) {
_db.close();
_dbCountMap.erase (name);
}
}
To copy to clipboard, switch view to plain text mode

Originally Posted by
codeman
Do you connect from one client to n DB´s??
Yes. I support multiple database connections w/in the same running application.
Bookmarks