Before you go to the restaurant (such as when you leave your home in the car) explain to him how you expect him to behave at the restaurant and when you all leave the restaurant (such as: "Mikey you need to hold grandma's hand before we go out the restaurant's door, so that you are safe and no cars hit you"). Tell him that if he does what you request, he gets a sticker or a small treat when you return home. If he does not do what you tell him, he gets a 3 minute "time-out" on the chair located in a boring corner when he gets home. Remind him again as the meal is ending what you expect him to do as he leaves the restaurant. When you get to the door, tell him to give you his little hand. Reward him when he gets home if he does well. It is all about managing expections, making sure he is listening and rewarding him if he does well. This is assuming he is a normal child.
You are focusing on the wrong end of the problem. You are thinking of how to respond when the horse has already left the barn. Do not permit him to walk by himself. You've learned what will happen if you defer to his request. Hold his hand.