summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAaron McCarthy <amccarthy@sigtec.com>2012-11-08 05:13:10 (GMT)
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-23 09:20:20 (GMT)
commit5c5358930afe743cc293911ec284549f3feeb687 (patch)
treef93a75ba022151206db68396f28f396dc5107b8f /tests
parent58384f346b13b27c58a2efb3ba8b6be98ab54fbf (diff)
downloadQt-5c5358930afe743cc293911ec284549f3feeb687.zip
Qt-5c5358930afe743cc293911ec284549f3feeb687.tar.gz
Qt-5c5358930afe743cc293911ec284549f3feeb687.tar.bz2
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. Backported from Qt5/qtbase change 7456562e7f647e7cb2c854c4272c5599b26dbd37 Change-Id: I43087a44d74de38918c7285a228e2f3d25d070fd Reviewed-by: Mark Brand <mabrand@mabrand.nl>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qsqldatabase/tst_qsqldatabase.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp
index 6839a64..ff1aeba 100644
--- a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp
+++ b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp
@@ -93,6 +93,8 @@ private slots:
void eventNotification_data() { generic_data(); }
void eventNotification();
void addDatabase();
+ void errorReporting_data();
+ void errorReporting();
//database specific tests
void recordMySQL_data() { generic_data("QMYSQL"); }
@@ -460,6 +462,36 @@ void tst_QSqlDatabase::addDatabase()
QVERIFY(!QSqlDatabase::contains("INVALID_CONNECTION"));
}
+void tst_QSqlDatabase::errorReporting_data()
+{
+ QTest::addColumn<QString>("driver");
+
+ QTest::newRow("QTDS") << QString::fromLatin1("QTDS");
+ QTest::newRow("QTDS7") << QString::fromLatin1("QTDS7");
+}
+
+void tst_QSqlDatabase::errorReporting()
+{
+ QFETCH(QString, driver);
+
+ if (!QSqlDatabase::drivers().contains(driver))
+ QSKIP(QString::fromLatin1("Database driver %1 not available").arg(driver).toLocal8Bit().constData(), SkipSingle);
+
+ const QString dbName = QLatin1String("errorReportingDb-") + driver;
+ QSqlDatabase db = QSqlDatabase::addDatabase(driver, dbName);
+
+ db.setHostName(QLatin1String("127.0.0.1"));
+ db.setDatabaseName(QLatin1String("NonExistantDatabase"));
+ db.setUserName(QLatin1String("InvalidUser"));
+ db.setPassword(QLatin1String("IncorrectPassword"));
+
+ QVERIFY(!db.open());
+
+ db = QSqlDatabase();
+
+ QSqlDatabase::removeDatabase(dbName);
+}
+
void tst_QSqlDatabase::open()
{
QFETCH(QString, dbName);