示例#1
0
def create_bsf_table(input_cnt, db_config_file):
    db = ArkDBMySQL(db_config_file=db_config_file)

    # db.run_sql(f'DROP TABLE IF EXISTS BSF_LIB')
    create_table_sql = 'CREATE TABLE IF NOT EXISTS `CADisCMOS`.`BSF_LIB` (\
        `BSF` VARCHAR(256) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,\
        `BSF_UNI` VARCHAR(256) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL NOT NULL,\
        PRIMARY KEY (`BSF`))\
        ENGINE = InnoDB'

    # create the BSF_LIB table if it does not exist
    db.run_sql(create_table_sql)
    db.set_table('BSF_LIB')

    uni_bsf_dict = get_uni_dict(input_cnt, ['0', '1', 'o', 'i', 'Z', 'X', 'R', 'r'])

    for key in tqdm(uni_bsf_dict.keys(), desc='Insert into DB'):
        rec = dict()
        rec['BSF_UNI'] = key
        for bsf in uni_bsf_dict[key]:
            rec['BSF'] = bsf
            db.insert_nocommit(rec)
    db.commit()
        str_size_desc = ''
        area = 0
        for size in size_desc:
            str_size_desc += str(size)
            area += int(size)
        yield str_size_desc, area


if __name__ == '__main__':
    db_config = sys.argv[1]
    db = ArkDBMySQL(db_config_file=db_config)

    create_table_sql = 'CREATE TABLE IF NOT EXISTS `CADisCMOS`.`SIZE_LIB` (\
        `idSIZE_LIB` INT NOT NULL AUTO_INCREMENT,\
        `SIZE_DESC` VARCHAR(45) NOT NULL,\
        `TX_CNT` INT NOT NULL,\
        `SIZE_AREA` INT NULL,\
        PRIMARY KEY (`idSIZE_LIB`))\
        ENGINE = InnoDB'

    # create the SIZE_LIB table if it does not exist
    db.run_sql(create_table_sql)
    db.set_table('SIZE_LIB')

    for i in range(1, 8):
        rec = {'TX_CNT': i}
        for rec['SIZE_DESC'], rec['SIZE_AREA'] in gen_sizes(
                rec['TX_CNT'], [1, 2, 3, 4]):
            db.insert_nocommit(rec)
        db.commit()