diff --git a/miniDB/dashboard.py b/miniDB/dashboard.py index ee97b0a8..5a2c6f8b 100644 --- a/miniDB/dashboard.py +++ b/miniDB/dashboard.py @@ -13,3 +13,4 @@ if sys.argv[2]=='meta' and name[:4]!='meta': continue db.show_table(name) + diff --git a/miniDB/database.py b/miniDB/database.py index a3ac6be7..9809f1fb 100644 --- a/miniDB/database.py +++ b/miniDB/database.py @@ -358,7 +358,8 @@ def select(self, columns, table_name, condition, distinct=None, order_by=None, \ return table_name._select_where(columns, condition, distinct, order_by, desc, limit) if condition is not None: - condition_column = split_condition(condition)[0] + if((" between " not in condition) and ("not " not in condition)): + condition_column = split_condition(condition)[0] else: condition_column = '' @@ -745,4 +746,4 @@ def drop_index(self, index_name): warnings.warn(f'"{self.savedir}/indexes/meta_{index_name}_index.pkl" not found.') self.save_database() - \ No newline at end of file + \ No newline at end of file diff --git a/miniDB/misc.py b/miniDB/misc.py index aefada74..7bddc8b8 100644 --- a/miniDB/misc.py +++ b/miniDB/misc.py @@ -48,3 +48,18 @@ def reverse_op(op): '<=' : '>=', '=' : '=' }.get(op) + +def not_op(op): + ''' + Return opposite of the operator given + ''' + return { + '>' : '<=', + '>=' : '<', + '<' : '>=', + '<=' : '>', + '=' : '!=', + '!=' : '=' + }.get(op) + + diff --git a/miniDB/table.py b/miniDB/table.py index f5c7d937..fb8ec374 100644 --- a/miniDB/table.py +++ b/miniDB/table.py @@ -233,9 +233,20 @@ def _select_where(self, return_columns, condition=None, distinct=False, order_by # if condition is None, return all rows # if not, return the rows with values where condition is met for value if condition is not None: - column_name, operator, value = self._parse_condition(condition) - column = self.column_by_name(column_name) - rows = [ind for ind, x in enumerate(column) if get_op(operator, x, value)] + if((" between " not in condition) and ("not " not in condition)): + column_name, operator, value = self._parse_condition(condition) + column = self.column_by_name(column_name) + rows = [ind for ind, x in enumerate(column) if get_op(operator, x, value)] + elif(" between " in str(condition)): + + # filter + rows = [i for i in range(len(self.data))] + + elif("not " in str(condition)): + + # filter + rows = [i for i in range(len(self.data))] + else: rows = [i for i in range(len(self.data))] @@ -577,3 +588,4 @@ def _load_from_file(self, filename): f.close() self.__dict__.update(tmp_dict.__dict__) + \ No newline at end of file