executeSQLsByIDs method

Future<bool> executeSQLsByIDs(
  1. List<String> sqlIDs, {
  2. Map<String, dynamic>? properties,
})

Implementation

Future<bool> executeSQLsByIDs(List<String> sqlIDs,
    {Map<String, dynamic>? properties}) async {
  final logInfo = this.logInfo;
  final logError = this.logError;

  sqlIDs = sqlIDs.toSet().toList();

  var dbCommands = sqlIDs.map(getDBCommandWithSQL).whereNotNull().toList();
  if (dbCommands.isEmpty) {
    if (logInfo != null) {
      logInfo("Can't find SQLs: $sqlIDs");
    }
    return false;
  }

  if (dbCommands.length < sqlIDs.length) {
    if (logInfo != null) {
      logInfo("Can't find ALL SQLs: $sqlIDs");
    }
    return false;
  }

  dbCommands = dbCommands.toSet().toList();

  for (var dbCommand in dbCommands) {
    dbCommand.logInfo ??= logInfo;
    dbCommand.logError ??= logError;

    var sqls = dbCommand.getSQLsByIDs(sqlIDs);

    var ok = await dbCommand.executeSQLs(sqls, properties: properties);
    if (!ok) {
      if (logInfo != null) {
        logInfo(" SQLs execution failed: $sqls");
      }
      return false;
    }
  }

  return true;
}