From 1a5e78d6d48489492b654b11b97c3d05e9a1dc1e Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Thu, 27 Aug 2020 15:03:57 +0200 Subject: [PATCH 1/4] Fix crash on empty text --- relational/optimizer.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/relational/optimizer.py b/relational/optimizer.py index 9de4444..5637b96 100644 --- a/relational/optimizer.py +++ b/relational/optimizer.py @@ -39,7 +39,8 @@ def optimize_program(code: str, rels: Dict[str, Relation]) -> str: lines = code.split('\n') context: Dict[str, Node] = {} - for line in lines: + last_res = None + for line in lines: # skip comments or empty lines line = line.strip() if line.startswith(';') or not line: @@ -51,6 +52,9 @@ def optimize_program(code: str, rels: Dict[str, Relation]) -> str: parsed = tree(query) _replace_leaves(parsed, context) context[res] = parsed + + if last_res is None: + return '' node = optimize_all(context[last_res], rels, tostr=False) return querysplit.split(node, rels) From c44a9abff4b7045c3ea1c0c32112a8142499269d Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Thu, 27 Aug 2020 16:29:11 +0200 Subject: [PATCH 2/4] No sip --- relational.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/relational.py b/relational.py index 06a6996..33cb75f 100755 --- a/relational.py +++ b/relational.py @@ -82,8 +82,6 @@ if __name__ == "__main__": if x11: import signal signal.signal(signal.SIGINT, signal.SIG_DFL) - - import sip # needed on windows from PyQt5 import QtWidgets try: from relational_gui import guihandler, about, surveyForm From 821b96c6e86789a9a383bd219d308a7b7bc3aa9d Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Thu, 27 Aug 2020 16:34:42 +0200 Subject: [PATCH 3/4] Force \n as endline Closes: #15 On windows python uses \r\n when saving, but \n when loading so it is a mess. So i need to force it. --- relational/relation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relational/relation.py b/relational/relation.py index 4524834..4523237 100644 --- a/relational/relation.py +++ b/relational/relation.py @@ -113,7 +113,7 @@ class Relation: format as defined in RFC4180. ''' import csv - with open(filename, 'w') as fp: + with open(filename, 'w', newline='\n') as fp: writer = csv.writer(fp) # Creating csv writer # It wants an iterable containing iterables From 482704be810fa5857f0d0986ae44849e33a452e8 Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Thu, 27 Aug 2020 22:05:29 +0200 Subject: [PATCH 4/4] Only show the tuple, not the full context --- relational/relation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relational/relation.py b/relational/relation.py index 4523237..1984ec7 100644 --- a/relational/relation.py +++ b/relational/relation.py @@ -193,7 +193,7 @@ class Relation: if eval(c_expr, attributes): content.append(i) except Exception as e: - raise Exception(f'Failed to evaluate {expr} with {attributes}\n{e}') + raise Exception(f'Failed to evaluate {expr} with {i}\n{e}') return Relation(self.header, frozenset(content)) def product(self, other: 'Relation') -> 'Relation':