-
Notifications
You must be signed in to change notification settings - Fork 346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transaction manager for SQLite3 #595
Comments
Sure, give me moment, to prepare a zip file and a brief explanation. |
OK, I have attached a zip file with the source code for the database manager that I use. It uses PostgreSQL but it should be relatively easy to adjust it to MySQL or SQLite3. It does optimistic locking, i.e. parallel/concurrent users try to make their changes to the database and if there is some kind of problem combining the parallel transactions, one or more of them are retried until they succeed. Here is how to use it:
g_dbm.tx (lambda) : Runs a transaction. The lambda contains your transaction code. If a transaction isolation error occurs, then the transaction is retries. Other exceptions are not intercepted so the bubble up and if unhandled terminate If the lambda returns normally (no exception), its return value becomes the return value of the call to g_dbm.tx g_dbm.exec (sqlpp11_query) : Calls the database handle with the given query. Does the same as g_dbm.dbc_no_tx() : Returns a database connection handle that can be used to do anything you do with regular sqlpp11 database connections, for example make a query outside of a transaction (I guess then the database engine uses autocommit mode).
The code includes db_model.h : This file is not included in the .zip. This is the database model generated by
The code in includes spdlog.h, but you can remove the calls to it. THe database manager uses it to log messages about transaction failures and their retries. The code in sqlpp::postgresql::serialization_failure You will need to change that probably to retry on The db manager takes (or at least should take) care of multithreading so it is OK to call I haven't used this code with SQLite3 so no guarantee that it will actually work, but it is worth trying. Hope that helps. |
Thanks a lot for sharing the code ad the detailed explanation! |
By the way, the code was originally written for a C++20 project, but I think that it is mostly compatible and should compile in C++17 mode with no or little changes. There is one place where it uses |
Hello @MeanSquaredError,
I am currently working with a SQLite3 database that can be accessed by several processes.
One of the processes can run a long write transaction and other processes could run read transactions at the same time.
In issue #554 you mentioned that you have a transaction manager for PostgreSQL and that sounds exactly like the solution I need for this. Could you share it?
What changes do you think would be needed in the SQLite3 connector to make it work with SQLite3?
Thanks a lot.
Best,
Roberto.
The text was updated successfully, but these errors were encountered: