From 135b9b720249327d1904b41f4c5b5b78ada77470 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Tue, 7 Jun 2022 15:26:05 +0200 Subject: [PATCH] updated test cases and added or condition --- queryTest.py | 36 ++++++++++++++++++++++++------------ test.json | 13 ++++++++++++- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/queryTest.py b/queryTest.py index 7e28cb3..21f74aa 100644 --- a/queryTest.py +++ b/queryTest.py @@ -7,26 +7,38 @@ with open('test.json') as f: for element in data: for key, value in element.items(): title=key - print("Search Title: " + title) +# 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) + # 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 + ")" + # print(k) + if j == "series" or j == "title": + firstS = True + query = query + "(" + for l in k: + if not firstS: + query = query + "or " + query = query + j + " like '%" + l + "%' " + if firstS: + firstS = False + query = query + ") " + else: + 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: diff --git a/test.json b/test.json index 074d280..0e5e0b7 100644 --- a/test.json +++ b/test.json @@ -13,10 +13,21 @@ } ] }, + { + "Marvel": [ + { + "title": "", + "volume": "", + "publisher": "marvel", + "series": "", + "issue": "" + } + ] + }, { "Girl": [ { - "title": "girl", + "title": ["girl","man","World"], "volume": "", "publisher": "", "series": "girl",