Rework getting database version (#469)

It seems we don't get the correct database version in some case with
some compilers, optimization flags. Suspecting some stale ->c_str().