开发者

Delphi SQLite3 using ZeosLib, how to share a database?

开发者 https://www.devze.com 2023-03-20 09:27 出处:网络
I am using Delphi 7 and ZeosLib 6.6.6 to access SQLite3 database. What is the best practice to use shared database.

I am using Delphi 7 and ZeosLib 6.6.6 to access SQLite3 database.

What is the best practice to use shared database.

I plan to put the database file (data.db3) in a sh开发者_运维问答ared location.

And the Delphi application is on local desktop computer of every users.

I want to know how to manage database locking for example. Detecting if the database is being locked by certain user, things like that.

Thanks.


SQlite3 handle database sharing by default, locally on the same computer. You have nothing to do, just open the database several times on your hard drive. Of course, it does have an overhead, and locking will make it slower than access from one unique process.

But if by "in a shared location" you mean a network drive, as your question suggests, it probably won't work as expected.

Locking files over a network are not safe (at least in Windows world). See http://www.sqlite.org/cvstrac/wiki?p=SqliteNetwork

You should instead rely on a true Client/Server approach, still possible with SQLite3 on the server, and Clients accessing to it via the network. See e.g. our RESTful server using JSON and several protocols.


  1. You can put a SQLite database on a shared network resource. According to the SQLite documentation - that is not recommended. Main reason - SQLite cannot effectively manage locking on a shared resource.
  2. If you need multi-user access to a SQLite database, then you may consider using middleware, like DataAbstract. As a driver for Data Abstract you can use our library AnyDAC. Some articles: Using SQLite with AnyDAC and Using Data Abstract with AnyDAC. In first article check "Connecting to SQLite database from Delphi application" for usage cases, including how to setup for concurrent access.
0

精彩评论

暂无评论...
验证码 换一张
取 消