def drop_row(database_name, table_name, row_name): if is_db_and_tb_both_exist(database_name, table_name) == False: return False if is_row_exist(database_name, table_name, row_name ) == False: print 'The row named %s has not exists!' % (row_name) return False table_info_txt_path = get_table_info_txt_path(database_name, table_name) table_info_list = get_object_from_file_append_to_list(table_info_txt_path) after_drop_info = get_drop_row_string_from_infolist(table_info_list,row_name) write_to_file(after_drop_info, table_info_txt_path) return True
def secret_check(user,secret,secret_file = SECRET_FILE_PATH): user = str(user) secret = str(secret) records = get_object_from_file_append_to_list(secret_file) user_secret_dict = {} for record in records: user_secret_dict[record[0]] = record[1] try: if user_secret_dict[user] == secret: return True else: return False except: return False
def modify_row_from_table(database_name, table_name, row_name,new_type): if new_type not in ROW_TUPLE: return False if is_db_and_tb_both_exist(database_name, table_name) == False: return False if is_row_exist(database_name, table_name, row_name ) == False: print 'The row named %s has not exists!' % (row_name) return False table_info_txt_path = get_table_info_txt_path(database_name, table_name) table_info_list = get_object_from_file_append_to_list(table_info_txt_path) after_modified_info = get_modified_row_string_from_infolist(table_info_list, row_name , new_type) write_to_file(after_modified_info, table_info_txt_path) return True
def is_row_exist(dbname,table_name,row_name): table_info_path = get_table_info_txt_path(dbname,table_name) delete_blank_line_in_file(table_info_path) rows_info = get_object_from_file_append_to_list(table_info_path) #print 'in is_row_exist rows_info',rows_info for r in rows_info: #print 'in is_row_exist r',r if len(r) == 0: continue try: if r[0] == row_name: return True except: return False return False
def desc_table(database_name,table_name): if table_name is None: print 'Please input the table you want to check out!' return None if is_database_exist(database_name) == False: print 'The database named %s was not exists!' % (database_name) return None if is_table_exist(dbname = database_name,table_name = table_name) == False: print 'The table named %s was not exists!' % (table_name) return None info_path = get_table_info_txt_path(database_name,table_name) table_infomation = get_object_from_file_append_to_list(info_path) for info in table_infomation: print ' '.join(info) return table_infomation