Unify database version fetching.

Removing duplicate code for getting database version.

Change-Id: Id9db0be4dcc5a59b940cc5192a1cda9cde437728