[1.7.x] Fixed #23152 -- Added support for transactional Spatialite metadata initialization.

Thanks Doug Goldstein for the initial patch.

Backport of 57e40551e4 from master