summaryrefslogtreecommitdiffstats
path: root/connectivity/source/drivers/firebird/Connection.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'connectivity/source/drivers/firebird/Connection.cxx')
-rw-r--r--connectivity/source/drivers/firebird/Connection.cxx122
1 files changed, 54 insertions, 68 deletions
diff --git a/connectivity/source/drivers/firebird/Connection.cxx b/connectivity/source/drivers/firebird/Connection.cxx
index 64a8495bfc3c..5a2be8872485 100644
--- a/connectivity/source/drivers/firebird/Connection.cxx
+++ b/connectivity/source/drivers/firebird/Connection.cxx
@@ -72,11 +72,11 @@ using namespace ::com::sun::star::uno;
* Location within the .odb that an embedded .fdb will be stored.
* Only relevant for embedded dbs.
*/
-constexpr OUStringLiteral our_sFDBLocation( u"firebird.fdb" );
+constexpr OUString our_sFDBLocation( u"firebird.fdb"_ustr );
/**
* Older version of LO may store the database in a .fdb file
*/
-constexpr OUStringLiteral our_sFBKLocation( u"firebird.fbk" );
+constexpr OUString our_sFBKLocation( u"firebird.fbk"_ustr );
Connection::Connection()
: Connection_BASE(m_aMutex)
@@ -161,7 +161,7 @@ void Connection::construct(const OUString& url, const Sequence< PropertyValue >&
bIsNewDatabase = !m_xEmbeddedStorage->hasElements();
- m_pDatabaseFileDir.reset(new ::utl::TempFile(nullptr, true));
+ m_pDatabaseFileDir.reset(new ::utl::TempFileNamed(nullptr, true));
m_pDatabaseFileDir->EnableKillingFile();
m_sFirebirdURL = m_pDatabaseFileDir->GetFileName() + "/firebird.fdb";
m_sFBKPath = m_pDatabaseFileDir->GetFileName() + "/firebird.fbk";
@@ -196,7 +196,7 @@ void Connection::construct(const OUString& url, const Sequence< PropertyValue >&
// External file AND/OR remote connection
else if (url.startsWith("sdbc:firebird:"))
{
- m_sFirebirdURL = url.copy(OUString("sdbc:firebird:").getLength());
+ m_sFirebirdURL = url.copy(strlen("sdbc:firebird:"));
if (m_sFirebirdURL.startsWith("file://"))
{
m_bIsFile = true;
@@ -233,8 +233,8 @@ void Connection::construct(const OUString& url, const Sequence< PropertyValue >&
if (m_bIsEmbedded || m_bIsFile)
{
- userName = "sysdba";
- userPassword = "masterkey";
+ userName = "sysdba"_ostr;
+ userPassword = "masterkey"_ostr;
}
else
{
@@ -339,12 +339,6 @@ 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",
"com.sun.star.sdbc.Connection")
@@ -358,7 +352,7 @@ Reference< XBlob> Connection::createBlob(ISC_QUAD const * pBlobId)
&m_aTransactionHandle,
*pBlobId);
- m_aStatements.push_back(WeakReferenceHelper(xReturn));
+ m_aStatements.emplace_back(xReturn);
return xReturn;
}
@@ -371,7 +365,7 @@ Reference< XClob> Connection::createClob(ISC_QUAD const * pBlobId)
&m_aTransactionHandle,
*pBlobId);
- m_aStatements.push_back(WeakReferenceHelper(xReturn));
+ m_aStatements.emplace_back(xReturn);
return xReturn;
}
@@ -383,7 +377,7 @@ sal_Int64 SAL_CALL Connection::getSomething(const css::uno::Sequence<sal_Int8>&
}
// static
-css::uno::Sequence<sal_Int8> Connection::getUnoTunnelId()
+const css::uno::Sequence<sal_Int8> & Connection::getUnoTunnelId()
{
static const comphelper::UnoIdInit implId;
return implId.getSeq();
@@ -402,7 +396,7 @@ Reference< XStatement > SAL_CALL Connection::createStatement( )
// create a statement
// the statement can only be executed once
Reference< XStatement > xReturn = new OStatement(this);
- m_aStatements.push_back(WeakReferenceHelper(xReturn));
+ m_aStatements.emplace_back(xReturn);
return xReturn;
}
@@ -418,7 +412,7 @@ Reference< XPreparedStatement > SAL_CALL Connection::prepareStatement(
buildTypeInfo();
Reference< XPreparedStatement > xReturn = new OPreparedStatement(this, _sSql);
- m_aStatements.push_back(WeakReferenceHelper(xReturn));
+ m_aStatements.emplace_back(xReturn);
return xReturn;
}
@@ -440,7 +434,6 @@ Reference< XPreparedStatement > SAL_CALL Connection::prepareCall(
OUString SAL_CALL Connection::nativeSQL( const OUString& _sSql )
{
- MutexGuard aGuard( m_aMutex );
// We do not need to adapt the SQL for Firebird atm.
return _sSql;
}
@@ -629,22 +622,18 @@ void Connection::runBackupService(const short nAction)
OString sFBKPath = OUStringToOString(m_sFBKPath, RTL_TEXTENCODING_UTF8);
- OStringBuffer aRequest; // byte array
-
-
- aRequest.append(static_cast<char>(nAction));
-
- aRequest.append(char(isc_spb_dbname)); // .fdb
sal_uInt16 nFDBLength = sFDBPath.getLength();
- aRequest.append(static_cast<char>(nFDBLength & 0xFF)); // least significant byte first
- aRequest.append(static_cast<char>((nFDBLength >> 8) & 0xFF));
- aRequest.append(sFDBPath);
-
- aRequest.append(char(isc_spb_bkp_file)); // .fbk
sal_uInt16 nFBKLength = sFBKPath.getLength();
- aRequest.append(static_cast<char>(nFBKLength & 0xFF));
- aRequest.append(static_cast<char>((nFBKLength >> 8) & 0xFF));
- aRequest.append(sFBKPath);
+ OStringBuffer aRequest( // byte array
+ OStringChar(static_cast<char>(nAction))
+ + OStringChar(char(isc_spb_dbname)) // .fdb
+ + OStringChar(static_cast<char>(nFDBLength & 0xFF)) // least significant byte first
+ + OStringChar(static_cast<char>((nFDBLength >> 8) & 0xFF))
+ + sFDBPath
+ + OStringChar(char(isc_spb_bkp_file)) // .fbk
+ + OStringChar(static_cast<char>(nFBKLength & 0xFF))
+ + OStringChar(static_cast<char>((nFBKLength >> 8) & 0xFF))
+ + sFBKPath);
if (nAction == isc_action_svc_restore)
{
@@ -827,42 +816,9 @@ void SAL_CALL Connection::documentEventOccured( const DocumentEvent& Event )
if ( !(m_bIsEmbedded && m_xEmbeddedStorage.is()) )
return;
- 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);
+ storeDatabase();
}
+
// XEventListener
void SAL_CALL Connection::disposing(const EventObject& /*rSource*/)
{
@@ -943,13 +899,43 @@ void Connection::disposing()
evaluateStatusVector(status, u"isc_detach_database", *this);
}
}
- // TODO: write to storage again?
+
+ storeDatabase();
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());
+ }
+}
+
+
void Connection::disposeStatements()
{
MutexGuard aGuard(m_aMutex);