/// Open an EXISTING database without writing a byte to it. /// /// [`Library::open`] cannot be used from a process that does not own the /// library: it runs `PRAGMA journal_mode = WAL` and a batch of /// `CREATE TABLE IF NOT EXISTS`, both writes, and on Android it may be /// racing the real app. Android Auto browses and plays from a /// service-started process with no Activity in it, and this is the door /// it uses. /// /// A read-only open of a WAL database is legal from SQLite 3.22 (this /// tree bundles 3.46) as long as the `-shm` and `-wal` files exist and /// are readable, OR there is write permission on the DIRECTORY holding /// the database. The second always holds for us — the reader is the /// app's own uid and owns `…/Library/.soulstream/` — which is why this /// works even though `journal_mode=WAL` is persistent and every /// SoulStream database is in it. /// /// `NO_MUTEX` because the connection is behind this struct's own /// `Mutex`; `URI` because the default flags carry it and dropping it /// would quietly change how a path with a `?` in it is read. pub fn open_read_only(db_path: &Path) -> Result { let conn = Connection::open_with_flags( db_path, rusqlite::OpenFlags::SQLITE_OPEN_READ_ONLY | rusqlite::OpenFlags::SQLITE_OPEN_NO_MUTEX | rusqlite::OpenFlags::SQLITE_OPEN_URI, )?; Ok(Library { conn: Mutex::new(conn), }) }