9 #if defined(SOCI_HEADERS_BURIED)
10 #include <soci/core/soci.h>
11 #include <soci/backends/mysql/soci-mysql.h>
12 #else // SOCI_HEADERS_BURIED
14 #include <mysql/soci-mysql.h>
15 #endif // SOCI_HEADERS_BURIED
25 DBSessionManager::DBSessionManager () : _dbSession (NULL) {
29 DBSessionManager::DBSessionManager (
const DBSessionManager&)
35 DBSessionManager::~DBSessionManager () {
41 void DBSessionManager::dbInit (
const BasDBParams& iDBParams) {
44 std::ostringstream oStr;
45 oStr <<
"db=" << iDBParams.getDBName() <<
" user=" << iDBParams.getUser()
46 <<
" password=" << iDBParams.getPassword()
47 <<
" port=" << iDBParams.getPort() <<
" host=" << iDBParams.getHost();
48 const std::string lDBSessionConnectionString (oStr.str());
55 _dbSession->open (soci::mysql, lDBSessionConnectionString);
57 }
catch (std::exception
const& lException) {
58 std::ostringstream oMessage;
59 oMessage <<
"Error while opening a connection to database: "
60 << lException.what() << std::endl
61 <<
"Database parameters used:"
62 <<
" db=" << iDBParams.getDBName()
63 <<
" user=" << iDBParams.getUser()
64 <<
" port=" << iDBParams.getPort()
65 <<
" host=" << iDBParams.getHost();
66 throw SQLDatabaseConnectionImpossibleException (oMessage.str());
71 void DBSessionManager::dbFinalise () {
72 delete _dbSession; _dbSession = NULL;
76 void DBSessionManager::init (
const BasDBParams& iDBParams) {
77 DBSessionManager& lInstance =
instance();
78 lInstance.dbInit (iDBParams);
88 void DBSessionManager::clean() {
93 if (_dbSession == NULL) {
96 assert (_dbSession != NULL);
Handle on the StdAir library context.
DBSession_T & getDBSession() const
soci::session DBSession_T
static DBSessionManager & instance()