From c53c1f1c5410e262615c8c2dc75a4bec0f353d30 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Sun, 26 Feb 2017 19:12:37 +0100 Subject: [PATCH] Properly escape single quotes, allow multi-line text --- lyricsmanager.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lyricsmanager.py b/lyricsmanager.py index 82d6fb4..0fb8755 100755 --- a/lyricsmanager.py +++ b/lyricsmanager.py @@ -3,24 +3,32 @@ import dbtools def addLyrics(text, ref = 0, db = dbtools.dbHelper()): - db.executeQuery("INSERT INTO lyrics(text, ref, active) VALUES('%s', %i, %i);" % (text, ref, (1 if ref == 0 else 0))) + db.executeQuery("INSERT INTO lyrics(text, ref, active) VALUES('%s', %i, %i);" % (text.replace("'", "''"), ref, (1 if ref == 0 else 0))) db.commit() return db.cur.lastrowid def queryLyrics(ref = 0): - text = input("Text: ") + text = "." + out = "" - if len(text) > 130: - print("Text too long (%i characters)" % len(text)) + while text != "": + text = input("Text: ") + if out != "": + out += "\n%s" % text + else: + out = text + + if len(out) > 130: + print("Text too long (%i characters)" % len(out)) return queryLyrics(ref) ref = int(input("Reference [%i]: " % ref) or ref) - row = addLyrics(text, ref) + row = addLyrics(out, ref) ans = "" - while ans.lower() not in ("y", "n"): + while ans.lower() not in ("y", "n", ""): ans = input("Add follow-up lyrics? [Y/n] ") if ans.lower() != "n":