summaryrefslogtreecommitdiff
path: root/connectivity/source/drivers/hsqldb/HDriver.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'connectivity/source/drivers/hsqldb/HDriver.cxx')
-rw-r--r--connectivity/source/drivers/hsqldb/HDriver.cxx111
1 files changed, 70 insertions, 41 deletions
diff --git a/connectivity/source/drivers/hsqldb/HDriver.cxx b/connectivity/source/drivers/hsqldb/HDriver.cxx
index 87c940a1c17c..19569dd77d61 100644
--- a/connectivity/source/drivers/hsqldb/HDriver.cxx
+++ b/connectivity/source/drivers/hsqldb/HDriver.cxx
@@ -41,7 +41,6 @@
#include <osl/file.h>
#include <osl/process.h>
#include <comphelper/namedvaluecollection.hxx>
-#include <comphelper/processfactory.hxx>
#include <comphelper/propertysequence.hxx>
#include <comphelper/servicehelper.hxx>
#include <cppuhelper/supportsservice.hxx>
@@ -51,7 +50,8 @@
#include <strings.hrc>
#include <resource/sharedresources.hxx>
#include <i18nlangtag/languagetag.hxx>
-#include <tools/diagnose_ex.h>
+#include <comphelper/diagnose_ex.hxx>
+#include <o3tl/string_view.hxx>
#include <memory>
@@ -69,9 +69,8 @@ namespace connectivity
using namespace css::embed;
using namespace css::io;
using namespace css::util;
- using namespace css::reflection;
- constexpr OUStringLiteral IMPL_NAME = "com.sun.star.sdbcx.comp.hsqldb.Driver";
+ constexpr OUString IMPL_NAME = u"com.sun.star.sdbcx.comp.hsqldb.Driver"_ustr;
@@ -236,14 +235,14 @@ namespace connectivity
// security: permitted Java classes
NamedValue aPermittedClasses(
"hsqldb.method_class_names",
- makeAny( lcl_getPermittedJavaMethods_nothrow( m_xContext ) )
+ Any( lcl_getPermittedJavaMethods_nothrow( m_xContext ) )
);
aProperties.put( "SystemProperties", Sequence< NamedValue >( &aPermittedClasses, 1 ) );
- const OUString sProperties( "properties" );
OUString sMessage;
try
{
+ static constexpr OUString sProperties( u"properties"_ustr );
if ( !bIsNewDatabase && xStorage->isStreamElement(sProperties) )
{
Reference<XStream > xStream = xStorage->openStreamElement(sProperties,ElementModes::READ);
@@ -252,15 +251,15 @@ namespace connectivity
std::unique_ptr<SvStream> pStream( ::utl::UcbStreamHelper::CreateStream(xStream) );
if (pStream)
{
- OString sLine;
+ OStringBuffer sLine;
OString sVersionString;
while ( pStream->ReadLine(sLine) )
{
if ( sLine.isEmpty() )
continue;
sal_Int32 nIdx {0};
- const OString sIniKey = sLine.getToken(0, '=', nIdx);
- const OString sValue = sLine.getToken(0, '=', nIdx);
+ const std::string_view sIniKey = o3tl::getToken(sLine, 0, '=', nIdx);
+ const OString sValue(o3tl::getToken(sLine, 0, '=', nIdx));
if( sIniKey == "hsqldb.compatible_version" )
{
sVersionString = sValue;
@@ -276,9 +275,9 @@ namespace connectivity
if (!sVersionString.isEmpty())
{
sal_Int32 nIdx {0};
- const sal_Int32 nMajor = sVersionString.getToken(0, '.', nIdx).toInt32();
- const sal_Int32 nMinor = sVersionString.getToken(0, '.', nIdx).toInt32();
- const sal_Int32 nMicro = sVersionString.getToken(0, '.', nIdx).toInt32();
+ const sal_Int32 nMajor = o3tl::toInt32(o3tl::getToken(sVersionString, 0, '.', nIdx));
+ const sal_Int32 nMinor = o3tl::toInt32(o3tl::getToken(sVersionString, 0, '.', nIdx));
+ const sal_Int32 nMicro = o3tl::toInt32(o3tl::getToken(sVersionString, 0, '.', nIdx));
if ( nMajor > 1
|| ( nMajor == 1 && nMinor > 8 )
|| ( nMajor == 1 && nMinor == 8 && nMicro > 0 ) )
@@ -291,6 +290,37 @@ namespace connectivity
} // if ( xStream.is() )
::comphelper::disposeComponent(xStream);
}
+
+ // 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);
+ }
+
}
catch(Exception&)
{
@@ -334,7 +364,7 @@ namespace connectivity
if ( xOrig.is() )
{
// now we have to set the URL to get the correct answer for metadata()->getURL()
- auto pMetaConnection = comphelper::getUnoTunnelImplementation<OMetaConnection>(xOrig);
+ auto pMetaConnection = comphelper::getFromUnoTunnel<OMetaConnection>(xOrig);
if ( pMetaConnection )
pMetaConnection->setURL(url);
@@ -347,7 +377,7 @@ namespace connectivity
{
Reference< XDesktop2 > xDesktop = Desktop::create( m_xContext );
- auto tmp = new OConnectionController(this);
+ rtl::Reference<OConnectionController> tmp = new OConnectionController(this);
xDesktop->addTerminateListener(tmp);
return tmp;
}();
@@ -358,8 +388,7 @@ namespace connectivity
Reference<XTransactionBroadcaster> xBroad(xStorage,UNO_QUERY);
if ( xBroad.is() )
{
- Reference<XTransactionListener> xListener(*this,UNO_QUERY);
- xBroad->addTransactionListener(xListener);
+ xBroad->addTransactionListener(Reference<XTransactionListener>(this));
}
}
}
@@ -394,29 +423,30 @@ namespace connectivity
{
if ( !acceptsURL(url) )
return Sequence< DriverPropertyInfo >();
- std::vector< DriverPropertyInfo > aDriverInfo;
- aDriverInfo.push_back(DriverPropertyInfo(
- "Storage"
- ,"Defines the storage where the database will be stored."
- ,true
- ,OUString()
- ,Sequence< OUString >())
- );
- aDriverInfo.push_back(DriverPropertyInfo(
- "URL"
- ,"Defines the url of the data source."
- ,true
- ,OUString()
- ,Sequence< OUString >())
- );
- aDriverInfo.push_back(DriverPropertyInfo(
- "AutoRetrievingStatement"
- ,"Defines the statement which will be executed to retrieve auto increment values."
- ,false
- ,"CALL IDENTITY()"
- ,Sequence< OUString >())
- );
- return Sequence< DriverPropertyInfo >(aDriverInfo.data(),aDriverInfo.size());
+ return
+ {
+ {
+ "Storage",
+ "Defines the storage where the database will be stored.",
+ true,
+ {},
+ {}
+ },
+ {
+ "URL",
+ "Defines the url of the data source.",
+ true,
+ {},
+ {}
+ },
+ {
+ "AutoRetrievingStatement",
+ "Defines the statement which will be executed to retrieve auto increment values.",
+ false,
+ "CALL IDENTITY()",
+ {}
+ }
+ };
}
@@ -833,8 +863,7 @@ namespace connectivity
OSL_ENSURE( xStatement.is(), "ODriverDelegator::onConnectedNewDatabase: could not create a statement!" );
if ( xStatement.is() )
{
- OUStringBuffer aStatement;
- aStatement.append( "SET DATABASE COLLATION \"" );
+ OUStringBuffer aStatement( "SET DATABASE COLLATION \"" );
aStatement.appendAscii( lcl_getCollationForLocale( lcl_getSystemLocale( m_xContext ) ) );
aStatement.append( "\"" );