From bb440a068f2b3b432ee34eebdd79b8402d7c4f68 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Tue, 7 Jun 2022 14:14:28 +0200 Subject: [PATCH] added json to sql query test case --- queryTest.py | 35 +++++++++++++++++++++++++++++++++++ test.json | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 queryTest.py create mode 100644 test.json diff --git a/queryTest.py b/queryTest.py new file mode 100644 index 0000000..7e28cb3 --- /dev/null +++ b/queryTest.py @@ -0,0 +1,35 @@ +import json + + +with open('test.json') as f: + data = json.load(f) + +for element in data: + for key, value in element.items(): + title=key + print("Search Title: " + title) + query="SELECT * FROM COMICS where " + for i in value: + first=True + for j,k in i.items(): + if k != '': + print(j,k) + if not first: + query = query + "and " + if type(k) == list: + print(k) + query = query + j + " in (" + firstL = True + for l in k: + if not firstL: + query = query + "," + query = query + "'" + l + "'" + if firstL: + firstL = False + query = query + ")" + else: + query = query + j + " like '%" + k + "%' " + if first: + first = False + query = query + ";" + print("----> " + query) diff --git a/test.json b/test.json new file mode 100644 index 0000000..074d280 --- /dev/null +++ b/test.json @@ -0,0 +1,50 @@ +[ + { + "Man 2020,2019": [ + { + "title": "Man", + "volume": [ + "2020", + "2019" + ], + "publisher": "", + "series": "", + "issue": "" + } + ] + }, + { + "Girl": [ + { + "title": "girl", + "volume": "", + "publisher": "", + "series": "girl", + "issue": "" + } + ] + }, + { + "Aquaman": [ + { + "title": "", + "volume": "", + "publisher": "", + "series": "aquaman", + "issue": ["2","3","5","10","22"] + } + ] + } +, + { + "Girl series": [ + { + "title": "", + "volume": "", + "publisher": "", + "series": "girl", + "issue": "2" + } + ] + } +]