forked from mirrors/linphone-iphone
fix(Abstract): in reconnect case, disable foreign key before init call
This commit is contained in:
parent
7d491f8689
commit
10049e078f
2 changed files with 14 additions and 10 deletions
|
|
@ -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 ¶meters) {
|
||||
|
|
@ -66,11 +75,7 @@ bool AbstractDb::connect (Backend backend, const string ¶meters) {
|
|||
|
||||
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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue