Untitled
unknown
plain_text
2 years ago
1.8 kB
7
Indexable
# Initialize counters
insert_success_count = 0
insert_failed_count = 0
update_success_count = 0
update_failed_count = 0
# ... (previous code)
for index, source_row in source_df.iterrows():
pk_value = source_row[pk]
# Check if the primary key exists in the target DataFrame
if pk_value not in target_df[pk].values:
# ... (code for constructing the INSERT query)
# Execute the INSERT query
if insert_columns: # Check if there are columns to insert
try:
cursor_ext.execute(insert_query)
# connection_ext.commit()
insert_success_count += 1 # Increment insert success count
except Exception as e:
logging.error(
"Error - {} . Line No - {} ".format(str(e), str(sys.exc_info()[-1].tb_lineno)))
insert_failed_count += 1 # Increment insert failed count
else:
# ... (code for updating columns)
# Execute the UPDATE query
if columns_to_update: # Check if there are columns to update
try:
cursor_ext.execute(update_query)
# connection_ext.commit()
update_success_count += 1 # Increment update success count
except Exception as e:
logging.error(
"Error - {} . Line No - {} ".format(str(e), str(sys.exc_info()[-1].tb_lineno)))
update_failed_count += 1 # Increment update failed count
# Print the counts for inserts and updates
print(f"Successful inserts: {insert_success_count}")
print(f"Failed inserts: {insert_failed_count}")
print(f"Successful updates: {update_success_count}")
print(f"Failed updates: {update_failed_count}")
# ... (remaining code)
Editor is loading...