forked from qt-creator/qt-creator
Sqlite: Fix double throwing for reset
We do want prevent throwing again for reset if we already have thrown an exception but we want to throw if there was no exception. Change-Id: Iaf9fffb872ccd579a8ccde02381b5e5d30d5c4cb Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -193,6 +193,8 @@ public:
|
||||
while (BaseStatement::next())
|
||||
emplaceBackValues<ResultTypeCount>(resultValues);
|
||||
|
||||
resetter.reset();
|
||||
|
||||
return resultValues;
|
||||
}
|
||||
|
||||
@@ -210,6 +212,8 @@ public:
|
||||
while (BaseStatement::next())
|
||||
emplaceBackValues<ResultTypeCount>(resultValues);
|
||||
|
||||
resetter.reset();
|
||||
|
||||
return resultValues;
|
||||
}
|
||||
|
||||
@@ -228,6 +232,8 @@ public:
|
||||
|
||||
while (BaseStatement::next())
|
||||
emplaceBackValues<ResultTypeCount>(resultValues);
|
||||
|
||||
resetter.reset();
|
||||
}
|
||||
|
||||
return resultValues;
|
||||
@@ -249,6 +255,8 @@ public:
|
||||
|
||||
while (BaseStatement::next())
|
||||
emplaceBackValues<ResultTypeCount>(resultValues);
|
||||
|
||||
resetter.reset();
|
||||
}
|
||||
|
||||
return resultValues;
|
||||
@@ -267,6 +275,8 @@ public:
|
||||
if (BaseStatement::next())
|
||||
resultValue = assignValue<Utils::optional<ResultType>, ResultTypeCount>();
|
||||
|
||||
resetter.reset();
|
||||
|
||||
return resultValue;
|
||||
}
|
||||
|
||||
@@ -288,12 +298,29 @@ private:
|
||||
: statement(statement)
|
||||
{}
|
||||
|
||||
~Resetter()
|
||||
void reset()
|
||||
{
|
||||
statement.reset();
|
||||
try {
|
||||
statement.reset();
|
||||
} catch (...) {
|
||||
shouldReset = false;
|
||||
throw;
|
||||
}
|
||||
|
||||
shouldReset = false;
|
||||
}
|
||||
|
||||
~Resetter() noexcept
|
||||
{
|
||||
try {
|
||||
if (shouldReset)
|
||||
statement.reset();
|
||||
} catch (...) {
|
||||
}
|
||||
}
|
||||
|
||||
StatementImplementation &statement;
|
||||
bool shouldReset = true;
|
||||
};
|
||||
|
||||
struct ValueGetter
|
||||
|
||||
@@ -620,6 +620,25 @@ TEST_F(SqliteStatement, GetValuesWithTupleArgumentsCallsResetIfExceptionIsThrown
|
||||
Sqlite::StatementHasError);
|
||||
}
|
||||
|
||||
TEST_F(SqliteStatement, DoubleThrowExceptionsInReset)
|
||||
{
|
||||
MockSqliteStatement mockStatement;
|
||||
ON_CALL(mockStatement, next()).WillByDefault(Throw(Sqlite::StatementHasError("")));
|
||||
ON_CALL(mockStatement, reset()).WillByDefault(Throw(Sqlite::StatementHasError("")));
|
||||
|
||||
ASSERT_THROW(mockStatement.values<int>(3, std::vector<std::tuple<int>>{{1}, {2}}),
|
||||
Sqlite::StatementHasError);
|
||||
}
|
||||
|
||||
TEST_F(SqliteStatement, ThrowExceptionOnlyInReset)
|
||||
{
|
||||
MockSqliteStatement mockStatement;
|
||||
ON_CALL(mockStatement, reset()).WillByDefault(Throw(Sqlite::StatementHasError("")));
|
||||
|
||||
ASSERT_THROW(mockStatement.values<int>(3, std::vector<std::tuple<int>>{{1}, {2}}),
|
||||
Sqlite::StatementHasError);
|
||||
}
|
||||
|
||||
void SqliteStatement::SetUp()
|
||||
{
|
||||
database.execute("CREATE TABLE test(name TEXT UNIQUE, number NUMERIC, value NUMERIC)");
|
||||
|
||||
Reference in New Issue
Block a user