[qtcontacts-sqlite] Improve expansion of detail existence tests

Producing a 'where exists' clause results in a better query plan than
a contact ID lookup into a subselect.

Also, add functions to lookup DetailInfo and FieldInfo tables to
remove explicit loops where avoidable.