summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2017-09-18 15:59:08 +0200
committerTim Jenssen <tim.jenssen@qt.io>2017-09-20 10:44:15 +0000
commitc870199823885da6cb90beea3b1224fe6930eb1a (patch)
tree8275d474e39a6acca5dba93e8f5eaa7902cdb8bc
parenta83d038208cb1e8f4430e5eb3ef5ae8e93636131 (diff)
downloadqt-creator-c870199823885da6cb90beea3b1224fe6930eb1a.tar.gz
Sqlite: Don't use the lower level interface of the statements
We now have the very powerful write and read methods, so using the low level interface leads only to stupid errors and prevents optimizations. Change-Id: If2340833977935cb2d319735dee96b0bac33142b Reviewed-by: Tim Jenssen <tim.jenssen@qt.io> Reviewed-by: Marco Bubke <marco.bubke@qt.io>
-rw-r--r--src/libs/sqlite/sqlitereadstatement.h12
-rw-r--r--src/libs/sqlite/sqlitereadwritestatement.h12
-rw-r--r--src/libs/sqlite/sqlitewritestatement.h7
-rw-r--r--tests/unit/unittest/sqlitestatement-test.cpp43
-rw-r--r--tests/unit/unittest/sqliteteststatement.h54
-rw-r--r--tests/unit/unittest/unittest.pro3
6 files changed, 78 insertions, 53 deletions
diff --git a/src/libs/sqlite/sqlitereadstatement.h b/src/libs/sqlite/sqlitereadstatement.h
index c20221c34f..1fddb3afce 100644
--- a/src/libs/sqlite/sqlitereadstatement.h
+++ b/src/libs/sqlite/sqlitereadstatement.h
@@ -34,21 +34,9 @@ class SQLITE_EXPORT ReadStatement final : private Statement
public:
explicit ReadStatement(Utils::SmallStringView sqlStatement, Database &database);
- using Statement::next;
- using Statement::reset;
- using Statement::value;
using Statement::structValues;
using Statement::tupleValues;
- using Statement::text;
using Statement::values;
- using Statement::columnCount;
- using Statement::columnNames;
- using Statement::bind;
- using Statement::bindValues;
- using Statement::bindNameValues;
- using Statement::bindingIndexForName;
- using Statement::setBindingColumnNames;
- using Statement::bindingColumnNames;
using Statement::toValue;
using Statement::database;
diff --git a/src/libs/sqlite/sqlitereadwritestatement.h b/src/libs/sqlite/sqlitereadwritestatement.h
index 4b982525e7..8c8d254198 100644
--- a/src/libs/sqlite/sqlitereadwritestatement.h
+++ b/src/libs/sqlite/sqlitereadwritestatement.h
@@ -36,22 +36,10 @@ class SQLITE_EXPORT ReadWriteStatement final : private Statement
public:
ReadWriteStatement(Utils::SmallStringView sqlStatement, Database &database);
- using Statement::next;
using Statement::execute;
- using Statement::reset;
- using Statement::bind;
- using Statement::bindValues;
- using Statement::bindNameValues;
- using Statement::bindingIndexForName;
- using Statement::setBindingColumnNames;
- using Statement::bindingColumnNames;
- using Statement::value;
- using Statement::text;
using Statement::values;
using Statement::structValues;
using Statement::tupleValues;
- using Statement::columnCount;
- using Statement::columnNames;
using Statement::toValue;
using Statement::database;
using Statement::write;
diff --git a/src/libs/sqlite/sqlitewritestatement.h b/src/libs/sqlite/sqlitewritestatement.h
index c673bbae20..ec00ae4e8f 100644
--- a/src/libs/sqlite/sqlitewritestatement.h
+++ b/src/libs/sqlite/sqlitewritestatement.h
@@ -35,13 +35,6 @@ public:
explicit WriteStatement(Utils::SmallStringView sqlStatement, Database &database);
using Statement::execute;
- using Statement::reset;
- using Statement::bind;
- using Statement::bindValues;
- using Statement::bindNameValues;
- using Statement::bindingIndexForName;
- using Statement::setBindingColumnNames;
- using Statement::bindingColumnNames;
using Statement::database;
using Statement::write;
using Statement::writeNamed;
diff --git a/tests/unit/unittest/sqlitestatement-test.cpp b/tests/unit/unittest/sqlitestatement-test.cpp
index 33703cf085..54be7bd0be 100644
--- a/tests/unit/unittest/sqlitestatement-test.cpp
+++ b/tests/unit/unittest/sqlitestatement-test.cpp
@@ -24,6 +24,7 @@
****************************************************************************/
#include "googletest.h"
+#include "sqliteteststatement.h"
#include <sqlitedatabase.h>
#include <sqlitereadstatement.h>
@@ -54,7 +55,7 @@ MATCHER_P3(HasValues, value1, value2, rowid,
{
Database &database = arg.database();
- ReadStatement statement("SELECT name, number FROM test WHERE rowid=?", database);
+ SqliteTestStatement statement("SELECT name, number FROM test WHERE rowid=?", database);
statement.bind(1, rowid);
statement.next();
@@ -106,7 +107,7 @@ TEST_F(SqliteStatement, ThrowsNotReadonlySqlStatementForWritableSqlStatementInRe
TEST_F(SqliteStatement, CountRows)
{
- ReadStatement statement("SELECT * FROM test", database);
+ SqliteTestStatement statement("SELECT * FROM test", database);
int nextCount = 0;
while (statement.next())
++nextCount;
@@ -118,7 +119,7 @@ TEST_F(SqliteStatement, CountRows)
TEST_F(SqliteStatement, Value)
{
- ReadStatement statement("SELECT name, number FROM test ORDER BY name", database);
+ SqliteTestStatement statement("SELECT name, number FROM test ORDER BY name", database);
statement.next();
statement.next();
@@ -135,14 +136,14 @@ TEST_F(SqliteStatement, Value)
TEST_F(SqliteStatement, ThrowNoValuesToFetchForNotSteppedStatement)
{
- ReadStatement statement("SELECT name, number FROM test", database);
+ SqliteTestStatement statement("SELECT name, number FROM test", database);
ASSERT_THROW(statement.value<int>(0), Sqlite::NoValuesToFetch);
}
TEST_F(SqliteStatement, ThrowNoValuesToFetchForDoneStatement)
{
- ReadStatement statement("SELECT name, number FROM test", database);
+ SqliteTestStatement statement("SELECT name, number FROM test", database);
while (statement.next()) {}
ASSERT_THROW(statement.value<int>(0), Sqlite::NoValuesToFetch);
@@ -150,7 +151,7 @@ TEST_F(SqliteStatement, ThrowNoValuesToFetchForDoneStatement)
TEST_F(SqliteStatement, ThrowInvalidColumnFetchedForNegativeColumn)
{
- ReadStatement statement("SELECT name, number FROM test", database);
+ SqliteTestStatement statement("SELECT name, number FROM test", database);
statement.next();
ASSERT_THROW(statement.value<int>(-1), Sqlite::InvalidColumnFetched);
@@ -158,7 +159,7 @@ TEST_F(SqliteStatement, ThrowInvalidColumnFetchedForNegativeColumn)
TEST_F(SqliteStatement, ThrowInvalidColumnFetchedForNotExistingColumn)
{
- ReadStatement statement("SELECT name, number FROM test", database);
+ SqliteTestStatement statement("SELECT name, number FROM test", database);
statement.next();
ASSERT_THROW(statement.value<int>(2), Sqlite::InvalidColumnFetched);
@@ -188,7 +189,7 @@ TEST_F(SqliteStatement, ToStringValue)
TEST_F(SqliteStatement, ColumnNames)
{
- ReadStatement statement("SELECT name, number FROM test", database);
+ SqliteTestStatement statement("SELECT name, number FROM test", database);
auto columnNames = statement.columnNames();
@@ -198,7 +199,7 @@ TEST_F(SqliteStatement, ColumnNames)
TEST_F(SqliteStatement, BindString)
{
- ReadStatement statement("SELECT name, number FROM test WHERE name=?", database);
+ SqliteTestStatement statement("SELECT name, number FROM test WHERE name=?", database);
statement.bind(1, "foo");
@@ -210,7 +211,7 @@ TEST_F(SqliteStatement, BindString)
TEST_F(SqliteStatement, BindInteger)
{
- ReadStatement statement("SELECT name, number FROM test WHERE number=?", database);
+ SqliteTestStatement statement("SELECT name, number FROM test WHERE number=?", database);
statement.bind(1, 40);
statement.next();
@@ -220,7 +221,7 @@ TEST_F(SqliteStatement, BindInteger)
TEST_F(SqliteStatement, BindLongInteger)
{
- ReadStatement statement("SELECT name, number FROM test WHERE number=?", database);
+ SqliteTestStatement statement("SELECT name, number FROM test WHERE number=?", database);
statement.bind(1, int64_t(40));
statement.next();
@@ -230,7 +231,7 @@ TEST_F(SqliteStatement, BindLongInteger)
TEST_F(SqliteStatement, BindDouble)
{
- ReadStatement statement("SELECT name, number FROM test WHERE number=?", database);
+ SqliteTestStatement statement("SELECT name, number FROM test WHERE number=?", database);
statement.bind(1, 23.3);
statement.next();
@@ -240,7 +241,7 @@ TEST_F(SqliteStatement, BindDouble)
TEST_F(SqliteStatement, BindIntegerByParameter)
{
- ReadStatement statement("SELECT name, number FROM test WHERE number=@number", database);
+ SqliteTestStatement statement("SELECT name, number FROM test WHERE number=@number", database);
statement.bind("@number", 40);
statement.next();
@@ -250,7 +251,7 @@ TEST_F(SqliteStatement, BindIntegerByParameter)
TEST_F(SqliteStatement, BindLongIntegerByParameter)
{
- ReadStatement statement("SELECT name, number FROM test WHERE number=@number", database);
+ SqliteTestStatement statement("SELECT name, number FROM test WHERE number=@number", database);
statement.bind("@number", int64_t(40));
statement.next();
@@ -260,7 +261,7 @@ TEST_F(SqliteStatement, BindLongIntegerByParameter)
TEST_F(SqliteStatement, BindDoubleByIndex)
{
- ReadStatement statement("SELECT name, number FROM test WHERE number=@number", database);
+ SqliteTestStatement statement("SELECT name, number FROM test WHERE number=@number", database);
statement.bind(statement.bindingIndexForName("@number"), 23.3);
statement.next();
@@ -270,35 +271,35 @@ TEST_F(SqliteStatement, BindDoubleByIndex)
TEST_F(SqliteStatement, BindIndexIsZeroIsThrowingBindingIndexIsOutOfBound)
{
- ReadStatement statement("SELECT name, number FROM test WHERE number=$1", database);
+ SqliteTestStatement statement("SELECT name, number FROM test WHERE number=$1", database);
ASSERT_THROW(statement.bind(0, 40), Sqlite::BindingIndexIsOutOfRange);
}
TEST_F(SqliteStatement, BindIndexIsTpLargeIsThrowingBindingIndexIsOutOfBound)
{
- ReadStatement statement("SELECT name, number FROM test WHERE number=$1", database);
+ SqliteTestStatement statement("SELECT name, number FROM test WHERE number=$1", database);
ASSERT_THROW(statement.bind(2, 40), Sqlite::BindingIndexIsOutOfRange);
}
TEST_F(SqliteStatement, WrongBindingNameThrowingBindingIndexIsOutOfBound)
{
- ReadStatement statement("SELECT name, number FROM test WHERE number=@name", database);
+ SqliteTestStatement statement("SELECT name, number FROM test WHERE number=@name", database);
ASSERT_THROW(statement.bind("@name2", 40), Sqlite::WrongBingingName);
}
TEST_F(SqliteStatement, RequestBindingNamesFromStatement)
{
- WriteStatement statement("UPDATE test SET name=@name, number=@number WHERE rowid=@id", database);
+ SqliteTestStatement statement("UPDATE test SET name=@name, number=@number WHERE rowid=@id", database);
ASSERT_THAT(statement.bindingColumnNames(), ElementsAre("name", "number", "id"));
}
TEST_F(SqliteStatement, BindValues)
{
- WriteStatement statement("UPDATE test SET name=?, number=? WHERE rowid=?", database);
+ SqliteTestStatement statement("UPDATE test SET name=?, number=? WHERE rowid=?", database);
statement.bindValues("see", 7.23, 1);
statement.execute();
@@ -317,7 +318,7 @@ TEST_F(SqliteStatement, WriteValues)
TEST_F(SqliteStatement, BindNamedValues)
{
- WriteStatement statement("UPDATE test SET name=@name, number=@number WHERE rowid=@id", database);
+ SqliteTestStatement statement("UPDATE test SET name=@name, number=@number WHERE rowid=@id", database);
statement.bindNameValues("@name", "see", "@number", 7.23, "@id", 1);
statement.execute();
diff --git a/tests/unit/unittest/sqliteteststatement.h b/tests/unit/unittest/sqliteteststatement.h
new file mode 100644
index 0000000000..43b6ab884c
--- /dev/null
+++ b/tests/unit/unittest/sqliteteststatement.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#pragma once
+
+#include <sqlitestatement.h>
+
+class SQLITE_EXPORT SqliteTestStatement : public Sqlite::Statement
+{
+public:
+ explicit SqliteTestStatement(Utils::SmallStringView sqlStatement, Sqlite::Database &database)
+ : Sqlite::Statement(sqlStatement, database)
+ {}
+
+ using Statement::bind;
+ using Statement::bindingColumnNames;
+ using Statement::bindingIndexForName;
+ using Statement::bindNameValues;
+ using Statement::bindValues;
+ using Statement::columnNames;
+ using Statement::database;
+ using Statement::execute;
+ using Statement::next;
+ using Statement::text;
+ using Statement::value;
+
+protected:
+ void checkIsWritableStatement();
+};
+
diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro
index 4b579ac779..0a3a50f158 100644
--- a/tests/unit/unittest/unittest.pro
+++ b/tests/unit/unittest/unittest.pro
@@ -200,7 +200,8 @@ HEADERS += \
mocksqlitedatabase.h \
mocksqlitereadstatement.h \
google-using-declarations.h \
- mocksymbolindexing.h
+ mocksymbolindexing.h \
+ sqliteteststatement.h
!isEmpty(LIBCLANG_LIBS) {
HEADERS += \