mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
sqlite3: Move begin transaction and commit into the driver
This has a slight side-effect of removing the actual begin and commit statements from the `db_write` hooks, but they are mostly redundant anyway (no harm in grouping pre-init statements into one transaction, and we know that each post-init call is supposed to be wrapped anyway). Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
committed by
Rusty Russell
parent
492d77f213
commit
716a3b11a5
@@ -16,9 +16,18 @@ def init(configuration, options, plugin):
|
||||
plugin.conn = sqlite3.connect(plugin.get_option('dblog-file'),
|
||||
isolation_level=None)
|
||||
plugin.log("replaying pre-init data:")
|
||||
plugin.conn.execute("PRAGMA foreign_keys = ON;")
|
||||
|
||||
print(plugin.sqlite_pre_init_cmds)
|
||||
|
||||
plugin.conn.execute("BEGIN TRANSACTION;")
|
||||
|
||||
for c in plugin.sqlite_pre_init_cmds:
|
||||
plugin.conn.execute(c)
|
||||
plugin.log("{}".format(c))
|
||||
|
||||
plugin.conn.execute("COMMIT;")
|
||||
|
||||
plugin.initted = True
|
||||
plugin.log("initialized {}".format(configuration))
|
||||
|
||||
@@ -29,9 +38,15 @@ def db_write(plugin, writes, **kwargs):
|
||||
plugin.log("deferring {} commands".format(len(writes)))
|
||||
plugin.sqlite_pre_init_cmds += writes
|
||||
else:
|
||||
print(writes)
|
||||
plugin.conn.execute("BEGIN TRANSACTION;")
|
||||
|
||||
for c in writes:
|
||||
plugin.conn.execute(c)
|
||||
plugin.log("{}".format(c))
|
||||
|
||||
plugin.conn.execute("COMMIT;")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user