mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-04-23 17:21:03 +02:00
Merge pull request #228 from deltecent/rddb
Implemented database reconnect in RDSqlQuery::RDSqlQuery in 'lib/rddb.cpp'
This commit is contained in:
commit
ada526fbc2
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user