Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.9 kB
3
Indexable
# ... (existing 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=conn_source)
            if not source_df.empty:
                for _, source_row in source_df.iterrows():
                    columns = ', '.join(source_df.columns)
                    values = ', '.join([f"'{value}'" for value in source_row])

                    query_insert = f"INSERT INTO {schema_target}.{eprm_table_name} ({columns}) VALUES ({values})"
                    try:
                        print(query_insert)
                        cursor_target.execute(query_insert)
                        conn_target.commit()
                        query_info = f"-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ STATUS|{replicationTarget}| TABLE| {eprm_table_name}\n"
                        query_info += f"-- #Query: Inserted 1 record\n"
                        query_info += query_insert + ";\n"
                        write_sql(query_info)
                        print(f"Inserted 1 record into {eprm_table_name}")
                        logging.info(f"Inserted 1 record into {eprm_table_name}")
                    except mysql.connector.Error as err:
                        print(f"Error occurred while inserting records into {eprm_table_name}: {err}")
                        logging.info(f"Error occurred while inserting records into {eprm_table_name}: {err}")
        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}")

# ... (remaining code)