First version of the database query script