CRM-12333 and lots of formatting fixes

----------------------------------------
* CRM-12333: Unescaped items in upgrade SQL script
  http://issues.civicrm.org/jira/browse/CRM-12333