isTransientError function

bool isTransientError({
  1. required int resultCode,
  2. required String sql,
  3. required bool isQuery,
  4. required bool wasInTransaction,
  5. required bool isInTransaction,
  6. bool? fileChanged,
})

Whether a statement that failed with resultCode may be run again: the error may go away on its own and nothing of the statement can have been stored. See the header of this file. fileChanged is whether the file change counter of the database differs from before the statement, for a statement that may commit (null when it was not checked).

Implementation

bool isTransientError({
  required int resultCode,
  required String sql,
  required bool isQuery,
  required bool wasInTransaction,
  required bool isInTransaction,
  bool? fileChanged,
}) {
  switch (resultCode) {
    case sqlite.SqlError.SQLITE_BUSY:
    case sqlite.SqlError.SQLITE_LOCKED:
    case sqlite.SqlError.SQLITE_IOERR:
    case sqlite.SqlError.SQLITE_FULL:
      break;
    default:
      return false;
  }
  final String verb = _verb(sql);
  if (_commits(verb)) {
    // Not committed when the transaction is still open, or when it ended
    // and the database file is as it was before (rolled back).
    return isInTransaction || fileChanged == false;
  }
  if (wasInTransaction) {
    return true;
  }
  return isQuery ||
      verb == 'BEGIN' ||
      verb == 'ROLLBACK' ||
      verb == 'SELECT' ||
      fileChanged == false;
}