diff options
-rw-r--r-- | sw/inc/dbmgr.hxx | 3 | ||||
-rw-r--r-- | sw/source/core/doc/docnew.cxx | 5 | ||||
-rw-r--r-- | sw/source/uibase/dbui/dbmgr.cxx | 10 |
3 files changed, 16 insertions, 2 deletions
diff --git a/sw/inc/dbmgr.hxx b/sw/inc/dbmgr.hxx index e397e5777373..657e957e1e68 100644 --- a/sw/inc/dbmgr.hxx +++ b/sw/inc/dbmgr.hxx @@ -376,6 +376,9 @@ public: /// Load the embedded data source of the document and also register it. void LoadAndRegisterEmbeddedDataSource(const SwDBData& rData, const SwDocShell& rDocShell); + /// Unregister a data source. + static void RevokeDataSource(const OUString& rName); + /** try to get the data source from the given connection through the XChild interface. If this is not possible, the data source will be created through its name. @param _xConnection diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx index ec44cb506d9b..302ebefd8b9e 100644 --- a/sw/source/core/doc/docnew.cxx +++ b/sw/source/core/doc/docnew.cxx @@ -540,6 +540,11 @@ SwDoc::~SwDoc() mpCharFormatTable->erase( mpCharFormatTable->begin() ); #if HAVE_FEATURE_DBCONNECTIVITY + // On load, SwDBManager::setEmbeddedName() may register a data source. + // If we have an embedded one, then sDataSoure points to the registered name, so revoke it here. + if (!mpDBManager->getEmbeddedName().isEmpty() && !maDBData.sDataSource.isEmpty()) + SwDBManager::RevokeDataSource(maDBData.sDataSource); + DELETEZ( mpDBManager ); #endif diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx index b138730f5c46..d59d78be73a4 100644 --- a/sw/source/uibase/dbui/dbmgr.cxx +++ b/sw/source/uibase/dbui/dbmgr.cxx @@ -2663,6 +2663,13 @@ OUString SwDBManager::LoadAndRegisterDataSource(const OUString &rURI, const OUSt return LoadAndRegisterDataSource( type, aURLAny, pSettings, rURI, pPrefix, pDestDir ); } +void SwDBManager::RevokeDataSource(const OUString& rName) +{ + uno::Reference<sdb::XDatabaseContext> xDatabaseContext = sdb::DatabaseContext::create(comphelper::getProcessComponentContext()); + if (xDatabaseContext->hasByName(rName)) + xDatabaseContext->revokeObject(rName); +} + void SwDBManager::LoadAndRegisterEmbeddedDataSource(const SwDBData& rData, const SwDocShell& rDocShell) { uno::Reference<sdb::XDatabaseContext> xDatabaseContext = sdb::DatabaseContext::create(comphelper::getProcessComponentContext()); @@ -2673,8 +2680,7 @@ void SwDBManager::LoadAndRegisterEmbeddedDataSource(const SwDBData& rData, const if (sDataSource.isEmpty()) sDataSource = "EmbeddedDatabase"; - if (xDatabaseContext->hasByName(rData.sDataSource)) - xDatabaseContext->revokeObject(rData.sDataSource); + SwDBManager::RevokeDataSource(rData.sDataSource); // Encode the stream name and the real path into a single URL. const INetURLObject& rURLObject = rDocShell.GetMedium()->GetURLObject(); |