fixing a severe bug in sql patch