Make sql query safe to another kind of error