1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#ifndef TESTSQLDRIVER_H
30#define TESTSQLDRIVER_H
31
32#include <QtSql/QSqlResult>
33#include <QtSql/QSqlDriver>
34#include <QtSql/QSqlRecord>
35#include <private/qsqldriver_p.h>
36
37class TestSqlDriverResult : public QSqlResult
38{
39public:
40 TestSqlDriverResult(const QSqlDriver *driver)
41 : QSqlResult(driver) {}
42 ~TestSqlDriverResult() {}
43
44 bool savePrepare(const QString& sqlquery)
45 {
46 return QSqlResult::savePrepare(sqlquery);
47 }
48
49 QVector<QVariant> boundValues() const
50 {
51 return QSqlResult::boundValues();
52 }
53
54protected:
55 QVariant data(int /* index */) { return QVariant(); }
56 bool isNull(int /* index */) { return false; }
57 bool reset(const QString & /* query */) { return false; }
58 bool fetch(int /* index */) { return false; }
59 bool fetchFirst() { return false; }
60 bool fetchLast() { return false; }
61 int size() { return 0; }
62 int numRowsAffected() { return 0; }
63 QSqlRecord record() const { return QSqlRecord(); }
64};
65
66class TestSqlDriver : public QSqlDriver
67{
68 Q_DECLARE_PRIVATE(QSqlDriver)
69
70public:
71 TestSqlDriver() {}
72 ~TestSqlDriver() {}
73
74 bool hasFeature(DriverFeature f) const {
75 switch (f) {
76 case QSqlDriver::PreparedQueries:
77 case QSqlDriver::NamedPlaceholders:
78 return true;
79 default:
80 break;
81 }
82 return false;
83 }
84 bool open(const QString & /* db */, const QString & /* user */,
85 const QString & /* password */, const QString & /* host */,
86 int /* port */, const QString & /* options */)
87 { return false; }
88 void close() {}
89
90 QSqlResult *createResult() const { return new TestSqlDriverResult(this); }
91};
92
93#endif // TESTSQLDRIVER_H
94

source code of qtbase/tests/auto/sql/kernel/qsqlresult/testsqldriver.h