executeSQLs method

Future<bool> executeSQLs(
  1. List<SQL> sqls, {
  2. DB<DBConnection>? prepared,
  3. Map<String, dynamic>? properties,
})

Implementation

Future<bool> executeSQLs(List<SQL> sqls,
    {DB? prepared, Map<String, dynamic>? properties}) async {
  if (sqls.isEmpty) return false;

  final logInfo = this.logInfo;
  final logError = this.logInfo;

  var db = prepared ?? (await openDB());

  if (db == null) {
    if (logError != null) {
      logError("Can't open DB: $this");
    }
    return false;
  }

  try {
    var started = await db.startTransaction();
    if (!started) return false;

    if (logInfo != null) {
      logInfo("Started transaction");
    }

    await resolveSQLs(db, properties: properties);

    var ok = await _executeImpl(db, sqls);

    if (ok) {
      ok = await db.commitTransaction();
      if (logInfo != null) {
        logInfo("Commit transaction: ${ok ? 'OK' : 'FAILED'}");
      }
      return ok;
    } else {
      if (logInfo != null) {
        logInfo("Rollback transaction");
      }
      await db.rollbackTransaction();
      return false;
    }
  } catch (e, s) {
    print(e);
    print(s);
    await db.rollbackTransaction();
    return false;
  }
}