def remove_constant(db_config, table): db = ArkDBMySQL(db_config_file=db_config) query = f'DELETE FROM {table} WHERE CELL_BSF_UNIFIED=%s' db.run_sql(query, ['0']) db.run_sql(query, ['1']) print(get_cell_cnt(db_config, table))
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()
def duplicate_table(db_config, new_table, source_table, copy_indexes_n_triggers=True): db = ArkDBMySQL(db_config_file=db_config) if db.is_table_exist(new_table): print(f'table {new_table} already exists') return if copy_indexes_n_triggers: query = f'CREATE TABLE {new_table} LIKE {source_table}' db.run_sql(query) if db.get_error(): exit(1) query = f'INSERT {new_table} SELECT * FROM {source_table}' db.run_sql(query) if db.get_error(): exit(1) else: query = f'CREATE TABLE {new_table} AS SELECT * FROM {source_table}' db.run_sql(query) if db.get_error(): exit(1)
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()
def remove_redundant_input(db_config, table): db = ArkDBMySQL(db_config_file=db_config) query = f'DELETE FROM {table} WHERE length(CELL_BSF) > length(CELL_BSF_UNIFIED)' db.run_sql(query) print(get_cell_cnt(db_config, table))