def add_row_to_table(database_name, table_name, row): #row like ['a','int'] if is_db_and_tb_both_exist(database_name, table_name) == False: return False table_info_path = get_table_info_txt_path(database_name, table_name) #print 'row',row row_obj = create_new_row_object(row) #print 'row_obj',row_obj if row_obj is None: #print 'Your input was wrong' return False else: row_name = row[0] if is_row_exist(database_name, table_name, row_name ) == True: print 'The row named %s has already exists!' % (row_name) return False row_info = '' for r in row: row_info += r + '\t' row_info += '\n' append_string_to_file(row_info,table_info_path) return True return False
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 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