forked from qt-creator/qt-creator
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 <qt_ci_bot@qt-project.org> Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
This commit is contained in:
@@ -210,7 +210,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename ResultType, typename... QueryTypes>
|
template<typename ResultType, typename... QueryTypes>
|
||||||
auto value(const QueryTypes &...queryValues)
|
std::enable_if_t<!std::is_function_v<ResultType>, ResultType> value(const QueryTypes &...queryValues)
|
||||||
{
|
{
|
||||||
Resetter resetter{this};
|
Resetter resetter{this};
|
||||||
ResultType resultValue;
|
ResultType resultValue;
|
||||||
|
@@ -1162,21 +1162,29 @@ TEST_F(SqliteStatement, GetTupleValueAndMultipleQueryValue)
|
|||||||
|
|
||||||
TEST_F(SqliteStatement, GetValueCallsReset)
|
TEST_F(SqliteStatement, GetValueCallsReset)
|
||||||
{
|
{
|
||||||
|
struct Value
|
||||||
|
{
|
||||||
|
int x = 0;
|
||||||
|
};
|
||||||
MockSqliteStatement mockStatement{databaseMock};
|
MockSqliteStatement mockStatement{databaseMock};
|
||||||
|
|
||||||
EXPECT_CALL(mockStatement, reset());
|
EXPECT_CALL(mockStatement, reset());
|
||||||
|
|
||||||
mockStatement.value<int>("bar");
|
mockStatement.value<Value>("bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SqliteStatement, GetValueCallsResetIfExceptionIsThrown)
|
TEST_F(SqliteStatement, GetValueCallsResetIfExceptionIsThrown)
|
||||||
{
|
{
|
||||||
|
struct Value
|
||||||
|
{
|
||||||
|
int x = 0;
|
||||||
|
};
|
||||||
MockSqliteStatement mockStatement{databaseMock};
|
MockSqliteStatement mockStatement{databaseMock};
|
||||||
ON_CALL(mockStatement, next()).WillByDefault(Throw(Sqlite::StatementHasError("")));
|
ON_CALL(mockStatement, next()).WillByDefault(Throw(Sqlite::StatementHasError("")));
|
||||||
|
|
||||||
EXPECT_CALL(mockStatement, reset());
|
EXPECT_CALL(mockStatement, reset());
|
||||||
|
|
||||||
EXPECT_THROW(mockStatement.value<int>("bar"), Sqlite::StatementHasError);
|
EXPECT_THROW(mockStatement.value<Value>("bar"), Sqlite::StatementHasError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SqliteStatement, GetValuesWithoutArgumentsCallsReset)
|
TEST_F(SqliteStatement, GetValuesWithoutArgumentsCallsReset)
|
||||||
|
Reference in New Issue
Block a user