Altering add_to_cart_form_submit() and random PDOException while adding to cart
When you call commerce_product_line_item_new, drupal is trying to insert an already existant record to the table field_data_commerce_unit_price which has it's primary key defined as :


  PRIMARY KEY (entity_type,entity_id,deleted,delta,language),


Since the product already exists, it fails with a constraint violation error :


  Integrity constraint violation: 1062 Duplicate entry


What you are trying to do could be accomplished by adding a new cost item to the current order based on the attributes you mention, not by modifying the current item price which I guess is what you are trying to do.

So IMHO, you may try to have a base price for your item (or even a 0 price) and once the customer adds it to cart, add another cost item with the charges calculated based on the attributes he sets.