10#include <soci/mysql/soci-mysql.h>
20 DBSessionManager::DBSessionManager () : _dbSession (NULL) {
24 DBSessionManager::DBSessionManager (
const DBSessionManager&)
30 DBSessionManager::~DBSessionManager () {
36 void DBSessionManager::dbInit (
const BasDBParams& iDBParams) {
39 std::ostringstream oStr;
40 oStr <<
"db=" << iDBParams.getDBName() <<
" user=" << iDBParams.getUser()
41 <<
" password=" << iDBParams.getPassword()
42 <<
" port=" << iDBParams.getPort() <<
" host=" << iDBParams.getHost();
43 const std::string lDBSessionConnectionString (oStr.str());
50 _dbSession->open (soci::mysql, lDBSessionConnectionString);
52 }
catch (std::exception
const& lException) {
53 std::ostringstream oMessage;
54 oMessage <<
"Error while opening a connection to database: "
55 << lException.what() << std::endl
56 <<
"Database parameters used:"
57 <<
" db=" << iDBParams.getDBName()
58 <<
" user=" << iDBParams.getUser()
59 <<
" port=" << iDBParams.getPort()
60 <<
" host=" << iDBParams.getHost();
61 throw SQLDatabaseConnectionImpossibleException (oMessage.str());
66 void DBSessionManager::dbFinalise () {
67 delete _dbSession; _dbSession = NULL;
71 void DBSessionManager::init (
const BasDBParams& iDBParams) {
72 DBSessionManager& lInstance = instance();
73 lInstance.dbInit (iDBParams);
83 void DBSessionManager::clean() {
88 if (_dbSession == NULL) {
91 assert (_dbSession != NULL);
Handle on the StdAir library context.
soci::session DBSession_T