diff options
author | Juan C. Sanz <jcsanz@libreoffice.org> | 2023-09-20 23:41:33 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-09-21 07:07:58 +0200 |
commit | fbf71a4c21106fbed7c070ba940809fd84c76dfe (patch) | |
tree | 2a33338adac33aab5c420b2a9dda81cee086cd42 /connectivity | |
parent | 7f69bca41c5034207ba9170420f6b3b214121a7b (diff) |
Revert "tdf#117118 - Saves data automatically in Firebird embedded database"
This reverts commit 9227fbabe0a33134f56aefdd8ec16024f006a659.
Reason for revert: This patch generate a new bug, so I revert it until further investigation
Change-Id: I4d613db8cef5363c6b276b8646147443871c312a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157116
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'connectivity')
4 files changed, 58 insertions, 53 deletions
diff --git a/connectivity/source/drivers/firebird/Connection.cxx b/connectivity/source/drivers/firebird/Connection.cxx index 4e2bce41267c..5b8cdb7b16d6 100644 --- a/connectivity/source/drivers/firebird/Connection.cxx +++ b/connectivity/source/drivers/firebird/Connection.cxx @@ -339,6 +339,11 @@ void Connection::construct(const OUString& url, const Sequence< PropertyValue >& } } +void Connection::notifyDatabaseModified() +{ + if (m_xParentDocument.is()) // Only true in embedded mode + m_xParentDocument->setModified(true); +} //----- XServiceInfo --------------------------------------------------------- IMPLEMENT_SERVICE_INFO(Connection, "com.sun.star.sdbc.drivers.firebird.Connection", @@ -817,7 +822,41 @@ void SAL_CALL Connection::documentEventOccured( const DocumentEvent& Event ) if ( !(m_bIsEmbedded && m_xEmbeddedStorage.is()) ) return; - storeDatabase(); + SAL_INFO("connectivity.firebird", "Writing .fbk from running db"); + try + { + runBackupService(isc_action_svc_backup); + } + catch (const SQLException& e) + { + auto a = cppu::getCaughtException(); + throw WrappedTargetRuntimeException(e.Message, e.Context, a); + } + + + Reference< XStream > xDBStream(m_xEmbeddedStorage->openStreamElement(our_sFBKLocation, + ElementModes::WRITE)); + + // TODO: verify the backup actually exists -- the backup service + // can fail without giving any sane error messages / telling us + // that it failed. + using namespace ::comphelper; + Reference< XComponentContext > xContext = comphelper::getProcessComponentContext(); + Reference< XInputStream > xInputStream; + if (!xContext.is()) + return; + + xInputStream = + OStorageHelper::GetInputStreamFromURL(m_sFBKPath, xContext); + if (xInputStream.is()) + OStorageHelper::CopyInputToOutput( xInputStream, + xDBStream->getOutputStream()); + + // remove old fdb file if exists + uno::Reference< ucb::XSimpleFileAccess > xFileAccess = + ucb::SimpleFileAccess::create(xContext); + if (xFileAccess->exists(m_sFirebirdURL)) + xFileAccess->kill(m_sFirebirdURL); } // XEventListener void SAL_CALL Connection::disposing(const EventObject& /*rSource*/) @@ -899,59 +938,13 @@ void Connection::disposing() evaluateStatusVector(status, u"isc_detach_database", *this); } } - - storeDatabase(); + // TODO: write to storage again? cppu::WeakComponentImplHelperBase::disposing(); m_pDatabaseFileDir.reset(); } -void Connection::storeDatabase() -{ - MutexGuard aGuard(m_aMutex); - - if (m_bIsEmbedded && m_xEmbeddedStorage.is()) - { - SAL_INFO("connectivity.firebird", "Writing .fbk from running db"); - try - { - runBackupService(isc_action_svc_backup); - } - catch (const SQLException& e) - { - auto a = cppu::getCaughtException(); - throw WrappedTargetRuntimeException(e.Message, e.Context, a); - } - - Reference<XStream> xDBStream( - m_xEmbeddedStorage->openStreamElement(our_sFBKLocation, ElementModes::WRITE)); - - using namespace ::comphelper; - Reference<XComponentContext> xContext = comphelper::getProcessComponentContext(); - Reference<XInputStream> xInputStream; - if (!xContext.is()) - return; - - xInputStream = OStorageHelper::GetInputStreamFromURL(m_sFBKPath, xContext); - if (xInputStream.is()) - OStorageHelper::CopyInputToOutput(xInputStream, xDBStream->getOutputStream()); - - // remove old fdb and fbk files if exist - uno::Reference<ucb::XSimpleFileAccess> xFileAccess - = ucb::SimpleFileAccess::create(xContext); - if (xFileAccess->exists(m_sFirebirdURL)) - xFileAccess->kill(m_sFirebirdURL); - - if (xFileAccess->exists(m_sFBKPath)) - xFileAccess->kill(m_sFBKPath); - - cppu::WeakComponentImplHelperBase::disposing(); - - m_pDatabaseFileDir.reset(); - } -} - void Connection::disposeStatements() { MutexGuard aGuard(m_aMutex); diff --git a/connectivity/source/drivers/firebird/Connection.hxx b/connectivity/source/drivers/firebird/Connection.hxx index 404f25860cb5..fa896439c9e7 100644 --- a/connectivity/source/drivers/firebird/Connection.hxx +++ b/connectivity/source/drivers/firebird/Connection.hxx @@ -171,6 +171,15 @@ namespace connectivity::firebird /// @throws css::sdbc::SQLException isc_tr_handle& getTransaction(); + /** + * Must be called anytime the underlying database is likely to have + * changed. + * + * This is used to notify the database document of any changes, so + * that the user is informed of any pending changes needing to be + * saved. + */ + void notifyDatabaseModified(); /** * Create a new Blob tied to this connection. Blobs are tied to a @@ -194,11 +203,6 @@ namespace connectivity::firebird css::uno::Reference< css::sdbcx::XTablesSupplier > createCatalog(); - /** - * Backup and store embedded extracted database to the .odb file - */ - void storeDatabase(); - // OComponentHelper virtual void SAL_CALL disposing() override; diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx index 35847d021ea0..608d05c274e0 100644 --- a/connectivity/source/drivers/firebird/PreparedStatement.cxx +++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx @@ -334,6 +334,9 @@ sal_Bool SAL_CALL OPreparedStatement::execute() m_aStatementHandle, m_pOutSqlda); + if (getStatementChangeCount() > 0) + m_pConnection->notifyDatabaseModified(); + return m_xResultSet.is(); // TODO: implement handling of multiple ResultSets. } diff --git a/connectivity/source/drivers/firebird/Statement.cxx b/connectivity/source/drivers/firebird/Statement.cxx index d135c4e4cda4..ed56b594a3d6 100644 --- a/connectivity/source/drivers/firebird/Statement.cxx +++ b/connectivity/source/drivers/firebird/Statement.cxx @@ -126,6 +126,11 @@ uno::Reference< XResultSet > SAL_CALL OStatement::executeQuery(const OUString& s if (isDDLStatement()) { m_pConnection->commit(); + m_pConnection->notifyDatabaseModified(); + } + else if (getStatementChangeCount() > 0) + { + m_pConnection->notifyDatabaseModified(); } return m_xResultSet; |