The error you 're getting is caused by duplicates on the wtmxg_sobipro_field_data table when adding option rows.
There is code to handle this which, I think, is what you have changed.
However, I could not see what was wrong with the original code.