xOpen method

  1. @override
XOpenResult xOpen(
  1. Sqlite3Filename path,
  2. int flags
)
override

Opens a file, returning supported flags and a file instance.

Implementation

@override
XOpenResult xOpen(Sqlite3Filename path, int flags) {
  final pathStr = path.path;
  if (pathStr == null) return _memory.xOpen(path, flags);

  final recognized = _recognizeType(pathStr);
  if (recognized == null) return _memory.xOpen(path, flags);

  final create = (flags & SqlFlag.SQLITE_OPEN_CREATE) != 0;
  final deleteOnClose = (flags & SqlFlag.SQLITE_OPEN_DELETEONCLOSE) != 0;

  _metaHandle.readDart(_existsList, FileSystemReadWriteOptions(at: 0));
  final existsAlready = _existsList[recognized.index] != 0;

  final syncHandle = _files[recognized]!;

  if (!existsAlready) {
    if (create) {
      syncHandle.truncate(0);
      _markExists(recognized, true);
    } else {
      throw const VfsException(SqlError.SQLITE_CANTOPEN);
    }
  }

  return (
    outFlags: 0,
    file: _SimpleOpfsFile(this, recognized, syncHandle, deleteOnClose),
  );
}