Fix crash during shutdown of LocalBCL #1035

The crash occurs because the LocalBCL singleton is destructed after the
QSqlite driver is unloaded but before QApplication has been destructed.

The primary solution is to make sure the QSQLITE driver is still loaded
before attempting to close / unregister the database.

Secondarily, we axe the local shared_ptr reference to the database, and
let the QSqlDatabase manage the connection, looking it up when
necessary. This is to avoid any problems with the destruction of
QSqlDatabase object during the cleanup of the singleton. We want to be
sure that all QSqlDatabase objects in play are valid and do not
reference any already closed databases.

Finally, we move to the more standard construct on first use idiom for
static data, moving the singleton instance to one that's owned by a
static function. This is more just for cleanup.