Beispiel #1
0
def show_databases():
    databases = get_object_from_file_extend_to_list(DATABASE_FILE_PATH)
    print 'All databases:'
    for db in databases:
        print db
    print '' 
    
    return databases
Beispiel #2
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 #3
0
def drop_database(database_name):
    if not object_in_file_list(obj = database_name , file_path = DATABASE_FILE_PATH):
        print 'The database had not exists!'
        return False
    
    database_path = get_database_path(database_name)
    
    try:
        shutil.rmtree(database_path)
    except:
        #print 'Drop error!'
        return False
    
    databases = get_object_from_file_extend_to_list(DATABASE_FILE_PATH)
    after_drop_databases = [db for db in databases if db != database_name]
    databases = '\n'.join(after_drop_databases)
    write_to_file(string = databases,file_path = DATABASE_FILE_PATH)
    if default_variable.CURRENT_DB == database_name:
        default_variable.CURRENT_DB = None
    return True
Beispiel #4
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