From f6ded0a87942605c4feb005b60a148706fe640f1 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 8 May 2021 18:26:43 -0700 Subject: [PATCH] Add sqlhelpers.executescript. --- voussoirkit/sqlhelpers.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/voussoirkit/sqlhelpers.py b/voussoirkit/sqlhelpers.py index 46fa11a..3f903ee 100644 --- a/voussoirkit/sqlhelpers.py +++ b/voussoirkit/sqlhelpers.py @@ -114,6 +114,18 @@ def update_filler(pairs, where_key): qmarks = qmarks.format(setters=setters, where_key=where_key) return (qmarks, bindings) +def executescript(conn, script): + ''' + The problem with Python's default executescript is that it executes a + commit before running your script. If I wanted a commit I'd write one! + ''' + lines = re.split(r';(:?\n|$)', script) + lines = (line.strip() for line in lines) + lines = (line for line in lines if line) + cur = conn.cursor() + for line in lines: + cur.execute(line) + def hex_byte(byte): ''' Return the hex string for this byte. 00-ff.