More unit tests and fix an issue with duplicate results in SQLDatabase.