From 091c7a009373c4e580e5477aa51f9f0ec6e27de1 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Thu, 24 Jun 2021 14:14:24 +0200 Subject: [PATCH] Sqlite: Disable value method for fundamentals There is optionalValue which can handle a null value. ints and floats can be initialize to zero but you cannot be sure that this value comes from the database, is a empty value. So it's better to force the use of optionalValue for ints and floats. In that case empty has to be handled. Change-Id: Id5c5db57a8d3335d91911824d06f388ed054df9e Reviewed-by: Qt CI Bot Reviewed-by: Vikas Pachdha --- src/libs/sqlite/sqlitebasestatement.h | 2 +- tests/unit/unittest/sqlitestatement-test.cpp | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/libs/sqlite/sqlitebasestatement.h b/src/libs/sqlite/sqlitebasestatement.h index e8e9026dae3..f58f73fdcdd 100644 --- a/src/libs/sqlite/sqlitebasestatement.h +++ b/src/libs/sqlite/sqlitebasestatement.h @@ -210,7 +210,7 @@ public: } template - auto value(const QueryTypes &...queryValues) + std::enable_if_t, ResultType> value(const QueryTypes &...queryValues) { Resetter resetter{this}; ResultType resultValue; diff --git a/tests/unit/unittest/sqlitestatement-test.cpp b/tests/unit/unittest/sqlitestatement-test.cpp index 3804f8b31ed..873ba1d5e30 100644 --- a/tests/unit/unittest/sqlitestatement-test.cpp +++ b/tests/unit/unittest/sqlitestatement-test.cpp @@ -1162,21 +1162,29 @@ TEST_F(SqliteStatement, GetTupleValueAndMultipleQueryValue) TEST_F(SqliteStatement, GetValueCallsReset) { + struct Value + { + int x = 0; + }; MockSqliteStatement mockStatement{databaseMock}; EXPECT_CALL(mockStatement, reset()); - mockStatement.value("bar"); + mockStatement.value("bar"); } TEST_F(SqliteStatement, GetValueCallsResetIfExceptionIsThrown) { + struct Value + { + int x = 0; + }; MockSqliteStatement mockStatement{databaseMock}; ON_CALL(mockStatement, next()).WillByDefault(Throw(Sqlite::StatementHasError(""))); EXPECT_CALL(mockStatement, reset()); - EXPECT_THROW(mockStatement.value("bar"), Sqlite::StatementHasError); + EXPECT_THROW(mockStatement.value("bar"), Sqlite::StatementHasError); } TEST_F(SqliteStatement, GetValuesWithoutArgumentsCallsReset)