From 9f9140b196bb28d0b4fcb13b1a37ea4e6e14fe56 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Tue, 26 May 2020 23:01:52 +0200 Subject: [PATCH] Sqlite: Remove unused code Binding by names is slower and we never used it. Change-Id: Ia6b9b78401f8c2711be34b667ac6f08b44418773 Reviewed-by: Thomas Hartmann --- src/libs/sqlite/sqlitebasestatement.cpp | 19 ------ src/libs/sqlite/sqlitebasestatement.h | 39 ----------- src/libs/sqlite/sqlitereadwritestatement.h | 1 - src/libs/sqlite/sqlitewritestatement.h | 1 - tests/unit/unittest/mocksqlitestatement.h | 1 - tests/unit/unittest/sqlitestatement-test.cpp | 69 -------------------- 6 files changed, 130 deletions(-) diff --git a/src/libs/sqlite/sqlitebasestatement.cpp b/src/libs/sqlite/sqlitebasestatement.cpp index 2cf355db88d..890c6639974 100644 --- a/src/libs/sqlite/sqlitebasestatement.cpp +++ b/src/libs/sqlite/sqlitebasestatement.cpp @@ -223,25 +223,6 @@ void BaseStatement::bind(int index, const Value &value) } } -template -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; diff --git a/src/libs/sqlite/sqlitebasestatement.h b/src/libs/sqlite/sqlitebasestatement.h index 027c94e54f6..48076c37da0 100644 --- a/src/libs/sqlite/sqlitebasestatement.h +++ b/src/libs/sqlite/sqlitebasestatement.h @@ -91,11 +91,6 @@ public: bind(index, static_cast(value)); } - template - 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 column) const; template <> SQLITE_EXPORT long BaseStatement::fetchValue(int column) const; template <> SQLITE_EXPORT long long BaseStatement::fetchValue(int column) const; @@ -187,21 +176,6 @@ public: resetter.reset(); } - template - void bindNameValues(const ValueType&... values) - { - bindValuesByName(values...); - } - - template - void writeNamed(const ValueType&... values) - { - Resetter resetter{*this}; - bindValuesByName(values...); - BaseStatement::next(); - resetter.reset(); - } - template std::vector values(std::size_t reserveSize) @@ -413,19 +387,6 @@ private: bindValuesByIndex(index + 1, values...); } - template - void bindValuesByName(Utils::SmallStringView name, const ValueType &value) - { - BaseStatement::bind(BaseStatement::bindingIndexForName(name), value); - } - - template - void bindValuesByName(Utils::SmallStringView name, const ValueType &value, const ValueTypes&... values) - { - BaseStatement::bind(BaseStatement::bindingIndexForName(name), value); - bindValuesByName(values...); - } - template void bindTupleValuesElement(const TupleType &tuple, std::index_sequence) { diff --git a/src/libs/sqlite/sqlitereadwritestatement.h b/src/libs/sqlite/sqlitereadwritestatement.h index c81ed628b29..caa9cbe2a06 100644 --- a/src/libs/sqlite/sqlitereadwritestatement.h +++ b/src/libs/sqlite/sqlitereadwritestatement.h @@ -41,7 +41,6 @@ public: using StatementImplementation::values; using StatementImplementation::toValue; using StatementImplementation::write; - using StatementImplementation::writeNamed; }; } // namespace Sqlite diff --git a/src/libs/sqlite/sqlitewritestatement.h b/src/libs/sqlite/sqlitewritestatement.h index 24cf5a87426..4dbcd4f9c68 100644 --- a/src/libs/sqlite/sqlitewritestatement.h +++ b/src/libs/sqlite/sqlitewritestatement.h @@ -37,7 +37,6 @@ public: using StatementImplementation::execute; using StatementImplementation::database; using StatementImplementation::write; - using StatementImplementation::writeNamed; protected: void checkIsWritableStatement(); diff --git a/tests/unit/unittest/mocksqlitestatement.h b/tests/unit/unittest/mocksqlitestatement.h index 26f5b0de6e0..351c6708a57 100644 --- a/tests/unit/unittest/mocksqlitestatement.h +++ b/tests/unit/unittest/mocksqlitestatement.h @@ -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)); }; diff --git a/tests/unit/unittest/sqlitestatement-test.cpp b/tests/unit/unittest/sqlitestatement-test.cpp index ce40e0c3d8b..2b8942dbf11 100644 --- a/tests/unit/unittest/sqlitestatement-test.cpp +++ b/tests/unit/unittest/sqlitestatement-test.cpp @@ -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(), 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("@foo"))) - .WillOnce(Return(1)); - EXPECT_CALL(mockStatement, bind(1, TypedEq("bar"))) - .WillOnce(Throw(Sqlite::StatementIsBusy(""))); - EXPECT_CALL(mockStatement, reset()); - - ASSERT_ANY_THROW(mockStatement.writeNamed("@foo", "bar")); -} - TEST_F(SqliteStatement, ResetIfExecuteThrowsException) { MockSqliteStatement mockStatement;