set a SQLite to read only mode ?

hello,

i was wondering if it possible to access SQLite dbs in read only mode ? on desktop or iOS.

the purpose is to have two apps : one is the editor, and a simple client is only a readonly. in postgres or mysql you can have users privileges, but on local desktop ?

i see on the doc some alert :
5 Database is locked
6 Database table is locked
8 Attempt to write a read/only database

but i guess this is for web or local unix users that don’t have write permissions

and on iOS is it possible that two apps share the same db ?

thanks for any insight

not without jumping thru hoops… since the database is in a Sandbox, and each app would need access to it…

PRAGMA schema.locking_mode = EXCLUSIVE

but that will lock all other apps out of the database completely

Encrypted SQLite ? Once you can’t get in, you can hardly change anything.

you supply the encryption key during the connection sequence… and once connected, everything works exactly the same as if it were never encrypted… you can change anything

A client app that can’t open the database?

Will need a lot of advertising to become a success … :wink:

Nothing wrong with a database you can only READ from.
Consider a database on a CD…

SQLLite doesnt have the concept of users and permissions.
So if you want one user to be able to write, and another only to be able to read, you might try setting sharing permissions on the folder where the database resides.
Your user has full acces.
“Everyone” has read-only

This assumes that SQLLite doesnt try to write something into the database to record an active session.
And you probably have no similar options in iOS.

That said, you could ship a read-only and a read-write version of your app, with the absence of write actions coded into the business logic.

[quote=339602:@Jeff Tullin]you could ship a read-only and a read-write version of your app, with the absence of write actions coded into[/quote] it !

This is the real answer to the op question.

Also note: in theory one can open a sqlite database file in readonly mode, but this is not available in the Xojo SQLiteDatabase class. This is why the temporary log files are always created, even in a case where one has no intention to write, but only to select data. A major hassle for sandboxed apps on macOS…

An alternate answer can be:

in the Read Only application, just below the code that let the user to select a sqlite file, (check if the file Locked is true; if false:) use FolderItem.Locked ( FolderItem.Locked to true (example code there), and set it to false on quit (load another file), whatever.

And if your applications does not know the .sqlite file Locked status, you can check it at Open time, store the status and restore the original one before left the .sqlite (either selecting another fie or applciation quit).

These are clues, you will do things how you feel is the best for what your application do.

BTW, there was a feedback case related to this:
<https://xojo.com/issue/21814>

It would be helpful, if we could set the available flags before connecting to a sqlite database file, for instance SQLITE_OPEN_READONLY

SQLite Docs:
https://sqlite.org/c3ref/c_open_autoproxy.html
https://sqlite.org/c3ref/open.html