/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// disallow any database/script files that contain a "SCRIPT[.*]" entry (this is belt and braces // in that bundled hsqldb 1.8.0 is patched to also reject them) // // hsqldb 2.6.0 release notes have: added system role SCRIPT_OPS for export / import of database structure and data // which seems to provide a builtin way to do this with contemporary hsqldb static constexpr OUString sScript(u"script"_ustr); if (!bIsNewDatabase && xStorage->isStreamElement(sScript))
{
Reference<XStream > xStream = xStorage->openStreamElement(sScript, ElementModes::READ); if (xStream.is())
{
std::unique_ptr<SvStream> pStream(::utl::UcbStreamHelper::CreateStream(xStream)); if (pStream)
{
OStringBuffer sLine; while (pStream->ReadLine(sLine))
{
OString sText = sLine.makeStringAndClear().trim(); if (sText.startsWithIgnoreAsciiCase("SCRIPT"))
{
::connectivity::SharedResources aResources;
sMessage = aResources.getResourceString(STR_COULD_NOT_LOAD_FILE).replaceFirst("$filename$", sSystemPath); break;
}
}
}
} // if ( xStream.is() )
::comphelper::disposeComponent(xStream);
}
// if the storage is completely empty, then we just created a new HSQLDB // In this case, do some initializations. if ( bIsNewDatabase && xOrig.is() )
onConnectedNewDatabase( xOrig );
if ( xOrig.is() )
{ // now we have to set the URL to get the correct answer for metadata()->getURL() auto pMetaConnection = comphelper::getFromUnoTunnel<OMetaConnection>(xOrig); if ( pMetaConnection )
pMetaConnection->setURL(url);
Reference<XComponent> xComp(xOrig,UNO_QUERY); if ( xComp.is() )
xComp->addEventListener(this);
// we want to close all connections when the office shuts down static rtl::Reference< OConnectionController > s_xTerminateListener = [&]()
{
Reference< XDesktop2 > xDesktop = Desktop::create( m_xContext );
Sequence< DriverPropertyInfo > SAL_CALL ODriverDelegator::getPropertyInfo( const OUString& url, const Sequence< PropertyValue >& /*info*/ )
{ if ( !acceptsURL(url) ) return Sequence< DriverPropertyInfo >(); return
{
{
u"Storage"_ustr,
u"Defines the storage where the database will be stored."_ustr, true,
{},
{}
},
{
u"URL"_ustr,
u"Defines the url of the data source."_ustr, true,
{},
{}
},
{
u"AutoRetrievingStatement"_ustr,
u"Defines the statement which will be executed to retrieve auto increment values."_ustr, false,
u"CALL IDENTITY()"_ustr,
{}
}
};
}
if ( _xConnection.is() )
{
Reference<XStatement> xStmt = _xConnection->createStatement(); if ( xStmt.is() )
{
Reference<XResultSet> xRes = xStmt->executeQuery(u"SELECT COUNT(*) FROM INFORMATION_SCHEMA.SYSTEM_SESSIONS WHERE USER_NAME ='SA'"_ustr);
Reference<XRow> xRow(xRes,UNO_QUERY); if ( xRow.is() && xRes->next() )
bLastOne = xRow->getInt(1) == 1; if ( bLastOne )
{ // during shutdown, we are running on the main thread, and if we call this, // it might trigger dbaccess::DocumentEventNotifier_Impl::impl_notifyEvent_nothrow // which is running on a different thread, and that will call other code that tries // to take the solar mutex.
SolarMutexReleaser aReleaser;
xStmt->execute(u"SHUTDOWN"_ustr);
}
}
}
} catch(Exception&)
{
} if ( bLastOne )
{ // Reference<XTransactionListener> xListener(*this,UNO_QUERY); // a shutdown should commit all changes to the db files
StorageContainer::revokeStorage(_aIter->sKey,nullptr);
} if ( !m_bInShutDownConnections )
m_aConnections.erase(_aIter);
}
auto i = std::find_if(m_aConnections.begin(), m_aConnections.end(),
[&sKey] (const TConnectionInfo& conn) { return conn.sKey == sKey;
});
OSL_ENSURE( i != m_aConnections.end(), "ODriverDelegator::preCommit: they're committing a storage which I do not know!" ); if ( i == m_aConnections.end() ) return;
try
{
Reference<XConnection> xConnection(i->xOrigConn); if ( xConnection.is() )
{
Reference< XStatement> xStmt = xConnection->createStatement();
OSL_ENSURE( xStmt.is(), "ODriverDelegator::preCommit: no statement!" ); if ( xStmt.is() )
xStmt->execute( u"SET WRITE_DELAY 0"_ustr );
if ( _bAcceptCountryMismatch )
{ // strip the country part from the compare string
sal_Int32 nCountrySep = sLocaleString.indexOf( '-' ); if ( nCountrySep > -1 )
sLocaleString = sLocaleString.copy( 0, nCountrySep );
// the entries in the translation table are compared until the // - character only, not until the terminating 0
nCompareTermination = '-';
}
// arguments for creating the config access
Sequence<Any> aArguments(comphelper::InitAnyPropertySequence(
{
{"nodepath", Any(u"/org.openoffice.Setup/L10N"_ustr)}, // the path to the node to open
{"depth", Any(sal_Int32(-1))}, // the depth: -1 means unlimited
})); // create the access
Reference< XPropertySet > xNode(
xConfigProvider->createInstanceWithArguments(
u"com.sun.star.configuration.ConfigurationAccess"_ustr,
aArguments ),
UNO_QUERY );
OSL_ENSURE( xNode.is(), "lcl_getSystemLocale: invalid access returned (should throw an exception instead)!" );
// ask for the system locale setting if ( xNode.is() )
xNode->getPropertyValue(u"ooSetupSystemLocale"_ustr) >>= sLocaleString;
} catch( const Exception& )
{
TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "lcl_getSystemLocale" );
} if ( sLocaleString.isEmpty() )
{
rtl_Locale* pProcessLocale = nullptr;
osl_getProcessLocale( &pProcessLocale );
sLocaleString = LanguageTag( *pProcessLocale).getBcp47();
} return sLocaleString;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.