Page 1 of 1
SQLite open shared
Posted: Sat May 28, 2016 10:31 am
by mk-soft
How to open SQLite Database as shared

Re: SQLite open shared
Posted: Sat May 28, 2016 11:07 am
by infratec
In general: bad idea.
It is not build for multi user usage.
There is no record locking and so on.
But there are attempts to do it.
http://purebasic.fr/english/viewtopic.php?f=14&t=43203
http://www.purebasic.fr/english/viewtop ... 14&t=63738
Bernd
Re: SQLite open shared
Posted: Sat May 28, 2016 12:04 pm
by mk-soft
I mean this
https://www.sqlite.org/lockingv3.html#shared_lock
I think Purebasic open database as unlocked
Re: SQLite open shared
Posted: Sat May 28, 2016 6:55 pm
by mrjiles
I am looking into this at the moment as well.
This article states the SQLite can be used for multiple concurrent read connections, but only a single write connection.
https://www.sqlite.org/whentouse.html. From using PB, it appears the database is locked, even when only reading from the database.
mk-soft, are you planning on accessing the database via network share?
Re: SQLite open shared
Posted: Sat May 28, 2016 7:05 pm
by infratec
Hi,
maybe this helps:
Code: Select all
UseSQLiteDatabase()
DB = OpenDatabase(#PB_Any, ":memory:", "", "")
If DB
If DatabaseUpdate(DB, "PRAGMA query_only=true") = 0
Debug DatabaseError()
EndIf
If DatabaseUpdate(DB, "CREATE TABLE test (text VARCHAR(255))") = 0
Debug DatabaseError()
EndIf
If DatabaseUpdate(DB, "PRAGMA query_only=false") = 0
Debug DatabaseError()
EndIf
If DatabaseUpdate(DB, "CREATE TABLE test (text VARCHAR(255))") = 0
Debug DatabaseError()
Else
Debug "Created"
EndIf
CloseDatabase(DB)
EndIf
See here:
https://www.sqlite.org/pragma.html
Bernd
Re: SQLite open shared
Posted: Sat May 28, 2016 7:09 pm
by infratec
Maybe you have to set the PRAGMA locking_mode to NORMAL.
Maybe it is set to EXCLUSIVE by PB.
Bernd
Re: SQLite open shared
Posted: Sat May 28, 2016 7:39 pm
by mrjiles
What about Write-Ahead Logging
https://www.sqlite.org/wal.html?
Code: Select all
If DatabaseUpdate(DB, "PRAGMA journal_mode=WAL") = 0
Debug DatabaseError()
EndIf
This appears to be working as intended, but I haven't tested it yet. Would this create the desired result of concurrent access?
Re: SQLite open shared
Posted: Sun May 29, 2016 10:12 am
by mk-soft
I think it´s a question to Fred.
Needed an optional parameter for open database as shared.
Re: SQLite open shared
Posted: Sun May 29, 2016 12:20 pm
by infratec
Hi,
I think you are wrong.
This SHARED is only handled internal of SQLite.
Read 5.0 Writing to a database file on the link you provided above.
I think it has nothing todo with how you open the database file.
Bernd
Re: SQLite open shared
Posted: Sun Jun 05, 2016 7:06 pm
by siesit
I will test later
thankee
