How to open FMDatase as ReadOnly?

131 views
Skip to first unread message

Steve Cronin

unread,
Jul 29, 2020, 4:28:55 PM7/29/20
to FMDB
Is there a way to open an FMDatabase as 'readonly'?

Don't see anything in the docs but maybe I just don't understand...

A pointer to documentation would be appreciated


August Mueller

unread,
Jul 29, 2020, 5:06:18 PM7/29/20
to fm...@googlegroups.com
You can pass the read only flag:

[[FMDatabaseQueue alloc] initWithURL:fileURL flags:SQLITE_OPEN_READONLY];

-gus
> --
> You received this message because you are subscribed to the Google Groups "FMDB" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to fmdb+uns...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/fmdb/09c4d2f5-203e-4161-90c8-675a93e2d82fo%40googlegroups.com.

Steve Cronin

unread,
Jul 29, 2020, 5:39:51 PM7/29/20
to fm...@googlegroups.com
On Jul 29, 2020, at 2:06 PM, August Mueller <g...@flyingmeat.com> wrote:

You can pass the read only flag:

[[FMDatabaseQueue alloc] initWithURL:fileURL flags:SQLITE_OPEN_READONLY];


Hey Thanks for the quick response!

Using Swift this seems to work:

SQLInternalFileURL = URL.init(fileURLWithPath: Bundle.main.path(forResource: SQLFileName, ofType: SQLFileExtension)!)
if (FileManager.default.fileExists(atPath: SQLInternalFileURL.path)) {
var internalDB:FMDatabase = FMDatabase(url: SQLInternalFileURL)
guard internalDB.open(withFlags:0x00000001) else {
}
} else {
}

Any gotchas with this that I should be aware of?

‘SQLITE_OPEN_READONLY’ wasn’t recognized in Swift (UIKit)
Reply all
Reply to author
Forward
0 new messages