Can I manually Lock a database?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Can I manually Lock a database?

Jerry Krinock
 From reading the documentation I see that sqlite seems to have a very  
smart locking mechanism going on under the hood, regulating concurrent  
access by multiple applications.  Unfortunately, the designers of  
another application with which I share a database have decided to  
cache data internally, so that the only safe access is when that other  
app is not running.

That's easy enough to detect with API from the OS, but a conflict can  
still occur if they launch and start reading while I am in the middle  
of writing something I don't want to stop.  I need to lock the  
database so that they get SQLITE_BUSY until I'm done.

How can I manually lock the database using the C API?  I can't find  
any "lock" function.

Thanks,

Jerry Krinock
_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Can I manually Lock a database?

Clay Dowling
Jerry Krinock wrote:
> That's easy enough to detect with API from the OS, but a conflict can  
> still occur if they launch and start reading while I am in the middle  
> of writing something I don't want to stop.  I need to lock the  
> database so that they get SQLITE_BUSY until I'm done.
>
> How can I manually lock the database using the C API?  I can't find  
> any "lock" function.

http://www.openbsd.org/cgi-bin/man.cgi?query=flock

That only works if you're on a UNIX based OS, but it's the right trick
to use there.

Clay
_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Can I manually Lock a database?

Luca Olivetti
In reply to this post by Jerry Krinock
En/na Jerry Krinock ha escrit:

> How can I manually lock the database using the C API?  I can't find  
> any "lock" function.

In think you could just execute a "BEGIN EXCLUSIVE" query, then do your
thing then execute a "COMMIT" (or a "ROLLBACK" if something failed).

Bye

--
Luca Olivetti
Wetron Automatización S.A. http://www.wetron.es/
Tel. +34 93 5883004      Fax +34 93 5883007
_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users