Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.5 kB
3
Indexable
Never
# ... (previous code)

for _, row in df.iterrows():
    eprm_table_name = row['eprm_table_name']
    if eprm_table_name != 'PKG_PRD_FED_EXT_ATTRS':
        source_query = f"SELECT * FROM {schema_source}.{eprm_table_name} WHERE release_id='{releaseId}' AND op_id='{opId}' AND bu_id='{buId}'"
        try:
            source_df = pd_read_sql(source_query, con=engine_source)
            if not source_df.empty:
                # Convert the table name to lowercase
                eprm_table_name_lower = eprm_table_name.lower()
                
                target_table = f"{schema_target}.{eprm_table_name_lower}"
                source_df.to_sql(name=target_table, con=engine_target, if_exists='append', index=False)
                num_records = len(source_df)
                query_info = f"-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ STATUS|{replicationTarget}| TABLE| {eprm_table_name}\n"
                query_info += f"-- #Query: Inserted {num_records} records into {target_table}\n"
                write_sql(query_info)
                print(f"Inserted {num_records} records into {target_table}")
                logging.info(f"Inserted {num_records} records into {target_table}")
        except mysql.connector.Error as err:
            print(f"Error occurred while executing the query: {source_query}: {err}")
            logging.info(f"Error occurred while executing the query: {source_query}: {err}")

# ... (rest of the code)