Added straighforward query generator

Don't know if it is correct. Cannot test it properly (also see email). I
think it is  correct approach.