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 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) diff --git a/relational/relation.py b/relational/relation.py index 4524834..1984ec7 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 @@ -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':