def runCommand(cmd): cmd.lower() cmds = cmd.split() if cmds[0] == "exit" or cmds[0] == "quit": return True elif cmds[0] == "help": print usage elif cmds[0] == "factory": cmds = [ "create table t1 (id int, name string, val int)", "create index i1 on t1 (id)", "insert into t1 values (3, s, 5)", "insert into t1 values (2, o, 6)", "insert into t1 values (1, e, 7)", "insert into t1 values (5, d, 3)", "insert into t1 values (4, i, 4)", "select * from t1", ] for c in cmds: print "> " + c queryproc.processQuery(c) elif cmds[0] == "save": queryproc.saveTables(cmds[1]) elif cmds[0] == "load": queryproc.loadTables(cmds[1]) else: raise DBCommandNotFound()
def runInterpreter(): print "Loading interpreter ..." print "Type .help for usage" while True: try: input = raw_input("> ") if input[0] == ".": # '.' -prefix means command if runCommand(input[1:]): break elif input[0] == "#": pass # '#' -prefix means comment else: # process sql queryproc.processQuery(input) except DBError as e: print str(e)