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:

Post by Karbon »

More on this..

The database is being locked but the problem is that DataBaseUpdate() is taking several minutes to return so the error can be read when it is. The lock is no problem, the software cause just pause for a few seconds and re-try.

It seems to only happen when the database is on a network drive and accessed by more than one application.

So, is there any reason that any of the query functions would take so long to return with the "database is locked" error?
-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 this was my nightmare too :D

I solved it by refining my sql queries and not using any type of begin transaction / commit, just a for / next loop with database updates or if i got this kind of delay, used databasequery instead... Not correct, but it get's the job done!
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Good, then I'm not crazy! Even trapping the error is causing a 1+ minute delay so it's a pretty serious problem.

When I was using the SQLite lib directly before (though a userlib) that didn't happen so I'm guessing it is something with the new PB->SQLite hook.

Fred? Help!? :-)
-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
npath
User
User
Posts: 74
Joined: Tue Feb 15, 2005 5:15 pm

Post by npath »

Karbon,

You are not alone. I am also having trouble with database locks when using the databaseupdate command. I suspect the problem is with the PB wrapper, as I have used this SQLite database with several other languages, including RealBasic and Powerbasic. I am not having any trouble querying the database. However, any attempts at updating the database results in a lock. I have tried numerous approaches to prevent this, but perhaps I am missing something.

npath
npath
User
User
Posts: 74
Joined: Tue Feb 15, 2005 5:15 pm

Post by npath »

Also, I forgot to mention that error traps are resulting in a 30-60 second delay before returning the "database is locked" error.

Does anyone know how to unlock databases?
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

There isn't any way to unlock a database except for all clients to release the lock. In my case I know it isn't locked even when my PB application is telling me it is. I've written another utility in C to connect to the SQLite database and issue SELECT and UPDATE queries - those queries complete but any queries issued through the PB application fail... Using the straight C API the query functions return instantly if the database is locked.

Locking is tricky with SQLite since it locks the entire database when a write operation is in progress. Still, the DatabaseQuery and DatabaseUpdate function should return instantly if the database is locked.
-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
npath
User
User
Posts: 74
Joined: Tue Feb 15, 2005 5:15 pm

Post by npath »

Interesting. Sounds quite suspicious for a bug.
npath
User
User
Posts: 74
Joined: Tue Feb 15, 2005 5:15 pm

Post by npath »

Karbon,

Do you have any snippets for doing an update using straight API? Perhaps I can bypass the supposed lock.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Only in C, and it is all right here : http://www.sqlite.org/c_interface.html

Can't use any of that inside a PB application though. I wrote a standalone program to access my databases.

I've ported all the database access to use the PB Database library function so I hesitate to try to find a userlib that directly uses the SQLite DLL at this point. Hopefully it is something Fred & CO can sort out for us pretty quickly -- they do rock after 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
npath
User
User
Posts: 74
Joined: Tue Feb 15, 2005 5:15 pm

Post by npath »

Thanks Karbon,

I too have rewritten an application, converting over to built-in SQLite database functionality in PB. I will also wait for a fix, and try to find a work around in the meantime. I have versions of the application in numerous other languages, and find that Purebasic is the best of all. Fred and the team have done an amazing job.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

[quote="Karbon"]Only in C, and it is all right here : http://www.sqlite.org/c_interface.html

Can't use any of that inside a PB application though. I wrote a standalone program to access my databases.

I've ported all the database access to use the PB Database library function so I hesitate to try to find a userlib that directly uses the SQLite DLL at this point. Hopefully it is something Fred & CO can sort out for us pretty quickly -- they do rock after all :-)[/quote]

Karbon, I use TS-Soft and company's SOURCE wrapper that directly imports the pb4.2 statically linked sqlite lib functions and it works a treat. Now that I almost know what I am doing (LOL).

So, it's not a user lib, it's a source format wrapper. That way, you can inspect and modify it yourself.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

There are OSL and inc files around for using the SQLite API directly. Probably all tips and tricks SQLite posts more than 3-4 months old are not using PBs implementation.
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 »

Hi Fang.. Is there a definitive version of the include you're using? I see several with 8 pages of suggestions and reports of strange things.. Where is the latest 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
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Karbon wrote:I see several with 8 pages of suggestions and reports of strange things.. Where is the latest version?
The latest version should be here : http://www.purebasic.fr/english/viewtop ... 853#240853
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
the.weavster
Addict
Addict
Posts: 1576
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Post by the.weavster »

Why are you all intent on doing something SQLite's developer specifically recommends not doing? i.e. sharing a SQLite database on a network share.

If you want to share a database on a network why don't you use something like Firebird which is designed for the job?
Post Reply