logOperation method
Implementation
Future<void> logOperation(String tableName, Operation operation, String rowguid,
{required String dbName, force = false}) async {
// Check if the table is configured for logging in the tableInfos
if (!tableInfos.containsKey(tableName)) return;
// Check if the client is configured for logging
final shouldLog = await isSyncConfigured(dbName: dbName);
if ((!force && !shouldLog) || isSyncing) {
debugPrint("Skipping LOG $tableName - $operation - rowguid $rowguid");
return;
}
debugPrint("LOG OPERATION $tableName - $operation - rowguid $rowguid");
// Follow the documented logic depending on the operation
switch (operation) {
case Operation.delete:
// Check if there is an existing log row
SyncData? existingLogRow =
await _existingLogRow(tableName, rowguid, null, dbName: dbName);
if (existingLogRow != null) {
// Delete the row whether it was an I or a U
await _deleteSyncDataRow(existingLogRow, dbName);
/*await SQLiteWrapper().execute("DELETE FROM sync_data WHERE id = ?",
params: [existingLogRow.id], dbName: dbName);
*/
// If it was an 'I' we don't insert anything more
if (existingLogRow.operation == "I") return;
}
// Insert the D for delete
await _insertLogRow(tableName, "D", rowguid, dbName: dbName);
break;
case Operation.insert:
await _insertLogRow(tableName, "I", rowguid, dbName: dbName);
break;
case Operation.update:
// Verify if there is an existing log row
SyncData? existingLogRow =
await _existingLogRow(tableName, rowguid, null, dbName: dbName);
if (existingLogRow != null) {
// If the previous row was an I we do nothing and don't update the date
// otherwise we could create precedence problems, it's a new insert anyway...
if (existingLogRow.operation == "I") return;
// Delete the row in case it was a U and insert it again
await _deleteSyncDataRow(existingLogRow, dbName);
}
await _insertLogRow(tableName, "U", rowguid, dbName: dbName);
break;
}
}