SQLite Connection Limit

Just starting out? Need help? Post your questions and find answers here.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

SQLite Connection Limit

Post by Karbon »

Is there any hard coded connection limit built into the PB SQLite support? I switched an app from using ODBC (with the SQlite ODBC driver) to the native PB support and now the application hangs if 3 or 4 connections are made to the db file (it seems to vary on XP and Vista?). None are explicitly asking for exclusive access but is that built-in to the PB lib somehow?

AFAIK SQlite itself enforces no limit other than whole-database locking on write (which is fine since the clients I'm speaking of only need read access)..
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
User avatar
bobobo
Enthusiast
Enthusiast
Posts: 206
Joined: Mon Jun 09, 2003 8:30 am

Post by bobobo »

do you use databaseerror() to recognize db/file-locks ?

i do preferr a delayed loop while databaseerror() ist not ok with sqlite.
사십 둘 .
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Yes, I do and there are no errors - the OpenDatabase call never returns.
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

I just tested a huge project i am working on with 8 concurrent clients and all works well... 2 databases, 16 connections...

I have noticed sqlite plugin is very picky about DatabaseQuery() and DatabaseUpdate() so be very careful and always test each sql statement with both !

If one gives an error, try the other command with the same sql statement!

Sometimes, when i'm in SQLITE MANAGER in firefox i get db locks, specially after a begin transaction / commit, they always lock the database, so try to avoid them under sqlite PB!

They work great outside but under PB i get db locks ...
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

SQLite's locking is whole-file locking so you'll run into problems trying to write to the database from concurrent connections.

DatabaseUpdate() should be used for queries that write to the database (INSERT UPDATE DELETE, ALTER, etc), DatabaseQuery() is only used when the query returns a result set (SELECT).

In your project are you connecting to a file on a network share?
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Yes, it's on a network share and i had no troubles so far...
I also test it on my pen drive for even slower times, and it works too.

Oh, wait, but i'm using the beta revised version!

http://purebasic.com/beta/windows/

Maybe that helps!
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

I'll re-run all my tests with the newest version..
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Unfortunately it is still happening.. It looks like the very first call to OpenDatabase on the 4th workstation hangs everything.
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

OpenDatabase for SQLite is just a wrapper to sqlite3_open_v2(), so i don't think it's specific to PB, you may try to test with the API to be sure..
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post by dige »

Check out "Pragmas" http://www.sqlite.org/pragma.html
if you dont use a single access.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

Fred wrote:OpenDatabase for SQLite is just a wrapper to sqlite3_open_v2(), so i don't think it's specific to PB, you may try to test with the API to be sure..
Thats useful to know, what params are used?
The sqlite3_open_v2() interface works like sqlite3_open() except that it acccepts two additional parameters for additional control over the new database connection. The flags parameter can be one of:

- SQLITE_OPEN_READONLY
- SQLITE_OPEN_READWRITE
- SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE

The first value opens the database read-only. If the database does not previously exist, an error is returned. The second option opens the database for reading and writing if possible, or reading only if if the file is write protected. In either case the database must already exist or an error is returned. The third option opens the database for reading and writing and creates it if it does not already exist. The third options is behavior that is always used for sqlite3_open() and sqlite3_open16().
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

dige wrote:Check out "Pragmas" http://www.sqlite.org/pragma.html
if you dont use a single access.
By default, it allows many access, or i miss something ?

pdwyer: it uses SQLITE_OPEN_READWRITE
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post by dige »

Yes, by default is: synchronous = FULL and locking_mode = NORMAL,
so my posting is redundant.
It was just an idea ... :?
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

Cheers Fred!

Karbon, maybe as a test you can try the API method and use the readonly flag to open the DB, see it it helps.

My guess is that over time the PB sqlite implementation will mature and put more options for us to use but it might not quite be everything to everyone in this first release
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

I've solved it, or at least I think I have..

The database was being locked in between connections (at application start the DB is written to several times). Apparently the ODBC driver had additional checks built-in and that is why it was working before using ODBC.

Thanks to all!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Post Reply