Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I notify a process of an SQLite database change done in a different process?

Let's say I have two or more processes dealing with an SQLite database - a "player" process and many "editor" processes.

The "player" process reads the database and updates a view - in my case it would be a waveform being mixed to the soundcard depending on events stored in the database.

An "editor" process is any editor for that database: it changes the database constantly.

Now I want the player to reflect the editing changes quickly.

I know that SQLite supplies hooks to trace database changes within the same process, but there seems to be little info on how to do this with multiple processes.

I could poll the database constantly, compare records and trigger events, but that seems to be quite inefficient, especially when the database grows to a large size.

I am thinking about using a log table and triggers, but I wonder if there is a simpler method.

like image 948
paniq Avatar asked Mar 24 '09 11:03

paniq


People also ask

Can multiple processes write to SQLite?

SQLite allows multiple processes to have the database file open at once, and for multiple processes to read the database at once. When any process wants to write, it must lock the entire database file for the duration of its update.

Can multiple applications use the same SQLite database?

Yes. From the FAQ: Can multiple applications or multiple instances of the same application access a single database file at the same time? Multiple processes can have the same database open at the same time.

What is CRUD operations in SQLite?

CRUD is nothing but an abbreviation for the basic operations that we perform in any database. And the operations are. Create. Read. Update.

Which command is used to modify records SQLite?

There are three commands in data manipulation language group: INSERT: This command is used to create a record. UPDATE: It is used to modify the records. DELETE: It is used to delete records.


1 Answers

If it's on the same machine, the simplest way would be to have named pipe, "player" with blocking read() and "editors" putting a token in pipe whenever they modify DB.

like image 79
vartec Avatar answered Sep 30 '22 13:09

vartec