Refactoring of cake_query.erl

Hi Peter,

I have done some refactoring on cake_query.erl.
I haven't created a confluence page; I did not feel there was much to say on it. 

I noticed that most of the code was duplicated in several functions. I found a way to simulate C function pointers and managed to refactor a good amount of code.

The code has been tested using the Java, Erlang and C drivers.

Cheers,
Gary