SQLite open shared

Just starting out? Need help? Post your questions and find answers here.
User avatar
mk-soft
Always Here
Always Here
Posts: 6204
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

SQLite open shared

Post by mk-soft »

How to open SQLite Database as shared :?:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: SQLite open shared

Post 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
User avatar
mk-soft
Always Here
Always Here
Posts: 6204
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: SQLite open shared

Post by mk-soft »

I mean this
https://www.sqlite.org/lockingv3.html#shared_lock

I think Purebasic open database as unlocked
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
mrjiles
Enthusiast
Enthusiast
Posts: 238
Joined: Fri Aug 18, 2006 7:21 pm
Location: IL

Re: SQLite open shared

Post 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?
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: SQLite open shared

Post 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
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: SQLite open shared

Post by infratec »

Maybe you have to set the PRAGMA locking_mode to NORMAL.
Maybe it is set to EXCLUSIVE by PB.

Bernd
mrjiles
Enthusiast
Enthusiast
Posts: 238
Joined: Fri Aug 18, 2006 7:21 pm
Location: IL

Re: SQLite open shared

Post 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?
User avatar
mk-soft
Always Here
Always Here
Posts: 6204
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: SQLite open shared

Post by mk-soft »

I think it´s a question to Fred.
Needed an optional parameter for open database as shared.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: SQLite open shared

Post 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
siesit
User
User
Posts: 12
Joined: Fri Aug 21, 2009 8:40 am
Location: rus
Contact:

Re: SQLite open shared

Post by siesit »

I will test later
thankee :)
site created by purebasic work-flow-Initiative
Post Reply