E
E
estry2020-11-10 07:23:04
MySQL
estry, 2020-11-10 07:23:04

Can two programs work with the same database?

Hello. Is it possible to organize the work of two programs with the same database in such a way that when queries from one program are executed, the database is locked and the second program waits until the work of the first program with the database ends? I'm afraid that both programs do not receive the same data. Are there any methods for MySQL and sqlite?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
alexalexes, 2020-11-10
@alexalexes


Both programs receive data from the database and work with them. So I want to exclude the possibility of obtaining the same data by both programs. Now I use using in my code and open a connection in it. Next, we get the data, in a certain column of the table I mark that the data has been taken, which indicates to the second program that it should no longer take this data.

Based on this comment, you need to get familiar with the theory: Scheduler
design pattern and task queue based systems .
In addition to "two programs", in your case these are workers (executors), your system must also have a scheduler that has priority over workers, which will form tasks.
Both the scheduler and the executors themselves can assign tasks to performers.
Each task must have an ID, an execution status, an assigned performer, and a list of objects that the performer must process. It is the list of objects that will limit the work of one performer so that they "do not climb on the same records in the tables."
Of course, you need to get acquainted with transactions and table lock levels - this is only part of the system implementation tools, but you cannot do without a scheduler.

S
Sergey Gornostaev, 2020-11-10
@sergey-gornostaev

SQLite locks on open by default, while MySQL has locks .

D
Dr. Bacon, 2020-11-10
@bacon

Locks are different, for reading/writing, for different entities - string/table/base. The specifics should be clarified from docks to a DBMS.

I'm afraid that both programs do not receive the same data.
what does this mean, why is it causing a problem? Explain.

D
Developer, 2020-11-10
@samodum

Read mana about table lock levels in databases

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question