Commit c8701998 authored by Marco Bubke's avatar Marco Bubke Committed by Tim Jenssen

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's avatarTim Jenssen <tim.jenssen@qt.io>
Reviewed-by: Marco Bubke's avatarMarco Bubke <marco.bubke@qt.io>
parent a83d0382
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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();
......
/****************************************************************************
**
** 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();
};
......@@ -200,7 +200,8 @@ HEADERS += \
mocksqlitedatabase.h \
mocksqlitereadstatement.h \
google-using-declarations.h \
mocksymbolindexing.h
mocksymbolindexing.h \
sqliteteststatement.h
!isEmpty(LIBCLANG_LIBS) {
HEADERS += \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment