diff options
-rw-r--r-- | sw/inc/dbmgr.hxx | 7 | ||||
-rw-r--r-- | sw/inc/swdbdata.hxx | 6 | ||||
-rw-r--r-- | sw/source/core/doc/doc.cxx | 9 | ||||
-rw-r--r-- | sw/source/core/doc/docfmt.cxx | 1 | ||||
-rw-r--r-- | sw/source/uibase/dbui/dbmgr.cxx | 29 | ||||
-rw-r--r-- | sw/source/uibase/uno/SwXDocumentSettings.cxx | 10 |
6 files changed, 41 insertions, 21 deletions
diff --git a/sw/inc/dbmgr.hxx b/sw/inc/dbmgr.hxx index 27c86a7268f0..e397e5777373 100644 --- a/sw/inc/dbmgr.hxx +++ b/sw/inc/dbmgr.hxx @@ -199,6 +199,8 @@ friend class SwConnectionDisposedListener_Impl; SwDSParamArr aDataSourceParams; SwDBManager_Impl* pImpl; const SwXMailMerge* pMergeEvtSrc; ///< != 0 if mail merge events are to be send + /// Name of the embedded database that's included in the current document. + OUString m_sEmbeddedName; SAL_DLLPRIVATE SwDSParam* FindDSData(const SwDBData& rData, bool bCreate); SAL_DLLPRIVATE SwDSParam* FindDSConnection(const OUString& rSource, bool bCreate); @@ -372,7 +374,7 @@ public: const ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySet > *pSettings = 0); /// Load the embedded data source of the document and also register it. - static void LoadAndRegisterEmbeddedDataSource(const SwDBData& rData, const SwDocShell& rDocShell); + void LoadAndRegisterEmbeddedDataSource(const SwDBData& rData, const SwDocShell& rDocShell); /** 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. @@ -405,6 +407,9 @@ public: sal_Int32 _nCommandType, const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection ); + + void setEmbeddedName(const OUString& rEmbeddedName, SwDocShell& rDocShell); + OUString getEmbeddedName() const; }; #endif diff --git a/sw/inc/swdbdata.hxx b/sw/inc/swdbdata.hxx index 02ccf6807815..6d91e2b85558 100644 --- a/sw/inc/swdbdata.hxx +++ b/sw/inc/swdbdata.hxx @@ -28,16 +28,14 @@ struct SwDBData OUString sDataSource; OUString sCommand; //table, query or statement sal_Int32 nCommandType; //com::sun::star::sdb::CommandType - /// Name of the embedded database that's included in the current document. - OUString sEmbeddedName; SwDBData() : nCommandType(0){} void dumpAsXml(struct _xmlTextWriter* pWriter) const; bool operator !=(const SwDBData& rCmp) const - {return rCmp.sDataSource != sDataSource || rCmp.sCommand != sCommand || rCmp.nCommandType != nCommandType || rCmp.sEmbeddedName != sEmbeddedName;} + {return rCmp.sDataSource != sDataSource || rCmp.sCommand != sCommand || rCmp.nCommandType != nCommandType;} bool operator ==(const SwDBData& rCmp) const - {return rCmp.sDataSource == sDataSource && rCmp.sCommand == sCommand && rCmp.nCommandType == nCommandType && rCmp.sEmbeddedName == sEmbeddedName;} + {return rCmp.sDataSource == sDataSource && rCmp.sCommand == sCommand && rCmp.nCommandType == nCommandType;} }; #endif diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx index b427c93430f9..fb43e0c78b25 100644 --- a/sw/source/core/doc/doc.cxx +++ b/sw/source/core/doc/doc.cxx @@ -494,15 +494,6 @@ void SwDoc::ChgDBData(const SwDBData& rNewData) { if( rNewData != maDBData ) { - if (maDBData.sEmbeddedName != rNewData.sEmbeddedName && GetDocShell()) - { - uno::Reference<embed::XStorage> xStorage = GetDocShell()->GetStorage(); - // It's OK that we don't have the named sub-storage yet, in case - // we're in the process of creating it. - if (xStorage->hasByName(rNewData.sEmbeddedName)) - SwDBManager::LoadAndRegisterEmbeddedDataSource(rNewData, *GetDocShell()); - } - maDBData = rNewData; getIDocumentState().SetModified(); } diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx index bb1ea8717ee7..4acd8e885bf6 100644 --- a/sw/source/core/doc/docfmt.cxx +++ b/sw/source/core/doc/docfmt.cxx @@ -1958,7 +1958,6 @@ void SwDBData::dumpAsXml(xmlTextWriterPtr pWriter) const xmlTextWriterWriteAttribute(pWriter, BAD_CAST("sDataSource"), BAD_CAST(sDataSource.toUtf8().getStr())); xmlTextWriterWriteAttribute(pWriter, BAD_CAST("sCommand"), BAD_CAST(sCommand.toUtf8().getStr())); xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nCommandType"), BAD_CAST(OString::number(nCommandType).getStr())); - xmlTextWriterWriteAttribute(pWriter, BAD_CAST("sEmbeddedName"), BAD_CAST(sEmbeddedName.toUtf8().getStr())); xmlTextWriterEndElement(pWriter); } diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx index fd57164a5993..b138730f5c46 100644 --- a/sw/source/uibase/dbui/dbmgr.cxx +++ b/sw/source/uibase/dbui/dbmgr.cxx @@ -2667,6 +2667,12 @@ void SwDBManager::LoadAndRegisterEmbeddedDataSource(const SwDBData& rData, const { uno::Reference<sdb::XDatabaseContext> xDatabaseContext = sdb::DatabaseContext::create(comphelper::getProcessComponentContext()); + OUString sDataSource = rData.sDataSource; + + // Fallback, just in case the document would contain an embedded data source, but no DB fields. + if (sDataSource.isEmpty()) + sDataSource = "EmbeddedDatabase"; + if (xDatabaseContext->hasByName(rData.sDataSource)) xDatabaseContext->revokeObject(rData.sDataSource); @@ -2674,7 +2680,7 @@ void SwDBManager::LoadAndRegisterEmbeddedDataSource(const SwDBData& rData, const const INetURLObject& rURLObject = rDocShell.GetMedium()->GetURLObject(); OUString aURL = "vnd.sun.star.pkg://"; aURL += INetURLObject::encode(rURLObject.GetMainURL(INetURLObject::DECODE_WITH_CHARSET), INetURLObject::PART_AUTHORITY, INetURLObject::ENCODE_ALL); - aURL += "/" + INetURLObject::encode(rData.sEmbeddedName, INetURLObject::PART_FPATH, INetURLObject::ENCODE_ALL); + aURL += "/" + INetURLObject::encode(m_sEmbeddedName, INetURLObject::PART_FPATH, INetURLObject::ENCODE_ALL); uno::Reference<uno::XInterface> xDataSource(xDatabaseContext->getByName(aURL), uno::UNO_QUERY); xDatabaseContext->registerObject(rData.sDataSource, xDataSource); @@ -2966,6 +2972,27 @@ uno::Reference<XResultSet> SwDBManager::createCursor(const OUString& _sDataSourc return xResultSet; } +void SwDBManager::setEmbeddedName(const OUString& rEmbeddedName, SwDocShell& rDocShell) +{ + bool bLoad = m_sEmbeddedName != rEmbeddedName && !rEmbeddedName.isEmpty(); + + m_sEmbeddedName = rEmbeddedName; + + if (bLoad) + { + uno::Reference<embed::XStorage> xStorage = rDocShell.GetStorage(); + // It's OK that we don't have the named sub-storage yet, in case + // we're in the process of creating it. + if (xStorage->hasByName(rEmbeddedName)) + LoadAndRegisterEmbeddedDataSource(rDocShell.GetDoc()->GetDBData(), rDocShell); + } +} + +OUString SwDBManager::getEmbeddedName() const +{ + return m_sEmbeddedName; +} + SwConnectionDisposedListener_Impl::SwConnectionDisposedListener_Impl(SwDBManager& rManager) : m_pDBManager(&rManager) { diff --git a/sw/source/uibase/uno/SwXDocumentSettings.cxx b/sw/source/uibase/uno/SwXDocumentSettings.cxx index 7d513d4767f5..78ad21e2b3f0 100644 --- a/sw/source/uibase/uno/SwXDocumentSettings.cxx +++ b/sw/source/uibase/uno/SwXDocumentSettings.cxx @@ -46,6 +46,7 @@ #include "swmodule.hxx" #include "cfgitems.hxx" #include "prtopt.hxx" +#include "dbmgr.hxx" using namespace comphelper; using namespace ::com::sun::star; @@ -508,9 +509,9 @@ void SwXDocumentSettings::_setSingleValue( const comphelper::PropertyInfo & rInf break; case HANDLE_EMBEDDED_DATABASE_NAME: { - SwDBData aData = mpDoc->GetDBData(); - if (rValue >>= aData.sEmbeddedName) - mpDoc->ChgDBData(aData); + OUString sEmbeddedName; + if (rValue >>= sEmbeddedName) + mpDoc->GetDBManager()->setEmbeddedName(sEmbeddedName, *mpDocSh); } break; case HANDLE_SAVE_VERSION_ON_CLOSE: @@ -988,8 +989,7 @@ void SwXDocumentSettings::_getSingleValue( const comphelper::PropertyInfo & rInf break; case HANDLE_EMBEDDED_DATABASE_NAME: { - const SwDBData& rData = mpDoc->GetDBDesc(); - rValue <<= rData.sEmbeddedName; + rValue <<= mpDoc->GetDBManager()->getEmbeddedName(); } break; case HANDLE_SAVE_VERSION_ON_CLOSE: |