Beispiel #1
0
def show_tables(database_name):
    if database_name is None:
        print 'Not database used, use a database fisrt!'
        return None
    
    if is_database_exist(database_name) == False:
        print 'The database named %s was not exists!' % (database_name)
        return None
    
    table_infomath_file_path = get_all_table_name_info_txt_path(database_name)
    tables = get_object_from_file_extend_to_list(table_infomath_file_path)
    print 'All tables:'
    for tb in tables:
        print tb
    print '' 
    
    return tables
Beispiel #2
0
def drop_table(database_name,table_name):
    if is_table_exist(database_name,table_name) == False:
        print 'The table has not exists!'
        return False
    
    table_info_path = get_table_info_txt_path(database_name,table_name)
    table_data_path = get_table_data_file_path(database_name,table_name)
    all_tables_info_path = get_all_table_name_info_txt_path(database_name)
    
    try:
        os.remove(table_info_path)
        os.remove(table_data_path)
    except:
        #print 'Drop error!'
        return False
        
    tables = get_object_from_file_extend_to_list(all_tables_info_path)
    after_drop_tables = [tb for tb in tables if tb != table_name]
    tables = '\n'.join(after_drop_tables)
    write_to_file(string = tables,file_path = all_tables_info_path)
    
    return True
Beispiel #3
0
def is_table_exist(dbname,table_name):
    table_infomath_file_path = get_all_table_name_info_txt_path(dbname)
    if object_in_file_list(obj = table_name, file_path = table_infomath_file_path):
        return True
    return False