def main():
DATABASE.load_contents()<EOL>continue_flag = False<EOL>while not continue_flag:<EOL><INDENT>DATABASE.print_contents()<EOL>try:<EOL><INDENT>command = input("<STR_LIT>")<EOL>for stmnt_unformated in sqlparse.parse(command):<EOL><INDENT>statement = sqlparse.parse(<EOL>sqlparse.format(<EOL>str(<EOL>stmnt_unformated<EOL>),<EOL>reindent=True<EOL>)<EOL>)[<NUM_LIT:0>]<EOL>type = statement.tokens[<NUM_LIT:0>]<EOL>if str(type).lower() == "<STR_LIT>":<EOL><INDENT>if str(statement.tokens[<NUM_LIT:2>]).lower() == "<STR_LIT>":<EOL><INDENT>tablename = str(statement.tokens[<NUM_LIT:4>])<EOL>table = DATABASE.get_table(tablename)<EOL>table.rows = []<EOL>table.store_contents()<EOL>DATABASE.delete_table(tablename)<EOL>DATABASE.store_contents()<EOL><DEDENT>else:<EOL><INDENT>raise Exception(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>elif str(type).lower() == "<STR_LIT>":<EOL><INDENT>if str(statement.tokens[<NUM_LIT:2>]).lower() == "<STR_LIT>":<EOL><INDENT>tablename = str(statement.tokens[<NUM_LIT:4>])<EOL>table = DATABASE.get_table(tablename)<EOL>table.rows = []<EOL>table.store_contents()<EOL><DEDENT>else:<EOL><INDENT>raise Exception(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>elif str(type).lower() == "<STR_LIT>":<EOL><INDENT>if str(statement.tokens[<NUM_LIT:2>]).lower() == "<STR_LIT>":<EOL><INDENT>tablename = str(statement.tokens[<NUM_LIT:4>])<EOL>table = DATABASE.get_table(tablename)<EOL>whereclause = statement.tokens[<NUM_LIT:6>]<EOL>if str(whereclause.tokens[<NUM_LIT:0>]).lower() == "<STR_LIT>":<EOL><INDENT>comparison = whereclause.tokens[<NUM_LIT:2>]<EOL>key = str(comparison.tokens[<NUM_LIT:0>])<EOL>value = int(str(comparison.tokens[<NUM_LIT:4>]))<EOL>table.delete_row(key, value)<EOL>table.store_contents()<EOL><DEDENT>else:<EOL><INDENT>raise Exception(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise Exception(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>elif str(type).lower() == "<STR_LIT>":<EOL><INDENT>if str(statement.tokens[<NUM_LIT:2>]).lower() == "<STR_LIT>":<EOL><INDENT>tablename = str(statement.tokens[<NUM_LIT:4>])<EOL>table = DATABASE.get_table(tablename)<EOL>if str(statement.tokens[<NUM_LIT:6>]).lower() == "<STR_LIT>":<EOL><INDENT>parenthesis = statement.tokens[<NUM_LIT:8>]<EOL>idlist = parenthesis.tokens[<NUM_LIT:1>]<EOL>values_list = [int(str(x)) for x in idlist.get_identifiers()]<EOL>table.put_row_raw(values_list)<EOL>table.store_contents()<EOL><DEDENT>else:<EOL><INDENT>raise Exception(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise Exception(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>elif str(type).lower() == "<STR_LIT>":<EOL><INDENT>if str(statement.tokens[<NUM_LIT:2>]).lower() == "<STR_LIT>":<EOL><INDENT>sublist = list(statement.tokens[<NUM_LIT:4>].get_sublists())<EOL>tablename = str(sublist[<NUM_LIT:0>])<EOL>garbage = str(sublist[<NUM_LIT:1>])<EOL>column_list = [x.strip("<STR_LIT>",).split()[<NUM_LIT:0>] for x in garbage.split("<STR_LIT:U+002C>")]<EOL>DATABASE.create_table_raw(<EOL>tablename=tablename,<EOL>columns=column_list[:],<EOL>)<EOL>DATABASE.store_contents()<EOL><DEDENT><DEDENT>elif str(type).lower() == "<STR_LIT>":<EOL><INDENT>col_list_or_single = statement.tokens[<NUM_LIT:2>]<EOL>if "<STR_LIT:U+002C>" not in str(col_list_or_single):<EOL><INDENT>if str(col_list_or_single) == "<STR_LIT:*>":<EOL><INDENT>column_list = ['<STR_LIT:*>']<EOL><DEDENT>else:<EOL><INDENT>column_list = [str(col_list_or_single)]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>column_list = [str(x) for x in col_list_or_single.get_identifiers()]<EOL><DEDENT>if str(statement.tokens[<NUM_LIT:4>]).lower() == "<STR_LIT>":<EOL><INDENT>tab_list_or_single = statement.tokens[<NUM_LIT:6>]<EOL>if "<STR_LIT:U+002C>" not in str(tab_list_or_single):<EOL><INDENT>table_list = [str(tab_list_or_single)]<EOL><DEDENT>else:<EOL><INDENT>table_list = [str(x) for x in tab_list_or_single.get_identifiers()]<EOL><DEDENT>cross_columns = reduce(<EOL>lambda x, y: x + y,<EOL>[DATABASE.get_table(<EOL>x<EOL>).get_column_list_prefixed() for x in table_list]<EOL>)<EOL>cross_table = parthsql.Table(<EOL>name="<STR_LIT>",<EOL>columns=cross_columns,<EOL>rows=[]<EOL>)<EOL>for i in itertools.product(<EOL>*[DATABASE.get_table(x).get_all_rows() for x in table_list]<EOL>):<EOL><INDENT>cross_table.put_row_raw(<EOL>reduce(<EOL>lambda x, y: x + y,<EOL>i<EOL>)<EOL>)<EOL><DEDENT>if len(statement.tokens) >= <NUM_LIT:9>:<EOL><INDENT>whereclause = statement.tokens[<NUM_LIT:8>]<EOL>if str(whereclause.tokens[<NUM_LIT:0>]).lower() == "<STR_LIT>":<EOL><INDENT>comparison = whereclause.tokens[<NUM_LIT:2>]<EOL>key = str(comparison.tokens[<NUM_LIT:0>])<EOL>try:<EOL><INDENT>value = int(str(comparison.tokens[<NUM_LIT:4>]))<EOL>cross_table.invert_delete_row(key, value)<EOL><DEDENT>except:<EOL><INDENT>value = str(comparison.tokens[<NUM_LIT:4>])<EOL>cross_table.invert_delete_row2(key, value)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise Exception(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>if "<STR_LIT:*>" in column_list:<EOL><INDENT>cross_table.print_contents()<EOL><DEDENT>else:<EOL><INDENT>temp_list = []<EOL>for i in column_list:<EOL><INDENT>temp_list.append(cross_table.get_column(i))<EOL><DEDENT>print("<STR_LIT>".join(column_list))<EOL>for i in zip(*(temp_list)):<EOL><INDENT>print("<STR_LIT>".join(map(str, i)))<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raise Exception(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise Exception(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT><DEDENT>except ValueError:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>except IOError:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>except IndexError:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>except AttributeError:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>except Exception as e:<EOL><INDENT>print(e.message)<EOL><DEDENT><DEDENT>
The main loop for the commandline parser.