Select inside commit_hook, implicit vs explicit transactions
(1) By Søren Sjørup (zorendk) on 2023-11-04 19:02:15 [link] [source]
I understand that one shouldn't do select statements inside a commit hook.
But I don't understand the behaviour I see here:
package require sqlite3
sqlite3 db1 :memory:
db1 eval {CREATE TABLE t(i)}
proc bad_commit_hook_that_selects {} {
db1 eval {SELECT i FROM t}
puts "inside bad_commit_hook_that_selects"
return 0
}
db1 commit_hook bad_commit_hook_that_selects
# this works fine
db1 eval {INSERT INTO t VALUES("outside transaction")}
# this causes an infinite loop
db1 transaction {
db1 eval {INSERT INTO t VALUES('inside transaction')}
}
puts "never reached"
As far as I understand the first INSERT runs inside an implicit transaction. It does trigger the bad commit_hook and inserts as expected.
The second INSERT inside an explicit transaction causes an infinite loop. Just out of interest. What is the cause of this difference in behaviour?
Kind regards Søren
(2) By Gunter Hick (gunter_hick) on 2023-11-06 09:35:51 in reply to 1 [source]
How much it hurts when attempting to hit yourself on the head with a hammer depends on if you hit or miss. Just don't do it.