Commit 10049e07 authored by Ronan's avatar Ronan

fix(Abstract): in reconnect case, disable foreign key before init call

parent 7d491f86
......@@ -35,6 +35,8 @@ public:
DbSession dbSession;
private:
void safeInit ();
AbstractDb::Backend backend;
L_DECLARE_PUBLIC(AbstractDb);
......
......@@ -43,6 +43,15 @@ LINPHONE_BEGIN_NAMESPACE
}
#endif // if defined(SOCI_ENABLED) && (TARGET_OS_IPHONE || defined(__ANDROID__))
void AbstractDbPrivate::safeInit () {
#ifdef SOCI_ENABLED
L_Q();
dbSession.enableForeignKeys(false);
q->init();
dbSession.enableForeignKeys(true);
#endif // ifdef SOCI_ENABLED
}
AbstractDb::AbstractDb (AbstractDbPrivate &p) : Object(p) {}
bool AbstractDb::connect (Backend backend, const string &parameters) {
......@@ -66,11 +75,7 @@ bool AbstractDb::connect (Backend backend, const string &parameters) {
if (d->dbSession) {
try {
#ifdef SOCI_ENABLED
d->dbSession.enableForeignKeys(false);
init();
d->dbSession.enableForeignKeys(true);
#endif // ifdef SOCI_ENABLED
d->safeInit();
} catch (const exception &e) {
lWarning() << "Unable to init database: " << e.what();
......@@ -99,14 +104,11 @@ bool AbstractDb::forceReconnect () {
lInfo() << "Trying sql backend reconnect...";
try {
soci::session *session = d->dbSession.getBackendSession();
session->close();
for (int i = 0; i < retryCount; ++i) {
try {
lInfo() << "Reconnect... Try: " << i;
session->reconnect();
init();
d->dbSession.getBackendSession()->reconnect(); // Equivalent to close and connect.
d->safeInit();
lInfo() << "Database reconnection successful!";
return true;
} catch (const soci::soci_error &e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment