"Attempt to write a readonly database" when database is created with MBS

I’ve got a totally perplexing problem with the SQLite version from MBS. Mainly I work with Valentina database which doesn’t have an FTS search. I’m using an index-only SQLite database for searching the main field. For large amounts of text I have seen the beachball. Therefore, I’ve tried to switch to the MT functions of the SQLite version in the MBS plugin.

If I create the SQLite database with MBS I get errors either “Attempt to write readonly database” or “no such table: bodyindex”:

If I create the database with SQLite from Xojo and then write to the database with the SQLite from MBS everything works fine. I’ve made an example using the exact same code to create the database and everything works fine.

The database itself isn’t exactly complicated:

Dim sql As String = "CREATE VIRTUAL TABLE bodyindex USING fts4(tokenize=unicode61,content='', messagebody);" SQLiteIndexDBMBS.SQLExecute(sql)

Does anyone have an idea what might cause these errors?

macOS 10.13 and 10.14, Xojo 2018r3, MBS 10.9.

You can open a database read only with a flag, but do you do that?

Can you show example project?

I’ll send you the example. But this doesn’t show the error.

Oh, and I get zombies, too, but only for Mojave:

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 MBS_SQL_SQLite_Plugin_19846.dylib 0x000000010d6e515c sqlite3LeaveMutexAndCloseZombie + 1596
1 MBS_SQL_SQLite_Plugin_19846.dylib 0x000000010d6e454e sqlite3Close + 878
2 MBS_SQL_SQL_Plugin_19846.dylib 0x000000010d460a1f Isl3Connection::Disconnect() + 31
3 MBS_SQL_SQL_Plugin_19846.dylib 0x000000010d409307 SAConnection::Disconnect() + 87
4 MBS_SQL_SQL_Plugin_19846.dylib 0x000000010d48297a closeDB(dbDatabase*) + 42
5 XojoFramework 0x0000000109b10206 databaseClose + 58
6 Mail Archiver X.debug 0x0000000105aa002b Database.Close%%o + 11
7 Mail Archiver X.debug 0x0000000106c949e4 SQLiteIndex.CloseSQLite%%o + 580 (/SQLiteIndex:376)

if you use threading, please make sure you don’t close it on one thread while it’s running on other thread.

The SQLite database is created on the main thread. The database is written to in a separate thread. Is this a problem?

Solved the problem by connecting/disconnecting for each database operation:

call ConnectToDatabaseLocalMBS if not ConnectedToSQLite then Return WriteLocalMBS(theRecID, MessageBody) CloseSQLite

Database and threads are extremely annoying.