Fix error handling of INSERT and DELETE queries