Sqlite: Improve LastChangedRowId

Sometimes we want not only the row id from one table but two or three.

Change-Id: I6d5444a71ecbfe6c1af8073be80b04932ea9268d
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2020-05-12 17:05:33 +02:00
committed by Tim Jenssen
parent b84025cd3a
commit a86fd58e40
2 changed files with 220 additions and 9 deletions

View File

@@ -40,12 +40,43 @@ public:
Utils::SmallStringView databaseName,
Utils::SmallStringView tableName)
: database(database)
, databaseName(databaseName)
, tableName(tableName)
{
callback = [this](ChangeType, char const *database, char const *table, long long rowId) {
if (this->databaseName == database && this->tableName == table)
lastRowId = rowId;
callback = [=](ChangeType, char const *database, char const *table, long long rowId) {
if (databaseName == database && tableName == table)
this->lastRowId = rowId;
};
database.setUpdateHook(callback);
}
LastChangedRowId(DatabaseInterface &database,
Utils::SmallStringView databaseName,
Utils::SmallStringView tableName,
Utils::SmallStringView tableName2)
: database(database)
{
callback = [=](ChangeType, char const *database, char const *table, long long rowId) {
if (databaseName == database && (tableName == table || tableName2 == table))
this->lastRowId = rowId;
};
database.setUpdateHook(callback);
}
LastChangedRowId(DatabaseInterface &database,
Utils::SmallStringView databaseName,
Utils::SmallStringView tableName,
Utils::SmallStringView tableName2,
Utils::SmallStringView tableName3)
: database(database)
{
callback = [=](ChangeType, char const *database, char const *table, long long rowId) {
if (databaseName == database
&& (tableName == table || tableName2 == table || tableName3 == table))
this->lastRowId = rowId;
};
database.setUpdateHook(callback);
@@ -63,8 +94,6 @@ public:
public:
DatabaseInterface &database;
DatabaseInterface::UpdateCallback callback;
Utils::SmallStringView databaseName;
Utils::SmallStringView tableName;
long long lastRowId = -1;
};