Bug fixes to the database query* methods