summaryrefslogtreecommitdiffstats
path: root/src/sql/drivers
diff options
context:
space:
mode:
authorAaron McCarthy <amccarthy@sigtec.com>2012-11-08 15:13:10 +1000
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-18 23:13:29 +0100
commit7456562e7f647e7cb2c854c4272c5599b26dbd37 (patch)
treeec81d7d072f1078474516a1bf1455c2f1b065e1d /src/sql/drivers
parent597a6024f468e97d26a22105791b21bc05bdfca6 (diff)
Fix error reporting in TDS SQL driver.
The error and message handlers used by the freetds library were getting reset to back to the default every time a database was opened. The Qt TDS SQL driver was calling dbinit() from QTDSDriver::open(). This had two problems: 1. dbinit() would reset the error handler previously set by a call to dberrhandle(). A db error would then cause the application to abort. 2. freetds expects dbinit() and dbexit() to be called symmetrically. Opening multiple database connections would result in freetds not cleaning up on application close. Solved by moving the dbinit() call into the QTDSDriver constructor. Change-Id: I59018d83238672c903b96a4d7f3f21b664c3ff4c Reviewed-by: Andy Shaw <andy.shaw@digia.com> Reviewed-by: Mark Brand <mabrand@mabrand.nl>
Diffstat (limited to 'src/sql/drivers')
-rw-r--r--src/sql/drivers/tds/qsql_tds.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/sql/drivers/tds/qsql_tds.cpp b/src/sql/drivers/tds/qsql_tds.cpp
index 35195c6f02..f740360550 100644
--- a/src/sql/drivers/tds/qsql_tds.cpp
+++ b/src/sql/drivers/tds/qsql_tds.cpp
@@ -138,10 +138,11 @@ QSqlError qMakeError(const QString& err, QSqlError::ErrorType type, int errNo =
class QTDSDriverPrivate
{
public:
- QTDSDriverPrivate(): login(0) {}
+ QTDSDriverPrivate(): login(0), initialized(false) {}
LOGINREC* login; // login information
QString hostName;
QString db;
+ bool initialized;
};
@@ -537,6 +538,7 @@ QVariant QTDSDriver::handle() const
void QTDSDriver::init()
{
d = new QTDSDriverPrivate();
+ d->initialized = (dbinit() == SUCCEED);
// the following two code-lines will fail compilation on some FreeTDS versions
// just comment them out if you have FreeTDS (you won't get any errors and warnings then)
dberrhandle((QERRHANDLE)qTdsErrHandler);
@@ -578,7 +580,7 @@ bool QTDSDriver::open(const QString & db,
{
if (isOpen())
close();
- if (!dbinit()) {
+ if (!d->initialized) {
setOpenError(true);
return false;
}