summaryrefslogtreecommitdiffstats
path: root/src/sql/kernel
diff options
context:
space:
mode:
authorHonglei Zhang <honglei.zhang@nokia.com>2011-12-08 15:38:25 +0200
committerQt by Nokia <qt-info@nokia.com>2011-12-12 10:43:44 +0100
commit67be01ae5048138e894fa8d3eb0abe93c5699048 (patch)
treeccb2c3f3e0c3f742d3a4f1b5d2cd20fd70521f20 /src/sql/kernel
parentb9ebb65c77ea779d4abbf92e93b8bef5a41c84bc (diff)
Check driver validity before using it
Even though it is stated in the documentation that the SQL driver must remain valid during the life time of QSqlQuery, there are users who don't follow the rule. It's common that the destructor of QSqlQuery is called after the driver is already deleted. This fix checks the validity of the SQLite driver before QSqliteResult uses it in destructor. Task-number: QTBUG-16967 Change-Id: If0f52113f12e14102da1671cd6e12bdaa267114f Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
Diffstat (limited to 'src/sql/kernel')
-rw-r--r--src/sql/kernel/qsqlresult.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/sql/kernel/qsqlresult.cpp b/src/sql/kernel/qsqlresult.cpp
index 71a81c0a8d..9065a6ad09 100644
--- a/src/sql/kernel/qsqlresult.cpp
+++ b/src/sql/kernel/qsqlresult.cpp
@@ -48,6 +48,7 @@
#include "qsqlresult.h"
#include "qvector.h"
#include "qsqldriver.h"
+#include "qpointer.h"
#include <QDebug>
QT_BEGIN_NAMESPACE
@@ -64,7 +65,7 @@ class QSqlResultPrivate
{
public:
QSqlResultPrivate(QSqlResult* d)
- : q(d), sqldriver(0), idx(QSql::BeforeFirstRow), active(false),
+ : q(d), idx(QSql::BeforeFirstRow), active(false),
isSel(false), forwardOnly(false), precisionPolicy(QSql::LowPrecisionDouble), bindCount(0), binds(QSqlResult::PositionalBinding)
{}
@@ -98,7 +99,7 @@ public:
public:
QSqlResult* q;
- const QSqlDriver* sqldriver;
+ QPointer<QSqlDriver> sqldriver;
int idx;
QString sql;
bool active;
@@ -250,7 +251,7 @@ QString QSqlResultPrivate::namedToPositionalBinding()
QSqlResult::QSqlResult(const QSqlDriver *db)
{
d = new QSqlResultPrivate(this);
- d->sqldriver = db;
+ d->sqldriver = const_cast<QSqlDriver *>(db);
if(db) {
setNumericalPrecisionPolicy(db->numericalPrecisionPolicy());
}