Пример #1
0
def create_table(database_name,table_name,rows):
       
    if is_database_exist(database_name) == False:
        print 'The database named %s was not exists!' % (database_name)
        return False
    
    if is_table_exist(dbname = database_name,table_name = table_name) == True:
        print 'The table named %s has already exists!' % (table_name)
        return False
    
    if whether_can_new_table_object(table_name,rows) == False:
        #print r' Your input was wrong.'
        return False
    
    database_path = get_data_base_path(database_name)
    table_name_append_suffix = table_name + TABLE_INFO_FILE_SUFFIX
    table_info = ''
    
    for row in rows:
        table_info += '\t'.join(row)
        table_info += '\n'
    write_to_file(string = table_info,file_path = r'%s\%s' % (database_path ,table_name_append_suffix))
    write_to_file(string = '',file_path = r'%s\%s%s' % (database_path ,table_name,TABLE_DATA_FILE_SUFFIX))

    append_string_to_file(string = table_name + '\n', file_path = r'%s\%s' % (database_path,TABLES_NAME_FILE))
    #print 'Table created successful!'
    return True
Пример #2
0
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
Пример #3
0
def create_database(database_name,databases_file_path = DATABASE_FILE_PATH):
    
    if is_database_exist(database_name) == True:
        print 'The database named %s was already exists!' % (database_name)
        return False

    new_database_path = get_data_base_path(database_name)
    
    try:
        os.mkdir(new_database_path)
    except:
        #print 'can not built the database!'
        return False    
    
    write_to_file(string = '',file_path = r'%s\%s' % (new_database_path,TABLES_NAME_FILE))    
    append_string_to_file(string = database_name + '\n', file_path = databases_file_path)
        
    return True