Closed svetlyak40wt closed 4 years ago
Hm, tests fails for mysql and postgresql.
I'll add a docker-compose file to run all tests in development,
@fukamachi please, review this pull. It is ready now.
@fukamachi Eitaro, please, review this pull :)
Sorry for the late reply, and thank you for your contribution. Especially, Docker configurations for testing look so nice :)
I suspect that SQL executions after a manual commit/rollback will be auto-committed though it's in a with-transaction
, won't they?
For example, the following code probably adds a new (name="cat"
) animal in spite of it will raise an error:
(with-transaction *connection*
(do-sql *connection* "INSERT INTO animal (name) VALUES ('dog')")
(rollback *connection*)
;; Will this be auto committed?
(do-sql *connection* "INSERT INTO animal (name) VALUES ('cat')")
;; Will raise an error.
(rollback *connection*))
Yes, this is why I've added a call to turn-off-autocommit
in unittests.
Probably it is better to change MySQL's driver to turn off auto-commit for with-transaction
block.
What do you think?
My understanding is that disabling autocommit implicitly begins a transaction when executing an SQL. Let's think about an example like the following code:
(with-transaction *connection*
(turn-off-autocommit)
(do-sql *connection* "INSERT INTO animal (name) VALUES ('dog')")
(rollback *connection*)
;; This implicitly starts a new transaction
(do-sql *connection* "INSERT INTO animal (name) VALUES ('cat')"))
;; And the transaction still lives here?
The implicit transaction opened by "INSERT INTO" would be leaked outside of with-transaction
.
IMHO, all DB operations after manual commit/rollback inside with-transaction
should be prohibited.
all DB operations after manual commit/rollback inside with-transaction should be prohibited.
@fukamachi do you want me to implement this requirement?
If you don't mind and have some time for it.
Ok.
@fukamachi please, review this pull again.
I've added a necessary check to prohibit SQL queries after the manual commit or rollback. The main job was made in the f8f7401cac2ca2a23e1360210dd1624dc6bd4080 commit.
Merged. Thank you for your effort!
Great! Thank you for the code review.
Now their state is stored in small structures and at any point of time it possible to know if the transaction already was committed or rolled back.
Also, the issue https://github.com/fukamachi/cl-dbi/issues/49 about non-local exit from
dbi:commit
function. Now control flow continues after the manuall call todbi:commit
. But second manual call todbi:commit
ordbi:rollback
will cause error.Other changes
with-took-ms
. Now it really report in milliseconds. Previously, macro returned the value in internal units which on some implementation may be equal to milliseconds.sqlite3
driver logs sql queries the same way as postgresql does.