Fix query preparation & type warnings in tests