def do_select(self, args): argList = str2List(args) if self.selectDB is not None: selectTablePath = DBMS.findTableAndRecordPath(self.selectDB ,argList)[0] if selectTablePath is not None: DBMS.selectRecords(selectTablePath, argList) else: print '[Select Error] The table does not exist. Plz try "use --help" or "use -h" to get help.' else: print '[Select Error] Choose the DB first. Plz try "use --help" or "use -h" to get help.'
def do_insert(self, args): argList = args.split() if self.authority == 'admin': if self.selectDB is not None: selectTablePath, selectRecordPath = DBMS.findTableAndRecordPath(self.selectDB ,argList) if selectTablePath is not None: if 'values' in argList: argList.remove('values') if DBMS.MatchTableSetting(selectTablePath, argList, 'insert'): DBMS.insertTable(selectTablePath, argList) else: print '[Insert Error] Choose the DB first. Plz try "use --help" or "use -h" to get help.' else: print '[Error] authority not enough.'
def do_delete(self, args): argList = str2List(args) if self.authority == 'admin': if self.selectDB is not None: selectTablePath, selectRecordPath = DBMS.findTableAndRecordPath(self.selectDB ,argList) if selectTablePath is not None: if selectRecordPath is not None: DBMS.deleteRecord(selectRecordPath) else: print '[Delete Error] The record does not exist. Plz try "use --help" or "use -h" to get help.' else: print '[Delete Error] The table does not exist. Plz try "use --help" or "use -h" to get help.' else: print '[Delete Error] Choose the DB first. Plz try "use --help" or "use -h" to get help.' else: print '[Error] authority not enough.'
def do_show(self, args): #show all DB/tables argList = str2List(args) if args == 'databases' or args == 'DATABASES': print "###################" for DB in os.listdir('./DB'): print DB print "###################" elif args == 'tables' or args == 'TABLES': print "###################" for table in os.listdir('./DB/default'): print table print "###################" elif argList[1] == 'columns' or argList[1] == 'COLUMNS': print "###################" if self.selectDB is not None: selectTablePath = DBMS.findTableAndRecordPath(self.selectDB, argList)[0] Column2IndexDict = DBMS.getAllColumn2IndexDict(selectTablePath) for column in Column2IndexDict.keys(): print column print "###################"