Sqlite: Use implicit transactions for ranges

Change-Id: I190835d1235deb9add51cc31bd730d18fdecddd3
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2025-05-16 09:20:19 +02:00
parent 5e6f8ba66b
commit 78707dd625
2 changed files with 2 additions and 10 deletions

View File

@@ -576,7 +576,7 @@ public:
const source_location &sourceLocation, const source_location &sourceLocation,
const QueryTypes &...queryValues) const QueryTypes &...queryValues)
: BaseSqliteResultRange<ResultType>{statement, sourceLocation} : BaseSqliteResultRange<ResultType>{statement, sourceLocation}
, m_transaction{statement.database(), sourceLocation} , m_transaction{statement.database()}
, resetter{&statement} , resetter{&statement}
, sourceLocation{sourceLocation} , sourceLocation{sourceLocation}
{ {
@@ -586,14 +586,10 @@ public:
~SqliteResultRangeWithTransaction() ~SqliteResultRangeWithTransaction()
{ {
resetter.reset(); resetter.reset();
if (!std::uncaught_exceptions()) {
m_transaction.commit(sourceLocation);
}
} }
private: private:
DeferredTransaction<typename BaseStatement::Database> m_transaction; ImplicitTransaction<typename BaseStatement::Database> m_transaction;
Resetter resetter; Resetter resetter;
source_location sourceLocation; source_location sourceLocation;
}; };

View File

@@ -1385,9 +1385,7 @@ TEST_F(SqliteStatement, get_range_with_transaction_without_arguments_calls)
MockSqliteStatement<1, 0> mockStatement{databaseMock}; MockSqliteStatement<1, 0> mockStatement{databaseMock};
EXPECT_CALL(databaseMock, lock()); EXPECT_CALL(databaseMock, lock());
EXPECT_CALL(databaseMock, deferredBegin(_));
EXPECT_CALL(mockStatement, reset()); EXPECT_CALL(mockStatement, reset());
EXPECT_CALL(databaseMock, commit(_));
EXPECT_CALL(databaseMock, unlock()); EXPECT_CALL(databaseMock, unlock());
mockStatement.rangeWithTransaction<int>(); mockStatement.rangeWithTransaction<int>();
@@ -1421,9 +1419,7 @@ TEST_F(SqliteStatement, get_range_with_transaction_without_arguments_calls_reset
ON_CALL(mockStatement, next(_)).WillByDefault(Throw(Sqlite::StatementHasError(""))); ON_CALL(mockStatement, next(_)).WillByDefault(Throw(Sqlite::StatementHasError("")));
EXPECT_CALL(databaseMock, lock()); EXPECT_CALL(databaseMock, lock());
EXPECT_CALL(databaseMock, deferredBegin(_));
EXPECT_CALL(mockStatement, reset()); EXPECT_CALL(mockStatement, reset());
EXPECT_CALL(databaseMock, rollback(_));
EXPECT_CALL(databaseMock, unlock()); EXPECT_CALL(databaseMock, unlock());
EXPECT_THROW( EXPECT_THROW(