Fix elisp warning.

Use #'(lambda .. instead of '(lambda ..
Remove useless code.
Add functions to build sql queries.