mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-12-10 14:46:26 +01:00
Implemented database reconnect in RDSqlQuery::RDSqlQuery in 'lib/rddb.cpp'.
This commit is contained in:
@@ -17625,3 +17625,6 @@
|
||||
2018-09-06 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Added instructions for building 'rivwebcapi' under Visual Studio
|
||||
2013 to 'INSTALL-WINDOWS'.
|
||||
2018-09-07 Patrick Linstruth <patrick@deltecent.com>
|
||||
Implemented database reconnect in RDSqlQuery::RDSqlQuery in
|
||||
'lib/rddb.cpp'.
|
||||
|
||||
23
lib/rddb.cpp
23
lib/rddb.cpp
@@ -39,8 +39,29 @@
|
||||
RDSqlQuery::RDSqlQuery (const QString &query,bool reconnect):
|
||||
QSqlQuery(query)
|
||||
{
|
||||
QSqlDatabase db;
|
||||
QString err;
|
||||
sql_columns=0;
|
||||
|
||||
if (!isActive() && reconnect) {
|
||||
db = QSqlDatabase::database();
|
||||
|
||||
if (db.open()) {
|
||||
clear();
|
||||
exec(query);
|
||||
err=QObject::tr("DB connection re-established");
|
||||
}
|
||||
else {
|
||||
err=QObject::tr("Could not re-establish DB connection")+
|
||||
+"["+db.lastError().text()+"]";
|
||||
}
|
||||
|
||||
fprintf(stderr,"%s\n",(const char *)err);
|
||||
#ifndef WIN32
|
||||
syslog(LOG_ERR,(const char *)err);
|
||||
#endif
|
||||
}
|
||||
|
||||
if(isActive()) {
|
||||
QStringList f0=query.split(" ");
|
||||
if(f0[0].toLower()=="select") {
|
||||
@@ -58,7 +79,7 @@ RDSqlQuery::RDSqlQuery (const QString &query,bool reconnect):
|
||||
}
|
||||
}
|
||||
else {
|
||||
QString err=QObject::tr("invalid SQL or failed DB connection")+
|
||||
err=QObject::tr("invalid SQL or failed DB connection")+
|
||||
+"["+lastError().text()+"]: "+query;
|
||||
|
||||
fprintf(stderr,"%s\n",(const char *)err);
|
||||
|
||||
Reference in New Issue
Block a user