Sqlite: Improve LastChangedRowId

Change-Id: I2fe559d4b40f93561e44eb138119416291dc7d41
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2020-05-26 20:31:07 +02:00
parent 49dc889c7f
commit 22c33fb859
2 changed files with 28 additions and 0 deletions

View File

@@ -114,6 +114,8 @@ public:
return rowId; return rowId;
} }
bool lastRowIdIsValid() { return lastRowId >= 0; }
public: public:
DatabaseInterface &database; DatabaseInterface &database;
DatabaseInterface::UpdateCallback callback; DatabaseInterface::UpdateCallback callback;

View File

@@ -442,4 +442,30 @@ TEST_F(LastChangedRowIdWithNoTable, TakeLastRowIdResetsRowIdToMinusOne)
ASSERT_THAT(id, -1); ASSERT_THAT(id, -1);
} }
TEST_F(LastChangedRowIdWithNoTable, LastRowIdIsNotValidForNegativeValues)
{
auto isValid = lastRowId.lastRowIdIsValid();
ASSERT_FALSE(isValid);
}
TEST_F(LastChangedRowIdWithNoTable, LastRowIdIsValidForNull)
{
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 0);
auto isValid = lastRowId.lastRowIdIsValid();
ASSERT_TRUE(isValid);
}
TEST_F(LastChangedRowIdWithNoTable, LastRowIdIsValidForPositiveValues)
{
lastRowId.callback(Sqlite::ChangeType::Update, "main", "foo", 777);
auto isValid = lastRowId.lastRowIdIsValid();
ASSERT_TRUE(isValid);
}
} // namespace } // namespace