Sign in to follow this  
Followers 0
grasshopper3

Quick SQLite Question

5 posts in this topic

Hey, I have a quick SQLite question. I am trying to execute two queries on a SQLite database. The first is executed sucessfully, but when the second one fails with an error message, "database is locked". I am currently using _SQLite_Close($Database) and _SQLite_Shutdown() between the two executions. I am not sure why the database is locked. The first execution is an INSERT statement and the second is a DELETE statement. Is there some kind of release functions that I am missing?

Thanks

Share this post


Link to post
Share on other sites



I guess it's just happening what the error code says, the database is locked ;). The first INSERT statement does not seem to be finalized when you start the DELETE statement. Afaik SQLite supports a parallel reading (select) query, but two writing queries (insert, update, delete) are not allowed at the same time. Did you issue an BEGIN TRANSACTION without a COMMIT TRANSACTION? Maybe also try _SQLite_QueryFinalize()? Hard to say without a code sample :)...

Here's some reading on the locking mechanism: http://www.sqlite.org/lockingv3.html

Share this post


Link to post
Share on other sites

It's a waste of resources and cycles to perform _close and (even more) _shutdown unnecessarily.

Typically, "Database is locked" means that an SQL statement (some SQLite VDBE) is still executing, when you attempt to execute another SQL statement using the same connection. This is a design error.

Post simple offending code with irrelevant parts removed and we'll show you what's going on and how to avoid problems.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Thanks for the support! I figured out the problem. I was missing _SQLite_QueryFinalize().

Share this post


Link to post
Share on other sites

I recommend not using split operations whenever possible. I mean you can generally have your job done by using only higher level function calls: _SQLite_Exec, _SQLite_GetTable[2d] or _SQLite_QuerySingleRow and such. Almost every piece of code I've been shown using "lower level" calls turns out to be less efficient and more error-prone.

Of course if your application calls for a more technical tuning, then you can achieve best performance by using _Preparev2 and friends yourself, but this requires careful structure in the code and a really good understanding of the working of the SQLite library itself.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0