add error checking to sql queries