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#include <QtTest/QtTest>
30#include <QtSql/QtSql>
31
32#include "testsqldriver.h"
33
34class tst_QSqlResult : public QObject
35{
36 Q_OBJECT
37
38public:
39 tst_QSqlResult();
40
41private slots:
42 void positionalToNamedBinding();
43 void parseOfBoundValues();
44
45};
46
47tst_QSqlResult::tst_QSqlResult()
48{
49}
50
51void tst_QSqlResult::positionalToNamedBinding()
52{
53 TestSqlDriver testDriver;
54 TestSqlDriverResult result(&testDriver);
55 QString query("INSERT INTO MYTABLE (ID, NAME, BIRTH) VALUES(?, ?, ?)");
56 QVERIFY(result.savePrepare(query));
57 QCOMPARE(result.boundValues().count(), 3);
58}
59
60void tst_QSqlResult::parseOfBoundValues()
61{
62 TestSqlDriver testDriver;
63 TestSqlDriverResult result(&testDriver);
64 QVERIFY(result.savePrepare("SELECT :1 AS \":2\""));
65 QCOMPARE(result.boundValues().count(), 1);
66 QVERIFY(result.savePrepare("SELECT :1 AS ':2'"));
67 QCOMPARE(result.boundValues().count(), 1);
68 QVERIFY(result.savePrepare("SELECT :1 AS [:2]"));
69 if (testDriver.dbmsType() == QSqlDriver::PostgreSQL)
70 QCOMPARE(result.boundValues().count(), 2);
71 else
72 QCOMPARE(result.boundValues().count(), 1);
73 QVERIFY(result.savePrepare("SELECT :1 AS [:2]]]"));
74 if (testDriver.dbmsType() == QSqlDriver::PostgreSQL)
75 QCOMPARE(result.boundValues().count(), 2);
76 else
77 QCOMPARE(result.boundValues().count(), 1);
78 QVERIFY(result.savePrepare("SELECT :1 AS [:2]]]]]"));
79 if (testDriver.dbmsType() == QSqlDriver::PostgreSQL)
80 QCOMPARE(result.boundValues().count(), 2);
81 else
82 QCOMPARE(result.boundValues().count(), 1);
83
84 QVERIFY(result.savePrepare("SELECT ? AS \"?\""));
85 QCOMPARE(result.boundValues().count(), 1);
86 QVERIFY(result.savePrepare("SELECT ? AS '?'"));
87 QCOMPARE(result.boundValues().count(), 1);
88 QVERIFY(result.savePrepare("SELECT ? AS [?]"));
89 if (testDriver.dbmsType() == QSqlDriver::PostgreSQL)
90 QCOMPARE(result.boundValues().count(), 2);
91 else
92 QCOMPARE(result.boundValues().count(), 1);
93
94 QVERIFY(result.savePrepare("SELECT ? AS \"'?\""));
95 QCOMPARE(result.boundValues().count(), 1);
96 QVERIFY(result.savePrepare("SELECT ? AS '?\"'"));
97 QCOMPARE(result.boundValues().count(), 1);
98 QVERIFY(result.savePrepare("SELECT ? AS '?''?'"));
99 QCOMPARE(result.boundValues().count(), 1);
100 QVERIFY(result.savePrepare("SELECT ? AS [\"?']"));
101 QCOMPARE(result.boundValues().count(), 1);
102}
103
104QTEST_MAIN( tst_QSqlResult )
105#include "tst_qsqlresult.moc"
106

source code of qtbase/tests/auto/sql/kernel/qsqlresult/tst_qsqlresult.cpp