Sqlite: Remove unused code

Binding by names is slower and we never used it.

Change-Id: Ia6b9b78401f8c2711be34b667ac6f08b44418773
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2020-05-26 23:01:52 +02:00
parent 9c44f8d88d
commit 9f9140b196
6 changed files with 0 additions and 130 deletions

View File

@@ -223,25 +223,6 @@ void BaseStatement::bind(int index, const Value &value)
}
}
template <typename Type>
void BaseStatement::bind(Utils::SmallStringView name, Type value)
{
int index = bindingIndexForName(name);
checkBindingName(index);
bind(index, value);
}
template SQLITE_EXPORT void BaseStatement::bind(Utils::SmallStringView name, int value);
template SQLITE_EXPORT void BaseStatement::bind(Utils::SmallStringView name, long value);
template SQLITE_EXPORT void BaseStatement::bind(Utils::SmallStringView name, long long value);
template SQLITE_EXPORT void BaseStatement::bind(Utils::SmallStringView name, double value);
template SQLITE_EXPORT void BaseStatement::bind(Utils::SmallStringView name, Utils::SmallStringView text);
int BaseStatement::bindingIndexForName(Utils::SmallStringView name) const
{
return sqlite3_bind_parameter_index(m_compiledStatement.get(), name.data());
}
void BaseStatement::prepare(Utils::SmallStringView sqlStatement)
{
int resultCode;

View File

@@ -91,11 +91,6 @@ public:
bind(index, static_cast<long long>(value));
}
template <typename Type>
void bind(Utils::SmallStringView name, Type fetchValue);
int bindingIndexForName(Utils::SmallStringView name) const;
void prepare(Utils::SmallStringView sqlStatement);
void waitForUnlockNotify() const;
@@ -140,12 +135,6 @@ private:
mutable bool m_isReadyToFetchValues;
};
extern template SQLITE_EXPORT void BaseStatement::bind(Utils::SmallStringView name, int value);
extern template SQLITE_EXPORT void BaseStatement::bind(Utils::SmallStringView name, long value);
extern template SQLITE_EXPORT void BaseStatement::bind(Utils::SmallStringView name, long long value);
extern template SQLITE_EXPORT void BaseStatement::bind(Utils::SmallStringView name, double value);
extern template SQLITE_EXPORT void BaseStatement::bind(Utils::SmallStringView name, Utils::SmallStringView text);
template <> SQLITE_EXPORT int BaseStatement::fetchValue<int>(int column) const;
template <> SQLITE_EXPORT long BaseStatement::fetchValue<long>(int column) const;
template <> SQLITE_EXPORT long long BaseStatement::fetchValue<long long>(int column) const;
@@ -187,21 +176,6 @@ public:
resetter.reset();
}
template<typename... ValueType>
void bindNameValues(const ValueType&... values)
{
bindValuesByName(values...);
}
template<typename... ValueType>
void writeNamed(const ValueType&... values)
{
Resetter resetter{*this};
bindValuesByName(values...);
BaseStatement::next();
resetter.reset();
}
template <typename ResultType,
int ResultTypeCount = 1>
std::vector<ResultType> values(std::size_t reserveSize)
@@ -413,19 +387,6 @@ private:
bindValuesByIndex(index + 1, values...);
}
template<typename ValueType>
void bindValuesByName(Utils::SmallStringView name, const ValueType &value)
{
BaseStatement::bind(BaseStatement::bindingIndexForName(name), value);
}
template<typename ValueType, typename... ValueTypes>
void bindValuesByName(Utils::SmallStringView name, const ValueType &value, const ValueTypes&... values)
{
BaseStatement::bind(BaseStatement::bindingIndexForName(name), value);
bindValuesByName(values...);
}
template <typename TupleType, std::size_t... ColumnIndices>
void bindTupleValuesElement(const TupleType &tuple, std::index_sequence<ColumnIndices...>)
{

View File

@@ -41,7 +41,6 @@ public:
using StatementImplementation::values;
using StatementImplementation::toValue;
using StatementImplementation::write;
using StatementImplementation::writeNamed;
};
} // namespace Sqlite

View File

@@ -37,7 +37,6 @@ public:
using StatementImplementation::execute;
using StatementImplementation::database;
using StatementImplementation::write;
using StatementImplementation::writeNamed;
protected:
void checkIsWritableStatement();

View File

@@ -52,7 +52,6 @@ public:
MOCK_METHOD2(bind, void (int, double));
MOCK_METHOD2(bind, void (int, Utils::SmallStringView));
MOCK_METHOD2(bind, void (int, long));
MOCK_CONST_METHOD1(bindingIndexForName, int (Utils::SmallStringView name));
MOCK_METHOD1(prepare, void (Utils::SmallStringView sqlStatement));
};

View File

@@ -320,36 +320,6 @@ TEST_F(SqliteStatement, BindEmptyBlob)
ASSERT_THAT(statement.fetchBlobValue(0), IsEmpty());
}
TEST_F(SqliteStatement, BindIntegerByParameter)
{
SqliteTestStatement statement("SELECT name, number FROM test WHERE number=@number", database);
statement.bind("@number", 40);
statement.next();
ASSERT_THAT(statement.fetchSmallStringViewValue(0), "poo");
}
TEST_F(SqliteStatement, BindLongIntegerByParameter)
{
SqliteTestStatement statement("SELECT name, number FROM test WHERE number=@number", database);
statement.bind("@number", int64_t(40));
statement.next();
ASSERT_THAT(statement.fetchSmallStringViewValue(0), "poo");
}
TEST_F(SqliteStatement, BindDoubleByIndex)
{
SqliteTestStatement statement("SELECT name, number FROM test WHERE number=@number", database);
statement.bind(statement.bindingIndexForName("@number"), 23.3);
statement.next();
ASSERT_THAT(statement.fetchSmallStringViewValue(0), "foo");
}
TEST_F(SqliteStatement, BindIndexIsZeroIsThrowingBindingIndexIsOutOfBoundInt)
{
SqliteTestStatement statement("SELECT name, number FROM test WHERE number=$1", database);
@@ -407,13 +377,6 @@ TEST_F(SqliteStatement, BindIndexIsToLargeIsThrowingBindingIndexIsOutOfBoundBlob
ASSERT_THROW(statement.bind(2, bytes), Sqlite::BindingIndexIsOutOfRange);
}
TEST_F(SqliteStatement, WrongBindingNameThrowingBindingIndexIsOutOfBound)
{
SqliteTestStatement statement("SELECT name, number FROM test WHERE number=@name", database);
ASSERT_THROW(statement.bind("@name2", 40), Sqlite::WrongBindingName);
}
TEST_F(SqliteStatement, BindValues)
{
SqliteTestStatement statement("UPDATE test SET name=?, number=? WHERE rowid=?", database);
@@ -505,25 +468,6 @@ TEST_F(SqliteStatement, WriteBlobs)
ASSERT_THAT(readStatement.template value<Blob>(), Optional(Field(&Blob::bytes, Eq(bytes))));
}
TEST_F(SqliteStatement, BindNamedValues)
{
SqliteTestStatement statement("UPDATE test SET name=@name, number=@number WHERE rowid=@id", database);
statement.bindNameValues("@name", "see", "@number", 7.23, "@id", 1);
statement.execute();
ASSERT_THAT(statement, HasValues("see", "7.23", 1));
}
TEST_F(SqliteStatement, WriteNamedValues)
{
WriteStatement statement("UPDATE test SET name=@name, number=@number WHERE rowid=@id", database);
statement.writeNamed("@name", "see", "@number", 7.23, "@id", 1);
ASSERT_THAT(statement, HasValues("see", "7.23", 1));
}
TEST_F(SqliteStatement, CannotWriteToClosedDatabase)
{
database.close();
@@ -902,19 +846,6 @@ TEST_F(SqliteStatement, ResetIfWriteIsThrowingException)
ASSERT_ANY_THROW(mockStatement.write("bar"));
}
TEST_F(SqliteStatement, ResetIfWriteNamedIsThrowingException)
{
MockSqliteStatement mockStatement;
EXPECT_CALL(mockStatement, bindingIndexForName(TypedEq<Utils::SmallStringView>("@foo")))
.WillOnce(Return(1));
EXPECT_CALL(mockStatement, bind(1, TypedEq<Utils::SmallStringView>("bar")))
.WillOnce(Throw(Sqlite::StatementIsBusy("")));
EXPECT_CALL(mockStatement, reset());
ASSERT_ANY_THROW(mockStatement.writeNamed("@foo", "bar"));
}
TEST_F(SqliteStatement, ResetIfExecuteThrowsException)
{
MockSqliteStatement mockStatement;