diff options
Diffstat (limited to 'connectivity/source')
665 files changed, 9809 insertions, 18263 deletions
diff --git a/connectivity/source/commontools/AutoRetrievingBase.cxx b/connectivity/source/commontools/AutoRetrievingBase.cxx index d1170fdd972b..99327f27eeb5 100644 --- a/connectivity/source/commontools/AutoRetrievingBase.cxx +++ b/connectivity/source/commontools/AutoRetrievingBase.cxx @@ -20,6 +20,7 @@ #include <AutoRetrievingBase.hxx> #include <osl/diagnose.h> +#include <o3tl/string_view.hxx> namespace connectivity { @@ -39,7 +40,7 @@ namespace connectivity { // we need a table name sal_Int32 nIntoIndex = sStmt.indexOf("INTO ") + 5; while (nIntoIndex<sStmt.getLength() && sStmt[nIntoIndex]==' ') ++nIntoIndex; - const OUString sTableName = sStmt.getToken(0, ' ', nIntoIndex); + const std::u16string_view sTableName = o3tl::getToken(sStmt, 0, ' ', nIntoIndex); return m_sGeneratedValueStatement.replaceAt(nTableIndex, strlen(sTable), sTableName); } return m_sGeneratedValueStatement; diff --git a/connectivity/source/commontools/BlobHelper.cxx b/connectivity/source/commontools/BlobHelper.cxx index 591fe961e517..f1f048a7318e 100644 --- a/connectivity/source/commontools/BlobHelper.cxx +++ b/connectivity/source/commontools/BlobHelper.cxx @@ -20,6 +20,7 @@ #include <comphelper/seqstream.hxx> #include <connectivity/dbexception.hxx> #include <com/sun/star/sdbc/SQLException.hpp> +#include <o3tl/unreachable.hxx> using namespace connectivity; using namespace dbtools; @@ -47,25 +48,16 @@ css::uno::Reference< css::io::XInputStream > SAL_CALL BlobHelper::getBinaryStrea return new ::comphelper::SequenceInputStream(m_aValue); } - -// The "return" after a call to throwFeatureNotImplementedSQLException() -// (which always throws) will be detected as unreachable when doing -// global inlining. - -SAL_WNOUNREACHABLE_CODE_PUSH - ::sal_Int64 SAL_CALL BlobHelper::position( const css::uno::Sequence< ::sal_Int8 >& /*pattern*/, ::sal_Int64 /*start*/ ) { ::dbtools::throwFeatureNotImplementedSQLException( "XBlob::position", *this ); - return 0; + O3TL_UNREACHABLE; } ::sal_Int64 SAL_CALL BlobHelper::positionOfBlob( const css::uno::Reference< css::sdbc::XBlob >& /*pattern*/, ::sal_Int64 /*start*/ ) { ::dbtools::throwFeatureNotImplementedSQLException( "XBlob::positionOfBlob", *this ); - return 0; + O3TL_UNREACHABLE; } -SAL_WNOUNREACHABLE_CODE_POP - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/commontools/CommonTools.cxx b/connectivity/source/commontools/CommonTools.cxx index 5c84bf6e6f18..b5f7ce50fe74 100644 --- a/connectivity/source/commontools/CommonTools.cxx +++ b/connectivity/source/commontools/CommonTools.cxx @@ -29,9 +29,8 @@ #include <osl/diagnose.h> #include <rtl/character.hxx> #include <rtl/process.h> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> -using namespace ::comphelper; static sal_Unicode rtl_ascii_toUpperCase( sal_Unicode ch ) { return ch >= 0x0061 && ch <= 0x007a ? ch + 0x20 : ch; @@ -40,8 +39,6 @@ static sal_Unicode rtl_ascii_toUpperCase( sal_Unicode ch ) namespace connectivity { using namespace ::com::sun::star::uno; - using namespace ::com::sun::star::lang; - using namespace ::com::sun::star::beans; using namespace ::com::sun::star::java; using namespace dbtools; @@ -120,10 +117,10 @@ namespace connectivity { Reference< XJavaVM > xVM = JavaVirtualMachine::create(_rxContext); - Sequence<sal_Int8> processID(16); - rtl_getGlobalProcessId( reinterpret_cast<sal_uInt8*>(processID.getArray()) ); - processID.realloc(17); - processID[16] = 0; + Sequence<sal_Int8> processID(17); // 16 + 1 + auto pprocessID = processID.getArray(); + rtl_getGlobalProcessId( reinterpret_cast<sal_uInt8*>(pprocessID) ); + pprocessID[16] = 0; // RETURN_VIRTUALMACHINE Any uaJVM = xVM->getJavaVM( processID ); sal_Int64 nTemp; @@ -141,7 +138,7 @@ namespace connectivity return aRet; } - bool existsJavaClassByName( const ::rtl::Reference< jvmaccess::VirtualMachine >& _pJVM,const OUString& _sClassName ) + bool existsJavaClassByName( const ::rtl::Reference< jvmaccess::VirtualMachine >& _pJVM,std::u16string_view _sClassName ) { bool bRet = false; if ( _pJVM.is() ) @@ -165,15 +162,15 @@ namespace connectivity namespace dbtools { -static bool isCharOk(sal_Unicode c,const OUString& _rSpecials) +static bool isCharOk(sal_Unicode c, std::u16string_view _rSpecials) { return ( ((c >= 97) && (c <= 122)) || ((c >= 65) && (c <= 90)) || ((c >= 48) && (c <= 57)) || - c == '_' || _rSpecials.indexOf(c) != -1); + c == '_' || _rSpecials.find(c) != std::u16string_view::npos); } -bool isValidSQLName(const OUString& rName,const OUString& _rSpecials) +bool isValidSQLName(const OUString& rName, std::u16string_view _rSpecials) { // Test for correct naming (in SQL sense) // This is important for table names for example @@ -202,7 +199,7 @@ bool isValidSQLName(const OUString& rName,const OUString& _rSpecials) } // Creates a new name if necessary -OUString convertName2SQLName(const OUString& rName,const OUString& _rSpecials) +OUString convertName2SQLName(const OUString& rName, std::u16string_view _rSpecials) { if(isValidSQLName(rName,_rSpecials)) return rName; @@ -221,10 +218,10 @@ OUString convertName2SQLName(const OUString& rName,const OUString& _rSpecials) return aNewName.makeStringAndClear(); } -OUString quoteName(const OUString& _rQuote, const OUString& _rName) +OUString quoteName(std::u16string_view _rQuote, const OUString& _rName) { OUString sName = _rName; - if( !_rQuote.isEmpty() && _rQuote.toChar() != ' ') + if( !_rQuote.empty() && _rQuote[0] != ' ') sName = _rQuote + _rName + _rQuote; return sName; } diff --git a/connectivity/source/commontools/ConnectionWrapper.cxx b/connectivity/source/commontools/ConnectionWrapper.cxx index d7d999058a24..b8e45fb027e7 100644 --- a/connectivity/source/commontools/ConnectionWrapper.cxx +++ b/connectivity/source/commontools/ConnectionWrapper.cxx @@ -25,7 +25,6 @@ #include <comphelper/servicehelper.hxx> #include <comphelper/hash.hxx> #include <cppuhelper/supportsservice.hxx> -#include <cppuhelper/typeprovider.hxx> #include <com/sun/star/reflection/ProxyFactory.hpp> #include <algorithm> @@ -123,7 +122,7 @@ css::uno::Sequence< OUString > SAL_CALL OConnectionWrapper::getSupportedServiceN { sal_Int32 nLen = aSupported.getLength(); aSupported.realloc( nLen + 1 ); - aSupported[ nLen ] = sConnectionService; + aSupported.getArray()[ nLen ] = sConnectionService; } // outta here @@ -154,8 +153,8 @@ Sequence< Type > SAL_CALL OConnectionWrapper::getTypes( ) // css::lang::XUnoTunnel sal_Int64 SAL_CALL OConnectionWrapper::getSomething( const Sequence< sal_Int8 >& rId ) { - if (isUnoTunnelId<OConnectionWrapper>(rId)) - return reinterpret_cast< sal_Int64 >( this ); + if (comphelper::isUnoTunnelId<OConnectionWrapper>(rId)) + return comphelper::getSomething_cast(this); if(m_xUnoTunnel.is()) return m_xUnoTunnel->getSomething(rId); @@ -163,11 +162,10 @@ sal_Int64 SAL_CALL OConnectionWrapper::getSomething( const Sequence< sal_Int8 >& } -Sequence< sal_Int8 > OConnectionWrapper::getUnoTunnelId() +const Sequence< sal_Int8 > & OConnectionWrapper::getUnoTunnelId() { - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); + static const comphelper::UnoIdInit implId; + return implId.getSeq(); } namespace @@ -201,9 +199,10 @@ void OConnectionWrapper::createUniqueId( const OUString& _rURL if ( !_rPassword.isEmpty() ) sha1.update(reinterpret_cast<unsigned char const*>(_rPassword.getStr()), _rPassword.getLength() * sizeof(sal_Unicode)); // now we need to sort the properties - std::sort(_rInfo.begin(),_rInfo.end(),TPropertyValueLessFunctor()); + auto [begin, end] = asNonConstRange(_rInfo); + std::sort(begin,end,TPropertyValueLessFunctor()); - for (PropertyValue const & prop : std::as_const(_rInfo)) + for (PropertyValue const& prop : _rInfo) { // we only include strings an integer values OUString sValue; @@ -219,7 +218,7 @@ void OConnectionWrapper::createUniqueId( const OUString& _rURL Sequence< OUString> aSeq; if ( prop.Value >>= aSeq ) { - for(OUString const & s : std::as_const(aSeq)) + for (OUString const& s : aSeq) sha1.update(reinterpret_cast<unsigned char const*>(s.getStr()), s.getLength() * sizeof(sal_Unicode)); } } diff --git a/connectivity/source/commontools/DateConversion.cxx b/connectivity/source/commontools/DateConversion.cxx index 510736cc6a3f..0895881d7ee3 100644 --- a/connectivity/source/commontools/DateConversion.cxx +++ b/connectivity/source/commontools/DateConversion.cxx @@ -33,7 +33,7 @@ #include <comphelper/types.hxx> #include <rtl/ustrbuf.hxx> #include <sal/log.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> using namespace ::connectivity; @@ -83,16 +83,7 @@ OUString DBTypeConversion::toSQLString(sal_Int32 eType, const Any& _rVal, { OUString aTemp; _rxTypeConverter->convertToSimpleType(_rVal, TypeClass_STRING) >>= aTemp; - sal_Int32 nIndex = sal_Int32(-2); - const OUString sQuot("\'"); - do - { - nIndex += 2; - nIndex = aTemp.indexOf(sQuot,nIndex); - if(nIndex != -1) - aTemp = aTemp.replaceAt(nIndex,sQuot.getLength(), "\'\'"); - } while (nIndex != -1); - + aTemp = aTemp.replaceAll(u"\'", u"\'\'"); aRet.append(aTemp); } aRet.append("'"); @@ -134,9 +125,9 @@ OUString DBTypeConversion::toSQLString(sal_Int32 eType, const Any& _rVal, // check if this is really a timestamp or only a date if ( bOk ) { - aRet.append("{ts '"); - aRet.append(DBTypeConversion::toDateTimeString(aDateTime)); - aRet.append("'}"); + aRet.append("{ts '" + + DBTypeConversion::toDateTimeString(aDateTime) + + "'}"); break; } break; @@ -162,9 +153,9 @@ OUString DBTypeConversion::toSQLString(sal_Int32 eType, const Any& _rVal, else bOk = _rVal >>= aDate; OSL_ENSURE( bOk, "DBTypeConversion::toSQLString: _rVal is not date!"); - aRet.append("{d '"); - aRet.append(DBTypeConversion::toDateString(aDate)); - aRet.append("'}"); + aRet.append("{d '" + + DBTypeConversion::toDateString(aDate) + + "'}"); } break; case DataType::TIME: { @@ -187,9 +178,9 @@ OUString DBTypeConversion::toSQLString(sal_Int32 eType, const Any& _rVal, else bOk = _rVal >>= aTime; OSL_ENSURE( bOk,"DBTypeConversion::toSQLString: _rVal is not time!"); - aRet.append("{t '"); - aRet.append(DBTypeConversion::toTimeString(aTime)); - aRet.append("'}"); + aRet.append("{t '" + + DBTypeConversion::toTimeString(aTime) + + "'}"); } break; } } @@ -433,7 +424,7 @@ OUString DBTypeConversion::getFormattedValue(const Reference< XPropertySet>& _xC } catch (const Exception& ) { - OSL_FAIL("DBTypeConversion::getValue: caught an exception while asking for the format key!"); + TOOLS_WARN_EXCEPTION( "connectivity.commontools", "DBTypeConversion::getValue: caught an exception while asking for the format key!"); } if (!nKey) diff --git a/connectivity/source/commontools/DriversConfig.cxx b/connectivity/source/commontools/DriversConfig.cxx index 9d2ab8a475d7..26a241e3f829 100644 --- a/connectivity/source/commontools/DriversConfig.cxx +++ b/connectivity/source/commontools/DriversConfig.cxx @@ -16,9 +16,13 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <config_fuzzers.h> + #include <connectivity/DriversConfig.hxx> +#include <o3tl/string_view.hxx> #include <tools/wldcrd.hxx> #include <comphelper/sequence.hxx> +#include <utility> using namespace connectivity; using namespace utl; @@ -117,8 +121,8 @@ const TInstalledDrivers& DriversConfigImpl::getInstalledDrivers(const uno::Refer return m_aDrivers; } -DriversConfig::DriversConfig(const uno::Reference< uno::XComponentContext >& _rxORB) -:m_xORB(_rxORB) +DriversConfig::DriversConfig(uno::Reference< uno::XComponentContext > _xORB) +:m_xORB(std::move(_xORB)) { } @@ -144,8 +148,13 @@ DriversConfig& DriversConfig::operator=( const DriversConfig& _rhs ) } -OUString DriversConfig::getDriverFactoryName(const OUString& _sURL) const +OUString DriversConfig::getDriverFactoryName(std::u16string_view _sURL) const { +#if ENABLE_FUZZERS + if (o3tl::starts_with(_sURL, u"sdbc:dbase:")) + return "com.sun.star.comp.sdbc.dbase.ODriver"; +#endif + const TInstalledDrivers& rDrivers = m_aNode->getInstalledDrivers(m_xORB); OUString sRet; OUString sOldPattern; @@ -162,7 +171,7 @@ OUString DriversConfig::getDriverFactoryName(const OUString& _sURL) const return sRet; } -OUString DriversConfig::getDriverTypeDisplayName(const OUString& _sURL) const +OUString DriversConfig::getDriverTypeDisplayName(std::u16string_view _sURL) const { const TInstalledDrivers& rDrivers = m_aNode->getInstalledDrivers(m_xORB); OUString sRet; @@ -180,22 +189,25 @@ OUString DriversConfig::getDriverTypeDisplayName(const OUString& _sURL) const return sRet; } -const ::comphelper::NamedValueCollection& DriversConfig::getProperties(const OUString& _sURL) const +const ::comphelper::NamedValueCollection& DriversConfig::getProperties(std::u16string_view _sURL) + const { return impl_get(_sURL,1); } -const ::comphelper::NamedValueCollection& DriversConfig::getFeatures(const OUString& _sURL) const +const ::comphelper::NamedValueCollection& DriversConfig::getFeatures(std::u16string_view _sURL) + const { return impl_get(_sURL,0); } -const ::comphelper::NamedValueCollection& DriversConfig::getMetaData(const OUString& _sURL) const +const ::comphelper::NamedValueCollection& DriversConfig::getMetaData(std::u16string_view _sURL) + const { return impl_get(_sURL,2); } -const ::comphelper::NamedValueCollection& DriversConfig::impl_get(const OUString& _sURL,sal_Int32 _nProps) const +const ::comphelper::NamedValueCollection& DriversConfig::impl_get(std::u16string_view _sURL,sal_Int32 _nProps) const { const TInstalledDrivers& rDrivers = m_aNode->getInstalledDrivers(m_xORB); const ::comphelper::NamedValueCollection* pRet = nullptr; diff --git a/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx b/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx index 969a1f1e1f4f..3f59f4646bc1 100644 --- a/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx +++ b/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx @@ -25,10 +25,10 @@ #include <com/sun/star/beans/PropertyAttribute.hpp> #include <cppuhelper/typeprovider.hxx> #include <comphelper/sequence.hxx> -#include <cppuhelper/factory.hxx> -#include <cppuhelper/implementationentry.hxx> #include <cppuhelper/supportsservice.hxx> #include <connectivity/dbexception.hxx> +#include <o3tl/safeint.hxx> +#include <o3tl/unreachable.hxx> #include <TConnection.hxx> using namespace connectivity; @@ -37,16 +37,13 @@ using namespace cppu; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; using namespace ::com::sun::star::lang; ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet() - :ODatabaseMetaDataResultSet_BASE(m_aMutex) - ,::comphelper::OPropertyContainer(ODatabaseMetaDataResultSet_BASE::rBHelper) - ,m_aStatement(nullptr) - ,m_nColPos(0) + : + m_nColPos(0) ,m_bBOF(true) ,m_bEOF(true) { @@ -55,10 +52,8 @@ ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet() ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet( MetaDataResultSetType _eType ) - :ODatabaseMetaDataResultSet_BASE(m_aMutex) - ,::comphelper::OPropertyContainer(ODatabaseMetaDataResultSet_BASE::rBHelper) - ,m_aStatement(nullptr) - ,m_nColPos(0) + : + m_nColPos(0) ,m_bBOF(true) ,m_bEOF(true) { @@ -107,24 +102,23 @@ void ODatabaseMetaDataResultSet::setType(MetaDataResultSetType _eType) } } -void ODatabaseMetaDataResultSet::disposing() +void ODatabaseMetaDataResultSet::disposing(std::unique_lock<std::mutex>& rGuard) { - OPropertySetHelper::disposing(); + OPropertySetHelper::disposing(rGuard); - ::osl::MutexGuard aGuard(m_aMutex); - m_aStatement = nullptr; + m_aStatement.clear(); m_xMetaData.clear(); m_aRowsIter = m_aRows.end(); m_aRows.clear(); m_aRowsIter = m_aRows.end(); } -void SAL_CALL ODatabaseMetaDataResultSet::acquire() throw() +void SAL_CALL ODatabaseMetaDataResultSet::acquire() noexcept { ODatabaseMetaDataResultSet_BASE::acquire(); } -void SAL_CALL ODatabaseMetaDataResultSet::release() throw() +void SAL_CALL ODatabaseMetaDataResultSet::release() noexcept { ODatabaseMetaDataResultSet_BASE::release(); } @@ -144,20 +138,19 @@ Sequence< Type > SAL_CALL ODatabaseMetaDataResultSet::getTypes( ) return ::comphelper::concatSequences(aTypes.getTypes(),ODatabaseMetaDataResultSet_BASE::getTypes()); } -void ODatabaseMetaDataResultSet::setRows(const ORows& _rRows) +void ODatabaseMetaDataResultSet::setRows(ORows&& _rRows) { - m_aRows = _rRows; + m_aRows = std::move(_rRows); m_bBOF = true; m_bEOF = m_aRows.empty(); } sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::findColumn( const OUString& columnName ) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed ); + std::unique_lock aGuard( m_aMutex ); + throwIfDisposed(aGuard); - - Reference< XResultSetMetaData > xMeta = getMetaData(); + Reference< XResultSetMetaData > xMeta = getMetaData(aGuard); sal_Int32 nLen = xMeta->getColumnCount(); sal_Int32 i = 1; for(;i<=nLen;++i) @@ -169,15 +162,12 @@ sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::findColumn( const OUString& colum } ::dbtools::throwInvalidColumnException( columnName, *this ); -#if !(defined(_MSC_VER) && defined(ENABLE_LTO)) - assert(false); - return 0; // Never reached -#endif + O3TL_UNREACHABLE; } -void ODatabaseMetaDataResultSet::checkIndex(sal_Int32 columnIndex ) +void ODatabaseMetaDataResultSet::checkIndex(std::unique_lock<std::mutex>& /*rGuard*/, sal_Int32 columnIndex ) { - if(columnIndex >= static_cast<sal_Int32>((*m_aRowsIter).size()) || columnIndex < 1) + if(columnIndex < 1 || o3tl::make_unsigned(columnIndex) >= (*m_aRowsIter).size()) ::dbtools::throwInvalidIndexException(*this); } @@ -194,43 +184,43 @@ Reference< css::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getChara sal_Bool SAL_CALL ODatabaseMetaDataResultSet::getBoolean( sal_Int32 columnIndex ) { - return bool(getValue(columnIndex)); + return getValue(columnIndex).getBool(); } sal_Int8 SAL_CALL ODatabaseMetaDataResultSet::getByte( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getInt8(); } Sequence< sal_Int8 > SAL_CALL ODatabaseMetaDataResultSet::getBytes( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getSequence(); } css::util::Date SAL_CALL ODatabaseMetaDataResultSet::getDate( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getDate(); } double SAL_CALL ODatabaseMetaDataResultSet::getDouble( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getDouble(); } float SAL_CALL ODatabaseMetaDataResultSet::getFloat( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getFloat(); } sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getInt( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getInt32(); } @@ -242,15 +232,19 @@ sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getRow( ) sal_Int64 SAL_CALL ODatabaseMetaDataResultSet::getLong( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getLong(); } Reference< XResultSetMetaData > SAL_CALL ODatabaseMetaDataResultSet::getMetaData( ) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed ); + std::unique_lock aGuard( m_aMutex ); + return getMetaData(aGuard); +} +Reference< XResultSetMetaData > ODatabaseMetaDataResultSet::getMetaData( std::unique_lock<std::mutex>& rGuard ) +{ + throwIfDisposed(rGuard); if(!m_xMetaData.is()) m_xMetaData = new ODatabaseMetaDataResultSetMetaData(); @@ -289,50 +283,50 @@ Any SAL_CALL ODatabaseMetaDataResultSet::getObject( sal_Int32 columnIndex, const sal_Int16 SAL_CALL ODatabaseMetaDataResultSet::getShort( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getInt16(); } OUString SAL_CALL ODatabaseMetaDataResultSet::getString( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getString(); } css::util::Time SAL_CALL ODatabaseMetaDataResultSet::getTime( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getTime(); } css::util::DateTime SAL_CALL ODatabaseMetaDataResultSet::getTimestamp( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getDateTime(); } -sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isAfterLast( ) +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isAfterLast() { return m_bEOF; } - -SAL_WNOUNREACHABLE_CODE_PUSH +bool ODatabaseMetaDataResultSet::isAfterLast( std::unique_lock<std::mutex>& /*rGuard*/) +{ + return m_bEOF; +} sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isFirst( ) { ::dbtools::throwFunctionSequenceException(*this); - return false; + O3TL_UNREACHABLE; } sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isLast( ) { ::dbtools::throwFunctionSequenceException(*this); - return false; + O3TL_UNREACHABLE; } -SAL_WNOUNREACHABLE_CODE_POP - void SAL_CALL ODatabaseMetaDataResultSet::beforeFirst( ) { @@ -348,49 +342,44 @@ void SAL_CALL ODatabaseMetaDataResultSet::afterLast( ) void SAL_CALL ODatabaseMetaDataResultSet::close( ) { { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed ); - + std::unique_lock aGuard( m_aMutex ); + throwIfDisposed(aGuard); } dispose(); } -SAL_WNOUNREACHABLE_CODE_PUSH - sal_Bool SAL_CALL ODatabaseMetaDataResultSet::first( ) { ::dbtools::throwFunctionSequenceException(*this); - return false; + O3TL_UNREACHABLE; } sal_Bool SAL_CALL ODatabaseMetaDataResultSet::last( ) { ::dbtools::throwFunctionSequenceException(*this); - return false; + O3TL_UNREACHABLE; } sal_Bool SAL_CALL ODatabaseMetaDataResultSet::absolute( sal_Int32 /*row*/ ) { ::dbtools::throwFunctionSequenceException(*this); - return false; + O3TL_UNREACHABLE; } sal_Bool SAL_CALL ODatabaseMetaDataResultSet::relative( sal_Int32 /*row*/ ) { ::dbtools::throwFunctionSequenceException(*this); - return false; + O3TL_UNREACHABLE; } sal_Bool SAL_CALL ODatabaseMetaDataResultSet::previous( ) { ::dbtools::throwFunctionSequenceException(*this); - return false; + O3TL_UNREACHABLE; } -SAL_WNOUNREACHABLE_CODE_POP - Reference< XInterface > SAL_CALL ODatabaseMetaDataResultSet::getStatement( ) { @@ -398,39 +387,44 @@ Reference< XInterface > SAL_CALL ODatabaseMetaDataResultSet::getStatement( ) } -SAL_WNOUNREACHABLE_CODE_PUSH - sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowDeleted( ) { ::dbtools::throwFunctionSequenceException(*this); - return false; + O3TL_UNREACHABLE; } sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowInserted( ) { ::dbtools::throwFunctionSequenceException(*this); - return false; + O3TL_UNREACHABLE; } sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowUpdated( ) { ::dbtools::throwFunctionSequenceException(*this); - return false; + O3TL_UNREACHABLE; } -SAL_WNOUNREACHABLE_CODE_POP - -sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isBeforeFirst( ) +sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isBeforeFirst() { return m_bBOF; } +bool ODatabaseMetaDataResultSet::isBeforeFirst(std::unique_lock<std::mutex>& /*rGuard*/) +{ + return m_bBOF; +} sal_Bool SAL_CALL ODatabaseMetaDataResultSet::next( ) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed ); + std::unique_lock aGuard( m_aMutex ); + return next(aGuard); +} + +bool ODatabaseMetaDataResultSet::next( std::unique_lock<std::mutex>& rGuard ) +{ + throwIfDisposed(rGuard); if ( m_bBOF ) { @@ -458,9 +452,8 @@ sal_Bool SAL_CALL ODatabaseMetaDataResultSet::next( ) sal_Bool SAL_CALL ODatabaseMetaDataResultSet::wasNull( ) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed ); - + std::unique_lock aGuard( m_aMutex ); + throwIfDisposed(aGuard); if(m_aRowsIter == m_aRows.end() || !(*m_aRowsIter)[m_nColPos].is()) return true; @@ -500,128 +493,126 @@ Any SAL_CALL ODatabaseMetaDataResultSet::getWarnings( ) void ODatabaseMetaDataResultSet::setProceduresMap() { - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(); pMetaData->setProceduresMap(); m_xMetaData = pMetaData; } void ODatabaseMetaDataResultSet::setCatalogsMap() { - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(); pMetaData->setCatalogsMap(); m_xMetaData = pMetaData; } void ODatabaseMetaDataResultSet::setSchemasMap() { - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(); pMetaData->setSchemasMap(); m_xMetaData = pMetaData; } void ODatabaseMetaDataResultSet::setColumnPrivilegesMap() { - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(); pMetaData->setColumnPrivilegesMap(); m_xMetaData = pMetaData; } void ODatabaseMetaDataResultSet::setColumnsMap() { - - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(); pMetaData->setColumnsMap(); m_xMetaData = pMetaData; } void ODatabaseMetaDataResultSet::setTablesMap() { - - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(); pMetaData->setTablesMap(); m_xMetaData = pMetaData; } void ODatabaseMetaDataResultSet::setProcedureColumnsMap() { - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(); pMetaData->setProcedureColumnsMap(); m_xMetaData = pMetaData; } void ODatabaseMetaDataResultSet::setPrimaryKeysMap() { - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(); pMetaData->setPrimaryKeysMap(); m_xMetaData = pMetaData; } void ODatabaseMetaDataResultSet::setIndexInfoMap() { - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(); pMetaData->setIndexInfoMap(); m_xMetaData = pMetaData; } void ODatabaseMetaDataResultSet::setTablePrivilegesMap() { - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(); pMetaData->setTablePrivilegesMap(); m_xMetaData = pMetaData; } void ODatabaseMetaDataResultSet::setCrossReferenceMap() { - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(); pMetaData->setCrossReferenceMap(); m_xMetaData = pMetaData; } void ODatabaseMetaDataResultSet::setVersionColumnsMap() { - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(); pMetaData->setVersionColumnsMap(); m_xMetaData = pMetaData; } void ODatabaseMetaDataResultSet::setBestRowIdentifierMap() { - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(); pMetaData->setBestRowIdentifierMap(); m_xMetaData = pMetaData; } void ODatabaseMetaDataResultSet::setTypeInfoMap() { - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(); pMetaData->setTypeInfoMap(); m_xMetaData = pMetaData; } void ODatabaseMetaDataResultSet::setUDTsMap() { - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(); pMetaData->setUDTsMap(); m_xMetaData = pMetaData; } void ODatabaseMetaDataResultSet::setTableTypes() { - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(); pMetaData->setTableTypes(); m_xMetaData = pMetaData; } void ODatabaseMetaDataResultSet::setExportedKeysMap() { - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(); pMetaData->setExportedKeysMap(); m_xMetaData = pMetaData; } void ODatabaseMetaDataResultSet::setImportedKeysMap() { - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(); pMetaData->setImportedKeysMap(); m_xMetaData = pMetaData; } @@ -639,13 +630,13 @@ ORowSetValueDecorator& ORowSetValueDecorator::operator=(const ORowSetValue& _aVa const ORowSetValue& ODatabaseMetaDataResultSet::getValue(sal_Int32 columnIndex) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed ); + std::unique_lock aGuard( m_aMutex ); + throwIfDisposed(aGuard); - if ( isBeforeFirst() || isAfterLast() ) + if ( isBeforeFirst(aGuard) || isAfterLast(aGuard) ) ::dbtools::throwFunctionSequenceException( *this ); - checkIndex(columnIndex ); + checkIndex(aGuard, columnIndex); m_nColPos = columnIndex; if(m_aRowsIter != m_aRows.end() && (*m_aRowsIter)[columnIndex].is()) @@ -828,7 +819,7 @@ void SAL_CALL ODatabaseMetaDataResultSet::initialize( const Sequence< Any >& _aA } aRowsToSet.push_back(aRowToSet); } // for (; pRowsIter != pRowsEnd;++pRowsIter - setRows(aRowsToSet); + setRows(std::move(aRowsToSet)); } // XServiceInfo diff --git a/connectivity/source/commontools/FDatabaseMetaDataResultSetMetaData.cxx b/connectivity/source/commontools/FDatabaseMetaDataResultSetMetaData.cxx index 561953a0796c..291ce7a7d96b 100644 --- a/connectivity/source/commontools/FDatabaseMetaDataResultSetMetaData.cxx +++ b/connectivity/source/commontools/FDatabaseMetaDataResultSetMetaData.cxx @@ -22,9 +22,7 @@ #include <com/sun/star/sdbc/ColumnValue.hpp> using namespace connectivity; -using namespace ::com::sun::star::uno; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::lang; ODatabaseMetaDataResultSetMetaData::~ODatabaseMetaDataResultSetMetaData() { diff --git a/connectivity/source/commontools/FValue.cxx b/connectivity/source/commontools/FValue.cxx index 2f1cabbd4520..4ac0235ac4e4 100644 --- a/connectivity/source/commontools/FValue.cxx +++ b/connectivity/source/commontools/FValue.cxx @@ -945,20 +945,20 @@ OUString ORowSetValue::getString( ) const aRet = m_aValue.m_pString; break; case DataType::FLOAT: - aRet = OUString::number(static_cast<float>(*this)); + aRet = OUString::number(getFloat()); break; case DataType::DOUBLE: case DataType::REAL: - aRet = OUString::number(static_cast<double>(*this)); + aRet = OUString::number(getDouble()); break; case DataType::DATE: - aRet = DBTypeConversion::toDateString(*this); + aRet = DBTypeConversion::toDateString(getDate()); break; case DataType::TIME: - aRet = DBTypeConversion::toTimeString(*this); + aRet = DBTypeConversion::toTimeString(getTime()); break; case DataType::TIMESTAMP: - aRet = DBTypeConversion::toDateTimeString(*this); + aRet = DBTypeConversion::toDateTimeString(getDateTime()); break; case DataType::BINARY: case DataType::VARBINARY: @@ -974,24 +974,24 @@ OUString ORowSetValue::getString( ) const } break; case DataType::BIT: - aRet = OUString::number(int(static_cast<bool>(*this))); + aRet = OUString::number(int(getBool())); break; case DataType::BOOLEAN: - aRet = OUString::boolean(static_cast<bool>(*this)); + aRet = OUString::boolean(getBool()); break; case DataType::TINYINT: case DataType::SMALLINT: case DataType::INTEGER: if ( m_bSigned ) - aRet = OUString::number(static_cast<sal_Int32>(*this)); + aRet = OUString::number(getInt32()); else - aRet = OUString::number(static_cast<sal_uInt32>(*this)); + aRet = OUString::number(getUInt32()); break; case DataType::BIGINT: if ( m_bSigned ) - aRet = OUString::number(static_cast<sal_Int64>(*this)); + aRet = OUString::number(getLong()); else - aRet = OUString::number(static_cast<sal_uInt64>(*this)); + aRet = OUString::number(getULong()); break; case DataType::CLOB: { @@ -1041,7 +1041,7 @@ bool ORowSetValue::getBool() const case DataType::DECIMAL: case DataType::NUMERIC: - bRet = OUString(m_aValue.m_pString).toInt32() != 0; + bRet = OUString::unacquired(&m_aValue.m_pString).toInt32() != 0; break; case DataType::FLOAT: bRet = m_aValue.m_nFloat != 0.0; @@ -1098,7 +1098,7 @@ sal_Int8 ORowSetValue::getInt8() const case DataType::DECIMAL: case DataType::NUMERIC: case DataType::LONGVARCHAR: - nRet = sal_Int8(OUString(m_aValue.m_pString).toInt32()); + nRet = sal_Int8(OUString::unacquired(&m_aValue.m_pString).toInt32()); break; case DataType::FLOAT: nRet = sal_Int8(m_aValue.m_nFloat); @@ -1169,7 +1169,7 @@ sal_uInt8 ORowSetValue::getUInt8() const case DataType::DECIMAL: case DataType::NUMERIC: case DataType::LONGVARCHAR: - nRet = sal_uInt8(OUString(m_aValue.m_pString).toInt32()); + nRet = sal_uInt8(OUString::unacquired(&m_aValue.m_pString).toInt32()); break; case DataType::FLOAT: nRet = sal_uInt8(m_aValue.m_nFloat); @@ -1244,7 +1244,7 @@ sal_Int16 ORowSetValue::getInt16() const case DataType::DECIMAL: case DataType::NUMERIC: case DataType::LONGVARCHAR: - nRet = sal_Int16(OUString(m_aValue.m_pString).toInt32()); + nRet = sal_Int16(OUString::unacquired(&m_aValue.m_pString).toInt32()); break; case DataType::FLOAT: nRet = sal_Int16(m_aValue.m_nFloat); @@ -1315,7 +1315,7 @@ sal_uInt16 ORowSetValue::getUInt16() const case DataType::DECIMAL: case DataType::NUMERIC: case DataType::LONGVARCHAR: - nRet = sal_uInt16(OUString(m_aValue.m_pString).toInt32()); + nRet = sal_uInt16(OUString::unacquired(&m_aValue.m_pString).toInt32()); break; case DataType::FLOAT: nRet = sal_uInt16(m_aValue.m_nFloat); @@ -1386,7 +1386,7 @@ sal_Int32 ORowSetValue::getInt32() const case DataType::DECIMAL: case DataType::NUMERIC: case DataType::LONGVARCHAR: - nRet = OUString(m_aValue.m_pString).toInt32(); + nRet = OUString::unacquired(&m_aValue.m_pString).toInt32(); break; case DataType::FLOAT: nRet = sal_Int32(m_aValue.m_nFloat); @@ -1459,7 +1459,7 @@ sal_uInt32 ORowSetValue::getUInt32() const case DataType::DECIMAL: case DataType::NUMERIC: case DataType::LONGVARCHAR: - nRet = OUString(m_aValue.m_pString).toUInt32(); + nRet = OUString::unacquired(&m_aValue.m_pString).toUInt32(); break; case DataType::FLOAT: nRet = sal_uInt32(m_aValue.m_nFloat); @@ -1532,7 +1532,7 @@ sal_Int64 ORowSetValue::getLong() const case DataType::DECIMAL: case DataType::NUMERIC: case DataType::LONGVARCHAR: - nRet = OUString(m_aValue.m_pString).toInt64(); + nRet = OUString::unacquired(&m_aValue.m_pString).toInt64(); break; case DataType::FLOAT: nRet = sal_Int64(m_aValue.m_nFloat); @@ -1605,7 +1605,7 @@ sal_uInt64 ORowSetValue::getULong() const case DataType::DECIMAL: case DataType::NUMERIC: case DataType::LONGVARCHAR: - nRet = OUString(m_aValue.m_pString).toUInt64(); + nRet = OUString::unacquired(&m_aValue.m_pString).toUInt64(); break; case DataType::FLOAT: nRet = sal_uInt64(m_aValue.m_nFloat); @@ -1678,7 +1678,7 @@ float ORowSetValue::getFloat() const case DataType::DECIMAL: case DataType::NUMERIC: case DataType::LONGVARCHAR: - nRet = OUString(m_aValue.m_pString).toFloat(); + nRet = OUString::unacquired(&m_aValue.m_pString).toFloat(); break; case DataType::FLOAT: nRet = m_aValue.m_nFloat; @@ -1754,7 +1754,7 @@ double ORowSetValue::getDouble() const case DataType::DECIMAL: case DataType::NUMERIC: case DataType::LONGVARCHAR: - nRet = OUString(m_aValue.m_pString).toDouble(); + nRet = OUString::unacquired(&m_aValue.m_pString).toDouble(); break; case DataType::FLOAT: nRet = m_aValue.m_nFloat; @@ -1907,7 +1907,7 @@ css::util::Date ORowSetValue::getDate() const case DataType::FLOAT: case DataType::DOUBLE: case DataType::REAL: - aValue = DBTypeConversion::toDate(static_cast<double>(*this)); + aValue = DBTypeConversion::toDate(getDouble()); break; case DataType::DATE: @@ -1927,7 +1927,7 @@ css::util::Date ORowSetValue::getDate() const case DataType::SMALLINT: case DataType::INTEGER: case DataType::BIGINT: - aValue = DBTypeConversion::toDate( double( sal_Int64( *this ) ) ); + aValue = DBTypeConversion::toDate( double( getLong() ) ); break; case DataType::BLOB: @@ -1962,12 +1962,12 @@ css::util::Time ORowSetValue::getTime() const break; case DataType::DECIMAL: case DataType::NUMERIC: - aValue = DBTypeConversion::toTime(static_cast<double>(*this)); + aValue = DBTypeConversion::toTime(getDouble()); break; case DataType::FLOAT: case DataType::DOUBLE: case DataType::REAL: - aValue = DBTypeConversion::toTime(static_cast<double>(*this)); + aValue = DBTypeConversion::toTime(getDouble()); break; case DataType::TIMESTAMP: { @@ -2006,12 +2006,12 @@ css::util::DateTime ORowSetValue::getDateTime() const break; case DataType::DECIMAL: case DataType::NUMERIC: - aValue = DBTypeConversion::toDateTime(static_cast<double>(*this)); + aValue = DBTypeConversion::toDateTime(getDouble()); break; case DataType::FLOAT: case DataType::DOUBLE: case DataType::REAL: - aValue = DBTypeConversion::toDateTime(static_cast<double>(*this)); + aValue = DBTypeConversion::toDateTime(getDouble()); break; case DataType::DATE: { @@ -2285,11 +2285,11 @@ void ORowSetValue::impl_fill( const sal_Int32 _nType, bool _bNullable, const det (*this) = _rValueSource.getLong(); break; case DataType::CLOB: - (*this) = css::uno::makeAny(_rValueSource.getClob()); + (*this) = css::uno::Any(_rValueSource.getClob()); setTypeKind(DataType::CLOB); break; case DataType::BLOB: - (*this) = css::uno::makeAny(_rValueSource.getBlob()); + (*this) = css::uno::Any(_rValueSource.getBlob()); setTypeKind(DataType::BLOB); break; case DataType::OTHER: diff --git a/connectivity/source/commontools/ParameterSubstitution.cxx b/connectivity/source/commontools/ParameterSubstitution.cxx index 3a58fed70b09..6fa55780803f 100644 --- a/connectivity/source/commontools/ParameterSubstitution.cxx +++ b/connectivity/source/commontools/ParameterSubstitution.cxx @@ -20,6 +20,7 @@ #include <connectivity/sqlparse.hxx> #include <comphelper/sequenceashashmap.hxx> #include <cppuhelper/supportsservice.hxx> +#include <utility> namespace connectivity { @@ -28,7 +29,7 @@ namespace connectivity using namespace ::com::sun::star::lang; using namespace ::com::sun::star; - ParameterSubstitution::ParameterSubstitution(const css::uno::Reference< css::uno::XComponentContext >& _rxContext ) : m_xContext(_rxContext) + ParameterSubstitution::ParameterSubstitution(css::uno::Reference< css::uno::XComponentContext > _xContext ) : m_xContext(std::move(_xContext)) { } void SAL_CALL ParameterSubstitution::initialize( const uno::Sequence< uno::Any >& _aArguments ) @@ -66,11 +67,11 @@ namespace connectivity { OSQLParser aParser( m_xContext ); OUString sErrorMessage; - OUString sNewSql; std::unique_ptr<OSQLParseNode> pNode = aParser.parseTree(sErrorMessage,_sText); if(pNode) { // special handling for parameters OSQLParseNode::substituteParameterNames(pNode.get()); + OUString sNewSql; pNode->parseNodeToStr( sNewSql, xConnection ); sRet = sNewSql; } diff --git a/connectivity/source/commontools/RowFunctionParser.cxx b/connectivity/source/commontools/RowFunctionParser.cxx index 21f5e638a651..f8799848de9b 100644 --- a/connectivity/source/commontools/RowFunctionParser.cxx +++ b/connectivity/source/commontools/RowFunctionParser.cxx @@ -38,6 +38,7 @@ #endif #include <algorithm> #include <stack> +#include <utility> namespace connectivity { @@ -56,8 +57,8 @@ class ConstantValueExpression : public ExpressionNode public: - explicit ConstantValueExpression( ORowSetValueDecoratorRef const & rValue ) : - maValue( rValue ) + explicit ConstantValueExpression(ORowSetValueDecoratorRef aValue) + : maValue(std::move(aValue)) { } virtual ORowSetValueDecoratorRef evaluate(const ODatabaseMetaDataResultSet::ORow& /*_aRow*/ ) const override @@ -81,10 +82,10 @@ class BinaryFunctionExpression : public ExpressionNode public: - BinaryFunctionExpression( const ExpressionFunct eFunct, const std::shared_ptr<ExpressionNode>& rFirstArg, const std::shared_ptr<ExpressionNode>& rSecondArg ) : + BinaryFunctionExpression( const ExpressionFunct eFunct, std::shared_ptr<ExpressionNode> xFirstArg, std::shared_ptr<ExpressionNode> xSecondArg ) : meFunct( eFunct ), - mpFirstArg( rFirstArg ), - mpSecondArg( rSecondArg ) + mpFirstArg(std::move( xFirstArg )), + mpSecondArg(std::move( xSecondArg )) { } virtual ORowSetValueDecoratorRef evaluate(const ODatabaseMetaDataResultSet::ORow& _aRow ) const override @@ -93,13 +94,13 @@ public: switch(meFunct) { case ExpressionFunct::Equation: - aRet = new ORowSetValueDecorator( mpFirstArg->evaluate(_aRow )->getValue() == mpSecondArg->evaluate(_aRow )->getValue() ); + aRet = new ORowSetValueDecorator( ORowSetValue(mpFirstArg->evaluate(_aRow )->getValue() == mpSecondArg->evaluate(_aRow )->getValue()) ); break; case ExpressionFunct::And: - aRet = new ORowSetValueDecorator( mpFirstArg->evaluate(_aRow )->getValue().getBool() && mpSecondArg->evaluate(_aRow )->getValue().getBool() ); + aRet = new ORowSetValueDecorator( ORowSetValue(mpFirstArg->evaluate(_aRow )->getValue().getBool() && mpSecondArg->evaluate(_aRow )->getValue().getBool()) ); break; case ExpressionFunct::Or: - aRet = new ORowSetValueDecorator( mpFirstArg->evaluate(_aRow )->getValue().getBool() || mpSecondArg->evaluate(_aRow )->getValue().getBool() ); + aRet = new ORowSetValueDecorator( ORowSetValue(mpFirstArg->evaluate(_aRow )->getValue().getBool() || mpSecondArg->evaluate(_aRow )->getValue().getBool()) ); break; default: break; @@ -148,14 +149,14 @@ class ConstantFunctor public: - explicit ConstantFunctor( const ParserContextSharedPtr& rContext ) : - mpContext( rContext ) + explicit ConstantFunctor( ParserContextSharedPtr xContext ) : + mpContext(std::move( xContext )) { } void operator()( StringIteratorT rFirst,StringIteratorT rSecond) const { OUString sVal( rFirst, rSecond - rFirst, RTL_TEXTENCODING_UTF8 ); - mpContext->maOperandStack.push( std::make_shared<ConstantValueExpression>( new ORowSetValueDecorator( sVal ) ) ); + mpContext->maOperandStack.push(std::make_shared<ConstantValueExpression>(ORowSetValueDecoratorRef(new ORowSetValueDecorator(sVal)))); } }; @@ -166,13 +167,13 @@ class IntConstantFunctor ParserContextSharedPtr mpContext; public: - explicit IntConstantFunctor( const ParserContextSharedPtr& rContext ) : - mpContext( rContext ) + explicit IntConstantFunctor( ParserContextSharedPtr xContext ) : + mpContext(std::move( xContext )) { } void operator()( sal_Int32 n ) const { - mpContext->maOperandStack.push( std::make_shared<ConstantValueExpression>( new ORowSetValueDecorator( n ) ) ); + mpContext->maOperandStack.push(std::make_shared<ConstantValueExpression>(ORowSetValueDecoratorRef(new ORowSetValueDecorator(n)))); } }; @@ -190,9 +191,9 @@ class BinaryFunctionFunctor public: - BinaryFunctionFunctor( const ExpressionFunct eFunct, const ParserContextSharedPtr& rContext ) : + BinaryFunctionFunctor( const ExpressionFunct eFunct, ParserContextSharedPtr xContext ) : meFunct( eFunct ), - mpContext( rContext ) + mpContext(std::move( xContext )) { } @@ -223,8 +224,8 @@ class UnaryFunctionExpression : public ExpressionNode std::shared_ptr<ExpressionNode> mpArg; public: - explicit UnaryFunctionExpression( const std::shared_ptr<ExpressionNode>& rArg ) : - mpArg( rArg ) + explicit UnaryFunctionExpression( std::shared_ptr<ExpressionNode> xArg ) : + mpArg(std::move( xArg )) { } virtual ORowSetValueDecoratorRef evaluate(const ODatabaseMetaDataResultSet::ORow& _aRow ) const override @@ -242,8 +243,8 @@ class UnaryFunctionFunctor public: - explicit UnaryFunctionFunctor(const ParserContextSharedPtr& rContext) - : mpContext(rContext) + explicit UnaryFunctionFunctor(ParserContextSharedPtr xContext) + : mpContext(std::move(xContext)) { } void operator()( StringIteratorT, StringIteratorT ) const @@ -290,8 +291,8 @@ public: @param rParserContext Contains context info for the parser */ - explicit ExpressionGrammar( const ParserContextSharedPtr& rParserContext ) : - mpParserContext( rParserContext ) + explicit ExpressionGrammar( ParserContextSharedPtr xParserContext ) : + mpParserContext(std::move( xParserContext )) { } diff --git a/connectivity/source/commontools/TColumnsHelper.cxx b/connectivity/source/commontools/TColumnsHelper.cxx index a97faeeb8b4e..aeb8b48a649a 100644 --- a/connectivity/source/commontools/TColumnsHelper.cxx +++ b/connectivity/source/commontools/TColumnsHelper.cxx @@ -34,10 +34,8 @@ using namespace connectivity; using namespace dbtools; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; namespace connectivity { @@ -84,7 +82,7 @@ sdbcx::ObjectType OColumnsHelper::createObject(const OUString& _rName) if ( aFind == m_pImpl->m_aColumnInfo.end() ) // we have to fill it { OUString sComposedName = ::dbtools::composeTableNameForSelect( xConnection, m_pTable ); - collectColumnInformation(xConnection,sComposedName,"*" ,m_pImpl->m_aColumnInfo); + collectColumnInformation(xConnection,sComposedName,u"*" ,m_pImpl->m_aColumnInfo); aFind = m_pImpl->m_aColumnInfo.find(_rName); } if ( aFind != m_pImpl->m_aColumnInfo.end() ) @@ -111,7 +109,7 @@ sdbcx::ObjectType OColumnsHelper::createObject(const OUString& _rName) m_pTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)) >>= aCatalog; m_pTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) >>= aSchema; m_pTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) >>= aTable; - connectivity::sdbcx::OColumn* pRet = new connectivity::sdbcx::OColumn(_rName, + rtl::Reference<connectivity::sdbcx::OColumn> pRet = new connectivity::sdbcx::OColumn(_rName, pColDesc->aField6, pColDesc->sField13, pColDesc->sField12, @@ -186,7 +184,7 @@ sdbcx::ObjectType OColumnsHelper::appendObject( const OUString& _rForName, const void OColumnsHelper::dropObject(sal_Int32 /*_nPos*/, const OUString& _sElementName) { OSL_ENSURE(m_pTable,"OColumnsHelper::dropByName: Table is null!"); - if ( !(m_pTable && !m_pTable->isNew()) ) + if ( !m_pTable || m_pTable->isNew() ) return; Reference<XDatabaseMetaData> xMetaData = m_pTable->getConnection()->getMetaData(); diff --git a/connectivity/source/commontools/TConnection.cxx b/connectivity/source/commontools/TConnection.cxx index 134aa5960115..c730946a56b7 100644 --- a/connectivity/source/commontools/TConnection.cxx +++ b/connectivity/source/commontools/TConnection.cxx @@ -18,7 +18,6 @@ */ #include <TConnection.hxx> -#include <cppuhelper/typeprovider.hxx> #include <comphelper/servicehelper.hxx> #include <comphelper/types.hxx> #include <connectivity/dbexception.hxx> @@ -27,7 +26,6 @@ using namespace connectivity; using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::sdbc; -using namespace com::sun::star::beans; using namespace ::osl; @@ -57,16 +55,13 @@ void OMetaConnection::disposing() //XUnoTunnel sal_Int64 SAL_CALL OMetaConnection::getSomething( const css::uno::Sequence< sal_Int8 >& rId ) { - return (isUnoTunnelId<OMetaConnection>(rId)) - ? reinterpret_cast< sal_Int64 >( this ) - : sal_Int64(0); + return comphelper::getSomethingImpl(rId, this); } -Sequence< sal_Int8 > OMetaConnection::getUnoTunnelId() +const Sequence< sal_Int8 > & OMetaConnection::getUnoTunnelId() { - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); + static const comphelper::UnoIdInit implId; + return implId.getSeq(); } ::dbtools::OPropertyMap& OMetaConnection::getPropMap() @@ -75,7 +70,7 @@ Sequence< sal_Int8 > OMetaConnection::getUnoTunnelId() return s_aPropertyNameMap; } -void OMetaConnection::throwGenericSQLException(const char* pErrorResourceId, const Reference< XInterface>& _xContext ) +void OMetaConnection::throwGenericSQLException(TranslateId pErrorResourceId, const Reference< XInterface>& _xContext ) { OUString sErrorMessage; if (pErrorResourceId) diff --git a/connectivity/source/commontools/TDatabaseMetaDataBase.cxx b/connectivity/source/commontools/TDatabaseMetaDataBase.cxx index e5823278095e..bd2b7a467142 100644 --- a/connectivity/source/commontools/TDatabaseMetaDataBase.cxx +++ b/connectivity/source/commontools/TDatabaseMetaDataBase.cxx @@ -17,6 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <cstddef> + #include <TDatabaseMetaDataBase.hxx> #include <RowFunctionParser.hxx> @@ -139,11 +143,11 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getTypeInfo( ) ::connectivity::ODatabaseMetaDataResultSet::ORow aRow; aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); const sal_Int32* pType = pTypes; - for (sal_Int32 i = 1; i <= sal_Int32(SAL_N_ELEMENTS(pTypes)); ++i,++pType) + for (std::size_t i = 1; i <= std::size(pTypes); ++i,++pType) { ORowSetValue aValue; aValue.fill(i,*pType,xRow); - aRow.push_back(new ORowSetValueDecorator(aValue)); + aRow.push_back(new ORowSetValueDecorator(std::move(aValue))); } std::vector<std::shared_ptr<ExpressionNode>>::iterator aIter = aConditions.begin(); @@ -163,10 +167,9 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getTypeInfo( ) m_aTypeInfoRows = aTypeInfoRows; } } - ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo); - Reference< XResultSet > xRet = pResult; - pResult->setRows(m_aTypeInfoRows); - return xRet; + rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo); + pResult->setRows(std::vector(m_aTypeInfoRows)); + return pResult; } Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getExportedKeys( diff --git a/connectivity/source/commontools/TIndex.cxx b/connectivity/source/commontools/TIndex.cxx index f7f891308e40..32112bcdbe17 100644 --- a/connectivity/source/commontools/TIndex.cxx +++ b/connectivity/source/commontools/TIndex.cxx @@ -27,10 +27,7 @@ using namespace connectivity; using namespace connectivity::sdbcx; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; OIndexHelper::OIndexHelper( OTableHelper* _pTable) : connectivity::sdbcx::OIndex(true) , m_pTable(_pTable) diff --git a/connectivity/source/commontools/TIndexColumns.cxx b/connectivity/source/commontools/TIndexColumns.cxx index bbb5ca706f20..d190bb2af312 100644 --- a/connectivity/source/commontools/TIndexColumns.cxx +++ b/connectivity/source/commontools/TIndexColumns.cxx @@ -30,8 +30,6 @@ using namespace connectivity::sdbcx; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; OIndexColumns::OIndexColumns( OIndexHelper* _pIndex, ::osl::Mutex& _rMutex, @@ -82,17 +80,16 @@ sdbcx::ObjectType OIndexColumns::createObject(const OUString& _rName) sal_Int32 nNull = xRow->getInt(11); OUString aColumnDef(xRow->getString(13)); - OIndexColumn* pRet = new OIndexColumn(bAsc, - _rName, - aTypeName, - aColumnDef, - nNull, - nSize, - nDec, - nDataType, - true, - aCatalog, aSchema, aTable); - xRet = pRet; + xRet = new OIndexColumn(bAsc, + _rName, + aTypeName, + aColumnDef, + nNull, + nSize, + nDec, + nDataType, + true, + aCatalog, aSchema, aTable); break; } } diff --git a/connectivity/source/commontools/TIndexes.cxx b/connectivity/source/commontools/TIndexes.cxx index f5cff00ec835..723b4a447a18 100644 --- a/connectivity/source/commontools/TIndexes.cxx +++ b/connectivity/source/commontools/TIndexes.cxx @@ -37,7 +37,6 @@ using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; using namespace cppu; @@ -101,10 +100,9 @@ sdbcx::ObjectType OIndexesHelper::createObject(const OUString& _rName) catch(const Exception&) { } - OIndexHelper* pRet = new OIndexHelper(m_pTable,aName,aQualifier,bUnique, + xRet = new OIndexHelper(m_pTable,aName,aQualifier,bUnique, bPrimarKeyIndex, nClustered == IndexType::CLUSTERED); - xRet = pRet; break; } } @@ -153,10 +151,10 @@ sdbcx::ObjectType OIndexesHelper::appendObject( const OUString& _rForName, const OUString aComposedName = dbtools::composeTableName(m_pTable->getMetaData(),aCatalog,aSchema,aTable, true, ::dbtools::EComposeRule::InIndexDefinitions); if (!_rForName.isEmpty() ) { - aSql.append( ::dbtools::quoteName( aQuote, _rForName ) ); - aSql.append(" ON "); - aSql.append(aComposedName); - aSql.append(" ( "); + aSql.append( ::dbtools::quoteName( aQuote, _rForName ) + + " ON " + + aComposedName + + " ( "); Reference<XColumnsSupplier> xColumnSup(descriptor,UNO_QUERY); Reference<XIndexAccess> xColumns(xColumnSup->getColumns(),UNO_QUERY); @@ -193,8 +191,8 @@ sdbcx::ObjectType OIndexesHelper::appendObject( const OUString& _rForName, const xColumns->getByIndex(0) >>= xColProp; - aSql.append("."); - aSql.append(::dbtools::quoteName( aQuote,comphelper::getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME))))); + aSql.append("." + + ::dbtools::quoteName( aQuote,comphelper::getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME))))); } Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); @@ -213,7 +211,7 @@ sdbcx::ObjectType OIndexesHelper::appendObject( const OUString& _rForName, const void OIndexesHelper::dropObject(sal_Int32 /*_nPos*/,const OUString& _sElementName) { Reference< XConnection> xConnection = m_pTable->getConnection(); - if( !(xConnection.is() && !m_pTable->isNew())) + if( !xConnection.is() || m_pTable->isNew() ) return; if ( m_pTable->getIndexService().is() ) diff --git a/connectivity/source/commontools/TKey.cxx b/connectivity/source/commontools/TKey.cxx index 1341291abcf3..3a16cf86a5a0 100644 --- a/connectivity/source/commontools/TKey.cxx +++ b/connectivity/source/commontools/TKey.cxx @@ -26,10 +26,7 @@ using namespace connectivity; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; OTableKeyHelper::OTableKeyHelper(OTableHelper* _pTable) : connectivity::sdbcx::OKey(true) ,m_pTable(_pTable) diff --git a/connectivity/source/commontools/TKeyColumns.cxx b/connectivity/source/commontools/TKeyColumns.cxx index acbfc54bf000..a26628765417 100644 --- a/connectivity/source/commontools/TKeyColumns.cxx +++ b/connectivity/source/commontools/TKeyColumns.cxx @@ -31,8 +31,6 @@ using namespace connectivity::sdbcx; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; OKeyColumnsHelper::OKeyColumnsHelper( OTableKeyHelper* _pKey, @@ -99,19 +97,18 @@ sdbcx::ObjectType OKeyColumnsHelper::createObject(const OUString& _rName) // sometimes we get an error when asking for this param } - OKeyColumn* pRet = new OKeyColumn(aRefColumnName, - _rName, - aTypeName, - sColumnDef, - nNull, - nSize, - nDec, - nDataType, - isCaseSensitive(), - aCatalog, - aSchema, - aTable); - xRet = pRet; + xRet = new OKeyColumn(aRefColumnName, + _rName, + aTypeName, + sColumnDef, + nNull, + nSize, + nDec, + nDataType, + isCaseSensitive(), + aCatalog, + aSchema, + aTable); } } } diff --git a/connectivity/source/commontools/TKeys.cxx b/connectivity/source/commontools/TKeys.cxx index 742a1832049a..427ab524162e 100644 --- a/connectivity/source/commontools/TKeys.cxx +++ b/connectivity/source/commontools/TKeys.cxx @@ -40,7 +40,6 @@ using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; OKeysHelper::OKeysHelper( OTableHelper* _pTable, @@ -57,14 +56,12 @@ sdbcx::ObjectType OKeysHelper::createObject(const OUString& _rName) if(!_rName.isEmpty()) { - OTableKeyHelper* pRet = new OTableKeyHelper(m_pTable,_rName,m_pTable->getKeyProperties(_rName)); - xRet = pRet; + xRet = new OTableKeyHelper(m_pTable,_rName,m_pTable->getKeyProperties(_rName)); } if(!xRet.is()) // we have a primary key with a system name { - OTableKeyHelper* pRet = new OTableKeyHelper(m_pTable,_rName,m_pTable->getKeyProperties(_rName)); - xRet = pRet; + xRet = new OTableKeyHelper(m_pTable,_rName,m_pTable->getKeyProperties(_rName)); } return xRet; @@ -157,12 +154,11 @@ sdbcx::ObjectType OKeysHelper::appendObject( const OUString& _rForName, const Re { // if we're here, we belong to a table which is not new, i.e. already exists in the database. // In this case, really append the new index. - OUStringBuffer aSql; - aSql.append("ALTER TABLE "); + OUStringBuffer aSql("ALTER TABLE "); OUString aQuote = m_pTable->getConnection()->getMetaData()->getIdentifierQuoteString( ); - aSql.append(composeTableName( m_pTable->getConnection()->getMetaData(), m_pTable, ::dbtools::EComposeRule::InTableDefinitions, true )); - aSql.append(" ADD "); + aSql.append(composeTableName( m_pTable->getConnection()->getMetaData(), m_pTable, ::dbtools::EComposeRule::InTableDefinitions, true ) + + " ADD "); if ( nKeyType == KeyType::PRIMARY ) { @@ -190,9 +186,9 @@ sdbcx::ObjectType OKeysHelper::appendObject( const OUString& _rForName, const Re if ( nKeyType == KeyType::FOREIGN ) { - aSql.append(" REFERENCES "); - aSql.append(::dbtools::quoteTableName(m_pTable->getConnection()->getMetaData(),sReferencedName,::dbtools::EComposeRule::InTableDefinitions)); - aSql.append(" ("); + aSql.append(" REFERENCES " + + ::dbtools::quoteTableName(m_pTable->getConnection()->getMetaData(),sReferencedName,::dbtools::EComposeRule::InTableDefinitions) + + " ("); for(sal_Int32 i=0;i<xColumns->getCount();++i) { @@ -202,9 +198,9 @@ sdbcx::ObjectType OKeysHelper::appendObject( const OUString& _rForName, const Re aSql.append(::dbtools::quoteName( aQuote,getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_RELATEDCOLUMN))))); } - aSql.append(")"); - aSql.append(getKeyRuleString(true ,nUpdateRule)); - aSql.append(getKeyRuleString(false ,nDeleteRule)); + aSql.append(")" + + getKeyRuleString(true ,nUpdateRule) + + getKeyRuleString(false ,nDeleteRule)); } Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); @@ -238,7 +234,7 @@ sdbcx::ObjectType OKeysHelper::appendObject( const OUString& _rForName, const Re OUString sName = xRow->getString(nColumn); if ( !m_pElements->exists(sName) ) // this name wasn't inserted yet so it must be the new one { - descriptor->setPropertyValue( rPropMap.getNameByIndex( PROPERTY_ID_NAME ), makeAny( sName ) ); + descriptor->setPropertyValue( rPropMap.getNameByIndex( PROPERTY_ID_NAME ), Any( sName ) ); sNewName = sName; break; } @@ -264,7 +260,7 @@ OUString OKeysHelper::getDropForeignKey() const void OKeysHelper::dropObject(sal_Int32 _nPos, const OUString& _sElementName) { Reference< XConnection> xConnection = m_pTable->getConnection(); - if ( !(xConnection.is() && !m_pTable->isNew()) ) + if ( !xConnection.is() || m_pTable->isNew() ) return; Reference<XPropertySet> xKey(getObject(_nPos),UNO_QUERY); @@ -274,10 +270,9 @@ void OKeysHelper::dropObject(sal_Int32 _nPos, const OUString& _sElementName) } else { - OUStringBuffer aSql; - aSql.append("ALTER TABLE "); - - aSql.append( composeTableName( m_pTable->getConnection()->getMetaData(), m_pTable,::dbtools::EComposeRule::InTableDefinitions, true )); + OUStringBuffer aSql( + "ALTER TABLE " + + composeTableName( m_pTable->getConnection()->getMetaData(), m_pTable,::dbtools::EComposeRule::InTableDefinitions, true )); sal_Int32 nKeyType = KeyType::PRIMARY; if ( xKey.is() ) diff --git a/connectivity/source/commontools/TPrivilegesResultSet.cxx b/connectivity/source/commontools/TPrivilegesResultSet.cxx index de255d3cb8c1..71a6986239f5 100644 --- a/connectivity/source/commontools/TPrivilegesResultSet.cxx +++ b/connectivity/source/commontools/TPrivilegesResultSet.cxx @@ -21,9 +21,7 @@ using namespace connectivity; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; using namespace ::com::sun::star::lang; @@ -38,11 +36,8 @@ OResultSetPrivileges::OResultSetPrivileges( const Reference< XDatabaseMetaData>& osl_atomic_increment( &m_refCount ); { OUString sUserWorkingFor; - Sequence< OUString > sTableTypes(3); // we want all catalogues, all schemas, all tables - sTableTypes[0] = "VIEW"; - sTableTypes[1] = "TABLE"; - sTableTypes[2] = "%"; // just to be sure to include anything else... + Sequence< OUString > sTableTypes {"VIEW", "TABLE", "%"}; // this last one is just to be sure to include anything else... try { m_xTables = _rxMeta->getTables(catalog,schemaPattern,tableNamePattern,sTableTypes); @@ -77,7 +72,7 @@ OResultSetPrivileges::OResultSetPrivileges( const Reference< XDatabaseMetaData>& aRow[6] = new ORowSetValueDecorator(OUString("REFERENCE")); aRows.push_back(aRow); - setRows(aRows); + setRows(std::move(aRows)); } osl_atomic_decrement( &m_refCount ); } @@ -107,17 +102,17 @@ const ORowSetValue& OResultSetPrivileges::getValue(sal_Int32 columnIndex) return ODatabaseMetaDataResultSet::getValue(columnIndex); } -void SAL_CALL OResultSetPrivileges::disposing() +void OResultSetPrivileges::disposing(std::unique_lock<std::mutex>& rGuard) { - ODatabaseMetaDataResultSet::disposing(); + ODatabaseMetaDataResultSet::disposing(rGuard); m_xTables.clear(); m_xRow.clear(); } sal_Bool SAL_CALL OResultSetPrivileges::next( ) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed ); + std::unique_lock aGuard( m_aMutex ); + throwIfDisposed(aGuard); bool bReturn = false; if ( m_xTables.is() ) @@ -129,7 +124,7 @@ sal_Bool SAL_CALL OResultSetPrivileges::next( ) return false; } - bReturn = ODatabaseMetaDataResultSet::next(); + bReturn = ODatabaseMetaDataResultSet::next(aGuard); if ( !bReturn ) { m_bBOF = false; diff --git a/connectivity/source/commontools/TSkipDeletedSet.cxx b/connectivity/source/commontools/TSkipDeletedSet.cxx index d3ae392f7a09..701bd743f6c0 100644 --- a/connectivity/source/commontools/TSkipDeletedSet.cxx +++ b/connectivity/source/commontools/TSkipDeletedSet.cxx @@ -171,7 +171,7 @@ bool OSkipDeletedSet::moveAbsolute(sal_Int32 _nPos,bool _bRetrieveData) { // bookmark isn't known yet // start at the last known position - sal_Int32 nCurPos = 0,nLastBookmark = 1; + sal_Int32 nCurPos = 0; if ( m_aBookmarksPositions.empty() ) { bDataFound = m_pHelper->move(IResultSetHelper::FIRST, 0, _bRetrieveData ); @@ -185,7 +185,7 @@ bool OSkipDeletedSet::moveAbsolute(sal_Int32 _nPos,bool _bRetrieveData) } // if ( m_aBookmarksPositions.empty() ) else { - nLastBookmark = (*m_aBookmarksPositions.rbegin())/*->first*/; + sal_Int32 nLastBookmark = *m_aBookmarksPositions.rbegin()/*->first*/; nCurPos = /*(**/m_aBookmarksPositions.size()/*->second*/; nNewPos = nNewPos - nCurPos; bDataFound = m_pHelper->move(IResultSetHelper::BOOKMARK, nLastBookmark, _bRetrieveData); diff --git a/connectivity/source/commontools/TSortIndex.cxx b/connectivity/source/commontools/TSortIndex.cxx index 6b94216a3719..44a883dc86c4 100644 --- a/connectivity/source/commontools/TSortIndex.cxx +++ b/connectivity/source/commontools/TSortIndex.cxx @@ -94,10 +94,10 @@ struct TKeyValueFunc return pKeySet; } -OSortIndex::OSortIndex( const std::vector<OKeyType>& _aKeyType, - const std::vector<TAscendingOrder>& _aAscending) - :m_aKeyType(_aKeyType) - ,m_aAscending(_aAscending) +OSortIndex::OSortIndex( std::vector<OKeyType>&& _aKeyType, + std::vector<TAscendingOrder>&& _aAscending) + :m_aKeyType(std::move(_aKeyType)) + ,m_aAscending(std::move(_aAscending)) ,m_bFrozen(false) { } diff --git a/connectivity/source/commontools/TTableHelper.cxx b/connectivity/source/commontools/TTableHelper.cxx index e86af9673052..27c874636069 100644 --- a/connectivity/source/commontools/TTableHelper.cxx +++ b/connectivity/source/commontools/TTableHelper.cxx @@ -72,6 +72,11 @@ public: } virtual void SAL_CALL elementRemoved( const css::container::ContainerEvent& Event ) override { + // tdf#137745, perhaps connectivity::OTableHelper::disposing() has been called + // which called OTableContainerListener::clear(), so m_pComponent may be null + if (m_pComponent == nullptr) + return; + OUString sName; Event.Accessor >>= sName; if ( m_aRefNames.find(sName) != m_aRefNames.end() ) @@ -176,7 +181,7 @@ void SAL_CALL OTableHelper::disposing() ::osl::MutexGuard aGuard(m_aMutex); if ( m_pImpl->m_xTablePropertyListener.is() ) { - m_pTables->removeContainerListener(m_pImpl->m_xTablePropertyListener.get()); + m_pTables->removeContainerListener(m_pImpl->m_xTablePropertyListener); m_pImpl->m_xTablePropertyListener->clear(); m_pImpl->m_xTablePropertyListener.clear(); } @@ -195,20 +200,17 @@ namespace void lcl_collectColumnDescs_throw( const Reference< XResultSet >& _rxResult, std::vector< ColumnDesc >& _out_rColumns ) { Reference< XRow > xRow( _rxResult, UNO_QUERY_THROW ); - OUString sName; - OrdinalPosition nOrdinalPosition( 0 ); while ( _rxResult->next() ) { - sName = xRow->getString( 4 ); // COLUMN_NAME - sal_Int32 nField5 = xRow->getInt(5); - OUString aField6 = xRow->getString(6); - sal_Int32 nField7 = xRow->getInt(7) - , nField9 = xRow->getInt(9) - , nField11= xRow->getInt(11); - OUString sField12 = xRow->getString(12) - ,sField13 = xRow->getString(13); - nOrdinalPosition = xRow->getInt( 17 ); // ORDINAL_POSITION - _out_rColumns.push_back( ColumnDesc( sName,nField5,aField6,nField7,nField9,nField11,sField12,sField13, nOrdinalPosition ) ); + _out_rColumns.emplace_back(xRow->getString(4), // COLUMN_NAME, + xRow->getInt(5), + xRow->getString(6), + xRow->getInt(7), + xRow->getInt(9), + xRow->getInt(11), + xRow->getString(12), + xRow->getString(13), + xRow->getInt(17)); // ORDINAL_POSITION } } @@ -291,7 +293,7 @@ void OTableHelper::refreshColumns() if(m_xColumns) m_xColumns->reFill(aVector); else - m_xColumns = createColumns(aVector); + m_xColumns.reset(createColumns(aVector)); } const ColumnDesc* OTableHelper::getColumnDescription(const OUString& _sName) const @@ -382,7 +384,7 @@ void OTableHelper::refreshForeignKeys(::std::vector< OUString>& _rNames) { if ( !m_pImpl->m_xTablePropertyListener.is() ) m_pImpl->m_xTablePropertyListener = new OTableContainerListener(this); - m_pTables->addContainerListener(m_pImpl->m_xTablePropertyListener.get()); + m_pTables->addContainerListener(m_pImpl->m_xTablePropertyListener); m_pImpl->m_xTablePropertyListener->add(sReferencedName); } // if ( m_pTables->hasByName(sReferencedName) ) sOldFKName = sFkName; @@ -408,10 +410,10 @@ void OTableHelper::refreshKeys() { refreshPrimaryKeys(aNames); refreshForeignKeys(aNames); - m_xKeys = createKeys(aNames); + m_xKeys.reset(createKeys(aNames)); } // if(!isNew()) else if (!m_xKeys ) - m_xKeys = createKeys(aNames); + m_xKeys.reset(createKeys(aNames)); /*if(m_pKeys) m_pKeys->reFill(aVector); else*/ @@ -455,7 +457,7 @@ void OTableHelper::refreshIndexes() if(m_xIndexes) m_xIndexes->reFill(aVector); else - m_xIndexes = createIndexes(aVector); + m_xIndexes.reset(createIndexes(aVector)); } OUString OTableHelper::getRenameStart() const @@ -544,6 +546,11 @@ OUString SAL_CALL OTableHelper::getName() return sComposedName; } +const OUString & OTableHelper::getTableName() +{ + return m_Name; +} + std::shared_ptr<sdbcx::KeyProperties> OTableHelper::getKeyProperties(const OUString& _sName) const { std::shared_ptr<sdbcx::KeyProperties> pKeyProps; diff --git a/connectivity/source/commontools/conncleanup.cxx b/connectivity/source/commontools/conncleanup.cxx index c33cc7289a65..7b703f093c80 100644 --- a/connectivity/source/commontools/conncleanup.cxx +++ b/connectivity/source/commontools/conncleanup.cxx @@ -23,7 +23,7 @@ #include <com/sun/star/sdbc/XRowSet.hpp> #include <com/sun/star/sdbc/XConnection.hpp> #include <osl/diagnose.h> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> namespace dbtools @@ -35,7 +35,7 @@ namespace dbtools using namespace css::sdbc; using namespace css::lang; - const char ACTIVE_CONNECTION_PROPERTY_NAME[] = "ActiveConnection"; + constexpr OUString ACTIVE_CONNECTION_PROPERTY_NAME = u"ActiveConnection"_ustr; OAutoConnectionDisposer::OAutoConnectionDisposer(const Reference< XRowSet >& _rxRowSet, const Reference< XConnection >& _rxConnection) :m_xRowSet( _rxRowSet ) @@ -50,7 +50,7 @@ namespace dbtools try { - xProps->setPropertyValue( ACTIVE_CONNECTION_PROPERTY_NAME, makeAny( _rxConnection ) ); + xProps->setPropertyValue( ACTIVE_CONNECTION_PROPERTY_NAME, Any( _rxConnection ) ); m_xOriginalConnection = _rxConnection; startPropertyListening( xProps ); } @@ -78,7 +78,7 @@ namespace dbtools void OAutoConnectionDisposer::stopPropertyListening( const Reference< XPropertySet >& _rxEventSource ) { // prevent deletion of ourself while we're herein - Reference< XInterface > xKeepAlive(static_cast< XWeak* >(this)); + Reference< XInterface > xKeepAlive(getXWeak()); try { // remove ourself as property change listener diff --git a/connectivity/source/commontools/dbcharset.cxx b/connectivity/source/commontools/dbcharset.cxx index ebe45c028207..381afa606e08 100644 --- a/connectivity/source/commontools/dbcharset.cxx +++ b/connectivity/source/commontools/dbcharset.cxx @@ -18,6 +18,7 @@ */ #include <connectivity/dbcharset.hxx> +#include <utility> #include <osl/diagnose.h> #include <rtl/tencinfo.h> @@ -92,15 +93,15 @@ namespace dbtools } - OCharsetMap::CharsetIterator OCharsetMap::findIanaName(const OUString& _rIanaName) const + OCharsetMap::CharsetIterator OCharsetMap::findIanaName(std::u16string_view _rIanaName) const { ensureConstructed( ); rtl_TextEncoding eEncoding = RTL_TEXTENCODING_DONTKNOW; - if ( !_rIanaName.isEmpty() ) + if ( !_rIanaName.empty() ) { // byte string conversion - OString sMimeByteString( _rIanaName.getStr(), _rIanaName.getLength(), RTL_TEXTENCODING_ASCII_US ); + OString sMimeByteString = OUStringToOString( _rIanaName, RTL_TEXTENCODING_ASCII_US ); // look up eEncoding = rtl_getTextEncodingFromMimeCharset( sMimeByteString.getStr() ); @@ -129,15 +130,15 @@ namespace dbtools } - CharsetIteratorDerefHelper:: CharsetIteratorDerefHelper(const rtl_TextEncoding _eEncoding, const OUString& _rIanaName ) + CharsetIteratorDerefHelper:: CharsetIteratorDerefHelper(const rtl_TextEncoding _eEncoding, OUString _aIanaName ) :m_eEncoding( _eEncoding ) - ,m_aIanaName( _rIanaName ) + ,m_aIanaName(std::move( _aIanaName )) { } - OCharsetMap::CharsetIterator::CharsetIterator(const OCharsetMap* _pContainer, OCharsetMap::TextEncBag::const_iterator const & _aPos ) + OCharsetMap::CharsetIterator::CharsetIterator(const OCharsetMap* _pContainer, OCharsetMap::TextEncBag::const_iterator _aPos ) :m_pContainer( _pContainer ) - ,m_aPos( _aPos ) + ,m_aPos(std::move( _aPos )) { OSL_ENSURE( m_pContainer, "OCharsetMap::CharsetIterator::CharsetIterator : invalid container!" ); } diff --git a/connectivity/source/commontools/dbconversion.cxx b/connectivity/source/commontools/dbconversion.cxx index dbe942a3fd01..4dd7d5b8e9f3 100644 --- a/connectivity/source/commontools/dbconversion.cxx +++ b/connectivity/source/commontools/dbconversion.cxx @@ -18,15 +18,16 @@ */ #include <connectivity/dbconversion.hxx> -#include <osl/diagnose.h> #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/util/Date.hpp> #include <com/sun/star/util/Time.hpp> #include <com/sun/star/util/DateTime.hpp> #include <rtl/character.hxx> -#include <rtl/ustrbuf.hxx> #include <rtl/math.hxx> +#include <sal/log.hxx> #include <unotools/datetime.hxx> +#include <comphelper/date.hxx> +#include <o3tl/string_view.hxx> #include <sstream> #include <iomanip> @@ -61,7 +62,6 @@ namespace dbtools using namespace ::com::sun::star::uno; using namespace ::com::sun::star::util; using namespace ::com::sun::star::sdb; - using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::beans; @@ -80,7 +80,7 @@ namespace dbtools ostr << setw(4) << rDate.Year << "-" << setw(2) << rDate.Month << "-" << setw(2) << rDate.Day; - return OUString::createFromAscii(ostr.str().c_str()); + return OUString::createFromAscii(ostr.str()); } OUString DBTypeConversion::toTimeStringS(const css::util::Time& rTime) @@ -91,7 +91,7 @@ namespace dbtools ostr << setw(2) << rTime.Hours << ":" << setw(2) << rTime.Minutes << ":" << setw(2) << rTime.Seconds; - return OUString::createFromAscii(ostr.str().c_str()); + return OUString::createFromAscii(ostr.str()); } OUString DBTypeConversion::toTimeString(const css::util::Time& rTime) @@ -103,18 +103,15 @@ namespace dbtools << setw(2) << rTime.Minutes << ":" << setw(2) << rTime.Seconds << "." << setw(9) << rTime.NanoSeconds; - return OUString::createFromAscii(ostr.str().c_str()); + return OUString::createFromAscii(ostr.str()); } OUString DBTypeConversion::toDateTimeString(const css::util::DateTime& _rDateTime) { css::util::Date aDate(_rDateTime.Day,_rDateTime.Month,_rDateTime.Year); - OUStringBuffer aTemp(toDateString(aDate)); - aTemp.append(" "); css::util::Time const aTime(_rDateTime.NanoSeconds, _rDateTime.Seconds, _rDateTime.Minutes, _rDateTime.Hours, _rDateTime.IsUTC); - aTemp.append( toTimeString(aTime) ); - return aTemp.makeStringAndClear(); + return toDateString(aDate) + " " + toTimeString(aTime); } css::util::Date DBTypeConversion::toDate(const sal_Int32 _nVal) @@ -151,93 +148,25 @@ namespace dbtools nHour * (minInHour * secInMin * nanoSecInSec); } - - const sal_Int32 aDaysInMonth[12] = { 31, 28, 31, 30, 31, 30, - 31, 31, 30, 31, 30, 31 }; - - - static bool implIsLeapYear(sal_Int32 _nYear) - { - return ( ((_nYear % 4) == 0) - && ((_nYear % 100) != 0) - ) - - || ((_nYear % 400) == 0) - ; - } - - - static sal_Int32 implDaysInMonth(sal_Int32 _nMonth, sal_Int32 _nYear) - { - OSL_ENSURE(_nMonth > 0 && _nMonth < 13,"Month as invalid value!"); - if (_nMonth != 2) - return aDaysInMonth[_nMonth-1]; - else - { - if (implIsLeapYear(_nYear)) - return aDaysInMonth[_nMonth-1] + 1; - else - return aDaysInMonth[_nMonth-1]; - } - } - - static sal_Int32 implRelativeToAbsoluteNull(const css::util::Date& _rDate) { - sal_Int32 nDays = 0; - - // ripped this code from the implementation of tools::Date - sal_Int32 nNormalizedYear = _rDate.Year - 1; - nDays = nNormalizedYear * 365; - // leap years - nDays += (nNormalizedYear / 4) - (nNormalizedYear / 100) + (nNormalizedYear / 400); - - for (sal_Int32 i = 1; i < _rDate.Month; ++i) - nDays += implDaysInMonth(i, _rDate.Year); - - nDays += _rDate.Day; - return nDays; - } - - static void implBuildFromRelative( const sal_Int32 nDays, sal_uInt16& rDay, sal_uInt16& rMonth, sal_Int16& rYear) - { - sal_Int32 nTempDays; - sal_Int32 i = 0; - bool bCalc; - - do + if (_rDate.Day == 0 && _rDate.Month == 0 && _rDate.Year == 0) { - nTempDays = nDays; - rYear = static_cast<sal_uInt16>((nTempDays / 365) - i); - nTempDays -= (rYear-1) * 365; - nTempDays -= ((rYear-1) / 4) - ((rYear-1) / 100) + ((rYear-1) / 400); - bCalc = false; - if ( nTempDays < 1 ) - { - i++; - bCalc = true; - } - else - { - if ( nTempDays > 365 ) - { - if ( (nTempDays != 366) || !implIsLeapYear( rYear ) ) - { - i--; - bCalc = true; - } - } - } + // 0000-00-00 is *NOT* a valid date and passing it to the date + // conversion even when normalizing rightly asserts. Whatever we + // return here, it will be wrong. The old before commit + // 52ff16771ac160d27fd7beb78a4cfba22ad84f06 wrong implementation + // calculated -365 for that, effectively that would be a date of + // -0001-01-01 now but it was likely assumed that would be + // 0000-00-01 or even 0000-00-00 instead. Try if we get away with 0 + // for -0001-12-31, the same that + // comphelper::date::convertDateToDaysNormalizing() + // would return if comphelper::date::normalize() wouldn't ignore + // such "empty" date. + + return 0; } - while ( bCalc ); - - rMonth = 1; - while ( nTempDays > implDaysInMonth( rMonth, rYear ) ) - { - nTempDays -= implDaysInMonth( rMonth, rYear ); - rMonth++; - } - rDay = static_cast<sal_uInt16>(nTempDays); + return comphelper::date::convertDateToDaysNormalizing( _rDate.Day, _rDate.Month, _rDate.Year); } sal_Int32 DBTypeConversion::toDays(const css::util::Date& _rVal, const css::util::Date& _rNullDate) @@ -273,7 +202,7 @@ namespace dbtools static void addDays(const sal_Int32 nDays, css::util::Date& _rDate) { - sal_Int32 nTempDays = implRelativeToAbsoluteNull( _rDate ); + sal_Int64 nTempDays = implRelativeToAbsoluteNull(_rDate); nTempDays += nDays; if ( nTempDays > maxDays ) @@ -283,7 +212,6 @@ namespace dbtools _rDate.Year = 9999; } // TODO: can we replace that check by minDays? Would allow dates BCE - // implBuildFromRelative probably needs to be updated for the "no year 0" question else if ( nTempDays <= 0 ) { _rDate.Day = 1; @@ -291,12 +219,12 @@ namespace dbtools _rDate.Year = 1; } else - implBuildFromRelative( nTempDays, _rDate.Day, _rDate.Month, _rDate.Year ); + comphelper::date::convertDaysToDate( nTempDays, _rDate.Day, _rDate.Month, _rDate.Year ); } static void subDays(const sal_Int32 nDays, css::util::Date& _rDate ) { - sal_Int32 nTempDays = implRelativeToAbsoluteNull( _rDate ); + sal_Int64 nTempDays = implRelativeToAbsoluteNull(_rDate); nTempDays -= nDays; if ( nTempDays > maxDays ) @@ -306,7 +234,6 @@ namespace dbtools _rDate.Year = 9999; } // TODO: can we replace that check by minDays? Would allow dates BCE - // implBuildFromRelative probably needs to be updated for the "no year 0" question else if ( nTempDays <= 0 ) { _rDate.Day = 1; @@ -314,7 +241,7 @@ namespace dbtools _rDate.Year = 1; } else - implBuildFromRelative( nTempDays, _rDate.Day, _rDate.Month, _rDate.Year ); + comphelper::date::convertDaysToDate( nTempDays, _rDate.Day, _rDate.Month, _rDate.Year ); } css::util::Date DBTypeConversion::toDate(const double dVal, const css::util::Date& _rNullDate) @@ -332,13 +259,10 @@ namespace dbtools css::util::Time DBTypeConversion::toTime(const double dVal, short nDigits) { - const sal_Int32 nDays = static_cast<sal_Int32>(dVal); - sal_Int64 nNS; - { - double fSeconds((dVal - static_cast<double>(nDays)) * (fNanoSecondsPerDay / nanoSecInSec)); - fSeconds = ::rtl::math::round( fSeconds, nDigits ); - nNS = fSeconds * nanoSecInSec; - } + const double nDays = std::trunc(dVal); + double fSeconds((dVal - nDays) * (fNanoSecondsPerDay / nanoSecInSec)); + fSeconds = ::rtl::math::round(fSeconds, nDigits); + sal_Int64 nNS = fSeconds * nanoSecInSec; sal_Int16 nSign; if ( nNS < 0 ) @@ -380,6 +304,14 @@ namespace dbtools css::util::DateTime DBTypeConversion::toDateTime(const double dVal, const css::util::Date& _rNullDate) { + css::util::DateTime aRet; + + if (!std::isfinite(dVal)) + { + SAL_WARN("connectivity.commontools", "DateTime has invalid value: " << dVal); + return aRet; + } + css::util::Date aDate = toDate(dVal, _rNullDate); // there is not enough precision in a double to have both a date // and a time up to nanoseconds -> limit to microseconds to have @@ -387,8 +319,6 @@ namespace dbtools // 12:59:59.999999790 css::util::Time aTime = toTime(dVal, 6); - css::util::DateTime aRet; - aRet.Day = aDate.Day; aRet.Month = aDate.Month; aRet.Year = aDate.Year; @@ -402,7 +332,7 @@ namespace dbtools return aRet; } - css::util::Date DBTypeConversion::toDate(const OUString& _sSQLString) + css::util::Date DBTypeConversion::toDate(std::u16string_view _sSQLString) { // get the token out of a string static const sal_Unicode sDateSep = '-'; @@ -411,12 +341,12 @@ namespace dbtools sal_uInt16 nYear = 0, nMonth = 0, nDay = 0; - nYear = static_cast<sal_uInt16>(_sSQLString.getToken(0,sDateSep,nIndex).toInt32()); + nYear = static_cast<sal_uInt16>(o3tl::toInt32(o3tl::getToken(_sSQLString, 0,sDateSep,nIndex))); if(nIndex != -1) { - nMonth = static_cast<sal_uInt16>(_sSQLString.getToken(0,sDateSep,nIndex).toInt32()); + nMonth = static_cast<sal_uInt16>(o3tl::toInt32(o3tl::getToken(_sSQLString, 0,sDateSep,nIndex))); if(nIndex != -1) - nDay = static_cast<sal_uInt16>(_sSQLString.getToken(0,sDateSep,nIndex).toInt32()); + nDay = static_cast<sal_uInt16>(o3tl::toInt32(o3tl::getToken(_sSQLString, 0,sDateSep,nIndex))); } return css::util::Date(nDay,nMonth,nYear); @@ -439,7 +369,7 @@ namespace dbtools const sal_Unicode *const begin = p; while (rtl::isAsciiWhiteSpace(*p)) { ++p; } nSeparation += p - begin; - aTime = toTime( _sSQLString.copy( nSeparation ) ); + aTime = toTime( _sSQLString.subView( nSeparation ) ); } return css::util::DateTime(aTime.NanoSeconds, aTime.Seconds, aTime.Minutes, aTime.Hours, @@ -447,7 +377,7 @@ namespace dbtools } - css::util::Time DBTypeConversion::toTime(const OUString& _sSQLString) + css::util::Time DBTypeConversion::toTime(std::u16string_view _sSQLString) { css::util::Time aTime; ::utl::ISO8601parseTime(_sSQLString, aTime); diff --git a/connectivity/source/commontools/dbexception.cxx b/connectivity/source/commontools/dbexception.cxx index f15237d82c88..bc5a9be80804 100644 --- a/connectivity/source/commontools/dbexception.cxx +++ b/connectivity/source/commontools/dbexception.cxx @@ -27,6 +27,7 @@ #include <com/sun/star/sdb/SQLErrorEvent.hpp> #include <strings.hrc> #include <resource/sharedresources.hxx> +#include <comphelper/diagnose_ex.hxx> namespace dbtools { @@ -65,8 +66,7 @@ SQLExceptionInfo::SQLExceptionInfo(const css::sdb::SQLContext& _rError) SQLExceptionInfo::SQLExceptionInfo( const OUString& _rSimpleErrorMessage ) { - SQLException aError; - aError.Message = _rSimpleErrorMessage; + SQLException aError(_rSimpleErrorMessage, {}, {}, 0, {}); m_aContent <<= aError; implDetermineType(); } @@ -176,54 +176,59 @@ SQLExceptionInfo::operator const css::sdb::SQLContext*() const void SQLExceptionInfo::prepend( const OUString& _rErrorMessage ) { - SQLException aException; - aException.Message = _rErrorMessage; - aException.ErrorCode = 0; - aException.SQLState = "S1000"; - aException.NextException = m_aContent; + SQLException aException(_rErrorMessage, {}, "S1000", 0, m_aContent); m_aContent <<= aException; m_eType = TYPE::SQLException; } - -void SQLExceptionInfo::append( TYPE _eType, const OUString& _rErrorMessage, const OUString& _rSQLState, const sal_Int32 _nErrorCode ) +// create the to-be-appended exception +Any SQLExceptionInfo::createException(TYPE eType, const OUString& rErrorMessage, const OUString& rSQLState, const sal_Int32 nErrorCode) { - // create the to-be-appended exception Any aAppend; - switch ( _eType ) + switch (eType) { - case TYPE::SQLException: aAppend <<= SQLException(); break; - case TYPE::SQLWarning: aAppend <<= SQLWarning(); break; - case TYPE::SQLContext: aAppend <<= SQLContext(); break; - default: - OSL_FAIL( "SQLExceptionInfo::append: invalid exception type: this will crash!" ); - break; + case TYPE::SQLException: + aAppend <<= SQLException(rErrorMessage, {}, rSQLState, nErrorCode, {}); + break; + case TYPE::SQLWarning: + aAppend <<= SQLWarning(rErrorMessage, {}, rSQLState, nErrorCode, {}); + break; + case TYPE::SQLContext: + aAppend <<= SQLContext(rErrorMessage, {}, rSQLState, nErrorCode, {}, {}); + break; + default: + TOOLS_WARN_EXCEPTION("connectivity.commontools", "SQLExceptionInfo::createException: invalid exception type: this will crash!"); + break; } - SQLException& pAppendException = const_cast<SQLException &>(*o3tl::forceAccess<SQLException>(aAppend)); - pAppendException.Message = _rErrorMessage; - pAppendException.SQLState = _rSQLState; - pAppendException.ErrorCode = _nErrorCode; + return aAppend; +} - // find the end of the current chain - Any* pChainIterator = &m_aContent; - SQLException* pLastException = nullptr; - const Type& aSQLExceptionType( cppu::UnoType<SQLException>::get() ); - while ( pChainIterator ) +// find the end of the exception chain +SQLException* SQLExceptionInfo::getLastException(SQLException* pLastException) +{ + SQLException* pException = pLastException; + while (pException) { - if ( !pChainIterator->hasValue() ) + pException = const_cast<SQLException*>(o3tl::tryAccess<SQLException>(pException->NextException)); + if (!pException) break; + pLastException = pException; + } + return pLastException; +} - if ( !isAssignableFrom( aSQLExceptionType, pChainIterator->getValueType() ) ) - break; +void SQLExceptionInfo::append( TYPE _eType, const OUString& _rErrorMessage, const OUString& _rSQLState, const sal_Int32 _nErrorCode ) +{ + // create the to-be-appended exception + Any aAppend = createException(_eType, _rErrorMessage, _rSQLState, _nErrorCode); - pLastException = const_cast< SQLException* >( o3tl::doAccess<SQLException>( *pChainIterator ) ); - pChainIterator = &pLastException->NextException; - } + // find the end of the current chain + SQLException* pLastException = getLastException(const_cast<SQLException*>(o3tl::tryAccess<SQLException>(m_aContent))); // append - if ( pLastException ) + if (pLastException) pLastException->NextException = aAppend; else { @@ -232,7 +237,6 @@ void SQLExceptionInfo::append( TYPE _eType, const OUString& _rErrorMessage, cons } } - void SQLExceptionInfo::doThrow() { if ( m_aContent.getValueTypeClass() == TypeClass_EXCEPTION ) diff --git a/connectivity/source/commontools/dbmetadata.cxx b/connectivity/source/commontools/dbmetadata.cxx index f8afdcda692c..8983ee25bada 100644 --- a/connectivity/source/commontools/dbmetadata.cxx +++ b/connectivity/source/commontools/dbmetadata.cxx @@ -33,7 +33,7 @@ #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp> #include <com/sun/star/sdbc/DriverManager.hpp> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <comphelper/namedvaluecollection.hxx> #include <comphelper/processfactory.hxx> #include <sal/log.hxx> @@ -75,11 +75,7 @@ namespace dbtools ::std::optional< OUString > sCachedCatalogSeparator; DatabaseMetaData_Impl() - :xConnection() - ,xConnectionMetaData() - ,aDriverConfig( ::comphelper::getProcessComponentContext() ) - ,sCachedIdentifierQuoteString() - ,sCachedCatalogSeparator() + : aDriverConfig( ::comphelper::getProcessComponentContext() ) { } }; @@ -111,7 +107,7 @@ namespace dbtools } - bool lcl_getDriverSetting( const char* _asciiName, const DatabaseMetaData_Impl& _metaData, Any& _out_setting ) + bool lcl_getDriverSetting( const OUString& _asciiName, const DatabaseMetaData_Impl& _metaData, Any& _out_setting ) { lcl_checkConnected( _metaData ); const ::comphelper::NamedValueCollection& rDriverMetaData = _metaData.aDriverConfig.getMetaData( _metaData.xConnectionMetaData->getURL() ); @@ -122,7 +118,7 @@ namespace dbtools } - bool lcl_getConnectionSetting( const char* _asciiName, const DatabaseMetaData_Impl& _metaData, Any& _out_setting ) + bool lcl_getConnectionSetting(const OUString& _asciiName, const DatabaseMetaData_Impl& _metaData, Any& _out_setting ) { try { @@ -134,13 +130,12 @@ namespace dbtools xDataSource->getPropertyValue("Settings"), UNO_QUERY_THROW ); - _out_setting = xDataSourceSettings->getPropertyValue( OUString::createFromAscii( _asciiName ) ); + _out_setting = xDataSourceSettings->getPropertyValue( _asciiName ); } else { Reference< XDatabaseMetaData2 > xExtendedMetaData( _metaData.xConnectionMetaData, UNO_QUERY_THROW ); - ::comphelper::NamedValueCollection aSettings( xExtendedMetaData->getConnectionInfo() ); - _out_setting = aSettings.get( _asciiName ); + _out_setting = ::comphelper::NamedValueCollection::get( xExtendedMetaData->getConnectionInfo(), _asciiName ); return _out_setting.hasValue(); } return true; diff --git a/connectivity/source/commontools/dbtools.cxx b/connectivity/source/commontools/dbtools.cxx index 7f2e418601e9..885e28c751f5 100644 --- a/connectivity/source/commontools/dbtools.cxx +++ b/connectivity/source/commontools/dbtools.cxx @@ -58,7 +58,6 @@ #include <com/sun/star/sdbcx/XKeysSupplier.hpp> #include <com/sun/star/sdbcx/XTablesSupplier.hpp> #include <com/sun/star/task/InteractionHandler.hpp> -#include <com/sun/star/task/XInteractionRequest.hpp> #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> #include <com/sun/star/util/NumberFormat.hpp> #include <com/sun/star/util/NumberFormatsSupplier.hpp> @@ -79,7 +78,7 @@ #include <osl/diagnose.h> #include <rtl/ustrbuf.hxx> #include <sal/log.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <tools/stream.hxx> #include <cppuhelper/implbase.hxx> #include <strings.hrc> @@ -279,9 +278,7 @@ static Reference< XConnection > getConnection_allowException( Reference<XInitialization> xIni(xDataSource, UNO_QUERY); if (xIni.is()) { - Sequence< Any > aArgs(1); - NamedValue aParam( "ParentWindow", makeAny(_rxParent) ); - aArgs[0] <<= aParam; + Sequence< Any > aArgs{ Any(NamedValue( "ParentWindow", Any(_rxParent) )) }; xIni->initialize(aArgs); } @@ -319,9 +316,7 @@ static Reference< XConnection > getConnection_allowException( if (xIni.is()) { - Sequence< Any > aArgs(1); - NamedValue aParam( "ParentWindow", makeAny(Reference<XWindow>()) ); - aArgs[0] <<= aParam; + Sequence< Any > aArgs{ Any(NamedValue( "ParentWindow", Any(Reference<XWindow>()) )) }; xIni->initialize(aArgs); } @@ -345,7 +340,7 @@ Reference< XConnection> getConnection_withFeedback(const OUString& _rDataSourceN } catch(Exception&) { - OSL_FAIL("::dbtools::getConnection_withFeedback: unexpected (non-SQL) exception caught!"); + TOOLS_WARN_EXCEPTION( "connectivity.commontools", "::dbtools::getConnection_withFeedback: unexpected (non-SQL) exception caught!"); } return xReturn; } @@ -385,7 +380,7 @@ static SharedConnection lcl_connectRowSet(const Reference< XRowSet>& _rxRowSet, || ( xExistingConn = findConnection( _rxRowSet ) ).is() ) { - xRowSetProps->setPropertyValue("ActiveConnection", makeAny( xExistingConn ) ); + xRowSetProps->setPropertyValue("ActiveConnection", Any( xExistingConn ) ); // no auto disposer needed, since we did not create the connection xConnection.reset( xExistingConn, SharedConnection::NoTakeOwnership ); @@ -394,7 +389,7 @@ static SharedConnection lcl_connectRowSet(const Reference< XRowSet>& _rxRowSet, // build a connection with its current settings (4. data source name, or 5. URL) - const OUString sUserProp( "User" ); + static constexpr OUString sUserProp( u"User"_ustr ); OUString sDataSourceName; xRowSetProps->getPropertyValue("DataSourceName") >>= sDataSourceName; OUString sURL; @@ -430,8 +425,8 @@ static SharedConnection lcl_connectRowSet(const Reference< XRowSet>& _rxRowSet, if (!sUser.isEmpty()) { // use user and pwd together with the url auto aInfo(::comphelper::InitPropertySequence({ - { "user", makeAny(sUser) }, - { "password", makeAny(sPwd) } + { "user", Any(sUser) }, + { "password", Any(sPwd) } })); xPureConnection = xDriverManager->getConnectionWithInfo( sURL, aInfo ); } @@ -458,12 +453,12 @@ static SharedConnection lcl_connectRowSet(const Reference< XRowSet>& _rxRowSet, else xRowSetProps->setPropertyValue( "ActiveConnection", - makeAny( xConnection.getTyped() ) + Any( xConnection.getTyped() ) ); } catch(Exception&) { - OSL_FAIL("EXception when we set the new active connection!"); + TOOLS_WARN_EXCEPTION( "connectivity.commontools", "EXception when we set the new active connection!"); } } } @@ -688,7 +683,7 @@ Reference< XNameAccess > getFieldsByCommandDescriptor( const Reference< XConnect try { if ( xStatementProps.is() ) - xStatementProps->setPropertyValue( "MaxRows", makeAny( sal_Int32( 0 ) ) ); + xStatementProps->setPropertyValue( "MaxRows", Any( sal_Int32( 0 ) ) ); } catch( const Exception& ) { @@ -717,7 +712,7 @@ Reference< XNameAccess > getFieldsByCommandDescriptor( const Reference< XConnect catch( const SQLException& e ) { if ( _pErrorInfo ) *_pErrorInfo = SQLExceptionInfo( e ); } catch( const Exception& ) { - OSL_FAIL( "::dbtools::getFieldsByCommandDescriptor: caught an exception while retrieving the fields!" ); + TOOLS_WARN_EXCEPTION( "connectivity.commontools", "::dbtools::getFieldsByCommandDescriptor: caught an exception while retrieving the fields!" ); } return xFields; @@ -748,7 +743,7 @@ SQLException prependErrorInfo( const SQLException& _rChainedException, const Ref { return SQLException( _rAdditionalError, _rxContext, _eSQLState == StandardSQLState::ERROR_UNSPECIFIED ? OUString() : getStandardSQLState( _eSQLState ), - 0, makeAny( _rChainedException ) ); + 0, Any( _rChainedException ) ); } namespace @@ -820,13 +815,13 @@ static OUString impl_doComposeTableName( const Reference< XDatabaseMetaData >& _ OUStringBuffer aComposedName; OUString sCatalogSep; - bool bCatlogAtStart = true; + bool bCatalogAtStart = true; if ( !_rCatalog.isEmpty() && aNameComps.bCatalogs ) { sCatalogSep = _rxMetaData->getCatalogSeparator(); - bCatlogAtStart = _rxMetaData->isCatalogAtStart(); + bCatalogAtStart = _rxMetaData->isCatalogAtStart(); - if ( bCatlogAtStart && !sCatalogSep.isEmpty()) + if ( bCatalogAtStart && !sCatalogSep.isEmpty()) { aComposedName.append( _bQuote ? quoteName( sQuoteString, _rCatalog ) : _rCatalog ); aComposedName.append( sCatalogSep ); @@ -835,14 +830,15 @@ static OUString impl_doComposeTableName( const Reference< XDatabaseMetaData >& _ if ( !_rSchema.isEmpty() && aNameComps.bSchemas ) { - aComposedName.append( _bQuote ? quoteName( sQuoteString, _rSchema ) : _rSchema ); - aComposedName.append( "." ); + aComposedName.append( + (_bQuote ? quoteName( sQuoteString, _rSchema ) : _rSchema ) + + "." ); } aComposedName.append( _bQuote ? quoteName( sQuoteString, _rName ) : _rName ); if ( !_rCatalog.isEmpty() - && !bCatlogAtStart + && !bCatalogAtStart && !sCatalogSep.isEmpty() && aNameComps.bCatalogs ) @@ -917,7 +913,7 @@ Reference< XNumberFormatsSupplier> getNumberFormats( // ask the parent of the connection (should be a DatabaseAccess) Reference< XNumberFormatsSupplier> xReturn; Reference< XChild> xConnAsChild(_rxConn, UNO_QUERY); - OUString sPropFormatsSupplier( "NumberFormatsSupplier" ); + static constexpr OUString sPropFormatsSupplier( u"NumberFormatsSupplier"_ustr ); if (xConnAsChild.is()) { Reference< XPropertySet> xConnParentProps(xConnAsChild->getParent(), UNO_QUERY); @@ -947,33 +943,30 @@ try Reference< XPropertySetInfo> xNewInfo( xNewProps->getPropertySetInfo()); const Sequence< Property> aOldProperties = xOldInfo->getProperties(); - Sequence< Property> aNewProperties = xNewInfo->getProperties(); - int nNewLen = aNewProperties.getLength(); - - Property* pNewProps = aNewProperties.getArray(); - - OUString sPropFormatsSupplier("FormatsSupplier"); - OUString sPropCurrencySymbol("CurrencySymbol"); - OUString sPropDecimals("Decimals"); - OUString sPropEffectiveMin("EffectiveMin"); - OUString sPropEffectiveMax("EffectiveMax"); - OUString sPropEffectiveDefault("EffectiveDefault"); - OUString sPropDefaultText("DefaultText"); - OUString sPropDefaultDate("DefaultDate"); - OUString sPropDefaultTime("DefaultTime"); - OUString sPropValueMin("ValueMin"); - OUString sPropValueMax("ValueMax"); - OUString sPropDecimalAccuracy("DecimalAccuracy"); - OUString sPropClassId("ClassId"); - OUString sFormattedServiceName( "com.sun.star.form.component.FormattedField" ); + const Sequence< Property> aNewProperties = xNewInfo->getProperties(); + + static constexpr OUString sPropFormatsSupplier(u"FormatsSupplier"_ustr); + static constexpr OUString sPropCurrencySymbol(u"CurrencySymbol"_ustr); + static constexpr OUString sPropDecimals(u"Decimals"_ustr); + static constexpr OUString sPropEffectiveMin(u"EffectiveMin"_ustr); + static constexpr OUString sPropEffectiveMax(u"EffectiveMax"_ustr); + static constexpr OUString sPropEffectiveDefault(u"EffectiveDefault"_ustr); + static constexpr OUString sPropDefaultText(u"DefaultText"_ustr); + static constexpr OUString sPropDefaultDate(u"DefaultDate"_ustr); + static constexpr OUString sPropDefaultTime(u"DefaultTime"_ustr); + static constexpr OUString sPropValueMin(u"ValueMin"_ustr); + static constexpr OUString sPropValueMax(u"ValueMax"_ustr); + static constexpr OUString sPropDecimalAccuracy(u"DecimalAccuracy"_ustr); + static constexpr OUString sPropClassId(u"ClassId"_ustr); + static constexpr OUString sFormattedServiceName( u"com.sun.star.form.component.FormattedField"_ustr ); for (const Property& rOldProp : aOldProperties) { if ( rOldProp.Name != "DefaultControl" && rOldProp.Name != "LabelControl" ) { // binary search - Property* pResult = std::lower_bound( - pNewProps, pNewProps + nNewLen, rOldProp, ::comphelper::PropertyCompareByName()); + const Property* pResult = std::lower_bound( + aNewProperties.begin(), aNewProperties.end(), rOldProp, ::comphelper::PropertyCompareByName()); if ( ( pResult != aNewProperties.end() ) && ( pResult->Name == rOldProp.Name ) @@ -1066,13 +1059,13 @@ try { // (to convert an OUString into a date will not always succeed, because it might be bound to a text-column, // but we can work with a double) Date aDate = DBTypeConversion::toDate(getDouble(aEffectiveDefault)); - xNewProps->setPropertyValue(sPropDefaultDate, makeAny(aDate)); + xNewProps->setPropertyValue(sPropDefaultDate, Any(aDate)); } if (hasProperty(sPropDefaultTime, xNewProps) && !bIsString) { // Completely analogous to time css::util::Time aTime = DBTypeConversion::toTime(getDouble(aEffectiveDefault)); - xNewProps->setPropertyValue(sPropDefaultTime, makeAny(aTime)); + xNewProps->setPropertyValue(sPropDefaultTime, Any(aTime)); } if (hasProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE), xNewProps) && !bIsString) @@ -1142,7 +1135,7 @@ try nKey = xFormats->addNew(sNewFormat, _rLocale); } - xNewProps->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FORMATKEY), makeAny(nKey)); + xNewProps->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FORMATKEY), Any(nKey)); } // min-/max-Value @@ -1284,7 +1277,7 @@ Reference< XSingleSelectQueryComposer > getCurrentSettingsComposer( } catch( const Exception& ) { - OSL_FAIL( "::getCurrentSettingsComposer : caught an exception !" ); + TOOLS_WARN_EXCEPTION( "connectivity.commontools", "::getCurrentSettingsComposer : caught an exception !" ); } return xReturn; @@ -1633,7 +1626,8 @@ namespace std::vector<bool, std::allocator<bool> > m_aSet; Reference<XIndexAccess> m_xSource; public: - OParameterWrapper(const std::vector<bool, std::allocator<bool> >& _aSet,const Reference<XIndexAccess>& _xSource) : m_aSet(_aSet),m_xSource(_xSource){} + OParameterWrapper(std::vector<bool, std::allocator<bool> >&& _aSet,const Reference<XIndexAccess>& _xSource) + : m_aSet(std::move(_aSet)), m_xSource(_xSource) {} private: // css::container::XElementAccess virtual Type SAL_CALL getElementType() override @@ -1713,21 +1707,20 @@ void askForParameters(const Reference< XSingleSelectQueryComposer >& _xComposer, } // build an interaction request // two continuations (Ok and Cancel) - OInteractionAbort* pAbort = new OInteractionAbort; - OParameterContinuation* pParams = new OParameterContinuation; + rtl::Reference<OInteractionAbort> pAbort = new OInteractionAbort; + rtl::Reference<OParameterContinuation> pParams = new OParameterContinuation; // the request ParametersRequest aRequest; - Reference<XIndexAccess> xWrappedParameters = new OParameterWrapper(aNewParameterSet,xParamsAsIndicies); + Reference<XIndexAccess> xWrappedParameters = new OParameterWrapper(std::move(aNewParameterSet),xParamsAsIndicies); aRequest.Parameters = xWrappedParameters; aRequest.Connection = _xConnection; - OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aRequest)); - Reference< XInteractionRequest > xRequest(pRequest); + rtl::Reference<OInteractionRequest> pRequest = new OInteractionRequest(Any(aRequest)); // some knittings pRequest->addContinuation(pAbort); pRequest->addContinuation(pParams); // execute the request - _rxHandler->handle(xRequest); + _rxHandler->handle(pRequest); if (!pParams->wasSelected()) { @@ -1799,7 +1792,7 @@ void setObjectWithInfo(const Reference<XParameters>& _xParams, case DataType::CHAR: case DataType::VARCHAR: case DataType::LONGVARCHAR: - _xParams->setString(parameterIndex,_rValue); + _xParams->setString(parameterIndex,_rValue.getString()); break; case DataType::CLOB: { @@ -1823,26 +1816,26 @@ void setObjectWithInfo(const Reference<XParameters>& _xParams, break; case DataType::BIGINT: if ( _rValue.isSigned() ) - _xParams->setLong(parameterIndex,_rValue); + _xParams->setLong(parameterIndex,_rValue.getLong()); else - _xParams->setString(parameterIndex,_rValue); + _xParams->setString(parameterIndex,_rValue.getString()); break; case DataType::FLOAT: - _xParams->setFloat(parameterIndex,_rValue); + _xParams->setFloat(parameterIndex,_rValue.getFloat()); break; case DataType::REAL: case DataType::DOUBLE: - _xParams->setDouble(parameterIndex,_rValue); + _xParams->setDouble(parameterIndex,_rValue.getDouble()); break; case DataType::DATE: - _xParams->setDate(parameterIndex,_rValue); + _xParams->setDate(parameterIndex,_rValue.getDate()); break; case DataType::TIME: - _xParams->setTime(parameterIndex,_rValue); + _xParams->setTime(parameterIndex,_rValue.getTime()); break; case DataType::TIMESTAMP: - _xParams->setTimestamp(parameterIndex,_rValue); + _xParams->setTimestamp(parameterIndex,_rValue.getDateTime()); break; case DataType::BINARY: case DataType::VARBINARY: @@ -1875,25 +1868,25 @@ void setObjectWithInfo(const Reference<XParameters>& _xParams, break; case DataType::BIT: case DataType::BOOLEAN: - _xParams->setBoolean(parameterIndex,static_cast<bool>(_rValue)); + _xParams->setBoolean(parameterIndex,_rValue.getBool()); break; case DataType::TINYINT: if ( _rValue.isSigned() ) - _xParams->setByte(parameterIndex,_rValue); + _xParams->setByte(parameterIndex,_rValue.getInt8()); else - _xParams->setShort(parameterIndex,_rValue); + _xParams->setShort(parameterIndex,_rValue.getInt16()); break; case DataType::SMALLINT: if ( _rValue.isSigned() ) - _xParams->setShort(parameterIndex,_rValue); + _xParams->setShort(parameterIndex,_rValue.getInt16()); else - _xParams->setInt(parameterIndex,_rValue); + _xParams->setInt(parameterIndex,_rValue.getInt32()); break; case DataType::INTEGER: if ( _rValue.isSigned() ) - _xParams->setInt(parameterIndex,_rValue); + _xParams->setInt(parameterIndex,_rValue.getULong()); else - _xParams->setLong(parameterIndex,_rValue); + _xParams->setLong(parameterIndex,_rValue.getLong()); break; default: { @@ -1908,7 +1901,7 @@ void setObjectWithInfo(const Reference<XParameters>& _xParams, } } -void getBooleanComparisonPredicate( const OUString& _rExpression, const bool _bValue, const sal_Int32 _nBooleanComparisonMode, +void getBooleanComparisonPredicate( std::u16string_view _rExpression, const bool _bValue, const sal_Int32 _nBooleanComparisonMode, OUStringBuffer& _out_rSQLPredicate ) { switch ( _nBooleanComparisonMode ) @@ -1964,7 +1957,7 @@ void checkDisposed(bool _bThrow) OSQLColumns::const_iterator find(const OSQLColumns::const_iterator& first, const OSQLColumns::const_iterator& last, - const OUString& _rVal, + std::u16string_view _rVal, const ::comphelper::UStringMixEqual& _rCase) { OUString sName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME); @@ -1973,7 +1966,7 @@ OSQLColumns::const_iterator find(const OSQLColumns::const_iterator& first, OSQLColumns::const_iterator findRealName(const OSQLColumns::const_iterator& first, const OSQLColumns::const_iterator& last, - const OUString& _rVal, + std::u16string_view _rVal, const ::comphelper::UStringMixEqual& _rCase) { OUString sRealName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME); @@ -1983,7 +1976,7 @@ OSQLColumns::const_iterator findRealName(const OSQLColumns::const_iterator& firs OSQLColumns::const_iterator find(OSQLColumns::const_iterator first, const OSQLColumns::const_iterator& last, const OUString& _rProp, - const OUString& _rVal, + std::u16string_view _rVal, const ::comphelper::UStringMixEqual& _rCase) { while (first != last && !_rCase(getString((*first)->getPropertyValue(_rProp)),_rVal)) @@ -2024,8 +2017,8 @@ namespace dbase case 0x65: eEncoding = RTL_TEXTENCODING_IBM_866; break; // Russian MS-DOS code page 866 case 0x66: eEncoding = RTL_TEXTENCODING_IBM_865; break; // Nordic MS-DOS code page 865 case 0x67: eEncoding = RTL_TEXTENCODING_IBM_861; break; // Icelandic MS-DOS - //case 0x68: eEncoding = ; break; // Kamenicky (Czech) MS-DOS - //case 0x69: eEncoding = ; break; // Mazovia (Polish) MS-DOS + case 0x68: eEncoding = RTL_TEXTENCODING_KAMENICKY; break; // Kamenicky (Czech) MS-DOS + case 0x69: eEncoding = RTL_TEXTENCODING_MAZOVIA; break; // Mazovia (Polish) MS-DOS case 0x6A: eEncoding = RTL_TEXTENCODING_IBM_737; break; // Greek MS-DOS (437G) case 0x6B: eEncoding = RTL_TEXTENCODING_IBM_857; break; // Turkish MS-DOS case 0x6C: eEncoding = RTL_TEXTENCODING_IBM_863; break; // MS-DOS, Canada diff --git a/connectivity/source/commontools/dbtools2.cxx b/connectivity/source/commontools/dbtools2.cxx index a9e0caff2eeb..8148b25ddca3 100644 --- a/connectivity/source/commontools/dbtools2.cxx +++ b/connectivity/source/commontools/dbtools2.cxx @@ -45,7 +45,7 @@ #include <com/sun/star/container/XChild.hpp> #include <comphelper/types.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <unotools/sharedunocomponent.hxx> #include <algorithm> #include <string_view> @@ -64,7 +64,7 @@ namespace dbtools using namespace connectivity; using namespace comphelper; -OUString createStandardTypePart(const Reference< XPropertySet >& xColProp,const Reference< XConnection>& _xConnection,const OUString& _sCreatePattern) +OUString createStandardTypePart(const Reference< XPropertySet >& xColProp,const Reference< XConnection>& _xConnection,std::u16string_view _sCreatePattern) { Reference<XDatabaseMetaData> xMetaData = _xConnection->getMetaData(); @@ -122,37 +122,45 @@ OUString createStandardTypePart(const Reference< XPropertySet >& xColProp,const { sal_Int32 nIndex = sTypeName.indexOf(sAutoIncrementValue); if (nIndex != -1) - sTypeName = sTypeName.replaceAt(nIndex,sTypeName.getLength() - nIndex,OUString()); + sTypeName = sTypeName.replaceAt(nIndex,sTypeName.getLength() - nIndex, u""); } if ( (nPrecision > 0 || nScale > 0) && bUseLiteral ) { - sal_Int32 nParenPos = sTypeName.indexOf('('); + bool bTimed = (nDataType == DataType::TIME || + nDataType == DataType::TIME_WITH_TIMEZONE || + nDataType == DataType::TIMESTAMP || + nDataType == DataType::TIMESTAMP_WITH_TIMEZONE); + + sal_Int32 nParenPos = (nDataType == DataType::TIME_WITH_TIMEZONE || + nDataType == DataType::TIMESTAMP_WITH_TIMEZONE) ? + sTypeName.indexOf(' ') : + sTypeName.indexOf('('); + if ( nParenPos == -1 ) - { aSql.append(sTypeName); - aSql.append("("); - } else - { - aSql.append(std::u16string_view(sTypeName).substr(0, ++nParenPos)); - } + aSql.append(sTypeName.subView(0, nParenPos)); + aSql.append("("); - if ( nPrecision > 0 && nDataType != DataType::TIMESTAMP ) + if ( nPrecision > 0 && !bTimed ) { aSql.append(nPrecision); - if ( (nScale > 0) || (!_sCreatePattern.isEmpty() && sCreateParams.indexOf(_sCreatePattern) != -1) ) + if ( (nScale > 0) || (!_sCreatePattern.empty() && sCreateParams.indexOf(_sCreatePattern) != -1) ) aSql.append(","); } - if ( (nScale > 0) || ( !_sCreatePattern.isEmpty() && sCreateParams.indexOf(_sCreatePattern) != -1 ) || nDataType == DataType::TIMESTAMP ) + if ( (nScale > 0) || ( !_sCreatePattern.empty() && sCreateParams.indexOf(_sCreatePattern) != -1 ) || bTimed ) aSql.append(nScale); if ( nParenPos == -1 ) aSql.append(")"); else { - nParenPos = sTypeName.indexOf(')',nParenPos); - aSql.append(std::u16string_view(sTypeName).substr(nParenPos)); + if ( bTimed ) + aSql.append(")"); + else + nParenPos = sTypeName.indexOf(')',nParenPos); + aSql.append(sTypeName.subView(nParenPos)); } } else @@ -161,16 +169,13 @@ OUString createStandardTypePart(const Reference< XPropertySet >& xColProp,const OUString aDefault = ::comphelper::getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_DEFAULTVALUE))); if ( !aDefault.isEmpty() ) { - aSql.append(" DEFAULT "); - aSql.append(sPrefix); - aSql.append(aDefault); - aSql.append(sPostfix); + aSql.append(" DEFAULT " + sPrefix + aDefault + sPostfix); } // if ( aDefault.getLength() ) return aSql.makeStringAndClear(); } -OUString createStandardColumnPart(const Reference< XPropertySet >& xColProp,const Reference< XConnection>& _xConnection,ISQLStatementHelper* _pHelper,const OUString& _sCreatePattern) +OUString createStandardColumnPart(const Reference< XPropertySet >& xColProp,const Reference< XConnection>& _xConnection,ISQLStatementHelper* _pHelper,std::u16string_view _sCreatePattern) { Reference<XDatabaseMetaData> xMetaData = _xConnection->getMetaData(); @@ -180,7 +185,7 @@ OUString createStandardColumnPart(const Reference< XPropertySet >& xColProp,cons xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)) >>= bIsAutoIncrement; const OUString sQuoteString = xMetaData->getIdentifierQuoteString(); - OUStringBuffer aSql = ::dbtools::quoteName(sQuoteString,::comphelper::getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)))); + OUStringBuffer aSql(::dbtools::quoteName(sQuoteString,::comphelper::getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME))))); // check if the user enter a specific string to create autoincrement values OUString sAutoIncrementValue; @@ -188,17 +193,14 @@ OUString createStandardColumnPart(const Reference< XPropertySet >& xColProp,cons if ( xPropInfo.is() && xPropInfo->hasPropertyByName(rPropMap.getNameByIndex(PROPERTY_ID_AUTOINCREMENTCREATION)) ) xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_AUTOINCREMENTCREATION)) >>= sAutoIncrementValue; - aSql.append(" "); - - aSql.append(createStandardTypePart(xColProp, _xConnection, _sCreatePattern)); + aSql.append(" " + createStandardTypePart(xColProp, _xConnection, _sCreatePattern)); if(::comphelper::getINT32(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_ISNULLABLE))) == ColumnValue::NO_NULLS) aSql.append(" NOT NULL"); if ( bIsAutoIncrement && !sAutoIncrementValue.isEmpty()) { - aSql.append(" "); - aSql.append(sAutoIncrementValue); + aSql.append(" " + sAutoIncrementValue); } if ( _pHelper ) @@ -208,7 +210,7 @@ OUString createStandardColumnPart(const Reference< XPropertySet >& xColProp,cons } -OUString createStandardCreateStatement(const Reference< XPropertySet >& descriptor,const Reference< XConnection>& _xConnection,ISQLStatementHelper* _pHelper,const OUString& _sCreatePattern) +OUString createStandardCreateStatement(const Reference< XPropertySet >& descriptor,const Reference< XConnection>& _xConnection,ISQLStatementHelper* _pHelper,std::u16string_view _sCreatePattern) { OUStringBuffer aSql("CREATE TABLE "); OUString sCatalog,sSchema,sTable,sComposedName; @@ -224,8 +226,7 @@ OUString createStandardCreateStatement(const Reference< XPropertySet >& descript if ( sComposedName.isEmpty() ) ::dbtools::throwFunctionSequenceException(_xConnection); - aSql.append(sComposedName); - aSql.append(" ("); + aSql.append(sComposedName + " ("); // columns Reference<XColumnsSupplier> xColumnSup(descriptor,UNO_QUERY); @@ -241,8 +242,9 @@ OUString createStandardCreateStatement(const Reference< XPropertySet >& descript { if ( (xColumns->getByIndex(i) >>= xColProp) && xColProp.is() ) { - aSql.append(createStandardColumnPart(xColProp,_xConnection,_pHelper,_sCreatePattern)); - aSql.append(","); + aSql.append( + createStandardColumnPart(xColProp,_xConnection,_pHelper,_sCreatePattern) + + ","); } } return aSql.makeStringAndClear(); @@ -261,8 +263,8 @@ namespace for(sal_Int32 i=0;i<nColCount;++i) { if ( (_xColumns->getByIndex(i) >>= xColProp) && xColProp.is() ) - sSql.append( ::dbtools::quoteName(sQuote,::comphelper::getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)))) ) - .append(","); + sSql.append( ::dbtools::quoteName(sQuote,::comphelper::getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)))) + + ","); } if ( nColCount ) @@ -305,8 +307,7 @@ OUString createStandardKeyStatement(const Reference< XPropertySet >& descriptor, if(!xColumns.is() || !xColumns->getCount()) ::dbtools::throwFunctionSequenceException(_xConnection); - aSql.append(" PRIMARY KEY "); - aSql.append(generateColumnNames(xColumns,xMetaData)); + aSql.append(" PRIMARY KEY " + generateColumnNames(xColumns,xMetaData)); } else if(nKeyType == KeyType::UNIQUE) { @@ -315,8 +316,7 @@ OUString createStandardKeyStatement(const Reference< XPropertySet >& descriptor, if(!xColumns.is() || !xColumns->getCount()) ::dbtools::throwFunctionSequenceException(_xConnection); - aSql.append(" UNIQUE "); - aSql.append(generateColumnNames(xColumns,xMetaData)); + aSql.append(" UNIQUE " + generateColumnNames(xColumns,xMetaData)); } else if(nKeyType == KeyType::FOREIGN) { @@ -380,14 +380,14 @@ OUString createStandardKeyStatement(const Reference< XPropertySet >& descriptor, OUString createSqlCreateTableStatement( const Reference< XPropertySet >& descriptor, const Reference< XConnection>& _xConnection) { - OUString aSql = ::dbtools::createStandardCreateStatement(descriptor,_xConnection,nullptr,OUString()); + OUString aSql = ::dbtools::createStandardCreateStatement(descriptor,_xConnection,nullptr,{}); const OUString sKeyStmt = ::dbtools::createStandardKeyStatement(descriptor,_xConnection); if ( !sKeyStmt.isEmpty() ) aSql += sKeyStmt; else { if ( aSql.endsWith(",") ) - aSql = aSql.replaceAt(aSql.getLength()-1, 1, ")"); + aSql = aSql.replaceAt(aSql.getLength()-1, 1, u")"); else aSql += ")"; } @@ -484,7 +484,7 @@ namespace } } - connectivity::sdbcx::OColumn* pRet = new connectivity::sdbcx::OColumn(_rName, + xProp = new connectivity::sdbcx::OColumn(_rName, aField6, sField13, sField12, @@ -500,7 +500,6 @@ namespace _aSchema, _aTable); - xProp = pRet; break; } } @@ -575,6 +574,11 @@ Reference<XPropertySet> createSDBCXColumn(const Reference<XPropertySet>& _xTable bool getBooleanDataSourceSetting( const Reference< XConnection >& _rxConnection, const char* _pAsciiSettingName ) { + return getBooleanDataSourceSetting(_rxConnection, OUString::createFromAscii( _pAsciiSettingName )); +} + +bool getBooleanDataSourceSetting( const Reference< XConnection >& _rxConnection, const OUString & rSettingName ) +{ bool bValue( false ); try { @@ -586,7 +590,7 @@ bool getBooleanDataSourceSetting( const Reference< XConnection >& _rxConnection, xDataSourceProperties->getPropertyValue("Settings"), UNO_QUERY_THROW ); - OSL_VERIFY( xSettings->getPropertyValue( OUString::createFromAscii( _pAsciiSettingName ) ) >>= bValue ); + OSL_VERIFY( xSettings->getPropertyValue( rSettingName ) >>= bValue ); } } catch( const Exception& ) @@ -638,11 +642,11 @@ bool isDataSourcePropertyEnabled(const Reference<XInterface>& _xProp, const OUSt { Sequence< PropertyValue > aInfo; xProp->getPropertyValue("Info") >>= aInfo; - const PropertyValue* pValue =std::find_if(aInfo.begin(), - aInfo.end(), + const PropertyValue* pValue =std::find_if(std::cbegin(aInfo), + std::cend(aInfo), [&_sProperty](const PropertyValue& lhs) { return lhs.Name == _sProperty; }); - if ( pValue != aInfo.end() ) + if ( pValue != std::cend(aInfo) ) pValue->Value >>= bEnabled; } } @@ -798,11 +802,11 @@ sal_Int32 getTablePrivileges(const Reference< XDatabaseMetaData>& _xMetaData, // we need some more information about the column void collectColumnInformation(const Reference< XConnection>& _xConnection, - const OUString& _sComposedName, - const OUString& _rName, + std::u16string_view _sComposedName, + std::u16string_view _rName, ColumnInformationMap& _rInfo) { - OUString sSelect = "SELECT " + _rName + + OUString sSelect = OUString::Concat("SELECT ") + _rName + " FROM " + _sComposedName + " WHERE 0 = 1"; @@ -810,7 +814,7 @@ void collectColumnInformation(const Reference< XConnection>& _xConnection, { ::utl::SharedUNOComponent< XStatement > xStmt( _xConnection->createStatement() ); Reference< XPropertySet > xStatementProps( xStmt, UNO_QUERY_THROW ); - xStatementProps->setPropertyValue( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_ESCAPEPROCESSING ), makeAny( false ) ); + xStatementProps->setPropertyValue( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_ESCAPEPROCESSING ), Any( false ) ); Reference< XResultSet > xResult( xStmt->executeQuery( sSelect ), UNO_SET_THROW ); Reference< XResultSetMetaDataSupplier > xSuppMeta( xResult, UNO_QUERY_THROW ); Reference< XResultSetMetaData > xMeta( xSuppMeta->getMetaData(), UNO_SET_THROW ); @@ -941,33 +945,19 @@ sal_Int32 DBTypeConversion::convertUnicodeStringToLength( const OUString& _rSour return nLen; } -static OUString lcl_getReportEngines() -{ - return "org.openoffice.Office.DataAccess/ReportEngines"; -} - -static OUString lcl_getDefaultReportEngine() -{ - return "DefaultReportEngine"; -} - -static OUString lcl_getReportEngineNames() -{ - return "ReportEngineNames"; -} OUString getDefaultReportEngineServiceName(const Reference< XComponentContext >& _rxORB) { ::utl::OConfigurationTreeRoot aReportEngines = ::utl::OConfigurationTreeRoot::createWithComponentContext( - _rxORB, lcl_getReportEngines(), -1, ::utl::OConfigurationTreeRoot::CM_READONLY); + _rxORB, "org.openoffice.Office.DataAccess/ReportEngines", -1, ::utl::OConfigurationTreeRoot::CM_READONLY); if ( aReportEngines.isValid() ) { OUString sDefaultReportEngineName; - aReportEngines.getNodeValue(lcl_getDefaultReportEngine()) >>= sDefaultReportEngineName; + aReportEngines.getNodeValue("DefaultReportEngine") >>= sDefaultReportEngineName; if ( !sDefaultReportEngineName.isEmpty() ) { - ::utl::OConfigurationNode aReportEngineNames = aReportEngines.openNode(lcl_getReportEngineNames()); + ::utl::OConfigurationNode aReportEngineNames = aReportEngines.openNode("ReportEngineNames"); if ( aReportEngineNames.isValid() ) { ::utl::OConfigurationNode aReportEngine = aReportEngineNames.openNode(sDefaultReportEngineName); @@ -1014,7 +1004,7 @@ bool isAggregateColumn( const Reference< XPropertySet > &_xColumn ) { bool bAgg(false); - static const char sAgg[] = "AggregateFunction"; + static constexpr OUString sAgg = u"AggregateFunction"_ustr; if ( _xColumn->getPropertySetInfo()->hasPropertyByName(sAgg) ) _xColumn->getPropertyValue(sAgg) >>= bAgg; diff --git a/connectivity/source/commontools/filtermanager.cxx b/connectivity/source/commontools/filtermanager.cxx index a6180dd00666..fa9fc7116d92 100644 --- a/connectivity/source/commontools/filtermanager.cxx +++ b/connectivity/source/commontools/filtermanager.cxx @@ -22,7 +22,7 @@ #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp> #include <TConnection.hxx> #include <osl/diagnose.h> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <rtl/ustrbuf.hxx> @@ -31,9 +31,6 @@ namespace dbtools using namespace ::com::sun::star::uno; - using namespace ::com::sun::star::sdbc; - using namespace ::com::sun::star::sdb; - using namespace ::com::sun::star::lang; using namespace ::com::sun::star::beans; using namespace connectivity; @@ -49,7 +46,7 @@ namespace dbtools OSL_ENSURE( m_xComponentAggregate.is(), "FilterManager::initialize: invalid arguments!" ); if ( m_xComponentAggregate.is() ) - m_xComponentAggregate->setPropertyValue( OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_APPLYFILTER), makeAny( true ) ); + m_xComponentAggregate->setPropertyValue( OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_APPLYFILTER), Any( true ) ); } @@ -74,7 +71,7 @@ namespace dbtools } assert(false); - static const OUString sErr("#FilterManager::getFilterComponent unknown component#"); + static constexpr OUString sErr(u"#FilterManager::getFilterComponent unknown component#"_ustr); return sErr; } @@ -108,14 +105,14 @@ namespace dbtools [[fallthrough]]; case FilterComponent::LinkFilter: if (propagate) - m_xComponentAggregate->setPropertyValue( OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FILTER), makeAny( getComposedFilter() ) ); + m_xComponentAggregate->setPropertyValue( OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FILTER), Any( getComposedFilter() ) ); break; case FilterComponent::PublicHaving: propagate = propagate && m_bApplyPublicFilter; [[fallthrough]]; case FilterComponent::LinkHaving: if (propagate) - m_xComponentAggregate->setPropertyValue( OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_HAVINGCLAUSE), makeAny( getComposedHaving() ) ); + m_xComponentAggregate->setPropertyValue( OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_HAVINGCLAUSE), Any( getComposedHaving() ) ); break; } } @@ -140,9 +137,9 @@ namespace dbtools { // only where/if something changed if (!getFilterComponent( FilterComponent::PublicFilter ).isEmpty()) - m_xComponentAggregate->setPropertyValue( OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FILTER), makeAny( getComposedFilter() ) ); + m_xComponentAggregate->setPropertyValue( OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FILTER), Any( getComposedFilter() ) ); if (!getFilterComponent( FilterComponent::PublicHaving ).isEmpty()) - m_xComponentAggregate->setPropertyValue( OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_HAVINGCLAUSE), makeAny( getComposedHaving() ) ); + m_xComponentAggregate->setPropertyValue( OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_HAVINGCLAUSE), Any( getComposedHaving() ) ); } } catch( const Exception& ) @@ -152,7 +149,7 @@ namespace dbtools } - void FilterManager::appendFilterComponent( OUStringBuffer& io_appendTo, const OUString& i_component ) + void FilterManager::appendFilterComponent( OUStringBuffer& io_appendTo, std::u16string_view i_component ) { if ( !io_appendTo.isEmpty() ) { diff --git a/connectivity/source/commontools/formattedcolumnvalue.cxx b/connectivity/source/commontools/formattedcolumnvalue.cxx index de317c43b4ab..32db3d7177c2 100644 --- a/connectivity/source/commontools/formattedcolumnvalue.cxx +++ b/connectivity/source/commontools/formattedcolumnvalue.cxx @@ -31,7 +31,7 @@ #include <com/sun/star/sdb/XColumn.hpp> #include <com/sun/star/sdb/XColumnUpdate.hpp> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <i18nlangtag/mslangid.hxx> #include <i18nlangtag/languagetag.hxx> #include <comphelper/numbers.hxx> @@ -76,14 +76,11 @@ namespace dbtools Reference< XColumnUpdate > m_xColumnUpdate; FormattedColumnValue_Data() - :m_xFormatter() - ,m_aNullDate( DBTypeConversion::getStandardDate() ) + :m_aNullDate( DBTypeConversion::getStandardDate() ) ,m_nFormatKey( 0 ) ,m_nFieldType( DataType::OTHER ) ,m_nKeyType( NumberFormat::UNDEFINED ) ,m_bNumericField( false ) - ,m_xColumn() - ,m_xColumnUpdate() { } }; @@ -129,7 +126,9 @@ namespace dbtools { case DataType::DATE: case DataType::TIME: + case DataType::TIME_WITH_TIMEZONE: case DataType::TIMESTAMP: + case DataType::TIMESTAMP_WITH_TIMEZONE: case DataType::BIT: case DataType::BOOLEAN: case DataType::TINYINT: @@ -150,7 +149,7 @@ namespace dbtools // get the format key of our bound field Reference< XPropertySetInfo > xPSI( _rxColumn->getPropertySetInfo(), UNO_SET_THROW ); bool bHaveFieldFormat = false; - const OUString sFormatKeyProperty( "FormatKey" ); + static constexpr OUString sFormatKeyProperty( u"FormatKey"_ustr ); if ( xPSI->hasPropertyByName( sFormatKeyProperty ) ) { bHaveFieldFormat = ( _rxColumn->getPropertyValue( sFormatKeyProperty ) >>= _rData.m_nFormatKey ); @@ -158,7 +157,7 @@ namespace dbtools if ( !bHaveFieldFormat ) { // fall back to a format key as indicated by the field type - Locale aSystemLocale( LanguageTag( MsLangId::getSystemLanguage() ).getLocale() ); + Locale aSystemLocale( LanguageTag( MsLangId::getConfiguredSystemLanguage() ).getLocale() ); Reference< XNumberFormatTypes > xNumTypes( xNumberFormatsSupp->getNumberFormats(), UNO_QUERY_THROW ); _rData.m_nFormatKey = getDefaultNumberFormat( _rxColumn, xNumTypes, aSystemLocale ); } diff --git a/connectivity/source/commontools/parameters.cxx b/connectivity/source/commontools/parameters.cxx index bd114ea19341..6c55b9884789 100644 --- a/connectivity/source/commontools/parameters.cxx +++ b/connectivity/source/commontools/parameters.cxx @@ -33,7 +33,7 @@ #include <connectivity/filtermanager.hxx> #include <TConnection.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <ParameterCont.hxx> #include <o3tl/safeint.hxx> @@ -46,7 +46,6 @@ namespace dbtools using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::sdbcx; - using namespace ::com::sun::star::lang; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::task; using namespace ::com::sun::star::form; @@ -99,15 +98,13 @@ namespace dbtools m_pOuterParameters->dispose(); m_pOuterParameters = nullptr; m_nInnerCount = 0; - ParameterInformation aEmptyInfo; - m_aParameterInformation.swap( aEmptyInfo ); + ParameterInformation().swap(m_aParameterInformation); m_aMasterFields.clear(); m_aDetailFields.clear(); m_sIdentifierQuoteString.clear(); m_sSpecialCharacters.clear(); m_xConnectionMetadata.clear(); - std::vector< bool > aEmptyArray; - m_aParametersVisited.swap( aEmptyArray ); + std::vector< bool >().swap(m_aParametersVisited); m_bUpToDate = false; } @@ -395,9 +392,7 @@ namespace dbtools if ( !sAdditionalFilter.isEmpty() ) sAdditionalFilter.append(" AND "); - sAdditionalFilter.append("( "); - sAdditionalFilter.append(elem); - sAdditionalFilter.append(" )"); + sAdditionalFilter.append("( " + elem + " )"); } // now set this filter at the filter manager @@ -415,9 +410,7 @@ namespace dbtools if ( !sAdditionalHaving.isEmpty() ) sAdditionalHaving.append(" AND "); - sAdditionalHaving.append("( "); - sAdditionalHaving.append(elem); - sAdditionalHaving.append(" )"); + sAdditionalHaving.append("( " + elem + " )"); } // now set this having clause at the filter manager @@ -482,7 +475,7 @@ namespace dbtools // property, but the parameter listeners expect such a property. So we need an object "aggregating" // xParam and supplying an additional property ("Value") // (it's no real aggregation of course...) - m_pOuterParameters->push_back( new param::ParameterWrapper( aParam.second.xComposerColumn, m_xInnerParamUpdate, aParam.second.aInnerIndexes ) ); + m_pOuterParameters->push_back( new param::ParameterWrapper( aParam.second.xComposerColumn, m_xInnerParamUpdate, std::vector(aParam.second.aInnerIndexes) ) ); } #if OSL_DEBUG_LEVEL > 0 @@ -645,15 +638,14 @@ namespace dbtools OSL_ENSURE ( _rxCompletionHandler.is(), "ParameterManager::completeParameters: invalid interaction handler!" ); // two continuations (Ok and Cancel) - OInteractionAbort* pAbort = new OInteractionAbort; - OParameterContinuation* pParams = new OParameterContinuation; + rtl::Reference<OInteractionAbort> pAbort = new OInteractionAbort; + rtl::Reference<OParameterContinuation> pParams = new OParameterContinuation; // the request ParametersRequest aRequest; aRequest.Parameters = m_pOuterParameters.get(); aRequest.Connection = _rxConnection; - OInteractionRequest* pRequest = new OInteractionRequest( makeAny( aRequest ) ); - Reference< XInteractionRequest > xRequest( pRequest ); + rtl::Reference<OInteractionRequest> pRequest = new OInteractionRequest( Any( aRequest ) ); // some knittings pRequest->addContinuation( pAbort ); @@ -662,7 +654,7 @@ namespace dbtools // execute the request try { - _rxCompletionHandler->handle( xRequest ); + _rxCompletionHandler->handle( pRequest ); } catch( const Exception& ) { @@ -710,14 +702,14 @@ namespace dbtools // TODO: shouldn't we subtract all the parameters which were already visited? if ( nParamsLeft ) { - ::comphelper::OInterfaceIteratorHelper2 aIter( m_aParameterListeners ); + ::comphelper::OInterfaceIteratorHelper3 aIter( m_aParameterListeners ); Reference< XPropertySet > xProp = m_xComponent; OSL_ENSURE(xProp.is(),"Some already released my component!"); - DatabaseParameterEvent aEvent( xProp.get(), m_pOuterParameters.get() ); + DatabaseParameterEvent aEvent( xProp, m_pOuterParameters ); _rClearForNotifies.clear(); while ( aIter.hasMoreElements() && !bCanceled ) - bCanceled = !static_cast< XDatabaseParameterListener* >( aIter.next() )->approveParameter( aEvent ); + bCanceled = !aIter.next()->approveParameter( aEvent ); _rClearForNotifies.reset(); } @@ -959,144 +951,245 @@ namespace dbtools m_aParametersVisited[ _nIndex - 1 ] = true; } -#define VISIT_PARAMETER( method ) \ - ::osl::MutexGuard aGuard( m_rMutex ); \ - OSL_ENSURE( m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!" ); \ - if ( !m_xInnerParamUpdate.is() ) \ - return; \ - m_xInnerParamUpdate->method; \ - externalParameterVisited( _nIndex ) \ - - void ParameterManager::setNull( sal_Int32 _nIndex, sal_Int32 sqlType ) { - VISIT_PARAMETER( setNull( _nIndex, sqlType ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setNull(_nIndex, sqlType); + externalParameterVisited(_nIndex); } void ParameterManager::setObjectNull( sal_Int32 _nIndex, sal_Int32 sqlType, const OUString& typeName ) { - VISIT_PARAMETER( setObjectNull( _nIndex, sqlType, typeName ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setObjectNull(_nIndex, sqlType, typeName); + externalParameterVisited(_nIndex); } void ParameterManager::setBoolean( sal_Int32 _nIndex, bool x ) { - VISIT_PARAMETER( setBoolean( _nIndex, x ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setBoolean(_nIndex, x); + externalParameterVisited(_nIndex); } void ParameterManager::setByte( sal_Int32 _nIndex, sal_Int8 x ) { - VISIT_PARAMETER( setByte( _nIndex, x ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setByte(_nIndex, x); + externalParameterVisited(_nIndex); } void ParameterManager::setShort( sal_Int32 _nIndex, sal_Int16 x ) { - VISIT_PARAMETER( setShort( _nIndex, x ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setShort(_nIndex, x); + externalParameterVisited(_nIndex); } void ParameterManager::setInt( sal_Int32 _nIndex, sal_Int32 x ) { - VISIT_PARAMETER( setInt( _nIndex, x ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setInt(_nIndex, x); + externalParameterVisited(_nIndex); } void ParameterManager::setLong( sal_Int32 _nIndex, sal_Int64 x ) { - VISIT_PARAMETER( setLong( _nIndex, x ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setLong(_nIndex, x); + externalParameterVisited(_nIndex); } void ParameterManager::setFloat( sal_Int32 _nIndex, float x ) { - VISIT_PARAMETER( setFloat( _nIndex, x ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setFloat(_nIndex, x); + externalParameterVisited(_nIndex); } void ParameterManager::setDouble( sal_Int32 _nIndex, double x ) { - VISIT_PARAMETER( setDouble( _nIndex, x ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setDouble(_nIndex, x); + externalParameterVisited(_nIndex); } void ParameterManager::setString( sal_Int32 _nIndex, const OUString& x ) { - VISIT_PARAMETER( setString( _nIndex, x ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setString(_nIndex, x); + externalParameterVisited(_nIndex); } void ParameterManager::setBytes( sal_Int32 _nIndex, const css::uno::Sequence< sal_Int8 >& x ) { - VISIT_PARAMETER( setBytes( _nIndex, x ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setBytes(_nIndex, x); + externalParameterVisited(_nIndex); } void ParameterManager::setDate( sal_Int32 _nIndex, const css::util::Date& x ) { - VISIT_PARAMETER( setDate( _nIndex, x ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setDate(_nIndex, x); + externalParameterVisited(_nIndex); } void ParameterManager::setTime( sal_Int32 _nIndex, const css::util::Time& x ) { - VISIT_PARAMETER( setTime( _nIndex, x ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setTime(_nIndex, x); + externalParameterVisited(_nIndex); } void ParameterManager::setTimestamp( sal_Int32 _nIndex, const css::util::DateTime& x ) { - VISIT_PARAMETER( setTimestamp( _nIndex, x ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setTimestamp(_nIndex, x); + externalParameterVisited(_nIndex); } void ParameterManager::setBinaryStream( sal_Int32 _nIndex, const css::uno::Reference< css::io::XInputStream>& x, sal_Int32 length ) { - VISIT_PARAMETER( setBinaryStream( _nIndex, x, length ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setBinaryStream(_nIndex, x, length); + externalParameterVisited(_nIndex); } void ParameterManager::setCharacterStream( sal_Int32 _nIndex, const css::uno::Reference< css::io::XInputStream>& x, sal_Int32 length ) { - VISIT_PARAMETER( setCharacterStream( _nIndex, x, length ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setCharacterStream(_nIndex, x, length); + externalParameterVisited(_nIndex); } void ParameterManager::setObject( sal_Int32 _nIndex, const css::uno::Any& x ) { - VISIT_PARAMETER( setObject( _nIndex, x ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setObject(_nIndex, x); + externalParameterVisited(_nIndex); } void ParameterManager::setObjectWithInfo( sal_Int32 _nIndex, const css::uno::Any& x, sal_Int32 targetSqlType, sal_Int32 scale ) { - VISIT_PARAMETER( setObjectWithInfo( _nIndex, x, targetSqlType, scale ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setObjectWithInfo(_nIndex, x, targetSqlType, scale); + externalParameterVisited(_nIndex); } void ParameterManager::setRef( sal_Int32 _nIndex, const css::uno::Reference< css::sdbc::XRef>& x ) { - VISIT_PARAMETER( setRef( _nIndex, x ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setRef(_nIndex, x); + externalParameterVisited(_nIndex); } void ParameterManager::setBlob( sal_Int32 _nIndex, const css::uno::Reference< css::sdbc::XBlob>& x ) { - VISIT_PARAMETER( setBlob( _nIndex, x ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setBlob(_nIndex, x); + externalParameterVisited(_nIndex); } void ParameterManager::setClob( sal_Int32 _nIndex, const css::uno::Reference< css::sdbc::XClob>& x ) { - VISIT_PARAMETER( setClob( _nIndex, x ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setClob(_nIndex, x); + externalParameterVisited(_nIndex); } void ParameterManager::setArray( sal_Int32 _nIndex, const css::uno::Reference< css::sdbc::XArray>& x ) { - VISIT_PARAMETER( setArray( _nIndex, x ) ); + ::osl::MutexGuard aGuard(m_rMutex); + OSL_ENSURE(m_xInnerParamUpdate.is(), "ParameterManager::XParameters::setXXX: no XParameters access to the RowSet!"); + if (!m_xInnerParamUpdate.is()) + return; + m_xInnerParamUpdate->setArray(_nIndex, x); + externalParameterVisited(_nIndex); } diff --git a/connectivity/source/commontools/paramwrapper.cxx b/connectivity/source/commontools/paramwrapper.cxx index ffe42419daa6..e25a3e7b4905 100644 --- a/connectivity/source/commontools/paramwrapper.cxx +++ b/connectivity/source/commontools/paramwrapper.cxx @@ -28,7 +28,8 @@ #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp> #include <com/sun/star/lang/DisposedException.hpp> -#include <tools/diagnose_ex.h> +#include <o3tl/safeint.hxx> +#include <comphelper/diagnose_ex.hxx> #include <comphelper/enumhelper.hxx> #define PROPERTY_ID_VALUE 1000 @@ -75,9 +76,9 @@ namespace dbtools::param ParameterWrapper::ParameterWrapper( const Reference< XPropertySet >& _rxColumn, - const Reference< XParameters >& _rxAllParameters, const std::vector< sal_Int32 >& _rIndexes ) + const Reference< XParameters >& _rxAllParameters, std::vector< sal_Int32 >&& _rIndexes ) :PropertyBase( m_aBHelper ) - ,m_aIndexes( _rIndexes ) + ,m_aIndexes( std::move(_rIndexes) ) ,m_xDelegator( _rxColumn ) ,m_xValueDestination( _rxAllParameters ) { @@ -158,7 +159,7 @@ namespace dbtools::param aProperties = m_xDelegatorPSI->getProperties(); sal_Int32 nProperties( aProperties.getLength() ); aProperties.realloc( nProperties + 1 ); - aProperties[ nProperties ] = Property( + aProperties.getArray()[ nProperties ] = Property( "Value", PROPERTY_ID_VALUE, ::cppu::UnoType< Any >::get(), @@ -214,11 +215,7 @@ namespace dbtools::param } catch( SQLException& e ) { - WrappedTargetException aExceptionWrapper; - aExceptionWrapper.Context = e.Context; - aExceptionWrapper.Message = e.Message; - aExceptionWrapper.TargetException <<= e; - throw aExceptionWrapper; + throw WrappedTargetException(e.Message, e.Context, css::uno::Any(e)); } } else @@ -257,13 +254,11 @@ namespace dbtools::param } ParameterWrapperContainer::ParameterWrapperContainer() - :ParameterWrapperContainer_Base( m_aMutex ) { } ParameterWrapperContainer::ParameterWrapperContainer( const Reference< XSingleSelectQueryAnalyzer >& _rxComposer ) - :ParameterWrapperContainer_Base( m_aMutex ) { Reference< XParametersSupplier > xSuppParams( _rxComposer, UNO_QUERY_THROW ); Reference< XIndexAccess > xParameters( xSuppParams->getParameters(), css::uno::UNO_SET_THROW ); @@ -283,7 +278,7 @@ namespace dbtools::param Type SAL_CALL ParameterWrapperContainer::getElementType() { - ::osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); impl_checkDisposed_throw(); return cppu::UnoType<XPropertySet>::get(); } @@ -291,7 +286,7 @@ namespace dbtools::param sal_Bool SAL_CALL ParameterWrapperContainer::hasElements() { - ::osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); impl_checkDisposed_throw(); return !m_aParameters.empty(); } @@ -299,7 +294,7 @@ namespace dbtools::param sal_Int32 SAL_CALL ParameterWrapperContainer::getCount() { - ::osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); impl_checkDisposed_throw(); return m_aParameters.size(); } @@ -307,19 +302,19 @@ namespace dbtools::param Any SAL_CALL ParameterWrapperContainer::getByIndex( sal_Int32 _nIndex ) { - ::osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); impl_checkDisposed_throw(); - if ( ( _nIndex < 0 ) || ( _nIndex >= static_cast<sal_Int32>(m_aParameters.size()) ) ) + if ( ( _nIndex < 0 ) || ( o3tl::make_unsigned(_nIndex) >= m_aParameters.size() ) ) throw IndexOutOfBoundsException(); - return makeAny( Reference< XPropertySet >( m_aParameters[ _nIndex ].get() ) ); + return Any( Reference< XPropertySet >( m_aParameters[ _nIndex ] ) ); } Reference< XEnumeration > ParameterWrapperContainer::createEnumeration() { - ::osl::MutexGuard aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); impl_checkDisposed_throw(); return new ::comphelper::OEnumerationByIndex( static_cast< XIndexAccess* >( this ) ); @@ -328,23 +323,19 @@ namespace dbtools::param void ParameterWrapperContainer::impl_checkDisposed_throw() { - if ( rBHelper.bDisposed ) + if ( m_bDisposed ) throw DisposedException( OUString(), *this ); } - void SAL_CALL ParameterWrapperContainer::disposing() + void ParameterWrapperContainer::disposing(std::unique_lock<std::mutex>& /*rGuard*/) { - ::osl::MutexGuard aGuard( m_aMutex ); - impl_checkDisposed_throw(); - for (const auto& rxParam : m_aParameters) { rxParam->dispose(); } - Parameters aEmpty; - m_aParameters.swap( aEmpty ); + Parameters().swap(m_aParameters); } diff --git a/connectivity/source/commontools/predicateinput.cxx b/connectivity/source/commontools/predicateinput.cxx index 0b229aa9ec5a..cbeaf511a943 100644 --- a/connectivity/source/commontools/predicateinput.cxx +++ b/connectivity/source/commontools/predicateinput.cxx @@ -30,10 +30,10 @@ #include <connectivity/sqlnode.hxx> #include <connectivity/PColumn.hxx> #include <comphelper/numbers.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <memory> - +#include <string_view> namespace dbtools { @@ -59,12 +59,13 @@ namespace dbtools using ::connectivity::OSQLParseNode; - static sal_Unicode lcl_getSeparatorChar( const OUString& _rSeparator, sal_Unicode _nFallback ) + static sal_Unicode lcl_getSeparatorChar( + std::u16string_view _rSeparator, sal_Unicode _nFallback ) { - OSL_ENSURE( !_rSeparator.isEmpty(), "::lcl_getSeparatorChar: invalid separator string!" ); + OSL_ENSURE( !_rSeparator.empty(), "::lcl_getSeparatorChar: invalid separator string!" ); sal_Unicode nReturn( _nFallback ); - if ( !_rSeparator.isEmpty() ) + if ( !_rSeparator.empty() ) nReturn = _rSeparator[0]; return nReturn; } @@ -146,17 +147,7 @@ namespace dbtools ) ) { - static const char sSingleQuote[] = "'"; - - sal_Int32 nIndex = -1; - sal_Int32 nTemp = 0; - while ( -1 != ( nIndex = sQuoted.indexOf( '\'',nTemp ) ) ) - { - sQuoted = sQuoted.replaceAt( nIndex, 1, "''" ); - nTemp = nIndex+2; - } - - sQuoted = sSingleQuote + sQuoted + sSingleQuote; + sQuoted = u"'" + sQuoted.replaceAll(u"'", u"''") + u"'"; } pReturn = const_cast< OSQLParser& >( m_aParser ).predicateTree( _rErrorMessage, sQuoted, m_xFormatter, _rxField ); } @@ -210,7 +201,7 @@ namespace dbtools } catch( const Exception& ) { - OSL_FAIL( "OPredicateInputController::implPredicateTree: caught an exception while dealing with the formats!" ); + TOOLS_WARN_EXCEPTION( "connectivity.commontools", "OPredicateInputController::implPredicateTree: caught an exception while dealing with the formats!" ); } bool bDecDiffers = ( nCtxDecSep != nFmtDecSep ); @@ -307,7 +298,7 @@ namespace dbtools } Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData(); - parse::OParseColumn* pColumn = new parse::OParseColumn( sField, + rtl::Reference<parse::OParseColumn> pColumn = new parse::OParseColumn( sField, OUString(), OUString(), OUString(), diff --git a/connectivity/source/commontools/propertyids.cxx b/connectivity/source/commontools/propertyids.cxx index 90c6beeede6a..cedd0f5f0614 100644 --- a/connectivity/source/commontools/propertyids.cxx +++ b/connectivity/source/commontools/propertyids.cxx @@ -95,6 +95,7 @@ namespace dbtools const OUString& OPropertyMap::getNameByIndex(sal_Int32 _nIndex) const { std::map<sal_Int32, OUString>::const_iterator aIter = m_aPropertyMap.find(_nIndex); + assert(aIter != m_aPropertyMap.end()); return aIter->second; } } diff --git a/connectivity/source/commontools/sqlerror.cxx b/connectivity/source/commontools/sqlerror.cxx index dee6f36f0b61..50c5968cd7d6 100644 --- a/connectivity/source/commontools/sqlerror.cxx +++ b/connectivity/source/commontools/sqlerror.cxx @@ -25,7 +25,6 @@ #include <com/sun/star/sdb/ErrorCondition.hpp> #include <cppuhelper/exc_hlp.hxx> -#include <rtl/ustrbuf.hxx> #include <unotools/resmgr.hxx> #include <osl/diagnose.h> @@ -50,7 +49,7 @@ namespace connectivity // versions of the public SQLError methods which are just delegated to this impl-class static const OUString& getMessagePrefix(); - OUString getErrorMessage( const ErrorCondition _eCondition, const std::optional<OUString>& _rParamValue1, const std::optional<OUString>& _rParamValue2, const std::optional<OUString>& _rParamValue3 ); + OUString getErrorMessage( const ErrorCondition _eCondition, const std::optional<OUString>& _rParamValue1, const std::optional<OUString>& _rParamValue2, const std::optional<OUString>& _rParamValue3 ) const; static ErrorCode getErrorCode( const ErrorCondition _eCondition ); void raiseException( const ErrorCondition _eCondition, const Reference< XInterface >& _rxContext, const std::optional<OUString>& _rParamValue1, const std::optional<OUString>& _rParamValue2, const std::optional<OUString>& _rParamValue3 ); void raiseException( const ErrorCondition _eCondition, const std::optional<OUString>& _rParamValue1, const std::optional<OUString>& _rParamValue2, const std::optional<OUString>& _rParamValue3 ); @@ -59,8 +58,7 @@ namespace connectivity private: /// returns the basic error message associated with the given error condition, without any parameter replacements - OUString - impl_getErrorMessage( ErrorCondition _eCondition ); + OUString impl_getErrorMessage( ErrorCondition _eCondition ) const; /// returns the SQLState associated with the given error condition static OUString @@ -81,7 +79,7 @@ namespace connectivity const OUString& SQLError_Impl::getMessagePrefix() { - static const OUString s_sMessagePrefix( "[OOoBase]" ); + static constexpr OUString s_sMessagePrefix( u"[OOoBase]"_ustr ); return s_sMessagePrefix; } @@ -103,7 +101,7 @@ namespace connectivity _rMessage = _rMessage.replaceAt( nIndex, nPlaceholderLen, *rParamValue ); } - const char* lcl_getResourceErrorID(const ErrorCondition _eCondition) + TranslateId lcl_getResourceErrorID(const ErrorCondition _eCondition) { switch (_eCondition) { @@ -126,7 +124,7 @@ namespace connectivity case css::sdb::ErrorCondition::DATA_CANNOT_SELECT_UNFILTERED: return STR_DATA_CANNOT_SELECT_UNFILTERED; } - return nullptr; + return {}; } OUString lcl_getResourceState(const ErrorCondition _eCondition) @@ -142,7 +140,7 @@ namespace connectivity } } - OUString SQLError_Impl::getErrorMessage( const ErrorCondition _eCondition, const std::optional<OUString>& _rParamValue1, const std::optional<OUString>& _rParamValue2, const std::optional<OUString>& _rParamValue3 ) + OUString SQLError_Impl::getErrorMessage( const ErrorCondition _eCondition, const std::optional<OUString>& _rParamValue1, const std::optional<OUString>& _rParamValue2, const std::optional<OUString>& _rParamValue3 ) const { OUString sErrorMessage( impl_getErrorMessage( _eCondition ) ); @@ -220,22 +218,19 @@ namespace connectivity ); } - OUString SQLError_Impl::impl_getErrorMessage( ErrorCondition _eCondition ) + OUString SQLError_Impl::impl_getErrorMessage( ErrorCondition _eCondition ) const { - OUStringBuffer aMessage; - OUString sResMessage(Translate::get(lcl_getResourceErrorID(_eCondition), m_aResources)); OSL_ENSURE( !sResMessage.isEmpty(), "SQLError_Impl::impl_getErrorMessage: illegal error condition, or invalid resource!" ); - aMessage.append( getMessagePrefix() ).append( " " ).append( sResMessage ); - - return aMessage.makeStringAndClear(); + return getMessagePrefix() + " " + sResMessage; } OUString SQLError_Impl::impl_getSQLState( ErrorCondition _eCondition ) { + static constexpr OUStringLiteral DEFAULT_STATE = u"S1000"; OUString sState = lcl_getResourceState(_eCondition); if (sState.isEmpty()) - sState = OUString::intern( RTL_CONSTASCII_USTRINGPARAM( "S1000" ) ); + sState = DEFAULT_STATE; return sState; } diff --git a/connectivity/source/commontools/statementcomposer.cxx b/connectivity/source/commontools/statementcomposer.cxx index 01f20e9c1e3c..8ebbd9ca8608 100644 --- a/connectivity/source/commontools/statementcomposer.cxx +++ b/connectivity/source/commontools/statementcomposer.cxx @@ -31,7 +31,7 @@ #include <com/sun/star/sdbc/XConnection.hpp> #include <unotools/sharedunocomponent.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <comphelper/property.hxx> @@ -69,9 +69,6 @@ namespace dbtools explicit StatementComposer_Data( const Reference< XConnection >& _rxConnection ) :xConnection( _rxConnection ) - ,sCommand() - ,sFilter() - ,sOrder() ,nCommandType( CommandType::COMMAND ) ,bEscapeProcessing( true ) ,bComposerDirty( true ) @@ -169,7 +166,7 @@ namespace dbtools xComposer->setElementaryQuery( sStatement ); // the sort order - const OUString sPropOrder( "Order" ); + static constexpr OUString sPropOrder( u"Order"_ustr ); if ( ::comphelper::hasProperty( sPropOrder, xQuery ) ) { OUString sOrder; @@ -179,7 +176,7 @@ namespace dbtools // the filter bool bApplyFilter = true; - const OUString sPropApply( "ApplyFilter" ); + static constexpr OUString sPropApply( u"ApplyFilter"_ustr ); if ( ::comphelper::hasProperty( sPropApply, xQuery ) ) { OSL_VERIFY( xQuery->getPropertyValue( sPropApply ) >>= bApplyFilter ); diff --git a/connectivity/source/commontools/warningscontainer.cxx b/connectivity/source/commontools/warningscontainer.cxx index 733bf5b4a450..ba7825612519 100644 --- a/connectivity/source/commontools/warningscontainer.cxx +++ b/connectivity/source/commontools/warningscontainer.cxx @@ -61,19 +61,19 @@ namespace dbtools void WarningsContainer::appendWarning(const SQLException& _rWarning) { - lcl_concatWarnings( m_aOwnWarnings, makeAny( _rWarning ) ); + lcl_concatWarnings( m_aOwnWarnings, Any( _rWarning ) ); } void WarningsContainer::appendWarning( const SQLContext& _rContext ) { - lcl_concatWarnings( m_aOwnWarnings, makeAny( _rContext )); + lcl_concatWarnings( m_aOwnWarnings, Any( _rContext )); } void WarningsContainer::appendWarning(const SQLWarning& _rWarning) { - lcl_concatWarnings( m_aOwnWarnings, makeAny( _rWarning ) ); + lcl_concatWarnings( m_aOwnWarnings, Any( _rWarning ) ); } diff --git a/connectivity/source/cpool/ZConnectionPool.cxx b/connectivity/source/cpool/ZConnectionPool.cxx index 7d05b6e0236b..e9c447a0db58 100644 --- a/connectivity/source/cpool/ZConnectionPool.cxx +++ b/connectivity/source/cpool/ZConnectionPool.cxx @@ -24,6 +24,7 @@ #include "ZPoolCollection.hxx" #include <connectivity/ConnectionWrapper.hxx> #include <com/sun/star/beans/XPropertySet.hpp> +#include <algorithm> using namespace ::com::sun::star::uno; @@ -31,17 +32,15 @@ using namespace ::com::sun::star::lang; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::container; -using namespace ::osl; using namespace connectivity; -#include <algorithm> void SAL_CALL OPoolTimer::onShot() { m_pPool->invalidatePooledConnections(); } -const char TIMEOUT_NODENAME[] = "Timeout"; +constexpr OUString TIMEOUT_NODENAME = u"Timeout"_ustr; OConnectionPool::OConnectionPool(const Reference< XDriver >& _xDriver, const Reference< XInterface >& _xDriverNode, @@ -129,7 +128,7 @@ struct TConnectionPoolFunctor void OConnectionPool::clear(bool _bDispose) { - MutexGuard aGuard(m_aMutex); + std::unique_lock aGuard(m_aMutex); if(m_xInvalidator->isTicking()) m_xInvalidator->stop(); @@ -153,7 +152,7 @@ void OConnectionPool::clear(bool _bDispose) Reference< XConnection > OConnectionPool::getConnectionWithInfo( const OUString& _rURL, const Sequence< PropertyValue >& _rInfo ) { - MutexGuard aGuard(m_aMutex); + std::unique_lock aGuard(m_aMutex); Reference<XConnection> xConnection; @@ -177,7 +176,7 @@ void SAL_CALL OConnectionPool::disposing( const css::lang::EventObject& Source ) Reference<XConnection> xConnection(Source.Source,UNO_QUERY); if(xConnection.is()) { - MutexGuard aGuard(m_aMutex); + std::unique_lock aGuard(m_aMutex); TActiveConnectionMap::iterator aIter = m_aActiveConnections.find(xConnection); OSL_ENSURE(aIter != m_aActiveConnections.end(),"OConnectionPool::disposing: Connection wasn't in pool"); if(aIter != m_aActiveConnections.end()) @@ -189,7 +188,7 @@ void SAL_CALL OConnectionPool::disposing( const css::lang::EventObject& Source ) } else { - m_xDriverNode.clear(); + m_xDriverNode.clear(); } } @@ -228,7 +227,7 @@ Reference< XConnection> OConnectionPool::createNewConnection(const OUString& _rU void OConnectionPool::invalidatePooledConnections() { - MutexGuard aGuard(m_aMutex); + std::unique_lock aGuard(m_aMutex); TConnectionMap::iterator aIter = m_aPool.begin(); for (; aIter != m_aPool.end(); ) { @@ -282,7 +281,7 @@ void SAL_CALL OConnectionPool::propertyChange( const PropertyChangeEvent& evt ) { if(TIMEOUT_NODENAME == evt.PropertyName) { - evt.NewValue >>= m_nALiveCount; + OPoolCollection::getNodeValue(TIMEOUT_NODENAME, m_xDriverNode) >>= m_nALiveCount; calculateTimeOuts(); } } diff --git a/connectivity/source/cpool/ZConnectionPool.hxx b/connectivity/source/cpool/ZConnectionPool.hxx index b05c7d1ff275..c5938f133f3c 100644 --- a/connectivity/source/cpool/ZConnectionPool.hxx +++ b/connectivity/source/cpool/ZConnectionPool.hxx @@ -16,12 +16,11 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZCONNECTIONPOOL_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZCONNECTIONPOOL_HXX - +#pragma once #include <sal/config.h> #include <map> +#include <mutex> #include <vector> #include <com/sun/star/sdbc/XPooledConnection.hpp> @@ -107,8 +106,8 @@ namespace connectivity TConnectionMap m_aPool; // the pooled connections TActiveConnectionMap m_aActiveConnections; // the currently active connections - ::osl::Mutex m_aMutex; - ::rtl::Reference<OPoolTimer> m_xInvalidator; // invalidates the conntection pool when shot + std::mutex m_aMutex; + ::rtl::Reference<OPoolTimer> m_xInvalidator; // invalidates the connection pool when shot css::uno::Reference< css::sdbc::XDriver > m_xDriver; // the one and only driver for this connectionpool css::uno::Reference< css::uno::XInterface > m_xDriverNode; // config node entry @@ -144,7 +143,5 @@ namespace connectivity void invalidatePooledConnections(); }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZCONNECTIONPOOL_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/cpool/ZConnectionWrapper.cxx b/connectivity/source/cpool/ZConnectionWrapper.cxx index dd4519859f21..8b1db6f2cd2f 100644 --- a/connectivity/source/cpool/ZConnectionWrapper.cxx +++ b/connectivity/source/cpool/ZConnectionWrapper.cxx @@ -23,7 +23,6 @@ using namespace connectivity; using namespace com::sun::star::uno; using namespace com::sun::star::lang; -using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; OConnectionWeakWrapper::OConnectionWeakWrapper(Reference< XAggregation >& _xConnection) diff --git a/connectivity/source/cpool/ZConnectionWrapper.hxx b/connectivity/source/cpool/ZConnectionWrapper.hxx index b74fb244662c..e4b945fa9cfe 100644 --- a/connectivity/source/cpool/ZConnectionWrapper.hxx +++ b/connectivity/source/cpool/ZConnectionWrapper.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZCONNECTIONWRAPPER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZCONNECTIONWRAPPER_HXX +#pragma once #include <cppuhelper/compbase.hxx> #include <cppuhelper/basemutex.hxx> @@ -74,6 +73,5 @@ namespace connectivity virtual void SAL_CALL close( ) override; }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZCONNECTIONWRAPPER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/cpool/ZDriverWrapper.cxx b/connectivity/source/cpool/ZDriverWrapper.cxx index 811f103bc9a6..9a1bdf971f97 100644 --- a/connectivity/source/cpool/ZDriverWrapper.cxx +++ b/connectivity/source/cpool/ZDriverWrapper.cxx @@ -48,7 +48,7 @@ namespace connectivity OSL_ENSURE(m_xDriver.is(), "ODriverWrapper::ODriverWrapper: invalid aggregate (no XDriver)!"); // set ourself as delegator - m_xDriverAggregate->setDelegator( static_cast< XWeak* >( this ) ); + m_xDriverAggregate->setDelegator( getXWeak() ); } osl_atomic_decrement( &m_refCount ); } diff --git a/connectivity/source/cpool/ZDriverWrapper.hxx b/connectivity/source/cpool/ZDriverWrapper.hxx index 854542c31c76..b08cfc3ad9b4 100644 --- a/connectivity/source/cpool/ZDriverWrapper.hxx +++ b/connectivity/source/cpool/ZDriverWrapper.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZDRIVERWRAPPER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZDRIVERWRAPPER_HXX +#pragma once #include <com/sun/star/sdbc/XDriver.hpp> #include <cppuhelper/implbase.hxx> @@ -71,8 +70,4 @@ namespace connectivity } // namespace connectivity - -#endif // INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZDRIVERWRAPPER_HXX - - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/cpool/ZPoolCollection.cxx b/connectivity/source/cpool/ZPoolCollection.cxx index 4160790ad93e..adc15a3b2a50 100644 --- a/connectivity/source/cpool/ZPoolCollection.cxx +++ b/connectivity/source/cpool/ZPoolCollection.cxx @@ -27,12 +27,11 @@ #include <com/sun/star/frame/Desktop.hpp> #include <com/sun/star/reflection/ProxyFactory.hpp> #include <com/sun/star/sdbc/DriverManager.hpp> -#include <comphelper/processfactory.hxx> #include <cppuhelper/supportsservice.hxx> #include <com/sun/star/beans/XPropertySet.hpp> #include <osl/diagnose.h> #include <sal/log.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; @@ -44,30 +43,11 @@ using namespace ::osl; using namespace connectivity; -static OUString getConnectionPoolNodeName() -{ - return "org.openoffice.Office.DataAccess/ConnectionPool"; -} - -static OUString getEnablePoolingNodeName() -{ - return "EnablePooling"; -} - -static OUString getDriverNameNodeName() -{ - return "DriverName"; -} - -static OUString getDriverSettingsNodeName() -{ - return "DriverSettings"; -} - -static OUString getEnableNodeName() -{ - return "Enable"; -} +constexpr OUString CONNECTIONPOOL_NODENAME = u"org.openoffice.Office.DataAccess/ConnectionPool"_ustr; +constexpr OUString ENABLE_POOLING = u"EnablePooling"_ustr; +constexpr OUString DRIVER_NAME = u"DriverName"_ustr; +constexpr OUString DRIVER_SETTINGS = u"DriverSettings"_ustr; +constexpr OUString ENABLE = u"Enable"_ustr; OPoolCollection::OPoolCollection(const Reference< XComponentContext >& _rxContext) @@ -77,10 +57,9 @@ OPoolCollection::OPoolCollection(const Reference< XComponentContext >& _rxContex m_xManager = DriverManager::create( m_xContext ); m_xProxyFactory = ProxyFactory::create( m_xContext ); - Reference<XPropertySet> xProp(getConfigPoolRoot(),UNO_QUERY); if ( xProp.is() ) - xProp->addPropertyChangeListener(getEnablePoolingNodeName(),this); + xProp->addPropertyChangeListener(ENABLE_POOLING,this); // attach as desktop listener to know when we have to release our pools osl_atomic_increment( &m_refCount ); { @@ -178,7 +157,7 @@ Reference< XDriver > SAL_CALL OPoolCollection::getDriverByURL( const OUString& _ else { // create a new proxy for the driver // this allows us to control the connections created by it - Reference< XAggregation > xDriverProxy = m_xProxyFactory->createProxy(xDriver.get()); + Reference< XAggregation > xDriverProxy = m_xProxyFactory->createProxy(xDriver); OSL_ENSURE(xDriverProxy.is(), "OConnectionPool::getDriverByURL: invalid proxy returned by the proxy factory!"); OConnectionPool* pConnectionPool = getConnectionPool(sImplName,xDriver,xDriverNode); @@ -189,13 +168,13 @@ Reference< XDriver > SAL_CALL OPoolCollection::getDriverByURL( const OUString& _ return xDriver; } -bool OPoolCollection::isDriverPoolingEnabled(const OUString& _sDriverImplName, +bool OPoolCollection::isDriverPoolingEnabled(std::u16string_view _sDriverImplName, Reference< XInterface >& _rxDriverNode) { bool bEnabled = false; Reference<XInterface> xConnectionPoolRoot = getConfigPoolRoot(); // then look for which of them settings are stored in the configuration - Reference< XNameAccess > xDirectAccess(openNode(getDriverSettingsNodeName(),xConnectionPoolRoot),UNO_QUERY); + Reference< XNameAccess > xDirectAccess(openNode(DRIVER_SETTINGS,xConnectionPoolRoot),UNO_QUERY); if(xDirectAccess.is()) { @@ -209,7 +188,7 @@ bool OPoolCollection::isDriverPoolingEnabled(const OUString& _sDriverImplName, { _rxDriverNode = openNode(*pDriverKeys,xDirectAccess); if(_rxDriverNode.is()) - getNodeValue(getEnableNodeName(),_rxDriverNode) >>= bEnabled; + getNodeValue(ENABLE,_rxDriverNode) >>= bEnabled; break; } } @@ -225,7 +204,7 @@ bool OPoolCollection::isPoolingEnabled() // the global "enabled" flag bool bEnabled = false; if(xConnectionPoolRoot.is()) - getNodeValue(getEnablePoolingNodeName(),xConnectionPoolRoot) >>= bEnabled; + getNodeValue(ENABLE_POOLING,xConnectionPoolRoot) >>= bEnabled; return bEnabled; } @@ -234,7 +213,7 @@ Reference<XInterface> const & OPoolCollection::getConfigPoolRoot() if(!m_xConfigNode.is()) m_xConfigNode = createWithProvider( css::configuration::theDefaultProvider::get(m_xContext), - getConnectionPoolNodeName()); + CONNECTIONPOOL_NODENAME); return m_xConfigNode; } @@ -247,13 +226,13 @@ bool OPoolCollection::isPoolingEnabledByUrl(const OUString& _sUrl, _rxDriver = m_xManager->getDriverByURL(_sUrl); if (_rxDriver.is() && isPoolingEnabled()) { - Reference< XServiceInfo > xSerivceInfo(_rxDriver,UNO_QUERY); - OSL_ENSURE(xSerivceInfo.is(),"Each driver should have a XServiceInfo interface!"); + Reference< XServiceInfo > xServiceInfo(_rxDriver,UNO_QUERY); + OSL_ENSURE(xServiceInfo.is(),"Each driver should have a XServiceInfo interface!"); - if(xSerivceInfo.is()) + if(xServiceInfo.is()) { // look for the implementation name of the driver - _rsImplName = xSerivceInfo->getImplementationName(); + _rsImplName = xServiceInfo->getImplementationName(); bEnabled = isDriverPoolingEnabled(_rsImplName,_rxDriverNode); } } @@ -281,10 +260,10 @@ OConnectionPool* OPoolCollection::getConnectionPool(const OUString& _sImplName, { Reference<XPropertySet> xProp(_xDriverNode,UNO_QUERY); if(xProp.is()) - xProp->addPropertyChangeListener(getEnableNodeName(),this); - OConnectionPool* pConnectionPool = new OConnectionPool(_xDriver,_xDriverNode,m_xProxyFactory); - aFind = m_aPools.emplace(_sImplName,pConnectionPool).first; - pRet = aFind->second.get(); + xProp->addPropertyChangeListener(ENABLE,this); + rtl::Reference<OConnectionPool> pConnectionPool = new OConnectionPool(_xDriver,_xDriverNode,m_xProxyFactory); + m_aPools.emplace(_sImplName,pConnectionPool); + pRet = pConnectionPool.get(); } OSL_ENSURE(pRet, "Could not query DriverManager from ConnectionPool!"); @@ -296,8 +275,7 @@ Reference< XInterface > OPoolCollection::createWithProvider(const Reference< XMu const OUString& _rPath) { OSL_ASSERT(_rxConfProvider.is()); - Sequence< Any > args(1); - args[0] <<= NamedValue( "nodepath", makeAny(_rPath)); + Sequence< Any > args{ Any(NamedValue( "nodepath", Any(_rPath))) }; Reference< XInterface > xInterface( _rxConfProvider->createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess", @@ -308,7 +286,7 @@ Reference< XInterface > OPoolCollection::createWithProvider(const Reference< XMu return xInterface; } -Reference<XInterface> OPoolCollection::openNode(const OUString& _rPath,const Reference<XInterface>& _xTreeNode) throw() +Reference<XInterface> OPoolCollection::openNode(const OUString& _rPath,const Reference<XInterface>& _xTreeNode) noexcept { Reference< XHierarchicalNameAccess > xHierarchyAccess(_xTreeNode, UNO_QUERY); Reference< XNameAccess > xDirectAccess(_xTreeNode, UNO_QUERY); @@ -346,7 +324,7 @@ Reference<XInterface> OPoolCollection::openNode(const OUString& _rPath,const Ref return xNode; } -Any OPoolCollection::getNodeValue(const OUString& _rPath,const Reference<XInterface>& _xTreeNode) throw() +Any OPoolCollection::getNodeValue(const OUString& _rPath,const Reference<XInterface>& _xTreeNode) noexcept { Reference< XHierarchicalNameAccess > xHierarchyAccess(_xTreeNode, UNO_QUERY); Reference< XNameAccess > xDirectAccess(_xTreeNode, UNO_QUERY); @@ -373,9 +351,9 @@ void SAL_CALL OPoolCollection::queryTermination( const EventObject& /*Event*/ ) { } -void SAL_CALL OPoolCollection::notifyTermination( const EventObject& /*Event*/ ) +void SAL_CALL OPoolCollection::notifyTermination( const EventObject& Event ) { - clearDesktop(); + disposing(Event); } void SAL_CALL OPoolCollection::disposing( const EventObject& Source ) @@ -393,17 +371,21 @@ void SAL_CALL OPoolCollection::disposing( const EventObject& Source ) if(Source.Source == m_xConfigNode) { if ( xProp.is() ) - xProp->removePropertyChangeListener(getEnablePoolingNodeName(),this); + xProp->removePropertyChangeListener(ENABLE_POOLING,this); m_xConfigNode.clear(); } else if ( xProp.is() ) - xProp->removePropertyChangeListener(getEnableNodeName(),this); + xProp->removePropertyChangeListener(ENABLE,this); } catch(const Exception&) { - SAL_WARN("connectivity.cpool", "Exception caught"); + TOOLS_WARN_EXCEPTION("connectivity.cpool", ""); } } + m_xConfigNode.clear(); + m_xProxyFactory.clear(); + m_xManager.clear(); + m_xContext.clear(); } void SAL_CALL OPoolCollection::propertyChange( const css::beans::PropertyChangeEvent& evt ) @@ -427,7 +409,7 @@ void SAL_CALL OPoolCollection::propertyChange( const css::beans::PropertyChangeE if(!bEnabled) { OUString sThisDriverName; - getNodeValue(getDriverNameNodeName(),evt.Source) >>= sThisDriverName; + getNodeValue(DRIVER_NAME,evt.Source) >>= sThisDriverName; // 1st release the driver // look if we already have a proxy for this driver MapDriver2DriverRef::iterator aLookup = m_aDriverProxies.begin(); diff --git a/connectivity/source/cpool/ZPoolCollection.hxx b/connectivity/source/cpool/ZPoolCollection.hxx index f9078c1baa72..3fdade8a9db6 100644 --- a/connectivity/source/cpool/ZPoolCollection.hxx +++ b/connectivity/source/cpool/ZPoolCollection.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZPOOLCOLLECTION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZPOOLCOLLECTION_HXX +#pragma once #include <sal/config.h> @@ -86,9 +85,9 @@ namespace connectivity static css::uno::Reference< css::uno::XInterface > createWithProvider( const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxConfProvider, const OUString& _rPath); static css::uno::Reference< css::uno::XInterface > openNode( const OUString& _rPath, - const css::uno::Reference< css::uno::XInterface >& _xTreeNode) throw(); + const css::uno::Reference< css::uno::XInterface >& _xTreeNode) noexcept; bool isPoolingEnabled(); - bool isDriverPoolingEnabled(const OUString& _sDriverImplName, + bool isDriverPoolingEnabled(std::u16string_view _sDriverImplName, css::uno::Reference< css::uno::XInterface >& _rxDriverNode); bool isPoolingEnabledByUrl( const OUString& _sUrl, css::uno::Reference< css::sdbc::XDriver >& _rxDriver, @@ -105,7 +104,7 @@ namespace connectivity public: static css::uno::Any getNodeValue( const OUString& _rPath, - const css::uno::Reference< css::uno::XInterface>& _xTreeNode)throw(); + const css::uno::Reference< css::uno::XInterface>& _xTreeNode)noexcept; // XDriverManager virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( const OUString& url ) override; @@ -130,6 +129,5 @@ namespace connectivity virtual void SAL_CALL notifyTermination( const css::lang::EventObject& Event ) override; }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZPOOLCOLLECTION_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/cpool/ZPooledConnection.cxx b/connectivity/source/cpool/ZPooledConnection.cxx index 2d0b83707905..42e8d6c02db7 100644 --- a/connectivity/source/cpool/ZPooledConnection.cxx +++ b/connectivity/source/cpool/ZPooledConnection.cxx @@ -59,7 +59,7 @@ Reference< XConnection > OPooledConnection::getConnection() { if(!m_xComponent.is() && m_xRealConnection.is()) { - Reference< XAggregation > xConProxy = m_xProxyFactory->createProxy(m_xRealConnection.get()); + Reference< XAggregation > xConProxy = m_xProxyFactory->createProxy(m_xRealConnection); m_xComponent = new OConnectionWeakWrapper(xConProxy); // register as event listener for the new connection if (m_xComponent.is()) diff --git a/connectivity/source/cpool/ZPooledConnection.hxx b/connectivity/source/cpool/ZPooledConnection.hxx index 5f529f0c3c33..79450ea081d3 100644 --- a/connectivity/source/cpool/ZPooledConnection.hxx +++ b/connectivity/source/cpool/ZPooledConnection.hxx @@ -16,9 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZPOOLEDCONNECTION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZPOOLEDCONNECTION_HXX - +#pragma once #include <cppuhelper/compbase.hxx> #include <cppuhelper/basemutex.hxx> #include <com/sun/star/sdbc/XPooledConnection.hpp> @@ -56,6 +54,5 @@ namespace connectivity }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_CPOOL_ZPOOLEDCONNECTION_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/ado/ACallableStatement.cxx b/connectivity/source/drivers/ado/ACallableStatement.cxx index d572a8f99d9e..94ad744d0134 100644 --- a/connectivity/source/drivers/ado/ACallableStatement.cxx +++ b/connectivity/source/drivers/ado/ACallableStatement.cxx @@ -30,12 +30,6 @@ using namespace com::sun::star::container; IMPLEMENT_SERVICE_INFO(OCallableStatement,"com.sun.star.sdbcx.ACallableStatement","com.sun.star.sdbc.CallableStatement"); -#define GET_PARAM() \ - ADOParameter* pParam = nullptr; \ - m_pParameters->get_Item(OLEVariant(sal_Int32(columnIndex-1)),&pParam); \ - if(pParam) \ - pParam->get_Value(&m_aValue); - //************ Class: java.sql.CallableStatement OCallableStatement::OCallableStatement( OConnection* _pConnection, const OUString& sql ) @@ -60,52 +54,76 @@ sal_Bool SAL_CALL OCallableStatement::wasNull( ) sal_Bool SAL_CALL OCallableStatement::getBoolean( sal_Int32 columnIndex ) { - GET_PARAM() + ADOParameter* pParam = nullptr; + m_pParameters->get_Item(OLEVariant(sal_Int32(columnIndex-1)),&pParam); + if(pParam) + pParam->get_Value(&m_aValue); return m_aValue.getBool(); } sal_Int8 SAL_CALL OCallableStatement::getByte( sal_Int32 columnIndex ) { - GET_PARAM() + ADOParameter* pParam = nullptr; + m_pParameters->get_Item(OLEVariant(sal_Int32(columnIndex-1)),&pParam); + if(pParam) + pParam->get_Value(&m_aValue); return m_aValue.getInt8(); } Sequence< sal_Int8 > SAL_CALL OCallableStatement::getBytes( sal_Int32 columnIndex ) { - GET_PARAM() + ADOParameter* pParam = nullptr; + m_pParameters->get_Item(OLEVariant(sal_Int32(columnIndex-1)),&pParam); + if(pParam) + pParam->get_Value(&m_aValue); return m_aValue.getByteSequence(); } css::util::Date SAL_CALL OCallableStatement::getDate( sal_Int32 columnIndex ) { - GET_PARAM() + ADOParameter* pParam = nullptr; + m_pParameters->get_Item(OLEVariant(sal_Int32(columnIndex-1)),&pParam); + if(pParam) + pParam->get_Value(&m_aValue); return m_aValue.getDate(); } double SAL_CALL OCallableStatement::getDouble( sal_Int32 columnIndex ) { - GET_PARAM() + ADOParameter* pParam = nullptr; + m_pParameters->get_Item(OLEVariant(sal_Int32(columnIndex-1)),&pParam); + if(pParam) + pParam->get_Value(&m_aValue); return m_aValue.getDouble(); } float SAL_CALL OCallableStatement::getFloat( sal_Int32 columnIndex ) { - GET_PARAM() + ADOParameter* pParam = nullptr; + m_pParameters->get_Item(OLEVariant(sal_Int32(columnIndex-1)),&pParam); + if(pParam) + pParam->get_Value(&m_aValue); return m_aValue.getFloat(); } sal_Int32 SAL_CALL OCallableStatement::getInt( sal_Int32 columnIndex ) { - GET_PARAM() + ADOParameter* pParam = nullptr; + m_pParameters->get_Item(OLEVariant(sal_Int32(columnIndex-1)),&pParam); + if(pParam) + pParam->get_Value(&m_aValue); return m_aValue.getInt32(); } sal_Int64 SAL_CALL OCallableStatement::getLong( sal_Int32 columnIndex ) { - GET_PARAM() + ADOParameter* pParam = nullptr; + m_pParameters->get_Item(OLEVariant(sal_Int32(columnIndex-1)),&pParam); + if(pParam) + pParam->get_Value(&m_aValue); return static_cast<sal_Int64>(m_aValue.getCurrency().int64); } @@ -119,28 +137,40 @@ Any SAL_CALL OCallableStatement::getObject( sal_Int32 /*columnIndex*/, const Ref sal_Int16 SAL_CALL OCallableStatement::getShort( sal_Int32 columnIndex ) { - GET_PARAM() + ADOParameter* pParam = nullptr; + m_pParameters->get_Item(OLEVariant(sal_Int32(columnIndex-1)),&pParam); + if(pParam) + pParam->get_Value(&m_aValue); return m_aValue.getInt16(); } OUString SAL_CALL OCallableStatement::getString( sal_Int32 columnIndex ) { - GET_PARAM() + ADOParameter* pParam = nullptr; + m_pParameters->get_Item(OLEVariant(sal_Int32(columnIndex-1)),&pParam); + if(pParam) + pParam->get_Value(&m_aValue); return m_aValue.getString(); } css::util::Time SAL_CALL OCallableStatement::getTime( sal_Int32 columnIndex ) { - GET_PARAM() + ADOParameter* pParam = nullptr; + m_pParameters->get_Item(OLEVariant(sal_Int32(columnIndex-1)),&pParam); + if(pParam) + pParam->get_Value(&m_aValue); return m_aValue.getTime(); } css::util::DateTime SAL_CALL OCallableStatement::getTimestamp( sal_Int32 columnIndex ) { - GET_PARAM() + ADOParameter* pParam = nullptr; + m_pParameters->get_Item(OLEVariant(sal_Int32(columnIndex-1)),&pParam); + if(pParam) + pParam->get_Value(&m_aValue); return m_aValue.getDateTime(); } @@ -209,12 +239,12 @@ Reference< XRef > SAL_CALL OCallableStatement::getRef( sal_Int32 /*columnIndex*/ } -void SAL_CALL OCallableStatement::acquire() throw() +void SAL_CALL OCallableStatement::acquire() noexcept { OPreparedStatement::acquire(); } -void SAL_CALL OCallableStatement::release() throw() +void SAL_CALL OCallableStatement::release() noexcept { OPreparedStatement::release(); } diff --git a/connectivity/source/drivers/ado/AColumn.cxx b/connectivity/source/drivers/ado/AColumn.cxx index b7175d54cf1b..8e4dd370a023 100644 --- a/connectivity/source/drivers/ado/AColumn.cxx +++ b/connectivity/source/drivers/ado/AColumn.cxx @@ -17,10 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <string_view> + #include <ado/AColumn.hxx> #include <ado/AConnection.hxx> #include <ado/Awrapado.hxx> -#include <cppuhelper/typeprovider.hxx> #include <com/sun/star/sdbc/ColumnValue.hpp> #include <comphelper/extract.hxx> #include <comphelper/servicehelper.hxx> @@ -37,19 +40,7 @@ using namespace com::sun::star::sdbc; void WpADOColumn::Create() { - _ADOColumn* pColumn = nullptr; - HRESULT hr = CoCreateInstance(ADOS::CLSID_ADOCOLUMN_25, - nullptr, - CLSCTX_INPROC_SERVER, - ADOS::IID_ADOCOLUMN_25, - reinterpret_cast<void**>(&pColumn) ); - - - if( !FAILED( hr ) ) - { - operator=( pColumn ); - pColumn->Release( ); - } + pInterface.CoCreateInstance(ADOS::CLSID_ADOCOLUMN_25, nullptr, CLSCTX_INPROC_SERVER); } OAdoColumn::OAdoColumn(bool _bCase,OConnection* _pConnection,_ADOColumn* _pColumn) @@ -58,7 +49,7 @@ OAdoColumn::OAdoColumn(bool _bCase,OConnection* _pConnection,_ADOColumn* _pColum { construct(); OSL_ENSURE(_pColumn,"Column can not be null!"); - m_aColumn = WpADOColumn(_pColumn); + m_aColumn.set(_pColumn); // m_aColumn.put_ParentCatalog(_pConnection->getAdoCatalog()->getCatalog()); fillPropertyValues(); } @@ -75,22 +66,6 @@ OAdoColumn::OAdoColumn(bool _bCase,OConnection* _pConnection) } -Sequence< sal_Int8 > OAdoColumn::getUnoTunnelId() -{ - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); -} - -// css::lang::XUnoTunnel - -sal_Int64 OAdoColumn::getSomething( const Sequence< sal_Int8 > & rId ) -{ - return isUnoTunnelId<OAdoColumn>(rId) - ? reinterpret_cast< sal_Int64 >( this ) - : OColumn_ADO::getSomething(rId); -} - void OAdoColumn::construct() { sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY; @@ -103,7 +78,7 @@ void OAdoColumn::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& r { if(m_aColumn.IsValid()) { - const char* pAdoPropertyName = nullptr; + std::u16string_view sAdoPropertyName; switch(nHandle) { @@ -161,21 +136,22 @@ void OAdoColumn::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& r break; case PROPERTY_ID_ISAUTOINCREMENT: - OTools::putValue( m_aColumn.get_Properties(), OUString( "Autoincrement" ), getBOOL( rValue ) ); + OTools::putValue( + m_aColumn.get_Properties(), std::u16string_view(u"Autoincrement"), + getBOOL(rValue)); break; - case PROPERTY_ID_IM001: case PROPERTY_ID_DESCRIPTION: - pAdoPropertyName = "Description"; + sAdoPropertyName = u"Description"; break; case PROPERTY_ID_DEFAULTVALUE: - pAdoPropertyName = "Default"; + sAdoPropertyName = u"Default"; break; } - if ( pAdoPropertyName ) - OTools::putValue( m_aColumn.get_Properties(), OUString::createFromAscii( pAdoPropertyName ), getString( rValue ) ); + if (!sAdoPropertyName.empty()) + OTools::putValue(m_aColumn.get_Properties(), sAdoPropertyName, getString(rValue)); } OColumn_ADO::setFastPropertyValue_NoBroadcast(nHandle,rValue); } @@ -207,7 +183,7 @@ void OAdoColumn::fillPropertyValues() ::comphelper::UStringMixEqual aCase(false); OTypeInfoMap::const_iterator aFind = std::find_if(pTypeInfoMap->begin(), pTypeInfoMap->end(), [&aCase] (const OTypeInfoMap::value_type& typeInfo) { - return aCase(typeInfo.second->getDBName(), OUString("VarBinary")); + return aCase(typeInfo.second->getDBName(), u"VarBinary"); }); if ( aFind != pTypeInfoMap->end() ) // change column type if necessary @@ -236,11 +212,14 @@ void OAdoColumn::fillPropertyValues() if ( aProps.IsValid() ) { - m_IsAutoIncrement = OTools::getValue( aProps, OUString("Autoincrement") ).getBool(); + m_IsAutoIncrement + = OTools::getValue(aProps, std::u16string_view(u"Autoincrement")).getBool(); - m_Description = OTools::getValue( aProps, OUString("Description") ).getString(); + m_Description + = OTools::getValue(aProps, std::u16string_view(u"Description")).getString(); - m_DefaultValue = OTools::getValue( aProps, OUString("Default") ).getString(); + m_DefaultValue + = OTools::getValue(aProps, std::u16string_view(u"Default")).getString(); } } } diff --git a/connectivity/source/drivers/ado/AColumns.cxx b/connectivity/source/drivers/ado/AColumns.cxx index e9dc7720fc99..f56a6d8d007a 100644 --- a/connectivity/source/drivers/ado/AColumns.cxx +++ b/connectivity/source/drivers/ado/AColumns.cxx @@ -29,7 +29,9 @@ #include <comphelper/servicehelper.hxx> #include <comphelper/types.hxx> #include <connectivity/dbexception.hxx> +#include <rtl/ref.hxx> #include <algorithm> +#include <string_view> #include <strings.hrc> using namespace connectivity::ado; @@ -60,9 +62,9 @@ Reference< XPropertySet > OColumns::createDescriptor() // XAppend sdbcx::ObjectType OColumns::appendObject( const OUString&, const Reference< XPropertySet >& descriptor ) { - OAdoColumn* pColumn = getUnoTunnelImplementation<OAdoColumn>( descriptor ); + rtl::Reference<OAdoColumn> pColumn = dynamic_cast<OAdoColumn*>( descriptor.get() ); Reference< XPropertySet > xColumn; - if ( pColumn == nullptr ) + if ( !pColumn.is() ) { // m_pConnection->throwGenericSQLException( STR_INVALID_COLUMN_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) ); pColumn = new OAdoColumn(isCaseSensitive(),m_pConnection); @@ -72,15 +74,6 @@ sdbcx::ObjectType OColumns::appendObject( const OUString&, const Reference< XPro WpADOColumn aColumn = pColumn->getColumnImpl(); -#if OSL_DEBUG_LEVEL > 0 - sal_Int32 nPrecision; - sal_Int32 nScale; - sal_Int32 nType; - nPrecision = aColumn.get_Precision(); - nScale = aColumn.get_NumericScale(); - nType = ADOS::MapADOType2Jdbc(aColumn.get_Type()); -#endif - OUString sTypeName; pColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)) >>= sTypeName; @@ -103,7 +96,9 @@ sdbcx::ObjectType OColumns::appendObject( const OUString&, const Reference< XPro bool bAutoIncrement = false; pColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)) >>= bAutoIncrement; if ( bAutoIncrement ) - OTools::putValue( aAddedColumn.get_Properties(), OUString("Autoincrement"), bAutoIncrement ); + OTools::putValue( + aAddedColumn.get_Properties(), std::u16string_view(u"Autoincrement"), + bAutoIncrement); if ( aFind != pTypeInfoMap->end() && aColumn.get_Type() != aAddedColumn.get_Type() ) // change column type if necessary aColumn.put_Type(aFind->first); @@ -114,7 +109,7 @@ sdbcx::ObjectType OColumns::appendObject( const OUString&, const Reference< XPro aAddedColumn.put_RelatedColumn(aColumn.get_RelatedColumn()); } } - ADOS::ThrowException(*m_pConnection->getConnection(),static_cast<XTypeProvider*>(this)); + ADOS::ThrowException(m_pConnection->getConnection(),static_cast<XTypeProvider*>(this)); return new OAdoColumn(isCaseSensitive(),m_pConnection,pColumn->getColumnImpl()); } @@ -123,7 +118,7 @@ sdbcx::ObjectType OColumns::appendObject( const OUString&, const Reference< XPro void OColumns::dropObject(sal_Int32 /*_nPos*/,const OUString& _sElementName) { if(!m_aCollection.Delete(_sElementName)) - ADOS::ThrowException(*m_pConnection->getConnection(),static_cast<XTypeProvider*>(this)); + ADOS::ThrowException(m_pConnection->getConnection(),static_cast<XTypeProvider*>(this)); } diff --git a/connectivity/source/drivers/ado/AConnection.cxx b/connectivity/source/drivers/ado/AConnection.cxx index c9251a9be88b..b879e1b11801 100644 --- a/connectivity/source/drivers/ado/AConnection.cxx +++ b/connectivity/source/drivers/ado/AConnection.cxx @@ -17,6 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <cstddef> +#include <string_view> + #include <ado/AConnection.hxx> #include <ado/ADatabaseMetaData.hxx> #include <ado/ADriver.hxx> @@ -29,9 +34,10 @@ #include <com/sun/star/sdbc/XRow.hpp> #include <com/sun/star/lang/DisposedException.hpp> #include <comphelper/servicehelper.hxx> -#include <cppuhelper/typeprovider.hxx> #include <connectivity/dbexception.hxx> +#include <o3tl/string_view.hxx> #include <osl/file.hxx> +#include <systools/win32/oleauto.hxx> #include <strings.hrc> using namespace dbtools; @@ -48,7 +54,6 @@ IMPLEMENT_SERVICE_INFO(OConnection,"com.sun.star.sdbcx.AConnection","com.sun.sta OConnection::OConnection(ODriver* _pDriver) : m_xCatalog(nullptr), m_pDriver(_pDriver), - m_pAdoConnection(nullptr), m_pCatalog(nullptr), m_nEngineType(0), m_bClosed(false), @@ -56,36 +61,19 @@ OConnection::OConnection(ODriver* _pDriver) { osl_atomic_increment( &m_refCount ); - IClassFactory2* pIUnknown = nullptr; - HRESULT hr; - hr = CoGetClassObject( ADOS::CLSID_ADOCONNECTION_21, - CLSCTX_INPROC_SERVER, - nullptr, - IID_IClassFactory2, - reinterpret_cast<void**>(&pIUnknown) ); - - if( !FAILED( hr ) ) + sal::systools::COMReference<IClassFactory2> pIUnknown; + if (!FAILED(pIUnknown.CoGetClassObject(ADOS::CLSID_ADOCONNECTION_21, CLSCTX_INPROC_SERVER))) { - ADOConnection *pCon = nullptr; - IUnknown *pOuter = nullptr; - hr = pIUnknown->CreateInstanceLic( pOuter, + HRESULT hr = pIUnknown->CreateInstanceLic(nullptr, nullptr, ADOS::IID_ADOCONNECTION_21, - ADOS::GetKeyStr().asBSTR(), - reinterpret_cast<void**>(&pCon)); + ADOS::GetKeyStr(), + reinterpret_cast<void**>(&m_aAdoConnection)); if( !FAILED( hr ) ) { - OSL_ENSURE( pCon, "OConnection::OConnection: invalid ADO object!" ); - - m_pAdoConnection = new WpADOConnection( pCon ); - // CreateInstanceLic returned an object which was already acquired - pCon->Release( ); - + OSL_ENSURE(m_aAdoConnection, "OConnection::OConnection: invalid ADO object!"); } - - // Class Factory is no longer needed - pIUnknown->Release(); } osl_atomic_decrement( &m_refCount ); @@ -95,17 +83,17 @@ OConnection::~OConnection() { } -void OConnection::construct(const OUString& url,const Sequence< PropertyValue >& info) +void OConnection::construct(std::u16string_view url,const Sequence< PropertyValue >& info) { osl_atomic_increment( &m_refCount ); setConnectionInfo(info); - sal_Int32 nLen = url.indexOf(':'); - nLen = url.indexOf(':',nLen+1); - OUString aDSN(url.copy(nLen+1)),aUID,aPWD; - if ( aDSN.startsWith("access:") ) - aDSN = aDSN.copy(7); + std::size_t nLen = url.find(':'); + nLen = url.find(':',nLen == std::u16string_view::npos ? 0 : nLen+1); + std::u16string_view aDSN(url.substr(nLen == std::u16string_view::npos ? 0 : nLen+1)); + OUString aUID,aPWD; + o3tl::starts_with(aDSN, u"access:", &aDSN); sal_Int32 nTimeout = 20; const PropertyValue *pIter = info.getConstArray(); @@ -121,20 +109,21 @@ void OConnection::construct(const OUString& url,const Sequence< PropertyValue >& } try { - if(m_pAdoConnection) + if(m_aAdoConnection) { - if(m_pAdoConnection->Open(aDSN,aUID,aPWD,adConnectUnspecified)) - m_pAdoConnection->PutCommandTimeout(nTimeout); + if(m_aAdoConnection.Open(aDSN,aUID,aPWD,adConnectUnspecified)) + m_aAdoConnection.PutCommandTimeout(nTimeout); else - ADOS::ThrowException(*m_pAdoConnection,*this); - if(m_pAdoConnection->get_State() != adStateOpen) + ADOS::ThrowException(m_aAdoConnection,*this); + if(m_aAdoConnection.get_State() != adStateOpen) throwGenericSQLException( STR_NO_CONNECTION,*this ); - WpADOProperties aProps = m_pAdoConnection->get_Properties(); + WpADOProperties aProps = m_aAdoConnection.get_Properties(); if(aProps.IsValid()) { - OTools::putValue(aProps,OUString("Jet OLEDB:ODBC Parsing"),true); - OLEVariant aVar(OTools::getValue(aProps,OUString("Jet OLEDB:Engine Type"))); + OTools::putValue(aProps, std::u16string_view(u"ACE OLEDB:ODBC Parsing"), true); + OLEVariant aVar( + OTools::getValue(aProps, std::u16string_view(u"ACE OLEDB:Engine Type"))); if(!aVar.isNull() && !aVar.isEmpty()) m_nEngineType = aVar.getInt32(); } @@ -158,10 +147,9 @@ Reference< XStatement > SAL_CALL OConnection::createStatement( ) ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OConnection_BASE::rBHelper.bDisposed); - OStatement* pStmt = new OStatement(this); - Reference< XStatement > xStmt = pStmt; - m_aStatements.push_back(WeakReferenceHelper(*pStmt)); - return pStmt; + Reference< XStatement > xStmt = new OStatement(this); + m_aStatements.push_back(WeakReferenceHelper(xStmt)); + return xStmt; } Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement( const OUString& sql ) @@ -170,9 +158,8 @@ Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement( const OU checkDisposed(OConnection_BASE::rBHelper.bDisposed); - OPreparedStatement* pStmt = new OPreparedStatement(this, sql); - Reference< XPreparedStatement > xPStmt = pStmt; - m_aStatements.push_back(WeakReferenceHelper(*pStmt)); + Reference< XPreparedStatement > xPStmt = new OPreparedStatement(this, sql); + m_aStatements.push_back(WeakReferenceHelper(xPStmt)); return xPStmt; } @@ -182,9 +169,8 @@ Reference< XPreparedStatement > SAL_CALL OConnection::prepareCall( const OUStrin checkDisposed(OConnection_BASE::rBHelper.bDisposed); - OCallableStatement* pStmt = new OCallableStatement(this, sql); - Reference< XPreparedStatement > xPStmt = pStmt; - m_aStatements.push_back(WeakReferenceHelper(*pStmt)); + Reference< XPreparedStatement > xPStmt = new OCallableStatement(this, sql); + m_aStatements.push_back(WeakReferenceHelper(xPStmt)); return xPStmt; } @@ -195,13 +181,13 @@ OUString SAL_CALL OConnection::nativeSQL( const OUString& _sql ) OUString sql = _sql; - WpADOProperties aProps = m_pAdoConnection->get_Properties(); + WpADOProperties aProps = m_aAdoConnection.get_Properties(); if(aProps.IsValid()) { - OTools::putValue(aProps,OUString("Jet OLEDB:ODBC Parsing"),true); + OTools::putValue(aProps, std::u16string_view(u"ACE OLEDB:ODBC Parsing"), true); WpADOCommand aCommand; aCommand.Create(); - aCommand.put_ActiveConnection(static_cast<IDispatch*>(*m_pAdoConnection)); + aCommand.put_ActiveConnection(static_cast<IDispatch*>(m_aAdoConnection)); aCommand.put_CommandText(sql); sql = aCommand.get_CommandText(); } @@ -217,9 +203,9 @@ void SAL_CALL OConnection::setAutoCommit( sal_Bool autoCommit ) m_bAutocommit = autoCommit; if(!autoCommit) - m_pAdoConnection->BeginTrans(); + m_aAdoConnection.BeginTrans(); else - m_pAdoConnection->RollbackTrans(); + m_aAdoConnection.RollbackTrans(); } sal_Bool SAL_CALL OConnection::getAutoCommit( ) @@ -237,7 +223,7 @@ void SAL_CALL OConnection::commit( ) checkDisposed(OConnection_BASE::rBHelper.bDisposed); - m_pAdoConnection->CommitTrans(); + m_aAdoConnection.CommitTrans(); } void SAL_CALL OConnection::rollback( ) @@ -246,14 +232,14 @@ void SAL_CALL OConnection::rollback( ) checkDisposed(OConnection_BASE::rBHelper.bDisposed); - m_pAdoConnection->RollbackTrans(); + m_aAdoConnection.RollbackTrans(); } sal_Bool SAL_CALL OConnection::isClosed( ) { ::osl::MutexGuard aGuard( m_aMutex ); - return OConnection_BASE::rBHelper.bDisposed && !m_pAdoConnection->get_State(); + return OConnection_BASE::rBHelper.bDisposed && !m_aAdoConnection.get_State(); } Reference< XDatabaseMetaData > SAL_CALL OConnection::getMetaData( ) @@ -278,8 +264,8 @@ void SAL_CALL OConnection::setReadOnly( sal_Bool readOnly ) checkDisposed(OConnection_BASE::rBHelper.bDisposed); - m_pAdoConnection->put_Mode(readOnly ? adModeRead : adModeReadWrite); - ADOS::ThrowException(*m_pAdoConnection,*this); + m_aAdoConnection.put_Mode(readOnly ? adModeRead : adModeReadWrite); + ADOS::ThrowException(m_aAdoConnection,*this); } sal_Bool SAL_CALL OConnection::isReadOnly( ) @@ -288,7 +274,7 @@ sal_Bool SAL_CALL OConnection::isReadOnly( ) checkDisposed(OConnection_BASE::rBHelper.bDisposed); - return m_pAdoConnection->get_Mode() == adModeRead; + return m_aAdoConnection.get_Mode() == adModeRead; } void SAL_CALL OConnection::setCatalog( const OUString& catalog ) @@ -296,8 +282,8 @@ void SAL_CALL OConnection::setCatalog( const OUString& catalog ) ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OConnection_BASE::rBHelper.bDisposed); - m_pAdoConnection->PutDefaultDatabase(catalog); - ADOS::ThrowException(*m_pAdoConnection,*this); + m_aAdoConnection.PutDefaultDatabase(catalog); + ADOS::ThrowException(m_aAdoConnection,*this); } OUString SAL_CALL OConnection::getCatalog( ) @@ -305,7 +291,7 @@ OUString SAL_CALL OConnection::getCatalog( ) ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OConnection_BASE::rBHelper.bDisposed); - return m_pAdoConnection->GetDefaultDatabase(); + return m_aAdoConnection.GetDefaultDatabase(); } void SAL_CALL OConnection::setTransactionIsolation( sal_Int32 level ) @@ -336,8 +322,8 @@ void SAL_CALL OConnection::setTransactionIsolation( sal_Int32 level ) OSL_FAIL("OConnection::setTransactionIsolation invalid level"); return; } - m_pAdoConnection->put_IsolationLevel(eIso); - ADOS::ThrowException(*m_pAdoConnection,*this); + m_aAdoConnection.put_IsolationLevel(eIso); + ADOS::ThrowException(m_aAdoConnection,*this); } sal_Int32 SAL_CALL OConnection::getTransactionIsolation( ) @@ -347,7 +333,7 @@ sal_Int32 SAL_CALL OConnection::getTransactionIsolation( ) sal_Int32 nRet = 0; - switch(m_pAdoConnection->get_IsolationLevel()) + switch(m_aAdoConnection.get_IsolationLevel()) { case adXactUnspecified: nRet = TransactionIsolation::NONE; @@ -367,7 +353,7 @@ sal_Int32 SAL_CALL OConnection::getTransactionIsolation( ) default: OSL_FAIL("OConnection::setTransactionIsolation invalid level"); } - ADOS::ThrowException(*m_pAdoConnection,*this); + ADOS::ThrowException(m_aAdoConnection,*this); return nRet; } @@ -410,7 +396,7 @@ void OConnection::buildTypeInfo() { ::osl::MutexGuard aGuard( m_aMutex ); - ADORecordset *pRecordset = m_pAdoConnection->getTypeInfo(); + ADORecordset *pRecordset = m_aAdoConnection.getTypeInfo(); if ( pRecordset ) { pRecordset->AddRef(); @@ -475,31 +461,26 @@ void OConnection::disposing() m_xCatalog = css::uno::WeakReference< css::sdbcx::XTablesSupplier>(); m_pDriver = nullptr; - m_pAdoConnection->Close(); + m_aAdoConnection.Close(); for (auto& rEntry : m_aTypeInfo) delete rEntry.second; m_aTypeInfo.clear(); - delete m_pAdoConnection; - m_pAdoConnection = nullptr; + m_aAdoConnection.clear(); } sal_Int64 SAL_CALL OConnection::getSomething( const css::uno::Sequence< sal_Int8 >& rId ) { - return isUnoTunnelId<OConnection>(rId) - ? - reinterpret_cast< sal_Int64 >( this ) - : - OConnection_BASE::getSomething(rId); + return comphelper::getSomethingImpl(rId, this, + comphelper::FallbackToGetSomethingOf<OConnection_BASE>{}); } Sequence< sal_Int8 > OConnection::getUnoTunnelId() { - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); + static const comphelper::UnoIdInit implId; + return implId.getSeq(); } const OExtendedTypeInfo* OConnection::getTypeInfoFromType(const OTypeInfoMap& _rTypeInfo, diff --git a/connectivity/source/drivers/ado/ADatabaseMetaData.cxx b/connectivity/source/drivers/ado/ADatabaseMetaData.cxx index 8e46761e8c27..65e0a80f52a8 100644 --- a/connectivity/source/drivers/ado/ADatabaseMetaData.cxx +++ b/connectivity/source/drivers/ado/ADatabaseMetaData.cxx @@ -28,6 +28,7 @@ #include <FDatabaseMetaDataResultSet.hxx> #include <comphelper/types.hxx> #include <connectivity/dbexception.hxx> +#include <rtl/ref.hxx> using namespace ::comphelper; @@ -41,15 +42,15 @@ using namespace com::sun::star::sdbc; ODatabaseMetaData::ODatabaseMetaData(OConnection* _pCon) : ::connectivity::ODatabaseMetaDataBase(_pCon,_pCon->getConnectionInfo()) - ,m_pADOConnection(_pCon->getConnection()) + ,m_rADOConnection(_pCon->getConnection()) ,m_pConnection(_pCon) { } sal_Int32 ODatabaseMetaData::getInt32Property(const OUString& _aProperty) { - connectivity::ado::WpADOProperties aProps(m_pADOConnection->get_Properties()); - // ADOS::ThrowException(*m_pADOConnection,*this); + connectivity::ado::WpADOProperties aProps(m_rADOConnection.get_Properties()); + // ADOS::ThrowException(m_rADOConnection,*this); OSL_ENSURE(aProps.IsValid(),"There are no properties at the connection"); ADO_PROP(_aProperty); sal_Int32 nValue(0); @@ -61,8 +62,8 @@ sal_Int32 ODatabaseMetaData::getInt32Property(const OUString& _aProperty) bool ODatabaseMetaData::getBoolProperty(const OUString& _aProperty) { - connectivity::ado::WpADOProperties aProps(m_pADOConnection->get_Properties()); - ADOS::ThrowException(*m_pADOConnection,*this); + connectivity::ado::WpADOProperties aProps(m_rADOConnection.get_Properties()); + ADOS::ThrowException(m_rADOConnection,*this); OSL_ENSURE(aProps.IsValid(),"There are no properties at the connection"); ADO_PROP(_aProperty); return !aVar.isNull() && !aVar.isEmpty() && aVar.getBool(); @@ -70,8 +71,8 @@ bool ODatabaseMetaData::getBoolProperty(const OUString& _aProperty) OUString ODatabaseMetaData::getStringProperty(const OUString& _aProperty) { - connectivity::ado::WpADOProperties aProps(m_pADOConnection->get_Properties()); - ADOS::ThrowException(*m_pADOConnection,*this); + connectivity::ado::WpADOProperties aProps(m_rADOConnection.get_Properties()); + ADOS::ThrowException(m_rADOConnection,*this); OSL_ENSURE(aProps.IsValid(),"There are no properties at the connection"); ADO_PROP(_aProperty); @@ -84,12 +85,11 @@ OUString ODatabaseMetaData::getStringProperty(const OUString& _aProperty) Reference< XResultSet > ODatabaseMetaData::impl_getTypeInfo_throw( ) { - ADORecordset *pRecordset = m_pADOConnection->getTypeInfo(); + ADORecordset *pRecordset = m_rADOConnection.getTypeInfo(); - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(pRecordset); pResult->setTypeInfoMap(ADOS::isJetEngine(m_pConnection->getEngineType())); - Reference< XResultSet > xRef = pResult; - return xRef; + return pResult; } Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCatalogs( ) @@ -98,16 +98,13 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCatalogs( ) vtEmpty.setNoArg(); ADORecordset *pRecordset = nullptr; - m_pADOConnection->OpenSchema(adSchemaCatalogs,vtEmpty,vtEmpty,&pRecordset); - ADOS::ThrowException(*m_pADOConnection,*this); - - Reference< XResultSet > xRef; + m_rADOConnection.OpenSchema(adSchemaCatalogs,vtEmpty,vtEmpty,&pRecordset); + ADOS::ThrowException(m_rADOConnection,*this); - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(pRecordset); pResult->setCatalogsMap(); - xRef = pResult; - return xRef; + return pResult; } OUString ODatabaseMetaData::impl_getCatalogSeparator_throw( ) @@ -121,78 +118,63 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getSchemas( ) vtEmpty.setNoArg(); ADORecordset *pRecordset = nullptr; - m_pADOConnection->OpenSchema(adSchemaSchemata,vtEmpty,vtEmpty,&pRecordset); - ADOS::ThrowException(*m_pADOConnection,*this); - - Reference< XResultSet > xRef; + m_rADOConnection.OpenSchema(adSchemaSchemata,vtEmpty,vtEmpty,&pRecordset); + ADOS::ThrowException(m_rADOConnection,*this); - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(pRecordset); pResult->setSchemasMap(); - xRef = pResult; - return xRef; + return pResult; } Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumnPrivileges( const Any& catalog, const OUString& schema, const OUString& table, const OUString& columnNamePattern ) { - ADORecordset *pRecordset = m_pADOConnection->getColumnPrivileges(catalog,schema,table,columnNamePattern); - ADOS::ThrowException(*m_pADOConnection,*this); - - Reference< XResultSet > xRef; + ADORecordset *pRecordset = m_rADOConnection.getColumnPrivileges(catalog,schema,table,columnNamePattern); + ADOS::ThrowException(m_rADOConnection,*this); - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(pRecordset); pResult->setColumnPrivilegesMap(); - xRef = pResult; - return xRef; + return pResult; } Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns( const Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const OUString& columnNamePattern ) { - ADORecordset *pRecordset = m_pADOConnection->getColumns(catalog,schemaPattern,tableNamePattern,columnNamePattern); - ADOS::ThrowException(*m_pADOConnection,*this); + ADORecordset *pRecordset = m_rADOConnection.getColumns(catalog,schemaPattern,tableNamePattern,columnNamePattern); + ADOS::ThrowException(m_rADOConnection,*this); - Reference< XResultSet > xRef; - - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(pRecordset); pResult->setColumnsMap(); - xRef = pResult; - return xRef; + return pResult; } Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( const Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const Sequence< OUString >& types ) { - ADORecordset *pRecordset = m_pADOConnection->getTables(catalog,schemaPattern,tableNamePattern,types); - ADOS::ThrowException(*m_pADOConnection,*this); + ADORecordset *pRecordset = m_rADOConnection.getTables(catalog,schemaPattern,tableNamePattern,types); + ADOS::ThrowException(m_rADOConnection,*this); - Reference< XResultSet > xRef; - - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(pRecordset); pResult->setTablesMap(); - xRef = pResult; - return xRef; + return pResult; } Reference< XResultSet > SAL_CALL ODatabaseMetaData::getProcedureColumns( const Any& catalog, const OUString& schemaPattern, const OUString& procedureNamePattern, const OUString& columnNamePattern ) { - ADORecordset *pRecordset = m_pADOConnection->getProcedureColumns(catalog,schemaPattern,procedureNamePattern,columnNamePattern); - ADOS::ThrowException(*m_pADOConnection,*this); + ADORecordset *pRecordset = m_rADOConnection.getProcedureColumns(catalog,schemaPattern,procedureNamePattern,columnNamePattern); + ADOS::ThrowException(m_rADOConnection,*this); - Reference< XResultSet > xRef; - - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(pRecordset); pResult->setProcedureColumnsMap(); - xRef = pResult; - return xRef; + return pResult; } Reference< XResultSet > SAL_CALL ODatabaseMetaData::getProcedures( @@ -200,16 +182,13 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getProcedures( const OUString& procedureNamePattern ) { // Create elements used in the array - ADORecordset *pRecordset = m_pADOConnection->getProcedures(catalog,schemaPattern,procedureNamePattern); - ADOS::ThrowException(*m_pADOConnection,*this); - - Reference< XResultSet > xRef; + ADORecordset *pRecordset = m_rADOConnection.getProcedures(catalog,schemaPattern,procedureNamePattern); + ADOS::ThrowException(m_rADOConnection,*this); - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(pRecordset); pResult->setProceduresMap(); - xRef = pResult; - return xRef; + return pResult; } sal_Int32 SAL_CALL ODatabaseMetaData::getMaxBinaryLiteralLength( ) @@ -275,61 +254,50 @@ sal_Int32 ODatabaseMetaData::impl_getMaxTablesInSelect_throw( ) Reference< XResultSet > SAL_CALL ODatabaseMetaData::getExportedKeys( const Any& catalog, const OUString& schema, const OUString& table ) { - ADORecordset *pRecordset = m_pADOConnection->getExportedKeys(catalog,schema,table); - ADOS::ThrowException(*m_pADOConnection,*this); + ADORecordset *pRecordset = m_rADOConnection.getExportedKeys(catalog,schema,table); + ADOS::ThrowException(m_rADOConnection,*this); - Reference< XResultSet > xRef; - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(pRecordset); pResult->setCrossReferenceMap(); - xRef = pResult; - return xRef; + return pResult; } Reference< XResultSet > SAL_CALL ODatabaseMetaData::getImportedKeys( const Any& catalog, const OUString& schema, const OUString& table ) { - ADORecordset *pRecordset = m_pADOConnection->getImportedKeys(catalog,schema,table); - ADOS::ThrowException(*m_pADOConnection,*this); + ADORecordset *pRecordset = m_rADOConnection.getImportedKeys(catalog,schema,table); + ADOS::ThrowException(m_rADOConnection,*this); - Reference< XResultSet > xRef; - - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(pRecordset); pResult->setCrossReferenceMap(); - xRef = pResult; - return xRef; + return pResult; } Reference< XResultSet > SAL_CALL ODatabaseMetaData::getPrimaryKeys( const Any& catalog, const OUString& schema, const OUString& table ) { - ADORecordset *pRecordset = m_pADOConnection->getPrimaryKeys(catalog,schema,table); - ADOS::ThrowException(*m_pADOConnection,*this); + ADORecordset *pRecordset = m_rADOConnection.getPrimaryKeys(catalog,schema,table); + ADOS::ThrowException(m_rADOConnection,*this); - Reference< XResultSet > xRef; - - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(pRecordset); pResult->setPrimaryKeysMap(); - xRef = pResult; - return xRef; + return pResult; } Reference< XResultSet > SAL_CALL ODatabaseMetaData::getIndexInfo( const Any& catalog, const OUString& schema, const OUString& table, sal_Bool unique, sal_Bool approximate ) { - ADORecordset *pRecordset = m_pADOConnection->getIndexInfo(catalog,schema,table,unique,approximate); - ADOS::ThrowException(*m_pADOConnection,*this); - - Reference< XResultSet > xRef; + ADORecordset *pRecordset = m_rADOConnection.getIndexInfo(catalog,schema,table,unique,approximate); + ADOS::ThrowException(m_rADOConnection,*this); - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(pRecordset); pResult->setIndexInfoMap(); - xRef = pResult; - return xRef; + return pResult; } Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges( @@ -340,16 +308,16 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges( { // the jet provider doesn't support this method // Create elements used in the array - ADORecordset *pRecordset = m_pADOConnection->getTablePrivileges(catalog,schemaPattern,tableNamePattern); - ADOS::ThrowException(*m_pADOConnection,*this); + ADORecordset *pRecordset = m_rADOConnection.getTablePrivileges(catalog,schemaPattern,tableNamePattern); + ADOS::ThrowException(m_rADOConnection,*this); - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(pRecordset); pResult->setTablePrivilegesMap(); xRef = pResult; } else { - ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTablePrivileges); + rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTablePrivileges); xRef = pResult; ::connectivity::ODatabaseMetaDataResultSet::ORows aRows; ::connectivity::ODatabaseMetaDataResultSet::ORow aRow(8); @@ -379,7 +347,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges( aRows.push_back(aRow); aRow[6] = ::connectivity::ODatabaseMetaDataResultSet::getDropValue(); aRows.push_back(aRow); - pResult->setRows(aRows); + pResult->setRows(std::move(aRows)); } return xRef; @@ -390,16 +358,13 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCrossReference( const OUString& primaryTable, const Any& foreignCatalog, const OUString& foreignSchema, const OUString& foreignTable ) { - ADORecordset *pRecordset = m_pADOConnection->getCrossReference(primaryCatalog,primarySchema,primaryTable,foreignCatalog,foreignSchema,foreignTable); - ADOS::ThrowException(*m_pADOConnection,*this); - - Reference< XResultSet > xRef; + ADORecordset *pRecordset = m_rADOConnection.getCrossReference(primaryCatalog,primarySchema,primaryTable,foreignCatalog,foreignSchema,foreignTable); + ADOS::ThrowException(m_rADOConnection,*this); - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(pRecordset); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(pRecordset); pResult->setCrossReferenceMap(); - xRef = pResult; - return xRef; + return pResult; } sal_Bool SAL_CALL ODatabaseMetaData::doesMaxRowSizeIncludeBlobs( ) @@ -825,7 +790,7 @@ sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92IntermediateSQL( ) OUString SAL_CALL ODatabaseMetaData::getURL( ) { - return "sdbc:ado:"+ m_pADOConnection->GetConnectionString(); + return "sdbc:ado:"+ m_rADOConnection.GetConnectionString(); } OUString SAL_CALL ODatabaseMetaData::getUserName( ) @@ -871,7 +836,7 @@ sal_Int32 SAL_CALL ODatabaseMetaData::getDriverMajorVersion( ) sal_Int32 SAL_CALL ODatabaseMetaData::getDefaultTransactionIsolation( ) { sal_Int32 nRet = TransactionIsolation::NONE; - switch(m_pADOConnection->get_IsolationLevel()) + switch(m_rADOConnection.get_IsolationLevel()) { case adXactReadCommitted: nRet = TransactionIsolation::READ_COMMITTED; @@ -898,22 +863,20 @@ sal_Int32 SAL_CALL ODatabaseMetaData::getDriverMinorVersion( ) OUString SAL_CALL ODatabaseMetaData::getSQLKeywords( ) { - ADORecordset *pRecordset = nullptr; + WpADORecordset aRecordset; OLEVariant vtEmpty; vtEmpty.setNoArg(); - m_pADOConnection->OpenSchema(adSchemaDBInfoKeywords,vtEmpty,vtEmpty,&pRecordset); - OSL_ENSURE(pRecordset,"getSQLKeywords: no resultset!"); - ADOS::ThrowException(*m_pADOConnection,*this); - if ( pRecordset ) + m_rADOConnection.OpenSchema(adSchemaDBInfoKeywords,vtEmpty,vtEmpty,&aRecordset); + OSL_ENSURE(aRecordset,"getSQLKeywords: no resultset!"); + ADOS::ThrowException(m_rADOConnection,*this); + if ( aRecordset ) { - WpADORecordset aRecordset(pRecordset); - aRecordset.MoveFirst(); OLEVariant aValue; OUString aRet; while(!aRecordset.IsAtEOF()) { - WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(aRecordset.GetFields()); + WpOLEAppendCollection<ADOFields, WpADOField> aFields(aRecordset.GetFields()); WpADOField aField(aFields.GetItem(0)); aField.get_Value(aValue); aRet += aValue.getString() + ","; @@ -933,8 +896,7 @@ OUString SAL_CALL ODatabaseMetaData::getSearchStringEscape( ) OUString SAL_CALL ODatabaseMetaData::getStringFunctions( ) { - OUString aValue; - return aValue.copy(0,aValue.lastIndexOf(',')); + return OUString(); } OUString SAL_CALL ODatabaseMetaData::getTimeDateFunctions( ) @@ -944,8 +906,7 @@ OUString SAL_CALL ODatabaseMetaData::getTimeDateFunctions( ) OUString SAL_CALL ODatabaseMetaData::getSystemFunctions( ) { - OUString aValue; - return aValue.copy(0,aValue.lastIndexOf(',')); + return OUString(); } OUString SAL_CALL ODatabaseMetaData::getNumericFunctions( ) diff --git a/connectivity/source/drivers/ado/ADatabaseMetaDataImpl.cxx b/connectivity/source/drivers/ado/ADatabaseMetaDataImpl.cxx index 34eb7501aae4..b7872070603f 100644 --- a/connectivity/source/drivers/ado/ADatabaseMetaDataImpl.cxx +++ b/connectivity/source/drivers/ado/ADatabaseMetaDataImpl.cxx @@ -17,6 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <string_view> + #include <ado/ADatabaseMetaData.hxx> #include <ado/ADatabaseMetaDataResultSetMetaData.hxx> #include <ado/Awrapado.hxx> @@ -25,6 +29,9 @@ #include <ado/AIndex.hxx> #include <ado/AKey.hxx> #include <ado/ATable.hxx> + +#include <systools/win32/oleauto.hxx> + #include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/sdbc/ProcedureResult.hpp> #include <com/sun/star/sdbc/ColumnValue.hpp> @@ -44,24 +51,22 @@ using namespace ::com::sun::star::uno; void ODatabaseMetaData::fillLiterals() { - ADORecordset *pRecordset = nullptr; + WpADORecordset aRecordset; OLEVariant vtEmpty; vtEmpty.setNoArg(); - m_pADOConnection->OpenSchema(adSchemaDBInfoLiterals,vtEmpty,vtEmpty,&pRecordset); + m_rADOConnection.OpenSchema(adSchemaDBInfoLiterals,vtEmpty,vtEmpty,&aRecordset); - ADOS::ThrowException(*m_pADOConnection,*this); + ADOS::ThrowException(m_rADOConnection,*this); - OSL_ENSURE(pRecordset,"fillLiterals: no resultset!"); - if ( pRecordset ) + OSL_ENSURE(aRecordset,"fillLiterals: no resultset!"); + if ( aRecordset ) { - WpADORecordset aRecordset(pRecordset); - aRecordset.MoveFirst(); OLEVariant aValue; LiteralInfo aInfo; while(!aRecordset.IsAtEOF()) { - WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(aRecordset.GetFields()); + WpOLEAppendCollection<ADOFields, WpADOField> aFields(aRecordset.GetFields()); WpADOField aField(aFields.GetItem(1)); aInfo.pwszLiteralValue = aField.get_Value().getString(); aField = aFields.GetItem(5); @@ -383,19 +388,7 @@ RightsEnum OAdoGroup::Map2Right(sal_Int32 _eNum) void WpADOIndex::Create() { - _ADOIndex* pIndex = nullptr; - HRESULT hr = CoCreateInstance(ADOS::CLSID_ADOINDEX_25, - nullptr, - CLSCTX_INPROC_SERVER, - ADOS::IID_ADOINDEX_25, - reinterpret_cast<void**>(&pIndex) ); - - - if( !FAILED( hr ) ) - { - operator=( pIndex ); - pIndex->Release(); - } + pInterface.CoCreateInstance(ADOS::CLSID_ADOINDEX_25, nullptr, CLSCTX_INPROC_SERVER); } void OAdoIndex::fillPropertyValues() @@ -411,19 +404,7 @@ void OAdoIndex::fillPropertyValues() void WpADOKey::Create() { - _ADOKey* pKey = nullptr; - HRESULT hr = CoCreateInstance(ADOS::CLSID_ADOKEY_25, - nullptr, - CLSCTX_INPROC_SERVER, - ADOS::IID_ADOKEY_25, - reinterpret_cast<void**>(&pKey) ); - - - if( !FAILED( hr ) ) - { - operator=( pKey ); - pKey->Release(); - } + pInterface.CoCreateInstance(ADOS::CLSID_ADOKEY_25, nullptr, CLSCTX_INPROC_SERVER); } void OAdoKey::fillPropertyValues() @@ -520,29 +501,17 @@ KeyTypeEnum OAdoKey::Map2KeyRule(sal_Int32 _eNum) void WpADOTable::Create() { - _ADOTable* pTable = nullptr; - HRESULT hr = CoCreateInstance(ADOS::CLSID_ADOTABLE_25, - nullptr, - CLSCTX_INPROC_SERVER, - ADOS::IID_ADOTABLE_25, - reinterpret_cast<void**>(&pTable) ); - - - if( !FAILED( hr ) ) - { - operator=( pTable ); - pTable->Release(); - } + pInterface.CoCreateInstance(ADOS::CLSID_ADOTABLE_25, nullptr, CLSCTX_INPROC_SERVER); } -OUString WpADOCatalog::GetObjectOwner(const OUString& _rName, ObjectTypeEnum _eNum) +OUString WpADOCatalog::GetObjectOwner(std::u16string_view _rName, ObjectTypeEnum _eNum) { OLEVariant _rVar; _rVar.setNoArg(); - OLEString aBSTR; - OLEString sStr1(_rName); - pInterface->GetObjectOwner(sStr1.asBSTR(),_eNum,_rVar,aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + sal::systools::BStr sStr1(_rName); + pInterface->GetObjectOwner(sStr1, _eNum, _rVar, &aBSTR); + return OUString(aBSTR); } void OAdoTable::fillPropertyValues() @@ -559,26 +528,15 @@ void OAdoTable::fillPropertyValues() { WpADOProperties aProps = m_aTable.get_Properties(); if(aProps.IsValid()) - m_Description = OTools::getValue(aProps,OUString("Description")).getString(); + m_Description + = OTools::getValue(aProps, std::u16string_view(u"Description")).getString(); } } } void WpADOUser::Create() { - _ADOUser* pUser = nullptr; - HRESULT hr = CoCreateInstance(ADOS::CLSID_ADOUSER_25, - nullptr, - CLSCTX_INPROC_SERVER, - ADOS::IID_ADOUSER_25, - reinterpret_cast<void**>(&pUser) ); - - - if( !FAILED( hr ) ) - { - operator=( pUser ); - pUser->Release(); - } + pInterface.CoCreateInstance(ADOS::CLSID_ADOUSER_25, nullptr, CLSCTX_INPROC_SERVER); } diff --git a/connectivity/source/drivers/ado/ADatabaseMetaDataResultSet.cxx b/connectivity/source/drivers/ado/ADatabaseMetaDataResultSet.cxx index 16acbc133bf3..bb5bda634cfc 100644 --- a/connectivity/source/drivers/ado/ADatabaseMetaDataResultSet.cxx +++ b/connectivity/source/drivers/ado/ADatabaseMetaDataResultSet.cxx @@ -34,7 +34,7 @@ #include <cppuhelper/typeprovider.hxx> #include <comphelper/seqstream.hxx> #include <connectivity/dbexception.hxx> - +#include <rtl/ref.hxx> #include <oledb.h> @@ -53,7 +53,6 @@ ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet(ADORecordset* _pRecordSet :ODatabaseMetaDataResultSet_BASE(m_aMutex) ,OPropertySetHelper(ODatabaseMetaDataResultSet_BASE::rBHelper) ,m_pRecordSet(_pRecordSet) - ,m_aStatement(nullptr) ,m_nRowPos(0) ,m_bWasNull(false) ,m_bEOF(false) @@ -88,7 +87,7 @@ void ODatabaseMetaDataResultSet::disposing() ::osl::MutexGuard aGuard(m_aMutex); if(m_pRecordSet) m_pRecordSet->Close(); - m_aStatement = nullptr; + m_aStatement.clear(); m_xMetaData.clear(); } @@ -151,14 +150,14 @@ Reference< css::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getBinar //Copy the data only up to the Actual Size of Field. sal_Int32 nSize = aField.GetActualSize(); Sequence<sal_Int8> aData(nSize); - long index = 0; + sal_Int32 index = 0; while(index < nSize) { m_aValue = aField.GetChunk(BLOCK_SIZE); if(m_aValue.isNull()) break; UCHAR chData; - for(long index2 = 0;index2 < BLOCK_SIZE;++index2) + for(LONG index2 = 0;index2 < BLOCK_SIZE;++index2) { HRESULT hr = ::SafeArrayGetElement(m_aValue.parray,&index2,&chData); if(SUCCEEDED(hr)) @@ -691,21 +690,41 @@ void ODatabaseMetaDataResultSet::setFetchSize(sal_Int32 _par0) ::cppu::IPropertyArrayHelper* ODatabaseMetaDataResultSet::createArrayHelper( ) const { - Sequence< css::beans::Property > aProps(5); - css::beans::Property* pProperties = aProps.getArray(); - sal_Int32 nPos = 0; - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), - PROPERTY_ID_CURSORNAME, cppu::UnoType<OUString>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), - PROPERTY_ID_FETCHDIRECTION, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), - PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), - PROPERTY_ID_RESULTSETCONCURRENCY, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), - PROPERTY_ID_RESULTSETTYPE, cppu::UnoType<sal_Int32>::get(), 0); - - return new ::cppu::OPropertyArrayHelper(aProps); + return new ::cppu::OPropertyArrayHelper + { + { + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), + PROPERTY_ID_CURSORNAME, + cppu::UnoType<OUString>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), + PROPERTY_ID_FETCHDIRECTION, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), + PROPERTY_ID_FETCHSIZE, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), + PROPERTY_ID_RESULTSETCONCURRENCY, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), + PROPERTY_ID_RESULTSETTYPE, + cppu::UnoType<sal_Int32>::get(), + 0 + } + } + }; } ::cppu::IPropertyArrayHelper & ODatabaseMetaDataResultSet::getInfoHelper() @@ -780,7 +799,6 @@ void ODatabaseMetaDataResultSet::getFastPropertyValue( void ODatabaseMetaDataResultSet::setProceduresMap() { - for(sal_Int32 i=1;i<4;i++) m_aColMapping.push_back(i); m_aColMapping.push_back(5); @@ -789,13 +807,15 @@ void ODatabaseMetaDataResultSet::setProceduresMap() m_aColMapping.push_back(6); m_aColMapping.push_back(4); - ::std::map<sal_Int32,sal_Int32> aMap; - aMap[DB_PT_UNKNOWN] = ProcedureResult::UNKNOWN; - aMap[DB_PT_PROCEDURE] = ProcedureResult::NONE; - aMap[DB_PT_FUNCTION] = ProcedureResult::RETURN; + ::std::map<sal_Int32,sal_Int32> aMap + { + {DB_PT_UNKNOWN, ProcedureResult::UNKNOWN}, + {DB_PT_PROCEDURE, ProcedureResult::NONE}, + {DB_PT_FUNCTION, ProcedureResult::RETURN} + }; m_aValueRange[4] = aMap; - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); pMetaData->setProceduresMap(); m_xMetaData = pMetaData; } @@ -825,7 +845,7 @@ void ODatabaseMetaDataResultSet::setColumnPrivilegesMap() m_aColMapping.push_back(9); m_aColMapping.push_back(10); - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); pMetaData->setColumnPrivilegesMap(); m_xMetaData = pMetaData; } @@ -854,55 +874,56 @@ void ODatabaseMetaDataResultSet::setColumnsMap() m_aColMapping.push_back(7); m_aColMapping.push_back(11); - ::std::map<sal_Int32,sal_Int32> aMap; - aMap[adEmpty] = ADOS::MapADOType2Jdbc(adEmpty); - aMap[adTinyInt] = ADOS::MapADOType2Jdbc(adTinyInt); - aMap[adSmallInt] = ADOS::MapADOType2Jdbc(adSmallInt); - aMap[adInteger] = ADOS::MapADOType2Jdbc(adInteger); - aMap[adBigInt] = ADOS::MapADOType2Jdbc(adBigInt); - aMap[adUnsignedTinyInt] = ADOS::MapADOType2Jdbc(adUnsignedTinyInt); - aMap[adUnsignedSmallInt]= ADOS::MapADOType2Jdbc(adUnsignedSmallInt); - aMap[adUnsignedInt] = ADOS::MapADOType2Jdbc(adUnsignedInt); - aMap[adUnsignedBigInt] = ADOS::MapADOType2Jdbc(adUnsignedBigInt); - aMap[adSingle] = ADOS::MapADOType2Jdbc(adSingle); - aMap[adDouble] = ADOS::MapADOType2Jdbc(adDouble); - aMap[adCurrency] = ADOS::MapADOType2Jdbc(adCurrency); - aMap[adDecimal] = ADOS::MapADOType2Jdbc(adDecimal); - aMap[adNumeric] = ADOS::MapADOType2Jdbc(adNumeric); - aMap[adBoolean] = ADOS::MapADOType2Jdbc(adBoolean); - aMap[adError] = ADOS::MapADOType2Jdbc(adError); - aMap[adUserDefined] = ADOS::MapADOType2Jdbc(adUserDefined); - aMap[adVariant] = ADOS::MapADOType2Jdbc(adVariant); - aMap[adIDispatch] = ADOS::MapADOType2Jdbc(adIDispatch); - aMap[adIUnknown] = ADOS::MapADOType2Jdbc(adIUnknown); - aMap[adGUID] = ADOS::MapADOType2Jdbc(adGUID); - aMap[adDate] = ADOS::MapADOType2Jdbc(adDate); - aMap[adDBDate] = ADOS::MapADOType2Jdbc(adDBDate); - aMap[adDBTime] = ADOS::MapADOType2Jdbc(adDBTime); - aMap[adDBTimeStamp] = ADOS::MapADOType2Jdbc(adDBTimeStamp); - aMap[adBSTR] = ADOS::MapADOType2Jdbc(adBSTR); - aMap[adChar] = ADOS::MapADOType2Jdbc(adChar); - aMap[adVarChar] = ADOS::MapADOType2Jdbc(adVarChar); - aMap[adLongVarChar] = ADOS::MapADOType2Jdbc(adLongVarChar); - aMap[adWChar] = ADOS::MapADOType2Jdbc(adWChar); - aMap[adVarWChar] = ADOS::MapADOType2Jdbc(adVarWChar); - aMap[adLongVarWChar] = ADOS::MapADOType2Jdbc(adLongVarWChar); - aMap[adBinary] = ADOS::MapADOType2Jdbc(adBinary); - aMap[adVarBinary] = ADOS::MapADOType2Jdbc(adVarBinary); - aMap[adLongVarBinary] = ADOS::MapADOType2Jdbc(adLongVarBinary); - aMap[adChapter] = ADOS::MapADOType2Jdbc(adChapter); - aMap[adFileTime] = ADOS::MapADOType2Jdbc(adFileTime); - aMap[adPropVariant] = ADOS::MapADOType2Jdbc(adPropVariant); - aMap[adVarNumeric] = ADOS::MapADOType2Jdbc(adVarNumeric); - + ::std::map<sal_Int32,sal_Int32> aMap { + {adEmpty, ADOS::MapADOType2Jdbc(adEmpty)}, + {adTinyInt, ADOS::MapADOType2Jdbc(adTinyInt)}, + {adSmallInt, ADOS::MapADOType2Jdbc(adSmallInt)}, + {adInteger, ADOS::MapADOType2Jdbc(adInteger)}, + {adBigInt, ADOS::MapADOType2Jdbc(adBigInt)}, + {adUnsignedTinyInt, ADOS::MapADOType2Jdbc(adUnsignedTinyInt)}, + {adUnsignedSmallInt, ADOS::MapADOType2Jdbc(adUnsignedSmallInt)}, + {adUnsignedInt, ADOS::MapADOType2Jdbc(adUnsignedInt)}, + {adUnsignedBigInt, ADOS::MapADOType2Jdbc(adUnsignedBigInt)}, + {adSingle, ADOS::MapADOType2Jdbc(adSingle)}, + {adDouble, ADOS::MapADOType2Jdbc(adDouble)}, + {adCurrency, ADOS::MapADOType2Jdbc(adCurrency)}, + {adDecimal, ADOS::MapADOType2Jdbc(adDecimal)}, + {adNumeric, ADOS::MapADOType2Jdbc(adNumeric)}, + {adBoolean, ADOS::MapADOType2Jdbc(adBoolean)}, + {adError, ADOS::MapADOType2Jdbc(adError)}, + {adUserDefined, ADOS::MapADOType2Jdbc(adUserDefined)}, + {adVariant, ADOS::MapADOType2Jdbc(adVariant)}, + {adIDispatch, ADOS::MapADOType2Jdbc(adIDispatch)}, + {adIUnknown, ADOS::MapADOType2Jdbc(adIUnknown)}, + {adGUID, ADOS::MapADOType2Jdbc(adGUID)}, + {adDate, ADOS::MapADOType2Jdbc(adDate)}, + {adDBDate, ADOS::MapADOType2Jdbc(adDBDate)}, + {adDBTime, ADOS::MapADOType2Jdbc(adDBTime)}, + {adDBTimeStamp, ADOS::MapADOType2Jdbc(adDBTimeStamp)}, + {adBSTR, ADOS::MapADOType2Jdbc(adBSTR)}, + {adChar, ADOS::MapADOType2Jdbc(adChar)}, + {adVarChar, ADOS::MapADOType2Jdbc(adVarChar)}, + {adLongVarChar, ADOS::MapADOType2Jdbc(adLongVarChar)}, + {adWChar, ADOS::MapADOType2Jdbc(adWChar)}, + {adVarWChar, ADOS::MapADOType2Jdbc(adVarWChar)}, + {adLongVarWChar, ADOS::MapADOType2Jdbc(adLongVarWChar)}, + {adBinary, ADOS::MapADOType2Jdbc(adBinary)}, + {adVarBinary, ADOS::MapADOType2Jdbc(adVarBinary)}, + {adLongVarBinary, ADOS::MapADOType2Jdbc(adLongVarBinary)}, + {adChapter, ADOS::MapADOType2Jdbc(adChapter)}, + {adFileTime, ADOS::MapADOType2Jdbc(adFileTime)}, + {adPropVariant, ADOS::MapADOType2Jdbc(adPropVariant)}, + {adVarNumeric, ADOS::MapADOType2Jdbc(adVarNumeric)} + }; m_aValueRange[12] = aMap; - std::map< sal_Int32,OUString> aMap2; - aMap2[0] = "YES"; - aMap2[1] = "NO"; + std::map< sal_Int32,OUString> aMap2 { + {0, "YES"}, + {1, "NO"} + }; m_aIntValueRange[18] = aMap2; - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); pMetaData->setColumnsMap(); m_xMetaData = pMetaData; } @@ -914,7 +935,7 @@ void ODatabaseMetaDataResultSet::setTablesMap() m_aColMapping.push_back(i); m_aColMapping.push_back(6); - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); pMetaData->setTablesMap(); m_xMetaData = pMetaData; } @@ -934,54 +955,56 @@ void ODatabaseMetaDataResultSet::setProcedureColumnsMap() m_aColMapping.push_back(9); m_aColMapping.push_back(14); - ::std::map<sal_Int32,sal_Int32> aMap; - aMap[DBTYPE_EMPTY] = DataType::SQLNULL; - aMap[DBTYPE_NULL] = DataType::SQLNULL; - aMap[DBTYPE_I2] = DataType::SMALLINT; - aMap[DBTYPE_I4] = DataType::INTEGER; - aMap[DBTYPE_R4] = DataType::FLOAT; - aMap[DBTYPE_R8] = DataType::DOUBLE; - aMap[DBTYPE_CY] = DataType::BIGINT; - aMap[DBTYPE_DATE] = DataType::DATE; - aMap[DBTYPE_BSTR] = DataType::VARCHAR; - aMap[DBTYPE_IDISPATCH] = DataType::OBJECT; - aMap[DBTYPE_ERROR] = DataType::OTHER; - aMap[DBTYPE_BOOL] = DataType::BIT; - aMap[DBTYPE_VARIANT] = DataType::STRUCT; - aMap[DBTYPE_IUNKNOWN] = DataType::OTHER; - aMap[DBTYPE_DECIMAL] = DataType::DECIMAL; - aMap[DBTYPE_UI1] = DataType::TINYINT; - aMap[DBTYPE_ARRAY] = DataType::ARRAY; - aMap[DBTYPE_BYREF] = DataType::REF; - aMap[DBTYPE_I1] = DataType::CHAR; - aMap[DBTYPE_UI2] = DataType::SMALLINT; - aMap[DBTYPE_UI4] = DataType::INTEGER; - - // aMap[The] = ; - // aMap[in] = ; - aMap[DBTYPE_I8] = DataType::BIGINT; - aMap[DBTYPE_UI8] = DataType::BIGINT; - aMap[DBTYPE_GUID] = DataType::OTHER; - aMap[DBTYPE_VECTOR] = DataType::OTHER; - aMap[DBTYPE_FILETIME] = DataType::OTHER; - aMap[DBTYPE_RESERVED] = DataType::OTHER; - - // aMap[The] = ; - aMap[DBTYPE_BYTES] = DataType::VARBINARY; - aMap[DBTYPE_STR] = DataType::LONGVARCHAR; - aMap[DBTYPE_WSTR] = DataType::LONGVARCHAR; - aMap[DBTYPE_NUMERIC] = DataType::NUMERIC; - aMap[DBTYPE_UDT] = DataType::OTHER; - aMap[DBTYPE_DBDATE] = DataType::DATE; - aMap[DBTYPE_DBTIME] = DataType::TIME; - aMap[DBTYPE_DBTIMESTAMP] = DataType::TIMESTAMP; - aMap[DBTYPE_HCHAPTER] = DataType::OTHER; - aMap[DBTYPE_PROPVARIANT] = DataType::OTHER; - aMap[DBTYPE_VARNUMERIC] = DataType::NUMERIC; + ::std::map<sal_Int32,sal_Int32> aMap + { + {DBTYPE_EMPTY, DataType::SQLNULL}, + {DBTYPE_NULL, DataType::SQLNULL}, + {DBTYPE_I2, DataType::SMALLINT}, + {DBTYPE_I4, DataType::INTEGER}, + {DBTYPE_R4, DataType::FLOAT}, + {DBTYPE_R8, DataType::DOUBLE}, + {DBTYPE_CY, DataType::BIGINT}, + {DBTYPE_DATE, DataType::DATE}, + {DBTYPE_BSTR, DataType::VARCHAR}, + {DBTYPE_IDISPATCH, DataType::OBJECT}, + {DBTYPE_ERROR, DataType::OTHER}, + {DBTYPE_BOOL, DataType::BIT}, + {DBTYPE_VARIANT, DataType::STRUCT}, + {DBTYPE_IUNKNOWN, DataType::OTHER}, + {DBTYPE_DECIMAL, DataType::DECIMAL}, + {DBTYPE_UI1, DataType::TINYINT}, + {DBTYPE_ARRAY, DataType::ARRAY}, + {DBTYPE_BYREF, DataType::REF}, + {DBTYPE_I1, DataType::CHAR}, + {DBTYPE_UI2, DataType::SMALLINT}, + {DBTYPE_UI4, DataType::INTEGER}, + + // aMap[The] = ; + // aMap[in] = ; + {DBTYPE_I8, DataType::BIGINT}, + {DBTYPE_UI8, DataType::BIGINT}, + {DBTYPE_GUID, DataType::OTHER}, + {DBTYPE_VECTOR, DataType::OTHER}, + {DBTYPE_FILETIME, DataType::OTHER}, + {DBTYPE_RESERVED, DataType::OTHER}, + + // aMap[The] = ; + {DBTYPE_BYTES, DataType::VARBINARY}, + {DBTYPE_STR, DataType::LONGVARCHAR}, + {DBTYPE_WSTR, DataType::LONGVARCHAR}, + {DBTYPE_NUMERIC, DataType::NUMERIC}, + {DBTYPE_UDT, DataType::OTHER}, + {DBTYPE_DBDATE, DataType::DATE}, + {DBTYPE_DBTIME, DataType::TIME}, + {DBTYPE_DBTIMESTAMP, DataType::TIMESTAMP}, + {DBTYPE_HCHAPTER, DataType::OTHER}, + {DBTYPE_PROPVARIANT, DataType::OTHER}, + {DBTYPE_VARNUMERIC, DataType::NUMERIC} + }; m_aValueRange[10] = aMap; - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); pMetaData->setProcedureColumnsMap(); m_xMetaData = pMetaData; } @@ -995,7 +1018,7 @@ void ODatabaseMetaDataResultSet::setPrimaryKeysMap() m_aColMapping.push_back(7); m_aColMapping.push_back(8); - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); pMetaData->setProcedureColumnsMap(); m_xMetaData = pMetaData; } @@ -1017,27 +1040,33 @@ void ODatabaseMetaDataResultSet::setIndexInfoMap() m_aColMapping.push_back(23); m_aColMapping.push_back(24); - ::std::map<sal_Int32,sal_Int32> aMap; - aMap[DBPROPVAL_IT_HASH] = IndexType::HASHED; - aMap[DBPROPVAL_IT_CONTENT] = IndexType::OTHER; - aMap[DBPROPVAL_IT_OTHER] = IndexType::OTHER; - aMap[DBPROPVAL_IT_BTREE] = IndexType::OTHER; + ::std::map<sal_Int32,sal_Int32> aMap + { + { DBPROPVAL_IT_HASH, IndexType::HASHED }, + { DBPROPVAL_IT_CONTENT, IndexType::OTHER }, + { DBPROPVAL_IT_OTHER, IndexType::OTHER }, + { DBPROPVAL_IT_BTREE, IndexType::OTHER } + }; m_aValueRange[10] = aMap; - ::std::map<sal_Int32,sal_Int32> aMap2; - aMap[0] = 1; - aMap[1] = 0; + ::std::map<sal_Int32,sal_Int32> aMap2 + { + { 0, 1 }, + { 1, 0 } + }; m_aValueRange[8] = aMap2; - std::map< sal_Int32,OUString> aMap3; - aMap3[0] = ""; - aMap3[DB_COLLATION_ASC] = "A"; - aMap3[DB_COLLATION_DESC] = "D"; + std::map< sal_Int32,OUString> aMap3 + { + { 0, "" }, + { DB_COLLATION_ASC, "A" }, + { DB_COLLATION_DESC, "D" } + }; m_aIntValueRange[21] = aMap3; - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); pMetaData->setIndexInfoMap(); m_xMetaData = pMetaData; } @@ -1053,13 +1082,15 @@ void ODatabaseMetaDataResultSet::setTablePrivilegesMap() m_aColMapping.push_back(6); m_aColMapping.push_back(7); - std::map< sal_Int32,OUString> aMap; - aMap[0] = "YES"; - aMap[1] = "NO"; + std::map< sal_Int32,OUString> aMap + { + { 0, "YES" }, + { 1, "NO" } + }; m_aIntValueRange[7] = aMap; - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); pMetaData->setTablePrivilegesMap(); m_xMetaData = pMetaData; } @@ -1080,17 +1111,19 @@ void ODatabaseMetaDataResultSet::setCrossReferenceMap() m_aColMapping.push_back(16); m_aColMapping.push_back(18); - std::map< OUString,sal_Int32> aMap; - aMap[ OUString("CASCADE")] = KeyRule::CASCADE; - aMap[ OUString("RESTRICT")] = KeyRule::RESTRICT; - aMap[ OUString("SET NULL")] = KeyRule::SET_NULL; - aMap[ OUString("SET DEFAULT")] = KeyRule::SET_DEFAULT; - aMap[ OUString("NO ACTION")] = KeyRule::NO_ACTION; + std::map< OUString,sal_Int32> aMap + { + { "CASCADE", KeyRule::CASCADE }, + { "RESTRICT", KeyRule::RESTRICT }, + { "SET NULL", KeyRule::SET_NULL }, + { "SET DEFAULT", KeyRule::SET_DEFAULT }, + { "NO ACTION", KeyRule::NO_ACTION } + }; m_aStrValueRange[14] = aMap; m_aStrValueRange[15] = aMap; - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); pMetaData->setCrossReferenceMap(); m_xMetaData = pMetaData; } @@ -1101,84 +1134,89 @@ void ODatabaseMetaDataResultSet::setTypeInfoMap(bool _bJetEngine) for(;i<19;i++) m_aColMapping.push_back(i); - std::map< OUString,sal_Int32> aMap1; - aMap1[ OUString()] = 10; + std::map< OUString,sal_Int32> aMap1 { { OUString(), 10 } }; m_aStrValueRange[18] = aMap1; - ::std::map<sal_Int32,sal_Int32> aMap; - aMap[adEmpty] = ADOS::MapADOType2Jdbc(adEmpty); - aMap[adTinyInt] = ADOS::MapADOType2Jdbc(adTinyInt); - aMap[adSmallInt] = ADOS::MapADOType2Jdbc(adSmallInt); - aMap[adInteger] = ADOS::MapADOType2Jdbc(adInteger); - aMap[adBigInt] = ADOS::MapADOType2Jdbc(adBigInt); - aMap[adUnsignedTinyInt] = ADOS::MapADOType2Jdbc(adUnsignedTinyInt); - aMap[adUnsignedSmallInt]= ADOS::MapADOType2Jdbc(adUnsignedSmallInt); - aMap[adUnsignedInt] = ADOS::MapADOType2Jdbc(adUnsignedInt); - aMap[adUnsignedBigInt] = ADOS::MapADOType2Jdbc(adUnsignedBigInt); - aMap[adSingle] = ADOS::MapADOType2Jdbc(adSingle); - aMap[adDouble] = ADOS::MapADOType2Jdbc(adDouble); - aMap[adCurrency] = ADOS::MapADOType2Jdbc(adCurrency); - aMap[adDecimal] = ADOS::MapADOType2Jdbc(adDecimal); - aMap[adNumeric] = ADOS::MapADOType2Jdbc(adNumeric); - aMap[adBoolean] = ADOS::MapADOType2Jdbc(adBoolean); - aMap[adError] = ADOS::MapADOType2Jdbc(adError); - aMap[adUserDefined] = ADOS::MapADOType2Jdbc(adUserDefined); - aMap[adVariant] = ADOS::MapADOType2Jdbc(adVariant); - aMap[adIDispatch] = ADOS::MapADOType2Jdbc(adIDispatch); - aMap[adIUnknown] = ADOS::MapADOType2Jdbc(adIUnknown); - aMap[adGUID] = ADOS::MapADOType2Jdbc(adGUID); - aMap[adDate] = _bJetEngine ? ADOS::MapADOType2Jdbc(adDBTimeStamp) : ADOS::MapADOType2Jdbc(adDate); - aMap[adDBDate] = ADOS::MapADOType2Jdbc(adDBDate); - aMap[adDBTime] = ADOS::MapADOType2Jdbc(adDBTime); - aMap[adDBTimeStamp] = ADOS::MapADOType2Jdbc(adDBTimeStamp); - aMap[adBSTR] = ADOS::MapADOType2Jdbc(adBSTR); - aMap[adChar] = ADOS::MapADOType2Jdbc(adChar); - aMap[adVarChar] = ADOS::MapADOType2Jdbc(adVarChar); - aMap[adLongVarChar] = ADOS::MapADOType2Jdbc(adLongVarChar); - aMap[adWChar] = ADOS::MapADOType2Jdbc(adWChar); - aMap[adVarWChar] = ADOS::MapADOType2Jdbc(adVarWChar); - aMap[adLongVarWChar] = ADOS::MapADOType2Jdbc(adLongVarWChar); - aMap[adBinary] = ADOS::MapADOType2Jdbc(adBinary); - aMap[adVarBinary] = ADOS::MapADOType2Jdbc(adVarBinary); - aMap[adLongVarBinary] = ADOS::MapADOType2Jdbc(adLongVarBinary); - aMap[adChapter] = ADOS::MapADOType2Jdbc(adChapter); - aMap[adFileTime] = ADOS::MapADOType2Jdbc(adFileTime); - aMap[adPropVariant] = ADOS::MapADOType2Jdbc(adPropVariant); - aMap[adVarNumeric] = ADOS::MapADOType2Jdbc(adVarNumeric); -// aMap[adArray] = ADOS::MapADOType2Jdbc(adArray); + ::std::map<sal_Int32,sal_Int32> aMap + { + {adEmpty, ADOS::MapADOType2Jdbc(adEmpty)}, + {adTinyInt, ADOS::MapADOType2Jdbc(adTinyInt)}, + {adSmallInt, ADOS::MapADOType2Jdbc(adSmallInt)}, + {adInteger, ADOS::MapADOType2Jdbc(adInteger)}, + {adBigInt, ADOS::MapADOType2Jdbc(adBigInt)}, + {adUnsignedTinyInt, ADOS::MapADOType2Jdbc(adUnsignedTinyInt)}, + {adUnsignedSmallInt, ADOS::MapADOType2Jdbc(adUnsignedSmallInt)}, + {adUnsignedInt, ADOS::MapADOType2Jdbc(adUnsignedInt)}, + {adUnsignedBigInt, ADOS::MapADOType2Jdbc(adUnsignedBigInt)}, + {adSingle, ADOS::MapADOType2Jdbc(adSingle)}, + {adDouble, ADOS::MapADOType2Jdbc(adDouble)}, + {adCurrency, ADOS::MapADOType2Jdbc(adCurrency)}, + {adDecimal, ADOS::MapADOType2Jdbc(adDecimal)}, + {adNumeric, ADOS::MapADOType2Jdbc(adNumeric)}, + {adBoolean, ADOS::MapADOType2Jdbc(adBoolean)}, + {adError, ADOS::MapADOType2Jdbc(adError)}, + {adUserDefined, ADOS::MapADOType2Jdbc(adUserDefined)}, + {adVariant, ADOS::MapADOType2Jdbc(adVariant)}, + {adIDispatch, ADOS::MapADOType2Jdbc(adIDispatch)}, + {adIUnknown, ADOS::MapADOType2Jdbc(adIUnknown)}, + {adGUID, ADOS::MapADOType2Jdbc(adGUID)}, + {adDate, ADOS::MapADOType2Jdbc(_bJetEngine?adDBTimeStamp:adDate)}, + {adDBDate, ADOS::MapADOType2Jdbc(adDBDate)}, + {adDBTime, ADOS::MapADOType2Jdbc(adDBTime)}, + {adDBTimeStamp, ADOS::MapADOType2Jdbc(adDBTimeStamp)}, + {adBSTR, ADOS::MapADOType2Jdbc(adBSTR)}, + {adChar, ADOS::MapADOType2Jdbc(adChar)}, + {adVarChar, ADOS::MapADOType2Jdbc(adVarChar)}, + {adLongVarChar, ADOS::MapADOType2Jdbc(adLongVarChar)}, + {adWChar, ADOS::MapADOType2Jdbc(adWChar)}, + {adVarWChar, ADOS::MapADOType2Jdbc(adVarWChar)}, + {adLongVarWChar, ADOS::MapADOType2Jdbc(adLongVarWChar)}, + {adBinary, ADOS::MapADOType2Jdbc(adBinary)}, + {adVarBinary, ADOS::MapADOType2Jdbc(adVarBinary)}, + {adLongVarBinary, ADOS::MapADOType2Jdbc(adLongVarBinary)}, + {adChapter, ADOS::MapADOType2Jdbc(adChapter)}, + {adFileTime, ADOS::MapADOType2Jdbc(adFileTime)}, + {adPropVariant, ADOS::MapADOType2Jdbc(adPropVariant)}, + {adVarNumeric, ADOS::MapADOType2Jdbc(adVarNumeric)} +// {adArray, ADOS::MapADOType2Jdbc(adArray)} + }; m_aValueRange[2] = aMap; - ::std::map<sal_Int32,sal_Int32> aColumnValueMapping; - aColumnValueMapping[VARIANT_FALSE] = ColumnValue::NO_NULLS; - aColumnValueMapping[VARIANT_TRUE] = ColumnValue::NULLABLE; + ::std::map<sal_Int32,sal_Int32> aColumnValueMapping + { + { VARIANT_FALSE, ColumnValue::NO_NULLS }, + { VARIANT_TRUE, ColumnValue::NULLABLE } + }; m_aValueRange[7] = aColumnValueMapping; // now adjust the column mapping // OJ 24.01.2002 96860 - ::std::map<sal_Int32,sal_Int32> aSearchMapping; - aSearchMapping[DB_UNSEARCHABLE] = ColumnSearch::NONE; - aSearchMapping[DB_LIKE_ONLY] = ColumnSearch::CHAR; - aSearchMapping[DB_ALL_EXCEPT_LIKE] = ColumnSearch::BASIC; - aSearchMapping[DB_SEARCHABLE] = ColumnSearch::FULL; + ::std::map<sal_Int32,sal_Int32> aSearchMapping + { + { DB_UNSEARCHABLE, ColumnSearch::NONE }, + { DB_LIKE_ONLY, ColumnSearch::CHAR }, + { DB_ALL_EXCEPT_LIKE, ColumnSearch::BASIC }, + { DB_SEARCHABLE, ColumnSearch::FULL } + }; m_aValueRange[9] = aSearchMapping; ::std::map<sal_Int32,sal_Int32> aCurrencyMapping; m_aValueRange[11] = aCurrencyMapping; - ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); + rtl::Reference<ODatabaseMetaDataResultSetMetaData> pMetaData = new ODatabaseMetaDataResultSetMetaData(m_pRecordSet,this); pMetaData->setTypeInfoMap(); m_xMetaData = pMetaData; } -void SAL_CALL ODatabaseMetaDataResultSet::acquire() throw() +void SAL_CALL ODatabaseMetaDataResultSet::acquire() noexcept { ODatabaseMetaDataResultSet_BASE::acquire(); } -void SAL_CALL ODatabaseMetaDataResultSet::release() throw() +void SAL_CALL ODatabaseMetaDataResultSet::release() noexcept { ODatabaseMetaDataResultSet_BASE::release(); } diff --git a/connectivity/source/drivers/ado/ADatabaseMetaDataResultSetMetaData.cxx b/connectivity/source/drivers/ado/ADatabaseMetaDataResultSetMetaData.cxx index 9a4365abfcce..3fa13d06b84a 100644 --- a/connectivity/source/drivers/ado/ADatabaseMetaDataResultSetMetaData.cxx +++ b/connectivity/source/drivers/ado/ADatabaseMetaDataResultSetMetaData.cxx @@ -21,7 +21,6 @@ #include <ado/Awrapado.hxx> #include <connectivity/dbexception.hxx> - using namespace connectivity; using namespace connectivity::ado; using namespace com::sun::star::uno; @@ -29,194 +28,183 @@ using namespace com::sun::star::lang; using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; - ODatabaseMetaDataResultSetMetaData::~ODatabaseMetaDataResultSetMetaData() { - if(m_pRecordSet) + if (m_pRecordSet) m_pRecordSet->Release(); } -sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) +sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnDisplaySize(sal_Int32 column) { sal_Int32 nSize = 0; - if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) nSize = (*m_mColumnsIter).second.getColumnDisplaySize(); - else if(m_pRecordSet) + else if (m_pRecordSet) { - WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]); - if(aField.IsValid()) + WpADOField aField = ADOS::getField(m_pRecordSet, m_vMapping[column]); + if (aField.IsValid()) nSize = aField.GetActualSize(); } return nSize; } - -sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnType( sal_Int32 column ) +sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnType(sal_Int32 column) { - sal_Int32 nType = 0; - if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + sal_Int32 nType = 0; + if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) nType = (*m_mColumnsIter).second.getColumnType(); - else if(m_pRecordSet) + else if (m_pRecordSet) { - WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]); + WpADOField aField = ADOS::getField(m_pRecordSet, m_vMapping[column]); nType = ADOS::MapADOType2Jdbc(aField.GetADOType()); } return nType; } - -sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnCount( ) +sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnCount() { - if(!m_pRecordSet) + if (!m_pRecordSet) return 0; - if(m_nColCount != -1) + if (m_nColCount != -1) return m_nColCount; - if(m_vMapping.size()) + if (m_vMapping.size()) return m_mColumns.size(); - ADOFields* pFields = nullptr; - m_pRecordSet->get_Fields(&pFields); - WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(pFields); + WpOLEAppendCollection<ADOFields, WpADOField> aFields; + m_pRecordSet->get_Fields(&aFields); m_nColCount = aFields.GetItemCount(); return m_nColCount; } - -OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnName( sal_Int32 column ) +OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnName(sal_Int32 column) { - if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) return (*m_mColumnsIter).second.getColumnName(); - if(!m_pRecordSet) + if (!m_pRecordSet) return OUString(); - WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]); - if(aField.IsValid()) + WpADOField aField = ADOS::getField(m_pRecordSet, m_vMapping[column]); + if (aField.IsValid()) return aField.GetName(); return OUString(); } -OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnLabel( sal_Int32 column ) +OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnLabel(sal_Int32 column) { - if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) return (*m_mColumnsIter).second.getColumnLabel(); return getColumnName(column); } - -sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isCurrency( sal_Int32 column ) +sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isCurrency(sal_Int32 column) { - if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) return (*m_mColumnsIter).second.isCurrency(); - if(!m_pRecordSet) + if (!m_pRecordSet) return false; - WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]); - if(aField.IsValid()) + WpADOField aField = ADOS::getField(m_pRecordSet, m_vMapping[column]); + if (aField.IsValid()) { return (aField.GetAttributes() & adFldFixed) == adFldFixed; } return false; } - -sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isSigned( sal_Int32 column ) +sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isSigned(sal_Int32 column) { - if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) return (*m_mColumnsIter).second.isSigned(); - if(!m_pRecordSet) + if (!m_pRecordSet) return false; - WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]); - if(aField.IsValid()) + WpADOField aField = ADOS::getField(m_pRecordSet, m_vMapping[column]); + if (aField.IsValid()) { return (aField.GetAttributes() & adFldNegativeScale) == adFldNegativeScale; } return false; } -sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getPrecision( sal_Int32 column ) +sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getPrecision(sal_Int32 column) { - if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) return (*m_mColumnsIter).second.getPrecision(); - if(!m_pRecordSet) + if (!m_pRecordSet) return 0; - WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]); - if(aField.IsValid()) + WpADOField aField = ADOS::getField(m_pRecordSet, m_vMapping[column]); + if (aField.IsValid()) return aField.GetPrecision(); return 0; } -sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getScale( sal_Int32 column ) +sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getScale(sal_Int32 column) { - if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) return (*m_mColumnsIter).second.getScale(); - if(!m_pRecordSet) + if (!m_pRecordSet) return 0; - WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]); - if(aField.IsValid()) + WpADOField aField = ADOS::getField(m_pRecordSet, m_vMapping[column]); + if (aField.IsValid()) return aField.GetNumericScale(); return 0; } - -sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::isNullable( sal_Int32 column ) +sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::isNullable(sal_Int32 column) { - if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) return (*m_mColumnsIter).second.isNullable(); - if(!m_pRecordSet) + if (!m_pRecordSet) return sal_Int32(false); - WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]); - if(aField.IsValid()) + WpADOField aField = ADOS::getField(m_pRecordSet, m_vMapping[column]); + if (aField.IsValid()) { return sal_Int32((aField.GetAttributes() & adFldIsNullable) == adFldIsNullable); } return sal_Int32(false); } - -sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isReadOnly( sal_Int32 column ) +sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isReadOnly(sal_Int32 column) { - if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) return (*m_mColumnsIter).second.isReadOnly(); - if(!m_pRecordSet) + if (!m_pRecordSet) return false; - WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]); - if(aField.IsValid()) + WpADOField aField = ADOS::getField(m_pRecordSet, m_vMapping[column]); + if (aField.IsValid()) { // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly; } return false; } - -sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) +sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isDefinitelyWritable(sal_Int32 column) { - if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) return (*m_mColumnsIter).second.isDefinitelyWritable(); - if(!m_pRecordSet) + if (!m_pRecordSet) return false; - WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]); - if(aField.IsValid()) + WpADOField aField = ADOS::getField(m_pRecordSet, m_vMapping[column]); + if (aField.IsValid()) { return (aField.GetAttributes() & adFldUpdatable) == adFldUpdatable; } return false; -; + ; } -sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isWritable( sal_Int32 column ) +sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isWritable(sal_Int32 column) { - if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) + if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end()) return (*m_mColumnsIter).second.isWritable(); return isDefinitelyWritable(column); } - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/ado/ADriver.cxx b/connectivity/source/drivers/ado/ADriver.cxx index 3fc5ce763103..6568f7a1ee84 100644 --- a/connectivity/source/drivers/ado/ADriver.cxx +++ b/connectivity/source/drivers/ado/ADriver.cxx @@ -24,16 +24,16 @@ #include <ado/Awrapado.hxx> #include <ado/adoimp.hxx> #include <com/sun/star/lang/DisposedException.hpp> +#include <comphelper/servicehelper.hxx> #include <connectivity/dbexception.hxx> #include <cppuhelper/supportsservice.hxx> #include <o3tl/safeCoInitUninit.hxx> +#include <rtl/ref.hxx> #include <strings.hrc> #include <objbase.h> #include <resource/sharedresources.hxx> -#include <memory> - using namespace connectivity; using namespace connectivity::ado; using namespace com::sun::star::uno; @@ -43,9 +43,9 @@ using namespace com::sun::star::sdbc; using namespace com::sun::star::sdbcx; -ODriver::ODriver(const css::uno::Reference< css::lang::XMultiServiceFactory >& _xORB) +ODriver::ODriver(const css::uno::Reference< css::uno::XComponentContext >& _xORB) : ODriver_BASE(m_aMutex) - ,m_xORB(_xORB) + ,m_xContext(_xORB) ,mnNbCallCoInitializeExForReinit(0) { o3tl::safeCoInitializeEx(COINIT_APARTMENTTHREADED, mnNbCallCoInitializeExForReinit); @@ -73,52 +73,33 @@ void ODriver::disposing() } // static ServiceInfo -OUString ODriver::getImplementationName_Static( ) +OUString ODriver::getImplementationName( ) { return "com.sun.star.comp.sdbc.ado.ODriver"; } -Sequence< OUString > ODriver::getSupportedServiceNames_Static( ) +Sequence< OUString > ODriver::getSupportedServiceNames( ) { return { "com.sun.star.sdbc.Driver", "com.sun.star.sdbcx.Driver" }; } -css::uno::Reference< css::uno::XInterface > connectivity::ado::ODriver_CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory) -{ - return *(new ODriver(_rxFactory)); -} - - -OUString SAL_CALL ODriver::getImplementationName( ) -{ - return getImplementationName_Static(); -} - sal_Bool SAL_CALL ODriver::supportsService( const OUString& _rServiceName ) { return cppu::supportsService(this, _rServiceName); } - -Sequence< OUString > SAL_CALL ODriver::getSupportedServiceNames( ) -{ - return getSupportedServiceNames_Static(); -} - - Reference< XConnection > SAL_CALL ODriver::connect( const OUString& url, const Sequence< PropertyValue >& info ) { if ( ! acceptsURL(url) ) return nullptr; // we need to wrap the connection as the construct call might throw - std::unique_ptr<OConnection> pCon(new OConnection(this)); + rtl::Reference<OConnection> pCon(new OConnection(this)); pCon->construct(url,info); OConnection* pPtr = pCon.get(); - Reference< XConnection > xCon = pCon.release(); m_xConnections.push_back(WeakReferenceHelper(*pPtr)); - return xCon; + return pCon; } sal_Bool SAL_CALL ODriver::acceptsURL( const OUString& url ) @@ -141,34 +122,32 @@ Sequence< DriverPropertyInfo > SAL_CALL ODriver::getPropertyInfo( const OUString impl_checkURL_throw(url); if ( acceptsURL(url) ) { - std::vector< DriverPropertyInfo > aDriverInfo; - - Sequence< OUString > aBooleanValues(2); - aBooleanValues[0] = "false"; - aBooleanValues[1] = "true"; + Sequence< OUString > aBooleanValues{ "false", "true" }; - aDriverInfo.push_back(DriverPropertyInfo( - "IgnoreDriverPrivileges" - ,"Ignore the privileges from the database driver." - ,false - ,"false" - ,aBooleanValues) - ); - aDriverInfo.push_back(DriverPropertyInfo( - "EscapeDateTime" - ,"Escape date time format." - ,false - ,"true" - ,aBooleanValues) - ); - aDriverInfo.push_back(DriverPropertyInfo( - "TypeInfoSettings" - ,"Defines how the type info of the database metadata should be manipulated." - ,false - ,OUString( ) - ,Sequence< OUString > ()) - ); - return Sequence< DriverPropertyInfo >(aDriverInfo.data(),aDriverInfo.size()); + return + { + { + "IgnoreDriverPrivileges", + "Ignore the privileges from the database driver.", + false, + "false", + aBooleanValues + }, + { + "EscapeDateTime", + "Escape date time format.", + false, + "true", + aBooleanValues + }, + { + "TypeInfoSettings", + "Defines how the type info of the database metadata should be manipulated.", + false, + {}, + {} + } + }; } return Sequence< DriverPropertyInfo >(); } @@ -192,13 +171,11 @@ Reference< XTablesSupplier > SAL_CALL ODriver::getDataDefinitionByConnection( co OConnection* pConnection = nullptr; Reference< css::lang::XUnoTunnel> xTunnel(connection,UNO_QUERY); - if(xTunnel.is()) + if (auto pSearchConnection = comphelper::getFromUnoTunnel<OConnection>(xTunnel)) { - OConnection* pSearchConnection = reinterpret_cast< OConnection* >( xTunnel->getSomething(OConnection::getUnoTunnelId()) ); - auto foundConnection = std::any_of(m_xConnections.begin(), m_xConnections.end(), [&pSearchConnection](const css::uno::WeakReferenceHelper& rxConnection) { - return static_cast<OConnection*>(Reference< XConnection >::query(rxConnection.get().get()).get()) == pSearchConnection; }); + return static_cast<OConnection*>(Reference< XConnection >::query(rxConnection.get()).get()) == pSearchConnection; }); if (foundConnection) pConnection = pSearchConnection; } @@ -210,11 +187,11 @@ Reference< XTablesSupplier > SAL_CALL ODriver::getDataDefinitionByConnection( co aCatalog.Create(); if(aCatalog.IsValid()) { - aCatalog.putref_ActiveConnection(*pConnection->getConnection()); - OCatalog* pCatalog = new OCatalog(aCatalog,pConnection); + aCatalog.putref_ActiveConnection(pConnection->getConnection()); + rtl::Reference<OCatalog> pCatalog = new OCatalog(aCatalog,pConnection); xTab = pCatalog; pConnection->setCatalog(xTab); - pConnection->setCatalog(pCatalog); + pConnection->setCatalog(pCatalog.get()); } } return xTab; @@ -229,13 +206,11 @@ Reference< XTablesSupplier > SAL_CALL ODriver::getDataDefinitionByURL( const OUS void ADOS::ThrowException(ADOConnection* _pAdoCon,const Reference< XInterface >& _xInterface) { - ADOErrors *pErrors = nullptr; + sal::systools::COMReference<ADOErrors> pErrors; _pAdoCon->get_Errors(&pErrors); if(!pErrors) return; // no error found - pErrors->AddRef( ); - // read all noted errors and issue them sal_Int32 nLen; pErrors->get_Count(&nLen); @@ -245,29 +220,31 @@ void ADOS::ThrowException(ADOConnection* _pAdoCon,const Reference< XInterface >& aException.ErrorCode = 1000; for (sal_Int32 i = nLen-1; i>=0; --i) { - ADOError *pError = nullptr; - pErrors->get_Item(OLEVariant(i),&pError); - WpADOError aErr(pError); - OSL_ENSURE(pError,"No error in collection found! BAD!"); - if(pError) + WpADOError aErr; + pErrors->get_Item(OLEVariant(i),&aErr); + OSL_ENSURE(aErr,"No error in collection found! BAD!"); + if(aErr) { if(i==nLen-1) aException = SQLException(aErr.GetDescription(),_xInterface,aErr.GetSQLState(),aErr.GetNumber(),Any()); else { SQLException aTemp(aErr.GetDescription(), - _xInterface,aErr.GetSQLState(),aErr.GetNumber(),makeAny(aException)); + _xInterface,aErr.GetSQLState(),aErr.GetNumber(),Any(aException)); aTemp.NextException <<= aException; aException = aTemp; } } } pErrors->Clear(); - pErrors->Release(); throw aException; } - pErrors->Release(); } - +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +connectivity_ado_ODriver_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&) +{ + return cppu::acquire(new ODriver(context)); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/ado/AGroup.cxx b/connectivity/source/drivers/ado/AGroup.cxx index b41fbdbba05d..02cd239d7682 100644 --- a/connectivity/source/drivers/ado/AGroup.cxx +++ b/connectivity/source/drivers/ado/AGroup.cxx @@ -21,7 +21,6 @@ #include <ado/AGroup.hxx> #include <ado/AUsers.hxx> #include <comphelper/servicehelper.hxx> -#include <cppuhelper/typeprovider.hxx> #include <com/sun/star/sdbc/XRow.hpp> #include <com/sun/star/sdbc/XResultSet.hpp> #include <ado/AConnection.hxx> @@ -37,26 +36,14 @@ using namespace com::sun::star::sdbcx; void WpADOGroup::Create() { - ADOGroup* pGroup = nullptr; - HRESULT hr = CoCreateInstance(ADOS::CLSID_ADOGROUP_25, - nullptr, - CLSCTX_INPROC_SERVER, - ADOS::IID_ADOGROUP_25, - reinterpret_cast<void**>(&pGroup) ); - - - if( !FAILED( hr ) ) - { - operator=( pGroup ); - pGroup->Release(); - } + pInterface.CoCreateInstance(ADOS::CLSID_ADOGROUP_25, nullptr, CLSCTX_INPROC_SERVER); } OAdoGroup::OAdoGroup(OCatalog* _pParent,bool _bCase, ADOGroup* _pGroup) : OGroup_ADO(_bCase),m_pCatalog(_pParent) { construct(); if(_pGroup) - m_aGroup = WpADOGroup(_pGroup); + m_aGroup.set(_pGroup); else m_aGroup.Create(); @@ -82,23 +69,6 @@ void OAdoGroup::refreshUsers() m_pUsers.reset(new OUsers(m_pCatalog, m_aMutex, aVector, aUsers, isCaseSensitive())); } -Sequence< sal_Int8 > OAdoGroup::getUnoTunnelId() -{ - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); -} - -// css::lang::XUnoTunnel - -sal_Int64 OAdoGroup::getSomething( const Sequence< sal_Int8 > & rId ) -{ - return isUnoTunnelId<OAdoGroup>(rId) - ? reinterpret_cast< sal_Int64 >( this ) - : OGroup_ADO::getSomething(rId); -} - - void OAdoGroup::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) { if(m_aGroup.IsValid()) diff --git a/connectivity/source/drivers/ado/AGroups.cxx b/connectivity/source/drivers/ado/AGroups.cxx index 211f34f6bebe..6f7c8b2da8d0 100644 --- a/connectivity/source/drivers/ado/AGroups.cxx +++ b/connectivity/source/drivers/ado/AGroups.cxx @@ -58,7 +58,7 @@ Reference< XPropertySet > OGroups::createDescriptor() // XAppend sdbcx::ObjectType OGroups::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) { - OAdoGroup* pGroup = getUnoTunnelImplementation<OAdoGroup>(descriptor); + OAdoGroup* pGroup = dynamic_cast<OAdoGroup*>(descriptor.get()); if ( pGroup == nullptr ) m_pCatalog->getConnection()->throwGenericSQLException( STR_INVALID_GROUP_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) ); diff --git a/connectivity/source/drivers/ado/AIndex.cxx b/connectivity/source/drivers/ado/AIndex.cxx index 61a047bc9b00..b183d49c2435 100644 --- a/connectivity/source/drivers/ado/AIndex.cxx +++ b/connectivity/source/drivers/ado/AIndex.cxx @@ -20,7 +20,6 @@ #include <ado/AIndex.hxx> #include <com/sun/star/sdbc/XRow.hpp> #include <com/sun/star/sdbc/XResultSet.hpp> -#include <cppuhelper/typeprovider.hxx> #include <ado/AColumns.hxx> #include <TConnection.hxx> #include <comphelper/servicehelper.hxx> @@ -40,7 +39,7 @@ OAdoIndex::OAdoIndex(bool _bCase,OConnection* _pConnection,ADOIndex* _pIndex) ,m_pConnection(_pConnection) { construct(); - m_aIndex = WpADOIndex(_pIndex); + m_aIndex.set(_pIndex); fillPropertyValues(); } @@ -71,22 +70,6 @@ void OAdoIndex::refreshColumns() } -Sequence< sal_Int8 > OAdoIndex::getUnoTunnelId() -{ - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); -} - -// css::lang::XUnoTunnel - -sal_Int64 OAdoIndex::getSomething( const Sequence< sal_Int8 > & rId ) -{ - return isUnoTunnelId<OAdoIndex>(rId) - ? reinterpret_cast< sal_Int64 >( this ) - : sdbcx::OIndex::getSomething(rId); -} - void SAL_CALL OAdoIndex::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) { if(m_aIndex.IsValid()) diff --git a/connectivity/source/drivers/ado/AIndexes.cxx b/connectivity/source/drivers/ado/AIndexes.cxx index 616cd863ada4..1e427a2f0782 100644 --- a/connectivity/source/drivers/ado/AIndexes.cxx +++ b/connectivity/source/drivers/ado/AIndexes.cxx @@ -58,14 +58,14 @@ Reference< XPropertySet > OIndexes::createDescriptor() // XAppend sdbcx::ObjectType OIndexes::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) { - OAdoIndex* pIndex = getUnoTunnelImplementation<OAdoIndex>(descriptor); + OAdoIndex* pIndex = dynamic_cast<OAdoIndex*>(descriptor.get()); if ( pIndex == nullptr ) m_pConnection->throwGenericSQLException( STR_INVALID_INDEX_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) ); ADOIndexes* pIndexes = m_aCollection; if ( FAILED( pIndexes->Append( OLEVariant( _rForName ), OLEVariant( pIndex->getImpl() ) ) ) ) { - ADOS::ThrowException(*m_pConnection->getConnection(),static_cast<XTypeProvider*>(this)); + ADOS::ThrowException(m_pConnection->getConnection(),static_cast<XTypeProvider*>(this)); m_pConnection->throwGenericSQLException( STR_INVALID_INDEX_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) ); } diff --git a/connectivity/source/drivers/ado/AKey.cxx b/connectivity/source/drivers/ado/AKey.cxx index 764765b35620..9c2734ede8f1 100644 --- a/connectivity/source/drivers/ado/AKey.cxx +++ b/connectivity/source/drivers/ado/AKey.cxx @@ -21,7 +21,6 @@ #include <com/sun/star/sdbc/XRow.hpp> #include <com/sun/star/sdbc/XResultSet.hpp> #include <comphelper/servicehelper.hxx> -#include <cppuhelper/typeprovider.hxx> #include <ado/AColumns.hxx> #include <ado/AConnection.hxx> @@ -38,7 +37,7 @@ OAdoKey::OAdoKey(bool _bCase,OConnection* _pConnection, ADOKey* _pKey) ,m_pConnection(_pConnection) { construct(); - m_aKey = WpADOKey(_pKey); + m_aKey.set(_pKey); fillPropertyValues(); } @@ -67,22 +66,6 @@ void OAdoKey::refreshColumns() m_pColumns.reset(new OColumns(*this, m_aMutex, aVector, aColumns, isCaseSensitive(), m_pConnection)); } -Sequence< sal_Int8 > OAdoKey::getUnoTunnelId() -{ - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); -} - -// css::lang::XUnoTunnel - -sal_Int64 OAdoKey::getSomething( const Sequence< sal_Int8 > & rId ) -{ - return isUnoTunnelId<OAdoKey>(rId) - ? reinterpret_cast< sal_Int64 >( this ) - : OKey_ADO::getSomething(rId); -} - void OAdoKey::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) { if(m_aKey.IsValid()) @@ -94,7 +77,7 @@ void OAdoKey::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rVal OUString aVal; rValue >>= aVal; m_aKey.put_Name(aVal); - ADOS::ThrowException(*m_pConnection->getConnection(),*this); + ADOS::ThrowException(m_pConnection->getConnection(),*this); } break; case PROPERTY_ID_TYPE: @@ -102,7 +85,7 @@ void OAdoKey::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rVal sal_Int32 nVal=0; rValue >>= nVal; m_aKey.put_Type(Map2KeyRule(nVal)); - ADOS::ThrowException(*m_pConnection->getConnection(),*this); + ADOS::ThrowException(m_pConnection->getConnection(),*this); } break; case PROPERTY_ID_REFERENCEDTABLE: @@ -110,7 +93,7 @@ void OAdoKey::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rVal OUString aVal; rValue >>= aVal; m_aKey.put_RelatedTable(aVal); - ADOS::ThrowException(*m_pConnection->getConnection(),*this); + ADOS::ThrowException(m_pConnection->getConnection(),*this); } break; case PROPERTY_ID_UPDATERULE: @@ -118,7 +101,7 @@ void OAdoKey::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rVal sal_Int32 nVal=0; rValue >>= nVal; m_aKey.put_UpdateRule(Map2Rule(nVal)); - ADOS::ThrowException(*m_pConnection->getConnection(),*this); + ADOS::ThrowException(m_pConnection->getConnection(),*this); } break; case PROPERTY_ID_DELETERULE: @@ -126,7 +109,7 @@ void OAdoKey::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rVal sal_Int32 nVal=0; rValue >>= nVal; m_aKey.put_DeleteRule(Map2Rule(nVal)); - ADOS::ThrowException(*m_pConnection->getConnection(),*this); + ADOS::ThrowException(m_pConnection->getConnection(),*this); } break; } diff --git a/connectivity/source/drivers/ado/AKeys.cxx b/connectivity/source/drivers/ado/AKeys.cxx index 19027e79ffb6..32d02bc743e7 100644 --- a/connectivity/source/drivers/ado/AKeys.cxx +++ b/connectivity/source/drivers/ado/AKeys.cxx @@ -58,7 +58,7 @@ Reference< XPropertySet > OKeys::createDescriptor() // XAppend sdbcx::ObjectType OKeys::appendObject( const OUString&, const Reference< XPropertySet >& descriptor ) { - OAdoKey* pKey = getUnoTunnelImplementation<OAdoKey>( descriptor ); + OAdoKey* pKey = dynamic_cast<OAdoKey*>( descriptor.get() ); if ( pKey == nullptr) m_pConnection->throwGenericSQLException( STR_INVALID_KEY_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) ); @@ -71,14 +71,14 @@ sdbcx::ObjectType OKeys::appendObject( const OUString&, const Reference< XProper WpADOKey aKey = pKey->getImpl(); OUString sName = aKey.get_Name(); if(!sName.getLength()) - aKey.put_Name("PrimaryKey"); + aKey.put_Name(u"PrimaryKey"); ADOKeys* pKeys = m_aCollection; if ( FAILED(pKeys->Append(OLEVariant(static_cast<ADOKey*>(aKey)), adKeyPrimary, // must be every time adKeyPrimary vOptional)) ) { - ADOS::ThrowException(*m_pConnection->getConnection(),static_cast<XTypeProvider*>(this)); + ADOS::ThrowException(m_pConnection->getConnection(),static_cast<XTypeProvider*>(this)); // just make sure that an SQLExceptionis thrown here m_pConnection->throwGenericSQLException( STR_INVALID_KEY_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) ); } @@ -90,7 +90,7 @@ sdbcx::ObjectType OKeys::appendObject( const OUString&, const Reference< XProper void OKeys::dropObject(sal_Int32 /*_nPos*/,const OUString& _sElementName) { if(!m_aCollection.Delete(OLEVariant(_sElementName).getString())) - ADOS::ThrowException(*m_pConnection->getConnection(),static_cast<XTypeProvider*>(this)); + ADOS::ThrowException(m_pConnection->getConnection(),static_cast<XTypeProvider*>(this)); } diff --git a/connectivity/source/drivers/ado/APreparedStatement.cxx b/connectivity/source/drivers/ado/APreparedStatement.cxx index ecd4ed538d83..9e17d71b0bed 100644 --- a/connectivity/source/drivers/ado/APreparedStatement.cxx +++ b/connectivity/source/drivers/ado/APreparedStatement.cxx @@ -31,13 +31,14 @@ #include <comphelper/types.hxx> #include <connectivity/dbexception.hxx> #include <connectivity/dbtools.hxx> +#include <rtl/ref.hxx> #include <strings.hrc> #include <limits> #define CHECK_RETURN(x) \ if(!x) \ - ADOS::ThrowException(*m_pConnection->getConnection(),*this); + ADOS::ThrowException(m_pConnection->getConnection(),*this); #ifdef max # undef max @@ -58,7 +59,7 @@ OPreparedStatement::OPreparedStatement( OConnection* _pConnection, const OUStrin { osl_atomic_increment( &m_refCount ); - OSQLParser aParser(comphelper::getComponentContext(_pConnection->getDriver()->getORB())); + OSQLParser aParser(_pConnection->getDriver()->getContext()); OUString sErrorMessage; OUString sNewSql; std::unique_ptr<OSQLParseNode> pNode = aParser.parseTree(sErrorMessage,sql); @@ -144,21 +145,18 @@ sal_Bool SAL_CALL OPreparedStatement::execute( ) ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OStatement_BASE::rBHelper.bDisposed); - SQLWarning warning; clearWarnings (); // Call SQLExecute try { ADORecordset* pSet=nullptr; CHECK_RETURN(m_Command.Execute(m_RecordsAffected,m_Parameters,adCmdUnknown,&pSet)) - m_RecordSet = WpADORecordset(pSet); + m_RecordSet.set(pSet); } - catch (SQLWarning& ex) + catch (SQLWarning&) { - // Save pointer to warning and save with ResultSet + //TODO: Save pointer to warning and save with ResultSet // object once it is created. - - warning = ex; } return m_RecordSet.IsValid(); } @@ -173,11 +171,11 @@ sal_Int32 SAL_CALL OPreparedStatement::executeUpdate( ) CHECK_RETURN(m_Command.Execute(m_RecordsAffected,m_Parameters,adCmdUnknown,&pSet)) if ( VT_ERROR == m_RecordsAffected.getType() ) { - ADOS::ThrowException(*m_pConnection->getConnection(),*this); + ADOS::ThrowException(m_pConnection->getConnection(),*this); // to be sure that we get the error really thrown throw SQLException(); } - m_RecordSet = WpADORecordset(pSet); + m_RecordSet.set(pSet); return m_RecordsAffected.getInt32(); } @@ -201,10 +199,9 @@ void OPreparedStatement::setParameter(sal_Int32 parameterIndex, const DataTypeEn } else { - ADOParameter* pParam = nullptr; - m_pParameters->get_Item(OLEVariant(sal_Int32(parameterIndex-1)),&pParam); - WpADOParameter aParam(pParam); - if(pParam) + WpADOParameter aParam; + m_pParameters->get_Item(OLEVariant(sal_Int32(parameterIndex-1)),&aParam); + if(aParam) { DataTypeEnum eType = aParam.GetADOType(); if ( _eType != eType && _eType != adDBTimeStamp ) @@ -222,7 +219,7 @@ void OPreparedStatement::setParameter(sal_Int32 parameterIndex, const DataTypeEn CHECK_RETURN(aParam.PutValue(Val)); } } - ADOS::ThrowException(*m_pConnection->getConnection(),*this); + ADOS::ThrowException(m_pConnection->getConnection(),*this); } void SAL_CALL OPreparedStatement::setString( sal_Int32 parameterIndex, const OUString& x ) @@ -264,13 +261,12 @@ Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery( ) CHECK_RETURN(m_RecordSet.get_CursorType(m_eCursorType)) CHECK_RETURN(m_RecordSet.get_LockType(m_eLockType)) - OResultSet* pSet = new OResultSet(m_RecordSet,this); - Reference< XResultSet > xRs = pSet; + rtl::Reference<OResultSet> pSet = new OResultSet(m_RecordSet,this); pSet->construct(); pSet->setMetaData(getMetaData()); - m_xResultSet = WeakReference<XResultSet>(xRs); + m_xResultSet = WeakReference<XResultSet>(pSet); - return xRs; + return pSet; } void SAL_CALL OPreparedStatement::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) @@ -415,10 +411,9 @@ void SAL_CALL OPreparedStatement::clearParameters( ) aVal.setEmpty(); for(sal_Int32 i=0;i<nCount;++i) { - ADOParameter* pParam = nullptr; - m_pParameters->get_Item(OLEVariant(i),&pParam); - WpADOParameter aParam(pParam); - if(pParam) + WpADOParameter aParam; + m_pParameters->get_Item(OLEVariant(i),&aParam); + if(aParam) { CHECK_RETURN(aParam.PutValue(aVal)); } @@ -426,12 +421,12 @@ void SAL_CALL OPreparedStatement::clearParameters( ) } } -void SAL_CALL OPreparedStatement::acquire() throw() +void SAL_CALL OPreparedStatement::acquire() noexcept { OStatement_Base::acquire(); } -void SAL_CALL OPreparedStatement::release() throw() +void SAL_CALL OPreparedStatement::release() noexcept { OStatement_Base::release(); } @@ -447,7 +442,7 @@ void OPreparedStatement::replaceParameterNodeName(OSQLParseNode const * _pNode, if(SQL_ISRULE(pChildNode,parameter) && pChildNode->count() == 1) { OSQLParseNode* pNewNode = new OSQLParseNode(OUString(":") ,SQLNodeType::Punctuation,0); - delete pChildNode->replace(pChildNode->getChild(0),pNewNode); + pChildNode->replaceAndDelete(pChildNode->getChild(0), pNewNode); OUString sParameterName = _sDefaultName + OUString::number(++_rParameterCount); pChildNode->append(new OSQLParseNode( sParameterName,SQLNodeType::Name,0)); } diff --git a/connectivity/source/drivers/ado/AResultSet.cxx b/connectivity/source/drivers/ado/AResultSet.cxx index dae0f91efb61..85ca2b081a07 100644 --- a/connectivity/source/drivers/ado/AResultSet.cxx +++ b/connectivity/source/drivers/ado/AResultSet.cxx @@ -44,7 +44,7 @@ using namespace ::comphelper; #define CHECK_RETURN(x) \ if(!SUCCEEDED(x)) \ - ADOS::ThrowException(*m_pStmt->m_pConnection->getConnection(),*this); + ADOS::ThrowException(m_pStmt->m_pConnection->getConnection(),*this); using namespace connectivity::ado; using namespace com::sun::star::uno; @@ -174,14 +174,14 @@ Reference< css::io::XInputStream > SAL_CALL OResultSet::getBinaryStream( sal_Int //Copy the data only up to the Actual Size of Field. sal_Int32 nSize = aField.GetActualSize(); Sequence<sal_Int8> aData(nSize); - long index = 0; + sal_Int32 index = 0; while(index < nSize) { m_aValue = aField.GetChunk(BLOCK_SIZE); if(m_aValue.isNull()) break; UCHAR chData; - for(long index2 = 0;index2 < BLOCK_SIZE;++index2) + for(LONG index2 = 0;index2 < BLOCK_SIZE;++index2) { HRESULT hr = ::SafeArrayGetElement(m_aValue.parray,&index2,&chData); if(SUCCEEDED(hr)) @@ -596,7 +596,7 @@ sal_Bool SAL_CALL OResultSet::next( ) ++m_nRowPos; } else - ADOS::ThrowException(*m_pStmt->m_pConnection->getConnection(),*this); + ADOS::ThrowException(m_pStmt->m_pConnection->getConnection(),*this); } return bRet; @@ -818,12 +818,12 @@ Any SAL_CALL OResultSet::getBookmark( ) checkDisposed(OResultSet_BASE::rBHelper.bDisposed); if(m_nRowPos < static_cast<sal_Int32>(m_aBookmarks.size())) // this bookmark was already fetched - return makeAny(sal_Int32(m_nRowPos-1)); + return Any(sal_Int32(m_nRowPos-1)); OLEVariant aVar; m_pRecordSet->get_Bookmark(&aVar); m_aBookmarks.push_back(aVar); - return makeAny(static_cast<sal_Int32>(m_aBookmarks.size()-1)); + return Any(static_cast<sal_Int32>(m_aBookmarks.size()-1)); } @@ -882,11 +882,9 @@ sal_Bool SAL_CALL OResultSet::hasOrderedBookmarks( ) checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - ADOProperties* pProps = nullptr; - m_pRecordSet->get_Properties(&pProps); WpADOProperties aProps; - aProps.setWithOutAddRef(pProps); - ADOS::ThrowException(*static_cast<OConnection*>(m_pStmt->getConnection().get())->getConnection(),*this); + m_pRecordSet->get_Properties(&aProps); + ADOS::ThrowException(static_cast<OConnection*>(m_pStmt->getConnection().get())->getConnection(),*this); OSL_ENSURE(aProps.IsValid(),"There are no properties at the connection"); WpADOProperty aProp(aProps.GetItem(OUString("Bookmarks Ordered"))); @@ -894,7 +892,7 @@ sal_Bool SAL_CALL OResultSet::hasOrderedBookmarks( ) if(aProp.IsValid()) aVar = aProp.GetValue(); else - ADOS::ThrowException(*static_cast<OConnection*>(m_pStmt->getConnection().get())->getConnection(),*this); + ADOS::ThrowException(static_cast<OConnection*>(m_pStmt->getConnection().get())->getConnection(),*this); bool bValue(false); if(!aVar.isNull() && !aVar.isEmpty()) @@ -1035,26 +1033,31 @@ void OResultSet::setFetchSize(sal_Int32 _par0) ::cppu::IPropertyArrayHelper* OResultSet::createArrayHelper( ) const { - Sequence< css::beans::Property > aProps(5); - css::beans::Property* pProperties = aProps.getArray(); - sal_Int32 nPos = 0; - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), - PROPERTY_ID_FETCHDIRECTION, cppu::UnoType<sal_Int32>::get(), 0); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), - PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE), - PROPERTY_ID_ISBOOKMARKABLE, cppu::UnoType<bool>::get(), PropertyAttribute::READONLY); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), - PROPERTY_ID_RESULTSETCONCURRENCY, cppu::UnoType<sal_Int32>::get(), PropertyAttribute::READONLY); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), - PROPERTY_ID_RESULTSETTYPE, cppu::UnoType<sal_Int32>::get(), PropertyAttribute::READONLY); - - return new ::cppu::OPropertyArrayHelper(aProps); + return new ::cppu::OPropertyArrayHelper + { + { + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), + PROPERTY_ID_FETCHDIRECTION, cppu::UnoType<sal_Int32>::get(), 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), + PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE), + PROPERTY_ID_ISBOOKMARKABLE, cppu::UnoType<bool>::get(), PropertyAttribute::READONLY + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), + PROPERTY_ID_RESULTSETCONCURRENCY, cppu::UnoType<sal_Int32>::get(), PropertyAttribute::READONLY + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), + PROPERTY_ID_RESULTSETTYPE, cppu::UnoType<sal_Int32>::get(), PropertyAttribute::READONLY + } + } + }; } ::cppu::IPropertyArrayHelper & OResultSet::getInfoHelper() @@ -1136,12 +1139,12 @@ void OResultSet::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const } } -void SAL_CALL OResultSet::acquire() throw() +void SAL_CALL OResultSet::acquire() noexcept { OResultSet_BASE::acquire(); } -void SAL_CALL OResultSet::release() throw() +void SAL_CALL OResultSet::release() noexcept { OResultSet_BASE::release(); } diff --git a/connectivity/source/drivers/ado/AResultSetMetaData.cxx b/connectivity/source/drivers/ado/AResultSetMetaData.cxx index 23983342ebc5..d43ee5da9216 100644 --- a/connectivity/source/drivers/ado/AResultSetMetaData.cxx +++ b/connectivity/source/drivers/ado/AResultSetMetaData.cxx @@ -17,6 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <string_view> + #include <ado/AResultSetMetaData.hxx> #include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/sdbc/ColumnValue.hpp> @@ -68,10 +72,9 @@ sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount( ) if ( !m_pRecordSet ) return 0; - ADOFields* pFields = nullptr; + WpOLEAppendCollection<ADOFields, WpADOField> pFields; m_pRecordSet->get_Fields(&pFields); - WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(pFields); - m_nColCount = aFields.GetItemCount(); + m_nColCount = pFields.GetItemCount(); return m_nColCount; } @@ -84,7 +87,7 @@ sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 column ) { WpADOProperties aProps( aField.get_Properties() ); if ( aProps.IsValid() ) - bRet = OTools::getValue( aProps, OUString("ISCASESENSITIVE") ).getBool(); + bRet = OTools::getValue(aProps, std::u16string_view(u"ISCASESENSITIVE")).getBool(); } return bRet; } @@ -114,7 +117,8 @@ OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 column ) { WpADOProperties aProps( aField.get_Properties() ); if ( aProps.IsValid() ) - sTableName = OTools::getValue( aProps, OUString("BASETABLENAME") ).getString(); + sTableName + = OTools::getValue(aProps, std::u16string_view(u"BASETABLENAME")).getString(); } return sTableName; } @@ -160,7 +164,7 @@ sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 column ) WpADOProperties aProps( aField.get_Properties() ); if ( aProps.IsValid() ) { - bRet = OTools::getValue( aProps, OUString("ISAUTOINCREMENT") ).getBool(); + bRet = OTools::getValue(aProps, std::u16string_view(u"ISAUTOINCREMENT")).getBool(); } } return bRet; diff --git a/connectivity/source/drivers/ado/AStatement.cxx b/connectivity/source/drivers/ado/AStatement.cxx index 01fea934cd19..c2a09385dee6 100644 --- a/connectivity/source/drivers/ado/AStatement.cxx +++ b/connectivity/source/drivers/ado/AStatement.cxx @@ -30,6 +30,7 @@ #include <com/sun/star/sdbc/FetchDirection.hpp> #include <connectivity/dbexception.hxx> #include <comphelper/types.hxx> +#include <rtl/ref.hxx> #undef max @@ -40,7 +41,7 @@ using namespace ::comphelper; #define CHECK_RETURN(x) \ if(!x) \ - ADOS::ThrowException(*m_pConnection->getConnection(),*this); + ADOS::ThrowException(m_pConnection->getConnection(),*this); using namespace connectivity::ado; @@ -50,7 +51,6 @@ using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; -using namespace ::std; OStatement_Base::OStatement_Base(OConnection* _pConnection ) : OStatement_BASE(m_aMutex) ,OPropertySetHelper(OStatement_BASE::rBHelper) @@ -66,7 +66,7 @@ OStatement_Base::OStatement_Base(OConnection* _pConnection ) : OStatement_BASE( if(m_Command.IsValid()) m_Command.putref_ActiveConnection(m_pConnection->getConnection()); else - ADOS::ThrowException(*m_pConnection->getConnection(),*this); + ADOS::ThrowException(m_pConnection->getConnection(),*this); m_RecordsAffected.setNoArg(); m_Parameters.setNoArg(); @@ -94,7 +94,7 @@ void OStatement_Base::disposing() disposeResultSet(); if ( m_Command.IsValid() ) - m_Command.putref_ActiveConnection( nullptr ); + m_Command.putref_ActiveConnection({}); m_Command.clear(); if ( m_RecordSet.IsValid() ) @@ -107,7 +107,7 @@ void OStatement_Base::disposing() OStatement_BASE::disposing(); } -void SAL_CALL OStatement_Base::release() throw() +void SAL_CALL OStatement_Base::release() noexcept { OStatement_BASE::release(); } @@ -239,7 +239,7 @@ void OStatement_Base::setWarning (const SQLWarning &ex) void OStatement_Base::assignRecordSet( ADORecordset* _pRS ) { WpADORecordset aOldRS( m_RecordSet ); - m_RecordSet = WpADORecordset( _pRS ); + m_RecordSet.set( _pRS ); if ( aOldRS.IsValid() ) aOldRS.PutRefDataSource( nullptr ); @@ -305,13 +305,12 @@ Reference< XResultSet > SAL_CALL OStatement_Base::executeQuery( const OUString& CHECK_RETURN(aSet.get_CursorType(m_eCursorType)) CHECK_RETURN(aSet.get_LockType(m_eLockType)) - OResultSet* pSet = new OResultSet(aSet,this); - Reference< XResultSet > xRs = pSet; + rtl::Reference<OResultSet> pSet = new OResultSet(aSet,this); pSet->construct(); - m_xResultSet = WeakReference<XResultSet>(xRs); + m_xResultSet = WeakReference<XResultSet>(pSet); - return xRs; + return pSet; } @@ -396,7 +395,7 @@ sal_Int32 SAL_CALL OStatement_Base::executeUpdate( const OUString& sql ) try { ADORecordset* pSet = nullptr; CHECK_RETURN(m_Command.put_CommandText(sql)) - CHECK_RETURN(m_Command.Execute(m_RecordsAffected,m_Parameters,adCmdText|adExecuteNoRecords,&pSet)) + CHECK_RETURN(m_Command.Execute(m_RecordsAffected,m_Parameters,long(adCmdText)|long(adExecuteNoRecords),&pSet)) } catch (SQLWarning& ex) { @@ -441,8 +440,6 @@ sal_Bool SAL_CALL OStatement_Base::getMoreResults( ) checkDisposed(OStatement_BASE::rBHelper.bDisposed); - SQLWarning warning; - // clear previous warnings clearWarnings (); @@ -456,13 +453,11 @@ sal_Bool SAL_CALL OStatement_Base::getMoreResults( ) if(m_RecordSet.IsValid() && m_RecordSet.NextRecordset(aRecordsAffected,&pSet) && pSet) assignRecordSet( pSet ); } - catch (SQLWarning &ex) + catch (SQLWarning &) { - // Save pointer to warning and save with ResultSet + //TODO: Save pointer to warning and save with ResultSet // object once it is created. - - warning = ex; } return m_RecordSet.IsValid(); } @@ -474,7 +469,7 @@ Any SAL_CALL OStatement_Base::getWarnings( ) checkDisposed(OStatement_BASE::rBHelper.bDisposed); - return makeAny(m_aLastWarning); + return Any(m_aLastWarning); } @@ -634,7 +629,7 @@ void OStatement_Base::setMaxFieldSize(sal_Int32 /*_par0*/) ::dbtools::throwFeatureNotImplementedSQLException( "Statement::MaxFieldSize", *this ); } -void OStatement_Base::setCursorName(const OUString &_par0) +void OStatement_Base::setCursorName(std::u16string_view _par0) { ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OStatement_BASE::rBHelper.bDisposed); @@ -645,31 +640,71 @@ void OStatement_Base::setCursorName(const OUString &_par0) ::cppu::IPropertyArrayHelper* OStatement_Base::createArrayHelper( ) const { - Sequence< css::beans::Property > aProps(10); - css::beans::Property* pProperties = aProps.getArray(); - sal_Int32 nPos = 0; - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), - PROPERTY_ID_CURSORNAME, cppu::UnoType<OUString>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ESCAPEPROCESSING), - PROPERTY_ID_ESCAPEPROCESSING, cppu::UnoType<bool>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), - PROPERTY_ID_FETCHDIRECTION, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), - PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXFIELDSIZE), - PROPERTY_ID_MAXFIELDSIZE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXROWS), - PROPERTY_ID_MAXROWS, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_QUERYTIMEOUT), - PROPERTY_ID_QUERYTIMEOUT, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), - PROPERTY_ID_RESULTSETCONCURRENCY, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), - PROPERTY_ID_RESULTSETTYPE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_USEBOOKMARKS), - PROPERTY_ID_USEBOOKMARKS, cppu::UnoType<bool>::get(), 0); - - return new ::cppu::OPropertyArrayHelper(aProps); + return new ::cppu::OPropertyArrayHelper + { + { + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), + PROPERTY_ID_CURSORNAME, + cppu::UnoType<OUString>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ESCAPEPROCESSING), + PROPERTY_ID_ESCAPEPROCESSING, + cppu::UnoType<bool>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), + PROPERTY_ID_FETCHDIRECTION, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), + PROPERTY_ID_FETCHSIZE, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXFIELDSIZE), + PROPERTY_ID_MAXFIELDSIZE, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXROWS), + PROPERTY_ID_MAXROWS, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_QUERYTIMEOUT), + PROPERTY_ID_QUERYTIMEOUT, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), + PROPERTY_ID_RESULTSETCONCURRENCY, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), + PROPERTY_ID_RESULTSETTYPE, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_USEBOOKMARKS), + PROPERTY_ID_USEBOOKMARKS, + cppu::UnoType<bool>::get(), + 0 + } + } + }; } @@ -809,17 +844,17 @@ OStatement::~OStatement() } IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbcx.AStatement","com.sun.star.sdbc.Statement"); -void SAL_CALL OStatement_Base::acquire() throw() +void SAL_CALL OStatement_Base::acquire() noexcept { OStatement_BASE::acquire(); } -void SAL_CALL OStatement::acquire() throw() +void SAL_CALL OStatement::acquire() noexcept { OStatement_Base::acquire(); } -void SAL_CALL OStatement::release() throw() +void SAL_CALL OStatement::release() noexcept { OStatement_Base::release(); } diff --git a/connectivity/source/drivers/ado/ATable.cxx b/connectivity/source/drivers/ado/ATable.cxx index 209255598476..47e22e125398 100644 --- a/connectivity/source/drivers/ado/ATable.cxx +++ b/connectivity/source/drivers/ado/ATable.cxx @@ -17,6 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <string_view> + #include <ado/ATable.hxx> #include <ado/AIndexes.hxx> #include <ado/AColumns.hxx> @@ -27,7 +31,6 @@ #include <com/sun/star/sdbc/XResultSet.hpp> #include <com/sun/star/sdbcx/KeyType.hpp> #include <com/sun/star/sdbc/KeyRule.hpp> -#include <cppuhelper/typeprovider.hxx> #include <com/sun/star/lang/DisposedException.hpp> #include <com/sun/star/sdbc/ColumnValue.hpp> #include <ado/Awrapado.hxx> @@ -51,7 +54,7 @@ OAdoTable::OAdoTable(sdbcx::OCollection* _pTables,bool _bCase,OCatalog* _pCatalo ,m_pCatalog(_pCatalog) { construct(); - m_aTable = WpADOTable(_pTable); + m_aTable.set(_pTable); // m_aTable.putref_ParentCatalog(_pCatalog->getCatalog()); fillPropertyValues(); @@ -87,7 +90,7 @@ void OAdoTable::refreshColumns() if(m_xColumns) m_xColumns->reFill(aVector); else - m_xColumns = new OColumns(*this,m_aMutex,aVector,aColumns,isCaseSensitive(),m_pCatalog->getConnection()); + m_xColumns.reset(new OColumns(*this,m_aMutex,aVector,aColumns,isCaseSensitive(),m_pCatalog->getConnection())); } void OAdoTable::refreshKeys() @@ -104,7 +107,7 @@ void OAdoTable::refreshKeys() if(m_xKeys) m_xKeys->reFill(aVector); else - m_xKeys = new OKeys(*this,m_aMutex,aVector,aKeys,isCaseSensitive(),m_pCatalog->getConnection()); + m_xKeys.reset(new OKeys(*this,m_aMutex,aVector,aKeys,isCaseSensitive(),m_pCatalog->getConnection())); } void OAdoTable::refreshIndexes() @@ -121,23 +124,7 @@ void OAdoTable::refreshIndexes() if(m_xIndexes) m_xIndexes->reFill(aVector); else - m_xIndexes = new OIndexes(*this,m_aMutex,aVector,aIndexes,isCaseSensitive(),m_pCatalog->getConnection()); -} - -Sequence< sal_Int8 > OAdoTable::getUnoTunnelId() -{ - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); -} - -// css::lang::XUnoTunnel - -sal_Int64 OAdoTable::getSomething( const Sequence< sal_Int8 > & rId ) -{ - return isUnoTunnelId<OAdoTable>(rId) - ? reinterpret_cast< sal_Int64 >( this ) - : OTable_TYPEDEF::getSomething(rId); + m_xIndexes.reset(new OIndexes(*this,m_aMutex,aVector,aIndexes,isCaseSensitive(),m_pCatalog->getConnection())); } // XRename @@ -147,7 +134,7 @@ void SAL_CALL OAdoTable::rename( const OUString& newName ) checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper.bDisposed); m_aTable.put_Name(newName); - ADOS::ThrowException(*(m_pCatalog->getConnection()->getConnection()),*this); + ADOS::ThrowException(m_pCatalog->getConnection()->getConnection(),*this); OTable_TYPEDEF::rename(newName); } @@ -164,7 +151,7 @@ void SAL_CALL OAdoTable::alterColumnByName( const OUString& colName, const Refer checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper.bDisposed); bool bError = true; - OAdoColumn* pColumn = comphelper::getUnoTunnelImplementation<OAdoColumn>(descriptor); + OAdoColumn* pColumn = dynamic_cast<OAdoColumn*>(descriptor.get()); if(pColumn != nullptr) { WpADOColumns aColumns = m_aTable.get_Columns(); @@ -172,7 +159,7 @@ void SAL_CALL OAdoTable::alterColumnByName( const OUString& colName, const Refer bError = bError || !aColumns.Append(pColumn->getColumnImpl()); } if(bError) - ADOS::ThrowException(*(m_pCatalog->getConnection()->getConnection()),*this); + ADOS::ThrowException(m_pCatalog->getConnection()->getConnection(),*this); m_xColumns->refresh(); refreshColumns(); @@ -207,7 +194,7 @@ void OAdoTable::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rV case PROPERTY_ID_DESCRIPTION: OTools::putValue( m_aTable.get_Properties(), - OUString("Description"), + std::u16string_view(u"Description"), getString(rValue)); break; diff --git a/connectivity/source/drivers/ado/ATables.cxx b/connectivity/source/drivers/ado/ATables.cxx index 9ce87634e425..07910462fb17 100644 --- a/connectivity/source/drivers/ado/ATables.cxx +++ b/connectivity/source/drivers/ado/ATables.cxx @@ -65,13 +65,13 @@ Reference< XPropertySet > OTables::createDescriptor() // XAppend sdbcx::ObjectType OTables::appendObject( const OUString&, const Reference< XPropertySet >& descriptor ) { - OAdoTable* pTable = getUnoTunnelImplementation<OAdoTable>( descriptor ); + OAdoTable* pTable = dynamic_cast<OAdoTable*>( descriptor.get() ); if ( pTable == nullptr ) m_pCatalog->getConnection()->throwGenericSQLException( STR_INVALID_TABLE_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) ); OSL_ENSURE(m_aCollection.IsValid(),"Collection isn't valid"); if(!m_aCollection.Append(pTable->getImpl())) - ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),static_cast<XTypeProvider*>(this)); + ADOS::ThrowException(m_pCatalog->getConnection()->getConnection(),static_cast<XTypeProvider*>(this)); m_aCollection.Refresh(); return new OAdoTable(this,isCaseSensitive(),m_pCatalog,pTable->getImpl()); @@ -82,7 +82,7 @@ void OTables::dropObject(sal_Int32 /*_nPos*/,const OUString& _sElementName) { OSL_ENSURE(m_aCollection.IsValid(),"Collection isn't valid"); if ( !m_aCollection.Delete(_sElementName) ) - ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),static_cast<XTypeProvider*>(this)); + ADOS::ThrowException(m_pCatalog->getConnection()->getConnection(),static_cast<XTypeProvider*>(this)); } void OTables::appendNew(const OUString& _rsNewTable) @@ -93,10 +93,10 @@ void OTables::appendNew(const OUString& _rsNewTable) insertElement(_rsNewTable,nullptr); // notify our container listeners - ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(_rsNewTable), Any(), Any()); - OInterfaceIteratorHelper2 aListenerLoop(m_aContainerListeners); + ContainerEvent aEvent(static_cast<XContainer*>(this), Any(_rsNewTable), Any(), Any()); + OInterfaceIteratorHelper3 aListenerLoop(m_aContainerListeners); while (aListenerLoop.hasMoreElements()) - static_cast<XContainerListener*>(aListenerLoop.next())->elementInserted(aEvent); + aListenerLoop.next()->elementInserted(aEvent); } diff --git a/connectivity/source/drivers/ado/AUser.cxx b/connectivity/source/drivers/ado/AUser.cxx index 724334cea696..eb7a5803f60c 100644 --- a/connectivity/source/drivers/ado/AUser.cxx +++ b/connectivity/source/drivers/ado/AUser.cxx @@ -21,7 +21,6 @@ #include <ado/ACatalog.hxx> #include <ado/AGroups.hxx> #include <comphelper/servicehelper.hxx> -#include <cppuhelper/typeprovider.hxx> #include <com/sun/star/sdbc/XRow.hpp> #include <com/sun/star/sdbc/XResultSet.hpp> #include <ado/AConnection.hxx> @@ -41,7 +40,7 @@ OAdoUser::OAdoUser(OCatalog* _pParent,bool _bCase, ADOUser* _pUser) construct(); if(_pUser) - m_aUser = WpADOUser(_pUser); + m_aUser.set(_pUser); else m_aUser.Create(); } @@ -66,23 +65,6 @@ void OAdoUser::refreshGroups() m_pGroups.reset(new OGroups(m_pCatalog, m_aMutex, aVector, aGroups, isCaseSensitive())); } -Sequence< sal_Int8 > OAdoUser::getUnoTunnelId() -{ - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); -} - -// css::lang::XUnoTunnel - -sal_Int64 OAdoUser::getSomething( const Sequence< sal_Int8 > & rId ) -{ - return isUnoTunnelId<OAdoUser>(rId) - ? reinterpret_cast< sal_Int64 >( this ) - : OUser_TYPEDEF::getSomething(rId); -} - - void OAdoUser::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) { if(m_aUser.IsValid()) @@ -160,7 +142,7 @@ sal_Int32 SAL_CALL OAdoUser::getGrantablePrivileges( const OUString& objName, sa RightsEnum eRights = m_aUser.GetPermissions(objName, ADOS::mapObjectType2Ado(objType)); if((eRights & adRightWithGrant) == adRightWithGrant) nRights = ADOS::mapAdoRights2Sdbc(eRights); - ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),*this); + ADOS::ThrowException(m_pCatalog->getConnection()->getConnection(),*this); return nRights; } @@ -169,7 +151,7 @@ void SAL_CALL OAdoUser::grantPrivileges( const OUString& objName, sal_Int32 objT ::osl::MutexGuard aGuard(m_aMutex); checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed); m_aUser.SetPermissions(objName,ADOS::mapObjectType2Ado(objType),adAccessGrant,RightsEnum(ADOS::mapRights2Ado(objPrivileges))); - ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),*this); + ADOS::ThrowException(m_pCatalog->getConnection()->getConnection(),*this); } void SAL_CALL OAdoUser::revokePrivileges( const OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) @@ -177,7 +159,7 @@ void SAL_CALL OAdoUser::revokePrivileges( const OUString& objName, sal_Int32 obj ::osl::MutexGuard aGuard(m_aMutex); checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed); m_aUser.SetPermissions(objName,ADOS::mapObjectType2Ado(objType),adAccessRevoke,RightsEnum(ADOS::mapRights2Ado(objPrivileges))); - ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),*this); + ADOS::ThrowException(m_pCatalog->getConnection()->getConnection(),*this); } // XUser @@ -186,7 +168,7 @@ void SAL_CALL OAdoUser::changePassword( const OUString& objPassword, const OUStr ::osl::MutexGuard aGuard(m_aMutex); checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed); m_aUser.ChangePassword(objPassword,newPassword); - ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),*this); + ADOS::ThrowException(m_pCatalog->getConnection()->getConnection(),*this); } diff --git a/connectivity/source/drivers/ado/AUsers.cxx b/connectivity/source/drivers/ado/AUsers.cxx index 2620e915a89e..4b050d239237 100644 --- a/connectivity/source/drivers/ado/AUsers.cxx +++ b/connectivity/source/drivers/ado/AUsers.cxx @@ -27,6 +27,7 @@ #include <comphelper/servicehelper.hxx> #include <comphelper/types.hxx> #include <connectivity/dbexception.hxx> +#include <systools/win32/oleauto.hxx> #include <strings.hrc> using namespace comphelper; @@ -56,12 +57,12 @@ Reference< XPropertySet > OUsers::createDescriptor() // XAppend sdbcx::ObjectType OUsers::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) { - OUserExtend* pUser = getUnoTunnelImplementation<OUserExtend>( descriptor ); + OUserExtend* pUser = dynamic_cast<OUserExtend*>( descriptor.get() ); if ( pUser == nullptr ) m_pCatalog->getConnection()->throwGenericSQLException( STR_INVALID_USER_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) ); ADOUsers* pUsers = m_aCollection; - pUsers->Append(OLEVariant(pUser->getImpl()),OLEString(pUser->getPassword()).asBSTR()); + pUsers->Append(OLEVariant(pUser->getImpl()), sal::systools::BStr(pUser->getPassword())); return createObject( _rForName ); } diff --git a/connectivity/source/drivers/ado/AView.cxx b/connectivity/source/drivers/ado/AView.cxx index b53c1a026200..10a5524db95b 100644 --- a/connectivity/source/drivers/ado/AView.cxx +++ b/connectivity/source/drivers/ado/AView.cxx @@ -20,10 +20,11 @@ #include <ado/AView.hxx> #include <com/sun/star/lang/DisposedException.hpp> #include <ado/adoimp.hxx> -#include <cppuhelper/typeprovider.hxx> #include <ado/Awrapado.hxx> #include <comphelper/servicehelper.hxx> #include <comphelper/types.hxx> +#include <systools/win32/oleauto.hxx> + #include <TConnection.hxx> @@ -41,23 +42,6 @@ OAdoView::OAdoView(bool _bCase,ADOView* _pView) : OView_ADO(_bCase,nullptr) { } -Sequence< sal_Int8 > OAdoView::getUnoTunnelId() -{ - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); -} - -// css::lang::XUnoTunnel - -sal_Int64 OAdoView::getSomething( const Sequence< sal_Int8 > & rId ) -{ - return isUnoTunnelId<OAdoView>(rId) - ? reinterpret_cast< sal_Int64 >( this ) - : OView_ADO::getSomething(rId); -} - - void OAdoView::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const { if(m_aView.IsValid()) @@ -79,9 +63,9 @@ void OAdoView::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const if(!aVar.isNull() && !aVar.isEmpty()) { ADOCommand* pCom = static_cast<ADOCommand*>(aVar.getIDispatch()); - OLEString aBSTR; - pCom->get_CommandText(aBSTR.getAddress()); - rValue <<= aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pCom->get_CommandText(&aBSTR); + rValue <<= OUString(aBSTR); } } break; diff --git a/connectivity/source/drivers/ado/AViews.cxx b/connectivity/source/drivers/ado/AViews.cxx index 77cc5abfae0f..943422289627 100644 --- a/connectivity/source/drivers/ado/AViews.cxx +++ b/connectivity/source/drivers/ado/AViews.cxx @@ -27,6 +27,9 @@ #include <comphelper/servicehelper.hxx> #include <comphelper/types.hxx> #include <connectivity/dbexception.hxx> +#include <rtl/ref.hxx> +#include <systools/win32/oleauto.hxx> + #include <strings.hrc> using namespace ::comphelper; @@ -41,7 +44,7 @@ using namespace com::sun::star::container; sdbcx::ObjectType OViews::createObject(const OUString& _rName) { - OAdoView* pView = new OAdoView(isCaseSensitive(),m_aCollection.GetItem(_rName)); + rtl::Reference<OAdoView> pView = new OAdoView(isCaseSensitive(),m_aCollection.GetItem(_rName)); pView->setNew(false); return pView; } @@ -60,7 +63,7 @@ Reference< XPropertySet > OViews::createDescriptor() // XAppend sdbcx::ObjectType OViews::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) { - OAdoView* pView = getUnoTunnelImplementation<OAdoView>( descriptor ); + OAdoView* pView = dynamic_cast<OAdoView*>( descriptor.get() ); if ( pView == nullptr ) m_pCatalog->getConnection()->throwGenericSQLException( STR_INVALID_VIEW_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) ); @@ -73,8 +76,8 @@ sdbcx::ObjectType OViews::appendObject( const OUString& _rForName, const Referen aCommand.put_Name(sName); aCommand.put_CommandText(getString(descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND)))); ADOViews* pViews = m_aCollection; - if(FAILED(pViews->Append(OLEString(sName).asBSTR(),aCommand))) - ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),static_cast<XTypeProvider*>(this)); + if (FAILED(pViews->Append(sal::systools::BStr(sName), aCommand))) + ADOS::ThrowException(m_pCatalog->getConnection()->getConnection(),static_cast<XTypeProvider*>(this)); OTables* pTables = static_cast<OTables*>(static_cast<OCatalog&>(m_rParent).getPrivateTables()); if ( pTables ) @@ -87,7 +90,7 @@ sdbcx::ObjectType OViews::appendObject( const OUString& _rForName, const Referen void OViews::dropObject(sal_Int32 /*_nPos*/,const OUString& _sElementName) { if(!m_aCollection.Delete(_sElementName)) - ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),static_cast<XTypeProvider*>(this)); + ADOS::ThrowException(m_pCatalog->getConnection()->getConnection(),static_cast<XTypeProvider*>(this)); } diff --git a/connectivity/source/drivers/ado/Aolevariant.cxx b/connectivity/source/drivers/ado/Aolevariant.cxx index 7f740e81d7c2..c082c1987ff0 100644 --- a/connectivity/source/drivers/ado/Aolevariant.cxx +++ b/connectivity/source/drivers/ado/Aolevariant.cxx @@ -37,64 +37,6 @@ using namespace com::sun::star::uno; using namespace com::sun::star::bridge::oleautomation; using namespace connectivity::ado; -OLEString::OLEString() - :m_sStr(nullptr) -{ -} -OLEString::OLEString(const BSTR& _sBStr) - :m_sStr(_sBStr) -{ -} -OLEString::OLEString(const OUString& _sBStr) -{ - m_sStr = ::SysAllocString(o3tl::toW(_sBStr.getStr())); -} -OLEString::~OLEString() -{ - if(m_sStr) - ::SysFreeString(m_sStr); -} -OLEString& OLEString::operator=(const OUString& _rSrc) -{ - if(m_sStr) - ::SysFreeString(m_sStr); - m_sStr = ::SysAllocString(o3tl::toW(_rSrc.getStr())); - return *this; -} -OLEString& OLEString::operator=(const OLEString& _rSrc) -{ - if(this != &_rSrc) - { - if(m_sStr) - ::SysFreeString(m_sStr); - m_sStr = ::SysAllocString(_rSrc.m_sStr); - } - return *this; -} -OLEString& OLEString::operator=(const BSTR& _rSrc) -{ - if(m_sStr) - ::SysFreeString(m_sStr); - m_sStr = _rSrc; - return *this; -} -OUString OLEString::asOUString() const -{ - return (m_sStr != nullptr) ? OUString(o3tl::toU(LPCOLESTR(m_sStr)),::SysStringLen(m_sStr)) : OUString(); -} -BSTR OLEString::asBSTR() const -{ - return m_sStr; -} -BSTR* OLEString::getAddress() -{ - return &m_sStr; -} -sal_Int32 OLEString::length() const -{ - return (m_sStr != nullptr) ? ::SysStringLen(m_sStr) : 0; -} - OLEVariant::OLEVariant() { VariantInit(this); @@ -118,11 +60,11 @@ OLEVariant::OLEVariant(sal_Int16 n) { VariantInit(this); vt = VT_ OLEVariant::OLEVariant(sal_Int32 n) { VariantInit(this); vt = VT_I4; lVal = n;} OLEVariant::OLEVariant(sal_Int64 x) { VariantInit(this); vt = VT_I4; lVal = static_cast<LONG>(x);} -OLEVariant::OLEVariant(const OUString& us) +OLEVariant::OLEVariant(std::u16string_view us) { ::VariantInit(this); vt = VT_BSTR; - bstrVal = SysAllocString(o3tl::toW(us.getStr())); + bstrVal = SysAllocStringLen(o3tl::toW(us.data()), us.length()); } OLEVariant::~OLEVariant() { @@ -273,12 +215,12 @@ void OLEVariant::setBool(bool b) vt = VT_BOOL; boolVal = b ? VARIANT_TRUE : VARIANT_FALSE; } -void OLEVariant::setString(const OUString& us) +void OLEVariant::setString(std::u16string_view us) { HRESULT eRet = VariantClear(this); OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!"); vt = VT_BSTR; - bstrVal = ::SysAllocString(o3tl::toW(us.getStr())); + bstrVal = SysAllocStringLen(o3tl::toW(us.data()), us.length()); } void OLEVariant::setNoArg() { @@ -378,7 +320,7 @@ void OLEVariant::set(double n) OUString OLEVariant::getString() const { if (V_VT(this) == VT_BSTR) - return o3tl::toU(LPCOLESTR(V_BSTR(this))); + return OUString(o3tl::toU(V_BSTR(this))); if(isNull()) return OUString(); @@ -387,7 +329,7 @@ OUString OLEVariant::getString() const varDest.ChangeType(VT_BSTR, this); - return o3tl::toU(LPCOLESTR(V_BSTR(&varDest))); + return OUString(o3tl::toU(V_BSTR(&varDest))); } @@ -427,8 +369,8 @@ css::uno::Sequence< sal_Int8 > OLEVariant::getByteSequence() const css::uno::Sequence< sal_Int8 > aRet; if(V_VT(this) == VT_BSTR) { - OLEString sStr(V_BSTR(this)); - aRet = css::uno::Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(sStr.asBSTR()),sizeof(sal_Unicode)*sStr.length()); + aRet = css::uno::Sequence<sal_Int8>(reinterpret_cast<sal_Int8*>(V_BSTR(this)), + ::SysStringByteLen(V_BSTR(this))); } else if(!isNull()) { @@ -437,16 +379,16 @@ css::uno::Sequence< sal_Int8 > OLEVariant::getByteSequence() const if(pArray) { HRESULT hresult1,hresult2; - long lBound,uBound; + LONG lBound,uBound; // Verify that the SafeArray is the proper shape. hresult1 = ::SafeArrayGetLBound(pArray, 1, &lBound); hresult2 = ::SafeArrayGetUBound(pArray, 1, &uBound); if ( SUCCEEDED(hresult1) && SUCCEEDED(hresult2) ) { - long nCount = uBound-lBound+1; + LONG nCount = uBound-lBound+1; aRet.realloc(nCount); sal_Int8* pData = aRet.getArray(); - for(long i=0; SUCCEEDED(hresult1) && lBound <= uBound ;++i,++lBound) + for(; SUCCEEDED(hresult1) && lBound <= uBound ;++lBound) { sal_Int32 nData = 0; hresult1 = ::SafeArrayGetElement(pArray,&lBound,&nData); diff --git a/connectivity/source/drivers/ado/Aservices.cxx b/connectivity/source/drivers/ado/Aservices.cxx deleted file mode 100644 index 0ec3ba953fbe..000000000000 --- a/connectivity/source/drivers/ado/Aservices.cxx +++ /dev/null @@ -1,105 +0,0 @@ -/* -*- 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 . - */ - -#include <ado/ADriver.hxx> -#include <cppuhelper/factory.hxx> -#include <com/sun/star/lang/XSingleServiceFactory.hpp> - -using namespace connectivity::ado; -using ::com::sun::star::uno::Reference; -using ::com::sun::star::uno::Sequence; -using ::com::sun::star::lang::XSingleServiceFactory; -using ::com::sun::star::lang::XMultiServiceFactory; - -typedef Reference< XSingleServiceFactory > (*createFactoryFunc) - ( - const Reference< XMultiServiceFactory > & rServiceManager, - const OUString & rComponentName, - ::cppu::ComponentInstantiation pCreateFunction, - const Sequence< OUString > & rServiceNames , - rtl_ModuleCount* - ); - -namespace { - -struct ProviderRequest -{ - Reference< XSingleServiceFactory > xRet; - Reference< XMultiServiceFactory > const xServiceManager; - OUString const sImplementationName; - - ProviderRequest( - void* pServiceManager, - char const* pImplementationName - ) - : xServiceManager(static_cast<XMultiServiceFactory*>(pServiceManager)) - , sImplementationName(OUString::createFromAscii(pImplementationName)) - { - } - - bool CREATE_PROVIDER( - const OUString& Implname, - const Sequence< OUString > & Services, - ::cppu::ComponentInstantiation Factory, - createFactoryFunc creator - ) - { - if (!xRet.is() && (Implname == sImplementationName)) - try - { - xRet = creator( xServiceManager, sImplementationName,Factory, Services,nullptr); - } - catch(...) - { - } - return xRet.is(); - } - - void* getProvider() const { return xRet.get(); } -}; - -} - -extern "C" SAL_DLLPUBLIC_EXPORT void* ado_component_getFactory( - const char* pImplementationName, - void* pServiceManager, - void* /*pRegistryKey*/) -{ - void* pRet = nullptr; - if (pServiceManager) - { - ProviderRequest aReq(pServiceManager,pImplementationName); - - aReq.CREATE_PROVIDER( - ODriver::getImplementationName_Static(), - ODriver::getSupportedServiceNames_Static(), - ODriver_CreateInstance, ::cppu::createSingleFactory) - ; - - if(aReq.xRet.is()) - aReq.xRet->acquire(); - - pRet = aReq.getProvider(); - } - - return pRet; -}; - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/ado/Awrapado.cxx b/connectivity/source/drivers/ado/Awrapado.cxx index 1fc664f89a5a..eebdc5d8c5a7 100644 --- a/connectivity/source/drivers/ado/Awrapado.cxx +++ b/connectivity/source/drivers/ado/Awrapado.cxx @@ -21,48 +21,39 @@ #include <ado/Awrapado.hxx> #include <ado/Awrapadox.hxx> #include <comphelper/types.hxx> +#include <o3tl/string_view.hxx> #include <rtl/ustrbuf.hxx> #include <sal/log.hxx> +#include <systools/win32/oleauto.hxx> using namespace connectivity::ado; void WpADOCatalog::Create() { - _ADOCatalog* pCommand; - HRESULT hr = CoCreateInstance(ADOS::CLSID_ADOCATALOG_25, - nullptr, - CLSCTX_INPROC_SERVER, - ADOS::IID_ADOCATALOG_25, - reinterpret_cast<void**>(&pCommand) ); - - - if( !FAILED( hr ) ) - setWithOutAddRef(pCommand); + pInterface.CoCreateInstance(ADOS::CLSID_ADOCATALOG_25, nullptr, CLSCTX_INPROC_SERVER); } WpADOProperties WpADOConnection::get_Properties() const { - ADOProperties* pProps=nullptr; + WpADOProperties pProps; pInterface->get_Properties(&pProps); - WpADOProperties aProps; - aProps.setWithOutAddRef(pProps); - return aProps; + return pProps; } OUString WpADOConnection::GetConnectionString() const { assert(pInterface); - OLEString aBSTR; - pInterface->get_ConnectionString(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pInterface->get_ConnectionString(&aBSTR); + return OUString(aBSTR); } -bool WpADOConnection::PutConnectionString(const OUString &aCon) const +bool WpADOConnection::PutConnectionString(std::u16string_view aCon) const { assert(pInterface); - OLEString bstr(aCon); - bool bErg = SUCCEEDED(pInterface->put_ConnectionString(bstr.asBSTR())); + sal::systools::BStr bstr(aCon); + bool bErg = SUCCEEDED(pInterface->put_ConnectionString(bstr)); return bErg; } @@ -101,11 +92,11 @@ bool WpADOConnection::Close() return (SUCCEEDED(pInterface->Close())); } -bool WpADOConnection::Execute(const OUString& CommandText,OLEVariant& RecordsAffected,long Options, WpADORecordset** ppiRset) +bool WpADOConnection::Execute(std::u16string_view CommandText,OLEVariant& RecordsAffected,long Options, WpADORecordset** ppiRset) { assert(pInterface); - OLEString sStr1(CommandText); - bool bErg = SUCCEEDED(pInterface->Execute(sStr1.asBSTR(),&RecordsAffected,Options,reinterpret_cast<ADORecordset**>(ppiRset))); + sal::systools::BStr sStr1(CommandText); + bool bErg = SUCCEEDED(pInterface->Execute(sStr1,&RecordsAffected,Options,reinterpret_cast<ADORecordset**>(ppiRset))); return bErg; } @@ -128,13 +119,13 @@ bool WpADOConnection::RollbackTrans( ) return SUCCEEDED(pInterface->RollbackTrans()); } -bool WpADOConnection::Open(const OUString& ConnectionString, const OUString& UserID,const OUString& Password,long Options) +bool WpADOConnection::Open(std::u16string_view ConnectionString, std::u16string_view UserID,std::u16string_view Password,long Options) { assert(pInterface); - OLEString sStr1(ConnectionString); - OLEString sStr2(UserID); - OLEString sStr3(Password); - bool bErg = SUCCEEDED(pInterface->Open(sStr1.asBSTR(),sStr2.asBSTR(),sStr3.asBSTR(),Options)); + sal::systools::BStr sStr1(ConnectionString); + sal::systools::BStr sStr2(UserID); + sal::systools::BStr sStr3(Password); + bool bErg = SUCCEEDED(pInterface->Open(sStr1, sStr2, sStr3, Options)); return bErg; } @@ -147,15 +138,15 @@ bool WpADOConnection::GetErrors(ADOErrors** pErrors) OUString WpADOConnection::GetDefaultDatabase() const { assert(pInterface); - OLEString aBSTR; pInterface->get_DefaultDatabase(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; pInterface->get_DefaultDatabase(&aBSTR); + return OUString(aBSTR); } -bool WpADOConnection::PutDefaultDatabase(const OUString& _bstr) +bool WpADOConnection::PutDefaultDatabase(std::u16string_view _bstr) { assert(pInterface); - OLEString bstr(_bstr); - bool bErg = SUCCEEDED(pInterface->put_DefaultDatabase(bstr.asBSTR())); + sal::systools::BStr bstr(_bstr); + bool bErg = SUCCEEDED(pInterface->put_DefaultDatabase(bstr)); return bErg; } @@ -219,15 +210,15 @@ bool WpADOConnection::put_Mode(const ConnectModeEnum &eNum) OUString WpADOConnection::get_Provider() const { assert(pInterface); - OLEString aBSTR; pInterface->get_Provider(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; pInterface->get_Provider(&aBSTR); + return OUString(aBSTR); } -bool WpADOConnection::put_Provider(const OUString& _bstr) +bool WpADOConnection::put_Provider(std::u16string_view _bstr) { assert(pInterface); - OLEString bstr(_bstr); - return SUCCEEDED(pInterface->put_Provider(bstr.asBSTR())); + sal::systools::BStr bstr(_bstr); + return SUCCEEDED(pInterface->put_Provider(bstr)); } sal_Int32 WpADOConnection::get_State() const @@ -247,18 +238,15 @@ bool WpADOConnection::OpenSchema(SchemaEnum eNum,OLEVariant const & Restrictions OUString WpADOConnection::get_Version() const { assert(pInterface); - OLEString aBSTR; - pInterface->get_Version(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pInterface->get_Version(&aBSTR); + return OUString(aBSTR); } -bool WpADOCommand::putref_ActiveConnection( WpADOConnection *pCon) +bool WpADOCommand::putref_ActiveConnection(const WpADOConnection& rCon) { assert(pInterface); - if(pCon) - return SUCCEEDED(pInterface->putref_ActiveConnection(pCon->pInterface)); - else - return SUCCEEDED(pInterface->putref_ActiveConnection(nullptr)); + return SUCCEEDED(pInterface->putref_ActiveConnection(rCon)); } void WpADOCommand::put_ActiveConnection(/* [in] */ const OLEVariant& vConn) @@ -269,31 +257,19 @@ void WpADOCommand::put_ActiveConnection(/* [in] */ const OLEVariant& vConn) void WpADOCommand::Create() { - IClassFactory2* pInterface2 = nullptr; - HRESULT hr = CoGetClassObject( ADOS::CLSID_ADOCOMMAND_21, - CLSCTX_INPROC_SERVER, - nullptr, - IID_IClassFactory2, - reinterpret_cast<void**>(&pInterface2) ); - - if( !FAILED( hr ) ) + sal::systools::COMReference<IClassFactory2> pInterface2; + if (!FAILED(pInterface2.CoGetClassObject(ADOS::CLSID_ADOCOMMAND_21, CLSCTX_INPROC_SERVER))) { - ADOCommand* pCommand=nullptr; - IUnknown* pOuter=nullptr; + sal::systools::COMReference<ADOCommand> pCommand; - hr = pInterface2->CreateInstanceLic( pOuter, + HRESULT hr = pInterface2->CreateInstanceLic(nullptr, nullptr, ADOS::IID_ADOCOMMAND_21, - ADOS::GetKeyStr().asBSTR(), + ADOS::GetKeyStr(), reinterpret_cast<void**>(&pCommand)); if( !FAILED( hr ) ) - { - operator=(pCommand); - pCommand->Release(); - } - - pInterface2->Release(); + pInterface = std::move(pCommand); } } @@ -308,16 +284,16 @@ sal_Int32 WpADOCommand::get_State() const OUString WpADOCommand::get_CommandText() const { assert(pInterface); - OLEString aBSTR; - pInterface->get_CommandText(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pInterface->get_CommandText(&aBSTR); + return OUString(aBSTR); } -bool WpADOCommand::put_CommandText(const OUString &aCon) +bool WpADOCommand::put_CommandText(std::u16string_view aCon) { assert(pInterface); - OLEString bstr(aCon); - bool bErg = SUCCEEDED(pInterface->put_CommandText(bstr.asBSTR())); + sal::systools::BStr bstr(aCon); + bool bErg = SUCCEEDED(pInterface->put_CommandText(bstr)); return bErg; } @@ -356,12 +332,12 @@ bool WpADOCommand::Execute(OLEVariant& RecordsAffected,OLEVariant& Params,long O return SUCCEEDED(pInterface->Execute(&RecordsAffected,&Params,Options,ppiRset)); } -ADOParameter* WpADOCommand::CreateParameter(const OUString &_bstr,DataTypeEnum Type,ParameterDirectionEnum Direction,long nSize,const OLEVariant &Value) +ADOParameter* WpADOCommand::CreateParameter(std::u16string_view _bstr,DataTypeEnum Type,ParameterDirectionEnum Direction,long nSize,const OLEVariant &Value) { assert(pInterface); ADOParameter* pPara = nullptr; - OLEString bstr(_bstr); - bool bErg = SUCCEEDED(pInterface->CreateParameter(bstr.asBSTR(),Type,Direction,nSize,Value,&pPara)); + sal::systools::BStr bstr(_bstr); + bool bErg = SUCCEEDED(pInterface->CreateParameter(bstr, Type, Direction, nSize, Value, &pPara)); return bErg ? pPara : nullptr; } @@ -392,16 +368,16 @@ CommandTypeEnum WpADOCommand::get_CommandType() const OUString WpADOCommand::GetName() const { assert(pInterface); - OLEString aBSTR; - pInterface->get_Name(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pInterface->get_Name(&aBSTR); + return OUString(aBSTR); } -bool WpADOCommand::put_Name(const OUString& Name) +bool WpADOCommand::put_Name(std::u16string_view Name) { assert(pInterface); - OLEString bstr(Name); - bool bErg = SUCCEEDED(pInterface->put_Name(bstr.asBSTR())); + sal::systools::BStr bstr(Name); + bool bErg = SUCCEEDED(pInterface->put_Name(bstr)); return bErg; } @@ -414,17 +390,17 @@ bool WpADOCommand::Cancel() OUString WpADOError::GetDescription() const { assert(pInterface); - OLEString aBSTR; - pInterface->get_Description(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pInterface->get_Description(&aBSTR); + return OUString(aBSTR); } OUString WpADOError::GetSource() const { assert(pInterface); - OLEString aBSTR; - pInterface->get_Source(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pInterface->get_Source(&aBSTR); + return OUString(aBSTR); } sal_Int32 WpADOError::GetNumber() const @@ -438,9 +414,9 @@ sal_Int32 WpADOError::GetNumber() const OUString WpADOError::GetSQLState() const { assert(pInterface); - OLEString aBSTR; - pInterface->get_SQLState(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pInterface->get_SQLState(&aBSTR); + return OUString(aBSTR); } sal_Int32 WpADOError::GetNativeError() const @@ -454,12 +430,9 @@ sal_Int32 WpADOError::GetNativeError() const WpADOProperties WpADOField::get_Properties() { assert(pInterface); - ADOProperties* pProps = nullptr; + WpADOProperties pProps; pInterface->get_Properties(&pProps); - WpADOProperties aProps; - - aProps.setWithOutAddRef(pProps); - return aProps; + return pProps; } sal_Int32 WpADOField::GetActualSize() const @@ -497,9 +470,9 @@ sal_Int32 WpADOField::GetDefinedSize() const OUString WpADOField::GetName() const { assert(pInterface); - OLEString aBSTR; - pInterface->get_Name(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pInterface->get_Name(&aBSTR); + return OUString(aBSTR); } DataTypeEnum WpADOField::GetADOType() const @@ -649,9 +622,9 @@ bool WpADOProperty::PutValue(const OLEVariant &aValVar) OUString WpADOProperty::GetName() const { assert(pInterface); - OLEString aBSTR; - pInterface->get_Name(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pInterface->get_Name(&aBSTR); + return OUString(aBSTR); } DataTypeEnum WpADOProperty::GetADOType() const @@ -677,30 +650,18 @@ bool WpADOProperty::PutAttributes(sal_Int32 _nDefSize) } void WpADORecordset::Create() { - IClassFactory2* pInterface2 = nullptr; - HRESULT hr = CoGetClassObject( ADOS::CLSID_ADORECORDSET_21, - CLSCTX_INPROC_SERVER, - nullptr, - IID_IClassFactory2, - reinterpret_cast<void**>(&pInterface2) ); - - if( !FAILED( hr ) ) + sal::systools::COMReference<IClassFactory2> pInterface2; + if (!FAILED(pInterface2.CoGetClassObject(ADOS::CLSID_ADORECORDSET_21, CLSCTX_INPROC_SERVER))) { - ADORecordset *pRec = nullptr; - IUnknown *pOuter = nullptr; - hr = pInterface2->CreateInstanceLic( pOuter, + sal::systools::COMReference<ADORecordset> pRec; + HRESULT hr = pInterface2->CreateInstanceLic(nullptr, nullptr, ADOS::IID_ADORECORDSET_21, - ADOS::GetKeyStr().asBSTR(), + ADOS::GetKeyStr(), reinterpret_cast<void**>(&pRec)); if( !FAILED( hr ) ) - { - operator=(pRec); - pRec->Release(); - } - - pInterface2->Release(); + pInterface = std::move(pRec); } } @@ -804,11 +765,9 @@ bool WpADORecordset::SetBookmark(const OLEVariant &pSafeAr) WpADOFields WpADORecordset::GetFields() const { assert(pInterface); - ADOFields* pFields=nullptr; + WpADOFields pFields; pInterface->get_Fields(&pFields); - WpADOFields aFields; - aFields.setWithOutAddRef(pFields); - return aFields; + return pFields; } @@ -861,11 +820,9 @@ bool WpADORecordset::CancelUpdate() WpADOProperties WpADORecordset::get_Properties() const { assert(pInterface); - ADOProperties* pProps=nullptr; + WpADOProperties pProps; pInterface->get_Properties(&pProps); - WpADOProperties aProps; - aProps.setWithOutAddRef(pProps); - return aProps; + return pProps; } bool WpADORecordset::NextRecordset(OLEVariant& RecordsAffected,ADORecordset** ppiRset) @@ -937,9 +894,9 @@ bool WpADORecordset::UpdateBatch(AffectEnum AffectRecords) OUString WpADOParameter::GetName() const { assert(pInterface); - OLEString aBSTR; - pInterface->get_Name(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pInterface->get_Name(&aBSTR); + return OUString(aBSTR); } DataTypeEnum WpADOParameter::GetADOType() const @@ -1021,30 +978,30 @@ bool WpADOParameter::put_Size(sal_Int32 _nSize) OUString WpADOColumn::get_Name() const { assert(pInterface); - OLEString aBSTR; - pInterface->get_Name(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pInterface->get_Name(&aBSTR); + return OUString(aBSTR); } OUString WpADOColumn::get_RelatedColumn() const { assert(pInterface); - OLEString aBSTR; - pInterface->get_RelatedColumn(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pInterface->get_RelatedColumn(&aBSTR); + return OUString(aBSTR); } -void WpADOColumn::put_Name(const OUString& _rName) +void WpADOColumn::put_Name(std::u16string_view _rName) { assert(pInterface); - OLEString bstr(_rName); - pInterface->put_Name(bstr.asBSTR()); + sal::systools::BStr bstr(_rName); + pInterface->put_Name(bstr); } -void WpADOColumn::put_RelatedColumn(const OUString& _rName) +void WpADOColumn::put_RelatedColumn(std::u16string_view _rName) { assert(pInterface); - OLEString bstr(_rName); - pInterface->put_RelatedColumn(bstr.asBSTR()); + sal::systools::BStr bstr(_rName); + pInterface->put_RelatedColumn(bstr); } DataTypeEnum WpADOColumn::get_Type() const @@ -1127,27 +1084,24 @@ bool WpADOColumn::put_Attributes(const ColumnAttributesEnum& _eNum) WpADOProperties WpADOColumn::get_Properties() const { assert(pInterface); - ADOProperties* pProps = nullptr; + WpADOProperties pProps; pInterface->get_Properties(&pProps); - WpADOProperties aProps; - - aProps.setWithOutAddRef(pProps); - return aProps; + return pProps; } OUString WpADOKey::get_Name() const { assert(pInterface); - OLEString aBSTR; - pInterface->get_Name(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pInterface->get_Name(&aBSTR); + return OUString(aBSTR); } -void WpADOKey::put_Name(const OUString& _rName) +void WpADOKey::put_Name(std::u16string_view _rName) { assert(pInterface); - OLEString bstr(_rName); - pInterface->put_Name(bstr.asBSTR()); + sal::systools::BStr bstr(_rName); + pInterface->put_Name(bstr); } KeyTypeEnum WpADOKey::get_Type() const @@ -1167,16 +1121,16 @@ void WpADOKey::put_Type(const KeyTypeEnum& _eNum) OUString WpADOKey::get_RelatedTable() const { assert(pInterface); - OLEString aBSTR; - pInterface->get_RelatedTable(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pInterface->get_RelatedTable(&aBSTR); + return OUString(aBSTR); } -void WpADOKey::put_RelatedTable(const OUString& _rName) +void WpADOKey::put_RelatedTable(std::u16string_view _rName) { assert(pInterface); - OLEString bstr(_rName); - pInterface->put_RelatedTable(bstr.asBSTR()); + sal::systools::BStr bstr(_rName); + pInterface->put_RelatedTable(bstr); } RuleEnum WpADOKey::get_DeleteRule() const @@ -1210,26 +1164,24 @@ void WpADOKey::put_UpdateRule(const RuleEnum& _eNum) WpADOColumns WpADOKey::get_Columns() const { assert(pInterface); - ADOColumns* pCols = nullptr; + WpADOColumns pCols; pInterface->get_Columns(&pCols); - WpADOColumns aCols; - aCols.setWithOutAddRef(pCols); - return aCols; + return pCols; } OUString WpADOIndex::get_Name() const { assert(pInterface); - OLEString aBSTR; - pInterface->get_Name(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pInterface->get_Name(&aBSTR); + return OUString(aBSTR); } -void WpADOIndex::put_Name(const OUString& _rName) +void WpADOIndex::put_Name(std::u16string_view _rName) { assert(pInterface); - OLEString bstr(_rName); - pInterface->put_Name(bstr.asBSTR()); + sal::systools::BStr bstr(_rName); + pInterface->put_Name(bstr); } bool WpADOIndex::get_Clustered() const @@ -1277,11 +1229,9 @@ void WpADOIndex::put_PrimaryKey(bool _b) WpADOColumns WpADOIndex::get_Columns() const { assert(pInterface); - ADOColumns* pCols = nullptr; + WpADOColumns pCols; pInterface->get_Columns(&pCols); - WpADOColumns aCols; - aCols.setWithOutAddRef(pCols); - return aCols; + return pCols; } void WpADOCatalog::putref_ActiveConnection(IDispatch* pCon) @@ -1293,41 +1243,33 @@ void WpADOCatalog::putref_ActiveConnection(IDispatch* pCon) WpADOTables WpADOCatalog::get_Tables() { assert(pInterface); - ADOTables* pRet = nullptr; + WpADOTables pRet; pInterface->get_Tables(&pRet); - WpADOTables aRet; - aRet.setWithOutAddRef(pRet); - return aRet; + return pRet; } WpADOViews WpADOCatalog::get_Views() { assert(pInterface); - ADOViews* pRet = nullptr; + WpADOViews pRet; pInterface->get_Views(&pRet); - WpADOViews aRet; - aRet.setWithOutAddRef(pRet); - return aRet; + return pRet; } WpADOGroups WpADOCatalog::get_Groups() { assert(pInterface); - ADOGroups* pRet = nullptr; + WpADOGroups pRet; pInterface->get_Groups(&pRet); - WpADOGroups aRet; - aRet.setWithOutAddRef(pRet); - return aRet; + return pRet; } WpADOUsers WpADOCatalog::get_Users() { assert(pInterface); - ADOUsers* pRet = nullptr; + WpADOUsers pRet; pInterface->get_Users(&pRet); - WpADOUsers aRet; - aRet.setWithOutAddRef(pRet); - return aRet; + return pRet; } ADOProcedures* WpADOCatalog::get_Procedures() @@ -1341,82 +1283,72 @@ ADOProcedures* WpADOCatalog::get_Procedures() OUString WpADOTable::get_Name() const { assert(pInterface); - OLEString aBSTR; - pInterface->get_Name(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pInterface->get_Name(&aBSTR); + return OUString(aBSTR); } -void WpADOTable::put_Name(const OUString& _rName) +void WpADOTable::put_Name(std::u16string_view _rName) { assert(pInterface); - OLEString bstr(_rName); - pInterface->put_Name(bstr.asBSTR()); + sal::systools::BStr bstr(_rName); + pInterface->put_Name(bstr); } OUString WpADOTable::get_Type() const { assert(pInterface); - OLEString aBSTR; - pInterface->get_Type(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pInterface->get_Type(&aBSTR); + return OUString(aBSTR); } WpADOColumns WpADOTable::get_Columns() const { assert(pInterface); - ADOColumns* pCols = nullptr; + WpADOColumns pCols; pInterface->get_Columns(&pCols); - WpADOColumns aCols; - aCols.setWithOutAddRef(pCols); - return aCols; + return pCols; } WpADOIndexes WpADOTable::get_Indexes() const { assert(pInterface); - ADOIndexes* pCols = nullptr; - pInterface->get_Indexes(&pCols); - WpADOIndexes aRet; - aRet.setWithOutAddRef(pCols); - return aRet; + WpADOIndexes pRet; + pInterface->get_Indexes(&pRet); + return pRet; } WpADOKeys WpADOTable::get_Keys() const { assert(pInterface); - ADOKeys* pCols = nullptr; - pInterface->get_Keys(&pCols); - WpADOKeys aRet; - aRet.setWithOutAddRef(pCols); - return aRet; + WpADOKeys pRet; + pInterface->get_Keys(&pRet); + return pRet; } WpADOCatalog WpADOTable::get_ParentCatalog() const { assert(pInterface); - ADOCatalog* pCat = nullptr; + WpADOCatalog pCat; pInterface->get_ParentCatalog(&pCat); - WpADOCatalog aRet; - aRet.setWithOutAddRef(pCat); - return aRet; + return pCat; } WpADOProperties WpADOTable::get_Properties() const { assert(pInterface); - ADOProperties* pProps = nullptr; + WpADOProperties pProps; pInterface->get_Properties(&pProps); - WpADOProperties aProps; - aProps.setWithOutAddRef(pProps); - return aProps; + return pProps; } OUString WpADOView::get_Name() const { assert(pInterface); - OLEString aBSTR; - pInterface->get_Name(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pInterface->get_Name(&aBSTR); + return OUString(aBSTR); } void WpADOView::get_Command(OLEVariant& _rVar) const @@ -1433,15 +1365,15 @@ void WpADOView::put_Command(OLEVariant const & _rVar) OUString WpADOGroup::get_Name() const { - OLEString aBSTR; - pInterface->get_Name(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pInterface->get_Name(&aBSTR); + return OUString(aBSTR); } -void WpADOGroup::put_Name(const OUString& _rName) +void WpADOGroup::put_Name(std::u16string_view _rName) { - OLEString bstr(_rName); - pInterface->put_Name(bstr.asBSTR()); + sal::systools::BStr bstr(_rName); + pInterface->put_Name(bstr); } RightsEnum WpADOGroup::GetPermissions( @@ -1468,41 +1400,37 @@ bool WpADOGroup::SetPermissions( WpADOUsers WpADOGroup::get_Users( ) { - ADOUsers* pRet = nullptr; + WpADOUsers pRet; pInterface->get_Users( &pRet); - WpADOUsers aRet; - aRet.setWithOutAddRef(pRet); - return aRet; + return pRet; } OUString WpADOUser::get_Name() const { - OLEString aBSTR; - pInterface->get_Name(aBSTR.getAddress()); - return aBSTR.asOUString(); + sal::systools::BStr aBSTR; + pInterface->get_Name(&aBSTR); + return OUString(aBSTR); } -void WpADOUser::put_Name(const OUString& _rName) +void WpADOUser::put_Name(std::u16string_view _rName) { - OLEString bstr(_rName); - pInterface->put_Name(bstr.asBSTR()); + sal::systools::BStr bstr(_rName); + pInterface->put_Name(bstr); } -bool WpADOUser::ChangePassword(const OUString& _rPwd,const OUString& _rNewPwd) +bool WpADOUser::ChangePassword(std::u16string_view _rPwd,std::u16string_view _rNewPwd) { - OLEString sStr1(_rPwd); - OLEString sStr2(_rNewPwd); - bool bErg = SUCCEEDED(pInterface->ChangePassword(sStr1.asBSTR(),sStr2.asBSTR())); + sal::systools::BStr sStr1(_rPwd); + sal::systools::BStr sStr2(_rNewPwd); + bool bErg = SUCCEEDED(pInterface->ChangePassword(sStr1, sStr2)); return bErg; } WpADOGroups WpADOUser::get_Groups() { - ADOGroups* pRet = nullptr; + WpADOGroups pRet; pInterface->get_Groups(&pRet); - WpADOGroups aRet; - aRet.setWithOutAddRef(pRet); - return aRet; + return pRet; } RightsEnum WpADOUser::GetPermissions( @@ -1527,74 +1455,7 @@ bool WpADOUser::SetPermissions( return SUCCEEDED(pInterface->SetPermissions(Name,ObjectType,Action,Rights,adInheritNone,ObjectTypeId)); } -WpBase::WpBase() : pIUnknown(nullptr) -{ -} -WpBase::WpBase(IDispatch* pInt) - :pIUnknown(pInt) -{ - if (pIUnknown) - { - pIUnknown->AddRef(); - } -} - -WpBase::WpBase(const WpBase& aWrapper) - :pIUnknown(aWrapper.pIUnknown) -{ - if (pIUnknown) - pIUnknown->AddRef(); -} - -//inline -WpBase& WpBase::operator=(const WpBase& rhs) -{ - operator=(rhs.pIUnknown); - return *this; -}; - -WpBase& WpBase::operator=(IDispatch* rhs) -{ - if (pIUnknown != rhs) - { - if (pIUnknown) - pIUnknown->Release(); - pIUnknown = rhs; - if (pIUnknown) - pIUnknown->AddRef(); - } - return *this; -} - -WpBase::~WpBase() -{ - if (pIUnknown) - { - pIUnknown->Release(); - pIUnknown = nullptr; - } -} - -void WpBase::clear() -{ - if (pIUnknown) - { - pIUnknown->Release(); - pIUnknown = nullptr; - } -} - - -bool WpBase::IsValid() const -{ - return pIUnknown != nullptr; -} -WpBase::operator IDispatch*() -{ - return pIUnknown; -} - -ADORecordset* WpADOConnection::getExportedKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) +ADORecordset* WpADOConnection::getExportedKeys( const css::uno::Any& catalog, const OUString& schema, std::u16string_view table ) { // Create elements used in the array SAFEARRAYBOUND rgsabound[1]; @@ -1603,7 +1464,7 @@ ADORecordset* WpADOConnection::getExportedKeys( const css::uno::Any& catalog, co // Create SafeArray Bounds and initialize the array rgsabound[0].lLbound = 0; - rgsabound[0].cElements = SAL_N_ELEMENTS(varCriteria); + rgsabound[0].cElements = std::size(varCriteria); psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); sal_Int32 nPos=0; @@ -1634,7 +1495,7 @@ ADORecordset* WpADOConnection::getExportedKeys( const css::uno::Any& catalog, co return pRecordset; } -ADORecordset* WpADOConnection::getImportedKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) +ADORecordset* WpADOConnection::getImportedKeys( const css::uno::Any& catalog, const OUString& schema, std::u16string_view table ) { // Create elements used in the array SAFEARRAYBOUND rgsabound[1]; @@ -1643,7 +1504,7 @@ ADORecordset* WpADOConnection::getImportedKeys( const css::uno::Any& catalog, co // Create SafeArray Bounds and initialize the array rgsabound[0].lLbound = 0; - rgsabound[0].cElements = SAL_N_ELEMENTS(varCriteria); + rgsabound[0].cElements = std::size(varCriteria); psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); sal_Int32 nPos=0; @@ -1676,7 +1537,7 @@ ADORecordset* WpADOConnection::getImportedKeys( const css::uno::Any& catalog, co } -ADORecordset* WpADOConnection::getPrimaryKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) +ADORecordset* WpADOConnection::getPrimaryKeys( const css::uno::Any& catalog, const OUString& schema, std::u16string_view table ) { // Create elements used in the array SAFEARRAYBOUND rgsabound[1]; @@ -1685,7 +1546,7 @@ ADORecordset* WpADOConnection::getPrimaryKeys( const css::uno::Any& catalog, con // Create SafeArray Bounds and initialize the array rgsabound[0].lLbound = 0; - rgsabound[0].cElements = SAL_N_ELEMENTS(varCriteria); + rgsabound[0].cElements = std::size(varCriteria); psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); sal_Int32 nPos=0; @@ -1715,7 +1576,7 @@ ADORecordset* WpADOConnection::getPrimaryKeys( const css::uno::Any& catalog, con } ADORecordset* WpADOConnection::getIndexInfo( - const css::uno::Any& catalog, const OUString& schema, const OUString& table, + const css::uno::Any& catalog, const OUString& schema, std::u16string_view table, bool /*unique*/, bool /*approximate*/ ) { // Create elements used in the array @@ -1725,7 +1586,7 @@ ADORecordset* WpADOConnection::getIndexInfo( // Create SafeArray Bounds and initialize the array rgsabound[0].lLbound = 0; - rgsabound[0].cElements = SAL_N_ELEMENTS(varCriteria); + rgsabound[0].cElements = std::size(varCriteria); psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); sal_Int32 nPos=0; @@ -1759,7 +1620,7 @@ ADORecordset* WpADOConnection::getIndexInfo( ADORecordset* WpADOConnection::getTablePrivileges( const css::uno::Any& catalog, const OUString& schemaPattern, - const OUString& tableNamePattern ) + std::u16string_view tableNamePattern ) { SAFEARRAYBOUND rgsabound[1]; SAFEARRAY *psa = nullptr; @@ -1767,7 +1628,7 @@ ADORecordset* WpADOConnection::getTablePrivileges( const css::uno::Any& catalog, // Create SafeArray Bounds and initialize the array rgsabound[0].lLbound = 0; - rgsabound[0].cElements = SAL_N_ELEMENTS(varCriteria); + rgsabound[0].cElements = std::size(varCriteria); psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); sal_Int32 nPos=0; @@ -1779,7 +1640,7 @@ ADORecordset* WpADOConnection::getTablePrivileges( const css::uno::Any& catalog, varCriteria[nPos].setString(schemaPattern); SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_SCHEMA - if(tableNamePattern.toChar() != '%') + if(!o3tl::starts_with(tableNamePattern, u"%")) varCriteria[nPos].setString(tableNamePattern); SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_NAME @@ -1801,10 +1662,10 @@ ADORecordset* WpADOConnection::getTablePrivileges( const css::uno::Any& catalog, ADORecordset* WpADOConnection::getCrossReference( const css::uno::Any& primaryCatalog, const OUString& primarySchema, - const OUString& primaryTable, + std::u16string_view primaryTable, const css::uno::Any& foreignCatalog, const OUString& foreignSchema, - const OUString& foreignTable) + std::u16string_view foreignTable) { // Create elements used in the array SAFEARRAYBOUND rgsabound[1]; @@ -1813,7 +1674,7 @@ ADORecordset* WpADOConnection::getCrossReference( const css::uno::Any& primaryCa // Create SafeArray Bounds and initialize the array rgsabound[0].lLbound = 0; - rgsabound[0].cElements = SAL_N_ELEMENTS(varCriteria); + rgsabound[0].cElements = std::size(varCriteria); psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); sal_Int32 nPos=0; @@ -1854,7 +1715,7 @@ ADORecordset* WpADOConnection::getCrossReference( const css::uno::Any& primaryCa ADORecordset* WpADOConnection::getProcedures( const css::uno::Any& catalog, const OUString& schemaPattern, - const OUString& procedureNamePattern ) + std::u16string_view procedureNamePattern ) { SAFEARRAYBOUND rgsabound[1]; SAFEARRAY *psa = nullptr; @@ -1862,7 +1723,7 @@ ADORecordset* WpADOConnection::getProcedures( const css::uno::Any& catalog, // Create SafeArray Bounds and initialize the array rgsabound[0].lLbound = 0; - rgsabound[0].cElements = SAL_N_ELEMENTS(varCriteria); + rgsabound[0].cElements = std::size(varCriteria); psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); sal_Int32 nPos=0; @@ -1874,7 +1735,7 @@ ADORecordset* WpADOConnection::getProcedures( const css::uno::Any& catalog, varCriteria[nPos].setString(schemaPattern); SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_SCHEMA - if(procedureNamePattern.toChar() != '%') + if(!o3tl::starts_with(procedureNamePattern, u"%")) varCriteria[nPos].setString(procedureNamePattern); SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_NAME @@ -1893,8 +1754,8 @@ ADORecordset* WpADOConnection::getProcedures( const css::uno::Any& catalog, ADORecordset* WpADOConnection::getProcedureColumns( const css::uno::Any& catalog, const OUString& schemaPattern, - const OUString& procedureNamePattern, - const OUString& columnNamePattern ) + std::u16string_view procedureNamePattern, + std::u16string_view columnNamePattern ) { // Create elements used in the array SAFEARRAYBOUND rgsabound[1]; @@ -1903,7 +1764,7 @@ ADORecordset* WpADOConnection::getProcedureColumns( const css::uno::Any& catalog // Create SafeArray Bounds and initialize the array rgsabound[0].lLbound = 0; - rgsabound[0].cElements = SAL_N_ELEMENTS(varCriteria); + rgsabound[0].cElements = std::size(varCriteria); psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); sal_Int32 nPos=0; @@ -1915,11 +1776,11 @@ ADORecordset* WpADOConnection::getProcedureColumns( const css::uno::Any& catalog varCriteria[nPos].setString(schemaPattern); SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_SCHEMA - if(procedureNamePattern.toChar() != '%') + if(!o3tl::starts_with(procedureNamePattern, u"%")) varCriteria[nPos].setString(procedureNamePattern); SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_NAME - if(columnNamePattern.toChar() != '%') + if(!o3tl::starts_with(columnNamePattern, u"%")) varCriteria[nPos].setString(columnNamePattern); SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// COLUMN_NAME @@ -1938,7 +1799,7 @@ ADORecordset* WpADOConnection::getProcedureColumns( const css::uno::Any& catalog ADORecordset* WpADOConnection::getTables( const css::uno::Any& catalog, const OUString& schemaPattern, - const OUString& tableNamePattern, + std::u16string_view tableNamePattern, const css::uno::Sequence< OUString >& types ) { // Create elements used in the array @@ -1955,7 +1816,7 @@ ADORecordset* WpADOConnection::getTables( const css::uno::Any& catalog, varCriteria[nPos].setString(schemaPattern); ++nPos; - if(tableNamePattern.toChar() != '%') + if(!o3tl::starts_with(tableNamePattern, u"%")) varCriteria[nPos].setString(tableNamePattern); ++nPos; @@ -1974,14 +1835,14 @@ ADORecordset* WpADOConnection::getTables( const css::uno::Any& catalog, varCriteria[nPos].setString(sTypeNames); // Create SafeArray Bounds and initialize the array - const sal_Int32 nCrit = SAL_N_ELEMENTS(varCriteria); + const sal_Int32 nCrit = std::size(varCriteria); SAFEARRAYBOUND rgsabound[1]; rgsabound[0].lLbound = 0; rgsabound[0].cElements = nCrit; SAFEARRAY *psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); // Set the values for each element of the array - for( long i = 0 ; i < nCrit && SUCCEEDED( hr );i++) + for( LONG i = 0 ; i < nCrit && SUCCEEDED( hr );i++) { hr = SafeArrayPutElement(psa, &i,&varCriteria[i]); } @@ -2001,8 +1862,8 @@ ADORecordset* WpADOConnection::getTables( const css::uno::Any& catalog, ADORecordset* WpADOConnection::getColumns( const css::uno::Any& catalog, const OUString& schemaPattern, - const OUString& tableNamePattern, - const OUString& columnNamePattern ) + std::u16string_view tableNamePattern, + std::u16string_view columnNamePattern ) { // Create elements used in the array SAFEARRAYBOUND rgsabound[1]; @@ -2011,7 +1872,7 @@ ADORecordset* WpADOConnection::getColumns( const css::uno::Any& catalog, // Create SafeArray Bounds and initialize the array rgsabound[0].lLbound = 0; - rgsabound[0].cElements = SAL_N_ELEMENTS(varCriteria); + rgsabound[0].cElements = std::size(varCriteria); psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); sal_Int32 nPos=0; @@ -2023,7 +1884,7 @@ ADORecordset* WpADOConnection::getColumns( const css::uno::Any& catalog, varCriteria[nPos].setString(schemaPattern); SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_SCHEMA - if(tableNamePattern.toChar() != '%') + if(!o3tl::starts_with(tableNamePattern, u"%")) varCriteria[nPos].setString(tableNamePattern); SafeArrayPutElement(psa,&nPos,&varCriteria[nPos]);nPos++;// TABLE_NAME @@ -2045,8 +1906,8 @@ ADORecordset* WpADOConnection::getColumns( const css::uno::Any& catalog, ADORecordset* WpADOConnection::getColumnPrivileges( const css::uno::Any& catalog, const OUString& schema, - const OUString& table, - const OUString& columnNamePattern ) + std::u16string_view table, + std::u16string_view columnNamePattern ) { // Create elements used in the array SAFEARRAYBOUND rgsabound[1]; @@ -2055,7 +1916,7 @@ ADORecordset* WpADOConnection::getColumnPrivileges( const css::uno::Any& catalog // Create SafeArray Bounds and initialize the array rgsabound[0].lLbound = 0; - rgsabound[0].cElements = SAL_N_ELEMENTS(varCriteria); + rgsabound[0].cElements = std::size(varCriteria); psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound ); sal_Int32 nPos=0; @@ -2090,7 +1951,7 @@ ADORecordset* WpADOConnection::getTypeInfo(DataTypeEnum /*_eType*/) { // Create elements used in the array OLEVariant varCriteria[2]; - const int nCrit = SAL_N_ELEMENTS(varCriteria); + const int nCrit = std::size(varCriteria); // Create SafeArray Bounds and initialize the array SAFEARRAYBOUND rgsabound[1]; rgsabound[0].lLbound = 0; @@ -2128,11 +1989,6 @@ void WpADOTable::putref_ParentCatalog(/* [in] */ _ADOCatalog __RPC_FAR *ppvObjec SAL_WARN_IF(!bRet, "connectivity.ado", "Could not set ParentCatalog!"); } -void WpBase::setIDispatch(IDispatch* _pIUnknown) -{ - pIUnknown = _pIUnknown; -} - void OTools::putValue(const WpADOProperties& _rProps,const OLEVariant &_aPosition,const OLEVariant &_aValVar) { SAL_WARN_IF(!_rProps.IsValid(), "connectivity.ado", "Properties are not valid!"); diff --git a/connectivity/source/drivers/ado/ado.component b/connectivity/source/drivers/ado/ado.component index b90673ae8644..7c97fb2d8533 100644 --- a/connectivity/source/drivers/ado/ado.component +++ b/connectivity/source/drivers/ado/ado.component @@ -17,10 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> -<component loader="com.sun.star.loader.SharedLibrary" - environment="@CPPU_ENV@:affine" prefix="ado" +<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@:affine" xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="com.sun.star.comp.sdbc.ado.ODriver"> + <implementation name="com.sun.star.comp.sdbc.ado.ODriver" + constructor="connectivity_ado_ODriver_get_implementation"> <service name="com.sun.star.sdbc.Driver"/> <service name="com.sun.star.sdbcx.Driver"/> </implementation> diff --git a/connectivity/source/drivers/ado/adoimp.cxx b/connectivity/source/drivers/ado/adoimp.cxx index 1e368d8ddec9..0f0d022681ea 100644 --- a/connectivity/source/drivers/ado/adoimp.cxx +++ b/connectivity/source/drivers/ado/adoimp.cxx @@ -23,6 +23,7 @@ #include <ado/Awrapado.hxx> #include <ado/adoimp.hxx> #include <osl/diagnose.h> +#include <systools/win32/oleauto.hxx> #include <com/sun/star/sdbc/DataType.hpp> @@ -67,9 +68,9 @@ const IID ADOS::IID_ADOUSER_25 = MYADOID(0x00000619); const CLSID ADOS::CLSID_ADOVIEW_25 = MYADOID(0x00000612); const IID ADOS::IID_ADOVIEW_25 = MYADOID(0x00000613); -OLEString& ADOS::GetKeyStr() +sal::systools::BStr& ADOS::GetKeyStr() { - static OLEString sKeyStr(OUString("gxwaezucfyqpwjgqbcmtsncuhwsnyhiohwxz")); + static sal::systools::BStr sKeyStr(u"gxwaezucfyqpwjgqbcmtsncuhwsnyhiohwxz"); return sKeyStr; } @@ -310,9 +311,8 @@ WpADOField ADOS::getField(ADORecordset* _pRecordSet,sal_Int32 _nColumnIndex) if ( !_pRecordSet ) return WpADOField(); - ADOFields* pFields = nullptr; - _pRecordSet->get_Fields(&pFields); - WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(pFields); + WpOLEAppendCollection<ADOFields, WpADOField> aFields; + _pRecordSet->get_Fields(&aFields); if(_nColumnIndex <= 0 || _nColumnIndex > aFields.GetItemCount()) ::dbtools::throwInvalidIndexException(nullptr); WpADOField aField(aFields.GetItem(_nColumnIndex-1)); diff --git a/connectivity/source/drivers/calc/CCatalog.cxx b/connectivity/source/drivers/calc/CCatalog.cxx index 6853a5f9dbc3..3a8493ac290a 100644 --- a/connectivity/source/drivers/calc/CCatalog.cxx +++ b/connectivity/source/drivers/calc/CCatalog.cxx @@ -24,41 +24,38 @@ #include <com/sun/star/sdbc/XResultSet.hpp> using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; - using namespace connectivity::calc; -OCalcCatalog::OCalcCatalog(OCalcConnection* _pCon) : file::OFileCatalog(_pCon) +OCalcCatalog::OCalcCatalog(OCalcConnection* _pCon) + : file::OFileCatalog(_pCon) { } void OCalcCatalog::refreshTables() { - ::std::vector< OUString> aVector; - Sequence< OUString > aTypes; + ::std::vector<OUString> aVector; + Sequence<OUString> aTypes; OCalcConnection::ODocHolder aDocHolder(static_cast<OCalcConnection*>(m_pConnection)); - Reference< XResultSet > xResult = m_xMetaData->getTables(Any(), - "%", "%", aTypes); + Reference<XResultSet> xResult = m_xMetaData->getTables(Any(), "%", "%", aTypes); - if(xResult.is()) + if (xResult.is()) { - Reference< XRow > xRow(xResult,UNO_QUERY); - while(xResult->next()) + Reference<XRow> xRow(xResult, UNO_QUERY); + while (xResult->next()) aVector.push_back(xRow->getString(3)); } - if(m_pTables) + if (m_pTables) m_pTables->reFill(aVector); else - m_pTables.reset( new OCalcTables(m_xMetaData,*this,m_aMutex,aVector) ); + m_pTables.reset(new OCalcTables(m_xMetaData, *this, m_aMutex, aVector)); // this avoids that the document will be loaded a 2nd time when one table will be accessed. //if ( m_pTables && m_pTables->hasElements() ) // m_pTables->getByIndex(0); } - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/calc/CConnection.cxx b/connectivity/source/drivers/calc/CConnection.cxx index 9b03d473bda1..5dc725e70ed9 100644 --- a/connectivity/source/drivers/calc/CConnection.cxx +++ b/connectivity/source/drivers/calc/CConnection.cxx @@ -62,9 +62,9 @@ void OCalcConnection::construct(const OUString& url,const Sequence< PropertyValu sal_Int32 nLen = url.indexOf(':'); nLen = url.indexOf(':',nLen+1); - OUString aDSN(url.copy(nLen+1)); - m_aFileName = aDSN; + m_aFileName = url.copy(nLen+1); // DSN + INetURLObject aURL; aURL.SetSmartProtocol(INetProtocol::File); { @@ -104,18 +104,17 @@ Reference< XSpreadsheetDocument> const & OCalcConnection::acquireDoc() return m_xDoc; } // open read-only as long as updating isn't implemented - Sequence<PropertyValue> aArgs(2); - aArgs[0].Name = "Hidden"; - aArgs[0].Value <<= true; - aArgs[1].Name = "ReadOnly"; - aArgs[1].Value <<= true; + Sequence<PropertyValue> aArgs(m_sPassword.isEmpty() ? 2 : 3); + auto pArgs = aArgs.getArray(); + pArgs[0].Name = "Hidden"; + pArgs[0].Value <<= true; + pArgs[1].Name = "ReadOnly"; + pArgs[1].Value <<= true; if ( !m_sPassword.isEmpty() ) { - const sal_Int32 nPos = aArgs.getLength(); - aArgs.realloc(nPos+1); - aArgs[nPos].Name = "Password"; - aArgs[nPos].Value <<= m_sPassword; + pArgs[2].Name = "Password"; + pArgs[2].Value <<= m_sPassword; } Reference< XDesktop2 > xDesktop = Desktop::create( getDriver()->getComponentContext() ); @@ -143,12 +142,11 @@ Reference< XSpreadsheetDocument> const & OCalcConnection::acquireDoc() Exception aLoaderError; OSL_VERIFY( aLoaderException >>= aLoaderError ); - SQLException aDetailException; - aDetailException.Message = m_aResources.getResourceStringWithSubstitution( - STR_LOAD_FILE_ERROR_MESSAGE, - "$exception_type$", aLoaderException.getValueTypeName(), - "$error_message$", aLoaderError.Message - ); + SQLException aDetailException(m_aResources.getResourceStringWithSubstitution( + STR_LOAD_FILE_ERROR_MESSAGE, "$exception_type$", + aLoaderException.getValueTypeName(), + "$error_message$", aLoaderError.Message), + {}, {}, 0, {}); aErrorDetails <<= aDetailException; } @@ -221,8 +219,7 @@ css::uno::Reference< XTablesSupplier > OCalcConnection::createCatalog() Reference< XTablesSupplier > xTab = m_xCatalog; if(!xTab.is()) { - OCalcCatalog *pCat = new OCalcCatalog(this); - xTab = pCat; + xTab = new OCalcCatalog(this); m_xCatalog = xTab; } return xTab; @@ -247,8 +244,7 @@ Reference< XPreparedStatement > SAL_CALL OCalcConnection::prepareStatement( cons checkDisposed(OConnection_BASE::rBHelper.bDisposed); - auto pStmt = new connectivity::component::OComponentPreparedStatement(this); - Reference< XPreparedStatement > xHoldAlive = pStmt; + rtl::Reference<connectivity::component::OComponentPreparedStatement> pStmt = new connectivity::component::OComponentPreparedStatement(this); pStmt->construct(sql); m_aStatements.push_back(WeakReferenceHelper(*pStmt)); return pStmt; diff --git a/connectivity/source/drivers/calc/CDatabaseMetaData.cxx b/connectivity/source/drivers/calc/CDatabaseMetaData.cxx index cea1b32c7a94..aad5b4e50193 100644 --- a/connectivity/source/drivers/calc/CDatabaseMetaData.cxx +++ b/connectivity/source/drivers/calc/CDatabaseMetaData.cxx @@ -34,7 +34,6 @@ using namespace connectivity::file; using namespace connectivity::component; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; using namespace ::com::sun::star::table; @@ -59,37 +58,37 @@ static bool lcl_IsEmptyOrHidden( const Reference<XSpreadsheets>& xSheets, const { Any aAny = xSheets->getByName( rName ); Reference<XSpreadsheet> xSheet; - if ( aAny >>= xSheet ) + if ( !(aAny >>= xSheet) ) + return false; + + // test if sheet is hidden + + Reference<XPropertySet> xProp( xSheet, UNO_QUERY ); + if (xProp.is()) { - // test if sheet is hidden + bool bVisible; + Any aVisAny = xProp->getPropertyValue("IsVisible"); + if ( (aVisAny >>= bVisible) && !bVisible) + return true; // hidden + } - Reference<XPropertySet> xProp( xSheet, UNO_QUERY ); - if (xProp.is()) - { - bool bVisible; - Any aVisAny = xProp->getPropertyValue("IsVisible"); - if ( (aVisAny >>= bVisible) && !bVisible) - return true; // hidden - } + // use the same data area as in OCalcTable to test for empty table - // use the same data area as in OCalcTable to test for empty table + Reference<XSheetCellCursor> xCursor = xSheet->createCursor(); + Reference<XCellRangeAddressable> xRange( xCursor, UNO_QUERY ); + if ( xRange.is() ) + { + xCursor->collapseToSize( 1, 1 ); // single (first) cell + xCursor->collapseToCurrentRegion(); // contiguous data area - Reference<XSheetCellCursor> xCursor = xSheet->createCursor(); - Reference<XCellRangeAddressable> xRange( xCursor, UNO_QUERY ); - if ( xRange.is() ) + CellRangeAddress aRangeAddr = xRange->getRangeAddress(); + if ( aRangeAddr.StartColumn == aRangeAddr.EndColumn && + aRangeAddr.StartRow == aRangeAddr.EndRow ) { - xCursor->collapseToSize( 1, 1 ); // single (first) cell - xCursor->collapseToCurrentRegion(); // contiguous data area - - CellRangeAddress aRangeAddr = xRange->getRangeAddress(); - if ( aRangeAddr.StartColumn == aRangeAddr.EndColumn && - aRangeAddr.StartRow == aRangeAddr.EndRow ) - { - // single cell -> check content - Reference<XCell> xCell = xCursor->getCellByPosition( 0, 0 ); - if ( xCell.is() && xCell->getType() == CellContentType_EMPTY ) - return true; - } + // single cell -> check content + Reference<XCell> xCell = xCursor->getCellByPosition( 0, 0 ); + if ( xCell.is() && xCell->getType() == CellContentType_EMPTY ) + return true; } } @@ -130,8 +129,7 @@ Reference< XResultSet > SAL_CALL OCalcDatabaseMetaData::getTables( { ::osl::MutexGuard aGuard( m_aMutex ); - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTables); - Reference< XResultSet > xRef = pResult; + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTables); // check if ORowSetValue type is given // when no types are given then we have to return all tables e.g. TABLE @@ -156,7 +154,7 @@ Reference< XResultSet > SAL_CALL OCalcDatabaseMetaData::getTables( } } if(!bTableFound) - return xRef; + return pResult; // get the sheet names from the document @@ -176,12 +174,11 @@ Reference< XResultSet > SAL_CALL OCalcDatabaseMetaData::getTables( OUString aName = aSheetNames[nSheet]; if ( !lcl_IsEmptyOrHidden( xSheets, aName ) && match(tableNamePattern,aName,'\0') ) { - ODatabaseMetaDataResultSet::ORow aRow { nullptr, nullptr, nullptr }; - aRow.reserve(6); - aRow.push_back(new ORowSetValueDecorator(aName)); - aRow.push_back(new ORowSetValueDecorator(aTable)); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRows.push_back(aRow); + aRows.push_back( { nullptr, nullptr, nullptr, + new ORowSetValueDecorator(aName), + new ORowSetValueDecorator(aTable), + ODatabaseMetaDataResultSet::getEmptyValue() + } ); } } @@ -201,20 +198,19 @@ Reference< XResultSet > SAL_CALL OCalcDatabaseMetaData::getTables( OUString aName = aDBNames[nRange]; if ( !lcl_IsUnnamed( xRanges, aName ) && match(tableNamePattern,aName,'\0') ) { - ODatabaseMetaDataResultSet::ORow aRow { nullptr, nullptr, nullptr }; - aRow.reserve(6); - aRow.push_back(new ORowSetValueDecorator(aName)); - aRow.push_back(new ORowSetValueDecorator(aTable)); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRows.push_back(aRow); + aRows.push_back( { nullptr, nullptr, nullptr, + new ORowSetValueDecorator(aName), + new ORowSetValueDecorator(aTable), + ODatabaseMetaDataResultSet::getEmptyValue() + } ); } } } } - pResult->setRows(aRows); + pResult->setRows(std::move(aRows)); - return xRef; + return pResult; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/calc/CDriver.cxx b/connectivity/source/drivers/calc/CDriver.cxx index 5a59515bb2d6..eccf97751c8f 100644 --- a/connectivity/source/drivers/calc/CDriver.cxx +++ b/connectivity/source/drivers/calc/CDriver.cxx @@ -22,7 +22,6 @@ #include <com/sun/star/lang/DisposedException.hpp> #include <connectivity/dbexception.hxx> #include <resource/sharedresources.hxx> -#include <comphelper/processfactory.hxx> #include <strings.hrc> using namespace connectivity::calc; @@ -54,7 +53,7 @@ connectivity_calc_ODriver( } if (ret) ret->acquire(); - return static_cast<cppu::OWeakObject*>(ret.get()); + return getXWeak(ret.get()); } @@ -69,12 +68,11 @@ Reference< XConnection > SAL_CALL ODriver::connect( const OUString& url, if ( ! acceptsURL(url) ) return nullptr; - OCalcConnection* pCon = new OCalcConnection(this); + rtl::Reference<OCalcConnection> pCon = new OCalcConnection(this); pCon->construct(url,info); - Reference< XConnection > xCon = pCon; m_xConnections.push_back(WeakReferenceHelper(*pCon)); - return xCon; + return pCon; } sal_Bool SAL_CALL ODriver::acceptsURL( const OUString& url ) diff --git a/connectivity/source/drivers/calc/CTable.cxx b/connectivity/source/drivers/calc/CTable.cxx index 045ea54190ac..879a2902d00c 100644 --- a/connectivity/source/drivers/calc/CTable.cxx +++ b/connectivity/source/drivers/calc/CTable.cxx @@ -41,7 +41,6 @@ #include <rtl/math.hxx> #include <tools/time.hxx> #include <comphelper/servicehelper.hxx> -#include <cppuhelper/typeprovider.hxx> using namespace connectivity; using namespace connectivity::calc; @@ -50,10 +49,8 @@ using namespace ::cppu; using namespace ::dbtools; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; using namespace ::com::sun::star::sheet; using namespace ::com::sun::star::table; using namespace ::com::sun::star::text; @@ -192,24 +189,23 @@ static bool lcl_HasTextInColumn( const Reference<XSpreadsheet>& xSheet, sal_Int3 // look for any text cell or text result in the column Reference<XCellRangeAddressable> xAddr( xSheet, UNO_QUERY ); - if (xAddr.is()) - { - CellRangeAddress aTotalRange = xAddr->getRangeAddress(); - sal_Int32 nLastRow = aTotalRange.EndRow; - Reference<XCellRangesQuery> xQuery( xSheet->getCellRangeByPosition( nDocColumn, nDocRow, nDocColumn, nLastRow ), UNO_QUERY ); - if (xQuery.is()) - { - // are there text cells in the column? - Reference<XSheetCellRanges> xTextContent = xQuery->queryContentCells( CellFlags::STRING ); - if ( xTextContent.is() && xTextContent->hasElements() ) - return true; - - // are there formulas with text results in the column? - Reference<XSheetCellRanges> xTextFormula = xQuery->queryFormulaCells( FormulaResult::STRING ); - if ( xTextFormula.is() && xTextFormula->hasElements() ) - return true; - } - } + if (!xAddr) + return false; + CellRangeAddress aTotalRange = xAddr->getRangeAddress(); + sal_Int32 nLastRow = aTotalRange.EndRow; + Reference<XCellRangesQuery> xQuery( xSheet->getCellRangeByPosition( nDocColumn, nDocRow, nDocColumn, nLastRow ), UNO_QUERY ); + if (!xQuery) + return false; + + // are there text cells in the column? + Reference<XSheetCellRanges> xTextContent = xQuery->queryContentCells( CellFlags::STRING ); + if ( xTextContent.is() && xTextContent->hasElements() ) + return true; + + // are there formulas with text results in the column? + Reference<XSheetCellRanges> xTextFormula = xQuery->queryFormulaCells( FormulaResult::STRING ); + if ( xTextFormula.is() && xTextFormula->hasElements() ) + return true; return false; } @@ -377,7 +373,7 @@ static void lcl_SetValue( ORowSetValue& rValue, const Reference<XSpreadsheet>& x double fCellVal = xCell->getValue(); double fDays = ::rtl::math::approxFloor( fCellVal ); double fTime = fCellVal - fDays; - long nIntDays = static_cast<long>(fDays); + tools::Long nIntDays = static_cast<tools::Long>(fDays); sal_Int64 nIntTime = ::rtl::math::round( fTime * static_cast<double>(::tools::Time::nanoSecPerDay) ); if ( nIntTime == ::tools::Time::nanoSecPerDay ) { @@ -486,13 +482,12 @@ void OCalcTable::fillColumns() aFind = connectivity::find(m_aColumns->begin(),m_aColumns->end(),aAlias,aCase); } - sdbcx::OColumn* pColumn = new sdbcx::OColumn( aAlias, aTypeName, OUString(),OUString(), + rtl::Reference<sdbcx::OColumn> pColumn = new sdbcx::OColumn( aAlias, aTypeName, OUString(),OUString(), ColumnValue::NULLABLE, nPrecision, nDecimals, eType, false, false, bCurrency, bStoresMixedCaseQuotedIdentifiers, m_CatalogName, getSchema(), getName()); - Reference< XPropertySet> xCol = pColumn; - m_aColumns->push_back(xCol); + m_aColumns->push_back(pColumn); m_aTypes.push_back(eType); } } @@ -611,22 +606,6 @@ void SAL_CALL OCalcTable::disposing() } -Sequence< sal_Int8 > OCalcTable::getUnoTunnelId() -{ - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); -} - -// css::lang::XUnoTunnel - -sal_Int64 OCalcTable::getSomething( const Sequence< sal_Int8 > & rId ) -{ - return (isUnoTunnelId<OCalcTable>(rId)) - ? reinterpret_cast< sal_Int64 >( this ) - : OCalcTable_BASE::getSomething(rId); -} - bool OCalcTable::fetchRow( OValueRefRow& _rRow, const OSQLColumns & _rCols, bool bRetrieveData ) { diff --git a/connectivity/source/drivers/calc/CTables.cxx b/connectivity/source/drivers/calc/CTables.cxx index 703ab27120c5..1f626f7b10d0 100644 --- a/connectivity/source/drivers/calc/CTables.cxx +++ b/connectivity/source/drivers/calc/CTables.cxx @@ -25,24 +25,18 @@ #include <file/FCatalog.hxx> #include <file/FConnection.hxx> -using namespace ::comphelper; using namespace connectivity; using namespace connectivity::calc; using namespace connectivity::file; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; -using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::lang; using namespace ::com::sun::star::container; sdbcx::ObjectType OCalcTables::createObject(const OUString& _rName) { - OCalcTable* pTable = new OCalcTable(this, static_cast<OCalcConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()), + rtl::Reference<OCalcTable> pTable = new OCalcTable(this, static_cast<OCalcConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()), _rName,"TABLE"); - sdbcx::ObjectType xRet = pTable; pTable->construct(); - return xRet; + return pTable; } diff --git a/connectivity/source/drivers/component/CColumns.cxx b/connectivity/source/drivers/component/CColumns.cxx index 9f802b6e4c57..7726d3a326d0 100644 --- a/connectivity/source/drivers/component/CColumns.cxx +++ b/connectivity/source/drivers/component/CColumns.cxx @@ -23,10 +23,6 @@ using namespace connectivity::component; using namespace connectivity; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdbcx; -using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; sdbcx::ObjectType OComponentColumns::createObject(const OUString& _rName) diff --git a/connectivity/source/drivers/component/CDatabaseMetaData.cxx b/connectivity/source/drivers/component/CDatabaseMetaData.cxx index f225747a6486..49d83e36af12 100644 --- a/connectivity/source/drivers/component/CDatabaseMetaData.cxx +++ b/connectivity/source/drivers/component/CDatabaseMetaData.cxx @@ -46,80 +46,72 @@ OComponentDatabaseMetaData::~OComponentDatabaseMetaData() Reference< XResultSet > OComponentDatabaseMetaData::impl_getTypeInfo_throw( ) { - ::osl::MutexGuard aGuard( m_aMutex ); - - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo); - Reference< XResultSet > xRef = pResult; + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo); - static ODatabaseMetaDataResultSet::ORows aRows; - if(aRows.empty()) + ODatabaseMetaDataResultSet::ORows aRows; + aRows.reserve(6); + ODatabaseMetaDataResultSet::ORow aRow { - ODatabaseMetaDataResultSet::ORow aRow; - - aRows.reserve(6); - aRow.reserve(18); - - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(new ORowSetValueDecorator(OUString("VARCHAR"))); - aRow.push_back(new ORowSetValueDecorator(DataType::VARCHAR)); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(65535))); - aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue()); - aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); // ORowSetValue((sal_Int32)ColumnValue::NULLABLE) - aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(ColumnSearch::CHAR))); - aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(10))); - - - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("DECIMAL")); - aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL); - aRow[3] = ODatabaseMetaDataResultSet::get0Value(); - aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); - aRow[15] = ODatabaseMetaDataResultSet::get0Value(); - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("BOOL")); - aRow[2] = new ORowSetValueDecorator(DataType::BIT); - aRow[3] = new ORowSetValueDecorator(sal_Int32(20)); - aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); - aRow[15] = new ORowSetValueDecorator(sal_Int32(15)); - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("DATE")); - aRow[2] = new ORowSetValueDecorator(DataType::DATE); - aRow[3] = ODatabaseMetaDataResultSet::get0Value(); - aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); - aRow[15] = ODatabaseMetaDataResultSet::get0Value(); - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("TIME")); - aRow[2] = new ORowSetValueDecorator(DataType::TIME); - aRow[3] = ODatabaseMetaDataResultSet::get0Value(); - aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); - aRow[15] = ODatabaseMetaDataResultSet::get0Value(); - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("TIMESTAMP")); - aRow[2] = new ORowSetValueDecorator(DataType::TIMESTAMP); - aRow[3] = ODatabaseMetaDataResultSet::get0Value(); - aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); - aRow[15] = ODatabaseMetaDataResultSet::get0Value(); - aRows.push_back(aRow); - } - - pResult->setRows(aRows); - return xRef; + ODatabaseMetaDataResultSet::getEmptyValue(), + new ORowSetValueDecorator(OUString("VARCHAR")), + new ORowSetValueDecorator(DataType::VARCHAR), + new ORowSetValueDecorator(sal_Int32(65535)), + ODatabaseMetaDataResultSet::getQuoteValue(), + ODatabaseMetaDataResultSet::getQuoteValue(), + ODatabaseMetaDataResultSet::getEmptyValue(), + ODatabaseMetaDataResultSet::get1Value(), // ORowSetValue((sal_Int32)ColumnValue::NULLABLE + ODatabaseMetaDataResultSet::get1Value(), + new ORowSetValueDecorator(sal_Int32(ColumnSearch::CHAR)), + ODatabaseMetaDataResultSet::get1Value(), + ODatabaseMetaDataResultSet::get0Value(), + ODatabaseMetaDataResultSet::get0Value(), + ODatabaseMetaDataResultSet::getEmptyValue(), + ODatabaseMetaDataResultSet::get0Value(), + ODatabaseMetaDataResultSet::get0Value(), + ODatabaseMetaDataResultSet::getEmptyValue(), + ODatabaseMetaDataResultSet::getEmptyValue(), + new ORowSetValueDecorator(sal_Int32(10)) + }; + + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(OUString("DECIMAL")); + aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL); + aRow[3] = ODatabaseMetaDataResultSet::get0Value(); + aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); + aRow[15] = ODatabaseMetaDataResultSet::get0Value(); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(OUString("BOOL")); + aRow[2] = new ORowSetValueDecorator(DataType::BIT); + aRow[3] = new ORowSetValueDecorator(sal_Int32(20)); + aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); + aRow[15] = new ORowSetValueDecorator(sal_Int32(15)); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(OUString("DATE")); + aRow[2] = new ORowSetValueDecorator(DataType::DATE); + aRow[3] = ODatabaseMetaDataResultSet::get0Value(); + aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); + aRow[15] = ODatabaseMetaDataResultSet::get0Value(); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(OUString("TIME")); + aRow[2] = new ORowSetValueDecorator(DataType::TIME); + aRow[3] = ODatabaseMetaDataResultSet::get0Value(); + aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); + aRow[15] = ODatabaseMetaDataResultSet::get0Value(); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(OUString("TIMESTAMP")); + aRow[2] = new ORowSetValueDecorator(DataType::TIMESTAMP); + aRow[3] = ODatabaseMetaDataResultSet::get0Value(); + aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); + aRow[15] = ODatabaseMetaDataResultSet::get0Value(); + aRows.push_back(aRow); + + pResult->setRows(std::move(aRows)); + return pResult; } Reference< XResultSet > SAL_CALL OComponentDatabaseMetaData::getColumns( @@ -179,7 +171,7 @@ Reference< XResultSet > SAL_CALL OComponentDatabaseMetaData::getColumns( aRow[13] = new ORowSetValueDecorator(::comphelper::getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)))); // aRow[14] = xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)); // aRow[15] = xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)); - switch(sal_Int32(aRow[5]->getValue())) + switch(aRow[5]->getValue().getInt32()) { case DataType::CHAR: case DataType::VARCHAR: @@ -192,7 +184,7 @@ Reference< XResultSet > SAL_CALL OComponentDatabaseMetaData::getColumns( aRow[16] = new ORowSetValueDecorator(sal_Int32(0)); } aRow[17] = new ORowSetValueDecorator(i); - switch(sal_Int32(aRow[11]->getValue())) + switch(aRow[11]->getValue().getInt32()) { case ColumnValue::NO_NULLS: aRow[18] = new ORowSetValueDecorator(OUString("NO")); @@ -209,11 +201,10 @@ Reference< XResultSet > SAL_CALL OComponentDatabaseMetaData::getColumns( } } - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns); - Reference< XResultSet > xRef = pResult; - pResult->setRows(aRows); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns); + pResult->setRows(std::move(aRows)); - return xRef; + return pResult; } sal_Int32 SAL_CALL OComponentDatabaseMetaData::getMaxBinaryLiteralLength( ) diff --git a/connectivity/source/drivers/component/CPreparedStatement.cxx b/connectivity/source/drivers/component/CPreparedStatement.cxx index bc3af3e8c9b8..82935cbd747d 100644 --- a/connectivity/source/drivers/component/CPreparedStatement.cxx +++ b/connectivity/source/drivers/component/CPreparedStatement.cxx @@ -22,9 +22,8 @@ using namespace connectivity::component; using namespace connectivity::file; -using namespace com::sun::star::uno; -OResultSet* OComponentPreparedStatement::createResultSet() +rtl::Reference<OResultSet> OComponentPreparedStatement::createResultSet() { return new connectivity::component::OComponentResultSet(this,m_aSQLIterator); } diff --git a/connectivity/source/drivers/component/CResultSet.cxx b/connectivity/source/drivers/component/CResultSet.cxx index 050b4034da45..08e6e04aca70 100644 --- a/connectivity/source/drivers/component/CResultSet.cxx +++ b/connectivity/source/drivers/component/CResultSet.cxx @@ -77,7 +77,7 @@ Any SAL_CALL OComponentResultSet::getBookmark( ) checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - return makeAny(static_cast<sal_Int32>((*m_aRow)[0]->getValue())); + return Any((*m_aRow)[0]->getValue().getInt32()); } sal_Bool SAL_CALL OComponentResultSet::moveToBookmark( const Any& bookmark ) @@ -153,12 +153,12 @@ bool OComponentResultSet::fillIndexValues(const Reference< XColumnsSupplier> &/* } -void SAL_CALL OComponentResultSet::acquire() throw() +void SAL_CALL OComponentResultSet::acquire() noexcept { OComponentResultSet_BASE2::acquire(); } -void SAL_CALL OComponentResultSet::release() throw() +void SAL_CALL OComponentResultSet::release() noexcept { OComponentResultSet_BASE2::release(); } diff --git a/connectivity/source/drivers/component/CStatement.cxx b/connectivity/source/drivers/component/CStatement.cxx index 8adfefae83f4..ff072ab5f548 100644 --- a/connectivity/source/drivers/component/CStatement.cxx +++ b/connectivity/source/drivers/component/CStatement.cxx @@ -22,13 +22,13 @@ using namespace connectivity::component; using namespace connectivity::file; -using namespace com::sun::star::uno; -OResultSet* OComponentStatement::createResultSet() +rtl::Reference<OResultSet> OComponentStatement::createResultSet() { - return new connectivity::component::OComponentResultSet(this,m_aSQLIterator); + return new connectivity::component::OComponentResultSet(this, m_aSQLIterator); } -IMPLEMENT_SERVICE_INFO(OComponentStatement,"com.sun.star.sdbc.driver.component.Statement","com.sun.star.sdbc.Statement"); +IMPLEMENT_SERVICE_INFO(OComponentStatement, "com.sun.star.sdbc.driver.component.Statement", + "com.sun.star.sdbc.Statement"); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/component/CTable.cxx b/connectivity/source/drivers/component/CTable.cxx index 9b5354d266d1..1fe32c339faa 100644 --- a/connectivity/source/drivers/component/CTable.cxx +++ b/connectivity/source/drivers/component/CTable.cxx @@ -25,7 +25,6 @@ using namespace connectivity; using namespace connectivity::component; using namespace connectivity::file; using namespace ::cppu; -using namespace ::dbtools; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; @@ -33,7 +32,6 @@ using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::sheet; -using namespace ::com::sun::star::util; OComponentTable::OComponentTable(sdbcx::OCollection* _pTables,file::OConnection* _pConnection, @@ -63,7 +61,7 @@ void OComponentTable::refreshColumns() if(m_xColumns) m_xColumns->reFill(aVector); else - m_xColumns = new component::OComponentColumns(this,m_aMutex,aVector); + m_xColumns.reset(new component::OComponentColumns(this,m_aMutex,aVector)); } void OComponentTable::refreshIndexes() @@ -104,8 +102,7 @@ Any SAL_CALL OComponentTable::queryInterface( const Type & rType ) rType == cppu::UnoType<XDataDescriptorFactory>::get()) return Any(); - const Any aRet = ::cppu::queryInterface(rType,static_cast< css::lang::XUnoTunnel*> (this)); - return aRet.hasValue() ? aRet : OTable_TYPEDEF::queryInterface(rType); + return OTable_TYPEDEF::queryInterface(rType); } diff --git a/connectivity/source/drivers/dbase/DCatalog.cxx b/connectivity/source/drivers/dbase/DCatalog.cxx index c35af1f28e62..79dce7ba2ce0 100644 --- a/connectivity/source/drivers/dbase/DCatalog.cxx +++ b/connectivity/source/drivers/dbase/DCatalog.cxx @@ -24,36 +24,33 @@ #include <com/sun/star/sdbc/XResultSet.hpp> using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; - using namespace connectivity::dbase; -ODbaseCatalog::ODbaseCatalog(ODbaseConnection* _pCon) : file::OFileCatalog(_pCon) +ODbaseCatalog::ODbaseCatalog(ODbaseConnection* _pCon) + : file::OFileCatalog(_pCon) { } void ODbaseCatalog::refreshTables() { - ::std::vector< OUString> aVector; - Sequence< OUString > aTypes; - Reference< XResultSet > xResult = m_xMetaData->getTables(Any(), - "%", "%", aTypes); + ::std::vector<OUString> aVector; + Sequence<OUString> aTypes; + Reference<XResultSet> xResult = m_xMetaData->getTables(Any(), "%", "%", aTypes); - if(xResult.is()) + if (xResult.is()) { - Reference< XRow > xRow(xResult,UNO_QUERY); - while(xResult->next()) + Reference<XRow> xRow(xResult, UNO_QUERY); + while (xResult->next()) aVector.push_back(xRow->getString(3)); } - if(m_pTables) + if (m_pTables) m_pTables->reFill(aVector); else - m_pTables.reset( new ODbaseTables(m_xMetaData,*this,m_aMutex,aVector) ); + m_pTables.reset(new ODbaseTables(m_xMetaData, *this, m_aMutex, aVector)); } - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/dbase/DColumns.cxx b/connectivity/source/drivers/dbase/DColumns.cxx index b997ec8d9087..402ec4e41c07 100644 --- a/connectivity/source/drivers/dbase/DColumns.cxx +++ b/connectivity/source/drivers/dbase/DColumns.cxx @@ -25,10 +25,6 @@ using namespace connectivity::dbase; using namespace connectivity; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::sdbcx; -using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; sdbcx::ObjectType ODbaseColumns::createObject(const OUString& _rName) { diff --git a/connectivity/source/drivers/dbase/DConnection.cxx b/connectivity/source/drivers/dbase/DConnection.cxx index 7c577b7c9541..7498f23e4bf7 100644 --- a/connectivity/source/drivers/dbase/DConnection.cxx +++ b/connectivity/source/drivers/dbase/DConnection.cxx @@ -33,10 +33,8 @@ typedef connectivity::file::OConnection OConnection_BASE; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::lang; ODbaseConnection::ODbaseConnection(ODriver* _pDriver) : OConnection(_pDriver) { @@ -74,8 +72,7 @@ css::uno::Reference< XTablesSupplier > ODbaseConnection::createCatalog() Reference< XTablesSupplier > xTab = m_xCatalog; if(!xTab.is()) { - ODbaseCatalog *pCat = new ODbaseCatalog(this); - xTab = pCat; + xTab = new ODbaseCatalog(this); m_xCatalog = xTab; } return xTab; @@ -97,9 +94,7 @@ Reference< XPreparedStatement > SAL_CALL ODbaseConnection::prepareStatement( con ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OConnection_BASE::rBHelper.bDisposed); - - ODbasePreparedStatement* pStmt = new ODbasePreparedStatement(this); - Reference< XPreparedStatement > xHoldAlive = pStmt; + rtl::Reference<ODbasePreparedStatement> pStmt = new ODbasePreparedStatement(this); pStmt->construct(sql); m_aStatements.push_back(WeakReferenceHelper(*pStmt)); return pStmt; diff --git a/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx b/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx index b896e942cb01..b3791f7d85d1 100644 --- a/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx +++ b/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx @@ -54,101 +54,96 @@ ODbaseDatabaseMetaData::~ODbaseDatabaseMetaData() Reference< XResultSet > ODbaseDatabaseMetaData::impl_getTypeInfo_throw( ) { - ::osl::MutexGuard aGuard( m_aMutex ); - - ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo); - Reference< XResultSet > xRef = pResult; + rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo); - static ODatabaseMetaDataResultSet::ORows aRows; - if(aRows.empty()) + ODatabaseMetaDataResultSet::ORows aRows; + aRows.reserve(10); + ODatabaseMetaDataResultSet::ORow aRow { - ODatabaseMetaDataResultSet::ORow aRow; - aRow.reserve(19); - - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(new ORowSetValueDecorator(OUString("VARCHAR"))); - aRow.push_back(new ORowSetValueDecorator(DataType::VARCHAR)); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(254))); - aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue()); - aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue()); - aRow.push_back(new ORowSetValueDecorator(OUString("length"))); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(ColumnValue::NULLABLE))); - aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(ColumnSearch::FULL))); - aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(new ORowSetValueDecorator(OUString("C"))); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(10))); - - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("LONGVARCHAR")); - aRow[2] = new ORowSetValueDecorator(DataType::LONGVARCHAR); - aRow[3] = new ORowSetValueDecorator(sal_Int32(2147483647)); - aRow[6] = new ORowSetValueDecorator(); - aRow[13] = new ORowSetValueDecorator(OUString("M")); - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("DATE")); - aRow[2] = new ORowSetValueDecorator(DataType::DATE); - aRow[3] = new ORowSetValueDecorator(sal_Int32(10)); - aRow[13] = new ORowSetValueDecorator(OUString("D")); - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("BOOLEAN")); - aRow[2] = new ORowSetValueDecorator(DataType::BIT); - aRow[3] = ODatabaseMetaDataResultSet::get1Value(); - aRow[4] = ODatabaseMetaDataResultSet::getEmptyValue(); - aRow[5] = ODatabaseMetaDataResultSet::getEmptyValue(); - aRow[6] = new ORowSetValueDecorator(OUString()); - aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); - aRow[13] = new ORowSetValueDecorator(OUString("L")); - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("DOUBLE")); - aRow[2] = new ORowSetValueDecorator(DataType::DOUBLE); - aRow[3] = new ORowSetValueDecorator(sal_Int32(8)); - aRow[13] = new ORowSetValueDecorator(OUString("B")); - aRows.push_back(aRow); - - aRow[11] = new ORowSetValueDecorator(true); - aRow[13] = new ORowSetValueDecorator(OUString("Y")); - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("TIMESTAMP")); - aRow[2] = new ORowSetValueDecorator(DataType::TIMESTAMP); - aRow[11] = new ORowSetValueDecorator(false); - aRow[13] = new ORowSetValueDecorator(OUString("T")); - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("INTEGER")); - aRow[2] = new ORowSetValueDecorator(DataType::INTEGER); - aRow[3] = new ORowSetValueDecorator(sal_Int32(10)); - aRow[13] = new ORowSetValueDecorator(OUString("I")); - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("DECIMAL")); - aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL); - aRow[3] = new ORowSetValueDecorator(sal_Int32(20)); - aRow[6] = new ORowSetValueDecorator(OUString("length,scale")); - aRow[13] = new ORowSetValueDecorator(OUString("F")); - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("NUMERIC")); - aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL); - aRow[3] = new ORowSetValueDecorator(sal_Int32(16)); - aRow[13] = new ORowSetValueDecorator(OUString("N")); - aRow[15] = new ORowSetValueDecorator(sal_Int32(16)); - aRows.push_back(aRow); - } - - pResult->setRows(aRows); - return xRef; + ODatabaseMetaDataResultSet::getEmptyValue(), + new ORowSetValueDecorator(OUString("VARCHAR")), + new ORowSetValueDecorator(DataType::VARCHAR), + new ORowSetValueDecorator(sal_Int32(254)), + ODatabaseMetaDataResultSet::getQuoteValue(), + ODatabaseMetaDataResultSet::getQuoteValue(), + new ORowSetValueDecorator(OUString("length")), + new ORowSetValueDecorator(sal_Int32(ColumnValue::NULLABLE)), + ODatabaseMetaDataResultSet::get1Value(), + new ORowSetValueDecorator(sal_Int32(ColumnSearch::FULL)), + ODatabaseMetaDataResultSet::get1Value(), + ODatabaseMetaDataResultSet::get0Value(), + ODatabaseMetaDataResultSet::get0Value(), + new ORowSetValueDecorator(OUString("C")), + ODatabaseMetaDataResultSet::get0Value(), + ODatabaseMetaDataResultSet::get0Value(), + ODatabaseMetaDataResultSet::getEmptyValue(), + ODatabaseMetaDataResultSet::getEmptyValue(), + new ORowSetValueDecorator(sal_Int32(10)) + }; + + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(OUString("LONGVARCHAR")); + aRow[2] = new ORowSetValueDecorator(DataType::LONGVARCHAR); + aRow[3] = new ORowSetValueDecorator(sal_Int32(2147483647)); + aRow[6] = new ORowSetValueDecorator(); + aRow[13] = new ORowSetValueDecorator(OUString("M")); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(OUString("DATE")); + aRow[2] = new ORowSetValueDecorator(DataType::DATE); + aRow[3] = new ORowSetValueDecorator(sal_Int32(10)); + aRow[13] = new ORowSetValueDecorator(OUString("D")); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(OUString("BOOLEAN")); + aRow[2] = new ORowSetValueDecorator(DataType::BIT); + aRow[3] = ODatabaseMetaDataResultSet::get1Value(); + aRow[4] = ODatabaseMetaDataResultSet::getEmptyValue(); + aRow[5] = ODatabaseMetaDataResultSet::getEmptyValue(); + aRow[6] = new ORowSetValueDecorator(OUString()); + aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); + aRow[13] = new ORowSetValueDecorator(OUString("L")); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(OUString("DOUBLE")); + aRow[2] = new ORowSetValueDecorator(DataType::DOUBLE); + aRow[3] = new ORowSetValueDecorator(sal_Int32(8)); + aRow[13] = new ORowSetValueDecorator(OUString("B")); + aRows.push_back(aRow); + + aRow[11] = new ORowSetValueDecorator(ORowSetValue(true)); + aRow[13] = new ORowSetValueDecorator(OUString("Y")); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(OUString("TIMESTAMP")); + aRow[2] = new ORowSetValueDecorator(DataType::TIMESTAMP); + aRow[11] = new ORowSetValueDecorator(ORowSetValue(false)); + aRow[13] = new ORowSetValueDecorator(OUString("T")); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(OUString("INTEGER")); + aRow[2] = new ORowSetValueDecorator(DataType::INTEGER); + aRow[3] = new ORowSetValueDecorator(sal_Int32(10)); + aRow[13] = new ORowSetValueDecorator(OUString("I")); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(OUString("DECIMAL")); + aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL); + aRow[3] = new ORowSetValueDecorator(sal_Int32(20)); + aRow[6] = new ORowSetValueDecorator(OUString("length,scale")); + aRow[13] = new ORowSetValueDecorator(OUString("F")); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(OUString("NUMERIC")); + aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL); + aRow[3] = new ORowSetValueDecorator(sal_Int32(16)); + aRow[13] = new ORowSetValueDecorator(OUString("N")); + aRow[15] = new ORowSetValueDecorator(sal_Int32(16)); + aRows.push_back(aRow); + + pResult->setRows(std::move(aRows)); + return pResult; } Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumns( @@ -207,7 +202,7 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumns( aRow[9] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)))); aRow[11] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)))); aRow[13] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)))); - switch(static_cast<sal_Int32>(aRow[5]->getValue())) + switch(aRow[5]->getValue().getInt32()) { case DataType::CHAR: case DataType::VARCHAR: @@ -220,7 +215,7 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumns( aRow[16] = new ORowSetValueDecorator(sal_Int32(0)); } aRow[17] = new ORowSetValueDecorator(i); - switch(sal_Int32(aRow[11]->getValue())) + switch(aRow[11]->getValue().getInt32()) { case ColumnValue::NO_NULLS: aRow[18] = new ORowSetValueDecorator(OUString("NO")); @@ -244,11 +239,10 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumns( throw aSql; throw WrappedTargetRuntimeException(e.Message, e.Context, e.TargetException); } - ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns); - Reference< XResultSet > xRef = pResult; - pResult->setRows(aRows); + rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns); + pResult->setRows(std::move(aRows)); - return xRef; + return pResult; } Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getIndexInfo( @@ -292,10 +286,10 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getIndexInfo( if(unique && !getBOOL(xIndex->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISUNIQUE)))) continue; - aRow[4] = new ORowSetValueDecorator(getBOOL(xIndex->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISUNIQUE)))); + aRow[4] = new ORowSetValueDecorator(ORowSetValue(getBOOL(xIndex->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISUNIQUE))))); aRow[6] = new ORowSetValueDecorator(*pBegin); - auto pIndex = comphelper::getUnoTunnelImplementation<ODbaseIndex>(xIndex); + auto pIndex = dynamic_cast<ODbaseIndex*>(xIndex.get()); if(pIndex) { aRow[11] = new ORowSetValueDecorator(static_cast<sal_Int32>(pIndex->getHeader().db_maxkeys)); @@ -316,10 +310,9 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getIndexInfo( } } - ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eIndexInfo); - Reference< XResultSet > xRef = pResult; - pResult->setRows(aRows); - return xRef; + rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eIndexInfo); + pResult->setRows(std::move(aRows)); + return pResult; } OUString SAL_CALL ODbaseDatabaseMetaData::getURL( ) diff --git a/connectivity/source/drivers/dbase/DDriver.cxx b/connectivity/source/drivers/dbase/DDriver.cxx index 6d3af175241b..ff0ec256e18a 100644 --- a/connectivity/source/drivers/dbase/DDriver.cxx +++ b/connectivity/source/drivers/dbase/DDriver.cxx @@ -22,7 +22,6 @@ #include <com/sun/star/lang/DisposedException.hpp> #include <connectivity/dbexception.hxx> #include <strings.hrc> -#include <comphelper/processfactory.hxx> using namespace connectivity::dbase; using namespace connectivity::file; @@ -52,7 +51,7 @@ connectivity_dbase_ODriver( } if (ret) ret->acquire(); - return static_cast<cppu::OWeakObject*>(ret.get()); + return getXWeak(ret.get()); } @@ -65,12 +64,11 @@ Reference< XConnection > SAL_CALL ODriver::connect( const OUString& url, const S if ( ! acceptsURL(url) ) return nullptr; - ODbaseConnection* pCon = new ODbaseConnection(this); + rtl::Reference<ODbaseConnection> pCon = new ODbaseConnection(this); pCon->construct(url,info); - Reference< XConnection > xCon = pCon; m_xConnections.push_back(WeakReferenceHelper(*pCon)); - return xCon; + return pCon; } sal_Bool SAL_CALL ODriver::acceptsURL( const OUString& url ) @@ -82,11 +80,10 @@ Sequence< DriverPropertyInfo > SAL_CALL ODriver::getPropertyInfo( const OUString { if ( acceptsURL(url) ) { - Sequence< OUString > aBoolean(2); - aBoolean[0] = "0"; - aBoolean[1] = "1"; + Sequence< OUString > aBoolean { "0", "1" }; - DriverPropertyInfo aDriverInfo[] = { + return + { { "CharSet" ,"CharSet of the database." @@ -109,8 +106,6 @@ Sequence< DriverPropertyInfo > SAL_CALL ODriver::getPropertyInfo( const OUString ,aBoolean } }; - - return Sequence< DriverPropertyInfo >(aDriverInfo, std::size(aDriverInfo)); } SharedResources aResources; diff --git a/connectivity/source/drivers/dbase/DIndex.cxx b/connectivity/source/drivers/dbase/DIndex.cxx index d168de39eb77..a3ee4a2688df 100644 --- a/connectivity/source/drivers/dbase/DIndex.cxx +++ b/connectivity/source/drivers/dbase/DIndex.cxx @@ -30,7 +30,6 @@ #include <unotools/ucbhelper.hxx> #include <comphelper/servicehelper.hxx> #include <comphelper/types.hxx> -#include <cppuhelper/typeprovider.hxx> #include <connectivity/dbexception.hxx> #include <dbase/DResultSet.hxx> #include <strings.hrc> @@ -42,13 +41,10 @@ using namespace connectivity; using namespace utl; using namespace ::cppu; using namespace connectivity::file; -using namespace connectivity::sdbcx; using namespace connectivity::dbase; using namespace com::sun::star::sdbc; -using namespace com::sun::star::sdbcx; using namespace com::sun::star::uno; using namespace com::sun::star::beans; -using namespace com::sun::star::lang; IMPLEMENT_SERVICE_INFO(ODbaseIndex,"com.sun.star.sdbcx.driver.dbase.Index","com.sun.star.sdbcx.Index"); @@ -100,22 +96,6 @@ void ODbaseIndex::refreshColumns() m_pColumns.reset(new ODbaseIndexColumns(this,m_aMutex,aVector)); } -Sequence< sal_Int8 > ODbaseIndex::getUnoTunnelId() -{ - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); -} - -// XUnoTunnel - -sal_Int64 ODbaseIndex::getSomething( const Sequence< sal_Int8 > & rId ) -{ - return (isUnoTunnelId<ODbaseIndex>(rId)) - ? reinterpret_cast< sal_Int64 >( this ) - : ODbaseIndex_BASE::getSomething(rId); -} - ONDXPagePtr const & ODbaseIndex::getRoot() { openIndexFile(); @@ -357,7 +337,7 @@ SvStream& connectivity::dbase::operator >> (SvStream &rStream, ODbaseIndex& rInd return rStream; } -SvStream& connectivity::dbase::WriteODbaseIndex(SvStream &rStream, ODbaseIndex& rIndex) +SvStream& connectivity::dbase::WriteODbaseIndex(SvStream &rStream, const ODbaseIndex& rIndex) { rStream.Seek(0); rStream.WriteUInt32(rIndex.m_aHeader.db_rootpage); @@ -404,8 +384,7 @@ void ODbaseIndex::createINFEntry() bool bCase = isCaseSensitive(); while (aNewEntry.isEmpty()) { - aNewEntry = OString("NDX"); - aNewEntry += OString::number(++nSuffix); + aNewEntry = "NDX" + OString::number(++nSuffix); for (sal_uInt16 i = 0; i < aInfFile.GetKeyCount(); i++) { aKeyName = aInfFile.GetKeyName(i); @@ -461,7 +440,7 @@ void ODbaseIndex::DropImpl() } } -void ODbaseIndex::impl_killFileAndthrowError_throw(const char* pErrorId, const OUString& _sFile) +void ODbaseIndex::impl_killFileAndthrowError_throw(TranslateId pErrorId, const OUString& _sFile) { closeImpl(); if(UCBContentHelper::Exists(_sFile)) @@ -568,15 +547,13 @@ void ODbaseIndex::CreateImpl() if(xSet->last()) { - Reference< XUnoTunnel> xTunnel(xSet, UNO_QUERY_THROW); - ODbaseResultSet* pDbaseRes = reinterpret_cast< ODbaseResultSet* >( xTunnel->getSomething(ODbaseResultSet::getUnoTunnelId()) ); + ODbaseResultSet* pDbaseRes = dynamic_cast<ODbaseResultSet*>(xSet.getTyped().get()); assert(pDbaseRes); //"No dbase resultset found? What's going on here! nRowsLeft = xSet->getRow(); xSet->beforeFirst(); - ORowSetValue atmpValue; - ONDXKey aKey(atmpValue, nType, 0); - ONDXKey aInsertKey(atmpValue, nType, 0); + ONDXKey aKey(ORowSetValue(), nType, 0); + ONDXKey aInsertKey(ORowSetValue(), nType, 0); // Create the index structure while (xSet->next()) { diff --git a/connectivity/source/drivers/dbase/DIndexColumns.cxx b/connectivity/source/drivers/dbase/DIndexColumns.cxx index 886c7273db31..8b20903fa1d3 100644 --- a/connectivity/source/drivers/dbase/DIndexColumns.cxx +++ b/connectivity/source/drivers/dbase/DIndexColumns.cxx @@ -28,9 +28,7 @@ using namespace connectivity::dbase; using namespace connectivity; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; sdbcx::ObjectType ODbaseIndexColumns::createObject(const OUString& _rName) diff --git a/connectivity/source/drivers/dbase/DIndexIter.cxx b/connectivity/source/drivers/dbase/DIndexIter.cxx index 62cc6601a54f..37e28a073f4c 100644 --- a/connectivity/source/drivers/dbase/DIndexIter.cxx +++ b/connectivity/source/drivers/dbase/DIndexIter.cxx @@ -27,22 +27,11 @@ using namespace connectivity::file; // OIndexIterator +OIndexIterator::~OIndexIterator() {} -OIndexIterator::~OIndexIterator() -{ -} - +sal_uInt32 OIndexIterator::First() { return Find(true); } -sal_uInt32 OIndexIterator::First() -{ - return Find(true); -} - - -sal_uInt32 OIndexIterator::Next() -{ - return Find(false); -} +sal_uInt32 OIndexIterator::Next() { return Find(false); } sal_uInt32 OIndexIterator::Find(bool bFirst) { @@ -69,19 +58,18 @@ sal_uInt32 OIndexIterator::Find(bool bFirst) ONDXKey* pKey = GetNextKey(); nRes = pKey ? pKey->GetRecord() : NODE_NOTFOUND; } - else if (dynamic_cast<const OOp_ISNOTNULL *>(m_pOperator) != nullptr) + else if (dynamic_cast<const OOp_ISNOTNULL*>(m_pOperator) != nullptr) nRes = GetNotNull(bFirst); - else if (dynamic_cast<const OOp_ISNULL *>(m_pOperator) != nullptr) + else if (dynamic_cast<const OOp_ISNULL*>(m_pOperator) != nullptr) nRes = GetNull(bFirst); - else if (dynamic_cast<const OOp_LIKE *>(m_pOperator) != nullptr) + else if (dynamic_cast<const OOp_LIKE*>(m_pOperator) != nullptr) nRes = GetLike(bFirst); - else if (dynamic_cast<const OOp_COMPARE *>(m_pOperator) != nullptr) + else if (dynamic_cast<const OOp_COMPARE*>(m_pOperator) != nullptr) nRes = GetCompare(bFirst); return nRes; } - ONDXKey* OIndexIterator::GetFirstKey(ONDXPage* pPage, const OOperand& rKey) { // searches a given key @@ -95,20 +83,19 @@ ONDXKey* OIndexIterator::GetFirstKey(ONDXPage* pPage, const OOperand& rKey) if (pPage->IsLeaf()) { // in the leaf the actual operation is run, otherwise temp. (>) - while (i < pPage->Count() && !m_pOperator->operate(&((*pPage)[i]).GetKey(),&rKey)) - i++; + while (i < pPage->Count() && !m_pOperator->operate(&((*pPage)[i]).GetKey(), &rKey)) + i++; } else - while (i < pPage->Count() && !aTempOp.operate(&((*pPage)[i]).GetKey(),&rKey)) - i++; - + while (i < pPage->Count() && !aTempOp.operate(&((*pPage)[i]).GetKey(), &rKey)) + i++; ONDXKey* pFoundKey = nullptr; if (!pPage->IsLeaf()) { // descend further - ONDXPagePtr aPage = (i==0) ? pPage->GetChild(m_xIndex.get()) - : ((*pPage)[i-1]).GetChild(m_xIndex.get(), pPage); + ONDXPagePtr aPage = (i == 0) ? pPage->GetChild(m_xIndex.get()) + : ((*pPage)[i - 1]).GetChild(m_xIndex.get(), pPage); pFoundKey = aPage.Is() ? GetFirstKey(aPage, rKey) : nullptr; } else if (i == pPage->Count()) @@ -118,7 +105,7 @@ ONDXKey* OIndexIterator::GetFirstKey(ONDXPage* pPage, const OOperand& rKey) else { pFoundKey = &(*pPage)[i].GetKey(); - if (!m_pOperator->operate(pFoundKey,&rKey)) + if (!m_pOperator->operate(pFoundKey, &rKey)) pFoundKey = nullptr; m_aCurLeaf = pPage; @@ -127,7 +114,6 @@ ONDXKey* OIndexIterator::GetFirstKey(ONDXPage* pPage, const OOperand& rKey) return pFoundKey; } - sal_uInt32 OIndexIterator::GetCompare(bool bFirst) { ONDXKey* pKey = nullptr; @@ -149,31 +135,31 @@ sal_uInt32 OIndexIterator::GetCompare(bool bFirst) m_nCurNode = NODE_NOTFOUND; } - switch (ePredicateType) { case SQLFilterOperator::NOT_EQUAL: - while ( ( pKey = GetNextKey() ) != nullptr ) - if (m_pOperator->operate(pKey,m_pOperand)) + while ((pKey = GetNextKey()) != nullptr) + if (m_pOperator->operate(pKey, m_pOperand)) break; break; case SQLFilterOperator::LESS: - while ( ( pKey = GetNextKey() ) != nullptr ) + while ((pKey = GetNextKey()) != nullptr) if (!pKey->getValue().isNull()) break; break; case SQLFilterOperator::LESS_EQUAL: - while ( ( pKey = GetNextKey() ) != nullptr ) ; + while ((pKey = GetNextKey()) != nullptr) + ; break; case SQLFilterOperator::GREATER_EQUAL: case SQLFilterOperator::EQUAL: - pKey = GetFirstKey(m_aRoot,*m_pOperand); + pKey = GetFirstKey(m_aRoot, *m_pOperand); break; case SQLFilterOperator::GREATER: - pKey = GetFirstKey(m_aRoot,*m_pOperand); - if ( !pKey ) - while ( ( pKey = GetNextKey() ) != nullptr ) - if (m_pOperator->operate(pKey,m_pOperand)) + pKey = GetFirstKey(m_aRoot, *m_pOperand); + if (!pKey) + while ((pKey = GetNextKey()) != nullptr) + if (m_pOperator->operate(pKey, m_pOperand)) break; } } @@ -182,15 +168,15 @@ sal_uInt32 OIndexIterator::GetCompare(bool bFirst) switch (ePredicateType) { case SQLFilterOperator::NOT_EQUAL: - while ( ( pKey = GetNextKey() ) != nullptr ) - if (m_pOperator->operate(pKey,m_pOperand)) + while ((pKey = GetNextKey()) != nullptr) + if (m_pOperator->operate(pKey, m_pOperand)) break; break; case SQLFilterOperator::LESS: case SQLFilterOperator::LESS_EQUAL: case SQLFilterOperator::EQUAL: pKey = GetNextKey(); - if ( pKey == nullptr || !m_pOperator->operate(pKey,m_pOperand)) + if (pKey == nullptr || !m_pOperator->operate(pKey, m_pOperand)) { pKey = nullptr; m_aCurLeaf.Clear(); @@ -205,7 +191,6 @@ sal_uInt32 OIndexIterator::GetCompare(bool bFirst) return pKey ? pKey->GetRecord() : NODE_NOTFOUND; } - sal_uInt32 OIndexIterator::GetLike(bool bFirst) { if (bFirst) @@ -220,13 +205,12 @@ sal_uInt32 OIndexIterator::GetLike(bool bFirst) } ONDXKey* pKey; - while ( ( pKey = GetNextKey() ) != nullptr ) - if (m_pOperator->operate(pKey,m_pOperand)) + while ((pKey = GetNextKey()) != nullptr) + if (m_pOperator->operate(pKey, m_pOperand)) break; return pKey ? pKey->GetRecord() : NODE_NOTFOUND; } - sal_uInt32 OIndexIterator::GetNull(bool bFirst) { if (bFirst) @@ -240,7 +224,7 @@ sal_uInt32 OIndexIterator::GetNull(bool bFirst) } ONDXKey* pKey = GetNextKey(); - if ( pKey == nullptr || !pKey->getValue().isNull()) + if (pKey == nullptr || !pKey->getValue().isNull()) { pKey = nullptr; m_aCurLeaf.Clear(); @@ -248,17 +232,14 @@ sal_uInt32 OIndexIterator::GetNull(bool bFirst) return pKey ? pKey->GetRecord() : NODE_NOTFOUND; } - sal_uInt32 OIndexIterator::GetNotNull(bool bFirst) { ONDXKey* pKey; if (bFirst) { // go through all NULL values first - for (sal_uInt32 nRec = GetNull(bFirst); - nRec != NODE_NOTFOUND; - nRec = GetNull(false)) - ; + for (sal_uInt32 nRec = GetNull(bFirst); nRec != NODE_NOTFOUND; nRec = GetNull(false)) + ; pKey = m_aCurLeaf.Is() ? &(*m_aCurLeaf)[m_nCurNode].GetKey() : nullptr; } else @@ -267,7 +248,6 @@ sal_uInt32 OIndexIterator::GetNotNull(bool bFirst) return pKey ? pKey->GetRecord() : NODE_NOTFOUND; } - ONDXKey* OIndexIterator::GetNextKey() { if (m_aCurLeaf.Is() && ((++m_nCurNode) >= m_aCurLeaf->Count())) @@ -281,8 +261,8 @@ ONDXKey* OIndexIterator::GetNextKey() { sal_uInt16 nPos = pParentPage->Search(pPage); if (nPos != pParentPage->Count() - 1) - { // page found - pPage = (*pParentPage)[nPos+1].GetChild(m_xIndex.get(),pParentPage); + { // page found + pPage = (*pParentPage)[nPos + 1].GetChild(m_xIndex.get(), pParentPage); break; } } diff --git a/connectivity/source/drivers/dbase/DIndexes.cxx b/connectivity/source/drivers/dbase/DIndexes.cxx index 1ebce2612098..df630c531c3e 100644 --- a/connectivity/source/drivers/dbase/DIndexes.cxx +++ b/connectivity/source/drivers/dbase/DIndexes.cxx @@ -24,18 +24,12 @@ #include <unotools/ucbhelper.hxx> #include <strings.hrc> -using namespace ::comphelper; - using namespace utl; using namespace ::connectivity; using namespace ::dbtools; using namespace ::connectivity::dbase; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdbcx; -using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; sdbcx::ObjectType ODbaseIndexes::createObject(const OUString& _rName) { @@ -63,7 +57,7 @@ sdbcx::ObjectType ODbaseIndexes::createObject(const OUString& _rName) ReadHeader(*pFileStream, aHeader); pFileStream.reset(); - ODbaseIndex* pIndex = new ODbaseIndex(m_pTable,aHeader,_rName); + rtl::Reference<ODbaseIndex> pIndex = new ODbaseIndex(m_pTable,aHeader,_rName); xRet = pIndex; pIndex->openIndexFile(); } @@ -92,14 +86,9 @@ Reference< XPropertySet > ODbaseIndexes::createDescriptor() // XAppend sdbcx::ObjectType ODbaseIndexes::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) { - Reference<XUnoTunnel> xTunnel(descriptor,UNO_QUERY); - if(xTunnel.is()) - { - ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelId()) ); - if(!pIndex) - throw SQLException(); + ODbaseIndex* pIndex = dynamic_cast<ODbaseIndex*>(descriptor.get()); + if(pIndex) pIndex->CreateImpl(); - } return createObject( _rForName ); } @@ -107,7 +96,7 @@ sdbcx::ObjectType ODbaseIndexes::appendObject( const OUString& _rForName, const // XDrop void ODbaseIndexes::dropObject(sal_Int32 _nPos, const OUString& /*_sElementName*/) { - auto pIndex = comphelper::getUnoTunnelImplementation<ODbaseIndex>(getObject(_nPos)); + rtl::Reference<ODbaseIndex> pIndex = dynamic_cast<ODbaseIndex*>(getObject(_nPos).get()); if ( pIndex ) pIndex->DropImpl(); } diff --git a/connectivity/source/drivers/dbase/DPreparedStatement.cxx b/connectivity/source/drivers/dbase/DPreparedStatement.cxx index 60e7a6a7f3ef..f349701e620b 100644 --- a/connectivity/source/drivers/dbase/DPreparedStatement.cxx +++ b/connectivity/source/drivers/dbase/DPreparedStatement.cxx @@ -22,13 +22,13 @@ using namespace connectivity::dbase; using namespace connectivity::file; -using namespace com::sun::star::uno; -OResultSet* ODbasePreparedStatement::createResultSet() +rtl::Reference<OResultSet> ODbasePreparedStatement::createResultSet() { - return new ODbaseResultSet(this,m_aSQLIterator); + return new ODbaseResultSet(this, m_aSQLIterator); } -IMPLEMENT_SERVICE_INFO(ODbasePreparedStatement,"com.sun.star.sdbc.driver.dbase.PreparedStatement","com.sun.star.sdbc.PreparedStatement"); +IMPLEMENT_SERVICE_INFO(ODbasePreparedStatement, "com.sun.star.sdbc.driver.dbase.PreparedStatement", + "com.sun.star.sdbc.PreparedStatement"); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/dbase/DResultSet.cxx b/connectivity/source/drivers/dbase/DResultSet.cxx index f9395a359465..123a29b8b069 100644 --- a/connectivity/source/drivers/dbase/DResultSet.cxx +++ b/connectivity/source/drivers/dbase/DResultSet.cxx @@ -81,7 +81,7 @@ Any SAL_CALL ODbaseResultSet::getBookmark( ) checkDisposed(OResultSet_BASE::rBHelper.bDisposed); OSL_ENSURE((m_bShowDeleted || !m_aRow->isDeleted()),"getBookmark called for deleted row"); - return makeAny(static_cast<sal_Int32>((*m_aRow)[0]->getValue())); + return Any((*m_aRow)[0]->getValue().getInt32()); } sal_Bool SAL_CALL ODbaseResultSet::moveToBookmark( const Any& bookmark ) @@ -155,7 +155,7 @@ Sequence< sal_Int32 > SAL_CALL ODbaseResultSet::deleteRows( const Sequence< An bool ODbaseResultSet::fillIndexValues(const Reference< XColumnsSupplier> &_xIndex) { - auto pIndex = comphelper::getUnoTunnelImplementation<dbase::ODbaseIndex>(_xIndex); + auto pIndex = dynamic_cast<dbase::ODbaseIndex*>(_xIndex.get()); if(pIndex) { std::unique_ptr<dbase::OIndexIterator> pIter = pIndex->createIterator(); @@ -187,12 +187,12 @@ bool ODbaseResultSet::fillIndexValues(const Reference< XColumnsSupplier> &_xInde return new ::cppu::OPropertyArrayHelper(aProps); } -void SAL_CALL ODbaseResultSet::acquire() throw() +void SAL_CALL ODbaseResultSet::acquire() noexcept { ODbaseResultSet_BASE2::acquire(); } -void SAL_CALL ODbaseResultSet::release() throw() +void SAL_CALL ODbaseResultSet::release() noexcept { ODbaseResultSet_BASE2::release(); } diff --git a/connectivity/source/drivers/dbase/DStatement.cxx b/connectivity/source/drivers/dbase/DStatement.cxx index 096878e3e245..0da788f98e54 100644 --- a/connectivity/source/drivers/dbase/DStatement.cxx +++ b/connectivity/source/drivers/dbase/DStatement.cxx @@ -22,10 +22,9 @@ using namespace connectivity::dbase; using namespace connectivity::file; -using namespace com::sun::star::uno; -OResultSet* ODbaseStatement::createResultSet() +rtl::Reference<OResultSet> ODbaseStatement::createResultSet() { return new ODbaseResultSet(this,m_aSQLIterator); } diff --git a/connectivity/source/drivers/dbase/DTable.cxx b/connectivity/source/drivers/dbase/DTable.cxx index ff01f3b6ba37..98d598d0478f 100644 --- a/connectivity/source/drivers/dbase/DTable.cxx +++ b/connectivity/source/drivers/dbase/DTable.cxx @@ -28,6 +28,7 @@ #include <dbase/DConnection.hxx> #include <dbase/DColumns.hxx> #include <tools/config.hxx> +#include <comphelper/diagnose_ex.hxx> #include <dbase/DIndex.hxx> #include <dbase/DIndexes.hxx> #include <comphelper/processfactory.hxx> @@ -38,11 +39,12 @@ #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> #include <comphelper/property.hxx> #include <comphelper/servicehelper.hxx> +#include <o3tl/string_view.hxx> #include <comphelper/string.hxx> +#include <comphelper/configuration.hxx> #include <unotools/tempfile.hxx> #include <unotools/ucbhelper.hxx> #include <comphelper/types.hxx> -#include <cppuhelper/typeprovider.hxx> #include <cppuhelper/exc_hlp.hxx> #include <cppuhelper/queryinterface.hxx> #include <connectivity/dbtools.hxx> @@ -53,10 +55,12 @@ #include <rtl/strbuf.hxx> #include <sal/log.hxx> #include <tools/date.hxx> +#include <i18nutil/calendar.hxx> #include <algorithm> #include <cassert> #include <memory> +#include <string_view> using namespace ::comphelper; using namespace connectivity; @@ -130,13 +134,13 @@ void lcl_CalcJulDate(sal_Int32& _nJulianDate,sal_Int32& _nJulianTime, const css: if ( aDateTime.Year <= 0 ) { _nJulianDate = static_cast<sal_Int32>((365.25 * iy0) - 0.75) - + static_cast<sal_Int32>(30.6001 * (im0 + 1) ) + + static_cast<sal_Int32>(i18nutil::monthDaysWithoutJanFeb * (im0 + 1) ) + aDateTime.Day + 1720994; } // if ( rDateTime.Year <= 0 ) else { _nJulianDate = static_cast<sal_Int32>(365.25 * iy0) - + static_cast<sal_Int32>(30.6001 * (im0 + 1)) + + static_cast<sal_Int32>(i18nutil::monthDaysWithoutJanFeb * (im0 + 1)) + aDateTime.Day + 1720994; } double JD = _nJulianDate + 0.5; @@ -153,18 +157,17 @@ void lcl_CalDate(sal_Int32 _nJulianDate,sal_Int32 _nJulianTime,css::util::DateTi { if ( _nJulianDate ) { - sal_Int32 ialp; - sal_Int32 ka = _nJulianDate; + sal_Int64 ka = _nJulianDate; if ( _nJulianDate >= 2299161 ) { - ialp = static_cast<sal_Int32>( (static_cast<double>(_nJulianDate) - 1867216.25 ) / 36524.25 ); - ka = _nJulianDate + 1 + ialp - ( ialp >> 2 ); + sal_Int64 ialp = static_cast<sal_Int64>( (static_cast<double>(_nJulianDate) - 1867216.25 ) / 36524.25 ); + ka = ka + 1 + ialp - ( ialp >> 2 ); } - sal_Int32 kb = ka + 1524; - sal_Int32 kc = static_cast<sal_Int32>( (static_cast<double>(kb) - 122.1 ) / 365.25 ); - sal_Int32 kd = static_cast<sal_Int32>(static_cast<double>(kc) * 365.25); - sal_Int32 ke = static_cast<sal_Int32>(static_cast<double>( kb - kd ) / 30.6001 ); - _rDateTime.Day = static_cast<sal_uInt16>(kb - kd - static_cast<sal_Int32>( static_cast<double>(ke) * 30.6001 )); + sal_Int64 kb = ka + 1524; + sal_Int64 kc = static_cast<sal_Int64>((static_cast<double>(kb) - 122.1) / 365.25); + sal_Int64 kd = static_cast<sal_Int64>(static_cast<double>(kc) * 365.25); + sal_Int64 ke = static_cast<sal_Int64>(static_cast<double>(kb - kd) / i18nutil::monthDaysWithoutJanFeb); + _rDateTime.Day = static_cast<sal_uInt16>(kb - kd - static_cast<sal_Int64>( static_cast<double>(ke) * i18nutil::monthDaysWithoutJanFeb )); if ( ke > 13 ) _rDateTime.Month = static_cast<sal_uInt16>(ke - 13); else @@ -272,7 +275,11 @@ void ODbaseTable::readHeader() void ODbaseTable::fillColumns() { m_pFileStream->Seek(STREAM_SEEK_TO_BEGIN); - m_pFileStream->Seek(32); + if (!checkSeek(*m_pFileStream, 32)) + { + SAL_WARN("connectivity.drivers", "ODbaseTable::fillColumns: bad offset!"); + return; + } if(!m_aColumns.is()) m_aColumns = new OSQLColumns(); @@ -284,8 +291,21 @@ void ODbaseTable::fillColumns() m_aScales.clear(); // Number of fields: - const sal_Int32 nFieldCount = (m_aHeader.headerLength - 1) / 32 - 1; - OSL_ENSURE(nFieldCount,"No columns in table!"); + sal_Int32 nFieldCount = (m_aHeader.headerLength - 1) / 32 - 1; + if (nFieldCount <= 0) + { + SAL_WARN("connectivity.drivers", "No columns in table!"); + return; + } + + auto nRemainingsize = m_pFileStream->remainingSize(); + auto nMaxPossibleRecords = nRemainingsize / 32; + if (o3tl::make_unsigned(nFieldCount) > nMaxPossibleRecords) + { + SAL_WARN("connectivity.drivers", "Parsing error: " << nMaxPossibleRecords << + " max possible entries, but " << nFieldCount << " claimed, truncating"); + nFieldCount = nMaxPossibleRecords; + } m_aColumns->reserve(nFieldCount); m_aTypes.reserve(nFieldCount); @@ -300,17 +320,13 @@ void ODbaseTable::fillColumns() for (; i < nFieldCount; i++) { DBFColumn aDBFColumn; -#if !defined(NDEBUG) - sal_uInt64 const nOldPos(m_pFileStream->Tell()); -#endif m_pFileStream->ReadBytes(aDBFColumn.db_fnm, 11); m_pFileStream->ReadUChar(aDBFColumn.db_typ); m_pFileStream->ReadUInt32(aDBFColumn.db_adr); m_pFileStream->ReadUChar(aDBFColumn.db_flng); m_pFileStream->ReadUChar(aDBFColumn.db_dez); m_pFileStream->ReadBytes(aDBFColumn.db_free2, 14); - assert(m_pFileStream->GetError() || m_pFileStream->Tell() == nOldPos + sizeof(aDBFColumn)); - if (m_pFileStream->GetError()) + if (!m_pFileStream->good()) { SAL_WARN("connectivity.drivers", "ODbaseTable::fillColumns: short read!"); break; @@ -454,7 +470,6 @@ ODbaseTable::ODbaseTable(sdbcx::OCollection* _pTables, ODbaseConnection* _pConne m_eEncoding = getConnection()->getTextEncoding(); } - void ODbaseTable::construct() { // initialize the header @@ -482,19 +497,47 @@ void ODbaseTable::construct() m_pFileStream = createStream_simpleError( sFileName, StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYNONE); } - if(!m_pFileStream) + if (!m_pFileStream) return; readHeader(); + + std::size_t nFileSize = lcl_getFileSize(*m_pFileStream); + + if (m_aHeader.headerLength > nFileSize) + { + SAL_WARN("connectivity.drivers", "Parsing error: " << nFileSize << + " max possible size, but " << m_aHeader.headerLength << " claimed, abandoning"); + return; + } + + if (m_aHeader.recordLength) + { + std::size_t nMaxPossibleRecords = (nFileSize - m_aHeader.headerLength) / m_aHeader.recordLength; + // #i83401# seems to be empty or someone wrote nonsense into the dbase + // file try and recover if m_aHeader.db_slng is sane + if (m_aHeader.nbRecords == 0) + { + SAL_WARN("connectivity.drivers", "Parsing warning: 0 records claimed, recovering"); + m_aHeader.nbRecords = nMaxPossibleRecords; + } + else if (m_aHeader.nbRecords > nMaxPossibleRecords) + { + SAL_WARN("connectivity.drivers", "Parsing error: " << nMaxPossibleRecords << + " max possible records, but " << m_aHeader.nbRecords << " claimed, truncating"); + m_aHeader.nbRecords = std::max(nMaxPossibleRecords, static_cast<size_t>(1)); + } + } + if (HasMemoFields()) { // Create Memo-Filename (.DBT): // nyi: Ugly for Unix and Mac! if ( m_aHeader.type == FoxProMemo || m_aHeader.type == VisualFoxPro || m_aHeader.type == VisualFoxProAuto) // foxpro uses another extension - aURL.SetExtension("fpt"); + aURL.SetExtension(u"fpt"); else - aURL.SetExtension("dbt"); + aURL.SetExtension(u"dbt"); // If the memo file isn't found, the data will be displayed anyhow. // However, updates can't be done @@ -507,18 +550,10 @@ void ODbaseTable::construct() if (m_pMemoStream) ReadMemoHeader(); } - fillColumns(); - std::size_t nFileSize = lcl_getFileSize(*m_pFileStream); + fillColumns(); m_pFileStream->Seek(STREAM_SEEK_TO_BEGIN); - // seems to be empty or someone wrote bullshit into the dbase file - // try and recover if m_aHeader.db_slng is sane - if (m_aHeader.nbRecords == 0 && m_aHeader.recordLength) - { - std::size_t nRecords = (nFileSize-m_aHeader.headerLength)/m_aHeader.recordLength; - if (nRecords > 0) - m_aHeader.nbRecords = nRecords; - } + // Buffersize dependent on the file size m_pFileStream->SetBufferSize(nFileSize > 1000000 ? 32768 : @@ -589,7 +624,7 @@ void ODbaseTable::ReadMemoHeader() } } -OUString ODbaseTable::getEntry(file::OConnection const * _pConnection,const OUString& _sName ) +OUString ODbaseTable::getEntry(file::OConnection const * _pConnection, std::u16string_view _sName ) { OUString sURL; try @@ -613,7 +648,7 @@ OUString ODbaseTable::getEntry(file::OConnection const * _pConnection,const OUSt // name and extension have to coincide if ( _pConnection->matchesExtension( sExt ) ) { - sName = sName.replaceAt(sName.getLength() - (sExt.getLength() + 1), sExt.getLength() + 1, OUString()); + sName = sName.replaceAt(sName.getLength() - (sExt.getLength() + 1), sExt.getLength() + 1, u""); if ( sName == _sName ) { Reference< XContentAccess > xContentAccess( xDir, UNO_QUERY ); @@ -644,7 +679,7 @@ void ODbaseTable::refreshColumns() if(m_xColumns) m_xColumns->reFill(aVector); else - m_xColumns = new ODbaseColumns(this,m_aMutex,aVector); + m_xColumns.reset(new ODbaseColumns(this,m_aMutex,aVector)); } void ODbaseTable::refreshIndexes() @@ -655,7 +690,7 @@ void ODbaseTable::refreshIndexes() INetURLObject aURL; aURL.SetURL(getEntry(m_pConnection,m_Name)); - aURL.setExtension("inf"); + aURL.setExtension(u"inf"); Config aInfFile(aURL.getFSysPath(FSysStyle::Detect)); aInfFile.SetGroup(dBASE_III_GROUP); sal_uInt16 nKeyCnt = aInfFile.GetKeyCount(); @@ -687,7 +722,7 @@ void ODbaseTable::refreshIndexes() if(m_xIndexes) m_xIndexes->reFill(aVector); else - m_xIndexes = new ODbaseIndexes(this,m_aMutex,aVector); + m_xIndexes.reset(new ODbaseIndexes(this,m_aMutex,aVector)); } @@ -708,8 +743,8 @@ Sequence< Type > SAL_CALL ODbaseTable::getTypes( ) const Type* pEnd = pBegin + aTypes.getLength(); for(;pBegin != pEnd;++pBegin) { - if(!(*pBegin == cppu::UnoType<XKeysSupplier>::get()|| - *pBegin == cppu::UnoType<XDataDescriptorFactory>::get())) + if(*pBegin != cppu::UnoType<XKeysSupplier>::get() && + *pBegin != cppu::UnoType<XDataDescriptorFactory>::get()) { aOwnTypes.push_back(*pBegin); } @@ -726,25 +761,9 @@ Any SAL_CALL ODbaseTable::queryInterface( const Type & rType ) return Any(); Any aRet = OTable_TYPEDEF::queryInterface(rType); - return aRet.hasValue() ? aRet : ::cppu::queryInterface(rType,static_cast< css::lang::XUnoTunnel*> (this)); -} - - -Sequence< sal_Int8 > ODbaseTable::getUnoTunnelId() -{ - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); + return aRet; } -// css::lang::XUnoTunnel - -sal_Int64 ODbaseTable::getSomething( const Sequence< sal_Int8 > & rId ) -{ - return (isUnoTunnelId<ODbaseTable>(rId)) - ? reinterpret_cast< sal_Int64 >( this ) - : ODbaseTable_BASE::getSomething(rId); -} bool ODbaseTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns & _rCols, bool bRetrieveData) { @@ -752,7 +771,7 @@ bool ODbaseTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns & _rCols, bool return false; // Read the data - bool bIsCurRecordDeleted = static_cast<char>(m_pBuffer[0]) == '*'; + bool bIsCurRecordDeleted = m_pBuffer[0] == '*'; // only read the bookmark @@ -771,10 +790,8 @@ bool ODbaseTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns & _rCols, bool for (std::size_t i = 1; aIter != aEnd && nByteOffset <= m_nBufferSize && i < nCount;++aIter, i++) { // Lengths depending on data type: - sal_Int32 nLen = 0; - sal_Int32 nType = 0; - nLen = m_aPrecisions[i-1]; - nType = m_aTypes[i-1]; + sal_Int32 nLen = m_aPrecisions[i-1]; + sal_Int32 nType = m_aTypes[i-1]; switch(nType) { @@ -826,15 +843,20 @@ bool ODbaseTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns & _rCols, bool } else { - // Commit the string. Use intern() to ref-count it. - *(*_rRow)[i] = OUString::intern(pData, static_cast<sal_Int32>(nLastPos+1), m_eEncoding); + // Commit the string + *(*_rRow)[i] = OUString(pData, static_cast<sal_Int32>(nLastPos+1), m_eEncoding); } } // if (nType == DataType::CHAR || nType == DataType::VARCHAR) else if ( DataType::TIMESTAMP == nType ) { sal_Int32 nDate = 0,nTime = 0; + if (o3tl::make_unsigned(nLen) < 8) + { + SAL_WARN("connectivity.drivers", "short TIMESTAMP"); + return false; + } memcpy(&nDate, pData, 4); - memcpy(&nTime, pData+ 4, 4); + memcpy(&nTime, pData + 4, 4); if ( !nDate && !nTime ) { (*_rRow)[i]->setNull(); @@ -906,20 +928,20 @@ bool ODbaseTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns & _rCols, bool continue; } - OUString aStr = OUString::intern(pData+nPos1, nPos2-nPos1+1, m_eEncoding); + OUString aStr(pData+nPos1, nPos2-nPos1+1, m_eEncoding); switch (nType) { case DataType::DATE: { - if (aStr.getLength() != nLen) + if (nLen < 8 || aStr.getLength() != nLen) { (*_rRow)[i]->setNull(); break; } - const sal_uInt16 nYear = static_cast<sal_uInt16>(aStr.copy( 0, 4 ).toInt32()); - const sal_uInt16 nMonth = static_cast<sal_uInt16>(aStr.copy( 4, 2 ).toInt32()); - const sal_uInt16 nDay = static_cast<sal_uInt16>(aStr.copy( 6, 2 ).toInt32()); + const sal_uInt16 nYear = static_cast<sal_uInt16>(o3tl::toInt32(aStr.subView( 0, 4 ))); + const sal_uInt16 nMonth = static_cast<sal_uInt16>(o3tl::toInt32(aStr.subView( 4, 2 ))); + const sal_uInt16 nDay = static_cast<sal_uInt16>(o3tl::toInt32(aStr.subView( 6, 2 ))); const css::util::Date aDate(nDay,nMonth,nYear); *(*_rRow)[i] = aDate; @@ -945,7 +967,7 @@ bool ODbaseTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns & _rCols, bool case DataType::BINARY: case DataType::LONGVARCHAR: { - const long nBlockNo = aStr.toInt32(); // read blocknumber + const tools::Long nBlockNo = aStr.toInt32(); // read blocknumber if (nBlockNo > 0 && m_pMemoStream) // Read data from memo-file, only if { if ( !ReadMemo(nBlockNo, (*_rRow)[i]->get()) ) @@ -970,9 +992,6 @@ bool ODbaseTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns & _rCols, bool void ODbaseTable::FileClose() { ::osl::MutexGuard aGuard(m_aMutex); - // if not everything has been written yet - if (m_pMemoStream && m_pMemoStream->IsWritable()) - m_pMemoStream->Flush(); m_pMemoStream.reset(); @@ -983,7 +1002,7 @@ bool ODbaseTable::CreateImpl() { OSL_ENSURE(!m_pFileStream, "SequenceError"); - if ( m_pConnection->isCheckEnabled() && ::dbtools::convertName2SQLName(m_Name,OUString()) != m_Name ) + if ( m_pConnection->isCheckEnabled() && ::dbtools::convertName2SQLName(m_Name, u"") != m_Name ) { const OUString sError( getConnection()->getResources().getResourceStringWithSubstitution( STR_SQL_NAME_ERROR, @@ -1046,7 +1065,7 @@ bool ODbaseTable::CreateImpl() if (bMemoFile) { OUString aExt = aURL.getExtension(); - aURL.setExtension("dbt"); // extension for memo file + aURL.setExtension(u"dbt"); // extension for memo file bool bMemoAlreadyExists = false; try @@ -1102,7 +1121,7 @@ bool ODbaseTable::CreateImpl() return true; } -void ODbaseTable::throwInvalidColumnType(const char* pErrorId, const OUString& _sColumnName) +void ODbaseTable::throwInvalidColumnType(TranslateId pErrorId, const OUString& _sColumnName) { try { @@ -1362,6 +1381,10 @@ bool ODbaseTable::CreateFile(const INetURLObject& aFile, bool& bCreateMemo) return true; } +bool ODbaseTable::HasMemoFields() const +{ + return m_aHeader.type > dBaseIV && !comphelper::IsFuzzing(); +} // creates in principle dBase III file format bool ODbaseTable::CreateMemoFile(const INetURLObject& aFile) @@ -1377,12 +1400,11 @@ bool ODbaseTable::CreateMemoFile(const INetURLObject& aFile) m_pMemoStream->Seek(0); (*m_pMemoStream).WriteUInt32( 1 ); // pointer to the first free block - m_pMemoStream->Flush(); m_pMemoStream.reset(); return true; } -bool ODbaseTable::Drop_Static(const OUString& _sUrl, bool _bHasMemoFields, OCollection* _pIndexes ) +bool ODbaseTable::Drop_Static(std::u16string_view _sUrl, bool _bHasMemoFields, OCollection* _pIndexes ) { INetURLObject aURL; aURL.SetURL(_sUrl); @@ -1393,7 +1415,7 @@ bool ODbaseTable::Drop_Static(const OUString& _sUrl, bool _bHasMemoFields, OColl { if (_bHasMemoFields) { // delete the memo fields - aURL.setExtension("dbt"); + aURL.setExtension(u"dbt"); bDropped = ::utl::UCBContentHelper::Kill(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE)); } @@ -1413,13 +1435,13 @@ bool ODbaseTable::Drop_Static(const OUString& _sUrl, bool _bHasMemoFields, OColl { } } - aURL.setExtension("inf"); + aURL.setExtension(u"inf"); // as the inf file does not necessarily exist, we aren't allowed to use UCBContentHelper::Kill try { ::ucbhelper::Content aDeleteContent( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), Reference< XCommandEnvironment >(), comphelper::getProcessComponentContext() ); - aDeleteContent.executeCommand( "delete", makeAny( true ) ); + aDeleteContent.executeCommand( "delete", Any( true ) ); } catch(const Exception&) { @@ -1512,7 +1534,7 @@ bool ODbaseTable::UpdateRow(OValueRefVector& rRow, OValueRefRow& pOrgRow, const return false; // position on desired record: - std::size_t nPos = m_aHeader.headerLength + static_cast<long>(m_nFilePos-1) * m_aHeader.recordLength; + std::size_t nPos = m_aHeader.headerLength + static_cast<tools::Long>(m_nFilePos-1) * m_aHeader.recordLength; m_pFileStream->Seek(nPos); m_pFileStream->ReadBytes(m_pBuffer.get(), m_aHeader.recordLength); @@ -1539,7 +1561,7 @@ bool ODbaseTable::DeleteRow(const OSQLColumns& _rCols) { // Set the Delete-Flag (be it set or not): // Position on desired record: - std::size_t nFilePos = m_aHeader.headerLength + static_cast<long>(m_nFilePos-1) * m_aHeader.recordLength; + std::size_t nFilePos = m_aHeader.headerLength + static_cast<tools::Long>(m_nFilePos-1) * m_aHeader.recordLength; m_pFileStream->Seek(nFilePos); OValueRefRow aRow = new OValueRefVector(_rCols.size()); @@ -1561,10 +1583,8 @@ bool ODbaseTable::DeleteRow(const OSQLColumns& _rCols) { xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aColName; - Reference<XUnoTunnel> xTunnel(xIndex,UNO_QUERY); - OSL_ENSURE(xTunnel.is(),"No TunnelImplementation!"); - ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelId()) ); - OSL_ENSURE(pIndex,"ODbaseTable::DeleteRow: No Index returned!"); + ODbaseIndex* pIndex = dynamic_cast<ODbaseIndex*>(xIndex.get()); + assert(pIndex && "ODbaseTable::DeleteRow: No Index returned!"); OSQLColumns::const_iterator aIter = std::find_if(_rCols.begin(), _rCols.end(), [&aCase, &aColName](const OSQLColumns::value_type& rxCol) { @@ -1612,7 +1632,7 @@ Reference<XPropertySet> ODbaseTable::isUniqueByColumnName(sal_Int32 _nColumnPos) return Reference<XPropertySet>(); } -static double toDouble(const OString& rString) +static double toDouble(std::string_view rString) { return ::rtl::math::stringToDouble( rString, '.', ',' ); } @@ -1634,7 +1654,7 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo ::comphelper::UStringMixEqual aCase(isCaseSensitive()); - Reference<XIndexAccess> xColumns = m_xColumns.get(); + Reference<XIndexAccess> xColumns(m_xColumns.get()); // first search a key that exist already in the table for (sal_Int32 i = 0; i < nColumnCount; ++i) { @@ -1667,10 +1687,8 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo continue; else { - Reference<XUnoTunnel> xTunnel(xIndex,UNO_QUERY); - OSL_ENSURE(xTunnel.is(),"No TunnelImplementation!"); - ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelId()) ); - OSL_ENSURE(pIndex,"ODbaseTable::UpdateBuffer: No Index returned!"); + ODbaseIndex* pIndex = dynamic_cast<ODbaseIndex*>(xIndex.get()); + assert(pIndex && "ODbaseTable::UpdateBuffer: No Index returned!"); if (pIndex->Find(0,*rRow[nPos])) { @@ -1775,10 +1793,8 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo } if (aIndexedCols[i].is()) { - Reference<XUnoTunnel> xTunnel(aIndexedCols[i],UNO_QUERY); - OSL_ENSURE(xTunnel.is(),"No TunnelImplementation!"); - ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelId()) ); - OSL_ENSURE(pIndex,"ODbaseTable::UpdateBuffer: No Index returned!"); + ODbaseIndex* pIndex = dynamic_cast<ODbaseIndex*>(aIndexedCols[i].get()); + assert(pIndex && "ODbaseTable::UpdateBuffer: No Index returned!"); // Update !! if (pOrgRow.is() && !thisColIsNull) pIndex->Update(m_nFilePos, *(*pOrgRow)[nPos], thisColVal); @@ -1805,7 +1821,7 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo case DataType::TIMESTAMP: { sal_Int32 nJulianDate = 0, nJulianTime = 0; - lcl_CalcJulDate(nJulianDate,nJulianTime, thisColVal); + lcl_CalcJulDate(nJulianDate,nJulianTime, thisColVal.getDateTime()); // Exactly 8 bytes to copy: memcpy(pData,&nJulianDate,4); memcpy(pData+4,&nJulianTime,4); @@ -1817,7 +1833,7 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo if(thisColVal.getTypeKind() == DataType::DOUBLE) aDate = ::dbtools::DBTypeConversion::toDate(thisColVal.getDouble()); else - aDate = thisColVal; + aDate = thisColVal.getDate(); char s[sizeof("-327686553565535")]; // reserve enough space for hypothetical max length snprintf(s, @@ -1832,7 +1848,7 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo } break; case DataType::INTEGER: { - sal_Int32 nValue = thisColVal; + sal_Int32 nValue = thisColVal.getInt32(); if (o3tl::make_unsigned(nLen) > sizeof(nValue)) return false; memcpy(pData,&nValue,nLen); @@ -1840,7 +1856,7 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo break; case DataType::DOUBLE: { - const double d = thisColVal; + const double d = thisColVal.getDouble(); m_xColumns->getByIndex(i) >>= xCol; if (getBOOL(xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))) // Currency is treated separately @@ -1866,7 +1882,7 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo { memset(pData,' ',nLen); // Clear to NULL - const double n = thisColVal; + const double n = thisColVal.getDouble(); // one, because const_cast GetFormatPrecision on SvNumberFormat is not constant, // even though it really could and should be @@ -1884,11 +1900,13 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo m_xColumns->getByIndex(i) >>= xCol; OSL_ENSURE(xCol.is(),"ODbaseTable::UpdateBuffer column is null!"); xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aColName; - std::vector< std::pair<const char* , OUString > > aStringToSubstitutes; - aStringToSubstitutes.push_back(std::pair<const char* , OUString >("$columnname$", aColName)); - aStringToSubstitutes.push_back(std::pair<const char* , OUString >("$precision$", OUString::number(nLen))); - aStringToSubstitutes.push_back(std::pair<const char* , OUString >("$scale$", OUString::number(nScale))); - aStringToSubstitutes.push_back(std::pair<const char* , OUString >("$value$", OStringToOUString(aDefaultValue,RTL_TEXTENCODING_UTF8))); + std::vector< std::pair<const char* , OUString > > aStringToSubstitutes + { + { "$columnname$", aColName }, + { "$precision$", OUString::number(nLen) }, + { "$scale$", OUString::number(nScale) }, + { "$value$", OStringToOUString(aDefaultValue,RTL_TEXTENCODING_UTF8) } + }; const OUString sError( getConnection()->getResources().getResourceStringWithSubstitution( STR_INVALID_COLUMN_DECIMAL_VALUE @@ -2137,7 +2155,6 @@ void ODbaseTable::alterColumn(sal_Int32 index, if(index < 0 || index >= m_xColumns->getCount()) throw IndexOutOfBoundsException(OUString::number(index),*this); - ODbaseTable* pNewTable = nullptr; try { OSL_ENSURE(descriptor.is(),"ODbaseTable::alterColumn: descriptor can not be null!"); @@ -2154,9 +2171,9 @@ void ODbaseTable::alterColumn(sal_Int32 index, OUString sTempName = createTempFile(); - pNewTable = new ODbaseTable(m_pTables,static_cast<ODbaseConnection*>(m_pConnection)); + rtl::Reference<ODbaseTable> pNewTable = new ODbaseTable(m_pTables,static_cast<ODbaseConnection*>(m_pConnection)); Reference<XPropertySet> xHoldTable = pNewTable; - pNewTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),makeAny(sTempName)); + pNewTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),Any(sTempName)); Reference<XAppend> xAppend(pNewTable->getColumns(),UNO_QUERY); OSL_ENSURE(xAppend.is(),"ODbaseTable::alterColumn: No XAppend interface!"); @@ -2205,7 +2222,7 @@ void ODbaseTable::alterColumn(sal_Int32 index, pNewTable->construct(); // copy the data - copyData(pNewTable,0); + copyData(pNewTable.get(),0); // now drop the old one if( DropImpl() ) // we don't want to delete the memo columns too @@ -2243,7 +2260,7 @@ void ODbaseTable::alterColumn(sal_Int32 index, } catch(const Exception&) { - SAL_WARN( "connectivity.drivers","ODbaseTable::alterColumn: Exception occurred!"); + TOOLS_WARN_EXCEPTION( "connectivity.drivers",""); throw; } } @@ -2271,13 +2288,13 @@ void SAL_CALL ODbaseTable::rename( const OUString& newName ) } namespace { - void renameFile(file::OConnection const * _pConenction,const OUString& oldName, - const OUString& newName,const OUString& _sExtension) + void renameFile(file::OConnection const * _pConnection,std::u16string_view oldName, + const OUString& newName, std::u16string_view _sExtension) { - OUString aName = ODbaseTable::getEntry(_pConenction,oldName); + OUString aName = ODbaseTable::getEntry(_pConnection,oldName); if(aName.isEmpty()) { - OUString aIdent = _pConenction->getContent()->getIdentifier()->getContentIdentifier(); + OUString aIdent = _pConnection->getContent()->getIdentifier()->getContentIdentifier(); if ( aIdent.lastIndexOf('/') != (aIdent.getLength()-1) ) aIdent += "/"; aIdent += oldName; @@ -2293,12 +2310,12 @@ namespace { Content aContent(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),Reference<XCommandEnvironment>(), comphelper::getProcessComponentContext()); - Sequence< PropertyValue > aProps( 1 ); - aProps[0].Name = "Title"; - aProps[0].Handle = -1; // n/a - aProps[0].Value <<= sNewName; + Sequence< PropertyValue > aProps{ { "Title", + -1, // n/a + Any(sNewName), + css::beans::PropertyState_DIRECT_VALUE } }; Sequence< Any > aValues; - aContent.executeCommand( "setPropertyValues",makeAny(aProps) ) >>= aValues; + aContent.executeCommand( "setPropertyValues",Any(aProps) ) >>= aValues; if(aValues.hasElements() && aValues[0].hasValue()) throw Exception("setPropertyValues returned non-zero", nullptr); } @@ -2319,7 +2336,7 @@ void ODbaseTable::renameImpl( const OUString& newName ) renameFile(m_pConnection,m_Name,newName,m_pConnection->getExtension()); if ( HasMemoFields() ) { // delete the memo fields - renameFile(m_pConnection,m_Name,newName,"dbt"); + renameFile(m_pConnection,m_Name,newName,u"dbt"); } } @@ -2328,7 +2345,7 @@ void ODbaseTable::addColumn(const Reference< XPropertySet >& _xNewColumn) OUString sTempName = createTempFile(); rtl::Reference xNewTable(new ODbaseTable(m_pTables,static_cast<ODbaseConnection*>(m_pConnection))); - xNewTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),makeAny(sTempName)); + xNewTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),Any(sTempName)); { Reference<XAppend> xAppend(xNewTable->getColumns(),UNO_QUERY); bool bCase = getConnection()->getMetaData()->supportsMixedCaseQuotedIdentifiers(); @@ -2386,7 +2403,7 @@ void ODbaseTable::dropColumn(sal_Int32 _nPos) OUString sTempName = createTempFile(); rtl::Reference xNewTable(new ODbaseTable(m_pTables,static_cast<ODbaseConnection*>(m_pConnection))); - xNewTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),makeAny(sTempName)); + xNewTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),Any(sTempName)); { Reference<XAppend> xAppend(xNewTable->getColumns(),UNO_QUERY); bool bCase = getConnection()->getMetaData()->supportsMixedCaseQuotedIdentifiers(); @@ -2440,16 +2457,14 @@ OUString ODbaseTable::createTempFile() if ( aIdent.lastIndexOf('/') != (aIdent.getLength()-1) ) aIdent += "/"; - OUString sTempName(aIdent); OUString sExt("." + m_pConnection->getExtension()); - OUString sName(m_Name); - TempFile aTempFile(sName, true, &sExt, &sTempName); - if(!aTempFile.IsValid()) + OUString aTempFileURL = utl::CreateTempURL(m_Name, true, sExt, &aIdent); + if(aTempFileURL.isEmpty()) getConnection()->throwGenericSQLException(STR_COULD_NOT_ALTER_TABLE, *this); INetURLObject aURL; aURL.SetSmartProtocol(INetProtocol::File); - aURL.SetURL(aTempFile.GetURL()); + aURL.SetURL(aTempFileURL); OUString sNewName(aURL.getName().copy(0, aURL.getName().getLength() - sExt.getLength())); @@ -2499,7 +2514,7 @@ void ODbaseTable::copyData(ODbaseTable* _pNewTable,sal_Int32 _nPos) } } } - bOk = _pNewTable->InsertRow(*aInsertRow,_pNewTable->m_xColumns.get()); + bOk = _pNewTable->InsertRow(*aInsertRow, _pNewTable->m_xColumns.get()); SAL_WARN_IF(!bOk, "connectivity.drivers", "Row could not be inserted!"); } else @@ -2646,7 +2661,7 @@ bool ODbaseTable::ReadMemo(std::size_t nBlockNo, ORowSetValue& aVariable) } while (!bReady && !m_pMemoStream->eof()); - aVariable = OStringToOUString(aBStr.makeStringAndClear(), + aVariable = OStringToOUString(aBStr, m_eEncoding); } break; @@ -2680,7 +2695,7 @@ bool ODbaseTable::ReadMemo(std::size_t nBlockNo, ORowSetValue& aVariable) //pad it out with ' ' to expected length on short read sal_Int32 nRequested = sal::static_int_cast<sal_Int32>(nLength); comphelper::string::padToLength(aBuffer, nRequested, ' '); - aVariable = OStringToOUString(aBuffer.makeStringAndClear(), m_eEncoding); + aVariable = OStringToOUString(aBuffer, m_eEncoding); } // if ( bIsText ) else { @@ -2719,7 +2734,7 @@ bool ODbaseTable::WriteBuffer() OSL_ENSURE(m_nFilePos >= 1,"SdbDBFCursor::FileFetchRow: invalid record position"); // position on desired record: - std::size_t nPos = m_aHeader.headerLength + static_cast<long>(m_nFilePos-1) * m_aHeader.recordLength; + std::size_t nPos = m_aHeader.headerLength + static_cast<tools::Long>(m_nFilePos-1) * m_aHeader.recordLength; m_pFileStream->Seek(nPos); return m_pFileStream->WriteBytes(m_pBuffer.get(), m_aHeader.recordLength) > 0; } diff --git a/connectivity/source/drivers/dbase/DTables.cxx b/connectivity/source/drivers/dbase/DTables.cxx index 1d922969493f..3424801e3842 100644 --- a/connectivity/source/drivers/dbase/DTables.cxx +++ b/connectivity/source/drivers/dbase/DTables.cxx @@ -32,7 +32,6 @@ #include <strings.hrc> #include <connectivity/dbexception.hxx> -using namespace ::comphelper; using namespace connectivity; using namespace connectivity::dbase; using namespace connectivity::file; @@ -40,17 +39,15 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::lang; using namespace ::com::sun::star::container; sdbcx::ObjectType ODbaseTables::createObject(const OUString& _rName) { - ODbaseTable* pRet = new ODbaseTable(this, static_cast<ODbaseConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()), + rtl::Reference<ODbaseTable> pRet = new ODbaseTable(this, static_cast<ODbaseConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()), _rName,"TABLE"); - sdbcx::ObjectType xRet = pRet; pRet->construct(); - return xRet; + return pRet; } void ODbaseTables::impl_refresh( ) @@ -66,10 +63,10 @@ Reference< XPropertySet > ODbaseTables::createDescriptor() // XAppend sdbcx::ObjectType ODbaseTables::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) { - auto pTable = comphelper::getUnoTunnelImplementation<ODbaseTable>(descriptor); + auto pTable = dynamic_cast<ODbaseTable*>(descriptor.get()); if(pTable) { - pTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),makeAny(_rForName)); + pTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),Any(_rForName)); try { if(!pTable->CreateImpl()) @@ -91,7 +88,7 @@ sdbcx::ObjectType ODbaseTables::appendObject( const OUString& _rForName, const R // XDrop void ODbaseTables::dropObject(sal_Int32 _nPos, const OUString& _sElementName) { - Reference< XUnoTunnel> xTunnel; + Reference< XInterface > xTunnel; try { xTunnel.set(getObject(_nPos),UNO_QUERY); @@ -104,7 +101,7 @@ void ODbaseTables::dropObject(sal_Int32 _nPos, const OUString& _sElementName) if ( xTunnel.is() ) { - ODbaseTable* pTable = reinterpret_cast< ODbaseTable* >( xTunnel->getSomething(ODbaseTable::getUnoTunnelId()) ); + ODbaseTable* pTable = dynamic_cast<ODbaseTable*>(xTunnel.get()); if(pTable) pTable->DropImpl(); } diff --git a/connectivity/source/drivers/dbase/dindexnode.cxx b/connectivity/source/drivers/dbase/dindexnode.cxx index 1ac10800f0a9..d091335f5495 100644 --- a/connectivity/source/drivers/dbase/dindexnode.cxx +++ b/connectivity/source/drivers/dbase/dindexnode.cxx @@ -26,6 +26,7 @@ #include <algorithm> #include <memory> +#include <utility> using namespace connectivity; @@ -38,10 +39,10 @@ ONDXKey::ONDXKey() { } -ONDXKey::ONDXKey(const ORowSetValue& rVal, sal_Int32 eType, sal_uInt32 nRec) +ONDXKey::ONDXKey(ORowSetValue aVal, sal_Int32 eType, sal_uInt32 nRec) : ONDXKey_BASE(eType) , nRecord(nRec) - , xValue(rVal) + , xValue(std::move(aVal)) { } @@ -482,7 +483,7 @@ void ONDXPage::Merge(sal_uInt16 nParentNodePos, const ONDXPagePtr& xPage) nMaxNodes_2 = nMaxNodes / 2; // Determine if page is right or left neighbour - bool bRight = ((*xPage)[0].GetKey() > (*this)[0].GetKey()); // sal_True, whenn xPage the right side is + bool bRight = ((*xPage)[0].GetKey() > (*this)[0].GetKey()); // true when xPage is at the right side sal_uInt16 nNewCount = (*xPage).Count() + Count(); if (IsLeaf()) @@ -701,7 +702,7 @@ void ONDXNode::Write(SvStream &rStream, const ONDXPage& rPage) const rStream.WriteBytes(&buf[0], sizeof(double)); } else - rStream.WriteDouble( static_cast<double>(aKey.getValue()) ); + rStream.WriteDouble( aKey.getValue().getDouble() ); } else { @@ -710,7 +711,7 @@ void ONDXNode::Write(SvStream &rStream, const ONDXPage& rPage) const memset(&pBuf[0], 0x20, nLen); if (!aKey.getValue().isNull()) { - OUString sValue = aKey.getValue(); + OUString sValue = aKey.getValue().getString(); OString aText(OUStringToOString(sValue, rIndex.m_pTable->getConnection()->getTextEncoding())); strncpy(reinterpret_cast<char *>(&pBuf[0]), aText.getStr(), std::min<size_t>(nLen, aText.getLength())); @@ -760,12 +761,12 @@ int ONDXKey::Compare(const ONDXKey& rKey) const } else if (IsText(getDBType())) { - nRes = getValue().getString().compareTo(rKey.getValue()); + nRes = getValue().getString().compareTo(rKey.getValue().getString()); } else { - double m = getValue(); - double n = rKey.getValue(); + double m = getValue().getDouble(); + double n = rKey.getValue().getDouble(); nRes = (m > n) ? 1 : ( m < n) ? -1 : 0; } diff --git a/connectivity/source/drivers/evoab2/EApi.cxx b/connectivity/source/drivers/evoab2/EApi.cxx index 56a957fabb63..9ec8e0d44e32 100644 --- a/connectivity/source/drivers/evoab2/EApi.cxx +++ b/connectivity/source/drivers/evoab2/EApi.cxx @@ -21,24 +21,14 @@ #define DECLARE_FN_POINTERS 1 #include "EApi.h" static const char *eBookLibNames[] = { + "libebook-1.2.so.21", // evolution-data-server 3.45.2+ "libebook-1.2.so.20", // evolution-data-server 3.33.2+ "libebook-1.2.so.19", // evolution-data-server 3.24+ - "libebook-1.2.so.16", - "libebook-1.2.so.15", - "libebook-1.2.so.14", // bumped again (evolution-3.6) - "libebook-1.2.so.13", // bumped again (evolution-3.4) - "libebook-1.2.so.12", // bumped again - "libebook-1.2.so.10", // bumped again - "libebook-1.2.so.9", // evolution-2.8 - "libebook-1.2.so.5", // evolution-2.4 and 2.6+ - "libebook-1.2.so.3", // evolution-2.2 - "libebook.so.8" // evolution-2.0 + "libebook-1.2.so.16" }; typedef void (*SymbolFunc) (); -#define SYM_MAP(a) { #a, reinterpret_cast<SymbolFunc *>(&a) } - namespace { struct ApiMap @@ -51,70 +41,48 @@ struct ApiMap const ApiMap aCommonApiMap[] = { - SYM_MAP( eds_check_version ), - SYM_MAP( e_contact_field_name ), - SYM_MAP( e_contact_get ), - SYM_MAP( e_contact_get_type ), - SYM_MAP( e_contact_field_id ), - SYM_MAP( e_book_new ), - SYM_MAP( e_book_open ), - SYM_MAP( e_book_get_source ), - SYM_MAP( e_book_get_contacts ), - SYM_MAP( e_book_query_field_test ), - SYM_MAP( e_book_query_and ), - SYM_MAP( e_book_query_or ), - SYM_MAP( e_book_query_not ), - SYM_MAP( e_book_query_ref ), - SYM_MAP( e_book_query_unref ), - SYM_MAP( e_book_query_from_string ), - SYM_MAP( e_book_query_to_string ), - SYM_MAP( e_book_query_field_exists ) -}; - -//< 3.6 api -const ApiMap aOldApiMap[] = -{ - SYM_MAP( e_book_get_addressbooks ), - SYM_MAP( e_book_get_uri ), - SYM_MAP( e_book_authenticate_user ), - SYM_MAP( e_source_group_peek_base_uri), - SYM_MAP( e_source_peek_name ), - SYM_MAP( e_source_get_property ), - SYM_MAP( e_source_list_peek_groups ), - SYM_MAP( e_source_group_peek_sources ) + { "eds_check_version", reinterpret_cast<SymbolFunc *>(&eds_check_version) }, + { "e_contact_field_name", reinterpret_cast<SymbolFunc *>(&e_contact_field_name) }, + { "e_contact_get", reinterpret_cast<SymbolFunc *>(&e_contact_get) }, + { "e_contact_get_type", reinterpret_cast<SymbolFunc *>(&e_contact_get_type) }, + { "e_contact_field_id", reinterpret_cast<SymbolFunc *>(&e_contact_field_id) }, + { "e_book_new", reinterpret_cast<SymbolFunc *>(&e_book_new) }, + { "e_book_open", reinterpret_cast<SymbolFunc *>(&e_book_open) }, + { "e_book_get_source", reinterpret_cast<SymbolFunc *>(&e_book_get_source) }, + { "e_book_get_contacts", reinterpret_cast<SymbolFunc *>(&e_book_get_contacts) }, + { "e_book_query_field_test", reinterpret_cast<SymbolFunc *>(&e_book_query_field_test) }, + { "e_book_query_and", reinterpret_cast<SymbolFunc *>(&e_book_query_and) }, + { "e_book_query_or", reinterpret_cast<SymbolFunc *>(&e_book_query_or) }, + { "e_book_query_not", reinterpret_cast<SymbolFunc *>(&e_book_query_not) }, + { "e_book_query_ref", reinterpret_cast<SymbolFunc *>(&e_book_query_ref) }, + { "e_book_query_unref", reinterpret_cast<SymbolFunc *>(&e_book_query_unref) }, + { "e_book_query_from_string", reinterpret_cast<SymbolFunc *>(&e_book_query_from_string) }, + { "e_book_query_to_string", reinterpret_cast<SymbolFunc *>(&e_book_query_to_string) }, + { "e_book_query_field_exists", reinterpret_cast<SymbolFunc *>(&e_book_query_field_exists) } }; -//>= 3.6 api const ApiMap aNewApiMap[] = { - SYM_MAP( e_source_registry_list_sources ), - SYM_MAP( e_source_registry_new_sync ), - SYM_MAP( e_source_has_extension ), - SYM_MAP( e_source_get_extension ), - SYM_MAP( e_source_backend_get_backend_name ), - SYM_MAP( e_source_get_display_name ), - SYM_MAP( e_source_get_uid ), - SYM_MAP( e_source_registry_ref_source), - SYM_MAP( e_client_open_sync ), - SYM_MAP( e_client_get_source ), - SYM_MAP( e_book_client_get_contacts_sync ), - SYM_MAP( e_client_util_free_object_slist ) -}; - -//== indirect read access (3.6 only) -const ApiMap aClientApiMap36[] = -{ - SYM_MAP( e_book_client_new ) + { "e_source_registry_list_sources", reinterpret_cast<SymbolFunc *>(&e_source_registry_list_sources) }, + { "e_source_registry_new_sync", reinterpret_cast<SymbolFunc *>(&e_source_registry_new_sync) }, + { "e_source_has_extension", reinterpret_cast<SymbolFunc *>(&e_source_has_extension) }, + { "e_source_get_extension", reinterpret_cast<SymbolFunc *>(&e_source_get_extension) }, + { "e_source_backend_get_backend_name", reinterpret_cast<SymbolFunc *>(&e_source_backend_get_backend_name) }, + { "e_source_get_display_name", reinterpret_cast<SymbolFunc *>(&e_source_get_display_name) }, + { "e_source_get_uid", reinterpret_cast<SymbolFunc *>(&e_source_get_uid) }, + { "e_source_registry_ref_source", reinterpret_cast<SymbolFunc *>(&e_source_registry_ref_source) }, + { "e_client_open_sync", reinterpret_cast<SymbolFunc *>(&e_client_open_sync) }, + { "e_client_get_source", reinterpret_cast<SymbolFunc *>(&e_client_get_source) }, + { "e_book_client_get_contacts_sync", reinterpret_cast<SymbolFunc *>(&e_book_client_get_contacts_sync) }, + { "e_client_util_free_object_slist", reinterpret_cast<SymbolFunc *>(&e_client_util_free_object_slist) } }; //>= direct read access API (>= 3.8) const ApiMap aClientApiMap38[] = { - SYM_MAP( e_book_client_connect_direct_sync ) + { "e_book_client_connect_direct_sync", reinterpret_cast<SymbolFunc *>(&e_book_client_connect_direct_sync) } }; -#undef SYM_MAP - template<size_t N> static bool tryLink( osl::Module &rModule, const char *pName, const ApiMap (&pMap)[N]) { @@ -144,33 +112,14 @@ bool EApiInit() if (tryLink( aModule, eBookLibNames[ j ], aCommonApiMap)) { - if (eds_check_version( 3, 6, 0 ) != nullptr) + if (tryLink( aModule, eBookLibNames[ j ], aNewApiMap)) { - if (tryLink( aModule, eBookLibNames[ j ], aOldApiMap)) + if (tryLink( aModule, eBookLibNames[ j ], aClientApiMap38)) { aModule.release(); return true; } } - else if (tryLink( aModule, eBookLibNames[ j ], aNewApiMap)) - { - if (eds_check_version( 3, 7, 6 ) != nullptr) - { - if (tryLink( aModule, eBookLibNames[ j ], aClientApiMap36)) - { - aModule.release(); - return true; - } - } - else - { - if (tryLink( aModule, eBookLibNames[ j ], aClientApiMap38)) - { - aModule.release(); - return true; - } - } - } } } fprintf( stderr, "Can find no compliant libebook client libraries\n" ); diff --git a/connectivity/source/drivers/evoab2/EApi.h b/connectivity/source/drivers/evoab2/EApi.h index 8c05f95fa2ce..a33bf9721de6 100644 --- a/connectivity/source/drivers/evoab2/EApi.h +++ b/connectivity/source/drivers/evoab2/EApi.h @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_EAPI_H -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_EAPI_H +#pragma once #include <glib-object.h> // Initializes the API below, returns false if not available @@ -147,7 +146,7 @@ EAPI_EXTERN const gchar* (*eds_check_version) (guint required_major, guint requi EAPI_EXTERN const gchar* (*e_source_get_uid) (ESource *source); EAPI_EXTERN ESource* (*e_source_registry_ref_source) (ESourceRegistry *registry, const gchar *uid); EAPI_EXTERN EBookClient* (*e_book_client_new) (ESource *source, GError **error); -EAPI_EXTERN EBookClient* (*e_book_client_connect_direct_sync) (ESourceRegistry *registry, ESource *source, GCancellable *cancellable, GError **error); +EAPI_EXTERN EBookClient* (*e_book_client_connect_direct_sync) (ESourceRegistry *registry, ESource *source, guint32 wait_for_connected_seconds, GCancellable *cancellable, GError **error); EAPI_EXTERN gboolean (*e_client_open_sync) (EClient *client, gboolean only_if_exists, GCancellable *cancellable, GError **error); EAPI_EXTERN ESource* (*e_client_get_source) (EClient *client); EAPI_EXTERN gboolean (*e_book_client_get_contacts_sync) (EBookClient *client, const gchar *sexp, GSList **contacts, GCancellable *cancellable, GError **error); @@ -157,6 +156,7 @@ ESourceRegistry *get_e_source_registry(); bool isSourceBackend(ESource *pSource, const char *backendname); G_END_DECLS -#endif + +inline void object_unref(gpointer data, gpointer) { g_object_unref(data); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/evoab2/NCatalog.cxx b/connectivity/source/drivers/evoab2/NCatalog.cxx index fb010b8dce5d..d16a6377d1d1 100644 --- a/connectivity/source/drivers/evoab2/NCatalog.cxx +++ b/connectivity/source/drivers/evoab2/NCatalog.cxx @@ -26,11 +26,8 @@ using namespace connectivity::evoab; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; OEvoabCatalog::OEvoabCatalog(OEvoabConnection* _pCon) : connectivity::sdbcx::OCatalog(_pCon) @@ -67,9 +64,8 @@ Reference< XNameAccess > SAL_CALL OEvoabCatalog::getTables( ) try { - if (!m_pTables) { - refreshTables(); - } + if (!m_pTables) + refreshTables(); } catch( const RuntimeException& ) { diff --git a/connectivity/source/drivers/evoab2/NCatalog.hxx b/connectivity/source/drivers/evoab2/NCatalog.hxx index d883d53c28a2..b2bd8084474c 100644 --- a/connectivity/source/drivers/evoab2/NCatalog.hxx +++ b/connectivity/source/drivers/evoab2/NCatalog.hxx @@ -17,15 +17,12 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NCATALOG_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NCATALOG_HXX +#pragma once #include <sdbcx/VCatalog.hxx> -namespace connectivity +namespace connectivity::evoab { - namespace evoab - { class OEvoabConnection; class OEvoabCatalog : public connectivity::sdbcx::OCatalog { @@ -41,8 +38,6 @@ namespace connectivity virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTables( ) override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NCATALOG_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/evoab2/NColumns.cxx b/connectivity/source/drivers/evoab2/NColumns.cxx index 378e2af77634..99fce8f3bf46 100644 --- a/connectivity/source/drivers/evoab2/NColumns.cxx +++ b/connectivity/source/drivers/evoab2/NColumns.cxx @@ -25,12 +25,8 @@ using namespace connectivity::sdbcx; using namespace connectivity; -using namespace ::comphelper; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; using namespace connectivity::evoab; @@ -55,7 +51,7 @@ sdbcx::ObjectType OEvoabColumns::createObject(const OUString& _rName) { if (xRow->getString(4) == _rName) { - OColumn* pRet = new OColumn( + xRet = new OColumn( _rName, xRow->getString(6), xRow->getString(13), @@ -71,7 +67,6 @@ sdbcx::ObjectType OEvoabColumns::createObject(const OUString& _rName) sCatalogName, sSchemaName, sTableName); - xRet = pRet; break; } } diff --git a/connectivity/source/drivers/evoab2/NColumns.hxx b/connectivity/source/drivers/evoab2/NColumns.hxx index d3038aaa62af..f768c51bb046 100644 --- a/connectivity/source/drivers/evoab2/NColumns.hxx +++ b/connectivity/source/drivers/evoab2/NColumns.hxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NCOLUMNS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NCOLUMNS_HXX +#pragma once #include "NTable.hxx" #include <connectivity/sdbcx/VCollection.hxx> -namespace connectivity +namespace connectivity::evoab { - namespace evoab - { class OEvoabColumns final : public sdbcx::OCollection { OEvoabTable* m_pTable; @@ -42,9 +39,6 @@ namespace connectivity m_pTable(_pTable) { } }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NCOLUMNS_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/evoab2/NConnection.cxx b/connectivity/source/drivers/evoab2/NConnection.cxx index d586d6ba2df1..66fc7ecb6511 100644 --- a/connectivity/source/drivers/evoab2/NConnection.cxx +++ b/connectivity/source/drivers/evoab2/NConnection.cxx @@ -24,6 +24,7 @@ #include "NPreparedStatement.hxx" #include "NStatement.hxx" #include <connectivity/dbexception.hxx> +#include <rtl/ref.hxx> #include <rtl/ustring.hxx> #include <sal/log.hxx> @@ -35,7 +36,6 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::lang; OEvoabConnection::OEvoabConnection(OEvoabDriver const & _rDriver) : m_rDriver(_rDriver) @@ -117,8 +117,7 @@ css::uno::Reference< XTablesSupplier > OEvoabConnection::createCatalog() Reference< XTablesSupplier > xTab = m_xCatalog; if(!xTab.is()) { - OEvoabCatalog *pCat = new OEvoabCatalog(this); - xTab = pCat; + xTab = new OEvoabCatalog(this); m_xCatalog = xTab; } return xTab; @@ -129,10 +128,8 @@ Reference< XStatement > SAL_CALL OEvoabConnection::createStatement( ) ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OConnection_BASE::rBHelper.bDisposed); - OStatement* pStmt = new OStatement(this); - - Reference< XStatement > xStmt = pStmt; - m_aStatements.push_back(WeakReferenceHelper(*pStmt)); + Reference< XStatement > xStmt = new OStatement(this); + m_aStatements.push_back(WeakReferenceHelper(xStmt)); return xStmt; } @@ -141,12 +138,11 @@ Reference< XPreparedStatement > SAL_CALL OEvoabConnection::prepareStatement( con ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OConnection_BASE::rBHelper.bDisposed); - OEvoabPreparedStatement* pStmt = new OEvoabPreparedStatement( this ); - Reference< XPreparedStatement > xStmt = pStmt; + rtl::Reference<OEvoabPreparedStatement> pStmt = new OEvoabPreparedStatement( this ); pStmt->construct( sql ); m_aStatements.push_back(WeakReferenceHelper(*pStmt)); - return xStmt; + return pStmt; } Reference< XPreparedStatement > SAL_CALL OEvoabConnection::prepareCall( const OUString& /*sql*/ ) diff --git a/connectivity/source/drivers/evoab2/NConnection.hxx b/connectivity/source/drivers/evoab2/NConnection.hxx index 2ba2a8db7ea8..8dd8714bc2fe 100644 --- a/connectivity/source/drivers/evoab2/NConnection.hxx +++ b/connectivity/source/drivers/evoab2/NConnection.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NCONNECTION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NCONNECTION_HXX +#pragma once #include "NDriver.hxx" #include <com/sun/star/sdbc/SQLWarning.hpp> @@ -31,10 +30,7 @@ #include <osl/module.h> #include "EApi.h" -namespace connectivity -{ - namespace evoab - { +namespace connectivity::evoab { namespace SDBCAddress { typedef enum { @@ -64,7 +60,6 @@ namespace connectivity /// @throws css::sdbc::SQLException void construct(const OUString& _rUrl,const css::uno::Sequence< css::beans::PropertyValue >& _rInfo ); - OString const & getPassword() const { return m_aPassword; } void setPassword( OString const & aStr ) { m_aPassword = aStr; } // own methods const OEvoabDriver& getDriver() const { return m_rDriver; } @@ -105,8 +100,6 @@ namespace connectivity virtual css::uno::Any SAL_CALL getWarnings( ) override; virtual void SAL_CALL clearWarnings( ) override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NCONNECTION_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx b/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx index 1f429d9850ad..110d01feb213 100644 --- a/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx +++ b/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx @@ -23,18 +23,18 @@ #include <connectivity/dbexception.hxx> #include <connectivity/FValue.hxx> #include <com/sun/star/sdbc/ColumnSearch.hpp> +#include <rtl/ref.hxx> #include <cstddef> #include <string.h> +#include <string_view> + #include "EApi.h" using namespace connectivity::evoab; using namespace connectivity; using namespace com::sun::star::uno; -using namespace com::sun::star::lang; -using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; -using namespace com::sun::star::sdbcx; namespace { @@ -167,7 +167,7 @@ namespace connectivity::evoab return nType == G_TYPE_STRING ? DataType::VARCHAR : DataType::BIT; } - guint findEvoabField(const OUString& aColName) + guint findEvoabField(std::u16string_view aColName) { guint nRet = guint(-1); bool bFound = false; @@ -250,8 +250,14 @@ OEvoabDatabaseMetaData::~OEvoabDatabaseMetaData() } -ODatabaseMetaDataResultSet::ORows OEvoabDatabaseMetaData::getColumnRows( const OUString& columnNamePattern ) +Reference< XResultSet > SAL_CALL OEvoabDatabaseMetaData::getColumns( + const Any& /*catalog*/, const OUString& /*schemaPattern*/, const OUString& /*tableNamePattern*/, + const OUString& columnNamePattern ) { + // this returns an empty resultset where the column-names are already set + // in special the metadata of the resultset already returns the right columns + rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eColumns ); + ODatabaseMetaDataResultSet::ORows aRows; ODatabaseMetaDataResultSet::ORow aRow(19); @@ -275,7 +281,7 @@ ODatabaseMetaDataResultSet::ORows OEvoabDatabaseMetaData::getColumnRows( const O aRow[11] = new ORowSetValueDecorator(s_nNULLABLE); // REMARKS aRow[12] = ODatabaseMetaDataResultSet::getEmptyValue(); - // COULUMN_DEF, not used + // COLUMN_DEF, not used aRow[13] = ODatabaseMetaDataResultSet::getEmptyValue(); // SQL_DATA_TYPE, not used aRow[14] = ODatabaseMetaDataResultSet::getEmptyValue(); @@ -291,7 +297,7 @@ ODatabaseMetaDataResultSet::ORows OEvoabDatabaseMetaData::getColumnRows( const O ::osl::MutexGuard aGuard( m_aMutex ); initFields(); - for (sal_Int32 i = 0; i < static_cast<sal_Int32>(nFields); i++) + for (guint i = 0; i < nFields; i++) { if( match( columnNamePattern, getFieldName( i ), '\0' ) ) { @@ -301,12 +307,14 @@ ODatabaseMetaDataResultSet::ORows OEvoabDatabaseMetaData::getColumnRows( const O // COLUMN_NAME aRow[4] = new ORowSetValueDecorator( getFieldName( i ) ); // ORDINAL_POSITION - aRow[17] = new ORowSetValueDecorator( i ); + aRow[17] = new ORowSetValueDecorator( sal_Int32(i) ); aRows.push_back( aRow ); } } - return aRows ; + pResultSet->setRows(std::move(aRows)); + + return pResultSet; } OUString OEvoabDatabaseMetaData::impl_getCatalogSeparator_throw( ) @@ -978,27 +986,23 @@ Reference< XResultSet > SAL_CALL OEvoabDatabaseMetaData::getTableTypes( ) /* Don't need to change as evoab driver supports only table */ // there exists no possibility to get table types so we have to check - static const OUStringLiteral sTableTypes[] = + static const std::u16string_view sTableTypes[] = { - "TABLE" // Currently we only support a 'TABLE' nothing more complex + u"TABLE" // Currently we only support a 'TABLE' nothing more complex }; - ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTableTypes); - Reference< XResultSet > xRef = pResult; + rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTableTypes); // here we fill the rows which should be visible when ask for data from the resultset returned here + auto nNbTypes = std::size(sTableTypes); ODatabaseMetaDataResultSet::ORows aRows; - for(std::size_t i=0;i < SAL_N_ELEMENTS(sTableTypes);++i) + for(std::size_t i=0;i < nNbTypes;++i) { - ODatabaseMetaDataResultSet::ORow aRow; - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(new ORowSetValueDecorator(OUString(sTableTypes[i]))); - // bound row - aRows.push_back(aRow); + aRows.push_back( { ODatabaseMetaDataResultSet::getEmptyValue(), new ORowSetValueDecorator(OUString(sTableTypes[i])) }); } // here we set the rows at the resultset - pResult->setRows(aRows); - return xRef; + pResult->setRows(std::move(aRows)); + return pResult; } Reference< XResultSet > OEvoabDatabaseMetaData::impl_getTypeInfo_throw( ) @@ -1007,34 +1011,33 @@ Reference< XResultSet > OEvoabDatabaseMetaData::impl_getTypeInfo_throw( ) * Return the proper type information required by evo driver */ - ODatabaseMetaDataResultSet* pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTypeInfo); + rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTypeInfo); - Reference< XResultSet > xResultSet = pResultSet; static ODatabaseMetaDataResultSet::ORows aRows = []() { ODatabaseMetaDataResultSet::ORows tmp; - ODatabaseMetaDataResultSet::ORow aRow; - aRow.reserve(19); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(new ORowSetValueDecorator(OUString("VARCHAR"))); - aRow.push_back(new ORowSetValueDecorator(DataType::VARCHAR)); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(s_nCHAR_OCTET_LENGTH))); - aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue()); - aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - // aRow.push_back(new ORowSetValueDecorator((sal_Int32)ColumnValue::NULLABLE)); - aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(ColumnSearch::FULL))); - aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(10))); + ODatabaseMetaDataResultSet::ORow aRow + { + ODatabaseMetaDataResultSet::getEmptyValue() , + new ORowSetValueDecorator(OUString("VARCHAR")) , + new ORowSetValueDecorator(DataType::VARCHAR) , + new ORowSetValueDecorator(sal_Int32(s_nCHAR_OCTET_LENGTH)) , + ODatabaseMetaDataResultSet::getQuoteValue() , + ODatabaseMetaDataResultSet::getQuoteValue() , + ODatabaseMetaDataResultSet::getEmptyValue() , + ODatabaseMetaDataResultSet::get1Value() , + ODatabaseMetaDataResultSet::get1Value() , + new ORowSetValueDecorator(sal_Int32(ColumnSearch::FULL)) , + ODatabaseMetaDataResultSet::get1Value() , + ODatabaseMetaDataResultSet::get0Value() , + ODatabaseMetaDataResultSet::get0Value() , + ODatabaseMetaDataResultSet::getEmptyValue() , + ODatabaseMetaDataResultSet::get0Value() , + ODatabaseMetaDataResultSet::get0Value() , + ODatabaseMetaDataResultSet::getEmptyValue() , + ODatabaseMetaDataResultSet::getEmptyValue() , + new ORowSetValueDecorator(sal_Int32(10)) + }; tmp.push_back(aRow); @@ -1044,23 +1047,10 @@ Reference< XResultSet > OEvoabDatabaseMetaData::impl_getTypeInfo_throw( ) tmp.push_back(aRow); return tmp; }(); - pResultSet->setRows(aRows); - return xResultSet; + pResultSet->setRows(std::move(aRows)); + return pResultSet; } -Reference< XResultSet > SAL_CALL OEvoabDatabaseMetaData::getColumns( - const Any& /*catalog*/, const OUString& /*schemaPattern*/, const OUString& /*tableNamePattern*/, - const OUString& columnNamePattern ) -{ - // this returns an empty resultset where the column-names are already set - // in special the metadata of the resultset already returns the right columns - ODatabaseMetaDataResultSet* pResultSet = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eColumns ); - Reference< XResultSet > xResultSet = pResultSet; - pResultSet->setRows( getColumnRows( columnNamePattern ) ); - return xResultSet; -} - - bool isSourceBackend(ESource *pSource, const char *backendname) { if (!pSource || !e_source_has_extension (pSource, E_SOURCE_EXTENSION_ADDRESS_BOOK)) @@ -1076,136 +1066,82 @@ Reference< XResultSet > SAL_CALL OEvoabDatabaseMetaData::getTables( { ::osl::MutexGuard aGuard( m_aMutex ); - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTableTypes); - Reference< XResultSet > xRef = pResult; + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTables); // check if any type is given // when no types are given then we have to return all tables e.g. TABLE - const OUString aTable("TABLE"); + static constexpr OUString aTable(u"TABLE"_ustr); bool bTableFound = true; sal_Int32 nLength = types.getLength(); if(nLength) - { - bTableFound = false; - - const OUString* pBegin = types.getConstArray(); - const OUString* pEnd = pBegin + nLength; - for(;pBegin != pEnd;++pBegin) - { - if(*pBegin == aTable) - { - bTableFound = true; - break; - } - } - } - if(!bTableFound) - return xRef; - - ODatabaseMetaDataResultSet::ORows aRows; - - if (eds_check_version(3, 6, 0) == nullptr) { - GList *pSources = e_source_registry_list_sources(get_e_source_registry(), E_SOURCE_EXTENSION_ADDRESS_BOOK); + bTableFound = false; - for (GList* liter = pSources; liter; liter = liter->next) + const OUString* pBegin = types.getConstArray(); + const OUString* pEnd = pBegin + nLength; + for(;pBegin != pEnd;++pBegin) { - ESource *pSource = E_SOURCE (liter->data); - bool can = false; - switch (m_pConnection->getSDBCAddressType()) + if(*pBegin == aTable) { - case SDBCAddress::EVO_GWISE: - can = isSourceBackend( pSource, "groupwise"); // not supported in evo/eds 3.6.x+, somehow - break; - case SDBCAddress::EVO_LOCAL: - can = isSourceBackend( pSource, "local"); - break; - case SDBCAddress::EVO_LDAP: - can = isSourceBackend( pSource, "ldap"); - break; - case SDBCAddress::Unknown: - can = true; - break; + bTableFound = true; + break; } - if (!can) - continue; - - OUString aHumanName = OStringToOUString( e_source_get_display_name( pSource ), - RTL_TEXTENCODING_UTF8 ); - OUString aUID = OStringToOUString( e_source_get_uid( pSource ), - RTL_TEXTENCODING_UTF8 ); - ODatabaseMetaDataResultSet::ORow aRow{ - ORowSetValueDecoratorRef(), - ORowSetValueDecoratorRef(), - ORowSetValueDecoratorRef(), - new ORowSetValueDecorator(aHumanName), //tablename - new ORowSetValueDecorator(aTable), - new ORowSetValueDecorator(aUID)}; //comment - //I'd prefer to swap the comment and the human name and - //just use e_source_registry_ref_source(get_e_source_registry(), aUID); - //in open book rather than search for the name again - aRows.push_back(aRow); } - - g_list_foreach (pSources, reinterpret_cast<GFunc>(g_object_unref), nullptr); - g_list_free (pSources); } - else - { - ESourceList *pSourceList; - if( !e_book_get_addressbooks (&pSourceList, nullptr) ) - pSourceList = nullptr; + if(!bTableFound) + return pResult; - GSList *g; - for( g = e_source_list_peek_groups( pSourceList ); g; g = g->next) - { - GSList *s; - const char *p = e_source_group_peek_base_uri(E_SOURCE_GROUP(g->data)); + ODatabaseMetaDataResultSet::ORows aRows; - switch (m_pConnection->getSDBCAddressType()) { + GList *pSources = e_source_registry_list_sources(get_e_source_registry(), E_SOURCE_EXTENSION_ADDRESS_BOOK); + + for (GList* liter = pSources; liter; liter = liter->next) + { + ESource *pSource = E_SOURCE (liter->data); + bool can = false; + switch (m_pConnection->getSDBCAddressType()) + { case SDBCAddress::EVO_GWISE: - if ( !strncmp( "groupwise://", p, 11 )) - break; - else - continue; + can = isSourceBackend( pSource, "groupwise"); // not supported in evo/eds 3.6.x+, somehow + break; case SDBCAddress::EVO_LOCAL: - if ( !strncmp( "file://", p, 6 ) || - !strncmp( "local://", p, 6 ) ) - break; - else - continue; + can = isSourceBackend( pSource, "local"); + break; case SDBCAddress::EVO_LDAP: - if ( !strncmp( "ldap://", p, 6 )) - break; - else - continue; + can = isSourceBackend( pSource, "ldap"); + break; case SDBCAddress::Unknown: + can = true; break; - } - for (s = e_source_group_peek_sources (E_SOURCE_GROUP (g->data)); s; s = s->next) - { - ESource *pSource = E_SOURCE (s->data); - - OUString aName = OStringToOUString( e_source_peek_name( pSource ), - RTL_TEXTENCODING_UTF8 ); - - ODatabaseMetaDataResultSet::ORow aRow{ - ORowSetValueDecoratorRef(), - ORowSetValueDecoratorRef(), - ORowSetValueDecoratorRef(), - new ORowSetValueDecorator(aName), - new ORowSetValueDecorator(aTable), - ODatabaseMetaDataResultSet::getEmptyValue()}; - aRows.push_back(aRow); - } } + if (!can) + continue; + + OUString aHumanName = OStringToOUString( e_source_get_display_name( pSource ), + RTL_TEXTENCODING_UTF8 ); + OUString aUID = OStringToOUString( e_source_get_uid( pSource ), + RTL_TEXTENCODING_UTF8 ); + ODatabaseMetaDataResultSet::ORow aRow{ + ORowSetValueDecoratorRef(), + ORowSetValueDecoratorRef(), + ORowSetValueDecoratorRef(), + new ORowSetValueDecorator(aHumanName), //tablename + new ORowSetValueDecorator(ORowSetValue(aTable)), + new ORowSetValueDecorator(aUID)}; //comment + //I'd prefer to swap the comment and the human name and + //just use e_source_registry_ref_source(get_e_source_registry(), aUID); + //in open book rather than search for the name again + aRows.push_back(aRow); } - pResult->setRows(aRows); + g_list_foreach (pSources, object_unref, nullptr); + g_list_free (pSources); + + pResult->setRows(std::move(aRows)); - return xRef; + return pResult; } Reference< XResultSet > SAL_CALL OEvoabDatabaseMetaData::getUDTs( const Any& /*catalog*/, const OUString& /*schemaPattern*/, const OUString& /*typeNamePattern*/, const Sequence< sal_Int32 >& /*types*/ ) diff --git a/connectivity/source/drivers/evoab2/NDatabaseMetaData.hxx b/connectivity/source/drivers/evoab2/NDatabaseMetaData.hxx index 61a9449e65b0..a64c234e6a52 100644 --- a/connectivity/source/drivers/evoab2/NDatabaseMetaData.hxx +++ b/connectivity/source/drivers/evoab2/NDatabaseMetaData.hxx @@ -17,18 +17,19 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NDATABASEMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NDATABASEMETADATA_HXX +#pragma once + +#include <sal/config.h> + +#include <string_view> #include "NConnection.hxx" #include <TDatabaseMetaDataBase.hxx> #include <FDatabaseMetaDataResultSet.hxx> -namespace connectivity +namespace connectivity::evoab { - namespace evoab - { //************ Class: OEvoabDatabaseMetaData @@ -56,7 +57,7 @@ namespace connectivity sal_Int32 getFieldType(guint nCol) ; OUString getFieldTypeName(guint nCol) ; OUString getFieldName(guint nCol) ; - guint findEvoabField(const OUString& aColName); + guint findEvoabField(std::u16string_view aColName); void free_column_resources(); @@ -64,8 +65,6 @@ namespace connectivity { OEvoabConnection* m_pConnection; - ODatabaseMetaDataResultSet::ORows getColumnRows( const OUString& columnNamePattern ); - protected: virtual css::uno::Reference< css::sdbc::XResultSet > impl_getTypeInfo_throw() override; // cached database information @@ -213,9 +212,7 @@ namespace connectivity virtual sal_Bool SAL_CALL supportsBatchUpdates( ) override; virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getUDTs( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& typeNamePattern, const css::uno::Sequence< sal_Int32 >& types ) override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NDATABASEMETADATA_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/evoab2/NDriver.cxx b/connectivity/source/drivers/evoab2/NDriver.cxx index ab6eb8ee48eb..c72d9b1a189f 100644 --- a/connectivity/source/drivers/evoab2/NDriver.cxx +++ b/connectivity/source/drivers/evoab2/NDriver.cxx @@ -23,6 +23,7 @@ #include <connectivity/dbexception.hxx> #include <cppuhelper/supportsservice.hxx> #include <com/sun/star/ucb/XContentAccess.hpp> +#include <rtl/ref.hxx> #include <strings.hrc> #include <resource/sharedresources.hxx> @@ -30,10 +31,8 @@ using namespace osl; using namespace connectivity::evoab; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::ucb; OEvoabDriver::OEvoabDriver(const Reference< XComponentContext >& _rxContext) : @@ -103,12 +102,11 @@ Reference< XConnection > SAL_CALL OEvoabDriver::connect( const OUString& url, co if ( ! acceptsURL(url) ) return nullptr; - OEvoabConnection* pCon = new OEvoabConnection( *this ); + rtl::Reference<OEvoabConnection> pCon = new OEvoabConnection( *this ); pCon->construct(url,info); - Reference< XConnection > xCon = pCon; m_xConnections.push_back(WeakReferenceHelper(*pCon)); - return xCon; + return pCon; } sal_Bool SAL_CALL OEvoabDriver::acceptsURL( const OUString& url ) @@ -141,9 +139,9 @@ sal_Int32 SAL_CALL OEvoabDriver::getMinorVersion( ) return 0; } -bool OEvoabDriver::acceptsURL_Stat( const OUString& url ) +bool OEvoabDriver::acceptsURL_Stat( std::u16string_view url ) { - return ( url == "sdbc:address:evolution:local" || url == "sdbc:address:evolution:groupwise" || url == "sdbc:address:evolution:ldap" ) && EApiInit(); + return ( url == u"sdbc:address:evolution:local" || url == u"sdbc:address:evolution:groupwise" || url == u"sdbc:address:evolution:ldap" ) && EApiInit(); } diff --git a/connectivity/source/drivers/evoab2/NDriver.hxx b/connectivity/source/drivers/evoab2/NDriver.hxx index d492e9bb5288..b505bb9db5fd 100644 --- a/connectivity/source/drivers/evoab2/NDriver.hxx +++ b/connectivity/source/drivers/evoab2/NDriver.hxx @@ -17,19 +17,20 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NDRIVER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NDRIVER_HXX +#pragma once + +#include <sal/config.h> + +#include <string_view> #include <com/sun/star/sdbc/XDriver.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <cppuhelper/compbase.hxx> #include <connectivity/CommonTools.hxx> -#define EVOAB_DRIVER_IMPL_NAME "com.sun.star.comp.sdbc.evoab.OEvoabDriver" +inline constexpr OUString EVOAB_DRIVER_IMPL_NAME = u"com.sun.star.comp.sdbc.evoab.OEvoabDriver"_ustr; -namespace connectivity -{ - namespace evoab +namespace connectivity::evoab { typedef ::cppu::WeakComponentImplHelper< css::sdbc::XDriver, css::lang::XServiceInfo > ODriver_BASE; @@ -62,14 +63,12 @@ namespace connectivity virtual sal_Int32 SAL_CALL getMinorVersion( ) override; public: - css::uno::Reference< css::uno::XComponentContext > getComponentContext( ) const { return m_xContext; } + const css::uno::Reference< css::uno::XComponentContext >& getComponentContext( ) const { return m_xContext; } // static methods - static bool acceptsURL_Stat( const OUString& url ); + static bool acceptsURL_Stat( std::u16string_view url ); }; - } - } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NDRIVER_HXX + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/evoab2/NPreparedStatement.cxx b/connectivity/source/drivers/evoab2/NPreparedStatement.cxx index 57981e95e82d..2ed8b0f166b9 100644 --- a/connectivity/source/drivers/evoab2/NPreparedStatement.cxx +++ b/connectivity/source/drivers/evoab2/NPreparedStatement.cxx @@ -21,14 +21,14 @@ #include "NPreparedStatement.hxx" #include <connectivity/dbexception.hxx> #include <connectivity/dbtools.hxx> -#include <tools/diagnose_ex.h> +#include <rtl/ref.hxx> +#include <comphelper/diagnose_ex.hxx> #include <strings.hrc> using namespace connectivity::evoab; using namespace com::sun::star::uno; using namespace com::sun::star::lang; -using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; using namespace com::sun::star::container; using namespace com::sun::star::io; @@ -39,8 +39,6 @@ IMPLEMENT_SERVICE_INFO(OEvoabPreparedStatement,"com.sun.star.sdbcx.evoab.Prepare OEvoabPreparedStatement::OEvoabPreparedStatement( OEvoabConnection* _pConnection ) :OCommonStatement(_pConnection) - ,m_sSqlStatement() - ,m_xMetaData() { } @@ -54,7 +52,8 @@ void OEvoabPreparedStatement::construct( const OUString& _sql ) ENSURE_OR_THROW( m_aQueryData.xSelectColumns.is(), "no SelectColumn" ); // create our meta data - OEvoabResultSetMetaData* pMeta = new OEvoabResultSetMetaData( m_aQueryData.sTable ); + rtl::Reference<OEvoabResultSetMetaData> pMeta + = new OEvoabResultSetMetaData( m_aQueryData.sTable ); m_xMetaData = pMeta; pMeta->setEvoabFields( m_aQueryData.xSelectColumns ); } @@ -65,13 +64,13 @@ OEvoabPreparedStatement::~OEvoabPreparedStatement() } -void SAL_CALL OEvoabPreparedStatement::acquire() throw() +void SAL_CALL OEvoabPreparedStatement::acquire() noexcept { OCommonStatement::acquire(); } -void SAL_CALL OEvoabPreparedStatement::release() throw() +void SAL_CALL OEvoabPreparedStatement::release() noexcept { OCommonStatement::release(); } diff --git a/connectivity/source/drivers/evoab2/NPreparedStatement.hxx b/connectivity/source/drivers/evoab2/NPreparedStatement.hxx index 20d5790ca4a0..cd42d42d505b 100644 --- a/connectivity/source/drivers/evoab2/NPreparedStatement.hxx +++ b/connectivity/source/drivers/evoab2/NPreparedStatement.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NPREPAREDSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NPREPAREDSTATEMENT_HXX +#pragma once #include "NStatement.hxx" #include "NConnection.hxx" @@ -31,10 +30,8 @@ #include <com/sun/star/io/XInputStream.hpp> #include <cppuhelper/implbase5.hxx> -namespace connectivity +namespace connectivity::evoab { - namespace evoab - { typedef ::cppu::ImplHelper5< css::sdbc::XPreparedStatement, css::sdbc::XParameters, @@ -59,12 +56,11 @@ namespace connectivity void construct( const OUString& _sql ); - private: DECLARE_SERVICE_INFO(); //XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; @@ -106,9 +102,7 @@ namespace connectivity virtual sal_Int32 SAL_CALL getUpdateCount( ) override; virtual sal_Bool SAL_CALL getMoreResults( ) override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NPREPAREDSTATEMENT_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/evoab2/NResultSet.cxx b/connectivity/source/drivers/evoab2/NResultSet.cxx index a9c73a65b740..bc9656337097 100644 --- a/connectivity/source/drivers/evoab2/NResultSet.cxx +++ b/connectivity/source/drivers/evoab2/NResultSet.cxx @@ -36,7 +36,7 @@ #include <connectivity/sqlerror.hxx> #include <rtl/string.hxx> #include <sal/log.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <unotools/syslocale.hxx> #include <unotools/intlwrapper.hxx> #include <unotools/collatorwrapper.hxx> @@ -51,7 +51,6 @@ using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; -using namespace com::sun::star::sdbcx; using namespace com::sun::star::container; using namespace com::sun::star::io; namespace ErrorCondition = ::com::sun::star::sdb::ErrorCondition; @@ -88,7 +87,7 @@ static OUString valueToOUString( GValue& _rValue ) { const char *pStr = g_value_get_string( &_rValue ); - OString aStr( pStr ? pStr : "" ); + std::string_view aStr( pStr ? pStr : "" ); OUString sResult( OStringToOUString( aStr, RTL_TEXTENCODING_UTF8 ) ); g_value_unset( &_rValue ); return sResult; @@ -308,6 +307,10 @@ static int CompareContacts( gconstpointer _lhs, gconstpointer _rhs, gpointer _us for ( const auto& sortCol : rCompData.rSortOrder ) { sal_Int32 nField = sortCol.nField; + int nOrder = 1; + // if descending sort, reverse order + if (!sortCol.bAscending) + nOrder = -1; GType eFieldType = evoab::getGFieldType( nField ); bool success = getValue( lhs, nField, eFieldType, &aLhsValue, bLhsNull ) @@ -317,9 +320,9 @@ static int CompareContacts( gconstpointer _lhs, gconstpointer _rhs, gpointer _us return 0; if ( bLhsNull && !bRhsNull ) - return -1; + return -1 * nOrder; if ( !bLhsNull && bRhsNull ) - return 1; + return 1 * nOrder; if ( bLhsNull && bRhsNull ) continue; @@ -329,16 +332,16 @@ static int CompareContacts( gconstpointer _lhs, gconstpointer _rhs, gpointer _us sRhs = valueToOUString( aRhsValue ); sal_Int32 nCompResult = rCompData.aIntlWrapper.getCaseCollator()->compareString( sLhs, sRhs ); if ( nCompResult != 0 ) - return nCompResult; + return nCompResult * nOrder; continue; } bLhs = valueToBool( aLhsValue ); bRhs = valueToBool( aRhsValue ); if ( bLhs && !bRhs ) - return -1; + return -1 * nOrder; if ( !bLhs && bRhs ) - return 1; + return 1 * nOrder; continue; } @@ -398,7 +401,7 @@ public: break; } } - g_list_foreach (pSources, reinterpret_cast<GFunc>(g_object_unref), nullptr); + g_list_foreach (pSources, object_unref, nullptr); g_list_free (pSources); if (!id) return nullptr; @@ -431,7 +434,7 @@ public: m_pContacts = nullptr; } - virtual void executeQuery (EBook* pBook, EBookQuery* pQuery, OString &/*rPassword*/) override + virtual void executeQuery (EBook* pBook, EBookQuery* pQuery) override { freeContacts(); char *sexp = e_book_query_to_string( pQuery ); @@ -476,123 +479,7 @@ class OEvoabVersion38Helper : public OEvoabVersion36Helper protected: virtual EBookClient * createClient( ESource *pSource ) override { - return e_book_client_connect_direct_sync (get_e_source_registry (), pSource, nullptr, nullptr); - } -}; - -ESource * findSource( const char *id ) -{ - ESourceList *pSourceList = nullptr; - - g_return_val_if_fail (id != nullptr, nullptr); - - if (!e_book_get_addressbooks (&pSourceList, nullptr)) - pSourceList = nullptr; - - for ( GSList *g = e_source_list_peek_groups (pSourceList); g; g = g->next) - { - for (GSList *s = e_source_group_peek_sources (E_SOURCE_GROUP (g->data)); s; s = s->next) - { - ESource *pSource = E_SOURCE (s->data); - if (!strcmp (e_source_peek_name (pSource), id)) - return pSource; - } - } - return nullptr; -} - -bool isAuthRequired( EBook *pBook ) -{ - return e_source_get_property( e_book_get_source( pBook ), - "auth" ) != nullptr; -} - -class OEvoabVersion35Helper : public OEvoabVersionHelper -{ -private: - GList *m_pContacts; - -public: - OEvoabVersion35Helper() - : m_pContacts(nullptr) - { - } - - virtual ~OEvoabVersion35Helper() override - { - freeContacts(); - } - - virtual EBook* openBook(const char *abname) override - { - ESource *pSource = findSource (abname); - EBook *pBook = pSource ? e_book_new (pSource, nullptr) : nullptr; - if (pBook && !e_book_open (pBook, true, nullptr)) - { - g_object_unref (G_OBJECT (pBook)); - pBook = nullptr; - } - return pBook; - } - - virtual bool isLDAP( EBook *pBook ) override - { - return pBook && !strncmp( "ldap://", e_book_get_uri( pBook ), 6 ); - } - - virtual bool isLocal( EBook *pBook ) override - { - return pBook && ( !strncmp( "file://", e_book_get_uri( pBook ), 6 ) || - !strncmp( "local:", e_book_get_uri( pBook ), 6 ) ); - } - - virtual void freeContacts() override final - { - g_list_free(m_pContacts); - m_pContacts = nullptr; - } - - virtual void executeQuery (EBook* pBook, EBookQuery* pQuery, OString &rPassword) override - { - freeContacts(); - - ESource *pSource = e_book_get_source( pBook ); - bool bAuthSuccess = true; - - if( isAuthRequired( pBook ) ) - { - OString aUser( getUserName( pBook ) ); - const char *pAuth = e_source_get_property( pSource, "auth" ); - bAuthSuccess = e_book_authenticate_user( pBook, aUser.getStr(), rPassword.getStr(), pAuth, nullptr ); - } - - if (bAuthSuccess) - e_book_get_contacts( pBook, pQuery, &m_pContacts, nullptr ); - } - - virtual EContact *getContact(sal_Int32 nIndex) override - { - gpointer pData = g_list_nth_data (m_pContacts, nIndex); - return pData ? E_CONTACT (pData) : nullptr; - } - - virtual sal_Int32 getNumContacts() override - { - return g_list_length( m_pContacts ); - } - - virtual bool hasContacts() override - { - return m_pContacts != nullptr; - } - - virtual void sortContacts( const ComparisonData& _rCompData ) override - { - OSL_ENSURE( !_rCompData.rSortOrder.empty(), "sortContacts: no need to call this without any sort order!" ); - ENSURE_OR_THROW( _rCompData.aIntlWrapper.getCaseCollator(), "no collator for comparing strings" ); - - m_pContacts = g_list_sort_with_data( m_pContacts, &CompareContacts, - const_cast< gpointer >( static_cast< gconstpointer >( &_rCompData ) ) ); + return e_book_client_connect_direct_sync (get_e_source_registry (), pSource, 10, nullptr, nullptr); } }; @@ -611,26 +498,36 @@ OEvoabResultSet::OEvoabResultSet( OCommonStatement* pStmt, OEvoabConnection *pCo ,m_nIndex(-1) ,m_nLength(0) { - if (eds_check_version( 3, 7, 6 ) == nullptr) - m_pVersionHelper = std::make_unique<OEvoabVersion38Helper>(); - else if (eds_check_version( 3, 6, 0 ) == nullptr) - m_pVersionHelper = std::make_unique<OEvoabVersion36Helper>(); - else - m_pVersionHelper = std::make_unique<OEvoabVersion35Helper>(); + m_pVersionHelper = std::make_unique<OEvoabVersion38Helper>(); - #define REGISTER_PROP( id, member ) \ - registerProperty( \ - OMetaConnection::getPropMap().getNameByIndex( id ), \ - id, \ - PropertyAttribute::READONLY, \ - &member, \ - cppu::UnoType<decltype(member)>::get() \ - ); - - REGISTER_PROP( PROPERTY_ID_FETCHSIZE, m_nFetchSize ); - REGISTER_PROP( PROPERTY_ID_RESULTSETTYPE, m_nResultSetType ); - REGISTER_PROP( PROPERTY_ID_FETCHDIRECTION, m_nFetchDirection ); - REGISTER_PROP( PROPERTY_ID_RESULTSETCONCURRENCY, m_nResultSetConcurrency ); + registerProperty( + OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), + PROPERTY_ID_FETCHSIZE, + PropertyAttribute::READONLY, + &m_nFetchSize, + cppu::UnoType<decltype(m_nFetchSize)>::get() + ); + registerProperty( + OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), + PROPERTY_ID_RESULTSETTYPE, + PropertyAttribute::READONLY, + &m_nResultSetType, + cppu::UnoType<decltype(m_nResultSetType)>::get() + ); + registerProperty( + OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), + PROPERTY_ID_FETCHDIRECTION, + PropertyAttribute::READONLY, + &m_nFetchDirection, + cppu::UnoType<decltype(m_nFetchDirection)>::get() + ); + registerProperty( + OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), + PROPERTY_ID_RESULTSETCONCURRENCY, + PropertyAttribute::READONLY, + &m_nResultSetConcurrency, + cppu::UnoType<decltype(m_nResultSetConcurrency)>::get() + ); } OEvoabResultSet::~OEvoabResultSet() @@ -672,9 +569,7 @@ void OEvoabResultSet::construct( const QueryData& _rData ) } if ( bExecuteQuery ) { - OString aPassword = m_pConnection->getPassword(); - m_pVersionHelper->executeQuery(pBook, _rData.getQuery(), aPassword); - m_pConnection->setPassword( aPassword ); + m_pVersionHelper->executeQuery(pBook, _rData.getQuery()); if ( m_pVersionHelper->hasContacts() && !_rData.aSortOrder.empty() ) { @@ -872,7 +767,7 @@ Reference< XResultSetMetaData > SAL_CALL OEvoabResultSet::getMetaData( ) // the meta data should have been created at construction time ENSURE_OR_THROW( m_xMetaData.is(), "internal error: no meta data" ); - return m_xMetaData.get(); + return m_xMetaData; } // XResultSetMetaDataSupplier Interface Ends @@ -1016,8 +911,7 @@ Reference< XInterface > SAL_CALL OEvoabResultSet::getStatement( ) { ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - css::uno::WeakReferenceHelper aStatement(static_cast<OWeakObject*>(m_pStatement)); - return aStatement.get(); + return cppu::getXWeak(m_pStatement); } @@ -1119,12 +1013,12 @@ sal_Int32 SAL_CALL OEvoabResultSet::findColumn( const OUString& columnName ) return *getArrayHelper(); } -void SAL_CALL OEvoabResultSet::acquire() throw() +void SAL_CALL OEvoabResultSet::acquire() noexcept { OResultSet_BASE::acquire(); } -void SAL_CALL OEvoabResultSet::release() throw() +void SAL_CALL OEvoabResultSet::release() noexcept { OResultSet_BASE::release(); } diff --git a/connectivity/source/drivers/evoab2/NResultSet.hxx b/connectivity/source/drivers/evoab2/NResultSet.hxx index 40b0027cfe48..3eeeab244ab3 100644 --- a/connectivity/source/drivers/evoab2/NResultSet.hxx +++ b/connectivity/source/drivers/evoab2/NResultSet.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NRESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NRESULTSET_HXX +#pragma once #include <memory> @@ -42,17 +41,15 @@ #include "NStatement.hxx" #include "NResultSetMetaData.hxx" -namespace connectivity +namespace connectivity::evoab { - namespace evoab - { struct ComparisonData; class OEvoabVersionHelper { public: virtual EBook* openBook(const char *abname) = 0; - virtual void executeQuery (EBook* pBook, EBookQuery* pQuery, OString &rPassword) = 0; + virtual void executeQuery (EBook* pBook, EBookQuery* pQuery) = 0; virtual void freeContacts() = 0; virtual bool isLDAP( EBook *pBook ) = 0; virtual bool isLocal( EBook *pBook ) = 0; @@ -121,8 +118,8 @@ namespace connectivity virtual void SAL_CALL disposing() override; // XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; // XPropertySet @@ -179,9 +176,7 @@ namespace connectivity // XColumnLocate virtual sal_Int32 SAL_CALL findColumn( const OUString& columnName ) override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NRESULTSET_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/evoab2/NResultSetMetaData.cxx b/connectivity/source/drivers/evoab2/NResultSetMetaData.cxx index 4982cc455665..a828b127fe68 100644 --- a/connectivity/source/drivers/evoab2/NResultSetMetaData.cxx +++ b/connectivity/source/drivers/evoab2/NResultSetMetaData.cxx @@ -21,15 +21,14 @@ #include "NDatabaseMetaData.hxx" #include <connectivity/dbexception.hxx> #include <strings.hrc> +#include <utility> using namespace connectivity::evoab; using namespace com::sun::star::uno; -using namespace com::sun::star::lang; using namespace com::sun::star::sdbc; -OEvoabResultSetMetaData::OEvoabResultSetMetaData(const OUString& _aTableName) - : m_aTableName(_aTableName), - m_aEvoabFields() +OEvoabResultSetMetaData::OEvoabResultSetMetaData(OUString _aTableName) + : m_aTableName(std::move(_aTableName)) { } @@ -40,7 +39,7 @@ OEvoabResultSetMetaData::~OEvoabResultSetMetaData() void OEvoabResultSetMetaData::setEvoabFields(const ::rtl::Reference<connectivity::OSQLColumns> &xColumns) { - static const char aName[] = "Name"; + static constexpr OUStringLiteral aName = u"Name"; for (const auto& rxColumn : *xColumns) { @@ -102,15 +101,7 @@ OUString SAL_CALL OEvoabResultSetMetaData::getColumnTypeName( sal_Int32 nColumnN OUString SAL_CALL OEvoabResultSetMetaData::getColumnLabel( sal_Int32 nColumnNum ) { - sal_uInt32 nField = m_aEvoabFields[nColumnNum - 1]; - const ColumnProperty *pSpecs = getField(nField); - GParamSpec *pSpec = pSpecs->pField; - OUString aLabel; - - if( pSpec ) - aLabel = OStringToOUString( g_param_spec_get_nick( pSpec ), - RTL_TEXTENCODING_UTF8 ); - return aLabel; + return getColumnName(nColumnNum); } OUString SAL_CALL OEvoabResultSetMetaData::getColumnServiceName( sal_Int32 /*nColumnNum*/ ) diff --git a/connectivity/source/drivers/evoab2/NResultSetMetaData.hxx b/connectivity/source/drivers/evoab2/NResultSetMetaData.hxx index 9c309aaddb67..e79d347b1c4d 100644 --- a/connectivity/source/drivers/evoab2/NResultSetMetaData.hxx +++ b/connectivity/source/drivers/evoab2/NResultSetMetaData.hxx @@ -17,18 +17,16 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NRESULTSETMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NRESULTSETMETADATA_HXX +#pragma once #include <com/sun/star/sdbc/XResultSetMetaData.hpp> #include <cppuhelper/implbase.hxx> #include "NConnection.hxx" #include <rtl/ref.hxx> #include <com/sun/star/connection/XConnection.hpp> -namespace connectivity + +namespace connectivity::evoab { - namespace evoab - { //************ Class: ResultSetMetaData @@ -42,13 +40,13 @@ namespace connectivity protected: virtual ~OEvoabResultSetMetaData() override; public: - explicit OEvoabResultSetMetaData(const OUString& _aTableName); + explicit OEvoabResultSetMetaData(OUString _aTableName); /// @throws css::sdbc::SQLException void setEvoabFields(const ::rtl::Reference<connectivity::OSQLColumns> &xColumns); sal_uInt32 fieldAtColumn(sal_Int32 columnIndex) const { return m_aEvoabFields[columnIndex - 1]; } /// Avoid ambiguous cast error from the compiler. - operator css::uno::Reference< css::sdbc::XResultSetMetaData > () throw() + operator css::uno::Reference< css::sdbc::XResultSetMetaData > () noexcept { return this; } virtual sal_Int32 SAL_CALL getColumnCount( ) override; @@ -73,9 +71,7 @@ namespace connectivity virtual sal_Bool SAL_CALL isDefinitelyWritable( sal_Int32 column ) override; virtual OUString SAL_CALL getColumnServiceName( sal_Int32 column ) override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NRESULTSETMETADATA_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/evoab2/NStatement.cxx b/connectivity/source/drivers/evoab2/NStatement.cxx index 1616f9fb1f1f..91ebdda56c70 100644 --- a/connectivity/source/drivers/evoab2/NStatement.cxx +++ b/connectivity/source/drivers/evoab2/NStatement.cxx @@ -17,7 +17,12 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <string_view> + #include <osl/diagnose.h> +#include <rtl/ref.hxx> #include <rtl/ustring.hxx> #include <sal/log.hxx> #include <com/sun/star/sdbc/ResultSetConcurrency.hpp> @@ -33,7 +38,7 @@ #include <sqlbison.hxx> #include <strings.hrc> #include <connectivity/dbexception.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> namespace connectivity::evoab { @@ -44,7 +49,6 @@ using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; using namespace com::sun::star::sdbcx; using namespace com::sun::star::container; -using namespace com::sun::star::io; using namespace com::sun::star::util; namespace { @@ -54,9 +58,9 @@ EBookQuery * createTrue() return e_book_query_from_string("(exists \"full_name\")"); } -EBookQuery * createTest( const OUString &aColumnName, +EBookQuery * createTest( std::u16string_view aColumnName, EBookQueryTest eTest, - const OUString &aMatch ) + std::u16string_view aMatch ) { OString sMatch = OUStringToOString( aMatch, RTL_TEXTENCODING_UTF8 ); OString sColumnName = OUStringToOString( aColumnName, RTL_TEXTENCODING_UTF8 ); @@ -84,24 +88,69 @@ OCommonStatement::OCommonStatement(OEvoabConnection* _pConnection) , m_nResultSetConcurrency(ResultSetConcurrency::UPDATABLE) , m_bEscapeProcessing(true) { -#define REGISTER_PROP( id, member ) \ - registerProperty( \ - OMetaConnection::getPropMap().getNameByIndex( id ), \ - id, \ - 0, \ - &member, \ - cppu::UnoType<decltype(member)>::get() \ + registerProperty( + OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), + PROPERTY_ID_CURSORNAME, + 0, + &m_aCursorName, + cppu::UnoType<decltype(m_aCursorName)>::get() + ); + registerProperty( + OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXFIELDSIZE), + PROPERTY_ID_MAXFIELDSIZE, + 0, + &m_nMaxFieldSize, + cppu::UnoType<decltype(m_nMaxFieldSize)>::get() + ); + registerProperty( + OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXROWS), + PROPERTY_ID_MAXROWS, + 0, + &m_nMaxRows, + cppu::UnoType<decltype(m_nMaxRows)>::get() + ); + registerProperty( + OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_QUERYTIMEOUT), + PROPERTY_ID_QUERYTIMEOUT, + 0, + &m_nQueryTimeOut, + cppu::UnoType<decltype(m_nQueryTimeOut)>::get() + ); + registerProperty( + OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), + PROPERTY_ID_FETCHSIZE, + 0, + &m_nFetchSize, + cppu::UnoType<decltype(m_nFetchSize)>::get() + ); + registerProperty( + OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), + PROPERTY_ID_RESULTSETTYPE, + 0, + &m_nResultSetType, + cppu::UnoType<decltype(m_nResultSetType)>::get() + ); + registerProperty( + OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), + PROPERTY_ID_FETCHDIRECTION, + 0, + &m_nFetchDirection, + cppu::UnoType<decltype(m_nFetchDirection)>::get() + ); + registerProperty( + OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ESCAPEPROCESSING), + PROPERTY_ID_ESCAPEPROCESSING, + 0, + &m_bEscapeProcessing, + cppu::UnoType<decltype(m_bEscapeProcessing)>::get() + ); + registerProperty( + OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), + PROPERTY_ID_RESULTSETCONCURRENCY, + 0, + &m_nResultSetConcurrency, + cppu::UnoType<decltype(m_nResultSetConcurrency)>::get() ); - - REGISTER_PROP( PROPERTY_ID_CURSORNAME, m_aCursorName ); - REGISTER_PROP( PROPERTY_ID_MAXFIELDSIZE, m_nMaxFieldSize ); - REGISTER_PROP( PROPERTY_ID_MAXROWS, m_nMaxRows ); - REGISTER_PROP( PROPERTY_ID_QUERYTIMEOUT, m_nQueryTimeOut ); - REGISTER_PROP( PROPERTY_ID_FETCHSIZE, m_nFetchSize ); - REGISTER_PROP( PROPERTY_ID_RESULTSETTYPE, m_nResultSetType ); - REGISTER_PROP( PROPERTY_ID_FETCHDIRECTION, m_nFetchDirection ); - REGISTER_PROP( PROPERTY_ID_ESCAPEPROCESSING, m_bEscapeProcessing ); - REGISTER_PROP( PROPERTY_ID_RESULTSETCONCURRENCY, m_nResultSetConcurrency ); } OCommonStatement::~OCommonStatement() @@ -218,8 +267,11 @@ void OCommonStatement::orderByAnalysis( const OSQLParseNode* _pOrderByClause, So ENSURE_OR_THROW( ( pColumnRef != nullptr ) && ( pAscDesc != nullptr ) - && SQL_ISRULE( pAscDesc, opt_asc_desc ) - && ( pAscDesc->count() < 2 ), + && ( pAscDesc->isLeaf() ) + && ( SQL_ISRULE( pAscDesc, opt_asc_desc ) + || SQL_ISTOKEN(pAscDesc, ASC) + || SQL_ISTOKEN(pAscDesc, DESC) + ), "ordering_spec structure error" ); // column name -> column field @@ -228,11 +280,7 @@ void OCommonStatement::orderByAnalysis( const OSQLParseNode* _pOrderByClause, So const OUString sColumnName( impl_getColumnRefColumnName_throw( *pColumnRef ) ); guint nField = evoab::findEvoabField( sColumnName ); // ascending/descending? - bool bAscending = true; - if ( ( pAscDesc->count() == 1 ) - && SQL_ISTOKEN( pAscDesc->getChild( 0 ), DESC ) - ) - bAscending = false; + bool bAscending = !SQL_ISTOKEN(pAscDesc, DESC); _out_rSort.push_back( FieldSort( nField, bAscending ) ); } @@ -364,7 +412,7 @@ EBookQuery *OCommonStatement::whereAnalysis( const OSQLParseNode* parseTree ) { // String containing only a '%' and nothing else matches everything pResult = createTest( aColumnName, E_BOOK_QUERY_CONTAINS, - "" ); + u"" ); } else if( aMatchString.indexOf( WILDCARD ) == -1 ) { // Simple string , eg. "to match" "contains in evo" @@ -381,9 +429,10 @@ EBookQuery *OCommonStatement::whereAnalysis( const OSQLParseNode* parseTree ) else if( aMatchString.indexOf ( WILDCARD ) == aMatchString.lastIndexOf ( WILDCARD ) ) { // One occurrence of '%' matches... if ( aMatchString.startsWith(OUStringChar(WILDCARD)) ) - pResult = createTest( aColumnName, E_BOOK_QUERY_ENDS_WITH, aMatchString.copy( 1 ) ); + pResult = createTest( + aColumnName, E_BOOK_QUERY_ENDS_WITH, aMatchString.subView( 1 ) ); else if ( aMatchString.indexOf ( WILDCARD ) == aMatchString.getLength() - 1 ) - pResult = createTest( aColumnName, E_BOOK_QUERY_BEGINS_WITH, aMatchString.copy( 0, aMatchString.getLength() - 1 ) ); + pResult = createTest( aColumnName, E_BOOK_QUERY_BEGINS_WITH, aMatchString.subView( 0, aMatchString.getLength() - 1 ) ); else m_xConnection->throwGenericSQLException(STR_QUERY_LIKE_WILDCARD,*this); } @@ -391,7 +440,7 @@ EBookQuery *OCommonStatement::whereAnalysis( const OSQLParseNode* parseTree ) aMatchString.startsWith(OUStringChar(WILDCARD)) && aMatchString.indexOf ( WILDCARD, 1) == aMatchString.getLength() - 1 ) { // one '%' at the start and another at the end - pResult = createTest( aColumnName, E_BOOK_QUERY_CONTAINS, aMatchString.copy (1, aMatchString.getLength() - 2) ); + pResult = createTest( aColumnName, E_BOOK_QUERY_CONTAINS, aMatchString.subView (1, aMatchString.getLength() - 2) ); } else m_xConnection->throwGenericSQLException(STR_QUERY_LIKE_WILDCARD_MANY,*this); @@ -455,6 +504,7 @@ void OCommonStatement::parseSql( const OUString& sql, QueryData& _out_rQueryData pOrderByClause->showParseTree( sTreeDebug ); SAL_INFO( "connectivity.evoab2", "found order-by tree:\n" << sTreeDebug ); #endif + orderByAnalysis( pOrderByClause, _out_rQueryData.aSortOrder ); } @@ -498,7 +548,7 @@ Any SAL_CALL OCommonStatement::getWarnings( ) checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed); - return makeAny(SQLWarning()); + return Any(SQLWarning()); } @@ -522,12 +572,12 @@ void SAL_CALL OCommonStatement::clearWarnings( ) } -void SAL_CALL OCommonStatement::acquire() throw() +void SAL_CALL OCommonStatement::acquire() noexcept { OCommonStatement_IBase::acquire(); } -void SAL_CALL OCommonStatement::release() throw() +void SAL_CALL OCommonStatement::release() noexcept { OCommonStatement_IBase::release(); } @@ -559,13 +609,12 @@ QueryData OCommonStatement::impl_getEBookQuery_throw( const OUString& _rSql ) Reference< XResultSet > OCommonStatement::impl_executeQuery_throw( const QueryData& _rQueryData ) { // create result set - OEvoabResultSet* pResult = new OEvoabResultSet( this, m_xConnection.get() ); - Reference< XResultSet > xRS = pResult; + rtl::Reference<OEvoabResultSet> pResult = new OEvoabResultSet( this, m_xConnection.get() ); pResult->construct( _rQueryData ); // done - m_xResultSet = xRS; - return xRS; + m_xResultSet = Reference<XWeak>(pResult); + return pResult; } diff --git a/connectivity/source/drivers/evoab2/NStatement.hxx b/connectivity/source/drivers/evoab2/NStatement.hxx index 14c12700ca62..a348c5335d56 100644 --- a/connectivity/source/drivers/evoab2/NStatement.hxx +++ b/connectivity/source/drivers/evoab2/NStatement.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NSTATEMENT_HXX +#pragma once #include <com/sun/star/sdbc/XStatement.hpp> #include <com/sun/star/sdbc/XWarningsSupplier.hpp> @@ -41,12 +40,10 @@ #include "EApi.h" #include "NConnection.hxx" -#include <list> +#include <vector> -namespace connectivity +namespace connectivity::evoab { - namespace evoab - { typedef ::cppu::WeakComponentImplHelper< css::sdbc::XWarningsSupplier , css::sdbc::XCloseable > OCommonStatement_IBase; @@ -200,8 +197,8 @@ namespace connectivity // OComponentHelper virtual void SAL_CALL disposing() override; // XInterface - virtual void SAL_CALL release() throw() override; - virtual void SAL_CALL acquire() throw() override; + virtual void SAL_CALL release() noexcept override; + virtual void SAL_CALL acquire() noexcept override; // XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; //XTypeProvider @@ -232,7 +229,7 @@ namespace connectivity impl_executeQuery_throw( const QueryData& _rData ); css::uno::Reference< css::sdbc::XConnection > - impl_getConnection() { return css::uno::Reference< css::sdbc::XConnection >( m_xConnection.get() ); } + impl_getConnection() { return css::uno::Reference< css::sdbc::XConnection >( m_xConnection ); } OUString impl_getColumnRefColumnName_throw( const ::connectivity::OSQLParseNode& _rColumnRef ); @@ -255,8 +252,8 @@ namespace connectivity // XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; // XTypeProvider DECLARE_XTYPEPROVIDER() @@ -270,9 +267,7 @@ namespace connectivity virtual sal_Bool SAL_CALL execute( const OUString& sql ) override ; virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( ) override ; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NSTATEMENT_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/evoab2/NTable.cxx b/connectivity/source/drivers/evoab2/NTable.cxx index b5c652a8ff67..631c27db244d 100644 --- a/connectivity/source/drivers/evoab2/NTable.cxx +++ b/connectivity/source/drivers/evoab2/NTable.cxx @@ -24,13 +24,8 @@ #include <com/sun/star/sdbc/XRow.hpp> using namespace connectivity; -using namespace ::comphelper; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; using namespace connectivity::evoab; OEvoabTable::OEvoabTable( sdbcx::OCollection* _pTables, @@ -62,15 +57,15 @@ void OEvoabTable::refreshColumns() if (xResult.is()) { - Reference< XRow > xRow(xResult, UNO_QUERY); - while (xResult->next()) - aVector.push_back(xRow->getString(4)); + Reference< XRow > xRow(xResult, UNO_QUERY); + while (xResult->next()) + aVector.push_back(xRow->getString(4)); } } if (m_xColumns) m_xColumns->reFill(aVector); else - m_xColumns = new OEvoabColumns(this,m_aMutex,aVector); + m_xColumns.reset(new OEvoabColumns(this,m_aMutex,aVector)); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/evoab2/NTable.hxx b/connectivity/source/drivers/evoab2/NTable.hxx index eb1159847d20..0aa30815b9b5 100644 --- a/connectivity/source/drivers/evoab2/NTable.hxx +++ b/connectivity/source/drivers/evoab2/NTable.hxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NTABLE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NTABLE_HXX +#pragma once #include "NConnection.hxx" #include <connectivity/sdbcx/VTable.hxx> -namespace connectivity +namespace connectivity::evoab { - namespace evoab - { typedef connectivity::sdbcx::OTable OEvoabTable_TYPEDEF; class OEvoabTable : public OEvoabTable_TYPEDEF @@ -50,9 +47,7 @@ namespace connectivity OUString const & getTableName() const { return m_Name; } OUString const & getSchema() const { return m_SchemaName; } }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NTABLE_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/evoab2/NTables.cxx b/connectivity/source/drivers/evoab2/NTables.cxx index b7a844fac15d..3be63e1e1049 100644 --- a/connectivity/source/drivers/evoab2/NTables.cxx +++ b/connectivity/source/drivers/evoab2/NTables.cxx @@ -29,12 +29,7 @@ using namespace ::cppu; using namespace connectivity::evoab; using namespace connectivity::sdbcx; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; -using namespace dbtools; ObjectType OEvoabTables::createObject(const OUString& aName) { @@ -48,7 +43,7 @@ ObjectType OEvoabTables::createObject(const OUString& aName) Reference< XRow > xRow(xResult,UNO_QUERY); if(xResult->next()) // there can be only one table with this name { - OEvoabTable* pRet = new OEvoabTable( + xRet = new OEvoabTable( this, static_cast<OEvoabCatalog&>(m_rParent).getConnection(), aName, @@ -56,7 +51,6 @@ ObjectType OEvoabTables::createObject(const OUString& aName) xRow->getString(5), "", ""); - xRet = pRet; } } diff --git a/connectivity/source/drivers/evoab2/NTables.hxx b/connectivity/source/drivers/evoab2/NTables.hxx index 99542ba53e5e..e5d454729431 100644 --- a/connectivity/source/drivers/evoab2/NTables.hxx +++ b/connectivity/source/drivers/evoab2/NTables.hxx @@ -16,15 +16,14 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NTABLES_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NTABLES_HXX +#pragma once #include <connectivity/sdbcx/VCollection.hxx> #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> -namespace connectivity +#include <utility> + +namespace connectivity::evoab { - namespace evoab - { class OEvoabTables : public sdbcx::OCollection { css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xMetaData; @@ -32,16 +31,14 @@ namespace connectivity virtual sdbcx::ObjectType createObject(const OUString& _rName) override; virtual void impl_refresh() override; public: - OEvoabTables(const css::uno::Reference< css::sdbc::XDatabaseMetaData >& _rMetaData, + OEvoabTables(css::uno::Reference< css::sdbc::XDatabaseMetaData > _xMetaData, ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, const ::std::vector< OUString> &_rVector) : sdbcx::OCollection(_rParent,true,_rMutex,_rVector), - m_xMetaData(_rMetaData) + m_xMetaData(std::move(_xMetaData)) {} virtual void disposing() override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_EVOAB2_NTABLES_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/file/FCatalog.cxx b/connectivity/source/drivers/file/FCatalog.cxx index eedda26efba2..54ad24bf1d59 100644 --- a/connectivity/source/drivers/file/FCatalog.cxx +++ b/connectivity/source/drivers/file/FCatalog.cxx @@ -24,10 +24,8 @@ #include <com/sun/star/sdbc/XResultSet.hpp> using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; using namespace connectivity::file; diff --git a/connectivity/source/drivers/file/FColumns.cxx b/connectivity/source/drivers/file/FColumns.cxx index e703112f71c4..97e9d0c23a2a 100644 --- a/connectivity/source/drivers/file/FColumns.cxx +++ b/connectivity/source/drivers/file/FColumns.cxx @@ -25,12 +25,8 @@ using namespace connectivity::file; using namespace connectivity; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; sdbcx::ObjectType OColumns::createObject(const OUString& _rName) { @@ -48,7 +44,7 @@ sdbcx::ObjectType OColumns::createObject(const OUString& _rName) { if(xRow->getString(4) == _rName) { - sdbcx::OColumn* pRet = new sdbcx::OColumn(_rName, + xRet = new sdbcx::OColumn(_rName, xRow->getString(6), xRow->getString(13), xRow->getString(12), @@ -63,7 +59,6 @@ sdbcx::ObjectType OColumns::createObject(const OUString& _rName) sCatalogName, sSchemaName, sTableName); - xRet = pRet; break; } } diff --git a/connectivity/source/drivers/file/FConnection.cxx b/connectivity/source/drivers/file/FConnection.cxx index 5c56ce4d5e5d..38ce342cb5e2 100644 --- a/connectivity/source/drivers/file/FConnection.cxx +++ b/connectivity/source/drivers/file/FConnection.cxx @@ -21,7 +21,6 @@ #include <comphelper/processfactory.hxx> #include <comphelper/servicehelper.hxx> -#include <cppuhelper/typeprovider.hxx> #include <file/FConnection.hxx> #include <file/FDatabaseMetaData.hxx> #include <file/FDriver.hxx> @@ -33,6 +32,7 @@ #include <com/sun/star/ucb/XContentIdentifier.hpp> #include <tools/urlobj.hxx> #include <file/FCatalog.hxx> +#include <comphelper/configuration.hxx> #include <unotools/pathoptions.hxx> #include <ucbhelper/content.hxx> #include <connectivity/dbcharset.hxx> @@ -132,6 +132,7 @@ void OConnection::construct(const OUString& url,const Sequence< PropertyValue >& OUString aFileName = aDSN; INetURLObject aURL; aURL.SetSmartProtocol(INetProtocol::File); + if (!comphelper::IsFuzzing()) { SvtPathOptions aPathOptions; aFileName = aPathOptions.SubstituteVariable(aFileName); @@ -229,8 +230,7 @@ Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement( const OU checkDisposed(OConnection_BASE::rBHelper.bDisposed); - OPreparedStatement* pStmt = new OPreparedStatement(this); - Reference< XPreparedStatement > xHoldAlive = pStmt; + rtl::Reference<OPreparedStatement> pStmt = new OPreparedStatement(this); pStmt->construct(sql); m_aStatements.push_back(WeakReferenceHelper(*pStmt)); return pStmt; @@ -402,31 +402,24 @@ Reference< XDynamicResultSet > OConnection::getDir() const sal_Int64 SAL_CALL OConnection::getSomething( const Sequence< sal_Int8 >& rId ) { - return (isUnoTunnelId<OConnection>(rId)) - ? reinterpret_cast< sal_Int64 >( this ) - : sal_Int64(0); + return comphelper::getSomethingImpl(rId, this); } -Sequence< sal_Int8 > OConnection::getUnoTunnelId() +const Sequence< sal_Int8 > & OConnection::getUnoTunnelId() { - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); + static const comphelper::UnoIdInit implId; + return implId.getSeq(); } void OConnection::throwUrlNotValid(const OUString & _rsUrl,const OUString & _rsMessage) { - SQLException aError; - aError.Message = getResources().getResourceStringWithSubstitution( - STR_NO_VALID_FILE_URL, - "$URL$", _rsUrl - ); - - aError.SQLState = "S1000"; - aError.ErrorCode = 0; - aError.Context = static_cast< XConnection* >(this); + XConnection* context = this; + css::uno::Any next; if (!_rsMessage.isEmpty()) - aError.NextException <<= SQLException(_rsMessage, aError.Context, OUString(), 0, Any()); + next <<= SQLException(_rsMessage, context, OUString(), 0, Any()); + SQLException aError( + getResources().getResourceStringWithSubstitution(STR_NO_VALID_FILE_URL, "$URL$", _rsUrl), + context, "S1000", 0, next); throw aError; } diff --git a/connectivity/source/drivers/file/FDatabaseMetaData.cxx b/connectivity/source/drivers/file/FDatabaseMetaData.cxx index 3d01216a39fd..6d157bb575da 100644 --- a/connectivity/source/drivers/file/FDatabaseMetaData.cxx +++ b/connectivity/source/drivers/file/FDatabaseMetaData.cxx @@ -17,6 +17,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <config_fuzzers.h> + #include <file/FDatabaseMetaData.hxx> #include <FDatabaseMetaDataResultSet.hxx> #include <com/sun/star/sdbc/ResultSetType.hpp> @@ -28,14 +30,13 @@ #include <file/FTable.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/servicehelper.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <ucbhelper/content.hxx> using namespace com::sun::star::ucb; using namespace connectivity::file; using namespace connectivity; using namespace com::sun::star::uno; -using namespace com::sun::star::lang; using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; using namespace com::sun::star::sdbcx; @@ -71,7 +72,8 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns( namespace { - sal_Int16 isCaseSensitiveParentFolder( const OUString& _rFolderOrDoc, const OUString& _rDocName ) +#if !ENABLE_FUZZERS + sal_Int16 isCaseSensitiveParentFolder( const OUString& _rFolderOrDoc, std::u16string_view _rDocName ) { sal_Int16 nIsCS = 1; try @@ -149,6 +151,7 @@ namespace return nIsCS; } +#endif } @@ -158,14 +161,12 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( { ::osl::MutexGuard aGuard( m_aMutex ); - - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTables ); - Reference< XResultSet > xRef = pResult; + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTables ); // check if any type is given // when no types are given then we have to return all tables e.g. TABLE - static const char aTable[] = "TABLE"; + static constexpr OUString aTable = u"TABLE"_ustr; bool bTableFound = true; sal_Int32 nLength = types.getLength(); @@ -185,7 +186,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( } } if(!bTableFound) - return xRef; + return pResult; Reference<XDynamicResultSet> xContent = m_pConnection->getDir(); Reference < XSortedDynamicResultSetFactory > xSRSFac = @@ -210,7 +211,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( INetURLObject aURL; xResultSet->beforeFirst(); - bool bKnowCaseSensivity = false; + bool bKnowCaseSensitivity = false; bool bCaseSensitiveDir = true; bool bCheckEnabled = m_pConnection->isCheckEnabled(); @@ -226,22 +227,26 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( aRow.reserve(6); bool bNewRow = false; - if ( !bKnowCaseSensivity ) + if ( !bKnowCaseSensitivity ) { - bKnowCaseSensivity = true; + bKnowCaseSensitivity = true; +#if ENABLE_FUZZERS + sal_Int16 nCase = 1; +#else sal_Int16 nCase = isCaseSensitiveParentFolder( m_pConnection->getURL(), aURL.getName() ); +#endif switch( nCase ) { case 1: bCaseSensitiveDir = true; break; case -1: - bKnowCaseSensivity = false; + bKnowCaseSensitivity = false; [[fallthrough]]; case 0: bCaseSensitiveDir = false; } - if ( bKnowCaseSensivity ) + if ( bKnowCaseSensitivity ) { m_pConnection->setCaseSensitiveExtension( bCaseSensitiveDir, OConnection::GrantAccess() ); if ( !bCaseSensitiveDir ) @@ -293,16 +298,16 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( } if(bNewRow) { - aRow.push_back(new ORowSetValueDecorator(OUString(aTable))); + aRow.push_back(new ORowSetValueDecorator(aTable)); aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); aRows.push_back(aRow); } } - pResult->setRows(aRows); + pResult->setRows(std::move(aRows)); - return xRef; + return pResult; } sal_Int32 SAL_CALL ODatabaseMetaData::getMaxBinaryLiteralLength( ) @@ -370,11 +375,9 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges( { ::osl::MutexGuard aGuard( m_aMutex ); - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTablePrivileges ); - Reference< XResultSet > xRef = pResult; + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTablePrivileges ); ODatabaseMetaDataResultSet::ORows aRows; - Reference< XTablesSupplier > xTabSup = m_pConnection->createCatalog(); if( xTabSup.is()) { @@ -397,7 +400,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges( xNames->getByName(*pBegin), css::uno::UNO_QUERY); if(xTable.is()) { - auto pTable = comphelper::getUnoTunnelImplementation<OFileTable>(xTable); + auto pTable = dynamic_cast<OFileTable*>(xTable.get()); if(pTable && !pTable->isReadOnly()) { aRow[6] = ODatabaseMetaDataResultSet::getInsertValue(); @@ -423,8 +426,8 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges( } } - pResult->setRows(aRows); - return xRef; + pResult->setRows(std::move(aRows)); + return pResult; } sal_Bool SAL_CALL ODatabaseMetaData::doesMaxRowSizeIncludeBlobs( ) @@ -614,20 +617,11 @@ sal_Bool SAL_CALL ODatabaseMetaData::supportsOuterJoins( ) Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTableTypes( ) { - ::osl::MutexGuard aGuard( m_aMutex ); - - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTableTypes ); - Reference< XResultSet > xRef = pResult; - static ODatabaseMetaDataResultSet::ORows aRows; - if(aRows.empty()) - { - ODatabaseMetaDataResultSet::ORow aRow; - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(new ORowSetValueDecorator(OUString("TABLE"))); - aRows.push_back(aRow); - } - pResult->setRows(aRows); - return xRef; + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTableTypes ); + ODatabaseMetaDataResultSet::ORows aRows; + aRows.push_back( { ODatabaseMetaDataResultSet::getEmptyValue(), new ORowSetValueDecorator(OUString("TABLE")) } ); + pResult->setRows(std::move(aRows)); + return pResult; } sal_Int32 SAL_CALL ODatabaseMetaData::getMaxStatementLength( ) diff --git a/connectivity/source/drivers/file/FDateFunctions.cxx b/connectivity/source/drivers/file/FDateFunctions.cxx index 5f9d1441859f..1be992d4b672 100644 --- a/connectivity/source/drivers/file/FDateFunctions.cxx +++ b/connectivity/source/drivers/file/FDateFunctions.cxx @@ -17,7 +17,6 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - #include <file/FDateFunctions.hxx> #include <tools/date.hxx> #include <tools/time.hxx> @@ -29,14 +28,14 @@ using namespace connectivity::file; ORowSetValue OOp_DayOfWeek::operate(const ORowSetValue& lhs) const { - if ( lhs.isNull() ) + if (lhs.isNull()) return lhs; sal_Int32 nRet = 0; - css::util::Date aD = lhs; - Date aDate(aD.Day,aD.Month,aD.Year); + css::util::Date aD = lhs.getDate(); + Date aDate(aD.Day, aD.Month, aD.Year); DayOfWeek eDayOfWeek = aDate.GetDayOfWeek(); - switch(eDayOfWeek) + switch (eDayOfWeek) { case MONDAY: nRet = 2; @@ -67,42 +66,42 @@ ORowSetValue OOp_DayOfWeek::operate(const ORowSetValue& lhs) const ORowSetValue OOp_DayOfMonth::operate(const ORowSetValue& lhs) const { - if ( lhs.isNull() ) + if (lhs.isNull()) return lhs; - css::util::Date aD = lhs; + css::util::Date aD = lhs.getDate(); return static_cast<sal_Int16>(aD.Day); } ORowSetValue OOp_DayOfYear::operate(const ORowSetValue& lhs) const { - if ( lhs.isNull() ) + if (lhs.isNull()) return lhs; - css::util::Date aD = lhs; - Date aDate(aD.Day,aD.Month,aD.Year); + css::util::Date aD = lhs.getDate(); + Date aDate(aD.Day, aD.Month, aD.Year); return static_cast<sal_Int16>(aDate.GetDayOfYear()); } ORowSetValue OOp_Month::operate(const ORowSetValue& lhs) const { - if ( lhs.isNull() ) + if (lhs.isNull()) return lhs; - css::util::Date aD = lhs; + css::util::Date aD = lhs.getDate(); return static_cast<sal_Int16>(aD.Month); } ORowSetValue OOp_DayName::operate(const ORowSetValue& lhs) const { - if ( lhs.isNull() ) + if (lhs.isNull()) return lhs; OUString sRet; - css::util::Date aD = lhs; - Date aDate(aD.Day,aD.Month,aD.Year); + css::util::Date aD = lhs.getDate(); + Date aDate(aD.Day, aD.Month, aD.Year); DayOfWeek eDayOfWeek = aDate.GetDayOfWeek(); - switch(eDayOfWeek) + switch (eDayOfWeek) { case MONDAY: sRet = "Monday"; @@ -133,12 +132,12 @@ ORowSetValue OOp_DayName::operate(const ORowSetValue& lhs) const ORowSetValue OOp_MonthName::operate(const ORowSetValue& lhs) const { - if ( lhs.isNull() ) + if (lhs.isNull()) return lhs; OUString sRet; - css::util::Date aD = lhs; - switch(aD.Month) + css::util::Date aD = lhs.getDate(); + switch (aD.Month) { case 1: sRet = "January"; @@ -182,99 +181,98 @@ ORowSetValue OOp_MonthName::operate(const ORowSetValue& lhs) const ORowSetValue OOp_Quarter::operate(const ORowSetValue& lhs) const { - if ( lhs.isNull() ) + if (lhs.isNull()) return lhs; sal_Int32 nRet = 1; - css::util::Date aD = lhs; - if ( aD.Month >= 4 && aD.Month < 7 ) + css::util::Date aD = lhs.getDate(); + if (aD.Month >= 4 && aD.Month < 7) nRet = 2; - else if ( aD.Month >= 7 && aD.Month < 10 ) + else if (aD.Month >= 7 && aD.Month < 10) nRet = 3; - else if ( aD.Month >= 10 && aD.Month <= 12 ) + else if (aD.Month >= 10 && aD.Month <= 12) nRet = 4; return nRet; } ORowSetValue OOp_Week::operate(const std::vector<ORowSetValue>& lhs) const { - if ( lhs.empty() || lhs.size() > 2 ) + if (lhs.empty() || lhs.size() > 2) return ORowSetValue(); size_t nSize = lhs.size(); - css::util::Date aD = lhs[nSize-1]; - Date aDate(aD.Day,aD.Month,aD.Year); + css::util::Date aD = lhs[nSize - 1].getDate(); + Date aDate(aD.Day, aD.Month, aD.Year); sal_Int16 nStartDay = SUNDAY; - if ( nSize == 2 && !lhs[0].isNull() ) - nStartDay = lhs[0]; + if (nSize == 2 && !lhs[0].isNull()) + nStartDay = lhs[0].getInt16(); return static_cast<sal_Int16>(aDate.GetWeekOfYear(static_cast<DayOfWeek>(nStartDay))); } ORowSetValue OOp_Year::operate(const ORowSetValue& lhs) const { - if ( lhs.isNull() ) + if (lhs.isNull()) return lhs; - css::util::Date aD = lhs; + css::util::Date aD = lhs.getDate(); return aD.Year; } ORowSetValue OOp_Hour::operate(const ORowSetValue& lhs) const { - if ( lhs.isNull() ) + if (lhs.isNull()) return lhs; - css::util::Time aT = lhs; + css::util::Time aT = lhs.getTime(); return static_cast<sal_Int16>(aT.Hours); } ORowSetValue OOp_Minute::operate(const ORowSetValue& lhs) const { - if ( lhs.isNull() ) + if (lhs.isNull()) return lhs; - css::util::Time aT = lhs; + css::util::Time aT = lhs.getTime(); return static_cast<sal_Int16>(aT.Minutes); } ORowSetValue OOp_Second::operate(const ORowSetValue& lhs) const { - if ( lhs.isNull() ) + if (lhs.isNull()) return lhs; - css::util::Time aT = lhs; + css::util::Time aT = lhs.getTime(); return static_cast<sal_Int16>(aT.Seconds); } ORowSetValue OOp_CurDate::operate(const std::vector<ORowSetValue>& lhs) const { - if ( !lhs.empty() ) + if (!lhs.empty()) return ORowSetValue(); - Date aCurDate( Date::SYSTEM ); + Date aCurDate(Date::SYSTEM); return aCurDate.GetUNODate(); } ORowSetValue OOp_CurTime::operate(const std::vector<ORowSetValue>& lhs) const { - if ( !lhs.empty() ) + if (!lhs.empty()) return ORowSetValue(); - tools::Time aCurTime( tools::Time::SYSTEM ); + tools::Time aCurTime(tools::Time::SYSTEM); return aCurTime.GetUNOTime(); } ORowSetValue OOp_Now::operate(const std::vector<ORowSetValue>& lhs) const { - if ( !lhs.empty() ) + if (!lhs.empty()) return ORowSetValue(); - DateTime aCurTime( DateTime::SYSTEM ); + DateTime aCurTime(DateTime::SYSTEM); return aCurTime.GetUNODateTime(); } - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/file/FDriver.cxx b/connectivity/source/drivers/file/FDriver.cxx index 16cf60e02cb4..b24c4e67a532 100644 --- a/connectivity/source/drivers/file/FDriver.cxx +++ b/connectivity/source/drivers/file/FDriver.cxx @@ -20,11 +20,13 @@ #include <file/FDriver.hxx> #include <file/FConnection.hxx> #include <file/fcode.hxx> +#include <comphelper/servicehelper.hxx> #include <comphelper/types.hxx> #include <cppuhelper/supportsservice.hxx> #include <connectivity/dbexception.hxx> #include <strings.hrc> #include <resource/sharedresources.hxx> +#include <utility> using namespace connectivity::file; @@ -35,9 +37,9 @@ using namespace com::sun::star::sdbc; using namespace com::sun::star::sdbcx; using namespace com::sun::star::container; -OFileDriver::OFileDriver(const css::uno::Reference< css::uno::XComponentContext >& _rxContext) +OFileDriver::OFileDriver(css::uno::Reference< css::uno::XComponentContext > _xContext) : ODriver_BASE(m_aMutex) - ,m_xContext(_rxContext) + ,m_xContext(std::move(_xContext)) { } @@ -81,12 +83,11 @@ Reference< XConnection > SAL_CALL OFileDriver::connect( const OUString& url, con ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(ODriver_BASE::rBHelper.bDisposed); - OConnection* pCon = new OConnection(this); - Reference< XConnection > xCon = pCon; + rtl::Reference<OConnection> pCon = new OConnection(this); pCon->construct(url,info); m_xConnections.push_back(WeakReferenceHelper(*pCon)); - return xCon; + return pCon; } sal_Bool SAL_CALL OFileDriver::acceptsURL( const OUString& url ) @@ -98,55 +99,54 @@ Sequence< DriverPropertyInfo > SAL_CALL OFileDriver::getPropertyInfo( const OUSt { if ( acceptsURL(url) ) { - std::vector< DriverPropertyInfo > aDriverInfo; - Sequence< OUString > aBoolean(2); - aBoolean[0] = "0"; - aBoolean[1] = "1"; + Sequence< OUString > aBoolean { "0", "1" }; - aDriverInfo.push_back(DriverPropertyInfo( + return + { + { "CharSet" ,"CharSet of the database." ,false - ,OUString() - ,Sequence< OUString >()) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,{} + ,{} + }, + { "Extension" ,"Extension of the file format." ,false ,".*" - ,Sequence< OUString >()) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,{} + }, + { "ShowDeleted" ,"Display inactive records." ,false ,"0" - ,aBoolean) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,aBoolean + }, + { "EnableSQL92Check" ,"Use SQL92 naming constraints." ,false ,"0" - ,aBoolean) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,aBoolean + }, + { "UseRelativePath" ,"Handle the connection url as relative path." ,false ,"0" - ,aBoolean) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,aBoolean + }, + { "URL" ,"The URL of the database document which is used to create an absolute path." ,false - ,OUString() - ,Sequence< OUString >()) - ); - return Sequence< DriverPropertyInfo >(aDriverInfo.data(),aDriverInfo.size()); + ,{} + ,{} + } + }; } // if ( acceptsURL(url) ) { ::connectivity::SharedResources aResources; @@ -173,25 +173,15 @@ Reference< XTablesSupplier > SAL_CALL OFileDriver::getDataDefinitionByConnection ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(ODriver_BASE::rBHelper.bDisposed); - Reference< XTablesSupplier > xTab; - Reference< css::lang::XUnoTunnel> xTunnel(connection,UNO_QUERY); - if(xTunnel.is()) + if (OConnection* pSearchConnection = comphelper::getFromUnoTunnel<OConnection>(connection)) { - OConnection* pSearchConnection = reinterpret_cast< OConnection* >( xTunnel->getSomething(OConnection::getUnoTunnelId()) ); - OConnection* pConnection = nullptr; for (auto const& elem : m_xConnections) { - if (static_cast<OConnection*>( Reference< XConnection >::query(elem.get().get()).get() ) == pSearchConnection) - { - pConnection = pSearchConnection; - break; - } + if (static_cast<OConnection*>( Reference< XConnection >::query(elem.get()).get() ) == pSearchConnection) + return pSearchConnection->createCatalog(); } - - if(pConnection) - xTab = pConnection->createCatalog(); } - return xTab; + return {}; } diff --git a/connectivity/source/drivers/file/FNoException.cxx b/connectivity/source/drivers/file/FNoException.cxx index 7c26081da12e..920bb38859f1 100644 --- a/connectivity/source/drivers/file/FNoException.cxx +++ b/connectivity/source/drivers/file/FNoException.cxx @@ -85,7 +85,7 @@ void OPreparedStatement::scanParameter(OSQLParseNode* pParseNode,std::vector< OS std::unique_ptr<OKeyValue> OResultSet::GetOrderbyKeyValue(OValueRefRow const & _rRow) { - sal_uInt32 nBookmarkValue = std::abs(static_cast<sal_Int32>((*_rRow)[0]->getValue())); + sal_uInt32 nBookmarkValue = std::abs((*_rRow)[0]->getValue().getInt32()); std::unique_ptr<OKeyValue> pKeyValue = OKeyValue::createKeyValue(nBookmarkValue); diff --git a/connectivity/source/drivers/file/FNumericFunctions.cxx b/connectivity/source/drivers/file/FNumericFunctions.cxx index a6784a55c140..7c7fdc75425f 100644 --- a/connectivity/source/drivers/file/FNumericFunctions.cxx +++ b/connectivity/source/drivers/file/FNumericFunctions.cxx @@ -19,20 +19,19 @@ #include <cmath> +#include <basegfx/numeric/ftools.hxx> #include <file/FNumericFunctions.hxx> #include <rtl/math.hxx> using namespace connectivity; using namespace connectivity::file; -const double fPi = 3.14159265358979323846; - ORowSetValue OOp_Abs::operate(const ORowSetValue& lhs) const { if ( lhs.isNull() ) return lhs; - double nVal(lhs); + double nVal = lhs.getDouble(); if ( nVal < 0 ) nVal *= -1.0; return fabs(nVal); @@ -44,7 +43,7 @@ ORowSetValue OOp_Sign::operate(const ORowSetValue& lhs) const return lhs; sal_Int32 nRet = 0; - double nVal(lhs); + double nVal = lhs.getDouble(); if ( nVal < 0 ) nRet = -1; else if ( nVal > 0 ) @@ -58,7 +57,7 @@ ORowSetValue OOp_Mod::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) c if ( lhs.isNull() || rhs.isNull() ) return ORowSetValue(); - return fmod(static_cast<double>(lhs),static_cast<double>(rhs)); + return fmod(lhs.getDouble(), rhs.getDouble()); } ORowSetValue OOp_Floor::operate(const ORowSetValue& lhs) const @@ -66,7 +65,7 @@ ORowSetValue OOp_Floor::operate(const ORowSetValue& lhs) const if ( lhs.isNull() ) return lhs; - return floor(static_cast<double>(lhs)); + return floor(lhs.getDouble()); } ORowSetValue OOp_Ceiling::operate(const ORowSetValue& lhs) const @@ -74,7 +73,7 @@ ORowSetValue OOp_Ceiling::operate(const ORowSetValue& lhs) const if ( lhs.isNull() ) return lhs; - double nVal(lhs); + double nVal = lhs.getDouble(); return ceil(nVal); } @@ -84,11 +83,11 @@ ORowSetValue OOp_Round::operate(const std::vector<ORowSetValue>& lhs) const return ORowSetValue(); size_t nSize = lhs.size(); - double nVal = lhs[nSize-1]; + double nVal = lhs[nSize-1].getDouble(); sal_Int32 nDec = 0; if ( nSize == 2 && !lhs[0].isNull() ) - nDec = lhs[0]; + nDec = lhs[0].getDouble(); return ::rtl::math::round(nVal,nDec); } @@ -97,16 +96,16 @@ ORowSetValue OOp_Exp::operate(const ORowSetValue& lhs) const if ( lhs.isNull() ) return lhs; - double nVal(lhs); + double nVal = lhs.getDouble(); return exp(nVal); } ORowSetValue OOp_Ln::operate(const ORowSetValue& lhs) const { - if ( lhs.isNull() || static_cast<double>(lhs) < 0.0 ) + if ( lhs.isNull() || lhs.getDouble() < 0.0 ) return lhs; - double nVal(lhs); + double nVal = lhs.getDouble(); nVal = log(nVal); if ( std::isnan(nVal) ) return ORowSetValue(); @@ -118,11 +117,11 @@ ORowSetValue OOp_Log::operate(const std::vector<ORowSetValue>& lhs) const if ( lhs.empty() || lhs.size() > 2 ) return ORowSetValue(); size_t nSize = lhs.size(); - double nVal = log( static_cast<double>(lhs[nSize-1]) ); + double nVal = log( lhs[nSize-1].getDouble() ); if ( nSize == 2 && !lhs[0].isNull() ) - nVal /= log(static_cast<double>(lhs[0])); + nVal /= log(lhs[0].getDouble()); if ( std::isnan(nVal) ) return ORowSetValue(); @@ -131,10 +130,10 @@ ORowSetValue OOp_Log::operate(const std::vector<ORowSetValue>& lhs) const ORowSetValue OOp_Log10::operate(const ORowSetValue& lhs) const { - if ( lhs.isNull() || static_cast<double>(lhs) < 0.0 ) + if ( lhs.isNull() || lhs.getDouble() < 0.0 ) return lhs; - double nVal = log(static_cast<double>(lhs)); + double nVal = log(lhs.getDouble()); if ( std::isnan(nVal) ) return ORowSetValue(); nVal /= log(10.0); @@ -146,7 +145,7 @@ ORowSetValue OOp_Pow::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) c if ( lhs.isNull() || rhs.isNull() ) return lhs; - return pow(static_cast<double>(lhs),static_cast<double>(rhs)); + return pow(lhs.getDouble(), rhs.getDouble()); } ORowSetValue OOp_Sqrt::operate(const ORowSetValue& lhs) const @@ -154,7 +153,7 @@ ORowSetValue OOp_Sqrt::operate(const ORowSetValue& lhs) const if ( lhs.isNull() ) return lhs; - double nVal = sqrt(static_cast<double>(lhs)); + double nVal = sqrt(lhs.getDouble()); if ( std::isnan(nVal) ) return ORowSetValue(); return nVal; @@ -162,7 +161,7 @@ ORowSetValue OOp_Sqrt::operate(const ORowSetValue& lhs) const ORowSetValue OOp_Pi::operate(const std::vector<ORowSetValue>& /*lhs*/) const { - return fPi; + return M_PI; } ORowSetValue OOp_Cos::operate(const ORowSetValue& lhs) const @@ -170,7 +169,7 @@ ORowSetValue OOp_Cos::operate(const ORowSetValue& lhs) const if ( lhs.isNull() ) return lhs; - return cos(static_cast<double>(lhs)); + return cos(lhs.getDouble()); } ORowSetValue OOp_Sin::operate(const ORowSetValue& lhs) const @@ -178,7 +177,7 @@ ORowSetValue OOp_Sin::operate(const ORowSetValue& lhs) const if ( lhs.isNull() ) return lhs; - return sin(static_cast<double>(lhs)); + return sin(lhs.getDouble()); } ORowSetValue OOp_Tan::operate(const ORowSetValue& lhs) const @@ -186,7 +185,7 @@ ORowSetValue OOp_Tan::operate(const ORowSetValue& lhs) const if ( lhs.isNull() ) return lhs; - return tan(static_cast<double>(lhs)); + return tan(lhs.getDouble()); } ORowSetValue OOp_ACos::operate(const ORowSetValue& lhs) const @@ -194,7 +193,7 @@ ORowSetValue OOp_ACos::operate(const ORowSetValue& lhs) const if ( lhs.isNull() ) return lhs; - return acos(static_cast<double>(lhs)); + return acos(lhs.getDouble()); } ORowSetValue OOp_ASin::operate(const ORowSetValue& lhs) const @@ -202,7 +201,7 @@ ORowSetValue OOp_ASin::operate(const ORowSetValue& lhs) const if ( lhs.isNull() ) return lhs; - return asin(static_cast<double>(lhs)); + return asin(lhs.getDouble()); } ORowSetValue OOp_ATan::operate(const ORowSetValue& lhs) const @@ -210,7 +209,7 @@ ORowSetValue OOp_ATan::operate(const ORowSetValue& lhs) const if ( lhs.isNull() ) return lhs; - return atan(static_cast<double>(lhs)); + return atan(lhs.getDouble()); } ORowSetValue OOp_ATan2::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const @@ -218,7 +217,7 @@ ORowSetValue OOp_ATan2::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) if ( lhs.isNull() || rhs.isNull() ) return lhs; - return atan2(static_cast<double>(lhs),static_cast<double>(rhs)); + return atan2(lhs.getDouble(), rhs.getDouble()); } ORowSetValue OOp_Degrees::operate(const ORowSetValue& lhs) const @@ -226,8 +225,8 @@ ORowSetValue OOp_Degrees::operate(const ORowSetValue& lhs) const if ( lhs.isNull() ) return lhs; - double nLhs = lhs; - return nLhs*180*(1.0/fPi); + double nLhs = lhs.getDouble(); + return basegfx::rad2deg(nLhs); } ORowSetValue OOp_Radians::operate(const ORowSetValue& lhs) const @@ -235,8 +234,8 @@ ORowSetValue OOp_Radians::operate(const ORowSetValue& lhs) const if ( lhs.isNull() ) return lhs; - double nLhs = lhs; - return nLhs*fPi*(1.0/180.0); + double nLhs = lhs.getDouble(); + return basegfx::deg2rad(nLhs); } diff --git a/connectivity/source/drivers/file/FPreparedStatement.cxx b/connectivity/source/drivers/file/FPreparedStatement.cxx index fc5b81923cb4..f2a8571b61e5 100644 --- a/connectivity/source/drivers/file/FPreparedStatement.cxx +++ b/connectivity/source/drivers/file/FPreparedStatement.cxx @@ -18,6 +18,7 @@ */ +#include <o3tl/safeint.hxx> #include <osl/diagnose.h> #include <file/FPreparedStatement.hxx> #include <com/sun/star/sdbc/DataType.hpp> @@ -100,7 +101,7 @@ rtl::Reference<OResultSet> OPreparedStatement::makeResultSet() closeResultSet(); rtl::Reference<OResultSet> xResultSet(createResultSet()); - m_xResultSet = xResultSet.get(); + m_xResultSet = uno::Reference<uno::XWeak>(xResultSet); initializeResultSet(xResultSet.get()); initResultSet(xResultSet.get()); return xResultSet; @@ -133,7 +134,7 @@ Reference< XResultSetMetaData > SAL_CALL OPreparedStatement::getMetaData( ) if(!m_xMetaData.is()) m_xMetaData = new OResultSetMetaData(m_aSQLIterator.getSelectColumns(),m_aSQLIterator.getTables().begin()->first,m_pTable.get()); - return m_xMetaData.get(); + return m_xMetaData; } @@ -189,7 +190,7 @@ Reference< XConnection > SAL_CALL OPreparedStatement::getConnection( ) ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OStatement_BASE::rBHelper.bDisposed); - return Reference< XConnection >(m_pConnection.get()); + return m_pConnection; } @@ -198,7 +199,7 @@ Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery( ) ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OStatement_BASE::rBHelper.bDisposed); - return makeResultSet().get(); + return makeResultSet(); } @@ -363,7 +364,7 @@ void SAL_CALL OPreparedStatement::clearParameters( ) m_aParameterRow->push_back(new ORowSetValueDecorator(sal_Int32(0)) ); } -OResultSet* OPreparedStatement::createResultSet() +rtl::Reference<OResultSet> OPreparedStatement::createResultSet() { return new OResultSet(this,m_aSQLIterator); } @@ -379,12 +380,12 @@ void OPreparedStatement::initResultSet(OResultSet *pResultSet) pResultSet->setMetaData(getMetaData()); } -void SAL_CALL OPreparedStatement::acquire() throw() +void SAL_CALL OPreparedStatement::acquire() noexcept { OStatement_BASE2::acquire(); } -void SAL_CALL OPreparedStatement::release() throw() +void SAL_CALL OPreparedStatement::release() noexcept { OStatement_BASE2::release(); } @@ -392,7 +393,7 @@ void SAL_CALL OPreparedStatement::release() throw() void OPreparedStatement::checkAndResizeParameters(sal_Int32 parameterIndex) { ::connectivity::checkDisposed(OStatement_BASE::rBHelper.bDisposed); - if ( m_aAssignValues.is() && (parameterIndex < 1 || parameterIndex >= static_cast<sal_Int32>(m_aParameterIndexes.size())) ) + if ( m_aAssignValues.is() && (parameterIndex < 1 || o3tl::make_unsigned(parameterIndex) >= m_aParameterIndexes.size()) ) throwInvalidIndexException(*this); else if ( static_cast<sal_Int32>(m_aParameterRow->size()) <= parameterIndex ) { diff --git a/connectivity/source/drivers/file/FResultSet.cxx b/connectivity/source/drivers/file/FResultSet.cxx index d7f3d6bd2090..5612c68feedf 100644 --- a/connectivity/source/drivers/file/FResultSet.cxx +++ b/connectivity/source/drivers/file/FResultSet.cxx @@ -29,6 +29,7 @@ #include <cppuhelper/typeprovider.hxx> #include <connectivity/dbtools.hxx> #include <cppuhelper/propshlp.hxx> +#include <o3tl/safeint.hxx> #include <sal/log.hxx> #include <iterator> #include <com/sun/star/sdbc/ResultSetType.hpp> @@ -41,6 +42,7 @@ #include <comphelper/types.hxx> #include <resource/sharedresources.hxx> #include <strings.hrc> +#include <comphelper/diagnose_ex.hxx> using namespace ::comphelper; using namespace connectivity; @@ -56,7 +58,7 @@ using namespace com::sun::star::container; namespace { - void lcl_throwError(const char* pErrorId, const css::uno::Reference< css::uno::XInterface>& _xContext) + void lcl_throwError(TranslateId pErrorId, const css::uno::Reference< css::uno::XInterface>& _xContext) { ::connectivity::SharedResources aResources; const OUString sMessage = aResources.getResourceString(pErrorId); @@ -132,9 +134,8 @@ void OResultSet::disposing() m_xColumns = nullptr; m_xColsIdx.clear(); - Reference<XComponent> xComp = m_pTable.get(); - if ( xComp.is() ) - xComp->removeEventListener(this); + if ( m_pTable.is() ) + m_pTable->removeEventListener(this); m_pTable.clear(); m_pFileSet = nullptr; @@ -217,43 +218,43 @@ Reference< css::io::XInputStream > SAL_CALL OResultSet::getCharacterStream( sal_ sal_Bool SAL_CALL OResultSet::getBoolean( sal_Int32 columnIndex ) { - return bool(getValue(columnIndex)); + return getValue(columnIndex).getBool(); } sal_Int8 SAL_CALL OResultSet::getByte( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getInt8(); } Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getSequence(); } css::util::Date SAL_CALL OResultSet::getDate( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getDate(); } double SAL_CALL OResultSet::getDouble( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getDouble(); } float SAL_CALL OResultSet::getFloat( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getFloat(); } sal_Int32 SAL_CALL OResultSet::getInt( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getInt32(); } @@ -264,13 +265,13 @@ sal_Int32 SAL_CALL OResultSet::getRow( ) OSL_ENSURE((m_bShowDeleted || !m_aRow->isDeleted()),"getRow called for deleted row"); - return m_aSkipDeletedSet.getMappedPosition((*m_aRow)[0]->getValue()); + return m_aSkipDeletedSet.getMappedPosition((*m_aRow)[0]->getValue().getInt32()); } sal_Int64 SAL_CALL OResultSet::getLong( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getLong(); } @@ -316,22 +317,22 @@ Any SAL_CALL OResultSet::getObject( sal_Int32 columnIndex, const Reference< css: sal_Int16 SAL_CALL OResultSet::getShort( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getInt16(); } OUString SAL_CALL OResultSet::getString( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getString(); } css::util::Time SAL_CALL OResultSet::getTime( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getTime(); } css::util::DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 columnIndex ) { - return getValue(columnIndex); + return getValue(columnIndex).getDateTime(); } @@ -518,12 +519,12 @@ void SAL_CALL OResultSet::insertRow( ) m_bRowInserted = m_pTable->InsertRow(*m_aInsertRow, m_xColsIdx); if(m_bRowInserted && m_pFileSet.is()) { - sal_Int32 nPos = (*m_aInsertRow)[0]->getValue(); + sal_Int32 nPos = (*m_aInsertRow)[0]->getValue().getInt32(); m_pFileSet->push_back(nPos); *(*m_aInsertRow)[0] = sal_Int32(m_pFileSet->size()); clearInsertRow(); - m_aSkipDeletedSet.insertNewPosition((*m_aRow)[0]->getValue()); + m_aSkipDeletedSet.insertNewPosition((*m_aRow)[0]->getValue().getInt32()); } } @@ -536,7 +537,7 @@ void SAL_CALL OResultSet::updateRow( ) lcl_throwError(STR_TABLE_READONLY,*this); m_bRowUpdated = m_pTable->UpdateRow(*m_aInsertRow, m_aRow,m_xColsIdx); - *(*m_aInsertRow)[0] = static_cast<sal_Int32>((*m_aRow)[0]->getValue()); + *(*m_aInsertRow)[0] = (*m_aRow)[0]->getValue().getInt32(); clearInsertRow(); } @@ -553,7 +554,7 @@ void SAL_CALL OResultSet::deleteRow() if(m_aRow->isDeleted()) lcl_throwError(STR_ROW_ALREADY_DELETED,*this); - sal_Int32 nPos = static_cast<sal_Int32>((*m_aRow)[0]->getValue()); + sal_Int32 nPos = (*m_aRow)[0]->getValue().getInt32(); m_bRowDeleted = m_pTable->DeleteRow(*m_xColumns); if(m_bRowDeleted && m_pFileSet.is()) { @@ -837,7 +838,7 @@ again: } else if (m_pFileSet.is()) { - sal_uInt32 nBookmarkValue = std::abs(static_cast<sal_Int32>((*m_aEvaluateRow)[0]->getValue())); + sal_uInt32 nBookmarkValue = std::abs((*m_aEvaluateRow)[0]->getValue().getInt32()); m_pFileSet->push_back(nBookmarkValue); } } @@ -921,7 +922,7 @@ bool OResultSet::Move(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOff // The FileCursor is outside of the valid range, if: // a.) m_nRowPos < 1 // b.) a KeySet exists and m_nRowPos > m_pFileSet->size() - if (m_nRowPos < 0 || (m_pFileSet->isFrozen() && eCursorPosition != IResultSetHelper::BOOKMARK && m_nRowPos >= static_cast<sal_Int32>(m_pFileSet->size()) )) // && m_pFileSet->IsFrozen() + if (m_nRowPos < 0 || (m_pFileSet->isFrozen() && eCursorPosition != IResultSetHelper::BOOKMARK && o3tl::make_unsigned(m_nRowPos) >= m_pFileSet->size() )) // && m_pFileSet->IsFrozen() { goto Error; } @@ -1136,14 +1137,14 @@ void OResultSet::sortRows() ++i; } - m_pSortIndex.reset(new OSortIndex(eKeyType,m_aOrderbyAscending)); + m_pSortIndex.reset(new OSortIndex(std::move(eKeyType), std::vector(m_aOrderbyAscending))); while ( ExecuteRow( IResultSetHelper::NEXT, 1, false ) ) { (*m_aSelectRow)[0]->setValue( (*m_aRow)[0]->getValue() ); if ( m_pSQLAnalyzer->hasFunctions() ) m_pSQLAnalyzer->setSelectionEvaluationResult( m_aSelectRow, m_aColMapping ); - const sal_Int32 nBookmark = (*m_aRow->begin())->getValue(); + const sal_Int32 nBookmark = (*m_aRow->begin())->getValue().getInt32(); ExecuteRow( IResultSetHelper::BOOKMARK, nBookmark, true, false ); } @@ -1380,22 +1381,6 @@ void OResultSet::OpenImpl() m_nFilePos = 0; } -Sequence< sal_Int8 > OResultSet::getUnoTunnelId() -{ - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); -} - -// css::lang::XUnoTunnel - -sal_Int64 OResultSet::getSomething( const Sequence< sal_Int8 > & rId ) -{ - return isUnoTunnelId<OResultSet>(rId) - ? reinterpret_cast< sal_Int64 >( this ) - : 0; -} - void OResultSet::setBoundedColumns(const OValueRefRow& _rRow, const OValueRefRow& _rSelectRow, const ::rtl::Reference<connectivity::OSQLColumns>& _rxColumns, @@ -1468,7 +1453,7 @@ void OResultSet::setBoundedColumns(const OValueRefRow& _rRow, } catch (Exception&) { - SAL_WARN( "connectivity.drivers","OResultSet::setBoundedColumns: caught an Exception!"); + TOOLS_WARN_EXCEPTION( "connectivity.drivers",""); } } // in this case we got more select columns as columns exist in the table @@ -1513,12 +1498,12 @@ void OResultSet::setBoundedColumns(const OValueRefRow& _rRow, } } -void SAL_CALL OResultSet::acquire() throw() +void SAL_CALL OResultSet::acquire() noexcept { OResultSet_BASE::acquire(); } -void SAL_CALL OResultSet::release() throw() +void SAL_CALL OResultSet::release() noexcept { OResultSet_BASE::release(); } @@ -1530,8 +1515,7 @@ Reference< css::beans::XPropertySetInfo > SAL_CALL OResultSet::getPropertySetInf void OResultSet::doTableSpecials(const OSQLTable& _xTable) { - Reference<css::lang::XUnoTunnel> xTunnel(_xTable, UNO_QUERY_THROW); - m_pTable = reinterpret_cast< OFileTable* >(xTunnel->getSomething(OFileTable::getUnoTunnelId())); + m_pTable = dynamic_cast<OFileTable*>(_xTable.get()); assert(m_pTable.is()); } @@ -1574,7 +1558,7 @@ bool OResultSet::move(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nO sal_Int32 OResultSet::getDriverPos() const { - return (*m_aRow)[0]->getValue(); + return (*m_aRow)[0]->getValue().getInt32(); } bool OResultSet::isRowDeleted() const @@ -1584,7 +1568,7 @@ bool OResultSet::isRowDeleted() const void SAL_CALL OResultSet::disposing( const EventObject& Source ) { - Reference<XPropertySet> xProp = m_pTable.get(); + Reference<XPropertySet> xProp = m_pTable; if(m_pTable.is() && Source.Source == xProp) { m_pTable.clear(); diff --git a/connectivity/source/drivers/file/FResultSetMetaData.cxx b/connectivity/source/drivers/file/FResultSetMetaData.cxx index f68a06532bb7..44898d88242b 100644 --- a/connectivity/source/drivers/file/FResultSetMetaData.cxx +++ b/connectivity/source/drivers/file/FResultSetMetaData.cxx @@ -22,6 +22,8 @@ #include <comphelper/extract.hxx> #include <connectivity/dbexception.hxx> #include <comphelper/types.hxx> +#include <o3tl/safeint.hxx> +#include <utility> using namespace ::comphelper; @@ -33,12 +35,11 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; -OResultSetMetaData::OResultSetMetaData(const ::rtl::Reference<connectivity::OSQLColumns>& _rxColumns,const OUString& _aTableName,OFileTable* _pTable) - :m_aTableName(_aTableName) - ,m_xColumns(_rxColumns) +OResultSetMetaData::OResultSetMetaData(::rtl::Reference<connectivity::OSQLColumns> _xColumns, OUString _aTableName, OFileTable* _pTable) + :m_aTableName(std::move(_aTableName)) + ,m_xColumns(std::move(_xColumns)) ,m_pTable(_pTable) { } @@ -51,7 +52,7 @@ OResultSetMetaData::~OResultSetMetaData() void OResultSetMetaData::checkColumnIndex(sal_Int32 column) { - if(column <= 0 || column > static_cast<sal_Int32>(m_xColumns->size())) + if(column <= 0 || o3tl::make_unsigned(column) > m_xColumns->size()) throwInvalidIndexException(*this); } diff --git a/connectivity/source/drivers/file/FStatement.cxx b/connectivity/source/drivers/file/FStatement.cxx index 08c4f7fdd844..4520abfeff1d 100644 --- a/connectivity/source/drivers/file/FStatement.cxx +++ b/connectivity/source/drivers/file/FStatement.cxx @@ -32,11 +32,13 @@ #include <com/sun/star/sdbc/FetchDirection.hpp> #include <com/sun/star/lang/DisposedException.hpp> #include <comphelper/sequence.hxx> +#include <comphelper/servicehelper.hxx> #include <cppuhelper/typeprovider.hxx> #include <comphelper/types.hxx> #include <connectivity/dbexception.hxx> #include <strings.hrc> #include <algorithm> +#include <cstddef> namespace connectivity::file { @@ -128,12 +130,12 @@ void OStatement_BASE2::disposing() OStatement_Base::disposing(); } -void SAL_CALL OStatement_Base::acquire() throw() +void SAL_CALL OStatement_Base::acquire() noexcept { OStatement_BASE::acquire(); } -void SAL_CALL OStatement_BASE2::release() throw() +void SAL_CALL OStatement_BASE2::release() noexcept { OStatement_BASE::release(); } @@ -192,7 +194,7 @@ Any SAL_CALL OStatement_Base::getWarnings( ) ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OStatement_BASE::rBHelper.bDisposed); - return makeAny(m_aLastWarning); + return Any(m_aLastWarning); } void SAL_CALL OStatement_Base::clearWarnings( ) @@ -216,19 +218,19 @@ void SAL_CALL OStatement_Base::clearWarnings( ) return *getArrayHelper(); } -OResultSet* OStatement::createResultSet() +rtl::Reference<OResultSet> OStatement::createResultSet() { return new OResultSet(this,m_aSQLIterator); } IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbc.driver.file.Statement","com.sun.star.sdbc.Statement"); -void SAL_CALL OStatement::acquire() throw() +void SAL_CALL OStatement::acquire() noexcept { OStatement_BASE2::acquire(); } -void SAL_CALL OStatement::release() throw() +void SAL_CALL OStatement::release() noexcept { OStatement_BASE2::release(); } @@ -251,9 +253,9 @@ Reference< XResultSet > SAL_CALL OStatement::executeQuery( const OUString& sql ) construct(sql); Reference< XResultSet > xRS; - OResultSet* pResult = createResultSet(); + rtl::Reference<OResultSet> pResult = createResultSet(); xRS = pResult; - initializeResultSet(pResult); + initializeResultSet(pResult.get()); m_xResultSet = xRS; pResult->OpenImpl(); @@ -263,7 +265,7 @@ Reference< XResultSet > SAL_CALL OStatement::executeQuery( const OUString& sql ) Reference< XConnection > SAL_CALL OStatement::getConnection( ) { - return Reference< XConnection >(m_pConnection.get()); + return m_pConnection; } sal_Int32 SAL_CALL OStatement::executeUpdate( const OUString& sql ) @@ -302,9 +304,9 @@ Any SAL_CALL OStatement::queryInterface( const Type & rType ) return aRet.hasValue() ? aRet : OStatement_BASE2::queryInterface( rType); } -void OStatement_Base::anylizeSQL() +void OStatement_Base::analyzeSQL() { - OSL_ENSURE(m_pSQLAnalyzer,"OResultSet::anylizeSQL: Analyzer isn't set!"); + OSL_ENSURE(m_pSQLAnalyzer,"OResultSet::analyzeSQL: Analyzer isn't set!"); // start analysing the statement m_pSQLAnalyzer->setOrigColumns(m_xColNames); m_pSQLAnalyzer->start(m_pParseTree); @@ -394,16 +396,19 @@ void OStatement_Base::construct(const OUString& sql) case OSQLStatementType::Unknown: m_pConnection->throwGenericSQLException(STR_QUERY_TOO_COMPLEX,*this); break; + case OSQLStatementType::Select: + if(SQL_ISRULE(m_aSQLIterator.getParseTree(), union_statement)) + { + m_pConnection->throwGenericSQLException(STR_QUERY_TOO_COMPLEX, *this); + } + assert(SQL_ISRULE(m_aSQLIterator.getParseTree(), select_statement)); + break; default: break; } // at this moment we support only one table per select statement - Reference< css::lang::XUnoTunnel> xTunnel(rTabs.begin()->second,UNO_QUERY); - if(xTunnel.is()) - { - m_pTable = reinterpret_cast<OFileTable*>(xTunnel->getSomething(OFileTable::getUnoTunnelId())); - } + m_pTable = dynamic_cast<OFileTable*>(rTabs.begin()->second.get()); OSL_ENSURE(m_pTable.is(),"No table!"); if ( m_pTable.is() ) m_xColNames = m_pTable->getColumns(); @@ -428,7 +433,7 @@ void OStatement_Base::construct(const OUString& sql) m_pSQLAnalyzer.reset( new OSQLAnalyzer(m_pConnection.get()) ); - anylizeSQL(); + analyzeSQL(); } void OStatement_Base::createColumnMapping() @@ -436,7 +441,7 @@ void OStatement_Base::createColumnMapping() // initialize the column index map (mapping select columns to table columns) ::rtl::Reference<connectivity::OSQLColumns> xColumns = m_aSQLIterator.getSelectColumns(); m_aColMapping.resize(xColumns->size() + 1); - for (sal_Int32 i=0; i<static_cast<sal_Int32>(m_aColMapping.size()); ++i) + for (std::size_t i=0; i<m_aColMapping.size(); ++i) m_aColMapping[i] = i; Reference<XIndexAccess> xNames(m_xColNames,UNO_QUERY); @@ -449,10 +454,10 @@ void OStatement_Base::initializeResultSet(OResultSet* _pResult) GetAssignValues(); _pResult->setSqlAnalyzer(m_pSQLAnalyzer.get()); - _pResult->setOrderByColumns(m_aOrderbyColumnNumber); - _pResult->setOrderByAscending(m_aOrderbyAscending); + _pResult->setOrderByColumns(std::vector(m_aOrderbyColumnNumber)); + _pResult->setOrderByAscending(std::vector(m_aOrderbyAscending)); _pResult->setBindingRow(m_aRow); - _pResult->setColumnMapping(m_aColMapping); + _pResult->setColumnMapping(std::vector(m_aColMapping)); _pResult->setEvaluationRow(m_aEvaluateRow); _pResult->setAssignValues(m_aAssignValues); _pResult->setSelectRow(m_aSelectRow); @@ -495,10 +500,7 @@ void OStatement_Base::GetAssignValues() if (pOptColumnCommalist->count() == 0) { const Sequence< OUString>& aNames = m_xColNames->getElementNames(); - const OUString* pBegin = aNames.getConstArray(); - const OUString* pEnd = pBegin + aNames.getLength(); - for (; pBegin != pEnd; ++pBegin) - aColumnNameList.push_back(*pBegin); + aColumnNameList.insert(aColumnNameList.end(), aNames.begin(), aNames.end()); } else { diff --git a/connectivity/source/drivers/file/FStringFunctions.cxx b/connectivity/source/drivers/file/FStringFunctions.cxx index 32f590e310f7..d02c7cce1737 100644 --- a/connectivity/source/drivers/file/FStringFunctions.cxx +++ b/connectivity/source/drivers/file/FStringFunctions.cxx @@ -17,8 +17,9 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - #include <file/FStringFunctions.hxx> + +#include <comphelper/string.hxx> #include <rtl/ustrbuf.hxx> using namespace connectivity; @@ -26,7 +27,7 @@ using namespace connectivity::file; ORowSetValue OOp_Upper::operate(const ORowSetValue& lhs) const { - if ( lhs.isNull() ) + if (lhs.isNull()) return lhs; return lhs.getString().toAsciiUpperCase(); @@ -34,7 +35,7 @@ ORowSetValue OOp_Upper::operate(const ORowSetValue& lhs) const ORowSetValue OOp_Lower::operate(const ORowSetValue& lhs) const { - if ( lhs.isNull() ) + if (lhs.isNull()) return lhs; return lhs.getString().toAsciiLowerCase(); @@ -42,16 +43,16 @@ ORowSetValue OOp_Lower::operate(const ORowSetValue& lhs) const ORowSetValue OOp_Ascii::operate(const ORowSetValue& lhs) const { - if ( lhs.isNull() ) + if (lhs.isNull()) return lhs; - OString sStr(OUStringToOString(lhs,RTL_TEXTENCODING_ASCII_US)); + OString sStr(OUStringToOString(lhs.getString(), RTL_TEXTENCODING_ASCII_US)); sal_Int32 nAscii = sStr.toChar(); return nAscii; } ORowSetValue OOp_CharLength::operate(const ORowSetValue& lhs) const { - if ( lhs.isNull() ) + if (lhs.isNull()) return lhs; return lhs.getString().getLength(); @@ -59,17 +60,17 @@ ORowSetValue OOp_CharLength::operate(const ORowSetValue& lhs) const ORowSetValue OOp_Char::operate(const std::vector<ORowSetValue>& lhs) const { - if ( lhs.empty() ) + if (lhs.empty()) return ORowSetValue(); - OUStringBuffer sRet; + OUStringBuffer sRet(static_cast<sal_Int32>(lhs.size())); std::vector<ORowSetValue>::const_reverse_iterator aIter = lhs.rbegin(); std::vector<ORowSetValue>::const_reverse_iterator aEnd = lhs.rend(); for (; aIter != aEnd; ++aIter) { - if ( !aIter->isNull() ) + if (!aIter->isNull()) { - char c = static_cast<char>(static_cast<sal_Int32>(*aIter)); + char c = static_cast<char>(aIter->getInt32()); sRet.appendAscii(&c, 1); } @@ -80,7 +81,7 @@ ORowSetValue OOp_Char::operate(const std::vector<ORowSetValue>& lhs) const ORowSetValue OOp_Concat::operate(const std::vector<ORowSetValue>& lhs) const { - if ( lhs.empty() ) + if (lhs.empty()) return ORowSetValue(); OUStringBuffer sRet; @@ -88,10 +89,10 @@ ORowSetValue OOp_Concat::operate(const std::vector<ORowSetValue>& lhs) const std::vector<ORowSetValue>::const_reverse_iterator aEnd = lhs.rend(); for (; aIter != aEnd; ++aIter) { - if ( aIter->isNull() ) + if (aIter->isNull()) return ORowSetValue(); - sRet.append(aIter->operator OUString()); + sRet.append(aIter->getString()); } return sRet.makeStringAndClear(); @@ -99,135 +100,127 @@ ORowSetValue OOp_Concat::operate(const std::vector<ORowSetValue>& lhs) const ORowSetValue OOp_Locate::operate(const std::vector<ORowSetValue>& lhs) const { - if (std::any_of(lhs.begin(), lhs.end(), [](const ORowSetValue& rValue) { return rValue.isNull(); })) + if (std::any_of(lhs.begin(), lhs.end(), + [](const ORowSetValue& rValue) { return rValue.isNull(); })) return ORowSetValue(); - if ( lhs.size() == 2 ) - return OUString(OUString::number(lhs[0].getString().indexOf(lhs[1].getString())+1)); + if (lhs.size() == 2) + return OUString(OUString::number(lhs[0].getString().indexOf(lhs[1].getString()) + 1)); - else if ( lhs.size() != 3 ) + else if (lhs.size() != 3) return ORowSetValue(); - return lhs[1].getString().indexOf(lhs[2].getString(),lhs[0]) + 1; + return lhs[1].getString().indexOf(lhs[2].getString(), lhs[0].getInt32()) + 1; } ORowSetValue OOp_SubString::operate(const std::vector<ORowSetValue>& lhs) const { - if (std::any_of(lhs.begin(), lhs.end(), [](const ORowSetValue& rValue) { return rValue.isNull(); })) + if (std::any_of(lhs.begin(), lhs.end(), + [](const ORowSetValue& rValue) { return rValue.isNull(); })) return ORowSetValue(); - if ( lhs.size() == 2 && static_cast<sal_Int32>(lhs[0]) >= sal_Int32(0) ) - return lhs[1].getString().copy(static_cast<sal_Int32>(lhs[0])-1); + if (lhs.size() == 2 && lhs[0].getInt32() >= sal_Int32(0)) + return lhs[1].getString().copy(lhs[0].getInt32() - 1); - else if ( lhs.size() != 3 || static_cast<sal_Int32>(lhs[1]) < sal_Int32(0)) + else if (lhs.size() != 3 || lhs[1].getInt32() < sal_Int32(0)) return ORowSetValue(); - return lhs[2].getString().copy(static_cast<sal_Int32>(lhs[1])-1,lhs[0]); + return lhs[2].getString().copy(lhs[1].getInt32() - 1, lhs[0].getInt32()); } ORowSetValue OOp_LTrim::operate(const ORowSetValue& lhs) const { - if ( lhs.isNull() ) + if (lhs.isNull()) return lhs; - OUString sRet = lhs; + OUString sRet = lhs.getString(); OUString sNew = sRet.trim(); return sRet.copy(sRet.indexOf(sNew)); } ORowSetValue OOp_RTrim::operate(const ORowSetValue& lhs) const { - if ( lhs.isNull() ) + if (lhs.isNull()) return lhs; - OUString sRet = lhs; + OUString sRet = lhs.getString(); OUString sNew = sRet.trim(); - return sRet.copy(0,sRet.lastIndexOf(sNew[sNew.getLength()-1])+1); + return sRet.copy(0, sRet.lastIndexOf(sNew[sNew.getLength() - 1]) + 1); } ORowSetValue OOp_Space::operate(const ORowSetValue& lhs) const { - if ( lhs.isNull() ) + if (lhs.isNull()) return lhs; - const char c = ' '; - OUStringBuffer sRet; - sal_Int32 nCount = lhs; - for (sal_Int32 i=0; i < nCount; ++i) - { - sRet.appendAscii(&c,1); - } + sal_Int32 nCount = std::max(lhs.getInt32(), sal_Int32(0)); + OUStringBuffer sRet(nCount); + comphelper::string::padToLength(sRet, nCount, ' '); return sRet.makeStringAndClear(); } ORowSetValue OOp_Replace::operate(const std::vector<ORowSetValue>& lhs) const { - if ( lhs.size() != 3 ) + if (lhs.size() != 3) return ORowSetValue(); - OUString sStr = lhs[2]; - OUString sFrom = lhs[1]; - OUString sTo = lhs[0]; - sal_Int32 nIndexOf = sStr.indexOf(sFrom); - while( nIndexOf != -1 ) - { - sStr = sStr.replaceAt(nIndexOf,sFrom.getLength(),sTo); - nIndexOf = sStr.indexOf(sFrom,nIndexOf + sTo.getLength()); - } - - return sStr; + OUString sStr = lhs[2].getString(); + OUString sFrom = lhs[1].getString(); + OUString sTo = lhs[0].getString(); + return sStr.replaceAll(sFrom, sTo); } -ORowSetValue OOp_Repeat::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const +ORowSetValue OOp_Repeat::operate(const ORowSetValue& lhs, const ORowSetValue& rhs) const { - if ( lhs.isNull() || rhs.isNull() ) + if (lhs.isNull() || rhs.isNull()) return lhs; - OUStringBuffer sRet; - sal_Int32 nCount = rhs; - for (sal_Int32 i=0; i < nCount; ++i) + const OUString s = lhs.getString(); + const sal_Int32 nCount = std::max(rhs.getInt32(), sal_Int32(0)); + OUStringBuffer sRet(s.getLength() * nCount); + for (sal_Int32 i = 0; i < nCount; ++i) { - sRet.append(lhs.operator OUString()); + sRet.append(s); } return sRet.makeStringAndClear(); } ORowSetValue OOp_Insert::operate(const std::vector<ORowSetValue>& lhs) const { - if ( lhs.size() != 4 ) + if (lhs.size() != 4) return ORowSetValue(); - OUString sStr = lhs[3]; + OUString sStr = lhs[3].getString(); - sal_Int32 nStart = static_cast<sal_Int32>(lhs[2]); - if ( nStart < 1 ) + sal_Int32 nStart = lhs[2].getInt32(); + if (nStart < 1) nStart = 1; - return sStr.replaceAt(nStart-1,static_cast<sal_Int32>(lhs[1]),lhs[0]); + return sStr.replaceAt(nStart - 1, lhs[1].getInt32(), lhs[0].getString()); } -ORowSetValue OOp_Left::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const +ORowSetValue OOp_Left::operate(const ORowSetValue& lhs, const ORowSetValue& rhs) const { - if ( lhs.isNull() || rhs.isNull() ) + if (lhs.isNull() || rhs.isNull()) return lhs; - OUString sRet = lhs; - sal_Int32 nCount = rhs; - if ( nCount < 0 ) + OUString sRet = lhs.getString(); + sal_Int32 nCount = rhs.getInt32(); + if (nCount < 0) return ORowSetValue(); - return sRet.copy(0,nCount); + return sRet.copy(0, nCount); } -ORowSetValue OOp_Right::operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const +ORowSetValue OOp_Right::operate(const ORowSetValue& lhs, const ORowSetValue& rhs) const { - if ( lhs.isNull() || rhs.isNull() ) + if (lhs.isNull() || rhs.isNull()) return lhs; - sal_Int32 nCount = rhs; - OUString sRet = lhs; - if ( nCount < 0 || nCount >= sRet.getLength() ) + sal_Int32 nCount = rhs.getInt32(); + OUString sRet = lhs.getString(); + if (nCount < 0 || nCount >= sRet.getLength()) return ORowSetValue(); - return sRet.copy(sRet.getLength()-nCount,nCount); + return sRet.copy(sRet.getLength() - nCount, nCount); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/file/FTable.cxx b/connectivity/source/drivers/file/FTable.cxx index b47bfb811a1f..06dc187fa20e 100644 --- a/connectivity/source/drivers/file/FTable.cxx +++ b/connectivity/source/drivers/file/FTable.cxx @@ -23,7 +23,6 @@ #include <com/sun/star/sdbc/XRow.hpp> #include <com/sun/star/sdbc/XResultSet.hpp> #include <comphelper/servicehelper.hxx> -#include <cppuhelper/typeprovider.hxx> #include <unotools/ucbstreamhelper.hxx> using namespace connectivity; @@ -87,7 +86,7 @@ void OFileTable::refreshColumns() if(m_xColumns) m_xColumns->reFill(aVector); else - m_xColumns = new OColumns(this,m_aMutex,aVector); + m_xColumns.reset(new OColumns(this,m_aMutex,aVector)); } void OFileTable::refreshKeys() @@ -119,29 +118,10 @@ void SAL_CALL OFileTable::disposing() FileClose(); } -Sequence< sal_Int8 > OFileTable::getUnoTunnelId() -{ - static ::cppu::OImplementationId s_Id; - - return s_Id.getImplementationId(); -} - -// css::lang::XUnoTunnel - -sal_Int64 OFileTable::getSomething( const Sequence< sal_Int8 > & rId ) -{ - return isUnoTunnelId<OFileTable>(rId) - ? reinterpret_cast< sal_Int64 >( this ) - : OTable_TYPEDEF::getSomething(rId); -} - void OFileTable::FileClose() { ::osl::MutexGuard aGuard(m_aMutex); - if (m_pFileStream && m_pFileStream->IsWritable()) - m_pFileStream->Flush(); - m_pFileStream.reset(); m_pBuffer.reset(); } diff --git a/connectivity/source/drivers/file/FTables.cxx b/connectivity/source/drivers/file/FTables.cxx index c063f4a890e6..eda988d9bb44 100644 --- a/connectivity/source/drivers/file/FTables.cxx +++ b/connectivity/source/drivers/file/FTables.cxx @@ -23,10 +23,8 @@ using namespace connectivity; using namespace connectivity::file; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; sdbcx::ObjectType OTables::createObject(const OUString& /*_rName*/) { diff --git a/connectivity/source/drivers/file/fanalyzer.cxx b/connectivity/source/drivers/file/fanalyzer.cxx index a0d1305f6f89..0a749cc3b22d 100644 --- a/connectivity/source/drivers/file/fanalyzer.cxx +++ b/connectivity/source/drivers/file/fanalyzer.cxx @@ -28,7 +28,6 @@ using namespace ::connectivity; using namespace ::connectivity::file; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; OSQLAnalyzer::OSQLAnalyzer(OConnection* _pConnection) diff --git a/connectivity/source/drivers/file/fcode.cxx b/connectivity/source/drivers/file/fcode.cxx index 36cba4a73485..ec56032c8491 100644 --- a/connectivity/source/drivers/file/fcode.cxx +++ b/connectivity/source/drivers/file/fcode.cxx @@ -20,11 +20,10 @@ #include <file/fcode.hxx> #include <osl/diagnose.h> #include <sal/log.hxx> -#include <connectivity/sqlparse.hxx> +#include <connectivity/sqlnode.hxx> #include <sqlbison.hxx> #include <com/sun/star/sdb/SQLFilterOperator.hpp> -using namespace ::comphelper; using namespace connectivity; using namespace connectivity::file; using namespace ::com::sun::star::sdbc; @@ -63,32 +62,14 @@ void OOperandValue::setValue(const ORowSetValue& _rVal) m_aValue = _rVal; } -OOperandParam::OOperandParam(OSQLParseNode const * pNode, sal_Int32 _nPos) +OOperandParam::OOperandParam(sal_Int32 _nPos) : OOperandRow(static_cast<sal_uInt16>(_nPos), DataType::VARCHAR) // Standard-Type { - OSL_ENSURE(SQL_ISRULE(pNode,parameter),"Argument is not a parameter"); - OSL_ENSURE(pNode->count() > 0,"Error in Parse Tree"); - OSQLParseNode *pMark = pNode->getChild(0); - - OUString aParameterName; - if (SQL_ISPUNCTUATION(pMark, "?")) - aParameterName = "?"; - else if (SQL_ISPUNCTUATION(pMark, ":")) - aParameterName = pNode->getChild(1)->getTokenValue(); - else - { - SAL_WARN( "connectivity.drivers","Error in Parse Tree"); - } - - // set up Parameter-Column with default type, can be specified more precisely later using Describe-Parameter - - // save Identity (not especially necessary here, just for the sake of symmetry) - - // todo - // OColumn* pColumn = new OFILEColumn(aParameterName,eDBType,255,0,SQL_FLAGS_NULLALLOWED); - // rParamColumns->AddColumn(pColumn); - - // the value will be set just before the evaluation + //TODO: Actually do something here (the current state of OOperandParam appears to be "the + // remains of the very beginnings of a never finished implementation of support for parameters + // in this code", as Lionel put it in the comments at <https://gerrit.libreoffice.org/c/core/+/ + // 116839/1#message-7b2bbf3543f559a0b67dc35cd940e2ab8829c274> "-Werror,-Wunused-but-set-variable + // (Clang 13 trunk)"). } @@ -249,7 +230,7 @@ bool OOp_COMPARE::operate(const OOperand* pLeft, const OOperand* pRight) const case DataType::VARCHAR: case DataType::LONGVARCHAR: { - OUString sLH = aLH, sRH = aRH; + OUString sLH = aLH.getString(), sRH = aRH.getString(); sal_Int32 nRes = sLH.compareToIgnoreAsciiCase(sRH); switch(aPredicateType) { @@ -274,7 +255,7 @@ bool OOp_COMPARE::operate(const OOperand* pLeft, const OOperand* pRight) const case DataType::DATE: case DataType::TIME: { - double n = aLH ,m = aRH; + double n = aLH.getDouble(), m = aRH.getDouble(); switch (aPredicateType) { @@ -303,7 +284,7 @@ void ONumOperator::Exec(OCodeStack& rCodeStack) OOperand *pLeft = rCodeStack.top(); rCodeStack.pop(); - rCodeStack.push(new OOperandResultNUM(operate(pLeft->getValue(), pRight->getValue()))); + rCodeStack.push(new OOperandResultNUM(operate(pLeft->getValue().getDouble(), pRight->getValue().getDouble()))); if( typeid(OOperandResult) == typeid(*pLeft)) delete pLeft; if( typeid(OOperandResult) == typeid(*pRight)) diff --git a/connectivity/source/drivers/file/fcomp.cxx b/connectivity/source/drivers/file/fcomp.cxx index 134565e3e3de..45c9022340a9 100644 --- a/connectivity/source/drivers/file/fcomp.cxx +++ b/connectivity/source/drivers/file/fcomp.cxx @@ -22,9 +22,6 @@ #include <connectivity/sqlparse.hxx> #include <file/fanalyzer.hxx> #include <com/sun/star/sdbc/XColumnLocate.hpp> -#include <com/sun/star/util/DateTime.hpp> -#include <com/sun/star/util/Date.hpp> -#include <com/sun/star/util/Time.hpp> #include <connectivity/dbexception.hxx> #include <connectivity/dbconversion.hxx> #include <com/sun/star/sdb/SQLFilterOperator.hpp> @@ -32,6 +29,7 @@ #include <file/FDateFunctions.hxx> #include <file/FNumericFunctions.hxx> #include <file/FConnection.hxx> +#include <comphelper/diagnose_ex.hxx> #include <sqlbison.hxx> #include <strings.hrc> @@ -352,29 +350,29 @@ void OPredicateCompiler::execute_BETWEEN(OSQLParseNode const * pPredicateNode) break; case DataType::DECIMAL: case DataType::NUMERIC: - pOb1->setValue(static_cast<double>(pOb1->getValue())); - pOb2->setValue(static_cast<double>(pOb2->getValue())); + pOb1->setValue(pOb1->getValue().getDouble()); + pOb2->setValue(pOb2->getValue().getDouble()); break; case DataType::FLOAT: - pOb1->setValue(static_cast<float>(pOb1->getValue())); - pOb2->setValue(static_cast<float>(pOb2->getValue())); + pOb1->setValue(pOb1->getValue().getFloat()); + pOb2->setValue(pOb2->getValue().getFloat()); break; case DataType::DOUBLE: case DataType::REAL: - pOb1->setValue(static_cast<double>(pOb1->getValue())); - pOb2->setValue(static_cast<double>(pOb2->getValue())); + pOb1->setValue(pOb1->getValue().getDouble()); + pOb2->setValue(pOb2->getValue().getDouble()); break; case DataType::DATE: - pOb1->setValue(static_cast<util::Date>(pOb1->getValue())); - pOb2->setValue(static_cast<util::Date>(pOb2->getValue())); + pOb1->setValue(pOb1->getValue().getDate()); + pOb2->setValue(pOb2->getValue().getDate()); break; case DataType::TIME: - pOb1->setValue(static_cast<util::Time>(pOb1->getValue())); - pOb2->setValue(static_cast<util::Time>(pOb2->getValue())); + pOb1->setValue(pOb1->getValue().getTime()); + pOb2->setValue(pOb2->getValue().getTime()); break; case DataType::TIMESTAMP: - pOb1->setValue(static_cast<util::DateTime>(pOb1->getValue())); - pOb2->setValue(static_cast<util::DateTime>(pOb2->getValue())); + pOb1->setValue(pOb1->getValue().getDateTime()); + pOb2->setValue(pOb2->getValue().getDateTime()); break; } } @@ -451,12 +449,12 @@ OOperand* OPredicateCompiler::execute_Operand(OSQLParseNode const * pPredicateNo } catch(Exception &) { - OSL_FAIL("OPredicateCompiler::execute_Operand Exception"); + TOOLS_WARN_EXCEPTION( "connectivity.drivers", "OPredicateCompiler::execute_Operand Exception"); } } else if (SQL_ISRULE(pPredicateNode,parameter)) { - pOperand = new OOperandParam(pPredicateNode, ++m_nParamCounter); + pOperand = new OOperandParam(++m_nParamCounter); } else if (pPredicateNode->getNodeType() == SQLNodeType::String || pPredicateNode->getNodeType() == SQLNodeType::IntNum || @@ -532,8 +530,6 @@ OOperand* OPredicateCompiler::execute_Operand(OSQLParseNode const * pPredicateNo bool OPredicateInterpreter::evaluate(OCodeList& rCodeList) { - static bool bResult; - if (!(rCodeList[0])) return true; // no Predicate @@ -552,7 +548,7 @@ bool OPredicateInterpreter::evaluate(OCodeList& rCodeList) DBG_ASSERT(m_aStack.empty(), "Stack error"); DBG_ASSERT(pOperand, "Stack error"); - bResult = pOperand->isValid(); + const bool bResult = pOperand->isValid(); if (typeid(OOperandResult) == typeid(*pOperand)) delete pOperand; return bResult; diff --git a/connectivity/source/drivers/firebird/Blob.cxx b/connectivity/source/drivers/firebird/Blob.cxx index 8ed9fc4a8ac7..26a5deaca0b4 100644 --- a/connectivity/source/drivers/firebird/Blob.cxx +++ b/connectivity/source/drivers/firebird/Blob.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -19,7 +19,7 @@ #include <connectivity/CommonTools.hxx> #include <connectivity/dbexception.hxx> #include <cppuhelper/exc_hlp.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> using namespace ::connectivity::firebird; @@ -67,7 +67,7 @@ void Blob::ensureBlobIsOpened() nullptr); if (aErr) - evaluateStatusVector(m_statusVector, "isc_open_blob2", *this); + evaluateStatusVector(m_statusVector, u"isc_open_blob2", *this); m_bBlobOpened = true; m_nBlobPosition = 0; @@ -90,7 +90,7 @@ void Blob::ensureBlobIsOpened() aResultBuffer); if (aErr) - evaluateStatusVector(m_statusVector, "isc_blob_info", *this); + evaluateStatusVector(m_statusVector, u"isc_blob_info", *this); char* pIt = aResultBuffer; while( *pIt != isc_info_end ) // info is in clusters @@ -122,28 +122,31 @@ sal_uInt16 Blob::getMaximumSegmentSize() return m_nMaxSegmentSize; } -bool Blob::readOneSegment(uno::Sequence< sal_Int8 >& rDataOut) +bool Blob::readOneSegment(std::vector<char>& rDataOut) { checkDisposed(Blob_BASE::rBHelper.bDisposed); ensureBlobIsOpened(); sal_uInt16 nMaxSize = getMaximumSegmentSize(); - if(rDataOut.getLength() < nMaxSize) - rDataOut.realloc(nMaxSize); + if(rDataOut.size() < nMaxSize) + rDataOut.resize(nMaxSize); sal_uInt16 nActualSize = 0; ISC_STATUS aRet = isc_get_segment(m_statusVector, &m_blobHandle, &nActualSize, nMaxSize, - reinterpret_cast<char*>(rDataOut.getArray()) ); + rDataOut.data() ); if (aRet && aRet != isc_segstr_eof && IndicatesError(m_statusVector)) { - OUString sError(StatusVectorToString(m_statusVector, "isc_get_segment")); + OUString sError(StatusVectorToString(m_statusVector, u"isc_get_segment")); throw IOException(sError, *this); } + + if (rDataOut.size() > nActualSize) + rDataOut.resize(nActualSize); m_nBlobPosition += nActualSize; return aRet == isc_segstr_eof; // last segment read } @@ -160,7 +163,7 @@ void Blob::closeBlob() aErr = isc_close_blob(m_statusVector, &m_blobHandle); if (aErr) - evaluateStatusVector(m_statusVector, "isc_close_blob", *this); + evaluateStatusVector(m_statusVector, u"isc_close_blob", *this); m_bBlobOpened = false; #if SAL_TYPES_SIZEOFPOINTER == 8 @@ -299,7 +302,7 @@ sal_Int32 SAL_CALL Blob::readBytes(uno::Sequence< sal_Int8 >& rDataOut, reinterpret_cast<char*>(rDataOut.getArray()) + nTotalBytesRead); if (aErr && IndicatesError(m_statusVector)) { - OUString sError(StatusVectorToString(m_statusVector, "isc_get_segment")); + OUString sError(StatusVectorToString(m_statusVector, u"isc_get_segment")); throw IOException(sError, *this); } nTotalBytesRead += nBytesRead; @@ -385,4 +388,4 @@ void SAL_CALL Blob::closeInput() } } -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Blob.hxx b/connectivity/source/drivers/firebird/Blob.hxx index 0a3627de417c..990108934bf2 100644 --- a/connectivity/source/drivers/firebird/Blob.hxx +++ b/connectivity/source/drivers/firebird/Blob.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -7,8 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_BLOB_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_BLOB_HXX +#pragma once #include <ibase.h> @@ -17,9 +16,9 @@ #include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/sdbc/XBlob.hpp> -namespace connectivity -{ - namespace firebird +#include <vector> + +namespace connectivity::firebird { typedef ::cppu::WeakComponentImplHelper< css::sdbc::XBlob, css::io::XInputStream > @@ -62,7 +61,7 @@ namespace connectivity isc_tr_handle* pTransactionHandle, ISC_QUAD const & aBlobID); - bool readOneSegment(css::uno::Sequence< sal_Int8 >& rDataOut); + bool readOneSegment(std::vector<char>& rDataOut); // ---- XBlob ---------------------------------------------------- virtual sal_Int64 SAL_CALL @@ -95,9 +94,7 @@ namespace connectivity // ---- OComponentHelper ------------------------------------------ virtual void SAL_CALL disposing() override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_BLOB_HXX -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Catalog.cxx b/connectivity/source/drivers/firebird/Catalog.cxx index 47fedab60d59..2ef4f514b12a 100644 --- a/connectivity/source/drivers/firebird/Catalog.cxx +++ b/connectivity/source/drivers/firebird/Catalog.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -10,6 +10,7 @@ #include "Catalog.hxx" #include "Tables.hxx" #include "Users.hxx" +#include "Views.hxx" #include <com/sun/star/sdbc/XRow.hpp> @@ -27,9 +28,7 @@ Catalog::Catalog(const uno::Reference< XConnection >& rConnection): //----- OCatalog ------------------------------------------------------------- void Catalog::refreshTables() { - Sequence< OUString > aTypes(2); - aTypes[0] = "TABLE"; - aTypes[1] = "VIEW"; + Sequence< OUString > aTypes {"TABLE", "VIEW"}; uno::Reference< XResultSet > xTables = m_xMetaData->getTables(Any(), "%", @@ -55,8 +54,20 @@ void Catalog::refreshTables() void Catalog::refreshViews() { - // TODO: implement me. - // Sets m_pViews (OCatalog) + css::uno::Reference<css::sdbc::XResultSet> xViews + = m_xMetaData->getTables(css::uno::Any(), "%", "%", { "VIEW" }); + + if (!xViews.is()) + return; + + ::std::vector<OUString> aViewNames; + + fillNames(xViews, aViewNames); + + if (!m_pViews) + m_pViews.reset(new Views(m_xConnection, *this, m_aMutex, aViewNames)); + else + m_pViews->reFill(aViewNames); } //----- IRefreshableGroups --------------------------------------------------- @@ -90,4 +101,5 @@ void Catalog::refreshUsers() else m_pUsers->reFill(aUserNames); } -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Catalog.hxx b/connectivity/source/drivers/firebird/Catalog.hxx index b3c9ae4fe820..3ffb9238eda7 100644 --- a/connectivity/source/drivers/firebird/Catalog.hxx +++ b/connectivity/source/drivers/firebird/Catalog.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -7,14 +7,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_CATALOG_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_CATALOG_HXX +#pragma once #include <sdbcx/VCatalog.hxx> -namespace connectivity -{ - namespace firebird +namespace connectivity::firebird { class Catalog: public ::connectivity::sdbcx::OCatalog { @@ -33,10 +30,11 @@ namespace connectivity // IRefreshableUsers virtual void refreshUsers() override; + + sdbcx::OCollection* getPrivateTables() const { return m_pTables.get(); } + sdbcx::OCollection* getPrivateViews() const { return m_pViews.get(); } }; - } // namespace firebird -} // namespace connectivity -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_CATALOG_HXX +} // namespace connectivity::firebird -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Clob.cxx b/connectivity/source/drivers/firebird/Clob.cxx index 2038dfc11350..dde050edee3a 100644 --- a/connectivity/source/drivers/firebird/Clob.cxx +++ b/connectivity/source/drivers/firebird/Clob.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -9,8 +9,6 @@ #include <sal/config.h> -#include <string_view> - #include "Clob.hxx" #include "Blob.hxx" @@ -54,13 +52,11 @@ sal_Int64 SAL_CALL Clob::length() // Read each segment, and calculate it's size by interpreting it as a // character stream. Assume that no characters are split by the segments. bool bLastSegmRead = false; + std::vector<char> aSegmentBytes; do { - uno::Sequence < sal_Int8 > aSegmentBytes; bLastSegmRead = m_aBlob->readOneSegment( aSegmentBytes ); - OUString sSegment ( reinterpret_cast< char *>( aSegmentBytes.getArray() ), - aSegmentBytes.getLength(), - RTL_TEXTENCODING_UTF8 ); + OUString sSegment(aSegmentBytes.data(), aSegmentBytes.size(), RTL_TEXTENCODING_UTF8); if( !bLastSegmRead) m_nCharCount += sSegment.getLength(); @@ -73,60 +69,51 @@ sal_Int64 SAL_CALL Clob::length() OUString SAL_CALL Clob::getSubString(sal_Int64 nPosition, sal_Int32 nLength) { + if (nPosition < 1) // XClob is indexed from 1 + throw lang::IllegalArgumentException("nPosition < 1", *this, 0); + --nPosition; // make 0-based + + if (nLength < 0) + throw lang::IllegalArgumentException("nLength < 0", *this, 0); + MutexGuard aGuard(m_aMutex); checkDisposed(Clob_BASE::rBHelper.bDisposed); // TODO do not reset position if it is not necessary m_aBlob->closeInput(); // reset position OUStringBuffer sSegmentBuffer; - sal_Int64 nActPos = 1; - sal_Int32 nActLen = 0; + std::vector<char> aSegmentBytes; - // skip irrelevant parts - while( nActPos < nPosition ) + for (;;) { - uno::Sequence < sal_Int8 > aSegmentBytes; bool bLastRead = m_aBlob->readOneSegment( aSegmentBytes ); - if( bLastRead ) - throw lang::IllegalArgumentException("nPosition out of range", *this, 0); - - OUString sSegment ( reinterpret_cast< char *>( aSegmentBytes.getArray() ), - aSegmentBytes.getLength(), - RTL_TEXTENCODING_UTF8 ); - sal_Int32 nStrLen = sSegment.getLength(); - nActPos += nStrLen; - if( nActPos > nPosition ) + // TODO: handle possible case of split UTF-8 character + OUString sSegment(aSegmentBytes.data(), aSegmentBytes.size(), RTL_TEXTENCODING_UTF8); + + // skip irrelevant parts + if (sSegment.getLength() < nPosition) { - sal_Int32 nCharsToCopy = static_cast<sal_Int32>(nActPos - nPosition); - if( nCharsToCopy > nLength ) - nCharsToCopy = nLength; - // append relevant part of first segment - sSegmentBuffer.append( std::u16string_view(sSegment).substr(0, nCharsToCopy) ); - nActLen += sSegmentBuffer.getLength(); + if (bLastRead) + throw lang::IllegalArgumentException("nPosition out of range", *this, 0); + nPosition -= sSegment.getLength(); + continue; } - } - // read nLength characters - while( nActLen < nLength ) - { - uno::Sequence < sal_Int8 > aSegmentBytes; - bool bLastRead = m_aBlob->readOneSegment( aSegmentBytes ); + // Getting here for the first time, nPosition may be > 0, meaning copy start offset. + // This also handles sSegment.getLength() == nPosition case, including nLength == 0. + const sal_Int32 nCharsToCopy = std::min<sal_Int32>(sSegment.getLength() - nPosition, + nLength - sSegmentBuffer.getLength()); + sSegmentBuffer.append(sSegment.subView(nPosition, nCharsToCopy)); + if (sSegmentBuffer.getLength() == nLength) + return sSegmentBuffer.makeStringAndClear(); + + assert(sSegmentBuffer.getLength() < nLength); - OUString sSegment ( reinterpret_cast< char *>( aSegmentBytes.getArray() ), - aSegmentBytes.getLength(), - RTL_TEXTENCODING_UTF8 ); - sal_Int32 nStrLen = sSegment.getLength(); - if( nActLen + nStrLen > nLength ) - sSegmentBuffer.append(std::u16string_view(sSegment).substr(0, nLength - nActLen)); - else - sSegmentBuffer.append(sSegment); - nActLen += nStrLen; - - if( bLastRead && nActLen < nLength ) + if (bLastRead) throw lang::IllegalArgumentException("out of range", *this, 0); - } - return sSegmentBuffer.makeStringAndClear(); + nPosition = 0; // No offset after first append + } } uno::Reference< XInputStream > SAL_CALL Clob::getCharacterStream() @@ -147,9 +134,8 @@ sal_Int64 SAL_CALL Clob::position(const OUString& /*rPattern*/, sal_Int64 SAL_CALL Clob::positionOfClob(const Reference <XClob >& /*rPattern*/, sal_Int64 /*aStart*/) { - ::dbtools::throwFeatureNotImplementedSQLException("Blob::positionOfBlob", *this); + ::dbtools::throwFeatureNotImplementedSQLException("Clob::positionOfClob", *this); return 0; } - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Clob.hxx b/connectivity/source/drivers/firebird/Clob.hxx index 626b284d3785..7fc5459d5d29 100644 --- a/connectivity/source/drivers/firebird/Clob.hxx +++ b/connectivity/source/drivers/firebird/Clob.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -7,8 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_CLOB_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_CLOB_HXX +#pragma once #include "Blob.hxx" @@ -18,9 +17,7 @@ #include <com/sun/star/sdbc/XClob.hpp> #include <rtl/ref.hxx> -namespace connectivity -{ - namespace firebird +namespace connectivity::firebird { typedef ::cppu::WeakComponentImplHelper< css::sdbc::XClob > Clob_BASE; @@ -61,9 +58,7 @@ namespace connectivity // ---- OComponentHelper ------------------------------------------ virtual void SAL_CALL disposing() override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_CLOB_HXX -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Column.cxx b/connectivity/source/drivers/firebird/Column.cxx index aa8abf9bb75c..0a18ebe5b441 100644 --- a/connectivity/source/drivers/firebird/Column.cxx +++ b/connectivity/source/drivers/firebird/Column.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -48,4 +48,4 @@ css::uno::Sequence< OUString > SAL_CALL Column::getSupportedServiceNames( ) return { "com.sun.star.sdbc.Firebird" }; } -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Column.hxx b/connectivity/source/drivers/firebird/Column.hxx index b72203da8a4e..c66287ce5668 100644 --- a/connectivity/source/drivers/firebird/Column.hxx +++ b/connectivity/source/drivers/firebird/Column.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -6,14 +6,11 @@ * 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/. */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_HCOLUMN_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_HCOLUMN_HXX +#pragma once #include <connectivity/sdbcx/VColumn.hxx> -namespace connectivity -{ - namespace firebird +namespace connectivity::firebird { class Column; typedef ::comphelper::OIdPropertyArrayUsageHelper<Column> Column_PROP; @@ -29,8 +26,7 @@ namespace connectivity virtual void construct() override; virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HCOLUMNS_HXX -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Columns.cxx b/connectivity/source/drivers/firebird/Columns.cxx index 293dac97dc5b..d36e25f9195b 100644 --- a/connectivity/source/drivers/firebird/Columns.cxx +++ b/connectivity/source/drivers/firebird/Columns.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -12,13 +12,11 @@ using namespace ::connectivity; using namespace ::connectivity::firebird; -using namespace ::connectivity::sdbcx; using namespace ::cppu; using namespace ::osl; using namespace ::com::sun::star; -using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::uno; Columns::Columns(Table& rTable, @@ -38,4 +36,4 @@ Reference< css::beans::XPropertySet > Columns::createDescriptor() return new Column; } -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Columns.hxx b/connectivity/source/drivers/firebird/Columns.hxx index 844d99ee0830..a211f70d1809 100644 --- a/connectivity/source/drivers/firebird/Columns.hxx +++ b/connectivity/source/drivers/firebird/Columns.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -7,17 +7,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_COLUMNS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_COLUMNS_HXX +#pragma once #include "Table.hxx" #include <connectivity/TColumnsHelper.hxx> -namespace connectivity +namespace connectivity::firebird { - namespace firebird - { class Columns: public ::connectivity::OColumnsHelper { protected: @@ -28,10 +25,6 @@ namespace connectivity const ::std::vector< OUString> &_rVector); }; - } // namespace firebird -} // namespace connectivity +} // namespace connectivity::firebird - -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_COLUMNS_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Connection.cxx b/connectivity/source/drivers/firebird/Connection.cxx index 6e42831f21d5..5a2be8872485 100644 --- a/connectivity/source/drivers/firebird/Connection.cxx +++ b/connectivity/source/drivers/firebird/Connection.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -22,7 +22,6 @@ #include "Clob.hxx" #include "Connection.hxx" #include "DatabaseMetaData.hxx" -#include "Driver.hxx" #include "PreparedStatement.hxx" #include "Statement.hxx" #include "Util.hxx" @@ -44,11 +43,12 @@ #include <resource/sharedresources.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/servicehelper.hxx> #include <comphelper/storagehelper.hxx> #include <cppuhelper/exc_hlp.hxx> #include <unotools/tempfile.hxx> -#include <unotools/localfilehelper.hxx> +#include <osl/file.hxx> #include <rtl/strbuf.hxx> #include <sal/log.hxx> @@ -72,16 +72,14 @@ using namespace ::com::sun::star::uno; * Location within the .odb that an embedded .fdb will be stored. * Only relevant for embedded dbs. */ -const OUStringLiteral our_sFDBLocation( "firebird.fdb" ); +constexpr OUString our_sFDBLocation( u"firebird.fdb"_ustr ); /** * Older version of LO may store the database in a .fdb file */ -const OUStringLiteral our_sFBKLocation( "firebird.fbk" ); +constexpr OUString our_sFBKLocation( u"firebird.fbk"_ustr ); Connection::Connection() : Connection_BASE(m_aMutex) - , m_sConnectionURL() - , m_sFirebirdURL() , m_bIsEmbedded(false) , m_bIsFile(false) , m_bIsAutoCommit(true) @@ -96,7 +94,6 @@ Connection::Connection() #endif , m_xCatalog(nullptr) , m_xMetaData(nullptr) - , m_aStatements() { } @@ -164,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"; @@ -199,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; @@ -208,19 +205,19 @@ void Connection::construct(const OUString& url, const Sequence< PropertyValue >& if (!xFileAccess->exists(m_sFirebirdURL)) bIsNewDatabase = true; - m_sFirebirdURL = m_sFirebirdURL.copy(OUString("file://").getLength()); + osl::FileBase::getSystemPathFromFileURL(m_sFirebirdURL, m_sFirebirdURL); } } std::string dpbBuffer; { - char userName[256] = ""; - char userPassword[256] = ""; + OString userName; + OString userPassword; dpbBuffer.push_back(isc_dpb_version1); dpbBuffer.push_back(isc_dpb_sql_dialect); dpbBuffer.push_back(1); // 1 byte long - dpbBuffer.push_back(FIREBIRD_SQL_DIALECT); + dpbBuffer.push_back(SQL_DIALECT_CURRENT); // set UTF8 as default character set of the database const char sCharset[] = "UTF8"; @@ -236,45 +233,64 @@ void Connection::construct(const OUString& url, const Sequence< PropertyValue >& if (m_bIsEmbedded || m_bIsFile) { - strcpy(userName,"sysdba"); - strcpy(userPassword,"masterkey"); + userName = "sysdba"_ostr; + userPassword = "masterkey"_ostr; } else { - // TODO: parse password from connection string as needed? + for (const auto& rIter : info) + { + if (rIter.Name == "user") + { + if (OUString value; rIter.Value >>= value) + userName = OUStringToOString(value, RTL_TEXTENCODING_UTF8); + } + else if (rIter.Name == "password") + { + if (OUString value; rIter.Value >>= value) + userPassword = OUStringToOString(value, RTL_TEXTENCODING_UTF8); + } + } } - if (strlen(userName)) + if (!userName.isEmpty()) { - int nUsernameLength = strlen(userName); + const sal_Int32 nMaxUsername = 255; //max size + int nUsernameLength = std::min(userName.getLength(), nMaxUsername); dpbBuffer.push_back(isc_dpb_user_name); dpbBuffer.push_back(nUsernameLength); - dpbBuffer.append(userName); + dpbBuffer.append(userName.getStr(), nUsernameLength); } - if (strlen(userPassword)) + if (!userPassword.isEmpty()) { - int nPasswordLength = strlen(userPassword); + const sal_Int32 nMaxPassword = 255; //max size + int nPasswordLength = std::min(userPassword.getLength(), nMaxPassword); dpbBuffer.push_back(isc_dpb_password); dpbBuffer.push_back(nPasswordLength); - dpbBuffer.append(userPassword); + dpbBuffer.append(userPassword.getStr(), nPasswordLength); } } + // use isc_dpb_utf8_filename to identify encoding of filenames + dpbBuffer.push_back(isc_dpb_utf8_filename); + dpbBuffer.push_back(0); // no filename here, it is passed to functions directly + ISC_STATUS_ARRAY status; /* status vector */ ISC_STATUS aErr; + const OString sFirebirdURL = OUStringToOString(m_sFirebirdURL, RTL_TEXTENCODING_UTF8); if (bIsNewDatabase) { aErr = isc_create_database(status, - m_sFirebirdURL.getLength(), - OUStringToOString(m_sFirebirdURL,RTL_TEXTENCODING_UTF8).getStr(), + sFirebirdURL.getLength(), + sFirebirdURL.getStr(), &m_aDBHandle, dpbBuffer.size(), dpbBuffer.c_str(), 0); if (aErr) { - evaluateStatusVector(status, "isc_create_database", *this); + evaluateStatusVector(status, u"isc_create_database", *this); } } else @@ -285,14 +301,14 @@ void Connection::construct(const OUString& url, const Sequence< PropertyValue >& } aErr = isc_attach_database(status, - m_sFirebirdURL.getLength(), - OUStringToOString(m_sFirebirdURL, RTL_TEXTENCODING_UTF8).getStr(), + sFirebirdURL.getLength(), + sFirebirdURL.getStr(), &m_aDBHandle, dpbBuffer.size(), dpbBuffer.c_str()); if (aErr) { - evaluateStatusVector(status, "isc_attach_database", *this); + evaluateStatusVector(status, u"isc_attach_database", *this); } } @@ -323,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") @@ -342,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; } @@ -355,10 +365,23 @@ Reference< XClob> Connection::createClob(ISC_QUAD const * pBlobId) &m_aTransactionHandle, *pBlobId); - m_aStatements.push_back(WeakReferenceHelper(xReturn)); + m_aStatements.emplace_back(xReturn); return xReturn; } +//----- XUnoTunnel ---------------------------------------------------------- +// virtual +sal_Int64 SAL_CALL Connection::getSomething(const css::uno::Sequence<sal_Int8>& rId) +{ + return comphelper::getSomethingImpl(rId, this); +} + +// static +const css::uno::Sequence<sal_Int8> & Connection::getUnoTunnelId() +{ + static const comphelper::UnoIdInit implId; + return implId.getSeq(); +} //----- XConnection ---------------------------------------------------------- Reference< XStatement > SAL_CALL Connection::createStatement( ) @@ -373,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; } @@ -389,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; } @@ -411,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; } @@ -490,7 +512,7 @@ void Connection::setupTransaction() aTPB); evaluateStatusVector(status_vector, - "isc_start_transaction", + u"isc_start_transaction", *this); } @@ -516,7 +538,7 @@ void SAL_CALL Connection::commit() disposeStatements(); isc_commit_transaction(status_vector, &m_aTransactionHandle); evaluateStatusVector(status_vector, - "isc_commit_transaction", + u"isc_commit_transaction", *this); } } @@ -569,7 +591,7 @@ isc_svc_handle Connection::attachServiceManager() aSPBBuffer)) { evaluateStatusVector(aStatusVector, - "isc_service_attach", + u"isc_service_attach", *this); } @@ -583,7 +605,7 @@ void Connection::detachServiceManager(isc_svc_handle aServiceHandle) &aServiceHandle)) { evaluateStatusVector(aStatusVector, - "isc_service_detach", + u"isc_service_detach", *this); } } @@ -600,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) { @@ -642,7 +660,7 @@ void Connection::runBackupService(const short nAction) aRequest.getLength(), aRequest.getStr())) { - evaluateStatusVector(aStatusVector, "isc_service_start", *this); + evaluateStatusVector(aStatusVector, u"isc_service_start", *this); } char aInfoSPB = isc_info_svc_line; @@ -658,7 +676,7 @@ void Connection::runBackupService(const short nAction) sizeof(aResults), aResults)) { - evaluateStatusVector(aStatusVector, "isc_service_query", *this); + evaluateStatusVector(aStatusVector, u"isc_service_query", *this); } detachServiceManager(aServiceHandle); @@ -791,49 +809,16 @@ void SAL_CALL Connection::documentEventOccured( const DocumentEvent& Event ) if (!m_bIsEmbedded) return; - if (!(Event.EventName == "OnSave" || Event.EventName == "OnSaveAs")) + if (Event.EventName != "OnSave" && Event.EventName != "OnSaveAs") return; commit(); // Commit and close transaction 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*/) { @@ -911,20 +896,46 @@ void Connection::disposing() { if (isc_detach_database(status, &m_aDBHandle)) { - evaluateStatusVector(status, "isc_detach_database", *this); + evaluateStatusVector(status, u"isc_detach_database", *this); } } - // TODO: write to storage again? + + storeDatabase(); cppu::WeakComponentImplHelperBase::disposing(); - if (m_pDatabaseFileDir) + m_pDatabaseFileDir.reset(); +} + +void Connection::storeDatabase() +{ + MutexGuard aGuard(m_aMutex); + if (m_bIsEmbedded && m_xEmbeddedStorage.is()) { - ::utl::removeTree(m_pDatabaseFileDir->GetURL()); - m_pDatabaseFileDir.reset(); + 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); @@ -956,4 +967,4 @@ uno::Reference< XTablesSupplier > Connection::createCatalog() } - +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Connection.hxx b/connectivity/source/drivers/firebird/Connection.hxx index 7365aa06aee2..16ac0ffa278d 100644 --- a/connectivity/source/drivers/firebird/Connection.hxx +++ b/connectivity/source/drivers/firebird/Connection.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_CONNECTION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_CONNECTION_HXX +#pragma once #include <ibase.h> @@ -34,6 +33,7 @@ #include <com/sun/star/document/XDocumentEventListener.hpp> #include <com/sun/star/embed/XStorage.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> #include <com/sun/star/sdbc/XBlob.hpp> #include <com/sun/star/sdbc/XClob.hpp> #include <com/sun/star/sdbc/XConnection.hpp> @@ -41,13 +41,12 @@ #include <com/sun/star/sdbcx/XTablesSupplier.hpp> #include <com/sun/star/util/XModifiable.hpp> -namespace connectivity -{ - namespace firebird +namespace connectivity::firebird { typedef ::cppu::WeakComponentImplHelper< css::document::XDocumentEventListener, css::lang::XServiceInfo, + css::lang::XUnoTunnel, css::sdbc::XConnection, css::sdbc::XWarningsSupplier > Connection_BASE; @@ -105,7 +104,7 @@ namespace connectivity * The extracted .fbk is written in firebird.fbk, the temporary * .fdb is stored as firebird.fdb. */ - std::unique_ptr< ::utl::TempFile > m_pDatabaseFileDir; + std::unique_ptr< ::utl::TempFileNamed > m_pDatabaseFileDir; /** * Path for our extracted .fbk file. * @@ -173,16 +172,6 @@ namespace connectivity 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 * transaction and not to a statement, hence the connection should * deal with their management. @@ -204,11 +193,19 @@ namespace connectivity 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; // XServiceInfo DECLARE_SERVICE_INFO(); + // XUnoTunnel + virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence<sal_Int8>& rId) override; + static const css::uno::Sequence<sal_Int8> & getUnoTunnelId(); // XConnection virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement( ) override; virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const OUString& sql ) override; @@ -239,8 +236,7 @@ namespace connectivity virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_CONNECTION_HXX -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx index 62a22454fc60..37c2ffe72c3d 100644 --- a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx +++ b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -771,7 +771,7 @@ sal_Bool SAL_CALL ODatabaseMetaData::supportsBatchUpdates() uno::Reference< XConnection > SAL_CALL ODatabaseMetaData::getConnection() { - return uno::Reference<XConnection>(m_pConnection.get()); + return m_pConnection; } // here follow all methods which return a resultset @@ -781,9 +781,8 @@ uno::Reference< XConnection > SAL_CALL ODatabaseMetaData::getConnection() uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTableTypes( ) { - ODatabaseMetaDataResultSet* pResultSet = new + rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTableTypes); - uno::Reference< XResultSet > xResultSet = pResultSet; ODatabaseMetaDataResultSet::ORows aResults; ODatabaseMetaDataResultSet::ORow aRow(2); @@ -802,8 +801,8 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTableTypes( ) aRow[1] = new ORowSetValueDecorator(OUString("SYSTEM TABLE")); aResults.push_back(aRow); - pResultSet->setRows(aResults); - return xResultSet; + pResultSet->setRows(std::move(aResults)); + return pResultSet; } uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() @@ -812,9 +811,8 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() // this returns an empty resultset where the column-names are already set // in special the metadata of the resultset already returns the right columns - ODatabaseMetaDataResultSet* pResultSet = + rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTypeInfo); - uno::Reference< XResultSet > xResultSet = pResultSet; static ODatabaseMetaDataResultSet::ORows aResults = []() { ODatabaseMetaDataResultSet::ORows tmp; @@ -823,14 +821,14 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() // Common data aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue(); // Literal quote marks aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue(); // Literal quote marks - aRow[7] = new ORowSetValueDecorator(true); // Nullable - aRow[8] = new ORowSetValueDecorator(true); // Case sensitive - aRow[10] = new ORowSetValueDecorator(false); // Is unsigned + aRow[7] = new ORowSetValueDecorator(ORowSetValue(true)); // Nullable + aRow[8] = new ORowSetValueDecorator(ORowSetValue(true)); // Case sensitive + aRow[10] = new ORowSetValueDecorator(ORowSetValue(false)); // Is unsigned // FIXED_PREC_SCALE: docs state "can it be a money value? " however // in reality this causes Base to treat all numbers as money formatted // by default which is wrong (and formatting as money value is still // possible for all values). - aRow[11] = new ORowSetValueDecorator(false); + aRow[11] = new ORowSetValueDecorator(ORowSetValue(false)); // Localised Type Name -- TODO: implement (but can be null): aRow[13] = new ORowSetValueDecorator(); aRow[16] = new ORowSetValueDecorator(); // Unused @@ -844,7 +842,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() aRow[6] = new ORowSetValueDecorator(OUString("length")); // Create Params aRow[9] = new ORowSetValueDecorator( sal_Int16(ColumnSearch::FULL)); // Searchable - aRow[12] = new ORowSetValueDecorator(false); // Autoincrement + aRow[12] = new ORowSetValueDecorator(ORowSetValue(false)); // Autoincrement aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale tmp.push_back(aRow); @@ -856,14 +854,16 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() aRow[6] = new ORowSetValueDecorator(OUString("length")); // Create Params aRow[9] = new ORowSetValueDecorator( sal_Int16(ColumnSearch::FULL)); // Searchable - aRow[12] = new ORowSetValueDecorator(false); // Autoincrement + aRow[12] = new ORowSetValueDecorator(ORowSetValue(false)); // Autoincrement aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale tmp.push_back(aRow); - // Binary (CHAR) - // It is distinguished from Text type by its character set - aRow[1] = new ORowSetValueDecorator(OUString("CHAR")); + // Binary (CHAR); we use the Firebird synonym CHARACTER + // to fool LO into seeing it as different types. + // It is distinguished from Text type by its character set OCTETS; + // that will be added by Tables::createStandardColumnPart + aRow[1] = new ORowSetValueDecorator(OUString("CHARACTER")); aRow[2] = new ORowSetValueDecorator(DataType::BINARY); aRow[3] = new ORowSetValueDecorator(sal_Int16(32765)); // Prevision = max length aRow[6] = new ORowSetValueDecorator(OUString("length")); // Create Params @@ -873,8 +873,8 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale tmp.push_back(aRow); - // Varbinary (VARCHAR) - aRow[1] = new ORowSetValueDecorator(OUString("VARCHAR")); + // Varbinary (VARCHAR); see comment above about BINARY + aRow[1] = new ORowSetValueDecorator(OUString("CHARACTER VARYING")); aRow[2] = new ORowSetValueDecorator(DataType::VARBINARY); aRow[3] = new ORowSetValueDecorator(sal_Int16(32765)); // Prevision = max length aRow[6] = new ORowSetValueDecorator(OUString("length")); // Create Params @@ -882,19 +882,20 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() sal_Int16(ColumnSearch::NONE)); // Searchable // Clob (SQL_BLOB) - aRow[1] = new ORowSetValueDecorator(OUString("BLOB")); // BLOB, with subtype 1 + aRow[1] = new ORowSetValueDecorator(OUString("BLOB SUB_TYPE TEXT")); // BLOB, with subtype 1 aRow[2] = new ORowSetValueDecorator(DataType::CLOB); aRow[3] = new ORowSetValueDecorator(sal_Int32(2147483647)); // Precision = max length aRow[6] = new ORowSetValueDecorator(); // Create Params aRow[9] = new ORowSetValueDecorator( sal_Int16(ColumnSearch::FULL)); // Searchable - aRow[12] = new ORowSetValueDecorator(false); // Autoincrement + aRow[12] = new ORowSetValueDecorator(ORowSetValue(false)); // Autoincrement aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale tmp.push_back(aRow); // Longvarbinary (SQL_BLOB) // Distinguished from simple blob with a user-defined subtype. + aRow[1] = new ORowSetValueDecorator(OUString("BLOB SUB_TYPE " + OUString::number(static_cast<short>(BlobSubtype::Image))) ); // BLOB, with subtype 0 aRow[2] = new ORowSetValueDecorator(DataType::LONGVARBINARY); tmp.push_back(aRow); @@ -903,7 +904,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() aRow[6] = new ORowSetValueDecorator(); // Create Params aRow[9] = new ORowSetValueDecorator( sal_Int16(ColumnSearch::FULL)); // Searchable - aRow[12] = new ORowSetValueDecorator(true); // Autoincrement + aRow[12] = new ORowSetValueDecorator(ORowSetValue(true)); // Autoincrement aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale } @@ -927,7 +928,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() { aRow[9] = new ORowSetValueDecorator( sal_Int16(ColumnSearch::FULL)); // Searchable - aRow[12] = new ORowSetValueDecorator(true); // Autoincrement + aRow[12] = new ORowSetValueDecorator(ORowSetValue(true)); // Autoincrement } aRow[6] = new ORowSetValueDecorator(OUString("PRECISION,SCALE")); // Create params @@ -971,7 +972,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() aRow[6] = new ORowSetValueDecorator(); // Create Params aRow[9] = new ORowSetValueDecorator( sal_Int16(ColumnSearch::FULL)); // Searchable - aRow[12] = new ORowSetValueDecorator(false); // Autoincrement + aRow[12] = new ORowSetValueDecorator(ORowSetValue(false)); // Autoincrement aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale tmp.push_back(aRow); @@ -983,7 +984,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() aRow[6] = new ORowSetValueDecorator(); // Create Params aRow[9] = new ORowSetValueDecorator( sal_Int16(ColumnSearch::FULL)); // Searchable - aRow[12] = new ORowSetValueDecorator(false); // Autoincrement + aRow[12] = new ORowSetValueDecorator(ORowSetValue(false)); // Autoincrement aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale tmp.push_back(aRow); @@ -995,19 +996,19 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() aRow[6] = new ORowSetValueDecorator(); // Create Params aRow[9] = new ORowSetValueDecorator( sal_Int16(ColumnSearch::FULL)); // Searchable - aRow[12] = new ORowSetValueDecorator(false); // Autoincrement + aRow[12] = new ORowSetValueDecorator(ORowSetValue(false)); // Autoincrement aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale tmp.push_back(aRow); // SQL_BLOB - aRow[1] = new ORowSetValueDecorator(OUString("BLOB")); + aRow[1] = new ORowSetValueDecorator(OUString("BLOB SUB_TYPE BINARY")); aRow[2] = new ORowSetValueDecorator(DataType::BLOB); aRow[3] = new ORowSetValueDecorator(sal_Int32(0)); // Prevision = max length aRow[6] = new ORowSetValueDecorator(); // Create Params aRow[9] = new ORowSetValueDecorator( sal_Int16(ColumnSearch::NONE)); // Searchable - aRow[12] = new ORowSetValueDecorator(false); // Autoincrement + aRow[12] = new ORowSetValueDecorator(ORowSetValue(false)); // Autoincrement aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale tmp.push_back(aRow); @@ -1019,14 +1020,15 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() aRow[6] = new ORowSetValueDecorator(); // Create Params aRow[9] = new ORowSetValueDecorator( sal_Int16(ColumnSearch::BASIC)); // Searchable - aRow[12] = new ORowSetValueDecorator(false); // Autoincrement + aRow[12] = new ORowSetValueDecorator(ORowSetValue(false)); // Autoincrement aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale tmp.push_back(aRow); return tmp; }(); - pResultSet->setRows(aResults); - return xResultSet; + // [-loplugin:redundantfcast] false positive: + pResultSet->setRows(ODatabaseMetaDataResultSet::ORows(aResults)); + return pResultSet; } uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumnPrivileges( @@ -1039,9 +1041,8 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumnPrivileges( "Table: " << sTable << " & ColumnNamePattern: " << sColumnNamePattern); - ODatabaseMetaDataResultSet* pResultSet = new + rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eColumnPrivileges); - uno::Reference< XResultSet > xResultSet = pResultSet; uno::Reference< XStatement > statement = m_pConnection->createStatement(); static const char wld[] = "%"; @@ -1075,7 +1076,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumnPrivileges( OUString query = queryBuf.makeStringAndClear(); - uno::Reference< XResultSet > rs = statement->executeQuery(query.getStr()); + uno::Reference< XResultSet > rs = statement->executeQuery(query); uno::Reference< XRow > xRow( rs, UNO_QUERY_THROW ); ODatabaseMetaDataResultSet::ORows aResults; @@ -1099,9 +1100,9 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumnPrivileges( aResults.push_back(aCurrentRow); } - pResultSet->setRows( aResults ); + pResultSet->setRows( std::move(aResults) ); - return xResultSet; + return pResultSet; } uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns( @@ -1164,7 +1165,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns( OUString query = queryBuf.makeStringAndClear(); uno::Reference< XStatement > statement = m_pConnection->createStatement(); - uno::Reference< XResultSet > rs = statement->executeQuery(query.getStr()); + uno::Reference< XResultSet > rs = statement->executeQuery(query); uno::Reference< XRow > xRow( rs, UNO_QUERY_THROW ); ODatabaseMetaDataResultSet::ORows aResults; @@ -1191,7 +1192,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns( // result field may be filled with spaces sCharsetName = sCharsetName.trim(); ColumnTypeInfo aInfo(aType, xRow->getShort(7), aScale, - xRow->getString(13)); + sCharsetName); aCurrentRow[5] = new ORowSetValueDecorator(aInfo.getSdbcType()); // 6. Typename (SQL_*) @@ -1243,13 +1244,23 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns( // 12. Comments -- may be omitted { OUString aDescription; - uno::Reference< XBlob > xDescriptionBlob = xRow->getBlob(3); - if (xDescriptionBlob.is()) + uno::Reference< XBlob > xBlob = xRow->getBlob(3); + if (xBlob.is()) { - sal_Int32 aBlobLength = static_cast<sal_Int32>(xDescriptionBlob->length()); - aDescription = OUString(reinterpret_cast<char*>(xDescriptionBlob->getBytes(1, aBlobLength).getArray()), - aBlobLength, - RTL_TEXTENCODING_UTF8); + const sal_Int64 aBlobLength = xBlob->length(); + if (aBlobLength > SAL_MAX_INT32) + { + SAL_WARN("connectivity.firebird", "getBytes can't return " << aBlobLength << " bytes but only max " << SAL_MAX_INT32); + aDescription = OUString(reinterpret_cast<char*>(xBlob->getBytes(1, SAL_MAX_INT32).getArray()), + SAL_MAX_INT32, + RTL_TEXTENCODING_UTF8); + } + else + { + aDescription = OUString(reinterpret_cast<char*>(xBlob->getBytes(1, static_cast<sal_Int32>(aBlobLength)).getArray()), + aBlobLength, + RTL_TEXTENCODING_UTF8); + } } aCurrentRow[12] = new ORowSetValueDecorator(aDescription); } @@ -1295,12 +1306,11 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns( aResults.push_back(aCurrentRow); } - ODatabaseMetaDataResultSet* pResultSet = new + rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eColumns); - uno::Reference< XResultSet > xResultSet = pResultSet; - pResultSet->setRows( aResults ); + pResultSet->setRows( std::move(aResults) ); - return xResultSet; + return pResultSet; } uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( @@ -1312,9 +1322,8 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( SAL_INFO("connectivity.firebird", "getTables() with " "TableNamePattern: " << tableNamePattern); - ODatabaseMetaDataResultSet* pResultSet = new + rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTables); - uno::Reference< XResultSet > xResultSet = pResultSet; uno::Reference< XStatement > statement = m_pConnection->createStatement(); static const char wld[] = "%"; @@ -1331,8 +1340,10 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( // TODO: GLOBAL TEMPORARY, LOCAL TEMPORARY, ALIAS, SYNONYM if (!types.hasElements() || (types.getLength() == 1 && types[0].match(wld))) { + // from Firebird: src/jrd/constants.h + // rel_persistent = 0, rel_view = 1, rel_external = 2 // All table types? I.e. includes system tables. - queryBuf.append("(RDB$RELATION_TYPE = 0 OR RDB$RELATION_TYPE = 1) "); + queryBuf.append("(RDB$RELATION_TYPE = 0 OR RDB$RELATION_TYPE = 1 OR RDB$RELATION_TYPE = 2) "); } else { @@ -1366,7 +1377,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( OUString query = queryBuf.makeStringAndClear(); - uno::Reference< XResultSet > rs = statement->executeQuery(query.getStr()); + uno::Reference< XResultSet > rs = statement->executeQuery(query); uno::Reference< XRow > xRow( rs, UNO_QUERY_THROW ); ODatabaseMetaDataResultSet::ORows aResults; @@ -1398,7 +1409,8 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( } else { - if (nTableType == 0) + // see above about src/jrd/constants.h + if (nTableType == 0 || nTableType == 2) sTableType = "TABLE"; } @@ -1409,16 +1421,16 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( uno::Reference< XClob > xClob = xRow->getClob(4); if (xClob.is()) { - aCurrentRow[5] = new ORowSetValueDecorator(xClob->getSubString(0, xClob->length())); + aCurrentRow[5] = new ORowSetValueDecorator(xClob->getSubString(1, xClob->length())); } } aResults.push_back(aCurrentRow); } - pResultSet->setRows( aResults ); + pResultSet->setRows( std::move(aResults) ); - return xResultSet; + return pResultSet; } uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getProcedureColumns( @@ -1462,11 +1474,10 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getImportedKeys( return ODatabaseMetaData::lcl_getKeys(true, table); } -uno::Reference< XResultSet > ODatabaseMetaData::lcl_getKeys(const bool& bIsImport, const OUString& table ) +uno::Reference< XResultSet > ODatabaseMetaData::lcl_getKeys(const bool bIsImport, std::u16string_view table ) { - ODatabaseMetaDataResultSet* pResultSet = new - ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eImportedKeys); - uno::Reference< XResultSet > xResultSet = pResultSet; + rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new + ODatabaseMetaDataResultSet(bIsImport?ODatabaseMetaDataResultSet::eImportedKeys:ODatabaseMetaDataResultSet::eExportedKeys); uno::Reference< XStatement > statement = m_pConnection->createStatement(); @@ -1493,9 +1504,9 @@ uno::Reference< XResultSet > ODatabaseMetaData::lcl_getKeys(const bool& bIsImpor "ON FOREI.RDB$INDEX_NAME = FOREIGN_INDEX.RDB$INDEX_NAME " "WHERE FOREI.RDB$CONSTRAINT_TYPE = 'FOREIGN KEY' "; if (bIsImport) - sSQL += "AND FOREI.RDB$RELATION_NAME = '"+ table +"'"; + sSQL += OUString::Concat("AND FOREI.RDB$RELATION_NAME = '")+ table +"'"; else - sSQL += "AND PRIM.RDB$RELATION_NAME = '"+ table +"'"; + sSQL += OUString::Concat("AND PRIM.RDB$RELATION_NAME = '")+ table +"'"; uno::Reference< XResultSet > rs = statement->executeQuery(sSQL); uno::Reference< XRow > xRow( rs, UNO_QUERY_THROW ); @@ -1545,8 +1556,8 @@ uno::Reference< XResultSet > ODatabaseMetaData::lcl_getKeys(const bool& bIsImpor aResults.push_back(aCurrentRow); } - pResultSet->setRows( aResults ); - return xResultSet; + pResultSet->setRows( std::move(aResults) ); + return pResultSet; } uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getPrimaryKeys( @@ -1597,12 +1608,11 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getPrimaryKeys( aResults.push_back(aCurrentRow); } - ODatabaseMetaDataResultSet* pResultSet = new + rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::ePrimaryKeys); - uno::Reference< XResultSet > xResultSet = pResultSet; - pResultSet->setRows( aResults ); + pResultSet->setRows( std::move(aResults) ); - return xResultSet; + return pResultSet; } uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getIndexInfo( @@ -1670,7 +1680,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getIndexInfo( } // 4. NON_UNIQUE -- i.e. specifically negate here. - aCurrentRow[4] = new ORowSetValueDecorator(xRow->getShort(5) == 0); + aCurrentRow[4] = new ORowSetValueDecorator(ORowSetValue(xRow->getShort(5) == 0)); // 6. INDEX NAME aCurrentRow[6] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(4))); @@ -1691,12 +1701,11 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getIndexInfo( aResults.push_back(aCurrentRow); } - ODatabaseMetaDataResultSet* pResultSet = new - ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::ePrimaryKeys); - uno::Reference< XResultSet > xResultSet = pResultSet; - pResultSet->setRows( aResults ); + rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new + ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eIndexInfo); + pResultSet->setRows( std::move(aResults) ); - return xResultSet; + return pResultSet; } uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getBestRowIdentifier( @@ -1716,9 +1725,8 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges( SAL_INFO("connectivity.firebird", "getTablePrivileges() with " "TableNamePattern: " << sTableNamePattern); - ODatabaseMetaDataResultSet* pResultSet = new + rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTablePrivileges); - uno::Reference< XResultSet > xResultSet = pResultSet; uno::Reference< XStatement > statement = m_pConnection->createStatement(); // TODO: column specific privileges are included, we may need @@ -1749,7 +1757,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges( OUString query = queryBuf.makeStringAndClear(); - uno::Reference< XResultSet > rs = statement->executeQuery(query.getStr()); + uno::Reference< XResultSet > rs = statement->executeQuery(query); uno::Reference< XRow > xRow( rs, UNO_QUERY_THROW ); ODatabaseMetaDataResultSet::ORows aResults; @@ -1765,14 +1773,14 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges( aRow[4] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(2))); // 4. GRANTOR aRow[5] = new ORowSetValueDecorator(sanitizeIdentifier(xRow->getString(3))); // 5. GRANTEE aRow[6] = new ORowSetValueDecorator(xRow->getString(4)); // 6. Privilege - aRow[7] = new ORowSetValueDecorator(bool(xRow->getBoolean(5))); // 7. Is Grantable + aRow[7] = new ORowSetValueDecorator(ORowSetValue(bool(xRow->getBoolean(5)))); // 7. Is Grantable aResults.push_back(aRow); } - pResultSet->setRows( aResults ); + pResultSet->setRows( std::move(aResults) ); - return xResultSet; + return pResultSet; } uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCrossReference( @@ -1792,5 +1800,4 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getUDTs( const Any&, co return new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eUDTs); } - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/DatabaseMetaData.hxx b/connectivity/source/drivers/firebird/DatabaseMetaData.hxx index 64025809ae23..c577f594d245 100644 --- a/connectivity/source/drivers/firebird/DatabaseMetaData.hxx +++ b/connectivity/source/drivers/firebird/DatabaseMetaData.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -17,8 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_DATABASEMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_DATABASEMETADATA_HXX +#pragma once + +#include <sal/config.h> + +#include <string_view> #include "Connection.hxx" @@ -26,9 +29,7 @@ #include <cppuhelper/implbase.hxx> #include <rtl/ref.hxx> -namespace connectivity -{ - namespace firebird +namespace connectivity::firebird { //************ Class: ODatabaseMetaData @@ -40,7 +41,7 @@ namespace connectivity { ::rtl::Reference<Connection> m_pConnection; private: - css::uno::Reference< css::sdbc::XResultSet > lcl_getKeys( const bool& bIsImport, const OUString& table ); + css::uno::Reference< css::sdbc::XResultSet > lcl_getKeys( bool bIsImport, std::u16string_view table ); public: explicit ODatabaseMetaData(Connection* _pCon); @@ -198,9 +199,7 @@ namespace connectivity virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getUDTs( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& typeNamePattern, const css::uno::Sequence< sal_Int32 >& types ) override; virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( ) override; }; - } -} -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_DATABASEMETADATA_HXX +} -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Driver.cxx b/connectivity/source/drivers/firebird/Driver.cxx index 71613408df24..3aa903d48abf 100644 --- a/connectivity/source/drivers/firebird/Driver.cxx +++ b/connectivity/source/drivers/firebird/Driver.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -25,13 +25,12 @@ #include <strings.hrc> #include <resource/sharedresources.hxx> -#include <comphelper/processfactory.hxx> +#include <comphelper/servicehelper.hxx> #include <cppuhelper/supportsservice.hxx> #include <osl/file.hxx> #include <osl/process.h> #include <rtl/bootstrap.hxx> #include <sal/log.hxx> -#include <unotools/localfilehelper.hxx> using namespace com::sun::star; using namespace com::sun::star::uno; @@ -46,11 +45,11 @@ using namespace connectivity::firebird; // Static const variables namespace { -const char our_sFirebirdTmpVar[] = "FIREBIRD_TMP"; -const char our_sFirebirdLockVar[] = "FIREBIRD_LOCK"; -const char our_sFirebirdMsgVar[] = "FIREBIRD_MSG"; +constexpr OUString our_sFirebirdTmpVar = u"FIREBIRD_TMP"_ustr; +constexpr OUString our_sFirebirdLockVar = u"FIREBIRD_LOCK"_ustr; +constexpr OUString our_sFirebirdMsgVar = u"FIREBIRD_MSG"_ustr; #ifdef MACOSX -const char our_sFirebirdLibVar[] = "LIBREOFFICE_FIREBIRD_LIB"; +constexpr OUString our_sFirebirdLibVar = u"LIBREOFFICE_FIREBIRD_LIB"_ustr; #endif }; @@ -63,12 +62,14 @@ FirebirdDriver::FirebirdDriver(const css::uno::Reference< css::uno::XComponentCo // ::utl::TempFile uses a unique temporary directory (subdirectory of // /tmp or other user specific tmp directory) per instance in which // we can create directories for firebird at will. + m_firebirdTMPDirectory.EnableKillingFile(true); + m_firebirdLockDirectory.EnableKillingFile(true); // Overrides firebird's default of /tmp or c:\temp - osl_setEnvironment(OUString(our_sFirebirdTmpVar).pData, m_firebirdTMPDirectory.GetFileName().pData); + osl_setEnvironment(our_sFirebirdTmpVar.pData, m_firebirdTMPDirectory.GetFileName().pData); // Overrides firebird's default of /tmp/firebird or c:\temp\firebird - osl_setEnvironment(OUString(our_sFirebirdLockVar).pData, m_firebirdLockDirectory.GetFileName().pData); + osl_setEnvironment(our_sFirebirdLockVar.pData, m_firebirdLockDirectory.GetFileName().pData); #ifndef SYSTEM_FIREBIRD // Overrides firebird's hardcoded default of /usr/local/firebird on *nix, @@ -77,7 +78,7 @@ FirebirdDriver::FirebirdDriver(const css::uno::Reference< css::uno::XComponentCo ::rtl::Bootstrap::expandMacros(sMsgURL); OUString sMsgPath; ::osl::FileBase::getSystemPathFromFileURL(sMsgURL, sMsgPath); - osl_setEnvironment(OUString(our_sFirebirdMsgVar).pData, sMsgPath.pData); + osl_setEnvironment(our_sFirebirdMsgVar.pData, sMsgPath.pData); #ifdef MACOSX // Set an env. variable to specify library location // for dlopen used in fbclient. @@ -85,16 +86,12 @@ FirebirdDriver::FirebirdDriver(const css::uno::Reference< css::uno::XComponentCo ::rtl::Bootstrap::expandMacros(sLibURL); OUString sLibPath; ::osl::FileBase::getSystemPathFromFileURL(sLibURL, sLibPath); - osl_setEnvironment(OUString(our_sFirebirdLibVar).pData, sLibPath.pData); + osl_setEnvironment(our_sFirebirdLibVar.pData, sLibPath.pData); #endif /*MACOSX*/ #endif /*!SYSTEM_FIREBIRD*/ } -FirebirdDriver::~FirebirdDriver() -{ - utl::removeTree(m_firebirdTMPDirectory.GetURL()); - utl::removeTree(m_firebirdLockDirectory.GetURL()); -} +FirebirdDriver::~FirebirdDriver() = default; void FirebirdDriver::disposing() { @@ -108,13 +105,13 @@ void FirebirdDriver::disposing() } m_xConnections.clear(); - osl_clearEnvironment(OUString(our_sFirebirdTmpVar).pData); - osl_clearEnvironment(OUString(our_sFirebirdLockVar).pData); + osl_clearEnvironment(our_sFirebirdTmpVar.pData); + osl_clearEnvironment(our_sFirebirdLockVar.pData); #ifndef SYSTEM_FIREBIRD - osl_clearEnvironment(OUString(our_sFirebirdMsgVar).pData); + osl_clearEnvironment(our_sFirebirdMsgVar.pData); #ifdef MACOSX - osl_clearEnvironment(OUString(our_sFirebirdLibVar).pData); + osl_clearEnvironment(our_sFirebirdLibVar.pData); #endif /*MACOSX*/ #endif /*!SYSTEM_FIREBIRD*/ @@ -151,13 +148,12 @@ Reference< XConnection > SAL_CALL FirebirdDriver::connect( if ( ! acceptsURL(url) ) return nullptr; - Connection* pCon = new Connection(); - Reference< XConnection > xCon = pCon; + rtl::Reference<Connection> pCon = new Connection(); pCon->construct(url, info); - m_xConnections.push_back(WeakReferenceHelper(*pCon)); + m_xConnections.emplace_back(*pCon); - return xCon; + return pCon; } sal_Bool SAL_CALL FirebirdDriver::acceptsURL( const OUString& url ) @@ -194,8 +190,9 @@ sal_Int32 SAL_CALL FirebirdDriver::getMinorVersion( ) uno::Reference< XTablesSupplier > SAL_CALL FirebirdDriver::getDataDefinitionByConnection( const uno::Reference< XConnection >& rConnection) { - Connection* pConnection = static_cast< Connection* >(rConnection.get()); - return pConnection->createCatalog(); + if (Connection* pConnection = comphelper::getFromUnoTunnel<Connection>(rConnection)) + return pConnection->createCatalog(); + return {}; } uno::Reference< XTablesSupplier > SAL_CALL FirebirdDriver::getDataDefinitionByURL( @@ -228,5 +225,4 @@ connectivity_FirebirdDriver_get_implementation( } } - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Driver.hxx b/connectivity/source/drivers/firebird/Driver.hxx index acace9d13298..d884b5008d6a 100644 --- a/connectivity/source/drivers/firebird/Driver.hxx +++ b/connectivity/source/drivers/firebird/Driver.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_DRIVER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_DRIVER_HXX +#pragma once #include "Connection.hxx" @@ -29,14 +28,14 @@ #include <cppuhelper/compbase.hxx> #include <unotools/tempfile.hxx> -namespace connectivity -{ - namespace firebird +namespace connectivity::firebird { // The SQL dialect in use // Has to be used in various isc_* calls. // 3: Is IB6 -- minimum required for delimited identifiers. - const int FIREBIRD_SQL_DIALECT = 3; + // SQL_DIALECT_V6 = 3, it's the last current version + // SQL_DIALECT_CURRENT is an alias for SQL_DIALECT_V6 + // See src/dsql/sqlda_pub.h for full details typedef ::cppu::WeakComponentImplHelper< css::sdbc::XDriver, css::sdbcx::XDataDefinitionSupplier, @@ -46,8 +45,8 @@ namespace connectivity { private: css::uno::Reference<css::uno::XComponentContext> m_aContext; - ::utl::TempFile m_firebirdTMPDirectory; - ::utl::TempFile m_firebirdLockDirectory; + ::utl::TempFileNamed m_firebirdTMPDirectory; + ::utl::TempFileNamed m_firebirdLockDirectory; protected: ::osl::Mutex m_aMutex; // mutex is need to control member access @@ -85,10 +84,7 @@ namespace connectivity const OUString& rsURL, const css::uno::Sequence< css::beans::PropertyValue >& rInfo) override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_DRIVER_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Indexes.cxx b/connectivity/source/drivers/firebird/Indexes.cxx index 86f4f9f6f66c..7bf783c79c7b 100644 --- a/connectivity/source/drivers/firebird/Indexes.cxx +++ b/connectivity/source/drivers/firebird/Indexes.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -13,12 +13,11 @@ using namespace ::connectivity; using namespace ::connectivity::firebird; using namespace ::osl; -using namespace ::std; using namespace ::com::sun::star; using namespace ::com::sun::star::sdbc; -Indexes::Indexes(Table* pTable, Mutex& rMutex, const vector< OUString>& rVector) +Indexes::Indexes(Table* pTable, Mutex& rMutex, const std::vector<OUString>& rVector) : OIndexesHelper(pTable, rMutex, rVector) , m_pTable(pTable) { @@ -27,6 +26,8 @@ Indexes::Indexes(Table* pTable, Mutex& rMutex, const vector< OUString>& rVector) // XDrop void Indexes::dropObject(sal_Int32 /*nPosition*/, const OUString& sIndexName) { - OUString sSql("DROP INDEX \"" + sIndexName +"\""); + OUString sSql("DROP INDEX \"" + sIndexName + "\""); m_pTable->getConnection()->createStatement()->execute(sSql); } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Indexes.hxx b/connectivity/source/drivers/firebird/Indexes.hxx index 364b36b04278..12d7dd198028 100644 --- a/connectivity/source/drivers/firebird/Indexes.hxx +++ b/connectivity/source/drivers/firebird/Indexes.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -7,16 +7,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_INDEXES_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_INDEXES_HXX +#pragma once #include "Table.hxx" #include <connectivity/TIndexes.hxx> -namespace connectivity -{ - namespace firebird +namespace connectivity::firebird { /** @@ -37,9 +34,6 @@ namespace connectivity const std::vector< OUString>& rVector); }; - } // namespace firebird -} // namespace connectivity +} // namespace connectivity::firebird -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_INDEXES_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Keys.cxx b/connectivity/source/drivers/firebird/Keys.cxx index dd4cca47fb20..8de112ec6fc4 100644 --- a/connectivity/source/drivers/firebird/Keys.cxx +++ b/connectivity/source/drivers/firebird/Keys.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -51,4 +51,4 @@ void Keys::dropObject(sal_Int32 nPosition, const OUString& sName) } } -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Keys.hxx b/connectivity/source/drivers/firebird/Keys.hxx index 143dbbf5486b..4e9ba5a7eede 100644 --- a/connectivity/source/drivers/firebird/Keys.hxx +++ b/connectivity/source/drivers/firebird/Keys.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -7,15 +7,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_KEYS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_KEYS_HXX +#pragma once #include <connectivity/TKeys.hxx> -namespace connectivity -{ - - namespace firebird +namespace connectivity::firebird { class Table; @@ -34,8 +30,7 @@ namespace connectivity void dropObject(sal_Int32 nPosition, const OUString& sName) override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_KEYS_HXX -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx index e86f8cf80982..35847d021ea0 100644 --- a/connectivity/source/drivers/firebird/PreparedStatement.cxx +++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx @@ -20,8 +20,6 @@ #include <sal/config.h> #include <cmath> -#include <string_view> - #include "Connection.hxx" #include "PreparedStatement.hxx" #include "ResultSet.hxx" @@ -52,6 +50,8 @@ using namespace com::sun::star::util; IMPLEMENT_SERVICE_INFO(OPreparedStatement,"com.sun.star.sdbcx.firebird.PreparedStatement","com.sun.star.sdbc.PreparedStatement"); +constexpr size_t MAX_SIZE_SEGMENT = 65535; // max value of a segment of CLOB, if we want more than 65535 bytes, we need more segments + OPreparedStatement::OPreparedStatement( Connection* _pConnection, const OUString& sql) @@ -81,9 +81,7 @@ void OPreparedStatement::ensurePrepared() m_pInSqlda->sqln = 10; } - prepareAndDescribeStatement(m_sSqlStatement, - m_pOutSqlda, - m_pInSqlda); + prepareAndDescribeStatement(m_sSqlStatement, m_pOutSqlda); aErr = isc_dsql_describe_bind(m_statusVector, &m_aStatementHandle, @@ -118,12 +116,12 @@ OPreparedStatement::~OPreparedStatement() { } -void SAL_CALL OPreparedStatement::acquire() throw() +void SAL_CALL OPreparedStatement::acquire() noexcept { OStatementCommonBase::acquire(); } -void SAL_CALL OPreparedStatement::release() throw() +void SAL_CALL OPreparedStatement::release() noexcept { OStatementCommonBase::release(); } @@ -211,7 +209,8 @@ void SAL_CALL OPreparedStatement::setString(sal_Int32 nParameterIndex, { str = str.copy(0, max_varchar_len); } - const auto nLength = str.getLength(); + const sal_uInt16 nLength = str.getLength(); + static_assert(sizeof(nLength) == 2, "must match dest memcpy len"); memcpy(pVar->sqldata, &nLength, 2); // Actual data memcpy(pVar->sqldata + 2, str.getStr(), str.getLength()); @@ -240,6 +239,36 @@ void SAL_CALL OPreparedStatement::setString(sal_Int32 nParameterIndex, setShort(nParameterIndex, int32Value); break; } + case SQL_LONG: + { + sal_Int32 int32Value = sInput.toInt32(); + setInt(nParameterIndex, int32Value); + break; + } + case SQL_INT64: + { + sal_Int64 int64Value = sInput.toInt64(); + setLong(nParameterIndex, int64Value); + break; + } + case SQL_FLOAT: + { + float floatValue = sInput.toFloat(); + setFloat(nParameterIndex, floatValue); + break; + } + case SQL_BOOLEAN: + { + bool boolValue = sInput.toBoolean(); + setBoolean(nParameterIndex, boolValue); + break; + } + case SQL_NULL: + { + // See https://www.firebirdsql.org/file/documentation/html/en/refdocs/fblangref25/firebird-25-language-reference.html#fblangref25-datatypes-special-sqlnull + pVar->sqldata = nullptr; + break; + } default: ::dbtools::throwSQLException( "Incorrect type for setString", @@ -253,7 +282,7 @@ Reference< XConnection > SAL_CALL OPreparedStatement::getConnection() MutexGuard aGuard( m_aMutex ); checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); - return Reference<XConnection>(m_pConnection.get()); + return m_pConnection; } sal_Bool SAL_CALL OPreparedStatement::execute() @@ -283,7 +312,7 @@ sal_Bool SAL_CALL OPreparedStatement::execute() // Do not throw error. Trying to close a closed cursor is not a // critical mistake. OUString sErrMsg = StatusVectorToString(m_statusVector, - "isc_dsql_free_statement: close cursor"); + u"isc_dsql_free_statement: close cursor"); SAL_WARN("connectivity.firebird", sErrMsg); } } @@ -296,7 +325,7 @@ sal_Bool SAL_CALL OPreparedStatement::execute() if (aErr) { SAL_WARN("connectivity.firebird", "isc_dsql_execute failed" ); - evaluateStatusVector(m_statusVector, "isc_dsql_execute", *this); + evaluateStatusVector(m_statusVector, u"isc_dsql_execute", *this); } m_xResultSet = new OResultSet(m_pConnection.get(), @@ -305,9 +334,6 @@ 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. } @@ -350,10 +376,10 @@ sal_Int64 toNumericWithoutDecimalPlace(const OUString& sSource) OUStringBuffer sBuffer(15); if(nDotIndex > 0) { - sBuffer.append(std::u16string_view(sNumber).substr(0, nDotIndex)); + sBuffer.append(sNumber.subView(0, nDotIndex)); } - sBuffer.append(std::u16string_view(sNumber).substr(nDotIndex + 1)); - return sBuffer.makeStringAndClear().toInt64(); + sBuffer.append(sNumber.subView(nDotIndex + 1)); + return o3tl::toInt64(sBuffer); } } @@ -541,7 +567,7 @@ void OPreparedStatement::openBlobForWriting(isc_blob_handle& rBlobHandle, ISC_QU if (aErr) { evaluateStatusVector(m_statusVector, - "setBlob failed on " + m_sSqlStatement, + Concat2View("setBlob failed on " + m_sSqlStatement), *this); assert(false); } @@ -556,7 +582,7 @@ void OPreparedStatement::closeBlobAfterWriting(isc_blob_handle& rBlobHandle) if (aErr) { evaluateStatusVector(m_statusVector, - "isc_close_blob failed", + u"isc_close_blob failed", *this); assert(false); } @@ -583,9 +609,9 @@ void SAL_CALL OPreparedStatement::setClob(sal_Int32 nParameterIndex, const Refer sal_Int64 nCharWritten = 1; // XClob is indexed from 1 ISC_STATUS aErr = 0; sal_Int64 nLen = xClob->length(); - while ( nLen > nCharWritten ) + while ( nLen >= nCharWritten ) { - sal_Int64 nCharRemain = nLen - nCharWritten; + sal_Int64 nCharRemain = nLen - nCharWritten + 1; constexpr sal_uInt16 MAX_SIZE = SAL_MAX_UINT16 / 4; sal_uInt16 nWriteSize = std::min<sal_Int64>(nCharRemain, MAX_SIZE); OString sData = OUStringToOString( @@ -608,7 +634,7 @@ void SAL_CALL OPreparedStatement::setClob(sal_Int32 nParameterIndex, const Refer if (aErr) { evaluateStatusVector(m_statusVector, - "isc_put_segment failed", + u"isc_put_segment failed", *this); assert(false); } @@ -634,10 +660,41 @@ void OPreparedStatement::setClob( sal_Int32 nParameterIndex, const OUString& rSt OString sData = OUStringToOString( rStr, RTL_TEXTENCODING_UTF8); - ISC_STATUS aErr = isc_put_segment( m_statusVector, + size_t nDataSize = sData.getLength(); + ISC_STATUS aErr = 0; + // we can't store more than MAX_SIZE_SEGMENT in a segment + if (nDataSize <= MAX_SIZE_SEGMENT) + { + aErr = isc_put_segment( m_statusVector, &aBlobHandle, sData.getLength(), sData.getStr() ); + } + else + { + // if we need more, let's split the input and first let's calculate the nb of entire chunks needed + size_t nNbEntireChunks = nDataSize / MAX_SIZE_SEGMENT; + for (size_t i = 0; i < nNbEntireChunks; ++i) + { + OString strCurrentChunk = sData.copy(i * MAX_SIZE_SEGMENT, MAX_SIZE_SEGMENT); + aErr = isc_put_segment( m_statusVector, + &aBlobHandle, + strCurrentChunk.getLength(), + strCurrentChunk.getStr() ); + if (aErr) + break; + } + size_t nRemainingBytes = nDataSize - (nNbEntireChunks * MAX_SIZE_SEGMENT); + if (nRemainingBytes && !aErr) + { + // then copy the remaining + OString strCurrentChunk = sData.copy(nNbEntireChunks * MAX_SIZE_SEGMENT, nRemainingBytes); + aErr = isc_put_segment( m_statusVector, + &aBlobHandle, + strCurrentChunk.getLength(), + strCurrentChunk.getStr() ); + } + } // We need to make sure we close the Blob even if there are errors, hence evaluate // errors after closing. @@ -646,7 +703,7 @@ void OPreparedStatement::setClob( sal_Int32 nParameterIndex, const OUString& rSt if (aErr) { evaluateStatusVector(m_statusVector, - "isc_put_segment failed", + u"isc_put_segment failed", *this); assert(false); } @@ -698,7 +755,7 @@ void SAL_CALL OPreparedStatement::setBlob(sal_Int32 nParameterIndex, if (aErr) { evaluateStatusVector(m_statusVector, - "isc_put_segment failed", + u"isc_put_segment failed", *this); assert(false); } @@ -756,7 +813,7 @@ void SAL_CALL OPreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex, c sBuffer.append(sValue); if(sValue.indexOf('.') != -1) // there is a dot { - for(sal_Int32 i=sValue.copy(sValue.indexOf('.')+1).getLength(); i<scale;i++) + for(sal_Int32 i=sValue.subView(sValue.indexOf('.')+1).size(); i<scale;i++) { sBuffer.append('0'); } @@ -866,7 +923,7 @@ void SAL_CALL OPreparedStatement::setBytes(sal_Int32 nParameterIndex, if (aErr) { evaluateStatusVector(m_statusVector, - "isc_put_segment failed", + u"isc_put_segment failed", *this); assert(false); } @@ -882,7 +939,7 @@ void SAL_CALL OPreparedStatement::setBytes(sal_Int32 nParameterIndex, { xBytesCopy.realloc( nMaxSize ); } - const auto nSize = xBytesCopy.getLength(); + const sal_uInt16 nSize = xBytesCopy.getLength(); // 8000 corresponds to value from lcl_addDefaultParameters // in dbaccess/source/filter/hsqldb/createparser.cxx if (nSize > 8000) @@ -890,6 +947,7 @@ void SAL_CALL OPreparedStatement::setBytes(sal_Int32 nParameterIndex, free(pVar->sqldata); pVar->sqldata = static_cast<char *>(malloc(sizeof(char) * nSize + 2)); } + static_assert(sizeof(nSize) == 2, "must match dest memcpy len"); // First 2 bytes indicate string size memcpy(pVar->sqldata, &nSize, 2); // Actual data @@ -897,9 +955,12 @@ void SAL_CALL OPreparedStatement::setBytes(sal_Int32 nParameterIndex, } else if( dType == SQL_TEXT ) { + if (pVar->sqllen < xBytes.getLength()) + dbtools::throwSQLException("Data too big for this field", + dbtools::StandardSQLState::INVALID_SQL_DATA_TYPE, *this); setParameterNull(nParameterIndex, false); memcpy(pVar->sqldata, xBytes.getConstArray(), xBytes.getLength() ); - // Fill remainder with spaces + // Fill remainder with zeroes memset(pVar->sqldata + xBytes.getLength(), 0, pVar->sqllen - xBytes.getLength()); } else @@ -991,4 +1052,4 @@ void OPreparedStatement::setParameterNull(sal_Int32 nParameterIndex, *pVar->sqlind = 0; } -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/PreparedStatement.hxx b/connectivity/source/drivers/firebird/PreparedStatement.hxx index e77201791cd1..3e61436b5874 100644 --- a/connectivity/source/drivers/firebird/PreparedStatement.hxx +++ b/connectivity/source/drivers/firebird/PreparedStatement.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_PREPAREDSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_PREPAREDSTATEMENT_HXX +#pragma once #include "StatementCommonBase.hxx" @@ -32,9 +31,7 @@ #include <ibase.h> -namespace connectivity -{ - namespace firebird +namespace connectivity::firebird { class OBoundParam; @@ -92,8 +89,8 @@ namespace connectivity //XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; @@ -149,8 +146,7 @@ namespace connectivity virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_PREPAREDSTATEMENT_HXX -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/ResultSet.cxx b/connectivity/source/drivers/firebird/ResultSet.cxx index 9409701d431f..ea3ac86ae762 100644 --- a/connectivity/source/drivers/firebird/ResultSet.cxx +++ b/connectivity/source/drivers/firebird/ResultSet.cxx @@ -144,7 +144,7 @@ sal_Bool SAL_CALL OResultSet::next() { SAL_WARN("connectivity.firebird", "Error when fetching data"); // Throws sql exception as appropriate - evaluateStatusVector(m_statusVector, "isc_dsql_fetch", *this); + evaluateStatusVector(m_statusVector, u"isc_dsql_fetch", *this); return false; } } @@ -430,13 +430,29 @@ T OResultSet::retrieveValue(const sal_Int32 nColumnIndex, const ISC_SHORT nType) if ((m_pSqlda->sqlvar[nColumnIndex-1].sqltype & ~1) == nType) return *reinterpret_cast<T*>(m_pSqlda->sqlvar[nColumnIndex-1].sqldata); else - return retrieveValue< ORowSetValue >(nColumnIndex, 0); + { + ORowSetValue row = retrieveValue< ORowSetValue >(nColumnIndex, 0); + if constexpr ( std::is_same_v<sal_Int64, T> ) + return row.getLong(); + else if constexpr ( std::is_same_v<sal_Int32, T> ) + return row.getInt32(); + else if constexpr ( std::is_same_v<sal_Int16, T> ) + return row.getInt16(); + else if constexpr ( std::is_same_v<float, T> ) + return row.getFloat(); + else if constexpr ( std::is_same_v<double, T> ) + return row.getDouble(); + else if constexpr ( std::is_same_v<bool, T> ) + return row.getBool(); + else + return row; + } } template <> ORowSetValue OResultSet::retrieveValue(const sal_Int32 nColumnIndex, const ISC_SHORT /*nType*/) { - // See http://wiki.openoffice.org/wiki/Documentation/DevGuide/Database/Using_the_getXXX_Methods + // See https://wiki.documentfoundation.org/Documentation/DevGuide/Database_Access#Using_the_getXXX_Methods // (bottom of page) for a chart of possible conversions, we should allow all // of these -- Blob/Clob will probably need some specialist handling especially // w.r.t. to generating Strings for them. @@ -511,7 +527,7 @@ Date OResultSet::retrieveValue(const sal_Int32 nColumnIndex, const ISC_SHORT /*n } else { - return retrieveValue< ORowSetValue >(nColumnIndex, 0); + return retrieveValue< ORowSetValue >(nColumnIndex, 0).getDate(); } } @@ -534,7 +550,7 @@ Time OResultSet::retrieveValue(const sal_Int32 nColumnIndex, const ISC_SHORT /*n } else { - return retrieveValue< ORowSetValue >(nColumnIndex, 0); + return retrieveValue< ORowSetValue >(nColumnIndex, 0).getTime(); } } @@ -560,7 +576,7 @@ DateTime OResultSet::retrieveValue(const sal_Int32 nColumnIndex, const ISC_SHORT } else { - return retrieveValue< ORowSetValue >(nColumnIndex, 0); + return retrieveValue< ORowSetValue >(nColumnIndex, 0).getDateTime(); } } @@ -579,10 +595,11 @@ OUString OResultSet::retrieveValue(const sal_Int32 nColumnIndex, const ISC_SHORT else if (aSqlType == SQL_VARYING) { // First 2 bytes are a short containing the length of the string - // No idea if sqllen is still valid here? + // Under unclear conditions, it may be wrong and greater than sqllen. sal_uInt16 aLength = *reinterpret_cast<sal_uInt16*>(m_pSqlda->sqlvar[nColumnIndex-1].sqldata); + // Use greater signed type sal_Int32 to get the minimum of two 16-bit values return OUString(m_pSqlda->sqlvar[nColumnIndex-1].sqldata + 2, - aLength, + std::min<sal_Int32>(aLength, m_pSqlda->sqlvar[nColumnIndex-1].sqllen), RTL_TEXTENCODING_UTF8); } else if ((aSqlType == SQL_SHORT || aSqlType == SQL_LONG || @@ -610,11 +627,11 @@ OUString OResultSet::retrieveValue(const sal_Int32 nColumnIndex, const ISC_SHORT else if(aSqlType == SQL_BLOB && aSqlSubType == static_cast<short>(BlobSubtype::Clob) ) { uno::Reference<XClob> xClob = getClob(nColumnIndex); - return xClob->getSubString( 0, xClob->length() ); + return xClob->getSubString( 1, xClob->length() ); } else { - return retrieveValue< ORowSetValue >(nColumnIndex, 0); + return retrieveValue< ORowSetValue >(nColumnIndex, 0).getString(); } } @@ -662,13 +679,35 @@ sal_Bool SAL_CALL OResultSet::getBoolean(sal_Int32 nColumnIndex) sal_Int8 SAL_CALL OResultSet::getByte(sal_Int32 nColumnIndex) { // Not a native firebird type hence we always have to convert. - return safelyRetrieveValue< ORowSetValue >(nColumnIndex); + return safelyRetrieveValue< ORowSetValue >(nColumnIndex).getInt8(); } -Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes(sal_Int32) +Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes(sal_Int32 nColumnIndex) { - return Sequence< sal_Int8 >(); // TODO: implement - //return safelyRetrieveValue(columnIndex); + // &~1 to remove the "can contain NULL" indicator + int aSqlType = m_pSqlda->sqlvar[nColumnIndex-1].sqltype & ~1; + if ( aSqlType == SQL_BLOB ) + { + Reference< XBlob> xBlob = getBlob(nColumnIndex); + if (xBlob.is()) + { + const sal_Int64 aBlobLength = xBlob->length(); + if (aBlobLength > SAL_MAX_INT32) + { + SAL_WARN("connectivity.firebird", "getBytes can't return " << aBlobLength << " bytes but only max " << SAL_MAX_INT32); + return xBlob->getBytes(1, SAL_MAX_INT32); + } + return xBlob->getBytes(1, static_cast<sal_Int32>(aBlobLength)); + } + else + return Sequence< sal_Int8 >(); + } + // TODO implement SQL_VARYING and SQL_TEXT + // as it's the counterpart as OPreparedStatement::setBytes + else + { + return Sequence< sal_Int8 >(); // TODO: implement + } } sal_Int16 SAL_CALL OResultSet::getShort(sal_Int32 columnIndex) @@ -853,12 +892,12 @@ IPropertyArrayHelper & OResultSet::getInfoHelper() return *getArrayHelper(); } -void SAL_CALL OResultSet::acquire() throw() +void SAL_CALL OResultSet::acquire() noexcept { OResultSet_BASE::acquire(); } -void SAL_CALL OResultSet::release() throw() +void SAL_CALL OResultSet::release() noexcept { OResultSet_BASE::release(); } @@ -884,4 +923,4 @@ sal_Bool SAL_CALL OResultSet::supportsService(const OUString& _rServiceName) return cppu::supportsService(this, _rServiceName); } -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/ResultSet.hxx b/connectivity/source/drivers/firebird/ResultSet.hxx index dc1a611febe2..fdae21dfbaaf 100644 --- a/connectivity/source/drivers/firebird/ResultSet.hxx +++ b/connectivity/source/drivers/firebird/ResultSet.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_RESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_RESULTSET_HXX +#pragma once #include "Connection.hxx" @@ -36,9 +35,7 @@ #include <com/sun/star/sdbc/XRow.hpp> #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> -namespace connectivity -{ - namespace firebird +namespace connectivity::firebird { /* ** OResultSet @@ -125,8 +122,8 @@ namespace connectivity // XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& rType) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; // XPropertySet @@ -213,8 +210,7 @@ namespace connectivity OResultSet::retrieveValue( const sal_Int32 nColumnIndex, const ISC_SHORT nType); - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_RESULTSET_HXX -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/ResultSetMetaData.cxx b/connectivity/source/drivers/firebird/ResultSetMetaData.cxx index d21115029df3..31a6796f5399 100644 --- a/connectivity/source/drivers/firebird/ResultSetMetaData.cxx +++ b/connectivity/source/drivers/firebird/ResultSetMetaData.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -53,8 +53,8 @@ OUString OResultSetMetaData::getCharacterSet( sal_Int32 nIndex ) "JOIN RDB$RELATION_FIELDS relfields " "ON (fields.RDB$FIELD_NAME = relfields.RDB$FIELD_SOURCE) " "WHERE relfields.RDB$RELATION_NAME = '" - + escapeWith(sTable, '\'', '\'') + "' AND " - "relfields.RDB$FIELD_NAME = '"+ escapeWith(sColumnName, '\'', '\'') +"'"; + + sTable.replaceAll("'", "''") + "' AND " + "relfields.RDB$FIELD_NAME = '"+ sColumnName.replaceAll("'", "''") +"'"; Reference<XStatement> xStmt= m_pConnection->createStatement(); @@ -128,9 +128,15 @@ OUString SAL_CALL OResultSetMetaData::getSchemaName(sal_Int32) OUString SAL_CALL OResultSetMetaData::getColumnName(sal_Int32 column) { verifyValidColumn(column); - OUString sRet(m_pSqlda->sqlvar[column-1].sqlname, - m_pSqlda->sqlvar[column-1].sqlname_length, - RTL_TEXTENCODING_UTF8); + char* pColumnName = m_pSqlda->sqlvar[column - 1].sqlname; + sal_Int32 nColumnNameLength = m_pSqlda->sqlvar[column - 1].sqlname_length; + // tdf#132924 - return column alias if specified + if (m_pSqlda->sqlvar[column - 1].aliasname_length > 0) + { + pColumnName = m_pSqlda->sqlvar[column - 1].aliasname; + nColumnNameLength = m_pSqlda->sqlvar[column - 1].aliasname_length; + } + OUString sRet(pColumnName, nColumnNameLength, RTL_TEXTENCODING_UTF8); sanitizeIdentifier(sRet); return sRet; } @@ -184,34 +190,34 @@ sal_Bool SAL_CALL OResultSetMetaData::isCurrency(sal_Int32) sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement(sal_Int32 column) { OUString sTable = getTableName(column); - if( !sTable.isEmpty() ) - { - OUString sColumnName = getColumnName( column ); + if( sTable.isEmpty() ) + return false; - OUString sSql = "SELECT RDB$IDENTITY_TYPE FROM RDB$RELATION_FIELDS " - "WHERE RDB$RELATION_NAME = '" - + escapeWith(sTable, '\'', '\'') + "' AND " - "RDB$FIELD_NAME = '"+ escapeWith(sColumnName, '\'', '\'') +"'"; + OUString sColumnName = getColumnName( column ); - Reference<XStatement> xStmt =m_pConnection ->createStatement(); + OUString sSql = "SELECT RDB$IDENTITY_TYPE FROM RDB$RELATION_FIELDS " + "WHERE RDB$RELATION_NAME = '" + + sTable.replaceAll("'", "''") + "' AND " + "RDB$FIELD_NAME = '"+ sColumnName.replaceAll("'", "''") +"'"; - Reference<XResultSet> xRes = - xStmt->executeQuery(sSql); - Reference<XRow> xRow ( xRes, UNO_QUERY); - if(xRes->next()) - { - int iType = xRow->getShort(1); - if(iType == 1) // IDENTITY - return true; - } - else - { - SAL_WARN("connectivity.firebird","Column '" - << sColumnName - << "' not found in database"); + Reference<XStatement> xStmt =m_pConnection ->createStatement(); - return false; - } + Reference<XResultSet> xRes = + xStmt->executeQuery(sSql); + Reference<XRow> xRow ( xRes, UNO_QUERY); + if(xRes->next()) + { + int iType = xRow->getShort(1); + if(iType == 1) // IDENTITY + return true; + } + else + { + SAL_WARN("connectivity.firebird","Column '" + << sColumnName + << "' not found in database"); + + return false; } return false; } @@ -226,34 +232,34 @@ sal_Bool SAL_CALL OResultSetMetaData::isSigned(sal_Int32) sal_Int32 SAL_CALL OResultSetMetaData::getPrecision(sal_Int32 column) { sal_Int32 nType = getColumnType(column); - if( nType == DataType::NUMERIC || nType == DataType::DECIMAL ) + if( nType != DataType::NUMERIC && nType != DataType::DECIMAL ) + return 0; + + OUString sColumnName = getColumnName( column ); + + // RDB$FIELD_SOURCE is a unique name of column per database + OUString sSql = "SELECT RDB$FIELD_PRECISION FROM RDB$FIELDS " + " INNER JOIN RDB$RELATION_FIELDS " + " ON RDB$RELATION_FIELDS.RDB$FIELD_SOURCE = RDB$FIELDS.RDB$FIELD_NAME " + "WHERE RDB$RELATION_FIELDS.RDB$RELATION_NAME = '" + + getTableName(column).replaceAll("'", "''") + "' AND " + "RDB$RELATION_FIELDS.RDB$FIELD_NAME = '" + + sColumnName.replaceAll("'", "''") +"'"; + Reference<XStatement> xStmt= m_pConnection->createStatement(); + + Reference<XResultSet> xRes = + xStmt->executeQuery(sSql); + Reference<XRow> xRow ( xRes, UNO_QUERY); + if(xRes->next()) { - OUString sColumnName = getColumnName( column ); - - // RDB$FIELD_SOURCE is a unique name of column per database - OUString sSql = "SELECT RDB$FIELD_PRECISION FROM RDB$FIELDS " - " INNER JOIN RDB$RELATION_FIELDS " - " ON RDB$RELATION_FIELDS.RDB$FIELD_SOURCE = RDB$FIELDS.RDB$FIELD_NAME " - "WHERE RDB$RELATION_FIELDS.RDB$RELATION_NAME = '" - + escapeWith(getTableName(column), '\'', '\'') + "' AND " - "RDB$RELATION_FIELDS.RDB$FIELD_NAME = '" - + escapeWith(sColumnName, '\'', '\'') +"'"; - Reference<XStatement> xStmt= m_pConnection->createStatement(); - - Reference<XResultSet> xRes = - xStmt->executeQuery(sSql); - Reference<XRow> xRow ( xRes, UNO_QUERY); - if(xRes->next()) - { - return static_cast<sal_Int32>(xRow->getShort(1)); - } - else - { - SAL_WARN("connectivity.firebird","Column '" - << sColumnName - << "' not found in database"); - return 0; - } + return static_cast<sal_Int32>(xRow->getShort(1)); + } + else + { + SAL_WARN("connectivity.firebird","Column '" + << sColumnName + << "' not found in database"); + return 0; } return 0; } @@ -292,5 +298,4 @@ sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 ) return !m_pConnection->isReadOnly(); } - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/ResultSetMetaData.hxx b/connectivity/source/drivers/firebird/ResultSetMetaData.hxx index 09474b8a7e9b..a32c206213aa 100644 --- a/connectivity/source/drivers/firebird/ResultSetMetaData.hxx +++ b/connectivity/source/drivers/firebird/ResultSetMetaData.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_RESULTSETMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_RESULTSETMETADATA_HXX +#pragma once #include "Connection.hxx" @@ -29,9 +28,7 @@ #include <com/sun/star/sdbc/XResultSetMetaData.hpp> -namespace connectivity -{ - namespace firebird +namespace connectivity::firebird { typedef ::cppu::WeakImplHelper< css::sdbc::XResultSetMetaData> OResultSetMetaData_BASE; @@ -77,9 +74,7 @@ namespace connectivity virtual sal_Bool SAL_CALL isDefinitelyWritable(sal_Int32 column) override; virtual OUString SAL_CALL getColumnServiceName(sal_Int32 column) override; }; - } -} -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_RESULTSETMETADATA_HXX +} -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Statement.cxx b/connectivity/source/drivers/firebird/Statement.cxx index 418c66a7d0cd..d135c4e4cda4 100644 --- a/connectivity/source/drivers/firebird/Statement.cxx +++ b/connectivity/source/drivers/firebird/Statement.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -40,7 +40,6 @@ using namespace com::sun::star::util; using namespace ::comphelper; using namespace ::osl; -using namespace ::std; // ---- XBatchExecution - UNSUPPORTED ---------------------------------------- void SAL_CALL OStatement::addBatch(const OUString&) @@ -58,12 +57,12 @@ Sequence< sal_Int32 > SAL_CALL OStatement::executeBatch() IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbcx.OStatement","com.sun.star.sdbc.Statement"); -void SAL_CALL OStatement::acquire() throw() +void SAL_CALL OStatement::acquire() noexcept { OStatementCommonBase::acquire(); } -void SAL_CALL OStatement::release() throw() +void SAL_CALL OStatement::release() noexcept { OStatementCommonBase::release(); } @@ -71,7 +70,8 @@ void SAL_CALL OStatement::release() throw() void OStatement::disposeResultSet() { MutexGuard aGuard(m_aMutex); - checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); + if (OStatementCommonBase_Base::rBHelper.bDisposed) + return; OStatementCommonBase::disposeResultSet(); @@ -126,11 +126,6 @@ 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; @@ -148,7 +143,7 @@ uno::Reference< XConnection > SAL_CALL OStatement::getConnection() MutexGuard aGuard(m_aMutex); checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); - return uno::Reference<XConnection>(m_pConnection.get()); + return m_pConnection; } Any SAL_CALL OStatement::queryInterface( const Type & rType ) @@ -172,4 +167,5 @@ void SAL_CALL OStatement::disposing() disposeResultSet(); close(); } -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Statement.hxx b/connectivity/source/drivers/firebird/Statement.hxx index 4c9168fd4304..d1b967def1d5 100644 --- a/connectivity/source/drivers/firebird/Statement.hxx +++ b/connectivity/source/drivers/firebird/Statement.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -17,17 +17,14 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_STATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_STATEMENT_HXX +#pragma once #include "StatementCommonBase.hxx" #include <cppuhelper/implbase1.hxx> #include <com/sun/star/sdbc/XBatchExecution.hpp> -namespace connectivity -{ - namespace firebird +namespace connectivity::firebird { typedef ::cppu::ImplHelper1< css::sdbc::XStatement > @@ -53,8 +50,8 @@ namespace connectivity DECLARE_SERVICE_INFO(); - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; // XStatement virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL @@ -80,10 +77,8 @@ namespace connectivity // OComponentHelper virtual void SAL_CALL disposing() override; - }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_STATEMENT_HXX -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/StatementCommonBase.cxx b/connectivity/source/drivers/firebird/StatementCommonBase.cxx index c1219d74b8ed..29ef5925657d 100644 --- a/connectivity/source/drivers/firebird/StatementCommonBase.cxx +++ b/connectivity/source/drivers/firebird/StatementCommonBase.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -17,7 +17,6 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include "Driver.hxx" #include "StatementCommonBase.hxx" #include "Util.hxx" @@ -44,7 +43,6 @@ using namespace ::com::sun::star::util; using namespace ::comphelper; using namespace ::osl; -using namespace ::std; OStatementCommonBase::OStatementCommonBase(Connection* _pConnection) : OStatementCommonBase_Base(m_aMutex), @@ -78,7 +76,7 @@ void OStatementCommonBase::freeStatementHandle() &m_aStatementHandle, DSQL_drop); evaluateStatusVector(m_statusVector, - "isc_dsql_free_statement", + u"isc_dsql_free_statement", *this); } } @@ -124,9 +122,7 @@ void SAL_CALL OStatementCommonBase::close() dispose(); } -void OStatementCommonBase::prepareAndDescribeStatement(const OUString& sql, - XSQLDA*& pOutSqlda, - XSQLDA* pInSqlda) +void OStatementCommonBase::prepareAndDescribeStatement(std::u16string_view sql, XSQLDA*& pOutSqlda) { SolarMutexGuard g; // tdf#122129 @@ -146,7 +142,7 @@ void OStatementCommonBase::prepareAndDescribeStatement(const OUString& sql, if (aErr) { evaluateStatusVector(m_statusVector, - "isc_dsql_allocate_statement", + u"isc_dsql_allocate_statement", *this); } else @@ -156,56 +152,41 @@ void OStatementCommonBase::prepareAndDescribeStatement(const OUString& sql, &m_aStatementHandle, 0, OUStringToOString(sql, RTL_TEXTENCODING_UTF8).getStr(), - FIREBIRD_SQL_DIALECT, - pInSqlda); + SQL_DIALECT_CURRENT, + pOutSqlda); if (aErr) { evaluateStatusVector(m_statusVector, - "isc_dsql_prepare", + u"isc_dsql_prepare", *this); } else { - aErr = isc_dsql_describe(m_statusVector, - &m_aStatementHandle, - 1, - pOutSqlda); + // Ensure we have enough space in pOutSqlda + if (pOutSqlda->sqld > pOutSqlda->sqln) + { + int n = pOutSqlda->sqld; + free(pOutSqlda); + pOutSqlda = static_cast<XSQLDA*>(calloc(1, XSQLDA_LENGTH(n))); + pOutSqlda->version = SQLDA_VERSION1; + pOutSqlda->sqln = n; + aErr = isc_dsql_describe(m_statusVector, + &m_aStatementHandle, + 1, + pOutSqlda); + } + // Process each XSQLVAR parameter structure in the output XSQLDA if (aErr) { - // TODO: free statement handle, etc.? evaluateStatusVector(m_statusVector, - "isc_dsql_describe", + u"isc_dsql_describe", *this); } else { - // Ensure we have enough space in pOutSqlda - if (pOutSqlda->sqld > pOutSqlda->sqln) - { - int n = pOutSqlda->sqld; - free(pOutSqlda); - pOutSqlda = static_cast<XSQLDA*>(calloc(1, XSQLDA_LENGTH(n))); - pOutSqlda->version = SQLDA_VERSION1; - pOutSqlda->sqln = n; - aErr = isc_dsql_describe(m_statusVector, - &m_aStatementHandle, - 1, - pOutSqlda); - } - - // Process each XSQLVAR parameter structure in the output XSQLDA - if (aErr) - { - evaluateStatusVector(m_statusVector, - "isc_dsql_describe", - *this); - } - else - { - mallocSQLVAR(pOutSqlda); - } + mallocSQLVAR(pOutSqlda); } } if(aErr) @@ -260,31 +241,71 @@ void SAL_CALL OStatementCommonBase::clearWarnings() { // this properties are define by the service statement // they must in alphabetic order - Sequence< Property > aProps(10); - Property* pProperties = aProps.getArray(); - sal_Int32 nPos = 0; - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), - PROPERTY_ID_CURSORNAME, cppu::UnoType<OUString>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ESCAPEPROCESSING), - PROPERTY_ID_ESCAPEPROCESSING, cppu::UnoType<bool>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), - PROPERTY_ID_FETCHDIRECTION, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), - PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXFIELDSIZE), - PROPERTY_ID_MAXFIELDSIZE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXROWS), - PROPERTY_ID_MAXROWS, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_QUERYTIMEOUT), - PROPERTY_ID_QUERYTIMEOUT, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), - PROPERTY_ID_RESULTSETCONCURRENCY, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), - PROPERTY_ID_RESULTSETTYPE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_USEBOOKMARKS), - PROPERTY_ID_USEBOOKMARKS, cppu::UnoType<bool>::get(), 0); - - return new ::cppu::OPropertyArrayHelper(aProps); + return new ::cppu::OPropertyArrayHelper + { + { + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), + PROPERTY_ID_CURSORNAME, + cppu::UnoType<OUString>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ESCAPEPROCESSING), + PROPERTY_ID_ESCAPEPROCESSING, + cppu::UnoType<bool>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), + PROPERTY_ID_FETCHDIRECTION, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), + PROPERTY_ID_FETCHSIZE, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXFIELDSIZE), + PROPERTY_ID_MAXFIELDSIZE, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXROWS), + PROPERTY_ID_MAXROWS, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_QUERYTIMEOUT), + PROPERTY_ID_QUERYTIMEOUT, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), + PROPERTY_ID_RESULTSETCONCURRENCY, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), + PROPERTY_ID_RESULTSETTYPE, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_USEBOOKMARKS), + PROPERTY_ID_USEBOOKMARKS, + cppu::UnoType<bool>::get(), + 0 + } + } + }; } @@ -342,12 +363,12 @@ void OStatementCommonBase::getFastPropertyValue(Any&,sal_Int32 nHandle) const } } -void SAL_CALL OStatementCommonBase::acquire() throw() +void SAL_CALL OStatementCommonBase::acquire() noexcept { OStatementCommonBase_Base::acquire(); } -void SAL_CALL OStatementCommonBase::release() throw() +void SAL_CALL OStatementCommonBase::release() noexcept { OStatementCommonBase_Base::release(); } @@ -379,7 +400,7 @@ short OStatementCommonBase::getSqlInfoItem(char aInfoItem) } evaluateStatusVector(aStatusVector, - "isc_dsq_sql_info", + u"isc_dsq_sql_info", *this); return 0; } @@ -411,7 +432,7 @@ sal_Int32 OStatementCommonBase::getStatementChangeCount() if (aErr) { evaluateStatusVector(aStatusVector, - "isc_dsq_sql_info", + u"isc_dsq_sql_info", *this); return 0; } @@ -432,32 +453,34 @@ sal_Int32 OStatementCommonBase::getStatementChangeCount() aDesiredInfoType = isc_info_req_delete_count; break; case isc_info_sql_stmt_exec_procedure: + case isc_info_sql_stmt_ddl: return 0; // cannot determine default: throw SQLException(); // TODO: better error message? } char* pResults = aResultsBuffer; - if (static_cast<short>(*pResults++) == isc_info_sql_records) - { -// const short aTotalLength = (short) isc_vax_integer(pResults, 2); - pResults += 2; + if (static_cast<short>(*pResults++) != isc_info_sql_records) + return 0; - // Seems to be of form TOKEN (1 byte), LENGTH (2 bytes), DATA (LENGTH bytes) - while (*pResults != isc_info_rsb_end) - { - const char aToken = *pResults; - const short aLength = static_cast<short>(isc_vax_integer(pResults+1, 2)); +// const short aTotalLength = (short) isc_vax_integer(pResults, 2); + pResults += 2; - if (aToken == aDesiredInfoType) - { - return isc_vax_integer(pResults + 3, aLength); - } + // Seems to be of form TOKEN (1 byte), LENGTH (2 bytes), DATA (LENGTH bytes) + while (*pResults != isc_info_rsb_end) + { + const char aToken = *pResults; + const short aLength = static_cast<short>(isc_vax_integer(pResults+1, 2)); - pResults += (3 + aLength); + if (aToken == aDesiredInfoType) + { + return isc_vax_integer(pResults + 3, aLength); } + + pResults += (3 + aLength); } return 0; } -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/StatementCommonBase.hxx b/connectivity/source/drivers/firebird/StatementCommonBase.hxx index 5a53706ee938..fa9cd790272e 100644 --- a/connectivity/source/drivers/firebird/StatementCommonBase.hxx +++ b/connectivity/source/drivers/firebird/StatementCommonBase.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -17,8 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_STATEMENTCOMMONBASE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_STATEMENTCOMMONBASE_HXX +#pragma once + +#include <sal/config.h> + +#include <string_view> #include "Connection.hxx" #include "SubComponent.hxx" @@ -33,9 +36,7 @@ #include <com/sun/star/sdbc/XWarningsSupplier.hpp> #include <com/sun/star/util/XCancellable.hpp> -namespace connectivity -{ - namespace firebird +namespace connectivity::firebird { typedef ::cppu::WeakComponentImplHelper< css::sdbc::XWarningsSupplier, @@ -83,9 +84,7 @@ namespace connectivity virtual ~OStatementCommonBase() override; /// @throws css::sdbc::SQLException - void prepareAndDescribeStatement(const OUString& sqlIn, - XSQLDA*& pOutSqlda, - XSQLDA* pInSqlda=nullptr); + void prepareAndDescribeStatement(std::u16string_view sqlIn, XSQLDA*& pOutSqlda); /// @throws css::sdbc::SQLException short getSqlInfoItem(char aInfoItem); @@ -105,8 +104,8 @@ namespace connectivity OStatementCommonBase_Base::disposing(); } // XInterface - virtual void SAL_CALL release() throw() override; - virtual void SAL_CALL acquire() throw() override; + virtual void SAL_CALL release() noexcept override; + virtual void SAL_CALL acquire() noexcept override; // XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; //XTypeProvider @@ -129,9 +128,7 @@ namespace connectivity virtual void SAL_CALL close( ) override; }; - } -} -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_STATEMENTCOMMONBASE_HXX +} -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/SubComponent.hxx b/connectivity/source/drivers/firebird/SubComponent.hxx index d37100670995..bea5d76d423d 100644 --- a/connectivity/source/drivers/firebird/SubComponent.hxx +++ b/connectivity/source/drivers/firebird/SubComponent.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -17,34 +17,16 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_SUBCOMPONENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_SUBCOMPONENT_HXX +#pragma once #include <cppuhelper/propshlp.hxx> #include <osl/diagnose.h> #include <osl/mutex.hxx> -namespace cppu { - class IPropertyArrayHelper; -} - -namespace com -{ - namespace sun - { - namespace star - { - namespace lang - { - class XComponent; - } - } - } -} -namespace connectivity -{ +namespace cppu { class IPropertyArrayHelper; } +namespace com::sun::star::lang { class XComponent; } - namespace firebird +namespace connectivity::firebird { /// @throws css::lang::DisposedException void checkDisposed(bool _bThrow); @@ -124,8 +106,6 @@ namespace connectivity return s_pProps; } - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_SUBCOMPONENT_HXX -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Table.cxx b/connectivity/source/drivers/firebird/Table.cxx index e0eba9d7e264..871febcf5122 100644 --- a/connectivity/source/drivers/firebird/Table.cxx +++ b/connectivity/source/drivers/firebird/Table.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -155,27 +155,14 @@ void SAL_CALL Table::alterColumnByName(const OUString& rColName, if (nNullable != ColumnValue::NULLABLE_UNKNOWN) { - OUString sSql; - // Dirty hack: can't change null directly in sql, we have to fiddle - // the system tables manually. + OUString sSql(getAlterTableColumn(rColName)); if (nNullable == ColumnValue::NULLABLE) { - sSql = "UPDATE RDB$RELATION_FIELDS SET RDB$NULL_FLAG = NULL " - "WHERE RDB$FIELD_NAME = '" + rColName + "' " - "AND RDB$RELATION_NAME = '" + getName() + "'"; + sSql += "DROP NOT NULL"; } else if (nNullable == ColumnValue::NO_NULLS) { - // And if we are making NOT NULL then we have to make sure we have - // no nulls left in the column. - OUString sFillNulls("UPDATE \"" + getName() + "\" SET \"" - + rColName + "\" = 0 " - "WHERE \"" + rColName + "\" IS NULL"); - getConnection()->createStatement()->execute(sFillNulls); - - sSql = "UPDATE RDB$RELATION_FIELDS SET RDB$NULL_FLAG = 1 " - "WHERE RDB$FIELD_NAME = '" + rColName + "' " - "AND RDB$RELATION_NAME = '" + getName() + "'"; + sSql += "SET NOT NULL"; } getConnection()->createStatement()->execute(sSql); } @@ -237,26 +224,9 @@ Any SAL_CALL Table::queryInterface(const Type& rType) return OTableHelper::queryInterface(rType); } -// ----- XTypeProvider -------------------------------------------------------- -uno::Sequence< Type > SAL_CALL Table::getTypes() -{ - uno::Sequence< Type > aTypes = OTableHelper::getTypes(); - - for (int i = 0; i < aTypes.getLength(); i++) - { - if (aTypes[i].getTypeName() == "com.sun.star.sdbcx.XRename") - { - ::comphelper::removeElementAt(aTypes, i); - break; - } - } - - return OTableHelper::getTypes(); -} - -OUString Table::getAlterTableColumn(const OUString& rColumn) +OUString Table::getAlterTableColumn(std::u16string_view rColumn) { return ("ALTER TABLE \"" + getName() + "\" ALTER COLUMN \"" + rColumn + "\" "); } -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Table.hxx b/connectivity/source/drivers/firebird/Table.hxx index 586152ecce10..ed638a9c88ac 100644 --- a/connectivity/source/drivers/firebird/Table.hxx +++ b/connectivity/source/drivers/firebird/Table.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -7,16 +7,17 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_TABLE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_TABLE_HXX +#pragma once + +#include <sal/config.h> + +#include <string_view> #include "Tables.hxx" #include <connectivity/TTableHelper.hxx> -namespace connectivity -{ - namespace firebird +namespace connectivity::firebird { /** @@ -33,7 +34,7 @@ namespace connectivity * Get the ALTER TABLE [TABLE] ALTER [COLUMN] String. * Includes a trailing space. */ - OUString getAlterTableColumn(const OUString& rColumn); + OUString getAlterTableColumn(std::u16string_view rColumn); protected: void construct() override; @@ -73,15 +74,8 @@ namespace connectivity virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type & rType) override; - //XTypeProvider - virtual css::uno::Sequence< css::uno::Type > - SAL_CALL getTypes() override; - }; - } // namespace firebird -} // namespace connectivity - -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_TABLE_HXX +} // namespace connectivity::firebird -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Tables.cxx b/connectivity/source/drivers/firebird/Tables.cxx index 34907418abf8..e3440137381a 100644 --- a/connectivity/source/drivers/firebird/Tables.cxx +++ b/connectivity/source/drivers/firebird/Tables.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -9,8 +9,8 @@ #include "Table.hxx" #include "Tables.hxx" +#include "Views.hxx" #include "Catalog.hxx" -#include "Util.hxx" #include <TConnection.hxx> @@ -30,7 +30,6 @@ using namespace ::osl; using namespace ::com::sun::star; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::uno; @@ -81,7 +80,7 @@ OUString Tables::createStandardColumnPart(const Reference< XPropertySet >& xColP xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)) >>= bIsAutoIncrement; const OUString sQuoteString = xMetaData->getIdentifierQuoteString(); - OUStringBuffer aSql = ::dbtools::quoteName(sQuoteString,::comphelper::getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)))); + OUStringBuffer aSql(::dbtools::quoteName(sQuoteString,::comphelper::getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME))))); // check if the user enter a specific string to create autoincrement values OUString sAutoIncrementValue; @@ -90,12 +89,10 @@ OUString Tables::createStandardColumnPart(const Reference< XPropertySet >& xColP if ( xPropInfo.is() && xPropInfo->hasPropertyByName(rPropMap.getNameByIndex(PROPERTY_ID_AUTOINCREMENTCREATION)) ) xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_AUTOINCREMENTCREATION)) >>= sAutoIncrementValue; - aSql.append(" "); - - aSql.append(dbtools::createStandardTypePart(xColProp, _xConnection)); - - // Add character set for BINARY (fix) type: - // BINARY is distinguished from other CHAR types by its character set. + aSql.append(" " + + dbtools::createStandardTypePart(xColProp, _xConnection)); + // Add character set for (VAR)BINARY (fix) types: + // (VAR) BINARY is distinguished from other CHAR types by its character set. // Octets is a special character set for binary data. if ( xPropInfo.is() && xPropInfo->hasPropertyByName(rPropMap.getNameByIndex( PROPERTY_ID_TYPE)) ) @@ -105,28 +102,13 @@ OUString Tables::createStandardColumnPart(const Reference< XPropertySet >& xColP >>= aType; if(aType == DataType::BINARY || aType == DataType::VARBINARY) { - aSql.append(" "); - aSql.append("CHARACTER SET OCTETS"); - } - else if(aType == DataType::CLOB) - { - // CLOB is a special type of blob in Firebird context. - // Subtype number 1 always refers to CLOB - aSql.append(" "); - aSql.append("SUB_TYPE 1"); - } - else if(aType == DataType::LONGVARBINARY) - { - aSql.append(" "); - aSql.append("SUB_TYPE "); - aSql.append(OUString::number(static_cast<short>(BlobSubtype::Image))); + aSql.append(" CHARACTER SET OCTETS"); } } if ( bIsAutoIncrement && !sAutoIncrementValue.isEmpty()) { - aSql.append(" "); - aSql.append(sAutoIncrementValue); + aSql.append(" " + sAutoIncrementValue); } // AutoIncrement "IDENTITY" is implicitly "NOT NULL" else if(::comphelper::getINT32(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_ISNULLABLE))) == ColumnValue::NO_NULLS) @@ -163,8 +145,8 @@ ObjectType Tables::appendObject(const OUString& rName, if ( sComposedName.isEmpty() ) ::dbtools::throwFunctionSequenceException(xConnection); - aSqlBuffer.append(sComposedName); - aSqlBuffer.append(" ("); + aSqlBuffer.append(sComposedName + + " ("); // columns Reference<XColumnsSupplier> xColumnSup(rDescriptor,UNO_QUERY); @@ -180,8 +162,8 @@ ObjectType Tables::appendObject(const OUString& rName, { if ( (xColumns->getByIndex(i) >>= xColProp) && xColProp.is() ) { - aSqlBuffer.append(createStandardColumnPart(xColProp,xConnection)); - aSqlBuffer.append(","); + aSqlBuffer.append(createStandardColumnPart(xColProp,xConnection) + + ","); } } OUString sSql = aSqlBuffer.makeStringAndClear(); @@ -192,7 +174,7 @@ ObjectType Tables::appendObject(const OUString& rName, else { if ( sSql.endsWith(",") ) - sSql = sSql.replaceAt(sSql.getLength()-1, 1, ")"); + sSql = sSql.replaceAt(sSql.getLength()-1, 1, u")"); else sSql += ")"; } @@ -210,16 +192,34 @@ void Tables::dropObject(sal_Int32 nPosition, const OUString& sName) if (ODescriptor::isNew(xTable)) return; - OUStringBuffer sSql("DROP "); - OUString sType; xTable->getPropertyValue("Type") >>= sType; - sSql.append(sType); const OUString sQuoteString = m_xMetaData->getIdentifierQuoteString(); - sSql.append(::dbtools::quoteName(sQuoteString,sName)); - m_xMetaData->getConnection()->createStatement()->execute(sSql.makeStringAndClear()); + m_xMetaData->getConnection()->createStatement()->execute( + "DROP " + sType + " " + ::dbtools::quoteName(sQuoteString,sName)); + + if (sType == "VIEW") + { + Views* pViews = static_cast<Views*>(static_cast<Catalog&>(m_rParent).getPrivateViews()); + if ( pViews && pViews->hasByName(sName) ) + pViews->dropByNameImpl(sName); + } } -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +void connectivity::firebird::Tables::appendNew(const OUString& _rsNewTable) +{ + insertElement(_rsNewTable, nullptr); + + // notify our container listeners + css::container::ContainerEvent aEvent(static_cast<XContainer*>(this), + css::uno::Any(_rsNewTable), css::uno::Any(), + css::uno::Any()); + comphelper::OInterfaceIteratorHelper3 aListenerLoop(m_aContainerListeners); + while (aListenerLoop.hasMoreElements()) + aListenerLoop.next()->elementInserted(aEvent); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Tables.hxx b/connectivity/source/drivers/firebird/Tables.hxx index 635774727095..ada1827097a5 100644 --- a/connectivity/source/drivers/firebird/Tables.hxx +++ b/connectivity/source/drivers/firebird/Tables.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -7,17 +7,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_TABLES_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_TABLES_HXX +#pragma once #include <com/sun/star/sdbc/XConnection.hpp> #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> #include <connectivity/sdbcx/VCollection.hxx> +#include <utility> -namespace connectivity -{ - namespace firebird +namespace connectivity::firebird { /** @@ -43,10 +41,10 @@ namespace connectivity const css::uno::Reference< css::beans::XPropertySet >& rDescriptor) override; public: - Tables(const css::uno::Reference< css::sdbc::XDatabaseMetaData >& rMetaData, + Tables(css::uno::Reference< css::sdbc::XDatabaseMetaData > xMetaData, ::cppu::OWeakObject& rParent, ::osl::Mutex& rMutex, - ::std::vector< OUString> const & rNames) : sdbcx::OCollection(rParent, true, rMutex, rNames), m_xMetaData(rMetaData) {} + ::std::vector< OUString> const & rNames) : sdbcx::OCollection(rParent, true, rMutex, rNames), m_xMetaData(std::move(xMetaData)) {} // TODO: we should also implement XDataDescriptorFactory, XRefreshable, // XAppend, etc., but all are optional. @@ -54,12 +52,10 @@ namespace connectivity // XDrop virtual void dropObject(sal_Int32 nPosition, const OUString& rName) override; - }; - - } // namespace firebird -} // namespace connectivity + void appendNew(const OUString& _rsNewTable); + }; -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_TABLES_HXX +} // namespace connectivity::firebird -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/User.cxx b/connectivity/source/drivers/firebird/User.cxx index 3a9682fb8264..9f647713a663 100644 --- a/connectivity/source/drivers/firebird/User.cxx +++ b/connectivity/source/drivers/firebird/User.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -49,3 +49,5 @@ void User::refreshGroups() { // TODO: implement. } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/User.hxx b/connectivity/source/drivers/firebird/User.hxx index 5668c3223c13..e47565f5d52e 100644 --- a/connectivity/source/drivers/firebird/User.hxx +++ b/connectivity/source/drivers/firebird/User.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -7,15 +7,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_USER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_USER_HXX +#pragma once #include <sdbcx/VUser.hxx> #include <com/sun/star/sdbc/XConnection.hpp> -namespace connectivity -{ - namespace firebird +namespace connectivity::firebird { /** @@ -44,10 +41,6 @@ namespace connectivity virtual void refreshGroups() override; }; - } // namespace firebird -} // namespace connectivity +} // namespace connectivity::firebird - -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_USER_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Users.cxx b/connectivity/source/drivers/firebird/Users.cxx index fc8914250ee6..10912d6be0ab 100644 --- a/connectivity/source/drivers/firebird/Users.cxx +++ b/connectivity/source/drivers/firebird/Users.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -17,8 +17,6 @@ using namespace ::cppu; using namespace ::osl; using namespace ::com::sun::star; using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::uno; @@ -75,4 +73,4 @@ void Users::dropObject(sal_Int32 nPosition, const OUString&) } } -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Users.hxx b/connectivity/source/drivers/firebird/Users.hxx index 39e019e4dada..7e78444d1199 100644 --- a/connectivity/source/drivers/firebird/Users.hxx +++ b/connectivity/source/drivers/firebird/Users.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -7,15 +7,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_USERS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_USERS_HXX +#pragma once #include <connectivity/sdbcx/VCollection.hxx> #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> -namespace connectivity -{ - namespace firebird +namespace connectivity::firebird { /** @@ -51,10 +48,6 @@ namespace connectivity }; - } // namespace firebird -} // namespace connectivity +} // namespace connectivity::firebird - -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_USERS_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Util.cxx b/connectivity/source/drivers/firebird/Util.cxx index 7befd4b99014..3cee5dab6e0b 100644 --- a/connectivity/source/drivers/firebird/Util.cxx +++ b/connectivity/source/drivers/firebird/Util.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -13,6 +13,7 @@ #include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/sdbc/SQLException.hpp> +#include <o3tl/string_view.hxx> using namespace ::connectivity; @@ -22,16 +23,16 @@ using namespace ::com::sun::star::uno; using namespace firebird; -OUString firebird::sanitizeIdentifier(const OUString& rIdentifier) +OUString firebird::sanitizeIdentifier(std::u16string_view rIdentifier) { - OUString sRet = rIdentifier.trim(); - assert(sRet.getLength() <= 31); // Firebird identifiers cannot be longer than this. + std::u16string_view sRet = o3tl::trim(rIdentifier); + assert(sRet.size() <= 31); // Firebird identifiers cannot be longer than this. - return sRet; + return OUString(sRet); } OUString firebird::StatusVectorToString(const ISC_STATUS_ARRAY& rStatusVector, - const OUString& rCause) + std::u16string_view rCause) { OUStringBuffer buf; const ISC_STATUS* pStatus = reinterpret_cast<const ISC_STATUS*>(&rStatusVector); @@ -43,15 +44,15 @@ OUString firebird::StatusVectorToString(const ISC_STATUS_ARRAY& rStatusVector, while(fb_interpret(msg, sizeof(msg), &pStatus)) { // TODO: verify encoding - buf.append("\n*"); - buf.append(OUString(msg, strlen(msg), RTL_TEXTENCODING_UTF8)); + buf.append("\n*" + + OUString(msg, strlen(msg), RTL_TEXTENCODING_UTF8)); } } catch (...) { SAL_WARN("connectivity.firebird", "ignore fb_interpret exception"); } - buf.append("\ncaused by\n'").append(rCause).append("'\n"); + buf.append(OUString::Concat("\ncaused by\n'") + rCause + "'\n"); OUString error = buf.makeStringAndClear(); SAL_WARN("connectivity.firebird", error); @@ -59,7 +60,7 @@ OUString firebird::StatusVectorToString(const ISC_STATUS_ARRAY& rStatusVector, } void firebird::evaluateStatusVector(const ISC_STATUS_ARRAY& rStatusVector, - const OUString& rCause, + std::u16string_view rCause, const uno::Reference< XInterface >& _rxContext) { if (IndicatesError(rStatusVector)) @@ -94,17 +95,17 @@ static sal_Int32 lcl_getNumberType( short aType, NumberSubType aSubType ) } } } -static sal_Int32 lcl_getCharColumnType( short aType, const OUString& sCharset ) +static sal_Int32 lcl_getCharColumnType( short aType, std::u16string_view sCharset ) { switch(aType) { case SQL_TEXT: - if( sCharset == "OCTETS") + if( sCharset == u"OCTETS") return DataType::BINARY; else return DataType::CHAR; case SQL_VARYING: - if( sCharset == "OCTETS") + if( sCharset == u"OCTETS") return DataType::VARBINARY; else return DataType::VARCHAR; @@ -181,47 +182,65 @@ sal_Int32 firebird::ColumnTypeInfo::getSdbcType() const OUString firebird::ColumnTypeInfo::getColumnTypeName() const { - short aType = m_aType & ~1; // Remove last bit -- it is used to denote whether column - // can store Null, not needed for type determination - - switch (aType) + sal_Int32 nDataType = this->getSdbcType(); + switch (nDataType) { - case SQL_TEXT: - return "SQL_TEXT"; - case SQL_VARYING: - return "SQL_VARYING"; - case SQL_SHORT: - return "SQL_SHORT"; - case SQL_LONG: - return "SQL_LONG"; - case SQL_FLOAT: - return "SQL_FLOAT"; - case SQL_DOUBLE: - return "SQL_DOUBLE"; - case SQL_D_FLOAT: - return "SQL_D_FLOAT"; - case SQL_TIMESTAMP: - return "SQL_TIMESTAMP"; - case SQL_BLOB: - return "SQL_BLOB"; - case SQL_ARRAY: - return "SQL_ARRAY"; - case SQL_TYPE_TIME: - return "SQL_TYPE_TIME"; - case SQL_TYPE_DATE: - return "SQL_TYPE_DATE"; - case SQL_INT64: - return "SQL_INT64"; - case SQL_NULL: - return "SQL_NULL"; - case SQL_QUAD: - return "SQL_QUAD"; - case SQL_BOOLEAN: - return "SQL_BOOLEAN"; - default: - assert(false); // Should never happen - return OUString(); - } + case DataType::BIT: + return "BIT"; + case DataType::TINYINT: + return "TINYINT"; + case DataType::SMALLINT: + return "SMALLINT"; + case DataType::INTEGER: + return "INTEGER"; + case DataType::BIGINT: + return "BIGINT"; + case DataType::FLOAT: + return "FLOAT"; + case DataType::REAL: + return "REAL"; + case DataType::DOUBLE: + return "DOUBLE"; + case DataType::NUMERIC: + return "NUMERIC"; + case DataType::DECIMAL: + return "DECIMAL"; + case DataType::CHAR: + return "CHAR"; + case DataType::VARCHAR: + return "VARCHAR"; + case DataType::LONGVARCHAR: + return "LONGVARCHAR"; + case DataType::DATE: + return "DATE"; + case DataType::TIME: + return "TIME"; + case DataType::TIMESTAMP: + return "TIMESTAMP"; + case DataType::BINARY: + // in Firebird, that is the same datatype "CHAR" as DataType::CHAR, + // only with CHARACTER SET OCTETS; we use the synonym CHARACTER + // to fool LO into seeing it as different types. + return "CHARACTER"; + case DataType::VARBINARY: + // see above comment about DataType::BINARY. + return "CHARACTER VARYING"; + case DataType::LONGVARBINARY: + return "BLOB SUB_TYPE " + OUString::number(static_cast<short>(BlobSubtype::Image)); + case DataType::ARRAY: + return "ARRAY"; + case DataType::BLOB: + return "BLOB SUB_TYPE BINARY"; + case DataType::CLOB: + return "BLOB SUB_TYPE TEXT"; + case DataType::BOOLEAN: + return "BOOLEAN"; + case DataType::SQLNULL: + return "NULL"; + default: + assert(false); // Should never happen + return OUString(); + } } short firebird::getFBTypeFromBlrType(short blrType) @@ -324,8 +343,9 @@ void firebird::mallocSQLVAR(XSQLDA* pSqlda) case SQL_BOOLEAN: pVar->sqldata = static_cast<char *>(malloc(sizeof(sal_Bool))); break; + // See https://www.firebirdsql.org/file/documentation/html/en/refdocs/fblangref25/firebird-25-language-reference.html#fblangref25-datatypes-special-sqlnull case SQL_NULL: - assert(false); // TODO: implement + pVar->sqldata = nullptr; break; case SQL_QUAD: assert(false); // TODO: implement @@ -370,7 +390,8 @@ void firebird::freeSQLVAR(XSQLDA* pSqlda) } break; case SQL_NULL: - assert(false); // TODO: implement + // See SQL_NULL case in mallocSQLVAR + assert(pVar->sqldata == nullptr); break; case SQL_QUAD: assert(false); // TODO: implement @@ -390,22 +411,6 @@ void firebird::freeSQLVAR(XSQLDA* pSqlda) } -OUString firebird::escapeWith( const OUString& sText, const char aKey, const char aEscapeChar) -{ - OUString sRet(sText); - sal_Int32 aIndex = 0; - for (;;) - { - aIndex = sRet.indexOf(aKey, aIndex); - if ( aIndex <= 0 || aIndex >= sRet.getLength()) - break; - sRet = sRet.replaceAt(aIndex, 1, OUStringChar(aEscapeChar) + OUStringChar(aKey) ); - aIndex += 2; - } - - return sRet; -} - sal_Int64 firebird::pow10Integer(int nDecimalCount) { sal_Int64 nRet = 1; @@ -415,4 +420,5 @@ sal_Int64 firebird::pow10Integer(int nDecimalCount) } return nRet; } -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Util.hxx b/connectivity/source/drivers/firebird/Util.hxx index 107840876e55..db407ef98b38 100644 --- a/connectivity/source/drivers/firebird/Util.hxx +++ b/connectivity/source/drivers/firebird/Util.hxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -7,18 +7,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_UTIL_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_UTIL_HXX +#pragma once #include <ibase.h> #include <rtl/ustring.hxx> #include <com/sun/star/uno/XInterface.hpp> +#include <utility> -namespace connectivity -{ - namespace firebird +namespace connectivity::firebird { // Type Blob has 2 subtypes values // 0 for BLOB, 1 for CLOB @@ -60,16 +58,16 @@ public: * */ explicit ColumnTypeInfo( short aType, short aSubType = 0, - short nScale = 0, const OUString& sCharset = OUString() ) + short nScale = 0, OUString sCharset = OUString() ) : m_aType(aType) , m_aSubType(aSubType) , m_nScale(nScale) - , m_sCharsetName(sCharset) {} - explicit ColumnTypeInfo( short aType, const OUString& sCharset ) + , m_sCharsetName(std::move(sCharset)) {} + explicit ColumnTypeInfo( short aType, OUString sCharset ) : m_aType(aType) , m_aSubType(0) , m_nScale(0) - , m_sCharsetName(sCharset) {} + , m_sCharsetName(std::move(sCharset)) {} short getType() const { return m_aType; } short getSubType() const { return m_aSubType; } short getScale() const { return m_nScale; } @@ -89,7 +87,7 @@ public: * for such shorter strings, however any trailing padding makes the gui * editing of such names harder, hence we remove all trailing whitespace. */ - OUString sanitizeIdentifier(const OUString& rIdentifier); + OUString sanitizeIdentifier(std::u16string_view rIdentifier); inline bool IndicatesError(const ISC_STATUS_ARRAY& rStatusVector) { @@ -97,7 +95,7 @@ public: } OUString StatusVectorToString(const ISC_STATUS_ARRAY& rStatusVector, - const OUString& rCause); + std::u16string_view rCause); /** * Evaluate a firebird status vector and throw exceptions as necessary. @@ -106,7 +104,7 @@ public: * @throws css::sdbc::SQLException */ void evaluateStatusVector(const ISC_STATUS_ARRAY& rStatusVector, - const OUString& aCause, + std::u16string_view aCause, const css::uno::Reference< css::uno::XInterface >& _rxContext); /** @@ -121,10 +119,8 @@ public: void freeSQLVAR(XSQLDA* pSqlda); - OUString escapeWith( const OUString& sText, const char aKey, const char aEscapeChar); sal_Int64 pow10Integer( int nDecimalCount ); - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_UTIL_HXX -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/View.cxx b/connectivity/source/drivers/firebird/View.cxx new file mode 100644 index 000000000000..6dcbf6bce2b2 --- /dev/null +++ b/connectivity/source/drivers/firebird/View.cxx @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ +#include "View.hxx" + +#include <propertyids.hxx> + +#include <com/sun/star/sdbc/XRow.hpp> + +namespace connectivity::firebird +{ +View::View(const css::uno::Reference<css::sdbc::XConnection>& _rxConnection, bool _bCaseSensitive, + const OUString& _rSchemaName, const OUString& _rName) + : View_Base(_bCaseSensitive, _rName, _rxConnection->getMetaData(), OUString(), _rSchemaName, + OUString()) + , m_xConnection(_rxConnection) +{ +} + +View::~View() {} + +void SAL_CALL View::acquire() noexcept { View_Base::acquire(); }; +void SAL_CALL View::release() noexcept { View_Base::release(); }; +css::uno::Any SAL_CALL View::queryInterface(const css::uno::Type& _rType) +{ + css::uno::Any aReturn = View_Base::queryInterface(_rType); + if (!aReturn.hasValue()) + aReturn = View_IBASE::queryInterface(_rType); + return aReturn; +} + +css::uno::Sequence<css::uno::Type> SAL_CALL View::getTypes() +{ + return ::comphelper::concatSequences(View_Base::getTypes(), View_IBASE::getTypes()); +} + +css::uno::Sequence<sal_Int8> SAL_CALL View::getImplementationId() +{ + return css::uno::Sequence<sal_Int8>(); +} + +void SAL_CALL View::alterCommand(const OUString& _rNewCommand) +{ + OUString aCommand = "ALTER VIEW \"" + m_Name + "\" AS " + _rNewCommand; + m_xMetaData->getConnection()->createStatement()->execute(aCommand); +} + +void SAL_CALL View::getFastPropertyValue(css::uno::Any& _rValue, sal_Int32 _nHandle) const +{ + if (_nHandle == PROPERTY_ID_COMMAND) + { + // retrieve the very current command, don't rely on the base classes cached value + // (which we initialized empty, anyway) + _rValue <<= impl_getCommand(); + return; + } + + View_Base::getFastPropertyValue(_rValue, _nHandle); +} + +OUString View::impl_getCommand() const +{ + OUString aCommand("SELECT RDB$VIEW_SOURCE FROM RDB$RELATIONS WHERE RDB$RELATION_NAME = '" + + m_Name + "'"); + css::uno::Reference<css::sdbc::XStatement> statement = m_xConnection->createStatement(); + css::uno::Reference<css::sdbc::XResultSet> xResult = statement->executeQuery(aCommand); + + css::uno::Reference<css::sdbc::XRow> xRow(xResult, css::uno::UNO_QUERY_THROW); + if (!xResult->next()) + { + // hmm. There is no view the name as we know it. Can only mean some other instance + // dropped this view meanwhile... + std::abort(); + } + + return xRow->getString(1); +} + +} // namespace connectivity::firebird +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/View.hxx b/connectivity/source/drivers/firebird/View.hxx new file mode 100644 index 000000000000..2b300a8d06d9 --- /dev/null +++ b/connectivity/source/drivers/firebird/View.hxx @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ +#pragma once + +#include <connectivity/sdbcx/VView.hxx> + +#include <com/sun/star/sdbcx/XAlterView.hpp> +#include <com/sun/star/sdbc/XConnection.hpp> + +#include <comphelper/sequence.hxx> +#include <cppuhelper/implbase1.hxx> + +namespace connectivity::firebird +{ +typedef ::connectivity::sdbcx::OView View_Base; +typedef ::cppu::ImplHelper1<css::sdbcx::XAlterView> View_IBASE; + +class View : public View_Base, public View_IBASE +{ +public: + View(const css::uno::Reference<css::sdbc::XConnection>& _rxConnection, bool _bCaseSensitive, + const OUString& _rSchemaName, const OUString& _rName); + + // UNO + virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& aType) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + + virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override; + virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override; + + // XAlterView + virtual void SAL_CALL alterCommand(const OUString& NewCommand) override; + +protected: + virtual ~View() override; + +protected: + // OPropertyContainer + virtual void SAL_CALL getFastPropertyValue(css::uno::Any& _rValue, + sal_Int32 _nHandle) const override; + +private: + /** retrieves the current command of the View */ + OUString impl_getCommand() const; + +private: + css::uno::Reference<css::sdbc::XConnection> m_xConnection; + + using View_Base::getFastPropertyValue; +}; + +} // namespace connectivity::firebird +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Views.cxx b/connectivity/source/drivers/firebird/Views.cxx new file mode 100644 index 000000000000..2e5bec42adc3 --- /dev/null +++ b/connectivity/source/drivers/firebird/Views.cxx @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ +#include "Tables.hxx" +#include "Views.hxx" +#include "View.hxx" +#include "Catalog.hxx" +#include <connectivity/dbtools.hxx> +#include <comphelper/types.hxx> +#include <TConnection.hxx> + +connectivity::firebird::Views::Views( + const css::uno::Reference<css::sdbc::XConnection>& _rxConnection, ::cppu::OWeakObject& _rParent, + ::osl::Mutex& _rMutex, const ::std::vector<OUString>& _rVector) + : sdbcx::OCollection(_rParent, true, _rMutex, _rVector) + , m_xConnection(_rxConnection) + , m_xMetaData(_rxConnection->getMetaData()) + , m_bInDrop(false) +{ +} + +connectivity::sdbcx::ObjectType connectivity::firebird::Views::createObject(const OUString& _rName) +{ + OUString sCatalog, sSchema, sTable; + ::dbtools::qualifiedNameComponents(m_xMetaData, _rName, sCatalog, sSchema, sTable, + ::dbtools::EComposeRule::InDataManipulation); + return new View(m_xConnection, isCaseSensitive(), sSchema, sTable); +} + +void connectivity::firebird::Views::impl_refresh() +{ + static_cast<Catalog&>(m_rParent).refreshViews(); +} + +css::uno::Reference<css::beans::XPropertySet> connectivity::firebird::Views::createDescriptor() +{ + return new connectivity::sdbcx::OView(true, m_xMetaData); +} + +// XAppend +connectivity::sdbcx::ObjectType connectivity::firebird::Views::appendObject( + const OUString& _rForName, const css::uno::Reference<css::beans::XPropertySet>& descriptor) +{ + createView(descriptor); + return createObject(_rForName); +} + +// XDrop +void connectivity::firebird::Views::dropObject(sal_Int32 _nPos, const OUString& /*_sElementName*/) +{ + if (m_bInDrop) + return; + + css::uno::Reference<XInterface> xObject(getObject(_nPos)); + bool bIsNew = connectivity::sdbcx::ODescriptor::isNew(xObject); + if (!bIsNew) + { + OUString aSql("DROP VIEW"); + + css::uno::Reference<css::beans::XPropertySet> xProp(xObject, css::uno::UNO_QUERY); + aSql += ::dbtools::composeTableName(m_xMetaData, xProp, + ::dbtools::EComposeRule::InTableDefinitions, true); + + css::uno::Reference<css::sdbc::XConnection> xConnection = m_xMetaData->getConnection(); + css::uno::Reference<css::sdbc::XStatement> xStmt = xConnection->createStatement(); + xStmt->execute(aSql); + ::comphelper::disposeComponent(xStmt); + } +} + +void connectivity::firebird::Views::dropByNameImpl(const OUString& elementName) +{ + m_bInDrop = true; + connectivity::sdbcx::OCollection::dropByName(elementName); + m_bInDrop = false; +} + +void connectivity::firebird::Views::createView( + const css::uno::Reference<css::beans::XPropertySet>& descriptor) +{ + css::uno::Reference<css::sdbc::XConnection> xConnection = m_xMetaData->getConnection(); + + OUString sCommand; + descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND)) + >>= sCommand; + + OUString aSql = "CREATE VIEW " + + ::dbtools::composeTableName(m_xMetaData, descriptor, + ::dbtools::EComposeRule::InTableDefinitions, true) + + " AS " + sCommand; + + css::uno::Reference<css::sdbc::XStatement> xStmt = xConnection->createStatement(); + if (xStmt.is()) + { + xStmt->execute(aSql); + ::comphelper::disposeComponent(xStmt); + } + connectivity::firebird::Tables* pTables = static_cast<connectivity::firebird::Tables*>( + static_cast<connectivity::firebird::Catalog&>(m_rParent).getPrivateTables()); + if (pTables) + { + OUString sName = ::dbtools::composeTableName( + m_xMetaData, descriptor, ::dbtools::EComposeRule::InDataManipulation, false); + pTables->appendNew(sName); + } +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/firebird/Views.hxx b/connectivity/source/drivers/firebird/Views.hxx new file mode 100644 index 000000000000..6887bdc66ed0 --- /dev/null +++ b/connectivity/source/drivers/firebird/Views.hxx @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ +#pragma once + +#include <connectivity/sdbcx/VCollection.hxx> +#include <com/sun/star/sdbc/XDatabaseMetaData.hpp> +namespace connectivity::firebird +{ +class Views final : public connectivity::sdbcx::OCollection +{ + css::uno::Reference<css::sdbc::XConnection> m_xConnection; + css::uno::Reference<css::sdbc::XDatabaseMetaData> m_xMetaData; + bool m_bInDrop; + + // OCollection + virtual connectivity::sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference<css::beans::XPropertySet> createDescriptor() override; + virtual sdbcx::ObjectType + appendObject(const OUString& _rForName, + const css::uno::Reference<css::beans::XPropertySet>& descriptor) override; + + void createView(const css::uno::Reference<css::beans::XPropertySet>& descriptor); + +public: + Views(const css::uno::Reference<css::sdbc::XConnection>& _rxConnection, + ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, + const ::std::vector<OUString>& _rVector); + + // XDrop + virtual void dropObject(sal_Int32 _nPos, const OUString& _sElementName) override; + + void dropByNameImpl(const OUString& elementName); +}; +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/flat/ECatalog.cxx b/connectivity/source/drivers/flat/ECatalog.cxx index b656b29c21b8..72b470235a01 100644 --- a/connectivity/source/drivers/flat/ECatalog.cxx +++ b/connectivity/source/drivers/flat/ECatalog.cxx @@ -25,36 +25,33 @@ #include <com/sun/star/sdbc/XResultSet.hpp> using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; - using namespace connectivity::flat; -OFlatCatalog::OFlatCatalog(OFlatConnection* _pCon) : file::OFileCatalog(_pCon) +OFlatCatalog::OFlatCatalog(OFlatConnection* _pCon) + : file::OFileCatalog(_pCon) { } void OFlatCatalog::refreshTables() { - ::std::vector< OUString> aVector; - Sequence< OUString > aTypes; - Reference< XResultSet > xResult = m_xMetaData->getTables(Any(), - "%", "%", aTypes); + ::std::vector<OUString> aVector; + Sequence<OUString> aTypes; + Reference<XResultSet> xResult = m_xMetaData->getTables(Any(), "%", "%", aTypes); - if(xResult.is()) + if (xResult.is()) { - Reference< XRow > xRow(xResult,UNO_QUERY); - while(xResult->next()) + Reference<XRow> xRow(xResult, UNO_QUERY); + while (xResult->next()) aVector.push_back(xRow->getString(3)); } - if(m_pTables) + if (m_pTables) m_pTables->reFill(aVector); else - m_pTables.reset( new OFlatTables(m_xMetaData,*this,m_aMutex,aVector) ); + m_pTables.reset(new OFlatTables(m_xMetaData, *this, m_aMutex, aVector)); } - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/flat/EColumns.cxx b/connectivity/source/drivers/flat/EColumns.cxx index a9e210321ba6..56585f1e8059 100644 --- a/connectivity/source/drivers/flat/EColumns.cxx +++ b/connectivity/source/drivers/flat/EColumns.cxx @@ -23,10 +23,6 @@ using namespace connectivity::flat; using namespace connectivity; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdbcx; -using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; sdbcx::ObjectType OFlatColumns::createObject(const OUString& _rName) diff --git a/connectivity/source/drivers/flat/EConnection.cxx b/connectivity/source/drivers/flat/EConnection.cxx index 5127d903cc6d..a65470caaad9 100644 --- a/connectivity/source/drivers/flat/EConnection.cxx +++ b/connectivity/source/drivers/flat/EConnection.cxx @@ -36,7 +36,6 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::lang; OFlatConnection::OFlatConnection(ODriver* _pDriver) : OConnection(_pDriver) @@ -136,8 +135,7 @@ css::uno::Reference< XTablesSupplier > OFlatConnection::createCatalog() Reference< XTablesSupplier > xTab = m_xCatalog; if(!xTab.is()) { - OFlatCatalog *pCat = new OFlatCatalog(this); - xTab = pCat; + xTab = new OFlatCatalog(this); m_xCatalog = xTab; } return xTab; @@ -148,11 +146,9 @@ Reference< XStatement > SAL_CALL OFlatConnection::createStatement( ) ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OConnection_B::rBHelper.bDisposed); - OFlatStatement* pStmt = new OFlatStatement(this); - - Reference< XStatement > xStmt = pStmt; + rtl::Reference<OFlatStatement> pStmt = new OFlatStatement(this); m_aStatements.push_back(WeakReferenceHelper(*pStmt)); - return xStmt; + return pStmt; } Reference< XPreparedStatement > SAL_CALL OFlatConnection::prepareStatement( const OUString& sql ) @@ -160,13 +156,10 @@ Reference< XPreparedStatement > SAL_CALL OFlatConnection::prepareStatement( cons ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OConnection_B::rBHelper.bDisposed); - - OFlatPreparedStatement* pStmt = new OFlatPreparedStatement(this); - Reference< XPreparedStatement > xStmt = pStmt; + rtl::Reference<OFlatPreparedStatement> pStmt = new OFlatPreparedStatement(this); pStmt->construct(sql); - m_aStatements.push_back(WeakReferenceHelper(*pStmt)); - return xStmt; + return pStmt; } Reference< XPreparedStatement > SAL_CALL OFlatConnection::prepareCall( const OUString& /*sql*/ ) diff --git a/connectivity/source/drivers/flat/EDatabaseMetaData.cxx b/connectivity/source/drivers/flat/EDatabaseMetaData.cxx index b69b34e363c3..729b55ef9e2d 100644 --- a/connectivity/source/drivers/flat/EDatabaseMetaData.cxx +++ b/connectivity/source/drivers/flat/EDatabaseMetaData.cxx @@ -47,35 +47,33 @@ OFlatDatabaseMetaData::~OFlatDatabaseMetaData() Reference< XResultSet > OFlatDatabaseMetaData::impl_getTypeInfo_throw( ) { - ::osl::MutexGuard aGuard( m_aMutex ); - - ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo); - Reference< XResultSet > xRef = pResult; + rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo); - static ODatabaseMetaDataResultSet::ORows aRows = [&]() + static ODatabaseMetaDataResultSet::ORows aRows = []() { ODatabaseMetaDataResultSet::ORows tmp; - ODatabaseMetaDataResultSet::ORow aRow; - - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(new ORowSetValueDecorator(OUString("CHAR"))); - aRow.push_back(new ORowSetValueDecorator(DataType::CHAR)); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(254))); - aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue()); - aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(ColumnValue::NULLABLE))); - aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(ColumnSearch::CHAR))); - aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(10))); + ODatabaseMetaDataResultSet::ORow aRow + { + ODatabaseMetaDataResultSet::getEmptyValue() , + new ORowSetValueDecorator(OUString("CHAR")) , + new ORowSetValueDecorator(DataType::CHAR) , + new ORowSetValueDecorator(sal_Int32(254)) , + ODatabaseMetaDataResultSet::getQuoteValue() , + ODatabaseMetaDataResultSet::getQuoteValue() , + ODatabaseMetaDataResultSet::getEmptyValue() , + new ORowSetValueDecorator(sal_Int32(ColumnValue::NULLABLE)) , + ODatabaseMetaDataResultSet::get1Value() , + new ORowSetValueDecorator(sal_Int32(ColumnSearch::CHAR)) , + ODatabaseMetaDataResultSet::get1Value() , + ODatabaseMetaDataResultSet::get0Value() , + ODatabaseMetaDataResultSet::get0Value() , + ODatabaseMetaDataResultSet::getEmptyValue() , + ODatabaseMetaDataResultSet::get0Value() , + ODatabaseMetaDataResultSet::get0Value() , + ODatabaseMetaDataResultSet::getEmptyValue() , + ODatabaseMetaDataResultSet::getEmptyValue() , + new ORowSetValueDecorator(sal_Int32(10)) + }; tmp.push_back(aRow); @@ -141,8 +139,8 @@ Reference< XResultSet > OFlatDatabaseMetaData::impl_getTypeInfo_throw( ) return tmp; }(); - pResult->setRows(aRows); - return xRef; + pResult->setRows(std::move(aRows)); + return pResult; } Reference< XResultSet > SAL_CALL OFlatDatabaseMetaData::getColumns( @@ -198,7 +196,7 @@ Reference< XResultSet > SAL_CALL OFlatDatabaseMetaData::getColumns( aRow[11] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)))); aRow[13] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)))); - switch(static_cast<sal_Int32>(aRow[5]->getValue())) + switch(aRow[5]->getValue().getInt32()) { case DataType::CHAR: case DataType::VARCHAR: @@ -211,7 +209,7 @@ Reference< XResultSet > SAL_CALL OFlatDatabaseMetaData::getColumns( aRow[16] = new ORowSetValueDecorator(sal_Int32(0)); } aRow[17] = new ORowSetValueDecorator(i); - switch(sal_Int32(aRow[11]->getValue())) + switch(aRow[11]->getValue().getInt32()) { case ColumnValue::NO_NULLS: aRow[18] = new ORowSetValueDecorator(OUString("NO")); @@ -228,11 +226,10 @@ Reference< XResultSet > SAL_CALL OFlatDatabaseMetaData::getColumns( } } - ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns); - Reference< XResultSet > xRef = pResult; - pResult->setRows(aRows); + rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns); + pResult->setRows(std::move(aRows)); - return xRef; + return pResult; } OUString SAL_CALL OFlatDatabaseMetaData::getURL( ) diff --git a/connectivity/source/drivers/flat/EDriver.cxx b/connectivity/source/drivers/flat/EDriver.cxx index 0e1767870859..034e1b0b97f4 100644 --- a/connectivity/source/drivers/flat/EDriver.cxx +++ b/connectivity/source/drivers/flat/EDriver.cxx @@ -24,7 +24,6 @@ #include <comphelper/sequence.hxx> #include <strings.hrc> #include <resource/sharedresources.hxx> -#include <comphelper/processfactory.hxx> using namespace connectivity::flat; @@ -55,7 +54,7 @@ connectivity_flat_ODriver( } if (ret) ret->acquire(); - return static_cast<cppu::OWeakObject*>(ret.get()); + return getXWeak(ret.get()); } Reference< XConnection > SAL_CALL ODriver::connect( const OUString& url, const Sequence< PropertyValue >& info ) @@ -67,12 +66,11 @@ Reference< XConnection > SAL_CALL ODriver::connect( const OUString& url, const S if ( ! acceptsURL(url) ) return nullptr; - OFlatConnection* pCon = new OFlatConnection(this); + rtl::Reference<OFlatConnection> pCon = new OFlatConnection(this); pCon->construct(url,info); - Reference< XConnection > xCon = pCon; - m_xConnections.push_back(WeakReferenceHelper(*pCon)); + m_xConnections.emplace_back(*pCon); - return xCon; + return pCon; } sal_Bool SAL_CALL ODriver::acceptsURL( const OUString& url ) @@ -84,47 +82,46 @@ Sequence< DriverPropertyInfo > SAL_CALL ODriver::getPropertyInfo( const OUString { if ( acceptsURL(url) ) { - std::vector< DriverPropertyInfo > aDriverInfo; + Sequence< OUString > aBoolean { "0", "1" }; - Sequence< OUString > aBoolean(2); - aBoolean[0] = "0"; - aBoolean[1] = "1"; - - aDriverInfo.push_back(DriverPropertyInfo( + std::vector< DriverPropertyInfo > aDriverInfo + { + { "FieldDelimiter" ,"Field separator." ,false - ,OUString() - ,Sequence< OUString >()) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,{} + ,{} + }, + { "HeaderLine" ,"Text contains headers." ,false ,"0" - ,aBoolean) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,aBoolean + }, + { "StringDelimiter" ,"Text separator." ,false ,"0" - ,aBoolean) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,aBoolean + }, + { "DecimalDelimiter" ,"Decimal separator." ,false ,"0" - ,aBoolean) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,aBoolean + }, + { "ThousandDelimiter" ,"Thousands separator." ,false ,"0" - ,aBoolean) - ); + ,aBoolean + } + }; return ::comphelper::concatSequences(OFileDriver::getPropertyInfo(url,info ), Sequence< DriverPropertyInfo >(aDriverInfo.data(),aDriverInfo.size())); } diff --git a/connectivity/source/drivers/flat/EPreparedStatement.cxx b/connectivity/source/drivers/flat/EPreparedStatement.cxx index 64a0b3a1c3bb..0ed4299258a2 100644 --- a/connectivity/source/drivers/flat/EPreparedStatement.cxx +++ b/connectivity/source/drivers/flat/EPreparedStatement.cxx @@ -17,19 +17,18 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - #include <flat/EPreparedStatement.hxx> #include <flat/EResultSet.hxx> using namespace connectivity::flat; using namespace connectivity::file; -using namespace ::com::sun::star::uno; -OResultSet* OFlatPreparedStatement::createResultSet() +rtl::Reference<OResultSet> OFlatPreparedStatement::createResultSet() { - return new OFlatResultSet(this,m_aSQLIterator); + return new OFlatResultSet(this, m_aSQLIterator); } -IMPLEMENT_SERVICE_INFO(OFlatPreparedStatement,"com.sun.star.sdbc.driver.flat.PreparedStatement","com.sun.star.sdbc.PreparedStatement"); +IMPLEMENT_SERVICE_INFO(OFlatPreparedStatement, "com.sun.star.sdbc.driver.flat.PreparedStatement", + "com.sun.star.sdbc.PreparedStatement"); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/flat/EResultSet.cxx b/connectivity/source/drivers/flat/EResultSet.cxx index aca803041827..9d1975c77e45 100644 --- a/connectivity/source/drivers/flat/EResultSet.cxx +++ b/connectivity/source/drivers/flat/EResultSet.cxx @@ -96,7 +96,7 @@ Any SAL_CALL OFlatResultSet::getBookmark( ) ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - return makeAny(static_cast<sal_Int32>((*m_aRow)[0]->getValue())); + return Any((*m_aRow)[0]->getValue().getInt32()); } sal_Bool SAL_CALL OFlatResultSet::moveToBookmark( const Any& bookmark ) @@ -150,12 +150,12 @@ IPropertyArrayHelper & OFlatResultSet::getInfoHelper() return *OFlatResultSet_BASE3::getArrayHelper(); } -void SAL_CALL OFlatResultSet::acquire() throw() +void SAL_CALL OFlatResultSet::acquire() noexcept { OFlatResultSet_BASE2::acquire(); } -void SAL_CALL OFlatResultSet::release() throw() +void SAL_CALL OFlatResultSet::release() noexcept { OFlatResultSet_BASE2::release(); } diff --git a/connectivity/source/drivers/flat/EStatement.cxx b/connectivity/source/drivers/flat/EStatement.cxx index 7774639052b3..df9fca5f58f2 100644 --- a/connectivity/source/drivers/flat/EStatement.cxx +++ b/connectivity/source/drivers/flat/EStatement.cxx @@ -22,9 +22,8 @@ using namespace connectivity::flat; using namespace connectivity::file; -using namespace css::uno; -OResultSet* OFlatStatement::createResultSet() +rtl::Reference<OResultSet> OFlatStatement::createResultSet() { return new OFlatResultSet(this,m_aSQLIterator); } diff --git a/connectivity/source/drivers/flat/ETable.cxx b/connectivity/source/drivers/flat/ETable.cxx index 0dceba05b641..9cab6b13da5a 100644 --- a/connectivity/source/drivers/flat/ETable.cxx +++ b/connectivity/source/drivers/flat/ETable.cxx @@ -27,10 +27,8 @@ #include <o3tl/safeint.hxx> #include <rtl/math.hxx> #include <sal/log.hxx> -#include <tools/solar.h> #include <tools/urlobj.hxx> #include <cppuhelper/queryinterface.hxx> -#include <cppuhelper/typeprovider.hxx> #include <comphelper/numbers.hxx> #include <comphelper/servicehelper.hxx> #include <com/sun/star/util/NumberFormat.hpp> @@ -65,6 +63,8 @@ void OFlatTable::fillColumns(const css::lang::Locale& _aLocale) { m_bNeedToReadLine = true; // we overwrite m_aCurrentLine, seek the stream, ... m_pFileStream->Seek(0); + // tdf#123055 - start to read unicode text in order to avoid the BOM + m_pFileStream->StartReadingUnicodeText(RTL_TEXTENCODING_DONTKNOW); m_aCurrentLine = QuotedTokenizedString(); bool bRead = true; @@ -72,7 +72,8 @@ void OFlatTable::fillColumns(const css::lang::Locale& _aLocale) const bool bHasHeaderLine = pConnection->isHeaderLine(); QuotedTokenizedString aHeaderLine; - TRowPositionInFile rowPos(0, 0); + const sal_Int32 nPos = static_cast<sal_Int32>(m_pFileStream->Tell()); + TRowPositionInFile rowPos(nPos, nPos); sal_Int32 rowNum(0); if ( bHasHeaderLine ) { @@ -176,7 +177,7 @@ void OFlatTable::fillColumns(const css::lang::Locale& _aLocale) aFind = connectivity::find(m_aColumns->begin(),m_aColumns->end(),aAlias,aCase); } - sdbcx::OColumn* pColumn = new sdbcx::OColumn(aAlias,aTypeNames[i],OUString(),OUString(), + rtl::Reference<sdbcx::OColumn> pColumn = new sdbcx::OColumn(aAlias,aTypeNames[i],OUString(),OUString(), ColumnValue::NULLABLE, m_aPrecisions[i], m_aScales[i], @@ -186,8 +187,7 @@ void OFlatTable::fillColumns(const css::lang::Locale& _aLocale) false, bCase, m_CatalogName, getSchema(), getName()); - Reference< XPropertySet> xCol = pColumn; - m_aColumns->push_back(xCol); + m_aColumns->push_back(pColumn); } m_pFileStream->Seek(m_aRowPosToFilePos[0].second); @@ -200,7 +200,7 @@ void OFlatTable::impl_fillColumnInfo_nothrow(QuotedTokenizedString const & aFirs if ( io_nType != DataType::VARCHAR ) { bool bNumeric = io_nType == DataType::SQLNULL || io_nType == DataType::DOUBLE || io_nType == DataType::DECIMAL || io_nType == DataType::INTEGER; - sal_uLong nIndex = 0; + sal_Int32 nIndex = 0; if ( bNumeric ) { @@ -265,8 +265,8 @@ void OFlatTable::impl_fillColumnInfo_nothrow(QuotedTokenizedString const & aFirs if (bNumeric && cThousandDelimiter) { // Is the delimiter correct? - const OUString aValue = aField2.getToken(0,cDecimalDelimiter); - for( sal_Int32 j = aValue.getLength() - 4; j >= 0; j -= 4) + const std::u16string_view aValue = o3tl::getToken(aField2, 0, cDecimalDelimiter); + for( sal_Int32 j = static_cast<sal_Int32>(aValue.size()) - 4; j >= 0; j -= 4) { const sal_Unicode c = aValue[j]; // just digits, decimal- and thousands-delimiter? @@ -471,7 +471,7 @@ OUString OFlatTable::getEntry() const if ( m_pConnection->matchesExtension( sExt ) ) { if ( !sExt.isEmpty() ) - sName = sName.replaceAt(sName.getLength() - (sExt.getLength() + 1), sExt.getLength()+1, OUString()); + sName = sName.replaceAt(sName.getLength() - (sExt.getLength() + 1), sExt.getLength()+1, u""); if ( sName == m_Name ) { Reference< XContentAccess > xContentAccess( xDir, UNO_QUERY ); @@ -502,7 +502,7 @@ void OFlatTable::refreshColumns() if(m_xColumns) m_xColumns->reFill(aVector); else - m_xColumns = new OFlatColumns(this,m_aMutex,aVector); + m_xColumns.reset(new OFlatColumns(this,m_aMutex,aVector)); } @@ -545,26 +545,10 @@ Any SAL_CALL OFlatTable::queryInterface( const Type & rType ) return Any(); Any aRet = OTable_TYPEDEF::queryInterface(rType); - return aRet.hasValue() ? aRet : ::cppu::queryInterface(rType,static_cast< css::lang::XUnoTunnel*> (this)); + return aRet; } -Sequence< sal_Int8 > OFlatTable::getUnoTunnelId() -{ - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); -} - -// css::lang::XUnoTunnel - -sal_Int64 OFlatTable::getSomething( const Sequence< sal_Int8 > & rId ) -{ - return (isUnoTunnelId<OFlatTable>(rId)) - ? reinterpret_cast< sal_Int64 >( this ) - : OFlatTable_BASE::getSomething(rId); -} - bool OFlatTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns & _rCols, bool bRetrieveData) { *(*_rRow)[0] = m_nFilePos; @@ -676,7 +660,7 @@ bool OFlatTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns & _rCols, bool // #99178# OJ if ( DataType::DECIMAL == nType || DataType::NUMERIC == nType ) - *(*_rRow)[i] = OUString(OUString::number(nVal)); + *(*_rRow)[i] = OUString::number(nVal); else *(*_rRow)[i] = nVal; } break; @@ -784,7 +768,6 @@ bool OFlatTable::seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32 n } // m_nMaxRowCount can still be zero, but now it means there a genuinely zero rows in the table return seekRow(IResultSetHelper::ABSOLUTE1, m_nMaxRowCount, nCurPos); - break; case IResultSetHelper::RELATIVE1: { const sal_Int32 nNewRowPos = m_nRowPos + nOffset; diff --git a/connectivity/source/drivers/flat/ETables.cxx b/connectivity/source/drivers/flat/ETables.cxx index 81f366a9e7d0..3b0d039311fc 100644 --- a/connectivity/source/drivers/flat/ETables.cxx +++ b/connectivity/source/drivers/flat/ETables.cxx @@ -22,23 +22,15 @@ #include <file/FCatalog.hxx> using namespace connectivity; -using namespace ::comphelper; using namespace connectivity::flat; using namespace connectivity::file; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdbcx; -using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::container; sdbcx::ObjectType OFlatTables::createObject(const OUString& _rName) { - OFlatTable* pRet = new OFlatTable(this, static_cast<OFlatConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()), + rtl::Reference<OFlatTable> pRet = new OFlatTable(this, static_cast<OFlatConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()), _rName,"TABLE"); - sdbcx::ObjectType xRet = pRet; pRet->construct(); - return xRet; + return pRet; } diff --git a/connectivity/source/drivers/hsqldb/HCatalog.cxx b/connectivity/source/drivers/hsqldb/HCatalog.cxx index 029e60f9450a..c51c9d15a520 100644 --- a/connectivity/source/drivers/hsqldb/HCatalog.cxx +++ b/connectivity/source/drivers/hsqldb/HCatalog.cxx @@ -30,11 +30,8 @@ using namespace connectivity; using namespace connectivity::hsqldb; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; OHCatalog::OHCatalog(const Reference< XConnection >& _xConnection) : sdbcx::OCatalog(_xConnection) ,m_xConnection(_xConnection) @@ -54,9 +51,7 @@ void OHCatalog::refreshTables() { ::std::vector< OUString> aVector; - Sequence< OUString > sTableTypes(2); - sTableTypes[0] = "VIEW"; - sTableTypes[1] = "TABLE"; + Sequence< OUString > sTableTypes {"VIEW", "TABLE"}; refreshObjects(sTableTypes,aVector); diff --git a/connectivity/source/drivers/hsqldb/HColumns.cxx b/connectivity/source/drivers/hsqldb/HColumns.cxx index 3f03c3616bc1..e37f9fbd3a5e 100644 --- a/connectivity/source/drivers/hsqldb/HColumns.cxx +++ b/connectivity/source/drivers/hsqldb/HColumns.cxx @@ -27,10 +27,6 @@ using namespace connectivity::sdbcx; using namespace connectivity; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdbcx; -using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; OHSQLColumns::OHSQLColumns( ::cppu::OWeakObject& _rParent ,::osl::Mutex& _rMutex diff --git a/connectivity/source/drivers/hsqldb/HConnection.cxx b/connectivity/source/drivers/hsqldb/HConnection.cxx index c3ff0169cea7..28feb95fce9b 100644 --- a/connectivity/source/drivers/hsqldb/HConnection.cxx +++ b/connectivity/source/drivers/hsqldb/HConnection.cxx @@ -32,10 +32,11 @@ #include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/sdbc/XDatabaseMetaData2.hpp> +#include <comphelper/propertyvalue.hxx> #include <cppuhelper/exc_hlp.hxx> #include <rtl/ustrbuf.hxx> #include <sal/log.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <resource/sharedresources.hxx> #include <strings.hrc> @@ -280,8 +281,7 @@ namespace connectivity::hsqldb ::dbtools::qualifiedNameComponents( xMetaData, _rTableName, sCatalog, sSchema, sName, ::dbtools::EComposeRule::Complete ); // get the table information - OUStringBuffer sSQL; - sSQL.append( "SELECT HSQLDB_TYPE FROM INFORMATION_SCHEMA.SYSTEM_TABLES" ); + OUStringBuffer sSQL( "SELECT HSQLDB_TYPE FROM INFORMATION_SCHEMA.SYSTEM_TABLES" ); HTools::appendTableFilterCrit( sSQL, sCatalog, sSchema, sName, true ); sSQL.append( " AND TABLE_TYPE = 'TABLE'" ); @@ -315,13 +315,12 @@ namespace connectivity::hsqldb xProvider.set( GraphicProvider::create(m_xContext) ); // ask the provider to obtain a graphic - Sequence< PropertyValue > aMediaProperties( 1 ); - aMediaProperties[0].Name = "URL"; - aMediaProperties[0].Value <<= OUString( - // load the graphic from the global graphic repository - "private:graphicrepository/" - // the relative path within the images.zip - LINKED_TEXT_TABLE_IMAGE_RESOURCE); + Sequence< PropertyValue > aMediaProperties{ comphelper::makePropertyValue( + "URL", OUString( + // load the graphic from the global graphic repository + "private:graphicrepository/" + // the relative path within the images.zip + LINKED_TEXT_TABLE_IMAGE_RESOURCE)) }; xGraphic = xProvider->queryGraphic( aMediaProperties ); OSL_ENSURE( xGraphic.is(), "OHsqlConnection::impl_getTextTableIcon_nothrow: the provider did not give us a graphic object!" ); } 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( "\"" ); diff --git a/connectivity/source/drivers/hsqldb/HStorageAccess.cxx b/connectivity/source/drivers/hsqldb/HStorageAccess.cxx index 7bb868d2ff1a..8d15d487372a 100644 --- a/connectivity/source/drivers/hsqldb/HStorageAccess.cxx +++ b/connectivity/source/drivers/hsqldb/HStorageAccess.cxx @@ -22,14 +22,14 @@ #include <hsqldb/HStorageMap.hxx> #include "accesslog.hxx" #include <osl/diagnose.h> +#include <comphelper/diagnose_ex.hxx> #include <string.h> -using namespace ::com::sun::star::container; +#include <algorithm> + using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::embed; using namespace ::com::sun::star::io; -using namespace ::com::sun::star::lang; using namespace ::connectivity::hsqldb; #define ThrowException(env, type, msg) { \ @@ -76,7 +76,7 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Nativ } catch(const Exception&) { - OSL_FAIL( "NativeStorageAccess::close: caught an exception while flushing!" ); + TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "NativeStorageAccess::close: caught an exception while flushing!" ); } #ifdef HSQLDB_DBG { @@ -145,28 +145,28 @@ jint read_from_storage_stream( JNIEnv * env, jstring name, jstring key ) std::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(env,name,key); Reference< XInputStream> xIn = pHelper ? pHelper->getInputStream() : Reference< XInputStream>(); OSL_ENSURE(xIn.is(),"Input stream is NULL!"); - if ( xIn.is() ) + if ( !xIn.is() ) + return -1; + + Sequence< ::sal_Int8 > aData(1); + sal_Int32 nBytesRead = -1; + try { - Sequence< ::sal_Int8 > aData(1); - sal_Int32 nBytesRead = -1; - try - { - nBytesRead = xIn->readBytes(aData,1); - } - catch(const Exception& e) - { - StorageContainer::throwJavaException(e,env); - return -1; + nBytesRead = xIn->readBytes(aData,1); + } + catch(const Exception& e) + { + StorageContainer::throwJavaException(e,env); + return -1; - } - if (nBytesRead <= 0) - { - return -1; - } - else - { - return static_cast<unsigned char>(aData[0]); - } + } + if (nBytesRead <= 0) + { + return -1; + } + else + { + return static_cast<unsigned char>(aData[0]); } return -1; } @@ -228,7 +228,7 @@ jint read_from_storage_stream_into_buffer( JNIEnv * env, jstring name, jstring k if (nBytesRead <= 0) return -1; - env->SetByteArrayRegion(buffer,off,nBytesRead,reinterpret_cast<jbyte*>(&aData[0])); + env->SetByteArrayRegion(buffer,off,nBytesRead,reinterpret_cast<const jbyte*>(&aData[0])); return nBytesRead; } @@ -298,10 +298,8 @@ extern "C" SAL_JNI_EXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Nativ } Sequence< sal_Int32 > ch(4); - for(sal_Int32 i = 0;i < 4; ++i) - { - ch[i] = static_cast<unsigned char>(aData[i]); - } + std::transform(aData.begin(), aData.end(), ch.getArray(), + [](auto c) { return static_cast<unsigned char>(c); }); if ((ch[0] | ch[1] | ch[2] | ch[3]) < 0) { @@ -340,10 +338,15 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Nativ #endif std::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(env,name,key); - Reference< XSeekable> xSeek = pHelper ? pHelper->getSeek() : Reference< XSeekable>(); - OSL_ENSURE(xSeek.is(),"No Seekable stream!"); - if ( !xSeek.is() ) + OSL_ENSURE(pHelper, "No StreamHelper!"); + if (!pHelper) + return; + + Reference< XSeekable> xSeek = pHelper->getSeek(); + + OSL_ENSURE(xSeek.is(), "No Seekable stream!"); + if (!xSeek) return; #ifdef HSQLDB_DBG @@ -426,7 +429,7 @@ void write_to_storage_stream_from_buffer( JNIEnv* env, jstring name, jstring key } catch(const Exception& e) { - OSL_FAIL("Exception caught! : write [BII)V"); + TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "Exception caught! : write [BII)V"); StorageContainer::throwJavaException(e,env); } } @@ -462,11 +465,13 @@ void write_to_storage_stream( JNIEnv* env, jstring name, jstring key, jint v ) { if ( xOut.is() ) { - Sequence< ::sal_Int8 > oneByte(4); - oneByte[0] = static_cast<sal_Int8>((v >> 24) & 0xFF); - oneByte[1] = static_cast<sal_Int8>((v >> 16) & 0xFF); - oneByte[2] = static_cast<sal_Int8>((v >> 8) & 0xFF); - oneByte[3] = static_cast<sal_Int8>((v >> 0) & 0xFF); + Sequence< ::sal_Int8 > oneByte + { + static_cast<sal_Int8>((v >> 24) & 0xFF), + static_cast<sal_Int8>((v >> 16) & 0xFF), + static_cast<sal_Int8>((v >> 8) & 0xFF), + static_cast<sal_Int8>((v >> 0) & 0xFF) + }; xOut->writeBytes(oneByte); } @@ -479,7 +484,7 @@ void write_to_storage_stream( JNIEnv* env, jstring name, jstring key, jint v ) } catch(const Exception& e) { - OSL_FAIL("Exception caught! : writeBytes(aData);"); + TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "writeBytes(aData);"); StorageContainer::throwJavaException(e,env); } } diff --git a/connectivity/source/drivers/hsqldb/HStorageMap.cxx b/connectivity/source/drivers/hsqldb/HStorageMap.cxx index d10ee29a69f6..01a9c3d34be3 100644 --- a/connectivity/source/drivers/hsqldb/HStorageMap.cxx +++ b/connectivity/source/drivers/hsqldb/HStorageMap.cxx @@ -27,6 +27,7 @@ #include <sal/log.hxx> #include <uno/mapping.hxx> #include <algorithm> +#include <comphelper/diagnose_ex.hxx> namespace connectivity::hsqldb { @@ -72,7 +73,7 @@ namespace connectivity::hsqldb } catch(const Exception&) { - OSL_FAIL("Exception caught!"); + TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", ""); } } @@ -131,9 +132,9 @@ namespace connectivity::hsqldb return OUString::number(s_nCount++); } - OUString StorageContainer::removeURLPrefix(const OUString& _sURL,const OUString& _sFileURL) + OUString StorageContainer::removeURLPrefix(std::u16string_view _sURL, std::u16string_view _sFileURL) { - return _sURL.copy(_sFileURL.getLength()+1); + return OUString(_sURL.substr(_sFileURL.size()+1)); } OUString StorageContainer::removeOldURLPrefix(const OUString& _sURL) @@ -308,7 +309,7 @@ namespace connectivity::hsqldb } catch(const Exception& e) { - SAL_WARN( "connectivity.hsqldb", "[HSQLDB-SDBC] caught an exception while opening a stream\n" + TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "[HSQLDB-SDBC] caught an exception while opening a stream\n" "Name: " << sName << "\nMode: 0x" << ( _nMode < 16 ? "0" : "") << std::hex << _nMode ); diff --git a/connectivity/source/drivers/hsqldb/HTable.cxx b/connectivity/source/drivers/hsqldb/HTable.cxx index f8dee57c510c..63fe36a34a34 100644 --- a/connectivity/source/drivers/hsqldb/HTable.cxx +++ b/connectivity/source/drivers/hsqldb/HTable.cxx @@ -18,7 +18,6 @@ */ #include <hsqldb/HTable.hxx> -#include <cppuhelper/typeprovider.hxx> #include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/sdbcx/Privilege.hpp> #include <comphelper/property.hxx> @@ -30,7 +29,7 @@ #include <hsqldb/HColumns.hxx> #include <TConnection.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> using namespace ::comphelper; @@ -116,21 +115,6 @@ sdbcx::OCollection* OHSQLTable::createIndexes(const ::std::vector< OUString>& _r return new OIndexesHelper(this,m_aMutex,_rNames); } -Sequence< sal_Int8 > OHSQLTable::getUnoTunnelId() -{ - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); -} - -// css::lang::XUnoTunnel - -sal_Int64 OHSQLTable::getSomething( const Sequence< sal_Int8 > & rId ) -{ - return (isUnoTunnelId<OHSQLTable>(rId)) - ? reinterpret_cast< sal_Int64 >( this ) - : OTable_TYPEDEF::getSomething(rId); -} // XAlterTable void SAL_CALL OHSQLTable::alterColumnByName( const OUString& colName, const Reference< XPropertySet >& descriptor ) @@ -260,16 +244,15 @@ void OHSQLTable::alterColumnType(sal_Int32 nNewType,const OUString& _rColName, c (void)_rColName; #endif - OHSQLColumn* pColumn = new OHSQLColumn; - Reference<XPropertySet> xProp = pColumn; - ::comphelper::copyProperties(_xDescriptor,xProp); - xProp->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),makeAny(nNewType)); + rtl::Reference<OHSQLColumn> pColumn = new OHSQLColumn; + ::comphelper::copyProperties(_xDescriptor,pColumn); + pColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),Any(nNewType)); - sSql += ::dbtools::createStandardColumnPart(xProp,getConnection()); + sSql += ::dbtools::createStandardColumnPart(pColumn,getConnection()); executeStatement(sSql); } -void OHSQLTable::alterDefaultValue(const OUString& _sNewDefault,const OUString& _rColName) +void OHSQLTable::alterDefaultValue(std::u16string_view _sNewDefault,const OUString& _rColName) { const OUString sQuote = getMetaData()->getIdentifierQuoteString( ); OUString sSql = getAlterTableColumnPart() + @@ -305,7 +288,7 @@ void OHSQLTable::executeStatement(const OUString& _rStatement ) { OUString sSQL = _rStatement; if(sSQL.endsWith(",")) - sSQL = sSQL.replaceAt(sSQL.getLength()-1, 1, ")"); + sSQL = sSQL.replaceAt(sSQL.getLength()-1, 1, u")"); Reference< XStatement > xStmt = getConnection()->createStatement( ); if ( xStmt.is() ) diff --git a/connectivity/source/drivers/hsqldb/HTables.cxx b/connectivity/source/drivers/hsqldb/HTables.cxx index 787af894b992..002dfbf9a295 100644 --- a/connectivity/source/drivers/hsqldb/HTables.cxx +++ b/connectivity/source/drivers/hsqldb/HTables.cxx @@ -37,7 +37,6 @@ using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; using namespace dbtools; sdbcx::ObjectType OTables::createObject(const OUString& _rName) @@ -45,10 +44,7 @@ sdbcx::ObjectType OTables::createObject(const OUString& _rName) OUString sCatalog,sSchema,sTable; ::dbtools::qualifiedNameComponents(m_xMetaData,_rName,sCatalog,sSchema,sTable,::dbtools::EComposeRule::InDataManipulation); - Sequence< OUString > sTableTypes(3); - sTableTypes[0] = "VIEW"; - sTableTypes[1] = "TABLE"; - sTableTypes[2] = "%"; // just to be sure to include anything else... + Sequence< OUString > sTableTypes {"VIEW", "TABLE", "%"}; // this last one just to be sure to include anything else... Any aCatalog; if ( !sCatalog.isEmpty() ) @@ -66,7 +62,7 @@ sdbcx::ObjectType OTables::createObject(const OUString& _rName) nPrivileges &= ~( Privilege::INSERT | Privilege::UPDATE | Privilege::DELETE | Privilege::CREATE | Privilege::ALTER | Privilege::DROP ); // obtain privileges - OHSQLTable* pRet = new OHSQLTable( this + xRet = new OHSQLTable( this ,static_cast<OHCatalog&>(m_rParent).getConnection() ,sTable ,xRow->getString(4) @@ -74,7 +70,6 @@ sdbcx::ObjectType OTables::createObject(const OUString& _rName) ,sSchema ,sCatalog ,nPrivileges); - xRet = pRet; } ::comphelper::disposeComponent(xResult); } @@ -164,10 +159,10 @@ void OTables::appendNew(const OUString& _rsNewTable) insertElement(_rsNewTable,nullptr); // notify our container listeners - ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(_rsNewTable), Any(), Any()); - OInterfaceIteratorHelper2 aListenerLoop(m_aContainerListeners); + ContainerEvent aEvent(static_cast<XContainer*>(this), Any(_rsNewTable), Any(), Any()); + OInterfaceIteratorHelper3 aListenerLoop(m_aContainerListeners); while (aListenerLoop.hasMoreElements()) - static_cast<XContainerListener*>(aListenerLoop.next())->elementInserted(aEvent); + aListenerLoop.next()->elementInserted(aEvent); } OUString OTables::getNameForObject(const sdbcx::ObjectType& _xObject) diff --git a/connectivity/source/drivers/hsqldb/HTerminateListener.cxx b/connectivity/source/drivers/hsqldb/HTerminateListener.cxx index df325efb75e8..7c6b494488db 100644 --- a/connectivity/source/drivers/hsqldb/HTerminateListener.cxx +++ b/connectivity/source/drivers/hsqldb/HTerminateListener.cxx @@ -17,36 +17,28 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - #include "HTerminateListener.hxx" #include <hsqldb/HDriver.hxx> - namespace connectivity { - - using namespace hsqldb; - using namespace ::com::sun::star::uno; - using namespace ::com::sun::star::lang; +using namespace hsqldb; +using namespace ::com::sun::star::lang; // XEventListener -void SAL_CALL OConnectionController::disposing( const EventObject& /*Source*/ ) -{ -} +void SAL_CALL OConnectionController::disposing(const EventObject& /*Source*/) {} // XTerminateListener -void SAL_CALL OConnectionController::queryTermination( const EventObject& /*aEvent*/ ) +void SAL_CALL OConnectionController::queryTermination(const EventObject& /*aEvent*/) { m_pDriver->flushConnections(); } -void SAL_CALL OConnectionController::notifyTermination( const EventObject& /*aEvent*/ ) +void SAL_CALL OConnectionController::notifyTermination(const EventObject& /*aEvent*/) { m_pDriver->shutdownConnections(); } - -} // namespace connectivity - +} // namespace connectivity /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/hsqldb/HTerminateListener.hxx b/connectivity/source/drivers/hsqldb/HTerminateListener.hxx index 62e8ec79d660..baf66e90eb1e 100644 --- a/connectivity/source/drivers/hsqldb/HTerminateListener.hxx +++ b/connectivity/source/drivers/hsqldb/HTerminateListener.hxx @@ -16,18 +16,13 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_HTERMINATELISTENER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_HTERMINATELISTENER_HXX +#pragma once #include <cppuhelper/implbase.hxx> #include <com/sun/star/frame/XTerminateListener.hpp> -namespace connectivity -{ - - - namespace hsqldb +namespace connectivity::hsqldb { class ODriverDelegator; class OConnectionController : public ::cppu::WeakImplHelper< css::frame::XTerminateListener > @@ -45,10 +40,7 @@ namespace connectivity virtual void SAL_CALL queryTermination( const css::lang::EventObject& aEvent ) override; virtual void SAL_CALL notifyTermination( const css::lang::EventObject& aEvent ) override; }; - } - -} // namespace connectivity -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_HTERMINATELISTENER_HXX +} // namespace connectivity::hsqldb /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/hsqldb/HTools.cxx b/connectivity/source/drivers/hsqldb/HTools.cxx index b9854c01ce67..3dd388aceecb 100644 --- a/connectivity/source/drivers/hsqldb/HTools.cxx +++ b/connectivity/source/drivers/hsqldb/HTools.cxx @@ -23,18 +23,18 @@ namespace connectivity::hsqldb { - void HTools::appendTableFilterCrit( OUStringBuffer& _inout_rBuffer, const OUString& _rCatalog, - const OUString& _rSchema, const OUString& _rName, bool _bShortForm ) + void HTools::appendTableFilterCrit( OUStringBuffer& _inout_rBuffer, std::u16string_view _rCatalog, + std::u16string_view _rSchema, std::u16string_view _rName, bool _bShortForm ) { _inout_rBuffer.append( " WHERE " ); - if ( !_rCatalog.isEmpty() ) + if ( !_rCatalog.empty() ) { _inout_rBuffer.appendAscii( _bShortForm ? "TABLE_CAT" : "TABLE_CATALOG" ); _inout_rBuffer.append( " = '" ); _inout_rBuffer.append ( _rCatalog ); _inout_rBuffer.append( "' AND " ); } - if ( !_rSchema.isEmpty() ) + if ( !_rSchema.empty() ) { _inout_rBuffer.appendAscii( _bShortForm ? "TABLE_SCHEM" : "TABLE_SCHEMA" ); _inout_rBuffer.append( " = '" ); diff --git a/connectivity/source/drivers/hsqldb/HUser.cxx b/connectivity/source/drivers/hsqldb/HUser.cxx index 2ed0c06262ff..f493e282a2b1 100644 --- a/connectivity/source/drivers/hsqldb/HUser.cxx +++ b/connectivity/source/drivers/hsqldb/HUser.cxx @@ -27,6 +27,7 @@ #include <com/sun/star/sdbcx/PrivilegeObject.hpp> #include <TConnection.hxx> #include <strings.hrc> +#include <utility> using namespace connectivity; using namespace connectivity::hsqldb; @@ -37,16 +38,16 @@ using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; using namespace ::com::sun::star::lang; -OHSQLUser::OHSQLUser( const css::uno::Reference< css::sdbc::XConnection >& _xConnection) : connectivity::sdbcx::OUser(true) - ,m_xConnection(_xConnection) +OHSQLUser::OHSQLUser( css::uno::Reference< css::sdbc::XConnection > _xConnection) : connectivity::sdbcx::OUser(true) + ,m_xConnection(std::move(_xConnection)) { construct(); } -OHSQLUser::OHSQLUser( const css::uno::Reference< css::sdbc::XConnection >& _xConnection, +OHSQLUser::OHSQLUser( css::uno::Reference< css::sdbc::XConnection > _xConnection, const OUString& Name ) : connectivity::sdbcx::OUser(Name,true) - ,m_xConnection(_xConnection) + ,m_xConnection(std::move(_xConnection)) { construct(); } diff --git a/connectivity/source/drivers/hsqldb/HUsers.cxx b/connectivity/source/drivers/hsqldb/HUsers.cxx index 40d1f5243cb6..07a91e7cbed2 100644 --- a/connectivity/source/drivers/hsqldb/HUsers.cxx +++ b/connectivity/source/drivers/hsqldb/HUsers.cxx @@ -23,6 +23,7 @@ #include <comphelper/types.hxx> #include <connectivity/dbtools.hxx> #include <TConnection.hxx> +#include <utility> using namespace ::comphelper; using namespace connectivity; @@ -30,16 +31,14 @@ using namespace connectivity::hsqldb; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; OUsers::OUsers( ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, const ::std::vector< OUString> &_rVector, - const css::uno::Reference< css::sdbc::XConnection >& _xConnection, + css::uno::Reference< css::sdbc::XConnection > _xConnection, connectivity::sdbcx::IRefreshableUsers* _pParent) : sdbcx::OCollection(_rParent, true, _rMutex, _rVector) - ,m_xConnection(_xConnection) + ,m_xConnection(std::move(_xConnection)) ,m_pParent(_pParent) { } @@ -57,8 +56,7 @@ void OUsers::impl_refresh() Reference< XPropertySet > OUsers::createDescriptor() { - OUserExtend* pNew = new OUserExtend(m_xConnection); - return pNew; + return new OUserExtend(m_xConnection); } // XAppend diff --git a/connectivity/source/drivers/hsqldb/HView.cxx b/connectivity/source/drivers/hsqldb/HView.cxx index 0a09ec0d201b..83946ee86f86 100644 --- a/connectivity/source/drivers/hsqldb/HView.cxx +++ b/connectivity/source/drivers/hsqldb/HView.cxx @@ -31,7 +31,7 @@ #include <com/sun/star/sdbc/SQLException.hpp> #include <cppuhelper/exc_hlp.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <unotools/sharedunocomponent.hxx> @@ -90,12 +90,11 @@ namespace connectivity::hsqldb // create a statement which can be used to re-create the original view, in case // dropping it succeeds, but creating it with a new statement fails - OUStringBuffer aRestoreCommand; - aRestoreCommand.append( "CREATE VIEW " ); - aRestoreCommand.append ( sQualifiedName ); - aRestoreCommand.append( " AS " ); - aRestoreCommand.append ( impl_getCommand_throwSQLException() ); - OUString sRestoreCommand( aRestoreCommand.makeStringAndClear() ); + OUString sRestoreCommand = + "CREATE VIEW " + + sQualifiedName + + " AS " + + impl_getCommand_throwSQLException(); bool bDropSucceeded( false ); try @@ -147,8 +146,8 @@ namespace connectivity::hsqldb OUString HView::impl_getCommand() const { - OUStringBuffer aCommand; - aCommand.append( "SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.SYSTEM_VIEWS " ); + OUStringBuffer aCommand( + "SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.SYSTEM_VIEWS " ); HTools::appendTableFilterCrit( aCommand, m_CatalogName, m_SchemaName, m_Name, false ); ::utl::SharedUNOComponent< XStatement > xStatement; xStatement.set( m_xConnection->createStatement(), UNO_QUERY_THROW ); Reference< XResultSet > xResult( xStatement->executeQuery( aCommand.makeStringAndClear() ), css::uno::UNO_SET_THROW ); diff --git a/connectivity/source/drivers/hsqldb/HViews.cxx b/connectivity/source/drivers/hsqldb/HViews.cxx index e67a9fa14f86..f80ec7716f09 100644 --- a/connectivity/source/drivers/hsqldb/HViews.cxx +++ b/connectivity/source/drivers/hsqldb/HViews.cxx @@ -33,10 +33,7 @@ using namespace connectivity; using namespace connectivity::hsqldb; using namespace css::uno; using namespace css::beans; -using namespace css::sdbcx; using namespace css::sdbc; -using namespace css::container; -using namespace css::lang; using namespace dbtools; typedef connectivity::sdbcx::OCollection OCollection_TYPE; @@ -78,8 +75,7 @@ void HViews::disposing() Reference< XPropertySet > HViews::createDescriptor() { Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection(); - connectivity::sdbcx::OView* pNew = new connectivity::sdbcx::OView(true, xConnection->getMetaData()); - return pNew; + return new connectivity::sdbcx::OView(true, xConnection->getMetaData()); } // XAppend diff --git a/connectivity/source/drivers/hsqldb/StorageFileAccess.cxx b/connectivity/source/drivers/hsqldb/StorageFileAccess.cxx index 3e8461a95f8f..bb07d6673fb1 100644 --- a/connectivity/source/drivers/hsqldb/StorageFileAccess.cxx +++ b/connectivity/source/drivers/hsqldb/StorageFileAccess.cxx @@ -24,8 +24,7 @@ #include <com/sun/star/embed/XStorage.hpp> #include <com/sun/star/lang/IllegalArgumentException.hpp> #include <hsqldb/HStorageMap.hxx> -#include <osl/diagnose.h> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> using namespace ::com::sun::star::container; using namespace ::com::sun::star::uno; @@ -44,42 +43,42 @@ extern "C" SAL_JNI_EXPORT jboolean JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_S { TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key)); auto storage = aStoragePair.mapStorage(); - if ( storage.is() ) + if ( !storage ) + return JNI_FALSE; + + try { + OUString sName = StorageContainer::jstring2ustring(env,name); try { - OUString sName = StorageContainer::jstring2ustring(env,name); - try + OUString sOldName = StorageContainer::removeOldURLPrefix(sName); + if ( storage->isStreamElement(sOldName) ) { - OUString sOldName = StorageContainer::removeOldURLPrefix(sName); - if ( storage->isStreamElement(sOldName) ) + try + { + storage->renameElement(sOldName,StorageContainer::removeURLPrefix(sName,aStoragePair.url)); + } + catch(const Exception&) { - try - { - storage->renameElement(sOldName,StorageContainer::removeURLPrefix(sName,aStoragePair.url)); - } - catch(const Exception&) - { - } } } - catch(const NoSuchElementException&) - { - } - catch(const IllegalArgumentException&) - { - } - return storage->isStreamElement(StorageContainer::removeURLPrefix(sName,aStoragePair.url)); } catch(const NoSuchElementException&) { } - catch(const Exception&) + catch(const IllegalArgumentException&) { - TOOLS_WARN_EXCEPTION("connectivity.hsqldb", "forwarding"); - if (env->ExceptionCheck()) - env->ExceptionClear(); } + return storage->isStreamElement(StorageContainer::removeURLPrefix(sName,aStoragePair.url)); + } + catch(const NoSuchElementException&) + { + } + catch(const Exception&) + { + TOOLS_WARN_EXCEPTION("connectivity.hsqldb", "forwarding"); + if (env->ExceptionCheck()) + env->ExceptionClear(); } return JNI_FALSE; } @@ -159,7 +158,7 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Stora } catch(const Exception& e) { - OSL_FAIL("Exception caught! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement"); + TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement"); StorageContainer::throwJavaException(e,env); } } diff --git a/connectivity/source/drivers/hsqldb/StorageNativeInputStream.cxx b/connectivity/source/drivers/hsqldb/StorageNativeInputStream.cxx index b16eaf742e1c..58d351673480 100644 --- a/connectivity/source/drivers/hsqldb/StorageNativeInputStream.cxx +++ b/connectivity/source/drivers/hsqldb/StorageNativeInputStream.cxx @@ -27,17 +27,16 @@ #include <hsqldb/HStorageMap.hxx> #include <osl/diagnose.h> +#include <comphelper/diagnose_ex.hxx> #include "accesslog.hxx" #include <limits> -using namespace ::com::sun::star::container; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::document; using namespace ::com::sun::star::embed; using namespace ::com::sun::star::io; -using namespace ::com::sun::star::lang; using namespace ::connectivity::hsqldb; /*****************************************************************************/ @@ -173,7 +172,7 @@ extern "C" SAL_JNI_EXPORT jlong JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Stor } catch(const Exception& e) { - OSL_FAIL("Exception caught! : skip();"); + TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "skip();"); StorageContainer::throwJavaException(e,env); } } @@ -216,7 +215,7 @@ extern "C" SAL_JNI_EXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Stora } catch(const Exception& e) { - OSL_FAIL("Exception caught! : available();"); + TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "available();"); StorageContainer::throwJavaException(e,env); } } @@ -260,7 +259,7 @@ extern "C" SAL_JNI_EXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Stora } catch(const Exception& e) { - OSL_FAIL("Exception caught! : skip();"); + TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "skip();"); StorageContainer::throwJavaException(e,env); } @@ -276,7 +275,7 @@ extern "C" SAL_JNI_EXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Stora } OSL_ENSURE(nLen >= nBytesRead,"Buffer is too small!"); OSL_ENSURE(aData.getLength() >= nBytesRead,"Buffer is too small!"); - env->SetByteArrayRegion(buffer, 0, nBytesRead, reinterpret_cast<jbyte*>(&aData[0])); + env->SetByteArrayRegion(buffer, 0, nBytesRead, reinterpret_cast<const jbyte*>(&aData[0])); #ifdef HSQLDB_DBG aDataLog.write( &aData[0], nBytesRead ); #endif diff --git a/connectivity/source/drivers/hsqldb/StorageNativeOutputStream.cxx b/connectivity/source/drivers/hsqldb/StorageNativeOutputStream.cxx index f766696e0d9b..bccbec20fcd2 100644 --- a/connectivity/source/drivers/hsqldb/StorageNativeOutputStream.cxx +++ b/connectivity/source/drivers/hsqldb/StorageNativeOutputStream.cxx @@ -30,12 +30,8 @@ #include <hsqldb/HStorageAccess.hxx> #include <hsqldb/HStorageMap.hxx> -using namespace ::com::sun::star::container; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::document; -using namespace ::com::sun::star::embed; using namespace ::com::sun::star::io; -using namespace ::com::sun::star::lang; using namespace ::connectivity::hsqldb; diff --git a/connectivity/source/drivers/hsqldb/accesslog.hxx b/connectivity/source/drivers/hsqldb/accesslog.hxx index a4dc41f2d35e..81db98ae7750 100644 --- a/connectivity/source/drivers/hsqldb/accesslog.hxx +++ b/connectivity/source/drivers/hsqldb/accesslog.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_ACCESSLOG_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_ACCESSLOG_HXX +#pragma once #ifdef HSQLDB_DBG @@ -133,6 +132,4 @@ namespace connectivity::hsqldb } } #endif -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_ACCESSLOG_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/jdbc/Blob.cxx b/connectivity/source/drivers/jdbc/Blob.cxx index adacd5d7c166..4531fc9b8724 100644 --- a/connectivity/source/drivers/jdbc/Blob.cxx +++ b/connectivity/source/drivers/jdbc/Blob.cxx @@ -135,7 +135,7 @@ sal_Int64 SAL_CALL java_sql_Blob::positionOfBlob( const css::uno::Reference< css ::dbtools::throwFeatureNotImplementedSQLException( "XBlob::positionOfBlob", *this ); // this was put here in CWS warnings01. The previous implementation was defective, as it did ignore // the pattern parameter. Since the effort for proper implementation is rather high - we would need - // to translated patter into a byte[] -, we defer this functionality for the moment (hey, it was + // to translated pattern into a byte[] -, we defer this functionality for the moment (hey, it was // unusable, anyway) // #i57457# return 0; diff --git a/connectivity/source/drivers/jdbc/Boolean.cxx b/connectivity/source/drivers/jdbc/Boolean.cxx index acd1e81ef821..5709674f35b6 100644 --- a/connectivity/source/drivers/jdbc/Boolean.cxx +++ b/connectivity/source/drivers/jdbc/Boolean.cxx @@ -22,22 +22,17 @@ using namespace connectivity; //************ Class: java.lang.Boolean - jclass java_lang_Boolean::theClass = nullptr; -java_lang_Boolean::~java_lang_Boolean() -{} +java_lang_Boolean::~java_lang_Boolean() {} jclass java_lang_Boolean::st_getMyClass() { // the class must be fetched only once, therefore static - if( !theClass ) + if (!theClass) theClass = findMyClass("java/lang/Boolean"); return theClass; } -jclass java_lang_Boolean::getMyClass() const -{ - return st_getMyClass(); -} +jclass java_lang_Boolean::getMyClass() const { return st_getMyClass(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/jdbc/CallableStatement.cxx b/connectivity/source/drivers/jdbc/CallableStatement.cxx index 0994c827e29a..ae521efba11a 100644 --- a/connectivity/source/drivers/jdbc/CallableStatement.cxx +++ b/connectivity/source/drivers/jdbc/CallableStatement.cxx @@ -33,7 +33,6 @@ using namespace connectivity; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; using namespace ::com::sun::star::lang; @@ -302,12 +301,12 @@ Reference< css::sdbc::XRef > SAL_CALL java_sql_CallableStatement::getRef( sal_In return out==nullptr ? nullptr : new java_sql_Ref( t.pEnv, out ); } -void SAL_CALL java_sql_CallableStatement::acquire() throw() +void SAL_CALL java_sql_CallableStatement::acquire() noexcept { java_sql_PreparedStatement::acquire(); } -void SAL_CALL java_sql_CallableStatement::release() throw() +void SAL_CALL java_sql_CallableStatement::release() noexcept { java_sql_PreparedStatement::release(); } @@ -318,7 +317,7 @@ void java_sql_CallableStatement::createStatement(JNIEnv* /*_pEnv*/) checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!"); - if( !(t.pEnv && !object) ) + if( !t.pEnv || object ) return; // initialize temporary variable diff --git a/connectivity/source/drivers/jdbc/Class.cxx b/connectivity/source/drivers/jdbc/Class.cxx index 98d37fbcc99f..862827d12c93 100644 --- a/connectivity/source/drivers/jdbc/Class.cxx +++ b/connectivity/source/drivers/jdbc/Class.cxx @@ -24,44 +24,44 @@ using namespace connectivity; //************ Class: java.lang.Class - jclass java_lang_Class::theClass = nullptr; -java_lang_Class::~java_lang_Class() -{} +java_lang_Class::~java_lang_Class() {} jclass java_lang_Class::getMyClass() const { // the class must be fetched only once, therefore static - if( !theClass ) + if (!theClass) theClass = findMyClass("java/lang/Class"); return theClass; } -java_lang_Class * java_lang_Class::forName( const OUString& _par0 ) +java_lang_Class* java_lang_Class::forName(std::u16string_view _par0) { jobject out(nullptr); SDBThreadAttach t; { OString sClassName = OUStringToOString(_par0, RTL_TEXTENCODING_JAVA_UTF8); - sClassName = sClassName.replace('.','/'); + sClassName = sClassName.replace('.', '/'); out = t.pEnv->FindClass(sClassName.getStr()); - ThrowSQLException(t.pEnv,nullptr); + ThrowSQLException(t.pEnv, nullptr); } //t.pEnv // WARNING: the caller becomes the owner of the returned pointer - return out==nullptr ? nullptr : new java_lang_Class( t.pEnv, out ); + return out == nullptr ? nullptr : new java_lang_Class(t.pEnv, out); } jobject java_lang_Class::newInstanceObject() { SDBThreadAttach t; auto const id = t.pEnv->GetMethodID(static_cast<jclass>(object), "<init>", "()V"); - if (id == nullptr) { + if (id == nullptr) + { ThrowSQLException(t.pEnv, nullptr); } auto const obj = t.pEnv->NewObject(static_cast<jclass>(object), id); - if (obj == nullptr) { + if (obj == nullptr) + { ThrowSQLException(t.pEnv, nullptr); } return obj; diff --git a/connectivity/source/drivers/jdbc/Clob.cxx b/connectivity/source/drivers/jdbc/Clob.cxx index 135512d5a245..6108981aca89 100644 --- a/connectivity/source/drivers/jdbc/Clob.cxx +++ b/connectivity/source/drivers/jdbc/Clob.cxx @@ -122,7 +122,7 @@ sal_Int64 SAL_CALL java_sql_Clob::positionOfClob( const css::uno::Reference< css ::dbtools::throwFeatureNotImplementedSQLException( "XClob::positionOfClob", *this ); // this was put here in CWS warnings01. The previous implementation was defective, as it did ignore // the pattern parameter. Since the effort for proper implementation is rather high - we would need - // to translated patter into a byte[] -, we defer this functionality for the moment (hey, it was + // to translated pattern into a byte[] -, we defer this functionality for the moment (hey, it was // unusable, anyway) // 2005-11-15 / #i57457# / frank.schoenheit@sun.com return 0; diff --git a/connectivity/source/drivers/jdbc/ContextClassLoader.cxx b/connectivity/source/drivers/jdbc/ContextClassLoader.cxx index 50e6bc632bc2..3ab1b88eb33b 100644 --- a/connectivity/source/drivers/jdbc/ContextClassLoader.cxx +++ b/connectivity/source/drivers/jdbc/ContextClassLoader.cxx @@ -43,33 +43,33 @@ namespace connectivity::jdbc do // artificial loop for easier flow control { - LocalRef< jclass > threadClass( m_environment ); - threadClass.set( m_environment.FindClass( "java/lang/Thread" ) ); - if ( !threadClass.is() ) - break; - - jmethodID currentThreadMethod( m_environment.GetStaticMethodID( - threadClass.get(), "currentThread", "()Ljava/lang/Thread;" ) ); - if ( currentThreadMethod == nullptr ) - break; - - m_currentThread.set( m_environment.CallStaticObjectMethod( threadClass.get(), currentThreadMethod ) ); - if ( !m_currentThread.is() ) - break; - - jmethodID getContextClassLoaderMethod( m_environment.GetMethodID( - threadClass.get(), "getContextClassLoader", "()Ljava/lang/ClassLoader;" ) ); - if ( getContextClassLoaderMethod == nullptr ) - break; - m_oldContextClassLoader.set( m_environment.CallObjectMethod( m_currentThread.get(), getContextClassLoaderMethod ) ); - LocalRef< jthrowable > throwable( m_environment, m_environment.ExceptionOccurred() ); - if ( throwable.is() ) - break; - - m_setContextClassLoaderMethod = m_environment.GetMethodID( - threadClass.get(), "setContextClassLoader", "(Ljava/lang/ClassLoader;)V" ); - if ( m_setContextClassLoaderMethod == nullptr ) - break; + LocalRef< jclass > threadClass( m_environment ); + threadClass.set( m_environment.FindClass( "java/lang/Thread" ) ); + if ( !threadClass.is() ) + break; + + jmethodID currentThreadMethod( m_environment.GetStaticMethodID( + threadClass.get(), "currentThread", "()Ljava/lang/Thread;" ) ); + if ( currentThreadMethod == nullptr ) + break; + + m_currentThread.set( m_environment.CallStaticObjectMethod( threadClass.get(), currentThreadMethod ) ); + if ( !m_currentThread.is() ) + break; + + jmethodID getContextClassLoaderMethod( m_environment.GetMethodID( + threadClass.get(), "getContextClassLoader", "()Ljava/lang/ClassLoader;" ) ); + if ( getContextClassLoaderMethod == nullptr ) + break; + m_oldContextClassLoader.set( m_environment.CallObjectMethod( m_currentThread.get(), getContextClassLoaderMethod ) ); + LocalRef< jthrowable > throwable( m_environment, m_environment.ExceptionOccurred() ); + if ( throwable.is() ) + break; + + m_setContextClassLoaderMethod = m_environment.GetMethodID( + threadClass.get(), "setContextClassLoader", "(Ljava/lang/ClassLoader;)V" ); + if ( m_setContextClassLoaderMethod == nullptr ) + break; } while ( false ); diff --git a/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx b/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx index e1918d11c58d..27c7ae01aec3 100644 --- a/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx +++ b/connectivity/source/drivers/jdbc/DatabaseMetaData.cxx @@ -17,6 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <string_view> + #include <sal/macros.h> #include <java/sql/DatabaseMetaData.hxx> #include <java/sql/Connection.hxx> @@ -33,10 +37,7 @@ using namespace ::comphelper; using namespace connectivity; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; jclass java_sql_DatabaseMetaData::theClass = nullptr; @@ -430,14 +431,14 @@ Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getTablePrivileges( { // here we know that the count of column doesn't match std::map<sal_Int32,sal_Int32> aColumnMatching; - static const OUStringLiteral sPrivs[] = { - "TABLE_CAT", - "TABLE_SCHEM", - "TABLE_NAME", - "GRANTOR", - "GRANTEE", - "PRIVILEGE", - "IS_GRANTABLE" + static const std::u16string_view sPrivs[] = { + u"TABLE_CAT", + u"TABLE_SCHEM", + u"TABLE_NAME", + u"GRANTOR", + u"GRANTEE", + u"PRIVILEGE", + u"IS_GRANTABLE" }; OUString sColumnName; @@ -445,7 +446,7 @@ Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getTablePrivileges( for (sal_Int32 i = 1 ; i <= nCount ; ++i) { sColumnName = xMeta->getColumnName(i); - for (size_t j = 0 ; j < SAL_N_ELEMENTS(sPrivs); ++j) + for (size_t j = 0 ; j < std::size(sPrivs); ++j) { if ( sPrivs[j] == sColumnName ) { @@ -456,7 +457,7 @@ Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getTablePrivileges( } // fill our own resultset - ODatabaseMetaDataResultSet* pNewPrivRes = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTablePrivileges ); + rtl::Reference<ODatabaseMetaDataResultSet> pNewPrivRes = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTablePrivileges ); Reference< XResultSet > xTemp = xReturn; xReturn = pNewPrivRes; ODatabaseMetaDataResultSet::ORows aRows; @@ -477,7 +478,7 @@ Reference< XResultSet > SAL_CALL java_sql_DatabaseMetaData::getTablePrivileges( aRows.push_back(aRow); } - pNewPrivRes->setRows(aRows); + pNewPrivRes->setRows(std::move(aRows)); } } } diff --git a/connectivity/source/drivers/jdbc/Date.cxx b/connectivity/source/drivers/jdbc/Date.cxx index 8adaf455aeb0..6086e8190659 100644 --- a/connectivity/source/drivers/jdbc/Date.cxx +++ b/connectivity/source/drivers/jdbc/Date.cxx @@ -23,19 +23,16 @@ using namespace connectivity; //************ Class: java.util.Date - jclass java_util_Date::theClass = nullptr; -java_util_Date::~java_util_Date() -{} +java_util_Date::~java_util_Date() {} jclass java_util_Date::getMyClass() const { // the class must be fetched only once, therefore static - if( !theClass ) + if (!theClass) theClass = findMyClass("java/util/Date"); return theClass; } - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/jdbc/DriverPropertyInfo.cxx b/connectivity/source/drivers/jdbc/DriverPropertyInfo.cxx index 9c33eeb605d0..961fd45f5508 100644 --- a/connectivity/source/drivers/jdbc/DriverPropertyInfo.cxx +++ b/connectivity/source/drivers/jdbc/DriverPropertyInfo.cxx @@ -20,25 +20,19 @@ #include <java/sql/DriverPropertyInfo.hxx> using namespace connectivity; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::lang; - //************ Class: java.sql.Driver - jclass java_sql_DriverPropertyInfo::theClass = nullptr; -java_sql_DriverPropertyInfo::~java_sql_DriverPropertyInfo() -{} +java_sql_DriverPropertyInfo::~java_sql_DriverPropertyInfo() {} jclass java_sql_DriverPropertyInfo::getMyClass() const { // the class must be fetched only once, therefore static - if( !theClass ) + if (!theClass) theClass = findMyClass("java/sql/DriverPropertyInfo"); return theClass; } - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/jdbc/Exception.cxx b/connectivity/source/drivers/jdbc/Exception.cxx index 2fdef4ee8028..9fa2d5c18c47 100644 --- a/connectivity/source/drivers/jdbc/Exception.cxx +++ b/connectivity/source/drivers/jdbc/Exception.cxx @@ -22,16 +22,14 @@ using namespace connectivity; //************ Class: java.lang.Exception - jclass java_lang_Exception::theClass = nullptr; -java_lang_Exception::~java_lang_Exception() -{} +java_lang_Exception::~java_lang_Exception() {} jclass java_lang_Exception::getMyClass() const { // the class must be fetched only once, therefore static - if( !theClass ) + if (!theClass) theClass = findMyClass("java/lang/Exception"); return theClass; } diff --git a/connectivity/source/drivers/jdbc/JConnection.cxx b/connectivity/source/drivers/jdbc/JConnection.cxx index 1d33f2941316..5844df568ba3 100644 --- a/connectivity/source/drivers/jdbc/JConnection.cxx +++ b/connectivity/source/drivers/jdbc/JConnection.cxx @@ -43,6 +43,7 @@ #include <unotools/confignode.hxx> #include <strings.hxx> +#include <utility> #include <vector> #include <memory> @@ -58,8 +59,8 @@ namespace { struct ClassMapEntry { ClassMapEntry( - OUString const & theClassPath, OUString const & theClassName): - classPath(theClassPath), className(theClassName), classLoader(nullptr), + OUString theClassPath, OUString theClassName): + classPath(std::move(theClassPath)), className(std::move(theClassName)), classLoader(nullptr), classObject(nullptr) {} OUString classPath; @@ -165,7 +166,7 @@ bool loadClass( // JVM that are not easily undone). If the pushed ClassMapEntry is // not used after all (return false, etc.) it will be pruned on next // call because its classLoader/classObject are null: - classMapData.map.push_back( ClassMapEntry( classPath, name ) ); + classMapData.map.emplace_back(classPath, name); i = std::prev(classMapData.map.end()); } @@ -246,11 +247,9 @@ IMPLEMENT_SERVICE_INFO(java_sql_Connection,"com.sun.star.sdbcx.JConnection","com jclass java_sql_Connection::theClass = nullptr; java_sql_Connection::java_sql_Connection( const java_sql_Driver& _rDriver ) - :java_lang_Object() - ,m_xContext( _rDriver.getContext() ) + :m_xContext( _rDriver.getContext() ) ,m_pDriver( &_rDriver ) ,m_pDriverobject(nullptr) - ,m_pDriverClassLoader() ,m_Driver_theClass(nullptr) ,m_aLogger( _rDriver.getLogger() ) ,m_bIgnoreDriverPrivileges(true) @@ -436,9 +435,9 @@ Reference< XStatement > SAL_CALL java_sql_Connection::createStatement( ) m_aLogger.log( LogLevel::FINE, STR_LOG_CREATE_STATEMENT ); SDBThreadAttach t; - java_sql_Statement* pStatement = new java_sql_Statement( t.pEnv, *this ); + rtl::Reference<java_sql_Statement> pStatement = new java_sql_Statement( t.pEnv, *this ); Reference< XStatement > xStmt = pStatement; - m_aStatements.push_back( WeakReferenceHelper( xStmt ) ); + m_aStatements.emplace_back(xStmt); m_aLogger.log( LogLevel::FINE, STR_LOG_CREATED_STATEMENT_ID, pStatement->getStatementObjectID() ); return xStmt; @@ -452,9 +451,9 @@ Reference< XPreparedStatement > SAL_CALL java_sql_Connection::prepareStatement( SDBThreadAttach t; - java_sql_PreparedStatement* pStatement = new java_sql_PreparedStatement( t.pEnv, *this, sql ); + rtl::Reference<java_sql_PreparedStatement> pStatement = new java_sql_PreparedStatement( t.pEnv, *this, sql ); Reference< XPreparedStatement > xReturn( pStatement ); - m_aStatements.push_back(WeakReferenceHelper(xReturn)); + m_aStatements.emplace_back(xReturn); m_aLogger.log( LogLevel::FINE, STR_LOG_PREPARED_STATEMENT_ID, pStatement->getStatementObjectID() ); return xReturn; @@ -468,9 +467,9 @@ Reference< XPreparedStatement > SAL_CALL java_sql_Connection::prepareCall( const SDBThreadAttach t; - java_sql_CallableStatement* pStatement = new java_sql_CallableStatement( t.pEnv, *this, sql ); + rtl::Reference<java_sql_CallableStatement> pStatement = new java_sql_CallableStatement( t.pEnv, *this, sql ); Reference< XPreparedStatement > xStmt( pStatement ); - m_aStatements.push_back(WeakReferenceHelper(xStmt)); + m_aStatements.emplace_back(xStmt); m_aLogger.log( LogLevel::FINE, STR_LOG_PREPARED_CALL_ID, pStatement->getStatementObjectID() ); return xStmt; @@ -525,14 +524,10 @@ Any SAL_CALL java_sql_Connection::getWarnings( ) SQLException aAsException( java_sql_SQLWarning( warn_base, *this ) ); // translate to warning - SQLWarning aWarning; - aWarning.Context = aAsException.Context; - aWarning.Message = aAsException.Message; - aWarning.SQLState = aAsException.SQLState; - aWarning.ErrorCode = aAsException.ErrorCode; - aWarning.NextException = aAsException.NextException; - - return makeAny( aWarning ); + SQLWarning aWarning(aAsException.Message, aAsException.Context, aAsException.SQLState, + aAsException.ErrorCode, aAsException.NextException); + + return Any( aWarning ); } return Any(); @@ -699,7 +694,8 @@ void java_sql_Connection::loadDriverFromProperties( const OUString& _sDriverClas OUString java_sql_Connection::impl_getJavaDriverClassPath_nothrow(const OUString& _sDriverClass) { - static const char s_sNodeName[] = "org.openoffice.Office.DataAccess/JDBC/DriverClassPaths"; + static constexpr OUStringLiteral s_sNodeName + = u"org.openoffice.Office.DataAccess/JDBC/DriverClassPaths"; ::utl::OConfigurationTreeRoot aNamesRoot = ::utl::OConfigurationTreeRoot::createWithComponentContext( m_pDriver->getContext(), s_sNodeName, -1, ::utl::OConfigurationTreeRoot::CM_READONLY); OUString sURL; diff --git a/connectivity/source/drivers/jdbc/JDriver.cxx b/connectivity/source/drivers/jdbc/JDriver.cxx index 661d9ea67d35..f294d30b4937 100644 --- a/connectivity/source/drivers/jdbc/JDriver.cxx +++ b/connectivity/source/drivers/jdbc/JDriver.cxx @@ -24,7 +24,6 @@ #include <jvmfwk/framework.hxx> #include <strings.hrc> #include <resource/sharedresources.hxx> -#include <comphelper/processfactory.hxx> #include <cppuhelper/supportsservice.hxx> #include <strings.hxx> @@ -72,7 +71,7 @@ Reference< XConnection > SAL_CALL java_sql_Driver::connect( const OUString& url, Reference< XConnection > xOut; if ( acceptsURL(url ) ) { - java_sql_Connection* pConnection = new java_sql_Connection( *this ); + rtl::Reference<java_sql_Connection> pConnection = new java_sql_Connection( *this ); xOut = pConnection; if ( !pConnection->construct(url,info) ) xOut.clear(); // an error occurred and the java driver didn't throw an exception @@ -109,104 +108,102 @@ Sequence< DriverPropertyInfo > SAL_CALL java_sql_Driver::getPropertyInfo( const { if ( acceptsURL(url) ) { - std::vector< DriverPropertyInfo > aDriverInfo; + Sequence< OUString > aBooleanValues{ "false", "true" }; - Sequence< OUString > aBooleanValues(2); - aBooleanValues[0] = "false"; - aBooleanValues[1] = "true"; - - aDriverInfo.push_back(DriverPropertyInfo( + return + { + { "JavaDriverClass" ,"The JDBC driver class name." ,true ,OUString() - ,Sequence< OUString >()) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,Sequence< OUString >() + }, + { "JavaDriverClassPath" ,"The class path where to look for the JDBC driver." ,true , "" - ,Sequence< OUString >()) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,Sequence< OUString >() + }, + { "SystemProperties" ,"Additional properties to set at java.lang.System before loading the driver." ,true , "" - ,Sequence< OUString >()) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,Sequence< OUString >() + }, + { "ParameterNameSubstitution" ,"Change named parameters with '?'." ,false ,"false" - ,aBooleanValues) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,aBooleanValues + }, + { "IgnoreDriverPrivileges" ,"Ignore the privileges from the database driver." ,false , "false" - ,aBooleanValues) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,aBooleanValues + }, + { "IsAutoRetrievingEnabled" ,"Retrieve generated values." ,false ,"false" - ,aBooleanValues) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,aBooleanValues + }, + { "AutoRetrievingStatement" ,"Auto-increment statement." ,false ,OUString() - ,Sequence< OUString >()) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,Sequence< OUString >() + }, + { "GenerateASBeforeCorrelationName" ,"Generate AS before table correlation names." ,false ,"false" - ,aBooleanValues) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,aBooleanValues + }, + { "IgnoreCurrency" ,"Ignore the currency field from the ResultsetMetaData." ,false ,"false" - ,aBooleanValues) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,aBooleanValues + }, + { "EscapeDateTime" ,"Escape date time format." ,false ,"true" - ,aBooleanValues) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,aBooleanValues + }, + { "TypeInfoSettings" ,"Defines how the type info of the database metadata should be manipulated." ,false - ,OUString( ) - ,Sequence< OUString > ()) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,OUString() + ,Sequence< OUString > () + }, + { "ImplicitCatalogRestriction" ,"The catalog which should be used in getTables calls, when the caller passed NULL." ,false ,OUString( ) - ,Sequence< OUString > ()) - ); - aDriverInfo.push_back(DriverPropertyInfo( + ,Sequence< OUString > () + }, + { "ImplicitSchemaRestriction" ,"The schema which should be used in getTables calls, when the caller passed NULL." ,false ,OUString( ) - ,Sequence< OUString > ()) - ); - return Sequence< DriverPropertyInfo >(aDriverInfo.data(),aDriverInfo.size()); + ,Sequence< OUString > () + } + }; } ::connectivity::SharedResources aResources; const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR); diff --git a/connectivity/source/drivers/jdbc/JStatement.cxx b/connectivity/source/drivers/jdbc/JStatement.cxx index 9bfe11838b7f..1d5326ca6302 100644 --- a/connectivity/source/drivers/jdbc/JStatement.cxx +++ b/connectivity/source/drivers/jdbc/JStatement.cxx @@ -31,7 +31,7 @@ #include <comphelper/sequence.hxx> #include <TConnection.hxx> #include <comphelper/types.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <com/sun/star/sdbc/ResultSetConcurrency.hpp> #include <com/sun/star/sdbc/ResultSetType.hpp> @@ -124,9 +124,10 @@ Sequence< Type > SAL_CALL java_sql_Statement_Base::getTypes( ) Sequence< Type > aOldTypes = java_sql_Statement_BASE::getTypes(); if ( m_pConnection.is() && !m_pConnection->isAutoRetrievingEnabled() ) { - auto newEnd = std::remove(aOldTypes.begin(), aOldTypes.end(), + auto [begin, end] = asNonConstRange(aOldTypes); + auto newEnd = std::remove(begin, end, cppu::UnoType<XGeneratedResultSet>::get()); - aOldTypes.realloc(std::distance(aOldTypes.begin(), newEnd)); + aOldTypes.realloc(std::distance(begin, newEnd)); } return ::comphelper::concatSequences(aTypes.getTypes(),aOldTypes); @@ -279,7 +280,7 @@ Reference< XConnection > SAL_CALL java_sql_Statement_Base::getConnection( ) { ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); - return Reference< XConnection >(m_pConnection.get()); + return m_pConnection; } @@ -377,9 +378,9 @@ Any SAL_CALL java_sql_Statement_Base::getWarnings( ) if( out ) { java_sql_SQLWarning_BASE warn_base( t.pEnv, out ); - return makeAny( + return Any( static_cast< css::sdbc::SQLException >( - java_sql_SQLWarning(warn_base,*static_cast<cppu::OWeakObject*>(this)))); + java_sql_SQLWarning(warn_base,getXWeak()))); } return Any(); @@ -575,31 +576,71 @@ void java_sql_Statement_Base::setCursorName(const OUString &_par0) ::cppu::IPropertyArrayHelper* java_sql_Statement_Base::createArrayHelper( ) const { - Sequence< Property > aProps(10); - Property* pProperties = aProps.getArray(); - sal_Int32 nPos = 0; - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), - PROPERTY_ID_CURSORNAME, cppu::UnoType<OUString>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ESCAPEPROCESSING), - PROPERTY_ID_ESCAPEPROCESSING, cppu::UnoType<bool>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), - PROPERTY_ID_FETCHDIRECTION, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), - PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXFIELDSIZE), - PROPERTY_ID_MAXFIELDSIZE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXROWS), - PROPERTY_ID_MAXROWS, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_QUERYTIMEOUT), - PROPERTY_ID_QUERYTIMEOUT, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), - PROPERTY_ID_RESULTSETCONCURRENCY, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), - PROPERTY_ID_RESULTSETTYPE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_USEBOOKMARKS), - PROPERTY_ID_USEBOOKMARKS, cppu::UnoType<bool>::get(), 0); - - return new ::cppu::OPropertyArrayHelper(aProps); + return new ::cppu::OPropertyArrayHelper + { + { + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), + PROPERTY_ID_CURSORNAME, + cppu::UnoType<OUString>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ESCAPEPROCESSING), + PROPERTY_ID_ESCAPEPROCESSING, + cppu::UnoType<bool>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), + PROPERTY_ID_FETCHDIRECTION, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), + PROPERTY_ID_FETCHSIZE, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXFIELDSIZE), + PROPERTY_ID_MAXFIELDSIZE, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXROWS), + PROPERTY_ID_MAXROWS, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_QUERYTIMEOUT), + PROPERTY_ID_QUERYTIMEOUT, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), + PROPERTY_ID_RESULTSETCONCURRENCY, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), + PROPERTY_ID_RESULTSETTYPE, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_USEBOOKMARKS), + PROPERTY_ID_USEBOOKMARKS, + cppu::UnoType<bool>::get(), + 0 + } + } + }; } @@ -761,7 +802,7 @@ void java_sql_Statement::createStatement(JNIEnv* _pEnv) ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); - if( !(_pEnv && !object) ) + if( !_pEnv || object ) return; // initialize temporary variable @@ -794,22 +835,22 @@ void java_sql_Statement::createStatement(JNIEnv* _pEnv) IMPLEMENT_SERVICE_INFO(java_sql_Statement,"com.sun.star.sdbcx.JStatement","com.sun.star.sdbc.Statement"); -void SAL_CALL java_sql_Statement_Base::acquire() throw() +void SAL_CALL java_sql_Statement_Base::acquire() noexcept { java_sql_Statement_BASE::acquire(); } -void SAL_CALL java_sql_Statement_Base::release() throw() +void SAL_CALL java_sql_Statement_Base::release() noexcept { java_sql_Statement_BASE::release(); } -void SAL_CALL java_sql_Statement::acquire() throw() +void SAL_CALL java_sql_Statement::acquire() noexcept { OStatement_BASE2::acquire(); } -void SAL_CALL java_sql_Statement::release() throw() +void SAL_CALL java_sql_Statement::release() noexcept { OStatement_BASE2::release(); } diff --git a/connectivity/source/drivers/jdbc/Object.cxx b/connectivity/source/drivers/jdbc/Object.cxx index 479699750e07..65d6680d745e 100644 --- a/connectivity/source/drivers/jdbc/Object.cxx +++ b/connectivity/source/drivers/jdbc/Object.cxx @@ -29,13 +29,9 @@ #include <comphelper/logging.hxx> #include <cppuhelper/exc_hlp.hxx> -#include <memory> - using namespace connectivity; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; using namespace ::com::sun::star::lang; @@ -170,22 +166,22 @@ namespace if ( _pEnvironment->IsInstanceOf( jThrow, java_sql_SQLException_BASE::st_getMyClass() ) ) { - std::unique_ptr< java_sql_SQLException_BASE > pException( new java_sql_SQLException_BASE( _pEnvironment, jThrow ) ); - _out_rException = SQLException( pException->getMessage(), _rxContext, - pException->getSQLState(), pException->getErrorCode(), Any() ); + java_sql_SQLException_BASE aException( _pEnvironment, jThrow ); + _out_rException = SQLException( aException.getMessage(), _rxContext, + aException.getSQLState(), aException.getErrorCode(), Any() ); return true; } else if ( _pEnvironment->IsInstanceOf( jThrow, java_lang_Throwable::st_getMyClass() ) ) { - std::unique_ptr< java_lang_Throwable > pThrow( new java_lang_Throwable( _pEnvironment, jThrow ) ); + java_lang_Throwable aThrow( _pEnvironment, jThrow ); #if OSL_DEBUG_LEVEL > 0 - pThrow->printStackTrace(); + aThrow.printStackTrace(); #endif - OUString sMessage = pThrow->getMessage(); + OUString sMessage = aThrow.getMessage(); if ( sMessage.isEmpty() ) - sMessage = pThrow->getLocalizedMessage(); + sMessage = aThrow.getLocalizedMessage(); if( sMessage.isEmpty() ) - sMessage = pThrow->toString(); + sMessage = aThrow.toString(); _out_rException = SQLException( sMessage, _rxContext, OUString(), -1, Any() ); return true; } diff --git a/connectivity/source/drivers/jdbc/PreparedStatement.cxx b/connectivity/source/drivers/jdbc/PreparedStatement.cxx index 34c28f084677..fa3f7b40c982 100644 --- a/connectivity/source/drivers/jdbc/PreparedStatement.cxx +++ b/connectivity/source/drivers/jdbc/PreparedStatement.cxx @@ -40,7 +40,6 @@ using namespace connectivity; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; using namespace ::com::sun::star::lang; @@ -143,7 +142,7 @@ void SAL_CALL java_sql_PreparedStatement::setString( sal_Int32 parameterIndex, c css::uno::Reference< css::sdbc::XConnection > SAL_CALL java_sql_PreparedStatement::getConnection( ) { - return Reference< XConnection >(m_pConnection.get()); + return m_pConnection; } @@ -354,7 +353,7 @@ void SAL_CALL java_sql_PreparedStatement::setObjectWithInfo( sal_Int32 parameter { ORowSetValue aValue; aValue.fill(x); - const OUString sValue = aValue; + const OUString sValue = aValue.getString(); if ( !sValue.isEmpty() ) pBigDecimal.reset(new java_math_BigDecimal(sValue)); else @@ -640,12 +639,12 @@ css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL java_sql_PreparedS return out==nullptr ? nullptr : new java_sql_ResultSetMetaData( t.pEnv, out, *m_pConnection ); } -void SAL_CALL java_sql_PreparedStatement::acquire() throw() +void SAL_CALL java_sql_PreparedStatement::acquire() noexcept { OStatement_BASE2::acquire(); } -void SAL_CALL java_sql_PreparedStatement::release() throw() +void SAL_CALL java_sql_PreparedStatement::release() noexcept { OStatement_BASE2::release(); } @@ -655,7 +654,7 @@ void java_sql_PreparedStatement::createStatement(JNIEnv* _pEnv) ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); - if( !(!object && _pEnv) ) + if( object || !_pEnv ) return; // initialize temporary variable diff --git a/connectivity/source/drivers/jdbc/Reader.cxx b/connectivity/source/drivers/jdbc/Reader.cxx index 8dd12157e3ee..85d02e87a3e3 100644 --- a/connectivity/source/drivers/jdbc/Reader.cxx +++ b/connectivity/source/drivers/jdbc/Reader.cxx @@ -129,7 +129,6 @@ sal_Int32 SAL_CALL java_io_Reader::readBytes( css::uno::Sequence< sal_Int8 >& aD sal_Int32 nCharsToRead = (nBytesToRead + 1)/2; - jint outChars(0); SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!"); { @@ -139,7 +138,7 @@ sal_Int32 SAL_CALL java_io_Reader::readBytes( css::uno::Sequence< sal_Int8 >& aD // Java-Call static jmethodID mID(nullptr); obtainMethodId_throwRuntime(t.pEnv, cMethodName,cSignature, mID); - outChars = t.pEnv->CallIntMethod( object, mID, pCharArray, 0, nCharsToRead ); + jint outChars = t.pEnv->CallIntMethod( object, mID, pCharArray, 0, nCharsToRead ); if ( !outChars ) { if(nBytesWritten==0) diff --git a/connectivity/source/drivers/jdbc/Ref.cxx b/connectivity/source/drivers/jdbc/Ref.cxx index ca8e2e112815..12ce9fda8aa3 100644 --- a/connectivity/source/drivers/jdbc/Ref.cxx +++ b/connectivity/source/drivers/jdbc/Ref.cxx @@ -23,30 +23,26 @@ using namespace connectivity; //************ Class: java.sql.Ref - jclass java_sql_Ref::theClass = nullptr; -java_sql_Ref::java_sql_Ref( JNIEnv * pEnv, jobject myObj ) -: java_lang_Object( pEnv, myObj ) +java_sql_Ref::java_sql_Ref(JNIEnv* pEnv, jobject myObj) + : java_lang_Object(pEnv, myObj) { SDBThreadAttach::addRef(); } -java_sql_Ref::~java_sql_Ref() -{ - SDBThreadAttach::releaseRef(); -} +java_sql_Ref::~java_sql_Ref() { SDBThreadAttach::releaseRef(); } jclass java_sql_Ref::getMyClass() const { // the class must be fetched only once, therefore static - if( !theClass ) + if (!theClass) theClass = findMyClass("java/sql/Ref"); return theClass; } -OUString SAL_CALL java_sql_Ref::getBaseTypeName( ) +OUString SAL_CALL java_sql_Ref::getBaseTypeName() { static jmethodID mID(nullptr); - return callStringMethod("getBaseTypeName",mID); + return callStringMethod("getBaseTypeName", mID); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/jdbc/ResultSet.cxx b/connectivity/source/drivers/jdbc/ResultSet.cxx index 238e78702c61..c274c521c33c 100644 --- a/connectivity/source/drivers/jdbc/ResultSet.cxx +++ b/connectivity/source/drivers/jdbc/ResultSet.cxx @@ -288,7 +288,6 @@ Reference< XRef > SAL_CALL java_sql_ResultSet::getRef( sal_Int32 columnIndex ) Any SAL_CALL java_sql_ResultSet::getObject( sal_Int32 columnIndex, const Reference< css::container::XNameAccess >& typeMap ) { - jobject out(nullptr); Any aRet; SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!"); { @@ -307,7 +306,7 @@ Any SAL_CALL java_sql_ResultSet::getObject( sal_Int32 columnIndex, const Referen obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID); } - out = t.pEnv->CallObjectMethodA( object, mID, args); + jobject out = t.pEnv->CallObjectMethodA( object, mID, args); t.pEnv->DeleteLocalRef(static_cast<jstring>(args[1].l)); ThrowLoggedSQLException( m_aLogger, t.pEnv, *this ); // and clean up @@ -515,7 +514,7 @@ css::uno::Any SAL_CALL java_sql_ResultSet::getWarnings( ) if( out ) { java_sql_SQLWarning_BASE warn_base( t.pEnv, out ); - return makeAny( + return Any( static_cast< css::sdbc::SQLException >( java_sql_SQLWarning(warn_base,*this))); } @@ -874,25 +873,41 @@ void java_sql_ResultSet::setFetchSize(sal_Int32 _par0) ::cppu::IPropertyArrayHelper* java_sql_ResultSet::createArrayHelper( ) const { - Sequence< Property > aProps(5); - Property* pProperties = aProps.getArray(); - sal_Int32 nPos = 0; - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), - PROPERTY_ID_CURSORNAME, cppu::UnoType<OUString>::get(), PropertyAttribute::READONLY); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), - PROPERTY_ID_FETCHDIRECTION, cppu::UnoType<sal_Int32>::get(), 0); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), - PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), - PROPERTY_ID_RESULTSETCONCURRENCY, cppu::UnoType<sal_Int32>::get(), PropertyAttribute::READONLY); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), - PROPERTY_ID_RESULTSETTYPE, cppu::UnoType<sal_Int32>::get(), PropertyAttribute::READONLY); - - return new ::cppu::OPropertyArrayHelper(aProps); + return new ::cppu::OPropertyArrayHelper + { + { + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), + PROPERTY_ID_CURSORNAME, + cppu::UnoType<OUString>::get(), + PropertyAttribute::READONLY + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), + PROPERTY_ID_FETCHDIRECTION, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), + PROPERTY_ID_FETCHSIZE, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), + PROPERTY_ID_RESULTSETCONCURRENCY, + cppu::UnoType<sal_Int32>::get(), + PropertyAttribute::READONLY + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), + PROPERTY_ID_RESULTSETTYPE, + cppu::UnoType<sal_Int32>::get(), + PropertyAttribute::READONLY + } + } + }; } ::cppu::IPropertyArrayHelper & java_sql_ResultSet::getInfoHelper() @@ -979,12 +994,12 @@ void java_sql_ResultSet::getFastPropertyValue( } } -void SAL_CALL java_sql_ResultSet::acquire() throw() +void SAL_CALL java_sql_ResultSet::acquire() noexcept { java_sql_ResultSet_BASE::acquire(); } -void SAL_CALL java_sql_ResultSet::release() throw() +void SAL_CALL java_sql_ResultSet::release() noexcept { java_sql_ResultSet_BASE::release(); } diff --git a/connectivity/source/drivers/jdbc/ResultSetMetaData.cxx b/connectivity/source/drivers/jdbc/ResultSetMetaData.cxx index fdf5bfe69c29..b5827ea991e7 100644 --- a/connectivity/source/drivers/jdbc/ResultSetMetaData.cxx +++ b/connectivity/source/drivers/jdbc/ResultSetMetaData.cxx @@ -21,10 +21,7 @@ #include <java/sql/Connection.hxx> using namespace connectivity; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; using namespace ::com::sun::star::lang; diff --git a/connectivity/source/drivers/jdbc/SQLException.cxx b/connectivity/source/drivers/jdbc/SQLException.cxx index 55bf0996c941..49fa95c456d5 100644 --- a/connectivity/source/drivers/jdbc/SQLException.cxx +++ b/connectivity/source/drivers/jdbc/SQLException.cxx @@ -22,7 +22,6 @@ using namespace connectivity; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::lang; //************ Class: java.sql.SQLException @@ -31,7 +30,7 @@ java_sql_SQLException::java_sql_SQLException( const java_sql_SQLException_BASE& _rContext, _rException.getSQLState(), _rException.getErrorCode(), - makeAny(_rException.getNextException()) + Any(_rException.getNextException()) ) { } diff --git a/connectivity/source/drivers/jdbc/SQLWarning.cxx b/connectivity/source/drivers/jdbc/SQLWarning.cxx index 16616d18bb9e..487665d7d09b 100644 --- a/connectivity/source/drivers/jdbc/SQLWarning.cxx +++ b/connectivity/source/drivers/jdbc/SQLWarning.cxx @@ -22,16 +22,14 @@ using namespace connectivity; //************ Class: java.sql.SQLWarning - jclass java_sql_SQLWarning_BASE::theClass = nullptr; -java_sql_SQLWarning_BASE::~java_sql_SQLWarning_BASE() -{} +java_sql_SQLWarning_BASE::~java_sql_SQLWarning_BASE() {} jclass java_sql_SQLWarning_BASE::getMyClass() const { // the class needs to be fetched only once, that is why it is static - if( !theClass ) + if (!theClass) theClass = findMyClass("java/sql/SQLWarning"); return theClass; } diff --git a/connectivity/source/drivers/jdbc/String.cxx b/connectivity/source/drivers/jdbc/String.cxx index f7e682c0281c..e229ef54a39a 100644 --- a/connectivity/source/drivers/jdbc/String.cxx +++ b/connectivity/source/drivers/jdbc/String.cxx @@ -23,29 +23,23 @@ using namespace connectivity; //************ Class: java.lang.String - jclass java_lang_String::theClass = nullptr; -java_lang_String::~java_lang_String() -{} +java_lang_String::~java_lang_String() {} -jclass java_lang_String::getMyClass() const -{ - return st_getMyClass(); -} +jclass java_lang_String::getMyClass() const { return st_getMyClass(); } jclass java_lang_String::st_getMyClass() { // the class needs to be fetched only once, that is why it is static - if( !theClass ) + if (!theClass) theClass = findMyClass("java/lang/String"); return theClass; } - java_lang_String::operator OUString() { SDBThreadAttach t; - if(!t.pEnv) + if (!t.pEnv) return OUString(); return JavaString2String(t.pEnv, static_cast<jstring>(object)); } diff --git a/connectivity/source/drivers/jdbc/Throwable.cxx b/connectivity/source/drivers/jdbc/Throwable.cxx index c96f5532f38d..db4bb89208ce 100644 --- a/connectivity/source/drivers/jdbc/Throwable.cxx +++ b/connectivity/source/drivers/jdbc/Throwable.cxx @@ -23,43 +23,36 @@ using namespace connectivity; //************ Class: java.lang.Throwable - jclass java_lang_Throwable::theClass = nullptr; -java_lang_Throwable::~java_lang_Throwable() -{} +java_lang_Throwable::~java_lang_Throwable() {} -jclass java_lang_Throwable::getMyClass() const -{ - return st_getMyClass(); -} +jclass java_lang_Throwable::getMyClass() const { return st_getMyClass(); } jclass java_lang_Throwable::st_getMyClass() { // the class needs to be fetched only once, that is why it is static - if( !theClass ) + if (!theClass) theClass = findMyClass("java/lang/Throwable"); return theClass; } - OUString java_lang_Throwable::getMessage() const { static jmethodID mID(nullptr); - return callStringMethod("getMessage",mID); + return callStringMethod("getMessage", mID); } - OUString java_lang_Throwable::getLocalizedMessage() const { static jmethodID mID(nullptr); - return callStringMethod("getLocalizedMessage",mID); + return callStringMethod("getLocalizedMessage", mID); } #if OSL_DEBUG_LEVEL > 0 void java_lang_Throwable::printStackTrace() const { static jmethodID mID(nullptr); - return callVoidMethod_ThrowSQL("printStackTrace",mID); + return callVoidMethod_ThrowSQL("printStackTrace", mID); } #endif diff --git a/connectivity/source/drivers/jdbc/tools.cxx b/connectivity/source/drivers/jdbc/tools.cxx index 5021d653a889..1d1959717370 100644 --- a/connectivity/source/drivers/jdbc/tools.cxx +++ b/connectivity/source/drivers/jdbc/tools.cxx @@ -32,12 +32,10 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; void java_util_Properties::setProperty(const OUString& key, const OUString& value) { SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!"); - jobject out(nullptr); { jvalue args[2]; @@ -50,7 +48,7 @@ void java_util_Properties::setProperty(const OUString& key, const OUString& valu // Turn off Java-Call static jmethodID mID(nullptr); obtainMethodId_throwSQL(t.pEnv, cMethodName,cSignature, mID); - out = t.pEnv->CallObjectMethod(object, mID, args[0].l,args[1].l); + jobject out = t.pEnv->CallObjectMethod(object, mID, args[0].l,args[1].l); ThrowSQLException(t.pEnv,nullptr); t.pEnv->DeleteLocalRef(static_cast<jstring>(args[1].l)); t.pEnv->DeleteLocalRef(static_cast<jstring>(args[0].l)); diff --git a/connectivity/source/drivers/macab/MacabAddressBook.cxx b/connectivity/source/drivers/macab/MacabAddressBook.cxx index 09e4892033e8..7ade1ac0a830 100644 --- a/connectivity/source/drivers/macab/MacabAddressBook.cxx +++ b/connectivity/source/drivers/macab/MacabAddressBook.cxx @@ -82,6 +82,13 @@ MacabAddressBook::MacabAddressBook( ) m_xMacabRecords(nullptr), m_bRetrievedGroups(false) { + if(m_aAddressBook == nullptr) + { + // TODO: tell the user to reset the permission via "tccutil reset AddressBook" + // or the system preferences and try again, this time granting the access + throw RuntimeException( + "failed to access the macOS address book - permission not granted?" ); + } } @@ -106,8 +113,8 @@ MacabAddressBook::~MacabAddressBook() const OUString & MacabAddressBook::getDefaultTableName() { /* This string probably needs to be localized. */ - static const OUString aDefaultTableName - (OUString("Address Book")); + static constexpr OUString aDefaultTableName + (u"Address Book"_ustr); return aDefaultTableName; } @@ -130,7 +137,7 @@ MacabRecords *MacabAddressBook::getMacabRecords() /* Get the MacabRecords for a given name: either a group name or the * default table name. */ -MacabRecords *MacabAddressBook::getMacabRecords(const OUString& _tableName) +MacabRecords *MacabAddressBook::getMacabRecords(std::u16string_view _tableName) { if(_tableName == getDefaultTableName()) { @@ -192,7 +199,7 @@ std::vector<MacabGroup *> MacabAddressBook::getMacabGroups() } -MacabGroup *MacabAddressBook::getMacabGroup(OUString const & _groupName) +MacabGroup *MacabAddressBook::getMacabGroup(std::u16string_view _groupName) { // initialize groups if not already initialized if(!m_bRetrievedGroups) diff --git a/connectivity/source/drivers/macab/MacabAddressBook.hxx b/connectivity/source/drivers/macab/MacabAddressBook.hxx index a74621ef2a39..a23e0c1eb2e7 100644 --- a/connectivity/source/drivers/macab/MacabAddressBook.hxx +++ b/connectivity/source/drivers/macab/MacabAddressBook.hxx @@ -17,12 +17,12 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABADDRESSBOOK_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABADDRESSBOOK_HXX +#pragma once #include "MacabRecords.hxx" #include "MacabGroup.hxx" +#include <string_view> #include <vector> #include <premac.h> @@ -30,10 +30,8 @@ #include <AddressBook/ABAddressBookC.h> #include <postmac.h> -namespace connectivity +namespace connectivity::macab { - namespace macab - { class MacabAddressBook { protected: @@ -50,16 +48,13 @@ namespace connectivity MacabRecords *getMacabRecords(); std::vector<MacabGroup *> getMacabGroups(); - MacabGroup *getMacabGroup(const OUString& _groupName); - MacabRecords *getMacabRecords(const OUString& _tableName); + MacabGroup *getMacabGroup(std::u16string_view _groupName); + MacabRecords *getMacabRecords(std::u16string_view _tableName); MacabGroup *getMacabGroupMatch(const OUString& _groupName); MacabRecords *getMacabRecordsMatch(const OUString& _tableName); }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABADDRESSBOOK_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/macab/MacabCatalog.cxx b/connectivity/source/drivers/macab/MacabCatalog.cxx index 96ff62fd5b6a..d6485ab1c971 100644 --- a/connectivity/source/drivers/macab/MacabCatalog.cxx +++ b/connectivity/source/drivers/macab/MacabCatalog.cxx @@ -80,7 +80,7 @@ void MacabCatalog::refreshUsers() const OUString& MacabCatalog::getDot() { - static const OUString sDot = "."; + static constexpr OUString sDot = u"."_ustr; return sDot; } diff --git a/connectivity/source/drivers/macab/MacabCatalog.hxx b/connectivity/source/drivers/macab/MacabCatalog.hxx index 9c45ab1f10ad..1757bb908851 100644 --- a/connectivity/source/drivers/macab/MacabCatalog.hxx +++ b/connectivity/source/drivers/macab/MacabCatalog.hxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABCATALOG_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABCATALOG_HXX +#pragma once #include <sdbcx/VCatalog.hxx> -namespace connectivity +namespace connectivity::macab { - namespace macab - { - class MacabConnection; + class MacabConnection; class MacabCatalog : public connectivity::sdbcx::OCatalog { @@ -49,9 +46,6 @@ namespace connectivity virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTables( ) override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABCATALOG_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/macab/MacabColumns.cxx b/connectivity/source/drivers/macab/MacabColumns.cxx index 6eaa51aa7906..6a49ad1d066c 100644 --- a/connectivity/source/drivers/macab/MacabColumns.cxx +++ b/connectivity/source/drivers/macab/MacabColumns.cxx @@ -54,7 +54,7 @@ sdbcx::ObjectType MacabColumns::createObject(const OUString& _rName) { if (xRow->getString(4) == _rName) { - OColumn* pRet = new OColumn( + xRet = new OColumn( _rName, xRow->getString(6), xRow->getString(13), @@ -70,7 +70,6 @@ sdbcx::ObjectType MacabColumns::createObject(const OUString& _rName) sCatalogName, sSchemaName, sTableName); - xRet = pRet; break; } } diff --git a/connectivity/source/drivers/macab/MacabColumns.hxx b/connectivity/source/drivers/macab/MacabColumns.hxx index 36da039a9ffc..7123af89d30a 100644 --- a/connectivity/source/drivers/macab/MacabColumns.hxx +++ b/connectivity/source/drivers/macab/MacabColumns.hxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABCOLUMNS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABCOLUMNS_HXX +#pragma once #include "MacabTable.hxx" #include <connectivity/sdbcx/VCollection.hxx> -namespace connectivity +namespace connectivity::macab { - namespace macab - { class MacabColumns : public sdbcx::OCollection { protected: @@ -40,9 +37,6 @@ namespace connectivity ::osl::Mutex& _rMutex, const ::std::vector< OUString> &_rVector); }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABCOLUMNS_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/macab/MacabConnection.cxx b/connectivity/source/drivers/macab/MacabConnection.cxx index 4e5a27354e54..eaa6cf523222 100644 --- a/connectivity/source/drivers/macab/MacabConnection.cxx +++ b/connectivity/source/drivers/macab/MacabConnection.cxx @@ -27,6 +27,7 @@ #include "MacabCatalog.hxx" #include <com/sun/star/sdbc/ColumnValue.hpp> #include <com/sun/star/sdbc/TransactionIsolation.hpp> +#include <cppuhelper/weak.hxx> using namespace connectivity::macab; using namespace com::sun::star::uno; @@ -295,8 +296,7 @@ Reference< XTablesSupplier > MacabConnection::createCatalog() Reference< XTablesSupplier > xTab = m_xCatalog; if (!m_xCatalog.is()) { - MacabCatalog *pCat = new MacabCatalog(this); - xTab = pCat; + xTab = new MacabCatalog(this); m_xCatalog = xTab; } return xTab; @@ -309,10 +309,8 @@ MacabAddressBook* MacabConnection::getAddressBook() const extern "C" SAL_DLLPUBLIC_EXPORT void* createMacabConnection( void* _pDriver ) { - MacabConnection* pConnection = new MacabConnection( static_cast< MacabDriver* >( _pDriver ) ); // by definition, the pointer crossing library boundaries as void ptr is acquired once - pConnection->acquire(); - return pConnection; + return cppu::acquire(new MacabConnection( static_cast< MacabDriver* >( _pDriver ) )); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/macab/MacabConnection.hxx b/connectivity/source/drivers/macab/MacabConnection.hxx index 6173b26dc5f4..dc2bfa34f5fd 100644 --- a/connectivity/source/drivers/macab/MacabConnection.hxx +++ b/connectivity/source/drivers/macab/MacabConnection.hxx @@ -17,23 +17,18 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABCONNECTION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABCONNECTION_HXX +#pragma once -#include <map> #include <connectivity/CommonTools.hxx> #include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/sdbc/SQLWarning.hpp> #include <com/sun/star/sdbc/XWarningsSupplier.hpp> #include <com/sun/star/sdbc/XConnection.hpp> #include <com/sun/star/sdbcx/XTablesSupplier.hpp> #include <cppuhelper/compbase.hxx> #include <TConnection.hxx> -namespace connectivity +namespace connectivity::macab { - namespace macab - { typedef ::cppu::WeakComponentImplHelper<css::sdbc::XConnection, css::sdbc::XWarningsSupplier, @@ -110,9 +105,6 @@ namespace connectivity MacabDriver* getDriver() const { return m_pDriver;} MacabAddressBook* getAddressBook() const; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABCONNECTION_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/macab/MacabDatabaseMetaData.cxx b/connectivity/source/drivers/macab/MacabDatabaseMetaData.cxx index 809537c2316b..b0b04fc08f21 100644 --- a/connectivity/source/drivers/macab/MacabDatabaseMetaData.cxx +++ b/connectivity/source/drivers/macab/MacabDatabaseMetaData.cxx @@ -30,7 +30,9 @@ #include <com/sun/star/sdbc/ColumnSearch.hpp> #include <com/sun/star/sdbc/ColumnValue.hpp> #include <com/sun/star/sdbc/ResultSetType.hpp> +#include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/sdbc/TransactionIsolation.hpp> +#include <rtl/ref.hxx> #include <vector> @@ -729,17 +731,16 @@ sal_Bool SAL_CALL MacabDatabaseMetaData::supportsBatchUpdates( ) Reference< XConnection > SAL_CALL MacabDatabaseMetaData::getConnection( ) { - return m_xConnection.get(); + return m_xConnection; } Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTableTypes( ) { - ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTableTypes); - Reference< XResultSet > xRef = pResult; + rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTableTypes); - static ODatabaseMetaDataResultSet::ORows aRows = [&] + static ODatabaseMetaDataResultSet::ORows aRows = [] { - static const char aTable[] = "TABLE"; + static constexpr OUStringLiteral aTable = u"TABLE"; ODatabaseMetaDataResultSet::ORows tmp; ODatabaseMetaDataResultSet::ORow aRow(2); aRow[0] = ODatabaseMetaDataResultSet::getEmptyValue(); @@ -747,16 +748,15 @@ Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTableTypes( ) tmp.push_back(aRow); return tmp; }(); - pResult->setRows(aRows); - return xRef; + pResult->setRows(std::vector(aRows)); + return pResult; } Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTypeInfo( ) { - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTypeInfo); - Reference< XResultSet > xRef = pResult; + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTypeInfo); - static ODatabaseMetaDataResultSet::ORows aRows = [&]() + static ODatabaseMetaDataResultSet::ORows aRows = []() { ODatabaseMetaDataResultSet::ORows tmp; ODatabaseMetaDataResultSet::ORow aRow(19); @@ -805,8 +805,8 @@ Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTypeInfo( ) return tmp; }(); - pResult->setRows(aRows); - return xRef; + pResult->setRows(std::vector(aRows)); + return pResult; } Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getCatalogs( ) @@ -832,8 +832,7 @@ Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getColumns( const OUString& tableNamePattern, const OUString& columnNamePattern) { - ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns); - Reference< XResultSet > xRef = pResult; + rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns); MacabRecords *aRecords; OUString sTableName; @@ -909,8 +908,8 @@ Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getColumns( } } } - pResult->setRows(aRows); - return xRef; + pResult->setRows(std::move(aRows)); + return pResult; } Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTables( @@ -919,13 +918,12 @@ Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTables( const OUString&, const Sequence< OUString >& types) { - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTables); - Reference< XResultSet > xRef = pResult; + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTables); // check whether we have tables in the requested types // for the moment, we answer only the "TABLE" table type // when no types are given at all, we return all the tables - static const char aTable[] = "TABLE"; + static constexpr OUString aTable = u"TABLE"_ustr; bool bTableFound = false; const OUString* p = types.getConstArray(), * pEnd = p + types.getLength(); @@ -944,7 +942,7 @@ Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTables( p++; } if (!bTableFound) - return xRef; + return pResult; static ODatabaseMetaDataResultSet::ORows aRows = [&]() { @@ -960,7 +958,7 @@ Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTables( aRow[1] = ODatabaseMetaDataResultSet::getEmptyValue(); aRow[2] = ODatabaseMetaDataResultSet::getEmptyValue(); aRow[3] = new ORowSetValueDecorator(xRecords->getName()); - aRow[4] = new ORowSetValueDecorator(OUString(aTable)); + aRow[4] = new ORowSetValueDecorator(aTable); aRow[5] = ODatabaseMetaDataResultSet::getEmptyValue(); tmp.push_back(aRow); @@ -971,8 +969,8 @@ Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTables( } return tmp; }(); - pResult->setRows(aRows); - return xRef; + pResult->setRows(std::vector(aRows)); + return pResult; } Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getProcedureColumns( @@ -992,8 +990,7 @@ Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getProcedures( Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getVersionColumns( const Any&, const OUString&, const OUString& table ) { - ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eVersionColumns); - Reference< XResultSet > xRef = pResult; + rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eVersionColumns); ODatabaseMetaDataResultSet::ORows aRows; @@ -1016,8 +1013,8 @@ Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getVersionColumns( aRows.push_back(aRow); } - pResult->setRows(aRows); - return xRef; + pResult->setRows(std::move(aRows)); + return pResult; } Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getExportedKeys( diff --git a/connectivity/source/drivers/macab/MacabDatabaseMetaData.hxx b/connectivity/source/drivers/macab/MacabDatabaseMetaData.hxx index c1c9feb5cc06..662be1c018ce 100644 --- a/connectivity/source/drivers/macab/MacabDatabaseMetaData.hxx +++ b/connectivity/source/drivers/macab/MacabDatabaseMetaData.hxx @@ -17,17 +17,14 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABDATABASEMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABDATABASEMETADATA_HXX +#pragma once #include "MacabConnection.hxx" #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> #include <cppuhelper/implbase.hxx> -namespace connectivity +namespace connectivity::macab { - namespace macab - { class MacabDatabaseMetaData : public ::cppu::WeakImplHelper< css::sdbc::XDatabaseMetaData> { @@ -193,9 +190,6 @@ namespace connectivity virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getUDTs( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& typeNamePattern, const css::uno::Sequence< sal_Int32 >& types ) override; virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( ) override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABDATABASEMETADATA_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/macab/MacabDriver.cxx b/connectivity/source/drivers/macab/MacabDriver.cxx index ee3d55407aa9..9c68e48f12a7 100644 --- a/connectivity/source/drivers/macab/MacabDriver.cxx +++ b/connectivity/source/drivers/macab/MacabDriver.cxx @@ -25,9 +25,8 @@ #include <com/sun/star/lang/NullPointerException.hpp> #include <com/sun/star/frame/Desktop.hpp> #include <sal/log.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <strings.hrc> -#include <comphelper/processfactory.hxx> #include <cppuhelper/supportsservice.hxx> using namespace com::sun::star::uno; @@ -116,7 +115,7 @@ bool MacabImplModule::impl_loadModule() OSL_ENSURE( !m_hConnectorModule && !m_pConnectionFactoryFunc, "MacabImplModule::impl_loadModule: inconsistence: inconsistency (never attempted load before, but some values already set)!"); - const OUString sModuleName( SAL_MODULENAME( "macabdrv1" ) ); + constexpr OUString sModuleName( u"" SAL_MODULENAME( "macabdrv1" ) ""_ustr ); m_hConnectorModule = osl_loadModuleRelative( &thisModule, sModuleName.pData, SAL_LOADMODULE_NOW ); // LAZY! #i61335# OSL_ENSURE( m_hConnectorModule, "MacabImplModule::impl_loadModule: could not load the implementation library!" ); if ( !m_hConnectorModule ) diff --git a/connectivity/source/drivers/macab/MacabDriver.hxx b/connectivity/source/drivers/macab/MacabDriver.hxx index 4c9412c9642a..d18f5e9827f4 100644 --- a/connectivity/source/drivers/macab/MacabDriver.hxx +++ b/connectivity/source/drivers/macab/MacabDriver.hxx @@ -17,12 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABDRIVER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABDRIVER_HXX +#pragma once #include <com/sun/star/sdbc/XDriver.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/frame/XTerminateListener.hpp> #include <com/sun/star/uno/XComponentContext.hpp> #include <cppuhelper/compbase.hxx> @@ -33,10 +31,8 @@ #define MACAB_DRIVER_VERSION_MAJOR 0 #define MACAB_DRIVER_VERSION_MINOR 1 -namespace connectivity +namespace connectivity::macab { - namespace macab - { class MacabConnection; class MacabDriver; @@ -159,10 +155,7 @@ namespace connectivity */ void impl_shutdownImplementationModule(); }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABDRIVER_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/macab/MacabGroup.hxx b/connectivity/source/drivers/macab/MacabGroup.hxx index 4d9313282a25..ddcd47b46423 100644 --- a/connectivity/source/drivers/macab/MacabGroup.hxx +++ b/connectivity/source/drivers/macab/MacabGroup.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABGROUP_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABGROUP_HXX +#pragma once #include "MacabRecords.hxx" @@ -28,17 +27,12 @@ #include <postmac.h> -namespace connectivity +namespace connectivity::macab { - namespace macab - { class MacabGroup: public MacabRecords { public: MacabGroup(const ABAddressBookRef _addressBook, const MacabRecords *_allRecords, const ABGroupRef _xGroup); }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABGROUP_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/macab/MacabHeader.cxx b/connectivity/source/drivers/macab/MacabHeader.cxx index dc83d9c3dec8..da270dd05ac8 100644 --- a/connectivity/source/drivers/macab/MacabHeader.cxx +++ b/connectivity/source/drivers/macab/MacabHeader.cxx @@ -263,7 +263,7 @@ sal_Int32 MacabHeader::compareFields(const macabfield *_field1, const macabfield } -sal_Int32 MacabHeader::getColumnNumber(const OUString& s) const +sal_Int32 MacabHeader::getColumnNumber(std::u16string_view s) const { sal_Int32 i; for(i = 0; i < size; i++) @@ -290,10 +290,6 @@ MacabHeader::iterator::iterator () } -MacabHeader::iterator::~iterator () -{ -} - MacabHeader::iterator& MacabHeader::iterator::operator= (MacabHeader *_record) { id = 0; diff --git a/connectivity/source/drivers/macab/MacabHeader.hxx b/connectivity/source/drivers/macab/MacabHeader.hxx index c77ae2da0c0a..24b3fc7b0b9c 100644 --- a/connectivity/source/drivers/macab/MacabHeader.hxx +++ b/connectivity/source/drivers/macab/MacabHeader.hxx @@ -17,15 +17,16 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABHEADER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABHEADER_HXX +#pragma once + +#include <sal/config.h> + +#include <string_view> #include "MacabRecord.hxx" -namespace connectivity +namespace connectivity::macab { - namespace macab - { class MacabHeader: public MacabRecord{ protected: macabfield **sortRecord(sal_Int32 _start, sal_Int32 _length); @@ -36,7 +37,7 @@ namespace connectivity void operator+= (const MacabHeader *r); OUString getString(const sal_Int32 i) const; void sortRecord(); - sal_Int32 getColumnNumber(const OUString& s) const; + sal_Int32 getColumnNumber(std::u16string_view s) const; static sal_Int32 compareFields(const macabfield *_field1, const macabfield *_field2); @@ -49,16 +50,12 @@ namespace connectivity public: iterator& operator= (MacabHeader *_record); iterator(); - ~iterator(); void operator++ (); bool operator!= (const sal_Int32 i) const; bool operator== (const sal_Int32 i) const; macabfield *operator* () const; }; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABHEADER_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/macab/MacabPreparedStatement.cxx b/connectivity/source/drivers/macab/MacabPreparedStatement.cxx index cbb3dc75608c..6d72345b6021 100644 --- a/connectivity/source/drivers/macab/MacabPreparedStatement.cxx +++ b/connectivity/source/drivers/macab/MacabPreparedStatement.cxx @@ -78,7 +78,7 @@ void MacabPreparedStatement::getNextParameter(OUString &rParameter) const ::dbtools::throwGenericSQLException(sError,*const_cast<MacabPreparedStatement *>(this)); } - rParameter = (*m_aParameterRow)[m_nParameterIndex]; + rParameter = (*m_aParameterRow)[m_nParameterIndex].getString(); m_nParameterIndex++; } @@ -131,7 +131,7 @@ Reference< XResultSetMetaData > SAL_CALL MacabPreparedStatement::getMetaData() m_xMetaData = new MacabResultSetMetaData(getOwnConnection(),sTableName); setMacabFields(); } - Reference< XResultSetMetaData > xMetaData = m_xMetaData.get(); + Reference< XResultSetMetaData > xMetaData = m_xMetaData; return xMetaData; } diff --git a/connectivity/source/drivers/macab/MacabPreparedStatement.hxx b/connectivity/source/drivers/macab/MacabPreparedStatement.hxx index a37c1b29a8a4..6e649bf647f3 100644 --- a/connectivity/source/drivers/macab/MacabPreparedStatement.hxx +++ b/connectivity/source/drivers/macab/MacabPreparedStatement.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABPREPAREDSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABPREPAREDSTATEMENT_HXX +#pragma once #include "MacabStatement.hxx" #include "MacabResultSetMetaData.hxx" @@ -27,10 +26,8 @@ #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> #include <cppuhelper/implbase.hxx> -namespace connectivity +namespace connectivity::macab { - namespace macab - { typedef ::cppu::ImplInheritanceHelper< MacabCommonStatement, css::sdbc::XPreparedStatement, css::sdbc::XParameters, @@ -109,9 +106,6 @@ namespace connectivity // XResultSetMetaDataSupplier virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABPREPAREDSTATEMENT_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/macab/MacabRecord.hxx b/connectivity/source/drivers/macab/MacabRecord.hxx index e677611bdec8..5184eefc8ab4 100644 --- a/connectivity/source/drivers/macab/MacabRecord.hxx +++ b/connectivity/source/drivers/macab/MacabRecord.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABRECORD_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABRECORD_HXX +#pragma once #include <sal/config.h> @@ -33,10 +32,8 @@ #include <AddressBook/ABAddressBookC.h> #include <postmac.h> -namespace connectivity +namespace connectivity::macab { - namespace macab - { /* a MacabRecord is at root a list of macabfields (which is just * something to hold both a CFTypeRef (a CoreFoundation object) and * its Address Book type. @@ -69,9 +66,6 @@ namespace connectivity static OUString fieldToString(const macabfield *_aField); }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABRECORD_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/macab/MacabRecords.cxx b/connectivity/source/drivers/macab/MacabRecords.cxx index 0bc27ea0ee6f..07d462425e65 100644 --- a/connectivity/source/drivers/macab/MacabRecords.cxx +++ b/connectivity/source/drivers/macab/MacabRecords.cxx @@ -244,7 +244,8 @@ macabfield *MacabRecords::getField(const sal_Int32 _recordNumber, const sal_Int3 } -macabfield *MacabRecords::getField(const sal_Int32 _recordNumber, const OUString& _columnName) const +macabfield *MacabRecords::getField(const sal_Int32 _recordNumber, std::u16string_view _columnName) + const { if(header != nullptr) { @@ -262,7 +263,7 @@ macabfield *MacabRecords::getField(const sal_Int32 _recordNumber, const OUString } -sal_Int32 MacabRecords::getFieldNumber(const OUString& _columnName) const +sal_Int32 MacabRecords::getFieldNumber(std::u16string_view _columnName) const { if(header != nullptr) return header->getColumnNumber(_columnName); @@ -343,7 +344,7 @@ MacabHeader *MacabRecords::createHeaderForRecordType(const CFArrayRef _records, /* While searching through the properties for required properties, these * sal_Bools will keep track of what we have found. */ - bool bFoundRequiredProperties[requiredProperties.size()]; + auto const bFoundRequiredProperties = std::make_unique<bool[]>(requiredProperties.size()); /* We have three MacabHeaders: headerDataForProperty is where we @@ -529,34 +530,34 @@ MacabHeader *MacabRecords::createHeaderForProperty(const ABPropertyType _propert */ if(_propertyValue != nullptr) { - sal_Int32 i; + sal_Int32 i; - sal_Int32 multiLength = ABMultiValueCount(static_cast<ABMutableMultiValueRef>(const_cast<void *>(_propertyValue))); - CFStringRef multiLabel, localizedMultiLabel; - OUString multiLabelString; - OUString multiPropertyString; - OUString headerNameString; - ABPropertyType multiType = static_cast<ABPropertyType>(ABMultiValuePropertyType(static_cast<ABMutableMultiValueRef>(const_cast<void *>(_propertyValue))) - 0x100); + sal_Int32 multiLength = ABMultiValueCount(static_cast<ABMutableMultiValueRef>(const_cast<void *>(_propertyValue))); + CFStringRef multiLabel, localizedMultiLabel; + OUString multiLabelString; + OUString multiPropertyString; + OUString headerNameString; + ABPropertyType multiType = static_cast<ABPropertyType>(ABMultiValuePropertyType(static_cast<ABMutableMultiValueRef>(const_cast<void *>(_propertyValue))) - 0x100); - length = multiLength; - headerNames = new macabfield *[multiLength]; - multiPropertyString = CFStringToOUString(_propertyName); + length = multiLength; + headerNames = new macabfield *[multiLength]; + multiPropertyString = CFStringToOUString(_propertyName); - /* Go through each element, and - since each element is a scalar - - * just create a new macabfield for it. - */ - for(i = 0; i < multiLength; i++) - { - multiLabel = ABMultiValueCopyLabelAtIndex(static_cast<ABMutableMultiValueRef>(const_cast<void *>(_propertyValue)), i); - localizedMultiLabel = ABCopyLocalizedPropertyOrLabel(multiLabel); - multiLabelString = CFStringToOUString(localizedMultiLabel); - CFRelease(multiLabel); - CFRelease(localizedMultiLabel); - headerNameString = multiPropertyString + ": " + fixLabel(multiLabelString); - headerNames[i] = new macabfield; - headerNames[i]->value = OUStringToCFString(headerNameString); - headerNames[i]->type = multiType; - } + /* Go through each element, and - since each element is a scalar - + * just create a new macabfield for it. + */ + for(i = 0; i < multiLength; i++) + { + multiLabel = ABMultiValueCopyLabelAtIndex(static_cast<ABMutableMultiValueRef>(const_cast<void *>(_propertyValue)), i); + localizedMultiLabel = ABCopyLocalizedPropertyOrLabel(multiLabel); + multiLabelString = CFStringToOUString(localizedMultiLabel); + CFRelease(multiLabel); + CFRelease(localizedMultiLabel); + headerNameString = multiPropertyString + ": " + fixLabel(multiLabelString); + headerNames[i] = new macabfield; + headerNames[i]->value = OUStringToCFString(headerNameString); + headerNames[i]->type = multiType; + } } break; @@ -652,77 +653,77 @@ MacabHeader *MacabRecords::createHeaderForProperty(const ABPropertyType _propert */ if(_propertyValue != nullptr) { - /* Assume all keys are strings */ - sal_Int32 numRecords = static_cast<sal_Int32>(CFDictionaryGetCount(static_cast<CFDictionaryRef>(_propertyValue))); + /* Assume all keys are strings */ + sal_Int32 numRecords = static_cast<sal_Int32>(CFDictionaryGetCount(static_cast<CFDictionaryRef>(_propertyValue))); - /* The only method for getting info out of a CFDictionary, of both - * keys and values, is to all of them all at once, so these - * variables will hold them. - */ - CFStringRef *dictKeys; - CFTypeRef *dictValues; - - sal_Int32 i,j,k; - OUString dictKeyString, propertyNameString; - ABPropertyType dictType; - MacabHeader **dictHeaders = new MacabHeader *[numRecords]; - OUString dictLabelString; - CFStringRef dictLabel, localizedDictKey; - - /* Get the keys and values */ - dictKeys = static_cast<CFStringRef *>(malloc(sizeof(CFStringRef)*numRecords)); - dictValues = static_cast<CFTypeRef *>(malloc(sizeof(CFTypeRef)*numRecords)); - CFDictionaryGetKeysAndValues(static_cast<CFDictionaryRef>(_propertyValue), reinterpret_cast<const void **>(dictKeys), dictValues); - - propertyNameString = CFStringToOUString(_propertyName); - - length = 0; - /* Go through each element - assuming that the key is a string but - * that the value could be anything. Since the value could be - * anything, we can't assume that it is scalar (it could even be - * another dictionary), so we attempt to get its type using - * the method getABTypeFromCFType and then run this method - * recursively on that element, storing the MacabHeader that - * results. Then, we just combine all of the MacabHeaders into - * one. - */ - for(i = 0; i < numRecords; i++) - { - dictType = getABTypeFromCFType( CFGetTypeID(dictValues[i]) ); - localizedDictKey = ABCopyLocalizedPropertyOrLabel(dictKeys[i]); - dictKeyString = CFStringToOUString(localizedDictKey); - dictLabelString = propertyNameString + ": " + fixLabel(dictKeyString); - dictLabel = OUStringToCFString(dictLabelString); - dictHeaders[i] = createHeaderForProperty(dictType, dictValues[i], dictLabel); - if (!dictHeaders[i]) - dictHeaders[i] = new MacabHeader(); - length += dictHeaders[i]->getSize(); - CFRelease(dictLabel); - CFRelease(localizedDictKey); - } + /* The only method for getting info out of a CFDictionary, of both + * keys and values, is to all of them all at once, so these + * variables will hold them. + */ + CFStringRef *dictKeys; + CFTypeRef *dictValues; - /* Combine all of the macabfields in each MacabHeader into the - * headerNames array, which (at the end of this method) is used - * to create the MacabHeader that is returned. - */ - headerNames = new macabfield *[length]; - for(i = 0, j = 0, k = 0; i < length; i++,k++) - { - while(dictHeaders[j]->getSize() == k) + sal_Int32 i,j,k; + OUString dictKeyString, propertyNameString; + ABPropertyType dictType; + MacabHeader **dictHeaders = new MacabHeader *[numRecords]; + OUString dictLabelString; + CFStringRef dictLabel, localizedDictKey; + + /* Get the keys and values */ + dictKeys = static_cast<CFStringRef *>(malloc(sizeof(CFStringRef)*numRecords)); + dictValues = static_cast<CFTypeRef *>(malloc(sizeof(CFTypeRef)*numRecords)); + CFDictionaryGetKeysAndValues(static_cast<CFDictionaryRef>(_propertyValue), reinterpret_cast<const void **>(dictKeys), dictValues); + + propertyNameString = CFStringToOUString(_propertyName); + + length = 0; + /* Go through each element - assuming that the key is a string but + * that the value could be anything. Since the value could be + * anything, we can't assume that it is scalar (it could even be + * another dictionary), so we attempt to get its type using + * the method getABTypeFromCFType and then run this method + * recursively on that element, storing the MacabHeader that + * results. Then, we just combine all of the MacabHeaders into + * one. + */ + for(i = 0; i < numRecords; i++) { - j++; - k = 0; + dictType = getABTypeFromCFType( CFGetTypeID(dictValues[i]) ); + localizedDictKey = ABCopyLocalizedPropertyOrLabel(dictKeys[i]); + dictKeyString = CFStringToOUString(localizedDictKey); + dictLabelString = propertyNameString + ": " + fixLabel(dictKeyString); + dictLabel = OUStringToCFString(dictLabelString); + dictHeaders[i] = createHeaderForProperty(dictType, dictValues[i], dictLabel); + if (!dictHeaders[i]) + dictHeaders[i] = new MacabHeader(); + length += dictHeaders[i]->getSize(); + CFRelease(dictLabel); + CFRelease(localizedDictKey); } - headerNames[i] = dictHeaders[j]->copy(k); - } + /* Combine all of the macabfields in each MacabHeader into the + * headerNames array, which (at the end of this method) is used + * to create the MacabHeader that is returned. + */ + headerNames = new macabfield *[length]; + for(i = 0, j = 0, k = 0; i < length; i++,k++) + { + while(dictHeaders[j]->getSize() == k) + { + j++; + k = 0; + } - for(i = 0; i < numRecords; i++) - delete dictHeaders[i]; + headerNames[i] = dictHeaders[j]->copy(k); + } - delete [] dictHeaders; - free(dictKeys); - free(dictValues); + for(i = 0; i < numRecords; i++) + delete dictHeaders[i]; + + delete [] dictHeaders; + free(dictKeys); + free(dictValues); } break; @@ -1098,11 +1099,6 @@ MacabRecords::iterator::iterator () } -MacabRecords::iterator::~iterator () -{ -} - - MacabRecords::iterator& MacabRecords::iterator::operator= (MacabRecords *_records) { id = 0; diff --git a/connectivity/source/drivers/macab/MacabRecords.hxx b/connectivity/source/drivers/macab/MacabRecords.hxx index 1e7d9975de15..8d0d5cf6f796 100644 --- a/connectivity/source/drivers/macab/MacabRecords.hxx +++ b/connectivity/source/drivers/macab/MacabRecords.hxx @@ -17,11 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABRECORDS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABRECORDS_HXX +#pragma once #include <sal/config.h> +#include <string_view> #include <vector> #include "MacabRecord.hxx" @@ -33,10 +33,8 @@ #include <postmac.h> #include <com/sun/star/util/DateTime.hpp> -namespace connectivity +namespace connectivity::macab { - namespace macab - { /* This struct is for converting CF types to AB types (Core Foundation * types to Address Book types). */ @@ -98,8 +96,8 @@ namespace connectivity void swap(const sal_Int32 _id1, const sal_Int32 _id2); macabfield *getField(const sal_Int32 _recordNumber, const sal_Int32 _columnNumber) const; - macabfield *getField(const sal_Int32 _recordNumber, const OUString& _columnName) const; - sal_Int32 getFieldNumber(const OUString& _columnName) const; + macabfield *getField(const sal_Int32 _recordNumber, std::u16string_view _columnName) const; + sal_Int32 getFieldNumber(std::u16string_view _columnName) const; sal_Int32 size() const; @@ -115,7 +113,6 @@ namespace connectivity sal_Int32 id; iterator& operator= (MacabRecords *_records); iterator(); - ~iterator(); void operator++ (); bool operator!= (const sal_Int32 i) const; bool operator== (const sal_Int32 i) const; @@ -123,9 +120,6 @@ namespace connectivity }; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABRECORDS_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/macab/MacabResultSet.cxx b/connectivity/source/drivers/macab/MacabResultSet.cxx index 7b0911223d7f..4142fcb6cce0 100644 --- a/connectivity/source/drivers/macab/MacabResultSet.cxx +++ b/connectivity/source/drivers/macab/MacabResultSet.cxx @@ -33,6 +33,7 @@ #include <comphelper/types.hxx> #include <connectivity/dbexception.hxx> #include <resource/sharedresources.hxx> +#include <rtl/ref.hxx> #include <strings.hrc> using namespace connectivity::macab; @@ -64,14 +65,14 @@ MacabResultSet::~MacabResultSet() void MacabResultSet::allMacabRecords() { - MacabConnection* pConnection = static_cast< MacabConnection *>(m_xStatement->getConnection().get()); + rtl::Reference<MacabConnection> pConnection = static_cast< MacabConnection *>(m_xStatement->getConnection().get()); m_aMacabRecords = pConnection->getAddressBook()->getMacabRecords(m_sTableName); } void MacabResultSet::someMacabRecords(const MacabCondition *pCondition) { - MacabConnection* pConnection = static_cast< MacabConnection *>(m_xStatement->getConnection().get()); + rtl::Reference<MacabConnection> pConnection = static_cast< MacabConnection *>(m_xStatement->getConnection().get()); MacabRecords* allRecords; allRecords = pConnection->getAddressBook()->getMacabRecords(m_sTableName); @@ -156,12 +157,12 @@ Any SAL_CALL MacabResultSet::queryInterface(const Type & rType) return aRet; } -void SAL_CALL MacabResultSet::acquire() throw() +void SAL_CALL MacabResultSet::acquire() noexcept { MacabResultSet_BASE::acquire(); } -void SAL_CALL MacabResultSet::release() throw() +void SAL_CALL MacabResultSet::release() noexcept { MacabResultSet_BASE::release(); } @@ -513,7 +514,7 @@ Reference< XResultSetMetaData > SAL_CALL MacabResultSet::getMetaData() if (!m_xMetaData.is()) m_xMetaData = new MacabResultSetMetaData(m_xStatement->getOwnConnection(), m_sTableName); - Reference< XResultSetMetaData > xMetaData = m_xMetaData.get(); + Reference< XResultSetMetaData > xMetaData = m_xMetaData; return xMetaData; } @@ -668,7 +669,7 @@ Reference< XInterface > SAL_CALL MacabResultSet::getStatement() ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(MacabResultSet_BASE::rBHelper.bDisposed); - Reference< XStatement > xStatement = m_xStatement.get(); + Reference< XStatement > xStatement = m_xStatement; return xStatement; } @@ -879,12 +880,12 @@ Any SAL_CALL MacabResultSet::getBookmark() if (m_nRowPos != -1 && m_nRowPos != nRecords) { - macabfield *uidField = m_aMacabRecords->getField(m_nRowPos,OUString("UID")); + macabfield *uidField = m_aMacabRecords->getField(m_nRowPos,u"UID"); if(uidField != nullptr) { if(uidField->type == kABStringProperty) { - return makeAny(CFStringToOUString( static_cast<CFStringRef>(uidField->value) )); + return Any(CFStringToOUString( static_cast<CFStringRef>(uidField->value) )); } } } @@ -901,7 +902,7 @@ sal_Bool SAL_CALL MacabResultSet::moveToBookmark(const Any& bookmark) for (sal_Int32 nRow = 0; nRow < nRecords; nRow++) { - macabfield *uidField = m_aMacabRecords->getField(m_nRowPos,OUString("UID")); + macabfield *uidField = m_aMacabRecords->getField(m_nRowPos,u"UID"); if(uidField != nullptr) { if(uidField->type == kABStringProperty) @@ -980,28 +981,47 @@ Sequence< sal_Int32 > SAL_CALL MacabResultSet::deleteRows(const Sequence< Any IPropertyArrayHelper* MacabResultSet::createArrayHelper() const { - Sequence< Property > aProps(6); - Property* pProperties = aProps.getArray(); - sal_Int32 nPos = 0; - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), - PROPERTY_ID_CURSORNAME, cppu::UnoType<OUString>::get(), PropertyAttribute::READONLY); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), - PROPERTY_ID_FETCHDIRECTION, cppu::UnoType<sal_Int32>::get(), 0); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), - PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE), - PROPERTY_ID_ISBOOKMARKABLE, cppu::UnoType<bool>::get(), PropertyAttribute::READONLY); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), - PROPERTY_ID_RESULTSETCONCURRENCY, cppu::UnoType<sal_Int32>::get(), PropertyAttribute::READONLY); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), - PROPERTY_ID_RESULTSETTYPE, cppu::UnoType<sal_Int32>::get(), PropertyAttribute::READONLY); - - return new OPropertyArrayHelper(aProps); + return new OPropertyArrayHelper + { + { + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), + PROPERTY_ID_CURSORNAME, + cppu::UnoType<OUString>::get(), + PropertyAttribute::READONLY + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), + PROPERTY_ID_FETCHDIRECTION, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), + PROPERTY_ID_FETCHSIZE, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE), + PROPERTY_ID_ISBOOKMARKABLE, + cppu::UnoType<bool>::get(), + PropertyAttribute::READONLY + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), + PROPERTY_ID_RESULTSETCONCURRENCY, + cppu::UnoType<sal_Int32>::get(), + PropertyAttribute::READONLY + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), + PROPERTY_ID_RESULTSETTYPE, + cppu::UnoType<sal_Int32>::get(), + PropertyAttribute::READONLY + } + } + }; } IPropertyArrayHelper & MacabResultSet::getInfoHelper() diff --git a/connectivity/source/drivers/macab/MacabResultSet.hxx b/connectivity/source/drivers/macab/MacabResultSet.hxx index 418a66c1f5b6..306ef562d3b4 100644 --- a/connectivity/source/drivers/macab/MacabResultSet.hxx +++ b/connectivity/source/drivers/macab/MacabResultSet.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABRESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABRESULTSET_HXX +#pragma once #include "MacabStatement.hxx" #include "MacabResultSetMetaData.hxx" @@ -32,10 +31,8 @@ #include <cppuhelper/compbase.hxx> #include <cppuhelper/basemutex.hxx> -namespace connectivity +namespace connectivity::macab { - namespace macab - { /* ** MacabResultSet */ @@ -107,8 +104,8 @@ namespace connectivity // XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; // XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; @@ -211,9 +208,6 @@ namespace connectivity // XDeleteRows virtual css::uno::Sequence< sal_Int32 > SAL_CALL deleteRows( const css::uno::Sequence< css::uno::Any >& rows ) override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABRESULTSET_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/macab/MacabResultSetMetaData.cxx b/connectivity/source/drivers/macab/MacabResultSetMetaData.cxx index 38e7dca051d4..e08d92cfceb6 100644 --- a/connectivity/source/drivers/macab/MacabResultSetMetaData.cxx +++ b/connectivity/source/drivers/macab/MacabResultSetMetaData.cxx @@ -23,6 +23,7 @@ #include "MacabRecords.hxx" #include "MacabAddressBook.hxx" #include "macabutilities.hxx" +#include <connectivity/dbexception.hxx> #include <strings.hrc> using namespace connectivity::macab; @@ -43,7 +44,7 @@ MacabResultSetMetaData::~MacabResultSetMetaData() void MacabResultSetMetaData::setMacabFields(const ::rtl::Reference<connectivity::OSQLColumns> &xColumns) { - static const char aName[] = "Name"; + static constexpr OUStringLiteral aName = u"Name"; MacabRecords *aRecords; MacabHeader *aHeader; diff --git a/connectivity/source/drivers/macab/MacabResultSetMetaData.hxx b/connectivity/source/drivers/macab/MacabResultSetMetaData.hxx index ec7c2c651dd5..b82088154cb9 100644 --- a/connectivity/source/drivers/macab/MacabResultSetMetaData.hxx +++ b/connectivity/source/drivers/macab/MacabResultSetMetaData.hxx @@ -17,20 +17,16 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABRESULTSETMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABRESULTSETMETADATA_HXX +#pragma once #include "MacabConnection.hxx" #include <connectivity/CommonTools.hxx> #include <com/sun/star/sdbc/XResultSetMetaData.hpp> #include <cppuhelper/implbase.hxx> -#include <connectivity/dbexception.hxx> #include <rtl/ref.hxx> -namespace connectivity +namespace connectivity::macab { - namespace macab - { /* ** MacabResultSetMetaData */ @@ -48,7 +44,7 @@ namespace connectivity MacabResultSetMetaData(MacabConnection* _pConnection, OUString const & _sTableName); // avoid ambiguous cast error from the compiler - operator css::uno::Reference< css::sdbc::XResultSetMetaData > () throw() + operator css::uno::Reference< css::sdbc::XResultSetMetaData > () noexcept { return this; } /// @throws css::sdbc::SQLException @@ -79,9 +75,6 @@ namespace connectivity virtual sal_Bool SAL_CALL isDefinitelyWritable( sal_Int32 column ) override; virtual OUString SAL_CALL getColumnServiceName( sal_Int32 column ) override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABRESULTSETMETADATA_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/macab/MacabStatement.cxx b/connectivity/source/drivers/macab/MacabStatement.cxx index db6e3876b993..95b922ce6bc7 100644 --- a/connectivity/source/drivers/macab/MacabStatement.cxx +++ b/connectivity/source/drivers/macab/MacabStatement.cxx @@ -32,6 +32,7 @@ #include <cppuhelper/typeprovider.hxx> #include <connectivity/dbexception.hxx> #include <resource/sharedresources.hxx> +#include <rtl/ref.hxx> #include <strings.hrc> using namespace connectivity::macab; @@ -44,17 +45,14 @@ using namespace com::sun::star::container; using namespace com::sun::star::io; using namespace com::sun::star::util; -namespace connectivity +namespace connectivity::macab { - namespace macab - { - void impl_throwError(const char* pErrorId) + void impl_throwError(TranslateId pErrorId) { ::connectivity::SharedResources aResources; const OUString sError( aResources.getResourceString(pErrorId) ); ::dbtools::throwGenericSQLException(sError,nullptr); } - } } IMPLEMENT_SERVICE_INFO(MacabStatement, "com.sun.star.sdbc.drivers.MacabStatement", "com.sun.star.sdbc.Statement"); @@ -291,7 +289,7 @@ OUString MacabCommonStatement::getTableName() const void MacabCommonStatement::setMacabFields(MacabResultSet *pResult) const { ::rtl::Reference<connectivity::OSQLColumns> xColumns; // selected columns - MacabResultSetMetaData *pMeta; // meta information - holds the list of AddressBook fields + rtl::Reference<MacabResultSetMetaData> pMeta; // meta information - holds the list of AddressBook fields xColumns = m_aSQLIterator.getSelectColumns(); if (!xColumns.is()) @@ -400,8 +398,7 @@ Reference< XResultSet > SAL_CALL MacabCommonStatement::executeQuery( ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(rBHelper.bDisposed); - MacabResultSet* pResult = new MacabResultSet(this); - Reference< XResultSet > xRS = pResult; + rtl::Reference<MacabResultSet> pResult = new MacabResultSet(this); OUString aErr; m_pParseTree = m_aParser.parseTree(aErr, sql).release(); @@ -431,9 +428,9 @@ Reference< XResultSet > SAL_CALL MacabCommonStatement::executeQuery( pResult->setTableName(sTableName); - setMacabFields(pResult); // SELECT which columns ? - selectRecords(pResult); // WHERE which condition ? - sortRecords(pResult); // ORDER BY which columns ? + setMacabFields(pResult.get()); // SELECT which columns ? + selectRecords(pResult.get()); // WHERE which condition ? + sortRecords(pResult.get()); // ORDER BY which columns ? } // To be continued: DISTINCT // etc... @@ -449,7 +446,7 @@ Reference< XResultSet > SAL_CALL MacabCommonStatement::executeQuery( } m_xResultSet = Reference<XResultSet>(pResult); - return xRS; + return pResult; } Reference< XConnection > SAL_CALL MacabCommonStatement::getConnection( ) @@ -475,7 +472,7 @@ Any SAL_CALL MacabCommonStatement::getWarnings( ) ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(rBHelper.bDisposed); - return makeAny(m_aLastWarning); + return Any(m_aLastWarning); } void SAL_CALL MacabCommonStatement::clearWarnings( ) @@ -490,31 +487,71 @@ void SAL_CALL MacabCommonStatement::clearWarnings( ) { // this properties are defined by the service statement // they must be in alphabetic order - Sequence< Property > aProps(10); - Property* pProperties = aProps.getArray(); - sal_Int32 nPos = 0; - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), - PROPERTY_ID_CURSORNAME, cppu::UnoType<OUString>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ESCAPEPROCESSING), - PROPERTY_ID_ESCAPEPROCESSING, cppu::UnoType<bool>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), - PROPERTY_ID_FETCHDIRECTION, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), - PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXFIELDSIZE), - PROPERTY_ID_MAXFIELDSIZE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXROWS), - PROPERTY_ID_MAXROWS, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_QUERYTIMEOUT), - PROPERTY_ID_QUERYTIMEOUT, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), - PROPERTY_ID_RESULTSETCONCURRENCY, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), - PROPERTY_ID_RESULTSETTYPE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_USEBOOKMARKS), - PROPERTY_ID_USEBOOKMARKS, cppu::UnoType<bool>::get(), 0); - - return new ::cppu::OPropertyArrayHelper(aProps); + return new ::cppu::OPropertyArrayHelper + { + { + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), + PROPERTY_ID_CURSORNAME, + cppu::UnoType<OUString>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ESCAPEPROCESSING), + PROPERTY_ID_ESCAPEPROCESSING, + cppu::UnoType<bool>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), + PROPERTY_ID_FETCHDIRECTION, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), + PROPERTY_ID_FETCHSIZE, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXFIELDSIZE), + PROPERTY_ID_MAXFIELDSIZE, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXROWS), + PROPERTY_ID_MAXROWS, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_QUERYTIMEOUT), + PROPERTY_ID_QUERYTIMEOUT, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), + PROPERTY_ID_RESULTSETCONCURRENCY, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), + PROPERTY_ID_RESULTSETTYPE, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_USEBOOKMARKS), + PROPERTY_ID_USEBOOKMARKS, + cppu::UnoType<bool>::get(), + 0 + } + } + }; } ::cppu::IPropertyArrayHelper & MacabCommonStatement::getInfoHelper() @@ -571,12 +608,12 @@ void MacabCommonStatement::getFastPropertyValue(Any&,sal_Int32 nHandle) const } } -void SAL_CALL MacabCommonStatement::acquire() throw() +void SAL_CALL MacabCommonStatement::acquire() noexcept { MacabCommonStatement_BASE::acquire(); } -void SAL_CALL MacabCommonStatement::release() throw() +void SAL_CALL MacabCommonStatement::release() noexcept { MacabCommonStatement_BASE::release(); } diff --git a/connectivity/source/drivers/macab/MacabStatement.hxx b/connectivity/source/drivers/macab/MacabStatement.hxx index 3c8187016499..700a895c0a38 100644 --- a/connectivity/source/drivers/macab/MacabStatement.hxx +++ b/connectivity/source/drivers/macab/MacabStatement.hxx @@ -17,24 +17,22 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABSTATEMENT_HXX +#pragma once #include "MacabConnection.hxx" #include "MacabHeader.hxx" #include <connectivity/sqliterator.hxx> #include <connectivity/sqlparse.hxx> #include <com/sun/star/sdbc/XStatement.hpp> +#include <com/sun/star/sdbc/SQLWarning.hpp> #include <com/sun/star/util/XCancellable.hpp> #include <cppuhelper/compbase.hxx> #include <cppuhelper/implbase.hxx> #include <cppuhelper/basemutex.hxx> #include <comphelper/proparrhlp.hxx> -namespace connectivity +namespace connectivity::macab { - namespace macab - { typedef ::cppu::WeakComponentImplHelper< css::sdbc::XStatement, css::sdbc::XWarningsSupplier, css::util::XCancellable, @@ -109,8 +107,8 @@ namespace connectivity using MacabCommonStatement_BASE::disposing; // XInterface - virtual void SAL_CALL release() throw() override; - virtual void SAL_CALL acquire() throw() override; + virtual void SAL_CALL release() noexcept override; + virtual void SAL_CALL acquire() noexcept override; virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; @@ -166,9 +164,6 @@ namespace connectivity explicit MacabStatement(MacabConnection* _pConnection); DECLARE_SERVICE_INFO(); }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABSTATEMENT_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/macab/MacabTable.cxx b/connectivity/source/drivers/macab/MacabTable.cxx index 75da75bc1035..1628cd297bfd 100644 --- a/connectivity/source/drivers/macab/MacabTable.cxx +++ b/connectivity/source/drivers/macab/MacabTable.cxx @@ -71,8 +71,8 @@ void MacabTable::refreshColumns() if (xResult.is()) { - Reference< XRow > xRow(xResult, UNO_QUERY); - while (xResult->next()) + Reference< XRow > xRow(xResult, UNO_QUERY); + while (xResult->next()) aVector.push_back(xRow->getString(4)); } } @@ -80,7 +80,7 @@ void MacabTable::refreshColumns() if (m_xColumns) m_xColumns->reFill(aVector); else - m_xColumns = new MacabColumns(this,m_aMutex,aVector); + m_xColumns.reset(new MacabColumns(this, m_aMutex, aVector)); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/macab/MacabTable.hxx b/connectivity/source/drivers/macab/MacabTable.hxx index 58e43175dfe2..897d589cc697 100644 --- a/connectivity/source/drivers/macab/MacabTable.hxx +++ b/connectivity/source/drivers/macab/MacabTable.hxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABTABLE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABTABLE_HXX +#pragma once #include "MacabConnection.hxx" #include <connectivity/sdbcx/VTable.hxx> -namespace connectivity +namespace connectivity::macab { - namespace macab - { typedef connectivity::sdbcx::OTable MacabTable_TYPEDEF; class MacabTable : public MacabTable_TYPEDEF @@ -52,9 +49,6 @@ namespace connectivity OUString const & getTableName() const { return m_Name; } OUString const & getSchema() const { return m_SchemaName; } }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABTABLE_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/macab/MacabTables.cxx b/connectivity/source/drivers/macab/MacabTables.cxx index c70aa87f87d5..e7149d2646c1 100644 --- a/connectivity/source/drivers/macab/MacabTables.cxx +++ b/connectivity/source/drivers/macab/MacabTables.cxx @@ -52,14 +52,13 @@ sdbcx::ObjectType MacabTables::createObject(const OUString& _rName) Reference< XRow > xRow(xResult, UNO_QUERY); if (xResult->next()) // there can be only one table with this name { - MacabTable* pRet = new MacabTable( + xRet = new MacabTable( this, static_cast<MacabCatalog&>(m_rParent).getConnection(), aName, xRow->getString(4), xRow->getString(5), ""); - xRet = pRet; } } ::comphelper::disposeComponent(xResult); diff --git a/connectivity/source/drivers/macab/MacabTables.hxx b/connectivity/source/drivers/macab/MacabTables.hxx index 7e87a473a37d..0b0d841b7a43 100644 --- a/connectivity/source/drivers/macab/MacabTables.hxx +++ b/connectivity/source/drivers/macab/MacabTables.hxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABTABLES_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABTABLES_HXX +#pragma once #include <connectivity/sdbcx/VCollection.hxx> #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> -namespace connectivity +namespace connectivity::macab { - namespace macab - { class MacabTables : public sdbcx::OCollection { css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xMetaData; @@ -47,9 +44,6 @@ namespace connectivity virtual void disposing() override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABTABLES_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/macab/macabcondition.cxx b/connectivity/source/drivers/macab/macabcondition.cxx index 0d1d20227a42..41e087b2c421 100644 --- a/connectivity/source/drivers/macab/macabcondition.cxx +++ b/connectivity/source/drivers/macab/macabcondition.cxx @@ -51,7 +51,8 @@ bool MacabConditionConstant::eval(const MacabRecord *) const return m_bValue; } -MacabConditionColumn::MacabConditionColumn(const MacabHeader *header, const OUString &sColumnName) +MacabConditionColumn::MacabConditionColumn( + const MacabHeader *header, std::u16string_view sColumnName) : MacabCondition(), m_nFieldNumber(header->getColumnNumber(sColumnName)) { @@ -69,7 +70,7 @@ bool MacabConditionColumn::isAlwaysFalse() const return false; } -MacabConditionNull::MacabConditionNull(const MacabHeader *header, const OUString &sColumnName) +MacabConditionNull::MacabConditionNull(const MacabHeader *header, std::u16string_view sColumnName) : MacabConditionColumn(header, sColumnName) { } @@ -86,7 +87,8 @@ bool MacabConditionNull::eval(const MacabRecord *aRecord) const return false; } -MacabConditionNotNull::MacabConditionNotNull(const MacabHeader *header, const OUString &sColumnName) +MacabConditionNotNull::MacabConditionNotNull( + const MacabHeader *header, std::u16string_view sColumnName) : MacabConditionColumn(header, sColumnName) { } @@ -103,13 +105,13 @@ bool MacabConditionNotNull::eval(const MacabRecord *aRecord) const return true; } -MacabConditionCompare::MacabConditionCompare(const MacabHeader *header, const OUString &sColumnName, const OUString &sMatchString) +MacabConditionCompare::MacabConditionCompare(const MacabHeader *header, std::u16string_view sColumnName, const OUString &sMatchString) : MacabConditionColumn(header, sColumnName), m_sMatchString(sMatchString) { } -MacabConditionEqual::MacabConditionEqual(const MacabHeader *header, const OUString &sColumnName, const OUString &sMatchString) +MacabConditionEqual::MacabConditionEqual(const MacabHeader *header, std::u16string_view sColumnName, const OUString &sMatchString) : MacabConditionCompare(header, sColumnName, sMatchString) { } @@ -132,7 +134,7 @@ bool MacabConditionEqual::eval(const MacabRecord *aRecord) const return nReturn == 0; } -MacabConditionDifferent::MacabConditionDifferent(const MacabHeader *header, const OUString &sColumnName, const OUString &sMatchString) +MacabConditionDifferent::MacabConditionDifferent(const MacabHeader *header, std::u16string_view sColumnName, const OUString &sMatchString) : MacabConditionCompare(header, sColumnName, sMatchString) { } @@ -155,7 +157,7 @@ bool MacabConditionDifferent::eval(const MacabRecord *aRecord) const return nReturn != 0; } -MacabConditionSimilar::MacabConditionSimilar(const MacabHeader *header, const OUString &sColumnName, const OUString &sMatchString) +MacabConditionSimilar::MacabConditionSimilar(const MacabHeader *header, std::u16string_view sColumnName, const OUString &sMatchString) : MacabConditionCompare(header, sColumnName, sMatchString) { } diff --git a/connectivity/source/drivers/macab/macabcondition.hxx b/connectivity/source/drivers/macab/macabcondition.hxx index 15eb853b19dd..32e7b7071cf3 100644 --- a/connectivity/source/drivers/macab/macabcondition.hxx +++ b/connectivity/source/drivers/macab/macabcondition.hxx @@ -17,18 +17,19 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABCONDITION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABCONDITION_HXX +#pragma once + +#include <sal/config.h> + +#include <string_view> #include "MacabHeader.hxx" #include "MacabRecord.hxx" #include <connectivity/dbexception.hxx> -namespace connectivity +namespace connectivity::macab { - namespace macab - { class MacabCondition { @@ -60,7 +61,7 @@ class MacabConditionColumn : public MacabCondition /// @throws css::sdbc::SQLException MacabConditionColumn( const MacabHeader *header, - const OUString &sColumnName); + std::u16string_view sColumnName); virtual bool isAlwaysTrue() const override; virtual bool isAlwaysFalse() const override; }; @@ -71,7 +72,7 @@ class MacabConditionNull : public MacabConditionColumn /// @throws css::sdbc::SQLException MacabConditionNull( const MacabHeader *header, - const OUString &sColumnName); + std::u16string_view sColumnName); virtual bool eval(const MacabRecord *aRecord) const override; }; @@ -81,7 +82,7 @@ class MacabConditionNotNull : public MacabConditionColumn /// @throws css::sdbc::SQLException MacabConditionNotNull( const MacabHeader *header, - const OUString &sColumnName); + std::u16string_view sColumnName); virtual bool eval(const MacabRecord *aRecord) const override; }; @@ -94,7 +95,7 @@ class MacabConditionCompare : public MacabConditionColumn /// @throws css::sdbc::SQLException MacabConditionCompare( const MacabHeader *header, - const OUString &sColumnName, + std::u16string_view sColumnName, const OUString &sMatchString); }; @@ -104,7 +105,7 @@ class MacabConditionEqual : public MacabConditionCompare /// @throws css::sdbc::SQLException MacabConditionEqual( const MacabHeader *header, - const OUString &sColumnName, + std::u16string_view sColumnName, const OUString &sMatchString); virtual bool eval(const MacabRecord *aRecord) const override; }; @@ -115,7 +116,7 @@ class MacabConditionDifferent : public MacabConditionCompare /// @throws css::sdbc::SQLException MacabConditionDifferent( const MacabHeader *header, - const OUString &sColumnName, + std::u16string_view sColumnName, const OUString &sMatchString); virtual bool eval(const MacabRecord *aRecord) const override; }; @@ -126,7 +127,7 @@ class MacabConditionSimilar : public MacabConditionCompare /// @throws css::sdbc::SQLException MacabConditionSimilar( const MacabHeader *header, - const OUString &sColumnName, + std::u16string_view sColumnName, const OUString &sMatchString); virtual bool eval(const MacabRecord *aRecord) const override; }; @@ -159,9 +160,6 @@ class MacabConditionAnd : public MacabConditionBoolean virtual bool eval(const MacabRecord *aRecord) const override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABCONDITION_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/macab/macaborder.cxx b/connectivity/source/drivers/macab/macaborder.cxx index aaef39ef6253..133e5d599136 100644 --- a/connectivity/source/drivers/macab/macaborder.cxx +++ b/connectivity/source/drivers/macab/macaborder.cxx @@ -28,7 +28,7 @@ MacabOrder::~MacabOrder() { } -MacabSimpleOrder::MacabSimpleOrder(MacabHeader const *header, OUString const &sColumnName, bool bAscending) +MacabSimpleOrder::MacabSimpleOrder(MacabHeader const *header, std::u16string_view sColumnName, bool bAscending) : MacabOrder(), m_nFieldNumber(header->getColumnNumber(sColumnName)), m_bAscending(bAscending) diff --git a/connectivity/source/drivers/macab/macaborder.hxx b/connectivity/source/drivers/macab/macaborder.hxx index de7a2ed7c189..e5eb6c987ce2 100644 --- a/connectivity/source/drivers/macab/macaborder.hxx +++ b/connectivity/source/drivers/macab/macaborder.hxx @@ -17,20 +17,18 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABORDER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABORDER_HXX +#pragma once #include <rtl/ustring.hxx> #include "MacabHeader.hxx" #include "MacabRecord.hxx" #include <memory> +#include <string_view> #include <vector> -namespace connectivity +namespace connectivity::macab { - namespace macab - { class MacabOrder { public: @@ -45,7 +43,7 @@ namespace connectivity bool m_bAscending; public: - MacabSimpleOrder(MacabHeader const *header, OUString const &sColumnName, bool bAscending); + MacabSimpleOrder(MacabHeader const *header, std::u16string_view sColumnName, bool bAscending); virtual sal_Int32 compare(const MacabRecord *record1, const MacabRecord *record2) const override; }; @@ -61,9 +59,6 @@ namespace connectivity void addOrder(MacabOrder *pOrder); virtual sal_Int32 compare(const MacabRecord *record1, const MacabRecord *record2) const override; }; - } } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/macab/macabutilities.hxx b/connectivity/source/drivers/macab/macabutilities.hxx index c384604e3514..7e0f6b091085 100644 --- a/connectivity/source/drivers/macab/macabutilities.hxx +++ b/connectivity/source/drivers/macab/macabutilities.hxx @@ -17,11 +17,15 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABUTILITIES_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABUTILITIES_HXX +#pragma once + +#include <sal/config.h> + +#include <memory> #include <com/sun/star/util/DateTime.hpp> #include <com/sun/star/sdbc/DataType.hpp> +#include <unotools/resmgr.hxx> #include <time.h> #include <premac.h> @@ -29,10 +33,8 @@ #include <AddressBook/ABAddressBookC.h> #include <postmac.h> -namespace connectivity +namespace connectivity::macab { - namespace macab - { inline OUString CFStringToOUString(const CFStringRef sOrig) { @@ -49,15 +51,15 @@ namespace connectivity CFRetain(sOrig); CFIndex nStringLength = CFStringGetLength(sOrig); - UniChar unichars[nStringLength+1]; + auto const unichars = std::make_unique<UniChar[]>(nStringLength+1); //'close' the string buffer correctly unichars[nStringLength] = '\0'; - CFStringGetCharacters (sOrig, CFRangeMake(0,nStringLength), unichars); + CFStringGetCharacters (sOrig, CFRangeMake(0,nStringLength), unichars.get()); CFRelease(sOrig); - return OUString(reinterpret_cast<sal_Unicode *>(unichars)); + return OUString(reinterpret_cast<sal_Unicode *>(unichars.get())); } @@ -134,10 +136,7 @@ namespace connectivity return dataType; } - void impl_throwError(const char* pErrorId); - } + void impl_throwError(TranslateId pErrorId); } -#endif // _ CONNECTIVITY_MACAB_UTILITIES_HXX_ - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MCatalog.cxx b/connectivity/source/drivers/mork/MCatalog.cxx deleted file mode 100644 index 743d1e5ab9c6..000000000000 --- a/connectivity/source/drivers/mork/MCatalog.cxx +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- 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 . - */ - -#include "MCatalog.hxx" -#include "MConnection.hxx" -#include "MTables.hxx" - -#include <com/sun/star/sdbc/XRow.hpp> - - -using namespace connectivity::mork; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; - - -OCatalog::OCatalog(OConnection* _pCon) : connectivity::sdbcx::OCatalog(_pCon) - ,m_pConnection(_pCon) -{ -// osl_atomic_increment( &m_refCount ); -// refreshTables(); -// refreshViews(); -// refreshGroups(); -// refreshUsers(); -// osl_atomic_decrement( &m_refCount ); -} - -void OCatalog::refreshTables() -{ - ::std::vector< OUString> aVector; - Sequence< OUString > aTypes { "%" }; - Reference< XResultSet > xResult = m_xMetaData->getTables(Any(), - "%", "%", aTypes); - - if(xResult.is()) - { - Reference< XRow > xRow(xResult,UNO_QUERY); - OUString aName; - while(xResult->next()) - { - aName = xRow->getString(3); - aVector.push_back(aName); - } - } - if(m_pTables) - m_pTables->reFill(aVector); - else - m_pTables.reset( new OTables(m_xMetaData,*this,m_aMutex,aVector) ); -} - -void OCatalog::refreshViews() -{ -} - -void OCatalog::refreshGroups() -{ -} - -void OCatalog::refreshUsers() -{ -} - - -// XTablesSupplier -Reference< XNameAccess > SAL_CALL OCatalog::getTables( ) -{ - ::osl::MutexGuard aGuard(m_aMutex); - checkDisposed(rBHelper.bDisposed); - - try - { - if(!m_pTables || OConnection::getForceLoadTables()) - refreshTables(); - } - catch( const RuntimeException& ) - { - // allowed to leave this method - throw; - } - catch( const Exception& ) - { - // allowed - } - - return m_pTables.get(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MCatalog.hxx b/connectivity/source/drivers/mork/MCatalog.hxx deleted file mode 100644 index 170809f7cd49..000000000000 --- a/connectivity/source/drivers/mork/MCatalog.hxx +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- 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 . - */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MCATALOG_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MCATALOG_HXX - -#include <sdbcx/VCatalog.hxx> - -namespace connectivity -{ - namespace mork - { - // please don't name the class the same name as in another namespaces - // some compilers have problems with this task as I noticed on windows - class OConnection; - class OCatalog : public connectivity::sdbcx::OCatalog - { - OConnection* m_pConnection; // used to get the metadata - - public: - // implementation of the pure virtual methods - virtual void refreshTables() override; - virtual void refreshViews() override ; - virtual void refreshGroups() override; - virtual void refreshUsers() override ; - virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTables( ) override; - public: - explicit OCatalog(OConnection* _pCon); - - OConnection* getConnection() const { return m_pConnection; } - - }; - } -} -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MCATALOG_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MColumnAlias.cxx b/connectivity/source/drivers/mork/MColumnAlias.cxx deleted file mode 100644 index b320d8c459e3..000000000000 --- a/connectivity/source/drivers/mork/MColumnAlias.cxx +++ /dev/null @@ -1,133 +0,0 @@ -/* -*- 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 . - */ - -#include "MColumnAlias.hxx" - -#include <com/sun/star/container/XHierarchicalNameAccess.hpp> -#include <com/sun/star/container/XNameAccess.hpp> -#include <officecfg/Office/DataAccess.hxx> - -#include <osl/diagnose.h> -#include <sal/log.hxx> - -#include <algorithm> - -using namespace ::connectivity::mork; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::container; - - -OColumnAlias::OColumnAlias( const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxORB ) -{ - static const char* s_pProgrammaticNames[] = - { - "FirstName", - "LastName", - "DisplayName", - "NickName", - "PrimaryEmail", - "SecondEmail", - "PreferMailFormat", - "WorkPhone", - "HomePhone", - "FaxNumber", - "PagerNumber", - "CellularNumber", - "HomeAddress", - "HomeAddress2", - "HomeCity", - "HomeState", - "HomeZipCode", - "HomeCountry", - "WorkAddress", - "WorkAddress2", - "WorkCity", - "WorkState", - "WorkZipCode", - "WorkCountry", - "JobTitle", - "Department", - "Company", - "WebPage1", - "WebPage2", - "BirthYear", - "BirthMonth", - "BirthDay", - "Custom1", - "Custom2", - "Custom3", - "Custom4", - "Notes", - }; - - for ( size_t i = 0; i < SAL_N_ELEMENTS( s_pProgrammaticNames ); ++i ) - m_aAliasMap[ OUString::createFromAscii( s_pProgrammaticNames[i] ) ] = AliasEntry( s_pProgrammaticNames[i], i ); - - initialize( _rxORB ); -} - - -void OColumnAlias::initialize( const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxORB ) -{ - Reference< XNameAccess > xAliasesNode( - officecfg::Office::DataAccess::DriverSettings:: - com_sun_star_comp_sdbc_MozabDriver::ColumnAliases::get( - comphelper::getComponentContext(_rxORB)), - UNO_QUERY_THROW); - const Sequence< OUString > aProgrammaticNames(xAliasesNode->getElementNames()); - for (const auto& rProgrammaticName : aProgrammaticNames) { - OString sAsciiProgrammaticName( - OUStringToOString( - rProgrammaticName, RTL_TEXTENCODING_ASCII_US)); - auto j = std::find_if(m_aAliasMap.begin(), m_aAliasMap.end(), - [&sAsciiProgrammaticName](const AliasMap::value_type& rEntry) { - return rEntry.second.programmaticAsciiName == sAsciiProgrammaticName; }); - if (j != m_aAliasMap.end()) { - OUString sAssignedAlias; - xAliasesNode->getByName(rProgrammaticName) >>= - sAssignedAlias; - if (sAssignedAlias.isEmpty()) { - sAssignedAlias = rProgrammaticName; - } - AliasEntry entry(j->second); - m_aAliasMap.erase(j); - m_aAliasMap[sAssignedAlias] = entry; - } - else { - SAL_WARN( - "connectivity.mork", - "unknown programmatic name " << rProgrammaticName - <<" from configuration"); - } - } -} - - -OString OColumnAlias::getProgrammaticNameOrFallbackToUTF8Alias( const OUString& _rAlias ) const -{ - AliasMap::const_iterator pos = m_aAliasMap.find( _rAlias ); - if ( pos == m_aAliasMap.end() ) - { - OSL_FAIL( "OColumnAlias::getProgrammaticNameOrFallbackToUTF8Alias: no programmatic name for this alias!" ); - return OUStringToOString( _rAlias, RTL_TEXTENCODING_UTF8 ); - } - return pos->second.programmaticAsciiName; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MColumnAlias.hxx b/connectivity/source/drivers/mork/MColumnAlias.hxx deleted file mode 100644 index 3900b324b394..000000000000 --- a/connectivity/source/drivers/mork/MColumnAlias.hxx +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- 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 . - */ - - -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MCOLUMNALIAS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MCOLUMNALIAS_HXX - -#include <unotools/confignode.hxx> - -#include <unordered_map> - -namespace connectivity -{ - namespace mork - { - class OColumnAlias - { - public: - struct AliasEntry - { - OString programmaticAsciiName; - size_t columnPosition; - - AliasEntry() - :programmaticAsciiName() - ,columnPosition( 0 ) - { - } - AliasEntry( const char* _programmaticAsciiName, size_t _columnPosition ) - :programmaticAsciiName( _programmaticAsciiName ) - ,columnPosition( _columnPosition ) - { - } - }; - typedef std::unordered_map< OUString, AliasEntry > AliasMap; - - private: - AliasMap m_aAliasMap; - - public: - explicit OColumnAlias( const css::uno::Reference< css::lang::XMultiServiceFactory > & ); - - OString getProgrammaticNameOrFallbackToUTF8Alias( const OUString& _rAlias ) const; - - AliasMap::const_iterator begin() const { return m_aAliasMap.begin(); } - AliasMap::const_iterator end() const { return m_aAliasMap.end(); } - - - private: - void initialize( const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxORB ); - }; - } -} -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MCOLUMNALIAS_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MColumns.cxx b/connectivity/source/drivers/mork/MColumns.cxx deleted file mode 100644 index c9163a6ab96b..000000000000 --- a/connectivity/source/drivers/mork/MColumns.cxx +++ /dev/null @@ -1,80 +0,0 @@ -/* -*- 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 . - */ - -#include "MColumns.hxx" -#include <com/sun/star/sdbc/XRow.hpp> -#include <connectivity/sdbcx/VColumn.hxx> - -using namespace connectivity::mork; -using namespace connectivity::sdbcx; -using namespace connectivity; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::sdbc; - - -sdbcx::ObjectType OColumns::createObject(const OUString& _rName) -{ - const Any aCatalog; - const OUString sCatalogName; - const OUString sSchemaName(m_pTable->getSchema()); - const OUString sTableName(m_pTable->getTableName()); - Reference< XResultSet > xResult = m_pTable->getConnection()->getMetaData()->getColumns( - aCatalog, sSchemaName, sTableName, _rName); - - sdbcx::ObjectType xRet; - if(xResult.is()) - { - Reference< XRow > xRow(xResult,UNO_QUERY); - while(xResult->next()) - { - if(xRow->getString(4) == _rName) - { - sal_Int32 nType = xRow->getInt(5); - OUString sTypeName = xRow->getString(6); - sal_Int32 nPrec = xRow->getInt(7); - - OColumn* pRet = new OColumn(_rName, - sTypeName, - xRow->getString(13), - xRow->getString(12), - xRow->getInt(11), - nPrec, - xRow->getInt(9), - nType, - false,false,false,true, - sCatalogName, - sSchemaName, - sTableName); - xRet = pRet; - break; - } - } - } - - return xRet; -} - - -void OColumns::impl_refresh() -{ - m_pTable->refreshColumns(); -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MColumns.hxx b/connectivity/source/drivers/mork/MColumns.hxx deleted file mode 100644 index b0774af27c88..000000000000 --- a/connectivity/source/drivers/mork/MColumns.hxx +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- 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 . - */ - -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MCOLUMNS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MCOLUMNS_HXX - -#include <connectivity/sdbcx/VCollection.hxx> -#include "MTable.hxx" - -namespace connectivity -{ - namespace mork - { - class OColumns final : public sdbcx::OCollection - { - OTable* m_pTable; - - virtual sdbcx::ObjectType createObject(const OUString& _rName) override; - virtual void impl_refresh() override; - public: - OColumns( OTable* _pTable, - ::osl::Mutex& _rMutex, - const ::std::vector< OUString> &_rVector - ) : sdbcx::OCollection(*_pTable, true, _rMutex, _rVector) - ,m_pTable(_pTable) - {} - }; - } -} -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MCOLUMNS_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MConnection.cxx b/connectivity/source/drivers/mork/MConnection.cxx deleted file mode 100644 index 2e1c08d0cdcf..000000000000 --- a/connectivity/source/drivers/mork/MConnection.cxx +++ /dev/null @@ -1,377 +0,0 @@ -/* -*- 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/. - */ - -#include "MConnection.hxx" -#include "MDriver.hxx" -#include "MDatabaseMetaData.hxx" -#include "MCatalog.hxx" -#include "MPreparedStatement.hxx" -#include "MorkParser.hxx" - -#include <connectivity/dbexception.hxx> -#include <sal/log.hxx> - -#include <strings.hrc> - -#include <com/sun/star/sdbc/TransactionIsolation.hpp> - -using namespace dbtools; - - -using namespace com::sun::star::uno; -using namespace com::sun::star::lang; -using namespace com::sun::star::beans; -using namespace com::sun::star::sdbc; -using namespace com::sun::star::sdbcx; - - -namespace connectivity::mork { - -const int defaultScope = 0x80; - - -OConnection::OConnection(MorkDriver* _pDriver) - :m_xDriver(_pDriver) - ,m_aColumnAlias( _pDriver->getFactory() ) -{ - m_pBook.reset( new MorkParser() ); - m_pHistory.reset( new MorkParser() ); -} - -OConnection::~OConnection() -{ - if(!isClosed()) - close(); - m_pBook.reset(); - m_pHistory.reset(); -} - -void OConnection::construct(const OUString& url) -{ - SAL_INFO("connectivity.mork", "=> OConnection::construct()" ); - // open file - setURL(url); - - // Skip 'sdbc:mozab: part of URL - - sal_Int32 nLen = url.indexOf(':'); - nLen = url.indexOf(':',nLen+1); - OSL_ENSURE( url.startsWith("sdbc:address:"), "OConnection::construct: invalid start of the URI - should never have survived XDriver::acceptsURL!" ); - - OUString aAddrbookURI(url.copy(nLen+1)); - // Get Scheme - nLen = aAddrbookURI.indexOf(':'); - OUString aAddrbookScheme; - if ( nLen == -1 ) - { - // There isn't any subschema: - but could be just subschema - if ( !aAddrbookURI.isEmpty() ) - { - aAddrbookScheme= aAddrbookURI; - } - else - { - SAL_WARN("connectivity.mork", "No subschema given!!!"); - throwGenericSQLException( STR_URI_SYNTAX_ERROR, *this ); - } - } - else - { - aAddrbookScheme = aAddrbookURI.copy(0, nLen); - } - - SAL_INFO("connectivity.mork", "URI = " << aAddrbookURI ); - SAL_INFO("connectivity.mork", "Scheme = " << aAddrbookScheme ); - - OUString abook; - OUString history; - const OUString UNITTEST_URL = "thunderbird:unittest:"; - sal_Int32 unittestIndex = url.indexOf(UNITTEST_URL); - - // production? - if (unittestIndex == -1) - { - OUString path = m_xDriver->getProfilePath(); - SAL_INFO("connectivity.mork", "ProfilePath: " << path); - abook = path + "/abook.mab"; - history = path + "/history.mab"; - SAL_INFO("connectivity.mork", "AdressbookPath (abook): " << abook); - SAL_INFO("connectivity.mork", "AdressbookPath (history): " << history); - } - else - { - abook = aAddrbookURI.replaceFirst(UNITTEST_URL, ""); - SAL_INFO("connectivity.mork", "unit test: " << abook); - } - - OString strPath = OUStringToOString(abook, RTL_TEXTENCODING_UTF8); - - // Open and parse mork file - if (!m_pBook->open(strPath.getStr())) - { - SAL_WARN("connectivity.mork", "Can not parse abook mork file: " << strPath); - const OUString sError( getResources().getResourceStringWithSubstitution( - STR_COULD_NOT_LOAD_FILE, "$filename$", abook)); - ::dbtools::throwGenericSQLException( sError, *this ); - } - - // read history only in production - if (unittestIndex == -1) - { - strPath = OUStringToOString(history, RTL_TEXTENCODING_UTF8); - if (!m_pHistory->open(strPath.getStr())) - { - SAL_WARN("connectivity.mork", "Can not parse history mork file: " << strPath); - const OUString sError( getResources().getResourceStringWithSubstitution( - STR_COULD_NOT_LOAD_FILE, "$filename$", history)); - ::dbtools::throwGenericSQLException( sError, *this ); - } - } - - // check that we can retrieve the tables: - MorkTableMap *Tables = m_pBook->getTables( defaultScope ); - if (Tables) - { - // Iterate all tables - for ( const auto& rEntry : Tables->map ) - { - if ( 0 == rEntry.first ) continue; - SAL_INFO("connectivity.mork", "table->first : " << rEntry.first); - } - } - // check that we can retrieve the history tables: - MorkTableMap *Tables_hist = m_pHistory->getTables( defaultScope ); - if (Tables_hist) - { - // Iterate all tables - for ( const auto& rEntry : Tables_hist->map ) - { - if ( 0 == rEntry.first ) continue; - SAL_INFO("connectivity.mork", "table->first : " << rEntry.first); - } - } -} - -// XServiceInfo - -IMPLEMENT_SERVICE_INFO(OConnection, "com.sun.star.sdbc.drivers.mork.OConnection", "com.sun.star.sdbc.Connection") - - -Reference< XStatement > SAL_CALL OConnection::createStatement( ) -{ - SAL_INFO("connectivity.mork", "=> OConnection::createStatement()" ); - - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OConnection_BASE::rBHelper.bDisposed); - - // create a statement - // the statement can only be executed once - Reference< XStatement > xReturn = new OStatement(this); - m_aStatements.push_back(WeakReferenceHelper(xReturn)); - return xReturn; -} - -Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement( const OUString& _sSql ) -{ - SAL_INFO("connectivity.mork", "=> OConnection::prepareStatement()" ); - SAL_INFO("connectivity.mork", "OConnection::prepareStatement( " << _sSql << " )"); - - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OConnection_BASE::rBHelper.bDisposed); - - // the pre - // create a statement - // the statement can only be executed more than once - OPreparedStatement* pPrepared = new OPreparedStatement(this,_sSql); - Reference< XPreparedStatement > xReturn = pPrepared; - pPrepared->lateInit(); - - m_aStatements.push_back(WeakReferenceHelper(xReturn)); - return xReturn; -} - -Reference< XPreparedStatement > SAL_CALL OConnection::prepareCall( const OUString& _sSql ) -{ - SAL_INFO("connectivity.mork", "=> OConnection::prepareCall()" ); - SAL_INFO("connectivity.mork", "sql: " << _sSql); - ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::prepareCall", *this ); - SAL_INFO("connectivity.mork", "OConnection::prepareCall( " << _sSql << " )"); - return nullptr; -} - -OUString SAL_CALL OConnection::nativeSQL( const OUString& _sSql ) -{ - SAL_INFO("connectivity.mork", "=> OConnection::nativeSQL()" ); - SAL_INFO("connectivity.mork", "sql: " << _sSql); - - ::osl::MutexGuard aGuard( m_aMutex ); - // when you need to transform SQL92 to you driver specific you can do it here - SAL_INFO("connectivity.mork", "OConnection::nativeSQL(" << _sSql << " )" ); - - return _sSql; -} - -void SAL_CALL OConnection::setAutoCommit( sal_Bool /*autoCommit*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::setAutoCommit", *this ); -} - -sal_Bool SAL_CALL OConnection::getAutoCommit( ) -{ - // you have to distinguish which if you are in autocommit mode or not - // at normal case true should be fine here - - return true; -} - -void SAL_CALL OConnection::commit( ) -{ - // when you database does support transactions you should commit here -} - -void SAL_CALL OConnection::rollback( ) -{ - // same as commit but for the other case -} - -sal_Bool SAL_CALL OConnection::isClosed( ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - // just simple -> we are close when we are disposed that means someone called dispose(); (XComponent) - return OConnection_BASE::rBHelper.bDisposed; -} - -Reference< XDatabaseMetaData > SAL_CALL OConnection::getMetaData( ) -{ - SAL_INFO("connectivity.mork", "=> OConnection::getMetaData()" ); - - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OConnection_BASE::rBHelper.bDisposed); - - // here we have to create the class with biggest interface - // The answer is 42 :-) - Reference< XDatabaseMetaData > xMetaData = m_xMetaData; - if(!xMetaData.is()) - { - xMetaData = new ODatabaseMetaData(this); // need the connection because it can return it - m_xMetaData = xMetaData; - } - - return xMetaData; -} - -void SAL_CALL OConnection::setReadOnly( sal_Bool /*readOnly*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::setReadOnly", *this ); -} - -sal_Bool SAL_CALL OConnection::isReadOnly( ) -{ - // return if your connection to readonly - return false; -} - -void SAL_CALL OConnection::setCatalog( const OUString& /*catalog*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::setCatalog", *this ); -} - -OUString SAL_CALL OConnection::getCatalog( ) -{ - return OUString(); -} - -void SAL_CALL OConnection::setTransactionIsolation( sal_Int32 /*level*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::setTransactionIsolation", *this ); -} - -sal_Int32 SAL_CALL OConnection::getTransactionIsolation( ) -{ - // please have a look at @see com.sun.star.sdbc.TransactionIsolation - return TransactionIsolation::NONE; -} - -Reference< css::container::XNameAccess > SAL_CALL OConnection::getTypeMap( ) -{ - // if your driver has special database types you can return it here - return nullptr; -} - -void SAL_CALL OConnection::setTypeMap( const Reference< css::container::XNameAccess >& /*typeMap*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::setTypeMap", *this ); -} - -// XCloseable -void SAL_CALL OConnection::close( ) -{ - // we just dispose us - { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OConnection_BASE::rBHelper.bDisposed); - - } - dispose(); -} - -// XWarningsSupplier -Any SAL_CALL OConnection::getWarnings( ) -{ - // when you collected some warnings -> return it - return Any(); -} - -void SAL_CALL OConnection::clearWarnings( ) -{ - // you should clear your collected warnings here -} - -void OConnection::disposing() -{ - // we noticed that we should be destroyed in near future so we have to dispose our statements - ::osl::MutexGuard aGuard(m_aMutex); - m_xCatalog.clear(); -} - -Reference< XTablesSupplier > OConnection::createCatalog() -{ - ::osl::MutexGuard aGuard( m_aMutex ); - Reference< XTablesSupplier > xTab = m_xCatalog; - if(!m_xCatalog.is()) - { - OCatalog *pCat = new OCatalog(this); - xTab = pCat; - m_xCatalog = xTab; - } - return xTab; -} - -void OConnection::throwSQLException( const ErrorDescriptor& _rError, const Reference< XInterface >& _rxContext ) -{ - if (_rError.getResId() != nullptr) - { - throwGenericSQLException( _rError.getResId(), _rxContext ); - OSL_FAIL( "OConnection::throwSQLException: unreachable (2)!" ); - } - - throwGenericSQLException( STR_UNSPECIFIED_ERROR, _rxContext ); -} - -void OConnection::throwSQLException( const char* pErrorResourceId, const Reference< XInterface >& _rxContext ) -{ - ErrorDescriptor aError; - aError.setResId(pErrorResourceId); - throwSQLException(aError, _rxContext); -} - -} // namespace connectivity::mork - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MConnection.hxx b/connectivity/source/drivers/mork/MConnection.hxx deleted file mode 100644 index b4e8e9f58c88..000000000000 --- a/connectivity/source/drivers/mork/MConnection.hxx +++ /dev/null @@ -1,100 +0,0 @@ -/* -*- 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/. - */ - -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MCONNECTION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MCONNECTION_HXX - -#include <TConnection.hxx> -#include "MColumnAlias.hxx" - -#include <rtl/ref.hxx> - -#include <com/sun/star/sdbcx/XTablesSupplier.hpp> - -// do we want here namespace too? -class MorkParser; - -namespace connectivity -{ - namespace mork - { - class MorkDriver; - class ErrorDescriptor; - - typedef connectivity::OMetaConnection OConnection_BASE; // implements basics and text encoding - - class OConnection final : public OConnection_BASE - { - // Data attributes - - rtl::Reference<MorkDriver> m_xDriver; // Pointer to the owning - // driver object - OColumnAlias m_aColumnAlias; - // Mork Parser (abook) - std::unique_ptr<MorkParser> m_pBook; - // Mork Parser (history) - std::unique_ptr<MorkParser> m_pHistory; - // Store Catalog - css::uno::Reference< css::sdbcx::XTablesSupplier> m_xCatalog; - - public: - /// @throws css::sdbc::SQLException - void construct( const OUString& url); - explicit OConnection(MorkDriver* const driver); - virtual ~OConnection() override; - - const rtl::Reference<MorkDriver>& getDriver() const {return m_xDriver;}; - MorkParser* getMorkParser(const OString& t) {return t == "CollectedAddressBook" ? m_pHistory.get() : m_pBook.get();}; - - // OComponentHelper - virtual void SAL_CALL disposing() override; - - // XServiceInfo - DECLARE_SERVICE_INFO(); - // XConnection - virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement( ) override; - virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const OUString& sql ) override; - virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall( const OUString& sql ) override; - virtual OUString SAL_CALL nativeSQL( const OUString& sql ) override; - virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) override; - virtual sal_Bool SAL_CALL getAutoCommit( ) override; - virtual void SAL_CALL commit( ) override; - virtual void SAL_CALL rollback( ) override; - virtual sal_Bool SAL_CALL isClosed( ) override; - virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( ) override; - virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) override; - virtual sal_Bool SAL_CALL isReadOnly( ) override; - virtual void SAL_CALL setCatalog( const OUString& catalog ) override; - virtual OUString SAL_CALL getCatalog( ) override; - virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) override; - virtual sal_Int32 SAL_CALL getTransactionIsolation( ) override; - virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTypeMap( ) override; - virtual void SAL_CALL setTypeMap( const css::uno::Reference< css::container::XNameAccess >& typeMap ) override; - // XCloseable - virtual void SAL_CALL close( ) override; - // XWarningsSupplier - virtual css::uno::Any SAL_CALL getWarnings( ) override; - virtual void SAL_CALL clearWarnings() override; - - const OColumnAlias & getColumnAlias() const { return m_aColumnAlias; } - - static bool getForceLoadTables() {return true;} - - // Added to enable me to use SQLInterpreter which requires an - // XNameAccess i/f to access tables. - css::uno::Reference< css::sdbcx::XTablesSupplier > createCatalog(); - - void throwSQLException( const ErrorDescriptor& _rError, const css::uno::Reference< css::uno::XInterface >& _rxContext ); - void throwSQLException( const char* pErrorResourceId, const css::uno::Reference< css::uno::XInterface >& _rxContext ); - }; - } -} -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MCONNECTION_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MDatabaseMetaData.cxx b/connectivity/source/drivers/mork/MDatabaseMetaData.cxx deleted file mode 100644 index 5155bf93c58a..000000000000 --- a/connectivity/source/drivers/mork/MDatabaseMetaData.cxx +++ /dev/null @@ -1,957 +0,0 @@ -/* -*- 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/. - */ - -#include "MConnection.hxx" -#include "MDatabaseMetaData.hxx" - -#include <com/sun/star/sdbc/TransactionIsolation.hpp> -#include <com/sun/star/sdbc/ColumnSearch.hpp> -#include <sal/log.hxx> -#include <vector> - -#include "MDatabaseMetaDataHelper.hxx" - -using namespace connectivity::mork; -using namespace connectivity; - -using namespace com::sun::star::uno; -using namespace com::sun::star::sdbc; - - -namespace connectivity::mork -{ - sal_Int32 const s_nCOLUMN_SIZE = 256; - sal_Int32 const s_nDECIMAL_DIGITS = 0; - sal_Int32 const s_nNULLABLE = 1; - sal_Int32 const s_nCHAR_OCTET_LENGTH = 65535; -} - -ODatabaseMetaData::ODatabaseMetaData(OConnection* _pCon) - : ::connectivity::ODatabaseMetaDataBase(_pCon,_pCon->getConnectionInfo()) - ,m_pConnection(_pCon) - ,m_pMetaDataHelper(new MDatabaseMetaDataHelper) -{ - OSL_ENSURE(m_pConnection,"ODatabaseMetaData::ODatabaseMetaData: No connection set!"); -} - -ODatabaseMetaData::~ODatabaseMetaData() -{ -} - - -ODatabaseMetaDataResultSet::ORows ODatabaseMetaData::getColumnRows( - const OUString& tableNamePattern, - const OUString& columnNamePattern ) -{ - SAL_INFO("connectivity.mork", "=> ODatabaseMetaData::getColumnRows()" ); - SAL_INFO("connectivity.mork", "tableNamePattern: " << tableNamePattern); - SAL_INFO("connectivity.mork", "columnNamePattern: " << columnNamePattern); - - ODatabaseMetaDataResultSet::ORows aRows; - ODatabaseMetaDataResultSet::ORow aRow(19); - - ::osl::MutexGuard aGuard( m_aMutex ); - std::vector< OUString > tables; - connectivity::mork::MDatabaseMetaDataHelper::getTableStrings(m_pConnection, tables); - - // **************************************************** - // Some entries in a row never change, so set them now - // **************************************************** - - // Catalog - aRow[1] = new ORowSetValueDecorator(OUString()); - // Schema - aRow[2] = new ORowSetValueDecorator(OUString()); - // DATA_TYPE - aRow[5] = new ORowSetValueDecorator(static_cast<sal_Int16>(DataType::VARCHAR)); - // TYPE_NAME, not used - aRow[6] = new ORowSetValueDecorator(OUString("VARCHAR")); - // COLUMN_SIZE - aRow[7] = new ORowSetValueDecorator(s_nCOLUMN_SIZE); - // BUFFER_LENGTH, not used - aRow[8] = ODatabaseMetaDataResultSet::getEmptyValue(); - // DECIMAL_DIGITS. - aRow[9] = new ORowSetValueDecorator(s_nDECIMAL_DIGITS); - // NUM_PREC_RADIX - aRow[10] = new ORowSetValueDecorator(sal_Int32(10)); - // NULLABLE - aRow[11] = new ORowSetValueDecorator(s_nNULLABLE); - // REMARKS - aRow[12] = ODatabaseMetaDataResultSet::getEmptyValue(); - // COULUMN_DEF, not used - aRow[13] = ODatabaseMetaDataResultSet::getEmptyValue(); - // SQL_DATA_TYPE, not used - aRow[14] = ODatabaseMetaDataResultSet::getEmptyValue(); - // SQL_DATETIME_SUB, not used - aRow[15] = ODatabaseMetaDataResultSet::getEmptyValue(); - // CHAR_OCTET_LENGTH, refer to [5] - aRow[16] = new ORowSetValueDecorator(s_nCHAR_OCTET_LENGTH); - // IS_NULLABLE - aRow[18] = new ORowSetValueDecorator(OUString("YES")); - - // Iterate over all tables - for(const OUString & table : tables) { - if(match(tableNamePattern, table,'\0')) { - // TABLE_NAME - aRow[3] = new ORowSetValueDecorator( table ); - - const OColumnAlias& colNames = m_pConnection->getColumnAlias(); - - SAL_INFO("connectivity.mork", "\tTableName = : " << table); - // Iterate over all columns in the table. - for (const auto& [rName, rAlias] : colNames) - { - if ( match( columnNamePattern, rName, '\0' ) ) - { - SAL_INFO("connectivity.mork", "\t\tColumnNam : " << rName); - - // COLUMN_NAME - aRow[4] = new ORowSetValueDecorator( rName ); - // ORDINAL_POSITION - aRow[17] = new ORowSetValueDecorator( static_cast< sal_Int32 >( rAlias.columnPosition ) + 1 ); - aRows.push_back(aRow); - } - } - } - } - return aRows; -} - -OUString ODatabaseMetaData::impl_getCatalogSeparator_throw( ) -{ - return OUString(); -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getMaxBinaryLiteralLength( ) -{ - return 65535; // 0 means no limit -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getMaxRowSize( ) -{ - return 0; // 0 means no limit -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getMaxCatalogNameLength( ) -{ - return 0; // 0 means no limit -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getMaxCharLiteralLength( ) -{ - return 254; // 0 means no limit -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnNameLength( ) -{ - return 20; // 0 means no limit -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInIndex( ) -{ - return 0; // 0 means no limit -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getMaxCursorNameLength( ) -{ - return 0; // 0 means no limit -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getMaxConnections( ) -{ - return 0; // 0 means no limit -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInTable( ) -{ - return 0; // 0 means no limit -} - -sal_Int32 ODatabaseMetaData::impl_getMaxStatements_throw( ) -{ - return 0; -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getMaxTableNameLength( ) -{ - return 0; // 0 means no limit -} - -sal_Int32 ODatabaseMetaData::impl_getMaxTablesInSelect_throw( ) -{ - // We only support a single table - return 1; -} - - -sal_Bool SAL_CALL ODatabaseMetaData::doesMaxRowSizeIncludeBlobs( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::storesLowerCaseQuotedIdentifiers( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::storesLowerCaseIdentifiers( ) -{ - return false; -} - -bool ODatabaseMetaData::impl_storesMixedCaseQuotedIdentifiers_throw( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::storesMixedCaseIdentifiers( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::storesUpperCaseQuotedIdentifiers( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::storesUpperCaseIdentifiers( ) -{ - return false; -} - -bool ODatabaseMetaData::impl_supportsAlterTableWithAddColumn_throw( ) -{ - return false; -} - -bool ODatabaseMetaData::impl_supportsAlterTableWithDropColumn_throw( ) -{ - return false; -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getMaxIndexLength( ) -{ - return 0; // 0 means no limit -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsNonNullableColumns( ) -{ - return false; -} - -OUString SAL_CALL ODatabaseMetaData::getCatalogTerm( ) -{ - return OUString(); -} - -OUString ODatabaseMetaData::impl_getIdentifierQuoteString_throw( ) -{ - // normally this is " - return "\""; -} - -OUString SAL_CALL ODatabaseMetaData::getExtraNameCharacters( ) -{ - return OUString(); -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsDifferentTableCorrelationNames( ) -{ - return true; -} - -bool ODatabaseMetaData::impl_isCatalogAtStart_throw( ) -{ - return true; -} - -sal_Bool SAL_CALL ODatabaseMetaData::dataDefinitionIgnoredInTransactions( ) -{ - return true; -} - -sal_Bool SAL_CALL ODatabaseMetaData::dataDefinitionCausesTransactionCommit( ) -{ - return true; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsDataManipulationTransactionsOnly( ) -{ - //We support create table - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsDataDefinitionAndDataManipulationTransactions( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsPositionedDelete( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsPositionedUpdate( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenStatementsAcrossRollback( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenStatementsAcrossCommit( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenCursorsAcrossCommit( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsOpenCursorsAcrossRollback( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsTransactionIsolationLevel( sal_Int32 /*level*/ ) -{ - return false; -} - -bool ODatabaseMetaData::impl_supportsSchemasInDataManipulation_throw( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92FullSQL( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92EntryLevelSQL( ) -{ - return true; // should be supported at least -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsIntegrityEnhancementFacility( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInIndexDefinitions( ) -{ - return false; -} - -bool ODatabaseMetaData::impl_supportsSchemasInTableDefinitions_throw( ) -{ - return false; -} - -bool ODatabaseMetaData::impl_supportsCatalogsInTableDefinitions_throw( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInIndexDefinitions( ) -{ - return false; -} - -bool ODatabaseMetaData::impl_supportsCatalogsInDataManipulation_throw( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsOuterJoins( ) -{ - return false; -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getMaxStatementLength( ) -{ - return 0;// 0 means no limit -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getMaxProcedureNameLength( ) -{ - return 0; // 0 means no limit -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getMaxSchemaNameLength( ) -{ - return 0; // 0 means no limit -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsTransactions( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::allProceduresAreCallable( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsStoredProcedures( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsSelectForUpdate( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::allTablesAreSelectable( ) -{ - // We allow you to select from any table. - return true; -} - -sal_Bool SAL_CALL ODatabaseMetaData::isReadOnly( ) -{ - //we support insert/update/delete now - //But we have to set this to return sal_True otherwise the UI will add create "table/edit table" - //entry to the popup menu. We should avoid them. - return true; -} - -sal_Bool SAL_CALL ODatabaseMetaData::usesLocalFiles( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::usesLocalFilePerTable( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsTypeConversion( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::nullPlusNonNullIsNull( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsColumnAliasing( ) -{ - // Support added for this. - return true; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsTableCorrelationNames( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsConvert( sal_Int32 /*fromType*/, sal_Int32 /*toType*/ ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsExpressionsInOrderBy( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsGroupBy( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsGroupByBeyondSelect( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsGroupByUnrelated( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsMultipleTransactions( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsMultipleResultSets( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsLikeEscapeClause( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsOrderByUnrelated( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsUnion( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsUnionAll( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsMixedCaseIdentifiers( ) -{ - return true; -} - -bool ODatabaseMetaData::impl_supportsMixedCaseQuotedIdentifiers_throw( ) -{ - // Any case may be used - return true; -} - -sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedAtEnd( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedAtStart( ) -{ - return true; -} - -sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedHigh( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::nullsAreSortedLow( ) -{ - return true; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInProcedureCalls( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsSchemasInPrivilegeDefinitions( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInProcedureCalls( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsCatalogsInPrivilegeDefinitions( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsCorrelatedSubqueries( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInComparisons( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInExists( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInIns( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsSubqueriesInQuantifieds( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsANSI92IntermediateSQL( ) -{ - return false; -} - -OUString SAL_CALL ODatabaseMetaData::getURL( ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - return m_pConnection->getURL(); -} - -OUString SAL_CALL ODatabaseMetaData::getUserName( ) -{ - return OUString(); -} - -OUString SAL_CALL ODatabaseMetaData::getDriverName( ) -{ - return OUString(); -} - -OUString SAL_CALL ODatabaseMetaData::getDriverVersion() -{ - OUString aValue = OUString::number(1); - return aValue; -} - -OUString SAL_CALL ODatabaseMetaData::getDatabaseProductVersion( ) -{ - OUString aValue = OUString::number(0); - return aValue; -} - -OUString SAL_CALL ODatabaseMetaData::getDatabaseProductName( ) -{ - return OUString(); -} - -OUString SAL_CALL ODatabaseMetaData::getProcedureTerm( ) -{ - return OUString(); -} - -OUString SAL_CALL ODatabaseMetaData::getSchemaTerm( ) -{ - return OUString(); -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getDriverMajorVersion( ) -{ - return 1; -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getDefaultTransactionIsolation( ) -{ - return TransactionIsolation::NONE; -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getDriverMinorVersion( ) -{ - return 0; -} - -OUString SAL_CALL ODatabaseMetaData::getSQLKeywords( ) -{ - return OUString(); -} - -OUString SAL_CALL ODatabaseMetaData::getSearchStringEscape( ) -{ - return OUString(); -} - -OUString SAL_CALL ODatabaseMetaData::getStringFunctions( ) -{ - return OUString(); -} - -OUString SAL_CALL ODatabaseMetaData::getTimeDateFunctions( ) -{ - return OUString(); -} - -OUString SAL_CALL ODatabaseMetaData::getSystemFunctions( ) -{ - return OUString(); -} - -OUString SAL_CALL ODatabaseMetaData::getNumericFunctions( ) -{ - return OUString(); -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsExtendedSQLGrammar( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsCoreSQLGrammar( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsMinimumSQLGrammar( ) -{ - return true; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsFullOuterJoins( ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsLimitedOuterJoins( ) -{ - return false; -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInGroupBy( ) -{ - return 0; // 0 means no limit -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInOrderBy( ) -{ - return 0; // 0 means no limit -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getMaxColumnsInSelect( ) -{ - return 0; // 0 means no limit -} - -sal_Int32 SAL_CALL ODatabaseMetaData::getMaxUserNameLength( ) -{ - return 0; // 0 means no limit -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsResultSetType( sal_Int32 /*setType*/ ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsResultSetConcurrency( sal_Int32 /*setType*/, sal_Int32 /*concurrency*/ ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::ownUpdatesAreVisible( sal_Int32 /*setType*/ ) -{ - return true; -} - -sal_Bool SAL_CALL ODatabaseMetaData::ownDeletesAreVisible( sal_Int32 /*setType*/ ) -{ - return true; -} - -sal_Bool SAL_CALL ODatabaseMetaData::ownInsertsAreVisible( sal_Int32 /*setType*/ ) -{ - return true; -} - -sal_Bool SAL_CALL ODatabaseMetaData::othersUpdatesAreVisible( sal_Int32 /*setType*/ ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::othersDeletesAreVisible( sal_Int32 /*setType*/ ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::othersInsertsAreVisible( sal_Int32 /*setType*/ ) -{ - return false; -} - -sal_Bool SAL_CALL ODatabaseMetaData::updatesAreDetected( sal_Int32 /*setType*/ ) -{ - return true; -} - -sal_Bool SAL_CALL ODatabaseMetaData::deletesAreDetected( sal_Int32 /*setType*/ ) -{ - return true; -} - -sal_Bool SAL_CALL ODatabaseMetaData::insertsAreDetected( sal_Int32 /*setType*/ ) -{ - return true; -} - -sal_Bool SAL_CALL ODatabaseMetaData::supportsBatchUpdates( ) -{ - return false; -} - -// here follow all methods which return a resultset -// the first methods is an example implementation how to use this resultset -// of course you could implement it on your and you should do this because -// the general way is more memory expensive - -Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTableTypes( ) -{ - // there exists no possibility to get table types so we have to check - static const OUStringLiteral sTableTypes[] = - { - "TABLE", - "VIEW" - // Currently we only support a 'TABLE' and 'VIEW' nothing more complex - - // OUString("SYSTEM TABLE"), - // OUString("GLOBAL TEMPORARY"), - // OUString("LOCAL TEMPORARY"), - // OUString("ALIAS"), - // OUString("SYNONYM") - }; - ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTableTypes); - Reference< XResultSet > xRef = pResult; - - // here we fill the rows which should be visible when ask for data from the resultset returned here - ODatabaseMetaDataResultSet::ORows aRows; - for(const auto & sTableType : sTableTypes) - { - ODatabaseMetaDataResultSet::ORow aRow; - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(new ORowSetValueDecorator(OUString(sTableType))); - // bound row - aRows.push_back(aRow); - } - // here we set the rows at the resultset - pResult->setRows(aRows); - return xRef; -} - -Reference< XResultSet > ODatabaseMetaData::impl_getTypeInfo_throw( ) -{ - // this returns an empty resultset where the column-names are already set - // in special the metadata of the resultset already returns the right columns - ODatabaseMetaDataResultSet* pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTypeInfo); - Reference< XResultSet > xResultSet = pResultSet; - static ODatabaseMetaDataResultSet::ORows aRows = [&]() - { - ODatabaseMetaDataResultSet::ORows tmp; - ODatabaseMetaDataResultSet::ORow aRow; - aRow.reserve(19); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(new ORowSetValueDecorator(OUString("VARCHAR"))); - aRow.push_back(new ORowSetValueDecorator(DataType::VARCHAR)); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(s_nCHAR_OCTET_LENGTH))); - aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue()); - aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - // aRow.push_back(new ORowSetValueDecorator((sal_Int32)ColumnValue::NULLABLE)); - aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(ColumnSearch::CHAR))); - aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(10))); - - tmp.push_back(aRow); - return tmp; - }(); - pResultSet->setRows(aRows); - return xResultSet; -} - -Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns( - const Any& /*catalog*/, const OUString& /*schemaPattern*/, const OUString& tableNamePattern, - const OUString& columnNamePattern ) -{ - // this returns an empty resultset where the column-names are already set - // in special the metadata of the resultset already returns the right columns - ODatabaseMetaDataResultSet* pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eColumns); - Reference< XResultSet > xResultSet = pResultSet; - pResultSet->setRows( getColumnRows( tableNamePattern, columnNamePattern )); - return xResultSet; -} - -Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( - const Any& /*catalog*/, const OUString& /*schemaPattern*/, - const OUString& tableNamePattern, const Sequence< OUString >& /*types*/ ) -{ - SAL_INFO("connectivity.mork", "=> ODatabaseMetaData::getTables()" ); - // this returns an empty resultset where the column-names are already set - // in special the metadata of the resultset already returns the right columns - ODatabaseMetaDataResultSet* pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTables); - Reference< XResultSet > xResultSet = pResultSet; - - // ODatabaseMetaDataResultSet::ORows aRows; - // aRows = m_pDbMetaDataHelper->getTables( m_pConnection, tableNamePattern ); - // pResultSet->setRows( aRows ); - ODatabaseMetaDataResultSet::ORows _rRows; - connectivity::mork::MDatabaseMetaDataHelper::getTables( m_pConnection, tableNamePattern, _rRows ); - pResultSet->setRows( _rRows ); - - return xResultSet; -} - -Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges( - const Any& /*catalog*/, const OUString& /*schemaPattern*/, const OUString& tableNamePattern ) -{ - SAL_INFO("connectivity.mork", "=> ODatabaseMetaData::getTablePrivileges()" ); - ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTablePrivileges); - Reference< XResultSet > xRef = pResult; - - std::vector< OUString > tables; - connectivity::mork::MDatabaseMetaDataHelper::getTableStrings( m_pConnection, tables); - - ::connectivity::ODatabaseMetaDataResultSet::ORows aRows; - ::connectivity::ODatabaseMetaDataResultSet::ORow aRow(8); - aRows.reserve(8); - aRow[0] = ::connectivity::ODatabaseMetaDataResultSet::getEmptyValue(); - aRow[1] = ::connectivity::ODatabaseMetaDataResultSet::getEmptyValue(); - aRow[3] = ::connectivity::ODatabaseMetaDataResultSet::getEmptyValue(); - aRow[4] = ::connectivity::ODatabaseMetaDataResultSet::getEmptyValue(); - aRow[5] = new ::connectivity::ORowSetValueDecorator(getUserName()); - aRow[7] = new ::connectivity::ORowSetValueDecorator(OUString("NO")); - - - // Iterate over all tables - for(const OUString & table : tables) { - if(match(tableNamePattern, table,'\0')) - { - // TABLE_NAME - aRow[2] = new ORowSetValueDecorator( table ); - - SAL_INFO("connectivity.mork", "\tTableName = : " << table); - - aRow[6] = ::connectivity::ODatabaseMetaDataResultSet::getSelectValue(); - aRows.push_back(aRow); - aRow[6] = ::connectivity::ODatabaseMetaDataResultSet::getInsertValue(); - aRows.push_back(aRow); - aRow[6] = ::connectivity::ODatabaseMetaDataResultSet::getDeleteValue(); - aRows.push_back(aRow); - aRow[6] = ::connectivity::ODatabaseMetaDataResultSet::getUpdateValue(); - aRows.push_back(aRow); - aRow[6] = ::connectivity::ODatabaseMetaDataResultSet::getCreateValue(); - aRows.push_back(aRow); - aRow[6] = ::connectivity::ODatabaseMetaDataResultSet::getReadValue(); - aRows.push_back(aRow); - aRow[6] = ::connectivity::ODatabaseMetaDataResultSet::getAlterValue(); - aRows.push_back(aRow); - aRow[6] = ::connectivity::ODatabaseMetaDataResultSet::getDropValue(); - aRows.push_back(aRow); - } - } - pResult->setRows(aRows); - return xRef; -} - -Reference< XResultSet > SAL_CALL ODatabaseMetaData::getUDTs( const Any& /*catalog*/, const OUString& /*schemaPattern*/, const OUString& /*typeNamePattern*/, const Sequence< sal_Int32 >& /*types*/ ) -{ - return nullptr; -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MDatabaseMetaData.hxx b/connectivity/source/drivers/mork/MDatabaseMetaData.hxx deleted file mode 100644 index 8677fc7aa903..000000000000 --- a/connectivity/source/drivers/mork/MDatabaseMetaData.hxx +++ /dev/null @@ -1,191 +0,0 @@ -/* -*- 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/. - */ - -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MDATABASEMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MDATABASEMETADATA_HXX - -#include <memory> -#include <TDatabaseMetaDataBase.hxx> -#include "MConnection.hxx" - -namespace connectivity -{ - namespace mork - { - class MDatabaseMetaDataHelper; - - //************ Class: ODatabaseMetaData - - - class ODatabaseMetaData : public ODatabaseMetaDataBase - { - OConnection* m_pConnection; - std::unique_ptr<MDatabaseMetaDataHelper> - m_pMetaDataHelper; - - /// @throws css::sdbc::SQLException - ODatabaseMetaDataResultSet::ORows getColumnRows( const OUString& tableNamePattern, const OUString& columnNamePattern ); - - protected: - virtual ~ODatabaseMetaData() override; - - public: - explicit ODatabaseMetaData(OConnection* _pCon); - - private: - virtual css::uno::Reference< css::sdbc::XResultSet > impl_getTypeInfo_throw() override; - // cached database information - virtual OUString impl_getIdentifierQuoteString_throw( ) override; - virtual bool impl_isCatalogAtStart_throw( ) override; - virtual OUString impl_getCatalogSeparator_throw( ) override; - virtual bool impl_supportsCatalogsInTableDefinitions_throw( ) override; - virtual bool impl_supportsSchemasInTableDefinitions_throw( ) override ; - virtual bool impl_supportsCatalogsInDataManipulation_throw( ) override; - virtual bool impl_supportsSchemasInDataManipulation_throw( ) override ; - virtual bool impl_supportsMixedCaseQuotedIdentifiers_throw( ) override ; - virtual bool impl_supportsAlterTableWithAddColumn_throw( ) override; - virtual bool impl_supportsAlterTableWithDropColumn_throw( ) override; - virtual sal_Int32 impl_getMaxStatements_throw( ) override; - virtual sal_Int32 impl_getMaxTablesInSelect_throw( ) override; - virtual bool impl_storesMixedCaseQuotedIdentifiers_throw( ) override; - - // as I mentioned before this interface is really BIG - // XDatabaseMetaData - virtual sal_Bool SAL_CALL allProceduresAreCallable( ) override; - virtual sal_Bool SAL_CALL allTablesAreSelectable( ) override; - virtual OUString SAL_CALL getURL( ) override; - virtual OUString SAL_CALL getUserName( ) override; - virtual sal_Bool SAL_CALL isReadOnly( ) override; - virtual sal_Bool SAL_CALL nullsAreSortedHigh( ) override; - virtual sal_Bool SAL_CALL nullsAreSortedLow( ) override; - virtual sal_Bool SAL_CALL nullsAreSortedAtStart( ) override; - virtual sal_Bool SAL_CALL nullsAreSortedAtEnd( ) override; - virtual OUString SAL_CALL getDatabaseProductName( ) override; - virtual OUString SAL_CALL getDatabaseProductVersion( ) override; - virtual OUString SAL_CALL getDriverName( ) override; - virtual OUString SAL_CALL getDriverVersion( ) override; - virtual sal_Int32 SAL_CALL getDriverMajorVersion( ) override; - virtual sal_Int32 SAL_CALL getDriverMinorVersion( ) override; - virtual sal_Bool SAL_CALL usesLocalFiles( ) override; - virtual sal_Bool SAL_CALL usesLocalFilePerTable( ) override; - virtual sal_Bool SAL_CALL supportsMixedCaseIdentifiers( ) override; - virtual sal_Bool SAL_CALL storesUpperCaseIdentifiers( ) override; - virtual sal_Bool SAL_CALL storesLowerCaseIdentifiers( ) override; - virtual sal_Bool SAL_CALL storesMixedCaseIdentifiers( ) override; - virtual sal_Bool SAL_CALL storesUpperCaseQuotedIdentifiers( ) override; - virtual sal_Bool SAL_CALL storesLowerCaseQuotedIdentifiers( ) override; - virtual OUString SAL_CALL getSQLKeywords( ) override; - virtual OUString SAL_CALL getNumericFunctions( ) override; - virtual OUString SAL_CALL getStringFunctions( ) override; - virtual OUString SAL_CALL getSystemFunctions( ) override; - virtual OUString SAL_CALL getTimeDateFunctions( ) override; - virtual OUString SAL_CALL getSearchStringEscape( ) override; - virtual OUString SAL_CALL getExtraNameCharacters( ) override; - virtual sal_Bool SAL_CALL supportsColumnAliasing( ) override; - virtual sal_Bool SAL_CALL nullPlusNonNullIsNull( ) override; - virtual sal_Bool SAL_CALL supportsTypeConversion( ) override; - virtual sal_Bool SAL_CALL supportsConvert( sal_Int32 fromType, sal_Int32 toType ) override; - virtual sal_Bool SAL_CALL supportsTableCorrelationNames( ) override; - virtual sal_Bool SAL_CALL supportsDifferentTableCorrelationNames( ) override; - virtual sal_Bool SAL_CALL supportsExpressionsInOrderBy( ) override; - virtual sal_Bool SAL_CALL supportsOrderByUnrelated( ) override; - virtual sal_Bool SAL_CALL supportsGroupBy( ) override; - virtual sal_Bool SAL_CALL supportsGroupByUnrelated( ) override; - virtual sal_Bool SAL_CALL supportsGroupByBeyondSelect( ) override; - virtual sal_Bool SAL_CALL supportsLikeEscapeClause( ) override; - virtual sal_Bool SAL_CALL supportsMultipleResultSets( ) override; - virtual sal_Bool SAL_CALL supportsMultipleTransactions( ) override; - virtual sal_Bool SAL_CALL supportsNonNullableColumns( ) override; - virtual sal_Bool SAL_CALL supportsMinimumSQLGrammar( ) override; - virtual sal_Bool SAL_CALL supportsCoreSQLGrammar( ) override; - virtual sal_Bool SAL_CALL supportsExtendedSQLGrammar( ) override; - virtual sal_Bool SAL_CALL supportsANSI92EntryLevelSQL( ) override; - virtual sal_Bool SAL_CALL supportsANSI92IntermediateSQL( ) override; - virtual sal_Bool SAL_CALL supportsANSI92FullSQL( ) override; - virtual sal_Bool SAL_CALL supportsIntegrityEnhancementFacility( ) override; - virtual sal_Bool SAL_CALL supportsOuterJoins( ) override; - virtual sal_Bool SAL_CALL supportsFullOuterJoins( ) override; - virtual sal_Bool SAL_CALL supportsLimitedOuterJoins( ) override; - virtual OUString SAL_CALL getSchemaTerm( ) override; - virtual OUString SAL_CALL getProcedureTerm( ) override; - virtual OUString SAL_CALL getCatalogTerm( ) override; - virtual sal_Bool SAL_CALL supportsSchemasInProcedureCalls( ) override; - virtual sal_Bool SAL_CALL supportsSchemasInIndexDefinitions( ) override; - virtual sal_Bool SAL_CALL supportsSchemasInPrivilegeDefinitions( ) override; - virtual sal_Bool SAL_CALL supportsCatalogsInProcedureCalls( ) override; - virtual sal_Bool SAL_CALL supportsCatalogsInIndexDefinitions( ) override; - virtual sal_Bool SAL_CALL supportsCatalogsInPrivilegeDefinitions( ) override; - virtual sal_Bool SAL_CALL supportsPositionedDelete( ) override; - virtual sal_Bool SAL_CALL supportsPositionedUpdate( ) override; - virtual sal_Bool SAL_CALL supportsSelectForUpdate( ) override; - virtual sal_Bool SAL_CALL supportsStoredProcedures( ) override; - virtual sal_Bool SAL_CALL supportsSubqueriesInComparisons( ) override; - virtual sal_Bool SAL_CALL supportsSubqueriesInExists( ) override; - virtual sal_Bool SAL_CALL supportsSubqueriesInIns( ) override; - virtual sal_Bool SAL_CALL supportsSubqueriesInQuantifieds( ) override; - virtual sal_Bool SAL_CALL supportsCorrelatedSubqueries( ) override; - virtual sal_Bool SAL_CALL supportsUnion( ) override; - virtual sal_Bool SAL_CALL supportsUnionAll( ) override; - virtual sal_Bool SAL_CALL supportsOpenCursorsAcrossCommit( ) override; - virtual sal_Bool SAL_CALL supportsOpenCursorsAcrossRollback( ) override; - virtual sal_Bool SAL_CALL supportsOpenStatementsAcrossCommit( ) override; - virtual sal_Bool SAL_CALL supportsOpenStatementsAcrossRollback( ) override; - virtual sal_Int32 SAL_CALL getMaxBinaryLiteralLength( ) override; - virtual sal_Int32 SAL_CALL getMaxCharLiteralLength( ) override; - virtual sal_Int32 SAL_CALL getMaxColumnNameLength( ) override; - virtual sal_Int32 SAL_CALL getMaxColumnsInGroupBy( ) override; - virtual sal_Int32 SAL_CALL getMaxColumnsInIndex( ) override; - virtual sal_Int32 SAL_CALL getMaxColumnsInOrderBy( ) override; - virtual sal_Int32 SAL_CALL getMaxColumnsInSelect( ) override; - virtual sal_Int32 SAL_CALL getMaxColumnsInTable( ) override; - virtual sal_Int32 SAL_CALL getMaxConnections( ) override; - virtual sal_Int32 SAL_CALL getMaxCursorNameLength( ) override; - virtual sal_Int32 SAL_CALL getMaxIndexLength( ) override; - virtual sal_Int32 SAL_CALL getMaxSchemaNameLength( ) override; - virtual sal_Int32 SAL_CALL getMaxProcedureNameLength( ) override; - virtual sal_Int32 SAL_CALL getMaxCatalogNameLength( ) override; - virtual sal_Int32 SAL_CALL getMaxRowSize( ) override; - virtual sal_Bool SAL_CALL doesMaxRowSizeIncludeBlobs( ) override; - virtual sal_Int32 SAL_CALL getMaxStatementLength( ) override; - virtual sal_Int32 SAL_CALL getMaxTableNameLength( ) override; - virtual sal_Int32 SAL_CALL getMaxUserNameLength( ) override; - virtual sal_Int32 SAL_CALL getDefaultTransactionIsolation( ) override; - virtual sal_Bool SAL_CALL supportsTransactions( ) override; - virtual sal_Bool SAL_CALL supportsTransactionIsolationLevel( sal_Int32 level ) override; - virtual sal_Bool SAL_CALL supportsDataDefinitionAndDataManipulationTransactions( ) override; - virtual sal_Bool SAL_CALL supportsDataManipulationTransactionsOnly( ) override; - virtual sal_Bool SAL_CALL dataDefinitionCausesTransactionCommit( ) override; - virtual sal_Bool SAL_CALL dataDefinitionIgnoredInTransactions( ) override; - - virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTables( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const css::uno::Sequence< OUString >& types ) override; - virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTableTypes( ) override; - virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTablePrivileges( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern ) override; - virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getColumns( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const OUString& columnNamePattern ) override; - - virtual sal_Bool SAL_CALL supportsResultSetType( sal_Int32 setType ) override; - virtual sal_Bool SAL_CALL supportsResultSetConcurrency( sal_Int32 setType, sal_Int32 concurrency ) override; - virtual sal_Bool SAL_CALL ownUpdatesAreVisible( sal_Int32 setType ) override; - virtual sal_Bool SAL_CALL ownDeletesAreVisible( sal_Int32 setType ) override; - virtual sal_Bool SAL_CALL ownInsertsAreVisible( sal_Int32 setType ) override; - virtual sal_Bool SAL_CALL othersUpdatesAreVisible( sal_Int32 setType ) override; - virtual sal_Bool SAL_CALL othersDeletesAreVisible( sal_Int32 setType ) override; - virtual sal_Bool SAL_CALL othersInsertsAreVisible( sal_Int32 setType ) override; - virtual sal_Bool SAL_CALL updatesAreDetected( sal_Int32 setType ) override; - virtual sal_Bool SAL_CALL deletesAreDetected( sal_Int32 setType ) override; - virtual sal_Bool SAL_CALL insertsAreDetected( sal_Int32 setType ) override; - virtual sal_Bool SAL_CALL supportsBatchUpdates( ) override; - - virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getUDTs( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& typeNamePattern, const css::uno::Sequence< sal_Int32 >& types ) override; - }; - } -} - -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MDATABASEMETADATA_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MDatabaseMetaDataHelper.cxx b/connectivity/source/drivers/mork/MDatabaseMetaDataHelper.cxx deleted file mode 100644 index ca699bafaefd..000000000000 --- a/connectivity/source/drivers/mork/MDatabaseMetaDataHelper.cxx +++ /dev/null @@ -1,123 +0,0 @@ -/* -*- 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/. - */ - -#include "MConnection.hxx" -#include "MDatabaseMetaDataHelper.hxx" - -// do we need it? -static ::osl::Mutex m_aMetaMutex; - -#include <sal/log.hxx> - -#include "MorkParser.hxx" - -using namespace connectivity; -using namespace connectivity::mork; - - -MDatabaseMetaDataHelper::MDatabaseMetaDataHelper() -{ - SAL_INFO("connectivity.mork", "=> MDatabaseMetaDataHelper::MDatabaseMetaDataHelper()" ); -} - - -MDatabaseMetaDataHelper::~MDatabaseMetaDataHelper() -{ -} - -void MDatabaseMetaDataHelper::getTableStrings( OConnection* _pCon, - std::vector< OUString >& _rStrings) -{ - SAL_INFO("connectivity.mork", "=> MDatabaseMetaDataHelper::getTableStrings()"); - - /* add default tables */ - _rStrings.push_back("AddressBook"); - _rStrings.push_back("CollectedAddressBook"); - - /* retrieve list table names (not from collected ab) */ - std::set<std::string> lists; - MorkParser* pMork = _pCon->getMorkParser("AddressBook"); - pMork->retrieveLists(lists); - for (auto const& elem : lists) - { - OUString groupTableName = OStringToOUString(elem.c_str(), RTL_TEXTENCODING_UTF8); - SAL_INFO("connectivity.mork", "add Table " << groupTableName); - - _rStrings.push_back(groupTableName); - // remember the list in the mork parser, we'll use it later - pMork->lists_.push_back(groupTableName); - } - - std::set<std::string> lists_history; - pMork = _pCon->getMorkParser("CollectedAddressBook"); - pMork->retrieveLists(lists_history); - for (auto const& elem : lists_history) - { - OUString groupTableName = OStringToOUString(elem.c_str(), RTL_TEXTENCODING_UTF8); - SAL_INFO("connectivity.mork", "add Table " << groupTableName); - - _rStrings.push_back(groupTableName); - // remember the list in the mork parser, we'll use it later - pMork->lists_.push_back(groupTableName); - } -} - -void MDatabaseMetaDataHelper::getTables( OConnection* _pCon, - const OUString& tableNamePattern, - ODatabaseMetaDataResultSet::ORows& _rRows) -{ - - SAL_INFO("connectivity.mork", "=> MDatabaseMetaDataHelper::getTables()"); - - static ODatabaseMetaDataResultSet::ORows aRows; - - SAL_INFO("connectivity.mork", "=> MDatabaseMetaDataHelper::getTables()" ); - SAL_INFO("connectivity.mork", "tableNamePattern : " << tableNamePattern); - ::osl::MutexGuard aGuard( m_aMetaMutex ); - - ODatabaseMetaDataResultSet::ORows().swap(aRows); // this makes real clear where memory is freed as well - aRows.clear(); - - std::vector< OUString > tables; - - getTableStrings( _pCon, tables ); - - for (OUString& aTableName : tables) { - ODatabaseMetaDataResultSet::ORow aRow { nullptr, nullptr, nullptr }; - - SAL_INFO("connectivity.mork", "TableName: " << aTableName ); - - - // return tables to caller - if (match( tableNamePattern, aTableName, '\0' )) - { - if ( aTableName.isEmpty() ) { - aTableName = "AddressBook"; - } - - SAL_INFO("connectivity.mork", "TableName: " << aTableName); - - aRow.push_back( new ORowSetValueDecorator( aTableName ) ); // Table/View name - if ((aTableName == "AddressBook") || (aTableName == "CollectedAddressBook")) - { - aRow.push_back( new ORowSetValueDecorator( OUString("TABLE") ) ); // Table type - } - else - { - aRow.push_back( new ORowSetValueDecorator( OUString("VIEW") ) ); // View type - } - aRow.push_back( ODatabaseMetaDataResultSet::getEmptyValue() ); // Remarks - aRows.push_back(aRow); - } - } - - _rRows = aRows; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MDatabaseMetaDataHelper.hxx b/connectivity/source/drivers/mork/MDatabaseMetaDataHelper.hxx deleted file mode 100644 index 0ae96dac96a6..000000000000 --- a/connectivity/source/drivers/mork/MDatabaseMetaDataHelper.hxx +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- 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/. - */ - -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MDATABASEMETADATAHELPER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MDATABASEMETADATAHELPER_HXX - -#include <FDatabaseMetaDataResultSet.hxx> -#include "MConnection.hxx" - -namespace connectivity -{ - namespace mork - { - class MDatabaseMetaDataHelper - { - public: - MDatabaseMetaDataHelper(); - ~MDatabaseMetaDataHelper(); - - - static void getTableStrings( OConnection* _pCon, - std::vector< OUString >& _rStrings); - - static void getTables( OConnection* _pCon, - const OUString& tableNamePattern, - ODatabaseMetaDataResultSet::ORows& _rRows); - }; - } -} - -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MDATABASEMETADATAHELPER_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MDriver.cxx b/connectivity/source/drivers/mork/MDriver.cxx deleted file mode 100644 index 0351b6c3e04f..000000000000 --- a/connectivity/source/drivers/mork/MDriver.cxx +++ /dev/null @@ -1,133 +0,0 @@ -/* -*- 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/. - */ - -#include "MDriver.hxx" -#include "MConnection.hxx" - -#include <com/sun/star/mozilla/XMozillaBootstrap.hpp> -#include <com/sun/star/uno/XComponentContext.hpp> - -#include <sal/log.hxx> - -using namespace connectivity::mork; - -extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_sdbc_MorkDriver_get_implementation( - css::uno::XComponentContext* context, - css::uno::Sequence<css::uno::Any> const &) -{ - return cppu::acquire(new MorkDriver(context)); -} - -MorkDriver::MorkDriver(const css::uno::Reference< css::uno::XComponentContext >& context): - context_(context), - m_xFactory(context_->getServiceManager(), css::uno::UNO_QUERY) -{ - SAL_INFO("connectivity.mork", "=> MorkDriver::MorkDriver()" ); -} - -OUString SAL_CALL MorkDriver::getImplementationName() -{ - return MORK_DRIVER_IMPL_NAME; -} - -sal_Bool SAL_CALL MorkDriver::supportsService(const OUString& serviceName) -{ - return cppu::supportsService(this, serviceName); -} - -css::uno::Sequence< OUString > MorkDriver::getSupportedServiceNames() -{ - return { "com.sun.star.sdbc.Driver" }; -} - -css::uno::Reference< css::sdbc::XConnection > MorkDriver::connect( - OUString const & url, - css::uno::Sequence< css::beans::PropertyValue > const &) -{ - SAL_INFO("connectivity.mork", "=> MorkDriver::connect()" ); - - // Profile discovery - css::uno::Reference<css::uno::XInterface> xInstance = context_->getServiceManager()->createInstanceWithContext("com.sun.star.mozilla.MozillaBootstrap", context_); - OSL_ENSURE( xInstance.is(), "failed to create instance" ); - - css::uno::Reference<css::mozilla::XMozillaBootstrap> xMozillaBootstrap(xInstance, css::uno::UNO_QUERY); - OSL_ENSURE( xMozillaBootstrap.is(), "failed to create instance" ); - - if (xMozillaBootstrap.is()) - { - OUString defaultProfile = xMozillaBootstrap->getDefaultProfile(css::mozilla::MozillaProductType_Thunderbird); - - if (!defaultProfile.isEmpty()) - { - m_sProfilePath = xMozillaBootstrap->getProfilePath(css::mozilla::MozillaProductType_Thunderbird, defaultProfile); - SAL_INFO("connectivity.mork", "Using Thunderbird profile " << m_sProfilePath); - } - } - - css::uno::Reference< css::sdbc::XConnection > xCon; - OConnection* pCon = new OConnection(this); - xCon = pCon; // important here because otherwise the connection could be deleted inside (refcount goes -> 0) - pCon->construct(url); - return xCon; -} - -sal_Bool MorkDriver::acceptsURL(OUString const & url) -{ - SAL_INFO("connectivity.mork", "=> MorkDriver::acceptsURL()" ); - // Skip 'sdbc:mozab: part of URL - - sal_Int32 nLen = url.indexOf(':'); - nLen = url.indexOf(':',nLen+1); - OUString aAddrbookURI(url.copy(nLen+1)); - // Get Scheme - nLen = aAddrbookURI.indexOf(':'); - OUString aAddrbookScheme; - if ( nLen == -1 ) - { - // There isn't any subschema: - but could be just subschema - if ( !aAddrbookURI.isEmpty() ) - { - aAddrbookScheme= aAddrbookURI; - } - else if( url == "sdbc:address:" ) - { - return false; - } - else - { - return false; - } - } - else - { - aAddrbookScheme = aAddrbookURI.copy(0, nLen); - } - - return aAddrbookScheme == "thunderbird" || aAddrbookScheme == "mozilla"; -} - -css::uno::Sequence< css::sdbc::DriverPropertyInfo > MorkDriver::getPropertyInfo( - OUString const &, - css::uno::Sequence< css::beans::PropertyValue > const &) -{ - //... TODO - return css::uno::Sequence< css::sdbc::DriverPropertyInfo >(); -} - -sal_Int32 MorkDriver::getMajorVersion() { - //... TODO - return 0; -} - -sal_Int32 MorkDriver::getMinorVersion() { - //... TODO - return 0; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MDriver.hxx b/connectivity/source/drivers/mork/MDriver.hxx deleted file mode 100644 index 6f6946af6f5b..000000000000 --- a/connectivity/source/drivers/mork/MDriver.hxx +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- 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/. - */ - -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MDRIVER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MDRIVER_HXX - -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/sdbc/DriverPropertyInfo.hpp> - -#include <com/sun/star/sdbc/XDriver.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <cppuhelper/implbase.hxx> - -#define MORK_DRIVER_IMPL_NAME "com.sun.star.comp.sdbc.MorkDriver" - -namespace com::sun::star { - namespace uno { - class XComponentContext; - class XInterface; - } -} - -namespace connectivity::mork { -class ProfileAccess; - -class MorkDriver: - public cppu::WeakImplHelper< css::lang::XServiceInfo, css::sdbc::XDriver > -{ -public: - explicit MorkDriver(const css::uno::Reference< css::uno::XComponentContext >& context); - - const css::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& getFactory() const {return m_xFactory;} - const OUString& getProfilePath() const {return m_sProfilePath;} -private: - - MorkDriver(const MorkDriver&) = delete; - MorkDriver& operator=(const MorkDriver&) = delete; - - virtual ~MorkDriver() override {} - - virtual OUString SAL_CALL getImplementationName() override; - - virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override; - - virtual css::uno::Sequence< OUString > SAL_CALL - getSupportedServiceNames() override; - - virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL connect( - OUString const & url, - css::uno::Sequence< css::beans::PropertyValue > const & info) override; - - virtual sal_Bool SAL_CALL acceptsURL( - OUString const & url) override; - - virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL - getPropertyInfo( - OUString const & url, - css::uno::Sequence< css::beans::PropertyValue > const & info) override; - - virtual sal_Int32 SAL_CALL getMajorVersion() override; - - virtual sal_Int32 SAL_CALL getMinorVersion() override; - - css::uno::Reference< css::uno::XComponentContext > context_; - css::uno::Reference< css::lang::XMultiServiceFactory > m_xFactory; - OUString m_sProfilePath; -}; - -} - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MErrorResource.hxx b/connectivity/source/drivers/mork/MErrorResource.hxx deleted file mode 100644 index 0691b18134f4..000000000000 --- a/connectivity/source/drivers/mork/MErrorResource.hxx +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- 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 . - */ - -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MERRORRESOURCE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MERRORRESOURCE_HXX - -namespace connectivity -{ - namespace mork - { - class ErrorDescriptor - { - private: - const char* m_pErrorResourceId; - - public: - ErrorDescriptor() - :m_pErrorResourceId(nullptr) - { - } - - void setResId(const char* pErrorResourceId) - { - m_pErrorResourceId = pErrorResourceId; - } - void reset() - { - m_pErrorResourceId = nullptr; - } - - const char* getResId() const { return m_pErrorResourceId; } - - bool is() const { return m_pErrorResourceId != nullptr; } - }; - } -} - -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MERRORRESOURCE_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MPreparedStatement.cxx b/connectivity/source/drivers/mork/MPreparedStatement.cxx deleted file mode 100644 index f2cd8fdc752e..000000000000 --- a/connectivity/source/drivers/mork/MPreparedStatement.cxx +++ /dev/null @@ -1,486 +0,0 @@ -/* -*- 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/. - */ - -#include <connectivity/sdbcx/VColumn.hxx> -#include "MPreparedStatement.hxx" -#include "MResultSetMetaData.hxx" -#include <connectivity/dbtools.hxx> -#include <comphelper/types.hxx> -#include <com/sun/star/sdbc/ColumnValue.hpp> -#include <sal/log.hxx> - -using namespace ::comphelper; -using namespace connectivity; -using namespace connectivity::mork; -using namespace com::sun::star::uno; -using namespace com::sun::star::sdbc; -using namespace com::sun::star::container; -using namespace com::sun::star::util; - -IMPLEMENT_SERVICE_INFO(OPreparedStatement,"com.sun.star.sdbcx.mork.PreparedStatement","com.sun.star.sdbc.PreparedStatement"); - - -OPreparedStatement::OPreparedStatement( OConnection* _pConnection,const OUString& sql) - :OCommonStatement(_pConnection) - ,m_sSqlStatement(sql) - ,m_pResultSet() -{ -} - -OPreparedStatement::~OPreparedStatement() -{ -} - -void OPreparedStatement::lateInit() -{ - if ( eSelect != parseSql( m_sSqlStatement ) ) - throw SQLException(); -} - -void SAL_CALL OPreparedStatement::disposing() -{ - ::osl::MutexGuard aGuard(m_aMutex); - - OCommonStatement::disposing(); - - m_xMetaData.clear(); - if(m_aParameterRow.is()) - { - m_aParameterRow->clear(); - m_aParameterRow = nullptr; - } - m_xParamColumns = nullptr; -} - -OCommonStatement::StatementType OPreparedStatement::parseSql( const OUString& sql , bool bAdjusted ) -{ - StatementType eStatementType = OCommonStatement::parseSql( sql, bAdjusted ); - if ( eStatementType != eSelect ) - return eStatementType; - - m_xParamColumns = new OSQLColumns(); - - // describe all parameters need for the resultset - describeParameter(); - - Reference<XIndexAccess> xNames(m_xColNames,UNO_QUERY); - OResultSet::setBoundedColumns( m_aRow, m_xParamColumns, xNames, false, m_xDBMetaData, m_aColMapping ); - - return eStatementType; -} - -void OPreparedStatement::initializeResultSet( OResultSet* _pResult ) -{ - OCommonStatement::initializeResultSet( _pResult ); - _pResult->setParameterRow( m_aParameterRow ); -} - - -void OPreparedStatement::clearCachedResultSet() -{ - OCommonStatement::clearCachedResultSet(); - m_pResultSet.clear(); - m_xMetaData.clear(); -} - -void OPreparedStatement::cacheResultSet( const ::rtl::Reference< OResultSet >& _pResult ) -{ - OCommonStatement::cacheResultSet( _pResult ); - OSL_PRECOND( m_pResultSet == nullptr, "OPreparedStatement::parseSql: you should call clearCachedResultSet before!" ); - m_pResultSet = _pResult; -} - - -void SAL_CALL OPreparedStatement::acquire() throw() -{ - OCommonStatement::acquire(); -} - -void SAL_CALL OPreparedStatement::release() throw() -{ - OCommonStatement::release(); -} - -Any SAL_CALL OPreparedStatement::queryInterface( const Type & rType ) -{ - Any aRet = OCommonStatement::queryInterface(rType); - if(!aRet.hasValue()) - aRet = OPreparedStatement_BASE::queryInterface(rType); - return aRet; -} - -css::uno::Sequence< css::uno::Type > SAL_CALL OPreparedStatement::getTypes( ) -{ - return ::comphelper::concatSequences(OPreparedStatement_BASE::getTypes(),OCommonStatement::getTypes()); -} - - -Reference< XResultSetMetaData > SAL_CALL OPreparedStatement::getMetaData( ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed); - - bool bReadOnly = true; - if ( m_pResultSet.is() ) - bReadOnly = m_pResultSet->determineReadOnly(); - // if we do not have a result set, then we have not been executed, yet. In this case, assuming readonly=true is - // okay, /me thinks. - - if ( !m_xMetaData.is() ) - m_xMetaData = new OResultSetMetaData( m_pSQLIterator->getSelectColumns(), m_pSQLIterator->getTables().begin()->first ,m_pTable,bReadOnly ); - - return m_xMetaData; -} - - -sal_Bool SAL_CALL OPreparedStatement::execute( ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed); - - Reference< XResultSet> xResult = executeQuery(); - return xResult.is(); -} - - -sal_Int32 SAL_CALL OPreparedStatement::executeUpdate( ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XStatement::executeUpdate", *this ); - return 0; -} - - -void SAL_CALL OPreparedStatement::setString( sal_Int32 parameterIndex, const OUString& x ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed); - - setParameter( parameterIndex, x ); -} - - -Reference< XConnection > SAL_CALL OPreparedStatement::getConnection( ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed); - - return Reference< XConnection >(m_pConnection.get()); -} - - -Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery( ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed); - - // our statement has already been parsed in lateInit, no need to do all this (potentially expensive) - // stuff again. Just execute. - return impl_executeCurrentQuery(); -} - - -void SAL_CALL OPreparedStatement::setBoolean( sal_Int32 /*parameterIndex*/, sal_Bool /*x*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setBoolean", *this ); -} - -void SAL_CALL OPreparedStatement::setByte( sal_Int32 /*parameterIndex*/, sal_Int8 /*x*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setByte", *this ); -} - - -void SAL_CALL OPreparedStatement::setDate( sal_Int32 /*parameterIndex*/, const Date& /*aData*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setDate", *this ); -} - - -void SAL_CALL OPreparedStatement::setTime( sal_Int32 /*parameterIndex*/, const css::util::Time& /*aVal*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setTime", *this ); -} - - -void SAL_CALL OPreparedStatement::setTimestamp( sal_Int32 /*parameterIndex*/, const DateTime& /*aVal*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setTimestamp", *this ); -} - - -void SAL_CALL OPreparedStatement::setDouble( sal_Int32 /*parameterIndex*/, double /*x*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setDouble", *this ); -} - - -void SAL_CALL OPreparedStatement::setFloat( sal_Int32 /*parameterIndex*/, float /*x*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setFloat", *this ); -} - - -void SAL_CALL OPreparedStatement::setInt( sal_Int32 /*parameterIndex*/, sal_Int32 /*x*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setInt", *this ); -} - - -void SAL_CALL OPreparedStatement::setLong( sal_Int32 /*parameterIndex*/, sal_Int64 /*aVal*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setLong", *this ); -} - - -void SAL_CALL OPreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 /*sqlType*/ ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed); - - checkAndResizeParameters(parameterIndex); - - (*m_aParameterRow)[parameterIndex].setNull(); -} - - -void SAL_CALL OPreparedStatement::setClob( sal_Int32 /*parameterIndex*/, const Reference< XClob >& /*x*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setClob", *this ); -} - - -void SAL_CALL OPreparedStatement::setBlob( sal_Int32 /*parameterIndex*/, const Reference< XBlob >& /*x*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setBlob", *this ); -} - - -void SAL_CALL OPreparedStatement::setArray( sal_Int32 /*parameterIndex*/, const Reference< XArray >& /*x*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setArray", *this ); -} - - -void SAL_CALL OPreparedStatement::setRef( sal_Int32 /*parameterIndex*/, const Reference< XRef >& /*x*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setRef", *this ); -} - - -void SAL_CALL OPreparedStatement::setObjectWithInfo( sal_Int32 /*parameterIndex*/, const Any& /*x*/, sal_Int32 /*sqlType*/, sal_Int32 /*scale*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setObjectWithInfo", *this ); -} - - -void SAL_CALL OPreparedStatement::setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const OUString& /*typeName*/ ) -{ - setNull(parameterIndex,sqlType); -} - - -void SAL_CALL OPreparedStatement::setObject( sal_Int32 parameterIndex, const Any& x ) -{ - ::dbtools::implSetObject(this,parameterIndex,x); -} - - -void SAL_CALL OPreparedStatement::setShort( sal_Int32 /*parameterIndex*/, sal_Int16 /*x*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setShort", *this ); -} - - -void SAL_CALL OPreparedStatement::setBytes( sal_Int32 /*parameterIndex*/, const Sequence< sal_Int8 >& /*x*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setBytes", *this ); -} - - -void SAL_CALL OPreparedStatement::setCharacterStream( sal_Int32 /*parameterIndex*/, const Reference< css::io::XInputStream >& /*x*/, sal_Int32 /*length*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setCharacterStream", *this ); -} - - -void SAL_CALL OPreparedStatement::setBinaryStream( sal_Int32 /*parameterIndex*/, const Reference< css::io::XInputStream >& /*x*/, sal_Int32 /*length*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XParameters::setBinaryStream", *this ); -} - - -void SAL_CALL OPreparedStatement::clearParameters( ) -{ -} - -void OPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) -{ - switch(nHandle) - { - case PROPERTY_ID_RESULTSETCONCURRENCY: - break; - case PROPERTY_ID_RESULTSETTYPE: - break; - case PROPERTY_ID_FETCHDIRECTION: - break; - case PROPERTY_ID_USEBOOKMARKS: - break; - default: - OCommonStatement::setFastPropertyValue_NoBroadcast(nHandle,rValue); - } -} - - -void OPreparedStatement::checkAndResizeParameters(sal_Int32 parameterIndex) -{ - ::connectivity::checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed); - - if ( !m_aParameterRow.is() ) { - m_aParameterRow = new OValueVector(); - m_aParameterRow->push_back(sal_Int32(0)); - } - - if (static_cast<sal_Int32>(m_aParameterRow->size()) <= parameterIndex) - m_aParameterRow->resize(parameterIndex+1); -} - -void OPreparedStatement::setParameter(sal_Int32 parameterIndex, const -ORowSetValue& x) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - checkAndResizeParameters(parameterIndex); - - SAL_INFO( - "connectivity.mork", - "setParameter(" << parameterIndex << ", '" << x.getString() << "')"); - (*m_aParameterRow)[parameterIndex] = x; -} - - -void OPreparedStatement::AddParameter(OSQLParseNode const * pParameter, const Reference<XPropertySet>& _xCol) -{ - OSL_ENSURE(SQL_ISRULE(pParameter,parameter),"OResultSet::AddParameter: Argument is not a Parameter"); - OSL_ENSURE(pParameter->count() > 0,"OResultSet: error in parse tree"); - - OUString sParameterName; - - // set up Parameter-Column: - sal_Int32 eType = DataType::VARCHAR; - sal_uInt32 nPrecision = 255; - sal_Int32 nScale = 0; - sal_Int32 nNullable = ColumnValue::NULLABLE; - - if (_xCol.is()) - { - // Type, Precision, Scale ... utilize the selected Columns, - // then this Column will get the value assigned or with this - // Column will the value be compared. - eType = getINT32(_xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))); - nPrecision = getINT32(_xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))); - nScale = getINT32(_xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))); - nNullable = getINT32(_xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))); - _xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= sParameterName; - } - - Reference<XPropertySet> xParaColumn = new connectivity::sdbcx::OColumn(sParameterName - ,OUString() - ,OUString() - ,OUString() - ,nNullable - ,nPrecision - ,nScale - ,eType - ,false - ,false - ,false - ,m_pSQLIterator->isCaseSensitive() - ,OUString() - ,OUString() - ,OUString()); - m_xParamColumns->push_back(xParaColumn); -} - -void OPreparedStatement::describeColumn(OSQLParseNode const * _pParameter, - OSQLParseNode const * _pNode, - const OSQLTable& _xTable) -{ - Reference<XPropertySet> xProp; - if(SQL_ISRULE(_pNode,column_ref)) - { - OUString sColumnName,sTableRange; - m_pSQLIterator->getColumnRange(_pNode,sColumnName,sTableRange); - if(!sColumnName.isEmpty()) - { - Reference<XNameAccess> xNameAccess = _xTable->getColumns(); - if(xNameAccess->hasByName(sColumnName)) - xNameAccess->getByName(sColumnName) >>= xProp; - AddParameter(_pParameter,xProp); - } - } - // else - // AddParameter(_pParameter,xProp); -} - -void OPreparedStatement::describeParameter() -{ - std::vector< OSQLParseNode*> aParseNodes; - scanParameter(m_pParseTree.get(), aParseNodes); - if(aParseNodes.empty()) - return; - - m_xParamColumns = new OSQLColumns(); - const OSQLTables& rTabs = m_pSQLIterator->getTables(); - if(!rTabs.empty()) - { - OSQLTable xTable = rTabs.begin()->second; - for (auto const& parseNode : aParseNodes) - { - describeColumn(parseNode,parseNode->getParent()->getChild(0),xTable); - } - } -} - - -void OPreparedStatement::scanParameter(OSQLParseNode* pParseNode,std::vector< OSQLParseNode*>& _rParaNodes) -{ - OSL_ENSURE(pParseNode != nullptr,"OResultSet: internal error: invalid ParseNode"); - - // Parameter Name-Row found? - if (SQL_ISRULE(pParseNode,parameter)) - { - OSL_ENSURE(pParseNode->count() >= 1,"OResultSet: Faulty Parse Tree"); - OSL_ENSURE(pParseNode->getChild(0)->getNodeType() == SQLNodeType::Punctuation,"OResultSet: Faulty Parse Tree"); - - _rParaNodes.push_back(pParseNode); - // further search isn't necessary - return; - } - - // Search on in Parse Tree - for (size_t i = 0; i < pParseNode->count(); i++) - scanParameter(pParseNode->getChild(i),_rParaNodes); -} - -css::uno::Reference< css::sdbc::XResultSet > SAL_CALL OPreparedStatement::getResultSet( ) -{ - return nullptr; -} - -sal_Int32 SAL_CALL OPreparedStatement::getUpdateCount( ) -{ - return 0; -} - -sal_Bool SAL_CALL OPreparedStatement::getMoreResults( ) -{ - return false; -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MPreparedStatement.hxx b/connectivity/source/drivers/mork/MPreparedStatement.hxx deleted file mode 100644 index c40ffc90950e..000000000000 --- a/connectivity/source/drivers/mork/MPreparedStatement.hxx +++ /dev/null @@ -1,134 +0,0 @@ -/* -*- 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 . - */ - -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MPREPAREDSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MPREPAREDSTATEMENT_HXX - -#include "MResultSet.hxx" -#include <com/sun/star/sdbc/XParameters.hpp> -#include <com/sun/star/sdbc/XMultipleResults.hpp> -#include <cppuhelper/implbase5.hxx> - -namespace connectivity -{ - namespace mork - { - - typedef ::cppu::ImplHelper5< css::sdbc::XPreparedStatement, - css::sdbc::XParameters, - css::sdbc::XResultSetMetaDataSupplier, - css::sdbc::XMultipleResults, - css::lang::XServiceInfo> OPreparedStatement_BASE; - - class OPreparedStatement final : public OCommonStatement, - public OPreparedStatement_BASE - { - // Data attributes - - OUString m_sSqlStatement; - css::uno::Reference< css::sdbc::XResultSetMetaData > m_xMetaData; - ::rtl::Reference< OResultSet > m_pResultSet; - ::rtl::Reference<connectivity::OSQLColumns> m_xParamColumns; // the parameter columns - OValueRow m_aParameterRow; - - virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, - const css::uno::Any& rValue) override; - virtual ~OPreparedStatement() override; - - virtual void SAL_CALL disposing() override; - - // OCommonStatement overridables - virtual StatementType - parseSql( const OUString& sql , bool bAdjusted = false) override; - virtual void initializeResultSet( OResultSet* _pResult ) override; - virtual void clearCachedResultSet() override; - virtual void cacheResultSet( const ::rtl::Reference< OResultSet >& _pResult ) override; - - - void checkAndResizeParameters(sal_Int32 parameterIndex); - void setParameter(sal_Int32 parameterIndex, const ORowSetValue& x); - - void AddParameter(connectivity::OSQLParseNode const * pParameter, - const css::uno::Reference< css::beans::XPropertySet>& _xCol); - void scanParameter(OSQLParseNode* pParseNode,std::vector< OSQLParseNode*>& _rParaNodes); - void describeColumn(OSQLParseNode const * _pParameter, OSQLParseNode const * _pNode, const OSQLTable& _xTable); - void describeParameter(); - - public: - DECLARE_SERVICE_INFO(); - // A ctor need for returning the object - OPreparedStatement( OConnection* _pConnection,const OUString& sql); - void lateInit(); - - //XInterface - virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; - //XTypeProvider - virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; - - // XPreparedStatement - virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery( ) override; - virtual sal_Int32 SAL_CALL executeUpdate( ) override; - virtual sal_Bool SAL_CALL execute( ) override; - virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( ) override; - // XParameters - virtual void SAL_CALL setNull( sal_Int32 parameterIndex, sal_Int32 sqlType ) override; - virtual void SAL_CALL setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const OUString& typeName ) override; - virtual void SAL_CALL setBoolean( sal_Int32 parameterIndex, sal_Bool x ) override; - virtual void SAL_CALL setByte( sal_Int32 parameterIndex, sal_Int8 x ) override; - virtual void SAL_CALL setShort( sal_Int32 parameterIndex, sal_Int16 x ) override; - virtual void SAL_CALL setInt( sal_Int32 parameterIndex, sal_Int32 x ) override; - virtual void SAL_CALL setLong( sal_Int32 parameterIndex, sal_Int64 x ) override; - virtual void SAL_CALL setFloat( sal_Int32 parameterIndex, float x ) override; - virtual void SAL_CALL setDouble( sal_Int32 parameterIndex, double x ) override; - virtual void SAL_CALL setString( sal_Int32 parameterIndex, const OUString& x ) override; - virtual void SAL_CALL setBytes( sal_Int32 parameterIndex, const css::uno::Sequence< sal_Int8 >& x ) override; - virtual void SAL_CALL setDate( sal_Int32 parameterIndex, const css::util::Date& x ) override; - virtual void SAL_CALL setTime( sal_Int32 parameterIndex, const css::util::Time& x ) override; - virtual void SAL_CALL setTimestamp( sal_Int32 parameterIndex, const css::util::DateTime& x ) override; - virtual void SAL_CALL setBinaryStream( sal_Int32 parameterIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override; - virtual void SAL_CALL setCharacterStream( sal_Int32 parameterIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override; - virtual void SAL_CALL setObject( sal_Int32 parameterIndex, const css::uno::Any& x ) override; - virtual void SAL_CALL setObjectWithInfo( sal_Int32 parameterIndex, const css::uno::Any& x, sal_Int32 targetSqlType, sal_Int32 scale ) override; - virtual void SAL_CALL setRef( sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XRef >& x ) override; - virtual void SAL_CALL setBlob( sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XBlob >& x ) override; - virtual void SAL_CALL setClob( sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XClob >& x ) override; - virtual void SAL_CALL setArray( sal_Int32 parameterIndex, const css::uno::Reference< css::sdbc::XArray >& x ) override; - virtual void SAL_CALL clearParameters( ) override; - // XResultSetMetaDataSupplier - virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override; - // XMultipleResults - virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getResultSet( ) override; - virtual sal_Int32 SAL_CALL getUpdateCount( ) override; - virtual sal_Bool SAL_CALL getMoreResults( ) override; - - public: - using OCommonStatement::executeQuery; - using OCommonStatement::executeUpdate; - using OCommonStatement::execute; - private: - using OPropertySetHelper::getFastPropertyValue; - }; - } -} - -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MPREPAREDSTATEMENT_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MQueryHelper.cxx b/connectivity/source/drivers/mork/MQueryHelper.cxx deleted file mode 100644 index aaf8cac6a682..000000000000 --- a/connectivity/source/drivers/mork/MQueryHelper.cxx +++ /dev/null @@ -1,321 +0,0 @@ -/* -*- 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 . - */ - - -#include "MColumnAlias.hxx" -#include "MQueryHelper.hxx" -#include "MConnection.hxx" - -#include "MorkParser.hxx" -#include <string> -#include <vector> -#include <algorithm> - -#include <strings.hrc> - -#include <unotools/textsearch.hxx> -#include <sal/log.hxx> - -using namespace connectivity::mork; -using namespace connectivity; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdbc; - - -static -std::vector<bool> entryMatchedByExpression(MQueryHelper* _aQuery, MQueryExpression const * _aExpr, MQueryHelperResultEntry* entry); - -MQueryHelperResultEntry::MQueryHelperResultEntry() -{ -} - -MQueryHelperResultEntry::~MQueryHelperResultEntry() -{ -} - -OUString MQueryHelperResultEntry::getValue( const OString &key ) const -{ - FieldMap::const_iterator iter = m_Fields.find( key ); - if ( iter == m_Fields.end() ) - { - return OUString(); - } - else - { - return iter->second; - } -} - -void MQueryHelperResultEntry::setValue( const OString &key, const OUString & rValue) -{ - m_Fields[ key ] = rValue; -} - -MQueryHelper::MQueryHelper(const OColumnAlias& _ca) - :m_rColumnAlias( _ca ) - ,m_aError() -{ - m_aResults.clear(); -} - -MQueryHelper::~MQueryHelper() -{ - clear_results(); -} - - -void MQueryHelper::setAddressbook(OUString const &ab) -{ - ::osl::MutexGuard aGuard(m_aMutex); - m_aAddressbook = ab; -} - -void MQueryHelper::append(std::unique_ptr<MQueryHelperResultEntry> resEnt) -{ - assert(resEnt); - m_aResults.push_back( std::move(resEnt) ); -} - -void MQueryHelper::clear_results() -{ - m_aResults.clear(); -} - -void MQueryHelper::reset() -{ - clear_results(); - m_aError.reset(); -} - -MQueryHelperResultEntry* -MQueryHelper::getByIndex(sal_uInt32 nRow) -{ - // Row numbers are from 1 to N, need to ensure this, and then - // subtract 1 - if ( nRow < 1 ) { - return nullptr; - } - return m_aResults[nRow -1].get(); -} - -sal_Int32 MQueryHelper::getResultCount() const -{ - sal_Int32 result = static_cast<sal_Int32>(m_aResults.size()); - - return result; -} - -bool MQueryHelper::getRowValue( ORowSetValue& rValue, sal_Int32 nDBRow,const OUString& aDBColumnName, sal_Int32 nType ) -{ - MQueryHelperResultEntry* pResEntry = getByIndex( nDBRow ); - - OSL_ENSURE( pResEntry != nullptr, "xResEntry == NULL"); - if (pResEntry == nullptr ) - { - rValue.setNull(); - return false; - } - switch ( nType ) - { - case DataType::VARCHAR: - rValue = pResEntry->getValue( m_rColumnAlias.getProgrammaticNameOrFallbackToUTF8Alias( aDBColumnName ) ); - break; - - default: - rValue.setNull(); - break; - } - - return true; -} - -sal_Int32 MQueryHelper::executeQuery(OConnection* xConnection, MQueryExpression & expr) -{ - reset(); - - OString oStringTable = OUStringToOString( m_aAddressbook, RTL_TEXTENCODING_UTF8 ); - std::set<int> listRecords; - bool handleListTable = false; - MorkParser* pMork; - - // check if we are retrieving the default table - if (oStringTable == "AddressBook" || oStringTable == "CollectedAddressBook") - { - pMork = xConnection->getMorkParser(oStringTable); - } - else - { - // Let's try to retrieve the list in Collected Addresses book - pMork = xConnection->getMorkParser("CollectedAddressBook"); - if (std::find(pMork->lists_.begin(), pMork->lists_.end(), m_aAddressbook) == pMork->lists_.end()) - { - // so the list is in Address book - // TODO : manage case where an address book has been created - pMork = xConnection->getMorkParser("AddressBook"); - } - handleListTable = true; - // retrieve row ids for that list table - std::string listTable = oStringTable.getStr(); - pMork->getRecordKeysForListTable(listTable, listRecords); - } - - MorkTableMap *Tables = pMork->getTables( 0x80 ); - if (!Tables) - return -1; - - MorkRowMap *Rows = nullptr; - - // Iterate all tables - for (auto & table : Tables->map) - { - if (table.first != 1) break; - Rows = MorkParser::getRows( 0x80, &table.second ); - if ( Rows ) - { - // Iterate all rows - for (auto const& row : Rows->map) - { - // list specific table - // only retrieve rowIds that belong to that list table. - if (handleListTable) - { - int rowId = row.first; - // belongs this row id to the list table? - if (listRecords.end() == listRecords.find(rowId)) - { - // no, skip it - continue; - } - } - - std::unique_ptr<MQueryHelperResultEntry> entry(new MQueryHelperResultEntry()); - for (auto const& cell : row.second) - { - std::string column = pMork->getColumn(cell.first); - std::string value = pMork->getValue(cell.second); - OString key(column.c_str(), static_cast<sal_Int32>(column.size())); - OString valueOString(value.c_str(), static_cast<sal_Int32>(value.size())); - OUString valueOUString = OStringToOUString( valueOString, RTL_TEXTENCODING_UTF8 ); - entry->setValue(key, valueOUString); - } - bool result = true; - for (bool elem : entryMatchedByExpression(this, &expr, entry.get())) - { - result = result && elem; - } - if (result) - { - append(std::move(entry)); - } - } - } - } - return 0; -} - -std::vector<bool> entryMatchedByExpression(MQueryHelper* _aQuery, MQueryExpression const * _aExpr, MQueryHelperResultEntry* entry) -{ - std::vector<bool> resultVector; - for (auto const& expr : _aExpr->getExpressions()) - { - if ( expr->isStringExpr() ) { - MQueryExpressionString* evStr = static_cast<MQueryExpressionString*> (expr); - // Set the 'name' property of the boolString. - OString attrName = _aQuery->getColumnAlias().getProgrammaticNameOrFallbackToUTF8Alias( evStr->getName() ); - SAL_INFO("connectivity.mork", "Name = " << attrName); - bool bRequiresValue = true; - OUString currentValue = entry->getValue(attrName); - if (evStr->getCond() == MQueryOp::Exists || evStr->getCond() == MQueryOp::DoesNotExist) - { - bRequiresValue = false; - } - if (bRequiresValue) - { - SAL_INFO("connectivity.mork", "Value = " << evStr->getValue() ); - const OUString& searchedValue = evStr->getValue(); - if (evStr->getCond() == MQueryOp::Is) { - SAL_INFO("connectivity.mork", "MQueryOp::Is; done"); - resultVector.push_back(currentValue == searchedValue); - } else if (evStr->getCond() == MQueryOp::IsNot) { - SAL_INFO("connectivity.mork", "MQueryOp::IsNot; done"); - resultVector.push_back(currentValue != searchedValue); - } else if (evStr->getCond() == MQueryOp::EndsWith) { - SAL_INFO("connectivity.mork", "MQueryOp::EndsWith; done"); - resultVector.push_back(currentValue.endsWith(searchedValue)); - } else if (evStr->getCond() == MQueryOp::BeginsWith) { - SAL_INFO("connectivity.mork", "MQueryOp::BeginsWith; done"); - resultVector.push_back(currentValue.startsWith(searchedValue)); - } else if (evStr->getCond() == MQueryOp::Contains) { - SAL_INFO("connectivity.mork", "MQueryOp::Contains; done"); - resultVector.push_back(currentValue.indexOf(searchedValue) != -1); - } else if (evStr->getCond() == MQueryOp::DoesNotContain) { - SAL_INFO("connectivity.mork", "MQueryOp::DoesNotContain; done"); - resultVector.push_back(currentValue.indexOf(searchedValue) == -1); - } else if (evStr->getCond() == MQueryOp::RegExp) { - SAL_INFO("connectivity.mork", "MQueryOp::RegExp; done"); - utl::SearchParam param( - searchedValue, utl::SearchParam::SearchType::Regexp); - utl::TextSearch ts(param, LANGUAGE_DONTKNOW); - sal_Int32 start = 0; - sal_Int32 end = currentValue.getLength(); - resultVector.push_back( - ts.SearchForward(currentValue, &start, &end)); - } - } else if (evStr->getCond() == MQueryOp::Exists) { - SAL_INFO("connectivity.mork", "MQueryOp::Exists; done"); - resultVector.push_back(!currentValue.isEmpty()); - } else if (evStr->getCond() == MQueryOp::DoesNotExist) { - SAL_INFO("connectivity.mork", "MQueryOp::DoesNotExist; done"); - resultVector.push_back(currentValue.isEmpty()); - } - } - else if ( expr->isExpr() ) { - SAL_INFO("connectivity.mork", "Appending Subquery Expression"); - MQueryExpression* queryExpression = static_cast<MQueryExpression*> (expr); - // recursive call - std::vector<bool> subquery_result = entryMatchedByExpression(_aQuery, queryExpression, entry); - MQueryExpression::bool_cond condition = queryExpression->getExpressionCondition(); - if (condition == MQueryExpression::OR) { - bool result = false; - for (bool elem : subquery_result) - { - result = result || elem; - } - resultVector.push_back(result); - } else { - assert(condition == MQueryExpression::AND && "only OR or AND should exist"); - bool result = true; - for (bool elem : subquery_result) - { - result = result && elem; - } - resultVector.push_back(result); - } - } - else { - // Should never see this... - SAL_WARN("connectivity.mork", "Unknown Expression Type!"); - _aQuery->getError().setResId(STR_ERROR_GET_ROW); - return resultVector; - } - } - return resultVector; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MQueryHelper.hxx b/connectivity/source/drivers/mork/MQueryHelper.hxx deleted file mode 100644 index 67d2b081d3c2..000000000000 --- a/connectivity/source/drivers/mork/MQueryHelper.hxx +++ /dev/null @@ -1,184 +0,0 @@ -/* -*- 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 . - */ - -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MQUERYHELPER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MQUERYHELPER_HXX - -#include <connectivity/FValue.hxx> -#include "MErrorResource.hxx" -#include "MColumnAlias.hxx" - -namespace connectivity -{ - namespace mork - { - class OConnection; - class MQueryHelper; - class ErrorDescriptor; - - namespace MQueryOp { - typedef enum { - Exists = 0, - DoesNotExist = 1, - Contains = 2, - DoesNotContain = 3, - Is = 4, - IsNot = 5, - BeginsWith = 6, - EndsWith = 7, - RegExp = 8 - } cond_type; - } - - class MQueryExpressionBase { - public: - enum class node_type { - StringExpr, - Expr - }; - - protected: - node_type m_eNodeType; - - explicit MQueryExpressionBase( node_type _eNodeType ) : m_eNodeType( _eNodeType ) {} - - public: - virtual ~MQueryExpressionBase() {} - - bool isStringExpr( ) const { return m_eNodeType == node_type::StringExpr; } - bool isExpr( ) const { return m_eNodeType == node_type::Expr; } - }; - - class MQueryExpressionString final : public MQueryExpressionBase { - OUString m_aName; // LHS - MQueryOp::cond_type m_aBooleanCondition; - OUString m_aValue; // RHS - - public: - - MQueryExpressionString( const OUString& lhs, - MQueryOp::cond_type cond, - const OUString& rhs ) - : MQueryExpressionBase( MQueryExpressionBase::node_type::StringExpr ) - , m_aName( lhs ) - , m_aBooleanCondition( cond ) - , m_aValue( rhs ) - { - } - - MQueryExpressionString( const OUString& lhs, - MQueryOp::cond_type cond ) - : MQueryExpressionBase( MQueryExpressionBase::node_type::StringExpr ) - , m_aName( lhs ) - , m_aBooleanCondition( cond ) - , m_aValue( OUString() ) - { - } - - const OUString& getName() const { return m_aName; } - MQueryOp::cond_type getCond() const { return m_aBooleanCondition; } - const OUString& getValue() const { return m_aValue; } - }; - - class MQueryExpression final : public MQueryExpressionBase - { - friend class MQueryHelper; - - public: - typedef std::vector< MQueryExpressionBase* > ExprVector; - - typedef enum { - AND, - OR - } bool_cond; - - // All expressions on a peer level use same condition operator - void setExpressionCondition( bool_cond _cond ) - { m_aExprCondType = _cond; } - - void addExpression(MQueryExpressionBase * expr) - { m_aExprVector.push_back(expr); } - - ExprVector const & getExpressions( ) const - { return m_aExprVector; } - - // All expressions on a peer level use same condition operator - bool_cond getExpressionCondition( ) const - { return m_aExprCondType; } - - MQueryExpression() : MQueryExpressionBase( MQueryExpressionBase::node_type::Expr ), - m_aExprCondType( OR ) - {} - - private: - ExprVector m_aExprVector; - bool_cond m_aExprCondType; - - MQueryExpression(const MQueryExpression&) = delete; - MQueryExpression& operator=(const MQueryExpression&) = delete; - }; - - class MQueryHelperResultEntry - { - private: - typedef std::unordered_map< OString, OUString > FieldMap; - - FieldMap m_Fields; - - public: - MQueryHelperResultEntry(); - ~MQueryHelperResultEntry(); - - OUString getValue( const OString &key ) const; - void setValue( const OString &key, const OUString & rValue); - }; - - class MQueryHelper final - { - private: - - mutable ::osl::Mutex m_aMutex; - std::vector< std::unique_ptr<MQueryHelperResultEntry> > m_aResults; - void append(std::unique_ptr<MQueryHelperResultEntry> resEnt ); - void clear_results(); - OColumnAlias m_rColumnAlias; - ErrorDescriptor m_aError; - OUString m_aAddressbook; - - public: - explicit MQueryHelper(const OColumnAlias& _ca); - ~MQueryHelper(); - - void reset(); - MQueryHelperResultEntry* getByIndex( sal_uInt32 nRow ); - sal_Int32 getResultCount() const; - bool getRowValue( ORowSetValue& rValue, sal_Int32 nDBRow,const OUString& aDBColumnName, sal_Int32 nType ); - sal_Int32 executeQuery(OConnection* xConnection, MQueryExpression & expr); - const OColumnAlias& getColumnAlias() const { return m_rColumnAlias; } - bool hadError() const { return m_aError.is(); } - ErrorDescriptor& getError() { return m_aError; } - - void setAddressbook( OUString const &); - }; - } -} - -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MQUERYHELPER_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MResultSet.cxx b/connectivity/source/drivers/mork/MResultSet.cxx deleted file mode 100644 index 6918479a86c0..000000000000 --- a/connectivity/source/drivers/mork/MResultSet.cxx +++ /dev/null @@ -1,1710 +0,0 @@ -/* -*- 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 . - */ - -#include <com/sun/star/sdbc/ResultSetType.hpp> -#include <com/sun/star/sdbc/FetchDirection.hpp> -#include <com/sun/star/sdbc/ResultSetConcurrency.hpp> -#include <com/sun/star/sdbcx/CompareBookmark.hpp> -#include <com/sun/star/beans/PropertyAttribute.hpp> -#include <connectivity/dbtools.hxx> -#include <comphelper/types.hxx> -#include <cppuhelper/typeprovider.hxx> -#include <o3tl/safeint.hxx> -#include <sal/log.hxx> - -#include <vector> -#include <algorithm> -#include "MResultSet.hxx" -#include <sqlbison.hxx> -#include "MResultSetMetaData.hxx" -#include <FDatabaseMetaDataResultSet.hxx> - -#include <strings.hrc> - -using namespace ::comphelper; -using namespace connectivity; -using namespace connectivity::mork; -using namespace ::cppu; -using namespace com::sun::star::uno; -using namespace com::sun::star::lang; -using namespace com::sun::star::beans; -using namespace com::sun::star::sdbc; -using namespace com::sun::star::sdbcx; -using namespace com::sun::star::container; -using namespace com::sun::star::io; -using namespace com::sun::star::util; - - -// IMPLEMENT_SERVICE_INFO(OResultSet,"com.sun.star.sdbcx.OResultSet","com.sun.star.sdbc.ResultSet"); -OUString SAL_CALL OResultSet::getImplementationName( ) -{ - return "com.sun.star.sdbcx.mork.ResultSet"; -} - - Sequence< OUString > SAL_CALL OResultSet::getSupportedServiceNames( ) -{ - return {"com.sun.star.sdbc.ResultSet","com.sun.star.sdbcx.ResultSet"}; -} - -sal_Bool SAL_CALL OResultSet::supportsService( const OUString& _rServiceName ) -{ - return cppu::supportsService(this, _rServiceName); -} - - -OResultSet::OResultSet(OCommonStatement* pStmt, const std::shared_ptr< connectivity::OSQLParseTreeIterator >& _pSQLIterator ) - : OResultSet_BASE(m_aMutex) - ,OPropertySetHelper(OResultSet_BASE::rBHelper) - ,m_pStatement(pStmt) - ,m_xStatement(*pStmt) - ,m_nRowPos(0) - ,m_bWasNull(false) - ,m_nResultSetType(ResultSetType::SCROLL_INSENSITIVE) - ,m_nFetchDirection(FetchDirection::FORWARD) - ,m_pSQLIterator( _pSQLIterator ) - ,m_pParseTree( _pSQLIterator->getParseTree() ) - ,m_aQueryHelper(pStmt->getOwnConnection()->getColumnAlias()) - ,m_CurrentRowCount(0) - ,m_nParamIndex(0) - ,m_bIsAlwaysFalseQuery(false) - ,m_bIsReadOnly(TRISTATE_INDET) -{ - //m_aQuery.setMaxNrOfReturns(pStmt->getOwnConnection()->getMaxResultRecords()); -} - -OResultSet::~OResultSet() -{ -} - - -void OResultSet::disposing() -{ - OPropertySetHelper::disposing(); - - ::osl::MutexGuard aGuard(m_aMutex); - - m_xStatement.clear(); - m_xMetaData.clear(); - m_pParseTree = nullptr; - m_xColumns = nullptr; - m_pKeySet = nullptr; - m_xTable.clear(); -} - -Any SAL_CALL OResultSet::queryInterface( const Type & rType ) -{ - Any aRet = OPropertySetHelper::queryInterface(rType); - if(!aRet.hasValue()) - aRet = OResultSet_BASE::queryInterface(rType); - return aRet; -} - - Sequence< Type > SAL_CALL OResultSet::getTypes( ) -{ - OTypeCollection aTypes( cppu::UnoType<css::beans::XMultiPropertySet>::get(), - cppu::UnoType<css::beans::XFastPropertySet>::get(), - cppu::UnoType<css::beans::XPropertySet>::get()); - - return ::comphelper::concatSequences(aTypes.getTypes(),OResultSet_BASE::getTypes()); -} - -void OResultSet::methodEntry() -{ - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - if ( !m_xTable.is() ) - { - OSL_FAIL( "OResultSet::methodEntry: looks like we're disposed, but how is this possible?" ); - throw DisposedException( OUString(), *this ); - } -} - - -sal_Int32 SAL_CALL OResultSet::findColumn( const OUString& columnName ) -{ - ResultSetEntryGuard aGuard( *this ); - - // find the first column with the name columnName - Reference< XResultSetMetaData > xMeta = getMetaData(); - sal_Int32 nLen = xMeta->getColumnCount(); - sal_Int32 i = 1; - for(;i<=nLen;++i) - { - if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) : - columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i))) - return i; - } - - ::dbtools::throwInvalidColumnException( columnName, *this ); - assert(false); - return 0; // Never reached -} - -Reference< XInputStream > SAL_CALL OResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ ) -{ - return nullptr; -} - -Reference< XInputStream > SAL_CALL OResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ ) -{ - return nullptr; -} - - -sal_Bool SAL_CALL OResultSet::getBoolean( sal_Int32 /*columnIndex*/ ) -{ - ResultSetEntryGuard aGuard( *this ); - m_bWasNull = true; - return false; -} - - -sal_Int8 SAL_CALL OResultSet::getByte( sal_Int32 /*columnIndex*/ ) -{ - return 0; -} - - -Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes( sal_Int32 /*columnIndex*/ ) -{ - return Sequence< sal_Int8 >(); -} - - -Date SAL_CALL OResultSet::getDate( sal_Int32 /*columnIndex*/ ) -{ - return Date(); -} - - -double SAL_CALL OResultSet::getDouble( sal_Int32 /*columnIndex*/ ) -{ - return 0.0; -} - - -float SAL_CALL OResultSet::getFloat( sal_Int32 /*columnIndex*/ ) -{ - return 0; -} - - -sal_Int32 SAL_CALL OResultSet::getInt( sal_Int32 /*columnIndex*/ ) -{ - return 0; -} - - -sal_Int32 SAL_CALL OResultSet::getRow( ) -{ - ResultSetEntryGuard aGuard( *this ); - - SAL_INFO("connectivity.mork", "return = " << m_nRowPos); - return m_nRowPos; -} - - -sal_Int64 SAL_CALL OResultSet::getLong( sal_Int32 /*columnIndex*/ ) -{ - return sal_Int64(); -} - - -Reference< XResultSetMetaData > SAL_CALL OResultSet::getMetaData( ) -{ - ResultSetEntryGuard aGuard( *this ); - - if(!m_xMetaData.is()) - m_xMetaData = new OResultSetMetaData( - m_pSQLIterator->getSelectColumns(), m_pSQLIterator->getTables().begin()->first, m_xTable.get(), determineReadOnly()); - return m_xMetaData; -} - -Reference< XArray > SAL_CALL OResultSet::getArray( sal_Int32 /*columnIndex*/ ) -{ - return nullptr; -} - - -Reference< XClob > SAL_CALL OResultSet::getClob( sal_Int32 /*columnIndex*/ ) -{ - return nullptr; -} - -Reference< XBlob > SAL_CALL OResultSet::getBlob( sal_Int32 /*columnIndex*/ ) -{ - return nullptr; -} - - -Reference< XRef > SAL_CALL OResultSet::getRef( sal_Int32 /*columnIndex*/ ) -{ - return nullptr; -} - - -Any SAL_CALL OResultSet::getObject( sal_Int32 /*columnIndex*/, const Reference< css::container::XNameAccess >& /*typeMap*/ ) -{ - return Any(); -} - - -sal_Int16 SAL_CALL OResultSet::getShort( sal_Int32 /*columnIndex*/ ) -{ - return 0; -} - - -void OResultSet::checkIndex(sal_Int32 columnIndex ) -{ - if(columnIndex <= 0 || columnIndex > static_cast<sal_Int32>(m_xColumns->size())) - ::dbtools::throwInvalidIndexException(*this); -} - -sal_uInt32 OResultSet::currentRowCount() -{ - if ( m_bIsAlwaysFalseQuery ) - return 0; - //return 0;//m_aQuery.getRealRowCount() - deletedCount(); - // new implementation - return m_aQueryHelper.getResultCount(); -} - - -bool OResultSet::fetchCurrentRow( ) -{ - SAL_INFO("connectivity.mork", "m_nRowPos = " << m_nRowPos); - return fetchRow(getCurrentCardNumber()); -} - - -bool OResultSet::fetchRow(sal_Int32 cardNumber,bool bForceReload) -{ - SAL_INFO("connectivity.mork", "cardNumber = " << cardNumber); - if (!bForceReload) - { - // Check whether we've already fetched the row... - if ( !(*m_aRow)[0].isNull() && static_cast<sal_Int32>((*m_aRow)[0]) == cardNumber ) - return true; - } -// else -// m_aQuery.resyncRow(cardNumber); - - if ( !validRow( cardNumber ) ) - return false; - - (*m_aRow)[0] = cardNumber; - sal_Int32 nCount = m_aColumnNames.getLength(); - //m_RowStates = m_aQuery.getRowStates(cardNumber); - for( sal_Int32 i = 1; i <= nCount; i++ ) - { - if ( (*m_aRow)[i].isBound() ) - { - - // Everything in the addressbook is a string! - - if ( !m_aQueryHelper.getRowValue( (*m_aRow)[i], cardNumber, m_aColumnNames[i-1], DataType::VARCHAR )) - { - m_pStatement->getOwnConnection()->throwSQLException( m_aQueryHelper.getError(), *this ); - } - } - } - return true; - -} - - -const ORowSetValue& OResultSet::getValue(sal_Int32 cardNumber, sal_Int32 columnIndex ) -{ - if ( !fetchRow( cardNumber ) ) - { - OSL_FAIL("fetchRow() returned False" ); - m_bWasNull = true; - return *ODatabaseMetaDataResultSet::getEmptyValue(); - } - - m_bWasNull = (*m_aRow)[columnIndex].isNull(); - return (*m_aRow)[columnIndex]; - -} - - -OUString SAL_CALL OResultSet::getString( sal_Int32 columnIndex ) -{ - ResultSetEntryGuard aGuard( *this ); - - OSL_ENSURE(m_xColumns.is(), "Need the Columns!!"); - OSL_ENSURE(columnIndex <= static_cast<sal_Int32>(m_xColumns->size()), "Trying to access invalid columns number"); - checkIndex( columnIndex ); - - // If this query was sorted then we should have a valid KeySet, so use it - return getValue(getCurrentCardNumber(), mapColumn( columnIndex ) ); - -} - - -Time SAL_CALL OResultSet::getTime( sal_Int32 /*columnIndex*/ ) -{ - ResultSetEntryGuard aGuard( *this ); - return Time(); -} - - -DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 /*columnIndex*/ ) -{ - ResultSetEntryGuard aGuard( *this ); - return DateTime(); -} - - -sal_Bool SAL_CALL OResultSet::isBeforeFirst( ) -{ - ResultSetEntryGuard aGuard( *this ); - - // here you have to implement your movements - // return true means there is no data - return( m_nRowPos < 1 ); -} - -sal_Bool SAL_CALL OResultSet::isAfterLast( ) -{ - SAL_WARN("connectivity.mork", "OResultSet::isAfterLast() NOT IMPLEMENTED!"); - ResultSetEntryGuard aGuard( *this ); - - return m_nRowPos > currentRowCount(); -} - -sal_Bool SAL_CALL OResultSet::isFirst( ) -{ - ResultSetEntryGuard aGuard( *this ); - - return m_nRowPos == 1; -} - -sal_Bool SAL_CALL OResultSet::isLast( ) -{ - SAL_WARN("connectivity.mork", "OResultSet::isLast() NOT IMPLEMENTED!"); - ResultSetEntryGuard aGuard( *this ); - -// return sal_True; - return m_nRowPos == currentRowCount(); -} - -void SAL_CALL OResultSet::beforeFirst( ) -{ - ResultSetEntryGuard aGuard( *this ); - - // move before the first row so that isBeforeFirst returns false - if ( first() ) - previous(); -} - -void SAL_CALL OResultSet::afterLast( ) -{ - ResultSetEntryGuard aGuard( *this ); - - if(last()) - next(); -} - - -void SAL_CALL OResultSet::close() -{ - dispose(); -} - - -sal_Bool SAL_CALL OResultSet::first( ) -{ - return seekRow( FIRST_POS ); -} - - -sal_Bool SAL_CALL OResultSet::last( ) -{ - return seekRow( LAST_POS ); -} - -sal_Bool SAL_CALL OResultSet::absolute( sal_Int32 row ) -{ - return seekRow( ABSOLUTE_POS, row ); -} - -sal_Bool SAL_CALL OResultSet::relative( sal_Int32 row ) -{ - return seekRow( RELATIVE_POS, row ); -} - -sal_Bool SAL_CALL OResultSet::previous( ) -{ - ResultSetEntryGuard aGuard( *this ); - return seekRow( PRIOR_POS ); -} - -Reference< XInterface > SAL_CALL OResultSet::getStatement( ) -{ - ResultSetEntryGuard aGuard( *this ); - return m_xStatement; -} - - -sal_Bool SAL_CALL OResultSet::rowDeleted( ) -{ - SAL_WARN("connectivity.mork", "OResultSet::rowDeleted() NOT IMPLEMENTED!"); - ResultSetEntryGuard aGuard( *this ); - return true;//return ((m_RowStates & RowStates_Deleted) == RowStates_Deleted) ; -} - -sal_Bool SAL_CALL OResultSet::rowInserted( ) -{ - SAL_WARN("connectivity.mork", "OResultSet::rowInserted() NOT IMPLEMENTED!"); - ResultSetEntryGuard aGuard( *this ); - return true;//return ((m_RowStates & RowStates_Inserted) == RowStates_Inserted); -} - -sal_Bool SAL_CALL OResultSet::rowUpdated( ) -{ - SAL_WARN("connectivity.mork", "OResultSet::rowUpdated() NOT IMPLEMENTED!"); - ResultSetEntryGuard aGuard( *this ); - return true;// return ((m_RowStates & RowStates_Updated) == RowStates_Updated) ; -} - - -sal_Bool SAL_CALL OResultSet::next( ) -{ - return seekRow( NEXT_POS ); -} - - -sal_Bool SAL_CALL OResultSet::wasNull( ) -{ - ResultSetEntryGuard aGuard( *this ); - - return m_bWasNull; -} - - -void SAL_CALL OResultSet::cancel( ) -{ -} - -void SAL_CALL OResultSet::clearWarnings( ) -{ -} - -Any SAL_CALL OResultSet::getWarnings( ) -{ - return Any(); -} - -void SAL_CALL OResultSet::refreshRow( ) -{ - if (fetchRow(getCurrentCardNumber(),true)) { - //force fetch current row will cause we lose all change to the current row - m_pStatement->getOwnConnection()->throwSQLException( STR_ERROR_REFRESH_ROW, *this ); - } -} - -IPropertyArrayHelper* OResultSet::createArrayHelper( ) const -{ - Sequence< Property > aProps(5); - Property* pProperties = aProps.getArray(); - sal_Int32 nPos = 0; - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), - PROPERTY_ID_FETCHDIRECTION, cppu::UnoType<sal_Int32>::get(), 0); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), - PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE), - PROPERTY_ID_ISBOOKMARKABLE, cppu::UnoType<bool>::get(), PropertyAttribute::READONLY); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), - PROPERTY_ID_RESULTSETCONCURRENCY, cppu::UnoType<sal_Int32>::get(), PropertyAttribute::READONLY); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), - PROPERTY_ID_RESULTSETTYPE, cppu::UnoType<sal_Int32>::get(), PropertyAttribute::READONLY); - - return new OPropertyArrayHelper(aProps); -} - -IPropertyArrayHelper & OResultSet::getInfoHelper() -{ - return *getArrayHelper(); -} - -sal_Bool OResultSet::convertFastPropertyValue( - Any & /*rConvertedValue*/, - Any & /*rOldValue*/, - sal_Int32 nHandle, - const Any& /*rValue*/ ) -{ - OSL_FAIL( "OResultSet::convertFastPropertyValue: not implemented!" ); - switch(nHandle) - { - case PROPERTY_ID_ISBOOKMARKABLE: - case PROPERTY_ID_RESULTSETCONCURRENCY: - case PROPERTY_ID_RESULTSETTYPE: - throw css::lang::IllegalArgumentException(); - case PROPERTY_ID_FETCHDIRECTION: - case PROPERTY_ID_FETCHSIZE: - default: - ; - } - return false; -} - -void OResultSet::setFastPropertyValue_NoBroadcast( - sal_Int32 nHandle, - const Any& /*rValue*/ - ) -{ - OSL_FAIL( "OResultSet::setFastPropertyValue_NoBroadcast: not implemented!" ); - switch(nHandle) - { - case PROPERTY_ID_ISBOOKMARKABLE: - case PROPERTY_ID_RESULTSETCONCURRENCY: - case PROPERTY_ID_RESULTSETTYPE: - throw Exception("cannot set prop " + OUString::number(nHandle), nullptr); - case PROPERTY_ID_FETCHDIRECTION: - break; - case PROPERTY_ID_FETCHSIZE: - break; - default: - ; - } -} - -void OResultSet::getFastPropertyValue( - Any& rValue, - sal_Int32 nHandle - ) const -{ - switch(nHandle) - { - case PROPERTY_ID_RESULTSETCONCURRENCY: - rValue <<= sal_Int32(ResultSetConcurrency::UPDATABLE); - break; - case PROPERTY_ID_RESULTSETTYPE: - rValue <<= m_nResultSetType; - break; - case PROPERTY_ID_FETCHDIRECTION: - rValue <<= m_nFetchDirection; - break; - case PROPERTY_ID_FETCHSIZE: - rValue <<= sal_Int32(0); - break; - case PROPERTY_ID_ISBOOKMARKABLE: - const_cast< OResultSet* >( this )->determineReadOnly(); - rValue <<= (m_bIsReadOnly == TRISTATE_FALSE); - break; - } -} - -void SAL_CALL OResultSet::acquire() throw() -{ - OResultSet_BASE::acquire(); -} - -void SAL_CALL OResultSet::release() throw() -{ - OResultSet_BASE::release(); -} - -css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL OResultSet::getPropertySetInfo( ) -{ - return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); -} - - -void OResultSet::parseParameter( const OSQLParseNode* pNode, OUString& rMatchString ) -{ - OSL_ENSURE(pNode->count() > 0,"Error parsing parameter in Parse Tree"); - OSQLParseNode *pMark = pNode->getChild(0); - - // Initialize to empty string - rMatchString.clear(); - - OUString aParameterName; - if (SQL_ISPUNCTUATION(pMark,"?")) { - aParameterName = "?"; - } - else if (SQL_ISPUNCTUATION(pMark,":")) { - aParameterName = pNode->getChild(1)->getTokenValue(); - } - // XXX - Now we know name, what's value???? - m_nParamIndex ++; - SAL_INFO( - "connectivity.mork", - "Parameter name [" << m_nParamIndex << "]: " << aParameterName); - - if ( m_aParameterRow.is() ) { - OSL_ENSURE( m_nParamIndex < static_cast<sal_Int32>(m_aParameterRow->size()) + 1, "More parameters than values found" ); - rMatchString = (*m_aParameterRow)[static_cast<sal_uInt16>(m_nParamIndex)]; - SAL_INFO("connectivity.mork", "Prop Value: " << rMatchString); - } - else { - SAL_INFO("connectivity.mork", "Prop Value: Invalid ParameterRow!"); - } -} - -#define WILDCARD "%" -#define ALT_WILDCARD "*" -const sal_Unicode MATCHCHAR = '_'; - -void OResultSet::analyseWhereClause( const OSQLParseNode* parseTree, - MQueryExpression &queryExpression) -{ - OUString columnName; - MQueryOp::cond_type op( MQueryOp::Is ); - OUString matchString; - - if ( parseTree == nullptr ) - return; - - if ( m_pSQLIterator->getParseTree() != nullptr ) { - ::rtl::Reference<OSQLColumns> xColumns = m_pSQLIterator->getParameters(); - if(xColumns.is()) - { - OUString aColName, aParameterValue; - sal_Int32 i = 1; - for (auto const& column : *xColumns) - { - column->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aColName; - SAL_INFO("connectivity.mork", "Prop Column Name: " << aColName); - if ( m_aParameterRow.is() ) { - aParameterValue = (*m_aParameterRow)[static_cast<sal_uInt16>(i)]; - SAL_INFO("connectivity.mork", "Prop Value: " << aParameterValue); - } - else { - SAL_INFO("connectivity.mork", "Prop Value: Invalid ParameterRow!"); - } - i++; - } - } - - } - - if ( SQL_ISRULE(parseTree,where_clause) ) - { - // Reset Parameter Counter - resetParameters(); - analyseWhereClause( parseTree->getChild( 1 ), queryExpression ); - } - else if ( parseTree->count() == 3 && // Handle ()'s - SQL_ISPUNCTUATION(parseTree->getChild(0),"(") && - SQL_ISPUNCTUATION(parseTree->getChild(2),")")) - { - MQueryExpression *subExpression = new MQueryExpression(); - analyseWhereClause( parseTree->getChild( 1 ), *subExpression ); - queryExpression.addExpression( subExpression ); - } - else if ((SQL_ISRULE(parseTree,search_condition) || SQL_ISRULE(parseTree,boolean_term)) - && parseTree->count() == 3) // Handle AND/OR - { - // TODO - Need to take care or AND, for now match is always OR - analyseWhereClause( parseTree->getChild( 0 ), queryExpression ); - analyseWhereClause( parseTree->getChild( 2 ), queryExpression ); - - if (SQL_ISTOKEN(parseTree->getChild(1),OR)) { // OR-Operator - queryExpression.setExpressionCondition( MQueryExpression::OR ); - } - else if (SQL_ISTOKEN(parseTree->getChild(1),AND)) { // AND-Operator - queryExpression.setExpressionCondition( MQueryExpression::AND ); - } - else { - OSL_FAIL("analyseSQL: Error in Parse Tree"); - } - } - else if (SQL_ISRULE(parseTree,comparison_predicate)) - { - OSL_ENSURE(parseTree->count() == 3, "Error parsing COMPARE predicate"); - if (!(SQL_ISRULE(parseTree->getChild(0),column_ref) || - parseTree->getChild(2)->getNodeType() == SQLNodeType::String || - parseTree->getChild(2)->getNodeType() == SQLNodeType::IntNum || - parseTree->getChild(2)->getNodeType() == SQLNodeType::ApproxNum || - SQL_ISTOKEN(parseTree->getChild(2),TRUE) || - SQL_ISTOKEN(parseTree->getChild(2),FALSE) || - SQL_ISRULE(parseTree->getChild(2),parameter) || - // odbc date - (SQL_ISRULE(parseTree->getChild(2),set_fct_spec) && SQL_ISPUNCTUATION(parseTree->getChild(2)->getChild(0),"{")))) - { - m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_TOO_COMPLEX, *this ); - } - - OSQLParseNode *pPrec = parseTree->getChild(1); - if (pPrec->getNodeType() == SQLNodeType::Equal) - op = MQueryOp::Is; - else if (pPrec->getNodeType() == SQLNodeType::NotEqual) - op = MQueryOp::IsNot; - - OUString sTableRange; - if(SQL_ISRULE(parseTree->getChild(0),column_ref)) - m_pSQLIterator->getColumnRange(parseTree->getChild(0),columnName,sTableRange); - else if(parseTree->getChild(0)->isToken()) - columnName = parseTree->getChild(0)->getTokenValue(); - - if ( SQL_ISRULE(parseTree->getChild(2),parameter) ) { - parseParameter( parseTree->getChild(2), matchString ); - } - else { - matchString = parseTree->getChild(2)->getTokenValue(); - } - - if ( columnName == "0" && op == MQueryOp::Is && matchString == "1" ) { - m_bIsAlwaysFalseQuery = true; - } - queryExpression.addExpression( new MQueryExpressionString( columnName, op, matchString )); - } - else if (SQL_ISRULE(parseTree,like_predicate)) - { - OSL_ENSURE(parseTree->count() == 2, "Error parsing LIKE predicate"); - - if ( !SQL_ISRULE(parseTree->getChild(0), column_ref) ) - { - m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_INVALID_LIKE_COLUMN, *this ); - } - - - OSQLParseNode *pColumn; - OSQLParseNode *pAtom; - OSQLParseNode *pOptEscape; - const OSQLParseNode* pPart2 = parseTree->getChild(1); - pColumn = parseTree->getChild(0); // Match Item - pAtom = pPart2->getChild(static_cast<sal_uInt32>(pPart2->count()-2)); // Match String - pOptEscape = pPart2->getChild(static_cast<sal_uInt32>(pPart2->count()-1)); // Opt Escape Rule - (void)pOptEscape; - const bool bNot = SQL_ISTOKEN(pPart2->getChild(0), NOT); - - if (!(pAtom->getNodeType() == SQLNodeType::String || - pAtom->getNodeType() == SQLNodeType::Name || - SQL_ISRULE(pAtom,parameter) || - ( pAtom->getChild(0) && pAtom->getChild(0)->getNodeType() == SQLNodeType::Name ) || - ( pAtom->getChild(0) && pAtom->getChild(0)->getNodeType() == SQLNodeType::String ) - ) ) - { - m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_INVALID_LIKE_STRING, *this ); - } - - OUString sTableRange; - if(SQL_ISRULE(pColumn,column_ref)) - m_pSQLIterator->getColumnRange(pColumn,columnName,sTableRange); - - SAL_INFO("connectivity.mork", "ColumnName = " << columnName); - - if ( SQL_ISRULE(pAtom,parameter) ) { - parseParameter( pAtom, matchString ); - // Replace all '*' with '%' : UI Usually does this but not with - // Parameters for some reason. - matchString = matchString.replaceAll( ALT_WILDCARD, WILDCARD ); - } - else - { - matchString = pAtom->getTokenValue(); - } - - // Determine where '%' character is... - - if ( matchString == WILDCARD ) - { - // String containing only a '%' and nothing else - op = MQueryOp::Exists; - // Will be ignored for Exists case, but clear anyway. - matchString.clear(); - } - else if ( matchString.indexOf ( WILDCARD ) == -1 && - matchString.indexOf ( MATCHCHAR ) == -1 ) - { - // Simple string , eg. "to match" - if ( bNot ) - op = MQueryOp::DoesNotContain; - else - op = MQueryOp::Contains; - } - else if ( matchString.startsWith( WILDCARD ) - && matchString.endsWith( WILDCARD ) - && matchString.indexOf ( WILDCARD, 1 ) == matchString.lastIndexOf ( WILDCARD ) - && matchString.indexOf( MATCHCHAR ) == -1 - ) - { - // Relatively simple "%string%" - ie, contains... - // Cut '%' from front and rear - matchString = matchString.replaceAt( 0, 1, OUString() ); - matchString = matchString.replaceAt( matchString.getLength() -1 , 1, OUString() ); - - if (bNot) - op = MQueryOp::DoesNotContain; - else - op = MQueryOp::Contains; - } - else if ( bNot ) - { - // We currently can't handle a 'NOT LIKE' when there are '%' or - // '_' dispersed throughout - m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_NOT_LIKE_TOO_COMPLEX, *this ); - } - else - { - if ( (matchString.indexOf ( WILDCARD ) == matchString.lastIndexOf ( WILDCARD )) - && matchString.indexOf( MATCHCHAR ) == -1 - ) - { - // One occurrence of '%' - no '_' matches... - if ( matchString.startsWith( WILDCARD ) ) - { - op = MQueryOp::EndsWith; - matchString = matchString.replaceAt( 0, 1, OUString()); - } - else if ( matchString.indexOf ( WILDCARD ) == matchString.getLength() -1 ) - { - op = MQueryOp::BeginsWith; - matchString = matchString.replaceAt( matchString.getLength() -1 , 1, OUString() ); - } - else - { - sal_Int32 pos = matchString.indexOf ( WILDCARD ); - matchString = matchString.replaceAt( pos, 1, ".*" ); - op = MQueryOp::RegExp; - } - - } - else - { - // Most Complex, need to use a RE - sal_Int32 pos; - while ( (pos = matchString.indexOf ( WILDCARD )) != -1 ) - { - matchString = matchString.replaceAt( pos, 1, ".*" ); - } - - while ( (pos = matchString.indexOf( MATCHCHAR )) != -1 ) - { - matchString = matchString.replaceAt( pos, 1, "." ); - } - - op = MQueryOp::RegExp; - } - } - - queryExpression.addExpression( new MQueryExpressionString( columnName, op, matchString )); - } - else if (SQL_ISRULE(parseTree,test_for_null)) - { - OSL_ENSURE(parseTree->count() == 2,"Error in ParseTree"); - const OSQLParseNode* pPart2 = parseTree->getChild(1); - OSL_ENSURE(SQL_ISTOKEN(pPart2->getChild(0),IS),"Error in ParseTree"); - - if (!SQL_ISRULE(parseTree->getChild(0),column_ref)) - { - m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_INVALID_IS_NULL_COLUMN, *this ); - } - - if (SQL_ISTOKEN(pPart2->getChild(1),NOT)) - { - op = MQueryOp::Exists; - } - else - { - op = MQueryOp::DoesNotExist; - } - - OUString sTableRange; - m_pSQLIterator->getColumnRange(parseTree->getChild(0),columnName,sTableRange); - - queryExpression.addExpression( new MQueryExpressionString( columnName, op )); - } - else - { - SAL_WARN("connectivity.mork", "Unexpected statement!!!" ); - m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_TOO_COMPLEX, *this ); - } -} - -void OResultSet::fillRowData() -{ - OSL_ENSURE( m_pStatement, "Require a statement" ); - - MQueryExpression queryExpression; - - OConnection* pConnection = static_cast<OConnection*>(m_pStatement->getConnection().get()); - m_xColumns = m_pSQLIterator->getSelectColumns(); - - OSL_ENSURE(m_xColumns.is(), "Need the Columns!!"); - - const OUString sPropertyName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME); - OUString sName; - sal_Int32 i = 1; - for (const auto& rxColumn : *m_xColumns) - { - rxColumn->getPropertyValue(sPropertyName) >>= sName; - SAL_INFO( - "connectivity.mork", "Query Columns : (" << i << ") " << sName); - i++; - } - - // Generate Match Conditions for Query - const OSQLParseNode* pParseTree = m_pSQLIterator->getWhereTree(); - - m_bIsAlwaysFalseQuery = false; - if ( pParseTree != nullptr ) - { - // Extract required info - - analyseWhereClause( pParseTree, queryExpression ); - } - // If the query is a 0=1 then set Row count to 0 and return - if ( m_bIsAlwaysFalseQuery ) - { - m_bIsReadOnly = TRISTATE_TRUE; - return; - } - - OUString aStr( m_xTable->getName() ); - m_aQueryHelper.setAddressbook( aStr ); - - sal_Int32 rv = m_aQueryHelper.executeQuery(pConnection, queryExpression); - if ( rv == -1 ) { - m_pStatement->getOwnConnection()->throwSQLException( STR_ERR_EXECUTING_QUERY, *this ); - } - - if (m_aQueryHelper.hadError()) - { - m_pStatement->getOwnConnection()->throwSQLException( m_aQueryHelper.getError(), *this ); - } - - //determine whether the address book is readonly - determineReadOnly(); - - SAL_INFO("connectivity.mork", "executeQuery returned " << rv); -} - - -static bool matchRow( OValueRow const & row1, OValueRow const & row2 ) -{ - // the first column is the bookmark column - return std::equal(std::next(row1->begin()), row1->end(), std::next(row2->begin()), - [](const ORowSetValue& a, const ORowSetValue& b) { return !a.isBound() || a == b; }); -} - -sal_Int32 OResultSet::getRowForCardNumber(sal_Int32 nCardNum) -{ - SAL_INFO("connectivity.mork", "nCardNum = " << nCardNum); - - if ( m_pKeySet.is() ) - { - sal_Int32 nPos; - for(nPos=0;nPos < static_cast<sal_Int32>(m_pKeySet->size());nPos++) - { - if (nCardNum == (*m_pKeySet)[nPos]) - { - SAL_INFO("connectivity.mork", "return = " << nPos+1); - return nPos+1; - } - } - } - - m_pStatement->getOwnConnection()->throwSQLException( STR_INVALID_BOOKMARK, *this ); - - return 0; -} - -void OResultSet::executeQuery() -{ - ResultSetEntryGuard aGuard( *this ); - - OSL_ENSURE( m_xTable.is(), "Need a Table object"); - if(!m_xTable.is()) - { - const OSQLTables& rTabs = m_pSQLIterator->getTables(); - if (rTabs.empty() || !rTabs.begin()->second.is()) - m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_TOO_COMPLEX, *this ); - - m_xTable = static_cast< OTable* > (rTabs.begin()->second.get()); - } - - m_nRowPos = 0; - - fillRowData(); - - OSL_ENSURE(m_xColumns.is(), "Need the Columns!!"); - - switch( m_pSQLIterator->getStatementType() ) - { - case OSQLStatementType::Select: - { - if(m_bIsAlwaysFalseQuery) { - break; - } - else if(isCount()) - { - m_pStatement->getOwnConnection()->throwSQLException( STR_NO_COUNT_SUPPORT, *this ); - } - else - { - bool bDistinct = false; - OSQLParseNode *pDistinct = m_pParseTree->getChild(1); - if (pDistinct && pDistinct->getTokenID() == SQL_TOKEN_DISTINCT) - { - if(!IsSorted()) - { - m_aOrderbyColumnNumber.push_back(m_aColMapping[1]); - m_aOrderbyAscending.push_back(TAscendingOrder::DESC); - } - bDistinct = true; - } - - OSortIndex::TKeyTypeVector eKeyType(m_aOrderbyColumnNumber.size()); - std::vector<sal_Int16>::size_type index = 0; - for (const auto& rColIndex : m_aOrderbyColumnNumber) - { - OSL_ENSURE(static_cast<sal_Int32>(m_aRow->size()) > rColIndex,"Invalid Index"); - switch ((m_aRow->begin()+rColIndex)->getTypeKind()) - { - case DataType::CHAR: - case DataType::VARCHAR: - eKeyType[index] = OKeyType::String; - break; - - case DataType::OTHER: - case DataType::TINYINT: - case DataType::SMALLINT: - case DataType::INTEGER: - case DataType::DECIMAL: - case DataType::NUMERIC: - case DataType::REAL: - case DataType::DOUBLE: - case DataType::DATE: - case DataType::TIME: - case DataType::TIMESTAMP: - case DataType::BIT: - eKeyType[index] = OKeyType::Double; - break; - - // Other types aren't implemented (so they are always FALSE) - default: - eKeyType[index] = OKeyType::NONE; - OSL_FAIL("MResultSet::executeQuery: Order By Data Type not implemented"); - break; - } - ++index; - } - - if (IsSorted()) - { - // Implement Sorting - - // So that we can sort we need to wait until the executed - // query to the mozilla addressbooks has returned all - // values. - - OSortIndex aSortIndex(eKeyType,m_aOrderbyAscending); - -#if OSL_DEBUG_LEVEL > 0 - for ( std::vector<sal_Int32>::size_type i = 0; i < m_aColMapping.size(); i++ ) - SAL_INFO( - "connectivity.mork", - "Mapped: " << i << " -> " << m_aColMapping[i]); -#endif - for ( sal_Int32 nRow = 1; nRow <= m_aQueryHelper.getResultCount(); nRow++ ) { - - std::unique_ptr<OKeyValue> pKeyValue = OKeyValue::createKeyValue(nRow); - - for (const auto& rColIndex : m_aOrderbyColumnNumber) - { - const ORowSetValue& value = getValue(nRow, rColIndex); - - SAL_INFO( - "connectivity.mork", - "Adding Value: (" << nRow << "," << rColIndex - << ") : " << value.getString()); - - pKeyValue->pushKey(new ORowSetValueDecorator(value)); - } - - aSortIndex.AddKeyValue( std::move(pKeyValue) ); - } - - m_pKeySet = aSortIndex.CreateKeySet(); - m_CurrentRowCount = static_cast<sal_Int32>(m_pKeySet->size()); -#if OSL_DEBUG_LEVEL > 0 - for( OKeySet::size_type i = 0; i < m_pKeySet->size(); i++ ) - SAL_INFO( - "connectivity.mork", - "Sorted: " << i << " -> " << (*m_pKeySet)[i]); -#endif - - beforeFirst(); // Go back to start - } - else //we always need m_pKeySet now - m_pKeySet = new OKeySet(); - - // Handle the DISTINCT case - if ( bDistinct && m_pKeySet.is() ) - { - OValueRow aSearchRow = new OValueVector( m_aRow->size() ); - - for(sal_Int32 & i : *m_pKeySet) - { - fetchRow( i ); // Fills m_aRow - if ( matchRow( m_aRow, aSearchRow ) ) - { - i = 0; // Marker for later to be removed - } - else - { - // They don't match, so it's not a duplicate. - // Use the current Row as the next one to match against - *aSearchRow = *m_aRow; - } - } - // Now remove any keys marked with a 0 - m_pKeySet->erase(std::remove_if(m_pKeySet->begin(),m_pKeySet->end() - ,[](sal_Int32 n) { return n == 0; }) - ,m_pKeySet->end()); - - } - } - } break; - - case OSQLStatementType::Update: - case OSQLStatementType::Delete: - case OSQLStatementType::Insert: - break; - default: - m_pStatement->getOwnConnection()->throwSQLException( STR_STMT_TYPE_NOT_SUPPORTED, *this ); - break; - } -} - -void OResultSet::setBoundedColumns(const OValueRow& _rRow, - const ::rtl::Reference<connectivity::OSQLColumns>& _rxColumns, - const Reference<XIndexAccess>& _xNames, - bool _bSetColumnMapping, - const Reference<XDatabaseMetaData>& _xMetaData, - std::vector<sal_Int32>& _rColMapping) -{ - ::comphelper::UStringMixEqual aCase(_xMetaData->supportsMixedCaseQuotedIdentifiers()); - - Reference<XPropertySet> xTableColumn; - OUString sTableColumnName, sSelectColumnRealName; - - const OUString sName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME); - const OUString sRealName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME); - - std::vector< OUString> aColumnNames; - aColumnNames.reserve(_rxColumns->size()); - OValueVector::iterator aRowIter = _rRow->begin()+1; - for (sal_Int32 i=0; // the first column is the bookmark column - aRowIter != _rRow->end(); - ++i, ++aRowIter - ) - { - try - { - // get the table column and its name - _xNames->getByIndex(i) >>= xTableColumn; - OSL_ENSURE(xTableColumn.is(), "OResultSet::setBoundedColumns: invalid table column!"); - if (xTableColumn.is()) - xTableColumn->getPropertyValue(sName) >>= sTableColumnName; - else - sTableColumnName.clear(); - - // look if we have such a select column - // TODO: would like to have a O(log n) search here ... - sal_Int32 nColumnPos = 0; - for (const auto& rxColumn : *_rxColumns) - { - if ( nColumnPos < static_cast<sal_Int32>(aColumnNames.size()) ) - sSelectColumnRealName = aColumnNames[nColumnPos]; - else - { - if(rxColumn->getPropertySetInfo()->hasPropertyByName(sRealName)) - rxColumn->getPropertyValue(sRealName) >>= sSelectColumnRealName; - else - rxColumn->getPropertyValue(sName) >>= sSelectColumnRealName; - aColumnNames.push_back(sSelectColumnRealName); - } - - if (aCase(sTableColumnName, sSelectColumnRealName)) - { - if(_bSetColumnMapping) - { - sal_Int32 nSelectColumnPos = nColumnPos + 1; - // the getXXX methods are 1-based ... - sal_Int32 nTableColumnPos = i + 1; - // get first table column is the bookmark column - - SAL_INFO( - "connectivity.mork", - "Set Col Mapping: " << nSelectColumnPos << " -> " - << nTableColumnPos); - _rColMapping[nSelectColumnPos] = nTableColumnPos; - } - - aRowIter->setBound(true); - aRowIter->setTypeKind(DataType::VARCHAR); - } - - ++nColumnPos; - } - } - catch (Exception&) - { - OSL_FAIL("OResultSet::setBoundedColumns: caught an Exception!"); - } - } -} - - -bool OResultSet::isCount() const -{ - return (m_pParseTree && - m_pParseTree->count() > 2 && - SQL_ISRULE(m_pParseTree->getChild(2),scalar_exp_commalist) && - SQL_ISRULE(m_pParseTree->getChild(2)->getChild(0),derived_column) && - SQL_ISRULE(m_pParseTree->getChild(2)->getChild(0)->getChild(0),general_set_fct) && - m_pParseTree->getChild(2)->getChild(0)->getChild(0)->count() == 4 - ); -} - - -// Check for valid row in m_aQuery - -bool OResultSet::validRow( sal_uInt32 nRow) -{ - sal_Int32 nNumberOfRecords = m_aQueryHelper.getResultCount(); - - if (( nRow == 0 ) || - ( nRow > o3tl::make_unsigned(nNumberOfRecords)) ){ - SAL_INFO("connectivity.mork", "validRow(" << nRow << "): return False"); - return false; - } - SAL_INFO("connectivity.mork", "validRow(" << nRow << "): return True"); - - return true; -} - -void OResultSet::fillKeySet(sal_Int32 nMaxCardNumber) -{ - impl_ensureKeySet(); - if (m_CurrentRowCount < nMaxCardNumber) - { - sal_Int32 nKeyValue; - if ( static_cast<sal_Int32>(m_pKeySet->capacity()) < nMaxCardNumber ) - m_pKeySet->reserve(nMaxCardNumber + 20 ); - - for (nKeyValue = m_CurrentRowCount+1; nKeyValue <= nMaxCardNumber; nKeyValue ++) - m_pKeySet->push_back( nKeyValue ); - m_CurrentRowCount = nMaxCardNumber; - } -} - -sal_Int32 OResultSet::deletedCount() -{ - impl_ensureKeySet(); - return m_CurrentRowCount - static_cast<sal_Int32>(m_pKeySet->size()); - -} - -bool OResultSet::seekRow( eRowPosition pos, sal_Int32 nOffset ) -{ - ResultSetEntryGuard aGuard( *this ); - if ( !m_pKeySet.is() ) - m_pStatement->getOwnConnection()->throwSQLException( STR_ILLEGAL_MOVEMENT, *this ); - - sal_Int32 nNumberOfRecords = m_aQueryHelper.getResultCount(); - sal_Int32 nRetrievedRows = currentRowCount(); - sal_Int32 nCurPos = m_nRowPos; - - SAL_INFO("connectivity.mork", "nCurPos = " << nCurPos); - switch( pos ) { - case NEXT_POS: - nCurPos++; - break; - case PRIOR_POS: - if ( nCurPos > 0 ) - nCurPos--; - break; - case FIRST_POS: - nCurPos = 1; - break; - case LAST_POS: - nCurPos = nRetrievedRows; - break; - case ABSOLUTE_POS: - nCurPos = nOffset; - break; - case RELATIVE_POS: - nCurPos += sal_uInt32( nOffset ); - break; - } - - if ( nCurPos <= 0 ) { - m_nRowPos = 0; - SAL_INFO( - "connectivity.mork", "return False, m_nRowPos = " << m_nRowPos); - return false; - } - sal_Int32 nCurCard; - if ( nCurPos < static_cast<sal_Int32>(m_pKeySet->size()) ) //The requested row is exist in m_pKeySet, so we just use it - { - nCurCard = (*m_pKeySet)[nCurPos-1]; - } - else //The requested row has not been retrieved until now. We should get the right card for it. - nCurCard = nCurPos + deletedCount(); - - if ( nCurCard > nNumberOfRecords) { - fillKeySet(nNumberOfRecords); - m_nRowPos = static_cast<sal_uInt32>(m_pKeySet->size() + 1); - SAL_INFO( - "connectivity.mork", "return False, m_nRowPos = " << m_nRowPos); - return false; - } - //Insert new retrieved items for later use - fillKeySet(nNumberOfRecords); - m_nRowPos = static_cast<sal_uInt32>(nCurPos); - SAL_INFO("connectivity.mork", "return True, m_nRowPos = " << m_nRowPos); - fetchCurrentRow(); - return true; -} - -void OResultSet::setColumnMapping(const std::vector<sal_Int32>& _aColumnMapping) -{ - m_aColMapping = _aColumnMapping; -#if OSL_DEBUG_LEVEL > 0 - for ( size_t i = 0; i < m_aColMapping.size(); i++ ) - SAL_INFO( - "connectivity.mork", - "Set Mapped: " << i << " -> " << m_aColMapping[i]); -#endif -} - - -css::uno::Any OResultSet::getBookmark( ) -{ - SAL_INFO("connectivity.mork", "m_nRowPos = " << m_nRowPos); - ResultSetEntryGuard aGuard( *this ); - if ( !fetchCurrentRow() ) { - m_pStatement->getOwnConnection()->throwSQLException( STR_ERROR_GET_ROW, *this ); - } - - OSL_ENSURE((!m_aRow->isDeleted()),"getBookmark called for deleted row"); - return makeAny(static_cast<sal_Int32>((*m_aRow)[0])); -} -sal_Bool OResultSet::moveToBookmark( const css::uno::Any& bookmark ) -{ - ResultSetEntryGuard aGuard( *this ); - SAL_INFO( - "connectivity.mork", "bookmark = " << comphelper::getINT32(bookmark)); - sal_Int32 nCardNum = comphelper::getINT32(bookmark); - m_nRowPos = getRowForCardNumber(nCardNum); - fetchCurrentRow(); - return true; -} -sal_Bool OResultSet::moveRelativeToBookmark( const css::uno::Any& bookmark, sal_Int32 rows ) -{ - ResultSetEntryGuard aGuard( *this ); - SAL_INFO( - "connectivity.mork", - "bookmark = " << comphelper::getINT32(bookmark) << " rows= " << rows); - sal_Int32 nCardNum = comphelper::getINT32(bookmark); - m_nRowPos = getRowForCardNumber(nCardNum); - return seekRow(RELATIVE_POS,rows ); -} -sal_Int32 OResultSet::compareBookmarks( const css::uno::Any& lhs, const css::uno::Any& rhs ) -{ - ResultSetEntryGuard aGuard( *this ); - SAL_INFO("connectivity.mork", "m_nRowPos = " << m_nRowPos); - sal_Int32 nFirst=0; - sal_Int32 nSecond=0; - sal_Int32 nResult=0; - - if ( !( lhs >>= nFirst ) || !( rhs >>= nSecond ) ) { - m_pStatement->getOwnConnection()->throwSQLException( STR_INVALID_BOOKMARK, *this ); - } - - if(nFirst < nSecond) - nResult = CompareBookmark::LESS; - else if(nFirst > nSecond) - nResult = CompareBookmark::GREATER; - else - nResult = CompareBookmark::EQUAL; - - return nResult; -} -sal_Bool OResultSet::hasOrderedBookmarks( ) -{ - ResultSetEntryGuard aGuard( *this ); - SAL_INFO("connectivity.mork", "m_nRowPos = " << m_nRowPos); - return true; -} -sal_Int32 OResultSet::hashBookmark( const css::uno::Any& bookmark ) -{ - ResultSetEntryGuard aGuard( *this ); - SAL_INFO("connectivity.mork", "m_nRowPos = " << m_nRowPos); - return comphelper::getINT32(bookmark); -} - -sal_Int32 OResultSet::getCurrentCardNumber() -{ - if ( ( m_nRowPos == 0 ) || !m_pKeySet.is() ) - return 0; - if (m_pKeySet->size() < m_nRowPos) - return 0; - return (*m_pKeySet)[m_nRowPos-1]; -} -void OResultSet::checkPendingUpdate() -{ - OSL_FAIL( "OResultSet::checkPendingUpdate() not implemented" ); -/* - const sal_Int32 nCurrentRow = getCurrentCardNumber(); - - if ((m_nNewRow && nCurrentRow != m_nNewRow) - || ( m_nUpdatedRow && m_nUpdatedRow != nCurrentRow)) - { - const OUString sError( m_pStatement->getOwnConnection()->getResources().getResourceStringWithSubstitution( - STR_COMMIT_ROW, - "$position$", OUString::valueOf(nCurrentRow) - ) ); - ::dbtools::throwGenericSQLException(sError,*this); - } -*/ - -} -void OResultSet::updateValue(sal_Int32 columnIndex ,const ORowSetValue& x) -{ - SAL_INFO("connectivity.mork", "m_nRowPos = " << m_nRowPos); - ResultSetEntryGuard aGuard( *this ); - if ( !fetchCurrentRow() ) { - m_pStatement->getOwnConnection()->throwSQLException( STR_ERROR_GET_ROW, *this ); - } - - checkPendingUpdate(); - - checkIndex(columnIndex ); - columnIndex = mapColumn(columnIndex); - - (*m_aRow)[columnIndex].setBound(true); - (*m_aRow)[columnIndex] = x; -} - - -void SAL_CALL OResultSet::updateNull( sal_Int32 columnIndex ) -{ - SAL_INFO("connectivity.mork", "m_nRowPos = " << m_nRowPos); - ResultSetEntryGuard aGuard( *this ); - if ( !fetchCurrentRow() ) - m_pStatement->getOwnConnection()->throwSQLException( STR_ERROR_GET_ROW, *this ); - - checkPendingUpdate(); - checkIndex(columnIndex ); - columnIndex = mapColumn(columnIndex); - - (*m_aRow)[columnIndex].setBound(true); - (*m_aRow)[columnIndex].setNull(); -} - - -void SAL_CALL OResultSet::updateBoolean( sal_Int32 columnIndex, sal_Bool x ) -{ - updateValue(columnIndex, static_cast<bool>(x)); -} - -void SAL_CALL OResultSet::updateByte( sal_Int32 columnIndex, sal_Int8 x ) -{ - updateValue(columnIndex,x); -} - - -void SAL_CALL OResultSet::updateShort( sal_Int32 columnIndex, sal_Int16 x ) -{ - updateValue(columnIndex,x); -} - -void SAL_CALL OResultSet::updateInt( sal_Int32 columnIndex, sal_Int32 x ) -{ - updateValue(columnIndex,x); -} - -void SAL_CALL OResultSet::updateLong( sal_Int32 /*columnIndex*/, sal_Int64 /*x*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XRowUpdate::updateLong", *this ); -} - -void SAL_CALL OResultSet::updateFloat( sal_Int32 columnIndex, float x ) -{ - updateValue(columnIndex,x); -} - - -void SAL_CALL OResultSet::updateDouble( sal_Int32 columnIndex, double x ) -{ - updateValue(columnIndex,x); -} - -void SAL_CALL OResultSet::updateString( sal_Int32 columnIndex, const OUString& x ) -{ - updateValue(columnIndex,x); -} - -void SAL_CALL OResultSet::updateBytes( sal_Int32 columnIndex, const Sequence< sal_Int8 >& x ) -{ - updateValue(columnIndex,x); -} - -void SAL_CALL OResultSet::updateDate( sal_Int32 columnIndex, const css::util::Date& x ) -{ - updateValue(columnIndex,x); -} - - -void SAL_CALL OResultSet::updateTime( sal_Int32 columnIndex, const css::util::Time& x ) -{ - updateValue(columnIndex,x); -} - - -void SAL_CALL OResultSet::updateTimestamp( sal_Int32 columnIndex, const css::util::DateTime& x ) -{ - updateValue(columnIndex,x); -} - - -void SAL_CALL OResultSet::updateBinaryStream( sal_Int32 columnIndex, const Reference< css::io::XInputStream >& x, sal_Int32 length ) -{ - ResultSetEntryGuard aGuard( *this ); - - if(!x.is()) - ::dbtools::throwFunctionSequenceException(*this); - - Sequence<sal_Int8> aSeq; - x->readBytes(aSeq,length); - updateValue(columnIndex,aSeq); -} - -void SAL_CALL OResultSet::updateCharacterStream( sal_Int32 columnIndex, const Reference< css::io::XInputStream >& x, sal_Int32 length ) -{ - updateBinaryStream(columnIndex,x,length); -} - -void SAL_CALL OResultSet::updateObject( sal_Int32 columnIndex, const Any& x ) -{ - if (!::dbtools::implUpdateObject(this, columnIndex, x)) - { - const OUString sError( m_pStatement->getOwnConnection()->getResources().getResourceStringWithSubstitution( - STR_COLUMN_NOT_UPDATEABLE, - "$position$", OUString::number(columnIndex) - ) ); - ::dbtools::throwGenericSQLException(sError,*this); - } // if (!::dbtools::implUpdateObject(this, columnIndex, x)) - } - - -void SAL_CALL OResultSet::updateNumericObject( sal_Int32 columnIndex, const Any& x, sal_Int32 /*scale*/ ) -{ - if (!::dbtools::implUpdateObject(this, columnIndex, x)) - { - const OUString sError( m_pStatement->getOwnConnection()->getResources().getResourceStringWithSubstitution( - STR_COLUMN_NOT_UPDATEABLE, - "$position$", OUString::number(columnIndex) - ) ); - ::dbtools::throwGenericSQLException(sError,*this); - } -} - -// XResultSetUpdate - -void SAL_CALL OResultSet::insertRow( ) -{ - ResultSetEntryGuard aGuard( *this ); - SAL_INFO("connectivity.mork", "in, m_nRowPos = " << m_nRowPos); -// m_RowStates = RowStates_Inserted; - updateRow(); - //m_aQueryHelper.setRowStates(getCurrentCardNumber(),m_RowStates); - SAL_INFO("connectivity.mork", "out, m_nRowPos = " << m_nRowPos); -} - -void SAL_CALL OResultSet::updateRow( ) -{ - OSL_FAIL( "OResultSet::updateRow( ) not implemented" ); -} - -void SAL_CALL OResultSet::deleteRow( ) -{ - OSL_FAIL( "OResultSet::deleteRow( ) not implemented" ); -} - -void SAL_CALL OResultSet::cancelRowUpdates( ) -{ - OSL_FAIL( "OResultSet::cancelRowUpdates( ) not implemented" ); -} - -void SAL_CALL OResultSet::moveToInsertRow( ) -{ - OSL_FAIL( "OResultSet::moveToInsertRow( ) not implemented" ); -} - -void SAL_CALL OResultSet::moveToCurrentRow( ) -{ - ResultSetEntryGuard aGuard( *this ); - SAL_INFO("connectivity.mork", "m_nRowPos = " << m_nRowPos); - if (rowInserted()) - { - m_nRowPos = 0; - fetchCurrentRow(); - } -} - -bool OResultSet::determineReadOnly() -{ -// OSL_FAIL( "OResultSet::determineReadOnly( ) not implemented" ); - - if (m_bIsReadOnly == TRISTATE_INDET) - { - m_bIsReadOnly = TRISTATE_TRUE; -// OConnection* xConnection = static_cast<OConnection*>(m_pStatement->getConnection().get()); -// m_bIsReadOnly = !m_aQueryHelper.isWritable(xConnection) || m_bIsAlwaysFalseQuery; - } - - return m_bIsReadOnly != TRISTATE_FALSE; -} - -void OResultSet::setTable(OTable* _rTable) -{ - m_xTable = _rTable; - m_xTableColumns = m_xTable->getColumns(); - if(m_xTableColumns.is()) - m_aColumnNames = m_xTableColumns->getElementNames(); -} - -void OResultSet::setOrderByColumns(const std::vector<sal_Int32>& _aColumnOrderBy) -{ - m_aOrderbyColumnNumber = _aColumnOrderBy; -} - -void OResultSet::setOrderByAscending(const std::vector<TAscendingOrder>& _aOrderbyAsc) -{ - m_aOrderbyAscending = _aOrderbyAsc; -} -Sequence< sal_Int32 > SAL_CALL OResultSet::deleteRows( const Sequence< Any >& /*rows*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XDeleteRows::deleteRows", *this ); - return Sequence< sal_Int32 >(); -}; - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MResultSet.hxx b/connectivity/source/drivers/mork/MResultSet.hxx deleted file mode 100644 index 0531781d7cc1..000000000000 --- a/connectivity/source/drivers/mork/MResultSet.hxx +++ /dev/null @@ -1,350 +0,0 @@ -/* -*- 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 . - */ - -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MRESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MRESULTSET_HXX - -#include <com/sun/star/sdbc/XResultSet.hpp> -#include <com/sun/star/sdbc/XRow.hpp> -#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> -#include <com/sun/star/sdbc/XCloseable.hpp> -#include <com/sun/star/sdbc/XColumnLocate.hpp> -#include <com/sun/star/util/XCancellable.hpp> -#include <com/sun/star/sdbc/XWarningsSupplier.hpp> -#include <com/sun/star/sdbc/XResultSetUpdate.hpp> -#include <com/sun/star/sdbcx/XRowLocate.hpp> -#include <com/sun/star/sdbcx/XDeleteRows.hpp> -#include <com/sun/star/sdbc/XRowUpdate.hpp> -#include <cppuhelper/compbase.hxx> -#include <comphelper/proparrhlp.hxx> -#include <tools/gen.hxx> -#include <rtl/ref.hxx> -#include "MStatement.hxx" -#include "MQueryHelper.hxx" -#include <connectivity/CommonTools.hxx> -#include <connectivity/FValue.hxx> -#include <connectivity/sqliterator.hxx> -#include <TSortIndex.hxx> - -namespace connectivity -{ - namespace mork - { - - /* - ** java_sql_ResultSet - */ - typedef ::cppu::WeakComponentImplHelper< css::sdbc::XResultSet, - css::sdbc::XRow, - css::sdbc::XResultSetMetaDataSupplier, - css::util::XCancellable, - css::sdbc::XWarningsSupplier, - css::sdbc::XCloseable, - css::sdbc::XColumnLocate, - css::sdbc::XResultSetUpdate, - css::sdbc::XRowUpdate, - css::sdbcx::XRowLocate, - css::sdbcx::XDeleteRows, - css::lang::XServiceInfo> OResultSet_BASE; - - - typedef sal_Int64 TVoidPtr; - typedef std::allocator< TVoidPtr > TVoidAlloc; - typedef std::vector<TVoidPtr> TVoidVector; - - class OResultSet : public cppu::BaseMutex, - public OResultSet_BASE, - public ::cppu::OPropertySetHelper, - public ::comphelper::OPropertyArrayUsageHelper<OResultSet> - { - protected: - OCommonStatement* m_pStatement; - css::uno::Reference< css::uno::XInterface> m_xStatement; - css::uno::Reference< css::sdbc::XResultSetMetaData> m_xMetaData; - sal_uInt32 m_nRowPos; - bool m_bWasNull; - sal_Int32 m_nResultSetType; - sal_Int32 m_nFetchDirection; - - - std::shared_ptr< ::connectivity::OSQLParseTreeIterator > - m_pSQLIterator; - const connectivity::OSQLParseNode* m_pParseTree; - - // OPropertyArrayUsageHelper - virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override; - // OPropertySetHelper - virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; - - virtual sal_Bool SAL_CALL convertFastPropertyValue( - css::uno::Any & rConvertedValue, - css::uno::Any & rOldValue, - sal_Int32 nHandle, - const css::uno::Any& rValue ) override; - virtual void SAL_CALL setFastPropertyValue_NoBroadcast( - sal_Int32 nHandle, - const css::uno::Any& rValue - ) override; - virtual void SAL_CALL getFastPropertyValue( - css::uno::Any& rValue, - sal_Int32 nHandle - ) const override; - - // you can't delete objects of this type - virtual ~OResultSet() override; - public: - DECLARE_SERVICE_INFO(); - - OResultSet(OCommonStatement* pStmt, const std::shared_ptr< ::connectivity::OSQLParseTreeIterator >& _pSQLIterator ); - - // ::cppu::OComponentHelper - virtual void SAL_CALL disposing() override; - // XInterface - virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; - //XTypeProvider - virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; - // XPropertySet - virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; - // XResultSet - virtual sal_Bool SAL_CALL next( ) override; - virtual sal_Bool SAL_CALL isBeforeFirst( ) override; - virtual sal_Bool SAL_CALL isAfterLast( ) override; - virtual sal_Bool SAL_CALL isFirst( ) override; - virtual sal_Bool SAL_CALL isLast( ) override; - virtual void SAL_CALL beforeFirst( ) override; - virtual void SAL_CALL afterLast( ) override; - virtual sal_Bool SAL_CALL first( ) override; - virtual sal_Bool SAL_CALL last( ) override; - virtual sal_Int32 SAL_CALL getRow( ) override; - virtual sal_Bool SAL_CALL absolute( sal_Int32 row ) override; - virtual sal_Bool SAL_CALL relative( sal_Int32 rows ) override; - virtual sal_Bool SAL_CALL previous( ) override; - virtual void SAL_CALL refreshRow( ) override; - virtual sal_Bool SAL_CALL rowUpdated( ) override; - virtual sal_Bool SAL_CALL rowInserted( ) override; - virtual sal_Bool SAL_CALL rowDeleted( ) override; - virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement( ) override; - // XRow - virtual sal_Bool SAL_CALL wasNull( ) override; - virtual OUString SAL_CALL getString( sal_Int32 columnIndex ) override; - virtual sal_Bool SAL_CALL getBoolean( sal_Int32 columnIndex ) override; - virtual sal_Int8 SAL_CALL getByte( sal_Int32 columnIndex ) override; - virtual sal_Int16 SAL_CALL getShort( sal_Int32 columnIndex ) override; - virtual sal_Int32 SAL_CALL getInt( sal_Int32 columnIndex ) override; - virtual sal_Int64 SAL_CALL getLong( sal_Int32 columnIndex ) override; - virtual float SAL_CALL getFloat( sal_Int32 columnIndex ) override; - virtual double SAL_CALL getDouble( sal_Int32 columnIndex ) override; - virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int32 columnIndex ) override; - virtual css::util::Date SAL_CALL getDate( sal_Int32 columnIndex ) override; - virtual css::util::Time SAL_CALL getTime( sal_Int32 columnIndex ) override; - virtual css::util::DateTime SAL_CALL getTimestamp( sal_Int32 columnIndex ) override; - virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream( sal_Int32 columnIndex ) override; - virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream( sal_Int32 columnIndex ) override; - virtual css::uno::Any SAL_CALL getObject( sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess >& typeMap ) override; - virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef( sal_Int32 columnIndex ) override; - virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob( sal_Int32 columnIndex ) override; - virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob( sal_Int32 columnIndex ) override; - virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray( sal_Int32 columnIndex ) override; - // XResultSetMetaDataSupplier - virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override; - // XCancellable - virtual void SAL_CALL cancel( ) override; - // XCloseable - virtual void SAL_CALL close( ) override; - // XWarningsSupplier - virtual css::uno::Any SAL_CALL getWarnings( ) override; - virtual void SAL_CALL clearWarnings( ) override; - // XColumnLocate - virtual sal_Int32 SAL_CALL findColumn( const OUString& columnName ) override; - - // XResultSetUpdate - virtual void SAL_CALL insertRow( ) override; - virtual void SAL_CALL updateRow( ) override; - virtual void SAL_CALL deleteRow( ) override; - virtual void SAL_CALL cancelRowUpdates( ) override; - virtual void SAL_CALL moveToInsertRow( ) override; - virtual void SAL_CALL moveToCurrentRow( ) override; - // XRowUpdate - virtual void SAL_CALL updateNull( sal_Int32 columnIndex ) override; - virtual void SAL_CALL updateBoolean( sal_Int32 columnIndex, sal_Bool x ) override; - virtual void SAL_CALL updateByte( sal_Int32 columnIndex, sal_Int8 x ) override; - virtual void SAL_CALL updateShort( sal_Int32 columnIndex, sal_Int16 x ) override; - virtual void SAL_CALL updateInt( sal_Int32 columnIndex, sal_Int32 x ) override; - virtual void SAL_CALL updateLong( sal_Int32 columnIndex, sal_Int64 x ) override; - virtual void SAL_CALL updateFloat( sal_Int32 columnIndex, float x ) override; - virtual void SAL_CALL updateDouble( sal_Int32 columnIndex, double x ) override; - virtual void SAL_CALL updateString( sal_Int32 columnIndex, const OUString& x ) override; - virtual void SAL_CALL updateBytes( sal_Int32 columnIndex, const css::uno::Sequence< sal_Int8 >& x ) override; - virtual void SAL_CALL updateDate( sal_Int32 columnIndex, const css::util::Date& x ) override; - virtual void SAL_CALL updateTime( sal_Int32 columnIndex, const css::util::Time& x ) override; - virtual void SAL_CALL updateTimestamp( sal_Int32 columnIndex, const css::util::DateTime& x ) override; - virtual void SAL_CALL updateBinaryStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override; - virtual void SAL_CALL updateCharacterStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override; - virtual void SAL_CALL updateObject( sal_Int32 columnIndex, const css::uno::Any& x ) override; - virtual void SAL_CALL updateNumericObject( sal_Int32 columnIndex, const css::uno::Any& x, sal_Int32 scale ) override; - // XRowLocate - virtual css::uno::Any SAL_CALL getBookmark( ) override; - virtual sal_Bool SAL_CALL moveToBookmark( const css::uno::Any& bookmark ) override; - virtual sal_Bool SAL_CALL moveRelativeToBookmark( const css::uno::Any& bookmark, sal_Int32 rows ) override; - virtual sal_Int32 SAL_CALL compareBookmarks( const css::uno::Any& first, const css::uno::Any& second ) override; - virtual sal_Bool SAL_CALL hasOrderedBookmarks( ) override; - virtual sal_Int32 SAL_CALL hashBookmark( const css::uno::Any& bookmark ) override; - // XDeleteRows - virtual css::uno::Sequence< sal_Int32 > SAL_CALL deleteRows( const css::uno::Sequence< css::uno::Any >& rows ) override; - -protected: - //MQuery m_aQuery; - MQueryHelper m_aQueryHelper; - rtl::Reference<OTable> m_xTable; - sal_Int32 m_CurrentRowCount; - css::uno::Reference< css::container::XNameAccess > - m_xTableColumns; - - std::vector<sal_Int32> m_aColMapping; // pos 0 is unused so we don't have to decrement 1 every time - std::vector<sal_Int32> m_aOrderbyColumnNumber; - std::vector<TAscendingOrder> m_aOrderbyAscending; - css::uno::Sequence< OUString> m_aColumnNames; - OValueRow m_aRow; - OValueRow m_aParameterRow; - sal_Int32 m_nParamIndex; - bool m_bIsAlwaysFalseQuery; - ::rtl::Reference<OKeySet> m_pKeySet; - TriState m_bIsReadOnly; - void resetParameters() { m_nParamIndex = 0; } - - ::rtl::Reference<connectivity::OSQLColumns> m_xColumns; // this are the select columns - - void parseParameter( const OSQLParseNode* pNode, OUString& rMatchString ); - /// @throws css::sdbc::SQLException - /// @throws css::uno::RuntimeException - void fillRowData(); - void analyseWhereClause( const OSQLParseNode* parseTree, - MQueryExpression &queryExpression); - - bool isCount() const; - - bool IsSorted() const { return !m_aOrderbyColumnNumber.empty(); } - - enum eRowPosition { - NEXT_POS, PRIOR_POS, FIRST_POS, LAST_POS, ABSOLUTE_POS, RELATIVE_POS - }; - - sal_uInt32 currentRowCount(); - - /// @throws css::sdbc::SQLException - /// @throws css::uno::RuntimeException - bool fetchRow(sal_Int32 rowIndex,bool bForceReload=false); - /// @throws css::sdbc::SQLException - /// @throws css::uno::RuntimeException - bool fetchCurrentRow(); - bool validRow( sal_uInt32 nRow ); - bool seekRow( eRowPosition pos, sal_Int32 nOffset = 0 ); - sal_Int32 deletedCount(); - void fillKeySet(sal_Int32 nMaxCardNumber); //When we get new rows, fill the m_pKeySet items for them - sal_Int32 getRowForCardNumber(sal_Int32 nCardNum); - /// @throws css::sdbc::SQLException - /// @throws css::uno::RuntimeException - const ORowSetValue& getValue(sal_Int32 rowIndex, sal_Int32 columnIndex); - - /// @throws css::sdbc::SQLException - /// @throws css::uno::RuntimeException - void updateValue(sal_Int32 columnIndex,const ORowSetValue& x ); - /// @throws css::sdbc::SQLException - /// @throws css::uno::RuntimeException - static void checkPendingUpdate(); - sal_Int32 getCurrentCardNumber(); - -public: - bool determineReadOnly(); - // MozAddressbook Specific methods - /// @throws css::sdbc::SQLException - /// @throws css::uno::RuntimeException - void executeQuery(); - - void setTable(OTable* _rTable); - - void setParameterRow(const OValueRow& _rParaRow) - { m_aParameterRow = _rParaRow; } - - void setBindingRow(const OValueRow& _aRow) - { m_aRow = _aRow; } - - void setColumnMapping(const std::vector<sal_Int32>& _aColumnMapping); - - void setOrderByColumns(const std::vector<sal_Int32>& _aColumnOrderBy); - - void setOrderByAscending(const std::vector<TAscendingOrder>& _aOrderbyAsc); - - inline sal_Int32 mapColumn(sal_Int32 column); - - /// @throws css::sdbc::SQLException - void checkIndex(sal_Int32 columnIndex ); - - static void setBoundedColumns( - const OValueRow& _rRow, - const ::rtl::Reference<connectivity::OSQLColumns>& _rxColumns, - const css::uno::Reference< css::container::XIndexAccess>& _xNames, - bool _bSetColumnMapping, - const css::uno::Reference< css::sdbc::XDatabaseMetaData>& _xMetaData, - std::vector<sal_Int32>& _rColMapping); - - ::osl::Mutex& getMutex() { return m_aMutex; } - void methodEntry(); - - private: - void impl_ensureKeySet() - { - if ( !m_pKeySet.is() ) - m_pKeySet = new OKeySet(); - } - - protected: - using OPropertySetHelper::getFastPropertyValue; - }; - - inline sal_Int32 OResultSet::mapColumn(sal_Int32 column) - { - sal_Int32 map = column; - - OSL_ENSURE(column > 0, "OResultSet::mapColumn: invalid column index!"); - // the first column (index 0) is for convenience only. The - // first real select column is no 1. - if ((column > 0) && (column < static_cast<sal_Int32>(m_aColMapping.size()))) - map = m_aColMapping[column]; - - return map; - } - - class ResultSetEntryGuard : public ::osl::MutexGuard - { - public: - explicit ResultSetEntryGuard( OResultSet& _rRS ) : ::osl::MutexGuard( _rRS.getMutex() ) - { - _rRS.methodEntry(); - } - }; - - } -} - -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MRESULTSET_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MResultSetMetaData.cxx b/connectivity/source/drivers/mork/MResultSetMetaData.cxx deleted file mode 100644 index e05eced22da2..000000000000 --- a/connectivity/source/drivers/mork/MResultSetMetaData.cxx +++ /dev/null @@ -1,192 +0,0 @@ -/* -*- 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 . - */ - -#include <connectivity/dbexception.hxx> -#include <comphelper/types.hxx> -#include <comphelper/extract.hxx> -#include <tools/diagnose_ex.h> -#include "MResultSetMetaData.hxx" -#include <com/sun/star/sdbc/DataType.hpp> - -using namespace connectivity::mork; -using namespace com::sun::star::uno; -using namespace com::sun::star::lang; -using namespace com::sun::star::sdbc; -using namespace com::sun::star::beans; -using namespace ::dbtools; -using namespace ::comphelper; - - -OResultSetMetaData::~OResultSetMetaData() -{ - m_xColumns = nullptr; -} - - -void OResultSetMetaData::checkColumnIndex(sal_Int32 column) -{ - if(column <= 0 || column > static_cast<sal_Int32>(m_xColumns->size())) - throwInvalidIndexException(*this); -} - -sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) -{ - return getPrecision(column); -} - - -sal_Int32 SAL_CALL OResultSetMetaData::getColumnType( sal_Int32 /*column*/ ) -{ - return DataType::VARCHAR; // at the moment there exists only this type -} - - -sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount( ) -{ - return static_cast<sal_Int32>(m_xColumns->size()); -} - - -sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 /*column*/ ) -{ - return false; -} - - -OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 /*column*/ ) -{ - return OUString(); -} - - -OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column ) -{ - checkColumnIndex(column); - - OUString sColumnName; - try - { - Reference< XPropertySet > xColumnProps( (*m_xColumns)[column-1], UNO_SET_THROW ); - OSL_VERIFY( xColumnProps->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_NAME ) ) >>= sColumnName ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION("connectivity.mork"); - } - return sColumnName; -} - -OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 /*column*/ ) -{ - return m_aTableName; -} - -OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 /*column*/ ) -{ - return OUString(); -} - -OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 column ) -{ - checkColumnIndex(column); - return getString((*m_xColumns)[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))); -} - -OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column ) -{ - return getColumnName(column); -} - -OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 /*column*/ ) -{ - return OUString(); -} - - -sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column ) -{ - checkColumnIndex(column); - return getBOOL((*m_xColumns)[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY))); -} - - -sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 /*column*/ ) -{ - return false; -} - -sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 /*column*/ ) -{ - return false; -} - -sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column ) -{ - checkColumnIndex(column); - return getINT32((*m_xColumns)[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))); -} - -sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column ) -{ - checkColumnIndex(column); - return getINT32((*m_xColumns)[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))); -} - - -sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column ) -{ - checkColumnIndex(column); - return getINT32((*m_xColumns)[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))); -} - - -sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 /*column*/ ) -{ - if ( !m_pTable || !m_pTable->getConnection() ) - { - OSL_FAIL( "OResultSetMetaData::isSearchable: suspicious: called without table or connection!" ); - return false; - } - - return true; -} - - -sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column ) -{ - checkColumnIndex(column); - bool bReadOnly = (*m_xColumns)[column-1]->getPropertySetInfo()->hasPropertyByName(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FUNCTION)) && - ::cppu::any2bool((*m_xColumns)[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FUNCTION))); - - return m_bReadOnly || bReadOnly || OTable::isReadOnly(); -} - - -sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) -{ - return !isReadOnly(column); -} - -sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column ) -{ - return !isReadOnly(column); -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MResultSetMetaData.hxx b/connectivity/source/drivers/mork/MResultSetMetaData.hxx deleted file mode 100644 index 5362a4ac080c..000000000000 --- a/connectivity/source/drivers/mork/MResultSetMetaData.hxx +++ /dev/null @@ -1,88 +0,0 @@ -/* -*- 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 . - */ - -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MRESULTSETMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MRESULTSETMETADATA_HXX - -#include <com/sun/star/sdbc/XResultSetMetaData.hpp> -#include <cppuhelper/implbase.hxx> -#include <rtl/ref.hxx> -#include "MTable.hxx" - -namespace connectivity -{ - namespace mork - { - - //************ Class: ResultSetMetaData - - typedef ::cppu::WeakImplHelper<css::sdbc::XResultSetMetaData> OResultSetMetaData_BASE; - - class OResultSetMetaData : public OResultSetMetaData_BASE - { - OUString m_aTableName; - ::rtl::Reference<connectivity::OSQLColumns> m_xColumns; - OTable* m_pTable; - bool m_bReadOnly; - - protected: - virtual ~OResultSetMetaData() override; - public: - // a constructor that is needed to return the object: - // OResultSetMetaData(OConnection* _pConnection) : m_pConnection(_pConnection){} - OResultSetMetaData(const ::rtl::Reference<connectivity::OSQLColumns>& _rxColumns, - const OUString& _aTableName,OTable* _pTable,bool aReadOnly - ) - :m_aTableName(_aTableName) - ,m_xColumns(_rxColumns) - ,m_pTable(_pTable) - ,m_bReadOnly(aReadOnly) - {} - - /// @throws css::sdbc::SQLException - /// @throws css::uno::RuntimeException - void checkColumnIndex(sal_Int32 column); - virtual sal_Int32 SAL_CALL getColumnCount( ) override; - virtual sal_Bool SAL_CALL isAutoIncrement( sal_Int32 column ) override; - virtual sal_Bool SAL_CALL isCaseSensitive( sal_Int32 column ) override; - virtual sal_Bool SAL_CALL isSearchable( sal_Int32 column ) override; - virtual sal_Bool SAL_CALL isCurrency( sal_Int32 column ) override; - virtual sal_Int32 SAL_CALL isNullable( sal_Int32 column ) override; - virtual sal_Bool SAL_CALL isSigned( sal_Int32 column ) override; - virtual sal_Int32 SAL_CALL getColumnDisplaySize( sal_Int32 column ) override; - virtual OUString SAL_CALL getColumnLabel( sal_Int32 column ) override; - virtual OUString SAL_CALL getColumnName( sal_Int32 column ) override; - virtual OUString SAL_CALL getSchemaName( sal_Int32 column ) override; - virtual sal_Int32 SAL_CALL getPrecision( sal_Int32 column ) override; - virtual sal_Int32 SAL_CALL getScale( sal_Int32 column ) override; - virtual OUString SAL_CALL getTableName( sal_Int32 column ) override; - virtual OUString SAL_CALL getCatalogName( sal_Int32 column ) override; - virtual sal_Int32 SAL_CALL getColumnType( sal_Int32 column ) override; - virtual OUString SAL_CALL getColumnTypeName( sal_Int32 column ) override; - virtual sal_Bool SAL_CALL isReadOnly( sal_Int32 column ) override; - virtual sal_Bool SAL_CALL isWritable( sal_Int32 column ) override; - virtual sal_Bool SAL_CALL isDefinitelyWritable( sal_Int32 column ) override; - virtual OUString SAL_CALL getColumnServiceName( sal_Int32 column ) override; - }; - } -} - -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MRESULTSETMETADATA_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MStatement.cxx b/connectivity/source/drivers/mork/MStatement.cxx deleted file mode 100644 index bd153afa6438..000000000000 --- a/connectivity/source/drivers/mork/MStatement.cxx +++ /dev/null @@ -1,471 +0,0 @@ -/* -*- 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 . - */ - - -#include <tools/diagnose_ex.h> -#include <sal/log.hxx> -#include <cppuhelper/queryinterface.hxx> -#include <cppuhelper/typeprovider.hxx> -#include <comphelper/processfactory.hxx> -#include <connectivity/dbexception.hxx> - -#include <algorithm> - -#include "MDriver.hxx" -#include "MStatement.hxx" -#include <sqlbison.hxx> -#include "MResultSet.hxx" - -#include <strings.hrc> - -static ::osl::Mutex m_ThreadMutex; - -using namespace ::comphelper; -using namespace connectivity::mork; -using namespace connectivity; - -using namespace com::sun::star::uno; -using namespace com::sun::star::lang; -using namespace com::sun::star::beans; -using namespace com::sun::star::sdbc; -using namespace com::sun::star::container; -using namespace com::sun::star::io; -using namespace com::sun::star::util; - - -OStatement::OStatement( OConnection* _pConnection) : OCommonStatement( _pConnection) -{ -} - -OCommonStatement::OCommonStatement(OConnection* _pConnection ) - :OCommonStatement_IBASE(m_aMutex) - ,OPropertySetHelper(OCommonStatement_IBASE::rBHelper) - ,m_xDBMetaData (_pConnection->getMetaData()) - ,m_pTable(nullptr) - ,m_pConnection(_pConnection) - ,m_aParser( comphelper::getComponentContext(_pConnection->getDriver()->getFactory()) ) - ,m_pSQLIterator( std::make_shared<OSQLParseTreeIterator>( _pConnection, _pConnection->createCatalog()->getTables(), m_aParser ) ) -{ -} - - -OCommonStatement::~OCommonStatement() -{ -} - - -void OCommonStatement::disposing() -{ - ::osl::MutexGuard aGuard(m_aMutex); - - clearWarnings(); - clearCachedResultSet(); - - m_pConnection.clear(); - - m_pSQLIterator->dispose(); - m_pParseTree.reset(); - - OCommonStatement_IBASE::disposing(); -} - -Any SAL_CALL OCommonStatement::queryInterface( const Type & rType ) -{ - Any aRet = OCommonStatement_IBASE::queryInterface(rType); - if(!aRet.hasValue()) - aRet = OPropertySetHelper::queryInterface(rType); - return aRet; -} - -Sequence< Type > SAL_CALL OCommonStatement::getTypes( ) -{ - ::cppu::OTypeCollection aTypes( cppu::UnoType<XMultiPropertySet>::get(), - cppu::UnoType<XFastPropertySet>::get(), - cppu::UnoType<XPropertySet>::get()); - - return ::comphelper::concatSequences(aTypes.getTypes(),OCommonStatement_IBASE::getTypes()); -} - -void SAL_CALL OCommonStatement::close( ) -{ - { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed); - } - dispose(); -} - -OCommonStatement::StatementType OCommonStatement::parseSql( const OUString& sql , bool bAdjusted) -{ - OUString aErr; - - m_pParseTree = m_aParser.parseTree(aErr,sql); - - if(m_pParseTree) - { - m_pSQLIterator->setParseTree(m_pParseTree.get()); - m_pSQLIterator->traverseAll(); - const OSQLTables& rTabs = m_pSQLIterator->getTables(); - - if (rTabs.empty()) - { - getOwnConnection()->throwSQLException( STR_QUERY_AT_LEAST_ONE_TABLES, *this ); - } - - Reference<XIndexAccess> xNames; - switch(m_pSQLIterator->getStatementType()) - { - case OSQLStatementType::Select: - - // at this moment we support only one table per select statement - - OSL_ENSURE( !rTabs.empty(), "Need a Table"); - - m_pTable = static_cast< OTable* > (rTabs.begin()->second.get()); - m_xColNames = m_pTable->getColumns(); - xNames.set(m_xColNames,UNO_QUERY); - // set the binding of the resultrow - m_aRow = new OValueVector(xNames->getCount()); - (*m_aRow)[0].setBound(true); - std::for_each(m_aRow->begin()+1,m_aRow->end(),TSetBound(false)); - // create the column mapping - createColumnMapping(); - - analyseSQL(); - return eSelect; - - case OSQLStatementType::CreateTable: - return eCreateTable; - - default: - break; - } - } - else if(!bAdjusted) //Our sql parser does not support a statement like "create table foo" - // So we append ("E-mail" varchar) to the last of it to make it work - { - return parseSql(sql + "(""E-mail"" character)", true); - } - - getOwnConnection()->throwSQLException( STR_QUERY_TOO_COMPLEX, *this ); - OSL_FAIL( "OCommonStatement::parseSql: unreachable!" ); - return eSelect; - -} - -Reference< XResultSet > OCommonStatement::impl_executeCurrentQuery() -{ - clearCachedResultSet(); - - ::rtl::Reference pResult( new OResultSet( this, m_pSQLIterator ) ); - initializeResultSet( pResult.get() ); - - pResult->executeQuery(); - cacheResultSet( pResult ); // only cache if we survived the execution - - return pResult.get(); - -} - - -void OCommonStatement::initializeResultSet( OResultSet* _pResult ) -{ - ENSURE_OR_THROW( _pResult, "invalid result set" ); - - _pResult->setColumnMapping(m_aColMapping); - _pResult->setOrderByColumns(m_aOrderbyColumnNumber); - _pResult->setOrderByAscending(m_aOrderbyAscending); - _pResult->setBindingRow(m_aRow); - _pResult->setTable(m_pTable); -} - - -void OCommonStatement::clearCachedResultSet() -{ - Reference< XResultSet > xResultSet( m_xResultSet.get(), UNO_QUERY ); - if ( !xResultSet.is() ) - return; - - Reference< XCloseable >( xResultSet, UNO_QUERY_THROW )->close(); - - m_xResultSet.clear(); -} - - -void OCommonStatement::cacheResultSet( const ::rtl::Reference< OResultSet >& _pResult ) -{ - ENSURE_OR_THROW( _pResult.is(), "invalid result set" ); - m_xResultSet = Reference< XResultSet >( _pResult.get() ); -} - - -sal_Bool SAL_CALL OCommonStatement::execute( const OUString& sql ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed); - - Reference< XResultSet > xRS = executeQuery( sql ); - // returns true when a resultset is available - return xRS.is(); -} - - -Reference< XResultSet > SAL_CALL OCommonStatement::executeQuery( const OUString& sql ) -{ - ::osl::MutexGuard aGuard( m_ThreadMutex ); - checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed); - - // parse the statement - StatementType eStatementType = parseSql( sql ); - if ( eStatementType != eSelect ) - return nullptr; - - return impl_executeCurrentQuery(); -} - - -Reference< XConnection > SAL_CALL OCommonStatement::getConnection( ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed); - - // just return our connection here - return Reference< XConnection >(m_pConnection.get()); -} - -Any SAL_CALL OStatement::queryInterface( const Type & rType ) -{ - Any aRet = ::cppu::queryInterface(rType,static_cast< XServiceInfo*> (this)); - if(!aRet.hasValue()) - aRet = OCommonStatement::queryInterface(rType); - return aRet; -} - -sal_Int32 SAL_CALL OCommonStatement::executeUpdate( const OUString& /*sql*/ ) -{ - ::dbtools::throwFeatureNotImplementedSQLException( "XStatement::executeUpdate", *this ); - return 0; - -} - -Any SAL_CALL OCommonStatement::getWarnings( ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed); - - return makeAny(m_aLastWarning); -} - - -void SAL_CALL OCommonStatement::clearWarnings( ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OCommonStatement_IBASE::rBHelper.bDisposed); - - - m_aLastWarning = SQLWarning(); -} - -::cppu::IPropertyArrayHelper* OCommonStatement::createArrayHelper( ) const -{ - // this properties are define by the service resultset - // they must in alphabetic order - Sequence< Property > aProps(9); - Property* pProperties = aProps.getArray(); - sal_Int32 nPos = 0; - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), - PROPERTY_ID_CURSORNAME, cppu::UnoType<OUString>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ESCAPEPROCESSING), - PROPERTY_ID_ESCAPEPROCESSING, cppu::UnoType<bool>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), - PROPERTY_ID_FETCHDIRECTION, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), - PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXFIELDSIZE), - PROPERTY_ID_MAXFIELDSIZE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXROWS), - PROPERTY_ID_MAXROWS, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_QUERYTIMEOUT), - PROPERTY_ID_QUERYTIMEOUT, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), - PROPERTY_ID_RESULTSETCONCURRENCY, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), - PROPERTY_ID_RESULTSETTYPE, cppu::UnoType<sal_Int32>::get(), 0); - - return new ::cppu::OPropertyArrayHelper(aProps); -} - - -::cppu::IPropertyArrayHelper & OCommonStatement::getInfoHelper() -{ - return *getArrayHelper(); -} - -sal_Bool OCommonStatement::convertFastPropertyValue( - Any & /*rConvertedValue*/, - Any & /*rOldValue*/, - sal_Int32 /*nHandle*/, - const Any& /*rValue*/ ) -{ - // here we have to try to convert - return false; -} - -void OCommonStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& /*rValue*/) -{ - // set the value to whatever is necessary - switch(nHandle) - { - case PROPERTY_ID_QUERYTIMEOUT: - case PROPERTY_ID_MAXFIELDSIZE: - case PROPERTY_ID_MAXROWS: - case PROPERTY_ID_RESULTSETCONCURRENCY: - case PROPERTY_ID_RESULTSETTYPE: - case PROPERTY_ID_FETCHDIRECTION: - case PROPERTY_ID_FETCHSIZE: - case PROPERTY_ID_ESCAPEPROCESSING: - default: - ; - } -} - -void OCommonStatement::getFastPropertyValue(Any& /*rValue*/,sal_Int32 nHandle) const -{ - switch(nHandle) - { - case PROPERTY_ID_QUERYTIMEOUT: - case PROPERTY_ID_MAXFIELDSIZE: - case PROPERTY_ID_MAXROWS: - case PROPERTY_ID_RESULTSETCONCURRENCY: - case PROPERTY_ID_RESULTSETTYPE: - case PROPERTY_ID_FETCHDIRECTION: - case PROPERTY_ID_FETCHSIZE: - case PROPERTY_ID_ESCAPEPROCESSING: - default: - ; - } -} - -IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbcx.OStatement","com.sun.star.sdbc.Statement"); - -void SAL_CALL OCommonStatement::acquire() throw() -{ - OCommonStatement_IBASE::acquire(); -} - -void SAL_CALL OCommonStatement::release() throw() -{ - OCommonStatement_IBASE::release(); -} - -void SAL_CALL OStatement::acquire() throw() -{ - OCommonStatement::acquire(); -} - -void SAL_CALL OStatement::release() throw() -{ - OCommonStatement::release(); -} - -Reference< css::beans::XPropertySetInfo > SAL_CALL OCommonStatement::getPropertySetInfo( ) -{ - return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); -} - -void OCommonStatement::createColumnMapping() -{ - size_t i; - - // initialize the column index map (mapping select columns to table columns) - ::rtl::Reference<connectivity::OSQLColumns> xColumns = m_pSQLIterator->getSelectColumns(); - m_aColMapping.resize(xColumns->size() + 1); - for (i=0; i<m_aColMapping.size(); ++i) - m_aColMapping[i] = static_cast<sal_Int32>(i); - - Reference<XIndexAccess> xNames(m_xColNames,UNO_QUERY); - // now check which columns are bound -#if OSL_DEBUG_LEVEL > 0 - for ( i = 0; i < m_aColMapping.size(); i++ ) - SAL_INFO( - "connectivity.mork", - "BEFORE Mapped: " << i << " -> " << m_aColMapping[i]); -#endif - OResultSet::setBoundedColumns(m_aRow,xColumns,xNames,true,m_xDBMetaData,m_aColMapping); -#if OSL_DEBUG_LEVEL > 0 - for ( i = 0; i < m_aColMapping.size(); i++ ) - SAL_INFO( - "connectivity.mork", - "AFTER Mapped: " << i << " -> " << m_aColMapping[i]); -#endif -} - - -void OCommonStatement::analyseSQL() -{ - const OSQLParseNode* pOrderbyClause = m_pSQLIterator->getOrderTree(); - if(!pOrderbyClause) - return; - - OSQLParseNode * pOrderingSpecCommalist = pOrderbyClause->getChild(2); - OSL_ENSURE(SQL_ISRULE(pOrderingSpecCommalist,ordering_spec_commalist),"OResultSet: Error in Parse Tree"); - - for (size_t m = 0; m < pOrderingSpecCommalist->count(); m++) - { - OSQLParseNode * pOrderingSpec = pOrderingSpecCommalist->getChild(m); - OSL_ENSURE(SQL_ISRULE(pOrderingSpec,ordering_spec),"OResultSet: Error in Parse Tree"); - OSL_ENSURE(pOrderingSpec->count() == 2,"OResultSet: Error in Parse Tree"); - - OSQLParseNode * pColumnRef = pOrderingSpec->getChild(0); - if(!SQL_ISRULE(pColumnRef,column_ref)) - { - throw SQLException(); - } - OSQLParseNode * pAscendingDescending = pOrderingSpec->getChild(1); - setOrderbyColumn(pColumnRef,pAscendingDescending); - } -} - -void OCommonStatement::setOrderbyColumn(OSQLParseNode const * pColumnRef, - OSQLParseNode const * pAscendingDescending) -{ - OUString aColumnName; - if (pColumnRef->count() == 1) - aColumnName = pColumnRef->getChild(0)->getTokenValue(); - else if (pColumnRef->count() == 3) - { - pColumnRef->getChild(2)->parseNodeToStr( aColumnName, getOwnConnection(), nullptr, false, false ); - } - else - { - throw SQLException(); - } - - Reference<XColumnLocate> xColLocate(m_xColNames,UNO_QUERY); - if(!xColLocate.is()) - return; - - m_aOrderbyColumnNumber.push_back(xColLocate->findColumn(aColumnName)); - - // Ascending or Descending? - m_aOrderbyAscending.push_back(SQL_ISTOKEN(pAscendingDescending,DESC) ? TAscendingOrder::DESC : TAscendingOrder::ASC); -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MStatement.hxx b/connectivity/source/drivers/mork/MStatement.hxx deleted file mode 100644 index 3cd7113a8e47..000000000000 --- a/connectivity/source/drivers/mork/MStatement.hxx +++ /dev/null @@ -1,184 +0,0 @@ -/* -*- 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 . - */ - -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MSTATEMENT_HXX - -#include <comphelper/proparrhlp.hxx> -#include <connectivity/sqliterator.hxx> -#include <connectivity/sqlparse.hxx> -#include <com/sun/star/sdbc/SQLWarning.hpp> -#include <TSortIndex.hxx> -#include "MTable.hxx" - -#include <memory> - -namespace connectivity -{ - namespace mork - { - class OResultSet; - - typedef ::cppu::WeakComponentImplHelper< css::sdbc::XStatement, - css::sdbc::XWarningsSupplier, - css::sdbc::XCloseable> OCommonStatement_IBASE; - - - //************ Class: OCommonStatement - // is a base class for the normal statement and for the prepared statement - - class OCommonStatement; - - class OCommonStatement :public cppu::BaseMutex - ,public OCommonStatement_IBASE - ,public ::cppu::OPropertySetHelper - ,public ::comphelper::OPropertyArrayUsageHelper< OCommonStatement > - { - private: - css::sdbc::SQLWarning m_aLastWarning; - - protected: - css::uno::WeakReference< css::sdbc::XResultSet > m_xResultSet; - css::uno::Reference< css::sdbc::XDatabaseMetaData> m_xDBMetaData; - css::uno::Reference< css::container::XNameAccess> m_xColNames; // table columns - - // for this Statement - - OTable* m_pTable; - rtl::Reference<OConnection> m_pConnection; // The owning Connection object - - OValueRow m_aRow; - - connectivity::OSQLParser m_aParser; - std::shared_ptr< ::connectivity::OSQLParseTreeIterator > - m_pSQLIterator; - - std::unique_ptr<connectivity::OSQLParseNode> m_pParseTree; - - std::vector<sal_Int32> m_aColMapping; - std::vector<sal_Int32> m_aOrderbyColumnNumber; - std::vector<TAscendingOrder> m_aOrderbyAscending; - - protected: - - // OPropertyArrayUsageHelper - virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override; - // OPropertySetHelper - virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; - virtual sal_Bool SAL_CALL convertFastPropertyValue( - css::uno::Any & rConvertedValue, - css::uno::Any & rOldValue, - sal_Int32 nHandle, - const css::uno::Any& rValue ) override; - virtual void SAL_CALL setFastPropertyValue_NoBroadcast( - sal_Int32 nHandle, - const css::uno::Any& rValue) override; - virtual void SAL_CALL getFastPropertyValue( - css::uno::Any& rValue, - sal_Int32 nHandle) const override; - virtual ~OCommonStatement() override; - - protected: - - // Driver Internal Methods - - enum StatementType { eSelect, eCreateTable }; - /** called to do the parsing of a to-be-executed SQL statement, and set all members as needed - - @throws css::sdbc::SQLException - @throws css::uno::RuntimeException - */ - virtual StatementType - parseSql( const OUString& sql , bool bAdjusted = false); - /** called to initialize a result set, according to a previously parsed SQL statement - */ - virtual void initializeResultSet( OResultSet* _pResult ); - /** called when a possible cached instance of our last result set should be cleared - */ - virtual void clearCachedResultSet(); - /** caches a result set which has just been created by an execution of an SQL statement - */ - virtual void cacheResultSet( const ::rtl::Reference< OResultSet >& _pResult ); - - - /** executes the current query (the one which has been passed to the last parseSql call) - */ - css::uno::Reference< css::sdbc::XResultSet > - impl_executeCurrentQuery(); - - void createColumnMapping(); - void analyseSQL(); - void setOrderbyColumn( connectivity::OSQLParseNode const * pColumnRef, - connectivity::OSQLParseNode const * pAscendingDescending); - - public: - // other methods - OConnection* getOwnConnection() const { return m_pConnection.get(); } - - explicit OCommonStatement(OConnection* _pConnection ); - using OCommonStatement_IBASE::operator css::uno::Reference< css::uno::XInterface >; - - // OComponentHelper - virtual void SAL_CALL disposing() override; - - // XInterface - virtual void SAL_CALL release() throw() override; - virtual void SAL_CALL acquire() throw() override; - // XInterface - virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - //XTypeProvider - virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; - - // XPropertySet - virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; - // XStatement - virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery( const OUString& sql ) override ; - virtual sal_Int32 SAL_CALL executeUpdate( const OUString& sql ) override ; - virtual sal_Bool SAL_CALL execute( const OUString& sql ) override ; - virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( ) override ; - // XWarningsSupplier - virtual css::uno::Any SAL_CALL getWarnings( ) override; - virtual void SAL_CALL clearWarnings( ) override; - // XCloseable - virtual void SAL_CALL close( ) override; - - protected: - using OPropertySetHelper::getFastPropertyValue; - }; - - class OStatement : public OCommonStatement, - public css::lang::XServiceInfo - { - protected: - virtual ~OStatement() override {} - public: - // a constructor, for when the object needs to be returned: - explicit OStatement( OConnection* _pConnection); - DECLARE_SERVICE_INFO(); - - virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; - }; - } -} - -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MSTATEMENT_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MTable.cxx b/connectivity/source/drivers/mork/MTable.cxx deleted file mode 100644 index 76db19fc6915..000000000000 --- a/connectivity/source/drivers/mork/MTable.cxx +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- 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 . - */ - -#include "MTable.hxx" -#include "MColumns.hxx" -#include <connectivity/TKeys.hxx> -#include <connectivity/TIndexes.hxx> - - -using namespace connectivity::mork; -using namespace connectivity; - - -OTable::OTable( sdbcx::OCollection* _pTables, OConnection* _pConnection, - const OUString& Name, const OUString& Type, const OUString& Description ) - :OTable_Base(_pTables, _pConnection, true, Name, Type, Description ) - ,m_pConnection( _pConnection ) -{ - construct(); -} - - -sdbcx::OCollection* OTable::createColumns( const ::std::vector< OUString>& _rNames ) -{ - return new OColumns( this, m_aMutex, _rNames ); -} - - -sdbcx::OCollection* OTable::createKeys(const ::std::vector< OUString>& _rNames) -{ - return new OKeysHelper( this, m_aMutex, _rNames ); -} - - -sdbcx::OCollection* OTable::createIndexes(const ::std::vector< OUString>& _rNames) -{ - return new OIndexesHelper( this, m_aMutex, _rNames ); -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MTable.hxx b/connectivity/source/drivers/mork/MTable.hxx deleted file mode 100644 index 7cbe216be9ae..000000000000 --- a/connectivity/source/drivers/mork/MTable.hxx +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- 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 . - */ - -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MTABLE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MTABLE_HXX - -#include <connectivity/TTableHelper.hxx> -#include "MConnection.hxx" - -namespace connectivity -{ - namespace mork - { - typedef ::connectivity::OTableHelper OTable_Base; - - class OTable : public OTable_Base - { - OConnection* m_pConnection; - - public: - OTable( sdbcx::OCollection* _pTables, - OConnection* _pConnection, - const OUString& Name, - const OUString& Type, - const OUString& Description ); - - OConnection* getConnection() { return m_pConnection;} - - static bool isReadOnly() { return false; } - - const OUString& getTableName() const { return m_Name; } - const OUString& getSchema() const { return m_SchemaName; } - - // OTableHelper overridables - virtual sdbcx::OCollection* createColumns( const ::std::vector< OUString>& _rNames ) override; - virtual sdbcx::OCollection* createKeys(const ::std::vector< OUString>& _rNames) override; - virtual sdbcx::OCollection* createIndexes(const ::std::vector< OUString>& _rNames) override; - private: - using OTable_Base::getConnection; - }; - } -} -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MTABLE_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MTables.cxx b/connectivity/source/drivers/mork/MTables.cxx deleted file mode 100644 index f1f169e2a727..000000000000 --- a/connectivity/source/drivers/mork/MTables.cxx +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- 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 . - */ - -#include "MTables.hxx" -#include "MTable.hxx" -#include "MCatalog.hxx" -#include <comphelper/types.hxx> - -#include <com/sun/star/sdbc/XRow.hpp> - -using namespace connectivity; -using namespace connectivity::mork; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::sdbc; - -sdbcx::ObjectType OTables::createObject(const OUString& _rName) -{ - OUString aName,aSchema; - aSchema = "%"; - aName = _rName; - - Sequence< OUString > aTypes { "%" }; - - Reference< XResultSet > xResult = m_xMetaData->getTables(Any(),aSchema,aName,aTypes); - - sdbcx::ObjectType xRet; - if(xResult.is()) - { - Reference< XRow > xRow(xResult,UNO_QUERY); - if(xResult->next()) // there can be only one table with this name - { - OTable* pRet = new OTable( this, static_cast<OCatalog&>(m_rParent).getConnection(), - aName,xRow->getString(4),xRow->getString(5)); - xRet = pRet; - } - } - ::comphelper::disposeComponent(xResult); - - return xRet; -} - -void OTables::impl_refresh( ) -{ - static_cast<OCatalog&>(m_rParent).refreshTables(); -} - -void OTables::disposing() -{ - m_xMetaData.clear(); - OCollection::disposing(); -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MorkParser.cxx b/connectivity/source/drivers/mork/MorkParser.cxx deleted file mode 100644 index 3b8b38120b3b..000000000000 --- a/connectivity/source/drivers/mork/MorkParser.cxx +++ /dev/null @@ -1,757 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * Software License Agreement (BSD License) - * - * Copyright (c) 2006, ScalingWeb.com - * All rights reserved. - * - * Redistribution and use of this software in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above - * copyright notice, this list of conditions and the - * following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * * Neither the name of ScalingWeb.com nor the names of its - * contributors may be used to endorse or promote products - * derived from this software without specific prior - * written permission of ScalingWeb.com. - - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "MorkParser.hxx" -#include <boost/io/ios_state.hpp> -#include <stdlib.h> -#include <string> -#include <string.h> -#include <fstream> -#include <iostream> - -std::string const g_Empty = ""; - -const char * const MorkDictColumnMeta = "<(a=c)>"; - -const int defaultScope_ = 0x80; - -MorkParser::MorkParser() : - columns_(), - values_(), - mork_(), - currentCells_(nullptr), - error_(NoError), - morkData_(), - morkPos_(0), - nextAddValueId_(0x7fffffff), - defaultTableId_(1), - nowParsing_(NP::Values) -{ -} - -bool MorkParser::open( const std::string &path ) -{ - initVars(); - std::string line; - std::ifstream infile(path.c_str(), std::ios_base::in); - if(!infile.is_open()) - { - error_ = FailedToOpen; - return false; - } - - while (getline(infile, line, '\n')) - { - morkData_.append(line); - morkData_.append("\n"); - } - - // Parse mork - return parse(); -} - -void MorkParser::initVars() -{ - error_ = NoError; - morkPos_ = 0; - nowParsing_ = NP::Values; - currentCells_ = nullptr; - nextAddValueId_ = 0x7fffffff; -} - -bool MorkParser::parse() -{ - bool Result = true; - - // Run over mork chars and parse each term - char cur = nextChar(); - - while ( Result && cur ) - { - if ( !isWhiteSpace( cur ) ) - { - // Figure out what a term - switch ( cur ) - { - case '<': - // Dict - Result = parseDict(); - break; - case '/': - // Comment - Result = parseComment(); - break; - case '{': - Result = parseTable(); - // Table - break; - case '[': - Result = parseRow( 0, 0 ); - // Row - break; - case '@': - parseGroup(); - // Group - break; - default: - error_ = DefectedFormat; - Result = false; - break; - } - } - - // Get next char - cur = nextChar(); - } - - return Result; -} - -bool MorkParser::isWhiteSpace( char c ) -{ - switch ( c ) - { - case ' ': - case '\t': - case '\r': - case '\n': - case '\f': - return true; - default: - return false; - } -} - -inline char MorkParser::nextChar() -{ - char cur = 0; - - - if ( morkPos_ < morkData_.length() ) - { - cur = morkData_[ morkPos_ ]; - morkPos_++; - } - - if ( !cur ) - { - cur = 0; - } - - return cur; -} - -bool MorkParser::parseDict() -{ - char cur = nextChar(); - bool Result = true; - nowParsing_ = NP::Values; - - while ( Result && cur != '>' && cur ) - { - if ( !isWhiteSpace( cur ) ) - { - switch ( cur ) - { - case '<': - { - - if ( morkData_.substr( morkPos_ - 1, strlen( MorkDictColumnMeta ) ) == MorkDictColumnMeta ) - { - nowParsing_ = NP::Columns; - morkPos_ += strlen( MorkDictColumnMeta ) - 1; - } - - - break; - } - case '(': - Result = parseCell(); - break; - case '/': - Result = parseComment(); - break; - - } - } - - cur = nextChar(); - } - - return Result; -} - -inline bool MorkParser::parseComment() -{ - char cur = nextChar(); - if ( '/' != cur ) return false; - - while ( cur != '\r' && cur != '\n' && cur ) - { - cur = nextChar(); - } - - return true; -} - -bool MorkParser::parseCell() -{ - bool Result = true; - bool bValueOid = false; - bool bColumn = true; - int Corners = 0; - - // Column = Value - std::string Column; - std::string Text; - Column.reserve( 4 ); - Text.reserve( 32 ); - - char cur = nextChar(); - - // Process cell start with column (bColumn == true) - while ( Result && cur != ')' && cur ) - { - switch ( cur ) - { - case '^': - // Oids - Corners++; - if ( 1 == Corners ) - { - } - else if ( 2 == Corners ) - { - bColumn = false; - bValueOid = true; - } - else - { - Text += cur; - } - - break; - case '=': - // From column to value - if ( bColumn ) - { - bColumn = false; - } - else - { - Text += cur; - } - break; - case '\\': - { - // Get next two chars - char NextChar= nextChar(); - if ( '\r' != NextChar && '\n' != NextChar ) - { - Text += NextChar; - } - else - { - (void)nextChar(); - } - } - break; - case '$': - { - // Get next two chars - std::string HexChar; - HexChar += nextChar(); - HexChar += nextChar(); - Text += static_cast<char>(strtoul(HexChar.c_str(), nullptr, 16)); - } - break; - default: - // Just a char - if ( bColumn ) - { - Column += cur; - } - else - { - Text += cur; - } - break; - } - - cur = nextChar(); - } - - // Apply column and text - int ColumnId = strtoul(Column.c_str(), nullptr, 16); - - if ( NP::Rows != nowParsing_ ) - { - // Dicts - if ( !Text.empty() ) - { - if ( nowParsing_ == NP::Columns ) - { - columns_[ ColumnId ] = Text; - } - else - { - values_[ ColumnId ] = Text; - } - } - } - else - { - if ( !Text.empty() ) - { - // Rows - //int ValueId = string( Text.c_str() ).toInt( 0, 16 ); - int ValueId = strtoul(Text.c_str(), nullptr, 16); - - if ( bValueOid ) - { - ( *currentCells_ )[ ColumnId ] = ValueId; - } - else - { - nextAddValueId_--; - values_[ nextAddValueId_ ] = Text; - ( *currentCells_ )[ ColumnId ] = nextAddValueId_; - } - } - } - - return Result; -} - -bool MorkParser::parseTable() -{ - bool Result = true; - std::string TextId; - int Id = 0, Scope = 0; - - char cur = nextChar(); - - // Get id - while ( cur != '{' && cur != '[' && cur != '}' && cur ) - { - if ( !isWhiteSpace( cur ) ) - { - TextId += cur; - } - - cur = nextChar(); - } - - parseScopeId( TextId, &Id, &Scope ); - - // Parse the table - while ( Result && cur != '}' && cur ) - { - if ( !isWhiteSpace( cur ) ) - { - switch ( cur ) - { - case '{': - parseMeta( '}' ); - break; - case '[': - Result = parseRow( Id, Scope ); - break; - case '-': - case '+': - break; - default: - { - std::string JustId; - while ( !isWhiteSpace( cur ) && cur ) - { - JustId += cur; - cur = nextChar(); - - if ( cur == '}' ) - { - return Result; - } - } - - int JustIdNum = 0, JustScopeNum = 0; - parseScopeId( JustId, &JustIdNum, &JustScopeNum ); - - setCurrentRow( Scope, Id, JustScopeNum, JustIdNum ); - } - break; - } - } - - cur = nextChar(); - } - - return Result; -} - -void MorkParser::parseScopeId( const std::string &TextId, int *Id, int *Scope ) -{ - int Pos = 0; - - if ( ( Pos = TextId.find( ':' ) ) >= 0 ) - { - std::string tId = TextId.substr( 0, Pos ); - std::string tSc = TextId.substr( Pos + 1, TextId.length() - Pos ); - - if ( tSc.length() > 1 && '^' == tSc[ 0 ] ) - { - // Delete '^' - tSc.erase( 0, 1 ); - } - - *Id = strtoul(tId.c_str(), nullptr, 16); - - *Scope = strtoul(tSc.c_str(), nullptr, 16); - } - else - { - *Id = strtoul(TextId.c_str(), nullptr, 16); - } -} - -inline void MorkParser::setCurrentRow( int TableScope, int TableId, int RowScope, int RowId ) -{ - if ( !RowScope ) - { - RowScope = defaultScope_; - } - - if ( !TableScope ) - { - TableScope = defaultScope_; - } - - // 01.08.2012 davido - // TableId 0 is wrong here. - // Straying rows (rows that defined outside the table) belong to the default scope and table is the last was seen: 1:^80 - // (at least i read so the specification) - if (TableId) - { - defaultTableId_ = TableId; - } - - if (!TableId) - { - TableId = defaultTableId_; - } - - currentCells_ = &( mork_.map[ abs( TableScope ) ].map[ abs( TableId ) ].map[ abs( RowScope ) ].map[ abs( RowId ) ] ); -} - -bool MorkParser::parseRow( int TableId, int TableScope ) -{ - bool Result = true; - std::string TextId; - int Id = 0, Scope = 0; - nowParsing_ = NP::Rows; - - char cur = nextChar(); - - // Get id - while ( cur != '(' && cur != ']' && cur != '[' && cur ) - { - if ( !isWhiteSpace( cur ) ) - { - TextId += cur; - } - - cur = nextChar(); - } - - parseScopeId( TextId, &Id, &Scope ); - setCurrentRow( TableScope, TableId, Scope, Id ); - - // Parse the row - while ( Result && cur != ']' && cur ) - { - if ( !isWhiteSpace( cur ) ) - { - switch ( cur ) - { - case '(': - Result = parseCell(); - break; - case '[': - parseMeta( ']' ); - break; - default: - Result = false; - break; - } - } - - cur = nextChar(); - } - - return Result; -} - -void MorkParser::parseGroup() -{ - parseMeta( '@' ); -} - -void MorkParser::parseMeta( char c ) -{ - char cur = nextChar(); - - while ( cur != c && cur ) - { - cur = nextChar(); - } -} - -MorkTableMap *MorkParser::getTables( int TableScope ) -{ - TableScopeMap::Map::iterator iter = mork_.map.find( TableScope ); - - if ( iter == mork_.map.end() ) - { - return nullptr; - } - - return &iter->second; -} - -MorkRowMap *MorkParser::getRows( int RowScope, RowScopeMap *table ) -{ - RowScopeMap::Map::iterator iter = table->map.find( RowScope ); - - if ( iter == table->map.end() ) - { - return nullptr; - } - - return &iter->second; -} - -std::string const &MorkParser::getValue( int oid ) -{ - MorkDict::iterator foundIter = values_.find( oid ); - - if ( values_.end() == foundIter ) - { - return g_Empty; - } - - return foundIter->second; -} - -std::string const &MorkParser::getColumn( int oid ) -{ - MorkDict::iterator foundIter = columns_.find( oid ); - - if ( columns_.end() == foundIter ) - { - return g_Empty; - } - - return foundIter->second; -} - -void MorkParser::retrieveLists(std::set<std::string>& lists) -{ -#ifdef VERBOSE - boost::io::ios_all_saver ias(std::cout); - std::cout << std::hex << std::uppercase; -#endif - - MorkTableMap* tables = getTables(defaultScope_); - if (!tables) return; - for (auto& rTable : tables->map) - { -#ifdef VERBOSE - std::cout << "\t Table:" - << ( ( int ) rTable.first < 0 ? "-" : " " ) - << rTable.first << std::endl; -#endif - MorkRowMap* rows = getRows( 0x81/*defaultListScope*/, &rTable.second ); - if (!rows) return; - for ( const auto& rRow : rows->map ) - { -#ifdef VERBOSE - std::cout << "\t\t\t Row Id:" - << ( ( int ) rRow.first < 0 ? "-" : " ") - << rRow.first << std::endl; - std::cout << "\t\t\t\t Cells:\r\n"; -#endif - // Get cells - MorkCells::const_iterator cellsIter = rRow.second.find(0xC1); - if (cellsIter != rRow.second.end()) - lists.insert(getValue( cellsIter->second )); - } - } -} - -void MorkParser::getRecordKeysForListTable(std::string const & listName, std::set<int>& records) -{ -#ifdef VERBOSE - boost::io::ios_all_saver ias(std::cout); - std::cout << std::hex << std::uppercase; -#endif - - MorkTableMap* tables = getTables(defaultScope_); - if (!tables) return; - for (auto& rTable : tables->map) - { -#ifdef VERBOSE - std::cout << "\t Table:" - << ( ( int ) rTable.first < 0 ? "-" : " " ) - << rTable.first << std::endl; -#endif - MorkRowMap* rows = getRows( 0x81, &rTable.second ); - if (!rows) return; - for ( const auto& rRow : rows->map ) - { -#ifdef VERBOSE - std::cout << "\t\t\t Row Id:" - << ( ( int ) rRow.first < 0 ? "-" : " ") - << rRow.first << std::endl; - std::cout << "\t\t\t\t Cells:\r\n"; -#endif - // Get cells - bool isListFound = false; - for ( const auto& [rColumnId, rValueId] : rRow.second ) - { - if (isListFound) - { - if (rColumnId >= 0xC7) - { - std::string value = getValue(rValueId); - int id = strtoul(value.c_str(), nullptr, 16); - records.insert(id); - } - } - else if ((rColumnId == 0xC1) && - listName == getValue( rValueId )) - { - isListFound = true; - } - } - - } - } -} - -void MorkParser::dump() -{ - boost::io::ios_all_saver ias(std::cout); - std::cout << std::hex << std::uppercase; - - std::cout << "Column Dict:\r\n"; - std::cout << "=============================================\r\n\r\n"; - - //// columns dict - for ( const auto& [rColumnId, rText] : columns_ ) - { - std::cout << rColumnId - << " : " - << rText - << std::endl; - } - - //// values dict - std::cout << "\r\nValues Dict:\r\n"; - std::cout << "=============================================\r\n\r\n"; - - for ( const auto& [rValueId, rText] : values_ ) - { - if (rValueId >= nextAddValueId_) { - continue; - } - - std::cout << rValueId - << " : " - << rText - << "\r\n"; - } - - std::cout << std::endl << "Data:" << std::endl; - std::cout << "=============================================" - << std::endl << std::endl; - - //// Mork data - for ( const auto& [rTableScopeId, rTableScope] : mork_.map ) - { - std::cout << "\r\n Scope:" << rTableScopeId << std::endl; - - for ( const auto& [rTableId, rTable] : rTableScope.map ) - { - std::cout << "\t Table:" - << ( rTableId < 0 ? "-" : " " ) - << rTableId << std::endl; - - for (const auto& [rRowScopeId, rRowScope] : rTable.map) - { - std::cout << "\t\t RowScope:" - << rRowScopeId << std::endl; - - for (const auto& [rRowId, rRow] : rRowScope.map) - { - std::cout << "\t\t\t Row Id:" - << (rRowId < 0 ? "-" : " ") - << rRowId << std::endl; - std::cout << "\t\t\t\t Cells:" << std::endl; - - for (const auto& [rColumnId, rValueId] : rRow) - { - // Write ids - std::cout << "\t\t\t\t\t" - << rColumnId - << " : " - << rValueId - << " => "; - - MorkDict::const_iterator FoundIter = values_.find( rValueId ); - if ( FoundIter != values_.end() ) - { - // Write string values - std::cout << columns_[ rColumnId ].c_str() - << " : " - << FoundIter->second.c_str() - << std::endl; - } - } - } - } - } - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MorkParser.hxx b/connectivity/source/drivers/mork/MorkParser.hxx deleted file mode 100644 index d16fc417dacd..000000000000 --- a/connectivity/source/drivers/mork/MorkParser.hxx +++ /dev/null @@ -1,152 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * Software License Agreement (BSD License) - * - * Copyright (c) 2006, ScalingWeb.com - * All rights reserved. - * - * Redistribution and use of this software in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above - * copyright notice, this list of conditions and the - * following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * * Neither the name of ScalingWeb.com nor the names of its - * contributors may be used to endorse or promote products - * derived from this software without specific prior - * written permission of ScalingWeb.com. - - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MORKPARSER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MORKPARSER_HXX - -#include <rtl/ustring.hxx> - -#include <string> -#include <map> -#include <set> -#include <vector> - -#include "dllapi.h" - -// Types - -typedef std::map< int, std::string > MorkDict; -typedef std::map< int, int > MorkCells; // ColumnId : ValueId -struct MorkRowMap { typedef std::map< int, MorkCells > Map; Map map; }; // Row id -struct RowScopeMap { typedef std::map< int, MorkRowMap > Map; Map map; }; // Row scope -struct MorkTableMap { typedef std::map< int, RowScopeMap > Map; Map map; }; // Table id -struct TableScopeMap { typedef std::map< int, MorkTableMap > Map; Map map; }; // Table Scope - -// Error codes -enum MorkErrors -{ - NoError = 0, - FailedToOpen, - DefectedFormat -}; - - -/// Class MorkParser - -class LO_DLLPUBLIC_MORK MorkParser final -{ -public: - - explicit MorkParser(); - - /// Open and parse mork file - - bool open( const std::string &path ); - - /// Returns all tables of specified scope - - MorkTableMap *getTables( int tableScope ); - - /// Returns all rows under specified scope - - static MorkRowMap *getRows( int rowScope, RowScopeMap *table ); - - /// Return value of specified value oid - - std::string const &getValue( int oid ); - - /// Return value of specified column oid - - std::string const &getColumn( int oid ); - - void retrieveLists(std::set<std::string>& lists); - void getRecordKeysForListTable(std::string const & listName, std::set<int>& records); - - void dump(); - - // All lists - std::vector<OUString> lists_; - -private: // Members - - void initVars(); - - static bool isWhiteSpace( char c ); - char nextChar(); - - static void parseScopeId( const std::string &TextId, int *Id, int *Scope ); - void setCurrentRow( int TableScope, int TableId, int RowScope, int RowId ); - - // Parse methods - bool parse(); - bool parseDict(); - bool parseComment(); - bool parseCell(); - bool parseTable(); - void parseMeta( char c ); - bool parseRow( int TableId, int TableScope ); - void parseGroup(); - -private: // Data - - // Columns in mork means value names - MorkDict columns_; - MorkDict values_; - - // All mork file data - TableScopeMap mork_; - MorkCells *currentCells_; - - // Error status of last operation - MorkErrors error_; - - // All Mork data - std::string morkData_; - - - unsigned morkPos_; - int nextAddValueId_; - int defaultTableId_; - - // Indicates entity is being parsed - enum class NP { Columns, Values, Rows } nowParsing_; - - MorkParser(const MorkParser &) = delete; - MorkParser &operator=(const MorkParser &) = delete; - -}; - -#endif // __MorkParser_h__ - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/README b/connectivity/source/drivers/mork/README deleted file mode 100644 index 0d4207b0ca0d..000000000000 --- a/connectivity/source/drivers/mork/README +++ /dev/null @@ -1,41 +0,0 @@ -Mork Format Parsing Library -============================= - -Description ------------ - -Cross Platform Mozilla Mork format reader. - - -Compilation ------------- - -g++ -o MorkParser main.cpp MorkParser.cpp - - -License -------- - -This program is licensed under permissive BSD license. -See the license.txt file for more information. - - -Date: October 16th, 2007 - -Project Maintainers: - Yuriy Soroka - ysoroka@scalingweb.com - - http://www.scalingweb.com/ - -Thanks -------------- -Thanks to Petr Stejskal <stejsky@volny.cz> who helped with porting this code from Qt to STL. - - -How you can help ----------------- - - Comments, patches, bug reports are welcome. - - diff --git a/connectivity/source/drivers/mork/dllapi.h b/connectivity/source/drivers/mork/dllapi.h deleted file mode 100644 index adf269107d22..000000000000 --- a/connectivity/source/drivers/mork/dllapi.h +++ /dev/null @@ -1,25 +0,0 @@ - -/* -*- 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/. - */ - -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_DLLAPI_H -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_DLLAPI_H - -#include <sal/config.h> -#include <sal/types.h> - -#if defined LO_DLLIMPLEMENTATION_MORK -#define LO_DLLPUBLIC_MORK SAL_DLLPUBLIC_EXPORT -#else -#define LO_DLLPUBLIC_MORK SAL_DLLPUBLIC_IMPORT -#endif - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/license.txt b/connectivity/source/drivers/mork/license.txt deleted file mode 100644 index 3e41befc7e7c..000000000000 --- a/connectivity/source/drivers/mork/license.txt +++ /dev/null @@ -1,31 +0,0 @@ -Software License Agreement (BSD License) - -Copyright (c) 2006, ScalingWeb.com -All rights reserved. - -Redistribution and use of this software in source and binary forms, with or without modification, are -permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above - copyright notice, this list of conditions and the - following disclaimer. - -* Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the - following disclaimer in the documentation and/or other - materials provided with the distribution. - -* Neither the name of ScalingWeb.com nor the names of its - contributors may be used to endorse or promote products - derived from this software without specific prior - written permission of ScalingWeb.com. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR -TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - diff --git a/connectivity/source/drivers/mork/mork.component b/connectivity/source/drivers/mork/mork.component deleted file mode 100644 index 1eeb6affb894..000000000000 --- a/connectivity/source/drivers/mork/mork.component +++ /dev/null @@ -1,17 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - * 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/. - * ---> - -<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" - xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="com.sun.star.comp.sdbc.MorkDriver" - constructor="com_sun_star_comp_sdbc_MorkDriver_get_implementation"> - <service name="com.sun.star.sdbc.Driver"/> - </implementation> -</component> diff --git a/connectivity/source/drivers/mork/mork_helper.cxx b/connectivity/source/drivers/mork/mork_helper.cxx deleted file mode 100644 index 4cb11864fee5..000000000000 --- a/connectivity/source/drivers/mork/mork_helper.cxx +++ /dev/null @@ -1,54 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ - -#include "MorkParser.hxx" -#include <iostream> -#include <sal/log.hxx> - -static bool openAddressBook(const std::string& path) -{ - MorkParser mork; - // Open and parse mork file - if (!mork.open(path)) - { - return false; - } - - const int defaultScope = 0x80; - MorkTableMap *Tables = mork.getTables( defaultScope ); - if ( Tables ) - { - // Iterate all tables - for (auto const& table : Tables->map) - { - if ( 0 == table.first ) continue; - SAL_INFO("connectivity.mork", "table->first : " << table.first); - std::string column = mork.getColumn( table.first ); - std::string value = mork.getValue( table.first ); - SAL_INFO("connectivity.mork", "table.column : " << column); - SAL_INFO("connectivity.mork", "table.value : " << value); - } - } - - mork.dump(); - - return true; -} - -int main(int argc, char* argv[]) -{ - if (argc < 2) - { - std::cerr << "Usage: " << argv[0] << " <path-to>/abook.mab" << std::endl; - std::cerr << "Example: " << argv[0] << " /home/johndoe/.thunderbird/m0tpqlky.default/abook.mab" << std::endl; - - return 1; - } - - OString aOString(argv[1]); - SAL_INFO("connectivity.mork", "abook.mab: " << aOString); - openAddressBook(aOString.getStr()); - - return 0; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.cxx b/connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.cxx index 62bea4e8f253..076a05d3b9dc 100644 --- a/connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.cxx +++ b/connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.cxx @@ -21,7 +21,7 @@ #include <cppuhelper/factory.hxx> #include <com/sun/star/lang/XSingleServiceFactory.hpp> #include <cppuhelper/supportsservice.hxx> -#include <rtl/ref.hxx> +#include <cppuhelper/weak.hxx> #include "MMozillaBootstrap.hxx" #include "MNSProfileDiscover.hxx" @@ -32,8 +32,6 @@ using namespace connectivity::mozab; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Sequence; -using ::com::sun::star::lang::XSingleServiceFactory; -using ::com::sun::star::lang::XMultiServiceFactory; MozillaBootstrap::MozillaBootstrap() : OMozillaBootstrap_BASE(m_aMutex) @@ -132,9 +130,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* connectivity_moz_MozillaBootstrap_get_implementation( css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&) { - static rtl::Reference<MozillaBootstrap> pMozillaBootstrap(new connectivity::mozab::MozillaBootstrap()); - pMozillaBootstrap->acquire(); - return static_cast<cppu::OWeakObject*>(pMozillaBootstrap.get()); + return cppu::acquire(new connectivity::mozab::MozillaBootstrap()); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.hxx b/connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.hxx index 24407e038ccb..e01a2bb9612c 100644 --- a/connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.hxx +++ b/connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_BOOTSTRAP_MMOZILLABOOTSTRAP_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_BOOTSTRAP_MMOZILLABOOTSTRAP_HXX +#pragma once #include <sal/config.h> @@ -28,10 +27,8 @@ #include <cppuhelper/compbase.hxx> -namespace connectivity +namespace connectivity::mozab { - namespace mozab - { typedef ::cppu::WeakComponentImplHelper< css::mozilla::XMozillaBootstrap, css::lang::XServiceInfo > OMozillaBootstrap_BASE; class ProfileAccess; @@ -75,10 +72,7 @@ namespace connectivity // XProxyRunner virtual ::sal_Int32 SAL_CALL Run( const css::uno::Reference< css::mozilla::XCodeProxy >& aCode ) override; }; - } } -#endif // CONNECTIVITY_SMozillaBootstrap_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mozab/bootstrap/MNSFolders.hxx b/connectivity/source/drivers/mozab/bootstrap/MNSFolders.hxx index 50c992f230af..90674a0f4e62 100644 --- a/connectivity/source/drivers/mozab/bootstrap/MNSFolders.hxx +++ b/connectivity/source/drivers/mozab/bootstrap/MNSFolders.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_BOOTSTRAP_MNSFOLDERS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_BOOTSTRAP_MNSFOLDERS_HXX +#pragma once #include <com/sun/star/mozilla/MozillaProductType.hpp> @@ -26,6 +25,4 @@ OUString getRegistryDir(css::mozilla::MozillaProductType product); -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mozab/bootstrap/MNSINIParser.cxx b/connectivity/source/drivers/mozab/bootstrap/MNSINIParser.cxx index ae775b6fca01..a146d0c09680 100644 --- a/connectivity/source/drivers/mozab/bootstrap/MNSINIParser.cxx +++ b/connectivity/source/drivers/mozab/bootstrap/MNSINIParser.cxx @@ -22,6 +22,7 @@ #include <osl/file.h> #include <rtl/byteseq.hxx> #include <sal/log.hxx> +#include <o3tl/string_view.hxx> IniParser::IniParser(OUString const & rIniName) { @@ -62,9 +63,9 @@ IniParser::IniParser(OUString const & rIniName) ini_Section *aSection = &mAllSection[sectionName]; struct ini_NameValue nameValue; nameValue.sName = OStringToOUString( - line.copy(0,nIndex).trim(), RTL_TEXTENCODING_ASCII_US ); + o3tl::trim(line.subView(0,nIndex)), RTL_TEXTENCODING_ASCII_US ); nameValue.sValue = OStringToOUString( - line.copy(nIndex+1).trim(), RTL_TEXTENCODING_UTF8 ); + o3tl::trim(line.subView(nIndex+1)), RTL_TEXTENCODING_UTF8 ); aSection->vVector.push_back(nameValue); @@ -76,7 +77,7 @@ IniParser::IniParser(OUString const & rIniName) if ( nIndexEnd > nIndexStart && nIndexStart >=0) { sectionName = OStringToOUString( - line.copy(nIndexStart + 1,nIndexEnd - nIndexStart -1).trim(), RTL_TEXTENCODING_ASCII_US ); + o3tl::trim(line.subView(nIndexStart + 1,nIndexEnd - nIndexStart -1)), RTL_TEXTENCODING_ASCII_US ); if (sectionName.isEmpty()) sectionName = "no name section"; } diff --git a/connectivity/source/drivers/mozab/bootstrap/MNSINIParser.hxx b/connectivity/source/drivers/mozab/bootstrap/MNSINIParser.hxx index 210553b73bcc..27746364a33a 100644 --- a/connectivity/source/drivers/mozab/bootstrap/MNSINIParser.hxx +++ b/connectivity/source/drivers/mozab/bootstrap/MNSINIParser.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_BOOTSTRAP_MNSINIPARSER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_BOOTSTRAP_MNSINIPARSER_HXX +#pragma once #include <rtl/ustring.hxx> @@ -52,6 +51,4 @@ public: explicit IniParser(OUString const & rIniName); }; -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.cxx b/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.cxx index 4dd9110a6f0f..804c8ccc66d8 100644 --- a/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.cxx +++ b/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.cxx @@ -18,6 +18,8 @@ */ +#include <utility> + #include "MNSProfileDiscover.hxx" #include "MNSFolders.hxx" #include "MNSINIParser.hxx" @@ -28,10 +30,10 @@ namespace connectivity::mozab { } - ProfileStruct::ProfileStruct(const OUString& aProfileName, - const OUString& aProfilePath) - : profileName(aProfileName) - , profilePath(aProfilePath) + ProfileStruct::ProfileStruct(OUString aProfileName, + OUString aProfilePath) + : profileName(std::move(aProfileName)) + , profilePath(std::move(aProfilePath)) { } @@ -168,11 +170,12 @@ namespace connectivity::mozab sal_Int32 index=static_cast<sal_Int32>(product); ProductStruct &rProduct = m_ProductProfileList[index]; list.realloc(static_cast<sal_Int32>(rProduct.mProfileList.size())); + auto listRange = list.getArray(); sal_Int32 i=0; for(const auto& rEntry : rProduct.mProfileList) { const ProfileStruct& rProfile = rEntry.second; - list[i] = rProfile.getProfileName(); + listRange[i] = rProfile.getProfileName(); i++; } diff --git a/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.hxx b/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.hxx index 8921a9c4bcfc..132ac06c003c 100644 --- a/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.hxx +++ b/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_BOOTSTRAP_MNSPROFILEDISCOVER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_BOOTSTRAP_MNSPROFILEDISCOVER_HXX +#pragma once #include <sal/types.h> #include <com/sun/star/mozilla/MozillaProductType.hpp> @@ -29,23 +28,16 @@ #include <map> using namespace com::sun::star::mozilla; -namespace connectivity -{ - namespace mozab - { - class ProfileStruct; - } -} +namespace connectivity::mozab { class ProfileStruct; } + typedef std::map<OUString, ::connectivity::mozab::ProfileStruct> ProfileList; -namespace connectivity -{ - namespace mozab +namespace connectivity::mozab { class ProfileStruct { public: ProfileStruct(); - ProfileStruct(const OUString& aProfileName, const OUString &aProfilePath); + ProfileStruct(OUString aProfileName, OUString aProfilePath); const OUString& getProfileName() const { return profileName;} const OUString& getProfilePath() const; private: @@ -82,9 +74,7 @@ namespace connectivity void LoadXPToolkitProfiles(MozillaProductType product); }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_BOOTSTRAP_MNSPROFILEDISCOVER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mozab/bootstrap/README b/connectivity/source/drivers/mozab/bootstrap/README new file mode 100644 index 000000000000..cea68d86cc56 --- /dev/null +++ b/connectivity/source/drivers/mozab/bootstrap/README @@ -0,0 +1,3 @@ +this provides com.sun.star.mozilla.MozillaBootstrap which is used by at least +xmlsecurity/source/xmlsec/nss/nssinitializer.cxx to find a user's +firefox/thunderbird profile to use its certs diff --git a/connectivity/source/drivers/mozab/bootstrap/mozbootstrap.component b/connectivity/source/drivers/mozab/bootstrap/mozbootstrap.component index 11b58c134ba8..bfc0afe389ef 100644 --- a/connectivity/source/drivers/mozab/bootstrap/mozbootstrap.component +++ b/connectivity/source/drivers/mozab/bootstrap/mozbootstrap.component @@ -20,7 +20,7 @@ <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" xmlns="http://openoffice.org/2010/uno-components"> <implementation name="com.sun.star.comp.mozilla.MozillaBootstrap" - constructor="connectivity_moz_MozillaBootstrap_get_implementation"> + constructor="connectivity_moz_MozillaBootstrap_get_implementation" single-instance="true"> <service name="com.sun.star.mozilla.MozillaBootstrap"/> </implementation> </component> diff --git a/connectivity/source/drivers/mysql_jdbc/YCatalog.cxx b/connectivity/source/drivers/mysql_jdbc/YCatalog.cxx index ad98bfa1a7fa..de9ffd7127d5 100644 --- a/connectivity/source/drivers/mysql_jdbc/YCatalog.cxx +++ b/connectivity/source/drivers/mysql_jdbc/YCatalog.cxx @@ -29,11 +29,8 @@ using namespace connectivity; using namespace connectivity::mysql; using namespace connectivity::sdbcx; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; OMySQLCatalog::OMySQLCatalog(const Reference<XConnection>& _xConnection) : OCatalog(_xConnection) @@ -52,10 +49,9 @@ void OMySQLCatalog::refreshTables() { ::std::vector<OUString> aVector; - Sequence<OUString> sTableTypes(3); - sTableTypes[0] = "VIEW"; - sTableTypes[1] = "TABLE"; - sTableTypes[2] = "%"; // just to be sure to include anything else... + Sequence<OUString> sTableTypes{ + "VIEW", "TABLE", "%" + }; // this last one just to be sure to include anything else... refreshObjects(sTableTypes, aVector); diff --git a/connectivity/source/drivers/mysql_jdbc/YColumns.cxx b/connectivity/source/drivers/mysql_jdbc/YColumns.cxx index 54beb77ca061..910b01e4fb11 100644 --- a/connectivity/source/drivers/mysql_jdbc/YColumns.cxx +++ b/connectivity/source/drivers/mysql_jdbc/YColumns.cxx @@ -26,10 +26,6 @@ using namespace connectivity::sdbcx; using namespace connectivity; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdbcx; -using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; OMySQLColumns::OMySQLColumns(::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, const ::std::vector<OUString>& _rVector) diff --git a/connectivity/source/drivers/mysql_jdbc/YDriver.cxx b/connectivity/source/drivers/mysql_jdbc/YDriver.cxx index 69d4bfbb77e1..e4e338ee0b31 100644 --- a/connectivity/source/drivers/mysql_jdbc/YDriver.cxx +++ b/connectivity/source/drivers/mysql_jdbc/YDriver.cxx @@ -17,10 +17,14 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <string_view> + #include <mysql/YDriver.hxx> #include <mysql/YCatalog.hxx> +#include <o3tl/string_view.hxx> #include <comphelper/namedvaluecollection.hxx> -#include <comphelper/processfactory.hxx> #include <comphelper/servicehelper.hxx> #include <comphelper/types.hxx> #include <cppuhelper/supportsservice.hxx> @@ -45,8 +49,8 @@ namespace { OUString getJavaDriverClass(css::uno::Sequence<css::beans::PropertyValue> const& info) { - return comphelper::NamedValueCollection(info).getOrDefault("JavaDriverClass", - OUString("com.mysql.jdbc.Driver")); + return comphelper::NamedValueCollection::getOrDefault(info, u"JavaDriverClass", + OUString("com.mysql.jdbc.Driver")); } } @@ -94,11 +98,14 @@ enum class T_DRIVERTYPE Native }; -bool isOdbcUrl(const OUString& _sUrl) { return _sUrl.startsWith("sdbc:mysql:odbc:"); } +bool isOdbcUrl(std::u16string_view _sUrl) { return o3tl::starts_with(_sUrl, u"sdbc:mysql:odbc:"); } -bool isNativeUrl(const OUString& _sUrl) { return _sUrl.startsWith("sdbc:mysql:mysqlc:"); } +bool isNativeUrl(std::u16string_view _sUrl) +{ + return o3tl::starts_with(_sUrl, u"sdbc:mysql:mysqlc:"); +} -T_DRIVERTYPE lcl_getDriverType(const OUString& _sUrl) +T_DRIVERTYPE lcl_getDriverType(std::u16string_view _sUrl) { T_DRIVERTYPE eRet = T_DRIVERTYPE::Jdbc; if (isOdbcUrl(_sUrl)) @@ -108,16 +115,16 @@ T_DRIVERTYPE lcl_getDriverType(const OUString& _sUrl) return eRet; } -OUString transformUrl(const OUString& _sUrl) +OUString transformUrl(std::u16string_view _sUrl) { - OUString sNewUrl = _sUrl.copy(11); + OUString sNewUrl(_sUrl.substr(11)); if (isOdbcUrl(_sUrl)) sNewUrl = "sdbc:" + sNewUrl; else if (isNativeUrl(_sUrl)) sNewUrl = "sdbc:" + sNewUrl; else { - sNewUrl = "jdbc:mysql://" + sNewUrl.copy(5); + sNewUrl = OUString::Concat("jdbc:mysql://") + sNewUrl.subView(5); } return sNewUrl; } @@ -151,36 +158,30 @@ Sequence<PropertyValue> lcl_convertProperties(T_DRIVERTYPE _eType, if (_eType == T_DRIVERTYPE::Odbc) { - aProps.push_back(PropertyValue("Silent", 0, makeAny(true), PropertyState_DIRECT_VALUE)); - aProps.push_back(PropertyValue("PreventGetVersionColumns", 0, makeAny(true), - PropertyState_DIRECT_VALUE)); + aProps.emplace_back("Silent", 0, Any(true), PropertyState_DIRECT_VALUE); + aProps.emplace_back("PreventGetVersionColumns", 0, Any(true), PropertyState_DIRECT_VALUE); } else if (_eType == T_DRIVERTYPE::Jdbc) { if (!jdc) { - aProps.push_back(PropertyValue("JavaDriverClass", 0, - makeAny(OUString("com.mysql.jdbc.Driver")), - PropertyState_DIRECT_VALUE)); + aProps.emplace_back("JavaDriverClass", 0, Any(OUString("com.mysql.jdbc.Driver")), + PropertyState_DIRECT_VALUE); } } else { - aProps.push_back( - PropertyValue("PublicConnectionURL", 0, makeAny(_sUrl), PropertyState_DIRECT_VALUE)); + aProps.emplace_back("PublicConnectionURL", 0, Any(_sUrl), PropertyState_DIRECT_VALUE); } - aProps.push_back( - PropertyValue("IsAutoRetrievingEnabled", 0, makeAny(true), PropertyState_DIRECT_VALUE)); - aProps.push_back(PropertyValue("AutoRetrievingStatement", 0, - makeAny(OUString("SELECT LAST_INSERT_ID()")), - PropertyState_DIRECT_VALUE)); - aProps.push_back( - PropertyValue("ParameterNameSubstitution", 0, makeAny(true), PropertyState_DIRECT_VALUE)); + aProps.emplace_back("IsAutoRetrievingEnabled", 0, Any(true), PropertyState_DIRECT_VALUE); + aProps.emplace_back("AutoRetrievingStatement", 0, Any(OUString("SELECT LAST_INSERT_ID()")), + PropertyState_DIRECT_VALUE); + aProps.emplace_back("ParameterNameSubstitution", 0, Any(true), PropertyState_DIRECT_VALUE); return Sequence<PropertyValue>(aProps.data(), aProps.size()); } } -Reference<XDriver> ODriverDelegator::loadDriver(const OUString& url, +Reference<XDriver> ODriverDelegator::loadDriver(std::u16string_view url, const Sequence<PropertyValue>& info) { Reference<XDriver> xDriver; @@ -225,8 +226,8 @@ Reference<XConnection> SAL_CALL ODriverDelegator::connect(const OUString& url, Sequence<PropertyValue> aConvertedProperties = lcl_convertProperties(eType, info, url); if (eType == T_DRIVERTYPE::Jdbc) { - ::comphelper::NamedValueCollection aSettings(info); - OUString sIanaName = aSettings.getOrDefault("CharSet", OUString()); + OUString sIanaName = ::comphelper::NamedValueCollection::getOrDefault( + info, u"CharSet", OUString()); if (!sIanaName.isEmpty()) { ::dbtools::OCharsetMap aLookupIanaName; @@ -237,7 +238,7 @@ Reference<XConnection> SAL_CALL ODriverDelegator::connect(const OUString& url, OUString sAdd; if (RTL_TEXTENCODING_UTF8 == (*aLookup).getEncoding()) { - static const char s_sCharSetOp[] = "useUnicode=true&"; + static constexpr OUString s_sCharSetOp = u"useUnicode=true&"_ustr; if (!sCuttedUrl.matchIgnoreAsciiCase(s_sCharSetOp)) { sAdd = s_sCharSetOp; @@ -256,13 +257,12 @@ Reference<XConnection> SAL_CALL ODriverDelegator::connect(const OUString& url, if (xConnection.is()) { // now we have to set the URL to get the correct answer for metadata()->getURL() - auto pMetaConnection - = comphelper::getUnoTunnelImplementation<OMetaConnection>(xConnection); + auto pMetaConnection = comphelper::getFromUnoTunnel<OMetaConnection>(xConnection); if (pMetaConnection) pMetaConnection->setURL(url); - m_aConnections.push_back( - TWeakPair(WeakReferenceHelper(xConnection), - TWeakConnectionPair(WeakReferenceHelper(), pMetaConnection))); + m_aConnections.emplace_back( + WeakReferenceHelper(xConnection), + TWeakConnectionPair(WeakReferenceHelper(), pMetaConnection)); } } } @@ -281,34 +281,30 @@ sal_Bool SAL_CALL ODriverDelegator::acceptsURL(const OUString& url) Sequence<DriverPropertyInfo> SAL_CALL ODriverDelegator::getPropertyInfo(const OUString& url, const Sequence<PropertyValue>& info) { - std::vector<DriverPropertyInfo> aDriverInfo; if (!acceptsURL(url)) return Sequence<DriverPropertyInfo>(); - Sequence<OUString> aBoolean(2); - aBoolean[0] = "0"; - aBoolean[1] = "1"; + Sequence<OUString> aBoolean{ "0", "1" }; - aDriverInfo.push_back(DriverPropertyInfo("CharSet", "CharSet of the database.", false, - OUString(), Sequence<OUString>())); - aDriverInfo.push_back(DriverPropertyInfo("SuppressVersionColumns", - "Display version columns (when available).", false, - "0", aBoolean)); + std::vector<DriverPropertyInfo> aDriverInfo{ + { "CharSet", "CharSet of the database.", false, {}, {} }, + { "SuppressVersionColumns", "Display version columns (when available).", false, "0", + aBoolean } + }; const T_DRIVERTYPE eType = lcl_getDriverType(url); if (eType == T_DRIVERTYPE::Jdbc) { - aDriverInfo.push_back(DriverPropertyInfo("JavaDriverClass", "The JDBC driver class name.", - true, getJavaDriverClass(info), - Sequence<OUString>())); + aDriverInfo.emplace_back("JavaDriverClass", "The JDBC driver class name.", true, + getJavaDriverClass(info), Sequence<OUString>()); } else if (eType == T_DRIVERTYPE::Native) { - aDriverInfo.push_back(DriverPropertyInfo( - "LocalSocket", "The file path of a socket to connect to a local MySQL server.", false, - OUString(), Sequence<OUString>())); - aDriverInfo.push_back(DriverPropertyInfo( - "NamedPipe", "The name of a pipe to connect to a local MySQL server.", false, - OUString(), Sequence<OUString>())); + aDriverInfo.emplace_back("LocalSocket", + "The file path of a socket to connect to a local MySQL server.", + false, OUString(), Sequence<OUString>()); + aDriverInfo.emplace_back("NamedPipe", + "The name of a pipe to connect to a local MySQL server.", false, + OUString(), Sequence<OUString>()); } return Sequence<DriverPropertyInfo>(aDriverInfo.data(), aDriverInfo.size()); @@ -325,7 +321,7 @@ ODriverDelegator::getDataDefinitionByConnection(const Reference<XConnection>& co checkDisposed(ODriverDelegator_BASE::rBHelper.bDisposed); Reference<XTablesSupplier> xTab; - auto pConnection = comphelper::getUnoTunnelImplementation<OMetaConnection>(connection); + auto pConnection = comphelper::getFromUnoTunnel<OMetaConnection>(connection); if (pConnection) { TWeakPairVector::iterator i diff --git a/connectivity/source/drivers/mysql_jdbc/YTable.cxx b/connectivity/source/drivers/mysql_jdbc/YTable.cxx index 7959bd9d30e5..b79b3f231bbf 100644 --- a/connectivity/source/drivers/mysql_jdbc/YTable.cxx +++ b/connectivity/source/drivers/mysql_jdbc/YTable.cxx @@ -19,7 +19,6 @@ #include <mysql/YTable.hxx> #include <mysql/YTables.hxx> -#include <cppuhelper/typeprovider.hxx> #include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/sdbcx/Privilege.hpp> #include <comphelper/property.hxx> @@ -117,21 +116,6 @@ sdbcx::OCollection* OMySQLTable::createIndexes(const ::std::vector<OUString>& _r return new OIndexesHelper(this, m_aMutex, _rNames); } -Sequence<sal_Int8> OMySQLTable::getUnoTunnelId() -{ - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); -} - -// css::lang::XUnoTunnel - -sal_Int64 OMySQLTable::getSomething(const Sequence<sal_Int8>& rId) -{ - return (isUnoTunnelId<OMySQLTable>(rId)) ? reinterpret_cast<sal_Int64>(this) - : OTable_TYPEDEF::getSomething(rId); -} - // XAlterTable void SAL_CALL OMySQLTable::alterColumnByName(const OUString& colName, const Reference<XPropertySet>& descriptor) @@ -198,9 +182,9 @@ void SAL_CALL OMySQLTable::alterColumnByName(const OUString& colName, { if (sTypeName.indexOf(s_sAutoIncrement) == -1) { - sTypeName += OUStringLiteral(" ") + s_sAutoIncrement; + sTypeName += OUString::Concat(" ") + s_sAutoIncrement; descriptor->setPropertyValue(rProp.getNameByIndex(PROPERTY_ID_TYPENAME), - makeAny(sTypeName)); + Any(sTypeName)); } } else @@ -212,7 +196,7 @@ void SAL_CALL OMySQLTable::alterColumnByName(const OUString& colName, { sTypeName = sTypeName.copy(0, nIndex); descriptor->setPropertyValue(rProp.getNameByIndex(PROPERTY_ID_TYPENAME), - makeAny(sTypeName)); + Any(sTypeName)); } } } @@ -268,20 +252,19 @@ void OMySQLTable::alterColumnType(sal_Int32 nNewType, const OUString& _rColName, OUString sSql = getAlterTableColumnPart() + " CHANGE " + ::dbtools::quoteName(sQuote, _rColName) + " "; - OColumn* pColumn = new OColumn(true); - Reference<XPropertySet> xProp = pColumn; - ::comphelper::copyProperties(_xDescriptor, xProp); - xProp->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE), - makeAny(nNewType)); + rtl::Reference<OColumn> pColumn = new OColumn(true); + ::comphelper::copyProperties(_xDescriptor, pColumn); + pColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE), + Any(nNewType)); sSql += OTables::adjustSQL(::dbtools::createStandardColumnPart( - xProp, getConnection(), static_cast<OTables*>(m_pTables), getTypeCreatePattern())); + pColumn, getConnection(), static_cast<OTables*>(m_pTables), getTypeCreatePattern())); executeStatement(sSql); } OUString OMySQLTable::getTypeCreatePattern() const { return "(M,D)"; } -void OMySQLTable::alterDefaultValue(const OUString& _sNewDefault, const OUString& _rColName) +void OMySQLTable::alterDefaultValue(std::u16string_view _sNewDefault, const OUString& _rColName) { const OUString sQuote = getMetaData()->getIdentifierQuoteString(); OUString sSql = getAlterTableColumnPart() + " ALTER " + ::dbtools::quoteName(sQuote, _rColName) @@ -315,7 +298,7 @@ void OMySQLTable::executeStatement(const OUString& _rStatement) { OUString sSQL = _rStatement; if (sSQL.endsWith(",")) - sSQL = sSQL.replaceAt(sSQL.getLength() - 1, 1, ")"); + sSQL = sSQL.replaceAt(sSQL.getLength() - 1, 1, u")"); Reference<XStatement> xStmt = getConnection()->createStatement(); if (xStmt.is()) diff --git a/connectivity/source/drivers/mysql_jdbc/YTables.cxx b/connectivity/source/drivers/mysql_jdbc/YTables.cxx index e21e05fb2914..aa527cf0cc30 100644 --- a/connectivity/source/drivers/mysql_jdbc/YTables.cxx +++ b/connectivity/source/drivers/mysql_jdbc/YTables.cxx @@ -37,7 +37,6 @@ using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; using namespace dbtools; sdbcx::ObjectType OTables::createObject(const OUString& _rName) @@ -46,10 +45,9 @@ sdbcx::ObjectType OTables::createObject(const OUString& _rName) ::dbtools::qualifiedNameComponents(m_xMetaData, _rName, sCatalog, sSchema, sTable, ::dbtools::EComposeRule::InDataManipulation); - Sequence<OUString> sTableTypes(3); - sTableTypes[0] = "VIEW"; - sTableTypes[1] = "TABLE"; - sTableTypes[2] = "%"; // just to be sure to include anything else... + Sequence<OUString> sTableTypes{ + "VIEW", "TABLE", "%" + }; // this last one just to be sure to include anything else... Any aCatalog; if (!sCatalog.isEmpty()) @@ -67,10 +65,9 @@ sdbcx::ObjectType OTables::createObject(const OUString& _rName) | Privilege::UPDATE | Privilege::INSERT | Privilege::SELECT; - OMySQLTable* pRet = new OMySQLTable( - this, static_cast<OMySQLCatalog&>(m_rParent).getConnection(), sTable, - xRow->getString(4), xRow->getString(5), sSchema, sCatalog, nPrivileges); - xRet = pRet; + xRet = new OMySQLTable(this, static_cast<OMySQLCatalog&>(m_rParent).getConnection(), + sTable, xRow->getString(4), xRow->getString(5), sSchema, + sCatalog, nPrivileges); } ::comphelper::disposeComponent(xResult); } @@ -155,7 +152,7 @@ OUString OTables::adjustSQL(const OUString& _sSql) sal_Int32 nPos = nIndex + strlen(s_sUNSIGNED); OUString sNewUnsigned(sSQL.copy(nPos, nParen - nPos + 1)); sSQL = sSQL.replaceAt(nIndex, strlen(s_sUNSIGNED) + sNewUnsigned.getLength(), - sNewUnsigned + s_sUNSIGNED); + rtl::Concat2View(sNewUnsigned + s_sUNSIGNED)); nIndex = sSQL.indexOf(s_sUNSIGNED, nIndex + strlen(s_sUNSIGNED) + sNewUnsigned.getLength()); } return sSQL; @@ -180,10 +177,10 @@ void OTables::appendNew(const OUString& _rsNewTable) insertElement(_rsNewTable, nullptr); // notify our container listeners - ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(_rsNewTable), Any(), Any()); - OInterfaceIteratorHelper2 aListenerLoop(m_aContainerListeners); + ContainerEvent aEvent(static_cast<XContainer*>(this), Any(_rsNewTable), Any(), Any()); + OInterfaceIteratorHelper3 aListenerLoop(m_aContainerListeners); while (aListenerLoop.hasMoreElements()) - static_cast<XContainerListener*>(aListenerLoop.next())->elementInserted(aEvent); + aListenerLoop.next()->elementInserted(aEvent); } OUString OTables::getNameForObject(const sdbcx::ObjectType& _xObject) diff --git a/connectivity/source/drivers/mysql_jdbc/YUser.cxx b/connectivity/source/drivers/mysql_jdbc/YUser.cxx index b683fe2b2757..ec3a6265967f 100644 --- a/connectivity/source/drivers/mysql_jdbc/YUser.cxx +++ b/connectivity/source/drivers/mysql_jdbc/YUser.cxx @@ -27,6 +27,7 @@ #include <TConnection.hxx> #include <strings.hrc> #include <comphelper/types.hxx> +#include <utility> using namespace connectivity; using namespace connectivity::mysql; @@ -37,17 +38,17 @@ using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; using namespace ::com::sun::star::lang; -OMySQLUser::OMySQLUser(const css::uno::Reference<css::sdbc::XConnection>& _xConnection) +OMySQLUser::OMySQLUser(css::uno::Reference<css::sdbc::XConnection> _xConnection) : connectivity::sdbcx::OUser(true) - , m_xConnection(_xConnection) + , m_xConnection(std::move(_xConnection)) { construct(); } -OMySQLUser::OMySQLUser(const css::uno::Reference<css::sdbc::XConnection>& _xConnection, +OMySQLUser::OMySQLUser(css::uno::Reference<css::sdbc::XConnection> _xConnection, const OUString& Name) : connectivity::sdbcx::OUser(Name, true) - , m_xConnection(_xConnection) + , m_xConnection(std::move(_xConnection)) { construct(); } diff --git a/connectivity/source/drivers/mysql_jdbc/YUsers.cxx b/connectivity/source/drivers/mysql_jdbc/YUsers.cxx index 17fc788179c1..b096310acd4c 100644 --- a/connectivity/source/drivers/mysql_jdbc/YUsers.cxx +++ b/connectivity/source/drivers/mysql_jdbc/YUsers.cxx @@ -23,6 +23,7 @@ #include <comphelper/types.hxx> #include <connectivity/dbtools.hxx> #include <TConnection.hxx> +#include <utility> using namespace ::comphelper; using namespace connectivity; @@ -30,15 +31,13 @@ using namespace connectivity::mysql; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; OUsers::OUsers(::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, const ::std::vector<OUString>& _rVector, - const css::uno::Reference<css::sdbc::XConnection>& _xConnection, + css::uno::Reference<css::sdbc::XConnection> _xConnection, connectivity::sdbcx::IRefreshableUsers* _pParent) : sdbcx::OCollection(_rParent, true, _rMutex, _rVector) - , m_xConnection(_xConnection) + , m_xConnection(std::move(_xConnection)) , m_pParent(_pParent) { } @@ -50,11 +49,7 @@ sdbcx::ObjectType OUsers::createObject(const OUString& _rName) void OUsers::impl_refresh() { m_pParent->refreshUsers(); } -Reference<XPropertySet> OUsers::createDescriptor() -{ - OUserExtend* pNew = new OUserExtend(m_xConnection); - return pNew; -} +Reference<XPropertySet> OUsers::createDescriptor() { return new OUserExtend(m_xConnection); } // XAppend sdbcx::ObjectType OUsers::appendObject(const OUString& _rForName, diff --git a/connectivity/source/drivers/mysql_jdbc/YViews.cxx b/connectivity/source/drivers/mysql_jdbc/YViews.cxx index 4bdeca9596b3..e9531df6950f 100644 --- a/connectivity/source/drivers/mysql_jdbc/YViews.cxx +++ b/connectivity/source/drivers/mysql_jdbc/YViews.cxx @@ -32,10 +32,7 @@ using namespace connectivity; using namespace connectivity::mysql; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; using namespace dbtools; typedef connectivity::sdbcx::OCollection OCollection_TYPE; @@ -59,7 +56,7 @@ void OViews::disposing() Reference<XPropertySet> OViews::createDescriptor() { Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection(); - connectivity::sdbcx::OView* pNew + rtl::Reference<connectivity::sdbcx::OView> pNew = new connectivity::sdbcx::OView(true, xConnection->getMetaData()); return pNew; } diff --git a/connectivity/source/drivers/mysqlc/DataAccess.xcu b/connectivity/source/drivers/mysqlc/DataAccess.xcu deleted file mode 100644 index 2b652ec87649..000000000000 --- a/connectivity/source/drivers/mysqlc/DataAccess.xcu +++ /dev/null @@ -1,35 +0,0 @@ -<!-- - * 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 . - --> -<oor:node xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="DataAccess" oor:package="org.openoffice.Office"> - <node oor:name="UserDefinedDriverSettings"> - <node oor:name="org.openoffice.comp.connectivity.mysql_native.Driver" oor:op="replace"> - <prop oor:name="DriverName"> - <value>org.openoffice.comp.connectivity.mysql_native.Driver</value> - </prop> - <prop oor:name="DriverPageDisplayName"> - <value>MySQL native driver</value> - </prop> - <prop oor:name="DriverTypeDisplayName"> - <value>MySQL native driver</value> - </prop> - <prop oor:name="DriverDsnPrefix"> - <value>sdbc:mysqlc:</value> - </prop> - </node> - </node> -</oor:node> diff --git a/connectivity/source/drivers/mysqlc/mysqlc_catalog.cxx b/connectivity/source/drivers/mysqlc/mysqlc_catalog.cxx new file mode 100644 index 000000000000..d72ab1f65d72 --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_catalog.cxx @@ -0,0 +1,93 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#include "mysqlc_catalog.hxx" +#include "mysqlc_tables.hxx" +#include "mysqlc_views.hxx" +#include "mysqlc_users.hxx" +#include <com/sun/star/sdbc/XRow.hpp> +#include <comphelper/types.hxx> + +connectivity::mysqlc::Catalog::Catalog( + const css::uno::Reference<css::sdbc::XConnection>& rConnection) + : OCatalog(rConnection) + , m_xConnection(rConnection) +{ +} + +//----- OCatalog ------------------------------------------------------------- +void connectivity::mysqlc::Catalog::refreshTables() +{ + css::uno::Reference<css::sdbc::XResultSet> xTables + = m_xMetaData->getTables(css::uno::Any(), "%", "%", {}); + + if (!xTables.is()) + return; + + ::std::vector<OUString> aTableNames; + + fillNames(xTables, aTableNames); + + if (!m_pTables) + m_pTables.reset(new Tables(m_xConnection->getMetaData(), *this, m_aMutex, aTableNames)); + else + m_pTables->reFill(aTableNames); +} + +void connectivity::mysqlc::Catalog::refreshViews() +{ + css::uno::Reference<css::sdbc::XResultSet> xViews + = m_xMetaData->getTables(css::uno::Any(), "%", "%", { "VIEW" }); + + if (!xViews.is()) + return; + + ::std::vector<OUString> aViewNames; + + fillNames(xViews, aViewNames); + + if (!m_pViews) + m_pViews.reset(new Views(m_xConnection, *this, m_aMutex, aViewNames)); + else + m_pViews->reFill(aViewNames); +} + +//----- IRefreshableGroups --------------------------------------------------- +void connectivity::mysqlc::Catalog::refreshGroups() +{ + // TODO: implement me +} + +//----- IRefreshableUsers ---------------------------------------------------- +void connectivity::mysqlc::Catalog::refreshUsers() +{ + css::uno::Reference<css::sdbc::XStatement> statement = m_xConnection->createStatement(); + css::uno::Reference<css::sdbc::XResultSet> xUsers = statement->executeQuery( + "SELECT grantee FROM information_schema.user_privileges GROUP BY grantee"); + + if (!xUsers.is()) + return; + + ::std::vector<OUString> aUserNames; + + css::uno::Reference<css::sdbc::XRow> xRow(xUsers, css::uno::UNO_QUERY); + while (xUsers->next()) + { + aUserNames.push_back(xRow->getString(1)); + } + xRow.clear(); + ::comphelper::disposeComponent(xUsers); + + if (!m_pUsers) + m_pUsers.reset(new Users(m_xConnection->getMetaData(), *this, m_aMutex, aUserNames)); + else + m_pUsers->reFill(aUserNames); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_catalog.hxx b/connectivity/source/drivers/mysqlc/mysqlc_catalog.hxx new file mode 100644 index 000000000000..1bea18c7667b --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_catalog.hxx @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#pragma once + +#include <sdbcx/VCatalog.hxx> + +namespace connectivity::mysqlc +{ +class Catalog : public ::connectivity::sdbcx::OCatalog +{ + css::uno::Reference<css::sdbc::XConnection> m_xConnection; + +public: + explicit Catalog(const css::uno::Reference<css::sdbc::XConnection>& rConnection); + + // OCatalog + virtual void refreshTables() override; + virtual void refreshViews() override; + + // IRefreshableGroups + virtual void refreshGroups() override; + + // IRefreshableUsers + virtual void refreshUsers() override; + + sdbcx::OCollection* getPrivateTables() const { return m_pTables.get(); } +}; + +} // namespace connectivity::mysqlc + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_column.cxx b/connectivity/source/drivers/mysqlc/mysqlc_column.cxx new file mode 100644 index 000000000000..ceb7437386e6 --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_column.cxx @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#include "mysqlc_column.hxx" + +#include <TConnection.hxx> + +connectivity::mysqlc::Column::Column() + : OColumn(true) // case sensitive +{ + construct(); +} + +void connectivity::mysqlc::Column::construct() +{ + m_sAutoIncrement = "auto_increment"; + registerProperty( + OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_AUTOINCREMENTCREATION), + PROPERTY_ID_AUTOINCREMENTCREATION, 0, &m_sAutoIncrement, + cppu::UnoType<decltype(m_sAutoIncrement)>::get()); +} + +::cppu::IPropertyArrayHelper* + connectivity::mysqlc::Column::createArrayHelper(sal_Int32 /*_nId*/) const +{ + return doCreateArrayHelper(); +} + +::cppu::IPropertyArrayHelper& SAL_CALL connectivity::mysqlc::Column::getInfoHelper() +{ + return *Column_PROP::getArrayHelper(isNew() ? 1 : 0); +} + +css::uno::Sequence<OUString> SAL_CALL connectivity::mysqlc::Column::getSupportedServiceNames() +{ + return { "com.sun.star.sdbcx.Column" }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_column.hxx b/connectivity/source/drivers/mysqlc/mysqlc_column.hxx new file mode 100644 index 000000000000..f69ef1afcea7 --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_column.hxx @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ +#pragma once + +#include <connectivity/sdbcx/VColumn.hxx> + +namespace connectivity::mysqlc +{ +class Column; +typedef ::comphelper::OIdPropertyArrayUsageHelper<Column> Column_PROP; +class Column : public sdbcx::OColumn, public Column_PROP +{ + OUString m_sAutoIncrement; + +protected: + virtual ::cppu::IPropertyArrayHelper* createArrayHelper(sal_Int32 _nId) const override; + virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; + +public: + Column(); + virtual void construct() override; + virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_columns.cxx b/connectivity/source/drivers/mysqlc/mysqlc_columns.cxx new file mode 100644 index 000000000000..b34b36b45cbe --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_columns.cxx @@ -0,0 +1,28 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#include "mysqlc_columns.hxx" +#include "mysqlc_column.hxx" + +connectivity::mysqlc::Columns::Columns(Table& rTable, osl::Mutex& rMutex, + const ::std::vector<OUString>& rVector) + : OColumnsHelper(rTable, + true, // case sensitivity + rMutex, rVector, + /*bUseHardRef*/ true) +{ + OColumnsHelper::setParent(&rTable); +} + +css::uno::Reference<css::beans::XPropertySet> connectivity::mysqlc::Columns::createDescriptor() +{ + return new Column; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_columns.hxx b/connectivity/source/drivers/mysqlc/mysqlc_columns.hxx new file mode 100644 index 000000000000..34230db37bb5 --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_columns.hxx @@ -0,0 +1,29 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#pragma once + +#include "mysqlc_table.hxx" + +#include <connectivity/TColumnsHelper.hxx> + +namespace connectivity::mysqlc +{ +class Columns : public ::connectivity::OColumnsHelper +{ +protected: + virtual css::uno::Reference<css::beans::XPropertySet> createDescriptor() override; + +public: + Columns(Table& rTable, ::osl::Mutex& rMutex, const ::std::vector<OUString>& _rVector); +}; + +} // namespace connectivity::mysqlc + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_connection.cxx b/connectivity/source/drivers/mysqlc/mysqlc_connection.cxx index 600e131b89b1..269113383d8d 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_connection.cxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_connection.cxx @@ -17,8 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include "mysqlc_catalog.hxx" #include "mysqlc_connection.hxx" #include "mysqlc_databasemetadata.hxx" +#include <com/sun/star/sdbc/SQLException.hpp> #include "mysqlc_driver.hxx" #include "mysqlc_statement.hxx" @@ -27,20 +29,17 @@ #include <com/sun/star/beans/NamedValue.hpp> -#include <osl/diagnose.h> -#include <cppuhelper/supportsservice.hxx> +#include <comphelper/servicehelper.hxx> using namespace connectivity::mysqlc; using namespace com::sun::star::uno; using namespace com::sun::star::container; -using namespace com::sun::star::lang; using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; +using namespace com::sun::star::sdbcx; using ::osl::MutexGuard; -#define MYSQLC_URI_PREFIX "sdbc:mysqlc:" - namespace { void lcl_executeUpdate(MYSQL* pMySql, const OString& sql) @@ -53,6 +52,7 @@ void lcl_executeUpdate(MYSQL* pMySql, const OString& sql) OConnection::OConnection(MysqlCDriver& _rDriver) : OMetaConnection_BASE(m_aMutex) , m_mysql() + , m_xCatalog(nullptr) , m_xMetaData(nullptr) , m_xDriver(&_rDriver) { @@ -73,10 +73,7 @@ void OConnection::construct(const OUString& url, const Sequence<PropertyValue>& mysql_library_init(0, nullptr, nullptr); mysql_init(&m_mysql); - // use TCP as connection - mysql_protocol_type protocol = MYSQL_PROTOCOL_TCP; - mysql_options(&m_mysql, MYSQL_OPT_PROTOCOL, &protocol); - OString charset_name{ "utf8mb4" }; + OString charset_name{ "utf8mb4"_ostr }; mysql_options(&m_mysql, MYSQL_SET_CHARSET_NAME, charset_name.getStr()); sal_Int32 nIndex; @@ -90,7 +87,7 @@ void OConnection::construct(const OUString& url, const Sequence<PropertyValue>& // parse url. Url has the following format: // external server: sdbc:mysqlc:[hostname]:[port]/[dbname] - if (url.startsWith(MYSQLC_URI_PREFIX)) + if (url.startsWith("sdbc:mysqlc:")) { nIndex = 12; } @@ -164,15 +161,22 @@ void OConnection::construct(const OUString& url, const Sequence<PropertyValue>& OString pass_str = OUStringToOString(aPass, m_settings.encoding); OString schema_str = OUStringToOString(aDbName, m_settings.encoding); OString socket_str; + + // use TCP as connection by default + mysql_protocol_type protocol = MYSQL_PROTOCOL_TCP; if (unixSocketPassed) { socket_str = OUStringToOString(sUnixSocket, m_settings.encoding); + protocol = MYSQL_PROTOCOL_SOCKET; } else if (namedPipePassed) { socket_str = OUStringToOString(sNamedPipe, m_settings.encoding); + protocol = MYSQL_PROTOCOL_PIPE; } + mysql_options(&m_mysql, MYSQL_OPT_PROTOCOL, &protocol); + // flags can also be passed as last parameter if (!mysql_real_connect(&m_mysql, host_str.getStr(), user_str.getStr(), pass_str.getStr(), schema_str.getStr(), nPort, socket_str.getStr(), @@ -188,9 +192,8 @@ void OConnection::construct(const OUString& url, const Sequence<PropertyValue>& *this, OUString(), 0, Any()); } - lcl_executeUpdate(&m_mysql, - OString{ "SET session sql_mode='ANSI_QUOTES,NO_AUTO_VALUE_ON_ZERO'" }); - lcl_executeUpdate(&m_mysql, OString{ "SET NAMES utf8mb4" }); + lcl_executeUpdate(&m_mysql, "SET session sql_mode='ANSI_QUOTES,NO_AUTO_VALUE_ON_ZERO'"_ostr); + lcl_executeUpdate(&m_mysql, "SET NAMES utf8mb4"_ostr); } OUString OConnection::getImplementationName() @@ -253,8 +256,6 @@ Reference<XPreparedStatement> SAL_CALL OConnection::prepareCall(const OUString& OUString SAL_CALL OConnection::nativeSQL(const OUString& /*_sSql*/) { - MutexGuard aGuard(m_aMutex); - // const OUString sSqlStatement = transFormPreparedStatement( _sSql ); // TODO return OUString(); @@ -460,9 +461,8 @@ OUString OConnection::transFormPreparedStatement(const OUString& _sSQL) { try { - Sequence<Any> aArgs(1); Reference<XConnection> xCon = this; - aArgs[0] <<= NamedValue("ActiveConnection", makeAny(xCon)); + Sequence<Any> aArgs{ Any(NamedValue("ActiveConnection", Any(xCon))) }; m_xParameterSubstitution.set( m_xDriver->getFactory()->createInstanceWithArguments( @@ -486,4 +486,36 @@ OUString OConnection::transFormPreparedStatement(const OUString& _sSQL) return sSqlStatement; } +//----- XUnoTunnel ---------------------------------------------------------- +// virtual +sal_Int64 SAL_CALL OConnection::getSomething(const css::uno::Sequence<sal_Int8>& rId) +{ + return comphelper::getSomethingImpl(rId, this); +} + +// static +const Sequence<sal_Int8>& OConnection::getUnoTunnelId() +{ + static const comphelper::UnoIdInit implId; + return implId.getSeq(); +} + +Reference<XTablesSupplier> OConnection::createCatalog() +{ + MutexGuard aGuard(m_aMutex); + + // m_xCatalog is a weak reference. Reuse it if it still exists. + Reference<XTablesSupplier> xCatalog = m_xCatalog; + if (xCatalog.is()) + { + return xCatalog; + } + else + { + xCatalog = new Catalog(this); + m_xCatalog = xCatalog; + return m_xCatalog; + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_connection.hxx b/connectivity/source/drivers/mysqlc/mysqlc_connection.hxx index 283b1d964d4b..3a0ccf36b4ed 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_connection.hxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_connection.hxx @@ -17,28 +17,25 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_MYSQLC_SOURCE_MYSQLC_CONNECTION_HXX -#define INCLUDED_MYSQLC_SOURCE_MYSQLC_CONNECTION_HXX +#pragma once #include <memory> #include "mysqlc_subcomponent.hxx" #include "mysqlc_types.hxx" #include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/lang/DisposedException.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XUnoTunnel.hpp> -#include <com/sun/star/sdbc/ColumnSearch.hpp> #include <com/sun/star/sdbc/ColumnValue.hpp> -#include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/sdbc/SQLWarning.hpp> #include <com/sun/star/sdbc/XConnection.hpp> #include <com/sun/star/sdbc/XWarningsSupplier.hpp> #include <com/sun/star/util/XStringSubstitution.hpp> -#include <cppuhelper/compbase3.hxx> -#include <cppuhelper/weakref.hxx> -#include <rtl/string.hxx> +#include <com/sun/star/sdbcx/XTablesSupplier.hpp> + +#include <cppuhelper/basemutex.hxx> +#include <cppuhelper/compbase.hxx> #include <rtl/ref.hxx> #include <mysql.h> @@ -57,12 +54,8 @@ class ODatabaseMetaData; namespace mysqlc { -using ::com::sun::star::sdbc::SQLException; -using ::com::sun::star::sdbc::SQLWarning; -using ::com::sun::star::uno::RuntimeException; - -typedef ::cppu::WeakComponentImplHelper3<css::sdbc::XConnection, css::sdbc::XWarningsSupplier, - css::lang::XServiceInfo> +typedef ::cppu::WeakComponentImplHelper<css::sdbc::XConnection, css::sdbc::XWarningsSupplier, + css::lang::XUnoTunnel, css::lang::XServiceInfo> OMetaConnection_BASE; struct ConnectionSettings @@ -83,7 +76,7 @@ typedef OMetaConnection_BASE OConnection_BASE; typedef std::vector<css::uno::WeakReferenceHelper> OWeakRefArray; -class OConnection final : public OBase_Mutex, public OConnection_BASE +class OConnection final : public cppu::BaseMutex, public OConnection_BASE { private: MYSQL m_mysql; @@ -93,6 +86,7 @@ private: // Data attributes + css::uno::WeakReference<css::sdbcx::XTablesSupplier> m_xCatalog; css::uno::WeakReference<css::sdbc::XDatabaseMetaData> m_xMetaData; OWeakRefArray m_aStatements; // vector containing a list @@ -115,6 +109,12 @@ public: rtl_TextEncoding getConnectionEncoding() const { return m_settings.encoding; } + /** + * Create and/or connect to the sdbcx Catalog. This is completely + * unrelated to the SQL "Catalog". + */ + css::uno::Reference<css::sdbcx::XTablesSupplier> createCatalog(); + // OComponentHelper virtual void SAL_CALL disposing() override; @@ -125,6 +125,10 @@ public: virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; + // XUnoTunnel + virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence<sal_Int8>& rId) override; + static const css::uno::Sequence<sal_Int8>& getUnoTunnelId(); + // XConnection css::uno::Reference<css::sdbc::XStatement> SAL_CALL createStatement() override; @@ -182,6 +186,5 @@ public: //inline OUString getPattern(OUString p) { return (p.getLength()) ? p : ASC2OU("%"); } } /* mysqlc */ } /* connectivity */ -#endif // INCLUDED_MYSQLC_SOURCE_MYSQLC_CONNECTION_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.cxx b/connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.cxx index a30e5d61808a..6d171b661815 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.cxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.cxx @@ -22,6 +22,7 @@ #include <com/sun/star/sdbc/Deferrability.hpp> #include <com/sun/star/lang/XInitialization.hpp> #include <comphelper/sequence.hxx> +#include <o3tl/string_view.hxx> #include <sal/log.hxx> #include <rtl/ustrbuf.hxx> @@ -32,7 +33,6 @@ using namespace connectivity::mysqlc; using namespace com::sun::star::uno; using namespace com::sun::star::lang; -using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; static std::string wild("%"); @@ -41,8 +41,6 @@ static void lcl_setRows_throw(const Reference<XResultSet>& _xResultSet, sal_Int3 const std::vector<std::vector<Any>>& _rRows) { Reference<XInitialization> xIni(_xResultSet, UNO_QUERY); - Sequence<Any> aArgs(2); - aArgs[0] <<= _nType; Sequence<Sequence<Any>> aRows(_rRows.size()); @@ -55,7 +53,7 @@ static void lcl_setRows_throw(const Reference<XResultSet>& _xResultSet, sal_Int3 } ++pRowsIter; } - aArgs[1] <<= aRows; + Sequence<Any> aArgs{ Any(_nType), Any(aRows) }; xIni->initialize(aArgs); } @@ -162,7 +160,7 @@ sal_Bool SAL_CALL ODatabaseMetaData::supportsNonNullableColumns() { return true; OUString SAL_CALL ODatabaseMetaData::getCatalogTerm() { return "n/a"; } -OUString SAL_CALL ODatabaseMetaData::getIdentifierQuoteString() { return "\""; } +OUString SAL_CALL ODatabaseMetaData::getIdentifierQuoteString() { return "`"; } OUString SAL_CALL ODatabaseMetaData::getExtraNameCharacters() { return "#@"; } @@ -565,9 +563,8 @@ Reference<XResultSet> SAL_CALL ODatabaseMetaData::getTableTypes() { if (m_rConnection.getMysqlVersion() >= requiredVersion[i]) { - std::vector<Any> aRow{ Any() }; - aRow.push_back(makeAny(mysqlc_sdbc_driver::convert(table_types[i], encoding))); - rRows.push_back(aRow); + rRows.push_back( + { { Any(), Any(mysqlc_sdbc_driver::convert(table_types[i], encoding)) } }); } } lcl_setRows_throw(xResultSet, 5, rRows); @@ -586,32 +583,19 @@ Reference<XResultSet> SAL_CALL ODatabaseMetaData::getTypeInfo() unsigned int i = 0; while (mysqlc_types[i].typeName) { - std::vector<Any> aRow{ Any() }; - - aRow.push_back(makeAny(mysqlc_sdbc_driver::convert(mysqlc_types[i].typeName, encoding))); - aRow.push_back(makeAny(mysqlc_types[i].dataType)); - aRow.push_back(makeAny(mysqlc_types[i].precision)); - aRow.push_back( - makeAny(mysqlc_sdbc_driver::convert(mysqlc_types[i].literalPrefix, encoding))); - aRow.push_back( - makeAny(mysqlc_sdbc_driver::convert(mysqlc_types[i].literalSuffix, encoding))); - aRow.push_back( - makeAny(mysqlc_sdbc_driver::convert(mysqlc_types[i].createParams, encoding))); - aRow.push_back(makeAny(mysqlc_types[i].nullable)); - aRow.push_back(makeAny(mysqlc_types[i].caseSensitive)); - aRow.push_back(makeAny(mysqlc_types[i].searchable)); - aRow.push_back(makeAny(mysqlc_types[i].isUnsigned)); - aRow.push_back(makeAny(mysqlc_types[i].fixedPrecScale)); - aRow.push_back(makeAny(mysqlc_types[i].autoIncrement)); - aRow.push_back( - makeAny(mysqlc_sdbc_driver::convert(mysqlc_types[i].localTypeName, encoding))); - aRow.push_back(makeAny(mysqlc_types[i].minScale)); - aRow.push_back(makeAny(mysqlc_types[i].maxScale)); - aRow.push_back(makeAny(sal_Int32(0))); - aRow.push_back(makeAny(sal_Int32(0))); - aRow.push_back(makeAny(sal_Int32(10))); + rRows.push_back( + { { Any(), Any(mysqlc_sdbc_driver::convert(mysqlc_types[i].typeName, encoding)), + Any(mysqlc_types[i].dataType), Any(mysqlc_types[i].precision), + Any(mysqlc_sdbc_driver::convert(mysqlc_types[i].literalPrefix, encoding)), + Any(mysqlc_sdbc_driver::convert(mysqlc_types[i].literalSuffix, encoding)), + Any(mysqlc_sdbc_driver::convert(mysqlc_types[i].createParams, encoding)), + Any(mysqlc_types[i].nullable), Any(mysqlc_types[i].caseSensitive), + Any(mysqlc_types[i].searchable), Any(mysqlc_types[i].isUnsigned), + Any(mysqlc_types[i].fixedPrecScale), Any(mysqlc_types[i].autoIncrement), + Any(mysqlc_sdbc_driver::convert(mysqlc_types[i].localTypeName, encoding)), + Any(mysqlc_types[i].minScale), Any(mysqlc_types[i].maxScale), Any(sal_Int32(0)), + Any(sal_Int32(0)), Any(sal_Int32(10)) } }); - rRows.push_back(aRow); i++; } @@ -634,14 +618,11 @@ Reference<XResultSet> SAL_CALL ODatabaseMetaData::getSchemas() UNO_QUERY); std::vector<std::vector<Any>> rRows; - OUString sSql - = m_rConnection.getMysqlVersion() > 49999 - ? OUString{ "SELECT SCHEMA_NAME AS TABLE_SCHEM, CATALOG_NAME AS TABLE_CATALOG " - "FROM INFORMATION_SCHEMA.SCHEMATA ORDER BY SCHEMA_NAME" } - : OUString{ "SHOW DATABASES" }; - Reference<XStatement> statement = m_rConnection.createStatement(); - Reference<XInterface> executed = statement->executeQuery(sSql); + Reference<XInterface> executed = statement->executeQuery( + u"SELECT SCHEMA_NAME AS TABLE_SCHEM, CATALOG_NAME AS TABLE_CATALOG FROM INFORMATION_SCHEMA.SCHEMATA \ + WHERE SCHEMA_NAME NOT IN ('information_schema', 'mysql', 'performance_schema') \ + ORDER BY SCHEMA_NAME"_ustr); Reference<XResultSet> rs(executed, UNO_QUERY_THROW); Reference<XResultSetMetaDataSupplier> supp(executed, UNO_QUERY_THROW); Reference<XResultSetMetaData> rs_meta = supp->getMetaData(); @@ -651,20 +632,12 @@ Reference<XResultSet> SAL_CALL ODatabaseMetaData::getSchemas() while (rs->next()) { std::vector<Any> aRow{ Any() }; - bool informationSchema = false; for (sal_uInt32 i = 1; i <= columns; i++) { OUString columnStringValue = xRow->getString(i); - if (i == 1) - { // TABLE_SCHEM - informationSchema = columnStringValue.equalsIgnoreAsciiCase("information_schema"); - } - aRow.push_back(makeAny(columnStringValue)); - } - if (!informationSchema) - { - rRows.push_back(aRow); + aRow.push_back(Any(columnStringValue)); } + rRows.push_back(aRow); } lcl_setRows_throw(xResultSet, 1, rRows); @@ -747,7 +720,7 @@ Reference<XResultSet> SAL_CALL ODatabaseMetaData::getColumns(const Any& /*catalo OUString query = queryBuf.makeStringAndClear(); Reference<XStatement> statement = m_rConnection.createStatement(); - Reference<XResultSet> rs = statement->executeQuery(query.getStr()); + Reference<XResultSet> rs = statement->executeQuery(query); Reference<XRow> xRow(rs, UNO_QUERY_THROW); Reference<XResultSet> xResultSet(getOwnConnection().getDriver().getFactory()->createInstance( @@ -759,25 +732,25 @@ Reference<XResultSet> SAL_CALL ODatabaseMetaData::getColumns(const Any& /*catalo std::vector<Any> aRow{ Any() }; // 0. element is unused // catalog name - aRow.push_back(makeAny(xRow->getString(1))); + aRow.emplace_back(xRow->getString(1)); // schema name - aRow.push_back(makeAny(xRow->getString(2))); + aRow.emplace_back(xRow->getString(2)); // table name - aRow.push_back(makeAny(xRow->getString(3))); + aRow.emplace_back(xRow->getString(3)); // column name - aRow.push_back(makeAny(xRow->getString(4))); + aRow.emplace_back(xRow->getString(4)); // data type OUString sDataType = xRow->getString(5); - aRow.push_back(makeAny(mysqlc_sdbc_driver::mysqlStrToOOOType(sDataType))); + aRow.emplace_back(mysqlc_sdbc_driver::mysqlStrToOOOType(sDataType)); // type name - aRow.push_back(makeAny(sDataType)); // TODO + aRow.emplace_back(sDataType); // TODO // column size sal_Int32 nColumnSize = 0; OUString sColumnType = xRow->getString(14); sal_Int32 nCharMaxLen = xRow->getShort(6); bool bIsCharMax = !xRow->wasNull(); if (sDataType.equalsIgnoreAsciiCase("year")) - nColumnSize = sColumnType.copy(6, 1).toInt32(); // 'year(' length is 5 + nColumnSize = o3tl::toInt32(sColumnType.subView(6, 1)); // 'year(' length is 5 else if (sDataType.equalsIgnoreAsciiCase("date")) nColumnSize = 10; else if (sDataType.equalsIgnoreAsciiCase("time")) @@ -789,34 +762,34 @@ Reference<XResultSet> SAL_CALL ODatabaseMetaData::getColumns(const Any& /*catalo nColumnSize = xRow->getShort(7); // numeric precision else nColumnSize = nCharMaxLen; - aRow.push_back(makeAny(nColumnSize)); - aRow.push_back(Any()); // buffer length - unused + aRow.emplace_back(nColumnSize); + aRow.emplace_back(); // buffer length - unused // decimal digits (scale) - aRow.push_back(makeAny(xRow->getShort(8))); + aRow.emplace_back(xRow->getShort(8)); // num_prec_radix - aRow.push_back(makeAny(sal_Int32(10))); + aRow.emplace_back(sal_Int32(10)); // nullable OUString sIsNullable = xRow->getString(13); if (xRow->wasNull()) - aRow.push_back(makeAny(ColumnValue::NULLABLE_UNKNOWN)); + aRow.emplace_back(ColumnValue::NULLABLE_UNKNOWN); else if (sIsNullable.equalsIgnoreAsciiCase("YES")) - aRow.push_back(makeAny(ColumnValue::NULLABLE)); + aRow.emplace_back(ColumnValue::NULLABLE); else - aRow.push_back(makeAny(ColumnValue::NO_NULLS)); + aRow.emplace_back(ColumnValue::NO_NULLS); // remarks - aRow.push_back(makeAny(xRow->getString(9))); + aRow.emplace_back(xRow->getString(9)); // default - aRow.push_back(makeAny(xRow->getString(10))); + aRow.emplace_back(xRow->getString(10)); - aRow.push_back(Any{}); // sql_data_type - unused - aRow.push_back(Any{}); // sql_datetime_sub - unused + aRow.emplace_back(); // sql_data_type - unused + aRow.emplace_back(); // sql_datetime_sub - unused // character octet length - aRow.push_back(makeAny(xRow->getString(11))); + aRow.emplace_back(xRow->getString(11)); // ordinal position - aRow.push_back(makeAny(xRow->getString(12))); + aRow.emplace_back(xRow->getString(12)); // is nullable - aRow.push_back(makeAny(sIsNullable)); + aRow.emplace_back(sIsNullable); aRows.push_back(aRow); } lcl_setRows_throw(xResultSet, 1, aRows); @@ -832,25 +805,20 @@ Reference<XResultSet> SAL_CALL ODatabaseMetaData::getTables(const Any& /*catalog "SELECT TABLE_CATALOG AS TABLE_CAT, TABLE_SCHEMA AS TABLE_SCHEM, TABLE_NAME," "IF(STRCMP(TABLE_TYPE,'BASE TABLE'), TABLE_TYPE, 'TABLE') AS TABLE_TYPE, TABLE_COMMENT AS " "REMARKS " - "FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA LIKE '?' AND TABLE_NAME LIKE '?' " + "FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema', 'mysql', " + "'performance_schema') AND TABLE_SCHEMA LIKE '?' AND TABLE_NAME LIKE '?' " }; if (types.getLength() == 1) { - buffer.append("AND TABLE_TYPE LIKE '"); - buffer.append(types[0]); - buffer.append("'"); + buffer.append("AND TABLE_TYPE LIKE '" + types[0] + "'"); } else if (types.getLength() > 1) { - buffer.append("AND (TABLE_TYPE LIKE '"); - buffer.append(types[0]); - buffer.append("'"); + buffer.append("AND (TABLE_TYPE LIKE '" + types[0] + "'"); for (sal_Int32 i = 1; i < types.getLength(); ++i) { - buffer.append(" OR TABLE_TYPE LIKE '"); - buffer.append(types[i]); - buffer.append("'"); + buffer.append(" OR TABLE_TYPE LIKE '" + types[i] + "'"); } buffer.append(")"); } @@ -946,7 +914,7 @@ Reference<XResultSet> SAL_CALL ODatabaseMetaData::getImportedKeys(const Any& /*c std::vector<std::vector<Any>> aRows; Reference<XStatement> statement = m_rConnection.createStatement(); - Reference<XResultSet> rs = statement->executeQuery(query.getStr()); + Reference<XResultSet> rs = statement->executeQuery(query); Reference<XRow> xRow(rs, UNO_QUERY_THROW); while (rs->next()) @@ -954,34 +922,34 @@ Reference<XResultSet> SAL_CALL ODatabaseMetaData::getImportedKeys(const Any& /*c std::vector<Any> aRow{ Any() }; // 0. element is unused // primary key catalog - aRow.push_back(makeAny(xRow->getString(3))); + aRow.push_back(Any(xRow->getString(3))); // primary key schema - aRow.push_back(makeAny(xRow->getString(4))); + aRow.push_back(Any(xRow->getString(4))); // primary key table - aRow.push_back(makeAny(xRow->getString(5))); + aRow.push_back(Any(xRow->getString(5))); // primary column name - aRow.push_back(makeAny(xRow->getString(6))); + aRow.push_back(Any(xRow->getString(6))); // fk table catalog - aRow.push_back(makeAny(xRow->getString(1))); + aRow.push_back(Any(xRow->getString(1))); // fk schema - aRow.push_back(makeAny(xRow->getString(11))); + aRow.push_back(Any(xRow->getString(11))); // fk table - aRow.push_back(makeAny(xRow->getString(10))); + aRow.push_back(Any(xRow->getString(10))); // fk column name - aRow.push_back(makeAny(xRow->getString(2))); + aRow.push_back(Any(xRow->getString(2))); // KEY_SEQ - aRow.push_back(makeAny(sal_Int32{ 0 })); // TODO + aRow.push_back(Any(sal_Int32{ 0 })); // TODO // update rule - aRow.push_back(makeAny(xRow->getShort(7))); + aRow.push_back(Any(xRow->getShort(7))); // delete rule - aRow.push_back(makeAny(xRow->getShort(8))); + aRow.push_back(Any(xRow->getShort(8))); // foreign key name - aRow.push_back(makeAny(xRow->getString(9))); + aRow.push_back(Any(xRow->getString(9))); // primary key name - aRow.push_back(makeAny(OUString{})); // TODO + aRow.push_back(Any(OUString{})); // TODO // deferrability - aRow.push_back(makeAny(Deferrability::NONE)); + aRow.push_back(Any(Deferrability::NONE)); aRows.push_back(aRow); } lcl_setRows_throw(xResultSet, 1, aRows); @@ -1042,11 +1010,23 @@ Reference<XResultSet> SAL_CALL ODatabaseMetaData::getBestRowIdentifier(const Any } Reference<XResultSet> SAL_CALL ODatabaseMetaData::getTablePrivileges( - const Any& /*catalog*/, const OUString& /*schemaPattern*/, const OUString& /*tableNamePattern*/) + const Any& /* catalog */, const OUString& schemaPattern, const OUString& tableNamePattern) { - // TODO - SAL_WARN("connectivity.mysqlc", "method not implemented"); - throw SQLException("getTablePrivileges method not implemented", *this, "IM001", 0, Any()); + OUString query("SELECT TABLE_SCHEMA TABLE_CAT, " + "NULL TABLE_SCHEM, " + "TABLE_NAME, " + "NULL GRANTOR," + "GRANTEE, " + "PRIVILEGE_TYPE PRIVILEGE, " + "IS_GRANTABLE " + "FROM INFORMATION_SCHEMA.TABLE_PRIVILEGES " + "WHERE TABLE_SCHEMA LIKE '?' " + "AND TABLE_NAME='?'"); + query = query.replaceFirst("?", schemaPattern); + query = query.replaceFirst("?", tableNamePattern); + Reference<XStatement> statement = m_rConnection.createStatement(); + Reference<XResultSet> rs = statement->executeQuery(query); + return rs; } Reference<XResultSet> SAL_CALL ODatabaseMetaData::getCrossReference( diff --git a/connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.hxx b/connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.hxx index 6814a574c87d..caed92f20e80 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.hxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_databasemetadata.hxx @@ -17,17 +17,14 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_MYSQLC_SOURCE_MYSQLC_DATABASEMETADATA_HXX -#define INCLUDED_MYSQLC_SOURCE_MYSQLC_DATABASEMETADATA_HXX +#pragma once #include "mysqlc_connection.hxx" #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> #include <cppuhelper/implbase1.hxx> -namespace connectivity -{ -namespace mysqlc +namespace connectivity::mysqlc { using ::com::sun::star::uno::Any; @@ -180,7 +177,7 @@ public: css::uno::Reference<css::sdbc::XResultSet> SAL_CALL getSchemas() override; css::uno::Reference<css::sdbc::XResultSet> SAL_CALL getCatalogs() override; css::uno::Reference<css::sdbc::XResultSet> SAL_CALL getTableTypes() override; - css::uno::Reference<css::sdbc::XResultSet> + virtual css::uno::Reference<css::sdbc::XResultSet> SAL_CALL getColumns(const Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const OUString& columnNamePattern) override; @@ -232,8 +229,5 @@ public: css::uno::Reference<css::sdbc::XConnection> SAL_CALL getConnection() override; }; } -} - -#endif // INCLUDED_MYSQLC_SOURCE_MYSQLC_DATABASEMETADATA_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_driver.cxx b/connectivity/source/drivers/mysqlc/mysqlc_driver.cxx index c7c88d03ebe6..79a514a57898 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_driver.cxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_driver.cxx @@ -18,15 +18,16 @@ */ #include "mysqlc_driver.hxx" #include "mysqlc_connection.hxx" +#include <cppuhelper/supportsservice.hxx> +#include <comphelper/servicehelper.hxx> using namespace css::uno; using namespace css::lang; using namespace css::beans; using namespace css::sdbc; +using namespace css::sdbcx; using namespace connectivity::mysqlc; -#include <cppuhelper/supportsservice.hxx> - MysqlCDriver::MysqlCDriver(const Reference<XMultiServiceFactory>& _rxFactory) : ODriver_BASE(m_aMutex) , m_xFactory(_rxFactory) @@ -59,7 +60,7 @@ OUString MysqlCDriver::getImplementationName_Static() Sequence<OUString> MysqlCDriver::getSupportedServiceNames_Static() { - return { "com.sun.star.sdbc.Driver" }; + return { "com.sun.star.sdbc.Driver", "com.sun.star.sdbcx.Driver" }; } OUString SAL_CALL MysqlCDriver::getImplementationName() { return getImplementationName_Static(); } @@ -84,14 +85,12 @@ Reference<XConnection> SAL_CALL MysqlCDriver::connect(const OUString& url, return nullptr; } - Reference<XConnection> xConn; // create a new connection with the given properties and append it to our vector - OConnection* pCon = new OConnection(*this); - xConn = pCon; + rtl::Reference<OConnection> pCon = new OConnection(*this); pCon->construct(url, info); m_xConnections.push_back(WeakReferenceHelper(*pCon)); - return xConn; + return pCon; } sal_Bool SAL_CALL MysqlCDriver::acceptsURL(const OUString& url) @@ -104,13 +103,8 @@ MysqlCDriver::getPropertyInfo(const OUString& url, const Sequence<PropertyValue> { if (acceptsURL(url)) { - ::std::vector<DriverPropertyInfo> aDriverInfo; - - aDriverInfo.push_back(DriverPropertyInfo("Hostname", "Name of host", true, "localhost", - Sequence<OUString>())); - aDriverInfo.push_back( - DriverPropertyInfo("Port", "Port", true, "3306", Sequence<OUString>())); - return Sequence<DriverPropertyInfo>(aDriverInfo.data(), aDriverInfo.size()); + return { { "Hostname", "Name of host", true, "localhost", {} }, + { "Port", "Port", true, "3306", {} } }; } return Sequence<DriverPropertyInfo>(); @@ -120,6 +114,21 @@ sal_Int32 SAL_CALL MysqlCDriver::getMajorVersion() { return MARIADBC_VERSION_MAJ sal_Int32 SAL_CALL MysqlCDriver::getMinorVersion() { return MARIADBC_VERSION_MINOR; } +Reference<XTablesSupplier> + SAL_CALL MysqlCDriver::getDataDefinitionByConnection(const Reference<XConnection>& rConnection) +{ + if (OConnection* pConnection = comphelper::getFromUnoTunnel<OConnection>(rConnection)) + return pConnection->createCatalog(); + return {}; +} + +Reference<XTablesSupplier> SAL_CALL +MysqlCDriver::getDataDefinitionByURL(const OUString& rURL, const Sequence<PropertyValue>& rInfo) +{ + Reference<XConnection> xConnection = connect(rURL, rInfo); + return getDataDefinitionByConnection(xConnection); +} + namespace connectivity::mysqlc { Reference<XInterface> MysqlCDriver_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) diff --git a/connectivity/source/drivers/mysqlc/mysqlc_driver.hxx b/connectivity/source/drivers/mysqlc/mysqlc_driver.hxx index b55d9cfeeeaf..a29040892577 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_driver.hxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_driver.hxx @@ -16,32 +16,26 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_MYSQLC_SOURCE_MYSQLC_DRIVER_HXX -#define INCLUDED_MYSQLC_SOURCE_MYSQLC_DRIVER_HXX +#pragma once #include "mysqlc_connection.hxx" #include <com/sun/star/sdbc/XDriver.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp> +#include <cppuhelper/compbase.hxx> -#include <cppuhelper/compbase2.hxx> -#include <osl/module.h> - -namespace connectivity -{ -namespace mysqlc +namespace connectivity::mysqlc { -using css::sdbc::SQLException; -using css::uno::Exception; using css::uno::Reference; -using css::uno::RuntimeException; using css::uno::Sequence; Reference<css::uno::XInterface> MysqlCDriver_CreateInstance(const Reference<css::lang::XMultiServiceFactory>& _rxFactory); -typedef ::cppu::WeakComponentImplHelper2<css::sdbc::XDriver, css::lang::XServiceInfo> ODriver_BASE; +typedef ::cppu::WeakComponentImplHelper<css::sdbc::XDriver, css::sdbcx::XDataDefinitionSupplier, + css::lang::XServiceInfo> + ODriver_BASE; typedef void* (*OMysqlCConnection_CreateInstanceFunction)(void* _pDriver); @@ -53,10 +47,6 @@ protected: OWeakRefArray m_xConnections; // vector containing a list // of all the Connection objects // for this Driver -#ifdef BUNDLE_MARIADB - oslModule m_hCConnModule; - bool m_bAttemptedLoadCConn; -#endif public: explicit MysqlCDriver(const Reference<css::lang::XMultiServiceFactory>& _rxFactory); @@ -85,10 +75,14 @@ public: const Reference<css::lang::XMultiServiceFactory>& getFactory() const { return m_xFactory; } static rtl_TextEncoding getDefaultEncoding() { return RTL_TEXTENCODING_UTF8; } + + // XDataDefinitionSupplier + virtual css::uno::Reference<css::sdbcx::XTablesSupplier> SAL_CALL getDataDefinitionByConnection( + const css::uno::Reference<css::sdbc::XConnection>& rxConnection) override; + virtual css::uno::Reference<css::sdbcx::XTablesSupplier> SAL_CALL getDataDefinitionByURL( + const OUString& rsURL, const css::uno::Sequence<css::beans::PropertyValue>& rInfo) override; }; -} /* mysqlc */ -} /* connectivity */ -#endif // INCLUDED_MYSQLC_SOURCE_MYSQLC_DRIVER_HXX +} /* connectivity::mysqlc */ /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_general.cxx b/connectivity/source/drivers/mysqlc/mysqlc_general.cxx index 7ed11fe3ff13..bc57770413f5 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_general.cxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_general.cxx @@ -20,6 +20,7 @@ #include <sal/log.hxx> #include <rtl/ustring.hxx> +#include <o3tl/string_view.hxx> #include <com/sun/star/sdbc/DataType.hpp> @@ -43,6 +44,7 @@ void allocateSqlVar(void** mem, enum_field_types eType, unsigned nSize) *mem = malloc(sizeof(sal_Int32)); break; case MYSQL_TYPE_SHORT: + case MYSQL_TYPE_YEAR: *mem = malloc(sizeof(sal_Int16)); break; case MYSQL_TYPE_BIT: @@ -62,7 +64,6 @@ void allocateSqlVar(void** mem, enum_field_types eType, unsigned nSize) case MYSQL_TYPE_TIME: case MYSQL_TYPE_DATETIME: case MYSQL_TYPE_TIMESTAMP: - case MYSQL_TYPE_YEAR: // FIXME below case MYSQL_TYPE_NEWDATE: case MYSQL_TYPE_ENUM: case MYSQL_TYPE_SET: @@ -125,12 +126,13 @@ sal_Int32 mysqlToOOOType(int eType, int charsetnr) noexcept switch (eType) { case MYSQL_TYPE_BIT: - return css::sdbc::DataType::VARCHAR; + return css::sdbc::DataType::BIT; case MYSQL_TYPE_TINY: return css::sdbc::DataType::TINYINT; case MYSQL_TYPE_SHORT: + case MYSQL_TYPE_YEAR: return css::sdbc::DataType::SMALLINT; case MYSQL_TYPE_INT24: @@ -163,6 +165,9 @@ sal_Int32 mysqlToOOOType(int eType, int charsetnr) noexcept return css::sdbc::DataType::VARCHAR; case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_TINY_BLOB: + case MYSQL_TYPE_MEDIUM_BLOB: + case MYSQL_TYPE_LONG_BLOB: if (charsetnr == 63) return css::sdbc::DataType::LONGVARBINARY; return css::sdbc::DataType::LONGVARCHAR; @@ -188,46 +193,58 @@ sal_Int32 mysqlToOOOType(int eType, int charsetnr) noexcept return css::sdbc::DataType::VARCHAR; } -sal_Int32 mysqlStrToOOOType(const OUString& sType) +sal_Int32 mysqlStrToOOOType(std::u16string_view sType) { // TODO other types. - if (sType.equalsIgnoreAsciiCase("tiny") || sType.equalsIgnoreAsciiCase("tinyint")) + if (o3tl::equalsIgnoreAsciiCase(sType, u"tiny") + || o3tl::equalsIgnoreAsciiCase(sType, u"tinyint")) return css::sdbc::DataType::TINYINT; - if (sType.equalsIgnoreAsciiCase("smallint") || sType.equalsIgnoreAsciiCase("mediumint")) + if (o3tl::equalsIgnoreAsciiCase(sType, u"smallint") + || o3tl::equalsIgnoreAsciiCase(sType, u"year")) return css::sdbc::DataType::SMALLINT; - if (sType.equalsIgnoreAsciiCase("longtext")) - return css::sdbc::DataType::LONGVARCHAR; - if (sType.equalsIgnoreAsciiCase("int")) + if (o3tl::equalsIgnoreAsciiCase(sType, u"int") + || o3tl::equalsIgnoreAsciiCase(sType, u"mediumint")) return css::sdbc::DataType::INTEGER; - if (sType.equalsIgnoreAsciiCase("varchar") || sType.equalsIgnoreAsciiCase("set") - || sType.equalsIgnoreAsciiCase("enum")) + if (o3tl::equalsIgnoreAsciiCase(sType, u"varchar") || o3tl::equalsIgnoreAsciiCase(sType, u"set") + || o3tl::equalsIgnoreAsciiCase(sType, u"enum")) return css::sdbc::DataType::VARCHAR; - if (sType.equalsIgnoreAsciiCase("bigint")) + if (o3tl::equalsIgnoreAsciiCase(sType, u"bigint")) return css::sdbc::DataType::BIGINT; - if (sType.equalsIgnoreAsciiCase("blob") || sType.equalsIgnoreAsciiCase("longblob")) + if (o3tl::equalsIgnoreAsciiCase(sType, u"blob") + || o3tl::equalsIgnoreAsciiCase(sType, u"longblob") + || o3tl::equalsIgnoreAsciiCase(sType, u"tinyblob") + || o3tl::equalsIgnoreAsciiCase(sType, u"mediumblob")) return css::sdbc::DataType::BLOB; - if (sType.equalsIgnoreAsciiCase("varbinary")) + if (o3tl::equalsIgnoreAsciiCase(sType, u"varbinary")) return css::sdbc::DataType::VARBINARY; - if (sType.equalsIgnoreAsciiCase("char")) + if (o3tl::equalsIgnoreAsciiCase(sType, u"char")) return css::sdbc::DataType::CHAR; - if (sType.equalsIgnoreAsciiCase("text")) + if (o3tl::equalsIgnoreAsciiCase(sType, u"tinytext")) + return css::sdbc::DataType::VARCHAR; + if (o3tl::equalsIgnoreAsciiCase(sType, u"text")) + return css::sdbc::DataType::LONGVARCHAR; + if (o3tl::equalsIgnoreAsciiCase(sType, u"mediumtext") + || o3tl::equalsIgnoreAsciiCase(sType, u"longtext")) return css::sdbc::DataType::CLOB; - if (sType.equalsIgnoreAsciiCase("binary")) + if (o3tl::equalsIgnoreAsciiCase(sType, u"binary")) return css::sdbc::DataType::BINARY; - if (sType.equalsIgnoreAsciiCase("time")) + if (o3tl::equalsIgnoreAsciiCase(sType, u"time")) return css::sdbc::DataType::TIME; - if (sType.equalsIgnoreAsciiCase("date")) + if (o3tl::equalsIgnoreAsciiCase(sType, u"date")) return css::sdbc::DataType::DATE; - if (sType.equalsIgnoreAsciiCase("datetime") || sType.equalsIgnoreAsciiCase("timestamp")) + if (o3tl::equalsIgnoreAsciiCase(sType, u"datetime") + || o3tl::equalsIgnoreAsciiCase(sType, u"timestamp")) return css::sdbc::DataType::TIMESTAMP; - if (sType.equalsIgnoreAsciiCase("decimal")) + if (o3tl::equalsIgnoreAsciiCase(sType, u"decimal")) return css::sdbc::DataType::DECIMAL; - if (sType.equalsIgnoreAsciiCase("real") || sType.equalsIgnoreAsciiCase("float")) + if (o3tl::equalsIgnoreAsciiCase(sType, u"real") || o3tl::equalsIgnoreAsciiCase(sType, u"float")) return css::sdbc::DataType::REAL; - if (sType.equalsIgnoreAsciiCase("double")) + if (o3tl::equalsIgnoreAsciiCase(sType, u"double")) return css::sdbc::DataType::DOUBLE; - if (sType.equalsIgnoreAsciiCase("bit") || sType.equalsIgnoreAsciiCase("bool") - || sType.equalsIgnoreAsciiCase("boolean")) + if (o3tl::equalsIgnoreAsciiCase(sType, u"bit")) + return css::sdbc::DataType::BIT; + if (o3tl::equalsIgnoreAsciiCase(sType, u"bool") + || o3tl::equalsIgnoreAsciiCase(sType, u"boolean")) return css::sdbc::DataType::BOOLEAN; OSL_FAIL("Unknown type name from string, failing back to varchar."); return css::sdbc::DataType::VARCHAR; diff --git a/connectivity/source/drivers/mysqlc/mysqlc_general.hxx b/connectivity/source/drivers/mysqlc/mysqlc_general.hxx index c00a11f412c5..16236e1530ed 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_general.hxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_general.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_MYSQLC_SOURCE_MYSQLC_GENERAL_HXX -#define INCLUDED_MYSQLC_SOURCE_MYSQLC_GENERAL_HXX +#pragma once #include <config_lgpl.h> @@ -109,11 +108,9 @@ sal_Int32 mysqlToOOOType(int eType, int charsetnr) noexcept; OUString mysqlTypeToStr(unsigned mysql_type, unsigned mysql_flags); -sal_Int32 mysqlStrToOOOType(const OUString& sType); +sal_Int32 mysqlStrToOOOType(std::u16string_view sType); OUString convert(const ::std::string& _string, const rtl_TextEncoding encoding); } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_indexes.cxx b/connectivity/source/drivers/mysqlc/mysqlc_indexes.cxx new file mode 100644 index 000000000000..c496f9c21cde --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_indexes.cxx @@ -0,0 +1,25 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#include "mysqlc_indexes.hxx" + +connectivity::mysqlc::Indexes::Indexes(Table* pTable, osl::Mutex& rMutex, + const std::vector<OUString>& rVector) + : OIndexesHelper(pTable, rMutex, rVector) +{ +} + +// XDrop +void connectivity::mysqlc::Indexes::dropObject(sal_Int32 /*nPosition*/, + const OUString& /* sIndexName */) +{ + // TODO: implement +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_indexes.hxx b/connectivity/source/drivers/mysqlc/mysqlc_indexes.hxx new file mode 100644 index 000000000000..4c918d1846fd --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_indexes.hxx @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#pragma once + +#include "mysqlc_table.hxx" + +#include <connectivity/TIndexes.hxx> + +namespace connectivity::mysqlc +{ +class Indexes : public ::connectivity::OIndexesHelper +{ +private: + // TODO: useful? + // Table* m_pTable; + +protected: + // XDrop + void dropObject(sal_Int32 nPosition, const OUString& sIndexName); + +public: + Indexes(Table* pTable, ::osl::Mutex& rMutex, const std::vector<OUString>& rVector); +}; + +} // namespace connectivity::mysqlc + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_keys.cxx b/connectivity/source/drivers/mysqlc/mysqlc_keys.cxx new file mode 100644 index 000000000000..7706844f238c --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_keys.cxx @@ -0,0 +1,19 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#include "mysqlc_keys.hxx" +#include "mysqlc_table.hxx" + +connectivity::mysqlc::Keys::Keys(Table* pTable, osl::Mutex& rMutex, + const ::std::vector<OUString>& rNames) + : OKeysHelper(pTable, rMutex, rNames) +{ +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_keys.hxx b/connectivity/source/drivers/mysqlc/mysqlc_keys.hxx new file mode 100644 index 000000000000..9d0a9ef1cc43 --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_keys.hxx @@ -0,0 +1,25 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#pragma once + +#include <connectivity/TKeys.hxx> + +namespace connectivity::mysqlc +{ +class Table; + +class Keys : public ::connectivity::OKeysHelper +{ +public: + Keys(Table* pTable, ::osl::Mutex& rMutex, const ::std::vector<OUString>& rNames); +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.cxx b/connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.cxx index 8031bfdf24b0..e11476dc9805 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.cxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.cxx @@ -31,10 +31,10 @@ #include <cppuhelper/typeprovider.hxx> #include <sal/log.hxx> -using namespace rtl; - #include <cstdlib> +#include <typeindex> +using namespace rtl; using namespace connectivity::mysqlc; using namespace connectivity; using namespace cppu; @@ -46,20 +46,20 @@ using namespace com::sun::star::sdbcx; using namespace com::sun::star::container; using namespace com::sun::star::io; using namespace com::sun::star::util; -using namespace ::comphelper; using ::osl::MutexGuard; -#include <typeindex> - namespace { std::type_index getTypeFromMysqlType(enum_field_types type) { switch (type) { + case MYSQL_TYPE_BIT: + return std::type_index(typeid(bool)); case MYSQL_TYPE_TINY: return std::type_index(typeid(sal_Int8)); case MYSQL_TYPE_SHORT: + case MYSQL_TYPE_YEAR: return std::type_index(typeid(sal_Int16)); case MYSQL_TYPE_LONG: case MYSQL_TYPE_INT24: @@ -83,8 +83,6 @@ std::type_index getTypeFromMysqlType(enum_field_types type) case MYSQL_TYPE_NEWDECIMAL: return std::type_index(typeid(OUString)); case MYSQL_TYPE_BLOB: - case MYSQL_TYPE_YEAR: - case MYSQL_TYPE_BIT: case MYSQL_TYPE_SET: case MYSQL_TYPE_ENUM: case MYSQL_TYPE_GEOMETRY: @@ -106,12 +104,24 @@ bool OPreparedResultSet::fetchResult() } for (sal_Int32 i = 0; i < m_nColumnCount; ++i) { + bool bIsBlobType = false; + switch (m_aFields[i].type) + { + case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_TINY_BLOB: + case MYSQL_TYPE_MEDIUM_BLOB: + case MYSQL_TYPE_LONG_BLOB: + bIsBlobType = true; + break; + default: + bIsBlobType = false; + } m_aMetaData[i].is_null = false; m_aMetaData[i].length = 0l; m_aMetaData[i].error = false; m_aData[i].is_null = &m_aMetaData[i].is_null; - m_aData[i].buffer_length = m_aFields[i].type == MYSQL_TYPE_BLOB ? 0 : m_aFields[i].length; + m_aData[i].buffer_length = bIsBlobType ? 0 : m_aFields[i].length; m_aData[i].length = &m_aMetaData[i].length; m_aData[i].error = &m_aMetaData[i].error; m_aData[i].buffer = nullptr; @@ -170,7 +180,7 @@ OPreparedResultSet::OPreparedResultSet(OConnection& rConn, OPreparedStatement* p : OPreparedResultSet_BASE(m_aMutex) , OPropertySetHelper(OPreparedResultSet_BASE::rBHelper) , m_rConnection(rConn) - , m_aStatement(static_cast<OWeakObject*>(pStmt)) + , m_aStatement(css::uno::Reference(cppu::getXWeak(pStmt))) , m_pStmt(pMyStmt) , m_encoding(rConn.getConnectionEncoding()) , m_nColumnCount(mysql_stmt_field_count(pMyStmt)) @@ -188,7 +198,7 @@ void OPreparedResultSet::disposing() MutexGuard aGuard(m_aMutex); - m_aStatement = nullptr; + m_aStatement.clear(); m_xMetaData = nullptr; } @@ -247,7 +257,25 @@ template <typename T> T OPreparedResultSet::retrieveValue(sal_Int32 nColumnIndex if (getTypeFromMysqlType(m_aFields[nColumnIndex - 1].type) == std::type_index(typeid(T))) return *static_cast<T*>(m_aData[nColumnIndex - 1].buffer); else - return getRowSetValue(nColumnIndex); + { + auto const& row = getRowSetValue(nColumnIndex); + if constexpr (std::is_same_v<sal_Int64, T>) + return row.getLong(); + else if constexpr (std::is_same_v<sal_Int32, T>) + return row.getInt32(); + else if constexpr (std::is_same_v<sal_Int16, T>) + return row.getInt16(); + else if constexpr (std::is_same_v<sal_Int8, T>) + return row.getInt8(); + else if constexpr (std::is_same_v<double, T>) + return row.getDouble(); + else if constexpr (std::is_same_v<float, T>) + return row.getFloat(); + else if constexpr (std::is_same_v<bool, T>) + return row.getBool(); + else + return row; + } } template <> uno::Sequence<sal_Int8> OPreparedResultSet::retrieveValue(sal_Int32 column) @@ -260,7 +288,7 @@ template <> uno::Sequence<sal_Int8> OPreparedResultSet::retrieveValue(sal_Int32 template <> Date OPreparedResultSet::retrieveValue(sal_Int32 column) { if (getTypeFromMysqlType(m_aFields[column - 1].type) != std::type_index(typeid(Date))) - return getRowSetValue(column); + return getRowSetValue(column).getDate(); const MYSQL_TIME* pTime = static_cast<MYSQL_TIME*>(m_aData[column - 1].buffer); Date d; @@ -273,7 +301,7 @@ template <> Date OPreparedResultSet::retrieveValue(sal_Int32 column) template <> Time OPreparedResultSet::retrieveValue(sal_Int32 column) { if (getTypeFromMysqlType(m_aFields[column - 1].type) != std::type_index(typeid(Time))) - return getRowSetValue(column); + return getRowSetValue(column).getTime(); const MYSQL_TIME* pTime = static_cast<MYSQL_TIME*>(m_aData[column - 1].buffer); Time t; @@ -286,7 +314,7 @@ template <> Time OPreparedResultSet::retrieveValue(sal_Int32 column) template <> DateTime OPreparedResultSet::retrieveValue(sal_Int32 column) { if (getTypeFromMysqlType(m_aFields[column - 1].type) != std::type_index(typeid(DateTime))) - return getRowSetValue(column); + return getRowSetValue(column).getDateTime(); const MYSQL_TIME* pTime = static_cast<MYSQL_TIME*>(m_aData[column - 1].buffer); DateTime t; @@ -303,9 +331,22 @@ template <> OUString OPreparedResultSet::retrieveValue(sal_Int32 column) { // redirect call to the appropriate method if needed // BLOB can be simply read out as string + bool bIsBlobType = false; + switch (m_aFields[column - 1].type) + { + case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_TINY_BLOB: + case MYSQL_TYPE_MEDIUM_BLOB: + case MYSQL_TYPE_LONG_BLOB: + bIsBlobType = true; + break; + default: + bIsBlobType = false; + } + if (getTypeFromMysqlType(m_aFields[column - 1].type) != std::type_index(typeid(OUString)) - && m_aFields[column - 1].type != MYSQL_TYPE_BLOB) - return getRowSetValue(column); + && !bIsBlobType) + return getRowSetValue(column).getString(); const char* sStr = static_cast<const char*>(m_aData[column - 1].buffer); return OUString(sStr, *m_aData[column - 1].length, m_encoding); @@ -318,10 +359,13 @@ ORowSetValue OPreparedResultSet::getRowSetValue(sal_Int32 nColumnIndex) case MYSQL_TYPE_TINY: return getByte(nColumnIndex); case MYSQL_TYPE_SHORT: + case MYSQL_TYPE_YEAR: return getShort(nColumnIndex); case MYSQL_TYPE_LONG: case MYSQL_TYPE_INT24: return getInt(nColumnIndex); + case MYSQL_TYPE_BIT: + return ORowSetValue(bool(getBoolean(nColumnIndex))); case MYSQL_TYPE_LONGLONG: return getLong(nColumnIndex); case MYSQL_TYPE_FLOAT: @@ -341,6 +385,9 @@ ORowSetValue OPreparedResultSet::getRowSetValue(sal_Int32 nColumnIndex) case MYSQL_TYPE_NEWDECIMAL: return getString(nColumnIndex); case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_TINY_BLOB: + case MYSQL_TYPE_MEDIUM_BLOB: + case MYSQL_TYPE_LONG_BLOB: throw SQLException("Column with type BLOB cannot be converted", *this, "22000", 1, Any()); default: @@ -980,21 +1027,16 @@ uno::Sequence<sal_Int32> IPropertyArrayHelper* OPreparedResultSet::createArrayHelper() const { - uno::Sequence<Property> aProps(5); - Property* pProperties = aProps.getArray(); - sal_Int32 nPos = 0; - pProperties[nPos++] = Property("FetchDirection", PROPERTY_ID_FETCHDIRECTION, - cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] - = Property("FetchSize", PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = Property("IsBookmarkable", PROPERTY_ID_ISBOOKMARKABLE, - cppu::UnoType<bool>::get(), PropertyAttribute::READONLY); - pProperties[nPos++] = Property("ResultSetConcurrency", PROPERTY_ID_RESULTSETCONCURRENCY, - cppu::UnoType<sal_Int32>::get(), PropertyAttribute::READONLY); - pProperties[nPos++] = Property("ResultSetType", PROPERTY_ID_RESULTSETTYPE, - cppu::UnoType<sal_Int32>::get(), PropertyAttribute::READONLY); - - return new OPropertyArrayHelper(aProps); + return new OPropertyArrayHelper{ + { { "FetchDirection", PROPERTY_ID_FETCHDIRECTION, cppu::UnoType<sal_Int32>::get(), 0 }, + { "FetchSize", PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0 }, + { "IsBookmarkable", PROPERTY_ID_ISBOOKMARKABLE, cppu::UnoType<bool>::get(), + PropertyAttribute::READONLY }, + { "ResultSetConcurrency", PROPERTY_ID_RESULTSETCONCURRENCY, + cppu::UnoType<sal_Int32>::get(), PropertyAttribute::READONLY }, + { "ResultSetType", PROPERTY_ID_RESULTSETTYPE, cppu::UnoType<sal_Int32>::get(), + PropertyAttribute::READONLY } } + }; } IPropertyArrayHelper& OPreparedResultSet::getInfoHelper() { return *getArrayHelper(); } @@ -1061,9 +1103,9 @@ void OPreparedResultSet::getFastPropertyValue(Any& _rValue, sal_Int32 nHandle) c } } -void SAL_CALL OPreparedResultSet::acquire() throw() { OPreparedResultSet_BASE::acquire(); } +void SAL_CALL OPreparedResultSet::acquire() noexcept { OPreparedResultSet_BASE::acquire(); } -void SAL_CALL OPreparedResultSet::release() throw() { OPreparedResultSet_BASE::release(); } +void SAL_CALL OPreparedResultSet::release() noexcept { OPreparedResultSet_BASE::release(); } css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL OPreparedResultSet::getPropertySetInfo() { diff --git a/connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.hxx b/connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.hxx index 4ff64d5b4320..40912c5534a7 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.hxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_MYSQLC_SOURCE_MYSQLC_RESULTSET_HXX -#define INCLUDED_MYSQLC_SOURCE_MYSQLC_RESULTSET_HXX +#pragma once #include "mysqlc_preparedstatement.hxx" #include "mysqlc_statement.hxx" @@ -40,13 +39,9 @@ #include <cppuhelper/compbase12.hxx> -namespace connectivity +namespace connectivity::mysqlc { -namespace mysqlc -{ -using ::com::sun::star::sdbc::SQLException; using ::com::sun::star::uno::Any; -using ::com::sun::star::uno::RuntimeException; typedef ::cppu::WeakComponentImplHelper12< css::sdbc::XResultSet, css::sdbc::XRow, css::sdbc::XResultSetMetaDataSupplier, @@ -55,7 +50,7 @@ typedef ::cppu::WeakComponentImplHelper12< css::sdbc::XColumnLocate, css::lang::XServiceInfo> OPreparedResultSet_BASE; -class OPreparedResultSet final : public OBase_Mutex, +class OPreparedResultSet final : public cppu::BaseMutex, public OPreparedResultSet_BASE, public ::cppu::OPropertySetHelper, public OPropertyArrayUsageHelper<OPreparedResultSet> @@ -117,8 +112,8 @@ public: // XInterface Any SAL_CALL queryInterface(const css::uno::Type& rType) override; - void SAL_CALL acquire() throw() override; - void SAL_CALL release() throw() override; + void SAL_CALL acquire() noexcept override; + void SAL_CALL release() noexcept override; //XTypeProvider css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override; @@ -250,8 +245,7 @@ public: private: using ::cppu::OPropertySetHelper::getFastPropertyValue; }; -} /* mysqlc */ -} /* connectivity */ -#endif // CONNECTIVITY_SRESULTSET_HXX + +} /* connectivity::mysqlc */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_preparedstatement.cxx b/connectivity/source/drivers/mysqlc/mysqlc_preparedstatement.cxx index 2b344843deb2..2e7be0894040 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_preparedstatement.cxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_preparedstatement.cxx @@ -23,6 +23,7 @@ #include "mysqlc_propertyids.hxx" #include "mysqlc_resultsetmetadata.hxx" +#include <o3tl/safeint.hxx> #include <sal/log.hxx> #include <com/sun/star/sdbc/DataType.hpp> @@ -31,8 +32,6 @@ using namespace connectivity::mysqlc; using namespace com::sun::star::uno; -using namespace com::sun::star::lang; -using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; using namespace com::sun::star::container; using namespace com::sun::star::io; @@ -73,9 +72,9 @@ OPreparedStatement::OPreparedStatement(OConnection* _pConnection, MYSQL_STMT* pS OPreparedStatement::~OPreparedStatement() {} -void SAL_CALL OPreparedStatement::acquire() throw() { OCommonStatement::acquire(); } +void SAL_CALL OPreparedStatement::acquire() noexcept { OCommonStatement::acquire(); } -void SAL_CALL OPreparedStatement::release() throw() { OCommonStatement::release(); } +void SAL_CALL OPreparedStatement::release() noexcept { OCommonStatement::release(); } Any SAL_CALL OPreparedStatement::queryInterface(const Type& rType) { @@ -95,7 +94,7 @@ Sequence<Type> SAL_CALL OPreparedStatement::getTypes() Reference<XResultSetMetaData> SAL_CALL OPreparedStatement::getMetaData() { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); if (!m_xMetaData.is()) { @@ -109,7 +108,7 @@ Reference<XResultSetMetaData> SAL_CALL OPreparedStatement::getMetaData() void SAL_CALL OPreparedStatement::close() { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); if (mysql_stmt_close(m_pStmt)) { @@ -124,7 +123,7 @@ void SAL_CALL OPreparedStatement::close() sal_Bool SAL_CALL OPreparedStatement::execute() { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); if (!m_binds.empty() && mysql_stmt_bind_param(m_pStmt, m_binds.data())) { @@ -149,7 +148,7 @@ sal_Bool SAL_CALL OPreparedStatement::execute() sal_Int32 SAL_CALL OPreparedStatement::executeUpdate() { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); if (!m_binds.empty() && mysql_stmt_bind_param(m_pStmt, m_binds.data())) { @@ -176,7 +175,7 @@ sal_Int32 SAL_CALL OPreparedStatement::executeUpdate() void SAL_CALL OPreparedStatement::setString(sal_Int32 parameter, const OUString& x) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); OString stringie(OUStringToOString(x, m_xConnection->getConnectionEncoding())); @@ -191,15 +190,15 @@ void SAL_CALL OPreparedStatement::setString(sal_Int32 parameter, const OUString& Reference<XConnection> SAL_CALL OPreparedStatement::getConnection() { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); - return m_xConnection.get(); + return m_xConnection; } Reference<XResultSet> SAL_CALL OPreparedStatement::executeQuery() { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); if (!m_binds.empty() && mysql_stmt_bind_param(m_pStmt, m_binds.data())) { @@ -226,7 +225,7 @@ Reference<XResultSet> SAL_CALL OPreparedStatement::executeQuery() void SAL_CALL OPreparedStatement::setBoolean(sal_Int32 parameter, sal_Bool x) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); const sal_Int32 nIndex = parameter - 1; @@ -238,7 +237,7 @@ void SAL_CALL OPreparedStatement::setBoolean(sal_Int32 parameter, sal_Bool x) void SAL_CALL OPreparedStatement::setByte(sal_Int32 parameter, sal_Int8 x) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); const sal_Int32 nIndex = parameter - 1; @@ -250,7 +249,7 @@ void SAL_CALL OPreparedStatement::setByte(sal_Int32 parameter, sal_Int8 x) void SAL_CALL OPreparedStatement::setDate(sal_Int32 parameter, const Date& aData) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); MYSQL_TIME my_time = {}; @@ -268,7 +267,7 @@ void SAL_CALL OPreparedStatement::setDate(sal_Int32 parameter, const Date& aData void SAL_CALL OPreparedStatement::setTime(sal_Int32 parameter, const Time& aVal) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); MYSQL_TIME my_time = {}; @@ -286,7 +285,7 @@ void SAL_CALL OPreparedStatement::setTime(sal_Int32 parameter, const Time& aVal) void SAL_CALL OPreparedStatement::setTimestamp(sal_Int32 parameter, const DateTime& aVal) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); MYSQL_TIME my_time = {}; @@ -307,7 +306,7 @@ void SAL_CALL OPreparedStatement::setTimestamp(sal_Int32 parameter, const DateTi void SAL_CALL OPreparedStatement::setDouble(sal_Int32 parameter, double x) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); const sal_Int32 nIndex = parameter - 1; @@ -319,7 +318,7 @@ void SAL_CALL OPreparedStatement::setDouble(sal_Int32 parameter, double x) void SAL_CALL OPreparedStatement::setFloat(sal_Int32 parameter, float x) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); const sal_Int32 nIndex = parameter - 1; @@ -331,7 +330,7 @@ void SAL_CALL OPreparedStatement::setFloat(sal_Int32 parameter, float x) void SAL_CALL OPreparedStatement::setInt(sal_Int32 parameter, sal_Int32 x) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); const sal_Int32 nIndex = parameter - 1; @@ -343,7 +342,7 @@ void SAL_CALL OPreparedStatement::setInt(sal_Int32 parameter, sal_Int32 x) void SAL_CALL OPreparedStatement::setLong(sal_Int32 parameter, sal_Int64 aVal) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); const sal_Int32 nIndex = parameter - 1; @@ -355,7 +354,7 @@ void SAL_CALL OPreparedStatement::setLong(sal_Int32 parameter, sal_Int64 aVal) void SAL_CALL OPreparedStatement::setNull(sal_Int32 parameter, sal_Int32 /*sqlType*/) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); const sal_Int32 nIndex = parameter - 1; @@ -367,7 +366,7 @@ void SAL_CALL OPreparedStatement::setNull(sal_Int32 parameter, sal_Int32 /*sqlTy void SAL_CALL OPreparedStatement::setClob(sal_Int32 parameter, const Reference<XClob>& /* x */) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setClob", *this); @@ -376,7 +375,7 @@ void SAL_CALL OPreparedStatement::setClob(sal_Int32 parameter, const Reference<X void SAL_CALL OPreparedStatement::setBlob(sal_Int32 parameter, const Reference<XBlob>& /* x */) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setBlob", *this); @@ -385,7 +384,7 @@ void SAL_CALL OPreparedStatement::setBlob(sal_Int32 parameter, const Reference<X void SAL_CALL OPreparedStatement::setArray(sal_Int32 parameter, const Reference<XArray>& /* x */) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setArray", *this); @@ -394,7 +393,7 @@ void SAL_CALL OPreparedStatement::setArray(sal_Int32 parameter, const Reference< void SAL_CALL OPreparedStatement::setRef(sal_Int32 parameter, const Reference<XRef>& /* x */) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setRef", *this); @@ -403,7 +402,7 @@ void SAL_CALL OPreparedStatement::setRef(sal_Int32 parameter, const Reference<XR void SAL_CALL OPreparedStatement::setObjectWithInfo(sal_Int32 parameterIndex, const Any& value, sal_Int32 targetSqlType, sal_Int32 /* scale */) { - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); MutexGuard aGuard(m_aMutex); checkParameterIndex(parameterIndex); @@ -432,7 +431,7 @@ void SAL_CALL OPreparedStatement::setObjectWithInfo(sal_Int32 parameterIndex, co { OString sAscii = OUStringToOString(sValue, getOwnConnection()->getConnectionEncoding()); - std::stringstream sStream{ sAscii.getStr() }; + std::stringstream sStream{ std::string(sAscii) }; sStream >> nValue; m_binds[nIndex].buffer_type = MYSQL_TYPE_DOUBLE; mysqlc_sdbc_driver::resetSqlVar(&m_binds[nIndex].buffer, &nValue, MYSQL_TYPE_DOUBLE, @@ -457,7 +456,7 @@ void SAL_CALL OPreparedStatement::setObjectNull(sal_Int32 parameter, sal_Int32 / const OUString& /* typeName */) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setObjectNull", @@ -467,7 +466,7 @@ void SAL_CALL OPreparedStatement::setObjectNull(sal_Int32 parameter, sal_Int32 / void SAL_CALL OPreparedStatement::setObject(sal_Int32 parameter, const Any& /* x */) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setObject", *this); @@ -476,7 +475,7 @@ void SAL_CALL OPreparedStatement::setObject(sal_Int32 parameter, const Any& /* x void SAL_CALL OPreparedStatement::setShort(sal_Int32 parameter, sal_Int16 x) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); const sal_Int32 nIndex = parameter - 1; @@ -488,13 +487,14 @@ void SAL_CALL OPreparedStatement::setShort(sal_Int32 parameter, sal_Int16 x) void SAL_CALL OPreparedStatement::setBytes(sal_Int32 parameter, const Sequence<sal_Int8>& x) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); const sal_Int32 nIndex = parameter - 1; - m_binds[nIndex].buffer_type = MYSQL_TYPE_BLOB; // FIXME - mysqlc_sdbc_driver::resetSqlVar(&m_binds[nIndex].buffer, &x, MYSQL_TYPE_BLOB); + m_binds[nIndex].buffer_type = MYSQL_TYPE_BLOB; + mysqlc_sdbc_driver::resetSqlVar(&m_binds[nIndex].buffer, &x[0], MYSQL_TYPE_BLOB, x.getLength()); m_bindMetas[nIndex].is_null = false; + m_bindMetas[nIndex].length = x.getLength(); } void SAL_CALL OPreparedStatement::setCharacterStream(sal_Int32 parameter, @@ -502,7 +502,7 @@ void SAL_CALL OPreparedStatement::setCharacterStream(sal_Int32 parameter, sal_Int32 /* length */) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); mysqlc_sdbc_driver::throwFeatureNotImplementedException( @@ -514,7 +514,7 @@ void SAL_CALL OPreparedStatement::setBinaryStream(sal_Int32 parameter, sal_Int32 /* length */) { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); checkParameterIndex(parameter); mysqlc_sdbc_driver::throwFeatureNotImplementedException("OPreparedStatement::setBinaryStream", @@ -524,7 +524,7 @@ void SAL_CALL OPreparedStatement::setBinaryStream(sal_Int32 parameter, void SAL_CALL OPreparedStatement::clearParameters() { MutexGuard aGuard(m_aMutex); - checkDisposed(OPreparedStatement::rBHelper.bDisposed); + checkDisposed(rBHelper.bDisposed); for (size_t i = 0; i < m_binds.size(); ++i) { @@ -569,7 +569,7 @@ void OPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, con void OPreparedStatement::checkParameterIndex(sal_Int32 column) { - if (column < 1 || column > static_cast<sal_Int32>(m_paramCount)) + if (column < 1 || o3tl::make_unsigned(column) > m_paramCount) { throw SQLException("Parameter index out of range", *this, OUString(), 1, Any()); } diff --git a/connectivity/source/drivers/mysqlc/mysqlc_preparedstatement.hxx b/connectivity/source/drivers/mysqlc/mysqlc_preparedstatement.hxx index 0177b15dbd03..e1743d91dbc4 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_preparedstatement.hxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_preparedstatement.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_MYSQLC_SOURCE_MYSQLC_PREPAREDSTATEMENT_HXX -#define INCLUDED_MYSQLC_SOURCE_MYSQLC_PREPAREDSTATEMENT_HXX +#pragma once #include "mysqlc_statement.hxx" #include "mysqlc_resultset.hxx" @@ -29,15 +28,11 @@ #include <com/sun/star/io/XInputStream.hpp> #include <cppuhelper/compbase4.hxx> -namespace connectivity +namespace connectivity::mysqlc { -namespace mysqlc -{ -using ::com::sun::star::sdbc::SQLException; using ::com::sun::star::sdbc::XResultSetMetaData; using ::com::sun::star::uno::Any; using ::com::sun::star::uno::Reference; -using ::com::sun::star::uno::RuntimeException; using ::com::sun::star::uno::Type; #if defined MYSQL_VERSION_ID && (MYSQL_VERSION_ID >= 80000) && !defined MARIADB_BASE_VERSION @@ -81,8 +76,8 @@ public: //XInterface Any SAL_CALL queryInterface(const Type& rType) override; - void SAL_CALL acquire() throw() override; - void SAL_CALL release() throw() override; + void SAL_CALL acquire() noexcept override; + void SAL_CALL release() noexcept override; //XTypeProvider css::uno::Sequence<Type> SAL_CALL getTypes() override; @@ -154,8 +149,7 @@ public: // XResultSetMetaDataSupplier Reference<css::sdbc::XResultSetMetaData> SAL_CALL getMetaData() override; }; -} /* mysqlc */ -} /* connectivity */ -#endif // INCLUDED_MYSQLC_SOURCE_MYSQLC_PREPAREDSTATEMENT_HXX + +} /* connectivity::mysqlc */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_propertyids.hxx b/connectivity/source/drivers/mysqlc/mysqlc_propertyids.hxx index b2c1a1be071e..113b28a2fee7 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_propertyids.hxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_propertyids.hxx @@ -17,15 +17,12 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_MYSQLC_SOURCE_MYSQLC_PROPERTYIDS_HXX -#define INCLUDED_MYSQLC_SOURCE_MYSQLC_PROPERTYIDS_HXX +#pragma once // this define has to be set to split the names into different dll's or so's // every dll has his own set of property names -namespace connectivity -{ -namespace mysqlc +namespace connectivity::mysqlc { enum { @@ -41,9 +38,7 @@ enum PROPERTY_ID_USEBOOKMARKS, PROPERTY_ID_ISBOOKMARKABLE }; -} /* mysqlc */ -} /* connectivity */ -#endif // INCLUDED_MYSQLC_SOURCE_MYSQLC_PROPERTYIDS_HXX +} /* connectivity::mysqlc */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx b/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx index 75c229823004..397ea7cbab64 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx @@ -30,6 +30,8 @@ #include <cppuhelper/supportsservice.hxx> #include <cppuhelper/typeprovider.hxx> #include <comphelper/seqstream.hxx> +#include <o3tl/safeint.hxx> +#include <o3tl/string_view.hxx> using namespace rtl; @@ -51,14 +53,13 @@ namespace { // copied from string misc, it should be replaced when library is not an // extension anymore -std::vector<OString> lcl_split(const OString& rStr, char cSeparator) +std::vector<OString> lcl_split(std::string_view rStr, char cSeparator) { std::vector<OString> vec; sal_Int32 idx = 0; do { - OString kw = rStr.getToken(0, cSeparator, idx); - kw = kw.trim(); + OString kw(o3tl::trim(o3tl::getToken(rStr, 0, cSeparator, idx))); if (!kw.isEmpty()) { vec.push_back(kw); @@ -107,7 +108,7 @@ OResultSet::OResultSet(OConnection& rConn, OCommonStatement* pStmt, MYSQL_RES* p : OResultSet_BASE(m_aMutex) , OPropertySetHelper(OResultSet_BASE::rBHelper) , m_pMysql(rConn.getMysqlConnection()) - , m_aStatement(static_cast<OWeakObject*>(pStmt)) + , m_aStatement(css::uno::Reference(cppu::getXWeak(pStmt))) , m_pResult(pResult) , m_encoding(_encoding) { @@ -138,8 +139,8 @@ void OResultSet::ensureFieldInfoFetched() MYSQL_FIELD* pFields = mysql_fetch_fields(m_pResult); m_aFields.reserve(nFieldCount); for (unsigned i = 0; i < nFieldCount; ++i) - m_aFields.push_back(OUString{ - pFields[i].name, static_cast<sal_Int32>(strlen(pFields[i].name)), m_encoding }); + m_aFields.emplace_back(pFields[i].name, static_cast<sal_Int32>(strlen(pFields[i].name)), + m_encoding); } void OResultSet::fetchResult() @@ -155,11 +156,11 @@ void OResultSet::fetchResult() { MYSQL_ROW data = mysql_fetch_row(m_pResult); unsigned long* lengths = mysql_fetch_lengths(m_pResult); - m_aRows.push_back(DataFields{}); + m_aRows.emplace_back(); // MYSQL_ROW is char**, array of strings for (std::size_t col = 0; col < m_aFields.size(); ++col) { - m_aRows.back().push_back(OString{ data[col], static_cast<sal_Int32>(lengths[col]) }); + m_aRows.back().emplace_back(data[col], static_cast<sal_Int32>(lengths[col])); } } unsigned errorNum = mysql_errno(m_pMysql); @@ -181,7 +182,7 @@ void OResultSet::disposing() mysql_free_result(m_pResult); m_pResult = nullptr; } - m_aStatement = nullptr; + m_aStatement.clear(); m_xMetaData = nullptr; } @@ -292,24 +293,23 @@ Date SAL_CALL OResultSet::getDate(sal_Int32 column) if (checkNull(column)) return d; - OString dateStr = m_aRows[m_nRowPosition][column - 1]; + const OString& dateStr = m_aRows[m_nRowPosition][column - 1]; - OString dateString(dateStr); - OString token; + std::string_view dateString(dateStr); sal_Int32 nIndex = 0, i = 0; do { - token = dateString.getToken(0, '-', nIndex); + std::string_view token = o3tl::getToken(dateString, 0, '-', nIndex); switch (i) { case 0: - d.Year = static_cast<sal_uInt16>(token.toUInt32()); + d.Year = static_cast<sal_uInt16>(o3tl::toUInt32(token)); break; case 1: - d.Month = static_cast<sal_uInt16>(token.toUInt32()); + d.Month = static_cast<sal_uInt16>(o3tl::toUInt32(token)); break; case 2: - d.Day = static_cast<sal_uInt16>(token.toUInt32()); + d.Day = static_cast<sal_uInt16>(o3tl::toUInt32(token)); break; default:; } @@ -467,25 +467,28 @@ Time SAL_CALL OResultSet::getTime(sal_Int32 column) if (checkNull(column)) return t; - OString sVal = m_aRows[m_nRowPosition][column - 1]; - OString timeString{ sVal.getStr(), getDataLength(column) }; - OString token; + const OString& sVal = m_aRows[m_nRowPosition][column - 1]; + std::string_view timeString{ sVal.getStr(), o3tl::make_unsigned(getDataLength(column)) }; sal_Int32 nIndex, i = 0; - nIndex = timeString.indexOf(' ') + 1; + size_t idx = timeString.find(' '); + if (idx == std::string_view::npos) + nIndex = 0; + else + nIndex = idx + 1; do { - token = timeString.getToken(0, ':', nIndex); + std::string_view token = o3tl::getToken(timeString, 0, ':', nIndex); switch (i) { case 0: - t.Hours = static_cast<sal_uInt16>(token.toUInt32()); + t.Hours = static_cast<sal_uInt16>(o3tl::toUInt32(token)); break; case 1: - t.Minutes = static_cast<sal_uInt16>(token.toUInt32()); + t.Minutes = static_cast<sal_uInt16>(o3tl::toUInt32(token)); break; case 2: - t.Seconds = static_cast<sal_uInt16>(token.toUInt32()); + t.Seconds = static_cast<sal_uInt16>(o3tl::toUInt32(token)); break; } i++; @@ -506,8 +509,7 @@ DateTime SAL_CALL OResultSet::getTimestamp(sal_Int32 column) OString sVal = m_aRows[m_nRowPosition][column - 1]; // YY-MM-DD HH:MM:SS - std::vector<OString> dateAndTime - = lcl_split(OString{ sVal.getStr(), getDataLength(column) }, ' '); + std::vector<OString> dateAndTime = lcl_split(sVal.subView(0, getDataLength(column)), ' '); auto dateParts = lcl_split(dateAndTime.at(0), '-'); auto timeParts = lcl_split(dateAndTime.at(1), ':'); @@ -1007,21 +1009,16 @@ uno::Sequence<sal_Int32> SAL_CALL OResultSet::deleteRows(const uno::Sequence<Any IPropertyArrayHelper* OResultSet::createArrayHelper() const { - uno::Sequence<Property> aProps(5); - Property* pProperties = aProps.getArray(); - sal_Int32 nPos = 0; - pProperties[nPos++] = Property("FetchDirection", PROPERTY_ID_FETCHDIRECTION, - cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] - = Property("FetchSize", PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = Property("IsBookmarkable", PROPERTY_ID_ISBOOKMARKABLE, - cppu::UnoType<bool>::get(), PropertyAttribute::READONLY); - pProperties[nPos++] = Property("ResultSetConcurrency", PROPERTY_ID_RESULTSETCONCURRENCY, - cppu::UnoType<sal_Int32>::get(), PropertyAttribute::READONLY); - pProperties[nPos++] = Property("ResultSetType", PROPERTY_ID_RESULTSETTYPE, - cppu::UnoType<sal_Int32>::get(), PropertyAttribute::READONLY); - - return new OPropertyArrayHelper(aProps); + return new OPropertyArrayHelper{ + { { "FetchDirection", PROPERTY_ID_FETCHDIRECTION, cppu::UnoType<sal_Int32>::get(), 0 }, + { "FetchSize", PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0 }, + { "IsBookmarkable", PROPERTY_ID_ISBOOKMARKABLE, cppu::UnoType<bool>::get(), + PropertyAttribute::READONLY }, + { "ResultSetConcurrency", PROPERTY_ID_RESULTSETCONCURRENCY, + cppu::UnoType<sal_Int32>::get(), PropertyAttribute::READONLY }, + { "ResultSetType", PROPERTY_ID_RESULTSETTYPE, cppu::UnoType<sal_Int32>::get(), + PropertyAttribute::READONLY } } + }; } IPropertyArrayHelper& OResultSet::getInfoHelper() { return *getArrayHelper(); } @@ -1086,9 +1083,9 @@ void OResultSet::getFastPropertyValue(Any& _rValue, sal_Int32 nHandle) const } } -void SAL_CALL OResultSet::acquire() throw() { OResultSet_BASE::acquire(); } +void SAL_CALL OResultSet::acquire() noexcept { OResultSet_BASE::acquire(); } -void SAL_CALL OResultSet::release() throw() { OResultSet_BASE::release(); } +void SAL_CALL OResultSet::release() noexcept { OResultSet_BASE::release(); } css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL OResultSet::getPropertySetInfo() { @@ -1097,7 +1094,7 @@ css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL OResultSet::getProper void OResultSet::checkColumnIndex(sal_Int32 index) { - if (index < 1 || index > static_cast<int>(m_aFields.size())) + if (index < 1 || o3tl::make_unsigned(index) > m_aFields.size()) { /* static object for efficiency or thread safety is a problem ? */ throw SQLException("index out of range", *this, OUString(), 1, Any()); diff --git a/connectivity/source/drivers/mysqlc/mysqlc_resultset.hxx b/connectivity/source/drivers/mysqlc/mysqlc_resultset.hxx index dca2bb4a9d88..3e43853d364e 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_resultset.hxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_resultset.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_MYSQLC_SOURCE_MYSQLC_RESULTSET_HXX -#define INCLUDED_MYSQLC_SOURCE_MYSQLC_RESULTSET_HXX +#pragma once #include "mysqlc_preparedstatement.hxx" #include "mysqlc_statement.hxx" @@ -39,13 +38,9 @@ #include <cppuhelper/compbase12.hxx> -namespace connectivity +namespace connectivity::mysqlc { -namespace mysqlc -{ -using ::com::sun::star::sdbc::SQLException; using ::com::sun::star::uno::Any; -using ::com::sun::star::uno::RuntimeException; /* ** OResultSet @@ -57,7 +52,7 @@ typedef ::cppu::WeakComponentImplHelper12< css::sdbc::XColumnLocate, css::lang::XServiceInfo> OResultSet_BASE; -class OResultSet final : public OBase_Mutex, +class OResultSet final : public cppu::BaseMutex, public OResultSet_BASE, public ::cppu::OPropertySetHelper, public OPropertyArrayUsageHelper<OResultSet> @@ -140,8 +135,8 @@ public: // XInterface Any SAL_CALL queryInterface(const css::uno::Type& rType) override; - void SAL_CALL acquire() throw() override; - void SAL_CALL release() throw() override; + void SAL_CALL acquire() noexcept override; + void SAL_CALL release() noexcept override; //XTypeProvider css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override; @@ -272,8 +267,7 @@ public: private: using ::cppu::OPropertySetHelper::getFastPropertyValue; }; -} /* mysqlc */ -} /* connectivity */ -#endif // CONNECTIVITY_SRESULTSET_HXX + +} /* connectivity::mysqlc */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata.cxx b/connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata.cxx index ab9c2fb39992..21dd0fafc686 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata.cxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata.cxx @@ -21,11 +21,11 @@ #include "mysqlc_general.hxx" #include <com/sun/star/sdbc/XRow.hpp> -#include <rtl/ustrbuf.hxx> +#include <com/sun/star/sdbcx/XColumnsSupplier.hpp> +#include <o3tl/safeint.hxx> using namespace connectivity::mysqlc; using namespace com::sun::star::uno; -using namespace com::sun::star::lang; using namespace com::sun::star::sdbc; OResultSetMetaData::OResultSetMetaData(OConnection& rConn, MYSQL_RES* pResult) @@ -80,11 +80,11 @@ sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive(sal_Int32 column) { // MYSQL_FIELD::charsetnr is the collation identifier // _ci postfix means it's insensitive - OUStringBuffer sql{ "SHOW COLLATION WHERE Id =" }; - sql.append(OUString::number(m_fields.at(column - 1).charsetNumber)); + OUString sql + = "SHOW COLLATION WHERE Id =" + OUString::number(m_fields.at(column - 1).charsetNumber); Reference<XStatement> stmt = m_rConnection.createStatement(); - Reference<XResultSet> rs = stmt->executeQuery(sql.makeStringAndClear()); + Reference<XResultSet> rs = stmt->executeQuery(sql); Reference<XRow> xRow(rs, UNO_QUERY_THROW); if (!rs->next()) // fetch first and only row @@ -199,7 +199,7 @@ sal_Bool SAL_CALL OResultSetMetaData::isWritable(sal_Int32 column) void OResultSetMetaData::checkColumnIndex(sal_Int32 columnIndex) { auto nColCount = m_fields.size(); - if (columnIndex < 1 || columnIndex > static_cast<sal_Int32>(nColCount)) + if (columnIndex < 1 || o3tl::make_unsigned(columnIndex) > nColCount) { OUString str = "Column index out of range (expected 1 to " + OUString::number(sal_Int32(nColCount)) + ", got " diff --git a/connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata.hxx b/connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata.hxx index 52ca9595b9ba..aa84ac05586c 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata.hxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_MYSQLC_SOURCE_MYSQLC_RESULTSETMETADATA_HXX -#define INCLUDED_MYSQLC_SOURCE_MYSQLC_RESULTSETMETADATA_HXX +#pragma once #include "mysqlc_connection.hxx" @@ -29,14 +28,8 @@ #include <cppuhelper/implbase1.hxx> #include <mysql.h> -namespace connectivity +namespace connectivity::mysqlc { -namespace mysqlc -{ -using ::com::sun::star::sdbc::SQLException; -using ::com::sun::star::uno::RuntimeException; -using ::com::sun::star::uno::RuntimeException; - struct MySqlFieldInfo { OUString columnName; @@ -102,8 +95,5 @@ public: OUString SAL_CALL getColumnServiceName(sal_Int32 column) override; }; } -} - -#endif // INCLUDED_MYSQLC_SOURCE_MYSQLC_RESULTSETMETADATA_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_services.cxx b/connectivity/source/drivers/mysqlc/mysqlc_services.cxx index de611375c371..6e4e2fbb5e84 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_services.cxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_services.cxx @@ -48,7 +48,7 @@ struct ProviderRequest { } - bool CREATE_PROVIDER(const OUString& Implname, const Sequence<OUString>& Services, + bool CREATE_PROVIDER(std::u16string_view Implname, const Sequence<OUString>& Services, ::cppu::ComponentInstantiation Factory, createFactoryFunc creator) { if (!xRet.is() && (Implname == sImplementationName)) diff --git a/connectivity/source/drivers/mysqlc/mysqlc_statement.cxx b/connectivity/source/drivers/mysqlc/mysqlc_statement.cxx index 0082f96b61d1..bcb6d3a6cafc 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_statement.cxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_statement.cxx @@ -18,7 +18,6 @@ */ #include <sal/config.h> -#include <sal/log.hxx> #include "mysqlc_connection.hxx" #include "mysqlc_propertyids.hxx" @@ -27,7 +26,6 @@ #include "mysqlc_general.hxx" #include <cppuhelper/typeprovider.hxx> -#include <cppuhelper/queryinterface.hxx> #include <cppuhelper/supportsservice.hxx> using namespace connectivity::mysqlc; @@ -36,9 +34,7 @@ using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; -using namespace com::sun::star::sdbcx; using namespace com::sun::star::container; -using namespace com::sun::star::io; using namespace com::sun::star::util; using ::osl::MutexGuard; @@ -167,7 +163,7 @@ Reference<XConnection> SAL_CALL OStatement::getConnection() checkDisposed(rBHelper.bDisposed); // just return our connection here - return m_xConnection.get(); + return m_xConnection; } sal_Int32 SAL_CALL OStatement::getUpdateCount() { return m_nAffectedRows; } @@ -284,7 +280,7 @@ Any SAL_CALL OCommonStatement::getWarnings() MutexGuard aGuard(m_aMutex); checkDisposed(rBHelper.bDisposed); - return makeAny(m_aLastWarning); + return Any(m_aLastWarning); } void SAL_CALL OCommonStatement::clearWarnings() @@ -299,31 +295,19 @@ void SAL_CALL OCommonStatement::clearWarnings() { // this properties are define by the service statement // they must in alphabetic order - Sequence<Property> aProps(10); - Property* pProperties = aProps.getArray(); - sal_Int32 nPos = 0; - pProperties[nPos++] - = Property("CursorName", PROPERTY_ID_CURSORNAME, cppu::UnoType<OUString>::get(), 0); - pProperties[nPos++] - = Property("EscapeProcessing", PROPERTY_ID_ESCAPEPROCESSING, cppu::UnoType<bool>::get(), 0); - pProperties[nPos++] = Property("FetchDirection", PROPERTY_ID_FETCHDIRECTION, - cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] - = Property("FetchSize", PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] - = Property("MaxFieldSize", PROPERTY_ID_MAXFIELDSIZE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] - = Property("MaxRows", PROPERTY_ID_MAXROWS, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] - = Property("QueryTimeOut", PROPERTY_ID_QUERYTIMEOUT, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = Property("ResultSetConcurrency", PROPERTY_ID_RESULTSETCONCURRENCY, - cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] - = Property("ResultSetType", PROPERTY_ID_RESULTSETTYPE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] - = Property("UseBookmarks", PROPERTY_ID_USEBOOKMARKS, cppu::UnoType<bool>::get(), 0); - - return new ::cppu::OPropertyArrayHelper(aProps); + return new ::cppu::OPropertyArrayHelper{ + { { "CursorName", PROPERTY_ID_CURSORNAME, cppu::UnoType<OUString>::get(), 0 }, + { "EscapeProcessing", PROPERTY_ID_ESCAPEPROCESSING, cppu::UnoType<bool>::get(), 0 }, + { "FetchDirection", PROPERTY_ID_FETCHDIRECTION, cppu::UnoType<sal_Int32>::get(), 0 }, + { "FetchSize", PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0 }, + { "MaxFieldSize", PROPERTY_ID_MAXFIELDSIZE, cppu::UnoType<sal_Int32>::get(), 0 }, + { "MaxRows", PROPERTY_ID_MAXROWS, cppu::UnoType<sal_Int32>::get(), 0 }, + { "QueryTimeOut", PROPERTY_ID_QUERYTIMEOUT, cppu::UnoType<sal_Int32>::get(), 0 }, + { "ResultSetConcurrency", PROPERTY_ID_RESULTSETCONCURRENCY, + cppu::UnoType<sal_Int32>::get(), 0 }, + { "ResultSetType", PROPERTY_ID_RESULTSETTYPE, cppu::UnoType<sal_Int32>::get(), 0 }, + { "UseBookmarks", PROPERTY_ID_USEBOOKMARKS, cppu::UnoType<bool>::get(), 0 } } + }; } ::cppu::IPropertyArrayHelper& OCommonStatement::getInfoHelper() { return *getArrayHelper(); } @@ -388,13 +372,13 @@ sal_Bool OStatement::supportsService(OUString const& ServiceName) return cppu::supportsService(this, ServiceName); } -void SAL_CALL OCommonStatement::acquire() throw() { OCommonStatement_IBase::acquire(); } +void SAL_CALL OCommonStatement::acquire() noexcept { OCommonStatement_IBase::acquire(); } -void SAL_CALL OCommonStatement::release() throw() { OCommonStatement_IBase::release(); } +void SAL_CALL OCommonStatement::release() noexcept { OCommonStatement_IBase::release(); } -void SAL_CALL OStatement::acquire() throw() { OCommonStatement::acquire(); } +void SAL_CALL OStatement::acquire() noexcept { OCommonStatement::acquire(); } -void SAL_CALL OStatement::release() throw() { OCommonStatement::release(); } +void SAL_CALL OStatement::release() noexcept { OCommonStatement::release(); } Reference<css::beans::XPropertySetInfo> SAL_CALL OCommonStatement::getPropertySetInfo() { diff --git a/connectivity/source/drivers/mysqlc/mysqlc_statement.hxx b/connectivity/source/drivers/mysqlc/mysqlc_statement.hxx index 4416ccceb150..c710b0b46a6d 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_statement.hxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_statement.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_MYSQLC_SOURCE_MYSQLC_STATEMENT_HXX -#define INCLUDED_MYSQLC_SOURCE_MYSQLC_STATEMENT_HXX +#pragma once #include "mysqlc_connection.hxx" #include "mysqlc_subcomponent.hxx" @@ -35,14 +34,10 @@ #include <cppuhelper/compbase3.hxx> #include <rtl/ref.hxx> -namespace connectivity +namespace connectivity::mysqlc { -namespace mysqlc -{ -using ::com::sun::star::sdbc::SQLException; using ::com::sun::star::sdbc::SQLWarning; using ::com::sun::star::uno::Any; -using ::com::sun::star::uno::RuntimeException; using ::com::sun::star::uno::Type; typedef ::cppu::WeakComponentImplHelper3<css::sdbc::XWarningsSupplier, css::util::XCancellable, @@ -52,7 +47,7 @@ typedef ::cppu::WeakComponentImplHelper3<css::sdbc::XWarningsSupplier, css::util //************ Class: OCommonStatement // is a base class for the normal statement and for the prepared statement -class OCommonStatement : public OBase_Mutex, +class OCommonStatement : public cppu::BaseMutex, public OCommonStatement_IBase, public ::cppu::OPropertySetHelper, public OPropertyArrayUsageHelper<OCommonStatement> @@ -96,8 +91,8 @@ public: void SAL_CALL disposing() override; // XInterface - void SAL_CALL release() throw() override; - void SAL_CALL acquire() throw() override; + void SAL_CALL release() noexcept override; + void SAL_CALL acquire() noexcept override; Any SAL_CALL queryInterface(const css::uno::Type& rType) override; //XTypeProvider @@ -149,8 +144,8 @@ public: //XInterface Any SAL_CALL queryInterface(const css::uno::Type& rType) override; - void SAL_CALL acquire() throw() override; - void SAL_CALL release() throw() override; + void SAL_CALL acquire() noexcept override; + void SAL_CALL release() noexcept override; //XTypeProvider css::uno::Sequence<Type> SAL_CALL getTypes() override; @@ -174,7 +169,5 @@ public: // css::uno::Sequence<sal_Int32> SAL_CALL executeBatch() override; }; } -} -#endif // INCLUDED_MYSQLC_SOURCE_MYSQLC_STATEMENT_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_subcomponent.hxx b/connectivity/source/drivers/mysqlc/mysqlc_subcomponent.hxx index a1b02da51fa5..edba70a935ab 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_subcomponent.hxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_subcomponent.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_MYSQLC_SOURCE_MYSQLC_SUBCOMPONENT_HXX -#define INCLUDED_MYSQLC_SOURCE_MYSQLC_SUBCOMPONENT_HXX +#pragma once #include <cppuhelper/propshlp.hxx> #include <osl/diagnose.h> @@ -28,24 +27,12 @@ namespace cppu { class IPropertyArrayHelper; } - -namespace com -{ -namespace sun -{ -namespace star -{ -namespace lang +namespace com::sun::star::lang { class XComponent; } -} -} -} -namespace connectivity -{ -namespace mysqlc +namespace connectivity::mysqlc { /// @throws css::lang::DisposedException void checkDisposed(bool _bThrow); @@ -119,12 +106,6 @@ template <class TYPE>::cppu::IPropertyArrayHelper* OPropertyArrayUsageHelper<TYP return s_pProps; } -class OBase_Mutex -{ -public: - ::osl::Mutex m_aMutex; -}; - namespace internal { template <class T> void implCopySequence(const T* _pSource, T*& _pDest, sal_Int32 _nSourceLen) @@ -153,8 +134,5 @@ css::uno::Sequence<T> concatSequences(const css::uno::Sequence<T>& _rLeft, return aReturn; } } -} - -#endif // INCLUDED_MYSQLC_SOURCE_MYSQLC_SUBCOMPONENT_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_table.cxx b/connectivity/source/drivers/mysqlc/mysqlc_table.cxx new file mode 100644 index 000000000000..eedcb35d6164 --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_table.cxx @@ -0,0 +1,167 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#include "mysqlc_columns.hxx" +#include "mysqlc_indexes.hxx" +#include "mysqlc_keys.hxx" +#include "mysqlc_table.hxx" + +#include <TConnection.hxx> + +#include <comphelper/types.hxx> +#include <connectivity/dbtools.hxx> + +#include <com/sun/star/sdbcx/Privilege.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> + +connectivity::mysqlc::Table::Table( + Tables* pTables, osl::Mutex& rMutex, + const css::uno::Reference<OMetaConnection::XConnection>& rConnection) + : OTableHelper(pTables, rConnection, true) + , m_rMutex(rMutex) + , m_nPrivileges(0) +{ + construct(); +} + +connectivity::mysqlc::Table::Table( + Tables* pTables, osl::Mutex& rMutex, + const css::uno::Reference<OMetaConnection::XConnection>& rConnection, const OUString& rCatalog, + const OUString& rSchema, const OUString& rName, const OUString& rType, + const OUString& rDescription) + : OTableHelper(pTables, rConnection, true, rName, rType, rDescription, rSchema, rCatalog) + , m_rMutex(rMutex) + , m_nPrivileges(0) +{ + construct(); +} + +void connectivity::mysqlc::Table::construct() +{ + OTableHelper::construct(); + if (isNew()) + return; + + // TODO: get privileges when in non-embedded mode. + m_nPrivileges = css::sdbcx::Privilege::DROP | css::sdbcx::Privilege::REFERENCE + | css::sdbcx::Privilege::ALTER | css::sdbcx::Privilege::CREATE + | css::sdbcx::Privilege::READ | css::sdbcx::Privilege::DELETE + | css::sdbcx::Privilege::UPDATE | css::sdbcx::Privilege::INSERT + | css::sdbcx::Privilege::SELECT; + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRIVILEGES), + PROPERTY_ID_PRIVILEGES, css::beans::PropertyAttribute::READONLY, + &m_nPrivileges, cppu::UnoType<decltype(m_nPrivileges)>::get()); +} +//----- OTableHelper --------------------------------------------------------- +connectivity::sdbcx::OCollection* +connectivity::mysqlc::Table::createColumns(const ::std::vector<OUString>& rNames) +{ + return new Columns(*this, m_rMutex, rNames); +} + +connectivity::sdbcx::OCollection* +connectivity::mysqlc::Table::createKeys(const ::std::vector<OUString>& rNames) +{ + return new Keys(this, m_rMutex, rNames); +} + +connectivity::sdbcx::OCollection* +connectivity::mysqlc::Table::createIndexes(const ::std::vector<OUString>& rNames) +{ + return new Indexes(this, m_rMutex, rNames); +} + +//----- XAlterTable ----------------------------------------------------------- +void SAL_CALL connectivity::mysqlc::Table::alterColumnByName( + const OUString& rColName, const css::uno::Reference<XPropertySet>& rDescriptor) +{ + osl::MutexGuard aGuard(m_rMutex); + checkDisposed(WeakComponentImplHelperBase::rBHelper.bDisposed); + + css::uno::Reference<XPropertySet> xColumn(m_xColumns->getByName(rColName), css::uno::UNO_QUERY); + + // sdbcx::Descriptor + const bool bNameChanged + = xColumn->getPropertyValue("Name") != rDescriptor->getPropertyValue("Name"); + // sdbcx::ColumnDescriptor + const bool bTypeChanged + = xColumn->getPropertyValue("Type") != rDescriptor->getPropertyValue("Type"); + const bool bTypeNameChanged = !comphelper::getString(xColumn->getPropertyValue("TypeName")) + .equalsIgnoreAsciiCase(comphelper::getString( + rDescriptor->getPropertyValue("TypeName"))); + const bool bPrecisionChanged + = xColumn->getPropertyValue("Precision") != rDescriptor->getPropertyValue("Precision"); + const bool bScaleChanged + = xColumn->getPropertyValue("Scale") != rDescriptor->getPropertyValue("Scale"); + + const bool bIsNullableChanged + = xColumn->getPropertyValue("IsNullable") != rDescriptor->getPropertyValue("IsNullable"); + + const bool bIsAutoIncrementChanged = xColumn->getPropertyValue("IsAutoIncrement") + != rDescriptor->getPropertyValue("IsAutoIncrement"); + + // there's also DefaultValue but not related to database directly, it seems completely internal to LO + // so no need to test it + // TODO: remainder -- these are all "optional" so have to detect presence and change. + if (bTypeChanged || bTypeNameChanged || bPrecisionChanged || bScaleChanged || bIsNullableChanged + || bIsAutoIncrementChanged) + { + // If bPrecisionChanged this will only succeed if we have increased the + // precision, otherwise an exception is thrown -- however the base + // gui then offers to delete and recreate the column. + OUStringBuffer sSql(300); + sSql.append(getAlterTableColumnPart() + " MODIFY COLUMN `" + rColName + "` " + + ::dbtools::createStandardTypePart(rDescriptor, getConnection())); + + if (comphelper::getBOOL(rDescriptor->getPropertyValue("IsAutoIncrement"))) + sSql.append(" auto_increment"); + + // see ColumnValue: NO_NULLS = 0, NULLABLE = 1, NULLABLE_UNKNOWN + // so entry required = yes corresponds to NO_NULLS = 0 and only in this case + // NOT NULL + if (comphelper::getINT32(rDescriptor->getPropertyValue("IsNullable")) == 0) + sSql.append(" NOT NULL"); + + getConnection()->createStatement()->execute(sSql.makeStringAndClear()); + } + + if (bNameChanged) + { + OUString sNewColName; + rDescriptor->getPropertyValue("Name") >>= sNewColName; + OUString sSql(getAlterTableColumnPart() + " RENAME COLUMN `" + rColName + "` TO `" + + sNewColName + "`"); + + getConnection()->createStatement()->execute(sSql); + } + + m_xColumns->refresh(); +} + +void SAL_CALL connectivity::mysqlc::Table::alterColumnByIndex( + sal_Int32 index, const css::uno::Reference<css::beans::XPropertySet>& descriptor) +{ + osl::MutexGuard aGuard(m_rMutex); + css::uno::Reference<XPropertySet> xColumn(m_xColumns->getByIndex(index), + css::uno::UNO_QUERY_THROW); + alterColumnByName(comphelper::getString(xColumn->getPropertyValue( + OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))), + descriptor); +} + +OUString connectivity::mysqlc::Table::getAlterTableColumnPart() const +{ + return "ALTER TABLE " + + ::dbtools::composeTableName(getMetaData(), m_CatalogName, m_SchemaName, m_Name, true, + ::dbtools::EComposeRule::InTableDefinitions); +} + +OUString connectivity::mysqlc::Table::getRenameStart() const { return "RENAME TABLE "; } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_table.hxx b/connectivity/source/drivers/mysqlc/mysqlc_table.hxx new file mode 100644 index 000000000000..7487f1bc7b34 --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_table.hxx @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#pragma once + +#include "mysqlc_tables.hxx" + +#include <connectivity/TTableHelper.hxx> + +namespace connectivity::mysqlc +{ +class Table : public OTableHelper +{ +private: + ::osl::Mutex& m_rMutex; + sal_Int32 m_nPrivileges; + +protected: + void construct() override; + +public: + Table(Tables* pTables, ::osl::Mutex& rMutex, + const css::uno::Reference<css::sdbc::XConnection>& _xConnection); + Table(Tables* pTables, ::osl::Mutex& rMutex, + const css::uno::Reference<css::sdbc::XConnection>& _xConnection, const OUString& rCatalog, + const OUString& rSchema, const OUString& rName, const OUString& rType, + const OUString& rDescription); + + // OTableHelper + virtual ::connectivity::sdbcx::OCollection* + createColumns(const ::std::vector<OUString>& rNames) override; + virtual ::connectivity::sdbcx::OCollection* + createKeys(const ::std::vector<OUString>& rNames) override; + virtual ::connectivity::sdbcx::OCollection* + createIndexes(const ::std::vector<OUString>& rNames) override; + + /** Returns always "RENAME TABLE " even for views. + * + * \return The start of the rename statement. + * @see http://dev.mysql.com/doc/refman/5.1/de/rename-table.html + */ + virtual OUString getRenameStart() const override; + + // XAlterTable + /** + * See css::sdbcx::ColumnDescriptor for details of + * rDescriptor. + */ + virtual void SAL_CALL + alterColumnByName(const OUString& rColName, + const css::uno::Reference<css::beans::XPropertySet>& rDescriptor) override; + + virtual void SAL_CALL alterColumnByIndex( + sal_Int32 index, const css::uno::Reference<css::beans::XPropertySet>& descriptor) override; + + /** returns the ALTER TABLE XXX statement + */ + OUString getAlterTableColumnPart() const; +}; + +} // namespace connectivity::mysqlc + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_tables.cxx b/connectivity/source/drivers/mysqlc/mysqlc_tables.cxx new file mode 100644 index 000000000000..81498978d3a5 --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_tables.cxx @@ -0,0 +1,157 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#include "mysqlc_table.hxx" +#include "mysqlc_tables.hxx" +#include "mysqlc_catalog.hxx" + +#include <TConnection.hxx> + +#include <connectivity/dbtools.hxx> + +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbc/ColumnValue.hpp> +#include <comphelper/types.hxx> + +//----- OCollection ----------------------------------------------------------- +void connectivity::mysqlc::Tables::impl_refresh() +{ + static_cast<Catalog&>(m_rParent).refreshTables(); +} + +static void lcl_unescape(OUString& rName) +{ + // Remove ending ` if there's one + sal_Int32 nLastIndexBacktick = rName.lastIndexOf("`"); + if ((nLastIndexBacktick > 0) && (nLastIndexBacktick == (rName.getLength() - 1))) + { + rName = rName.copy(0, nLastIndexBacktick); + } + + // Remove beginning ` + nLastIndexBacktick = rName.indexOf("`"); + if (nLastIndexBacktick == 0) + { + rName = rName.copy(1, rName.getLength() - 1); + } + + // Replace double ` by simple ` + rName = rName.replaceAll("``", "`"); +} + +connectivity::sdbcx::ObjectType connectivity::mysqlc::Tables::createObject(const OUString& rName) +{ + OUString sCatalog, sSchema, sTable; + ::dbtools::qualifiedNameComponents(m_xMetaData, rName, sCatalog, sSchema, sTable, + ::dbtools::EComposeRule::InDataManipulation); + + css::uno::Any aCatalog; + if (!sCatalog.isEmpty()) + { + lcl_unescape(sCatalog); + aCatalog <<= sCatalog; + } + + lcl_unescape(sSchema); + lcl_unescape(sTable); + + // Only retrieving a single table, so table type is irrelevant (param 4) + css::uno::Reference<css::sdbc::XResultSet> xTables + = m_xMetaData->getTables(aCatalog, sSchema, sTable, css::uno::Sequence<OUString>()); + + if (!xTables.is()) + throw css::uno::RuntimeException("Could not acquire table."); + + css::uno::Reference<css::sdbc::XRow> xRow(xTables, css::uno::UNO_QUERY_THROW); + + if (!xTables->next()) + throw css::uno::RuntimeException(); + + connectivity::sdbcx::ObjectType xRet( + new Table(this, m_rMutex, m_xMetaData->getConnection(), + xRow->getString(1), // Catalog + xRow->getString(2), // Schema + xRow->getString(3), // Name + xRow->getString(4), // Type + xRow->getString(5))); // Description / Remarks / Comments + + if (xTables->next()) + throw css::uno::RuntimeException("Found more tables than expected."); + + return xRet; +} + +css::uno::Reference<css::beans::XPropertySet> connectivity::mysqlc::Tables::createDescriptor() +{ + // There is some internal magic so that the same class can be used as either + // a descriptor or as a normal table. See VTable.cxx for the details. In our + // case we just need to ensure we use the correct constructor. + return new Table(this, m_rMutex, m_xMetaData->getConnection()); +} + +//----- XAppend --------------------------------------------------------------- +void connectivity::mysqlc::Tables::createTable( + const css::uno::Reference<css::beans::XPropertySet>& descriptor) +{ + const css::uno::Reference<css::sdbc::XConnection> xConnection = m_xMetaData->getConnection(); + OUString aSql = ::dbtools::createSqlCreateTableStatement(descriptor, xConnection); + + css::uno::Reference<css::sdbc::XStatement> xStmt = xConnection->createStatement(); + if (xStmt.is()) + { + xStmt->execute(aSql); + ::comphelper::disposeComponent(xStmt); + } +} + +// XAppend +connectivity::sdbcx::ObjectType connectivity::mysqlc::Tables::appendObject( + const OUString& _rForName, const css::uno::Reference<css::beans::XPropertySet>& descriptor) +{ + createTable(descriptor); + return createObject(_rForName); +} + +void connectivity::mysqlc::Tables::appendNew(const OUString& _rsNewTable) +{ + insertElement(_rsNewTable, nullptr); + + // notify our container listeners + css::container::ContainerEvent aEvent(static_cast<XContainer*>(this), + css::uno::Any(_rsNewTable), css::uno::Any(), + css::uno::Any()); + comphelper::OInterfaceIteratorHelper3 aListenerLoop(m_aContainerListeners); + while (aListenerLoop.hasMoreElements()) + aListenerLoop.next()->elementInserted(aEvent); +} + +OUString +connectivity::mysqlc::Tables::getNameForObject(const connectivity::sdbcx::ObjectType& _xObject) +{ + OSL_ENSURE(_xObject.is(), "OTables::getNameForObject: Object is NULL!"); + return ::dbtools::composeTableName(m_xMetaData, _xObject, + ::dbtools::EComposeRule::InDataManipulation, false) + .replaceAll(u"`", u"Ì€ `"); +} + +//----- XDrop ----------------------------------------------------------------- +void connectivity::mysqlc::Tables::dropObject(sal_Int32 nPosition, const OUString& sName) +{ + css::uno::Reference<css::beans::XPropertySet> xTable(getObject(nPosition)); + + if (connectivity::sdbcx::ODescriptor::isNew(xTable)) + return; + + OUString sType; + xTable->getPropertyValue("Type") >>= sType; + + m_xMetaData->getConnection()->createStatement()->execute("DROP " + sType + " " + sName); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_tables.hxx b/connectivity/source/drivers/mysqlc/mysqlc_tables.hxx new file mode 100644 index 000000000000..8b05c5afaf9f --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_tables.hxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#pragma once + +#include <com/sun/star/sdbc/XDatabaseMetaData.hpp> + +#include <connectivity/sdbcx/VCollection.hxx> +#include <utility> + +namespace connectivity::mysqlc +{ +/** +* This implements com.sun.star.sdbcx.Container, which seems to be +* also known by the name of Tables and Collection. +*/ +class Tables : public ::connectivity::sdbcx::OCollection +{ +protected: + css::uno::Reference<css::sdbc::XDatabaseMetaData> m_xMetaData; + + // OCollection + virtual void impl_refresh() override; + virtual ::connectivity::sdbcx::ObjectType createObject(const OUString& rName) override; + virtual css::uno::Reference<css::beans::XPropertySet> createDescriptor() override; + virtual ::connectivity::sdbcx::ObjectType + appendObject(const OUString& rName, + const css::uno::Reference<css::beans::XPropertySet>& rDescriptor) override; + + void createTable(const css::uno::Reference<css::beans::XPropertySet>& descriptor); + virtual OUString getNameForObject(const sdbcx::ObjectType& _xObject) override; + // XDrop + virtual void dropObject(sal_Int32 nPosition, const OUString& rName) override; + +public: + Tables(css::uno::Reference<css::sdbc::XDatabaseMetaData> xMetaData, + ::cppu::OWeakObject& rParent, ::osl::Mutex& rMutex, + ::std::vector<OUString> const& rNames) + : sdbcx::OCollection(rParent, true, rMutex, rNames) + , m_xMetaData(std::move(xMetaData)) + { + } + + void appendNew(const OUString& _rsNewTable); + // TODO: should we also implement XDataDescriptorFactory, XRefreshable, + // XAppend, etc. ? +}; + +} // namespace connectivity::mysqlc + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_types.cxx b/connectivity/source/drivers/mysqlc/mysqlc_types.cxx index 219e0d553d41..ca473cebd84f 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_types.cxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_types.cxx @@ -673,6 +673,27 @@ TypeInfoDef const mysqlc_types[] = { }, // ----------- MySQL-Type: TIMESTAMP SDBC-Type: TIMESTAMP ---------- + + // ----------- MySQL-Type: YEAR SDBC-Type: INTEGER ---------- + { + "YEAR", // Typename + com::sun::star::sdbc::DataType::SMALLINT, // sdbc-type + 10, // Precision + "", // Literal prefix + "", // Literal suffix + "[(M)] [UNSIGNED] [ZEROFILL]", // Create params + com::sun::star::sdbc::ColumnValue::NULLABLE, // nullable + false, // case sensitive + com::sun::star::sdbc::ColumnSearch::FULL, // searchable + true, // unsignable + false, // fixed_prec_scale + true, // auto_increment + "YEAR", // local type name + 0, // minimum scale + 0 // maximum scale + }, + + // ----------- MySQL-Type: YEAR SDBC-Type: INTEGER ---------- { nullptr, 0, 0, nullptr, nullptr, nullptr, 0, false, 0, false, false, false, nullptr, 0, 0 } }; diff --git a/connectivity/source/drivers/mysqlc/mysqlc_types.hxx b/connectivity/source/drivers/mysqlc/mysqlc_types.hxx index 5f577ee0352b..9f2db7715fe6 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_types.hxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_types.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_MYSQLC_SOURCE_MYSQLC_TYPES_HXX -#define INCLUDED_MYSQLC_SOURCE_MYSQLC_TYPES_HXX +#pragma once #include <sal/types.h> @@ -43,6 +42,4 @@ struct TypeInfoDef extern TypeInfoDef const mysqlc_types[]; -#endif // INCLUDED_MYSQLC_SOURCE_MYSQLC_TYPES_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_user.cxx b/connectivity/source/drivers/mysqlc/mysqlc_user.cxx new file mode 100644 index 000000000000..6e8c3d734a67 --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_user.cxx @@ -0,0 +1,211 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#include <utility> + +#include "mysqlc_user.hxx" +#include <comphelper/types.hxx> +#include <connectivity/dbtools.hxx> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbcx/Privilege.hpp> +#include <com/sun/star/sdbcx/PrivilegeObject.hpp> +#include <TConnection.hxx> + +using namespace ::connectivity; +using namespace ::connectivity::mysqlc; +using namespace ::connectivity::sdbcx; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::sdbcx; + +User::User(css::uno::Reference<css::sdbc::XConnection> xConnection) + : OUser(true) // Case Sensitive + , m_xConnection(std::move(xConnection)) +{ +} + +User::User(css::uno::Reference<css::sdbc::XConnection> xConnection, const OUString& rName) + : OUser(rName, + true) // Case Sensitive + , m_xConnection(std::move(xConnection)) +{ +} + +OUserExtend::OUserExtend(const css::uno::Reference<css::sdbc::XConnection>& xConnection, + const OUString& rName) + : User(xConnection, rName) +{ + construct(); +} + +void OUserExtend::construct() +{ + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME), + PROPERTY_ID_NAME, 0, &m_Name, ::cppu::UnoType<OUString>::get()); + + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD), + PROPERTY_ID_PASSWORD, 0, &m_Password, ::cppu::UnoType<OUString>::get()); +} + +void User::changePassword(const OUString& /* oldPassword */, const OUString& newPassword) +{ + css::uno::Reference<XStatement> statement = m_xConnection->createStatement(); + statement->execute("SET PASSWORD FOR " + m_Name + " = PASSWORD('" + newPassword + "')"); + ::comphelper::disposeComponent(statement); +} + +cppu::IPropertyArrayHelper* OUserExtend::createArrayHelper() const +{ + css::uno::Sequence<css::beans::Property> aProps; + describeProperties(aProps); + return new cppu::OPropertyArrayHelper(aProps); +} + +cppu::IPropertyArrayHelper& OUserExtend::getInfoHelper() +{ + return *OUserExtend_PROP::getArrayHelper(); +} + +typedef connectivity::sdbcx::OUser_BASE OUser_BASE_RBHELPER; + +sal_Int32 SAL_CALL User::getPrivileges(const OUString& objName, sal_Int32 objType) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE_RBHELPER::rBHelper.bDisposed); + + sal_Int32 nRights, nRightsWithGrant; + findPrivilegesAndGrantPrivileges(objName, objType, nRights, nRightsWithGrant); + return nRights; +} + +void User::findPrivilegesAndGrantPrivileges(const OUString& objName, sal_Int32 objType, + sal_Int32& nRights, sal_Int32& nRightsWithGrant) +{ + nRightsWithGrant = nRights = 0; + // first we need to create the sql stmt to select the privs + css::uno::Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData(); + OUString sCatalog, sSchema, sTable; + ::dbtools::qualifiedNameComponents(xMeta, objName, sCatalog, sSchema, sTable, + ::dbtools::EComposeRule::InDataManipulation); + css::uno::Reference<XResultSet> xRes; + switch (objType) + { + case css::sdbcx::PrivilegeObject::TABLE: + case css::sdbcx::PrivilegeObject::VIEW: + { + css::uno::Any aCatalog; + if (!sCatalog.isEmpty()) + aCatalog <<= sCatalog; + xRes = xMeta->getTablePrivileges(aCatalog, sSchema, sTable); + } + break; + + case css::sdbcx::PrivilegeObject::COLUMN: + { + css::uno::Any aCatalog; + if (!sCatalog.isEmpty()) + aCatalog <<= sCatalog; + xRes = xMeta->getColumnPrivileges(aCatalog, sSchema, sTable, "%"); + } + break; + } + + if (!xRes.is()) + return; + + static const char sYes[] = "YES"; + + nRightsWithGrant = nRights = 0; + + css::uno::Reference<XRow> xCurrentRow(xRes, css::uno::UNO_QUERY); + while (xCurrentRow.is() && xRes->next()) + { + OUString sGrantee = xCurrentRow->getString(5); + OUString sPrivilege = xCurrentRow->getString(6); + OUString sGrantable = xCurrentRow->getString(7); + + if (!m_Name.equalsIgnoreAsciiCase(sGrantee)) + continue; + + if (sPrivilege.equalsIgnoreAsciiCase("SELECT")) + { + nRights |= Privilege::SELECT; + if (sGrantable.equalsIgnoreAsciiCase(sYes)) + nRightsWithGrant |= Privilege::SELECT; + } + else if (sPrivilege.equalsIgnoreAsciiCase("INSERT")) + { + nRights |= Privilege::INSERT; + if (sGrantable.equalsIgnoreAsciiCase(sYes)) + nRightsWithGrant |= Privilege::INSERT; + } + else if (sPrivilege.equalsIgnoreAsciiCase("UPDATE")) + { + nRights |= Privilege::UPDATE; + if (sGrantable.equalsIgnoreAsciiCase(sYes)) + nRightsWithGrant |= Privilege::UPDATE; + } + else if (sPrivilege.equalsIgnoreAsciiCase("DELETE")) + { + nRights |= Privilege::DELETE; + if (sGrantable.equalsIgnoreAsciiCase(sYes)) + nRightsWithGrant |= Privilege::DELETE; + } + else if (sPrivilege.equalsIgnoreAsciiCase("READ")) + { + nRights |= Privilege::READ; + if (sGrantable.equalsIgnoreAsciiCase(sYes)) + nRightsWithGrant |= Privilege::READ; + } + else if (sPrivilege.equalsIgnoreAsciiCase("CREATE")) + { + nRights |= Privilege::CREATE; + if (sGrantable.equalsIgnoreAsciiCase(sYes)) + nRightsWithGrant |= Privilege::CREATE; + } + else if (sPrivilege.equalsIgnoreAsciiCase("ALTER")) + { + nRights |= Privilege::ALTER; + if (sGrantable.equalsIgnoreAsciiCase(sYes)) + nRightsWithGrant |= Privilege::ALTER; + } + else if (sPrivilege.equalsIgnoreAsciiCase("REFERENCES")) + { + nRights |= Privilege::REFERENCE; + if (sGrantable.equalsIgnoreAsciiCase(sYes)) + nRightsWithGrant |= Privilege::REFERENCE; + } + else if (sPrivilege.equalsIgnoreAsciiCase("DROP")) + { + nRights |= Privilege::DROP; + if (sGrantable.equalsIgnoreAsciiCase(sYes)) + nRightsWithGrant |= Privilege::DROP; + } + } + ::comphelper::disposeComponent(xRes); +} + +sal_Int32 SAL_CALL User::getGrantablePrivileges(const OUString& objName, sal_Int32 objType) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE_RBHELPER::rBHelper.bDisposed); + + sal_Int32 nRights, nRightsWithGrant; + findPrivilegesAndGrantPrivileges(objName, objType, nRights, nRightsWithGrant); + return nRightsWithGrant; +} + +//----- IRefreshableGroups ---------------------------------------------------- +void User::refreshGroups() +{ + // TODO: implement. +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_user.hxx b/connectivity/source/drivers/mysqlc/mysqlc_user.hxx new file mode 100644 index 000000000000..6bebbaa64a11 --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_user.hxx @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#pragma once + +#include <sdbcx/VUser.hxx> +#include <com/sun/star/sdbc/XConnection.hpp> + +namespace connectivity::mysqlc +{ +/** +* This implements com.sun.star.sdbcx.Container. +*/ +class User : public ::connectivity::sdbcx::OUser +{ + css::uno::Reference<css::sdbc::XConnection> m_xConnection; + +public: + /** + * Create a "new" descriptor, which isn't yet in the database. + */ + User(css::uno::Reference<css::sdbc::XConnection> xConnection); + /** + * For a user that already exists in the db. + */ + User(css::uno::Reference<css::sdbc::XConnection> xConnection, const OUString& rName); + + // XAuthorizable + virtual void SAL_CALL changePassword(const OUString&, const OUString& newPassword) override; + virtual sal_Int32 SAL_CALL getPrivileges(const OUString&, sal_Int32) override; + // return the privileges and additional the grant rights + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void findPrivilegesAndGrantPrivileges(const OUString& objName, sal_Int32 objType, + sal_Int32& nRights, sal_Int32& nRightsWithGrant); + + virtual sal_Int32 SAL_CALL getGrantablePrivileges(const OUString&, sal_Int32) override; + + // IRefreshableGroups:: + virtual void refreshGroups() override; +}; + +class OUserExtend; +typedef ::comphelper::OPropertyArrayUsageHelper<OUserExtend> OUserExtend_PROP; + +class OUserExtend : public User, public OUserExtend_PROP +{ + OUString m_Password; + +protected: + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const override; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; + +public: + OUserExtend(const css::uno::Reference<css::sdbc::XConnection>& _xConnection, + const OUString& rName); + + virtual void construct() override; +}; + +} // namespace connectivity::mysqlc + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_users.cxx b/connectivity/source/drivers/mysqlc/mysqlc_users.cxx new file mode 100644 index 000000000000..296377c1be94 --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_users.cxx @@ -0,0 +1,93 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#include <utility> + +#include "mysqlc_user.hxx" +#include "mysqlc_users.hxx" +#include <comphelper/types.hxx> +#include <connectivity/dbtools.hxx> +#include <TConnection.hxx> + +using namespace ::connectivity; +using namespace ::connectivity::mysqlc; +using namespace ::connectivity::sdbcx; +using namespace ::cppu; +using namespace ::osl; +using namespace ::com::sun::star; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::uno; + +Users::Users(const uno::Reference<XDatabaseMetaData>& rMetaData, OWeakObject& rParent, + Mutex& rMutex, ::std::vector<OUString> const& rNames) + : OCollection(rParent, true, rMutex, rNames) + , m_xMetaData(rMetaData) +{ +} + +//----- OCollection ----------------------------------------------------------- +void Users::impl_refresh() +{ + // TODO: IMPLEMENT ME +} + +ObjectType Users::createObject(const OUString& rName) +{ + return new OUserExtend(m_xMetaData->getConnection(), rName); +} + +uno::Reference<XPropertySet> Users::createDescriptor() +{ + // There is some internal magic so that the same class can be used as either + // a descriptor or as a normal user. See VUser.cxx for the details. In our + // case we just need to ensure we use the correct constructor. + return new OUserExtend(m_xMetaData->getConnection(), ""); +} + +//----- XAppend --------------------------------------------------------------- +ObjectType Users::appendObject(const OUString& rName, + const uno::Reference<XPropertySet>& descriptor) +{ + OUString aSql("GRANT USAGE ON * TO "); + OUString aQuote = m_xMetaData->getIdentifierQuoteString(); + aSql += ::dbtools::quoteName(aQuote, rName) + " @\"%\" "; + OUString sPassword; + descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD)) + >>= sPassword; + if (!sPassword.isEmpty()) + { + aSql += " IDENTIFIED BY '" + sPassword + "'"; + } + + Reference<XStatement> statement = m_xMetaData->getConnection()->createStatement(); + if (statement.is()) + statement->execute(aSql); + ::comphelper::disposeComponent(statement); + + return createObject(rName); +} + +//----- XDrop ----------------------------------------------------------------- +void Users::dropObject(sal_Int32 nPosition, const OUString& rName) +{ + uno::Reference<XPropertySet> xUser(getObject(nPosition)); + + if (!ODescriptor::isNew(xUser)) + { + Reference<XStatement> statement = m_xMetaData->getConnection()->createStatement(); + if (statement.is()) + { + statement->execute("DROP USER " + rName); + ::comphelper::disposeComponent(statement); + } + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_users.hxx b/connectivity/source/drivers/mysqlc/mysqlc_users.hxx new file mode 100644 index 000000000000..d4c4d3558e42 --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_users.hxx @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#pragma once + +#include <connectivity/sdbcx/VCollection.hxx> +#include <com/sun/star/sdbc/XDatabaseMetaData.hpp> + +namespace connectivity::mysqlc +{ +class Users : public ::connectivity::sdbcx::OCollection +{ + css::uno::Reference<css::sdbc::XDatabaseMetaData> m_xMetaData; + +protected: + // OCollection + virtual void impl_refresh() override; + virtual ::connectivity::sdbcx::ObjectType createObject(const OUString& rName) override; + virtual css::uno::Reference<css::beans::XPropertySet> createDescriptor() override; + virtual ::connectivity::sdbcx::ObjectType + appendObject(const OUString& rName, + const css::uno::Reference<css::beans::XPropertySet>& rDescriptor) override; + +public: + Users(const css::uno::Reference<css::sdbc::XDatabaseMetaData>& rMetaData, + ::cppu::OWeakObject& rParent, ::osl::Mutex& rMutex, + ::std::vector<OUString> const& rNames); + + // TODO: we should also implement XDataDescriptorFactory, XRefreshable, + // XAppend, etc., but all are optional. + + // XDrop + virtual void dropObject(sal_Int32 nPosition, const OUString& rName) override; +}; +} // namespace connectivity::mysqlc + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_view.cxx b/connectivity/source/drivers/mysqlc/mysqlc_view.cxx new file mode 100644 index 000000000000..86837381d2bc --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_view.cxx @@ -0,0 +1,98 @@ +/* -*- 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 . + */ + +#include "mysqlc_view.hxx" + +#include <propertyids.hxx> + +#include <com/sun/star/sdbc/XRow.hpp> + +namespace connectivity::mysqlc +{ +View::View(const css::uno::Reference<css::sdbc::XConnection>& _rxConnection, bool _bCaseSensitive, + const OUString& _rSchemaName, const OUString& _rName) + : View_Base(_bCaseSensitive, _rName, _rxConnection->getMetaData(), OUString(), _rSchemaName, + OUString()) + , m_xConnection(_rxConnection) +{ +} + +View::~View() {} + +void SAL_CALL View::acquire() noexcept { View_Base::acquire(); }; +void SAL_CALL View::release() noexcept { View_Base::release(); }; +css::uno::Any SAL_CALL View::queryInterface(const css::uno::Type& _rType) +{ + css::uno::Any aReturn = View_Base::queryInterface(_rType); + if (!aReturn.hasValue()) + aReturn = View_IBASE::queryInterface(_rType); + return aReturn; +} + +css::uno::Sequence<css::uno::Type> SAL_CALL View::getTypes() +{ + return ::comphelper::concatSequences(View_Base::getTypes(), View_IBASE::getTypes()); +} + +css::uno::Sequence<sal_Int8> SAL_CALL View::getImplementationId() +{ + return css::uno::Sequence<sal_Int8>(); +} + +void SAL_CALL View::alterCommand(const OUString& _rNewCommand) +{ + OUString aCommand = "ALTER VIEW " + m_SchemaName + "." + m_Name + " AS " + _rNewCommand; + m_xMetaData->getConnection()->createStatement()->execute(aCommand); +} + +void SAL_CALL View::getFastPropertyValue(css::uno::Any& _rValue, sal_Int32 _nHandle) const +{ + if (_nHandle == PROPERTY_ID_COMMAND) + { + // retrieve the very current command, don't rely on the base classes cached value + // (which we initialized empty, anyway) + _rValue <<= impl_getCommand(); + return; + } + + View_Base::getFastPropertyValue(_rValue, _nHandle); +} + +OUString View::impl_getCommand() const +{ + OUString aCommand("SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = '" + + m_SchemaName + "' AND TABLE_NAME = '" + m_Name + "'"); + //::utl::SharedUNOComponent< XStatement > xStatement; xStatement.set( m_xConnection->createStatement(), UNO_QUERY_THROW ); + css::uno::Reference<css::sdbc::XResultSet> xResult( + m_xMetaData->getConnection()->createStatement()->executeQuery(aCommand), + css::uno::UNO_SET_THROW); + if (!xResult->next()) + { + // hmm. There is no view the name as we know it. Can only mean some other instance + // dropped this view meanwhile... + std::abort(); + } + + css::uno::Reference<css::sdbc::XRow> xRow(xResult, css::uno::UNO_QUERY_THROW); + return xRow->getString(1); +} + +} // namespace connectivity::mysqlc + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_view.hxx b/connectivity/source/drivers/mysqlc/mysqlc_view.hxx new file mode 100644 index 000000000000..8450152499c0 --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_view.hxx @@ -0,0 +1,72 @@ +/* -*- 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 . + */ + +#pragma once + +#include <connectivity/sdbcx/VView.hxx> + +#include <com/sun/star/sdbcx/XAlterView.hpp> +#include <com/sun/star/sdbc/XConnection.hpp> + +#include <comphelper/sequence.hxx> +#include <cppuhelper/implbase1.hxx> + +namespace connectivity::mysqlc +{ +typedef ::connectivity::sdbcx::OView View_Base; +typedef ::cppu::ImplHelper1<css::sdbcx::XAlterView> View_IBASE; + +class View : public View_Base, public View_IBASE +{ +public: + View(const css::uno::Reference<css::sdbc::XConnection>& _rxConnection, bool _bCaseSensitive, + const OUString& _rSchemaName, const OUString& _rName); + + // UNO + virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& aType) override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; + + virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override; + virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override; + + // XAlterView + virtual void SAL_CALL alterCommand(const OUString& NewCommand) override; + +protected: + virtual ~View() override; + +protected: + // OPropertyContainer + virtual void SAL_CALL getFastPropertyValue(css::uno::Any& _rValue, + sal_Int32 _nHandle) const override; + +private: + /** retrieves the current command of the View */ + OUString impl_getCommand() const; + +private: + css::uno::Reference<css::sdbc::XConnection> m_xConnection; + + using View_Base::getFastPropertyValue; +}; + +} // namespace connectivity::mysqlc + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mysqlc/mysqlc_views.cxx b/connectivity/source/drivers/mysqlc/mysqlc_views.cxx new file mode 100644 index 000000000000..1c79c9225d44 --- /dev/null +++ b/connectivity/source/drivers/mysqlc/mysqlc_views.cxx @@ -0,0 +1,113 @@ +/* -*- 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 . + */ + +#include "mysqlc_tables.hxx" +#include "mysqlc_views.hxx" +#include "mysqlc_view.hxx" +#include "mysqlc_catalog.hxx" +#include <connectivity/dbtools.hxx> +#include <comphelper/types.hxx> +#include <TConnection.hxx> + +connectivity::mysqlc::Views::Views(const css::uno::Reference<css::sdbc::XConnection>& _rxConnection, + ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, + const ::std::vector<OUString>& _rVector) + : sdbcx::OCollection(_rParent, true, _rMutex, _rVector) + , m_xConnection(_rxConnection) + , m_xMetaData(_rxConnection->getMetaData()) +{ +} + +connectivity::sdbcx::ObjectType connectivity::mysqlc::Views::createObject(const OUString& _rName) +{ + OUString sCatalog, sSchema, sTable; + ::dbtools::qualifiedNameComponents(m_xMetaData, _rName, sCatalog, sSchema, sTable, + ::dbtools::EComposeRule::InDataManipulation); + return new View(m_xConnection, isCaseSensitive(), sSchema, sTable); +} + +void connectivity::mysqlc::Views::impl_refresh() +{ + static_cast<Catalog&>(m_rParent).refreshViews(); +} + +css::uno::Reference<css::beans::XPropertySet> connectivity::mysqlc::Views::createDescriptor() +{ + return new connectivity::sdbcx::OView(true, m_xMetaData); +} + +// XAppend +connectivity::sdbcx::ObjectType connectivity::mysqlc::Views::appendObject( + const OUString& _rForName, const css::uno::Reference<css::beans::XPropertySet>& descriptor) +{ + createView(descriptor); + return createObject(_rForName); +} + +// XDrop +void connectivity::mysqlc::Views::dropObject(sal_Int32 _nPos, const OUString& /*_sElementName*/) +{ + css::uno::Reference<XInterface> xObject(getObject(_nPos)); + bool bIsNew = connectivity::sdbcx::ODescriptor::isNew(xObject); + if (!bIsNew) + { + OUString aSql("DROP VIEW"); + + css::uno::Reference<css::beans::XPropertySet> xProp(xObject, css::uno::UNO_QUERY); + aSql += ::dbtools::composeTableName(m_xMetaData, xProp, + ::dbtools::EComposeRule::InTableDefinitions, true); + + css::uno::Reference<css::sdbc::XConnection> xConnection = m_xMetaData->getConnection(); + css::uno::Reference<css::sdbc::XStatement> xStmt = xConnection->createStatement(); + xStmt->execute(aSql); + ::comphelper::disposeComponent(xStmt); + } +} + +void connectivity::mysqlc::Views::createView( + const css::uno::Reference<css::beans::XPropertySet>& descriptor) +{ + css::uno::Reference<css::sdbc::XConnection> xConnection = m_xMetaData->getConnection(); + + OUString sCommand; + descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND)) + >>= sCommand; + + OUString aSql = "CREATE VIEW " + + ::dbtools::composeTableName(m_xMetaData, descriptor, + ::dbtools::EComposeRule::InTableDefinitions, true) + + " AS " + sCommand; + + css::uno::Reference<css::sdbc::XStatement> xStmt = xConnection->createStatement(); + if (xStmt.is()) + { + xStmt->execute(aSql); + ::comphelper::disposeComponent(xStmt); + } + connectivity::mysqlc::Tables* pTables = static_cast<connectivity::mysqlc::Tables*>( + static_cast<connectivity::mysqlc::Catalog&>(m_rParent).getPrivateTables()); + if (pTables) + { + OUString sName = ::dbtools::composeTableName( + m_xMetaData, descriptor, ::dbtools::EComposeRule::InDataManipulation, false); + pTables->appendNew(sName); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MTables.hxx b/connectivity/source/drivers/mysqlc/mysqlc_views.hxx index ac3730f9aa16..14570fc8d9a9 100644 --- a/connectivity/source/drivers/mork/MTables.hxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_views.hxx @@ -16,32 +16,35 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MTABLES_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MTABLES_HXX +#pragma once #include <connectivity/sdbcx/VCollection.hxx> #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> -namespace connectivity +namespace connectivity::mysqlc { - namespace mork - { - class OTables : public sdbcx::OCollection - { - css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xMetaData; - protected: - virtual sdbcx::ObjectType createObject(const OUString& _rName) override; - virtual void impl_refresh() override; - public: - OTables(const css::uno::Reference< css::sdbc::XDatabaseMetaData >& _rMetaData,::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, - const ::std::vector< OUString> &_rVector) : sdbcx::OCollection(_rParent, true, _rMutex, _rVector) - ,m_xMetaData(_rMetaData) - {} +class Views final : public connectivity::sdbcx::OCollection +{ + css::uno::Reference<css::sdbc::XConnection> m_xConnection; + css::uno::Reference<css::sdbc::XDatabaseMetaData> m_xMetaData; + + // OCollection + virtual connectivity::sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference<css::beans::XPropertySet> createDescriptor() override; + virtual sdbcx::ObjectType + appendObject(const OUString& _rForName, + const css::uno::Reference<css::beans::XPropertySet>& descriptor) override; + + void createView(const css::uno::Reference<css::beans::XPropertySet>& descriptor); + +public: + Views(const css::uno::Reference<css::sdbc::XConnection>& _rxConnection, + ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, + const ::std::vector<OUString>& _rVector); - // only the name is identical to ::cppu::OComponentHelper - virtual void disposing() override; - }; - } + // XDrop + virtual void dropObject(sal_Int32 _nPos, const OUString& _sElementName) override; +}; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MTABLES_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/odbc/OConnection.cxx b/connectivity/source/drivers/odbc/OConnection.cxx index 26a549814cf3..b483165212b4 100644 --- a/connectivity/source/drivers/odbc/OConnection.cxx +++ b/connectivity/source/drivers/odbc/OConnection.cxx @@ -37,7 +37,6 @@ using namespace dbtools; using namespace com::sun::star::uno; -using namespace com::sun::star::lang; using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; @@ -60,21 +59,21 @@ OConnection::~OConnection() if(!isClosed( )) close(); - if ( SQL_NULL_HANDLE != m_aConnectionHandle ) - { - SQLRETURN rc; - - if (!m_bClosed) - { - rc = N3SQLDisconnect( m_aConnectionHandle ); - OSL_ENSURE( rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO, "Failure from SQLDisconnect" ); - } + if ( SQL_NULL_HANDLE == m_aConnectionHandle ) + return; - rc = N3SQLFreeHandle( SQL_HANDLE_DBC, m_aConnectionHandle ); - OSL_ENSURE( rc == SQL_SUCCESS , "Failure from SQLFreeHandle for connection"); + SQLRETURN rc; - m_aConnectionHandle = SQL_NULL_HANDLE; + if (!m_bClosed) + { + rc = N3SQLDisconnect( m_aConnectionHandle ); + OSL_ENSURE( rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO, "Failure from SQLDisconnect" ); } + + rc = N3SQLFreeHandle( SQL_HANDLE_DBC, m_aConnectionHandle ); + OSL_ENSURE( rc == SQL_SUCCESS , "Failure from SQLFreeHandle for connection"); + + m_aConnectionHandle = SQL_NULL_HANDLE; } oslGenericFunction OConnection::getOdbcFunction(ODBC3SQLFunctionId _nIndex) const @@ -98,7 +97,7 @@ SQLRETURN OConnection::OpenConnection(const OUString& aConnectStr, sal_Int32 nTi memcpy(szConnStrIn, aConStr.getStr(), std::min<sal_Int32>(sal_Int32(2048),aConStr.getLength())); #ifndef MACOSX - N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_LOGIN_TIMEOUT,reinterpret_cast<SQLPOINTER>(nTimeOut),SQL_IS_UINTEGER); + N3SQLSetConnectAttr(m_aConnectionHandle,SQL_ATTR_LOGIN_TIMEOUT,reinterpret_cast<SQLPOINTER>(static_cast<sal_IntPtr>(nTimeOut)),SQL_IS_UINTEGER); #else (void)nTimeOut; /* WaE */ #endif @@ -175,7 +174,7 @@ SQLRETURN OConnection::Construct(const OUString& url,const Sequence< PropertyVal sal_Int32 nLen = url.indexOf(':'); nLen = url.indexOf(':',nLen+2); OUString aDSN("DSN="), aUID, aPWD, aSysDrvSettings; - aDSN += url.copy(nLen+1); + aDSN += url.subView(nLen+1); sal_Int32 nTimeout = 20; bool bSilent = true; @@ -312,10 +311,10 @@ void SAL_CALL OConnection::setAutoCommit( sal_Bool autoCommit ) ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OConnection_BASE::rBHelper.bDisposed); - + const sal_IntPtr nAutocommit = autoCommit ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF; OTools::ThrowException(this,N3SQLSetConnectAttr(m_aConnectionHandle, SQL_ATTR_AUTOCOMMIT, - reinterpret_cast<SQLPOINTER>((autoCommit) ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF) ,SQL_IS_INTEGER), + reinterpret_cast<SQLPOINTER>(nAutocommit) ,SQL_IS_INTEGER), m_aConnectionHandle,SQL_HANDLE_DBC,*this); } @@ -423,7 +422,7 @@ void SAL_CALL OConnection::setTransactionIsolation( sal_Int32 level ) OTools::ThrowException(this,N3SQLSetConnectAttr(m_aConnectionHandle, SQL_ATTR_TXN_ISOLATION, - reinterpret_cast<SQLPOINTER>(level),SQL_IS_INTEGER), + reinterpret_cast<SQLPOINTER>(static_cast<sal_IntPtr>(level)),SQL_IS_INTEGER), m_aConnectionHandle,SQL_HANDLE_DBC,*this); } diff --git a/connectivity/source/drivers/odbc/ODatabaseMetaData.cxx b/connectivity/source/drivers/odbc/ODatabaseMetaData.cxx index c9ed165a8c26..bd721d60a617 100644 --- a/connectivity/source/drivers/odbc/ODatabaseMetaData.cxx +++ b/connectivity/source/drivers/odbc/ODatabaseMetaData.cxx @@ -28,11 +28,10 @@ #include <TPrivilegesResultSet.hxx> #include <rtl/ustrbuf.hxx> #include <sal/log.hxx> +#include <o3tl/string_view.hxx> using namespace connectivity::odbc; using namespace com::sun::star::uno; -using namespace com::sun::star::lang; -using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; ODatabaseMetaData::ODatabaseMetaData(const SQLHANDLE _pHandle,OConnection* _pCon) @@ -65,7 +64,7 @@ Reference< XResultSet > ODatabaseMetaData::impl_getTypeInfo_throw( ) Reference< XResultSet > xRef; try { - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection); xRef = pResult; pResult->openTypeInfo(); } @@ -88,7 +87,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCatalogs( ) { try { - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection); xRef = pResult; pResult->openCatalogs(); } @@ -115,7 +114,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getSchemas( ) Reference< XResultSet > xRef; try { - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection); xRef = pResult; pResult->openSchemas(); } @@ -133,7 +132,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumnPrivileges( Reference< XResultSet > xRef; try { - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection); xRef = pResult; pResult->openColumnPrivileges(m_bUseCatalog ? catalog : Any(),schema,table,columnNamePattern); } @@ -151,7 +150,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns( Reference< XResultSet > xRef; try { - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection); xRef = pResult; pResult->openColumns(m_bUseCatalog ? catalog : Any(),schemaPattern,tableNamePattern,columnNamePattern); } @@ -169,7 +168,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( Reference< XResultSet > xRef; try { - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection); xRef = pResult; pResult->openTables(m_bUseCatalog ? catalog : Any(),schemaPattern,tableNamePattern,types); } @@ -187,7 +186,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getProcedureColumns( Reference< XResultSet > xRef; try { - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection); xRef = pResult; pResult->openProcedureColumns(m_bUseCatalog ? catalog : Any(),schemaPattern,procedureNamePattern,columnNamePattern); } @@ -205,7 +204,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getProcedures( Reference< XResultSet > xRef; try { - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection); xRef = pResult; pResult->openProcedures(m_bUseCatalog ? catalog : Any(),schemaPattern,procedureNamePattern); } @@ -225,7 +224,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getVersionColumns( { if ( !m_pConnection->preventGetVersionColumns() ) { - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection); xRef = pResult; pResult->openVersionColumns(m_bUseCatalog ? catalog : Any(),schema,table); bSuccess = true; @@ -333,7 +332,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getExportedKeys( Reference< XResultSet > xRef; try { - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection); xRef = pResult; pResult->openExportedKeys(m_bUseCatalog ? catalog : Any(),schema,table); } @@ -350,7 +349,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getImportedKeys( Reference< XResultSet > xRef; try { - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection); xRef = pResult; pResult->openImportedKeys(m_bUseCatalog ? catalog : Any(),schema,table); } @@ -367,7 +366,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getPrimaryKeys( Reference< XResultSet > xRef; try { - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection); xRef = pResult; pResult->openPrimaryKeys(m_bUseCatalog ? catalog : Any(),schema,table); } @@ -385,7 +384,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getIndexInfo( Reference< XResultSet > xRef; try { - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection); xRef = pResult; pResult->openIndexInfo(m_bUseCatalog ? catalog : Any(),schema,table,unique,approximate); } @@ -403,7 +402,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getBestRowIdentifier( Reference< XResultSet > xRef; try { - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection); xRef = pResult; pResult->openBestRowIdentifier(m_bUseCatalog ? catalog : Any(),schema,table,scope,nullable); } @@ -421,10 +420,9 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTablePrivileges( { return new OResultSetPrivileges(this,catalog,schemaPattern,tableNamePattern); } - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); - Reference< XResultSet > xRef = pResult; + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection); pResult->openTablePrivileges(m_bUseCatalog ? catalog : Any(),schemaPattern,tableNamePattern); - return xRef; + return pResult; } Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCrossReference( @@ -435,7 +433,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getCrossReference( Reference< XResultSet > xRef; try { - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection); xRef = pResult; pResult->openForeignKeys(m_bUseCatalog ? primaryCatalog : Any(),primarySchema.toChar() == '%' ? &primarySchema : nullptr,&primaryTable, m_bUseCatalog ? foreignCatalog : Any(), foreignSchema.toChar() == '%' ? &foreignSchema : nullptr,&foreignTable); @@ -718,7 +716,7 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTableTypes( ) Reference< XResultSet > xRef; try { - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(m_pConnection); + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(m_pConnection); xRef = pResult; pResult->openTablesTypes(); } @@ -1242,7 +1240,7 @@ sal_Int32 SAL_CALL ODatabaseMetaData::getDriverMajorVersion( ) try { OUString aValue; OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_DRIVER_VER,aValue,*this,m_pConnection->getTextEncoding()); - return aValue.copy(0,aValue.indexOf('.')).toInt32(); + return o3tl::toInt32(aValue.subView(0,aValue.indexOf('.'))); } catch (const SQLException &) { @@ -1278,7 +1276,7 @@ sal_Int32 SAL_CALL ODatabaseMetaData::getDriverMinorVersion( ) try { OUString aValue; OTools::GetInfo(m_pConnection,m_aConnectionHandle,SQL_DRIVER_VER,aValue,*this,m_pConnection->getTextEncoding()); - return aValue.copy(0,aValue.lastIndexOf('.')).toInt32(); + return o3tl::toInt32(aValue.subView(0,aValue.lastIndexOf('.'))); } catch (const SQLException &) { diff --git a/connectivity/source/drivers/odbc/ODatabaseMetaDataResultSet.cxx b/connectivity/source/drivers/odbc/ODatabaseMetaDataResultSet.cxx index 7afd4bed54f9..5fbe8bf8f460 100644 --- a/connectivity/source/drivers/odbc/ODatabaseMetaDataResultSet.cxx +++ b/connectivity/source/drivers/odbc/ODatabaseMetaDataResultSet.cxx @@ -47,7 +47,6 @@ ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet(OConnection* _pConnection ,OPropertySetHelper(ODatabaseMetaDataResultSet_BASE::rBHelper) ,m_aStatementHandle(_pConnection->createStatementHandle()) - ,m_aStatement(nullptr) ,m_pConnection(_pConnection) ,m_nTextEncoding(_pConnection->getTextEncoding()) ,m_nRowPos(-1) @@ -84,7 +83,7 @@ void ODatabaseMetaDataResultSet::disposing() m_pConnection->freeStatementHandle(m_aStatementHandle); - m_aStatement = nullptr; + m_aStatement.clear(); m_xMetaData.clear(); m_pConnection.clear(); } @@ -100,12 +99,12 @@ Reference< XPropertySetInfo > SAL_CALL ODatabaseMetaDataResultSet::getPropertySe return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); } -void SAL_CALL ODatabaseMetaDataResultSet::acquire() throw() +void SAL_CALL ODatabaseMetaDataResultSet::acquire() noexcept { ODatabaseMetaDataResultSet_BASE::acquire(); } -void SAL_CALL ODatabaseMetaDataResultSet::release() throw() +void SAL_CALL ODatabaseMetaDataResultSet::release() noexcept { ODatabaseMetaDataResultSet_BASE::release(); } @@ -698,21 +697,41 @@ OUString ODatabaseMetaDataResultSet::getCursorName() ::cppu::IPropertyArrayHelper* ODatabaseMetaDataResultSet::createArrayHelper( ) const { - Sequence< css::beans::Property > aProps(5); - css::beans::Property* pProperties = aProps.getArray(); - sal_Int32 nPos = 0; - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), - PROPERTY_ID_CURSORNAME, cppu::UnoType<OUString>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), - PROPERTY_ID_FETCHDIRECTION, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), - PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), - PROPERTY_ID_RESULTSETCONCURRENCY, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), - PROPERTY_ID_RESULTSETTYPE, cppu::UnoType<sal_Int32>::get(), 0); - - return new ::cppu::OPropertyArrayHelper(aProps); + return new ::cppu::OPropertyArrayHelper + { + { + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), + PROPERTY_ID_CURSORNAME, + cppu::UnoType<OUString>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), + PROPERTY_ID_FETCHDIRECTION, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), + PROPERTY_ID_FETCHSIZE, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), + PROPERTY_ID_RESULTSETCONCURRENCY, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), + PROPERTY_ID_RESULTSETTYPE, + cppu::UnoType<sal_Int32>::get(), + 0 + } + } + }; } ::cppu::IPropertyArrayHelper & ODatabaseMetaDataResultSet::getInfoHelper() @@ -822,7 +841,7 @@ void ODatabaseMetaDataResultSet::openTypeInfo() } void ODatabaseMetaDataResultSet::openTables(const Any& catalog, const OUString& schemaPattern, - const OUString& tableNamePattern, + std::u16string_view tableNamePattern, const Sequence< OUString >& types ) { OString aPKQ,aPKO,aPKN,aCOL; @@ -881,7 +900,7 @@ void ODatabaseMetaDataResultSet::openTablesTypes( ) m_aColMapping.clear(); m_aColMapping.push_back(-1); m_aColMapping.push_back(4); - m_xMetaData = new OResultSetMetaData(m_pConnection.get(),m_aStatementHandle,m_aColMapping); + m_xMetaData = new OResultSetMetaData(m_pConnection.get(),m_aStatementHandle,std::vector(m_aColMapping)); checkColumnCount(); } @@ -898,7 +917,7 @@ void ODatabaseMetaDataResultSet::openCatalogs() m_aColMapping.clear(); m_aColMapping.push_back(-1); m_aColMapping.push_back(1); - m_xMetaData = new OResultSetMetaData(m_pConnection.get(),m_aStatementHandle,m_aColMapping); + m_xMetaData = new OResultSetMetaData(m_pConnection.get(),m_aStatementHandle,std::vector(m_aColMapping)); checkColumnCount(); } @@ -914,12 +933,13 @@ void ODatabaseMetaDataResultSet::openSchemas() m_aColMapping.clear(); m_aColMapping.push_back(-1); m_aColMapping.push_back(2); - m_xMetaData = new OResultSetMetaData(m_pConnection.get(),m_aStatementHandle,m_aColMapping); + m_xMetaData = new OResultSetMetaData(m_pConnection.get(),m_aStatementHandle,std::vector(m_aColMapping)); checkColumnCount(); } void ODatabaseMetaDataResultSet::openColumnPrivileges( const Any& catalog, const OUString& schema, - const OUString& table, const OUString& columnNamePattern ) + std::u16string_view table, + std::u16string_view columnNamePattern ) { const OUString *pSchemaPat = nullptr; @@ -953,7 +973,7 @@ void ODatabaseMetaDataResultSet::openColumnPrivileges( const Any& catalog, cons } void ODatabaseMetaDataResultSet::openColumns( const Any& catalog, const OUString& schemaPattern, - const OUString& tableNamePattern, const OUString& columnNamePattern ) + std::u16string_view tableNamePattern, std::u16string_view columnNamePattern ) { const OUString *pSchemaPat = nullptr; @@ -1020,7 +1040,7 @@ void ODatabaseMetaDataResultSet::openColumns( const Any& catalog, } void ODatabaseMetaDataResultSet::openProcedureColumns( const Any& catalog, const OUString& schemaPattern, - const OUString& procedureNamePattern,const OUString& columnNamePattern ) + std::u16string_view procedureNamePattern,std::u16string_view columnNamePattern ) { const OUString *pSchemaPat = nullptr; @@ -1053,7 +1073,7 @@ void ODatabaseMetaDataResultSet::openProcedureColumns( const Any& catalog, } void ODatabaseMetaDataResultSet::openProcedures(const Any& catalog, const OUString& schemaPattern, - const OUString& procedureNamePattern) + std::u16string_view procedureNamePattern) { const OUString *pSchemaPat = nullptr; @@ -1083,14 +1103,15 @@ void ODatabaseMetaDataResultSet::openProcedures(const Any& catalog, const OUStri } void ODatabaseMetaDataResultSet::openSpecialColumns(bool _bRowVer,const Any& catalog, const OUString& schema, - const OUString& table,sal_Int32 scope, bool nullable ) + std::u16string_view table,sal_Int32 scope, bool nullable ) { // Some ODBC drivers really don't like getting an empty string as tableName // E.g. psqlodbc up to at least version 09.01.0100 segfaults - if (table.isEmpty()) + if (table.empty()) { - const char errMsg[] = "ODBC: Trying to get special columns of empty table name"; - const char SQLState[] = "HY009"; + static constexpr OUStringLiteral errMsg + = u"ODBC: Trying to get special columns of empty table name"; + static constexpr OUStringLiteral SQLState = u"HY009"; throw SQLException( errMsg, *this, SQLState, -1, Any() ); } @@ -1123,13 +1144,13 @@ void ODatabaseMetaDataResultSet::openSpecialColumns(bool _bRowVer,const Any& cat } void ODatabaseMetaDataResultSet::openVersionColumns(const Any& catalog, const OUString& schema, - const OUString& table) + std::u16string_view table) { openSpecialColumns(true,catalog,schema,table,SQL_SCOPE_TRANSACTION,false); } void ODatabaseMetaDataResultSet::openBestRowIdentifier( const Any& catalog, const OUString& schema, - const OUString& table,sal_Int32 scope,bool nullable ) + std::u16string_view table,sal_Int32 scope,bool nullable ) { openSpecialColumns(false,catalog,schema,table,scope,nullable); } @@ -1198,7 +1219,7 @@ void ODatabaseMetaDataResultSet::openExportedKeys(const Any& catalog, const OUSt } void ODatabaseMetaDataResultSet::openPrimaryKeys(const Any& catalog, const OUString& schema, - const OUString& table) + std::u16string_view table) { const OUString *pSchemaPat = nullptr; @@ -1228,7 +1249,7 @@ void ODatabaseMetaDataResultSet::openPrimaryKeys(const Any& catalog, const OUStr } void ODatabaseMetaDataResultSet::openTablePrivileges(const Any& catalog, const OUString& schemaPattern, - const OUString& tableNamePattern) + std::u16string_view tableNamePattern) { const OUString *pSchemaPat = nullptr; @@ -1257,7 +1278,7 @@ void ODatabaseMetaDataResultSet::openTablePrivileges(const Any& catalog, const O } void ODatabaseMetaDataResultSet::openIndexInfo( const Any& catalog, const OUString& schema, - const OUString& table, bool unique, bool approximate ) + std::u16string_view table, bool unique, bool approximate ) { const OUString *pSchemaPat = nullptr; diff --git a/connectivity/source/drivers/odbc/ODriver.cxx b/connectivity/source/drivers/odbc/ODriver.cxx index 42dbff07ba95..cf3c5596aad4 100644 --- a/connectivity/source/drivers/odbc/ODriver.cxx +++ b/connectivity/source/drivers/odbc/ODriver.cxx @@ -24,6 +24,7 @@ #include <cppuhelper/supportsservice.hxx> #include <strings.hrc> #include <resource/sharedresources.hxx> +#include <utility> using namespace connectivity::odbc; using namespace com::sun::star::uno; @@ -31,9 +32,9 @@ using namespace com::sun::star::lang; using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; -ODBCDriver::ODBCDriver(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory) +ODBCDriver::ODBCDriver(css::uno::Reference< css::uno::XComponentContext > _xContext) :ODriver_BASE(m_aMutex) - ,m_xORB(_rxFactory) + ,m_xContext(std::move(_xContext)) ,m_pDriverHandle(SQL_NULL_HANDLE) { } @@ -56,7 +57,7 @@ void ODBCDriver::disposing() // static ServiceInfo -OUString ODBCDriver::getImplementationName_Static( ) +OUString ODBCDriver::getImplementationName( ) { return "com.sun.star.comp.sdbc.ODBCDriver"; // this name is referenced in the configuration and in the odbc.xml @@ -64,29 +65,18 @@ OUString ODBCDriver::getImplementationName_Static( ) } -Sequence< OUString > ODBCDriver::getSupportedServiceNames_Static( ) +Sequence< OUString > ODBCDriver::getSupportedServiceNames( ) { return { "com.sun.star.sdbc.Driver" }; } -OUString SAL_CALL ODBCDriver::getImplementationName( ) -{ - return getImplementationName_Static(); -} - sal_Bool SAL_CALL ODBCDriver::supportsService( const OUString& _rServiceName ) { return cppu::supportsService(this, _rServiceName); } -Sequence< OUString > SAL_CALL ODBCDriver::getSupportedServiceNames( ) -{ - return getSupportedServiceNames_Static(); -} - - Reference< XConnection > SAL_CALL ODBCDriver::connect( const OUString& url, const Sequence< PropertyValue >& info ) { if ( ! acceptsURL(url) ) @@ -98,12 +88,11 @@ Reference< XConnection > SAL_CALL ODBCDriver::connect( const OUString& url, cons if(!EnvironmentHandle(aPath)) throw SQLException(aPath,*this,OUString(),1000,Any()); } - OConnection* pCon = new OConnection(m_pDriverHandle,this); - Reference< XConnection > xCon = pCon; + rtl::Reference<OConnection> pCon = new OConnection(m_pDriverHandle,this); pCon->Construct(url,info); m_xConnections.push_back(WeakReferenceHelper(*pCon)); - return xCon; + return pCon; } sal_Bool SAL_CALL ODBCDriver::acceptsURL( const OUString& url ) @@ -115,77 +104,74 @@ Sequence< DriverPropertyInfo > SAL_CALL ODBCDriver::getPropertyInfo( const OUStr { if ( acceptsURL(url) ) { - std::vector< DriverPropertyInfo > aDriverInfo; - - Sequence< OUString > aBooleanValues(2); - aBooleanValues[0] = "false"; - aBooleanValues[1] = "true"; - - aDriverInfo.push_back(DriverPropertyInfo( - "CharSet" - ,"CharSet of the database." - ,false - ,OUString() - ,Sequence< OUString >()) - ); - aDriverInfo.push_back(DriverPropertyInfo( - "UseCatalog" - ,"Use catalog for file-based databases." - ,false - ,"false" - ,aBooleanValues) - ); - aDriverInfo.push_back(DriverPropertyInfo( - "SystemDriverSettings" - ,"Driver settings." - ,false - ,OUString() - ,Sequence< OUString >()) - ); - aDriverInfo.push_back(DriverPropertyInfo( - "ParameterNameSubstitution" - ,"Change named parameters with '?'." - ,false - ,"false" - ,aBooleanValues) - ); - aDriverInfo.push_back(DriverPropertyInfo( - "IgnoreDriverPrivileges" - ,"Ignore the privileges from the database driver." - ,false - ,"false" - ,aBooleanValues) - ); - aDriverInfo.push_back(DriverPropertyInfo( - "IsAutoRetrievingEnabled" - ,"Retrieve generated values." - ,false - ,"false" - ,aBooleanValues) - ); - aDriverInfo.push_back(DriverPropertyInfo( - "AutoRetrievingStatement" - ,"Auto-increment statement." - ,false - ,OUString() - ,Sequence< OUString >()) - ); - aDriverInfo.push_back(DriverPropertyInfo( - "GenerateASBeforeCorrelationName" - ,"Generate AS before table correlation names." - ,false - ,"false" - ,aBooleanValues) - ); - aDriverInfo.push_back(DriverPropertyInfo( - "EscapeDateTime" - ,"Escape date time format." - ,false - ,"true" - ,aBooleanValues) - ); - - return Sequence< DriverPropertyInfo >(aDriverInfo.data(),aDriverInfo.size()); + Sequence< OUString > aBooleanValues{ "false", "true" }; + + return + { + { + "CharSet", + "CharSet of the database.", + false, + {}, + {} + }, + { + "UseCatalog", + "Use catalog for file-based databases.", + false, + "false", + aBooleanValues + }, + { + "SystemDriverSettings", + "Driver settings.", + false, + {}, + {} + }, + { + "ParameterNameSubstitution", + "Change named parameters with '?'.", + false, + "false", + aBooleanValues + }, + { + "IgnoreDriverPrivileges", + "Ignore the privileges from the database driver.", + false, + "false", + aBooleanValues + }, + { + "IsAutoRetrievingEnabled", + "Retrieve generated values.", + false, + "false", + aBooleanValues + }, + { + "AutoRetrievingStatement", + "Auto-increment statement.", + false, + {}, + {} + }, + { + "GenerateASBeforeCorrelationName", + "Generate AS before table correlation names.", + false, + "false", + aBooleanValues + }, + { + "EscapeDateTime", + "Escape date time format.", + false, + "true", + aBooleanValues + } + }; } ::connectivity::SharedResources aResources; const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR); diff --git a/connectivity/source/drivers/odbc/OFunctions.cxx b/connectivity/source/drivers/odbc/OFunctions.cxx index ae89531763a1..951eb8b36bff 100644 --- a/connectivity/source/drivers/odbc/OFunctions.cxx +++ b/connectivity/source/drivers/odbc/OFunctions.cxx @@ -89,7 +89,9 @@ bool LoadLibrary_ODBC3(OUString &_rPath) if (bLoaded) return true; -#ifndef DISABLE_DYNLOADING +#ifdef DISABLE_DYNLOADING + (void)_rPath; +#else #ifdef _WIN32 _rPath = "ODBC32.DLL"; #endif @@ -112,7 +114,7 @@ bool LoadLibrary_ODBC3(OUString &_rPath) if ( !pODBCso ) pODBCso = osl_loadModule( _rPath.pData,SAL_LOADMODULE_NOW ); -#endif +#endif // DISABLE_DYNLOADING if( !pODBCso) return false; diff --git a/connectivity/source/drivers/odbc/OPreparedStatement.cxx b/connectivity/source/drivers/odbc/OPreparedStatement.cxx index 65cfbf5e7b5f..21baa12e45c1 100644 --- a/connectivity/source/drivers/odbc/OPreparedStatement.cxx +++ b/connectivity/source/drivers/odbc/OPreparedStatement.cxx @@ -40,9 +40,7 @@ using namespace connectivity; using namespace connectivity::odbc; using namespace com::sun::star::uno; using namespace com::sun::star::lang; -using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; -using namespace com::sun::star::sdbcx; using namespace com::sun::star::container; using namespace com::sun::star::io; using namespace com::sun::star::util; @@ -69,12 +67,12 @@ OPreparedStatement::~OPreparedStatement() { } -void SAL_CALL OPreparedStatement::acquire() throw() +void SAL_CALL OPreparedStatement::acquire() noexcept { OStatement_BASE2::acquire(); } -void SAL_CALL OPreparedStatement::release() throw() +void SAL_CALL OPreparedStatement::release() noexcept { OStatement_BASE2::release(); } @@ -227,7 +225,7 @@ Reference< XConnection > SAL_CALL OPreparedStatement::getConnection( ) ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OStatement_BASE::rBHelper.bDisposed); - return Reference< XConnection >(m_pConnection.get()); + return m_pConnection; } @@ -491,7 +489,7 @@ void SAL_CALL OPreparedStatement::setLong( sal_Int32 parameterIndex, sal_Int64 x } catch(SQLException&) { - setString(parameterIndex, ORowSetValue(x)); + setString(parameterIndex, ORowSetValue(x).getString()); } } @@ -584,8 +582,7 @@ void SAL_CALL OPreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex, c { ORowSetValue aValue; aValue.fill(x); - // TODO: make sure that this calls the string overload - setParameter(parameterIndex, sqlType, scale, aValue); + setParameter(parameterIndex, sqlType, scale, aValue.getString()); } else setNull(parameterIndex,sqlType); @@ -910,13 +907,13 @@ void OPreparedStatement::checkParameterIndex(sal_Int32 _parameterIndex) )); SQLException aNext(sError,*this, OUString(),0,Any()); - ::dbtools::throwInvalidIndexException(*this,makeAny(aNext)); + ::dbtools::throwInvalidIndexException(*this,Any(aNext)); } } -OResultSet* OPreparedStatement::createResulSet() +rtl::Reference<OResultSet> OPreparedStatement::createResultSet() { - OResultSet* pReturn = new OResultSet(m_aStatementHandle,this); + rtl::Reference<OResultSet> pReturn = new OResultSet(m_aStatementHandle,this); pReturn->setMetaData(getMetaData()); return pReturn; } diff --git a/connectivity/source/drivers/odbc/ORealDriver.cxx b/connectivity/source/drivers/odbc/ORealDriver.cxx index 47576954a8f2..28c054b45f7c 100644 --- a/connectivity/source/drivers/odbc/ORealDriver.cxx +++ b/connectivity/source/drivers/odbc/ORealDriver.cxx @@ -17,7 +17,6 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include "ORealDriver.hxx" #include <odbc/ODriver.hxx> #include <odbc/OTools.hxx> #include <odbc/OFunctions.hxx> @@ -32,7 +31,7 @@ namespace connectivity::odbc virtual oslGenericFunction getOdbcFunction(ODBC3SQLFunctionId _nIndex) const override; virtual SQLHANDLE EnvironmentHandle(OUString &_rPath) override; public: - explicit ORealOdbcDriver(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory) : ODBCDriver(_rxFactory) {} + explicit ORealOdbcDriver(const css::uno::Reference< css::uno::XComponentContext >& _rxContext) : ODBCDriver(_rxContext) {} }; } @@ -259,11 +258,6 @@ oslGenericFunction ORealOdbcDriver::getOdbcFunction(ODBC3SQLFunctionId _nIndex) } -css::uno::Reference< css::uno::XInterface > ODBCDriver_CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory) -{ - return *(new ORealOdbcDriver(_rxFactory)); -} - // ODBC Environment (common for all Connections): SQLHANDLE ORealOdbcDriver::EnvironmentHandle(OUString &_rPath) { @@ -286,7 +280,12 @@ SQLHANDLE ORealOdbcDriver::EnvironmentHandle(OUString &_rPath) return m_pDriverHandle; } - } +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +connectivity_odbc_ORealOdbcDriver_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&) +{ + return cppu::acquire(new connectivity::odbc::ORealOdbcDriver(context)); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/odbc/ORealDriver.hxx b/connectivity/source/drivers/odbc/ORealDriver.hxx deleted file mode 100644 index cfecb38936d2..000000000000 --- a/connectivity/source/drivers/odbc/ORealDriver.hxx +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- 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 . - */ - -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_ODBC_OREALDRIVER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_ODBC_OREALDRIVER_HXX - -#include <sal/config.h> - -#include <com/sun/star/uno/Reference.hxx> - -namespace com::sun::star { - namespace lang { class XMultiServiceFactory; } - namespace uno { class XInterface; } -} - -namespace connectivity::odbc { - -/// @throws css::uno::Exception -css::uno::Reference< css::uno::XInterface > -ODBCDriver_CreateInstance( css::uno::Reference< css::lang::XMultiServiceFactory > const & factory); - -} - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/odbc/OResultSet.cxx b/connectivity/source/drivers/odbc/OResultSet.cxx index 61e5caecfa77..9e68cd1763c2 100644 --- a/connectivity/source/drivers/odbc/OResultSet.cxx +++ b/connectivity/source/drivers/odbc/OResultSet.cxx @@ -104,10 +104,10 @@ OResultSet::OResultSet(SQLHANDLE _pStatementHandle ,OStatement_Base* pStmt) : catch(const Exception&) { // we don't want our result destroy here } - SQLULEN nCurType = 0; + try { - nCurType = getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_TYPE); + SQLULEN nCurType = getStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_CURSOR_TYPE); SQLUINTEGER nValueLen = m_pStatement->getCursorProperties(nCurType,false); if( (nValueLen & SQL_CA2_SENSITIVITY_DELETIONS) != SQL_CA2_SENSITIVITY_DELETIONS || (nValueLen & SQL_CA2_CRC_EXACT) != SQL_CA2_CRC_EXACT) @@ -443,8 +443,33 @@ template < typename T > T OResultSet::getValue( sal_Int32 columnIndex ) checkDisposed(OResultSet_BASE::rBHelper.bDisposed); fillColumn(columnIndex); m_bWasNull = m_aRow[columnIndex].isNull(); - return m_aRow[columnIndex]; + auto const & row = m_aRow[columnIndex]; + if constexpr ( std::is_same_v<css::util::Time, T> ) + return row.getTime(); + else if constexpr ( std::is_same_v<css::util::DateTime, T> ) + return row.getDateTime(); + else if constexpr ( std::is_same_v<css::util::Date, T> ) + return row.getDate(); + else if constexpr ( std::is_same_v<OUString, T> ) + return row.getString(); + else if constexpr ( std::is_same_v<sal_Int64, T> ) + return row.getLong(); + else if constexpr ( std::is_same_v<sal_Int32, T> ) + return row.getInt32(); + else if constexpr ( std::is_same_v<sal_Int16, T> ) + return row.getInt16(); + else if constexpr ( std::is_same_v<sal_Int8, T> ) + return row.getInt8(); + else if constexpr ( std::is_same_v<float, T> ) + return row.getFloat(); + else if constexpr ( std::is_same_v<double, T> ) + return row.getDouble(); + else if constexpr ( std::is_same_v<bool, T> ) + return row.getBool(); + else + return row; } + sal_Bool SAL_CALL OResultSet::getBoolean( sal_Int32 columnIndex ) { return getValue<bool>( columnIndex ); @@ -469,7 +494,7 @@ Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes( sal_Int32 columnIndex ) case DataType::BINARY: case DataType::VARBINARY: case DataType::LONGVARBINARY: - nRet = m_aRow[columnIndex]; + nRet = m_aRow[columnIndex].getSequence(); break; default: { @@ -866,7 +891,7 @@ void SAL_CALL OResultSet::insertRow( ) if(m_pSkipDeletedSet) { - if(moveToBookmark(makeAny(aBookmark))) + if(moveToBookmark(Any(aBookmark))) { sal_Int32 nRowPos = getDriverPos(); if ( -1 == m_nRowPos ) @@ -1378,28 +1403,47 @@ void OResultSet::setFetchSize(sal_Int32 _par0) IPropertyArrayHelper* OResultSet::createArrayHelper( ) const { - Sequence< Property > aProps(6); - Property* pProperties = aProps.getArray(); - sal_Int32 nPos = 0; - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), - PROPERTY_ID_CURSORNAME, cppu::UnoType<OUString>::get(), PropertyAttribute::READONLY); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), - PROPERTY_ID_FETCHDIRECTION, cppu::UnoType<sal_Int32>::get(), 0); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), - PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE), - PROPERTY_ID_ISBOOKMARKABLE, cppu::UnoType<bool>::get(), PropertyAttribute::READONLY); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), - PROPERTY_ID_RESULTSETCONCURRENCY, cppu::UnoType<sal_Int32>::get(), PropertyAttribute::READONLY); - - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), - PROPERTY_ID_RESULTSETTYPE, cppu::UnoType<sal_Int32>::get(), PropertyAttribute::READONLY); - - return new OPropertyArrayHelper(aProps); + return new OPropertyArrayHelper + { + { + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), + PROPERTY_ID_CURSORNAME, + cppu::UnoType<OUString>::get(), + PropertyAttribute::READONLY + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), + PROPERTY_ID_FETCHDIRECTION, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), + PROPERTY_ID_FETCHSIZE, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE), + PROPERTY_ID_ISBOOKMARKABLE, + cppu::UnoType<bool>::get(), + PropertyAttribute::READONLY + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), + PROPERTY_ID_RESULTSETCONCURRENCY, + cppu::UnoType<sal_Int32>::get(), + PropertyAttribute::READONLY + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), + PROPERTY_ID_RESULTSETTYPE, + cppu::UnoType<sal_Int32>::get(), + PropertyAttribute::READONLY + } + } + }; } IPropertyArrayHelper & OResultSet::getInfoHelper() @@ -1599,12 +1643,12 @@ void OResultSet::fillColumn(const sal_Int32 _nColumn) } } -void SAL_CALL OResultSet::acquire() throw() +void SAL_CALL OResultSet::acquire() noexcept { OResultSet_BASE::acquire(); } -void SAL_CALL OResultSet::release() throw() +void SAL_CALL OResultSet::release() noexcept { OResultSet_BASE::release(); } @@ -1642,7 +1686,7 @@ bool OResultSet::move(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nO TBookmarkPosMap::const_iterator aIter = std::find_if(m_aPosToBookmarks.begin(), m_aPosToBookmarks.end(), [&_nOffset](const TBookmarkPosMap::value_type& rEntry) { return rEntry.second == _nOffset; }); if (aIter != m_aPosToBookmarks.end()) - return moveToBookmark(makeAny(aIter->first)); + return moveToBookmark(Any(aIter->first)); SAL_WARN( "connectivity.odbc", "Bookmark not found!"); } return false; @@ -1764,7 +1808,7 @@ void OResultSet::fillNeededData(SQLRETURN _nRet) case DataType::VARBINARY: case DataType::LONGVARBINARY: case DataType::BLOB: - aSeq = m_aRow[nColumnIndex]; + aSeq = m_aRow[nColumnIndex].getSequence(); N3SQLPutData (m_aStatementHandle, aSeq.getArray(), aSeq.getLength()); break; case SQL_WLONGVARCHAR: diff --git a/connectivity/source/drivers/odbc/OResultSetMetaData.cxx b/connectivity/source/drivers/odbc/OResultSetMetaData.cxx index 21b95c6a7b29..f71e77d19c81 100644 --- a/connectivity/source/drivers/odbc/OResultSetMetaData.cxx +++ b/connectivity/source/drivers/odbc/OResultSetMetaData.cxx @@ -22,7 +22,6 @@ using namespace connectivity::odbc; using namespace com::sun::star::uno; -using namespace com::sun::star::lang; using namespace com::sun::star::sdbc; diff --git a/connectivity/source/drivers/odbc/OStatement.cxx b/connectivity/source/drivers/odbc/OStatement.cxx index 6e0a37169064..d8b5d6ce75de 100644 --- a/connectivity/source/drivers/odbc/OStatement.cxx +++ b/connectivity/source/drivers/odbc/OStatement.cxx @@ -49,9 +49,7 @@ using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; -using namespace com::sun::star::sdbcx; using namespace com::sun::star::container; -using namespace com::sun::star::io; using namespace com::sun::star::util; OStatement_Base::OStatement_Base(OConnection* _pConnection ) @@ -131,9 +129,10 @@ Sequence< Type > SAL_CALL OStatement_Base::getTypes( ) Sequence< Type > aOldTypes = OStatement_BASE::getTypes(); if ( m_pConnection.is() && !m_pConnection->isAutoRetrievingEnabled() ) { - auto newEnd = std::remove(aOldTypes.begin(), aOldTypes.end(), + auto [begin, end] = asNonConstRange(aOldTypes); + auto newEnd = std::remove(begin, end, cppu::UnoType<XGeneratedResultSet>::get()); - aOldTypes.realloc(std::distance(aOldTypes.begin(), newEnd)); + aOldTypes.realloc(std::distance(begin, newEnd)); } return ::comphelper::concatSequences(aTypes.getTypes(),aOldTypes); @@ -319,7 +318,6 @@ sal_Bool SAL_CALL OStatement_Base::execute( const OUString& sql ) OString aSql(OUStringToOString(sql,getOwnConnection()->getTextEncoding())); bool hasResultSet = false; - SQLWarning aWarning; // Reset the statement handle and warning @@ -336,12 +334,10 @@ sal_Bool SAL_CALL OStatement_Base::execute( const OUString& sql ) try { THROW_SQL(N3SQLExecDirect(m_aStatementHandle, reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(aSql.getStr())), aSql.getLength())); } - catch (const SQLWarning& ex) { + catch (const SQLWarning&) { - // Save pointer to warning and save with ResultSet + //TODO: Save pointer to warning and save with ResultSet // object once it is created. - - aWarning = ex; } // Now determine if there is a result set associated with @@ -372,7 +368,7 @@ Reference< XResultSet > OStatement_Base::getResultSet(bool checkCount) ::dbtools::throwFunctionSequenceException(*this); } - OResultSet* pRs = nullptr; + rtl::Reference<OResultSet> pRs; sal_Int32 numCols = 1; // If we already know we have result columns, checkCount @@ -387,7 +383,7 @@ Reference< XResultSet > OStatement_Base::getResultSet(bool checkCount) if (numCols > 0) { OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); - pRs = createResulSet(); + pRs = createResultSet(); pRs->construct(); // Save a copy of our last result set @@ -449,7 +445,7 @@ Reference< XConnection > SAL_CALL OStatement_Base::getConnection( ) ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OStatement_BASE::rBHelper.bDisposed); - return Reference< XConnection >(m_pConnection.get()); + return m_pConnection; } @@ -479,8 +475,8 @@ Sequence< sal_Int32 > SAL_CALL OStatement::executeBatch( ) for (auto const& elem : m_aBatchVector) { - aBatchSql.append(OUStringToOString(elem,getOwnConnection()->getTextEncoding())); - aBatchSql.append(";"); + aBatchSql.append(OUStringToOString(elem,getOwnConnection()->getTextEncoding()) + + ";"); } OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); @@ -617,7 +613,7 @@ Any SAL_CALL OStatement_Base::getWarnings( ) checkDisposed(OStatement_BASE::rBHelper.bDisposed); - return makeAny(m_aLastWarning); + return Any(m_aLastWarning); } @@ -833,7 +829,7 @@ void OStatement_Base::setMaxFieldSize(sal_Int64 _par0) setStmtOption<SQLULEN, SQL_IS_UINTEGER>(SQL_ATTR_MAX_LENGTH, _par0); } -void OStatement_Base::setCursorName(const OUString &_par0) +void OStatement_Base::setCursorName(std::u16string_view _par0) { OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!"); OString aName(OUStringToOString(_par0,getOwnConnection()->getTextEncoding())); @@ -861,31 +857,71 @@ void OStatement_Base::setUsingBookmarks(bool _bUseBookmark) ::cppu::IPropertyArrayHelper* OStatement_Base::createArrayHelper( ) const { - Sequence< Property > aProps(10); - Property* pProperties = aProps.getArray(); - sal_Int32 nPos = 0; - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), - PROPERTY_ID_CURSORNAME, cppu::UnoType<OUString>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ESCAPEPROCESSING), - PROPERTY_ID_ESCAPEPROCESSING, cppu::UnoType<bool>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), - PROPERTY_ID_FETCHDIRECTION, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), - PROPERTY_ID_FETCHSIZE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXFIELDSIZE), - PROPERTY_ID_MAXFIELDSIZE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXROWS), - PROPERTY_ID_MAXROWS, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_QUERYTIMEOUT), - PROPERTY_ID_QUERYTIMEOUT, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), - PROPERTY_ID_RESULTSETCONCURRENCY, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), - PROPERTY_ID_RESULTSETTYPE, cppu::UnoType<sal_Int32>::get(), 0); - pProperties[nPos++] = css::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_USEBOOKMARKS), - PROPERTY_ID_USEBOOKMARKS, cppu::UnoType<bool>::get(), 0); - - return new ::cppu::OPropertyArrayHelper(aProps); + return new ::cppu::OPropertyArrayHelper + { + { + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CURSORNAME), + PROPERTY_ID_CURSORNAME, + cppu::UnoType<OUString>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ESCAPEPROCESSING), + PROPERTY_ID_ESCAPEPROCESSING, + cppu::UnoType<bool>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), + PROPERTY_ID_FETCHDIRECTION, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), + PROPERTY_ID_FETCHSIZE, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXFIELDSIZE), + PROPERTY_ID_MAXFIELDSIZE, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_MAXROWS), + PROPERTY_ID_MAXROWS, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_QUERYTIMEOUT), + PROPERTY_ID_QUERYTIMEOUT, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), + PROPERTY_ID_RESULTSETCONCURRENCY, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), + PROPERTY_ID_RESULTSETTYPE, + cppu::UnoType<sal_Int32>::get(), + 0 + }, + { + ::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_USEBOOKMARKS), + PROPERTY_ID_USEBOOKMARKS, + cppu::UnoType<bool>::get(), + 0 + } + } + }; } @@ -1043,27 +1079,27 @@ void OStatement_Base::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbcx.OStatement","com.sun.star.sdbc.Statement"); -void SAL_CALL OStatement_Base::acquire() throw() +void SAL_CALL OStatement_Base::acquire() noexcept { OStatement_BASE::acquire(); } -void SAL_CALL OStatement_Base::release() throw() +void SAL_CALL OStatement_Base::release() noexcept { OStatement_BASE::release(); } -void SAL_CALL OStatement::acquire() throw() +void SAL_CALL OStatement::acquire() noexcept { OStatement_BASE2::acquire(); } -void SAL_CALL OStatement::release() throw() +void SAL_CALL OStatement::release() noexcept { OStatement_BASE2::release(); } -OResultSet* OStatement_Base::createResulSet() +rtl::Reference<OResultSet> OStatement_Base::createResultSet() { return new OResultSet(m_aStatementHandle,this); } diff --git a/connectivity/source/drivers/odbc/odbc.component b/connectivity/source/drivers/odbc/odbc.component index 4fa186ea2a0e..4d3348378bc9 100644 --- a/connectivity/source/drivers/odbc/odbc.component +++ b/connectivity/source/drivers/odbc/odbc.component @@ -18,8 +18,9 @@ --> <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" - prefix="odbc" xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="com.sun.star.comp.sdbc.ODBCDriver"> + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.comp.sdbc.ODBCDriver" + constructor="connectivity_odbc_ORealOdbcDriver_get_implementation"> <service name="com.sun.star.sdbc.Driver"/> </implementation> </component> diff --git a/connectivity/source/drivers/odbc/oservices.cxx b/connectivity/source/drivers/odbc/oservices.cxx deleted file mode 100644 index 6461f8dde48f..000000000000 --- a/connectivity/source/drivers/odbc/oservices.cxx +++ /dev/null @@ -1,108 +0,0 @@ -/* -*- 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 . - */ - -#include "ORealDriver.hxx" -#include <odbc/ODriver.hxx> -#include <cppuhelper/factory.hxx> -#include <com/sun/star/lang/XSingleServiceFactory.hpp> - -using namespace connectivity::odbc; -using ::com::sun::star::uno::Reference; -using ::com::sun::star::uno::Sequence; -using ::com::sun::star::lang::XSingleServiceFactory; -using ::com::sun::star::lang::XMultiServiceFactory; - -typedef Reference< XSingleServiceFactory > (*createFactoryFunc) - ( - const Reference< XMultiServiceFactory > & rServiceManager, - const OUString & rComponentName, - ::cppu::ComponentInstantiation pCreateFunction, - const Sequence< OUString > & rServiceNames, - rtl_ModuleCount* - ); - -namespace { - -struct ProviderRequest -{ - Reference< XSingleServiceFactory > xRet; - Reference< XMultiServiceFactory > const xServiceManager; - OUString const sImplementationName; - - ProviderRequest( - void* pServiceManager, - char const* pImplementationName - ) - : xServiceManager(static_cast<XMultiServiceFactory*>(pServiceManager)) - , sImplementationName(OUString::createFromAscii(pImplementationName)) - { - } - - bool CREATE_PROVIDER( - const OUString& Implname, - const Sequence< OUString > & Services, - ::cppu::ComponentInstantiation Factory, - createFactoryFunc creator - ) - { - if (!xRet.is() && (Implname == sImplementationName)) - { - try - { - xRet = creator( xServiceManager, sImplementationName,Factory, Services,nullptr); - } - catch(...) - { - } - } - return xRet.is(); - } - - void* getProvider() const { return xRet.get(); } -}; - -} - -extern "C" SAL_DLLPUBLIC_EXPORT void* odbc_component_getFactory( - const char* pImplementationName, - void* pServiceManager, - void* /*pRegistryKey*/) -{ - void* pRet = nullptr; - if (pServiceManager) - { - ProviderRequest aReq(pServiceManager,pImplementationName); - - aReq.CREATE_PROVIDER( - ODBCDriver::getImplementationName_Static(), - ODBCDriver::getSupportedServiceNames_Static(), - ODBCDriver_CreateInstance, ::cppu::createSingleFactory) - ; - - if(aReq.xRet.is()) - aReq.xRet->acquire(); - - pRet = aReq.getProvider(); - } - - return pRet; -}; - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/postgresql-sdbc.component b/connectivity/source/drivers/postgresql/postgresql-sdbc.component index 0a10aa77b826..a14ab2c96fea 100644 --- a/connectivity/source/drivers/postgresql/postgresql-sdbc.component +++ b/connectivity/source/drivers/postgresql/postgresql-sdbc.component @@ -11,7 +11,7 @@ <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" xmlns="http://openoffice.org/2010/uno-components"> <implementation name="org.openoffice.comp.connectivity.pq.Driver.noext" - constructor="connectivity_pq_sdbc_driver_get_implementation"> + constructor="connectivity_pq_sdbc_driver_get_implementation" single-instance="true"> <service name="com.sun.star.sdbc.Driver"/> </implementation> </component> diff --git a/connectivity/source/drivers/postgresql/pq_array.cxx b/connectivity/source/drivers/postgresql/pq_array.cxx index 5ae646f230e3..841ed70c6cb2 100644 --- a/connectivity/source/drivers/postgresql/pq_array.cxx +++ b/connectivity/source/drivers/postgresql/pq_array.cxx @@ -100,7 +100,7 @@ css::uno::Reference< css::sdbc::XResultSet > Array::getResultSetAtIndex( } return new SequenceResultSet( - m_xMutex, m_owner, getStatics().resultSetArrayColumnNames, ret, m_tc ); + m_xMutex, m_owner, std::vector(getStatics().resultSetArrayColumnNames), std::move(ret), m_tc ); } diff --git a/connectivity/source/drivers/postgresql/pq_array.hxx b/connectivity/source/drivers/postgresql/pq_array.hxx index c0ed6aa97efd..589fe063d234 100644 --- a/connectivity/source/drivers/postgresql/pq_array.hxx +++ b/connectivity/source/drivers/postgresql/pq_array.hxx @@ -34,12 +34,12 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_ARRAY_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_ARRAY_HXX +#pragma once #include <cppuhelper/implbase.hxx> #include <com/sun/star/sdbc/XArray.hpp> #include "pq_connection.hxx" +#include <utility> #include <vector> namespace pq_sdbc_driver @@ -54,14 +54,14 @@ class Array : public cppu::WeakImplHelper< css::sdbc::XArray > public: Array( - const rtl::Reference< comphelper::RefCountedMutex > & mutex, - const std::vector< css::uno::Any > & data, - const css::uno::Reference< css::uno::XInterface > & owner, - const css::uno::Reference< css::script::XTypeConverter > &tc) : - m_data( data ), - m_owner( owner ), - m_tc( tc ), - m_xMutex( mutex ) + rtl::Reference< comphelper::RefCountedMutex > mutex, + std::vector< css::uno::Any > && data, + css::uno::Reference< css::uno::XInterface > owner, + css::uno::Reference< css::script::XTypeConverter > tc) : + m_data( std::move(data) ), + m_owner(std::move( owner )), + m_tc(std::move( tc )), + m_xMutex(std::move( mutex )) {} public: // XArray @@ -95,6 +95,4 @@ private: }; -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_baseresultset.cxx b/connectivity/source/drivers/postgresql/pq_baseresultset.cxx index 8fc7140e4817..9ff5e01e098a 100644 --- a/connectivity/source/drivers/postgresql/pq_baseresultset.cxx +++ b/connectivity/source/drivers/postgresql/pq_baseresultset.cxx @@ -456,7 +456,7 @@ Sequence< sal_Int8 > BaseResultSet::getBytes( sal_Int32 columnIndex ) char * res = reinterpret_cast<char*>(PQunescapeBytea( reinterpret_cast<unsigned char const *>(val.getStr()), &length)); ret = Sequence< sal_Int8 > ( reinterpret_cast<sal_Int8*>(res), length ); if( res ) - free( res ); + PQfreemem( res ); } return ret; } diff --git a/connectivity/source/drivers/postgresql/pq_baseresultset.hxx b/connectivity/source/drivers/postgresql/pq_baseresultset.hxx index 8b062ddf9ac0..90e6609a0860 100644 --- a/connectivity/source/drivers/postgresql/pq_baseresultset.hxx +++ b/connectivity/source/drivers/postgresql/pq_baseresultset.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_BASERESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_BASERESULTSET_HXX +#pragma once #include <cppuhelper/propshlp.hxx> #include <cppuhelper/component.hxx> @@ -104,8 +103,8 @@ protected: virtual ~BaseResultSet() override; public: // XInterface - virtual void SAL_CALL acquire() throw() override { BaseResultSet_BASE::acquire(); } - virtual void SAL_CALL release() throw() override { BaseResultSet_BASE::release(); } + virtual void SAL_CALL acquire() noexcept override { BaseResultSet_BASE::acquire(); } + virtual void SAL_CALL release() noexcept override { BaseResultSet_BASE::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -200,6 +199,5 @@ public: // OComponentHelper }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_connection.cxx b/connectivity/source/drivers/postgresql/pq_connection.cxx index b0521d0a83a7..091479f87f95 100644 --- a/connectivity/source/drivers/postgresql/pq_connection.cxx +++ b/connectivity/source/drivers/postgresql/pq_connection.cxx @@ -34,27 +34,25 @@ * ************************************************************************/ +#include <utility> #include <vector> -#include <time.h> #include <string.h> #include <memory> #include "pq_connection.hxx" #include "pq_statement.hxx" +#include "pq_tools.hxx" #include "pq_preparedstatement.hxx" #include "pq_databasemetadata.hxx" #include "pq_xtables.hxx" #include "pq_xviews.hxx" #include "pq_xusers.hxx" +#include <rtl/ref.hxx> #include <rtl/uuid.h> -#include <rtl/bootstrap.hxx> #include <sal/log.hxx> -#include <o3tl/enumarray.hxx> -#include <osl/module.h> -#include <cppuhelper/implementationentry.hxx> #include <cppuhelper/implbase.hxx> #include <com/sun/star/beans/PropertyValue.hpp> @@ -99,8 +97,8 @@ class ClosableReference : public cppu::WeakImplHelper< css::uno::XReference > rtl::Reference<Connection> m_conn; ::rtl::ByteSequence m_id; public: - ClosableReference( const ::rtl::ByteSequence & id , Connection *that ) - : m_conn( that ), m_id( id ) + ClosableReference( ::rtl::ByteSequence id , Connection *that ) + : m_conn( that ), m_id(std::move( id )) { } @@ -118,9 +116,9 @@ public: Connection::Connection( const rtl::Reference< comphelper::RefCountedMutex > &refMutex, - const css::uno::Reference< css::uno::XComponentContext > & ctx ) + css::uno::Reference< css::uno::XComponentContext > ctx ) : ConnectionBase( refMutex->GetMutex() ), - m_ctx( ctx ) , + m_ctx(std::move( ctx )) , m_xMutex( refMutex ) { } @@ -133,14 +131,11 @@ Connection::~Connection() m_settings.pConnection = nullptr; } } -typedef std::vector< css::uno::Reference< css::sdbc::XCloseable > > CloseableVector; - -typedef std::vector< css::uno::Reference< css::lang::XComponent > > DisposeableVector; void Connection::close() { - CloseableVector vectorCloseable; - DisposeableVector vectorDispose; + std::vector< css::uno::Reference< css::sdbc::XCloseable > > vectorCloseable; + std::vector< css::uno::Reference< css::lang::XComponent > > vectorDispose; { MutexGuard guard( m_xMutex->GetMutex() ); // silently ignore, if the connection has been closed already @@ -193,13 +188,12 @@ Reference< XStatement > Connection::createStatement() MutexGuard guard( m_xMutex->GetMutex() ); checkClosed(); - Statement *stmt = new Statement( m_xMutex, this , &m_settings ); - Reference< XStatement > ret( stmt ); + rtl::Reference<Statement> stmt = new Statement( m_xMutex, this , &m_settings ); ::rtl::ByteSequence id( 16 ); rtl_createUuid( reinterpret_cast<sal_uInt8*>(id.getArray()), nullptr, false ); m_myStatements[ id ] = Reference< XCloseable > ( stmt ); stmt->queryAdapter()->addReference( new ClosableReference( id, this ) ); - return ret; + return stmt; } Reference< XPreparedStatement > Connection::prepareStatement( const OUString& sql ) @@ -208,14 +202,14 @@ Reference< XPreparedStatement > Connection::prepareStatement( const OUString& sq checkClosed(); OString byteSql = OUStringToOString( sql, ConnectionSettings::encoding ); - PreparedStatement *stmt = new PreparedStatement( m_xMutex, this, &m_settings, byteSql ); - Reference< XPreparedStatement > ret = stmt; + rtl::Reference<PreparedStatement> stmt + = new PreparedStatement( m_xMutex, this, &m_settings, byteSql ); ::rtl::ByteSequence id( 16 ); rtl_createUuid( reinterpret_cast<sal_uInt8*>(id.getArray()), nullptr, false ); m_myStatements[ id ] = Reference< XCloseable > ( stmt ); stmt->queryAdapter()->addReference( new ClosableReference( id, this ) ); - return ret; + return stmt; } Reference< XPreparedStatement > Connection::prepareCall( const OUString& ) @@ -337,7 +331,15 @@ class cstr_vector std::vector<char*> values; std::vector<bool> acquired; public: - cstr_vector () : values(), acquired() { values.reserve(8); acquired.reserve(8); } +#if defined __GNUC__ && !defined __clang__ && __GNUC__ == 14 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" +#pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif + cstr_vector () { values.reserve(8); acquired.reserve(8); } +#if defined __GNUC__ && !defined __clang__ && __GNUC__ == 14 +#pragma GCC diagnostic pop +#endif ~cstr_vector () { OSL_ENSURE(values.size() == acquired.size(), "pq_connection: cstr_vector values and acquired size mismatch"); @@ -451,7 +453,7 @@ void Connection::initialize( const Sequence< Any >& aArguments ) nColon = url.indexOf( ':' , 1+ nColon ); if( nColon != -1 ) { - o = OUStringToOString( url.getStr()+nColon+1, ConnectionSettings::encoding ); + o = rtl::OUStringToOString( url.subView(nColon+1), ConnectionSettings::encoding ); } } { @@ -461,14 +463,15 @@ void Connection::initialize( const Sequence< Any >& aArguments ) if ( o.getLength() > 0 ) { char *err; - std::shared_ptr<PQconninfoOption> oOpts(PQconninfoParse(o.getStr(), &err), PQconninfoFree); + const std::unique_ptr<PQconninfoOption, deleter_from_fn<PQconninfoFree>> + oOpts(PQconninfoParse(o.getStr(), &err)); if (oOpts == nullptr) { OUString errorMessage; if ( err != nullptr) { errorMessage = OUString( err, strlen(err), ConnectionSettings::encoding ); - free(err); + PQfreemem(err); } else errorMessage = "#no error message#"; diff --git a/connectivity/source/drivers/postgresql/pq_connection.hxx b/connectivity/source/drivers/postgresql/pq_connection.hxx index f8d19c406b18..2bba070a7273 100644 --- a/connectivity/source/drivers/postgresql/pq_connection.hxx +++ b/connectivity/source/drivers/postgresql/pq_connection.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_CONNECTION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_CONNECTION_HXX +#pragma once #include <config_lgpl.h> #include <com/sun/star/uno/XComponentContext.hpp> @@ -61,19 +60,18 @@ #include <libpq-fe.h> #include <unordered_map> +#include "pq_xtables.hxx" +#include "pq_xviews.hxx" + namespace pq_sdbc_driver { struct ConnectionSettings; -class Tables; -class Views; struct ConnectionSettings { ConnectionSettings() : pConnection(nullptr), maxNameLen(0), - maxIndexKeys(0), - pTablesImpl(nullptr), - pViewsImpl(nullptr) + maxIndexKeys(0) {} static const rtl_TextEncoding encoding = RTL_TEXTENCODING_UTF8; PGconn *pConnection; @@ -83,8 +81,8 @@ struct ConnectionSettings css::uno::Reference< css::container::XNameAccess > tables; css::uno::Reference< css::container::XNameAccess > users; css::uno::Reference< css::container::XNameAccess > views; - Tables *pTablesImpl; // needed to implement renaming of tables / views - Views *pViewsImpl; // needed to implement renaming of tables / views + rtl::Reference<Tables> pTablesImpl; // needed to implement renaming of tables / views + rtl::Reference<Views> pViewsImpl; // needed to implement renaming of tables / views OUString user; OUString catalog; }; @@ -136,7 +134,7 @@ private: public: Connection( const rtl::Reference< comphelper::RefCountedMutex > &refMutex, - const css::uno::Reference< css::uno::XComponentContext > & ctx ); + css::uno::Reference< css::uno::XComponentContext > ctx ); virtual ~Connection( ) override; @@ -192,6 +190,5 @@ public: // helper function }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx b/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx index 4794d21e8c7b..1fbcb1aa69f5 100644 --- a/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx +++ b/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx @@ -65,6 +65,8 @@ ************************************************************************/ #include <algorithm> +#include <string_view> + #include <sal/log.hxx> #include "pq_databasemetadata.hxx" #include "pq_driver.hxx" @@ -72,6 +74,7 @@ #include "pq_statics.hxx" #include "pq_tools.hxx" +#include <o3tl/string_view.hxx> #include <rtl/ustrbuf.hxx> #include <sal/macros.h> #include <com/sun/star/sdbc/TransactionIsolation.hpp> @@ -81,6 +84,7 @@ #include <com/sun/star/sdbc/IndexType.hpp> #include <com/sun/star/sdbc/ColumnValue.hpp> #include <com/sun/star/sdbc/ColumnSearch.hpp> +#include <utility> using ::osl::MutexGuard; @@ -111,12 +115,12 @@ namespace pq_sdbc_driver #define DEFERRABILITY_NONE 7 DatabaseMetaData::DatabaseMetaData( - const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, - const css::uno::Reference< css::sdbc::XConnection > & origin, + ::rtl::Reference< comphelper::RefCountedMutex > refMutex, + css::uno::Reference< css::sdbc::XConnection > origin, ConnectionSettings *pSettings ) - : m_xMutex( refMutex ), + : m_xMutex(std::move( refMutex )), m_pSettings( pSettings ), - m_origin( origin ), + m_origin(std::move( origin )), m_getIntSetting_stmt ( m_origin->prepareStatement("SELECT setting FROM pg_catalog.pg_settings WHERE name=?") ) { init_getReferences_stmt(); @@ -207,10 +211,10 @@ sal_Int32 DatabaseMetaData::getDriverMinorVersion( ) sal_Bool DatabaseMetaData::usesLocalFiles( ) { // LEM TODO: - // http://wiki.openoffice.org/wiki/Documentation/DevGuide/Database/XDatabaseMetaData_Interface + // https://wiki.documentfoundation.org/Documentation/DevGuide/Database_Access#XDatabaseMetaData_Interface // says "Returns true when the catalog name of the // database should not appear in the DatasourceBrowser - // of OpenOffice.org API, otherwise false is returned." + // of LibreOffice API, otherwise false is returned." // So, hmmm, think about it. return false; } @@ -307,8 +311,8 @@ OUString DatabaseMetaData::getSQLKeywords( ) } OUString DatabaseMetaData::getNumericFunctions( ) { - // See http://www.postgresql.org/docs/9.1/static/functions-math.html - // LEM TODO: Err... http://wiki.openoffice.org/wiki/Documentation/DevGuide/Database/Support_Scalar_Functions + // See https://www.postgresql.org/docs/9.1/static/functions-math.html + // LEM TODO: Err... https://wiki.documentfoundation.org/Documentation/DevGuide/Database_Access#Support_Scalar_Functions // says this should be "Open Group CLI" names, not PostgreSQL names. // Currently this is just a list of supported functions in PostgreSQL, with PostgreSQL names. // And it is my job to map from Open Group CLI names/syntax to PostgreSQL names/syntax. Where? By parsing the SQL??? @@ -1176,46 +1180,46 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getTables( closeable->close(); return new SequenceResultSet( - m_xMutex, *this, statics.tablesRowNames, vec, m_pSettings->tc ); + m_xMutex, *this, std::vector(statics.tablesRowNames), std::move(vec), m_pSettings->tc ); } namespace { // sort no schema first, then "public", then normal schemas, then internal schemas - int compare_schema(const OUString &nsA, const OUString &nsB) + int compare_schema(std::u16string_view nsA, std::u16string_view nsB) { - if (nsA.isEmpty()) + if (nsA.empty()) { - return nsB.isEmpty() ? 0 : -1; + return nsB.empty() ? 0 : -1; } - else if (nsB.isEmpty()) + else if (nsB.empty()) { - assert(!nsA.isEmpty()); + assert(!nsA.empty()); return 1; } - else if(nsA == "public") + else if(nsA == u"public") { - return (nsB == "public") ? 0 : -1; + return (nsB == u"public") ? 0 : -1; } - else if(nsB == "public") + else if(nsB == u"public") { - assert(nsA != "public"); + assert(nsA != u"public"); return 1; } - else if(nsA.startsWith("pg_")) + else if(o3tl::starts_with(nsA, u"pg_")) { - if(nsB.startsWith("pg_")) - return nsA.compareTo(nsB); + if(o3tl::starts_with(nsB, u"pg_")) + return nsA.compare(nsB); else return 1; } - else if(nsB.startsWith("pg_")) + else if(o3tl::starts_with(nsB, u"pg_")) { return -1; } else { - return nsA.compareTo(nsB); + return nsA.compare(nsB); } } @@ -1227,7 +1231,7 @@ namespace OUString valueB; a[0] >>= valueA; b[0] >>= valueB; - return compare_schema(valueA, valueB); + return compare_schema(valueA, valueB) < 0; } }; } @@ -1249,9 +1253,7 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getSchemas( ) std::vector< std::vector<Any> > vec; while( rs->next() ) { - std::vector<Any> row(1); - row[0] <<= xRow->getString(1); - vec.push_back( row ); + vec.push_back( { Any(xRow->getString(1)) } ); } // sort public first, sort internal schemas last, sort rest in alphabetic order @@ -1261,7 +1263,7 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getSchemas( ) if( closeable.is() ) closeable->close(); return new SequenceResultSet( - m_xMutex, *this, getStatics().schemaNames, vec, m_pSettings->tc ); + m_xMutex, *this, std::vector(getStatics().schemaNames), std::move(vec), m_pSettings->tc ); } css::uno::Reference< XResultSet > DatabaseMetaData::getCatalogs( ) @@ -1278,21 +1280,21 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getTableTypes( ) // LEM TODO: this can be made dynamic, see JDBC driver MutexGuard guard( m_xMutex->GetMutex() ); return new SequenceResultSet( - m_xMutex, *this, getStatics().tableTypeNames, getStatics().tableTypeData, + m_xMutex, *this, std::vector(getStatics().tableTypeNames), std::vector(getStatics().tableTypeData), m_pSettings->tc ); } /** returns the constant from sdbc.DataType */ -sal_Int32 typeNameToDataType( const OUString &typeName, const OUString &typtype ) +sal_Int32 typeNameToDataType( const OUString &typeName, std::u16string_view typtype ) { // sal_Int32 ret = css::sdbc::DataType::DISTINCT; // map all unknown types to memo (longvarchar). This allows to show them in // string representation. Additionally, the edit-table-type-selection-box // is not so unusable anymore. sal_Int32 ret = css::sdbc::DataType::LONGVARCHAR; - if( typtype == "b" ) + if( typtype == u"b" ) { // as long as the OOo framework does not support arrays, // the user is better of with interpreting arrays as strings ! @@ -1310,11 +1312,11 @@ sal_Int32 typeNameToDataType( const OUString &typeName, const OUString &typtype ret = ii->second; } } - else if( typtype == "c" ) + else if( typtype == u"c" ) { ret = css::sdbc::DataType::STRUCT; } - else if( typtype == "d" ) + else if( typtype == u"d" ) { ret = css::sdbc::DataType::LONGVARCHAR; } @@ -1363,9 +1365,9 @@ namespace { { DatabaseTypeDescription() {} - DatabaseTypeDescription( const OUString &name, const OUString & type ) : - typeName( name ), - typeType( type ) + DatabaseTypeDescription( OUString name, OUString type ) : + typeName(std::move( name )), + typeType(std::move( type )) {} DatabaseTypeDescription( const DatabaseTypeDescription &source ) : typeName( source.typeName ), @@ -1404,8 +1406,7 @@ static void columnMetaData2DatabaseTypeDescription( oidMap[row->getInt(12)] = DatabaseTypeDescription(); if( domains ) queryBuf.append( " OR " ); - queryBuf.append( "oid = " ); - queryBuf.append( row->getInt(12 ) ); + queryBuf.append( "oid = " + OUString::number( row->getInt(12 ) ) ); domains ++; } } @@ -1598,7 +1599,7 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getColumns( closeable->close(); return new SequenceResultSet( - m_xMutex, *this, statics.columnRowNames, vec, m_pSettings->tc ); + m_xMutex, *this, std::vector(statics.columnRowNames), std::move(vec), m_pSettings->tc ); } css::uno::Reference< XResultSet > DatabaseMetaData::getColumnPrivileges( @@ -1781,7 +1782,7 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getPrimaryKeys( elements ++; } return new SequenceResultSet( - m_xMutex, *this, getStatics().primaryKeyNames, ret, m_pSettings->tc ); + m_xMutex, *this, std::vector(getStatics().primaryKeyNames), std::move(ret), m_pSettings->tc ); } // Copied / adapted / simplified from JDBC driver @@ -2085,45 +2086,45 @@ namespace OUString nameB; a[0 /*TYPE_NAME*/] >>= nameA; b[0 /*TYPE_NAME*/] >>= nameB; - OUString nsA, tnA, nsB, tnB; + std::u16string_view nsA, tnA, nsB, tnB; // parse typename into schema and typename sal_Int32 nIndex=0; - nsA = nameA.getToken(0, '.', nIndex); + nsA = o3tl::getToken(nameA, 0, '.', nIndex); if (nIndex<0) { tnA = nsA; - nsA.clear(); + nsA = std::u16string_view(); } else { - tnA = nameA.getToken(0, '.', nIndex); + tnA = o3tl::getToken(nameA, 0, '.', nIndex); assert(nIndex < 0); } nIndex=0; - nsB = nameB.getToken(0, '.', nIndex); + nsB = o3tl::getToken(nameB, 0, '.', nIndex); if (nIndex<0) { tnB = nsB; - nsB.clear(); + nsB = std::u16string_view(); } else { - tnB = nameB.getToken(0, '.', nIndex); + tnB = o3tl::getToken(nameB, 0, '.', nIndex); assert(nIndex < 0); } const int ns_comp = compare_schema(nsA, nsB); if(ns_comp == 0) { - if(nsA.isEmpty()) + if(nsA.empty()) { - assert(nsB.isEmpty()); + assert(nsB.empty()); // within each type category, sort privileged choice first - if( tnA == "int4" || tnA == "varchar" || tnA == "char" || tnA == "text") + if( tnA == u"int4" || tnA == u"varchar" || tnA == u"char" || tnA == u"text") return true; - if( tnB == "int4" || tnB == "varchar" || tnB == "char" || tnB == "text") + if( tnB == u"int4" || tnB == u"varchar" || tnB == u"char" || tnB == u"text") return false; } return nameA.compareTo( nameB ) < 0; @@ -2162,12 +2163,12 @@ namespace return ret; } - OUString construct_full_typename(const OUString &ns, const OUString &tn) + OUString construct_full_typename(std::u16string_view ns, const OUString &tn) { - if(ns.isEmpty() || ns == "pg_catalog") + if(ns.empty() || ns == u"pg_catalog") return tn; else - return ns + "." + tn; + return OUString::Concat(ns) + "." + tn; } void pgTypeInfo2ResultSet( @@ -2297,8 +2298,8 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getTypeInfo( ) return new SequenceResultSet( m_xMutex, *this, - getStatics().typeinfoColumnNames, - vec, + std::vector(getStatics().typeinfoColumnNames), + std::move(vec), m_pSettings->tc, &( getStatics().typeInfoMetaData )); } @@ -2338,7 +2339,7 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getIndexInfo( 11. CARDINALITY long -> When TYPE is tableIndexStatistic, then this is the number of rows in the table; otherwise, it is the number of unique values in the index. - 12. PAGES long -> When TYPE is tableIndexStatisic then this is + 12. PAGES long -> When TYPE is tableIndexStatistic then this is the number of pages used for the table, otherwise it is the number of pages used for the current index. 13. FILTER_CONDITION string -> Filter condition, if any. (may be NULL ) @@ -2422,8 +2423,8 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getIndexInfo( } } return new SequenceResultSet( - m_xMutex, *this, getStatics().indexinfoColumnNames, - vec, + m_xMutex, *this, std::vector(getStatics().indexinfoColumnNames), + std::move(vec), m_pSettings->tc ); } diff --git a/connectivity/source/drivers/postgresql/pq_databasemetadata.hxx b/connectivity/source/drivers/postgresql/pq_databasemetadata.hxx index c016886f2643..4e8b717a96b2 100644 --- a/connectivity/source/drivers/postgresql/pq_databasemetadata.hxx +++ b/connectivity/source/drivers/postgresql/pq_databasemetadata.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_DATABASEMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_DATABASEMETADATA_HXX +#pragma once #include "pq_connection.hxx" #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> @@ -75,8 +74,8 @@ class DatabaseMetaData : public: DatabaseMetaData( - const ::rtl::Reference< comphelper::RefCountedMutex > & reMutex, - const css::uno::Reference< css::sdbc::XConnection > & origin, + ::rtl::Reference< comphelper::RefCountedMutex > reMutex, + css::uno::Reference< css::sdbc::XConnection > origin, ConnectionSettings *pSettings ); @@ -235,6 +234,4 @@ public: } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_driver.cxx b/connectivity/source/drivers/postgresql/pq_driver.cxx index ff63e8226db9..8e07123a2b0f 100644 --- a/connectivity/source/drivers/postgresql/pq_driver.cxx +++ b/connectivity/source/drivers/postgresql/pq_driver.cxx @@ -34,23 +34,12 @@ * ************************************************************************/ -#include <comphelper/processfactory.hxx> -#include <cppuhelper/factory.hxx> -#include <cppuhelper/compbase.hxx> -#include <cppuhelper/implementationentry.hxx> #include <cppuhelper/supportsservice.hxx> +#include <cppuhelper/weak.hxx> #include <com/sun/star/lang/XSingleComponentFactory.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <rtl/ref.hxx> #include "pq_driver.hxx" -using osl::MutexGuard; - -using com::sun::star::lang::XSingleComponentFactory; -using com::sun::star::lang::XServiceInfo; -using com::sun::star::lang::XComponent; - using com::sun::star::uno::Sequence; using com::sun::star::uno::Reference; using com::sun::star::uno::XInterface; @@ -75,9 +64,7 @@ Reference< XConnection > Driver::connect( if( ! acceptsURL( url ) ) // XDriver spec tells me to do so ... return Reference< XConnection > (); - Sequence< Any > seq ( 2 ); - seq[0] <<= url; - seq[1] <<= info; + Sequence< Any > seq{ Any(url), Any(info) }; return Reference< XConnection> ( m_smgr->createInstanceWithArgumentsAndContext( "org.openoffice.comp.connectivity.pq.Connection.noext", @@ -148,10 +135,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* connectivity_pq_sdbc_driver_get_implementation( css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&) { - static rtl::Reference<pq_sdbc_driver::Driver> g_Driver(new pq_sdbc_driver::Driver(context)); - - g_Driver->acquire(); - return static_cast<cppu::OWeakObject*>(g_Driver.get()); + return cppu::acquire(new pq_sdbc_driver::Driver(context)); } diff --git a/connectivity/source/drivers/postgresql/pq_driver.hxx b/connectivity/source/drivers/postgresql/pq_driver.hxx index 3b61a7bcf269..31d407f36965 100644 --- a/connectivity/source/drivers/postgresql/pq_driver.hxx +++ b/connectivity/source/drivers/postgresql/pq_driver.hxx @@ -34,12 +34,11 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_DRIVER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_DRIVER_HXX +#pragma once -#include <osl/mutex.hxx> #include <sal/macros.h> #include <cppuhelper/compbase.hxx> +#include <cppuhelper/basemutex.hxx> #include <com/sun/star/lang/XServiceInfo.hpp> @@ -55,7 +54,6 @@ namespace pq_sdbc_driver SAL_STRINGIFY(PQ_SDBC_MINOR) "." \ SAL_STRINGIFY(PQ_SDBC_MICRO) -struct MutexHolder { osl::Mutex m_mutex; }; // use this to switch off sdbc support ! // typedef cppu::WeakComponentImplHelper< // css::sdbc::XDriver, @@ -65,14 +63,14 @@ typedef cppu::WeakComponentImplHelper< css::sdbc::XDriver, css::lang::XServiceInfo, css::sdbcx::XDataDefinitionSupplier > DriverBase ; -class Driver : public MutexHolder, public DriverBase +class Driver : public cppu::BaseMutex, public DriverBase { css::uno::Reference< css::uno::XComponentContext > m_ctx; css::uno::Reference< css::lang::XMultiComponentFactory > m_smgr; public: explicit Driver ( const css::uno::Reference < css::uno::XComponentContext > & ctx ) - : DriverBase( m_mutex ), + : DriverBase( m_aMutex ), m_ctx( ctx ), m_smgr( ctx->getServiceManager() ) {} @@ -115,6 +113,4 @@ public: } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_fakedupdateableresultset.cxx b/connectivity/source/drivers/postgresql/pq_fakedupdateableresultset.cxx index a75897ccb211..216a25220355 100644 --- a/connectivity/source/drivers/postgresql/pq_fakedupdateableresultset.cxx +++ b/connectivity/source/drivers/postgresql/pq_fakedupdateableresultset.cxx @@ -38,6 +38,7 @@ #include <com/sun/star/sdbc/SQLException.hpp> #include <cppuhelper/typeprovider.hxx> #include <cppuhelper/queryinterface.hxx> +#include <utility> using com::sun::star::uno::Sequence; @@ -58,9 +59,9 @@ FakedUpdateableResultSet::FakedUpdateableResultSet( PGresult *result, const OUString &schema, const OUString &table, - const OUString &aReason ) + OUString aReason ) : ResultSet( mutex, owner, pSettings, result, schema, table ), - m_aReason( aReason ) + m_aReason(std::move( aReason )) {} diff --git a/connectivity/source/drivers/postgresql/pq_fakedupdateableresultset.hxx b/connectivity/source/drivers/postgresql/pq_fakedupdateableresultset.hxx index 65113344cdec..44e7dc9bcf13 100644 --- a/connectivity/source/drivers/postgresql/pq_fakedupdateableresultset.hxx +++ b/connectivity/source/drivers/postgresql/pq_fakedupdateableresultset.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_FAKEDUPDATEABLERESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_FAKEDUPDATEABLERESULTSET_HXX +#pragma once #include <com/sun/star/sdbc/XResultSetUpdate.hpp> #include <com/sun/star/sdbc/XRowUpdate.hpp> @@ -62,11 +61,11 @@ public: PGresult *result, const OUString &schema, const OUString &table, - const OUString &aReason ); + OUString aReason ); public: // XInterface - virtual void SAL_CALL acquire() throw() override { ResultSet::acquire(); } - virtual void SAL_CALL release() throw() override { ResultSet::release(); } + virtual void SAL_CALL acquire() noexcept override { ResultSet::acquire(); } + virtual void SAL_CALL release() noexcept override { ResultSet::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -103,6 +102,5 @@ public: // XRowUpdate }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx b/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx index 30d386a6cd3c..e616e9b22966 100644 --- a/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx +++ b/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx @@ -40,7 +40,7 @@ #include "pq_statics.hxx" #include "pq_statement.hxx" -#include <o3tl/deleter.hxx> +#include <o3tl/safeint.hxx> #include <rtl/strbuf.hxx> #include <rtl/ustrbuf.hxx> @@ -54,8 +54,10 @@ #include <memory> #include <string.h> +#include <string_view> #include <connectivity/dbconversion.hxx> +#include <utility> using osl::MutexGuard; @@ -133,13 +135,13 @@ static bool isOperator( char c ) return *w != 0; } -static bool isNamedParameterStart( const OString & o , int index ) +static bool isNamedParameterStart( std::string_view o , int index ) { return o[index] == ':' && ( isWhitespace( o[index-1] ) || isOperator(o[index-1]) ); } -static bool isQuoted( const OString & str ) +static bool isQuoted( std::string_view str ) { return str[0] == '"' || str[0] == '\''; } @@ -148,12 +150,12 @@ PreparedStatement::PreparedStatement( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const Reference< XConnection > & conn, struct ConnectionSettings *pSettings, - const OString & stmt ) + OString stmt ) : PreparedStatement_BASE(refMutex->GetMutex()) , OPropertySetHelper(PreparedStatement_BASE::rBHelper) , m_connection(conn) , m_pSettings(pSettings) - , m_stmt(stmt) + , m_stmt(std::move(stmt)) , m_xMutex(refMutex) , m_multipleResultAvailable(false) , m_multipleResultUpdateCount(0) @@ -197,7 +199,7 @@ PreparedStatement::~PreparedStatement() void PreparedStatement::checkColumnIndex( sal_Int32 parameterIndex ) { - if( parameterIndex < 1 || parameterIndex > static_cast<sal_Int32>(m_vars.size()) ) + if( parameterIndex < 1 || o3tl::make_unsigned(parameterIndex) > m_vars.size() ) { throw SQLException( "pq_preparedstatement: parameter index out of range (expected 1 to " @@ -261,10 +263,9 @@ void PreparedStatement::close( ) void PreparedStatement::raiseSQLException( const char * errorMsg ) { OUStringBuffer buf(128); - buf.append( "pq_driver: "); - buf.append( - OUString( errorMsg, strlen(errorMsg) , ConnectionSettings::encoding ) ); - buf.append( " (caused by statement '" ); + buf.append( "pq_driver: " + + OUString( errorMsg, strlen(errorMsg) , ConnectionSettings::encoding ) + + " (caused by statement '" ); buf.appendAscii( m_executedStatement.getStr() ); buf.append( "')" ); OUString error = buf.makeStringAndClear(); @@ -389,7 +390,7 @@ void PreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 ) MutexGuard guard( m_xMutex->GetMutex() ); checkClosed(); checkColumnIndex( parameterIndex ); - m_vars[parameterIndex-1] = OString( "NULL" ); + m_vars[parameterIndex-1] = "NULL"_ostr; } void PreparedStatement::setObjectNull( @@ -398,7 +399,7 @@ void PreparedStatement::setObjectNull( MutexGuard guard( m_xMutex->GetMutex() ); checkClosed(); checkColumnIndex( parameterIndex ); - m_vars[parameterIndex-1] = OString( "NULL" ); + m_vars[parameterIndex-1] = "NULL"_ostr; } @@ -408,9 +409,9 @@ void PreparedStatement::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) checkClosed(); checkColumnIndex( parameterIndex ); if( x ) - m_vars[parameterIndex-1] = OString( "'t'" ); + m_vars[parameterIndex-1] = "'t'"_ostr; else - m_vars[parameterIndex-1] = OString( "'f'" ); + m_vars[parameterIndex-1] = "'f'"_ostr; } void PreparedStatement::setByte( sal_Int32 parameterIndex, sal_Int8 x ) @@ -480,7 +481,7 @@ void PreparedStatement::setBytes( checkClosed(); checkColumnIndex( parameterIndex ); size_t len; - std::unique_ptr<unsigned char, o3tl::free_delete> escapedString( + const std::unique_ptr<unsigned char, deleter_from_fn<PQfreemem>> escapedString( PQescapeBytea( reinterpret_cast<unsigned char const *>(x.getConstArray()), x.getLength(), &len)); if( ! escapedString ) { @@ -489,7 +490,7 @@ void PreparedStatement::setBytes( *this, OUString(), 1, Any() ); } m_vars[parameterIndex-1] - = "'" + rtl::OStringView(reinterpret_cast<char *>(escapedString.get()), len -1) + "'"; + = OString::Concat("'") + std::string_view(reinterpret_cast<char *>(escapedString.get()), len -1) + "'"; } diff --git a/connectivity/source/drivers/postgresql/pq_preparedstatement.hxx b/connectivity/source/drivers/postgresql/pq_preparedstatement.hxx index eb0794f9efe0..ed81420cec7d 100644 --- a/connectivity/source/drivers/postgresql/pq_preparedstatement.hxx +++ b/connectivity/source/drivers/postgresql/pq_preparedstatement.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_PREPAREDSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_PREPAREDSTATEMENT_HXX +#pragma once #include <vector> #include <libpq-fe.h> @@ -99,12 +98,12 @@ public: PreparedStatement( const rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection> & con, struct ConnectionSettings *pSettings, - const OString &stmt ); + OString stmt ); virtual ~PreparedStatement() override; public: // XInterface - virtual void SAL_CALL acquire() throw() override { PreparedStatement_BASE::acquire(); } - virtual void SAL_CALL release() throw() override { PreparedStatement_BASE::release(); } + virtual void SAL_CALL acquire() noexcept override { PreparedStatement_BASE::acquire(); } + virtual void SAL_CALL release() noexcept override { PreparedStatement_BASE::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; public: // XCloseable @@ -218,6 +217,5 @@ private: }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_resultset.cxx b/connectivity/source/drivers/postgresql/pq_resultset.cxx index 556bae92d5be..0058041c87b5 100644 --- a/connectivity/source/drivers/postgresql/pq_resultset.cxx +++ b/connectivity/source/drivers/postgresql/pq_resultset.cxx @@ -44,6 +44,7 @@ #include <com/sun/star/sdbc/ResultSetType.hpp> #include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/sdbc/SQLException.hpp> +#include <utility> using osl::MutexGuard; @@ -79,14 +80,14 @@ ResultSet::ResultSet( const ::rtl::Reference< comphelper::RefCountedMutex > & re const Reference< XInterface > & owner, ConnectionSettings **ppSettings, PGresult * result, - const OUString &schema, - const OUString &table) + OUString schema, + OUString table) : BaseResultSet( refMutex, owner, PQntuples( result ), PQnfields( result ),(*ppSettings)->tc ), m_result( result ), - m_schema( schema ), - m_table( table ), + m_schema(std::move( schema )), + m_table(std::move( table )), m_ppSettings( ppSettings ) { // LEM TODO: shouldn't these things be inherited from the statement or something like that? diff --git a/connectivity/source/drivers/postgresql/pq_resultset.hxx b/connectivity/source/drivers/postgresql/pq_resultset.hxx index 4b2bb6f41fb9..cf2888bf5b93 100644 --- a/connectivity/source/drivers/postgresql/pq_resultset.hxx +++ b/connectivity/source/drivers/postgresql/pq_resultset.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_RESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_RESULTSET_HXX +#pragma once #include <cppuhelper/propshlp.hxx> #include <cppuhelper/component.hxx> @@ -73,8 +72,8 @@ public: const css::uno::Reference< css::uno::XInterface > &owner, ConnectionSettings **pSettings, PGresult *result, - const OUString &schema, - const OUString &table ); + OUString schema, + OUString table ); virtual ~ResultSet() override; public: // XCloseable @@ -91,6 +90,5 @@ public: }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_resultsetmetadata.cxx b/connectivity/source/drivers/postgresql/pq_resultsetmetadata.cxx index fbe10f82dacb..26b11de27985 100644 --- a/connectivity/source/drivers/postgresql/pq_resultsetmetadata.cxx +++ b/connectivity/source/drivers/postgresql/pq_resultsetmetadata.cxx @@ -46,6 +46,7 @@ #include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/sdbc/XRow.hpp> +#include <utility> #include <string.h> @@ -113,18 +114,18 @@ static void extractPrecisionAndScale( sal_Int32 atttypmod, sal_Int32 *precision, } ResultSetMetaData::ResultSetMetaData( - const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, - const css::uno::Reference< css::sdbc::XResultSet > & origin, + ::rtl::Reference< comphelper::RefCountedMutex > refMutex, + css::uno::Reference< css::sdbc::XResultSet > origin, ResultSet * pResultSet, ConnectionSettings **ppSettings, PGresult const *pResult, - const OUString &schemaName, - const OUString &tableName ) : - m_xMutex( refMutex ), + OUString schemaName, + OUString tableName ) : + m_xMutex(std::move( refMutex )), m_ppSettings( ppSettings ), - m_origin( origin ), - m_tableName( tableName ), - m_schemaName( schemaName ), + m_origin(std::move( origin )), + m_tableName(std::move( tableName )), + m_schemaName(std::move( schemaName )), m_colDesc( PQnfields( pResult ) ), m_pResultSet( pResultSet ), m_checkedForTable( false ), @@ -166,8 +167,7 @@ void ResultSetMetaData::checkForTypes() if( i > 0 ) buf.append( " OR " ); int oid = m_colDesc[i].typeOid; - buf.append( "oid=" ); - buf.append( static_cast<sal_Int32>(oid) ); + buf.append( "oid=" + OUString::number(static_cast<sal_Int32>(oid)) ); } Reference< XResultSet > rs = stmt->executeQuery( buf.makeStringAndClear() ); Reference< XRow > xRow( rs, UNO_QUERY ); diff --git a/connectivity/source/drivers/postgresql/pq_resultsetmetadata.hxx b/connectivity/source/drivers/postgresql/pq_resultsetmetadata.hxx index 2c1b5e5e5965..71c98190ba2b 100644 --- a/connectivity/source/drivers/postgresql/pq_resultsetmetadata.hxx +++ b/connectivity/source/drivers/postgresql/pq_resultsetmetadata.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_RESULTSETMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_RESULTSETMETADATA_HXX +#pragma once #include <vector> #include "pq_connection.hxx" @@ -90,13 +89,13 @@ class ResultSetMetaData : public: ResultSetMetaData( - const ::rtl::Reference< comphelper::RefCountedMutex > & reMutex, - const css::uno::Reference< css::sdbc::XResultSet > & origin, + ::rtl::Reference< comphelper::RefCountedMutex > reMutex, + css::uno::Reference< css::sdbc::XResultSet > origin, ResultSet *pResultSet, ConnectionSettings **pSettings, PGresult const *pResult, - const OUString &schemaName, - const OUString &tableName ); + OUString schemaName, + OUString tableName ); public: // Methods @@ -125,6 +124,4 @@ public: } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_sequenceresultset.cxx b/connectivity/source/drivers/postgresql/pq_sequenceresultset.cxx index 02030729ad73..defb99906048 100644 --- a/connectivity/source/drivers/postgresql/pq_sequenceresultset.cxx +++ b/connectivity/source/drivers/postgresql/pq_sequenceresultset.cxx @@ -65,17 +65,17 @@ Any SequenceResultSet::getValue( sal_Int32 columnIndex ) SequenceResultSet::SequenceResultSet( const ::rtl::Reference< comphelper::RefCountedMutex > & mutex, const css::uno::Reference< css::uno::XInterface > &owner, - const std::vector< OUString > &colNames, - const std::vector< std::vector< Any > > &data, + std::vector< OUString >&& colNames, + std::vector< std::vector< Any > >&& data, const Reference< css::script::XTypeConverter > & tc, const ColumnMetaDataVector *pVec) : BaseResultSet( mutex, owner, data.size(), colNames.size(), tc ), - m_data(data ), - m_columnNames( colNames ) + m_data(std::move(data) ), + m_columnNames( std::move(colNames) ) { if( pVec ) { - m_meta = new SequenceResultSetMetaData( *pVec, m_columnNames.size() ); + m_meta = new SequenceResultSetMetaData( std::vector(*pVec), m_columnNames.size() ); } } diff --git a/connectivity/source/drivers/postgresql/pq_sequenceresultset.hxx b/connectivity/source/drivers/postgresql/pq_sequenceresultset.hxx index 3b97e24a3001..64ac212b6b76 100644 --- a/connectivity/source/drivers/postgresql/pq_sequenceresultset.hxx +++ b/connectivity/source/drivers/postgresql/pq_sequenceresultset.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_SEQUENCERESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_SEQUENCERESULTSET_HXX +#pragma once #include <cppuhelper/propshlp.hxx> #include <cppuhelper/component.hxx> @@ -72,8 +71,8 @@ public: SequenceResultSet( const ::rtl::Reference< comphelper::RefCountedMutex > & mutex, const css::uno::Reference< css::uno::XInterface > &owner, - const std::vector< OUString > &colNames, - const std::vector< std::vector< css::uno::Any > > &data, + std::vector< OUString >&& colNames, + std::vector< std::vector< css::uno::Any > >&& data, const css::uno::Reference< css::script::XTypeConverter > &tc, const ColumnMetaDataVector *pVec = nullptr); virtual ~SequenceResultSet() override; @@ -89,6 +88,5 @@ public: // XColumnLocate }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_sequenceresultsetmetadata.cxx b/connectivity/source/drivers/postgresql/pq_sequenceresultsetmetadata.cxx index d45ffc0a614a..568e6bb9f49d 100644 --- a/connectivity/source/drivers/postgresql/pq_sequenceresultsetmetadata.cxx +++ b/connectivity/source/drivers/postgresql/pq_sequenceresultsetmetadata.cxx @@ -46,9 +46,9 @@ namespace pq_sdbc_driver { SequenceResultSetMetaData::SequenceResultSetMetaData( - const ColumnMetaDataVector &metaDataVector, + ColumnMetaDataVector&& metaDataVector, int colCount ) : - m_columnData( metaDataVector ), + m_columnData( std::move(metaDataVector) ), m_colCount( colCount ) { } diff --git a/connectivity/source/drivers/postgresql/pq_sequenceresultsetmetadata.hxx b/connectivity/source/drivers/postgresql/pq_sequenceresultsetmetadata.hxx index 2bba06aa7d2f..3cd32ff66d7a 100644 --- a/connectivity/source/drivers/postgresql/pq_sequenceresultsetmetadata.hxx +++ b/connectivity/source/drivers/postgresql/pq_sequenceresultsetmetadata.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_SEQUENCERESULTSETMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_SEQUENCERESULTSETMETADATA_HXX +#pragma once #include <cppuhelper/implbase.hxx> #include <com/sun/star/sdbc/XResultSetMetaData.hpp> @@ -57,7 +56,7 @@ namespace pq_sdbc_driver public: SequenceResultSetMetaData( - const ColumnMetaDataVector &vec, + ColumnMetaDataVector&& vec, int colCount ); public: @@ -87,6 +86,4 @@ namespace pq_sdbc_driver } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_SEQUENCERESULTSETMETADATA_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_statement.cxx b/connectivity/source/drivers/postgresql/pq_statement.cxx index dd7ab576b37f..648faa69811b 100644 --- a/connectivity/source/drivers/postgresql/pq_statement.cxx +++ b/connectivity/source/drivers/postgresql/pq_statement.cxx @@ -44,7 +44,6 @@ #include <osl/time.h> #include <rtl/ustrbuf.hxx> -#include <rtl/strbuf.hxx> #include <comphelper/sequence.hxx> @@ -60,7 +59,9 @@ #include <com/sun/star/container/XIndexAccess.hpp> #include <com/sun/star/container/XEnumerationAccess.hpp> +#include <cstddef> #include <string.h> +#include <string_view> using osl::MutexGuard; @@ -209,7 +210,7 @@ void Statement::close( ) } void Statement::raiseSQLException( - const OUString & sql, const char * errorMsg ) + std::u16string_view sql, const char * errorMsg ) { OUString error = "pq_driver: " + OUString( errorMsg, strlen(errorMsg), ConnectionSettings::encoding ) @@ -239,7 +240,7 @@ sal_Int32 Statement::executeUpdate( const OUString& sql ) /// @throws SQLException static void raiseSQLException( const Reference< XInterface> & owner, - const OString & sql, + std::string_view sql, const char * errorMsg, const char *errorType = nullptr ) { @@ -252,10 +253,10 @@ static void raiseSQLException( buf.append( "]" ); } buf.append( - OUString( errorMsg, strlen(errorMsg) , ConnectionSettings::encoding ) ); - buf.append( " (caused by statement '" ); - buf.append( OStringToOUString( sql, ConnectionSettings::encoding ) ); - buf.append( "')" ); + OUString( errorMsg, strlen(errorMsg) , ConnectionSettings::encoding ) + + " (caused by statement '" + + OStringToOUString( sql, ConnectionSettings::encoding ) + + "')" ); OUString error = buf.makeStringAndClear(); SAL_WARN("connectivity.postgresql", error); throw SQLException( error, owner, OUString(), 1, Any() ); @@ -429,8 +430,8 @@ bool executePostgresCommand( const OString & cmd, struct CommandData *data ) &table); // check, whether the columns are in the result set (required !) - int i; - for( i = 0 ; i < static_cast<int>(sourceTableKeys.size()) ; i ++ ) + std::size_t i; + for( i = 0 ; i < sourceTableKeys.size() ; i ++ ) { if( -1 == PQfnumber( result, @@ -441,12 +442,12 @@ bool executePostgresCommand( const OString & cmd, struct CommandData *data ) } } - if( !sourceTableKeys.empty() && i == static_cast<int>(sourceTableKeys.size()) ) + if( !sourceTableKeys.empty() && i == sourceTableKeys.size() ) { *(data->pLastResultset) = UpdateableResultSet::createFromPGResultSet( data->refMutex, data->owner, data->ppSettings, result, - schema, table,sourceTableKeys ); + schema, table, std::move(sourceTableKeys) ); } else if( ! table.getLength() ) { @@ -455,15 +456,12 @@ bool executePostgresCommand( const OString & cmd, struct CommandData *data ) } else if( !sourceTableKeys.empty() ) { - OStringBuffer buf( 128 ); - buf.append( "can't support updateable resultset for table " ); - buf.append( OUStringToOString( schema, ConnectionSettings::encoding ) ); - buf.append( "." ); - buf.append( OUStringToOString( table, ConnectionSettings::encoding ) ); - buf.append( ", because resultset does not contain a part of the primary key ( column " ); - buf.append( OUStringToOString( sourceTableKeys[i], ConnectionSettings::encoding ) ); - buf.append( " is missing )" ); - aReason = buf.makeStringAndClear(); + aReason = "can't support updateable resultset for table " + + OUStringToOString( schema, ConnectionSettings::encoding ) + "." + + OUStringToOString( table, ConnectionSettings::encoding ) + + ", because resultset does not contain a part of the primary key ( column " + + OUStringToOString( sourceTableKeys[i], ConnectionSettings::encoding ) + + " is missing )"; } else { @@ -558,7 +556,7 @@ static void getAutoValues( const Reference< XConnection > & connection, const OUString &schemaName, const OUString & tableName, - ConnectionSettings *pConnectionSettings ) + const ConnectionSettings *pConnectionSettings ) { OUString strDefaultValue = getColExprForDefaultSettingVal(pConnectionSettings); Reference< XPreparedStatement > stmt = connection->prepareStatement( @@ -592,7 +590,7 @@ Reference< XResultSet > getGeneratedValuesFromLastInsert( ConnectionSettings *pConnectionSettings, const Reference< XConnection > &connection, sal_Int32 nLastOid, - const OUString & lastTableInserted, + std::u16string_view lastTableInserted, const OString & lastQuery ) { Reference< XResultSet > ret; @@ -601,7 +599,7 @@ Reference< XResultSet > getGeneratedValuesFromLastInsert( splitConcatenatedIdentifier( lastTableInserted, &schemaName, &tableName ); - if( nLastOid && lastTableInserted.getLength() ) + if( nLastOid && lastTableInserted.size() ) { OUStringBuffer buf( 128 ); buf.append( "SELECT * FROM " ); @@ -609,11 +607,10 @@ Reference< XResultSet > getGeneratedValuesFromLastInsert( bufferQuoteQualifiedIdentifier(buf, schemaName, tableName, pConnectionSettings ); else bufferQuoteIdentifier( buf, lastTableInserted, pConnectionSettings ); - buf.append( " WHERE oid = " ); - buf.append( nLastOid ); + buf.append( " WHERE oid = " + OUString::number(nLastOid) ); query = buf.makeStringAndClear(); } - else if ( lastTableInserted.getLength() && lastQuery.getLength() ) + else if ( lastTableInserted.size() && lastQuery.getLength() ) { // extract nameValue Pairs String2StringMap namedValues; @@ -702,8 +699,7 @@ Reference< XResultSet > getGeneratedValuesFromLastInsert( if( bAdditionalCondition ) buf.append( " AND " ); bufferQuoteIdentifier( buf, columnNameUnicode, pConnectionSettings ); - buf.append( " = " ); - buf.append( value ); + buf.append( " = " + value ); bAdditionalCondition = true; } query = buf.makeStringAndClear(); diff --git a/connectivity/source/drivers/postgresql/pq_statement.hxx b/connectivity/source/drivers/postgresql/pq_statement.hxx index 8e93c07b7125..816d2a55afaa 100644 --- a/connectivity/source/drivers/postgresql/pq_statement.hxx +++ b/connectivity/source/drivers/postgresql/pq_statement.hxx @@ -34,8 +34,12 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_STATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_STATEMENT_HXX +#pragma once + +#include <sal/config.h> + +#include <string_view> + #include <cppuhelper/propshlp.hxx> #include <cppuhelper/compbase.hxx> #include <cppuhelper/component.hxx> @@ -96,8 +100,8 @@ public: virtual ~Statement() override; public: // XInterface - virtual void SAL_CALL acquire() throw() override { Statement_BASE::acquire(); } - virtual void SAL_CALL release() throw() override { Statement_BASE::release(); } + virtual void SAL_CALL acquire() noexcept override { Statement_BASE::acquire(); } + virtual void SAL_CALL release() noexcept override { Statement_BASE::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; public: // XCloseable @@ -161,7 +165,7 @@ private: /// @throws css::uno::RuntimeException void checkClosed(); /// @throws css::sdbc::SQLException - void raiseSQLException( const OUString & sql, const char * errorMsg ); + void raiseSQLException( std::u16string_view sql, const char * errorMsg ); }; @@ -185,11 +189,10 @@ css::uno::Reference< css::sdbc::XResultSet > getGeneratedValuesFromLastInsert( ConnectionSettings *pConnectionSettings, const css::uno::Reference< css::sdbc::XConnection > &connection, sal_Int32 nLastOid, - const OUString & lastTableInserted, + std::u16string_view lastTableInserted, const OString & lastQuery ); } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_statics.cxx b/connectivity/source/drivers/postgresql/pq_statics.cxx index a68242e2c55d..f69556202240 100644 --- a/connectivity/source/drivers/postgresql/pq_statics.cxx +++ b/connectivity/source/drivers/postgresql/pq_statics.cxx @@ -35,9 +35,9 @@ ************************************************************************/ #include "pq_statics.hxx" -#include "pq_updateableresultset.hxx" #include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp> +#include <utility> using com::sun::star::uno::Sequence; using com::sun::star::uno::Any; @@ -69,8 +69,8 @@ struct BaseTypeDef { const char * typeName; sal_Int32 value; }; struct PropertyDef { - PropertyDef( const OUString &str, const Type &t ) - : name( str ) , type( t ) {} + PropertyDef( OUString str, const Type &t ) + : name(std::move( str )) , type( t ) {} OUString name; css::uno::Type type; }; @@ -89,9 +89,10 @@ static cppu::IPropertyArrayHelper * createPropertyArrayHelper( PropertyDef const *props, int count , sal_Int16 attr ) { Sequence< Property > seq( count ); + auto seqRange = asNonConstRange(seq); for( int i = 0 ; i < count ; i ++ ) { - seq[i] = Property( props[i].name, i, props[i].type, attr ); + seqRange[i] = Property( props[i].name, i, props[i].type, attr ); } return new cppu::OPropertyArrayHelper( seq, true ); } @@ -100,9 +101,10 @@ static cppu::IPropertyArrayHelper * createPropertyArrayHelper( PropertyDefEx const *props, int count ) { Sequence< Property > seq( count ); + auto seqRange = asNonConstRange(seq); for( int i = 0 ; i < count ; i ++ ) { - seq[i] = Property( props[i].name, i, props[i].type, props[i].attribute ); + seqRange[i] = Property( props[i].name, i, props[i].type, props[i].attribute ); } return new cppu::OPropertyArrayHelper( seq, true ); } @@ -184,8 +186,7 @@ Statics & getStatics() // Table props set ImplementationStatics &ist = statics.refl.table; ist.implName = "org.openoffice.comp.pq.sdbcx.Table"; - ist.serviceNames = Sequence< OUString > ( 1 ); - ist.serviceNames[0] = "com.sun.star.sdbcx.Table"; + ist.serviceNames = { "com.sun.star.sdbcx.Table" }; PropertyDef tableDef[] = { PropertyDef( statics.CATALOG_NAME , tString ), @@ -196,13 +197,11 @@ Statics & getStatics() PropertyDef( statics.TYPE , tString ) }; ist.pProps = createPropertyArrayHelper( - tableDef, SAL_N_ELEMENTS(tableDef), READONLY ); + tableDef, std::size(tableDef), READONLY ); statics.refl.tableDescriptor.implName = "org.openoffice.comp.pq.sdbcx.TableDescriptor"; - statics.refl.tableDescriptor.serviceNames = Sequence< OUString > (1); - statics.refl.tableDescriptor.serviceNames[0] = - "com.sun.star.sdbcx.TableDescriptor"; + statics.refl.tableDescriptor.serviceNames = { "com.sun.star.sdbcx.TableDescriptor" }; PropertyDef tableDescDef[] = { PropertyDef( statics.CATALOG_NAME , tString ), @@ -212,12 +211,11 @@ Statics & getStatics() PropertyDef( statics.SCHEMA_NAME , tString ) }; statics.refl.tableDescriptor.pProps = createPropertyArrayHelper( - tableDescDef, SAL_N_ELEMENTS(tableDescDef), 0 ); + tableDescDef, std::size(tableDescDef), 0 ); // Column props set statics.refl.column.implName = "org.openoffice.comp.pq.sdbcx.Column"; - statics.refl.column.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.column.serviceNames[0] = "com.sun.star.sdbcx.Column"; + statics.refl.column.serviceNames = { "com.sun.star.sdbcx.Column" }; PropertyDefEx columnDef[] = { PropertyDefEx( statics.CATALOG_NAME , tString, READONLY ), @@ -235,13 +233,11 @@ Statics & getStatics() PropertyDefEx( statics.TYPE_NAME , tString ,READONLY) }; statics.refl.column.pProps = createPropertyArrayHelper( - columnDef, SAL_N_ELEMENTS(columnDef) ); + columnDef, std::size(columnDef) ); statics.refl.columnDescriptor.implName = "org.openoffice.comp.pq.sdbcx.ColumnDescriptor"; - statics.refl.columnDescriptor.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.columnDescriptor.serviceNames[0] = - "com.sun.star.sdbcx.ColumnDescriptor"; + statics.refl.columnDescriptor.serviceNames = { "com.sun.star.sdbcx.ColumnDescriptor" }; PropertyDef columnDescDef[] = { PropertyDef( statics.CATALOG_NAME , tString ), @@ -260,12 +256,11 @@ Statics & getStatics() }; statics.refl.columnDescriptor.pProps = createPropertyArrayHelper( - columnDescDef, SAL_N_ELEMENTS(columnDescDef), 0 ); + columnDescDef, std::size(columnDescDef), 0 ); // Key properties statics.refl.key.implName = "org.openoffice.comp.pq.sdbcx.Key"; - statics.refl.key.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.key.serviceNames[0] = "com.sun.star.sdbcx.Key"; + statics.refl.key.serviceNames = { "com.sun.star.sdbcx.Key" }; PropertyDef keyDef[] = { PropertyDef( statics.DELETE_RULE, tInt ), @@ -277,15 +272,13 @@ Statics & getStatics() PropertyDef( statics.UPDATE_RULE, tInt ) }; statics.refl.key.pProps = createPropertyArrayHelper( - keyDef, SAL_N_ELEMENTS(keyDef), READONLY ); + keyDef, std::size(keyDef), READONLY ); // Key properties statics.refl.keyDescriptor.implName = "org.openoffice.comp.pq.sdbcx.KeyDescriptor"; - statics.refl.keyDescriptor.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.keyDescriptor.serviceNames[0] = - "com.sun.star.sdbcx.KeyDescriptor"; + statics.refl.keyDescriptor.serviceNames = { "com.sun.star.sdbcx.KeyDescriptor" }; PropertyDef keyDescDef[] = { PropertyDef( statics.DELETE_RULE, tInt ), @@ -295,13 +288,12 @@ Statics & getStatics() PropertyDef( statics.UPDATE_RULE, tInt ) }; statics.refl.keyDescriptor.pProps = createPropertyArrayHelper( - keyDescDef, SAL_N_ELEMENTS(keyDescDef), 0 ); + keyDescDef, std::size(keyDescDef), 0 ); // KeyColumn props set statics.refl.keycolumn.implName = "org.openoffice.comp.pq.sdbcx.KeyColumn"; - statics.refl.keycolumn.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.keycolumn.serviceNames[0] = "com.sun.star.sdbcx.KeyColumn"; + statics.refl.keycolumn.serviceNames = { "com.sun.star.sdbcx.KeyColumn" }; PropertyDef keycolumnDef[] = { PropertyDef( statics.CATALOG_NAME , tString ), @@ -319,26 +311,24 @@ Statics & getStatics() PropertyDef( statics.TYPE_NAME , tString ) }; statics.refl.keycolumn.pProps = createPropertyArrayHelper( - keycolumnDef, SAL_N_ELEMENTS(keycolumnDef), READONLY ); + keycolumnDef, std::size(keycolumnDef), READONLY ); // KeyColumn props set statics.refl.keycolumnDescriptor.implName = "org.openoffice.comp.pq.sdbcx.KeyColumnDescriptor"; - statics.refl.keycolumnDescriptor.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.keycolumnDescriptor.serviceNames[0] = - "com.sun.star.sdbcx.KeyColumnDescriptor"; + statics.refl.keycolumnDescriptor.serviceNames = + { "com.sun.star.sdbcx.KeyColumnDescriptor" }; PropertyDef keycolumnDescDef[] = { PropertyDef( statics.NAME , tString ), PropertyDef( statics.RELATED_COLUMN, tString ) }; statics.refl.keycolumnDescriptor.pProps = createPropertyArrayHelper( - keycolumnDescDef, SAL_N_ELEMENTS(keycolumnDescDef), 0 ); + keycolumnDescDef, std::size(keycolumnDescDef), 0 ); // view props set statics.refl.view.implName = "org.openoffice.comp.pq.sdbcx.View"; - statics.refl.view.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.view.serviceNames[0] = "com.sun.star.sdbcx.View"; + statics.refl.view.serviceNames = { "com.sun.star.sdbcx.View" }; PropertyDef viewDef[] = { PropertyDef( statics.CATALOG_NAME , tString ), @@ -348,43 +338,38 @@ Statics & getStatics() PropertyDef( statics.SCHEMA_NAME , tString ) }; statics.refl.view.pProps = createPropertyArrayHelper( - viewDef, SAL_N_ELEMENTS(viewDef), READONLY ); + viewDef, std::size(viewDef), READONLY ); // view props set statics.refl.viewDescriptor.implName = "org.openoffice.comp.pq.sdbcx.ViewDescriptor"; - statics.refl.viewDescriptor.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.viewDescriptor.serviceNames[0] = "com.sun.star.sdbcx.ViewDescriptor"; + statics.refl.viewDescriptor.serviceNames = { "com.sun.star.sdbcx.ViewDescriptor" }; statics.refl.viewDescriptor.pProps = createPropertyArrayHelper( - viewDef, SAL_N_ELEMENTS(viewDef), 0 ); // reuse view, as it is identical + viewDef, std::size(viewDef), 0 ); // reuse view, as it is identical // user props set statics.refl.user.implName = "org.openoffice.comp.pq.sdbcx.User"; - statics.refl.user.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.user.serviceNames[0] = "com.sun.star.sdbcx.User"; + statics.refl.user.serviceNames = { "com.sun.star.sdbcx.User" }; PropertyDef userDefRO[] = { PropertyDef( statics.NAME , tString ) }; statics.refl.user.pProps = createPropertyArrayHelper( - userDefRO, SAL_N_ELEMENTS(userDefRO), READONLY ); + userDefRO, std::size(userDefRO), READONLY ); // user props set statics.refl.userDescriptor.implName = "org.openoffice.comp.pq.sdbcx.UserDescriptor"; - statics.refl.userDescriptor.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.userDescriptor.serviceNames[0] = - "com.sun.star.sdbcx.UserDescriptor"; + statics.refl.userDescriptor.serviceNames = { "com.sun.star.sdbcx.UserDescriptor" }; PropertyDef userDefWR[] = { PropertyDef( statics.NAME , tString ), PropertyDef( statics.PASSWORD , tString ) }; statics.refl.userDescriptor.pProps = createPropertyArrayHelper( - userDefWR, SAL_N_ELEMENTS(userDefWR), 0 ); + userDefWR, std::size(userDefWR), 0 ); // index props set statics.refl.index.implName = "org.openoffice.comp.pq.sdbcx.Index"; - statics.refl.index.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.index.serviceNames[0] = "com.sun.star.sdbcx.Index"; + statics.refl.index.serviceNames = { "com.sun.star.sdbcx.Index" }; PropertyDef indexDef[] = { PropertyDef( statics.CATALOG , tString ), @@ -395,21 +380,18 @@ Statics & getStatics() PropertyDef( statics.PRIVATE_COLUMN_INDEXES, tStringSequence ) }; statics.refl.index.pProps = createPropertyArrayHelper( - indexDef, SAL_N_ELEMENTS(indexDef), READONLY ); + indexDef, std::size(indexDef), READONLY ); // index props set statics.refl.indexDescriptor.implName = "org.openoffice.comp.pq.sdbcx.IndexDescriptor"; - statics.refl.indexDescriptor.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.indexDescriptor.serviceNames[0] = - "com.sun.star.sdbcx.IndexDescriptor"; + statics.refl.indexDescriptor.serviceNames = { "com.sun.star.sdbcx.IndexDescriptor" }; statics.refl.indexDescriptor.pProps = createPropertyArrayHelper( - indexDef, SAL_N_ELEMENTS(indexDef), 0 ); + indexDef, std::size(indexDef), 0 ); // indexColumn props set statics.refl.indexColumn.implName = "org.openoffice.comp.pq.sdbcx.IndexColumn"; - statics.refl.indexColumn.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.indexColumn.serviceNames[0] = "com.sun.star.sdbcx.IndexColumn"; + statics.refl.indexColumn.serviceNames = { "com.sun.star.sdbcx.IndexColumn" }; PropertyDef indexColumnDef[] = { PropertyDef( statics.CATALOG_NAME , tString ), @@ -427,47 +409,20 @@ Statics & getStatics() PropertyDef( statics.TYPE_NAME , tString ) }; statics.refl.indexColumn.pProps = createPropertyArrayHelper( - indexColumnDef, SAL_N_ELEMENTS(indexColumnDef), READONLY ); + indexColumnDef, std::size(indexColumnDef), READONLY ); // indexColumn props set statics.refl.indexColumnDescriptor.implName = "org.openoffice.comp.pq.sdbcx.IndexColumnDescriptor"; - statics.refl.indexColumnDescriptor.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.indexColumnDescriptor.serviceNames[0] = - "com.sun.star.sdbcx.IndexColumnDescriptor"; + statics.refl.indexColumnDescriptor.serviceNames = + { "com.sun.star.sdbcx.IndexColumnDescriptor" }; PropertyDef indexColumnDescDef[] = { PropertyDef( statics.IS_ASCENDING, tBool ), PropertyDef( statics.NAME , tString ) }; statics.refl.indexColumnDescriptor.pProps = createPropertyArrayHelper( - indexColumnDescDef, SAL_N_ELEMENTS(indexColumnDescDef), 0 ); - - // resultset - statics.refl.resultSet.implName = "org.openoffice.comp.pq.ResultSet"; - statics.refl.resultSet.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.resultSet.serviceNames[0] = "com.sun.star.sdbc.ResultSet"; - statics.refl.resultSet.types = UpdateableResultSet::getStaticTypes( false /* updateable */ ); - PropertyDef resultSet[] = - { - PropertyDef( statics.CURSOR_NAME , tString ), - PropertyDef( statics.ESCAPE_PROCESSING , tBool ), - PropertyDef( statics.FETCH_DIRECTION , tInt ), - PropertyDef( statics.FETCH_SIZE , tInt ), - PropertyDef( statics.IS_BOOKMARKABLE , tBool ), - PropertyDef( statics.RESULT_SET_CONCURRENCY , tInt ), - PropertyDef( statics.RESULT_SET_TYPE , tInt ) - }; - statics.refl.resultSet.pProps = createPropertyArrayHelper( - resultSet, SAL_N_ELEMENTS(resultSet), 0 ); - - // updateableResultset - statics.refl.updateableResultSet.implName = "org.openoffice.comp.pq.UpdateableResultSet"; - statics.refl.updateableResultSet.serviceNames = Sequence< OUString > ( 1 ); - statics.refl.updateableResultSet.serviceNames[0] = "com.sun.star.sdbc.ResultSet"; - statics.refl.updateableResultSet.types = UpdateableResultSet::getStaticTypes( true /* updateable */ ); - statics.refl.updateableResultSet.pProps = createPropertyArrayHelper( - resultSet, SAL_N_ELEMENTS(resultSet), 0 ); + indexColumnDescDef, std::size(indexColumnDescDef), 0 ); // databasemetadata statics.tablesRowNames = std::vector< OUString > ( 5 ); diff --git a/connectivity/source/drivers/postgresql/pq_statics.hxx b/connectivity/source/drivers/postgresql/pq_statics.hxx index 017f49b5a655..4e745e4086ee 100644 --- a/connectivity/source/drivers/postgresql/pq_statics.hxx +++ b/connectivity/source/drivers/postgresql/pq_statics.hxx @@ -34,10 +34,10 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_STATICS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_STATICS_HXX +#pragma once #include <unordered_map> +#include <utility> #include <vector> #include <com/sun/star/uno/Any.hxx> @@ -51,20 +51,20 @@ namespace pq_sdbc_driver struct ColumnMetaData { ColumnMetaData( - const OUString &_columnName, - const OUString &_tableName, - const OUString &_schemaTableName, - const OUString &_typeName, + OUString _columnName, + OUString _tableName, + OUString _schemaTableName, + OUString _typeName, sal_Int32 _type, sal_Int32 _precision, sal_Int32 _scale, bool _isCurrency, bool _isNullable, bool _isAutoIncrement ) : - columnName( _columnName ), - tableName( _tableName ), - schemaTableName( _schemaTableName ), - typeName( _typeName ), + columnName(std::move( _columnName )), + tableName(std::move( _tableName )), + schemaTableName(std::move( _schemaTableName )), + typeName(std::move( _typeName )), type( _type ), precision( _precision ), scale( _scale ), @@ -123,9 +123,6 @@ struct ReflectionImplementations struct ImplementationStatics indexDescriptor; struct ImplementationStatics indexColumn; struct ImplementationStatics indexColumnDescriptor; - - struct ImplementationStatics updateableResultSet; - struct ImplementationStatics resultSet; }; const sal_Int32 TABLE_INDEX_CATALOG = 0; @@ -239,6 +236,5 @@ private: Statics & getStatics(); } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_tools.cxx b/connectivity/source/drivers/postgresql/pq_tools.cxx index bece8a806f29..fb42f864f97e 100644 --- a/connectivity/source/drivers/postgresql/pq_tools.cxx +++ b/connectivity/source/drivers/postgresql/pq_tools.cxx @@ -37,6 +37,7 @@ #include <sal/config.h> #include <o3tl/any.hxx> +#include <o3tl/string_view.hxx> #include <rtl/strbuf.hxx> #include <rtl/ustrbuf.hxx> #include <sal/log.hxx> @@ -57,6 +58,7 @@ #include <libpq-fe.h> #include <string.h> +#include <string_view> using com::sun::star::beans::XPropertySet; @@ -78,7 +80,6 @@ using com::sun::star::uno::Reference; using com::sun::star::uno::Sequence; using com::sun::star::uno::XInterface; using com::sun::star::uno::Any; -using com::sun::star::uno::makeAny; using com::sun::star::container::XEnumeration; using com::sun::star::container::XEnumerationAccess; @@ -86,21 +87,21 @@ using com::sun::star::container::XEnumerationAccess; namespace pq_sdbc_driver { -OUString concatQualified( const OUString & a, const OUString &b) +OUString concatQualified( std::u16string_view a, std::u16string_view b) { - return a + "." + b; + return OUString::Concat(a) + "." + b; } -static OString iOUStringToOString( const OUString& str, ConnectionSettings const *settings) { +static OString iOUStringToOString( std::u16string_view str, ConnectionSettings const *settings) { OSL_ENSURE(settings, "pgsql-sdbc: OUStringToOString got NULL settings"); - return OUStringToOString( str, ConnectionSettings::encoding ); + return rtl::OUStringToOString( str, ConnectionSettings::encoding ); } -OString OUStringToOString( const OUString& str, ConnectionSettings const *settings) { +OString OUStringToOString( std::u16string_view str, ConnectionSettings const *settings) { return iOUStringToOString( str, settings ); } -void bufferEscapeConstant( OUStringBuffer & buf, const OUString & value, ConnectionSettings *settings ) +void bufferEscapeConstant( OUStringBuffer & buf, std::u16string_view value, ConnectionSettings *settings ) { OString y = iOUStringToOString( value, settings ); @@ -124,17 +125,17 @@ void bufferEscapeConstant( OUStringBuffer & buf, const OUString & value, Connect strbuf.setLength( len ); // Previously here RTL_TEXTENCODING_ASCII_US; as we set the PostgreSQL client_encoding to UTF8, // we get UTF8 here, too. I'm not sure why it worked well before... - buf.append( OStringToOUString( strbuf.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ) ); + buf.append( OStringToOUString( strbuf, RTL_TEXTENCODING_UTF8 ) ); } -static void ibufferQuoteConstant( OUStringBuffer & buf, const OUString & value, ConnectionSettings *settings ) +static void ibufferQuoteConstant( OUStringBuffer & buf, std::u16string_view value, ConnectionSettings *settings ) { buf.append( "'" ); bufferEscapeConstant( buf, value, settings ); buf.append( "'" ); } -void bufferQuoteConstant( OUStringBuffer & buf, const OUString & value, ConnectionSettings *settings ) +void bufferQuoteConstant( OUStringBuffer & buf, std::u16string_view value, ConnectionSettings *settings ) { return ibufferQuoteConstant( buf, value, settings ); } @@ -151,7 +152,7 @@ void bufferQuoteAnyConstant( OUStringBuffer & buf, const Any &val, ConnectionSet buf.append( "NULL" ); } -static void ibufferQuoteIdentifier( OUStringBuffer & buf, const OUString &toQuote, ConnectionSettings *settings ) +static void ibufferQuoteIdentifier( OUStringBuffer & buf, std::u16string_view toQuote, ConnectionSettings *settings ) { OSL_ENSURE(settings, "pgsql-sdbc: bufferQuoteIdentifier got NULL settings"); @@ -171,14 +172,14 @@ static void ibufferQuoteIdentifier( OUStringBuffer & buf, const OUString &toQuot PQfreemem( cstr ); } -void bufferQuoteIdentifier( OUStringBuffer & buf, const OUString &toQuote, ConnectionSettings *settings ) +void bufferQuoteIdentifier( OUStringBuffer & buf, std::u16string_view toQuote, ConnectionSettings *settings ) { return ibufferQuoteIdentifier(buf, toQuote, settings); } void bufferQuoteQualifiedIdentifier( - OUStringBuffer & buf, const OUString &schema, const OUString &table, ConnectionSettings *settings ) + OUStringBuffer & buf, std::u16string_view schema, std::u16string_view table, ConnectionSettings *settings ) { ibufferQuoteIdentifier(buf, schema, settings); buf.append( "." ); @@ -187,9 +188,9 @@ void bufferQuoteQualifiedIdentifier( void bufferQuoteQualifiedIdentifier( OUStringBuffer & buf, - const OUString &schema, - const OUString &table, - const OUString &col, + std::u16string_view schema, + std::u16string_view table, + std::u16string_view col, ConnectionSettings *settings) { ibufferQuoteIdentifier(buf, schema, settings); @@ -314,30 +315,30 @@ bool isWhitespace( sal_Unicode c ) return ' ' == c || 9 == c || 10 == c || 13 == c; } -OUString extractTableFromInsert( const OUString & sql ) +OUString extractTableFromInsert( std::u16string_view sql ) { OUString ret; - int i = 0; - while (i < sql.getLength() && isWhitespace(sql[i])) { i++; } + size_t i = 0; + while (i < sql.size() && isWhitespace(sql[i])) { i++; } - if( sql.matchIgnoreAsciiCase("insert", i) ) + if( o3tl::matchIgnoreAsciiCase(sql, u"insert", i) ) { i += 6; - while (i < sql.getLength() && isWhitespace(sql[i])) { i++; } - if( sql.matchIgnoreAsciiCase("into", i) ) + while (i < sql.size() && isWhitespace(sql[i])) { i++; } + if( o3tl::matchIgnoreAsciiCase(sql, u"into", i) ) { i +=4; - while (i < sql.getLength() && isWhitespace(sql[i])) { i++; } + while (i < sql.size() && isWhitespace(sql[i])) { i++; } int start = i; bool quote = (sql[i] == '"'); - for( i++ ; i < sql.getLength() ; i ++ ) + for( i++ ; i < sql.size() ; i ++ ) { if( quote && sql[i] == '"' ) { - while (i < sql.getLength() && isWhitespace(sql[i])) { i++; } + while (i < sql.size() && isWhitespace(sql[i])) { i++; } if( '.' == sql[i] ) { - while (i < sql.getLength() && isWhitespace(sql[i])) { i++; } + while (i < sql.size() && isWhitespace(sql[i])) { i++; } if( '"' == sql[i] ) { // the second part of the table name does not use quotes @@ -360,7 +361,7 @@ OUString extractTableFromInsert( const OUString & sql ) } } } - ret = sql.copy(start, i - start ).trim(); + ret = o3tl::trim(sql.substr(start, i - start )); // printf( "pq_statement: parsed table name %s from insert\n" , // OUStringToOString( ret, RTL_TEXTENCODING_ASCII_US).getStr() ); } @@ -415,7 +416,7 @@ void splitSQL( const OString & sql, std::vector< OString > &vec ) { if( '"' == c ) { - vec.push_back( OString( &sql.getStr()[start], i-start+1 ) ); + vec.emplace_back( &sql.getStr()[start], i-start+1 ); start = i + 1; doubleQuote = false; } @@ -430,7 +431,7 @@ void splitSQL( const OString & sql, std::vector< OString > &vec ) } else if( '\'' == c ) { - vec.push_back( OString( &sql.getStr()[start], i - start +1 ) ); + vec.emplace_back( &sql.getStr()[start], i - start +1 ); start = i + 1; // leave single quotes ! singleQuote = false; } @@ -439,20 +440,20 @@ void splitSQL( const OString & sql, std::vector< OString > &vec ) { if( '"' == c ) { - vec.push_back( OString( &sql.getStr()[start], i - start ) ); + vec.emplace_back( &sql.getStr()[start], i - start ); doubleQuote = true; start = i; } else if( '\'' == c ) { - vec.push_back( OString( &sql.getStr()[start], i - start ) ); + vec.emplace_back( &sql.getStr()[start], i - start ); singleQuote = true; start = i; } } } if( start < i ) - vec.push_back( OString( &sql.getStr()[start] , i - start ) ); + vec.emplace_back( &sql.getStr()[start] , i - start ); // for( i = 0 ; i < vec.size() ; i ++ ) // printf( "%s!" , vec[i].getStr() ); @@ -475,7 +476,7 @@ void tokenizeSQL( const OString & sql, std::vector< OString > &vec ) { if( '"' == c ) { - vec.push_back( OString( &sql.getStr()[start], i-start ) ); + vec.emplace_back( &sql.getStr()[start], i-start ); start = i + 1; doubleQuote = false; } @@ -484,7 +485,7 @@ void tokenizeSQL( const OString & sql, std::vector< OString > &vec ) { if( '\'' == c ) { - vec.push_back( OString( &sql.getStr()[start], i - start +1 ) ); + vec.emplace_back( &sql.getStr()[start], i - start +1 ); start = i + 1; // leave single quotes ! singleQuote = false; } @@ -507,15 +508,15 @@ void tokenizeSQL( const OString & sql, std::vector< OString > &vec ) start ++; // skip additional whitespace else { - vec.push_back( OString( &sql.getStr()[start], i - start ) ); + vec.emplace_back( &sql.getStr()[start], i - start ); start = i +1; } } else if( ',' == c || isOperator( c ) || '(' == c || ')' == c ) { if( i - start ) - vec.push_back( OString( &sql.getStr()[start], i - start ) ); - vec.push_back( OString( &sql.getStr()[i], 1 ) ); + vec.emplace_back( &sql.getStr()[start], i - start ); + vec.emplace_back( &sql.getStr()[i], 1 ); start = i + 1; } else if( '.' == c ) @@ -528,15 +529,15 @@ void tokenizeSQL( const OString & sql, std::vector< OString > &vec ) else { if( i - start ) - vec.push_back( OString( &sql.getStr()[start], i - start ) ); - vec.push_back( OString( "." ) ); + vec.emplace_back( &sql.getStr()[start], i - start ); + vec.emplace_back( "." ); start = i + 1; } } } } if( start < i ) - vec.push_back( OString( &sql.getStr()[start] , i - start ) ); + vec.emplace_back( &sql.getStr()[start] , i - start ); // for( i = 0 ; i < vec.size() ; i ++ ) // printf( "%s!" , vec[i].getStr() ); @@ -544,10 +545,10 @@ void tokenizeSQL( const OString & sql, std::vector< OString > &vec ) } -void splitConcatenatedIdentifier( const OUString & source, OUString *first, OUString *second) +void splitConcatenatedIdentifier( std::u16string_view source, OUString *first, OUString *second) { std::vector< OString > vec; - tokenizeSQL( OUStringToOString( source, RTL_TEXTENCODING_UTF8 ), vec ); + tokenizeSQL( rtl::OUStringToOString( source, RTL_TEXTENCODING_UTF8 ), vec ); switch (vec.size()) { case 1: @@ -595,12 +596,12 @@ OUString array2String( const css::uno::Sequence< Any > &seq ) } -std::vector< Any > parseArray( const OUString & str ) +std::vector< Any > parseArray( std::u16string_view str ) { - int len = str.getLength(); + size_t len = str.size(); bool doubleQuote = false; int brackets = 0; - int i = 0; + size_t i = 0; OUStringBuffer current; std::vector<Any> elements; @@ -643,7 +644,7 @@ std::vector< Any > parseArray( const OUString & str ) if( brackets == 0 ) { if( !current.isEmpty() || doubleQuotedValue ) - elements.push_back( makeAny( current.makeStringAndClear() ) ); + elements.emplace_back( current.makeStringAndClear() ); } else { @@ -672,7 +673,7 @@ std::vector< Any > parseArray( const OUString & str ) else if( ',' == c && brackets == 1) { doubleQuotedValue = false; - elements.push_back( makeAny( current.makeStringAndClear() ) ); + elements.emplace_back( current.makeStringAndClear() ); } else if( isWhitespace( c ) ) { @@ -839,17 +840,17 @@ OUString getColExprForDefaultSettingVal(ConnectionSettings const *settings) OUString("pg_get_expr(pg_attrdef.adbin, pg_attrdef.adrelid, true)"); } -css::uno::Sequence< sal_Int32 > string2intarray( const OUString & str ) +css::uno::Sequence< sal_Int32 > string2intarray( std::u16string_view str ) { css::uno::Sequence< sal_Int32 > ret; - const sal_Int32 strlen = str.getLength(); - if( str.getLength() > 1 ) + const sal_Int32 strlen = str.size(); + if( strlen > 1 ) { sal_Int32 start = 0; sal_uInt32 c; for (;;) { - c = str.iterateCodePoints(&start); + c = o3tl::iterateCodePoints(str, &start); if (!iswspace(c)) break; if ( start == strlen) @@ -859,7 +860,7 @@ css::uno::Sequence< sal_Int32 > string2intarray( const OUString & str ) return ret; for (;;) { - c = str.iterateCodePoints(&start); + c = o3tl::iterateCodePoints(str, &start); if ( !iswspace(c) ) break; if ( start == strlen) @@ -878,7 +879,7 @@ css::uno::Sequence< sal_Int32 > string2intarray( const OUString & str ) break; if ( start == strlen) return ret; - c=str.iterateCodePoints(&start); + c = o3tl::iterateCodePoints(str, &start); } while ( c ); do { @@ -887,20 +888,20 @@ css::uno::Sequence< sal_Int32 > string2intarray( const OUString & str ) if ( start == strlen) return ret; digits.append(OUString(&c, 1)); - c = str.iterateCodePoints(&start); + c = o3tl::iterateCodePoints(str, &start); } while ( c ); - vec.push_back( digits.makeStringAndClear().toInt32() ); + vec.push_back( o3tl::toInt32(digits) ); do { if(!iswspace(c)) break; if ( start == strlen) return ret; - c = str.iterateCodePoints(&start); + c = o3tl::iterateCodePoints(str, &start); } while ( c ); if ( c == L'}' ) break; - if ( str.iterateCodePoints(&start) != L',' ) + if ( o3tl::iterateCodePoints(str, &start) != L',' ) return ret; if ( start == strlen) return ret; @@ -917,11 +918,12 @@ Sequence< OUString > convertMappedIntArray2StringArray( const Int2StringMap &map, const Sequence< sal_Int32 > &intArray ) { Sequence< OUString > ret( intArray.getLength() ); + auto retRange = asNonConstRange(ret); for( int i = 0; i < intArray.getLength() ; i ++ ) { Int2StringMap::const_iterator ii = map.find( intArray[i] ); if( ii != map.end() ) - ret[i] = ii->second; + retRange[i] = ii->second; } return ret; } @@ -941,19 +943,17 @@ OUString sqltype2string( const Reference< XPropertySet > & desc ) case css::sdbc::DataType::VARCHAR: case css::sdbc::DataType::CHAR: { - typeName.append( "(" ); - typeName.append( precision ); - typeName.append( ")" ); + typeName.append( "(" + OUString::number(precision) + ")" ); break; } case css::sdbc::DataType::DECIMAL: case css::sdbc::DataType::NUMERIC: { - typeName.append( "(" ); - typeName.append( precision ); - typeName.append( "," ); - typeName.append( extractIntProperty( desc, getStatics().SCALE ) ); - typeName.append( ")" ); + typeName.append( "(" + + OUString::number(precision) + + "," + + OUString::number(extractIntProperty( desc, getStatics().SCALE )) + + ")" ); break; } default: diff --git a/connectivity/source/drivers/postgresql/pq_tools.hxx b/connectivity/source/drivers/postgresql/pq_tools.hxx index af751f8e633b..c5f9174111ca 100644 --- a/connectivity/source/drivers/postgresql/pq_tools.hxx +++ b/connectivity/source/drivers/postgresql/pq_tools.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_TOOLS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_TOOLS_HXX +#pragma once #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/sdbc/XParameters.hpp> @@ -47,36 +46,46 @@ #include <rtl/string.hxx> #include "pq_connection.hxx" + +#include <string_view> #include <vector> +namespace +{ +// helper to create one-time deleters +template <auto fn> +using deleter_from_fn = std::integral_constant<decltype(fn), fn>; + +} + namespace pq_sdbc_driver { bool isWhitespace( sal_Unicode c ); -OUString concatQualified( const OUString & a, const OUString &b); +OUString concatQualified( std::u16string_view a, std::u16string_view b); -OString OUStringToOString( const OUString& str, ConnectionSettings const *settings); +OString OUStringToOString( std::u16string_view str, ConnectionSettings const *settings); -void bufferQuoteConstant( OUStringBuffer & buf, const OUString & str, ConnectionSettings *settings ); +void bufferQuoteConstant( OUStringBuffer & buf, std::u16string_view str, ConnectionSettings *settings ); void bufferQuoteAnyConstant( OUStringBuffer & buf, const css::uno::Any &val, ConnectionSettings *settings ); -void bufferEscapeConstant( OUStringBuffer & buf, const OUString & str, ConnectionSettings *settings ); +void bufferEscapeConstant( OUStringBuffer & buf, std::u16string_view str, ConnectionSettings *settings ); OUString sqltype2string( const css::uno::Reference< css::beans::XPropertySet > & column ); void bufferQuoteQualifiedIdentifier( - OUStringBuffer & buf, const OUString &schema, const OUString &name, ConnectionSettings *settings ); + OUStringBuffer & buf, std::u16string_view schema, std::u16string_view name, ConnectionSettings *settings ); void bufferQuoteQualifiedIdentifier( OUStringBuffer & buf, - const OUString &schema, - const OUString &name, - const OUString &col, + std::u16string_view schema, + std::u16string_view name, + std::u16string_view col, ConnectionSettings *settings ); -void bufferQuoteIdentifier( OUStringBuffer & buf, const OUString &toQuote, ConnectionSettings *settings ); +void bufferQuoteIdentifier( OUStringBuffer & buf, std::u16string_view toQuote, ConnectionSettings *settings ); void bufferKey2TableConstraint( OUStringBuffer &buf, const css::uno::Reference< css::beans::XPropertySet > &key, @@ -97,7 +106,7 @@ bool extractBoolProperty( void disposeNoThrow( const css::uno::Reference< css::uno::XInterface > & r ); void disposeObject( const css::uno::Reference< css::uno::XInterface > & r ); -OUString extractTableFromInsert( const OUString & sql ); +OUString extractTableFromInsert( std::u16string_view sql ); OString extractSingleTableFromSelect( const std::vector< OString > &vec ); OUString getColExprForDefaultSettingVal(ConnectionSettings const *settings); @@ -106,14 +115,14 @@ void tokenizeSQL( const OString & sql, std::vector< OString > &vec ); void splitSQL( const OString & sql, std::vector< OString > &vec ); std::vector< sal_Int32 > parseIntArray( const OUString & str ); /// @throws css::sdbc::SQLException -std::vector< css::uno::Any > parseArray( const OUString & str ); +std::vector< css::uno::Any > parseArray( std::u16string_view str ); OUString array2String( const css::uno::Sequence< css::uno::Any > &seq ); css::uno::Reference< css::sdbc::XConnection > extractConnectionFromStatement( const css::uno::Reference< css::uno::XInterface > & stmt ); -void splitConcatenatedIdentifier( const OUString & source, OUString *first, OUString *second); +void splitConcatenatedIdentifier( std::u16string_view source, OUString *first, OUString *second); void fillAttnum2attnameMap( @@ -122,7 +131,7 @@ void fillAttnum2attnameMap( const OUString &schema, const OUString &table ); -css::uno::Sequence< sal_Int32 > string2intarray( const OUString & str ); +css::uno::Sequence< sal_Int32 > string2intarray( std::u16string_view str ); css::uno::Sequence< OUString > convertMappedIntArray2StringArray( const Int2StringMap &map, const css::uno::Sequence< sal_Int32> &source ); @@ -134,7 +143,7 @@ OUString querySingleValue( const OUString &query ); void extractNameValuePairsFromInsert( String2StringMap & map, const OString & lastQuery ); -sal_Int32 typeNameToDataType( const OUString &typeName, const OUString &typtype ); +sal_Int32 typeNameToDataType( const OUString &typeName, std::u16string_view typtype ); // copied from connectivity/source/dbtools, can't use the function directly bool implSetObject( const css::uno::Reference< css::sdbc::XParameters >& _rxParameters, @@ -164,6 +173,4 @@ public: } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx b/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx index 880adc647c7e..49eb65cd9fbf 100644 --- a/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx +++ b/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx @@ -35,6 +35,7 @@ ************************************************************************/ #include <sal/log.hxx> +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <cppuhelper/queryinterface.hxx> @@ -88,7 +89,7 @@ css::uno::Reference< css::sdbc::XCloseable > UpdateableResultSet::createFromPGRe PGresult *result, const OUString &schema, const OUString &table, - const std::vector< OUString > &primaryKey ) + std::vector< OUString > && primaryKey ) { sal_Int32 columnCount = PQnfields( result ); sal_Int32 rowCount = PQntuples( result ); @@ -118,16 +119,14 @@ css::uno::Reference< css::sdbc::XCloseable > UpdateableResultSet::createFromPGRe data[row] = aRow; } - UpdateableResultSet *pRS = new UpdateableResultSet( - mutex, owner, columnNames, data, ppSettings, schema, table, primaryKey ); - - Reference <XCloseable > ret = pRS; // give it a refcount + rtl::Reference<UpdateableResultSet> pRS = new UpdateableResultSet( + mutex, owner, std::move(columnNames), std::move(data), ppSettings, schema, table, std::move(primaryKey) ); pRS->m_meta = new ResultSetMetaData( mutex, pRS,nullptr, ppSettings, result, schema, table ); PQclear( result ); // we don't need it anymore - return ret; + return pRS; } css::uno::Any UpdateableResultSet::queryInterface( @@ -297,8 +296,8 @@ void UpdateableResultSet::updateRow( ) buf.append( ", " ); columns ++; - buf.append( m_columnNames[i] ); - buf.append( " = " ); + buf.append( m_columnNames[i] + + " = " ); bufferQuoteAnyConstant( buf, m_updateableField[i].value, *m_ppSettings ); // OUString val; // m_updateableField[i].value >>= val; @@ -343,8 +342,8 @@ void UpdateableResultSet::deleteRow( ) OUStringBuffer buf( 128 ); buf.append( "DELETE FROM " ); bufferQuoteQualifiedIdentifier( buf, m_schema, m_table, *m_ppSettings ); - buf.append( " " ); - buf.append( buildWhereClause() ); + buf.append( " " + + buildWhereClause() ); stmt->executeUpdate( buf.makeStringAndClear() ); @@ -481,7 +480,7 @@ void UpdateableResultSet::updateBytes( sal_Int32 columnIndex, const css::uno::Se m_updateableField[columnIndex-1].value <<= OUString( reinterpret_cast<char*>(escapedString), len, RTL_TEXTENCODING_ASCII_US ); - free( escapedString ); + PQfreemem( escapedString ); } void UpdateableResultSet::updateDate( sal_Int32 columnIndex, const css::util::Date& x ) diff --git a/connectivity/source/drivers/postgresql/pq_updateableresultset.hxx b/connectivity/source/drivers/postgresql/pq_updateableresultset.hxx index feb3f53225d5..52cb513a5856 100644 --- a/connectivity/source/drivers/postgresql/pq_updateableresultset.hxx +++ b/connectivity/source/drivers/postgresql/pq_updateableresultset.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_UPDATEABLERESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_UPDATEABLERESULTSET_HXX +#pragma once #include "pq_sequenceresultset.hxx" #include "pq_resultsetmetadata.hxx" @@ -45,6 +44,7 @@ #include <com/sun/star/sdbc/ResultSetType.hpp> #include <com/sun/star/sdbc/XResultSetUpdate.hpp> #include <com/sun/star/sdbc/XRowUpdate.hpp> +#include <utility> namespace pq_sdbc_driver { @@ -76,17 +76,17 @@ private: UpdateableResultSet( const ::rtl::Reference< comphelper::RefCountedMutex > & mutex, const css::uno::Reference< css::uno::XInterface > &owner, - const std::vector< OUString > &colNames, - const std::vector< std::vector< css::uno::Any > > &data, + std::vector< OUString >&& colNames, + std::vector< std::vector< css::uno::Any > >&& data, ConnectionSettings **ppSettings, - const OUString &schema, - const OUString &table, - const std::vector< OUString > &primaryKey) - : SequenceResultSet( mutex, owner, colNames, data, (*ppSettings)->tc ), + OUString schema, + OUString table, + std::vector< OUString >&& primaryKey) + : SequenceResultSet( mutex, owner, std::move(colNames), std::move(data), (*ppSettings)->tc ), m_ppSettings( ppSettings ), - m_schema( schema ), - m_table( table ), - m_primaryKey( primaryKey ), + m_schema(std::move( schema )), + m_table(std::move( table )), + m_primaryKey( std::move(primaryKey) ), m_insertRow( false ) { // LEM TODO: this duplicates code in pq_resultset.cxx, except for different value @@ -119,11 +119,11 @@ public: PGresult *result, const OUString &schema, const OUString &table, - const std::vector< OUString > &primaryKey ); + std::vector< OUString > && primaryKey ); public: // XInterface - virtual void SAL_CALL acquire() throw() override { SequenceResultSet::acquire(); } - virtual void SAL_CALL release() throw() override { SequenceResultSet::release(); } + virtual void SAL_CALL acquire() noexcept override { SequenceResultSet::acquire(); } + virtual void SAL_CALL release() noexcept override { SequenceResultSet::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -167,6 +167,4 @@ public: } -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_UPDATEABLERESULTSET_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xbase.cxx b/connectivity/source/drivers/postgresql/pq_xbase.cxx index 1fec4130a9db..001046aa52fa 100644 --- a/connectivity/source/drivers/postgresql/pq_xbase.cxx +++ b/connectivity/source/drivers/postgresql/pq_xbase.cxx @@ -36,7 +36,9 @@ #include <cppuhelper/supportsservice.hxx> #include <comphelper/sequence.hxx> +#include <utility> +#include "pq_statics.hxx" #include "pq_tools.hxx" #include "pq_xbase.hxx" @@ -55,18 +57,18 @@ namespace pq_sdbc_driver { ReflectionBase::ReflectionBase( - const OUString &implName, + OUString implName, const css::uno::Sequence< OUString > &supportedServices, const ::rtl::Reference< comphelper::RefCountedMutex >& refMutex, - const css::uno::Reference< css::sdbc::XConnection > &conn, + css::uno::Reference< css::sdbc::XConnection > conn, ConnectionSettings *pSettings, cppu::IPropertyArrayHelper & props /* must survive this object !*/ ) : ReflectionBase_BASE( refMutex->GetMutex() ), OPropertySetHelper( ReflectionBase_BASE::rBHelper ), - m_implName( implName ), + m_implName(std::move( implName )), m_supportedServices( supportedServices ), m_xMutex( refMutex ), - m_conn( conn ), + m_conn(std::move( conn )), m_pSettings( pSettings ), m_propsDesc( props ), m_values( props.getProperties().getLength() ) diff --git a/connectivity/source/drivers/postgresql/pq_xbase.hxx b/connectivity/source/drivers/postgresql/pq_xbase.hxx index 6e7ac8413f47..e4ca16fd5e6a 100644 --- a/connectivity/source/drivers/postgresql/pq_xbase.hxx +++ b/connectivity/source/drivers/postgresql/pq_xbase.hxx @@ -34,10 +34,8 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XBASE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XBASE_HXX +#pragma once #include <cppuhelper/propshlp.hxx> -#include <cppuhelper/component.hxx> #include <cppuhelper/compbase.hxx> #include <com/sun/star/lang/XServiceInfo.hpp> @@ -67,10 +65,10 @@ protected: std::vector< css::uno::Any > m_values; public: ReflectionBase( - const OUString &implName, + OUString implName, const css::uno::Sequence< OUString > &supportedServices, const ::rtl::Reference< comphelper::RefCountedMutex >& refMutex, - const css::uno::Reference< css::sdbc::XConnection > &conn, + css::uno::Reference< css::sdbc::XConnection > conn, ConnectionSettings *pSettings, cppu::IPropertyArrayHelper & props /* must survive this object !*/ ); @@ -82,8 +80,8 @@ public: // for initialization purposes only, not exported via an interface ! const OUString & name, const css::uno::Any & value ); public: //XInterface - virtual void SAL_CALL acquire() throw() override { ReflectionBase_BASE::acquire(); } - virtual void SAL_CALL release() throw() override { ReflectionBase_BASE::release(); } + virtual void SAL_CALL acquire() noexcept override { ReflectionBase_BASE::acquire(); } + virtual void SAL_CALL release() noexcept override { ReflectionBase_BASE::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -129,6 +127,5 @@ public: // XNamed }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xcolumn.cxx b/connectivity/source/drivers/postgresql/pq_xcolumn.cxx index c6d98b0fcb85..b19d95c3c994 100644 --- a/connectivity/source/drivers/postgresql/pq_xcolumn.cxx +++ b/connectivity/source/drivers/postgresql/pq_xcolumn.cxx @@ -34,6 +34,11 @@ * ************************************************************************/ +#include <sal/config.h> + +#include <rtl/ref.hxx> + +#include "pq_statics.hxx" #include "pq_xcolumn.hxx" using com::sun::star::uno::Reference; @@ -56,7 +61,7 @@ Column::Column( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex Reference< XPropertySet > Column::createDataDescriptor( ) { - ColumnDescriptor * pColumn = new ColumnDescriptor( + rtl::Reference<ColumnDescriptor> pColumn = new ColumnDescriptor( m_xMutex, m_conn, m_pSettings ); pColumn->copyValuesFrom( this ); return Reference< XPropertySet > ( pColumn ); @@ -77,7 +82,7 @@ ColumnDescriptor::ColumnDescriptor( Reference< XPropertySet > ColumnDescriptor::createDataDescriptor( ) { - ColumnDescriptor * pColumn = new ColumnDescriptor( + rtl::Reference<ColumnDescriptor> pColumn = new ColumnDescriptor( m_xMutex, m_conn, m_pSettings ); pColumn->copyValuesFrom( this ); diff --git a/connectivity/source/drivers/postgresql/pq_xcolumn.hxx b/connectivity/source/drivers/postgresql/pq_xcolumn.hxx index ea4e099fcd2b..794b5851d3c7 100644 --- a/connectivity/source/drivers/postgresql/pq_xcolumn.hxx +++ b/connectivity/source/drivers/postgresql/pq_xcolumn.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XCOLUMN_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XCOLUMN_HXX +#pragma once #include <cppuhelper/component.hxx> #include <cppuhelper/propshlp.hxx> @@ -80,6 +79,4 @@ public: // XDataDescriptorFactory } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xcolumns.cxx b/connectivity/source/drivers/postgresql/pq_xcolumns.cxx index 4edb1aabc068..2902879c49b0 100644 --- a/connectivity/source/drivers/postgresql/pq_xcolumns.cxx +++ b/connectivity/source/drivers/postgresql/pq_xcolumns.cxx @@ -34,6 +34,13 @@ * ************************************************************************/ +#include <sal/config.h> + +#include <string_view> + +#include <o3tl/safeint.hxx> +#include <o3tl/string_view.hxx> +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <sal/log.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> @@ -43,6 +50,7 @@ #include <com/sun/star/sdbc/ColumnValue.hpp> #include <cppuhelper/exc_hlp.hxx> +#include <utility> #include "pq_xcolumns.hxx" #include "pq_xcolumn.hxx" @@ -55,7 +63,6 @@ using osl::MutexGuard; using com::sun::star::beans::XPropertySet; using com::sun::star::uno::Any; -using com::sun::star::uno::makeAny; using com::sun::star::uno::UNO_QUERY; using com::sun::star::uno::Reference; using com::sun::star::uno::RuntimeException; @@ -69,9 +76,9 @@ using com::sun::star::sdbc::SQLException; namespace pq_sdbc_driver { -static Any isCurrency( const OUString & typeName ) +static Any isCurrency( std::u16string_view typeName ) { - return Any( typeName.equalsIgnoreAsciiCase("money") ); + return Any( o3tl::equalsIgnoreAsciiCase(typeName, u"money") ); } // static sal_Bool isAutoIncrement8( const OUString & typeName ) @@ -80,9 +87,9 @@ static Any isCurrency( const OUString & typeName ) // typeName.equalsIgnoreAsciiCase("bigserial"); // } -static Any isAutoIncrement( const OUString & defaultValue ) +static Any isAutoIncrement( std::u16string_view defaultValue ) { - bool ret = defaultValue.startsWith( "nextval(" ); + bool ret = o3tl::starts_with( defaultValue, u"nextval(" ); // printf( "%s %d\n", // OUStringToOString(defaultValue, RTL_TEXTENCODING_ASCII_US).getStr(), // ret ); @@ -103,11 +110,11 @@ Columns::Columns( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName) + OUString schemaName, + OUString tableName) : Container( refMutex, origin, pSettings, "COLUMN" ), - m_schemaName( schemaName ), - m_tableName( tableName ) + m_schemaName(std::move( schemaName )), + m_tableName(std::move( tableName )) {} Columns::~Columns() @@ -179,25 +186,25 @@ OUString columnMetaData2SDBCX( OUString typeName = xRow->getString( TYPE_NAME ); pBase->setPropertyValue_NoBroadcast_public( - st.NAME, makeAny( name ) ); + st.NAME, Any( name ) ); pBase->setPropertyValue_NoBroadcast_public( - st.TYPE, makeAny( xRow->getInt( DATA_TYPE ) ) ); + st.TYPE, Any( xRow->getInt( DATA_TYPE ) ) ); pBase->setPropertyValue_NoBroadcast_public( - st.TYPE_NAME, makeAny( typeName ) ); + st.TYPE_NAME, Any( typeName ) ); pBase->setPropertyValue_NoBroadcast_public( - st.PRECISION, makeAny( xRow->getInt( COLUMN_SIZE ) ) ); + st.PRECISION, Any( xRow->getInt( COLUMN_SIZE ) ) ); pBase->setPropertyValue_NoBroadcast_public( - st.SCALE, makeAny( xRow->getInt( DECIMAL_DIGITS ) ) ); + st.SCALE, Any( xRow->getInt( DECIMAL_DIGITS ) ) ); pBase->setPropertyValue_NoBroadcast_public( - st.IS_NULLABLE, makeAny( xRow->getInt( IS_NULLABLE ) ) ); + st.IS_NULLABLE, Any( xRow->getInt( IS_NULLABLE ) ) ); pBase->setPropertyValue_NoBroadcast_public( - st.DEFAULT_VALUE, makeAny( xRow->getString( DEFAULT_VALUE ) ) ); + st.DEFAULT_VALUE, Any( xRow->getString( DEFAULT_VALUE ) ) ); // pBase->setPropertyValue_NoBroadcast_public( // st.DESCRIPTION, makeAny( xRow->getString( DESCRIPTION ) ) ); @@ -207,7 +214,7 @@ OUString columnMetaData2SDBCX( // st.HELP_TEXT, makeAny( xRow->getString( DESCRIPTION ) ) ); // else // for key columns, etc. ... pBase->setPropertyValue_NoBroadcast_public( - st.DESCRIPTION, makeAny( xRow->getString( DESCRIPTION ) ) ); + st.DESCRIPTION, Any( xRow->getString( DESCRIPTION ) ) ); // maybe a better criterion than the type name can be found in future @@ -294,11 +301,11 @@ void Columns::refresh() int columnIndex = 0; while( rs->next() ) { - Column * pColumn = + rtl::Reference<Column> pColumn = new Column( m_xMutex, m_origin, m_pSettings ); Reference< css::beans::XPropertySet > prop = pColumn; - OUString name = columnMetaData2SDBCX( pColumn, xRow ); + OUString name = columnMetaData2SDBCX( pColumn.get(), xRow ); // pColumn->addPropertyChangeListener( // st.HELP_TEXT, // new CommentChanger( @@ -310,7 +317,7 @@ void Columns::refresh() // name ) ); { - m_values.push_back( makeAny( prop ) ); + m_values.emplace_back(prop); map[ name ] = columnIndex; ++columnIndex; } @@ -328,8 +335,8 @@ void Columns::refresh() void alterColumnByDescriptor( - const OUString & schemaName, - const OUString & tableName, + std::u16string_view schemaName, + std::u16string_view tableName, ConnectionSettings *settings, const Reference< XStatement > &stmt, const css::uno::Reference< css::beans::XPropertySet > & past, @@ -399,11 +406,10 @@ void alterColumnByDescriptor( bufferQuoteQualifiedIdentifier( buf, schemaName, tableName, settings ); buf.append( "ALTER COLUMN" ); bufferQuoteIdentifier( buf, futureColumnName, settings ); - buf.append( "SET DEFAULT " ); // LEM TODO: check out // default value is not quoted, caller needs to quote himself (otherwise // how to pass e.g. nextval('something' ) ???? - buf.append( futureDefaultValue ); + buf.append( "SET DEFAULT " + futureDefaultValue ); // bufferQuoteConstant( buf, defaultValue, encoding ); transaction.executeUpdate( buf.makeStringAndClear() ); } @@ -455,7 +461,7 @@ void Columns::appendByDescriptor( osl::MutexGuard guard( m_xMutex->GetMutex() ); Statics & st = getStatics(); Reference< XPropertySet > past = createDataDescriptor(); - past->setPropertyValue( st.IS_NULLABLE, makeAny( css::sdbc::ColumnValue::NULLABLE ) ); + past->setPropertyValue( st.IS_NULLABLE, Any( css::sdbc::ColumnValue::NULLABLE ) ); alterColumnByDescriptor( m_schemaName, m_tableName, m_pSettings, m_origin->createStatement() , past, future ); @@ -487,7 +493,7 @@ void Columns::appendByDescriptor( void Columns::dropByIndex( sal_Int32 index ) { osl::MutexGuard guard( m_xMutex->GetMutex() ); - if( index < 0 || index >= static_cast<sal_Int32>(m_values.size()) ) + if( index < 0 || o3tl::make_unsigned(index) >= m_values.size() ) { throw css::lang::IndexOutOfBoundsException( "COLUMNS: Index out of range (allowed 0 to " @@ -526,14 +532,13 @@ Reference< css::container::XNameAccess > Columns::create( ConnectionSettings *pSettings, const OUString &schemaName, const OUString &tableName, - Columns **ppColumns) + rtl::Reference<Columns> *ppColumns) { *ppColumns = new Columns( refMutex, origin, pSettings, schemaName, tableName ); - Reference< css::container::XNameAccess > ret = *ppColumns; (*ppColumns)->refresh(); - return ret; + return *ppColumns; } diff --git a/connectivity/source/drivers/postgresql/pq_xcolumns.hxx b/connectivity/source/drivers/postgresql/pq_xcolumns.hxx index ab8c47914516..8ff8fcfbd95c 100644 --- a/connectivity/source/drivers/postgresql/pq_xcolumns.hxx +++ b/connectivity/source/drivers/postgresql/pq_xcolumns.hxx @@ -34,8 +34,13 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XCOLUMNS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XCOLUMNS_HXX +#pragma once + +#include <sal/config.h> + +#include <string_view> + +#include <rtl/ref.hxx> #include "pq_xcontainer.hxx" #include "pq_xbase.hxx" @@ -46,8 +51,8 @@ namespace pq_sdbc_driver { void alterColumnByDescriptor( - const OUString & schemaName, - const OUString & tableName, + std::u16string_view schemaName, + std::u16string_view tableName, ConnectionSettings *settings, const css::uno::Reference< css::sdbc::XStatement > &stmt, const css::uno::Reference< css::beans::XPropertySet > & past, @@ -68,15 +73,15 @@ public: // instances Columns 'exception safe' ConnectionSettings *pSettings, const OUString &schemaName, const OUString &tableName, - Columns **pColumns); + rtl::Reference<Columns> *pColumns); private: Columns( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName); + OUString schemaName, + OUString tableName); virtual ~Columns() override; @@ -113,6 +118,5 @@ public: // XDataDescriptorFactory }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xcontainer.cxx b/connectivity/source/drivers/postgresql/pq_xcontainer.cxx index 06323615f4b7..131148c3e192 100644 --- a/connectivity/source/drivers/postgresql/pq_xcontainer.cxx +++ b/connectivity/source/drivers/postgresql/pq_xcontainer.cxx @@ -36,7 +36,10 @@ #include <com/sun/star/container/ElementExistException.hpp> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> +#include <comphelper/diagnose_ex.hxx> #include <cppuhelper/implbase.hxx> +#include <o3tl/safeint.hxx> +#include <utility> #include "pq_xcontainer.hxx" #include "pq_statics.hxx" @@ -47,7 +50,6 @@ using osl::MutexGuard; using com::sun::star::beans::XPropertySet; using com::sun::star::uno::Any; -using com::sun::star::uno::makeAny; using com::sun::star::uno::Type; using com::sun::star::uno::XInterface; using com::sun::star::uno::Reference; @@ -76,7 +78,7 @@ public: const OUString & name, const Any & newElement, const OUString & oldElement ) : - m_event( source, makeAny( name ), newElement, makeAny(oldElement) ) + m_event( source, Any( name ), newElement, Any(oldElement) ) {} virtual void fire( XEventListener * listener ) const override @@ -97,7 +99,7 @@ public: const Reference< XInterface > & source, const OUString & name, const Any & newElement ) : - m_event( source, makeAny( name ), newElement, Any() ) + m_event( source, Any( name ), newElement, Any() ) {} virtual void fire( XEventListener * listener ) const override @@ -118,7 +120,7 @@ public: RemovedBroadcaster( const Reference< XInterface > & source, const OUString & name) : - m_event( source, makeAny( name ), Any(), Any() ) + m_event( source, Any( name ), Any(), Any() ) {} virtual void fire( XEventListener * listener ) const override @@ -136,14 +138,14 @@ public: Container::Container( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, - const css::uno::Reference< css::sdbc::XConnection > & origin, + css::uno::Reference< css::sdbc::XConnection > origin, ConnectionSettings *pSettings, - const OUString &type) + OUString type) : ContainerBase( refMutex->GetMutex() ), m_xMutex( refMutex ), m_pSettings( pSettings ), - m_origin( origin ), - m_type( type ) + m_origin(std::move( origin )), + m_type(std::move( type )) { } @@ -156,17 +158,18 @@ Any Container::getByName( const OUString& aName ) "Element " + aName + " unknown in " + m_type + "-Container", *this ); } - OSL_ASSERT( ii->second >= 0 && ii->second < static_cast<int>(m_values.size()) ); + OSL_ASSERT( ii->second >= 0 && o3tl::make_unsigned(ii->second) < m_values.size() ); return m_values[ ii->second ]; } Sequence< OUString > Container::getElementNames( ) { Sequence< OUString > ret( m_values.size() ); + auto retRange = asNonConstRange(ret); for( const auto& [rName, rIndex] : m_name2index ) { // give element names in index order ! - ret[rIndex] = rName; + retRange[rIndex] = rName; } return ret; } @@ -188,7 +191,7 @@ sal_Bool Container::hasElements( ) Any Container::getByIndex( sal_Int32 Index ) { - if( Index < 0 || Index >= static_cast<sal_Int32>(m_values.size()) ) + if( Index < 0 || o3tl::make_unsigned(Index) >= m_values.size() ) { throw IndexOutOfBoundsException( "Index " + OUString::number( Index ) @@ -211,8 +214,8 @@ class ContainerEnumeration : public ::cppu::WeakImplHelper< XEnumeration > std::vector< css::uno::Any > m_vec; sal_Int32 m_index; public: - explicit ContainerEnumeration( const std::vector< css::uno::Any > &vec ) - : m_vec( vec ), + explicit ContainerEnumeration( std::vector< css::uno::Any >&& vec ) + : m_vec( std::move(vec) ), m_index( -1 ) {} @@ -243,7 +246,7 @@ css::uno::Any ContainerEnumeration::nextElement() Reference< XEnumeration > Container::createEnumeration( ) { - return new ContainerEnumeration( m_values ); + return new ContainerEnumeration( std::vector(m_values) ); } void Container::addRefreshListener( @@ -298,7 +301,7 @@ void Container::dropByName( const OUString& elementName ) void Container::dropByIndex( sal_Int32 index ) { osl::MutexGuard guard( m_xMutex->GetMutex() ); - if( index < 0 || index >=static_cast<sal_Int32>(m_values.size()) ) + if( index < 0 || o3tl::make_unsigned(index) >=m_values.size() ) { throw css::lang::IndexOutOfBoundsException( "Index out of range (allowed 0 to " @@ -349,10 +352,10 @@ void Container::append( } int index = m_values.size(); - m_values.push_back( makeAny( descriptor ) ); + m_values.emplace_back(descriptor); m_name2index[name] = index; - fire( InsertedBroadcaster( *this, name, makeAny( descriptor ) ) ); + fire( InsertedBroadcaster( *this, name, Any( descriptor ) ) ); } void Container::appendByDescriptor( @@ -390,13 +393,13 @@ void Container::fire( const EventBroadcastHelper &helper ) } catch ( css::uno::RuntimeException & ) { - OSL_ENSURE( false, "exception caught" ); + TOOLS_WARN_EXCEPTION( "connectivity.postgresql", "exception caught" ); // loose coupling, a runtime exception shall not break anything // TODO: log away as warning ! } catch( css::uno::Exception & ) { - OSL_ENSURE( false, "exception from listener flying through" ); + TOOLS_WARN_EXCEPTION( "connectivity.postgresql", "exception from listener flying through" ); throw; } } diff --git a/connectivity/source/drivers/postgresql/pq_xcontainer.hxx b/connectivity/source/drivers/postgresql/pq_xcontainer.hxx index f53b0303ae1b..4b6c190b0a59 100644 --- a/connectivity/source/drivers/postgresql/pq_xcontainer.hxx +++ b/connectivity/source/drivers/postgresql/pq_xcontainer.hxx @@ -34,29 +34,30 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XCONTAINER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XCONTAINER_HXX +#pragma once #include <com/sun/star/container/XNameAccess.hpp> #include <com/sun/star/container/XIndexAccess.hpp> #include <com/sun/star/container/XEnumerationAccess.hpp> #include <com/sun/star/container/XContainer.hpp> +#include <com/sun/star/sdbc/XConnection.hpp> #include <com/sun/star/sdbcx/XAppend.hpp> #include <com/sun/star/sdbcx/XDrop.hpp> #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp> #include <com/sun/star/util/XRefreshable.hpp> +#include <comphelper/refcountedmutex.hxx> #include <cppuhelper/compbase.hxx> +#include <rtl/ref.hxx> #include <unordered_map> -#include "pq_connection.hxx" -#include "pq_statics.hxx" - namespace pq_sdbc_driver { +struct ConnectionSettings; + class EventBroadcastHelper { public: @@ -116,9 +117,9 @@ protected: public: Container( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, - const css::uno::Reference< css::sdbc::XConnection > & origin, + css::uno::Reference< css::sdbc::XConnection > origin, ConnectionSettings *pSettings, - const OUString & type // for exception messages + OUString type // for exception messages ); public: // XIndexAccess @@ -183,6 +184,5 @@ protected: }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xindex.cxx b/connectivity/source/drivers/postgresql/pq_xindex.cxx index c340484a17df..4753b5fd4e3c 100644 --- a/connectivity/source/drivers/postgresql/pq_xindex.cxx +++ b/connectivity/source/drivers/postgresql/pq_xindex.cxx @@ -36,6 +36,8 @@ #include <cppuhelper/typeprovider.hxx> #include <cppuhelper/queryinterface.hxx> +#include <rtl/ref.hxx> +#include <utility> #include "pq_xindex.hxx" #include "pq_xindexcolumns.hxx" @@ -57,8 +59,8 @@ namespace pq_sdbc_driver Index::Index( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const Reference< css::sdbc::XConnection > & connection, ConnectionSettings *pSettings, - const OUString & schemaName, - const OUString & tableName ) + OUString schemaName, + OUString tableName ) : ReflectionBase( getStatics().refl.index.implName, getStatics().refl.index.serviceNames, @@ -66,13 +68,13 @@ Index::Index( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, connection, pSettings, * getStatics().refl.index.pProps ), - m_schemaName( schemaName ), - m_tableName( tableName ) + m_schemaName(std::move( schemaName )), + m_tableName(std::move( tableName )) {} Reference< XPropertySet > Index::createDataDescriptor( ) { - IndexDescriptor * pIndex = new IndexDescriptor( + rtl::Reference<IndexDescriptor> pIndex = new IndexDescriptor( m_xMutex, m_conn, m_pSettings ); pIndex->copyValuesFrom( this ); @@ -133,7 +135,7 @@ IndexDescriptor::IndexDescriptor( Reference< XPropertySet > IndexDescriptor::createDataDescriptor( ) { - IndexDescriptor * pIndex = new IndexDescriptor( + rtl::Reference<IndexDescriptor> pIndex = new IndexDescriptor( m_xMutex, m_conn, m_pSettings ); pIndex->copyValuesFrom( this ); return Reference< XPropertySet > ( pIndex ); diff --git a/connectivity/source/drivers/postgresql/pq_xindex.hxx b/connectivity/source/drivers/postgresql/pq_xindex.hxx index 26e5613630a2..8ccf45660467 100644 --- a/connectivity/source/drivers/postgresql/pq_xindex.hxx +++ b/connectivity/source/drivers/postgresql/pq_xindex.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XINDEX_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XINDEX_HXX +#pragma once #include <cppuhelper/component.hxx> #include <cppuhelper/propshlp.hxx> @@ -62,12 +61,12 @@ public: Index( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & connection, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName); + OUString schemaName, + OUString tableName); public: // XInterface - virtual void SAL_CALL acquire() throw() override { ReflectionBase::acquire(); } - virtual void SAL_CALL release() throw() override { ReflectionBase::release(); } + virtual void SAL_CALL acquire() noexcept override { ReflectionBase::acquire(); } + virtual void SAL_CALL release() noexcept override { ReflectionBase::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -98,8 +97,8 @@ public: ConnectionSettings *pSettings); public: // XInterface - virtual void SAL_CALL acquire() throw() override { ReflectionBase::acquire(); } - virtual void SAL_CALL release() throw() override { ReflectionBase::release(); } + virtual void SAL_CALL acquire() noexcept override { ReflectionBase::acquire(); } + virtual void SAL_CALL release() noexcept override { ReflectionBase::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -121,6 +120,4 @@ public: // XDataDescriptorFactory } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xindexcolumn.cxx b/connectivity/source/drivers/postgresql/pq_xindexcolumn.cxx index 58b36234b1fb..fe72059bc15a 100644 --- a/connectivity/source/drivers/postgresql/pq_xindexcolumn.cxx +++ b/connectivity/source/drivers/postgresql/pq_xindexcolumn.cxx @@ -34,6 +34,11 @@ * ************************************************************************/ +#include <sal/config.h> + +#include <rtl/ref.hxx> + +#include "pq_statics.hxx" #include "pq_xindexcolumn.hxx" using com::sun::star::uno::Reference; @@ -56,7 +61,7 @@ IndexColumn::IndexColumn( const ::rtl::Reference< comphelper::RefCountedMutex > Reference< XPropertySet > IndexColumn::createDataDescriptor( ) { - IndexColumnDescriptor * pIndexColumn = new IndexColumnDescriptor( + rtl::Reference<IndexColumnDescriptor> pIndexColumn = new IndexColumnDescriptor( m_xMutex, m_conn, m_pSettings ); pIndexColumn->copyValuesFrom( this ); @@ -79,7 +84,7 @@ IndexColumnDescriptor::IndexColumnDescriptor( Reference< XPropertySet > IndexColumnDescriptor::createDataDescriptor( ) { - IndexColumnDescriptor * pIndexColumn = new IndexColumnDescriptor( + rtl::Reference<IndexColumnDescriptor> pIndexColumn = new IndexColumnDescriptor( m_xMutex, m_conn, m_pSettings ); pIndexColumn->copyValuesFrom( this ); diff --git a/connectivity/source/drivers/postgresql/pq_xindexcolumn.hxx b/connectivity/source/drivers/postgresql/pq_xindexcolumn.hxx index 5e7ae8d4fa65..7872985ec801 100644 --- a/connectivity/source/drivers/postgresql/pq_xindexcolumn.hxx +++ b/connectivity/source/drivers/postgresql/pq_xindexcolumn.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XINDEXCOLUMN_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XINDEXCOLUMN_HXX +#pragma once #include <cppuhelper/component.hxx> #include <cppuhelper/propshlp.hxx> @@ -81,6 +80,4 @@ public: // XDataDescriptorFactory } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xindexcolumns.cxx b/connectivity/source/drivers/postgresql/pq_xindexcolumns.cxx index 12acb6f321d6..2bca00e13b77 100644 --- a/connectivity/source/drivers/postgresql/pq_xindexcolumns.cxx +++ b/connectivity/source/drivers/postgresql/pq_xindexcolumns.cxx @@ -35,12 +35,16 @@ ************************************************************************/ #include <sal/log.hxx> + +#include <string_view> +#include <utility> #include <vector> #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/sdbc/XRow.hpp> #include <cppuhelper/exc_hlp.hxx> +#include <rtl/ref.hxx> #include "pq_xcolumns.hxx" #include "pq_xindexcolumns.hxx" @@ -53,7 +57,6 @@ using osl::MutexGuard; using com::sun::star::beans::XPropertySet; using com::sun::star::uno::Any; -using com::sun::star::uno::makeAny; using com::sun::star::uno::UNO_QUERY; using com::sun::star::uno::Reference; using com::sun::star::uno::Sequence; @@ -70,21 +73,21 @@ IndexColumns::IndexColumns( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName, - const OUString &indexName, + OUString schemaName, + OUString tableName, + OUString indexName, const css::uno::Sequence< OUString > &columns ) : Container( refMutex, origin, pSettings, "INDEX_COLUMN" ), - m_schemaName( schemaName ), - m_tableName( tableName ), - m_indexName( indexName ), + m_schemaName(std::move( schemaName )), + m_tableName(std::move( tableName )), + m_indexName(std::move( indexName )), m_columns( columns ) {} IndexColumns::~IndexColumns() {} -static sal_Int32 findInSequence( const Sequence< OUString > & seq , const OUString &str) +static sal_Int32 findInSequence( const Sequence< OUString > & seq , std::u16string_view str) { int index; for( index = 0 ; index < seq.getLength() ; index ++ ) @@ -122,13 +125,13 @@ void IndexColumns::refresh() if( index >= m_columns.getLength() ) continue; - IndexColumn * pIndexColumn = + rtl::Reference<IndexColumn> pIndexColumn = new IndexColumn( m_xMutex, m_origin, m_pSettings ); Reference< css::beans::XPropertySet > prop = pIndexColumn; - columnMetaData2SDBCX( pIndexColumn, xRow ); + columnMetaData2SDBCX( pIndexColumn.get(), xRow ); pIndexColumn->setPropertyValue_NoBroadcast_public( - st.IS_ASCENDING , makeAny( false ) ); + st.IS_ASCENDING , Any( false ) ); m_values[ index ] <<= prop; m_name2index[ columnName ] = index; @@ -232,12 +235,11 @@ Reference< css::container::XNameAccess > IndexColumns::create( const OUString &indexName, const Sequence< OUString > &columns ) { - IndexColumns *pIndexColumns = new IndexColumns( + rtl::Reference<IndexColumns> pIndexColumns = new IndexColumns( refMutex, origin, pSettings, schemaName, tableName, indexName, columns ); - Reference< css::container::XNameAccess > ret = pIndexColumns; pIndexColumns->refresh(); - return ret; + return pIndexColumns; } diff --git a/connectivity/source/drivers/postgresql/pq_xindexcolumns.hxx b/connectivity/source/drivers/postgresql/pq_xindexcolumns.hxx index 353b75ddbf63..a838d5d66908 100644 --- a/connectivity/source/drivers/postgresql/pq_xindexcolumns.hxx +++ b/connectivity/source/drivers/postgresql/pq_xindexcolumns.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XINDEXCOLUMNS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XINDEXCOLUMNS_HXX +#pragma once #include "pq_xcontainer.hxx" @@ -64,9 +63,9 @@ private: const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName, - const OUString &indexName, + OUString schemaName, + OUString tableName, + OUString indexName, const css::uno::Sequence< OUString > &columns ); virtual ~IndexColumns() override; @@ -107,6 +106,5 @@ public: // XDataDescriptorFactory }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xindexes.cxx b/connectivity/source/drivers/postgresql/pq_xindexes.cxx index 2f6df914f0a2..bff96216c568 100644 --- a/connectivity/source/drivers/postgresql/pq_xindexes.cxx +++ b/connectivity/source/drivers/postgresql/pq_xindexes.cxx @@ -35,6 +35,7 @@ ************************************************************************/ #include <sal/log.hxx> +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> @@ -42,6 +43,8 @@ #include <com/sun/star/sdbc/XRow.hpp> #include <com/sun/star/sdbc/XParameters.hpp> #include <cppuhelper/exc_hlp.hxx> +#include <o3tl/safeint.hxx> +#include <utility> #include "pq_xindexes.hxx" #include "pq_xindex.hxx" @@ -54,7 +57,6 @@ using osl::MutexGuard; using com::sun::star::beans::XPropertySet; using com::sun::star::uno::Any; -using com::sun::star::uno::makeAny; using com::sun::star::uno::UNO_QUERY; using com::sun::star::uno::Reference; using com::sun::star::uno::Sequence; @@ -77,11 +79,11 @@ Indexes::Indexes( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName) + OUString schemaName, + OUString tableName) : Container( refMutex, origin, pSettings, getStatics().KEY ), - m_schemaName( schemaName ), - m_tableName( tableName ) + m_schemaName(std::move( schemaName )), + m_tableName(std::move( tableName )) { } @@ -133,7 +135,7 @@ void Indexes::refresh() static const sal_Int32 C_IS_PRIMARY = 6; static const sal_Int32 C_COLUMNS = 7; OUString currentIndexName = row->getString( C_INDEXNAME ); - Index *pIndex = + rtl::Reference<Index> pIndex = new Index( m_xMutex, m_origin, m_pSettings, m_schemaName, m_tableName ); @@ -148,20 +150,21 @@ void Indexes::refresh() pIndex->setPropertyValue_NoBroadcast_public( st.IS_CLUSTERED, Any( isClusterd ) ); pIndex->setPropertyValue_NoBroadcast_public( - st.NAME, makeAny( currentIndexName ) ); + st.NAME, Any( currentIndexName ) ); std::vector< sal_Int32 > seq = parseIntArray( row->getString( C_COLUMNS ) ); Sequence< OUString > columnNames(seq.size()); + auto columnNamesRange = asNonConstRange(columnNames); for( size_t columns = 0 ; columns < seq.size() ; columns ++ ) { - columnNames[columns] = column2NameMap[ seq[columns] ]; + columnNamesRange[columns] = column2NameMap[ seq[columns] ]; } pIndex->setPropertyValue_NoBroadcast_public( - st.PRIVATE_COLUMN_INDEXES, makeAny( columnNames )); + st.PRIVATE_COLUMN_INDEXES, Any( columnNames )); { - m_values.push_back( makeAny( prop ) ); + m_values.emplace_back(prop); map[ currentIndexName ] = index; ++index; } @@ -233,7 +236,7 @@ void Indexes::dropByIndex( sal_Int32 index ) osl::MutexGuard guard( m_xMutex->GetMutex() ); - if( index < 0 || index >= static_cast<sal_Int32>(m_values.size()) ) + if( index < 0 || o3tl::make_unsigned(index) >= m_values.size() ) { throw css::lang::IndexOutOfBoundsException( "Indexes: Index out of range (allowed 0 to " @@ -268,10 +271,10 @@ Reference< css::container::XNameAccess > Indexes::create( const OUString & schemaName, const OUString & tableName) { - Indexes *pIndexes = new Indexes( refMutex, origin, pSettings, schemaName, tableName ); - Reference< css::container::XNameAccess > ret = pIndexes; + rtl::Reference<Indexes> pIndexes + = new Indexes( refMutex, origin, pSettings, schemaName, tableName ); pIndexes->refresh(); - return ret; + return pIndexes; } diff --git a/connectivity/source/drivers/postgresql/pq_xindexes.hxx b/connectivity/source/drivers/postgresql/pq_xindexes.hxx index 7991058f5799..536d17b96198 100644 --- a/connectivity/source/drivers/postgresql/pq_xindexes.hxx +++ b/connectivity/source/drivers/postgresql/pq_xindexes.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XINDEXES_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XINDEXES_HXX +#pragma once #include "pq_xcontainer.hxx" @@ -59,8 +58,8 @@ private: const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName); + OUString schemaName, + OUString tableName); virtual ~Indexes() override; @@ -99,6 +98,5 @@ public: // XDataDescriptorFactory }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xkey.cxx b/connectivity/source/drivers/postgresql/pq_xkey.cxx index ed0b2669e894..81d1f7a86eb6 100644 --- a/connectivity/source/drivers/postgresql/pq_xkey.cxx +++ b/connectivity/source/drivers/postgresql/pq_xkey.cxx @@ -36,6 +36,8 @@ #include <cppuhelper/typeprovider.hxx> #include <cppuhelper/queryinterface.hxx> +#include <rtl/ref.hxx> +#include <utility> #include "pq_xkey.hxx" #include "pq_xkeycolumns.hxx" @@ -56,8 +58,8 @@ namespace pq_sdbc_driver Key::Key( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const Reference< css::sdbc::XConnection > & connection, ConnectionSettings *pSettings, - const OUString & schemaName, - const OUString & tableName ) + OUString schemaName, + OUString tableName ) : ReflectionBase( getStatics().refl.key.implName, getStatics().refl.key.serviceNames, @@ -65,13 +67,13 @@ Key::Key( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, connection, pSettings, * getStatics().refl.key.pProps ), - m_schemaName( schemaName ), - m_tableName( tableName ) + m_schemaName(std::move( schemaName )), + m_tableName(std::move( tableName )) {} Reference< XPropertySet > Key::createDataDescriptor( ) { - KeyDescriptor * pKeyDescriptor = new KeyDescriptor( + rtl::Reference<KeyDescriptor> pKeyDescriptor = new KeyDescriptor( m_xMutex, m_conn, m_pSettings ); pKeyDescriptor->copyValuesFrom( this ); @@ -134,7 +136,7 @@ KeyDescriptor::KeyDescriptor( const ::rtl::Reference< comphelper::RefCountedMute Reference< XPropertySet > KeyDescriptor::createDataDescriptor( ) { - KeyDescriptor * pKeyDescriptor = new KeyDescriptor( + rtl::Reference<KeyDescriptor> pKeyDescriptor = new KeyDescriptor( m_xMutex, m_conn, m_pSettings ); pKeyDescriptor->copyValuesFrom( this ); diff --git a/connectivity/source/drivers/postgresql/pq_xkey.hxx b/connectivity/source/drivers/postgresql/pq_xkey.hxx index 3174d189206b..68f05fd27d4e 100644 --- a/connectivity/source/drivers/postgresql/pq_xkey.hxx +++ b/connectivity/source/drivers/postgresql/pq_xkey.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XKEY_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XKEY_HXX +#pragma once #include <cppuhelper/component.hxx> #include <cppuhelper/propshlp.hxx> @@ -62,12 +61,12 @@ public: Key( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & connection, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName); + OUString schemaName, + OUString tableName); public: // XInterface - virtual void SAL_CALL acquire() throw() override { ReflectionBase::acquire(); } - virtual void SAL_CALL release() throw() override { ReflectionBase::release(); } + virtual void SAL_CALL acquire() noexcept override { ReflectionBase::acquire(); } + virtual void SAL_CALL release() noexcept override { ReflectionBase::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -96,8 +95,8 @@ public: ConnectionSettings *pSettings ); public: // XInterface - virtual void SAL_CALL acquire() throw() override { ReflectionBase::acquire(); } - virtual void SAL_CALL release() throw() override { ReflectionBase::release(); } + virtual void SAL_CALL acquire() noexcept override { ReflectionBase::acquire(); } + virtual void SAL_CALL release() noexcept override { ReflectionBase::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -117,6 +116,4 @@ public: // XDataDescriptorFactory } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xkeycolumn.cxx b/connectivity/source/drivers/postgresql/pq_xkeycolumn.cxx index 9eea45204f3d..30eef179716c 100644 --- a/connectivity/source/drivers/postgresql/pq_xkeycolumn.cxx +++ b/connectivity/source/drivers/postgresql/pq_xkeycolumn.cxx @@ -34,6 +34,11 @@ * ************************************************************************/ +#include <sal/config.h> + +#include <rtl/ref.hxx> + +#include "pq_statics.hxx" #include "pq_xkeycolumn.hxx" using com::sun::star::uno::Reference; @@ -56,7 +61,7 @@ KeyColumn::KeyColumn( const ::rtl::Reference< comphelper::RefCountedMutex > & re Reference< XPropertySet > KeyColumn::createDataDescriptor( ) { - KeyColumnDescriptor * pKeyColumn = new KeyColumnDescriptor( + rtl::Reference<KeyColumnDescriptor> pKeyColumn = new KeyColumnDescriptor( m_xMutex, m_conn, m_pSettings ); pKeyColumn->copyValuesFrom( this ); @@ -78,7 +83,7 @@ KeyColumnDescriptor::KeyColumnDescriptor( Reference< XPropertySet > KeyColumnDescriptor::createDataDescriptor( ) { - KeyColumnDescriptor * pKeyColumn = new KeyColumnDescriptor( + rtl::Reference<KeyColumnDescriptor> pKeyColumn = new KeyColumnDescriptor( m_xMutex, m_conn, m_pSettings ); pKeyColumn->copyValuesFrom( this ); diff --git a/connectivity/source/drivers/postgresql/pq_xkeycolumn.hxx b/connectivity/source/drivers/postgresql/pq_xkeycolumn.hxx index 14baf7f66cf2..7d49d5d26570 100644 --- a/connectivity/source/drivers/postgresql/pq_xkeycolumn.hxx +++ b/connectivity/source/drivers/postgresql/pq_xkeycolumn.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XKEYCOLUMN_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XKEYCOLUMN_HXX +#pragma once #include <cppuhelper/component.hxx> #include <cppuhelper/propshlp.hxx> @@ -80,6 +79,4 @@ public: // XDataDescriptorFactory } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xkeycolumns.cxx b/connectivity/source/drivers/postgresql/pq_xkeycolumns.cxx index 890b57fa7420..89f63ceb5a65 100644 --- a/connectivity/source/drivers/postgresql/pq_xkeycolumns.cxx +++ b/connectivity/source/drivers/postgresql/pq_xkeycolumns.cxx @@ -39,6 +39,8 @@ #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/sdbc/XRow.hpp> #include <cppuhelper/exc_hlp.hxx> +#include <rtl/ref.hxx> +#include <utility> #include "pq_xcolumns.hxx" #include "pq_xkeycolumns.hxx" @@ -51,7 +53,6 @@ using osl::MutexGuard; using com::sun::star::beans::XPropertySet; using com::sun::star::uno::Any; -using com::sun::star::uno::makeAny; using com::sun::star::uno::UNO_QUERY; using com::sun::star::uno::Reference; using com::sun::star::uno::Sequence; @@ -68,13 +69,13 @@ KeyColumns::KeyColumns( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName, + OUString schemaName, + OUString tableName, const Sequence< OUString > &columnNames, const Sequence< OUString > &foreignColumnNames ) : Container( refMutex, origin, pSettings, "KEY_COLUMN" ), - m_schemaName( schemaName ), - m_tableName( tableName ), + m_schemaName(std::move( schemaName )), + m_tableName(std::move( tableName )), m_columnNames( columnNames ), m_foreignColumnNames( foreignColumnNames ) {} @@ -117,19 +118,19 @@ void KeyColumns::refresh() if( m_columnNames.getLength() == keyindex ) continue; - KeyColumn * pKeyColumn = + rtl::Reference<KeyColumn> pKeyColumn = new KeyColumn( m_xMutex, m_origin, m_pSettings ); Reference< css::beans::XPropertySet > prop = pKeyColumn; - OUString name = columnMetaData2SDBCX( pKeyColumn, xRow ); + OUString name = columnMetaData2SDBCX( pKeyColumn.get(), xRow ); if( keyindex < m_foreignColumnNames.getLength() ) { pKeyColumn->setPropertyValue_NoBroadcast_public( - st.RELATED_COLUMN, makeAny( m_foreignColumnNames[keyindex]) ); + st.RELATED_COLUMN, Any( m_foreignColumnNames[keyindex]) ); } { - m_values.push_back( makeAny( prop ) ); + m_values.emplace_back(prop); map[ name ] = columnIndex; ++columnIndex; } @@ -214,12 +215,11 @@ Reference< css::container::XNameAccess > KeyColumns::create( const Sequence< OUString > &columnNames , const Sequence< OUString > &foreignColumnNames ) { - KeyColumns *pKeyColumns = new KeyColumns( + rtl::Reference<KeyColumns> pKeyColumns = new KeyColumns( refMutex, origin, pSettings, schemaName, tableName, columnNames, foreignColumnNames ); - Reference< css::container::XNameAccess > ret = pKeyColumns; pKeyColumns->refresh(); - return ret; + return pKeyColumns; } diff --git a/connectivity/source/drivers/postgresql/pq_xkeycolumns.hxx b/connectivity/source/drivers/postgresql/pq_xkeycolumns.hxx index 0ada98aa4052..60bbd0c0de36 100644 --- a/connectivity/source/drivers/postgresql/pq_xkeycolumns.hxx +++ b/connectivity/source/drivers/postgresql/pq_xkeycolumns.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XKEYCOLUMNS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XKEYCOLUMNS_HXX +#pragma once #include "pq_xcontainer.hxx" @@ -64,8 +63,8 @@ private: const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName, + OUString schemaName, + OUString tableName, const css::uno::Sequence< OUString > &keyColumns, const css::uno::Sequence< OUString > &foreignColumnNames); @@ -98,6 +97,5 @@ public: // XDataDescriptorFactory virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL createDataDescriptor( ) override; }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xkeys.cxx b/connectivity/source/drivers/postgresql/pq_xkeys.cxx index 2297b557e6af..0758be630e04 100644 --- a/connectivity/source/drivers/postgresql/pq_xkeys.cxx +++ b/connectivity/source/drivers/postgresql/pq_xkeys.cxx @@ -34,7 +34,12 @@ * ************************************************************************/ +#include <sal/config.h> + +#include <string_view> + #include <sal/log.hxx> +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> @@ -44,6 +49,8 @@ #include <com/sun/star/sdbc/KeyRule.hpp> #include <com/sun/star/sdbcx/KeyType.hpp> #include <cppuhelper/exc_hlp.hxx> +#include <o3tl/safeint.hxx> +#include <utility> #include "pq_xkeys.hxx" #include "pq_xkey.hxx" @@ -55,7 +62,7 @@ using osl::MutexGuard; using css::beans::XPropertySet; -using com::sun::star::uno::makeAny; +using com::sun::star::uno::Any; using com::sun::star::uno::UNO_QUERY; using com::sun::star::uno::Reference; @@ -73,36 +80,36 @@ Keys::Keys( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName) + OUString schemaName, + OUString tableName) : Container( refMutex, origin, pSettings, getStatics().KEY ), - m_schemaName( schemaName ), - m_tableName( tableName ) + m_schemaName(std::move( schemaName )), + m_tableName(std::move( tableName )) {} Keys::~Keys() {} -static sal_Int32 string2keytype( const OUString &type ) +static sal_Int32 string2keytype( std::u16string_view type ) { sal_Int32 ret = css::sdbcx::KeyType::UNIQUE; - if ( type == "p" ) + if ( type == u"p" ) ret = css::sdbcx::KeyType::PRIMARY; - else if ( type == "f" ) + else if ( type == u"f" ) ret = css::sdbcx::KeyType::FOREIGN; return ret; } -static sal_Int32 string2keyrule( const OUString & rule ) +static sal_Int32 string2keyrule( std::u16string_view rule ) { sal_Int32 ret = css::sdbc::KeyRule::NO_ACTION; - if( rule == "r" ) + if( rule == u"r" ) ret = css::sdbc::KeyRule::RESTRICT; - else if( rule == "c" ) + else if( rule == u"c" ) ret = css::sdbc::KeyRule::CASCADE; - else if( rule == "n" ) + else if( rule == u"n" ) ret = css::sdbc::KeyRule::SET_NULL; - else if( rule == "d" ) + else if( rule == u"d" ) ret = css::sdbc::KeyRule::SET_DEFAULT; return ret; } @@ -146,37 +153,36 @@ void Keys::refresh() int keyIndex = 0; while( rs->next() ) { - Key * pKey = + rtl::Reference<Key> pKey = new Key( m_xMutex, m_origin, m_pSettings , m_schemaName, m_tableName ); Reference< css::beans::XPropertySet > prop = pKey; pKey->setPropertyValue_NoBroadcast_public( - st.NAME, makeAny( xRow->getString( 1 ) ) ); + st.NAME, Any( xRow->getString( 1 ) ) ); sal_Int32 keyType = string2keytype( xRow->getString(2) ); - pKey->setPropertyValue_NoBroadcast_public( st.TYPE, makeAny( keyType ) ); + pKey->setPropertyValue_NoBroadcast_public( st.TYPE, Any( keyType ) ); pKey->setPropertyValue_NoBroadcast_public( - st.UPDATE_RULE, makeAny( string2keyrule( xRow->getString(3) ) ) ); + st.UPDATE_RULE, Any( string2keyrule( xRow->getString(3) ) ) ); pKey->setPropertyValue_NoBroadcast_public( - st.DELETE_RULE, makeAny( string2keyrule( xRow->getString(4) ) ) ); + st.DELETE_RULE, Any( string2keyrule( xRow->getString(4) ) ) ); pKey->setPropertyValue_NoBroadcast_public( st.PRIVATE_COLUMNS, - makeAny( + Any( convertMappedIntArray2StringArray( mainMap, string2intarray( xRow->getString( 7 ) ) ) ) ); if( css::sdbcx::KeyType::FOREIGN == keyType ) { - OUStringBuffer buf( 128 ); - buf.append( xRow->getString( 6 ) ).append( "." ).append( xRow->getString( 5 ) ); + OUString buf = xRow->getString( 6 ) + "." + xRow->getString( 5 ); pKey->setPropertyValue_NoBroadcast_public( - st.REFERENCED_TABLE, makeAny( buf.makeStringAndClear() ) ); + st.REFERENCED_TABLE, Any( buf ) ); Int2StringMap foreignMap; fillAttnum2attnameMap( foreignMap, m_origin, xRow->getString(6), xRow->getString(5)); pKey->setPropertyValue_NoBroadcast_public( st.PRIVATE_FOREIGN_COLUMNS, - makeAny( + Any( convertMappedIntArray2StringArray( foreignMap, string2intarray( xRow->getString(8) ) ) ) ); @@ -185,7 +191,7 @@ void Keys::refresh() { map[ xRow->getString( 1 ) ] = keyIndex; - m_values.push_back( makeAny( prop ) ); + m_values.push_back( Any( prop ) ); ++keyIndex; } } @@ -222,7 +228,7 @@ void Keys::appendByDescriptor( void Keys::dropByIndex( sal_Int32 index ) { osl::MutexGuard guard( m_xMutex->GetMutex() ); - if( index < 0 || index >= static_cast<sal_Int32>(m_values.size()) ) + if( index < 0 || o3tl::make_unsigned(index) >= m_values.size() ) { throw css::lang::IndexOutOfBoundsException( "TABLES: Index out of range (allowed 0 to " + OUString::number(m_values.size() -1) @@ -258,11 +264,10 @@ Reference< css::container::XIndexAccess > Keys::create( const OUString & schemaName, const OUString & tableName) { - Keys *pKeys = new Keys( refMutex, origin, pSettings, schemaName, tableName ); - Reference< css::container::XIndexAccess > ret = pKeys; + rtl::Reference<Keys> pKeys = new Keys( refMutex, origin, pSettings, schemaName, tableName ); pKeys->refresh(); - return ret; + return pKeys; } KeyDescriptors::KeyDescriptors( diff --git a/connectivity/source/drivers/postgresql/pq_xkeys.hxx b/connectivity/source/drivers/postgresql/pq_xkeys.hxx index aedd46b578da..ef6376d4d780 100644 --- a/connectivity/source/drivers/postgresql/pq_xkeys.hxx +++ b/connectivity/source/drivers/postgresql/pq_xkeys.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XKEYS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XKEYS_HXX +#pragma once #include "pq_xcontainer.hxx" @@ -59,8 +58,8 @@ private: const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - const OUString &schemaName, - const OUString &tableName); + OUString schemaName, + OUString tableName); virtual ~Keys() override; @@ -98,6 +97,5 @@ public: // XDataDescriptorFactory }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xtable.cxx b/connectivity/source/drivers/postgresql/pq_xtable.cxx index 82b66a316a3f..de8196f9fecd 100644 --- a/connectivity/source/drivers/postgresql/pq_xtable.cxx +++ b/connectivity/source/drivers/postgresql/pq_xtable.cxx @@ -34,6 +34,7 @@ * ************************************************************************/ +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <cppuhelper/typeprovider.hxx> @@ -59,7 +60,6 @@ using com::sun::star::uno::Reference; using com::sun::star::uno::UNO_QUERY; using com::sun::star::uno::Sequence; using com::sun::star::uno::Any; -using com::sun::star::uno::makeAny; using com::sun::star::uno::Type; using com::sun::star::beans::XPropertySet; @@ -78,13 +78,12 @@ Table::Table( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, refMutex, connection, pSettings, - * getStatics().refl.table.pProps ), - m_pColumns( nullptr ) + * getStatics().refl.table.pProps ) {} Reference< XPropertySet > Table::createDataDescriptor( ) { - TableDescriptor * pTable = new TableDescriptor( + rtl::Reference<TableDescriptor> pTable = new TableDescriptor( m_xMutex, m_conn, m_pSettings ); pTable->copyValuesFrom( this ); @@ -168,7 +167,7 @@ void Table::rename( const OUString& newName ) if( Xrename.is() ) { Xrename->rename( newName ); - setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME, makeAny(newSchemaName) ); + setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME, Any(newSchemaName) ); } } else @@ -185,14 +184,13 @@ void Table::rename( const OUString& newName ) bufferQuoteIdentifier( buf, newSchemaName, m_pSettings ); Reference< XStatement > statement = m_conn->createStatement(); statement->executeUpdate( buf.makeStringAndClear() ); - setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME, makeAny(newSchemaName) ); + setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME, Any(newSchemaName) ); disposeNoThrow( statement ); schema = newSchemaName; } catch( css::sdbc::SQLException &e ) { - OUString buf( e.Message + "(NOTE: Only postgresql server >= V8.1 support changing a table's schema)" ); - e.Message = buf; + e.Message += "(NOTE: Only postgresql server >= V8.1 support changing a table's schema)"; throw; } @@ -209,7 +207,7 @@ void Table::rename( const OUString& newName ) disposeNoThrow( statement ); } } - setPropertyValue_NoBroadcast_public( st.NAME, makeAny(newTableName) ); + setPropertyValue_NoBroadcast_public( st.NAME, Any(newTableName) ); // inform the container of the name change ! if( m_pSettings->tables.is() ) { @@ -381,7 +379,7 @@ Any TableDescriptor::queryInterface( const Type & reqType ) Reference< XPropertySet > TableDescriptor::createDataDescriptor( ) { - TableDescriptor * pTable = new TableDescriptor( + rtl::Reference<TableDescriptor> pTable = new TableDescriptor( m_xMutex, m_conn, m_pSettings ); // TODO: deep copies diff --git a/connectivity/source/drivers/postgresql/pq_xtable.hxx b/connectivity/source/drivers/postgresql/pq_xtable.hxx index 69e9d6435c8a..7c8ca73f566b 100644 --- a/connectivity/source/drivers/postgresql/pq_xtable.hxx +++ b/connectivity/source/drivers/postgresql/pq_xtable.hxx @@ -34,22 +34,16 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XTABLE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XTABLE_HXX +#pragma once -#include <cppuhelper/component.hxx> -#include <cppuhelper/propshlp.hxx> - -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp> #include <com/sun/star/sdbcx/XColumnsSupplier.hpp> #include <com/sun/star/sdbcx/XIndexesSupplier.hpp> #include <com/sun/star/sdbcx/XKeysSupplier.hpp> #include <com/sun/star/sdbcx/XRename.hpp> #include <com/sun/star/sdbcx/XAlterTable.hpp> -#include <com/sun/star/container/XNamed.hpp> #include "pq_xbase.hxx" +#include "pq_xcolumns.hxx" namespace pq_sdbc_driver { @@ -66,7 +60,7 @@ class Table : public ReflectionBase, css::uno::Reference< css::container::XNameAccess > m_columns; css::uno::Reference< css::container::XIndexAccess > m_keys; css::uno::Reference< css::container::XNameAccess > m_indexes; - Columns *m_pColumns; + rtl::Reference<Columns> m_pColumns; public: Table( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, @@ -74,8 +68,8 @@ public: ConnectionSettings *pSettings); // XInterface - virtual void SAL_CALL acquire() throw() override { ReflectionBase::acquire(); } - virtual void SAL_CALL release() throw() override { ReflectionBase::release(); } + virtual void SAL_CALL acquire() noexcept override { ReflectionBase::acquire(); } + virtual void SAL_CALL release() noexcept override { ReflectionBase::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -134,8 +128,8 @@ public: ConnectionSettings *pSettings); public: // XInterface - virtual void SAL_CALL acquire() throw() override { ReflectionBase::acquire(); } - virtual void SAL_CALL release() throw() override { ReflectionBase::release(); } + virtual void SAL_CALL acquire() noexcept override { ReflectionBase::acquire(); } + virtual void SAL_CALL release() noexcept override { ReflectionBase::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -164,6 +158,4 @@ public: // XDataDescriptorFactory } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xtables.cxx b/connectivity/source/drivers/postgresql/pq_xtables.cxx index 83758208b203..423ec81f2166 100644 --- a/connectivity/source/drivers/postgresql/pq_xtables.cxx +++ b/connectivity/source/drivers/postgresql/pq_xtables.cxx @@ -34,6 +34,7 @@ * ************************************************************************/ +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> @@ -42,6 +43,7 @@ #include <com/sun/star/sdbcx/Privilege.hpp> #include <com/sun/star/sdbc/DataType.hpp> #include <cppuhelper/exc_hlp.hxx> +#include <o3tl/safeint.hxx> #include "pq_xtables.hxx" #include "pq_xviews.hxx" @@ -54,7 +56,6 @@ using osl::MutexGuard; using com::sun::star::beans::XPropertySet; using com::sun::star::uno::Any; -using com::sun::star::uno::makeAny; using com::sun::star::uno::UNO_QUERY; using com::sun::star::uno::Reference; using com::sun::star::uno::Sequence; @@ -103,23 +104,23 @@ void Tables::refresh() { // if creating all these tables turns out to have too bad performance, we might // instead offer a factory interface - Table * pTable = + rtl::Reference<Table> pTable = new Table( m_xMutex, m_origin, m_pSettings ); Reference< css::beans::XPropertySet > prop = pTable; OUString name = xRow->getString( TABLE_INDEX_NAME+1); OUString schema = xRow->getString( TABLE_INDEX_SCHEMA+1); pTable->setPropertyValue_NoBroadcast_public( - st.CATALOG_NAME , makeAny(xRow->getString( TABLE_INDEX_CATALOG+1) ) ); - pTable->setPropertyValue_NoBroadcast_public( st.NAME , makeAny( name ) ); - pTable->setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME , makeAny( schema )); + st.CATALOG_NAME , Any(xRow->getString( TABLE_INDEX_CATALOG+1) ) ); + pTable->setPropertyValue_NoBroadcast_public( st.NAME , Any( name ) ); + pTable->setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME , Any( schema )); pTable->setPropertyValue_NoBroadcast_public( - st.TYPE , makeAny( xRow->getString( TABLE_INDEX_TYPE+1) ) ); + st.TYPE , Any( xRow->getString( TABLE_INDEX_TYPE+1) ) ); pTable->setPropertyValue_NoBroadcast_public( - st.DESCRIPTION , makeAny( xRow->getString( TABLE_INDEX_REMARKS+1) ) ); + st.DESCRIPTION , Any( xRow->getString( TABLE_INDEX_REMARKS+1) ) ); pTable->setPropertyValue_NoBroadcast_public( st.PRIVILEGES , - makeAny( sal_Int32( css::sdbcx::Privilege::SELECT | + Any( sal_Int32( css::sdbcx::Privilege::SELECT | css::sdbcx::Privilege::INSERT | css::sdbcx::Privilege::UPDATE | css::sdbcx::Privilege::DELETE | @@ -130,7 +131,7 @@ void Tables::refresh() css::sdbcx::Privilege::DROP ) ) ); { - m_values.push_back( makeAny( prop ) ); + m_values.push_back( Any( prop ) ); map[ schema + "." + name ] = tableIndex; ++tableIndex; } @@ -310,7 +311,7 @@ void Tables::appendByDescriptor( void Tables::dropByIndex( sal_Int32 index ) { osl::MutexGuard guard( m_xMutex->GetMutex() ); - if( index < 0 || index >= static_cast<sal_Int32>(m_values.size()) ) + if( index < 0 || o3tl::make_unsigned(index) >= m_values.size() ) { throw css::lang::IndexOutOfBoundsException( "TABLES: Index out of range (allowed 0 to " + OUString::number(m_values.size() -1) @@ -355,13 +356,12 @@ Reference< css::container::XNameAccess > Tables::create( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - Tables **ppTables) + rtl::Reference<Tables> *ppTables) { *ppTables = new Tables( refMutex, origin, pSettings ); - Reference< css::container::XNameAccess > ret = *ppTables; (*ppTables)->refresh(); - return ret; + return *ppTables; } }; diff --git a/connectivity/source/drivers/postgresql/pq_xtables.hxx b/connectivity/source/drivers/postgresql/pq_xtables.hxx index 33eab3a5b8c4..9222db82c77f 100644 --- a/connectivity/source/drivers/postgresql/pq_xtables.hxx +++ b/connectivity/source/drivers/postgresql/pq_xtables.hxx @@ -34,14 +34,19 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XTABLES_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XTABLES_HXX +#pragma once + +#include <sal/config.h> + +#include <rtl/ref.hxx> #include "pq_xcontainer.hxx" namespace pq_sdbc_driver { +struct ConnectionSettings; + class Tables : public Container { @@ -50,7 +55,7 @@ public: // instances Tables 'exception safe' const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - Tables ** ppTables); + rtl::Reference<Tables> * ppTables); protected: Tables( @@ -82,6 +87,5 @@ protected: }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xuser.cxx b/connectivity/source/drivers/postgresql/pq_xuser.cxx index bc06c541064e..4d0a01f6366f 100644 --- a/connectivity/source/drivers/postgresql/pq_xuser.cxx +++ b/connectivity/source/drivers/postgresql/pq_xuser.cxx @@ -35,6 +35,7 @@ ************************************************************************/ #include <sal/log.hxx> +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <cppuhelper/typeprovider.hxx> @@ -73,7 +74,7 @@ User::User( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, Reference< XPropertySet > User::createDataDescriptor( ) { - UserDescriptor * pUser = new UserDescriptor( m_xMutex, m_conn, m_pSettings ); + rtl::Reference<UserDescriptor> pUser = new UserDescriptor( m_xMutex, m_conn, m_pSettings ); pUser->copyValuesFrom( this ); return Reference< XPropertySet > ( pUser ); @@ -159,7 +160,7 @@ UserDescriptor::UserDescriptor( Reference< XPropertySet > UserDescriptor::createDataDescriptor( ) { - UserDescriptor * pUser = new UserDescriptor( m_xMutex, m_conn, m_pSettings ); + rtl::Reference<UserDescriptor> pUser = new UserDescriptor( m_xMutex, m_conn, m_pSettings ); pUser->copyValuesFrom( this ); return Reference< XPropertySet > ( pUser ); diff --git a/connectivity/source/drivers/postgresql/pq_xuser.hxx b/connectivity/source/drivers/postgresql/pq_xuser.hxx index 950cd998b0d5..702787a67496 100644 --- a/connectivity/source/drivers/postgresql/pq_xuser.hxx +++ b/connectivity/source/drivers/postgresql/pq_xuser.hxx @@ -34,14 +34,8 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XUSER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XUSER_HXX +#pragma once -#include <cppuhelper/component.hxx> -#include <cppuhelper/propshlp.hxx> - -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp> #include <com/sun/star/sdbcx/XUser.hpp> #include "pq_xbase.hxx" @@ -59,8 +53,8 @@ public: ConnectionSettings *pSettings); // XInterface - virtual void SAL_CALL acquire() throw() override { ReflectionBase::acquire(); } - virtual void SAL_CALL release() throw() override { ReflectionBase::release(); } + virtual void SAL_CALL acquire() noexcept override { ReflectionBase::acquire(); } + virtual void SAL_CALL release() noexcept override { ReflectionBase::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -96,6 +90,4 @@ public: // XDataDescriptorFactory } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xusers.cxx b/connectivity/source/drivers/postgresql/pq_xusers.cxx index a6fe3489fa7f..08cdf2d1c135 100644 --- a/connectivity/source/drivers/postgresql/pq_xusers.cxx +++ b/connectivity/source/drivers/postgresql/pq_xusers.cxx @@ -34,12 +34,14 @@ * ************************************************************************/ +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/sdbc/XRow.hpp> #include <cppuhelper/exc_hlp.hxx> +#include <o3tl/safeint.hxx> #include "pq_xusers.hxx" #include "pq_xuser.hxx" @@ -50,7 +52,7 @@ using osl::MutexGuard; using com::sun::star::beans::XPropertySet; -using com::sun::star::uno::makeAny; +using com::sun::star::uno::Any; using com::sun::star::uno::UNO_QUERY; using com::sun::star::uno::Reference; @@ -91,16 +93,16 @@ void Users::refresh() sal_Int32 tableIndex = 0; while( rs->next() ) { - User * pUser = + rtl::Reference<User> pUser = new User( m_xMutex, m_origin, m_pSettings ); Reference< css::beans::XPropertySet > prop = pUser; OUString name = xRow->getString( 1); pUser->setPropertyValue_NoBroadcast_public( - st.NAME , makeAny(xRow->getString( TABLE_INDEX_CATALOG+1) ) ); + st.NAME , Any(xRow->getString( TABLE_INDEX_CATALOG+1) ) ); { - m_values.push_back( makeAny( prop ) ); + m_values.push_back( Any( prop ) ); map[ name ] = tableIndex; ++tableIndex; } @@ -150,7 +152,7 @@ void Users::dropByIndex( sal_Int32 index ) { osl::MutexGuard guard( m_xMutex->GetMutex() ); - if( index < 0 || index >= static_cast<sal_Int32>(m_values.size()) ) + if( index < 0 || o3tl::make_unsigned(index) >= m_values.size() ) { throw css::lang::IndexOutOfBoundsException( "USERS: Index out of range (allowed 0 to " @@ -185,11 +187,10 @@ Reference< css::container::XNameAccess > Users::create( const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings ) { - Users *pUsers = new Users( refMutex, origin, pSettings ); - Reference< css::container::XNameAccess > ret = pUsers; + rtl::Reference<Users> pUsers = new Users( refMutex, origin, pSettings ); pUsers->refresh(); - return ret; + return pUsers; } void Users::disposing() diff --git a/connectivity/source/drivers/postgresql/pq_xusers.hxx b/connectivity/source/drivers/postgresql/pq_xusers.hxx index 359b97dd11cf..f95ec174915f 100644 --- a/connectivity/source/drivers/postgresql/pq_xusers.hxx +++ b/connectivity/source/drivers/postgresql/pq_xusers.hxx @@ -34,8 +34,7 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XUSERS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XUSERS_HXX +#pragma once #include "pq_xcontainer.hxx" @@ -79,6 +78,5 @@ private: }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xview.cxx b/connectivity/source/drivers/postgresql/pq_xview.cxx index 1b00b9b5d326..c2e936e9a314 100644 --- a/connectivity/source/drivers/postgresql/pq_xview.cxx +++ b/connectivity/source/drivers/postgresql/pq_xview.cxx @@ -34,6 +34,7 @@ * ************************************************************************/ +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <cppuhelper/typeprovider.hxx> @@ -51,7 +52,6 @@ using osl::MutexGuard; using com::sun::star::uno::Reference; using com::sun::star::uno::Sequence; using com::sun::star::uno::Any; -using com::sun::star::uno::makeAny; using com::sun::star::uno::Type; using com::sun::star::beans::XPropertySet; @@ -76,7 +76,7 @@ View::View( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, Reference< XPropertySet > View::createDataDescriptor( ) { - ViewDescriptor * pView = new ViewDescriptor( + rtl::Reference<ViewDescriptor> pView = new ViewDescriptor( m_xMutex, m_conn, m_pSettings ); pView->copyValuesFrom( this ); @@ -120,14 +120,13 @@ void View::rename( const OUString& newName ) bufferQuoteIdentifier( buf, newSchemaName, m_pSettings ); Reference< XStatement > statement = m_conn->createStatement(); statement->executeUpdate( buf.makeStringAndClear() ); - setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME, makeAny(newSchemaName) ); + setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME, Any(newSchemaName) ); disposeNoThrow( statement ); schema = newSchemaName; } catch( css::sdbc::SQLException &e ) { - OUString buf( e.Message + "(NOTE: Only postgresql server >= V8.1 support changing a table's schema)" ); - e.Message = buf; + e.Message += "(NOTE: Only postgresql server >= V8.1 support changing a table's schema)"; throw; } @@ -141,7 +140,7 @@ void View::rename( const OUString& newName ) bufferQuoteIdentifier( buf, newTableName, m_pSettings ); Reference< XStatement > statement = m_conn->createStatement(); statement->executeUpdate( buf.makeStringAndClear() ); - setPropertyValue_NoBroadcast_public( st.NAME, makeAny(newTableName) ); + setPropertyValue_NoBroadcast_public( st.NAME, Any(newTableName) ); } // inform the container of the name change ! @@ -205,7 +204,7 @@ ViewDescriptor::ViewDescriptor( Reference< XPropertySet > ViewDescriptor::createDataDescriptor( ) { - ViewDescriptor * pView = new ViewDescriptor( + rtl::Reference<ViewDescriptor> pView = new ViewDescriptor( m_xMutex, m_conn, m_pSettings ); pView->copyValuesFrom( this ); diff --git a/connectivity/source/drivers/postgresql/pq_xview.hxx b/connectivity/source/drivers/postgresql/pq_xview.hxx index d5c86981f6f4..f68b5535a8d7 100644 --- a/connectivity/source/drivers/postgresql/pq_xview.hxx +++ b/connectivity/source/drivers/postgresql/pq_xview.hxx @@ -34,16 +34,9 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XVIEW_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XVIEW_HXX +#pragma once -#include <cppuhelper/component.hxx> -#include <cppuhelper/propshlp.hxx> - -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp> #include <com/sun/star/sdbcx/XRename.hpp> -#include <com/sun/star/container/XNamed.hpp> #include "pq_xbase.hxx" @@ -58,8 +51,8 @@ public: ConnectionSettings *pSettings); // XInterface - virtual void SAL_CALL acquire() throw() override { ReflectionBase::acquire(); } - virtual void SAL_CALL release() throw() override { ReflectionBase::release(); } + virtual void SAL_CALL acquire() noexcept override { ReflectionBase::acquire(); } + virtual void SAL_CALL release() noexcept override { ReflectionBase::release(); } virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override; @@ -96,6 +89,4 @@ public: } -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/postgresql/pq_xviews.cxx b/connectivity/source/drivers/postgresql/pq_xviews.cxx index ac684a16c124..1f5b6c4fa52c 100644 --- a/connectivity/source/drivers/postgresql/pq_xviews.cxx +++ b/connectivity/source/drivers/postgresql/pq_xviews.cxx @@ -34,12 +34,14 @@ * ************************************************************************/ +#include <rtl/ref.hxx> #include <rtl/ustrbuf.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/sdbc/XRow.hpp> #include <cppuhelper/exc_hlp.hxx> +#include <o3tl/safeint.hxx> #include "pq_xviews.hxx" #include "pq_xview.hxx" @@ -51,7 +53,7 @@ using osl::MutexGuard; using com::sun::star::beans::XPropertySet; -using com::sun::star::uno::makeAny; +using com::sun::star::uno::Any; using com::sun::star::uno::UNO_QUERY; using com::sun::star::uno::Reference; @@ -106,15 +108,15 @@ void Views::refresh() table = xRow->getString( 2 ); command = xRow->getString( 3 ); - View *pView = new View (m_xMutex, m_origin, m_pSettings ); + rtl::Reference<View> pView = new View (m_xMutex, m_origin, m_pSettings ); Reference< css::beans::XPropertySet > prop = pView; - pView->setPropertyValue_NoBroadcast_public(st.NAME , makeAny(table) ); - pView->setPropertyValue_NoBroadcast_public(st.SCHEMA_NAME, makeAny(schema) ); - pView->setPropertyValue_NoBroadcast_public(st.COMMAND, makeAny(command) ); + pView->setPropertyValue_NoBroadcast_public(st.NAME , Any(table) ); + pView->setPropertyValue_NoBroadcast_public(st.SCHEMA_NAME, Any(schema) ); + pView->setPropertyValue_NoBroadcast_public(st.COMMAND, Any(command) ); { - m_values.push_back( makeAny( prop ) ); + m_values.push_back( Any( prop ) ); map[ schema + "." + table ] = viewIndex; ++viewIndex; } @@ -148,7 +150,7 @@ void Views::appendByDescriptor( buf.append( "CREATE VIEW "); bufferQuoteQualifiedIdentifier( buf, schema, name, m_pSettings ); - buf.append(" AS " ).append( command ); + buf.append(" AS " + command ); stmt->executeUpdate( buf.makeStringAndClear() ); @@ -174,7 +176,7 @@ void Views::dropByName( const OUString& elementName ) void Views::dropByIndex( sal_Int32 index ) { osl::MutexGuard guard( m_xMutex->GetMutex() ); - if( index < 0 || index >= static_cast<sal_Int32>(m_values.size()) ) + if( index < 0 || o3tl::make_unsigned(index) >= m_values.size() ) { throw css::lang::IndexOutOfBoundsException( "VIEWS: Index out of range (allowed 0 to " + OUString::number(m_values.size() -1) @@ -204,13 +206,12 @@ Reference< css::container::XNameAccess > Views::create( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - Views **ppViews) + rtl::Reference<Views> *ppViews) { *ppViews = new Views( refMutex, origin, pSettings ); - Reference< css::container::XNameAccess > ret = *ppViews; (*ppViews)->refresh(); - return ret; + return *ppViews; } }; diff --git a/connectivity/source/drivers/postgresql/pq_xviews.hxx b/connectivity/source/drivers/postgresql/pq_xviews.hxx index 5ce5b879bd0e..04137b6868a1 100644 --- a/connectivity/source/drivers/postgresql/pq_xviews.hxx +++ b/connectivity/source/drivers/postgresql/pq_xviews.hxx @@ -34,14 +34,19 @@ * ************************************************************************/ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XVIEWS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_XVIEWS_HXX +#pragma once + +#include <sal/config.h> + +#include <rtl/ref.hxx> #include "pq_xcontainer.hxx" namespace pq_sdbc_driver { +struct ConnectionSettings; + class Views : public Container { @@ -50,7 +55,7 @@ public: // instances Views 'exception safe' const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, const css::uno::Reference< css::sdbc::XConnection > & origin, ConnectionSettings *pSettings, - Views **ppViews ); + rtl::Reference<Views> *ppViews ); protected: Views( @@ -79,6 +84,5 @@ protected: }; } -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/writer/WConnection.cxx b/connectivity/source/drivers/writer/WConnection.cxx index c4cc699e4ad2..c9900a4e5544 100644 --- a/connectivity/source/drivers/writer/WConnection.cxx +++ b/connectivity/source/drivers/writer/WConnection.cxx @@ -32,7 +32,7 @@ #include <unotools/pathoptions.hxx> #include <connectivity/dbexception.hxx> #include <cppuhelper/exc_hlp.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> using namespace ::com::sun::star; @@ -42,7 +42,6 @@ namespace connectivity::writer { OWriterConnection::OWriterConnection(ODriver* _pDriver) : OConnection(_pDriver) - , m_nDocCount(0) { } @@ -55,9 +54,9 @@ void OWriterConnection::construct(const OUString& rURL, sal_Int32 nLen = rURL.indexOf(':'); nLen = rURL.indexOf(':', nLen + 1); - OUString aDSN(rURL.copy(nLen + 1)); - m_aFileName = aDSN; + m_aFileName = rURL.copy(nLen + 1); // DSN + INetURLObject aURL; aURL.SetSmartProtocol(INetProtocol::File); { @@ -97,18 +96,17 @@ uno::Reference<text::XTextDocument> const& OWriterConnection::acquireDoc() return m_xDoc; } // open read-only as long as updating isn't implemented - uno::Sequence<beans::PropertyValue> aArgs(2); - aArgs[0].Name = "Hidden"; - aArgs[0].Value <<= true; - aArgs[1].Name = "ReadOnly"; - aArgs[1].Value <<= true; + uno::Sequence<beans::PropertyValue> aArgs(m_sPassword.isEmpty() ? 2 : 3); + auto pArgs = aArgs.getArray(); + pArgs[0].Name = "Hidden"; + pArgs[0].Value <<= true; + pArgs[1].Name = "ReadOnly"; + pArgs[1].Value <<= true; if (!m_sPassword.isEmpty()) { - const sal_Int32 nPos = aArgs.getLength(); - aArgs.realloc(nPos + 1); - aArgs[nPos].Name = "Password"; - aArgs[nPos].Value <<= m_sPassword; + pArgs[2].Name = "Password"; + pArgs[2].Value <<= m_sPassword; } uno::Reference<frame::XDesktop2> xDesktop @@ -203,8 +201,7 @@ css::uno::Reference<css::sdbcx::XTablesSupplier> OWriterConnection::createCatalo uno::Reference<css::sdbcx::XTablesSupplier> xTab = m_xCatalog; if (!xTab.is()) { - auto pCat = new OWriterCatalog(this); - xTab = pCat; + xTab = new OWriterCatalog(this); m_xCatalog = xTab; } return xTab; @@ -216,7 +213,7 @@ uno::Reference<sdbc::XStatement> SAL_CALL OWriterConnection::createStatement() checkDisposed(OConnection_BASE::rBHelper.bDisposed); uno::Reference<sdbc::XStatement> xReturn = new component::OComponentStatement(this); - m_aStatements.push_back(uno::WeakReferenceHelper(xReturn)); + m_aStatements.emplace_back(xReturn); return xReturn; } @@ -226,10 +223,10 @@ uno::Reference<sdbc::XPreparedStatement> ::osl::MutexGuard aGuard(m_aMutex); checkDisposed(OConnection_BASE::rBHelper.bDisposed); - auto pStmt = new component::OComponentPreparedStatement(this); - uno::Reference<sdbc::XPreparedStatement> xHoldAlive = pStmt; + rtl::Reference<component::OComponentPreparedStatement> pStmt + = new component::OComponentPreparedStatement(this); pStmt->construct(sql); - m_aStatements.push_back(uno::WeakReferenceHelper(*pStmt)); + m_aStatements.emplace_back(*pStmt); return pStmt; } diff --git a/connectivity/source/drivers/writer/WDatabaseMetaData.cxx b/connectivity/source/drivers/writer/WDatabaseMetaData.cxx index 2e55a46d2c6d..1eed92ddcf07 100644 --- a/connectivity/source/drivers/writer/WDatabaseMetaData.cxx +++ b/connectivity/source/drivers/writer/WDatabaseMetaData.cxx @@ -47,8 +47,8 @@ uno::Reference<sdbc::XResultSet> SAL_CALL OWriterDatabaseMetaData::getTables( { ::osl::MutexGuard aGuard(m_aMutex); - auto pResult = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTables); - uno::Reference<sdbc::XResultSet> xRef = pResult; + rtl::Reference<ODatabaseMetaDataResultSet> pResult + = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTables); // check if ORowSetValue type is given // when no types are given then we have to return all tables e.g. TABLE @@ -73,7 +73,7 @@ uno::Reference<sdbc::XResultSet> SAL_CALL OWriterDatabaseMetaData::getTables( } } if (!bTableFound) - return xRef; + return pResult; // get the table names from the document @@ -90,21 +90,22 @@ uno::Reference<sdbc::XResultSet> SAL_CALL OWriterDatabaseMetaData::getTables( sal_Int32 nTableCount = aTableNames.getLength(); for (sal_Int32 nTable = 0; nTable < nTableCount; nTable++) { - OUString aName = aTableNames[nTable]; - if (match(tableNamePattern, aName, '\0')) + const OUString& rName = aTableNames[nTable]; + if (match(tableNamePattern, rName, '\0')) { - ODatabaseMetaDataResultSet::ORow aRow{ nullptr, nullptr, nullptr }; - aRow.reserve(6); - aRow.push_back(new ORowSetValueDecorator(aName)); - aRow.push_back(new ORowSetValueDecorator(aTable)); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); + ODatabaseMetaDataResultSet::ORow aRow{ nullptr, + nullptr, + nullptr, + new ORowSetValueDecorator(rName), + new ORowSetValueDecorator(aTable), + ODatabaseMetaDataResultSet::getEmptyValue() }; aRows.push_back(aRow); } } - pResult->setRows(aRows); + pResult->setRows(std::move(aRows)); - return xRef; + return pResult; } } // namespace diff --git a/connectivity/source/drivers/writer/WDriver.cxx b/connectivity/source/drivers/writer/WDriver.cxx index 3d30c00fb571..bbd0f71838c1 100644 --- a/connectivity/source/drivers/writer/WDriver.cxx +++ b/connectivity/source/drivers/writer/WDriver.cxx @@ -23,7 +23,6 @@ #include <connectivity/dbexception.hxx> #include <resource/sharedresources.hxx> #include <strings.hrc> -#include <comphelper/processfactory.hxx> using namespace connectivity::file; using namespace ::com::sun::star; @@ -37,19 +36,16 @@ OUString SAL_CALL ODriver::getImplementationName() extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* connectivity_writer_ODriver(css::uno::XComponentContext* context, - css::uno::Sequence<css::uno::Any> const&) + css::uno::Sequence<css::uno::Any> const& /*rArguments*/) { - rtl::Reference<ODriver> ret; try { - ret = new ODriver(context); + return acquire(new ODriver(context)); } catch (...) { } - if (ret) - ret->acquire(); - return static_cast<cppu::OWeakObject*>(ret.get()); + return nullptr; } uno::Reference<sdbc::XConnection> @@ -62,12 +58,11 @@ uno::Reference<sdbc::XConnection> if (!acceptsURL(url)) return nullptr; - auto pCon = new OWriterConnection(this); + rtl::Reference<OWriterConnection> pCon = new OWriterConnection(this); pCon->construct(url, info); - uno::Reference<sdbc::XConnection> xCon = pCon; - m_xConnections.push_back(uno::WeakReferenceHelper(*pCon)); + m_xConnections.emplace_back(*pCon); - return xCon; + return pCon; } sal_Bool SAL_CALL ODriver::acceptsURL(const OUString& url) @@ -84,7 +79,7 @@ ODriver::getPropertyInfo(const OUString& url, const uno::Sequence<beans::Propert const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR); ::dbtools::throwGenericSQLException(sMessage, *this); } - return uno::Sequence<sdbc::DriverPropertyInfo>(); + return {}; } } // namespace diff --git a/connectivity/source/drivers/writer/WTable.cxx b/connectivity/source/drivers/writer/WTable.cxx index 7236df2476dd..2f0f44855d86 100644 --- a/connectivity/source/drivers/writer/WTable.cxx +++ b/connectivity/source/drivers/writer/WTable.cxx @@ -30,8 +30,6 @@ #include <writer/WConnection.hxx> #include <connectivity/sdbcx/VColumn.hxx> #include <sal/log.hxx> -#include <comphelper/servicehelper.hxx> -#include <cppuhelper/typeprovider.hxx> namespace com::sun::star::text { @@ -159,12 +157,11 @@ void OWriterTable::fillColumns() aFind = connectivity::find(m_aColumns->begin(), m_aColumns->end(), aAlias, aCase); } - auto pColumn = new sdbcx::OColumn( + rtl::Reference<sdbcx::OColumn> pColumn = new sdbcx::OColumn( aAlias, aTypeName, OUString(), OUString(), sdbc::ColumnValue::NULLABLE, nPrecision, nDecimals, eType, false, false, bCurrency, bStoresMixedCaseQuotedIdentifiers, m_CatalogName, getSchema(), getName()); - uno::Reference<XPropertySet> xCol = pColumn; - m_aColumns->push_back(xCol); + m_aColumns->push_back(pColumn); } } @@ -173,9 +170,6 @@ OWriterTable::OWriterTable(sdbcx::OCollection* _pTables, OWriterConnection* _pCo : OWriterTable_BASE(_pTables, _pConnection, Name, Type, OUString() /*Description*/, OUString() /*SchemaName*/, OUString() /*CatalogName*/) , m_pWriterConnection(_pConnection) - , m_nStartCol(0) - , m_nDataCols(0) - , m_bHasHeaders(false) { } @@ -212,19 +206,6 @@ void SAL_CALL OWriterTable::disposing() m_pWriterConnection = nullptr; } -uno::Sequence<sal_Int8> OWriterTable::getUnoTunnelId() -{ - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); -} - -sal_Int64 OWriterTable::getSomething(const uno::Sequence<sal_Int8>& rId) -{ - return (isUnoTunnelId<OWriterTable>(rId)) ? reinterpret_cast<sal_Int64>(this) - : OWriterTable_BASE::getSomething(rId); -} - bool OWriterTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns& _rCols, bool bRetrieveData) { // read the bookmark diff --git a/connectivity/source/drivers/writer/WTables.cxx b/connectivity/source/drivers/writer/WTables.cxx index 15dc9e0c1941..8b2692d93a01 100644 --- a/connectivity/source/drivers/writer/WTables.cxx +++ b/connectivity/source/drivers/writer/WTables.cxx @@ -31,13 +31,13 @@ namespace connectivity::writer { sdbcx::ObjectType OWriterTables::createObject(const OUString& rName) { - auto pTable = new OWriterTable(this, - static_cast<OWriterConnection*>( - static_cast<file::OFileCatalog&>(m_rParent).getConnection()), - rName, "TABLE"); - sdbcx::ObjectType xRet = pTable; + rtl::Reference<OWriterTable> pTable + = new OWriterTable(this, + static_cast<OWriterConnection*>( + static_cast<file::OFileCatalog&>(m_rParent).getConnection()), + rName, "TABLE"); pTable->construct(); - return xRet; + return pTable; } } // namespace diff --git a/connectivity/source/inc/AutoRetrievingBase.hxx b/connectivity/source/inc/AutoRetrievingBase.hxx index f24d94f7932a..a85b92c6361f 100644 --- a/connectivity/source/inc/AutoRetrievingBase.hxx +++ b/connectivity/source/inc/AutoRetrievingBase.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_AUTORETRIEVINGBASE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_AUTORETRIEVINGBASE_HXX +#pragma once #include <rtl/ustring.hxx> #include <connectivity/dbtoolsdllapi.hxx> @@ -46,6 +45,6 @@ namespace connectivity OUString getTransformedGeneratedStatement(const OUString& _sInsertStatement) const; }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_AUTORETRIEVINGBASE_HXX + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/FDatabaseMetaDataResultSet.hxx b/connectivity/source/inc/FDatabaseMetaDataResultSet.hxx index de20771f9787..f0a3fef76d00 100644 --- a/connectivity/source/inc/FDatabaseMetaDataResultSet.hxx +++ b/connectivity/source/inc/FDatabaseMetaDataResultSet.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FDATABASEMETADATARESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FDATABASEMETADATARESULTSET_HXX +#pragma once #include <sal/config.h> @@ -33,16 +32,15 @@ #include <com/sun/star/lang/XInitialization.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/sdbc/XWarningsSupplier.hpp> -#include <cppuhelper/compbase.hxx> -#include <cppuhelper/basemutex.hxx> #include <comphelper/proparrhlp.hxx> -#include <comphelper/propertycontainer.hxx> +#include <comphelper/propertycontainer2.hxx> #include <connectivity/FValue.hxx> #include <connectivity/dbtoolsdllapi.hxx> +#include <comphelper/compbase.hxx> namespace connectivity { - typedef ::cppu::WeakComponentImplHelper< css::sdbc::XResultSet, + typedef ::comphelper::WeakComponentImplHelper< css::sdbc::XResultSet, css::sdbc::XRow, css::sdbc::XResultSetMetaDataSupplier, css::util::XCancellable, @@ -55,11 +53,10 @@ namespace connectivity // typedef ORefVector<ORowSetValue> ORow; // typedef ORefVector<ORow> ORows; - class OOO_DLLPUBLIC_DBTOOLS ODatabaseMetaDataResultSet : - public cppu::BaseMutex, - public ODatabaseMetaDataResultSet_BASE, - public ::comphelper::OPropertyContainer, - public ::comphelper::OPropertyArrayUsageHelper<ODatabaseMetaDataResultSet> + class SAL_DLLPUBLIC_RTTI ODatabaseMetaDataResultSet : + public ODatabaseMetaDataResultSet_BASE, + public ::comphelper::OPropertyContainer2, + public ::comphelper::OPropertyArrayUsageHelper<ODatabaseMetaDataResultSet> { public: @@ -119,8 +116,9 @@ namespace connectivity void construct(); /// @throws css::sdbc::SQLException - void checkIndex(sal_Int32 columnIndex ); + void checkIndex(std::unique_lock<std::mutex>& rGuard, sal_Int32 columnIndex ); void setType(MetaDataResultSetType _eType); + css::uno::Reference< css::sdbc::XResultSetMetaData > getMetaData( std::unique_lock<std::mutex>& ); protected: ORows m_aRows; @@ -131,22 +129,26 @@ namespace connectivity virtual const ORowSetValue& getValue(sal_Int32 columnIndex); // OPropertyArrayUsageHelper - virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override; + OOO_DLLPUBLIC_DBTOOLS virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override; // OPropertySetHelper - virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + OOO_DLLPUBLIC_DBTOOLS virtual ::cppu::IPropertyArrayHelper & getInfoHelper() override; + + bool next(std::unique_lock<std::mutex>& ); + bool isBeforeFirst(std::unique_lock<std::mutex>& ); + bool isAfterLast(std::unique_lock<std::mutex>& ); virtual ~ODatabaseMetaDataResultSet() override; public: - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + OOO_DLLPUBLIC_DBTOOLS virtual void SAL_CALL acquire() noexcept override; + OOO_DLLPUBLIC_DBTOOLS virtual void SAL_CALL release() noexcept override; /// default construction ODatabaseMetaDataResultSet(); /// construction of a pre-defined result set type - ODatabaseMetaDataResultSet( MetaDataResultSetType _eType ); + OOO_DLLPUBLIC_DBTOOLS ODatabaseMetaDataResultSet( MetaDataResultSetType _eType ); - void setRows(const ORows& _rRows); + OOO_DLLPUBLIC_DBTOOLS void setRows(ORows&& _rRows); // XServiceInfo @@ -154,14 +156,14 @@ namespace connectivity virtual OUString SAL_CALL getImplementationName( ) override; virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; - // ::cppu::OComponentHelper - virtual void SAL_CALL disposing() override; + // ::comphelper::WeakComponentImplHelper + virtual void disposing(std::unique_lock<std::mutex>&) override; // XInterface - virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + OOO_DLLPUBLIC_DBTOOLS virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; // XPropertySet - virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; + OOO_DLLPUBLIC_DBTOOLS virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; // XResultSet virtual sal_Bool SAL_CALL next( ) override; virtual sal_Bool SAL_CALL isBeforeFirst( ) override; @@ -239,34 +241,33 @@ namespace connectivity // some methods to get already defined ORowSetValues // this increase the reuse of ORowSetValues /// return an empty ORowSetValueDecorator - static ORowSetValueDecoratorRef const & getEmptyValue(); + OOO_DLLPUBLIC_DBTOOLS static ORowSetValueDecoratorRef const & getEmptyValue(); /// return an ORowSetValueDecorator with 0 as value - static ORowSetValueDecoratorRef const & get0Value(); + OOO_DLLPUBLIC_DBTOOLS static ORowSetValueDecoratorRef const & get0Value(); /// return an ORowSetValueDecorator with 1 as value - static ORowSetValueDecoratorRef const & get1Value(); + OOO_DLLPUBLIC_DBTOOLS static ORowSetValueDecoratorRef const & get1Value(); /// return an ORowSetValueDecorator with ColumnSearch::BASIC as value - static ORowSetValueDecoratorRef const & getBasicValue(); + OOO_DLLPUBLIC_DBTOOLS static ORowSetValueDecoratorRef const & getBasicValue(); /// return an ORowSetValueDecorator with string SELECT as value - static ORowSetValueDecoratorRef const & getSelectValue(); + OOO_DLLPUBLIC_DBTOOLS static ORowSetValueDecoratorRef const & getSelectValue(); /// return an ORowSetValueDecorator with string INSERT as value - static ORowSetValueDecoratorRef const & getInsertValue(); + OOO_DLLPUBLIC_DBTOOLS static ORowSetValueDecoratorRef const & getInsertValue(); /// return an ORowSetValueDecorator with string DELETE as value - static ORowSetValueDecoratorRef const & getDeleteValue(); + OOO_DLLPUBLIC_DBTOOLS static ORowSetValueDecoratorRef const & getDeleteValue(); /// return an ORowSetValueDecorator with string UPDATE as value - static ORowSetValueDecoratorRef const & getUpdateValue(); + OOO_DLLPUBLIC_DBTOOLS static ORowSetValueDecoratorRef const & getUpdateValue(); /// return an ORowSetValueDecorator with string CREATE as value - static ORowSetValueDecoratorRef const & getCreateValue(); + OOO_DLLPUBLIC_DBTOOLS static ORowSetValueDecoratorRef const & getCreateValue(); /// return an ORowSetValueDecorator with string READ as value - static ORowSetValueDecoratorRef const & getReadValue(); + OOO_DLLPUBLIC_DBTOOLS static ORowSetValueDecoratorRef const & getReadValue(); /// return an ORowSetValueDecorator with string ALTER as value - static ORowSetValueDecoratorRef const & getAlterValue(); + OOO_DLLPUBLIC_DBTOOLS static ORowSetValueDecoratorRef const & getAlterValue(); /// return an ORowSetValueDecorator with string DROP as value - static ORowSetValueDecoratorRef const & getDropValue(); + OOO_DLLPUBLIC_DBTOOLS static ORowSetValueDecoratorRef const & getDropValue(); /// return an ORowSetValueDecorator with string ' as value - static ORowSetValueDecoratorRef const & getQuoteValue(); + OOO_DLLPUBLIC_DBTOOLS static ORowSetValueDecoratorRef const & getQuoteValue(); }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FDATABASEMETADATARESULTSET_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/FDatabaseMetaDataResultSetMetaData.hxx b/connectivity/source/inc/FDatabaseMetaDataResultSetMetaData.hxx index 2e5ccb00763d..9de12267229c 100644 --- a/connectivity/source/inc/FDatabaseMetaDataResultSetMetaData.hxx +++ b/connectivity/source/inc/FDatabaseMetaDataResultSetMetaData.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FDATABASEMETADATARESULTSETMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FDATABASEMETADATARESULTSETMETADATA_HXX +#pragma once #include <com/sun/star/sdbc/XResultSetMetaData.hpp> #include <cppuhelper/implbase.hxx> @@ -92,7 +91,6 @@ namespace connectivity void setUDTsMap(); }; } -#endif // _CONNECTIVITY_FILE_ADATABASEMETARESULTSETMETADATA_HXX_ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/OColumn.hxx b/connectivity/source/inc/OColumn.hxx index a60f44e2bb8b..2131b3e15254 100644 --- a/connectivity/source/inc/OColumn.hxx +++ b/connectivity/source/inc/OColumn.hxx @@ -17,12 +17,12 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_OCOLUMN_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_OCOLUMN_HXX +#pragma once #include <rtl/ustring.hxx> #include <sal/types.h> #include <connectivity/dbtoolsdllapi.hxx> +#include <utility> namespace connectivity { @@ -65,14 +65,14 @@ namespace connectivity , m_DefinitelyWritable(false) {} - OColumn(const OUString &_aTableName, + OColumn(OUString _aTableName, const OUString &_aColumnName, sal_Int32 _aNullable, sal_Int32 _aColumnDisplaySize, sal_Int32 _aPrecision, sal_Int32 _aScale, sal_Int32 _aColumnType) - : m_TableName(_aTableName), + : m_TableName(std::move(_aTableName)), m_ColumnName(_aColumnName), m_ColumnLabel(), @@ -116,6 +116,4 @@ namespace connectivity }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_OCOLUMN_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/OTypeInfo.hxx b/connectivity/source/inc/OTypeInfo.hxx index 772a46223c88..4e9cbdf05e6a 100644 --- a/connectivity/source/inc/OTypeInfo.hxx +++ b/connectivity/source/inc/OTypeInfo.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_OTYPEINFO_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_OTYPEINFO_HXX +#pragma once #include <com/sun/star/sdbc/DataType.hpp> @@ -48,6 +47,4 @@ namespace connectivity }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_OTYPEINFO_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ParameterSubstitution.hxx b/connectivity/source/inc/ParameterSubstitution.hxx index e0a540332ff3..a76bd09398fa 100644 --- a/connectivity/source/inc/ParameterSubstitution.hxx +++ b/connectivity/source/inc/ParameterSubstitution.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_PARAMETERSUBSTITUTION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_PARAMETERSUBSTITUTION_HXX +#pragma once #include <com/sun/star/util/XStringSubstitution.hpp> #include <com/sun/star/lang/XInitialization.hpp> @@ -42,7 +41,7 @@ namespace connectivity ParameterSubstitution( const ParameterSubstitution& ) = delete; ParameterSubstitution& operator=( const ParameterSubstitution& ) = delete; public: - ParameterSubstitution(const css::uno::Reference< css::uno::XComponentContext >& _rxContext ); + ParameterSubstitution(css::uno::Reference< css::uno::XComponentContext > _rContext ); private: // XServiceInfo @@ -61,6 +60,4 @@ namespace connectivity } // connectivity -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/RowFunctionParser.hxx b/connectivity/source/inc/RowFunctionParser.hxx index 5bb508bc12ff..059544e51f2d 100644 --- a/connectivity/source/inc/RowFunctionParser.hxx +++ b/connectivity/source/inc/RowFunctionParser.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ROWFUNCTIONPARSER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ROWFUNCTIONPARSER_HXX +#pragma once #include <sal/config.h> #include "FDatabaseMetaDataResultSet.hxx" @@ -27,7 +26,6 @@ namespace connectivity { - enum class ExpressionFunct { Equation, @@ -40,15 +38,16 @@ enum class ExpressionFunct class OOO_DLLPUBLIC_DBTOOLS SAL_NO_VTABLE ExpressionNode { public: - virtual ~ExpressionNode(){} + virtual ~ExpressionNode() {} /** Operator to calculate function value. This method calculates the function value. */ - virtual ORowSetValueDecoratorRef evaluate(const ODatabaseMetaDataResultSet::ORow& _aRow ) const = 0; + virtual ORowSetValueDecoratorRef + evaluate(const ODatabaseMetaDataResultSet::ORow& _aRow) const = 0; - virtual void fill(const ODatabaseMetaDataResultSet::ORow& _aRow ) const = 0; + virtual void fill(const ODatabaseMetaDataResultSet::ORow& _aRow) const = 0; }; /** This exception is thrown, when the arithmetic expression @@ -56,13 +55,12 @@ public: */ struct OOO_DLLPUBLIC_DBTOOLS ParseError { - ParseError( const char* ) {} + ParseError(const char*) {} }; class FunctionParser { public: - /** Parse a string The following grammar is accepted by this method: @@ -96,19 +94,16 @@ public: @return the generated function object. */ - static std::shared_ptr<ExpressionNode> const & parseFunction( const OUString& _sFunction); + static std::shared_ptr<ExpressionNode> const& parseFunction(const OUString& _sFunction); private: // disabled constructor/destructor, since this is // supposed to be a singleton FunctionParser() = delete; FunctionParser(const FunctionParser&) = delete; - FunctionParser& operator=( const FunctionParser& ) = delete; + FunctionParser& operator=(const FunctionParser&) = delete; }; - } // namespace connectivity -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ROWFUNCTIONPARSER_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/TConnection.hxx b/connectivity/source/inc/TConnection.hxx index 85e6e4fac546..2dbe2ef6a756 100644 --- a/connectivity/source/inc/TConnection.hxx +++ b/connectivity/source/inc/TConnection.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_TCONNECTION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_TCONNECTION_HXX +#pragma once #include <rtl/textenc.h> #include <com/sun/star/beans/PropertyValue.hpp> @@ -62,7 +61,7 @@ namespace connectivity rtl_TextEncoding getTextEncoding() const { return m_nTextEncoding; } const OUString& getURL() const { return m_sURL; } void setURL(const OUString& _rsUrl) { m_sURL = _rsUrl; } - void throwGenericSQLException(const char* pErrorResourceId, const css::uno::Reference< css::uno::XInterface>& _xContext); + void throwGenericSQLException(TranslateId pErrorResourceId, const css::uno::Reference< css::uno::XInterface>& _xContext); const SharedResources& getResources() const { return m_aResources;} void setConnectionInfo(const css::uno::Sequence< css::beans::PropertyValue >& _aInfo) { m_aConnectionInfo = _aInfo; } @@ -74,10 +73,9 @@ namespace connectivity //XUnoTunnel virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; - static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); + static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId(); }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_TCONNECTION_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/TDatabaseMetaDataBase.hxx b/connectivity/source/inc/TDatabaseMetaDataBase.hxx index a13adf215167..4d8c7715ca2d 100644 --- a/connectivity/source/inc/TDatabaseMetaDataBase.hxx +++ b/connectivity/source/inc/TDatabaseMetaDataBase.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_TDATABASEMETADATABASE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_TDATABASEMETADATABASE_HXX +#pragma once #include <com/sun/star/sdbc/XDatabaseMetaData2.hpp> #include <cppuhelper/implbase.hxx> @@ -130,6 +129,5 @@ namespace connectivity virtual sal_Bool SAL_CALL storesMixedCaseQuotedIdentifiers( ) override; }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_TDATABASEMETADATABASE_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/TKeyValue.hxx b/connectivity/source/inc/TKeyValue.hxx index abf61a4c7429..49d41e0144f2 100644 --- a/connectivity/source/inc/TKeyValue.hxx +++ b/connectivity/source/inc/TKeyValue.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_TKEYVALUE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_TKEYVALUE_HXX +#pragma once #include <connectivity/FValue.hxx> #include <connectivity/dbtoolsdllapi.hxx> @@ -45,18 +44,16 @@ namespace connectivity OUString getKeyString(std::vector<ORowSetValueDecoratorRef>::size_type i) const { OSL_ENSURE(m_aKeys.size() > i,"Wrong index for KEyValue"); - return m_aKeys[i]->getValue(); + return m_aKeys[i]->getValue().getString(); } double getKeyDouble(std::vector<ORowSetValueDecoratorRef>::size_type i) const { OSL_ENSURE(m_aKeys.size() > i,"Wrong index for KEyValue"); - return m_aKeys[i]->getValue(); + return m_aKeys[i]->getValue().getDouble(); } sal_Int32 getValue() const { return m_nValue; } }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_TKEYVALUE_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/TPrivilegesResultSet.hxx b/connectivity/source/inc/TPrivilegesResultSet.hxx index d8f31194dc16..8c4070fce97a 100644 --- a/connectivity/source/inc/TPrivilegesResultSet.hxx +++ b/connectivity/source/inc/TPrivilegesResultSet.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_TPRIVILEGESRESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_TPRIVILEGESRESULTSET_HXX +#pragma once #include "FDatabaseMetaDataResultSet.hxx" #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> @@ -37,12 +36,11 @@ namespace connectivity OResultSetPrivileges(const css::uno::Reference< css::sdbc::XDatabaseMetaData>& _rxMeta ,const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern); - // ::cppu::OComponentHelper - virtual void SAL_CALL disposing() override; + // ::comphelper::WeakComponentImplHelper + virtual void disposing(std::unique_lock<std::mutex>&) override; // XResultSet virtual sal_Bool SAL_CALL next( ) override; }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_TPRIVILEGESRESULTSET_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/TResultSetHelper.hxx b/connectivity/source/inc/TResultSetHelper.hxx index e6c0efd9c97f..cedea102725a 100644 --- a/connectivity/source/inc/TResultSetHelper.hxx +++ b/connectivity/source/inc/TResultSetHelper.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_TRESULTSETHELPER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_TRESULTSETHELPER_HXX +#pragma once #include <sal/types.h> #include <connectivity/dbtoolsdllapi.hxx> @@ -49,6 +48,4 @@ namespace connectivity }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_TRESULTSETHELPER_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/TSkipDeletedSet.hxx b/connectivity/source/inc/TSkipDeletedSet.hxx index 3935264696ed..efe142af548c 100644 --- a/connectivity/source/inc/TSkipDeletedSet.hxx +++ b/connectivity/source/inc/TSkipDeletedSet.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_TSKIPDELETEDSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_TSKIPDELETEDSET_HXX +#pragma once #include "TResultSetHelper.hxx" #include <vector> @@ -77,6 +76,5 @@ namespace connectivity void SetDeletedVisible(bool _bDeletedVisible) { m_bDeletedVisible = _bDeletedVisible; } }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_TSKIPDELETEDSET_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/TSortIndex.hxx b/connectivity/source/inc/TSortIndex.hxx index c0354316efd9..3ac339f7e9f0 100644 --- a/connectivity/source/inc/TSortIndex.hxx +++ b/connectivity/source/inc/TSortIndex.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_TSORTINDEX_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_TSORTINDEX_HXX +#pragma once #include <connectivity/dbtoolsdllapi.hxx> #include "TKeyValue.hxx" @@ -58,8 +57,8 @@ namespace connectivity public: - OSortIndex( const std::vector<OKeyType>& _aKeyType, - const std::vector<TAscendingOrder>& _aAscending); + OSortIndex( std::vector<OKeyType>&& _aKeyType, + std::vector<TAscendingOrder>&& _aAscending); OSortIndex(OSortIndex const &) = delete; // MSVC2015 workaround OSortIndex& operator=(OSortIndex const &) = delete; // MSVC2015 workaround @@ -107,6 +106,5 @@ namespace connectivity void setFrozen() { m_bFrozen = true; } }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_TSORTINDEX_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/ACallableStatement.hxx b/connectivity/source/inc/ado/ACallableStatement.hxx index 6d6979e40f35..e58617b3b00e 100644 --- a/connectivity/source/inc/ado/ACallableStatement.hxx +++ b/connectivity/source/inc/ado/ACallableStatement.hxx @@ -17,18 +17,15 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ACALLABLESTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ACALLABLESTATEMENT_HXX +#pragma once #include <ado/APreparedStatement.hxx> #include <com/sun/star/sdbc/XRow.hpp> #include <com/sun/star/sdbc/XOutParameters.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> -namespace connectivity +namespace connectivity::ado { - namespace ado - { //************ Class: java.sql.CallableStatement @@ -45,8 +42,8 @@ namespace connectivity OCallableStatement( OConnection* _pConnection, const OUString& sql ); virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; // XRow virtual sal_Bool SAL_CALL wasNull( ) override; @@ -73,9 +70,7 @@ namespace connectivity virtual void SAL_CALL registerOutParameter( sal_Int32 parameterIndex, sal_Int32 sqlType, const OUString& typeName ) override; virtual void SAL_CALL registerNumericOutParameter( sal_Int32 parameterIndex, sal_Int32 sqlType, sal_Int32 scale ) override; }; - } } -#endif // _CONNECTIVITY_OCallableStatement_HXX_ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/ACatalog.hxx b/connectivity/source/inc/ado/ACatalog.hxx index d1d8e22bf49c..fd09e9ad3c40 100644 --- a/connectivity/source/inc/ado/ACatalog.hxx +++ b/connectivity/source/inc/ado/ACatalog.hxx @@ -16,16 +16,13 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ACATALOG_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ACATALOG_HXX +#pragma once #include <sdbcx/VCatalog.hxx> #include <ado/Awrapadox.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { class OConnection; class OCatalog : public connectivity::sdbcx::OCatalog @@ -47,8 +44,6 @@ namespace connectivity sdbcx::OCollection* getPrivateTables() const { return m_pTables.get(); } WpADOCatalog getCatalog() const { return m_aCatalog; } }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ACATALOG_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AColumn.hxx b/connectivity/source/inc/ado/AColumn.hxx index cc49f3b364c4..f297964820dc 100644 --- a/connectivity/source/inc/ado/AColumn.hxx +++ b/connectivity/source/inc/ado/AColumn.hxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ACOLUMN_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ACOLUMN_HXX +#pragma once #include <connectivity/sdbcx/VColumn.hxx> #include <ado/Awrapadox.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { class OConnection; typedef sdbcx::OColumn OColumn_ADO; class OAdoColumn : public OColumn_ADO @@ -47,14 +44,9 @@ namespace connectivity OAdoColumn(bool _bCase,OConnection* _pConnection); // ODescriptor virtual void construct() override; - // css::lang::XUnoTunnel - virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; - static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); WpADOColumn getColumnImpl() const; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ACOLUMN_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AColumns.hxx b/connectivity/source/inc/ado/AColumns.hxx index 6b605df7cab2..25decfa6877f 100644 --- a/connectivity/source/inc/ado/AColumns.hxx +++ b/connectivity/source/inc/ado/AColumns.hxx @@ -17,18 +17,15 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ACOLUMNS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ACOLUMNS_HXX +#pragma once #include <connectivity/sdbcx/VCollection.hxx> #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> #include <connectivity/sdbcx/IRefreshable.hxx> #include <ado/Awrapadox.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { class OConnection; class OColumns : public sdbcx::OCollection { @@ -54,8 +51,6 @@ namespace connectivity } }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ACOLUMNS_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AConnection.hxx b/connectivity/source/inc/ado/AConnection.hxx index 21bc9129c2c8..c2c82100363d 100644 --- a/connectivity/source/inc/ado/AConnection.hxx +++ b/connectivity/source/inc/ado/AConnection.hxx @@ -16,22 +16,20 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ACONNECTION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ACONNECTION_HXX +#pragma once #include <com/sun/star/sdbc/SQLWarning.hpp> #include <com/sun/star/sdbcx/XTablesSupplier.hpp> #include <com/sun/star/beans/PropertyValue.hpp> #include <map> +#include <string_view> #include <connectivity/CommonTools.hxx> #include <OTypeInfo.hxx> #include <TConnection.hxx> #include <ado/Awrapado.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { struct OExtendedTypeInfo { ::connectivity::OTypeInfo aSimpleType; // the general type info @@ -59,7 +57,7 @@ namespace connectivity css::uno::WeakReference< css::sdbcx::XTablesSupplier> m_xCatalog; ODriver* m_pDriver; private: - WpADOConnection* m_pAdoConnection; + WpADOConnection m_aAdoConnection; OCatalog* m_pCatalog; sal_Int32 m_nEngineType; bool m_bClosed; @@ -74,7 +72,7 @@ namespace connectivity OConnection(ODriver* _pDriver); // OConnection(const SQLHANDLE _pConnectionHandle); ~OConnection() override; - void construct(const OUString& url,const css::uno::Sequence< css::beans::PropertyValue >& info); + void construct(std::u16string_view url,const css::uno::Sequence< css::beans::PropertyValue >& info); //XUnoTunnel virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; @@ -109,7 +107,7 @@ namespace connectivity virtual css::uno::Any SAL_CALL getWarnings( ) override; virtual void SAL_CALL clearWarnings( ) override; - WpADOConnection* getConnection() { return m_pAdoConnection; } + WpADOConnection& getConnection() { return m_aAdoConnection; } void setCatalog(const css::uno::WeakReference< css::sdbcx::XTablesSupplier>& _xCat) { m_xCatalog = _xCat; } void setCatalog(OCatalog* _pCatalog) { m_pCatalog = _pCatalog; } @@ -131,8 +129,6 @@ namespace connectivity sal_Int32 _nScale, bool& _brForceToType); }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ACONNECTION_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/ADatabaseMetaData.hxx b/connectivity/source/inc/ado/ADatabaseMetaData.hxx index 83a84f3bda03..1661ca44181c 100644 --- a/connectivity/source/inc/ado/ADatabaseMetaData.hxx +++ b/connectivity/source/inc/ado/ADatabaseMetaData.hxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ADATABASEMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ADATABASEMETADATA_HXX +#pragma once #include <TDatabaseMetaDataBase.hxx> #include <map> -namespace connectivity +namespace connectivity::ado { - namespace ado - { class WpADOConnection; class OConnection; @@ -43,7 +40,7 @@ namespace connectivity }; std::map<sal_uInt32,LiteralInfo> m_aLiteralInfo; - WpADOConnection* m_pADOConnection; + WpADOConnection& m_rADOConnection; OConnection* m_pConnection; void fillLiterals(); @@ -218,9 +215,7 @@ namespace connectivity virtual sal_Bool SAL_CALL supportsBatchUpdates( ) override; virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getUDTs( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& typeNamePattern, const css::uno::Sequence< sal_Int32 >& types ) override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ADATABASEMETADATA_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/ADatabaseMetaDataResultSet.hxx b/connectivity/source/inc/ado/ADatabaseMetaDataResultSet.hxx index 4d99bdce387d..dce6971658d3 100644 --- a/connectivity/source/inc/ado/ADatabaseMetaDataResultSet.hxx +++ b/connectivity/source/inc/ado/ADatabaseMetaDataResultSet.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ADATABASEMETADATARESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ADATABASEMETADATARESULTSET_HXX +#pragma once #include <com/sun/star/sdbc/XResultSet.hpp> #include <com/sun/star/sdbc/XRow.hpp> @@ -34,10 +33,8 @@ #include <comphelper/proparrhlp.hxx> #include <ado/AStatement.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { /* ** java_sql_ResultSet */ @@ -134,8 +131,8 @@ namespace connectivity virtual void SAL_CALL disposing() override; // XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; // XPropertySet @@ -222,9 +219,7 @@ namespace connectivity return map; } - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ADATABASEMETADATARESULTSET_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/ADatabaseMetaDataResultSetMetaData.hxx b/connectivity/source/inc/ado/ADatabaseMetaDataResultSetMetaData.hxx index 714aa91367bd..abac49ba1d9b 100644 --- a/connectivity/source/inc/ado/ADatabaseMetaDataResultSetMetaData.hxx +++ b/connectivity/source/inc/ado/ADatabaseMetaDataResultSetMetaData.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ADATABASEMETADATARESULTSETMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ADATABASEMETADATARESULTSETMETADATA_HXX +#pragma once #include <com/sun/star/sdbc/XResultSetMetaData.hpp> #include <cppuhelper/implbase.hxx> @@ -27,10 +26,8 @@ #include <ado/ADatabaseMetaDataResultSet.hxx> #include <OColumn.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { //************ Class: ResultSetMetaData @@ -75,7 +72,7 @@ namespace connectivity ~ODatabaseMetaDataResultSetMetaData() override; /// Avoid ambiguous cast error from the compiler. - operator css::uno::Reference< css::sdbc::XResultSetMetaData > () throw() + operator css::uno::Reference< css::sdbc::XResultSetMetaData > () noexcept { return this; } virtual sal_Int32 SAL_CALL getColumnCount( ) override; @@ -100,8 +97,6 @@ namespace connectivity virtual sal_Bool SAL_CALL isDefinitelyWritable( sal_Int32 column ) override; virtual OUString SAL_CALL getColumnServiceName( sal_Int32 column ) override; }; - } } -#endif // _CONNECTIVITY_ADO_ADATABASEMETARESULTSETMETADATA_HXX_ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/ADriver.hxx b/connectivity/source/inc/ado/ADriver.hxx index df017f2b6fa2..8542e03f6d60 100644 --- a/connectivity/source/inc/ado/ADriver.hxx +++ b/connectivity/source/inc/ado/ADriver.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ADRIVER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ADRIVER_HXX +#pragma once #include <com/sun/star/sdbc/XDriver.hpp> #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp> @@ -26,15 +25,10 @@ #include <cppuhelper/compbase.hxx> #include <connectivity/CommonTools.hxx> -namespace com::sun::star::lang { class XMultiServiceFactory; } +namespace com::sun::star::uno { class XComponentContext; } -namespace connectivity +namespace connectivity::ado { - namespace ado - { - /// @throws css::uno::Exception - css::uno::Reference< css::uno::XInterface > ODriver_CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory); - typedef ::cppu::WeakComponentImplHelper< css::sdbc::XDriver, css::sdbcx::XDataDefinitionSupplier, css::lang::XServiceInfo @@ -46,23 +40,19 @@ namespace connectivity connectivity::OWeakRefArray m_xConnections; // vector containing a list // of all the Connection objects // for this Driver - css::uno::Reference< css::lang::XMultiServiceFactory > m_xORB; + css::uno::Reference< css::uno::XComponentContext > m_xContext; // to put back all the inits with COINIT_MULTITHREADED if needed int mnNbCallCoInitializeExForReinit; public: - ODriver(const css::uno::Reference< css::lang::XMultiServiceFactory >& _xORB); + ODriver(const css::uno::Reference< css::uno::XComponentContext >& xContext); ~ODriver() override; // OComponentHelper virtual void SAL_CALL disposing() override; - // XInterface - /// @throws css::uno::RuntimeException - static OUString getImplementationName_Static( ); - /// @throws css::uno::RuntimeException - static css::uno::Sequence< OUString > getSupportedServiceNames_Static( ); - css::uno::Reference< css::lang::XMultiServiceFactory > getORB() const { return m_xORB; } + + css::uno::Reference< css::uno::XComponentContext > getContext() const { return m_xContext; } private: void impl_checkURL_throw(const OUString& _sUrl); @@ -83,10 +73,8 @@ namespace connectivity virtual css::uno::Reference< css::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByConnection( const css::uno::Reference< css::sdbc::XConnection >& connection ) override; virtual css::uno::Reference< css::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByURL( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ADRIVER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AGroup.hxx b/connectivity/source/inc/ado/AGroup.hxx index 2b3f36fff30f..00207a5fa23a 100644 --- a/connectivity/source/inc/ado/AGroup.hxx +++ b/connectivity/source/inc/ado/AGroup.hxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AGROUP_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AGROUP_HXX +#pragma once #include <sdbcx/VGroup.hxx> #include <ado/Awrapadox.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { typedef sdbcx::OGroup OGroup_ADO; class OCatalog; @@ -48,10 +45,6 @@ namespace connectivity OAdoGroup(OCatalog* _pParent,bool _bCase, ADOGroup* _pGroup=nullptr); OAdoGroup(OCatalog* _pParent,bool _bCase, const OUString& Name); - // css::lang::XUnoTunnel - virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; - static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); - // XAuthorizable virtual sal_Int32 SAL_CALL getPrivileges( const OUString& objName, sal_Int32 objType ) override; virtual sal_Int32 SAL_CALL getGrantablePrivileges( const OUString& objName, sal_Int32 objType ) override; @@ -60,8 +53,6 @@ namespace connectivity WpADOGroup getImpl() const { return m_aGroup; } }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AGROUP_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AGroups.hxx b/connectivity/source/inc/ado/AGroups.hxx index 1676b9a6c089..85817cec84d0 100644 --- a/connectivity/source/inc/ado/AGroups.hxx +++ b/connectivity/source/inc/ado/AGroups.hxx @@ -17,17 +17,14 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AGROUPS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AGROUPS_HXX +#pragma once #include <connectivity/sdbcx/VCollection.hxx> #include <ado/Awrapadox.hxx> #include <ado/ACatalog.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { class OGroups : public sdbcx::OCollection { WpADOGroups m_aCollection; @@ -49,9 +46,6 @@ namespace connectivity { } }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AGROUPS_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AIndex.hxx b/connectivity/source/inc/ado/AIndex.hxx index b31bef3f808c..98c3a77d1ceb 100644 --- a/connectivity/source/inc/ado/AIndex.hxx +++ b/connectivity/source/inc/ado/AIndex.hxx @@ -17,17 +17,14 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AINDEX_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AINDEX_HXX +#pragma once #include <sdbcx/VIndex.hxx> #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> #include <ado/Awrapadox.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { class OConnection; class OAdoIndex : public sdbcx::OIndex { @@ -41,14 +38,9 @@ namespace connectivity public: OAdoIndex(bool _bCase, OConnection* _pConnection,ADOIndex* _pIndex); OAdoIndex(bool _bCase, OConnection* _pConnection); - // css::lang::XUnoTunnel - virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; - static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); WpADOIndex getImpl() const { return m_aIndex;} }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AINDEX_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AIndexes.hxx b/connectivity/source/inc/ado/AIndexes.hxx index 4c253cac5e2e..48c2d1abee83 100644 --- a/connectivity/source/inc/ado/AIndexes.hxx +++ b/connectivity/source/inc/ado/AIndexes.hxx @@ -16,17 +16,14 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AINDEXES_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AINDEXES_HXX +#pragma once #include <connectivity/sdbcx/VCollection.hxx> #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> #include <ado/Awrapadox.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { class OConnection; class OIndexes : public sdbcx::OCollection { @@ -51,9 +48,6 @@ namespace connectivity { } }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AINDEXES_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AKey.hxx b/connectivity/source/inc/ado/AKey.hxx index bd0b5a6404e9..5ec3fa972b12 100644 --- a/connectivity/source/inc/ado/AKey.hxx +++ b/connectivity/source/inc/ado/AKey.hxx @@ -17,17 +17,14 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AKEY_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AKEY_HXX +#pragma once #include <sdbcx/VKey.hxx> #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> #include <ado/Awrapadox.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { typedef sdbcx::OKey OKey_ADO; class OConnection; @@ -44,10 +41,6 @@ namespace connectivity OAdoKey(bool _bCase,OConnection* _pConnection,ADOKey* _pKey); OAdoKey(bool _bCase,OConnection* _pConnection); - // css::lang::XUnoTunnel - virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; - static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); - WpADOKey getImpl() const { return m_aKey;} // map the update/delete rules static RuleEnum Map2Rule(sal_Int32 _eNum); @@ -57,8 +50,6 @@ namespace connectivity static sal_Int32 MapKeyRule(const KeyTypeEnum& _eNum); static KeyTypeEnum Map2KeyRule(sal_Int32 _eNum); }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AKEY_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AKeys.hxx b/connectivity/source/inc/ado/AKeys.hxx index 35ef33e37455..45e127e29bf7 100644 --- a/connectivity/source/inc/ado/AKeys.hxx +++ b/connectivity/source/inc/ado/AKeys.hxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AKEYS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AKEYS_HXX +#pragma once #include <connectivity/sdbcx/VCollection.hxx> #include <ado/Awrapadox.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { class OConnection; class OKeys : public sdbcx::OCollection { @@ -51,9 +48,6 @@ namespace connectivity { } }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AKEYS_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/APreparedStatement.hxx b/connectivity/source/inc/ado/APreparedStatement.hxx index 214f277c16bf..2ce394dbdefb 100644 --- a/connectivity/source/inc/ado/APreparedStatement.hxx +++ b/connectivity/source/inc/ado/APreparedStatement.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_APREPAREDSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_APREPAREDSTATEMENT_HXX +#pragma once #include <ado/AStatement.hxx> #include <com/sun/star/sdbc/XPreparedStatement.hpp> @@ -63,8 +62,8 @@ namespace connectivity // a Constructor, that is needed for when Returning the Object is needed: OPreparedStatement( OConnection* _pConnection, const OUString& sql); - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; @@ -110,6 +109,5 @@ namespace connectivity }; } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_APREPAREDSTATEMENT_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AResultSet.hxx b/connectivity/source/inc/ado/AResultSet.hxx index f901553332e0..58de2baeb539 100644 --- a/connectivity/source/inc/ado/AResultSet.hxx +++ b/connectivity/source/inc/ado/AResultSet.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ARESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ARESULTSET_HXX +#pragma once #include <com/sun/star/sdbc/XResultSet.hpp> #include <com/sun/star/sdbc/XRow.hpp> @@ -37,10 +36,8 @@ #include <cppuhelper/basemutex.hxx> #include <com/sun/star/lang/XServiceInfo.hpp> -namespace connectivity +namespace connectivity::ado { - namespace ado - { /* ** java_sql_ResultSet */ @@ -137,8 +134,8 @@ namespace connectivity virtual void SAL_CALL disposing() override; // XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; // XPropertySet @@ -230,10 +227,8 @@ namespace connectivity virtual css::uno::Sequence< sal_Int32 > SAL_CALL deleteRows( const css::uno::Sequence< css::uno::Any >& rows ) override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ARESULTSET_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AResultSetMetaData.hxx b/connectivity/source/inc/ado/AResultSetMetaData.hxx index ebb52be02e2b..1eeb22656245 100644 --- a/connectivity/source/inc/ado/AResultSetMetaData.hxx +++ b/connectivity/source/inc/ado/AResultSetMetaData.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ARESULTSETMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ARESULTSETMETADATA_HXX +#pragma once #include <com/sun/star/sdbc/XResultSetMetaData.hpp> #include <cppuhelper/implbase.hxx> @@ -27,10 +26,8 @@ #include <ado/AResultSet.hxx> #include <OColumn.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { //************ Class: ResultSetMetaData @@ -77,8 +74,6 @@ namespace connectivity virtual sal_Bool SAL_CALL isDefinitelyWritable( sal_Int32 column ) override; virtual OUString SAL_CALL getColumnServiceName( sal_Int32 column ) override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ARESULTSETMETADATA_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AStatement.hxx b/connectivity/source/inc/ado/AStatement.hxx index 278a3595095b..625339917591 100644 --- a/connectivity/source/inc/ado/AStatement.hxx +++ b/connectivity/source/inc/ado/AStatement.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ASTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ASTATEMENT_HXX +#pragma once #include <com/sun/star/sdbc/XStatement.hpp> #include <com/sun/star/sdbc/XWarningsSupplier.hpp> @@ -31,14 +30,13 @@ #include <cppuhelper/basemutex.hxx> #include <comphelper/proparrhlp.hxx> #include <ado/AConnection.hxx> +#include <string_view> #include <vector> #include <ado/Awrapado.hxx> #include <com/sun/star/lang/XServiceInfo.hpp> -namespace connectivity +namespace connectivity::ado { - namespace ado - { typedef ::cppu::WeakComponentImplHelper< css::sdbc::XStatement, css::sdbc::XWarningsSupplier, css::util::XCancellable, @@ -127,7 +125,7 @@ namespace connectivity void setFetchSize(sal_Int32 _par0); /// @throws css::sdbc::SQLException /// @throws css::uno::RuntimeException - void setCursorName(const OUString &_par0); + void setCursorName(std::u16string_view _par0); protected: @@ -169,8 +167,8 @@ namespace connectivity // OComponentHelper virtual void SAL_CALL disposing() override; // XInterface - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; @@ -206,16 +204,14 @@ namespace connectivity DECLARE_SERVICE_INFO(); - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; // XBatchExecution virtual void SAL_CALL addBatch( const OUString& sql ) override; virtual void SAL_CALL clearBatch( ) override; virtual css::uno::Sequence< sal_Int32 > SAL_CALL executeBatch( ) override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ASTATEMENT_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/ATable.hxx b/connectivity/source/inc/ado/ATable.hxx index 51a9fd14588b..827485a6b480 100644 --- a/connectivity/source/inc/ado/ATable.hxx +++ b/connectivity/source/inc/ado/ATable.hxx @@ -17,17 +17,14 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ATABLE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ATABLE_HXX +#pragma once #include <connectivity/sdbcx/VTable.hxx> #include <ado/Awrapadox.hxx> #include <ado/ACatalog.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { typedef connectivity::sdbcx::OTable OTable_TYPEDEF; typedef connectivity::sdbcx::OTableDescriptor_BASE OTableDescriptor_BASE_TYPEDEF; @@ -56,9 +53,6 @@ namespace connectivity virtual OUString SAL_CALL getName() override; OUString getSchema() const { return m_SchemaName; } virtual css::uno::Reference< css::sdbc::XDatabaseMetaData> getMetaData() const override; - // css::lang::XUnoTunnel - virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; - static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); // XRename virtual void SAL_CALL rename( const OUString& newName ) override; @@ -70,8 +64,6 @@ namespace connectivity WpADOTable getImpl() const { return m_aTable;} OCatalog* getCatalog() const { return m_pCatalog; } }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ATABLE_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/ATables.hxx b/connectivity/source/inc/ado/ATables.hxx index a65741862702..4fff5b97956e 100644 --- a/connectivity/source/inc/ado/ATables.hxx +++ b/connectivity/source/inc/ado/ATables.hxx @@ -16,17 +16,14 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ATABLES_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ATABLES_HXX +#pragma once #include <connectivity/sdbcx/VCollection.hxx> #include <ado/Awrapadox.hxx> #include <ado/ACatalog.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { class OCatalog; class OTables : public sdbcx::OCollection { @@ -50,8 +47,6 @@ namespace connectivity } void appendNew(const OUString& _rsNewTable); }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ATABLES_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AUser.hxx b/connectivity/source/inc/ado/AUser.hxx index 3b7227d36455..8d0c0f7321b6 100644 --- a/connectivity/source/inc/ado/AUser.hxx +++ b/connectivity/source/inc/ado/AUser.hxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AUSER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AUSER_HXX +#pragma once #include <sdbcx/VUser.hxx> #include <ado/Awrapadox.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { class OCatalog; typedef connectivity::sdbcx::OUser OUser_TYPEDEF; typedef connectivity::sdbcx::OUser_BASE OUser_BASE_TYPEDEF; @@ -51,9 +48,6 @@ namespace connectivity OAdoUser(OCatalog* _pParent,bool _bCase, ADOUser* _pUser=nullptr); OAdoUser(OCatalog* _pParent,bool _bCase, const OUString& Name); - // css::lang::XUnoTunnel - virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; - static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); // XUser virtual void SAL_CALL changePassword( const OUString& objPassword, const OUString& newPassword ) override; // XAuthorizable @@ -84,8 +78,6 @@ namespace connectivity virtual void construct() override; OUString getPassword() const { return m_Password;} }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AUSER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AUsers.hxx b/connectivity/source/inc/ado/AUsers.hxx index 181639196576..1ec0bd5ad8f7 100644 --- a/connectivity/source/inc/ado/AUsers.hxx +++ b/connectivity/source/inc/ado/AUsers.hxx @@ -17,17 +17,14 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AUSERS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AUSERS_HXX +#pragma once #include <connectivity/sdbcx/VCollection.hxx> #include <ado/Awrapadox.hxx> #include <ado/ACatalog.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { class OUsers : public sdbcx::OCollection { @@ -51,9 +48,6 @@ namespace connectivity { } }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AUSERS_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AView.hxx b/connectivity/source/inc/ado/AView.hxx index 1bc3dd00bf2d..db81c4e70bb5 100644 --- a/connectivity/source/inc/ado/AView.hxx +++ b/connectivity/source/inc/ado/AView.hxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AVIEW_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AVIEW_HXX +#pragma once #include <connectivity/sdbcx/VView.hxx> #include <ado/Awrapadox.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { typedef sdbcx::OView OView_ADO; @@ -43,15 +40,8 @@ namespace connectivity public: OAdoView(bool _bCase, ADOView* _pView=nullptr); - // css::lang::XUnoTunnel - virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; - static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); - WpADOView getImpl() const { return m_aView;} }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AVIEW_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/AViews.hxx b/connectivity/source/inc/ado/AViews.hxx index 1ef1a6be31c3..ef0c692fdfc3 100644 --- a/connectivity/source/inc/ado/AViews.hxx +++ b/connectivity/source/inc/ado/AViews.hxx @@ -17,18 +17,15 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AVIEWS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AVIEWS_HXX +#pragma once #include <connectivity/sdbcx/VCollection.hxx> #include <ado/Awrapadox.hxx> #include <ado/ACatalog.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { class OViews : public sdbcx::OCollection { @@ -49,8 +46,6 @@ namespace connectivity { } }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AVIEWS_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/Aolevariant.hxx b/connectivity/source/inc/ado/Aolevariant.hxx index 732880a7c088..ba0653156a94 100644 --- a/connectivity/source/inc/ado/Aolevariant.hxx +++ b/connectivity/source/inc/ado/Aolevariant.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AOLEVARIANT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AOLEVARIANT_HXX +#pragma once #include <sal/types.h> #include <rtl/ustring.hxx> @@ -25,46 +24,15 @@ #include <oaidl.h> -namespace com +namespace com::sun::star::util { - namespace sun - { - namespace star - { - namespace util - { - struct Date; - struct Time; - struct DateTime; - } - } - } + struct Date; + struct Time; + struct DateTime; } -namespace connectivity -{ - namespace ado - { - class OLEString - { - BSTR m_sStr; - public: - OLEString(); - OLEString(const BSTR& _sBStr); - OLEString(const OUString& _sBStr); - OLEString(const OLEString& _rRh) - { - OLEString::operator=(_rRh); - } - ~OLEString(); - OLEString& operator=(const OUString& _rSrc); - OLEString& operator=(const BSTR& _rSrc); - OLEString& operator=(const OLEString& _rSrc); - OUString asOUString() const; - BSTR asBSTR() const; - BSTR* getAddress(); - sal_Int32 length() const; - }; +namespace connectivity::ado +{ class OLEVariant : public ::tagVARIANT { public: @@ -78,7 +46,11 @@ namespace connectivity OLEVariant(sal_Int32 n) ; OLEVariant(sal_Int64 x) ; - OLEVariant(const OUString& us) ; + OLEVariant(std::u16string_view us); + OLEVariant(const OUString& us) + : OLEVariant(std::u16string_view(us)) + { + } ~OLEVariant() ; OLEVariant(const css::util::Date& x ); OLEVariant(const css::util::Time& x ); @@ -103,7 +75,7 @@ namespace connectivity void setChar(unsigned char a) ; void setCurrency(double aCur) ; void setBool(bool b) ; - void setString(const OUString& us) ; + void setString(std::u16string_view us); void setNoArg() ; void setIDispatch(IDispatch* pDispInterface); @@ -146,9 +118,6 @@ namespace connectivity void set(double n); }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AOLEVARIANT_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/Aolewrap.hxx b/connectivity/source/inc/ado/Aolewrap.hxx index ef5c1a85995f..9d402fcf21b1 100644 --- a/connectivity/source/inc/ado/Aolewrap.hxx +++ b/connectivity/source/inc/ado/Aolewrap.hxx @@ -16,118 +16,76 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AOLEWRAP_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AOLEWRAP_HXX +#pragma once #include <osl/diagnose.h> #include <osl/thread.h> +#include <systools/win32/comtools.hxx> + #include <map> #include <vector> +#include "Aolevariant.hxx" + namespace rtl { class OUString; } -namespace connectivity +namespace connectivity::ado { - namespace ado - { - class OLEVariant; - class WpBase - { - protected: - IDispatch* pIUnknown; - - void setIDispatch(IDispatch* _pIUnknown); - public: - WpBase(); - WpBase(IDispatch* pInt); - //inline - WpBase& operator=(const WpBase& rhs); - WpBase& operator=(IDispatch* rhs); - WpBase(const WpBase& aWrapper); - virtual ~WpBase(); - void clear(); - - - bool IsValid() const; - operator IDispatch*(); - - }; - // Template class WpOLEBase<class T> // ================================== // // Objects of this class contain a pointer to an interface of the type T. - // The ctors and operator= make sure, that AddRef() and Release() are being - // called adhering to COM conventions. - // An object can also hold no pointer (null pointer), calling IsValid() then - // returns false. - // - // In order to do efficient pass-by-value, this class (as all derived classes) - // is a thin wrapper class, avoiding virtual methods and inlining. - template<class T> class WpOLEBase : public WpBase + template<class T> class WpOLEBase { protected: - T* pInterface; + sal::systools::COMReference<T> pInterface; public: - WpOLEBase(T* pInt = nullptr) : WpBase(pInt),pInterface(pInt){} + WpOLEBase(T* pInt = nullptr) : pInterface(pInt){} + WpOLEBase(const WpOLEBase<T>& aWrapper) + : pInterface( aWrapper.pInterface ) + { + } //inline WpOLEBase<T>& operator=(const WpOLEBase<T>& rhs) { - WpBase::operator=(rhs); pInterface = rhs.pInterface; return *this; }; - WpOLEBase<T>& operator=(T* rhs) - { - WpBase::operator=(rhs); - pInterface = rhs.pInterface; - return *this; - } - - WpOLEBase(const WpOLEBase<T>& aWrapper) - : WpBase( aWrapper ) - , pInterface( aWrapper.pInterface ) - { - } - - operator T*() const { return pInterface; } - void setWithOutAddRef(T* _pInterface) - { - pInterface = _pInterface; - WpBase::setIDispatch(_pInterface); - } + operator T*() const { return pInterface.get(); } + T** operator&() { return &pInterface; } + bool IsValid() const { return pInterface.is(); } + void set(T* p) { pInterface = p; } + void clear() { pInterface.clear(); } }; - // Template class WpOLECollection<class Ts, class T, class WrapT> + // Template class WpOLECollection<class Ts, class WrapT> // =============================================================== // // This class (derived from WpOLEBase<Ts>), abstracts away the properties // common to DAO collections: // // They are accessed via an interface Ts (e.g. DAOFields) and can return - // Items of the Type T (actually: with the interface T, e.g. DAOField) - // via get_Item (here GetItem). + // Items of the type wrapped by WrapT (actually: with the interface, e.g. + // DAOField) via get_Item (here GetItem). // - // This wrapper class does not expose an interface T, however, - // it exposes an object of the class WrapT. This must allow a construction - // by T, preferably it is derived from WpOLEBase<T>. + // This wrapper class exposes an object of the class WrapT. - template<class Ts, class T, class WrapT> class WpOLECollection : public WpOLEBase<Ts> + template<class Ts, class WrapT> class WpOLECollection : public WpOLEBase<Ts> { public: using WpOLEBase<Ts>::pInterface; using WpOLEBase<Ts>::IsValid; // Ctors, operator= // They only call the superclass - WpOLECollection(Ts* pInt=nullptr):WpOLEBase<Ts>(pInt){} + WpOLECollection() = default; WpOLECollection(const WpOLECollection& rhs) : WpOLEBase<Ts>(rhs) {} WpOLECollection& operator=(const WpOLECollection& rhs) {WpOLEBase<Ts>::operator=(rhs); return *this;}; @@ -144,35 +102,28 @@ namespace connectivity WrapT GetItem(sal_Int32 index) const { OSL_ENSURE(index >= 0 && index<GetItemCount(),"Wrong index for field!"); - T* pT = NULL; - WrapT aRet(NULL); - if(SUCCEEDED(pInterface->get_Item(OLEVariant(index), &pT))) - aRet.setWithOutAddRef(pT); + WrapT aRet; + pInterface->get_Item(OLEVariant(index), &aRet); return aRet; } WrapT GetItem(const OLEVariant& index) const { - T* pT = NULL; - WrapT aRet(NULL); - if(SUCCEEDED(pInterface->get_Item(index, &pT))) - aRet.setWithOutAddRef(pT); + WrapT aRet; + pInterface->get_Item(index, &aRet); return aRet; } WrapT GetItem(const OUString& sStr) const { - WrapT aRet(NULL); - T* pT = NULL; - if (FAILED(pInterface->get_Item(OLEVariant(sStr), &pT))) + WrapT aRet; + if (FAILED(pInterface->get_Item(OLEVariant(sStr), &aRet))) { #if OSL_DEBUG_LEVEL > 0 OString sTemp("Unknown Item: " + OString(sStr.getStr(),sStr.getLength(),osl_getThreadTextEncoding())); OSL_FAIL(sTemp.getStr()); #endif } - else - aRet.setWithOutAddRef(pT); return aRet; } void fillElementNames(::std::vector< OUString>& _rVector) @@ -192,23 +143,23 @@ namespace connectivity } }; - template<class Ts, class T, class WrapT> class WpOLEAppendCollection: - public WpOLECollection<Ts,T,WrapT> + template<class Ts, class WrapT> class WpOLEAppendCollection: + public WpOLECollection<Ts,WrapT> { public: // Ctors, operator= // They only call the superclass using WpOLEBase<Ts>::pInterface; - WpOLEAppendCollection(Ts* pInt=nullptr):WpOLECollection<Ts,T,WrapT>(pInt){} - WpOLEAppendCollection(const WpOLEAppendCollection& rhs) : WpOLECollection<Ts, T, WrapT>(rhs) {} + WpOLEAppendCollection() = default; + WpOLEAppendCollection(const WpOLEAppendCollection& rhs) : WpOLECollection<Ts, WrapT>(rhs) {} WpOLEAppendCollection& operator=(const WpOLEAppendCollection& rhs) {WpOLEBase<Ts>::operator=(rhs); return *this;}; bool Append(const WrapT& aWrapT) { - return SUCCEEDED(pInterface->Append(OLEVariant(static_cast<T*>(aWrapT)))); + return SUCCEEDED(pInterface->Append(OLEVariant(aWrapT))); }; bool Delete(const OUString& sName) @@ -218,8 +169,6 @@ namespace connectivity }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AOLEWRAP_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/Awrapado.hxx b/connectivity/source/inc/ado/Awrapado.hxx index c7817a75b326..507b85522674 100644 --- a/connectivity/source/inc/ado/Awrapado.hxx +++ b/connectivity/source/inc/ado/Awrapado.hxx @@ -16,8 +16,11 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AWRAPADO_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AWRAPADO_HXX +#pragma once + +#include <sal/config.h> + +#include <string_view> #include <com/sun/star/beans/PropertyAttribute.hpp> @@ -29,10 +32,8 @@ #include <ado/Aolewrap.hxx> #include <ado/Aolevariant.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { class WpADOConnection; class WpADOCommand; class WpADORecordset; @@ -41,16 +42,15 @@ namespace connectivity class WpADOError; class WpADOProperty; - typedef WpOLEAppendCollection< ADOFields, ADOField, WpADOField> WpADOFields; - typedef WpOLECollection< ADOProperties, ADOProperty, WpADOProperty> WpADOProperties; + typedef WpOLEAppendCollection< ADOFields, WpADOField> WpADOFields; + typedef WpOLECollection< ADOProperties, WpADOProperty> WpADOProperties; class WpADOConnection : public WpOLEBase<ADOConnection> { - friend class WpADOCommand; public: - WpADOConnection(ADOConnection* pInt) : WpOLEBase<ADOConnection>(pInt){} + WpADOConnection() = default; WpADOConnection(const WpADOConnection& rhs) : WpOLEBase<ADOConnection>(rhs) {} @@ -61,22 +61,22 @@ namespace connectivity WpADOProperties get_Properties() const; OUString GetConnectionString() const; - bool PutConnectionString(const OUString &aCon) const; + bool PutConnectionString(std::u16string_view aCon) const; sal_Int32 GetCommandTimeout() const; void PutCommandTimeout(sal_Int32 nRet); sal_Int32 GetConnectionTimeout() const ; void PutConnectionTimeout(sal_Int32 nRet); bool Close( ) ; - bool Execute(const OUString& CommandText,OLEVariant& RecordsAffected,long Options, WpADORecordset** ppiRset); + bool Execute(std::u16string_view CommandText,OLEVariant& RecordsAffected,long Options, WpADORecordset** ppiRset); bool BeginTrans(); bool CommitTrans( ) ; bool RollbackTrans( ); - bool Open(const OUString& ConnectionString, const OUString& UserID,const OUString& Password,long Options); + bool Open(std::u16string_view ConnectionString, std::u16string_view UserID,std::u16string_view Password,long Options); bool GetErrors(ADOErrors** pErrors); OUString GetDefaultDatabase() const; - bool PutDefaultDatabase(const OUString& _bstr); + bool PutDefaultDatabase(std::u16string_view _bstr); IsolationLevelEnum get_IsolationLevel() const ; bool put_IsolationLevel(const IsolationLevelEnum& eNum) ; @@ -91,7 +91,7 @@ namespace connectivity bool put_Mode(const ConnectModeEnum &eNum) ; OUString get_Provider() const; - bool put_Provider(const OUString& _bstr); + bool put_Provider(std::u16string_view _bstr); sal_Int32 get_State() const; @@ -100,38 +100,38 @@ namespace connectivity OUString get_Version() const; // special methods - ADORecordset* getExportedKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ); - ADORecordset* getImportedKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ); - ADORecordset* getPrimaryKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ); - ADORecordset* getIndexInfo( const css::uno::Any& catalog, const OUString& schema, const OUString& table, bool unique, bool approximate ); + ADORecordset* getExportedKeys( const css::uno::Any& catalog, const OUString& schema, std::u16string_view table ); + ADORecordset* getImportedKeys( const css::uno::Any& catalog, const OUString& schema, std::u16string_view table ); + ADORecordset* getPrimaryKeys( const css::uno::Any& catalog, const OUString& schema, std::u16string_view table ); + ADORecordset* getIndexInfo( const css::uno::Any& catalog, const OUString& schema, std::u16string_view table, bool unique, bool approximate ); ADORecordset* getTablePrivileges( const css::uno::Any& catalog, const OUString& schemaPattern, - const OUString& tableNamePattern ); + std::u16string_view tableNamePattern ); ADORecordset* getCrossReference( const css::uno::Any& primaryCatalog, const OUString& primarySchema, - const OUString& primaryTable, + std::u16string_view primaryTable, const css::uno::Any& foreignCatalog, const OUString& foreignSchema, - const OUString& foreignTable); + std::u16string_view foreignTable); ADORecordset* getProcedures( const css::uno::Any& catalog, const OUString& schemaPattern, - const OUString& procedureNamePattern ); + std::u16string_view procedureNamePattern ); ADORecordset* getProcedureColumns( const css::uno::Any& catalog, const OUString& schemaPattern, - const OUString& procedureNamePattern, - const OUString& columnNamePattern ); + std::u16string_view procedureNamePattern, + std::u16string_view columnNamePattern ); ADORecordset* getTables( const css::uno::Any& catalog, const OUString& schemaPattern, - const OUString& tableNamePattern, + std::u16string_view tableNamePattern, const css::uno::Sequence< OUString >& types ); ADORecordset* getColumns( const css::uno::Any& catalog, const OUString& schemaPattern, - const OUString& tableNamePattern, - const OUString& columnNamePattern ); + std::u16string_view tableNamePattern, + std::u16string_view columnNamePattern ); ADORecordset* getColumnPrivileges( const css::uno::Any& catalog, const OUString& schemaPattern, - const OUString& table, - const OUString& columnNamePattern ); + std::u16string_view table, + std::u16string_view columnNamePattern ); ADORecordset* getTypeInfo(DataTypeEnum _eType = adEmpty ); }; @@ -139,11 +139,9 @@ namespace connectivity class WpADOCommand : public WpOLEBase<ADOCommand> { public: - WpADOCommand(){} + WpADOCommand() = default; // Ctors, operator= // They only call the superclass - WpADOCommand(ADOCommand* pInt) : WpOLEBase<ADOCommand>(pInt){} - WpADOCommand(const WpADOCommand& rhs) : WpOLEBase<ADOCommand>(rhs) {} WpADOCommand& operator=(const WpADOCommand& rhs) @@ -151,26 +149,26 @@ namespace connectivity WpOLEBase<ADOCommand>::operator=(rhs); return *this;} - bool putref_ActiveConnection( WpADOConnection *pCon); + bool putref_ActiveConnection(const WpADOConnection& rCon); void put_ActiveConnection(/* [in] */ const OLEVariant& vConn); void Create(); sal_Int32 get_State() const; OUString get_CommandText() const; - bool put_CommandText(const OUString &aCon) ; + bool put_CommandText(std::u16string_view aCon) ; sal_Int32 get_CommandTimeout() const; void put_CommandTimeout(sal_Int32 nRet); bool get_Prepared() const; bool put_Prepared(VARIANT_BOOL bPrepared) const; bool Execute(OLEVariant& RecordsAffected,OLEVariant& Parameters,long Options, ADORecordset** ppiRset); - ADOParameter* CreateParameter(const OUString &_bstr,DataTypeEnum Type,ParameterDirectionEnum Direction,long nSize,const OLEVariant &Value); + ADOParameter* CreateParameter(std::u16string_view _bstr,DataTypeEnum Type,ParameterDirectionEnum Direction,long nSize,const OLEVariant &Value); ADOParameters* get_Parameters() const; bool put_CommandType( /* [in] */ CommandTypeEnum lCmdType); CommandTypeEnum get_CommandType( ) const ; // Returns the field's name OUString GetName() const ; - bool put_Name(const OUString& Name); + bool put_Name(std::u16string_view Name); bool Cancel(); }; @@ -180,7 +178,7 @@ namespace connectivity // Ctors, operator= // They only call the superclass - WpADOError(ADOError* pInt):WpOLEBase<ADOError>(pInt){} + WpADOError() = default; WpADOError(const WpADOError& rhs) : WpOLEBase<ADOError>(rhs) {} @@ -203,7 +201,7 @@ namespace connectivity // Ctors, operator= // They only call the superclass - WpADOField(ADOField* pInt=nullptr):WpOLEBase<ADOField>(pInt){} + WpADOField() = default; WpADOField(const WpADOField& rhs) : WpOLEBase<ADOField>(rhs) {} WpADOField& operator=(const WpADOField& rhs) @@ -249,7 +247,7 @@ namespace connectivity public: // Ctors, operator= // They only call the superclass - WpADOProperty(ADOProperty* pInt=nullptr):WpOLEBase<ADOProperty>(pInt){} + WpADOProperty() = default; WpADOProperty(const WpADOProperty& rhs) : WpOLEBase<ADOProperty>(rhs) {} WpADOProperty& operator=(const WpADOProperty& rhs) {WpOLEBase<ADOProperty>::operator=(rhs); return *this;} @@ -271,7 +269,7 @@ namespace connectivity public: // Ctors, operator= // They only call the superclass - WpADORecordset(ADORecordset* pInt=nullptr):WpOLEBase<ADORecordset>(pInt){} + WpADORecordset() = default; WpADORecordset(const WpADORecordset& rhs) : WpOLEBase<ADORecordset>() {operator=(rhs);} WpADORecordset& operator=(const WpADORecordset& rhs) { @@ -331,7 +329,7 @@ namespace connectivity public: // Ctors, operator= // They only call the superclass - WpADOParameter(ADOParameter* pInt):WpOLEBase<ADOParameter>(pInt){} + WpADOParameter() = default; WpADOParameter(const WpADOParameter& rhs):WpOLEBase<ADOParameter>(rhs){} WpADOParameter& operator=(const WpADOParameter& rhs) {WpOLEBase<ADOParameter>::operator=(rhs); return *this;} @@ -369,8 +367,6 @@ namespace connectivity */ static OLEVariant getValue(const WpADOProperties& _rProps,const OLEVariant &_aPosition); }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_AWRAPADO_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/Awrapadox.hxx b/connectivity/source/inc/ado/Awrapadox.hxx index 7a4f3e5a1ef7..ba91422a1d09 100644 --- a/connectivity/source/inc/ado/Awrapadox.hxx +++ b/connectivity/source/inc/ado/Awrapadox.hxx @@ -19,6 +19,10 @@ #pragma once +#include <sal/config.h> + +#include <string_view> + #include <com/sun/star/beans/PropertyAttribute.hpp> #ifndef __User_FWD_DEFINED__ @@ -66,10 +70,8 @@ typedef struct _ADOTable Table; #include <ado/WrapTable.hxx> #include <ado/WrapCatalog.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { class WpADOView : public WpOLEBase<ADOView> { public: @@ -87,7 +89,7 @@ namespace connectivity class WpADOGroup : public WpOLEBase<ADOGroup> { public: - WpADOGroup(ADOGroup* pInt=nullptr) : WpOLEBase<ADOGroup>(pInt){} + WpADOGroup() = default; WpADOGroup(const WpADOGroup& rhs) : WpOLEBase<ADOGroup>(rhs) {} WpADOGroup& operator=(const WpADOGroup& rhs) @@ -96,7 +98,7 @@ namespace connectivity void Create(); OUString get_Name() const; - void put_Name(const OUString& _rName); + void put_Name(std::u16string_view _rName); RightsEnum GetPermissions( /* [in] */ const OLEVariant& Name, /* [in] */ ObjectTypeEnum ObjectType); @@ -111,7 +113,7 @@ namespace connectivity class WpADOUser : public WpOLEBase<_ADOUser> { public: - WpADOUser(_ADOUser* pInt=nullptr) : WpOLEBase<_ADOUser>(pInt){} + WpADOUser() = default; WpADOUser(const WpADOUser& rhs) : WpOLEBase<_ADOUser>(rhs) {} WpADOUser& operator=(const WpADOUser& rhs) @@ -120,8 +122,8 @@ namespace connectivity void Create(); OUString get_Name() const; - void put_Name(const OUString& _rName); - bool ChangePassword(const OUString& _rPwd,const OUString& _rNewPwd); + void put_Name(std::u16string_view _rName); + bool ChangePassword(std::u16string_view _rPwd,std::u16string_view _rNewPwd); WpADOGroups get_Groups(); RightsEnum GetPermissions( /* [in] */ const OLEVariant& Name, @@ -132,7 +134,6 @@ namespace connectivity /* [in] */ ActionEnum Action, /* [in] */ RightsEnum Rights); }; - } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/WrapCatalog.hxx b/connectivity/source/inc/ado/WrapCatalog.hxx index 3587d5bcd34a..0bcff441c23a 100644 --- a/connectivity/source/inc/ado/WrapCatalog.hxx +++ b/connectivity/source/inc/ado/WrapCatalog.hxx @@ -16,15 +16,16 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_WRAPCATALOG_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_WRAPCATALOG_HXX +#pragma once + +#include <sal/config.h> + +#include <string_view> #include <ado/WrapTypeDefs.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { class WpADOCatalog : public WpOLEBase<_ADOCatalog> { public: @@ -34,7 +35,7 @@ namespace connectivity WpADOCatalog& operator=(const WpADOCatalog& rhs) {WpOLEBase<_ADOCatalog>::operator=(rhs); return *this;} - OUString GetObjectOwner(const OUString& _rName, ObjectTypeEnum _eNum); + OUString GetObjectOwner(std::u16string_view _rName, ObjectTypeEnum _eNum); void putref_ActiveConnection(IDispatch* pCon); WpADOTables get_Tables(); @@ -44,9 +45,6 @@ namespace connectivity ADOProcedures* get_Procedures(); void Create(); }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_WRAPCATALOG_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/WrapColumn.hxx b/connectivity/source/inc/ado/WrapColumn.hxx index 7f3dd3d86903..f1b73585fba9 100644 --- a/connectivity/source/inc/ado/WrapColumn.hxx +++ b/connectivity/source/inc/ado/WrapColumn.hxx @@ -16,21 +16,22 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_WRAPCOLUMN_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_WRAPCOLUMN_HXX +#pragma once + +#include <sal/config.h> + +#include <string_view> #include <ado/Aolewrap.hxx> #include <adoint.h> -namespace connectivity +namespace connectivity::ado { - namespace ado - { class WpADOColumn : public WpOLEBase<_ADOColumn> { public: - WpADOColumn(_ADOColumn* pInt=nullptr) : WpOLEBase<_ADOColumn>(pInt){} + WpADOColumn() = default; WpADOColumn(const WpADOColumn& rhs) : WpOLEBase<_ADOColumn>(rhs) {} void Create(); @@ -40,8 +41,8 @@ namespace connectivity OUString get_Name() const; OUString get_RelatedColumn() const; - void put_Name(const OUString& _rName); - void put_RelatedColumn(const OUString& _rName); + void put_Name(std::u16string_view _rName); + void put_RelatedColumn(std::u16string_view _rName); DataTypeEnum get_Type() const; void put_Type(const DataTypeEnum& _eNum) ; sal_Int32 get_Precision() const; @@ -56,9 +57,6 @@ namespace connectivity WpADOProperties get_Properties() const; void put_ParentCatalog(/* [in] */ _ADOCatalog __RPC_FAR *ppvObject); }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_WRAPCOLUMN_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/WrapIndex.hxx b/connectivity/source/inc/ado/WrapIndex.hxx index e60a1249afc2..4444bb340ae5 100644 --- a/connectivity/source/inc/ado/WrapIndex.hxx +++ b/connectivity/source/inc/ado/WrapIndex.hxx @@ -16,19 +16,20 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_WRAPINDEX_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_WRAPINDEX_HXX +#pragma once + +#include <sal/config.h> + +#include <string_view> #include <ado/WrapTypeDefs.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { class WpADOIndex : public WpOLEBase<_ADOIndex> { public: - WpADOIndex(_ADOIndex* pInt=nullptr) : WpOLEBase<_ADOIndex>(pInt){} + WpADOIndex() = default; WpADOIndex(const WpADOIndex& rhs) : WpOLEBase<_ADOIndex>(rhs) {} WpADOIndex& operator=(const WpADOIndex& rhs) @@ -37,7 +38,7 @@ namespace connectivity void Create(); OUString get_Name() const; - void put_Name(const OUString& _rName); + void put_Name(std::u16string_view _rName); bool get_Clustered() const; void put_Clustered(bool _b); bool get_Unique() const; @@ -46,9 +47,6 @@ namespace connectivity void put_PrimaryKey(bool _b); WpADOColumns get_Columns() const; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_WRAPINDEX_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/WrapKey.hxx b/connectivity/source/inc/ado/WrapKey.hxx index e5e10a56c835..1f984445b8ae 100644 --- a/connectivity/source/inc/ado/WrapKey.hxx +++ b/connectivity/source/inc/ado/WrapKey.hxx @@ -16,19 +16,20 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_WRAPKEY_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_WRAPKEY_HXX +#pragma once + +#include <sal/config.h> + +#include <string_view> #include <ado/WrapTypeDefs.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { class WpADOKey : public WpOLEBase<ADOKey> { public: - WpADOKey(ADOKey* pInt=nullptr) : WpOLEBase<ADOKey>(pInt){} + WpADOKey() = default; WpADOKey(const WpADOKey& rhs) : WpOLEBase<ADOKey>(rhs) {} WpADOKey& operator=(const WpADOKey& rhs) @@ -37,20 +38,17 @@ namespace connectivity void Create(); OUString get_Name() const; - void put_Name(const OUString& _rName); + void put_Name(std::u16string_view _rName); KeyTypeEnum get_Type() const; void put_Type(const KeyTypeEnum& _eNum) ; OUString get_RelatedTable() const; - void put_RelatedTable(const OUString& _rName); + void put_RelatedTable(std::u16string_view _rName); RuleEnum get_DeleteRule() const; void put_DeleteRule(const RuleEnum& _eNum) ; RuleEnum get_UpdateRule() const; void put_UpdateRule(const RuleEnum& _eNum) ; WpADOColumns get_Columns() const; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_WRAPKEY_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/WrapTable.hxx b/connectivity/source/inc/ado/WrapTable.hxx index b7a1be72eb30..dc06dbc03a8e 100644 --- a/connectivity/source/inc/ado/WrapTable.hxx +++ b/connectivity/source/inc/ado/WrapTable.hxx @@ -16,21 +16,22 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_WRAPTABLE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_WRAPTABLE_HXX +#pragma once + +#include <sal/config.h> + +#include <string_view> #include <ado/WrapTypeDefs.hxx> -namespace connectivity +namespace connectivity::ado { - namespace ado - { class WpADOCatalog; class WpADOTable : public WpOLEBase<_ADOTable> { public: - WpADOTable(_ADOTable* pInt=nullptr) : WpOLEBase<_ADOTable>(pInt){} + WpADOTable() = default; WpADOTable(const WpADOTable& rhs) : WpOLEBase<_ADOTable>(rhs) {} WpADOTable& operator=(const WpADOTable& rhs) @@ -39,7 +40,7 @@ namespace connectivity void Create(); OUString get_Name() const; - void put_Name(const OUString& _rName); + void put_Name(std::u16string_view _rName); OUString get_Type() const; WpADOColumns get_Columns() const; WpADOIndexes get_Indexes() const; @@ -50,10 +51,7 @@ namespace connectivity }; - typedef WpOLEAppendCollection<ADOTables, _ADOTable, WpADOTable> WpADOTables; - } + typedef WpOLEAppendCollection<ADOTables, WpADOTable> WpADOTables; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_WRAPTABLE_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/WrapTypeDefs.hxx b/connectivity/source/inc/ado/WrapTypeDefs.hxx index 1a76dc5f898c..91bea8453480 100644 --- a/connectivity/source/inc/ado/WrapTypeDefs.hxx +++ b/connectivity/source/inc/ado/WrapTypeDefs.hxx @@ -16,14 +16,11 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_WRAPTYPEDEFS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_WRAPTYPEDEFS_HXX +#pragma once -namespace connectivity +namespace connectivity::ado { - namespace ado - { class WpADOTable; class WpADOKey; class WpADOIndex; @@ -32,16 +29,13 @@ namespace connectivity class WpADOView; class WpADOUser; - typedef WpOLEAppendCollection<ADOTables, _ADOTable, WpADOTable> WpADOTables; - typedef WpOLEAppendCollection<ADOKeys, ADOKey, WpADOKey> WpADOKeys; - typedef WpOLEAppendCollection<ADOIndexes, _ADOIndex, WpADOIndex> WpADOIndexes; - typedef WpOLEAppendCollection<ADOColumns, _ADOColumn, WpADOColumn> WpADOColumns; - typedef WpOLEAppendCollection<ADOGroups, ADOGroup, WpADOGroup> WpADOGroups; - typedef WpOLEAppendCollection<ADOViews, ADOView, WpADOView> WpADOViews; - typedef WpOLEAppendCollection<ADOUsers, _ADOUser, WpADOUser> WpADOUsers; - } + typedef WpOLEAppendCollection<ADOTables, WpADOTable> WpADOTables; + typedef WpOLEAppendCollection<ADOKeys, WpADOKey> WpADOKeys; + typedef WpOLEAppendCollection<ADOIndexes, WpADOIndex> WpADOIndexes; + typedef WpOLEAppendCollection<ADOColumns, WpADOColumn> WpADOColumns; + typedef WpOLEAppendCollection<ADOGroups, WpADOGroup> WpADOGroups; + typedef WpOLEAppendCollection<ADOViews, WpADOView> WpADOViews; + typedef WpOLEAppendCollection<ADOUsers, WpADOUser> WpADOUsers; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_WRAPTYPEDEFS_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/ado/adoimp.hxx b/connectivity/source/inc/ado/adoimp.hxx index 8393ca731aa3..60c6fd313d77 100644 --- a/connectivity/source/inc/ado/adoimp.hxx +++ b/connectivity/source/inc/ado/adoimp.hxx @@ -16,26 +16,25 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ADOIMP_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ADOIMP_HXX +#pragma once #include <com/sun/star/sdbc/SQLException.hpp> #include <adoctint.h> struct ADOConnection; -namespace connectivity + +namespace sal::systools { class BStr; }; + +namespace connectivity::ado { - namespace ado - { class WpADOField; - class OLEString; class ADOS { public: // Also here: Free BSTR with SysFreeString()! - static OLEString& GetKeyStr(); + static sal::systools::BStr& GetKeyStr(); static const CLSID CLSID_ADOCATALOG_25; static const IID IID_ADOCATALOG_25; @@ -88,19 +87,17 @@ namespace connectivity }; - } } + #define ADO_PROP(ItemName) \ WpADOProperty aProp(aProps.GetItem(ItemName)); \ OLEVariant aVar; \ if(aProp.IsValid()) \ aVar = aProp.GetValue(); \ else \ - ADOS::ThrowException(*m_pADOConnection,*this); - + ADOS::ThrowException(m_rADOConnection,*this); -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ADO_ADOIMP_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/calc/CCatalog.hxx b/connectivity/source/inc/calc/CCatalog.hxx index 724b5fb129a0..466e96ece829 100644 --- a/connectivity/source/inc/calc/CCatalog.hxx +++ b/connectivity/source/inc/calc/CCatalog.hxx @@ -21,10 +21,8 @@ #include <file/FCatalog.hxx> -namespace connectivity +namespace connectivity::calc { - namespace calc - { class OCalcConnection; class OCalcCatalog : public file::OFileCatalog { @@ -34,7 +32,7 @@ namespace connectivity public: OCalcCatalog(OCalcConnection* _pCon); }; - } + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/calc/CConnection.hxx b/connectivity/source/inc/calc/CConnection.hxx index b0eeb2d4acea..6eabeccef5ff 100644 --- a/connectivity/source/inc/calc/CConnection.hxx +++ b/connectivity/source/inc/calc/CConnection.hxx @@ -33,9 +33,7 @@ namespace com::sun::star { namespace utl { class CloseVeto; } -namespace connectivity -{ - namespace calc +namespace connectivity::calc { class ODriver; class OCalcConnection : public file::OConnection @@ -145,7 +143,7 @@ namespace connectivity const css::uno::Reference< css::sheet::XSpreadsheetDocument>& getDoc() const { return m_xDoc; } }; }; - } + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/calc/CDatabaseMetaData.hxx b/connectivity/source/inc/calc/CDatabaseMetaData.hxx index a46d09c14b1c..61f9f6aa7ea2 100644 --- a/connectivity/source/inc/calc/CDatabaseMetaData.hxx +++ b/connectivity/source/inc/calc/CDatabaseMetaData.hxx @@ -21,9 +21,7 @@ #include <component/CDatabaseMetaData.hxx> -namespace connectivity -{ - namespace calc +namespace connectivity::calc { //************ Class: java.sql.DatabaseMetaDataDate @@ -38,7 +36,7 @@ namespace connectivity public: OCalcDatabaseMetaData(file::OConnection* _pCon); }; - } + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/calc/CDriver.hxx b/connectivity/source/inc/calc/CDriver.hxx index 02d9dea55033..99200d23ee54 100644 --- a/connectivity/source/inc/calc/CDriver.hxx +++ b/connectivity/source/inc/calc/CDriver.hxx @@ -23,9 +23,7 @@ #include <com/sun/star/lang/XMultiServiceFactory.hpp> -namespace connectivity -{ - namespace calc +namespace connectivity::calc { /// @throws css::uno::Exception css::uno::Reference< css::uno::XInterface > @@ -47,7 +45,7 @@ namespace connectivity virtual sal_Bool SAL_CALL acceptsURL( const OUString& url ) override; virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; }; - } + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/calc/CTable.hxx b/connectivity/source/inc/calc/CTable.hxx index b9835c222fc4..b4751fd876d7 100644 --- a/connectivity/source/inc/calc/CTable.hxx +++ b/connectivity/source/inc/calc/CTable.hxx @@ -31,9 +31,7 @@ namespace com::sun::star::util { } -namespace connectivity -{ - namespace calc +namespace connectivity::calc { typedef component::OComponentTable OCalcTable_BASE; class OCalcConnection; @@ -66,13 +64,9 @@ namespace connectivity virtual void SAL_CALL disposing() override; - // css::lang::XUnoTunnel - virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; - static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); - void construct() override; }; - } + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/calc/CTables.hxx b/connectivity/source/inc/calc/CTables.hxx index 65c7135f0981..0b88592a2e6a 100644 --- a/connectivity/source/inc/calc/CTables.hxx +++ b/connectivity/source/inc/calc/CTables.hxx @@ -21,9 +21,7 @@ #include <file/FTables.hxx> -namespace connectivity -{ - namespace calc +namespace connectivity::calc { typedef file::OTables OCalcTables_BASE; @@ -36,7 +34,7 @@ namespace connectivity const ::std::vector< OUString> &_rVector) : OCalcTables_BASE(_rMetaData,_rParent,_rMutex,_rVector) {} }; - } + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/component/CColumns.hxx b/connectivity/source/inc/component/CColumns.hxx index 2a37db2b56ee..a63cae4bde6e 100644 --- a/connectivity/source/inc/component/CColumns.hxx +++ b/connectivity/source/inc/component/CColumns.hxx @@ -17,14 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CCOLUMNS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CCOLUMNS_HXX +#pragma once #include <file/FColumns.hxx> -namespace connectivity -{ - namespace component +namespace connectivity::component { /// Columns implementation for Writer tables and Calc sheets. class OComponentColumns : public file::OColumns @@ -39,9 +36,7 @@ namespace connectivity {} }; - } -} -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CCOLUMNS_HXX +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/component/CDatabaseMetaData.hxx b/connectivity/source/inc/component/CDatabaseMetaData.hxx index 6006455a3029..c4721ecadb9f 100644 --- a/connectivity/source/inc/component/CDatabaseMetaData.hxx +++ b/connectivity/source/inc/component/CDatabaseMetaData.hxx @@ -17,14 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CDATABASEMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CDATABASEMETADATA_HXX +#pragma once #include <file/FDatabaseMetaData.hxx> -namespace connectivity -{ - namespace component +namespace connectivity::component { //************ Class: java.sql.DatabaseMetaDataDate @@ -44,9 +41,7 @@ namespace connectivity public: OComponentDatabaseMetaData(file::OConnection* _pCon); }; - } -} -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CDATABASEMETADATA_HXX +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/component/CPreparedStatement.hxx b/connectivity/source/inc/component/CPreparedStatement.hxx index 30597141a023..d39a3edad136 100644 --- a/connectivity/source/inc/component/CPreparedStatement.hxx +++ b/connectivity/source/inc/component/CPreparedStatement.hxx @@ -17,28 +17,23 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CPREPAREDSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CPREPAREDSTATEMENT_HXX +#pragma once #include <file/FPreparedStatement.hxx> -namespace connectivity -{ - namespace component +namespace connectivity::component { class OConnection; /// Prepared statement implementation for Writer tables and Calc sheets. class OOO_DLLPUBLIC_FILE OComponentPreparedStatement : public file::OPreparedStatement { protected: - virtual file::OResultSet* createResultSet() override; + virtual rtl::Reference<file::OResultSet> createResultSet() override; public: OComponentPreparedStatement( file::OConnection* _pConnection) : file::OPreparedStatement( _pConnection){} DECLARE_SERVICE_INFO(); }; - } -} -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CPREPAREDSTATEMENT_HXX +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/component/CResultSet.hxx b/connectivity/source/inc/component/CResultSet.hxx index e3abc8e78beb..4874f22151b6 100644 --- a/connectivity/source/inc/component/CResultSet.hxx +++ b/connectivity/source/inc/component/CResultSet.hxx @@ -16,17 +16,14 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CRESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CRESULTSET_HXX +#pragma once #include <file/FResultSet.hxx> #include <com/sun/star/sdbcx/XRowLocate.hpp> #include <com/sun/star/sdbcx/XDeleteRows.hpp> #include <cppuhelper/implbase2.hxx> -namespace connectivity -{ - namespace component +namespace connectivity::component { class OComponentResultSet; // these typedef's are only necessary for the compiler @@ -56,8 +53,8 @@ namespace connectivity private: // XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; // XPropertySet @@ -76,9 +73,7 @@ namespace connectivity virtual bool isRowDeleted() const override { return false; } }; - } -} -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CRESULTSET_HXX +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/component/CStatement.hxx b/connectivity/source/inc/component/CStatement.hxx index d7fc749810e5..10346e7c8559 100644 --- a/connectivity/source/inc/component/CStatement.hxx +++ b/connectivity/source/inc/component/CStatement.hxx @@ -17,28 +17,23 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CSTATEMENT_HXX +#pragma once #include <file/FStatement.hxx> -namespace connectivity -{ - namespace component +namespace connectivity::component { class OConnection; /// Statement implementation for Writer tables and Calc sheets. class OOO_DLLPUBLIC_FILE OComponentStatement : public file::OStatement { protected: - virtual file::OResultSet* createResultSet() override; + virtual rtl::Reference<file::OResultSet> createResultSet() override; public: OComponentStatement( file::OConnection* _pConnection) : file::OStatement( _pConnection){} DECLARE_SERVICE_INFO(); }; - } -} -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CSTATEMENT_HXX +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/component/CTable.hxx b/connectivity/source/inc/component/CTable.hxx index 5068f88d56ee..3ace6f922ae0 100644 --- a/connectivity/source/inc/component/CTable.hxx +++ b/connectivity/source/inc/component/CTable.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CTABLE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CTABLE_HXX +#pragma once #include <file/FTable.hxx> @@ -31,9 +30,7 @@ namespace com::sun::star::util { } -namespace connectivity -{ - namespace component +namespace connectivity::component { typedef file::OFileTable OComponentTable_BASE; @@ -63,9 +60,7 @@ namespace connectivity //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; }; - } -} -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CTABLE_HXX +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DCatalog.hxx b/connectivity/source/inc/dbase/DCatalog.hxx index 3ccfed6f661c..f8954d012211 100644 --- a/connectivity/source/inc/dbase/DCatalog.hxx +++ b/connectivity/source/inc/dbase/DCatalog.hxx @@ -17,14 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DCATALOG_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DCATALOG_HXX +#pragma once #include <file/FCatalog.hxx> -namespace connectivity -{ - namespace dbase +namespace connectivity::dbase { class ODbaseConnection; class ODbaseCatalog : public file::OFileCatalog @@ -35,8 +32,7 @@ namespace connectivity public: ODbaseCatalog(ODbaseConnection* _pCon); }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DCATALOG_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DColumns.hxx b/connectivity/source/inc/dbase/DColumns.hxx index c282b43e8480..dbbbbec90acc 100644 --- a/connectivity/source/inc/dbase/DColumns.hxx +++ b/connectivity/source/inc/dbase/DColumns.hxx @@ -17,14 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DCOLUMNS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DCOLUMNS_HXX +#pragma once #include <file/FColumns.hxx> -namespace connectivity -{ - namespace dbase +namespace connectivity::dbase { class ODbaseColumns : public file::OColumns { @@ -41,8 +38,6 @@ namespace connectivity ) : file::OColumns(_pTable,_rMutex,_rVector) {} }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DCOLUMNS_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DConnection.hxx b/connectivity/source/inc/dbase/DConnection.hxx index f81f7b494773..864e9a22c870 100644 --- a/connectivity/source/inc/dbase/DConnection.hxx +++ b/connectivity/source/inc/dbase/DConnection.hxx @@ -17,14 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DCONNECTION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DCONNECTION_HXX +#pragma once #include <file/FConnection.hxx> -namespace connectivity -{ - namespace dbase +namespace connectivity::dbase { class ODriver; class ODbaseConnection : public file::OConnection @@ -43,8 +40,7 @@ namespace connectivity virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const OUString& sql ) override; virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall( const OUString& sql ) override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DCONNECTION_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DDatabaseMetaData.hxx b/connectivity/source/inc/dbase/DDatabaseMetaData.hxx index 3424f9c8b5e4..fed3fcc70ea9 100644 --- a/connectivity/source/inc/dbase/DDatabaseMetaData.hxx +++ b/connectivity/source/inc/dbase/DDatabaseMetaData.hxx @@ -17,14 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DDATABASEMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DDATABASEMETADATA_HXX +#pragma once #include <file/FDatabaseMetaData.hxx> -namespace connectivity -{ - namespace dbase +namespace connectivity::dbase { //************ Class: java.sql.DatabaseMetaDataDate @@ -54,8 +51,7 @@ namespace connectivity public: ODbaseDatabaseMetaData(file::OConnection* _pCon); }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DDATABASEMETADATA_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DDriver.hxx b/connectivity/source/inc/dbase/DDriver.hxx index 63de640dfe22..310f9b1dc8d5 100644 --- a/connectivity/source/inc/dbase/DDriver.hxx +++ b/connectivity/source/inc/dbase/DDriver.hxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DDRIVER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DDRIVER_HXX +#pragma once #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <connectivity/CommonTools.hxx> #include <file/FDriver.hxx> -namespace connectivity -{ - namespace dbase +namespace connectivity::dbase { /// @throws css::uno::Exception css::uno::Reference< css::uno::XInterface > ODriver_CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory); @@ -43,9 +40,7 @@ namespace connectivity virtual sal_Bool SAL_CALL acceptsURL( const OUString& url ) override; virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DDRIVER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DIndex.hxx b/connectivity/source/inc/dbase/DIndex.hxx index 018c4b915ae8..3cc7da9ad1d3 100644 --- a/connectivity/source/inc/dbase/DIndex.hxx +++ b/connectivity/source/inc/dbase/DIndex.hxx @@ -17,18 +17,15 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEX_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEX_HXX +#pragma once #include <sdbcx/VIndex.hxx> #include <dbase/DTable.hxx> #include <dbase/dindexnode.hxx> -#define dBASE_III_GROUP "dBase III" +inline constexpr OString dBASE_III_GROUP = "dBase III"_ostr; -namespace connectivity -{ - namespace dbase +namespace connectivity::dbase { class OIndexIterator; class ONDXKey; @@ -37,7 +34,7 @@ namespace connectivity class ODbaseIndex : public ODbaseIndex_BASE { - friend SvStream& WriteODbaseIndex(SvStream &rStream, ODbaseIndex&); + friend SvStream& WriteODbaseIndex(SvStream &rStream, const ODbaseIndex&); friend SvStream& operator >> (SvStream &rStream, ODbaseIndex&); friend class ONDXNode; @@ -84,7 +81,7 @@ namespace connectivity OUString getCompletePath() const; void closeImpl(); // Closes and kills the index file and throws an error - void impl_killFileAndthrowError_throw(const char* pErrorId, const OUString& _sFile); + void impl_killFileAndthrowError_throw(TranslateId pErrorId, const OUString& _sFile); protected: virtual ~ODbaseIndex() override; public: @@ -94,10 +91,6 @@ namespace connectivity void openIndexFile(); virtual void refreshColumns() override; - // css::lang::XUnoTunnel - virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; - static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); - const ODbaseTable* getTable() const { return m_pTable; } const NDXHeader& getHeader() const { return m_aHeader; } std::unique_ptr<OIndexIterator> createIterator(); @@ -132,14 +125,11 @@ namespace connectivity bool ConvertToKey(ONDXKey* rKey, sal_uInt32 nRec, const ORowSetValue& rValue); }; - SvStream& WriteODbaseIndex(SvStream &rStream, ODbaseIndex&); + SvStream& WriteODbaseIndex(SvStream &rStream, const ODbaseIndex&); SvStream& operator >> (SvStream &rStream, ODbaseIndex&); void ReadHeader(SvStream & rStream, ODbaseIndex::NDXHeader & rHeader); - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEX_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DIndexColumns.hxx b/connectivity/source/inc/dbase/DIndexColumns.hxx index 07aa3d551234..8f7a895b95ad 100644 --- a/connectivity/source/inc/dbase/DIndexColumns.hxx +++ b/connectivity/source/inc/dbase/DIndexColumns.hxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXCOLUMNS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXCOLUMNS_HXX +#pragma once #include <connectivity/sdbcx/VCollection.hxx> #include <dbase/DIndex.hxx> #include <dbase/DTable.hxx> -namespace connectivity -{ - namespace dbase +namespace connectivity::dbase { class ODbaseIndexColumns : public sdbcx::OCollection { @@ -45,9 +42,8 @@ namespace connectivity {} }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXCOLUMNS_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DIndexIter.hxx b/connectivity/source/inc/dbase/DIndexIter.hxx index 1401a0eccb3c..2de327be1138 100644 --- a/connectivity/source/inc/dbase/DIndexIter.hxx +++ b/connectivity/source/inc/dbase/DIndexIter.hxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXITER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXITER_HXX +#pragma once #include <file/fcode.hxx> #include <dbase/DIndex.hxx> #include <dbase/dindexnode.hxx> -namespace connectivity -{ - namespace dbase +namespace connectivity::dbase { // IndexIterator @@ -64,8 +61,7 @@ namespace connectivity sal_uInt32 Next(); }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXITER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DIndexes.hxx b/connectivity/source/inc/dbase/DIndexes.hxx index cccc9347ff99..a5b1c27e67f2 100644 --- a/connectivity/source/inc/dbase/DIndexes.hxx +++ b/connectivity/source/inc/dbase/DIndexes.hxx @@ -17,15 +17,12 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXES_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXES_HXX +#pragma once #include <connectivity/sdbcx/VCollection.hxx> #include <dbase/DTable.hxx> -namespace connectivity -{ - namespace dbase +namespace connectivity::dbase { class ODbaseTable; @@ -47,8 +44,7 @@ namespace connectivity {} }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXES_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DPreparedStatement.hxx b/connectivity/source/inc/dbase/DPreparedStatement.hxx index 22df7be8e01f..a2a792f62342 100644 --- a/connectivity/source/inc/dbase/DPreparedStatement.hxx +++ b/connectivity/source/inc/dbase/DPreparedStatement.hxx @@ -17,27 +17,22 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DPREPAREDSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DPREPAREDSTATEMENT_HXX +#pragma once #include <file/FPreparedStatement.hxx> -namespace connectivity -{ - namespace dbase +namespace connectivity::dbase { class OConnection; class ODbasePreparedStatement : public file::OPreparedStatement { protected: - virtual file::OResultSet* createResultSet() override; + virtual rtl::Reference<file::OResultSet> createResultSet() override; public: ODbasePreparedStatement( file::OConnection* _pConnection) : file::OPreparedStatement( _pConnection){} DECLARE_SERVICE_INFO(); }; - } -} -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DPREPAREDSTATEMENT_HXX +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DResultSet.hxx b/connectivity/source/inc/dbase/DResultSet.hxx index 31a0f6722cb1..106a63cbb842 100644 --- a/connectivity/source/inc/dbase/DResultSet.hxx +++ b/connectivity/source/inc/dbase/DResultSet.hxx @@ -16,17 +16,14 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DRESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DRESULTSET_HXX +#pragma once #include <file/FResultSet.hxx> #include <com/sun/star/sdbcx/XRowLocate.hpp> #include <com/sun/star/sdbcx/XDeleteRows.hpp> #include <cppuhelper/implbase2.hxx> -namespace connectivity -{ - namespace dbase +namespace connectivity::dbase { class ODbaseResultSet; // these typedef's are only necessary for the compiler @@ -54,8 +51,8 @@ namespace connectivity // XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; // XPropertySet @@ -75,8 +72,7 @@ namespace connectivity sal_Int32 getCurrentFilePos() const; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DRESULTSET_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DStatement.hxx b/connectivity/source/inc/dbase/DStatement.hxx index 9c02e2abe6dc..cb4b1d8e4a03 100644 --- a/connectivity/source/inc/dbase/DStatement.hxx +++ b/connectivity/source/inc/dbase/DStatement.hxx @@ -17,27 +17,22 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DSTATEMENT_HXX +#pragma once #include <file/FStatement.hxx> -namespace connectivity -{ - namespace dbase +namespace connectivity::dbase { class OConnection; class ODbaseStatement : public file::OStatement { protected: - virtual file::OResultSet* createResultSet() override; + virtual rtl::Reference<file::OResultSet> createResultSet() override; public: ODbaseStatement( file::OConnection* _pConnection) : file::OStatement( _pConnection){} DECLARE_SERVICE_INFO(); }; - } -} -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DSTATEMENT_HXX +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DTable.hxx b/connectivity/source/inc/dbase/DTable.hxx index 5b98439875dc..bb0b6baa5fa2 100644 --- a/connectivity/source/inc/dbase/DTable.hxx +++ b/connectivity/source/inc/dbase/DTable.hxx @@ -17,17 +17,14 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DTABLE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DTABLE_HXX +#pragma once #include <file/FTable.hxx> #include <connectivity/CommonTools.hxx> #include <tools/urlobj.hxx> -namespace connectivity -{ - namespace dbase +namespace connectivity::dbase { typedef file::OFileTable ODbaseTable_BASE; class ODbaseConnection; @@ -118,7 +115,7 @@ namespace connectivity void copyData(ODbaseTable* _pNewTable,sal_Int32 _nPos); bool CreateFile(const INetURLObject& aFile, bool& bCreateMemo); bool CreateMemoFile(const INetURLObject& aFile); - bool HasMemoFields() const { return m_aHeader.type > dBaseIV;} + bool HasMemoFields() const; void ReadMemoHeader(); bool ReadMemo(std::size_t nBlockNo, ORowSetValue& aVariable); @@ -133,7 +130,7 @@ namespace connectivity /// @throws css::container::ElementExistException /// @throws css::uno::RuntimeException void renameImpl( const OUString& newName ); - void throwInvalidColumnType(const char* pErrorId, const OUString& _sColumnName); + void throwInvalidColumnType(TranslateId pErrorId, const OUString& _sColumnName); protected: virtual void FileClose() override; @@ -164,9 +161,6 @@ namespace connectivity virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; virtual void SAL_CALL disposing() override; - // css::lang::XUnoTunnel - virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; - static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); // XAlterTable virtual void SAL_CALL alterColumnByName( const OUString& colName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; virtual void SAL_CALL alterColumnByIndex( sal_Int32 index, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; @@ -184,15 +178,14 @@ namespace connectivity virtual void addColumn(const css::uno::Reference< css::beans::XPropertySet>& descriptor) override; virtual void dropColumn(sal_Int32 _nPos) override; - static OUString getEntry(file::OConnection const * _pConnection,const OUString& _sURL ); - static bool Drop_Static(const OUString& _sUrl, bool _bHasMemoFields, sdbcx::OCollection* _pIndexes ); + static OUString getEntry(file::OConnection const * _pConnection, std::u16string_view _sURL ); + static bool Drop_Static(std::u16string_view _sUrl, bool _bHasMemoFields, sdbcx::OCollection* _pIndexes ); virtual void refreshHeader() override; virtual css::uno::Reference< css::sdbc::XDatabaseMetaData> getMetaData() const override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DTABLE_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/DTables.hxx b/connectivity/source/inc/dbase/DTables.hxx index fa1957236c21..c85a1ab3cd07 100644 --- a/connectivity/source/inc/dbase/DTables.hxx +++ b/connectivity/source/inc/dbase/DTables.hxx @@ -17,14 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DTABLES_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DTABLES_HXX +#pragma once #include <file/FTables.hxx> -namespace connectivity -{ - namespace dbase +namespace connectivity::dbase { typedef file::OTables ODbaseTables_BASE; @@ -43,8 +40,7 @@ namespace connectivity virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DTABLES_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/dbase/dindexnode.hxx b/connectivity/source/inc/dbase/dindexnode.hxx index 70c7b832a927..c1db23f76b60 100644 --- a/connectivity/source/inc/dbase/dindexnode.hxx +++ b/connectivity/source/inc/dbase/dindexnode.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXNODE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXNODE_HXX +#pragma once #include <file/fcode.hxx> #include <connectivity/FValue.hxx> @@ -28,9 +27,7 @@ class SvStream; -namespace connectivity -{ - namespace dbase +namespace connectivity::dbase { class ONDXNode; @@ -47,7 +44,7 @@ namespace connectivity public: ONDXKey(); - ONDXKey(const ORowSetValue& rVal, sal_Int32 eType, sal_uInt32 nRec); + ONDXKey(ORowSetValue aVal, sal_Int32 eType, sal_uInt32 nRec); ONDXKey(const OUString& aStr, sal_uInt32 nRec); ONDXKey(double aVal, sal_uInt32 nRec); @@ -166,8 +163,8 @@ namespace connectivity const ODbaseIndex& GetIndex() const {return rIndex;} // Setting the child, via reference to retain the PagePos - void SetChild(ONDXPagePtr aCh); - void SetParent(ONDXPagePtr aPa); + void SetChild(const ONDXPagePtr& rCh); + void SetParent(const ONDXPagePtr& rPa); sal_uInt16 Search(const ONDXKey& rSearch); sal_uInt16 Search(const ONDXPage* pPage); @@ -212,14 +209,14 @@ namespace connectivity inline bool ONDXPage::HasParent() const {return aParent.Is();} inline const ONDXPagePtr& ONDXPage::GetParent() const {return aParent;} - inline void ONDXPage::SetParent(ONDXPagePtr aPa = ONDXPagePtr()) + inline void ONDXPage::SetParent(const ONDXPagePtr& rPa = ONDXPagePtr()) { - aParent = aPa; + aParent = rPa; } - inline void ONDXPage::SetChild(ONDXPagePtr aCh = ONDXPagePtr()) + inline void ONDXPage::SetChild(const ONDXPagePtr& rCh = ONDXPagePtr()) { - aChild = aCh; + aChild = rCh; if (aChild.Is()) aChild->SetParent(this); } @@ -249,7 +246,7 @@ namespace connectivity ONDXKey& GetKey() { return aKey;} // Setting the child, via reference to retain the PagePos - void SetChild(ONDXPagePtr aCh = ONDXPagePtr(), ONDXPage* = nullptr); + void SetChild(const ONDXPagePtr& rCh = ONDXPagePtr(), ONDXPage* = nullptr); void Write(SvStream &rStream, const ONDXPage& rPage) const; void Read(SvStream &rStream, ODbaseIndex const &); @@ -296,19 +293,15 @@ namespace connectivity return !operator > (rKey); } - inline void ONDXNode::SetChild(ONDXPagePtr aCh, ONDXPage* pParent) + inline void ONDXNode::SetChild(const ONDXPagePtr& rCh, ONDXPage* pParent) { - aChild = aCh; + aChild = rCh; if (aChild.Is()) aChild->SetParent(pParent); } - } - } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEXNODE_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FCatalog.hxx b/connectivity/source/inc/file/FCatalog.hxx index 7bdbb7edb649..2bcf82df2a57 100644 --- a/connectivity/source/inc/file/FCatalog.hxx +++ b/connectivity/source/inc/file/FCatalog.hxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FCATALOG_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FCATALOG_HXX +#pragma once #include <sdbcx/VCatalog.hxx> #include <file/filedllapi.hxx> -namespace connectivity -{ - namespace file +namespace connectivity::file { class OConnection; class OOO_DLLPUBLIC_FILE SAL_NO_VTABLE OFileCatalog : @@ -57,8 +54,7 @@ namespace connectivity virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; virtual void SAL_CALL disposing() override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FCATALOG_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FColumns.hxx b/connectivity/source/inc/file/FColumns.hxx index 57fa6f65cb55..056934f88c65 100644 --- a/connectivity/source/inc/file/FColumns.hxx +++ b/connectivity/source/inc/file/FColumns.hxx @@ -17,19 +17,16 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FCOLUMNS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FCOLUMNS_HXX +#pragma once #include <connectivity/sdbcx/VCollection.hxx> #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> #include <file/FTable.hxx> #include <file/filedllapi.hxx> -namespace connectivity -{ - namespace file +namespace connectivity::file { - class OOO_DLLPUBLIC_FILE OColumns : public sdbcx::OCollection + class UNLESS_MERGELIBS_MORE(OOO_DLLPUBLIC_FILE) OColumns : public sdbcx::OCollection { protected: OFileTable* m_pTable; @@ -44,8 +41,7 @@ namespace connectivity ,m_pTable(_pTable) {} }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FCOLUMNS_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FConnection.hxx b/connectivity/source/inc/file/FConnection.hxx index 8511f277102f..e6412992ab77 100644 --- a/connectivity/source/inc/file/FConnection.hxx +++ b/connectivity/source/inc/file/FConnection.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FCONNECTION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FCONNECTION_HXX +#pragma once #include <com/sun/star/ucb/XContent.hpp> #include <com/sun/star/beans/PropertyValue.hpp> @@ -28,9 +27,7 @@ #include <TConnection.hxx> #include <file/filedllapi.hxx> -namespace connectivity -{ - namespace file +namespace connectivity::file { class ODatabaseMetaData; class OFileDriver; @@ -101,7 +98,7 @@ namespace connectivity virtual void SAL_CALL clearWarnings( ) override; //XUnoTunnel virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; - static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); + static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId(); // no interface methods css::uno::Reference< css::ucb::XDynamicResultSet > getDir() const; @@ -128,8 +125,7 @@ namespace connectivity void setCaseSensitiveExtension( bool _bIsCS, GrantAccess ) { m_bCaseSensitiveExtension = _bIsCS; } }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FCONNECTION_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FDatabaseMetaData.hxx b/connectivity/source/inc/file/FDatabaseMetaData.hxx index 6f726cf74305..5c766c31d1f4 100644 --- a/connectivity/source/inc/file/FDatabaseMetaData.hxx +++ b/connectivity/source/inc/file/FDatabaseMetaData.hxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FDATABASEMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FDATABASEMETADATA_HXX +#pragma once #include <TDatabaseMetaDataBase.hxx> #include <file/FConnection.hxx> #include <file/filedllapi.hxx> -namespace connectivity -{ - namespace file +namespace connectivity::file { //************ Class: ODatabaseMetaData @@ -183,8 +180,7 @@ namespace connectivity virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getUDTs( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& typeNamePattern, const css::uno::Sequence< sal_Int32 >& types ) override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FDATABASEMETADATA_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FDateFunctions.hxx b/connectivity/source/inc/file/FDateFunctions.hxx index e2fa6965d75e..e8eb12d0cf24 100644 --- a/connectivity/source/inc/file/FDateFunctions.hxx +++ b/connectivity/source/inc/file/FDateFunctions.hxx @@ -17,14 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FDATEFUNCTIONS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FDATEFUNCTIONS_HXX +#pragma once #include <file/fcode.hxx> -namespace connectivity -{ - namespace file +namespace connectivity::file { /** DAYOFWEEK(date) Returns the weekday index for date (1 = Sunday, 2 = Monday, ... 7 = Saturday). These index values correspond to the ODBC standard. @@ -225,9 +222,7 @@ namespace connectivity protected: virtual ORowSetValue operate(const std::vector<ORowSetValue>& lhs) const override; }; - } -} -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FDATEFUNCTIONS_HXX +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FDriver.hxx b/connectivity/source/inc/file/FDriver.hxx index 61037352071e..0351c59ca27a 100644 --- a/connectivity/source/inc/file/FDriver.hxx +++ b/connectivity/source/inc/file/FDriver.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FDRIVER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FDRIVER_HXX +#pragma once #include <com/sun/star/sdbc/XDriver.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> @@ -27,9 +26,7 @@ #include <connectivity/CommonTools.hxx> #include <file/filedllapi.hxx> -namespace connectivity -{ - namespace file +namespace connectivity::file { typedef ::cppu::WeakComponentImplHelper< css::sdbc::XDriver, css::lang::XServiceInfo, @@ -45,7 +42,7 @@ namespace connectivity // for this Driver css::uno::Reference< css::uno::XComponentContext > m_xContext; public: - OFileDriver(const css::uno::Reference< css::uno::XComponentContext >& _rxContext); + OFileDriver(css::uno::Reference< css::uno::XComponentContext > _xContext); // OComponentHelper virtual void SAL_CALL disposing() override; @@ -68,10 +65,8 @@ namespace connectivity const css::uno::Reference< css::uno::XComponentContext >& getComponentContext() const { return m_xContext; } }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FDRIVER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FNumericFunctions.hxx b/connectivity/source/inc/file/FNumericFunctions.hxx index 3f143c658268..765f2cde8223 100644 --- a/connectivity/source/inc/file/FNumericFunctions.hxx +++ b/connectivity/source/inc/file/FNumericFunctions.hxx @@ -17,14 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FNUMERICFUNCTIONS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FNUMERICFUNCTIONS_HXX +#pragma once #include <file/fcode.hxx> -namespace connectivity -{ - namespace file +namespace connectivity::file { /** ABS(X) Returns the absolute value of X: @@ -359,9 +356,7 @@ namespace connectivity protected: virtual ORowSetValue operate(const ORowSetValue& lhs) const override; }; - } -} -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FNUMERICFUNCTIONS_HXX +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FPreparedStatement.hxx b/connectivity/source/inc/file/FPreparedStatement.hxx index 31002f6f1306..f83d74a6d065 100644 --- a/connectivity/source/inc/file/FPreparedStatement.hxx +++ b/connectivity/source/inc/file/FPreparedStatement.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FPREPAREDSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FPREPAREDSTATEMENT_HXX +#pragma once #include <file/filedllapi.hxx> #include <file/FStatement.hxx> @@ -28,9 +27,7 @@ #include <com/sun/star/io/XInputStream.hpp> #include <file/FResultSet.hxx> -namespace connectivity -{ - namespace file +namespace connectivity::file { class OOO_DLLPUBLIC_FILE SAL_NO_VTABLE OPreparedStatement : public OStatement_BASE2, @@ -50,7 +47,7 @@ namespace connectivity ::rtl::Reference<connectivity::OSQLColumns> m_xParamColumns; // the parameter columns // factory method for resultset's - virtual OResultSet* createResultSet() override; + virtual rtl::Reference<OResultSet> createResultSet() override; ::rtl::Reference< OResultSet > makeResultSet(); void initResultSet(OResultSet*); @@ -78,8 +75,8 @@ namespace connectivity virtual void SAL_CALL disposing() override; //XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; @@ -117,9 +114,8 @@ namespace connectivity // XResultSetMetaDataSupplier virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FPREPAREDSTATEMENT_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FResultSet.hxx b/connectivity/source/inc/file/FResultSet.hxx index 6cb42da8e5e8..0870593e6388 100644 --- a/connectivity/source/inc/file/FResultSet.hxx +++ b/connectivity/source/inc/file/FResultSet.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FRESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FRESULTSET_HXX +#pragma once #include <com/sun/star/sdbc/XResultSet.hpp> #include <com/sun/star/sdbc/XRow.hpp> @@ -41,10 +40,9 @@ #include <TSortIndex.hxx> #include <TSkipDeletedSet.hxx> #include <com/sun/star/lang/XEventListener.hpp> +#include <o3tl/safeint.hxx> -namespace connectivity -{ - namespace file +namespace connectivity::file { typedef ::cppu::WeakComponentImplHelper< css::sdbc::XResultSet, css::sdbc::XRow, @@ -56,10 +54,9 @@ namespace connectivity css::sdbc::XCloseable, css::sdbc::XColumnLocate, css::lang::XServiceInfo, - css::lang::XEventListener, - css::lang::XUnoTunnel> OResultSet_BASE; + css::lang::XEventListener> OResultSet_BASE; - class OOO_DLLPUBLIC_FILE OResultSet : + class UNLESS_MERGELIBS_MORE(OOO_DLLPUBLIC_FILE) OResultSet : public cppu::BaseMutex, public ::connectivity::IResultSetHelper, public OResultSet_BASE, @@ -166,8 +163,8 @@ namespace connectivity virtual void SAL_CALL disposing() override final; // XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; // XPropertySet @@ -248,9 +245,6 @@ namespace connectivity virtual void SAL_CALL updateNumericObject( sal_Int32 columnIndex, const css::uno::Any& x, sal_Int32 scale ) override; // XColumnLocate virtual sal_Int32 SAL_CALL findColumn( const OUString& columnName ) override; - // css::lang::XUnoTunnel - virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; - static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); //XEventlistener virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override; @@ -268,11 +262,11 @@ namespace connectivity m_aSelectRow = _rRow; m_nColumnCount = m_aSelectRow->size(); } - void setColumnMapping(const std::vector<sal_Int32>& _aColumnMapping) { m_aColMapping = _aColumnMapping; } + void setColumnMapping(std::vector<sal_Int32>&& _aColumnMapping) { m_aColMapping = std::move(_aColumnMapping); } void setSqlAnalyzer(OSQLAnalyzer* _pSQLAnalyzer) { m_pSQLAnalyzer = _pSQLAnalyzer; } - void setOrderByColumns(const std::vector<sal_Int32>& _aColumnOrderBy) { m_aOrderbyColumnNumber = _aColumnOrderBy; } - void setOrderByAscending(const std::vector<TAscendingOrder>& _aOrderbyAsc) { m_aOrderbyAscending = _aOrderbyAsc; } + void setOrderByColumns(std::vector<sal_Int32>&& _aColumnOrderBy) { m_aOrderbyColumnNumber = std::move(_aColumnOrderBy); } + void setOrderByAscending(std::vector<TAscendingOrder>&& _aOrderbyAsc) { m_aOrderbyAscending = std::move(_aOrderbyAsc); } void setMetaData(const css::uno::Reference< css::sdbc::XResultSetMetaData>& _xMetaData) { m_xMetaData = _xMetaData;} static void setBoundedColumns(const OValueRefRow& _rRow, @@ -295,14 +289,13 @@ namespace connectivity OSL_ENSURE(column > 0, "file::OResultSet::mapColumn: invalid column index!"); // the first column (index 0) is for convenience only. The first real select column is number 1. - if ((column > 0) && (column < static_cast<sal_Int32>(m_aColMapping.size()))) + if ((column > 0) && (o3tl::make_unsigned(column) < m_aColMapping.size())) map = m_aColMapping[column]; return map; } - } + } -#endif // _CONNECTIVITY_FILE_ORESULTSET_HXX_ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FResultSetMetaData.hxx b/connectivity/source/inc/file/FResultSetMetaData.hxx index 9ba77bc29822..dee656a915f4 100644 --- a/connectivity/source/inc/file/FResultSetMetaData.hxx +++ b/connectivity/source/inc/file/FResultSetMetaData.hxx @@ -17,17 +17,14 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FRESULTSETMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FRESULTSETMETADATA_HXX +#pragma once #include <com/sun/star/sdbc/XResultSetMetaData.hpp> #include <cppuhelper/implbase.hxx> #include <connectivity/CommonTools.hxx> #include <rtl/ref.hxx> -namespace connectivity -{ - namespace file +namespace connectivity::file { class OFileTable; @@ -49,7 +46,7 @@ namespace connectivity virtual ~OResultSetMetaData() override; public: // a Constructor, that is needed for when Returning the Object is needed: - OResultSetMetaData(const ::rtl::Reference<connectivity::OSQLColumns>& _rxColumns,const OUString& _aTableName,OFileTable* _pTable); + OResultSetMetaData(::rtl::Reference<connectivity::OSQLColumns> _xColumns, OUString _aTableName, OFileTable* _pTable); virtual sal_Int32 SAL_CALL getColumnCount( ) override; virtual sal_Bool SAL_CALL isAutoIncrement( sal_Int32 column ) override; @@ -73,9 +70,8 @@ namespace connectivity virtual sal_Bool SAL_CALL isDefinitelyWritable( sal_Int32 column ) override; virtual OUString SAL_CALL getColumnServiceName( sal_Int32 column ) override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FRESULTSETMETADATA_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FStatement.hxx b/connectivity/source/inc/file/FStatement.hxx index a5e61a2dd65d..57ce0a2fc0de 100644 --- a/connectivity/source/inc/file/FStatement.hxx +++ b/connectivity/source/inc/file/FStatement.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FSTATEMENT_HXX +#pragma once #include <com/sun/star/sdbc/XStatement.hpp> #include <com/sun/star/sdbc/XWarningsSupplier.hpp> @@ -38,9 +37,7 @@ #include <file/fanalyzer.hxx> #include <TSortIndex.hxx> -namespace connectivity -{ - namespace file +namespace connectivity::file { class OResultSet; class OFileTable; @@ -98,7 +95,7 @@ namespace connectivity // initialize the column index map (mapping select columns to table columns) void createColumnMapping(); // searches the statement for sort criteria - void anylizeSQL(); + void analyzeSQL(); void setOrderbyColumn( connectivity::OSQLParseNode const * pColumnRef, connectivity::OSQLParseNode const * pAscendingDescending); @@ -119,7 +116,7 @@ namespace connectivity virtual void parseParamterElem(const OUString& _sColumnName,OSQLParseNode* pRow_Value_Constructor_Elem); // factory method for resultset's - virtual OResultSet* createResultSet() = 0; + virtual rtl::Reference<OResultSet> createResultSet() = 0; // OPropertyArrayUsageHelper virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override; // OPropertySetHelper @@ -142,7 +139,7 @@ namespace connectivity virtual void SAL_CALL disposing() override; // XInterface // virtual void SAL_CALL release() throw(css::uno::RuntimeException) = 0; - virtual void SAL_CALL acquire() throw() override; + virtual void SAL_CALL acquire() noexcept override; // XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; //XTypeProvider @@ -167,7 +164,7 @@ namespace connectivity // OComponentHelper virtual void SAL_CALL disposing() override; // XInterface - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL release() noexcept override; }; typedef ::cppu::ImplHelper2< css::sdbc::XStatement,css::lang::XServiceInfo > OStatement_XStatement; @@ -177,15 +174,15 @@ namespace connectivity { protected: // factory method for resultset's - virtual OResultSet* createResultSet() override; + virtual rtl::Reference<OResultSet> createResultSet() override; public: // a Constructor, that is needed for when Returning the Object is needed: OStatement( OConnection* _pConnection) : OStatement_BASE2( _pConnection){} DECLARE_SERVICE_INFO(); virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; // XStatement virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery( const OUString& sql ) override ; @@ -193,8 +190,7 @@ namespace connectivity virtual sal_Bool SAL_CALL execute( const OUString& sql ) override ; virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( ) override ; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FSTATEMENT_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FStringFunctions.hxx b/connectivity/source/inc/file/FStringFunctions.hxx index 8d2ea1cef98e..b3d72294fa68 100644 --- a/connectivity/source/inc/file/FStringFunctions.hxx +++ b/connectivity/source/inc/file/FStringFunctions.hxx @@ -17,14 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FSTRINGFUNCTIONS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FSTRINGFUNCTIONS_HXX +#pragma once #include <file/fcode.hxx> -namespace connectivity -{ - namespace file +namespace connectivity::file { /** UCASE(str) UPPER(str) @@ -266,9 +263,7 @@ namespace connectivity protected: virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const override; }; - } -} -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FSTRINGFUNCTIONS_HXX +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FTable.hxx b/connectivity/source/inc/file/FTable.hxx index 68d6efb45837..d8bbd92d6c85 100644 --- a/connectivity/source/inc/file/FTable.hxx +++ b/connectivity/source/inc/file/FTable.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FTABLE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FTABLE_HXX +#pragma once #include <connectivity/sdbcx/VTable.hxx> #include <file/FConnection.hxx> @@ -27,9 +26,7 @@ #include <connectivity/FValue.hxx> #include <TResultSetHelper.hxx> -namespace connectivity -{ - namespace file +namespace connectivity::file { typedef connectivity::sdbcx::OTable OTable_TYPEDEF; @@ -86,10 +83,6 @@ namespace connectivity const OUString& getSchema() const { return m_SchemaName; } bool isReadOnly() const { return !m_bWriteable; } // m_pFileStream && !m_pFileStream->IsWritable(); } - // css::lang::XUnoTunnel - virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; - static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); - sal_Int32 getFilePos() const { return m_nFilePos; } @@ -100,8 +93,7 @@ namespace connectivity // (NULL or non-NULL is returned) static std::unique_ptr<SvStream> createStream_simpleError( const OUString& _rFileName, StreamMode _eOpenMode); }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FTABLE_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/FTables.hxx b/connectivity/source/inc/file/FTables.hxx index bbc787b57a3f..9d14c3627916 100644 --- a/connectivity/source/inc/file/FTables.hxx +++ b/connectivity/source/inc/file/FTables.hxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FTABLES_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FTABLES_HXX +#pragma once #include <file/filedllapi.hxx> #include <connectivity/sdbcx/VCollection.hxx> #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> -namespace connectivity -{ - namespace file +namespace connectivity::file { class OOO_DLLPUBLIC_FILE SAL_NO_VTABLE OTables : public sdbcx::OCollection @@ -41,8 +38,7 @@ namespace connectivity virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FTABLES_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/fanalyzer.hxx b/connectivity/source/inc/file/fanalyzer.hxx index 9fa5d7f45ed3..f913529d268e 100644 --- a/connectivity/source/inc/file/fanalyzer.hxx +++ b/connectivity/source/inc/file/fanalyzer.hxx @@ -17,14 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FANALYZER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FANALYZER_HXX +#pragma once #include <file/fcomp.hxx> -namespace connectivity -{ - namespace file +namespace connectivity::file { class OConnection; class OSQLAnalyzer final @@ -67,8 +64,7 @@ namespace connectivity static OOperandAttr* createOperandAttr(sal_Int32 _nPos, const css::uno::Reference< css::beans::XPropertySet>& _xCol); }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FANALYZER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/fcode.hxx b/connectivity/source/inc/file/fcode.hxx index 6a6feb412844..541377c7dd5f 100644 --- a/connectivity/source/inc/file/fcode.hxx +++ b/connectivity/source/inc/file/fcode.hxx @@ -17,15 +17,16 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FCODE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FCODE_HXX +#pragma once +#include <config_options.h> #include <connectivity/sqliterator.hxx> #include <com/sun/star/sdbc/DataType.hpp> #include <connectivity/FValue.hxx> #include <file/filedllapi.hxx> #include <stack> +#include <utility> namespace connectivity { @@ -36,7 +37,7 @@ namespace connectivity class OOperand; typedef std::stack<OOperand*> OCodeStack; - class OOO_DLLPUBLIC_FILE OCode + class UNLESS_MERGELIBS_MORE(OOO_DLLPUBLIC_FILE) OCode { public: //virtual dtor to allow this to be the root of the class hierarchy @@ -97,7 +98,7 @@ namespace connectivity class OOperandParam : public OOperandRow { public: - OOperandParam(connectivity::OSQLParseNode const * pNode, sal_Int32 _nPos); + OOperandParam(sal_Int32 _nPos); }; // Value operands @@ -108,9 +109,9 @@ namespace connectivity protected: OOperandValue(){} - OOperandValue(const ORowSetValue& _rVar, sal_Int32 eDbType) + OOperandValue(ORowSetValue _aVar, sal_Int32 eDbType) : OOperand(eDbType) - , m_aValue(_rVar) + , m_aValue(std::move(_aVar)) {} OOperandValue(sal_Int32 eDbType) :OOperand(eDbType){} @@ -244,7 +245,7 @@ namespace connectivity virtual bool operate(const OOperand*, const OOperand*) const override; }; - class OOO_DLLPUBLIC_FILE OOp_COMPARE : public OBoolOperator + class UNLESS_MERGELIBS_MORE(OOO_DLLPUBLIC_FILE) OOp_COMPARE : public OBoolOperator { sal_Int32 aPredicateType; @@ -328,6 +329,4 @@ namespace connectivity } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FCODE_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/fcomp.hxx b/connectivity/source/inc/file/fcomp.hxx index f43b05374b60..72afcdb0a84e 100644 --- a/connectivity/source/inc/file/fcomp.hxx +++ b/connectivity/source/inc/file/fcomp.hxx @@ -16,10 +16,10 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FCOMP_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FCOMP_HXX +#pragma once #include <file/fcode.hxx> +#include <utility> namespace connectivity { @@ -87,7 +87,7 @@ namespace connectivity ::rtl::Reference<OPredicateCompiler> m_rCompiler; public: - OPredicateInterpreter(const ::rtl::Reference<OPredicateCompiler>& rComp) : m_rCompiler(rComp){} + OPredicateInterpreter(::rtl::Reference<OPredicateCompiler> xComp) : m_rCompiler(std::move(xComp)){} virtual ~OPredicateInterpreter() override; bool evaluate(OCodeList& rCodeList); @@ -107,6 +107,5 @@ namespace connectivity }; } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FCOMP_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/filedllapi.hxx b/connectivity/source/inc/file/filedllapi.hxx index 7bc8ed0ce0e7..e32f5f17cb05 100644 --- a/connectivity/source/inc/file/filedllapi.hxx +++ b/connectivity/source/inc/file/filedllapi.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FILEDLLAPI_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FILEDLLAPI_HXX +#pragma once #include <sal/config.h> @@ -30,6 +29,4 @@ #define OOO_DLLPUBLIC_FILE SAL_DLLPUBLIC_IMPORT #endif -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/file/quotedstring.hxx b/connectivity/source/inc/file/quotedstring.hxx index 8d80d15f0319..7c6becc37feb 100644 --- a/connectivity/source/inc/file/quotedstring.hxx +++ b/connectivity/source/inc/file/quotedstring.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_QUOTEDSTRING_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_QUOTEDSTRING_HXX +#pragma once #include <rtl/ustring.hxx> #include <file/filedllapi.hxx> @@ -44,6 +43,4 @@ namespace connectivity }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_QUOTEDSTRING_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/flat/ECatalog.hxx b/connectivity/source/inc/flat/ECatalog.hxx index b28d110a35a9..d1252e464cfa 100644 --- a/connectivity/source/inc/flat/ECatalog.hxx +++ b/connectivity/source/inc/flat/ECatalog.hxx @@ -17,14 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_ECATALOG_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_ECATALOG_HXX +#pragma once #include <file/FCatalog.hxx> -namespace connectivity -{ - namespace flat +namespace connectivity::flat { class OFlatConnection; class OFlatCatalog : public file::OFileCatalog @@ -35,8 +32,7 @@ namespace connectivity public: OFlatCatalog(OFlatConnection* _pCon); }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_ECATALOG_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/flat/EColumns.hxx b/connectivity/source/inc/flat/EColumns.hxx index 800ac771fcf4..d25f79aae240 100644 --- a/connectivity/source/inc/flat/EColumns.hxx +++ b/connectivity/source/inc/flat/EColumns.hxx @@ -17,14 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_ECOLUMNS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_ECOLUMNS_HXX +#pragma once #include <file/FColumns.hxx> -namespace connectivity -{ - namespace flat +namespace connectivity::flat { class OFlatColumns : public file::OColumns { @@ -38,8 +35,7 @@ namespace connectivity {} }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_ECOLUMNS_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/flat/EConnection.hxx b/connectivity/source/inc/flat/EConnection.hxx index 36f6d0f49879..be7c3596d4d9 100644 --- a/connectivity/source/inc/flat/EConnection.hxx +++ b/connectivity/source/inc/flat/EConnection.hxx @@ -17,14 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_ECONNECTION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_ECONNECTION_HXX +#pragma once #include <file/FConnection.hxx> -namespace connectivity -{ - namespace flat +namespace connectivity::flat { class ODriver; class OFlatConnection : public file::OConnection @@ -59,8 +56,7 @@ namespace connectivity virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const OUString& sql ) override; virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall( const OUString& sql ) override; }; - } + } -#endif // _CONNECTIVITY_FLAT_DCONNECTION_HXX_ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/flat/EDatabaseMetaData.hxx b/connectivity/source/inc/flat/EDatabaseMetaData.hxx index f5c1bdd3ccfc..bd6ce7758162 100644 --- a/connectivity/source/inc/flat/EDatabaseMetaData.hxx +++ b/connectivity/source/inc/flat/EDatabaseMetaData.hxx @@ -17,14 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_EDATABASEMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_EDATABASEMETADATA_HXX +#pragma once #include <file/FDatabaseMetaData.hxx> -namespace connectivity -{ - namespace flat +namespace connectivity::flat { //************ Class: java.sql.DatabaseMetaDataDate @@ -41,8 +38,7 @@ namespace connectivity virtual OUString SAL_CALL getURL( ) override; virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getColumns( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const OUString& columnNamePattern ) override; }; - } + } -#endif // _CONNECTIVITY_FLAT_ODATABASEMETADATA_HXX_ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/flat/EDriver.hxx b/connectivity/source/inc/flat/EDriver.hxx index 9b5669920415..7ed2718f2014 100644 --- a/connectivity/source/inc/flat/EDriver.hxx +++ b/connectivity/source/inc/flat/EDriver.hxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_EDRIVER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_EDRIVER_HXX +#pragma once #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <connectivity/CommonTools.hxx> #include <file/FDriver.hxx> -namespace connectivity -{ - namespace flat +namespace connectivity::flat { /// @throws css::uno::Exception css::uno::Reference< css::uno::XInterface > ODriver_CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory); @@ -42,9 +39,7 @@ namespace connectivity virtual sal_Bool SAL_CALL acceptsURL( const OUString& url ) override; virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; }; - } } -#endif //_CONNECTIVITY_FLAT_DDRIVER_HXX_ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/flat/EPreparedStatement.hxx b/connectivity/source/inc/flat/EPreparedStatement.hxx index 3af19bd9420c..ca164be8d5ba 100644 --- a/connectivity/source/inc/flat/EPreparedStatement.hxx +++ b/connectivity/source/inc/flat/EPreparedStatement.hxx @@ -17,27 +17,22 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_EPREPAREDSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_EPREPAREDSTATEMENT_HXX +#pragma once #include <file/FPreparedStatement.hxx> -namespace connectivity -{ - namespace flat +namespace connectivity::flat { class OConnection; class OFlatPreparedStatement : public file::OPreparedStatement { protected: - virtual file::OResultSet* createResultSet() override; + virtual rtl::Reference<file::OResultSet> createResultSet() override; public: OFlatPreparedStatement( file::OConnection* _pConnection) : file::OPreparedStatement( _pConnection){} DECLARE_SERVICE_INFO(); }; - } -} -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_EPREPAREDSTATEMENT_HXX +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/flat/EResultSet.hxx b/connectivity/source/inc/flat/EResultSet.hxx index e7b7c6d8744e..8d99ed55da04 100644 --- a/connectivity/source/inc/flat/EResultSet.hxx +++ b/connectivity/source/inc/flat/EResultSet.hxx @@ -17,16 +17,13 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_ERESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_ERESULTSET_HXX +#pragma once #include <file/FResultSet.hxx> #include <com/sun/star/sdbcx/XRowLocate.hpp> #include <cppuhelper/implbase1.hxx> -namespace connectivity -{ - namespace flat +namespace connectivity::flat { class OFlatResultSet; // these typedef's are only necessary for the compiler @@ -52,8 +49,8 @@ namespace connectivity // XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; // XPropertySet @@ -67,8 +64,7 @@ namespace connectivity virtual sal_Bool SAL_CALL hasOrderedBookmarks( ) override; virtual sal_Int32 SAL_CALL hashBookmark( const css::uno::Any& bookmark ) override; }; - } + } -#endif //_CONNECTIVITY_FLAT_DRESULTSET_HXX_ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/flat/EStatement.hxx b/connectivity/source/inc/flat/EStatement.hxx index 215d0b0a9e5b..d30bfc70977f 100644 --- a/connectivity/source/inc/flat/EStatement.hxx +++ b/connectivity/source/inc/flat/EStatement.hxx @@ -17,27 +17,22 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_ESTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_ESTATEMENT_HXX +#pragma once #include <file/FStatement.hxx> -namespace connectivity -{ - namespace flat +namespace connectivity::flat { class OConnection; class OFlatStatement : public file::OStatement { protected: - virtual file::OResultSet* createResultSet() override; + virtual rtl::Reference<file::OResultSet> createResultSet() override; public: OFlatStatement( file::OConnection* _pConnection) : file::OStatement( _pConnection){} DECLARE_SERVICE_INFO(); }; - } -} -#endif //_CONNECTIVITY_FLAT_DSTATEMENT_HXX_ +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/flat/ETable.hxx b/connectivity/source/inc/flat/ETable.hxx index 6680c25851bc..99359edfddaa 100644 --- a/connectivity/source/inc/flat/ETable.hxx +++ b/connectivity/source/inc/flat/ETable.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_ETABLE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_ETABLE_HXX +#pragma once #include <file/FTable.hxx> #include <flat/EConnection.hxx> @@ -27,9 +26,7 @@ #include <unotools/syslocale.hxx> #include <com/sun/star/util/XNumberFormatter.hpp> -namespace connectivity -{ - namespace flat +namespace connectivity::flat { typedef file::OFileTable OFlatTable_BASE; class OFlatConnection; @@ -95,14 +92,9 @@ namespace connectivity virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; virtual void SAL_CALL disposing() override; - // css::lang::XUnoTunnel - virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; - static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); - OUString getEntry() const; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_ETABLE_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/flat/ETables.hxx b/connectivity/source/inc/flat/ETables.hxx index 69b6f5562be3..cb9b032dbc45 100644 --- a/connectivity/source/inc/flat/ETables.hxx +++ b/connectivity/source/inc/flat/ETables.hxx @@ -17,14 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_ETABLES_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_ETABLES_HXX +#pragma once #include <file/FTables.hxx> -namespace connectivity -{ - namespace flat +namespace connectivity::flat { typedef file::OTables OFlatTables_BASE; @@ -37,8 +34,7 @@ namespace connectivity const ::std::vector< OUString> &_rVector) : OFlatTables_BASE(_rMetaData,_rParent,_rMutex,_rVector) {} }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FLAT_ETABLES_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HCatalog.hxx b/connectivity/source/inc/hsqldb/HCatalog.hxx index 0202da3502d1..8d1da42de111 100644 --- a/connectivity/source/inc/hsqldb/HCatalog.hxx +++ b/connectivity/source/inc/hsqldb/HCatalog.hxx @@ -16,14 +16,11 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HCATALOG_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HCATALOG_HXX +#pragma once #include <sdbcx/VCatalog.hxx> -namespace connectivity -{ - namespace hsqldb +namespace connectivity::hsqldb { // please don't name the class the same name as in another namespaces // some compilers have problems with this task as I noticed on windows @@ -57,8 +54,7 @@ namespace connectivity // ::cppu::OComponentHelper virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HCATALOG_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HColumns.hxx b/connectivity/source/inc/hsqldb/HColumns.hxx index f3fd008cd92f..c27645f45891 100644 --- a/connectivity/source/inc/hsqldb/HColumns.hxx +++ b/connectivity/source/inc/hsqldb/HColumns.hxx @@ -16,14 +16,11 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HCOLUMNS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HCOLUMNS_HXX +#pragma once #include <connectivity/TColumnsHelper.hxx> #include <connectivity/sdbcx/VColumn.hxx> -namespace connectivity -{ - namespace hsqldb +namespace connectivity::hsqldb { class OHSQLColumns : public OColumnsHelper { @@ -53,8 +50,7 @@ namespace connectivity virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HCOLUMNS_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HConnection.hxx b/connectivity/source/inc/hsqldb/HConnection.hxx index dcc2eb49f6a6..6e2a54c9ce85 100644 --- a/connectivity/source/inc/hsqldb/HConnection.hxx +++ b/connectivity/source/inc/hsqldb/HConnection.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HCONNECTION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HCONNECTION_HXX +#pragma once #include <connectivity/ConnectionWrapper.hxx> #include <com/sun/star/util/XFlushable.hpp> @@ -29,9 +28,7 @@ #include <comphelper/uno3.hxx> #include <comphelper/interfacecontainer2.hxx> -namespace connectivity -{ - namespace hsqldb +namespace connectivity::hsqldb { class SAL_NO_VTABLE IMethodGuardAccess { @@ -132,18 +129,14 @@ namespace connectivity class MethodGuard : public ::osl::MutexGuard { - private: - typedef ::osl::MutexGuard BaseGuard; - public: MethodGuard( const IMethodGuardAccess& _rComponent ) - :BaseGuard( _rComponent.getMutex() ) + : ::osl::MutexGuard( _rComponent.getMutex() ) { _rComponent.checkDisposed(); } }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HCONNECTION_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HDriver.hxx b/connectivity/source/inc/hsqldb/HDriver.hxx index f376dc83a1bf..0dda7e5e0fa2 100644 --- a/connectivity/source/inc/hsqldb/HDriver.hxx +++ b/connectivity/source/inc/hsqldb/HDriver.hxx @@ -16,14 +16,12 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HDRIVER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HDRIVER_HXX +#pragma once #include <com/sun/star/sdbc/XDriver.hpp> #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp> #include <com/sun/star/sdbcx/XCreateCatalog.hpp> #include <com/sun/star/embed/XTransactionListener.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/uno/XComponentContext.hpp> #include <cppuhelper/compbase.hxx> @@ -31,11 +29,7 @@ #include <connectivity/CommonTools.hxx> -namespace connectivity -{ - - - namespace hsqldb +namespace connectivity::hsqldb { typedef ::cppu::WeakComponentImplHelper< css::sdbc::XDriver , css::sdbcx::XDataDefinitionSupplier @@ -122,11 +116,8 @@ namespace connectivity const css::uno::Reference< css::sdbc::XConnection >& _rxConnection ); }; - } - -} // namespace connectivity -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HDRIVER_HXX +} // namespace connectivity::hsqldb /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HStorageAccess.hxx b/connectivity/source/inc/hsqldb/HStorageAccess.hxx index 457d1eaffc73..5a49162c2e6b 100644 --- a/connectivity/source/inc/hsqldb/HStorageAccess.hxx +++ b/connectivity/source/inc/hsqldb/HStorageAccess.hxx @@ -17,12 +17,18 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HSTORAGEACCESS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HSTORAGEACCESS_HXX +#pragma once #include <sal/config.h> +#if defined __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-attributes" +#endif #include <jni.h> +#if defined __clang__ +#pragma clang diagnostic pop +#endif namespace connectivity::hsqldb { @@ -34,6 +40,4 @@ jint read_from_storage_stream_into_buffer( JNIEnv * env, jstring name, jstring k void write_to_storage_stream_from_buffer( JNIEnv* env, jstring name, jstring key, jbyteArray buffer, jint off, jint len ); void write_to_storage_stream( JNIEnv* env, jstring name, jstring key, jint v ); -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HSTORAGEACCESS_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HStorageMap.hxx b/connectivity/source/inc/hsqldb/HStorageMap.hxx index 62ae7ec3d233..1186c680ac07 100644 --- a/connectivity/source/inc/hsqldb/HStorageMap.hxx +++ b/connectivity/source/inc/hsqldb/HStorageMap.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HSTORAGEMAP_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HSTORAGEMAP_HXX +#pragma once #include <sal/config.h> @@ -30,13 +29,19 @@ #include <com/sun/star/io/XOutputStream.hpp> #include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/io/XSeekable.hpp> + +#if defined __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-attributes" +#endif #include <jni.h> -#include <uno/environment.hxx> +#if defined __clang__ +#pragma clang diagnostic pop +#endif -namespace connectivity -{ +#include <uno/environment.hxx> - namespace hsqldb +namespace connectivity::hsqldb { class StreamHelper { @@ -81,17 +86,12 @@ namespace connectivity static TStreamMap::mapped_type getRegisteredStream( JNIEnv * env, jstring name, jstring key); static OUString jstring2ustring(JNIEnv * env, jstring jstr); - static OUString removeURLPrefix(const OUString& _sURL,const OUString& _sFileURL); + static OUString removeURLPrefix(std::u16string_view _sURL, std::u16string_view _sFileURL); static OUString removeOldURLPrefix(const OUString& _sURL); static void throwJavaException(const css::uno::Exception& _aException,JNIEnv * env); }; - } // namespace hsqldb - - -} // namespace connectivity - +} // namespace connectivity::hsqldb -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HSTORAGEMAP_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HTable.hxx b/connectivity/source/inc/hsqldb/HTable.hxx index 4540bb089a81..d6ac5ced7646 100644 --- a/connectivity/source/inc/hsqldb/HTable.hxx +++ b/connectivity/source/inc/hsqldb/HTable.hxx @@ -17,15 +17,16 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HTABLE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HTABLE_HXX +#pragma once + +#include <sal/config.h> + +#include <string_view> #include <connectivity/TTableHelper.hxx> #include <comphelper/IdPropArrayHelper.hxx> -namespace connectivity -{ - namespace hsqldb +namespace connectivity::hsqldb { class OHSQLTable; @@ -84,9 +85,6 @@ namespace connectivity // ODescriptor virtual void construct() override; - // css::lang::XUnoTunnel - virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; - static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; //XTypeProvider @@ -104,12 +102,11 @@ namespace connectivity // some methods to alter table structures void alterColumnType(sal_Int32 nNewType,const OUString& _rColName,const css::uno::Reference< css::beans::XPropertySet >& _xDescriptor); - void alterDefaultValue(const OUString& _sNewDefault,const OUString& _rColName); + void alterDefaultValue(std::u16string_view _sNewDefault,const OUString& _rColName); void dropDefaultValue(const OUString& _sNewDefault); }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HTABLE_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HTables.hxx b/connectivity/source/inc/hsqldb/HTables.hxx index bf0580396df2..bff5e0e6421a 100644 --- a/connectivity/source/inc/hsqldb/HTables.hxx +++ b/connectivity/source/inc/hsqldb/HTables.hxx @@ -16,14 +16,12 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HTABLES_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HTABLES_HXX +#pragma once #include <connectivity/sdbcx/VCollection.hxx> #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> -namespace connectivity -{ - namespace hsqldb +#include <utility> +namespace connectivity::hsqldb { class OTables final : public sdbcx::OCollection { @@ -38,9 +36,9 @@ namespace connectivity void createTable( const css::uno::Reference< css::beans::XPropertySet >& descriptor ); virtual OUString getNameForObject(const sdbcx::ObjectType& _xObject) override; public: - OTables(const css::uno::Reference< css::sdbc::XDatabaseMetaData >& _rMetaData,::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, + OTables(css::uno::Reference< css::sdbc::XDatabaseMetaData > _xMetaData, ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, const ::std::vector< OUString> &_rVector) : sdbcx::OCollection(_rParent, true, _rMutex, _rVector) - ,m_xMetaData(_rMetaData) + ,m_xMetaData(std::move(_xMetaData)) {} // only the name is identical to ::cppu::OComponentHelper @@ -49,8 +47,7 @@ namespace connectivity // XDrop void appendNew(const OUString& _rsNewTable); }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HTABLES_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HTools.hxx b/connectivity/source/inc/hsqldb/HTools.hxx index be30e8e281ee..a847b2d9a589 100644 --- a/connectivity/source/inc/hsqldb/HTools.hxx +++ b/connectivity/source/inc/hsqldb/HTools.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HTOOLS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HTOOLS_HXX +#pragma once #include <rtl/ustrbuf.hxx> @@ -37,8 +36,8 @@ namespace connectivity::hsqldb have the short form (TABLE_CAT instead of TABLE_CATALOG, and so on) */ static void appendTableFilterCrit( - OUStringBuffer& _inout_rBuffer, const OUString& _rCatalog, - const OUString& _rSchema, const OUString& _rName, + OUStringBuffer& _inout_rBuffer, std::u16string_view _rCatalog, + std::u16string_view _rSchema, std::u16string_view _rName, bool _bShortForm ); }; @@ -47,6 +46,4 @@ namespace connectivity::hsqldb } // namespace connectivity::hsqldb -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HTOOLS_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HUser.hxx b/connectivity/source/inc/hsqldb/HUser.hxx index 1e16a765246f..67c44e185bd2 100644 --- a/connectivity/source/inc/hsqldb/HUser.hxx +++ b/connectivity/source/inc/hsqldb/HUser.hxx @@ -17,15 +17,12 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HUSER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HUSER_HXX +#pragma once #include <sdbcx/VUser.hxx> #include <com/sun/star/sdbc/XConnection.hpp> -namespace connectivity -{ - namespace hsqldb +namespace connectivity::hsqldb { typedef connectivity::sdbcx::OUser OUser_TYPEDEF; @@ -41,8 +38,8 @@ namespace connectivity public: virtual void refreshGroups() override; public: - OHSQLUser( const css::uno::Reference< css::sdbc::XConnection >& _xConnection); - OHSQLUser( const css::uno::Reference< css::sdbc::XConnection >& _xConnection,const OUString& Name); + OHSQLUser( css::uno::Reference< css::sdbc::XConnection > _xConnection); + OHSQLUser( css::uno::Reference< css::sdbc::XConnection > _xConnection, const OUString& Name); // XUser virtual void SAL_CALL changePassword( const OUString& objPassword, const OUString& newPassword ) override; @@ -70,8 +67,7 @@ namespace connectivity virtual void construct() override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HUSER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HUsers.hxx b/connectivity/source/inc/hsqldb/HUsers.hxx index 392b3412a39b..a5a099e9927e 100644 --- a/connectivity/source/inc/hsqldb/HUsers.hxx +++ b/connectivity/source/inc/hsqldb/HUsers.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HUSERS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HUSERS_HXX +#pragma once #include <connectivity/sdbcx/VCollection.hxx> #include <com/sun/star/sdbc/XConnection.hpp> @@ -44,12 +43,10 @@ namespace connectivity OUsers( ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, const ::std::vector< OUString> &_rVector, - const css::uno::Reference< css::sdbc::XConnection >& _xConnection, + css::uno::Reference< css::sdbc::XConnection > _xConnection, connectivity::sdbcx::IRefreshableUsers* _pParent); }; } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HUSERS_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HView.hxx b/connectivity/source/inc/hsqldb/HView.hxx index 3e158c753d1b..62e8e5f4568a 100644 --- a/connectivity/source/inc/hsqldb/HView.hxx +++ b/connectivity/source/inc/hsqldb/HView.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HVIEW_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HVIEW_HXX +#pragma once #include <connectivity/sdbcx/VView.hxx> @@ -86,6 +85,4 @@ namespace connectivity::hsqldb } // namespace connectivity::hsqldb -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HVIEW_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HViews.hxx b/connectivity/source/inc/hsqldb/HViews.hxx index 6f6724383e32..cb2041524ecc 100644 --- a/connectivity/source/inc/hsqldb/HViews.hxx +++ b/connectivity/source/inc/hsqldb/HViews.hxx @@ -16,14 +16,11 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HVIEWS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HVIEWS_HXX +#pragma once #include <connectivity/sdbcx/VCollection.hxx> #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> -namespace connectivity -{ - namespace hsqldb +namespace connectivity::hsqldb { class HViews final : public sdbcx::OCollection { @@ -48,8 +45,7 @@ namespace connectivity void dropByNameImpl(const OUString& elementName); }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HVIEWS_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/ContextClassLoader.hxx b/connectivity/source/inc/java/ContextClassLoader.hxx index dea3fb58b50a..e7079239aa05 100644 --- a/connectivity/source/inc/java/ContextClassLoader.hxx +++ b/connectivity/source/inc/java/ContextClassLoader.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_CONTEXTCLASSLOADER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_CONTEXTCLASSLOADER_HXX +#pragma once #include <java/GlobalRef.hxx> @@ -77,6 +76,4 @@ namespace connectivity::jdbc } // namespace connectivity::jdbc -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_CONTEXTCLASSLOADER_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/GlobalRef.hxx b/connectivity/source/inc/java/GlobalRef.hxx index 80888cb48810..1a97bfb33a45 100644 --- a/connectivity/source/inc/java/GlobalRef.hxx +++ b/connectivity/source/inc/java/GlobalRef.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_GLOBALREF_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_GLOBALREF_HXX +#pragma once #include <java/LocalRef.hxx> #include <java/lang/Object.hxx> @@ -100,6 +99,4 @@ namespace connectivity::jdbc } // namespace connectivity::jdbc -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_GLOBALREF_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/LocalRef.hxx b/connectivity/source/inc/java/LocalRef.hxx index 5973405acea5..ad40737f8620 100644 --- a/connectivity/source/inc/java/LocalRef.hxx +++ b/connectivity/source/inc/java/LocalRef.hxx @@ -17,11 +17,16 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LOCALREF_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LOCALREF_HXX +#pragma once +#if defined __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-attributes" +#endif #include <jni.h> - +#if defined __clang__ +#pragma clang diagnostic pop +#endif namespace connectivity::jdbc { @@ -87,6 +92,4 @@ namespace connectivity::jdbc } // namespace connectivity::jdbc -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LOCALREF_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/io/InputStream.hxx b/connectivity/source/inc/java/io/InputStream.hxx index c05309e87c1b..4a0b5788f19b 100644 --- a/connectivity/source/inc/java/io/InputStream.hxx +++ b/connectivity/source/inc/java/io/InputStream.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_IO_INPUTSTREAM_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_IO_INPUTSTREAM_HXX +#pragma once #include <java/lang/Object.hxx> #include <cppuhelper/implbase.hxx> @@ -48,6 +47,5 @@ namespace connectivity virtual void SAL_CALL closeInput( ) override; }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_IO_INPUTSTREAM_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/io/Reader.hxx b/connectivity/source/inc/java/io/Reader.hxx index 7a2cf0524483..8386eda449e3 100644 --- a/connectivity/source/inc/java/io/Reader.hxx +++ b/connectivity/source/inc/java/io/Reader.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_IO_READER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_IO_READER_HXX +#pragma once #include <java/lang/Object.hxx> #include <cppuhelper/implbase.hxx> @@ -49,6 +48,5 @@ namespace connectivity virtual void SAL_CALL closeInput( ) override; }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_IO_READER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/lang/Boolean.hxx b/connectivity/source/inc/java/lang/Boolean.hxx index 27a7e06685c2..536ba5de316b 100644 --- a/connectivity/source/inc/java/lang/Boolean.hxx +++ b/connectivity/source/inc/java/lang/Boolean.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LANG_BOOLEAN_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LANG_BOOLEAN_HXX +#pragma once #include <java/lang/Object.hxx> @@ -40,7 +39,5 @@ namespace connectivity }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LANG_BOOLEAN_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/lang/Class.hxx b/connectivity/source/inc/java/lang/Class.hxx index bc68a01a536a..bcd5628c1d87 100644 --- a/connectivity/source/inc/java/lang/Class.hxx +++ b/connectivity/source/inc/java/lang/Class.hxx @@ -16,11 +16,14 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LANG_CLASS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LANG_CLASS_HXX +#pragma once //************ Class: java.lang.Class +#include <sal/config.h> + +#include <string_view> + #include <java/lang/Object.hxx> namespace connectivity @@ -36,13 +39,11 @@ namespace connectivity // a Constructor, that is needed for when Returning the Object is needed: java_lang_Class( JNIEnv * pEnv, jobject myObj ) : java_lang_Object( pEnv, myObj ){} - static java_lang_Class * forName( const OUString &_par0 ); + static java_lang_Class * forName( std::u16string_view _par0 ); // return the jre object jobject newInstanceObject(); }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LANG_CLASS_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/lang/Exception.hxx b/connectivity/source/inc/java/lang/Exception.hxx index 5e11e7890be7..28b2d56dc90a 100644 --- a/connectivity/source/inc/java/lang/Exception.hxx +++ b/connectivity/source/inc/java/lang/Exception.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LANG_EXCEPTION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LANG_EXCEPTION_HXX +#pragma once #include <java/lang/Throwable.hxx> @@ -39,6 +38,5 @@ namespace connectivity }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LANG_EXCEPTION_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/lang/Object.hxx b/connectivity/source/inc/java/lang/Object.hxx index ba9414008163..63d7af3f5976 100644 --- a/connectivity/source/inc/java/lang/Object.hxx +++ b/connectivity/source/inc/java/lang/Object.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LANG_OBJECT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LANG_OBJECT_HXX +#pragma once #include <com/sun/star/uno/XComponentContext.hpp> #include <jvmaccess/virtualmachine.hxx> @@ -143,7 +142,6 @@ namespace connectivity }; } -#endif //_CONNECTIVITY_JAVA_LANG_OBJECT_HXX_ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/lang/String.hxx b/connectivity/source/inc/java/lang/String.hxx index 25ba03d0da4c..2783b6eeb9bf 100644 --- a/connectivity/source/inc/java/lang/String.hxx +++ b/connectivity/source/inc/java/lang/String.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LANG_STRING_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LANG_STRING_HXX +#pragma once #include <java/lang/Object.hxx> @@ -41,6 +40,4 @@ namespace connectivity } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LANG_STRING_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/lang/Throwable.hxx b/connectivity/source/inc/java/lang/Throwable.hxx index d24395286116..65cfc24fe73d 100644 --- a/connectivity/source/inc/java/lang/Throwable.hxx +++ b/connectivity/source/inc/java/lang/Throwable.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LANG_THROWABLE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LANG_THROWABLE_HXX +#pragma once #include <java/lang/Object.hxx> @@ -46,6 +45,5 @@ namespace connectivity static jclass st_getMyClass(); }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_LANG_THROWABLE_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/math/BigDecimal.hxx b/connectivity/source/inc/java/math/BigDecimal.hxx index e345aeed250d..f4fb684b87ac 100644 --- a/connectivity/source/inc/java/math/BigDecimal.hxx +++ b/connectivity/source/inc/java/math/BigDecimal.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_MATH_BIGDECIMAL_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_MATH_BIGDECIMAL_HXX +#pragma once #include <java/lang/Object.hxx> @@ -38,7 +37,5 @@ namespace connectivity }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_MATH_BIGDECIMAL_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/Array.hxx b/connectivity/source/inc/java/sql/Array.hxx index 8677daa47763..93cce6938661 100644 --- a/connectivity/source/inc/java/sql/Array.hxx +++ b/connectivity/source/inc/java/sql/Array.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_ARRAY_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_ARRAY_HXX +#pragma once #include <java/lang/Object.hxx> #include <com/sun/star/sdbc/XArray.hpp> @@ -51,6 +50,5 @@ namespace connectivity }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_ARRAY_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/Blob.hxx b/connectivity/source/inc/java/sql/Blob.hxx index 605853f60e6a..02ac0df13401 100644 --- a/connectivity/source/inc/java/sql/Blob.hxx +++ b/connectivity/source/inc/java/sql/Blob.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_BLOB_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_BLOB_HXX +#pragma once #include <java/lang/Object.hxx> #include <com/sun/star/sdbc/XBlob.hpp> @@ -51,6 +50,5 @@ namespace connectivity virtual sal_Int64 SAL_CALL positionOfBlob( const css::uno::Reference< css::sdbc::XBlob >& pattern, sal_Int64 start ) override; }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_BLOB_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/CallableStatement.hxx b/connectivity/source/inc/java/sql/CallableStatement.hxx index 31cafdeed2c5..7391837741ef 100644 --- a/connectivity/source/inc/java/sql/CallableStatement.hxx +++ b/connectivity/source/inc/java/sql/CallableStatement.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_CALLABLESTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_CALLABLESTATEMENT_HXX +#pragma once #include <java/sql/PreparedStatement.hxx> #include <com/sun/star/sdbc/XRow.hpp> @@ -48,8 +47,8 @@ namespace connectivity java_sql_CallableStatement( JNIEnv * pEnv, java_sql_Connection& _rCon, const OUString& sql ); virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; @@ -79,6 +78,5 @@ namespace connectivity virtual void SAL_CALL registerNumericOutParameter( sal_Int32 parameterIndex, sal_Int32 sqlType, sal_Int32 scale ) override; }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_CALLABLESTATEMENT_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/Clob.hxx b/connectivity/source/inc/java/sql/Clob.hxx index ecea073fa1f2..67a69bb6db17 100644 --- a/connectivity/source/inc/java/sql/Clob.hxx +++ b/connectivity/source/inc/java/sql/Clob.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_CLOB_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_CLOB_HXX +#pragma once #include <java/lang/Object.hxx> #include <com/sun/star/sdbc/XClob.hpp> @@ -51,6 +50,5 @@ namespace connectivity virtual sal_Int64 SAL_CALL positionOfClob( const css::uno::Reference< css::sdbc::XClob >& pattern, sal_Int64 start ) override; }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_CLOB_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/Connection.hxx b/connectivity/source/inc/java/sql/Connection.hxx index cc453e6e87ca..444d44df51e7 100644 --- a/connectivity/source/inc/java/sql/Connection.hxx +++ b/connectivity/source/inc/java/sql/Connection.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_CONNECTION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_CONNECTION_HXX +#pragma once #include <java/lang/Object.hxx> #include <TConnection.hxx> @@ -132,6 +131,5 @@ namespace connectivity virtual void SAL_CALL clearWarnings( ) override; }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_CONNECTION_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/ConnectionLog.hxx b/connectivity/source/inc/java/sql/ConnectionLog.hxx index 780b7f27eb2c..cea19cdff0ac 100644 --- a/connectivity/source/inc/java/sql/ConnectionLog.hxx +++ b/connectivity/source/inc/java/sql/ConnectionLog.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_CONNECTIONLOG_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_CONNECTIONLOG_HXX +#pragma once #include <com/sun/star/logging/LogLevel.hpp> @@ -125,6 +124,4 @@ namespace connectivity::java::sql { } // namespace connectivity::java::sql -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_CONNECTIONLOG_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/DatabaseMetaData.hxx b/connectivity/source/inc/java/sql/DatabaseMetaData.hxx index d87cd6c21849..eb43f2537aef 100644 --- a/connectivity/source/inc/java/sql/DatabaseMetaData.hxx +++ b/connectivity/source/inc/java/sql/DatabaseMetaData.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_DATABASEMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_DATABASEMETADATA_HXX +#pragma once #include <java/lang/Object.hxx> #include <TDatabaseMetaDataBase.hxx> @@ -213,6 +212,5 @@ namespace connectivity const OUString* _pOptionalAdditionalString = nullptr); }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_DATABASEMETADATA_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/Driver.hxx b/connectivity/source/inc/java/sql/Driver.hxx index 3deba1b9887d..805df2ed12ee 100644 --- a/connectivity/source/inc/java/sql/Driver.hxx +++ b/connectivity/source/inc/java/sql/Driver.hxx @@ -17,12 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_DRIVER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_DRIVER_HXX +#pragma once #include <com/sun/star/sdbc/XDriver.hpp> #include <cppuhelper/implbase.hxx> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <comphelper/logging.hxx> @@ -57,6 +55,5 @@ namespace connectivity }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_DRIVER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/DriverPropertyInfo.hxx b/connectivity/source/inc/java/sql/DriverPropertyInfo.hxx index b0ab4efda344..4bc681622692 100644 --- a/connectivity/source/inc/java/sql/DriverPropertyInfo.hxx +++ b/connectivity/source/inc/java/sql/DriverPropertyInfo.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_DRIVERPROPERTYINFO_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_DRIVERPROPERTYINFO_HXX +#pragma once #include <java/lang/Object.hxx> @@ -39,6 +38,5 @@ namespace connectivity }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_DRIVERPROPERTYINFO_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/JStatement.hxx b/connectivity/source/inc/java/sql/JStatement.hxx index 62cbe81547d2..89a091bd96a7 100644 --- a/connectivity/source/inc/java/sql/JStatement.hxx +++ b/connectivity/source/inc/java/sql/JStatement.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_JSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_JSTATEMENT_HXX +#pragma once #include <java/lang/Object.hxx> #include <com/sun/star/sdbc/XStatement.hpp> @@ -163,8 +162,8 @@ namespace connectivity // OComponentHelper virtual void SAL_CALL disposing() override; // XInterface - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; @@ -223,14 +222,13 @@ namespace connectivity java_sql_Statement( JNIEnv * pEnv, java_sql_Connection& _rCon ) : OStatement_BASE2( pEnv, _rCon){}; virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; // XBatchExecution virtual void SAL_CALL addBatch( const OUString& sql ) override; virtual void SAL_CALL clearBatch( ) override; virtual css::uno::Sequence< sal_Int32 > SAL_CALL executeBatch( ) override; }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_JSTATEMENT_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/PreparedStatement.hxx b/connectivity/source/inc/java/sql/PreparedStatement.hxx index 5bfc085876b6..711fd2d00661 100644 --- a/connectivity/source/inc/java/sql/PreparedStatement.hxx +++ b/connectivity/source/inc/java/sql/PreparedStatement.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_PREPAREDSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_PREPAREDSTATEMENT_HXX +#pragma once #include <java/sql/JStatement.hxx> #include <com/sun/star/sdbc/XPreparedStatement.hpp> @@ -53,8 +52,8 @@ namespace connectivity java_sql_PreparedStatement( JNIEnv * pEnv, java_sql_Connection& _rCon,const OUString& sql ); virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; @@ -100,6 +99,5 @@ namespace connectivity using java_sql_Statement_Base::execute; }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_PREPAREDSTATEMENT_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/Ref.hxx b/connectivity/source/inc/java/sql/Ref.hxx index eb658925fd92..f127178b277d 100644 --- a/connectivity/source/inc/java/sql/Ref.hxx +++ b/connectivity/source/inc/java/sql/Ref.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_REF_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_REF_HXX +#pragma once #include <java/lang/Object.hxx> #include <com/sun/star/sdbc/XRef.hpp> @@ -46,6 +45,5 @@ namespace connectivity virtual OUString SAL_CALL getBaseTypeName( ) override; }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_REF_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/ResultSet.hxx b/connectivity/source/inc/java/sql/ResultSet.hxx index e5e0155ff3e9..183c6fa3a362 100644 --- a/connectivity/source/inc/java/sql/ResultSet.hxx +++ b/connectivity/source/inc/java/sql/ResultSet.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_RESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_RESULTSET_HXX +#pragma once #include <java/lang/Object.hxx> #include <com/sun/star/sdbc/XResultSet.hpp> @@ -120,8 +119,8 @@ namespace connectivity virtual void SAL_CALL disposing() override; // XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; // XPropertySet @@ -207,6 +206,5 @@ namespace connectivity using ::cppu::OPropertySetHelper::getFastPropertyValue; }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_RESULTSET_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/ResultSetMetaData.hxx b/connectivity/source/inc/java/sql/ResultSetMetaData.hxx index bc96fdf4b9a8..e5017f1158fd 100644 --- a/connectivity/source/inc/java/sql/ResultSetMetaData.hxx +++ b/connectivity/source/inc/java/sql/ResultSetMetaData.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_RESULTSETMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_RESULTSETMETADATA_HXX +#pragma once #include <java/lang/Object.hxx> #include <com/sun/star/sdbc/XResultSetMetaData.hpp> @@ -67,6 +66,5 @@ namespace connectivity virtual OUString SAL_CALL getColumnServiceName( sal_Int32 column ) override; }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_RESULTSETMETADATA_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/SQLException.hxx b/connectivity/source/inc/java/sql/SQLException.hxx index 88a147faaebe..cff1aad4662d 100644 --- a/connectivity/source/inc/java/sql/SQLException.hxx +++ b/connectivity/source/inc/java/sql/SQLException.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_SQLEXCEPTION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_SQLEXCEPTION_HXX +#pragma once #include <java/lang/Exception.hxx> #include <com/sun/star/sdbc/SQLException.hpp> @@ -53,6 +52,5 @@ namespace connectivity }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_SQLEXCEPTION_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/SQLWarning.hxx b/connectivity/source/inc/java/sql/SQLWarning.hxx index 68a83f4635be..5fd8c979430d 100644 --- a/connectivity/source/inc/java/sql/SQLWarning.hxx +++ b/connectivity/source/inc/java/sql/SQLWarning.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_SQLWARNING_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_SQLWARNING_HXX +#pragma once #include <java/sql/SQLException.hxx> @@ -46,6 +45,5 @@ namespace connectivity : java_sql_SQLException(_rW,_rContext) {} }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_SQLWARNING_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/sql/Timestamp.hxx b/connectivity/source/inc/java/sql/Timestamp.hxx index 0d41d46d69c5..599dfb78e4dd 100644 --- a/connectivity/source/inc/java/sql/Timestamp.hxx +++ b/connectivity/source/inc/java/sql/Timestamp.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_TIMESTAMP_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_TIMESTAMP_HXX +#pragma once #include <java/util/Date.hxx> #include <com/sun/star/util/Date.hpp> @@ -85,6 +84,5 @@ namespace connectivity static jclass st_getMyClass(); }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_SQL_TIMESTAMP_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/tools.hxx b/connectivity/source/inc/java/tools.hxx index aa7cb20cad9b..44a35ecee3f9 100644 --- a/connectivity/source/inc/java/tools.hxx +++ b/connectivity/source/inc/java/tools.hxx @@ -17,13 +17,23 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_TOOLS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_TOOLS_HXX +#pragma once + +#include <sal/config.h> + +#include <memory> #include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/uno/Sequence.h> +#if defined __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-attributes" +#endif #include <jni.h> +#if defined __clang__ +#pragma clang diagnostic pop +#endif #include <com/sun/star/container/XNameAccess.hpp> #include <com/sun/star/io/XInputStream.hpp> @@ -53,6 +63,4 @@ namespace connectivity jobject createCharArrayReader(const css::uno::Reference< css::io::XInputStream >& x,sal_Int32 length); } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_TOOLS_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/util/Date.hxx b/connectivity/source/inc/java/util/Date.hxx index 9c2e8a3ee76a..fe552428675f 100644 --- a/connectivity/source/inc/java/util/Date.hxx +++ b/connectivity/source/inc/java/util/Date.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_UTIL_DATE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_UTIL_DATE_HXX +#pragma once #include <java/lang/Object.hxx> //#include <com/sun/star/util/Date.hpp> @@ -42,6 +41,5 @@ namespace connectivity java_util_Date( JNIEnv * pEnv, jobject myObj ) : java_lang_Object( pEnv, myObj ){} }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_UTIL_DATE_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/java/util/Property.hxx b/connectivity/source/inc/java/util/Property.hxx index f7835e5f1d8d..628f951ba4d8 100644 --- a/connectivity/source/inc/java/util/Property.hxx +++ b/connectivity/source/inc/java/util/Property.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_UTIL_PROPERTY_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_UTIL_PROPERTY_HXX +#pragma once #include <java/lang/Object.hxx> @@ -36,6 +35,4 @@ namespace connectivity }; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_JAVA_UTIL_PROPERTY_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/mysql/YCatalog.hxx b/connectivity/source/inc/mysql/YCatalog.hxx index 35dd2a3cdad4..5eb348af997d 100644 --- a/connectivity/source/inc/mysql/YCatalog.hxx +++ b/connectivity/source/inc/mysql/YCatalog.hxx @@ -16,14 +16,11 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YCATALOG_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YCATALOG_HXX +#pragma once #include <sdbcx/VCatalog.hxx> -namespace connectivity -{ - namespace mysql +namespace connectivity::mysql { // please don't name the class the same name as in another namespaces // some compilers have problems with this task as I noticed on windows @@ -57,8 +54,7 @@ namespace connectivity // ::cppu::OComponentHelper virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YCATALOG_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/mysql/YColumns.hxx b/connectivity/source/inc/mysql/YColumns.hxx index 9e2d49535149..1ffcfc95338b 100644 --- a/connectivity/source/inc/mysql/YColumns.hxx +++ b/connectivity/source/inc/mysql/YColumns.hxx @@ -16,14 +16,11 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YCOLUMNS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YCOLUMNS_HXX +#pragma once #include <connectivity/TColumnsHelper.hxx> #include <connectivity/sdbcx/VColumn.hxx> -namespace connectivity -{ - namespace mysql +namespace connectivity::mysql { class OMySQLColumns : public OColumnsHelper { @@ -53,8 +50,7 @@ namespace connectivity virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YCOLUMNS_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/mysql/YDriver.hxx b/connectivity/source/inc/mysql/YDriver.hxx index f4065dcc7fb0..84fad1af1c99 100644 --- a/connectivity/source/inc/mysql/YDriver.hxx +++ b/connectivity/source/inc/mysql/YDriver.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YDRIVER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YDRIVER_HXX +#pragma once #include <sal/config.h> @@ -25,7 +24,6 @@ #include <com/sun/star/sdbc/XDriver.hpp> #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/uno/XComponentContext.hpp> #include <cppuhelper/compbase.hxx> @@ -74,7 +72,7 @@ namespace connectivity @return The driver which was currently selected. */ - css::uno::Reference< css::sdbc::XDriver > loadDriver( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ); + css::uno::Reference< css::sdbc::XDriver > loadDriver( std::u16string_view url, const css::uno::Sequence< css::beans::PropertyValue >& info ); public: /** creates a new delegator for a mysql driver @@ -105,6 +103,4 @@ namespace connectivity } // namespace connectivity -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YDRIVER_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/mysql/YTable.hxx b/connectivity/source/inc/mysql/YTable.hxx index 00739de5ccf5..c891b7d7d95e 100644 --- a/connectivity/source/inc/mysql/YTable.hxx +++ b/connectivity/source/inc/mysql/YTable.hxx @@ -17,15 +17,16 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YTABLE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YTABLE_HXX +#pragma once + +#include <sal/config.h> + +#include <string_view> #include <connectivity/TTableHelper.hxx> #include <comphelper/IdPropArrayHelper.hxx> -namespace connectivity -{ - namespace mysql +namespace connectivity::mysql { class OMySQLTable; @@ -91,9 +92,6 @@ namespace connectivity // ODescriptor virtual void construct() override; - // css::lang::XUnoTunnel - virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; - static css::uno::Sequence< sal_Int8 > getUnoTunnelId(); // XAlterTable virtual void SAL_CALL alterColumnByName( const OUString& colName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; @@ -103,13 +101,12 @@ namespace connectivity // some methods to alter table structures void alterColumnType(sal_Int32 nNewType,const OUString& _rColName,const css::uno::Reference< css::beans::XPropertySet >& _xDescriptor); - void alterDefaultValue(const OUString& _sNewDefault,const OUString& _rColName); + void alterDefaultValue(std::u16string_view _sNewDefault,const OUString& _rColName); void dropDefaultValue(const OUString& _sNewDefault); virtual OUString getTypeCreatePattern() const override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YTABLE_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/mysql/YTables.hxx b/connectivity/source/inc/mysql/YTables.hxx index 5c960f5f0a62..3e3283ca96da 100644 --- a/connectivity/source/inc/mysql/YTables.hxx +++ b/connectivity/source/inc/mysql/YTables.hxx @@ -16,15 +16,13 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YTABLES_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YTABLES_HXX +#pragma once #include <connectivity/sdbcx/VCollection.hxx> #include <SQLStatementHelper.hxx> #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> -namespace connectivity -{ - namespace mysql +#include <utility> +namespace connectivity::mysql { class OTables final : public sdbcx::OCollection, public ::dbtools::ISQLStatementHelper @@ -40,9 +38,9 @@ namespace connectivity void createTable( const css::uno::Reference< css::beans::XPropertySet >& descriptor ); virtual OUString getNameForObject(const sdbcx::ObjectType& _xObject) override; public: - OTables(const css::uno::Reference< css::sdbc::XDatabaseMetaData >& _rMetaData,::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, + OTables(css::uno::Reference< css::sdbc::XDatabaseMetaData > _xMetaData, ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, const ::std::vector< OUString> &_rVector) : sdbcx::OCollection(_rParent, true, _rMutex, _rVector) - ,m_xMetaData(_rMetaData) + ,m_xMetaData(std::move(_xMetaData)) {} // only the name is identical to ::cppu::OComponentHelper @@ -59,8 +57,7 @@ namespace connectivity // ISQLStatementHelper virtual void addComment(const css::uno::Reference< css::beans::XPropertySet >& descriptor,OUStringBuffer& _rOut) override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YTABLES_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/mysql/YUser.hxx b/connectivity/source/inc/mysql/YUser.hxx index 3377d13fca86..1713f63bfb64 100644 --- a/connectivity/source/inc/mysql/YUser.hxx +++ b/connectivity/source/inc/mysql/YUser.hxx @@ -17,15 +17,12 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YUSER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YUSER_HXX +#pragma once #include <sdbcx/VUser.hxx> #include <com/sun/star/sdbc/XConnection.hpp> -namespace connectivity -{ - namespace mysql +namespace connectivity::mysql { typedef connectivity::sdbcx::OUser OUser_TYPEDEF; @@ -41,8 +38,8 @@ namespace connectivity public: virtual void refreshGroups() override; public: - OMySQLUser( const css::uno::Reference< css::sdbc::XConnection >& _xConnection); - OMySQLUser( const css::uno::Reference< css::sdbc::XConnection >& _xConnection,const OUString& Name); + OMySQLUser( css::uno::Reference< css::sdbc::XConnection > _xConnection); + OMySQLUser( css::uno::Reference< css::sdbc::XConnection > _xConnection, const OUString& Name); // XUser virtual void SAL_CALL changePassword( const OUString& objPassword, const OUString& newPassword ) override; @@ -70,8 +67,7 @@ namespace connectivity virtual void construct() override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YUSER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/mysql/YUsers.hxx b/connectivity/source/inc/mysql/YUsers.hxx index 69695ca642b6..e4b35c12e718 100644 --- a/connectivity/source/inc/mysql/YUsers.hxx +++ b/connectivity/source/inc/mysql/YUsers.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YUSERS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YUSERS_HXX +#pragma once #include <connectivity/sdbcx/VCollection.hxx> #include <com/sun/star/sdbc/XConnection.hpp> @@ -44,12 +43,10 @@ namespace connectivity OUsers( ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, const ::std::vector< OUString> &_rVector, - const css::uno::Reference< css::sdbc::XConnection >& _xConnection, + css::uno::Reference< css::sdbc::XConnection > _xConnection, connectivity::sdbcx::IRefreshableUsers* _pParent); }; } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YUSERS_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/mysql/YViews.hxx b/connectivity/source/inc/mysql/YViews.hxx index 05c47edcbc1b..2e9a1b25162a 100644 --- a/connectivity/source/inc/mysql/YViews.hxx +++ b/connectivity/source/inc/mysql/YViews.hxx @@ -16,14 +16,12 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YVIEWS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YVIEWS_HXX +#pragma once #include <connectivity/sdbcx/VCollection.hxx> #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> -namespace connectivity -{ - namespace mysql +#include <utility> +namespace connectivity::mysql { class OViews final : public sdbcx::OCollection { @@ -37,9 +35,9 @@ namespace connectivity void createView( const css::uno::Reference< css::beans::XPropertySet >& descriptor ); public: - OViews(const css::uno::Reference< css::sdbc::XDatabaseMetaData >& _rMetaData,::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, + OViews(css::uno::Reference< css::sdbc::XDatabaseMetaData > _xMetaData, ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, const ::std::vector< OUString> &_rVector) : sdbcx::OCollection(_rParent, true, _rMutex, _rVector) - ,m_xMetaData(_rMetaData) + ,m_xMetaData(std::move(_xMetaData)) ,m_bInDrop(false) {} @@ -48,8 +46,7 @@ namespace connectivity void dropByNameImpl(const OUString& elementName); }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_MYSQL_YVIEWS_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/OBoundParam.hxx b/connectivity/source/inc/odbc/OBoundParam.hxx index 0616760bfaeb..77d09ba29789 100644 --- a/connectivity/source/inc/odbc/OBoundParam.hxx +++ b/connectivity/source/inc/odbc/OBoundParam.hxx @@ -16,16 +16,14 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OBOUNDPARAM_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OBOUNDPARAM_HXX +#pragma once #include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/sdbc/DataType.hpp> #include <odbc/odbcbasedllapi.hxx> +#include <connectivity/odbc.hxx> -namespace connectivity -{ - namespace odbc +namespace connectivity::odbc { class OOO_DLLPUBLIC_ODBCBASE OBoundParam { @@ -124,8 +122,7 @@ namespace connectivity sal_Int32 paramInputStreamLen; // Length of input stream }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OBOUNDPARAM_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/OConnection.hxx b/connectivity/source/inc/odbc/OConnection.hxx index 8393b2c3173c..93875c66193c 100644 --- a/connectivity/source/inc/odbc/OConnection.hxx +++ b/connectivity/source/inc/odbc/OConnection.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OCONNECTION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OCONNECTION_HXX +#pragma once #include <com/sun/star/sdbc/SQLWarning.hpp> #include <com/sun/star/beans/PropertyValue.hpp> @@ -35,16 +34,14 @@ #include <map> -namespace connectivity -{ - namespace odbc +namespace connectivity::odbc { class ODBCDriver; typedef connectivity::OMetaConnection OConnection_BASE; typedef std::vector< ::connectivity::OTypeInfo> TTypeInfoVector; - class OOO_DLLPUBLIC_ODBCBASE OConnection final : + class OConnection final : public OConnection_BASE, public OAutoRetrievingBase { @@ -123,8 +120,7 @@ namespace connectivity // close and free the handle and set it to SQL_NULLHANDLE void freeStatementHandle(SQLHANDLE& _pHandle); }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OCONNECTION_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/ODatabaseMetaData.hxx b/connectivity/source/inc/odbc/ODatabaseMetaData.hxx index c4ad2c07551c..457d1e684206 100644 --- a/connectivity/source/inc/odbc/ODatabaseMetaData.hxx +++ b/connectivity/source/inc/odbc/ODatabaseMetaData.hxx @@ -17,22 +17,19 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_ODATABASEMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_ODATABASEMETADATA_HXX +#pragma once #include <odbc/OConnection.hxx> #include <odbc/odbcbasedllapi.hxx> #include <TDatabaseMetaDataBase.hxx> -namespace connectivity -{ - namespace odbc +namespace connectivity::odbc { //************ Class: ODatabaseMetaData - class OOO_DLLPUBLIC_ODBCBASE ODatabaseMetaData final : + class ODatabaseMetaData final : public ODatabaseMetaDataBase { SQLHANDLE m_aConnectionHandle; @@ -200,8 +197,7 @@ namespace connectivity virtual sal_Bool SAL_CALL supportsBatchUpdates( ) override; virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getUDTs( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& typeNamePattern, const css::uno::Sequence< sal_Int32 >& types ) override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_ODATABASEMETADATA_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/ODatabaseMetaDataResultSet.hxx b/connectivity/source/inc/odbc/ODatabaseMetaDataResultSet.hxx index 64d548a76b94..dc011f37802c 100644 --- a/connectivity/source/inc/odbc/ODatabaseMetaDataResultSet.hxx +++ b/connectivity/source/inc/odbc/ODatabaseMetaDataResultSet.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_ODATABASEMETADATARESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_ODATABASEMETADATARESULTSET_HXX +#pragma once #include <com/sun/star/sdbc/ResultSetType.hpp> #include <com/sun/star/sdbc/FetchDirection.hpp> @@ -39,10 +38,9 @@ #include <odbc/ODatabaseMetaData.hxx> #include <odbc/odbcbasedllapi.hxx> #include <memory> +#include <string_view> -namespace connectivity -{ - namespace odbc +namespace connectivity::odbc { /* ** java_sql_ResultSet @@ -55,7 +53,7 @@ namespace connectivity css::sdbc::XCloseable, css::sdbc::XColumnLocate> ODatabaseMetaDataResultSet_BASE; - class OOO_DLLPUBLIC_ODBCBASE ODatabaseMetaDataResultSet : + class ODatabaseMetaDataResultSet : public cppu::BaseMutex, public ODatabaseMetaDataResultSet_BASE, public ::cppu::OPropertySetHelper, @@ -124,8 +122,8 @@ namespace connectivity virtual void SAL_CALL disposing() override; // XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; // XPropertySet @@ -201,31 +199,31 @@ namespace connectivity /// @throws css::sdbc::SQLException /// @throws css::uno::RuntimeException void openTables(const css::uno::Any& catalog, const OUString& schemaPattern, - const OUString& tableNamePattern, const css::uno::Sequence< OUString >& types ); + std::u16string_view tableNamePattern, const css::uno::Sequence< OUString >& types ); /// @throws css::sdbc::SQLException /// @throws css::uno::RuntimeException void openColumnPrivileges( const css::uno::Any& catalog, const OUString& schema, - const OUString& table, const OUString& columnNamePattern ); + std::u16string_view table, std::u16string_view columnNamePattern ); /// @throws css::sdbc::SQLException /// @throws css::uno::RuntimeException void openColumns( const css::uno::Any& catalog, const OUString& schemaPattern, - const OUString& tableNamePattern, const OUString& columnNamePattern ); + std::u16string_view tableNamePattern, std::u16string_view columnNamePattern ); /// @throws css::sdbc::SQLException /// @throws css::uno::RuntimeException void openProcedureColumns( const css::uno::Any& catalog, const OUString& schemaPattern, - const OUString& procedureNamePattern,const OUString& columnNamePattern ); + std::u16string_view procedureNamePattern,std::u16string_view columnNamePattern ); /// @throws css::sdbc::SQLException /// @throws css::uno::RuntimeException void openProcedures( const css::uno::Any& catalog, const OUString& schemaPattern, - const OUString& procedureNamePattern); + std::u16string_view procedureNamePattern); /// @throws css::sdbc::SQLException /// @throws css::uno::RuntimeException void openVersionColumns(const css::uno::Any& catalog, const OUString& schema, - const OUString& table); + std::u16string_view table); /// @throws css::sdbc::SQLException /// @throws css::uno::RuntimeException void openBestRowIdentifier( const css::uno::Any& catalog, const OUString& schema, - const OUString& table,sal_Int32 scope, bool nullable ); + std::u16string_view table,sal_Int32 scope, bool nullable ); /// @throws css::sdbc::SQLException /// @throws css::uno::RuntimeException void openForeignKeys( const css::uno::Any& catalog, const OUString* schema,const OUString* table, @@ -238,26 +236,24 @@ namespace connectivity void openImportedKeys(const css::uno::Any& catalog, const OUString& schema,const OUString& table); /// @throws css::sdbc::SQLException /// @throws css::uno::RuntimeException - void openPrimaryKeys(const css::uno::Any& catalog, const OUString& schema,const OUString& table); + void openPrimaryKeys(const css::uno::Any& catalog, const OUString& schema,std::u16string_view table); /// @throws css::sdbc::SQLException /// @throws css::uno::RuntimeException void openTablePrivileges(const css::uno::Any& catalog, const OUString& schemaPattern, - const OUString& tableNamePattern); + std::u16string_view tableNamePattern); /// @throws css::sdbc::SQLException /// @throws css::uno::RuntimeException void openSpecialColumns(bool _bRowVer,const css::uno::Any& catalog, const OUString& schema, - const OUString& table,sal_Int32 scope, bool nullable ); + std::u16string_view table,sal_Int32 scope, bool nullable ); /// @throws css::sdbc::SQLException /// @throws css::uno::RuntimeException void openIndexInfo( const css::uno::Any& catalog, const OUString& schema, - const OUString& table,bool unique,bool approximate ); + std::u16string_view table,bool unique,bool approximate ); protected: using OPropertySetHelper::getFastPropertyValue; }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_ODATABASEMETADATARESULTSET_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/ODriver.hxx b/connectivity/source/inc/odbc/ODriver.hxx index 6172cd01aa89..6cba90648d6e 100644 --- a/connectivity/source/inc/odbc/ODriver.hxx +++ b/connectivity/source/inc/odbc/ODriver.hxx @@ -17,12 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_ODRIVER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_ODRIVER_HXX +#pragma once #include <com/sun/star/sdbc/XDriver.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> #include <cppuhelper/compbase.hxx> #include <connectivity/odbc.hxx> #include <odbc/odbcbasedllapi.hxx> @@ -30,9 +29,7 @@ #include <osl/module.h> #include <odbc/OTools.hxx> -namespace connectivity -{ - namespace odbc +namespace connectivity::odbc { typedef ::cppu::WeakComponentImplHelper< css::sdbc::XDriver, css::lang::XServiceInfo > ODriver_BASE; @@ -45,24 +42,19 @@ namespace connectivity // of all the Connection objects // for this Driver - css::uno::Reference< css::lang::XMultiServiceFactory > m_xORB; + css::uno::Reference< css::uno::XComponentContext > m_xContext; SQLHANDLE m_pDriverHandle; virtual SQLHANDLE EnvironmentHandle(OUString &_rPath) = 0; public: - ODBCDriver(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory); + ODBCDriver(css::uno::Reference< css::uno::XComponentContext > xContext); // only possibility to get the odbc functions virtual oslGenericFunction getOdbcFunction(ODBC3SQLFunctionId _nIndex) const = 0; // OComponentHelper virtual void SAL_CALL disposing() override; - // XInterface - /// @throws css::uno::RuntimeException - static OUString getImplementationName_Static( ); - /// @throws css::uno::RuntimeException - static css::uno::Sequence< OUString > getSupportedServiceNames_Static( ); // XServiceInfo virtual OUString SAL_CALL getImplementationName( ) override; @@ -76,12 +68,10 @@ namespace connectivity virtual sal_Int32 SAL_CALL getMajorVersion( ) override; virtual sal_Int32 SAL_CALL getMinorVersion( ) override; - const css::uno::Reference< css::lang::XMultiServiceFactory >& getORB() const { return m_xORB; } + const css::uno::Reference< css::uno::XComponentContext >& getContext() const { return m_xContext; } }; - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_ODRIVER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/OFunctions.hxx b/connectivity/source/inc/odbc/OFunctions.hxx index 95787a1db4d2..a44fe5a15031 100644 --- a/connectivity/source/inc/odbc/OFunctions.hxx +++ b/connectivity/source/inc/odbc/OFunctions.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OFUNCTIONS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OFUNCTIONS_HXX +#pragma once #include <connectivity/odbc.hxx> #include <rtl/ustring.hxx> @@ -524,7 +523,7 @@ bool LoadLibrary_ODBC3(OUString &_rPath); #define N3SQLGetCursorName(a,b,c,d) (*reinterpret_cast<T3SQLGetCursorName>(getOdbcFunction(ODBC3SQLFunctionId::GetCursorName)))(a,b,c,d) - typedef SQLRETURN (SQL_API *T3SQLNativeSql) ( SQLHSTMT ConnectionHandle, + typedef SQLRETURN (SQL_API *T3SQLNativeSql) ( SQLHDBC ConnectionHandle, SQLCHAR * InStatementText, SQLINTEGER TextLength1, SQLCHAR * OutStatementText, @@ -597,7 +596,5 @@ bool LoadLibrary_ODBC3(OUString &_rPath); extern T3SQLNativeSql pODBC3SQLNativeSql; } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OFUNCTIONS_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/OPreparedStatement.hxx b/connectivity/source/inc/odbc/OPreparedStatement.hxx index c593a859da33..aa5e895bfc79 100644 --- a/connectivity/source/inc/odbc/OPreparedStatement.hxx +++ b/connectivity/source/inc/odbc/OPreparedStatement.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OPREPAREDSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OPREPAREDSTATEMENT_HXX +#pragma once #include <odbc/odbcbasedllapi.hxx> #include <odbc/OStatement.hxx> @@ -29,9 +28,7 @@ #include <com/sun/star/io/XInputStream.hpp> #include <cppuhelper/implbase5.hxx> -namespace connectivity -{ - namespace odbc +namespace connectivity::odbc { class OBoundParam; @@ -41,7 +38,7 @@ namespace connectivity css::sdbc::XResultSetMetaDataSupplier, css::lang::XServiceInfo> OPreparedStatement_BASE; - class OOO_DLLPUBLIC_ODBCBASE OPreparedStatement final : + class OPreparedStatement final : public OStatement_BASE2, public OPreparedStatement_BASE { @@ -84,7 +81,7 @@ namespace connectivity /** creates the driver specific resultset (factory) */ - virtual OResultSet* createResulSet() override; + virtual rtl::Reference<OResultSet> createResultSet() override; virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any& rValue) override; @@ -98,8 +95,8 @@ namespace connectivity //XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; @@ -146,8 +143,7 @@ namespace connectivity using OStatement_Base::executeUpdate; using OStatement_Base::execute; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OPREPAREDSTATEMENT_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/OResultSet.hxx b/connectivity/source/inc/odbc/OResultSet.hxx index 960db182497a..719c6be14da8 100644 --- a/connectivity/source/inc/odbc/OResultSet.hxx +++ b/connectivity/source/inc/odbc/OResultSet.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_ORESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_ORESULTSET_HXX +#pragma once #include <com/sun/star/sdbc/FetchDirection.hpp> #include <com/sun/star/sdbc/XResultSet.hpp> @@ -42,9 +41,7 @@ #include <TSkipDeletedSet.hxx> #include <memory> -namespace connectivity -{ - namespace odbc +namespace connectivity::odbc { /* @@ -105,12 +102,12 @@ namespace connectivity typedef std::map< css::uno::Sequence<sal_Int8>, sal_Int32,TBookmarkPosMapCompare > TBookmarkPosMap; - class OOO_DLLPUBLIC_ODBCBASE OResultSet : - public cppu::BaseMutex, - public ::connectivity::IResultSetHelper, - public OResultSet_BASE, - public ::cppu::OPropertySetHelper, - public ::comphelper::OPropertyArrayUsageHelper<OResultSet> + class OResultSet : + public cppu::BaseMutex, + public ::connectivity::IResultSetHelper, + public OResultSet_BASE, + public ::cppu::OPropertySetHelper, + public ::comphelper::OPropertyArrayUsageHelper<OResultSet> { protected: TBookmarkPosMap m_aPosToBookmarks; @@ -250,8 +247,8 @@ namespace connectivity virtual void SAL_CALL disposing() override; // XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; //XTypeProvider virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; // XPropertySet @@ -350,9 +347,8 @@ namespace connectivity protected: using OPropertySetHelper::getFastPropertyValue; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_ORESULTSET_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/OResultSetMetaData.hxx b/connectivity/source/inc/odbc/OResultSetMetaData.hxx index b1ffb20ce639..76abe6eecd06 100644 --- a/connectivity/source/inc/odbc/OResultSetMetaData.hxx +++ b/connectivity/source/inc/odbc/OResultSetMetaData.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_ORESULTSETMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_ORESULTSETMETADATA_HXX +#pragma once #include <com/sun/star/sdbc/XResultSetMetaData.hpp> #include <cppuhelper/implbase.hxx> @@ -27,16 +26,14 @@ #include <vector> #include <odbc/OConnection.hxx> -namespace connectivity -{ - namespace odbc +namespace connectivity::odbc { //************ Class: ResultSetMetaData typedef ::cppu::WeakImplHelper< css::sdbc::XResultSetMetaData> OResultSetMetaData_BASE; - class OOO_DLLPUBLIC_ODBCBASE OResultSetMetaData final : + class OResultSetMetaData final : public OResultSetMetaData_BASE { std::vector<sal_Int32> m_vMapping; // when not every column is needed @@ -61,11 +58,11 @@ namespace connectivity ,m_nColCount(-1) ,m_bUseODBC2Types(false) {} - OResultSetMetaData(OConnection* _pConnection, SQLHANDLE _pStmt ,const std::vector<sal_Int32> & _vMapping) - :m_vMapping(_vMapping) + OResultSetMetaData(OConnection* _pConnection, SQLHANDLE _pStmt, std::vector<sal_Int32>&& _vMapping) + :m_vMapping(std::move(_vMapping)) ,m_aStatementHandle( _pStmt ) ,m_pConnection(_pConnection) - ,m_nColCount(_vMapping.size()-1) + ,m_nColCount(m_vMapping.size()-1) ,m_bUseODBC2Types(false) {} virtual ~OResultSetMetaData() override; @@ -113,8 +110,7 @@ namespace connectivity virtual sal_Bool SAL_CALL isDefinitelyWritable( sal_Int32 column ) override; virtual OUString SAL_CALL getColumnServiceName( sal_Int32 column ) override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_ORESULTSETMETADATA_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/OStatement.hxx b/connectivity/source/inc/odbc/OStatement.hxx index 5beaf9bb6fb3..2f0d0d814fea 100644 --- a/connectivity/source/inc/odbc/OStatement.hxx +++ b/connectivity/source/inc/odbc/OStatement.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OSTATEMENT_HXX +#pragma once #include <com/sun/star/sdbc/XStatement.hpp> #include <com/sun/star/sdbc/XWarningsSupplier.hpp> @@ -35,12 +34,11 @@ #include <odbc/OFunctions.hxx> #include <odbc/OConnection.hxx> #include <odbc/odbcbasedllapi.hxx> +#include <string_view> #include <vector> #include <com/sun/star/lang/XServiceInfo.hpp> -namespace connectivity -{ - namespace odbc +namespace connectivity::odbc { typedef ::cppu::WeakComponentImplHelper< css::sdbc::XStatement, @@ -54,11 +52,11 @@ namespace connectivity //************ Class: java.sql.Statement - class OOO_DLLPUBLIC_ODBCBASE OStatement_Base : - public cppu::BaseMutex, - public OStatement_BASE, - public ::cppu::OPropertySetHelper, - public ::comphelper::OPropertyArrayUsageHelper<OStatement_Base> + class OStatement_Base : + public cppu::BaseMutex, + public OStatement_BASE, + public ::cppu::OPropertySetHelper, + public ::comphelper::OPropertyArrayUsageHelper<OStatement_Base> { css::sdbc::SQLWarning m_aLastWarning; @@ -93,7 +91,7 @@ namespace connectivity void setMaxRows(sal_Int64 _par0) ; void setFetchDirection(sal_Int32 _par0) ; void setFetchSize(sal_Int32 _par0) ; - void setCursorName(const OUString &_par0); + void setCursorName(std::u16string_view _par0); void setEscapeProcessing( const bool _bEscapeProc ); template < typename T, SQLINTEGER BufferLength > SQLRETURN setStmtOption (SQLINTEGER fOption, T value) const; @@ -128,7 +126,7 @@ namespace connectivity /** creates the driver specific resultset (factory) */ - virtual OResultSet* createResulSet(); + virtual rtl::Reference<OResultSet> createResultSet(); /// @throws css::sdbc::SQLException /// @throws css::uno::RuntimeException @@ -167,8 +165,8 @@ namespace connectivity // OComponentHelper virtual void SAL_CALL disposing() override; // XInterface - virtual void SAL_CALL release() throw() override; - virtual void SAL_CALL acquire() throw() override; + virtual void SAL_CALL release() noexcept override; + virtual void SAL_CALL acquire() noexcept override; // XInterface virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; //XTypeProvider @@ -220,10 +218,10 @@ namespace connectivity virtual void SAL_CALL disposing() override; }; - class OOO_DLLPUBLIC_ODBCBASE OStatement : - public OStatement_BASE2, - public css::sdbc::XBatchExecution, - public css::lang::XServiceInfo + class OStatement : + public OStatement_BASE2, + public css::sdbc::XBatchExecution, + public css::lang::XServiceInfo { protected: virtual ~OStatement() override {} @@ -233,15 +231,14 @@ namespace connectivity DECLARE_SERVICE_INFO(); virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; - virtual void SAL_CALL acquire() throw() override; - virtual void SAL_CALL release() throw() override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; // XBatchExecution virtual void SAL_CALL addBatch( const OUString& sql ) override; virtual void SAL_CALL clearBatch( ) override; virtual css::uno::Sequence< sal_Int32 > SAL_CALL executeBatch( ) override; }; - } + } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OSTATEMENT_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/OTools.hxx b/connectivity/source/inc/odbc/OTools.hxx index 3f2fddb8178e..b03db91dce33 100644 --- a/connectivity/source/inc/odbc/OTools.hxx +++ b/connectivity/source/inc/odbc/OTools.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OTOOLS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OTOOLS_HXX +#pragma once #include <connectivity/odbc.hxx> #include <odbc/odbcbasedllapi.hxx> @@ -88,9 +87,7 @@ enum class ODBC3SQLFunctionId NativeSql = 54, }; -namespace connectivity -{ - namespace odbc +namespace connectivity::odbc { class OConnection; @@ -243,8 +240,6 @@ namespace connectivity } - } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OTOOLS_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/odbc/odbcbasedllapi.hxx b/connectivity/source/inc/odbc/odbcbasedllapi.hxx index 59619eee7014..bf7f5a486dc2 100644 --- a/connectivity/source/inc/odbc/odbcbasedllapi.hxx +++ b/connectivity/source/inc/odbc/odbcbasedllapi.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_ODBCBASEDLLAPI_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_ODBCBASEDLLAPI_HXX +#pragma once #include <sal/config.h> @@ -30,6 +29,4 @@ #define OOO_DLLPUBLIC_ODBCBASE SAL_DLLPUBLIC_IMPORT #endif -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/propertyids.hxx b/connectivity/source/inc/propertyids.hxx index 538fe88c586e..b10b4f008e64 100644 --- a/connectivity/source/inc/propertyids.hxx +++ b/connectivity/source/inc/propertyids.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_PROPERTYIDS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_PROPERTYIDS_HXX +#pragma once // this define has to be set to split the names into different dll's or so's // every dll has his own set of property names @@ -37,76 +36,76 @@ namespace dbtools }; } -#define PROPERTY_ID_QUERYTIMEOUT 1 -#define PROPERTY_ID_MAXFIELDSIZE 2 -#define PROPERTY_ID_MAXROWS 3 -#define PROPERTY_ID_CURSORNAME 4 -#define PROPERTY_ID_RESULTSETCONCURRENCY 5 -#define PROPERTY_ID_RESULTSETTYPE 6 -#define PROPERTY_ID_FETCHDIRECTION 7 -#define PROPERTY_ID_FETCHSIZE 8 -#define PROPERTY_ID_ESCAPEPROCESSING 9 -#define PROPERTY_ID_USEBOOKMARKS 10 -// Column -#define PROPERTY_ID_NAME 11 -#define PROPERTY_ID_TYPE 12 -#define PROPERTY_ID_TYPENAME 13 -#define PROPERTY_ID_PRECISION 14 -#define PROPERTY_ID_SCALE 15 -#define PROPERTY_ID_ISNULLABLE 16 -#define PROPERTY_ID_ISAUTOINCREMENT 17 -#define PROPERTY_ID_ISROWVERSION 18 -#define PROPERTY_ID_DESCRIPTION 19 -#define PROPERTY_ID_DEFAULTVALUE 20 +enum PropertyId +{ + PROPERTY_ID_QUERYTIMEOUT = 1, + PROPERTY_ID_MAXFIELDSIZE = 2, + PROPERTY_ID_MAXROWS = 3, + PROPERTY_ID_CURSORNAME = 4, + PROPERTY_ID_RESULTSETCONCURRENCY = 5, + PROPERTY_ID_RESULTSETTYPE = 6, + PROPERTY_ID_FETCHDIRECTION = 7, + PROPERTY_ID_FETCHSIZE = 8, + PROPERTY_ID_ESCAPEPROCESSING = 9, + PROPERTY_ID_USEBOOKMARKS = 10, -#define PROPERTY_ID_REFERENCEDTABLE 21 -#define PROPERTY_ID_UPDATERULE 22 -#define PROPERTY_ID_DELETERULE 23 -#define PROPERTY_ID_CATALOG 24 -#define PROPERTY_ID_ISUNIQUE 25 -#define PROPERTY_ID_ISPRIMARYKEYINDEX 26 -#define PROPERTY_ID_ISCLUSTERED 27 -#define PROPERTY_ID_ISASCENDING 28 -#define PROPERTY_ID_SCHEMANAME 29 -#define PROPERTY_ID_CATALOGNAME 30 + // Column + PROPERTY_ID_NAME = 11, + PROPERTY_ID_TYPE = 12, + PROPERTY_ID_TYPENAME = 13, + PROPERTY_ID_PRECISION = 14, + PROPERTY_ID_SCALE = 15, + PROPERTY_ID_ISNULLABLE = 16, + PROPERTY_ID_ISAUTOINCREMENT = 17, + PROPERTY_ID_ISROWVERSION = 18, + PROPERTY_ID_DESCRIPTION = 19, + PROPERTY_ID_DEFAULTVALUE = 20, -#define PROPERTY_ID_COMMAND 31 -#define PROPERTY_ID_CHECKOPTION 32 -#define PROPERTY_ID_PASSWORD 33 -#define PROPERTY_ID_RELATEDCOLUMN 34 + PROPERTY_ID_REFERENCEDTABLE = 21, + PROPERTY_ID_UPDATERULE = 22, + PROPERTY_ID_DELETERULE = 23, + PROPERTY_ID_CATALOG = 24, + PROPERTY_ID_ISUNIQUE = 25, + PROPERTY_ID_ISPRIMARYKEYINDEX = 26, + PROPERTY_ID_ISCLUSTERED = 27, + PROPERTY_ID_ISASCENDING = 28, + PROPERTY_ID_SCHEMANAME = 29, + PROPERTY_ID_CATALOGNAME = 30, -#define PROPERTY_ID_FUNCTION 35 -#define PROPERTY_ID_TABLENAME 36 -#define PROPERTY_ID_REALNAME 37 -#define PROPERTY_ID_DBASEPRECISIONCHANGED 38 -#define PROPERTY_ID_ISCURRENCY 39 -#define PROPERTY_ID_ISBOOKMARKABLE 40 + PROPERTY_ID_COMMAND = 31, + PROPERTY_ID_CHECKOPTION = 32, + PROPERTY_ID_PASSWORD = 33, + PROPERTY_ID_RELATEDCOLUMN = 34, -#define PROPERTY_ID_INVALID_INDEX 41 -#define PROPERTY_ID_HY010 43 -#define PROPERTY_ID_LABEL 44 -#define PROPERTY_ID_DELIMITER 45 -#define PROPERTY_ID_FORMATKEY 46 -#define PROPERTY_ID_LOCALE 47 -#define PROPERTY_ID_IM001 48 + PROPERTY_ID_FUNCTION = 35, + PROPERTY_ID_TABLENAME = 36, + PROPERTY_ID_REALNAME = 37, + PROPERTY_ID_DBASEPRECISIONCHANGED = 38, + PROPERTY_ID_ISCURRENCY = 39, + PROPERTY_ID_ISBOOKMARKABLE = 40, -#define PROPERTY_ID_AUTOINCREMENTCREATION 49 + PROPERTY_ID_HY010 = 41, + PROPERTY_ID_LABEL = 42, + PROPERTY_ID_DELIMITER = 43, + PROPERTY_ID_FORMATKEY = 44, + PROPERTY_ID_LOCALE = 45, -#define PROPERTY_ID_PRIVILEGES 50 -#define PROPERTY_ID_HAVINGCLAUSE 51 + PROPERTY_ID_AUTOINCREMENTCREATION = 46, -#define PROPERTY_ID_ISSIGNED 52 -#define PROPERTY_ID_AGGREGATEFUNCTION 53 -#define PROPERTY_ID_ISSEARCHABLE 54 + PROPERTY_ID_PRIVILEGES = 47, + PROPERTY_ID_HAVINGCLAUSE = 48, -#define PROPERTY_ID_APPLYFILTER 55 -#define PROPERTY_ID_FILTER 56 -#define PROPERTY_ID_MASTERFIELDS 57 -#define PROPERTY_ID_DETAILFIELDS 58 -#define PROPERTY_ID_FIELDTYPE 59 -#define PROPERTY_ID_VALUE 60 -#define PROPERTY_ID_ACTIVE_CONNECTION 61 + PROPERTY_ID_ISSIGNED = 49, + PROPERTY_ID_AGGREGATEFUNCTION = 50, + PROPERTY_ID_ISSEARCHABLE = 51, -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_PROPERTYIDS_HXX + PROPERTY_ID_APPLYFILTER = 52, + PROPERTY_ID_FILTER = 53, + PROPERTY_ID_MASTERFIELDS = 54, + PROPERTY_ID_DETAILFIELDS = 55, + PROPERTY_ID_FIELDTYPE = 56, + PROPERTY_ID_VALUE = 57, + PROPERTY_ID_ACTIVE_CONNECTION = 58 +}; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/resource/sharedresources.hxx b/connectivity/source/inc/resource/sharedresources.hxx index bc4c1aecaa06..0c439cdf24e3 100644 --- a/connectivity/source/inc/resource/sharedresources.hxx +++ b/connectivity/source/inc/resource/sharedresources.hxx @@ -17,13 +17,12 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_RESOURCE_SHAREDRESOURCES_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_RESOURCE_SHAREDRESOURCES_HXX +#pragma once #include <rtl/ustring.hxx> #include <vector> #include <connectivity/dbtoolsdllapi.hxx> - +#include <unotools/resmgr.hxx> namespace connectivity { @@ -48,7 +47,7 @@ namespace connectivity */ OUString getResourceString( - const char* pResId + TranslateId pResId ) const; /** loads a string from the shared resource file, and replaces @@ -66,7 +65,7 @@ namespace connectivity */ OUString getResourceStringWithSubstitution( - const char* pResId, + TranslateId pResId, const char* _pAsciiPatternToReplace, const OUString& _rStringToSubstitute ) const; @@ -90,7 +89,7 @@ namespace connectivity */ OUString getResourceStringWithSubstitution( - const char* pResId, + TranslateId pResId, const char* _pAsciiPatternToReplace1, const OUString& _rStringToSubstitute1, const char* _pAsciiPatternToReplace2, @@ -120,7 +119,7 @@ namespace connectivity */ OUString getResourceStringWithSubstitution( - const char* pResId, + TranslateId pResId, const char* _pAsciiPatternToReplace1, const OUString& _rStringToSubstitute1, const char* _pAsciiPatternToReplace2, @@ -139,7 +138,7 @@ namespace connectivity @return the string from the resource file, with applied string substitution */ - OUString getResourceStringWithSubstitution( const char* pResId, + OUString getResourceStringWithSubstitution( TranslateId pResId, const std::vector< std::pair<const char* , OUString > >& _rStringToSubstitutes) const; }; @@ -147,6 +146,4 @@ namespace connectivity } // namespace connectivity -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_RESOURCE_SHAREDRESOURCES_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/writer/WCatalog.hxx b/connectivity/source/inc/writer/WCatalog.hxx index a6d8bd93d504..be61dbabd1e0 100644 --- a/connectivity/source/inc/writer/WCatalog.hxx +++ b/connectivity/source/inc/writer/WCatalog.hxx @@ -17,14 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WCATALOG_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WCATALOG_HXX +#pragma once #include <file/FCatalog.hxx> -namespace connectivity -{ -namespace writer +namespace connectivity::writer { class OWriterConnection; class OWriterCatalog : public file::OFileCatalog @@ -35,9 +32,6 @@ public: OWriterCatalog(OWriterConnection* pConnection); }; -} // namespace writer -} // namespace connectivity - -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WCATALOG_HXX +} // namespace connectivity::writer /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/writer/WConnection.hxx b/connectivity/source/inc/writer/WConnection.hxx index a526d0e1e720..5ae8b2818e0f 100644 --- a/connectivity/source/inc/writer/WConnection.hxx +++ b/connectivity/source/inc/writer/WConnection.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WCONNECTION_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WCONNECTION_HXX +#pragma once #include <memory> #include <file/FConnection.hxx> @@ -27,37 +26,25 @@ #include <rtl/ref.hxx> #include <unotools/closeveto.hxx> -namespace com -{ -namespace sun -{ -namespace star -{ -namespace text +namespace com::sun::star::text { class XTextDocument; } -} -} -} - namespace utl { class CloseVeto; } -namespace connectivity -{ -namespace writer +namespace connectivity::writer { class ODriver; class OWriterConnection : public file::OConnection { - // the spreadsheet document: + // the text document: css::uno::Reference<css::text::XTextDocument> m_xDoc; OUString m_sPassword; OUString m_aFileName; - oslInterlockedCount m_nDocCount; + oslInterlockedCount m_nDocCount = 0; class CloseVetoButTerminateListener : public cppu::WeakComponentImplHelper<css::frame::XTerminateListener> @@ -163,8 +150,5 @@ public: }; }; } -} - -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WCONNECTION_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/writer/WDatabaseMetaData.hxx b/connectivity/source/inc/writer/WDatabaseMetaData.hxx index b2d85cfa3050..b464be11c46b 100644 --- a/connectivity/source/inc/writer/WDatabaseMetaData.hxx +++ b/connectivity/source/inc/writer/WDatabaseMetaData.hxx @@ -17,14 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WDATABASEMETADATA_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WDATABASEMETADATA_HXX +#pragma once #include <component/CDatabaseMetaData.hxx> -namespace connectivity -{ -namespace writer +namespace connectivity::writer { class OWriterDatabaseMetaData : public component::OComponentDatabaseMetaData { @@ -41,9 +38,6 @@ public: OWriterDatabaseMetaData(file::OConnection* pConnection); }; -} // namespace writer -} // namespace connectivity - -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WDATABASEMETADATA_HXX +} // namespace connectivity::writer /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/writer/WDriver.hxx b/connectivity/source/inc/writer/WDriver.hxx index d719111b2cbf..b43168eac9a8 100644 --- a/connectivity/source/inc/writer/WDriver.hxx +++ b/connectivity/source/inc/writer/WDriver.hxx @@ -17,28 +17,16 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WDRIVER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WDRIVER_HXX +#pragma once #include <file/FDriver.hxx> -namespace com -{ -namespace sun -{ -namespace star -{ -namespace lang +namespace com::sun::star::lang { class XMultiServiceFactory; } -} -} -} -namespace connectivity -{ -namespace writer +namespace connectivity::writer { class ODriver : public file::OFileDriver { @@ -60,8 +48,5 @@ public: const OUString& url, const css::uno::Sequence<css::beans::PropertyValue>& info) override; }; } -} - -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WDRIVER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/writer/WTable.hxx b/connectivity/source/inc/writer/WTable.hxx index fa533e1e34da..46ee5412e0a6 100644 --- a/connectivity/source/inc/writer/WTable.hxx +++ b/connectivity/source/inc/writer/WTable.hxx @@ -17,42 +17,20 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WTABLE_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WTABLE_HXX +#pragma once #include <component/CTable.hxx> -namespace com -{ -namespace sun -{ -namespace star -{ -namespace text +namespace com::sun::star::text { class XTextTable; } -} -} -} - -namespace com -{ -namespace sun -{ -namespace star -{ -namespace util +namespace com::sun::star::util { class XNumberFormats; } -} -} -} -namespace connectivity -{ -namespace writer +namespace connectivity::writer { using OWriterTable_BASE = component::OComponentTable; class OWriterConnection; @@ -62,9 +40,9 @@ class OWriterTable : public OWriterTable_BASE private: css::uno::Reference<css::text::XTextTable> m_xTable; OWriterConnection* m_pWriterConnection; - sal_Int32 m_nStartCol; - sal_Int32 m_nDataCols; - bool m_bHasHeaders; + sal_Int32 m_nStartCol = 0; + sal_Int32 m_nDataCols = 0; + bool m_bHasHeaders = false; void fillColumns(); @@ -76,16 +54,9 @@ public: void SAL_CALL disposing() override; - // css::lang::XUnoTunnel - sal_Int64 SAL_CALL getSomething(const css::uno::Sequence<sal_Int8>& rId) override; - static css::uno::Sequence<sal_Int8> getUnoTunnelId(); - void construct() override; }; -} // namespace writer -} // namespace connectivity - -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WTABLE_HXX +} // namespace connectivity::writer /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/writer/WTables.hxx b/connectivity/source/inc/writer/WTables.hxx index 5477d89e0e19..df39cc1c22ce 100644 --- a/connectivity/source/inc/writer/WTables.hxx +++ b/connectivity/source/inc/writer/WTables.hxx @@ -17,14 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WTABLES_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WTABLES_HXX +#pragma once #include <file/FTables.hxx> -namespace connectivity -{ -namespace writer +namespace connectivity::writer { using OWriterTables_BASE = file::OTables; @@ -42,8 +39,5 @@ public: } }; } -} - -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WTABLES_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/manager/mdrivermanager.cxx b/connectivity/source/manager/mdrivermanager.cxx index 3f66e0606baa..ed09cc3c816e 100644 --- a/connectivity/source/manager/mdrivermanager.cxx +++ b/connectivity/source/manager/mdrivermanager.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <config_fuzzers.h> #include "mdrivermanager.hxx" #include <com/sun/star/configuration/theDefaultProvider.hpp> @@ -26,14 +27,15 @@ #include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/logging/LogLevel.hpp> -#include <tools/diagnose_ex.h> -#include <comphelper/processfactory.hxx> +#include <comphelper/diagnose_ex.hxx> #include <cppuhelper/implbase.hxx> #include <cppuhelper/supportsservice.hxx> +#include <cppuhelper/weak.hxx> #include <osl/diagnose.h> #include <algorithm> #include <iterator> +#include <utility> #include <vector> namespace drivermanager @@ -47,13 +49,7 @@ using namespace ::com::sun::star::container; using namespace ::com::sun::star::logging; using namespace ::osl; -#define SERVICE_SDBC_DRIVER "com.sun.star.sdbc.Driver" - -/// @throws NoSuchElementException -static void throwNoSuchElementException() -{ - throw NoSuchElementException(); -} +constexpr OUStringLiteral SERVICE_SDBC_DRIVER = u"com.sun.star.sdbc.Driver"; class ODriverEnumeration : public ::cppu::WeakImplHelper< XEnumeration > { @@ -67,7 +63,7 @@ class ODriverEnumeration : public ::cppu::WeakImplHelper< XEnumeration > protected: virtual ~ODriverEnumeration() override; public: - explicit ODriverEnumeration(const DriverArray& _rDriverSequence); + explicit ODriverEnumeration(DriverArray&& _rDriverSequence); // XEnumeration virtual sal_Bool SAL_CALL hasMoreElements( ) override; @@ -75,8 +71,8 @@ public: }; -ODriverEnumeration::ODriverEnumeration(const DriverArray& _rDriverSequence) - :m_aDrivers( _rDriverSequence ) +ODriverEnumeration::ODriverEnumeration(DriverArray&& _rDriverSequence) + :m_aDrivers( std::move(_rDriverSequence) ) ,m_aPos( m_aDrivers.begin() ) { } @@ -96,13 +92,13 @@ sal_Bool SAL_CALL ODriverEnumeration::hasMoreElements( ) Any SAL_CALL ODriverEnumeration::nextElement( ) { if ( !hasMoreElements() ) - throwNoSuchElementException(); + throw NoSuchElementException(); - return makeAny( *m_aPos++ ); + return Any( *m_aPos++ ); } - namespace { - +namespace +{ /// an STL functor which ensures that a SdbcDriver described by a DriverAccess is loaded struct EnsureDriver { @@ -112,23 +108,23 @@ Any SAL_CALL ODriverEnumeration::nextElement( ) const DriverAccess& operator()( const DriverAccess& _rDescriptor ) const { // we did not load this driver, yet - if (!_rDescriptor.xDriver.is()) + if (_rDescriptor.xDriver.is()) + return _rDescriptor; + + // we have a factory for it + if (_rDescriptor.xComponentFactory.is()) { - // we have a factory for it - if (_rDescriptor.xComponentFactory.is()) + DriverAccess& rDesc = const_cast<DriverAccess&>(_rDescriptor); + try { - DriverAccess& rDesc = const_cast<DriverAccess&>(_rDescriptor); - try - { - //load driver - rDesc.xDriver.set( - rDesc.xComponentFactory->createInstanceWithContext(mxContext), css::uno::UNO_QUERY); - } - catch (const Exception&) - { - //failure, abandon driver - rDesc.xComponentFactory.clear(); - } + //load driver + rDesc.xDriver.set( + rDesc.xComponentFactory->createInstanceWithContext(mxContext), css::uno::UNO_QUERY); + } + catch (const Exception&) + { + //failure, abandon driver + rDesc.xComponentFactory.clear(); } } return _rDescriptor; @@ -156,26 +152,14 @@ Any SAL_CALL ODriverEnumeration::nextElement( ) }; // predicate for checking whether or not a driver accepts a given URL - class AcceptsURL + bool AcceptsURL( const OUString& _rURL, const Reference<XDriver>& _rDriver ) { - protected: - const OUString& m_rURL; - - public: - // ctor - explicit AcceptsURL( const OUString& _rURL ) : m_rURL( _rURL ) { } - - - bool operator()( const Reference<XDriver>& _rDriver ) const - { - // ask the driver - return _rDriver.is() && _rDriver->acceptsURL( m_rURL ); - } - }; - + // ask the driver + return _rDriver.is() && _rDriver->acceptsURL( _rURL ); } - static sal_Int32 lcl_getDriverPrecedence( const Reference<XComponentContext>& _rContext, Sequence< OUString >& _rPrecedence ) +#if !ENABLE_FUZZERS + sal_Int32 lcl_getDriverPrecedence( const Reference<XComponentContext>& _rContext, Sequence< OUString >& _rPrecedence ) { _rPrecedence.realloc( 0 ); try @@ -185,8 +169,8 @@ Any SAL_CALL ODriverEnumeration::nextElement( ) css::configuration::theDefaultProvider::get( _rContext ) ); // one argument for creating the node access: the path to the configuration node - Sequence< Any > aCreationArgs(1); - aCreationArgs[0] <<= NamedValue( "nodepath", makeAny( OUString("org.openoffice.Office.DataAccess/DriverManager") ) ); + Sequence< Any > aCreationArgs{ Any(NamedValue( + "nodepath", Any( OUString("org.openoffice.Office.DataAccess/DriverManager") ) )) }; // create the node access Reference< XNameAccess > xDriverManagerNode( @@ -209,10 +193,9 @@ Any SAL_CALL ODriverEnumeration::nextElement( ) return _rPrecedence.getLength(); } +#endif - namespace { - - /// an STL argorithm compatible predicate comparing two DriverAccess instances by their implementation names + /// an STL algorithm compatible predicate comparing two DriverAccess instances by their implementation names struct CompareDriverAccessByName { @@ -222,22 +205,22 @@ Any SAL_CALL ODriverEnumeration::nextElement( ) } }; - /// and STL argorithm compatible predicate comparing a DriverAccess' impl name to a string + /// and an STL algorithm compatible predicate comparing the impl name of a DriverAccess to a string struct EqualDriverAccessToName { OUString m_sImplName; - explicit EqualDriverAccessToName(const OUString& _sImplName) : m_sImplName(_sImplName){} + explicit EqualDriverAccessToName(OUString _sImplName) : m_sImplName(std::move(_sImplName)){} bool operator()( const DriverAccess& lhs) { return lhs.sImplementationName == m_sImplName; } }; - - } +} OSDBCDriverManager::OSDBCDriverManager( const Reference< XComponentContext >& _rxContext ) - :m_xContext( _rxContext ) + :OSDBCDriverManager_Base(m_aMutex) + ,m_xContext( _rxContext ) ,m_aEventLogger( _rxContext, "org.openoffice.logging.sdbc.DriverManager" ) ,m_aDriverConfig(m_xContext) ,m_nLoginTimeout(0) @@ -300,7 +283,7 @@ void OSDBCDriverManager::bootstrapDrivers() if ( xDriver.is() ) { aDriverDescriptor.xDriver = xDriver; - // and obtain it's implementation name + // and obtain its implementation name xSI.set(xDriver, css::uno::UNO_QUERY); OSL_ENSURE( xSI.is(), "OSDBCDriverManager::bootstrapDrivers: a driver without service info?" ); if ( xSI.is() ) @@ -327,6 +310,7 @@ void OSDBCDriverManager::bootstrapDrivers() void OSDBCDriverManager::initializeDriverPrecedence() { +#if !ENABLE_FUZZERS if ( m_aDriversBS.empty() ) // nothing to do return; @@ -359,7 +343,7 @@ void OSDBCDriverManager::initializeDriverPrecedence() // at the moment this is the first of all drivers we know // loop through the names in the precedence order - for ( const OUString& rDriverOrder : std::as_const(aDriverOrder) ) + for (const OUString& rDriverOrder : aDriverOrder) { if (aNoPrefDriversStart == m_aDriversBS.end()) break; @@ -392,8 +376,9 @@ void OSDBCDriverManager::initializeDriverPrecedence() } catch (Exception&) { - OSL_FAIL("OSDBCDriverManager::initializeDriverPrecedence: caught an exception while sorting the drivers!"); + TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "OSDBCDriverManager::initializeDriverPrecedence: caught an exception while sorting the drivers!"); } +#endif } @@ -488,7 +473,7 @@ Reference< XEnumeration > SAL_CALL OSDBCDriverManager::createEnumeration( ) ExtractDriverFromCollectionElement() // transformation to apply (extract a driver from a driver access) ); - return new ODriverEnumeration( aDrivers ); + return new ODriverEnumeration( std::move(aDrivers) ); } @@ -507,7 +492,7 @@ sal_Bool SAL_CALL OSDBCDriverManager::hasElements( ) OUString SAL_CALL OSDBCDriverManager::getImplementationName( ) { - return getImplementationName_static(); + return "com.sun.star.comp.sdbc.OSDBCDriverManager"; } sal_Bool SAL_CALL OSDBCDriverManager::supportsService( const OUString& _rServiceName ) @@ -518,31 +503,7 @@ sal_Bool SAL_CALL OSDBCDriverManager::supportsService( const OUString& _rService Sequence< OUString > SAL_CALL OSDBCDriverManager::getSupportedServiceNames( ) { - return getSupportedServiceNames_static(); -} - - -Reference< XInterface > OSDBCDriverManager::Create( const Reference< XMultiServiceFactory >& _rxFactory ) -{ - return *( new OSDBCDriverManager( comphelper::getComponentContext(_rxFactory) ) ); -} - - -OUString OSDBCDriverManager::getImplementationName_static( ) -{ - return "com.sun.star.comp.sdbc.OSDBCDriverManager"; -} - - -Sequence< OUString > OSDBCDriverManager::getSupportedServiceNames_static( ) -{ - return { getSingletonName_static() }; -} - - -OUString OSDBCDriverManager::getSingletonName_static( ) -{ - return "com.sun.star.sdbc.DriverManager"; + return { "com.sun.star.sdbc.DriverManager" }; } @@ -551,9 +512,9 @@ Reference< XInterface > SAL_CALL OSDBCDriverManager::getRegisteredObject( const MutexGuard aGuard(m_aMutex); DriverCollection::const_iterator aSearch = m_aDriversRT.find(_rName); if (aSearch == m_aDriversRT.end()) - throwNoSuchElementException(); + throw NoSuchElementException(); - return aSearch->second.get(); + return aSearch->second; } @@ -593,7 +554,7 @@ void SAL_CALL OSDBCDriverManager::revokeObject( const OUString& _rName ) DriverCollection::iterator aSearch = m_aDriversRT.find(_rName); if (aSearch == m_aDriversRT.end()) - throwNoSuchElementException(); + throw NoSuchElementException(); m_aDriversRT.erase(aSearch); // we already have the iterator so we could use it @@ -630,8 +591,8 @@ Reference< XDriver > OSDBCDriverManager::implGetDriverForURL(const OUString& _rU { const OUString sDriverFactoryName = m_aDriverConfig.getDriverFactoryName(_rURL); - EqualDriverAccessToName aEqual(sDriverFactoryName); - DriverAccessArray::const_iterator aFind = std::find_if(m_aDriversBS.begin(),m_aDriversBS.end(),aEqual); + DriverAccessArray::const_iterator aFind = std::find_if(m_aDriversBS.begin(), m_aDriversBS.end(), + EqualDriverAccessToName(sDriverFactoryName)); if ( aFind == m_aDriversBS.end() ) { // search all bootstrapped drivers @@ -640,9 +601,16 @@ Reference< XDriver > OSDBCDriverManager::implGetDriverForURL(const OUString& _rU m_aDriversBS.end(), // end of search range [&_rURL, this] (const DriverAccessArray::value_type& driverAccess) { // extract the driver from the access, then ask the resulting driver for acceptance +#if defined __GNUC__ && !defined __clang__ && __GNUC__ >= 13 && __GNUC__ <= 14 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdangling-reference" +#endif const DriverAccess& ensuredAccess = EnsureDriver(m_xContext)(driverAccess); +#if defined __GNUC__ && !defined __clang__ && __GNUC__ >= 13 && __GNUC__ <= 14 +#pragma GCC diagnostic pop +#endif const Reference<XDriver> driver = ExtractDriverFromAccess()(ensuredAccess); - return AcceptsURL(_rURL)(driver); + return AcceptsURL(_rURL, driver); }); } // if ( m_aDriversBS.find(sDriverFactoryName ) == m_aDriversBS.end() ) else @@ -665,7 +633,7 @@ Reference< XDriver > OSDBCDriverManager::implGetDriverForURL(const OUString& _rU [&_rURL] (const DriverCollection::value_type& element) { // extract the driver from the collection element, then ask the resulting driver for acceptance const Reference<XDriver> driver = ExtractDriverFromCollectionElement()(element); - return AcceptsURL(_rURL)(driver); + return AcceptsURL(_rURL, driver); }); if ( m_aDriversRT.end() != aPos ) @@ -677,4 +645,12 @@ Reference< XDriver > OSDBCDriverManager::implGetDriverForURL(const OUString& _rU } // namespace drivermanager +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +connectivity_OSDBCDriverManager_get_implementation( + css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&) +{ + return cppu::acquire(new drivermanager::OSDBCDriverManager(context)); +} + + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/manager/mdrivermanager.hxx b/connectivity/source/manager/mdrivermanager.hxx index 21e7bb5df7ac..239116f1ccc7 100644 --- a/connectivity/source/manager/mdrivermanager.hxx +++ b/connectivity/source/manager/mdrivermanager.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_MANAGER_MDRIVERMANAGER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_MANAGER_MDRIVERMANAGER_HXX +#pragma once #include <sal/config.h> @@ -26,14 +25,13 @@ #include <vector> #include <com/sun/star/sdbc/XDriverManager2.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/uno/XNamingService.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XSingleComponentFactory.hpp> -#include <cppuhelper/implbase.hxx> +#include <cppuhelper/basemutex.hxx> +#include <cppuhelper/compbase.hxx> #include <comphelper/logging.hxx> -#include <osl/mutex.hxx> #include <connectivity/DriversConfig.hxx> namespace drivermanager @@ -51,16 +49,15 @@ namespace drivermanager // OSDBCDriverManager - the one-instance service for managing SDBC drivers - typedef ::cppu::WeakImplHelper< css::sdbc::XDriverManager2 + typedef ::cppu::WeakComponentImplHelper< css::sdbc::XDriverManager2 , css::lang::XServiceInfo , css::uno::XNamingService > OSDBCDriverManager_Base; - class OSDBCDriverManager final : public OSDBCDriverManager_Base + class OSDBCDriverManager final : public cppu::BaseMutex, public OSDBCDriverManager_Base { friend class ODriverEnumeration; - ::osl::Mutex m_aMutex; css::uno::Reference<css::uno::XComponentContext> m_xContext; ::comphelper::EventLogger m_aEventLogger; @@ -75,12 +72,12 @@ namespace drivermanager ::connectivity::DriversConfig m_aDriverConfig; sal_Int32 m_nLoginTimeout; + public: + explicit OSDBCDriverManager( const css::uno::Reference< css::uno::XComponentContext >& _rxContext ); virtual ~OSDBCDriverManager() override; - public: - // XDriverManager virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( const OUString& url ) override; virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnectionWithInfo( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; @@ -102,15 +99,6 @@ namespace drivermanager virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; - // XServiceInfo - static methods - /// @throws css::uno::RuntimeException - static OUString getImplementationName_static( ); - /// @throws css::uno::RuntimeException - static css::uno::Sequence< OUString > getSupportedServiceNames_static( ); - /// @throws css::uno::RuntimeException - static OUString getSingletonName_static( ); - static css::uno::Reference< css::uno::XInterface > Create( const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxContext ); - // XNamingService virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getRegisteredObject( const OUString& Name ) override; virtual void SAL_CALL registerObject( const OUString& Name, const css::uno::Reference< css::uno::XInterface >& Object ) override; @@ -129,7 +117,5 @@ namespace drivermanager } // namespace drivermanager -#endif // INCLUDED_CONNECTIVITY_SOURCE_MANAGER_MDRIVERMANAGER_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/manager/mregistration.cxx b/connectivity/source/manager/mregistration.cxx deleted file mode 100644 index c78d3ec6d786..000000000000 --- a/connectivity/source/manager/mregistration.cxx +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- 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 . - */ - - -#include "mdrivermanager.hxx" - -#include <cppuhelper/factory.hxx> -#include <com/sun/star/lang/XSingleServiceFactory.hpp> - -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::lang; - -extern "C" -{ - - -SAL_DLLPUBLIC_EXPORT void* sdbc2_component_getFactory(const char* _pImplName, void * _pServiceManager, void* /*_pRegistryKey*/) -{ - void* pRet = nullptr; - - if (::drivermanager::OSDBCDriverManager::getImplementationName_static().equalsAscii(_pImplName)) - { - Reference< XSingleServiceFactory > xFactory( - ::cppu::createOneInstanceFactory( - static_cast<css::lang::XMultiServiceFactory *>( - _pServiceManager), - ::drivermanager::OSDBCDriverManager::getImplementationName_static(), - ::drivermanager::OSDBCDriverManager::Create, - ::drivermanager::OSDBCDriverManager::getSupportedServiceNames_static() - ) - ); - if (xFactory.is()) - { - xFactory->acquire(); - pRet = xFactory.get(); - } - } - - return pRet; -} - -} // extern "C" - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/manager/sdbc2.component b/connectivity/source/manager/sdbc2.component index b192bebad89d..b9433256aabf 100644 --- a/connectivity/source/manager/sdbc2.component +++ b/connectivity/source/manager/sdbc2.component @@ -18,8 +18,9 @@ --> <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" - prefix="sdbc2" xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="com.sun.star.comp.sdbc.OSDBCDriverManager"> + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.comp.sdbc.OSDBCDriverManager" + constructor="connectivity_OSDBCDriverManager_get_implementation" single-instance="true"> <service name="com.sun.star.sdbc.DriverManager"/> </implementation> </component> diff --git a/connectivity/source/parse/PColumn.cxx b/connectivity/source/parse/PColumn.cxx index cf9b17ee51df..5ada4136cc93 100644 --- a/connectivity/source/parse/PColumn.cxx +++ b/connectivity/source/parse/PColumn.cxx @@ -109,7 +109,7 @@ OParseColumn::OParseColumn( const OUString& Name, StringMap aColumnMap; for ( sal_Int32 i = 1; i <= nColumnCount; ++i ) { - OParseColumn* pColumn = createColumnForResultSet( _rxResMetaData, _rxDBMetaData, i,aColumnMap ); + rtl::Reference<OParseColumn> pColumn = createColumnForResultSet( _rxResMetaData, _rxDBMetaData, i,aColumnMap ); aReturn->push_back( pColumn ); if ( i_xQueryColumns.is() && i_xQueryColumns->hasByName(pColumn->getRealName()) ) { @@ -125,7 +125,7 @@ OParseColumn::OParseColumn( const OUString& Name, } -OParseColumn* OParseColumn::createColumnForResultSet( const Reference< XResultSetMetaData >& _rxResMetaData, +rtl::Reference<OParseColumn> OParseColumn::createColumnForResultSet( const Reference< XResultSetMetaData >& _rxResMetaData, const Reference< XDatabaseMetaData >& _rxDBMetaData, sal_Int32 _nColumnPos, StringMap& _rColumns ) { OUString sLabel = _rxResMetaData->getColumnLabel( _nColumnPos ); @@ -142,7 +142,7 @@ OParseColumn* OParseColumn::createColumnForResultSet( const Reference< XResultSe sLabel = sAlias; } _rColumns.emplace(sLabel,0); - OParseColumn* pColumn = new OParseColumn( + rtl::Reference<OParseColumn> pColumn = new OParseColumn( sLabel, _rxResMetaData->getColumnTypeName( _nColumnPos ), OUString(), diff --git a/connectivity/source/parse/internalnode.cxx b/connectivity/source/parse/internalnode.cxx index ccee05746a17..1906ad3d4625 100644 --- a/connectivity/source/parse/internalnode.cxx +++ b/connectivity/source/parse/internalnode.cxx @@ -33,7 +33,7 @@ OSQLInternalNode::OSQLInternalNode(const char* pNewValue, } -OSQLInternalNode::OSQLInternalNode(const OString &NewValue, +OSQLInternalNode::OSQLInternalNode(std::string_view NewValue, SQLNodeType eNodeType, sal_uInt32 nNodeID) :OSQLParseNode(NewValue,eNodeType,nNodeID) diff --git a/connectivity/source/parse/sqlbison.y b/connectivity/source/parse/sqlbison.y index d14f36e7794f..23de1cb772ab 100644 --- a/connectivity/source/parse/sqlbison.y +++ b/connectivity/source/parse/sqlbison.y @@ -44,7 +44,6 @@ #include <osl/diagnose.h> #include "connectivity/dbconversion.hxx" #include <rtl/ustrbuf.hxx> -#include <sal/macros.h> #include <sal/log.hxx> #if defined _MSC_VER @@ -74,9 +73,15 @@ inline connectivity::OSQLInternalNode* newNode(const OUString& _newValue, // yyi is the internal number of the rule that is currently being reduced // This can be mapped to external rule number via the yyrmap. +#if defined YYBISON && YYBISON >= 30800 +#define SQL_NEW_RULE newNode("", SQLNodeType::Rule, yyr1[yyrule]) +#define SQL_NEW_LISTRULE newNode("", SQLNodeType::ListRule, yyr1[yyrule]) +#define SQL_NEW_COMMALISTRULE newNode("", SQLNodeType::CommaListRule, yyr1[yyrule]) +#else #define SQL_NEW_RULE newNode("", SQLNodeType::Rule, yyr1[yyn]) #define SQL_NEW_LISTRULE newNode("", SQLNodeType::ListRule, yyr1[yyn]) #define SQL_NEW_COMMALISTRULE newNode("", SQLNodeType::CommaListRule, yyr1[yyn]) +#endif extern connectivity::OSQLParser* xxx_pGLOBAL_SQLPARSER; @@ -151,6 +156,7 @@ using namespace connectivity; %token <pParseNode> SQL_TOKEN_DAYNAME SQL_TOKEN_DAYOFMONTH SQL_TOKEN_DAYOFWEEK SQL_TOKEN_DAYOFYEAR SQL_TOKEN_EXTRACT %token <pParseNode> SQL_TOKEN_HOUR SQL_TOKEN_MILLISECOND SQL_TOKEN_MINUTE SQL_TOKEN_MONTH SQL_TOKEN_MONTHNAME SQL_TOKEN_NOW SQL_TOKEN_QUARTER SQL_TOKEN_DATEDIFF %token <pParseNode> SQL_TOKEN_SECOND SQL_TOKEN_TIMESTAMPADD SQL_TOKEN_TIMESTAMPDIFF SQL_TOKEN_TIMEVALUE SQL_TOKEN_WEEK SQL_TOKEN_WEEKDAY SQL_TOKEN_YEAR SQL_TOKEN_YEARDAY +%token <pParseNode> SQL_TOKEN_DATEADD /* numeric functions */ %token <pParseNode> SQL_TOKEN_ABS SQL_TOKEN_ACOS SQL_TOKEN_ASIN SQL_TOKEN_ATAN SQL_TOKEN_ATAN2 SQL_TOKEN_CEILING @@ -213,7 +219,7 @@ using namespace connectivity; %type <pParseNode> like_predicate opt_escape test_for_null null_predicate_part_2 in_predicate in_predicate_part_2 character_like_predicate_part_2 other_like_predicate_part_2 %type <pParseNode> all_or_any_predicate any_all_some existence_test subquery quantified_comparison_predicate_part_2 %type <pParseNode> scalar_exp_commalist parameter_ref literal parenthesized_boolean_value_expression -%type <pParseNode> column_ref data_type column cursor parameter range_variable user /*like_check*/ +%type <pParseNode> column_ref data_type column cursor parameter range_variable user /*like_check*/ datetime_unit /* new rules at OJ */ %type <pParseNode> derived_column as_clause table_name num_primary term num_value_exp %type <pParseNode> value_exp_primary num_value_fct unsigned_value_spec cast_spec set_fct_spec scalar_subquery @@ -227,12 +233,12 @@ using namespace connectivity; %type <pParseNode> datetime_primary datetime_value_fct time_zone time_zone_specifier /*interval_term*/ interval_qualifier %type <pParseNode> start_field non_second_datetime_field end_field single_datetime_field extract_field datetime_field time_zone_field %type <pParseNode> char_length_exp octet_length_exp bit_length_exp select_sublist string_value_exp -%type <pParseNode> char_value_exp concatenation char_factor char_primary string_value_fct char_substring_fct fold +%type <pParseNode> char_value_exp concatenation char_factor char_primary string_value_fct char_substring_fct %type <pParseNode> form_conversion char_translation trim_fct trim_operands trim_spec bit_value_fct bit_substring_fct op_column_commalist %type <pParseNode> /*bit_concatenation*/ bit_value_exp bit_factor bit_primary collate_clause char_value_fct unique_spec value_exp_commalist in_predicate_value unique_test update_source %type <pParseNode> function_arg_commalist3 string_function_3Argument function_arg_commalist4 string_function_4Argument function_arg_commalist2 string_function_1Argument string_function_2Argument %type <pParseNode> date_function_0Argument date_function_1Argument function_name12 function_name23 function_name1 function_name2 function_name3 function_name0 numeric_function_0Argument numeric_function_1Argument numeric_function_2Argument -%type <pParseNode> all query_primary sql_not for_length upper_lower comparison column_val cross_union /*opt_schema_element_list*/ +%type <pParseNode> all query_primary sql_not for_length comparison column_val cross_union /*opt_schema_element_list*/ %type <pParseNode> /*op_authorization op_schema*/ nil_fkt schema_element base_table_def base_table_element base_table_element_commalist %type <pParseNode> column_def odbc_fct_spec odbc_call_spec odbc_fct_type op_parameter union_statement %type <pParseNode> op_odbc_call_parameter odbc_parameter_commalist odbc_parameter function_args_commalist function_arg @@ -318,7 +324,7 @@ schema: opt_schema_element_list: {$$ = SQL_NEW_RULE;} - | schema_glement_list + | schema_element_list ; schema_element_list: @@ -1923,10 +1929,12 @@ string_function_1Argument: SQL_TOKEN_LENGTH | SQL_TOKEN_ASCII | SQL_TOKEN_LCASE + | SQL_TOKEN_LOWER | SQL_TOKEN_LTRIM | SQL_TOKEN_RTRIM | SQL_TOKEN_SPACE | SQL_TOKEN_UCASE + | SQL_TOKEN_UPPER ; string_function_2Argument: @@ -1973,6 +1981,7 @@ date_function_1Argument: date_function: SQL_TOKEN_TIMESTAMPADD | SQL_TOKEN_TIMESTAMPDIFF + | SQL_TOKEN_DATEADD ; numeric_function_0Argument: SQL_TOKEN_PI @@ -2952,11 +2961,27 @@ interval_value_exp: */ non_second_datetime_field: SQL_TOKEN_YEAR + | SQL_TOKEN_YEARDAY + | SQL_TOKEN_MONTH + | SQL_TOKEN_WEEK + | SQL_TOKEN_WEEKDAY + | SQL_TOKEN_DAY + | SQL_TOKEN_HOUR + | SQL_TOKEN_MINUTE + | SQL_TOKEN_MILLISECOND + ; + +datetime_unit: + SQL_TOKEN_YEAR | SQL_TOKEN_MONTH + | SQL_TOKEN_WEEK | SQL_TOKEN_DAY | SQL_TOKEN_HOUR | SQL_TOKEN_MINUTE + | SQL_TOKEN_SECOND + | SQL_TOKEN_MILLISECOND ; + start_field: non_second_datetime_field opt_paren_precision { @@ -3088,6 +3113,13 @@ function_args_commalist: else YYERROR; } + | datetime_unit ',' function_arg ',' function_arg + { + $$ = SQL_NEW_COMMALISTRULE; + $$->append($1); + $$->append($3); + $$->append($5); + } ; value_exp: @@ -3219,7 +3251,6 @@ bit_primary: ; char_value_fct: char_substring_fct - | fold | form_conversion { $$ = SQL_NEW_RULE; @@ -3266,20 +3297,6 @@ char_substring_fct: $$->append(newNode(")", SQLNodeType::Punctuation)); } ; -upper_lower: - SQL_TOKEN_UPPER - | SQL_TOKEN_LOWER - ; -fold: - upper_lower '(' value_exp ')' - { - $$ = SQL_NEW_RULE; - $$->append($1); - $$->append(newNode("(", SQLNodeType::Punctuation)); - $$->append($3); - $$->append(newNode(")", SQLNodeType::Punctuation)); - } - ; form_conversion: SQL_TOKEN_CONVERT '(' string_value_exp SQL_TOKEN_USING table_node ')' { @@ -4376,7 +4393,7 @@ OString OParseContext::getIntlKeywordAscii(InternationalKeyCode _eKey) const IParseContext::InternationalKeyCode OParseContext::getIntlKeyCode(const OString& rToken) const { - static IParseContext::InternationalKeyCode Intl_TokenID[] = + static IParseContext::InternationalKeyCode const Intl_TokenID[] = { InternationalKeyCode::Like, InternationalKeyCode::Not, InternationalKeyCode::Null, InternationalKeyCode::True, InternationalKeyCode::False, InternationalKeyCode::Is, InternationalKeyCode::Between, InternationalKeyCode::Or, @@ -4386,15 +4403,14 @@ IParseContext::InternationalKeyCode OParseContext::getIntlKeyCode(const OString& InternationalKeyCode::VarPop,InternationalKeyCode::Collect,InternationalKeyCode::Fusion,InternationalKeyCode::Intersection }; - sal_uInt32 nCount = SAL_N_ELEMENTS( Intl_TokenID ); - for (sal_uInt32 i = 0; i < nCount; i++) - { - OString aKey = getIntlKeywordAscii(Intl_TokenID[i]); - if (rToken.equalsIgnoreAsciiCase(aKey)) - return Intl_TokenID[i]; - } + auto const token = std::find_if(std::cbegin(Intl_TokenID), std::cend(Intl_TokenID) + , [&rToken, this](IParseContext::InternationalKeyCode const & tokenID) + { return rToken.equalsIgnoreAsciiCase(getIntlKeywordAscii(tokenID)); }); + + if (std::cend(Intl_TokenID) != token) + return *token; - return InternationalKeyCode::None; + return InternationalKeyCode::None; } @@ -4489,7 +4505,7 @@ sal_Int32 OSQLParser::s_nRefCount = 0; // ::osl::Mutex OSQLParser::s_aMutex; OSQLScanner* OSQLParser::s_pScanner = nullptr; OSQLParseNodesGarbageCollector* OSQLParser::s_pGarbageCollector = nullptr; -css::uno::Reference< css::i18n::XLocaleData4> OSQLParser::s_xLocaleData = nullptr; +vcl::DeleteOnDeinit<css::uno::Reference< css::i18n::XLocaleData4>> OSQLParser::s_xLocaleData(vcl::DeleteOnDeinitFlag::Empty); void setParser(OSQLParser* _pParser) { @@ -4498,7 +4514,6 @@ void setParser(OSQLParser* _pParser) void OSQLParser::setParseTree(OSQLParseNode* pNewParseTree) { - ::osl::MutexGuard aGuard(getMutex()); m_pParseTree.reset(pNewParseTree); } @@ -4570,7 +4585,7 @@ std::unique_ptr<OSQLParseNode> OSQLParser::parseTree(OUString& rErrorMessage, // Guard the parsing - ::osl::MutexGuard aGuard(getMutex()); + std::unique_lock aGuard(getMutex()); // must be reset setParser(this); @@ -4599,7 +4614,8 @@ std::unique_ptr<OSQLParseNode> OSQLParser::parseTree(OUString& rErrorMessage, // clear the garbage collector (*s_pGarbageCollector)->clearAndDelete(); - m_pParseTree.release(); // because the garbage collector deleted it + // coverity[leaked_storage : FALSE] - because the garbage collector deleted it + m_pParseTree.release(); return nullptr; } else @@ -4645,6 +4661,7 @@ OString OSQLParser::TokenIDToStr(sal_uInt32 nTokenID, const IParseContext* pCont if (aStr.isEmpty()) { + // coverity[unsigned_compare : SUPPRESS] - YYTRANSLATE is out of our control aStr = yytname[YYTRANSLATE(nTokenID)]; if(aStr.startsWith("SQL_TOKEN_")) aStr = aStr.copy(10); @@ -4663,7 +4680,7 @@ OString OSQLParser::TokenIDToStr(sal_uInt32 nTokenID, const IParseContext* pCont #if OSL_DEBUG_LEVEL > 0 OUString OSQLParser::RuleIDToStr(sal_uInt32 nRuleID) { - OSL_ENSURE(nRuleID < SAL_N_ELEMENTS(yytname), "OSQLParser::RuleIDToStr: Invalid nRuleId!"); + OSL_ENSURE(nRuleID < std::size(yytname), "OSQLParser::RuleIDToStr: Invalid nRuleId!"); return OUString::createFromAscii(yytname[nRuleID]); } #endif @@ -4673,8 +4690,8 @@ sal_uInt32 OSQLParser::StrToRuleID(const OString & rValue) { // Search for the given name in yytname and return the index // (or UNKNOWN_RULE, if not found) - static sal_uInt32 nLen = SAL_N_ELEMENTS(yytname); - for (sal_uInt32 i = YYTRANSLATE(SQL_TOKEN_INVALIDSYMBOL); i < (nLen-1); i++) + static sal_uInt32 const nLen = std::size(yytname)-1; + for (sal_uInt32 i = YYTRANSLATE(SQL_TOKEN_INVALIDSYMBOL); i < nLen; ++i) { if (rValue == yytname[i]) return i; @@ -4743,8 +4760,7 @@ sal_Int16 OSQLParser::buildStringNodes(OSQLParseNode*& pLiteral) OSQLParseNode* pParent = pLiteral->getParent(); OSQLParseNode* pNewNode = new OSQLInternalNode(pLiteral->getTokenValue(), SQLNodeType::String); - pParent->replace(pLiteral, pNewNode); - delete pLiteral; + pParent->replaceAndDelete(pLiteral, pNewNode); pLiteral = nullptr; return 1; } @@ -4802,12 +4818,11 @@ void OSQLParser::error(const char *fmt) sal_Int32 nPos2 = sStr.indexOf(sSQL_TOKEN,nPos1+1); if(nPos2 != -1) { - OUString sSecond = sStr.copy(nPos1+sSQL_TOKEN.getLength(),nPos2-nPos1-sSQL_TOKEN.getLength()); - sFirst += sSecond; - sFirst += sStr.copy(nPos2+sSQL_TOKEN.getLength()); + sFirst += sStr.subView(nPos1+sSQL_TOKEN.getLength(),nPos2-nPos1-sSQL_TOKEN.getLength()); + sFirst += sStr.subView(nPos2+sSQL_TOKEN.getLength()); } else - sFirst += sStr.copy(nPos1+sSQL_TOKEN.getLength()); + sFirst += sStr.subView(nPos1+sSQL_TOKEN.getLength()); m_sErrorMessage = sFirst; } diff --git a/connectivity/source/parse/sqlflex.l b/connectivity/source/parse/sqlflex.l index 34a4067ea21c..44daeb236bf7 100644 --- a/connectivity/source/parse/sqlflex.l +++ b/connectivity/source/parse/sqlflex.l @@ -186,6 +186,7 @@ CURSOR {SQL_NEW_KEYWORD(SQL_TOKEN_CURSOR); } D {SQL_NEW_KEYWORD(SQL_TOKEN_D); } DATE {SQL_NEW_KEYWORD(SQL_TOKEN_DATE); } +DATEADD {SQL_NEW_KEYWORD(SQL_TOKEN_DATEADD); } DATEDIFF {SQL_NEW_KEYWORD(SQL_TOKEN_DATEDIFF); } DATEVALUE {SQL_NEW_KEYWORD(SQL_TOKEN_DATEVALUE); } DAY {SQL_NEW_KEYWORD(SQL_TOKEN_DAY); } diff --git a/connectivity/source/parse/sqliterator.cxx b/connectivity/source/parse/sqliterator.cxx index a91390eca2b8..8ca4d6271fc4 100644 --- a/connectivity/source/parse/sqliterator.cxx +++ b/connectivity/source/parse/sqliterator.cxx @@ -32,15 +32,17 @@ #include <iostream> #endif #include <connectivity/PColumn.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <TConnection.hxx> #include <comphelper/types.hxx> #include <connectivity/dbmetadata.hxx> #include <com/sun/star/sdb/SQLFilterOperator.hpp> +#include <o3tl/safeint.hxx> #include <sal/log.hxx> #include <iterator> #include <memory> +#include <utility> using namespace ::comphelper; using namespace ::connectivity; @@ -119,9 +121,9 @@ namespace connectivity OUString m_sForbiddenQueryName; public: - ForbidQueryName( OSQLParseTreeIteratorImpl& _rIteratorImpl, const OUString& _rForbiddenQueryName ) + ForbidQueryName( OSQLParseTreeIteratorImpl& _rIteratorImpl, OUString _aForbiddenQueryName ) :m_rpAllForbiddenNames( _rIteratorImpl.m_pForbiddenQueryNames ) - ,m_sForbiddenQueryName( _rForbiddenQueryName ) + ,m_sForbiddenQueryName(std::move( _aForbiddenQueryName )) { if ( !m_rpAllForbiddenNames ) m_rpAllForbiddenNames = std::make_shared<QueryNameSet>(); @@ -264,20 +266,17 @@ namespace { OUString sComposedName; - static const char s_sWildcard[] = "%" ; + static constexpr OUString s_sWildcard = u"%"_ustr ; // we want all catalogues, all schemas, all tables - Sequence< OUString > sTableTypes(3); - sTableTypes[0] = "VIEW"; - sTableTypes[1] = "TABLE"; - sTableTypes[2] = s_sWildcard; // just to be sure to include anything else... + Sequence< OUString > sTableTypes { "VIEW", "TABLE", s_sWildcard }; // this last one just to be sure to include anything else... if ( _rxDBMeta.is() ) { sComposedName.clear(); Reference< XResultSet> xRes = _rxDBMeta->getTables( - !_rCatalog.isEmpty() ? makeAny( _rCatalog ) : Any(), !_rSchema.isEmpty() ? _rSchema : s_sWildcard, _rTableName, sTableTypes ); + !_rCatalog.isEmpty() ? Any( _rCatalog ) : Any(), !_rSchema.isEmpty() ? _rSchema : s_sWildcard, _rTableName, sTableTypes ); Reference< XRow > xCurrentRow( xRes, UNO_QUERY ); if ( xCurrentRow.is() && xRes->next() ) @@ -526,7 +525,7 @@ void OSQLParseTreeIterator::getQualified_join( OSQLTables& _rTables, const OSQLP { const OSQLParseNode * pCol = pColumnCommalist->getChild(i); // add twice because the column must exists in both tables - m_pImpl->m_aJoinConditions.push_back( TNodePair(pCol,pCol) ); + m_pImpl->m_aJoinConditions.emplace_back(pCol,pCol); } } } @@ -820,14 +819,13 @@ void OSQLParseTreeIterator::traverseCreateColumns(const OSQLParseNode* pSelectNo if (!aTypeName.isEmpty()) { //TODO:Create a new class for create statement to handle field length - OParseColumn* pColumn = new OParseColumn(aColumnName,aTypeName,OUString(),OUString(), + rtl::Reference<OParseColumn> pColumn = new OParseColumn(aColumnName,aTypeName,OUString(),OUString(), ColumnValue::NULLABLE_UNKNOWN,0,0,nType,false,false,isCaseSensitive(), OUString(),OUString(),OUString()); pColumn->setFunction(false); pColumn->setRealName(aColumnName); - Reference< XPropertySet> xCol = pColumn; - m_aCreateColumns->push_back(xCol); + m_aCreateColumns->push_back(pColumn); } } @@ -855,7 +853,7 @@ bool OSQLParseTreeIterator::traverseSelectColumnNames(const OSQLParseNode* pSele if (pSelectNode->getChild(2)->isRule() && SQL_ISPUNCTUATION(pSelectNode->getChild(2)->getChild(0),"*")) { // SELECT * ... - setSelectColumnName(m_aSelectColumns, "*", "", ""); + setSelectColumnName("*", "", ""); } else if (SQL_ISRULE(pSelectNode->getChild(2),scalar_exp_commalist)) { @@ -875,7 +873,7 @@ bool OSQLParseTreeIterator::traverseSelectColumnNames(const OSQLParseNode* pSele // All the table's columns OUString aTableRange; pColumnRef->getChild(0)->parseNodeToStr( aTableRange, m_pImpl->m_xConnection, nullptr, false, false ); - setSelectColumnName(m_aSelectColumns, "*", "", aTableRange); + setSelectColumnName("*", "", aTableRange); continue; } else if (SQL_ISRULE(pColumnRef,derived_column)) @@ -927,7 +925,7 @@ bool OSQLParseTreeIterator::traverseSelectColumnNames(const OSQLParseNode* pSele */ if(aColumnAlias.isEmpty()) aColumnAlias = sColumnName; - setSelectColumnName(m_aSelectColumns,sColumnName,aColumnAlias,aTableRange,bFkt,nType,SQL_ISRULE(pColumnRef,general_set_fct) || SQL_ISRULE(pColumnRef,set_fct_spec)); + setSelectColumnName(sColumnName,aColumnAlias,aTableRange,bFkt,nType,SQL_ISRULE(pColumnRef,general_set_fct) || SQL_ISRULE(pColumnRef,set_fct_spec)); } } } @@ -1218,10 +1216,10 @@ void OSQLParseTreeIterator::traverseSearchCondition(OSQLParseNode const * pSearc OSL_ENSURE(pSearchCondition->count() == 2,"OSQLParseTreeIterator: error in parse tree!"); const OSQLParseNode* pPart2 = pSearchCondition->getChild(1); - sal_Int32 nCurentPos = pPart2->count()-2; + sal_Int32 nCurrentPos = pPart2->count()-2; - OSQLParseNode * pNum_value_exp = pPart2->getChild(nCurentPos); - OSQLParseNode * pOptEscape = pPart2->getChild(nCurentPos+1); + OSQLParseNode * pNum_value_exp = pPart2->getChild(nCurrentPos); + OSQLParseNode * pOptEscape = pPart2->getChild(nCurrentPos+1); OSL_ENSURE(pNum_value_exp != nullptr,"OSQLParseTreeIterator: error in parse tree!"); OSL_ENSURE(pOptEscape != nullptr,"OSQLParseTreeIterator: error in parse tree!"); @@ -1344,7 +1342,7 @@ void OSQLParseTreeIterator::traverseParameter(const OSQLParseNode* _pParseNode } sal_Int32 nType = ::connectivity::OSQLParser::getFunctionParameterType( _pParentNode->getChild(0)->getTokenID(), i-1); - OParseColumn* pColumn = new OParseColumn( sParameterName, + rtl::Reference<OParseColumn> pColumn = new OParseColumn( sParameterName, OUString(), OUString(), OUString(), @@ -1373,7 +1371,7 @@ void OSQLParseTreeIterator::traverseParameter(const OSQLParseNode* _pParseNode ); if(aIter != m_aSelectColumns->end()) { - OParseColumn* pNewColumn = new OParseColumn(*aIter,isCaseSensitive()); + rtl::Reference<OParseColumn> pNewColumn = new OParseColumn(*aIter,isCaseSensitive()); pNewColumn->setName(sParameterName); pNewColumn->setRealName(_aColumnName); m_aParameters->push_back(pNewColumn); @@ -1386,7 +1384,7 @@ void OSQLParseTreeIterator::traverseParameter(const OSQLParseNode* _pParseNode if ( xColumn.is() ) { - OParseColumn* pNewColumn = new OParseColumn(xColumn,isCaseSensitive()); + rtl::Reference<OParseColumn> pNewColumn = new OParseColumn(xColumn,isCaseSensitive()); pNewColumn->setName(sParameterName); pNewColumn->setRealName(_aColumnName); m_aParameters->push_back(pNewColumn); @@ -1409,9 +1407,9 @@ void OSQLParseTreeIterator::traverseParameter(const OSQLParseNode* _pParseNode nType = ::connectivity::OSQLParser::getFunctionParameterType( pParent->getChild(0)->getTokenID(), i+1); } - OUString aNewColName( getUniqueColumnName( sParameterName ) ); + OUString aNewColName(getUniqueColumnName(getSelectColumnNames(), sParameterName)); - OParseColumn* pColumn = new OParseColumn(aNewColName, + rtl::Reference<OParseColumn> pColumn = new OParseColumn(aNewColName, OUString(), OUString(), OUString(), @@ -1526,7 +1524,7 @@ OSQLTable OSQLParseTreeIterator::impl_createTableObject( const OUString& rTableN return aReturnTable; } -void OSQLParseTreeIterator::appendColumns(::rtl::Reference<OSQLColumns> const & _rColumns,const OUString& _rTableAlias,const OSQLTable& _rTable) +void OSQLParseTreeIterator::appendColumns(const OUString& _rTableAlias, const OSQLTable& _rTable) { if (!_rTable.is()) return; @@ -1539,14 +1537,16 @@ void OSQLParseTreeIterator::appendColumns(::rtl::Reference<OSQLColumns> const & const OUString* pBegin = aColNames.getConstArray(); const OUString* pEnd = pBegin + aColNames.getLength(); + ::comphelper::UStringMixLess aCompare(isCaseSensitive()); + std::vector<OUString> aSelectColumnNames = getSelectColumnNames(); + for(;pBegin != pEnd;++pBegin) { - - OUString aName(getUniqueColumnName(*pBegin)); + OUString aName(getUniqueColumnName(aSelectColumnNames, *pBegin)); Reference< XPropertySet > xColumn; if(xColumns->hasByName(*pBegin) && (xColumns->getByName(*pBegin) >>= xColumn) && xColumn.is()) { - OParseColumn* pColumn = new OParseColumn(aName + rtl::Reference<OParseColumn> pColumn = new OParseColumn(aName , getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))) , getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE))) , getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION))) @@ -1563,29 +1563,28 @@ void OSQLParseTreeIterator::appendColumns(::rtl::Reference<OSQLColumns> const & pColumn->setTableName(_rTableAlias); pColumn->setRealName(*pBegin); - Reference< XPropertySet> xCol = pColumn; - _rColumns->push_back(xCol); + m_aSelectColumns->push_back(pColumn); + // update aSelectColumnNames with newly insert aName + aSelectColumnNames.insert(std::upper_bound(aSelectColumnNames.begin(), aSelectColumnNames.end(), aName, aCompare), aName); } else impl_appendError( IParseContext::ErrorCode::InvalidColumn, pBegin, &_rTableAlias ); } } -void OSQLParseTreeIterator::setSelectColumnName(::rtl::Reference<OSQLColumns> const & _rColumns,const OUString & rColumnName,const OUString & rColumnAlias, const OUString & rTableRange, bool bFkt, sal_Int32 _nType, bool bAggFkt) +void OSQLParseTreeIterator::setSelectColumnName(const OUString & rColumnName,const OUString & rColumnAlias, const OUString & rTableRange, bool bFkt, sal_Int32 _nType, bool bAggFkt) { if(rColumnName.toChar() == '*' && rTableRange.isEmpty()) { // SELECT * ... - OSL_ENSURE(_rColumns == m_aSelectColumns,"Invalid columns used here!"); for (auto const& table : *m_pImpl->m_pTables) - appendColumns(_rColumns,table.first,table.second); + appendColumns(table.first, table.second); } else if( rColumnName.toChar() == '*' && !rTableRange.isEmpty() ) { // SELECT <table>.* - OSL_ENSURE(_rColumns == m_aSelectColumns,"Invalid columns used here!"); OSQLTables::const_iterator aFind = m_pImpl->m_pTables->find(rTableRange); if(aFind != m_pImpl->m_pTables->end()) - appendColumns(_rColumns,rTableRange,aFind->second); + appendColumns(rTableRange, aFind->second); } else if ( rTableRange.isEmpty() ) { // SELECT <something> ... @@ -1606,9 +1605,9 @@ void OSQLParseTreeIterator::setSelectColumnName(::rtl::Reference<OSQLColumns> co ) continue; - OUString aNewColName(getUniqueColumnName(rColumnAlias)); + OUString aNewColName(getUniqueColumnName(getSelectColumnNames(), rColumnAlias)); - OParseColumn* pColumn = new OParseColumn(xColumn,isCaseSensitive()); + rtl::Reference<OParseColumn> pColumn = new OParseColumn(xColumn,isCaseSensitive()); xNewColumn = pColumn; pColumn->setTableName(table.first); pColumn->setName(aNewColName); @@ -1621,9 +1620,9 @@ void OSQLParseTreeIterator::setSelectColumnName(::rtl::Reference<OSQLColumns> co { // no function (due to the above !bFkt), no existing column // => assume an expression - OUString aNewColName( getUniqueColumnName( rColumnAlias ) ); + OUString aNewColName(getUniqueColumnName(getSelectColumnNames(), rColumnAlias)); // did not find a column with this name in any of the tables - OParseColumn* pColumn = new OParseColumn( + rtl::Reference<OParseColumn> pColumn = new OParseColumn( aNewColName, "VARCHAR", // TODO: does this match with _nType? @@ -1646,21 +1645,20 @@ void OSQLParseTreeIterator::setSelectColumnName(::rtl::Reference<OSQLColumns> co pColumn->setRealName( rColumnName ); } - _rColumns->push_back( xNewColumn ); + m_aSelectColumns->push_back( xNewColumn ); } else { - OUString aNewColName(getUniqueColumnName(rColumnAlias)); + OUString aNewColName(getUniqueColumnName(getSelectColumnNames(), rColumnAlias)); - OParseColumn* pColumn = new OParseColumn(aNewColName,OUString(),OUString(),OUString(), + rtl::Reference<OParseColumn> pColumn = new OParseColumn(aNewColName,OUString(),OUString(),OUString(), ColumnValue::NULLABLE_UNKNOWN,0,0,_nType,false,false,isCaseSensitive(), OUString(),OUString(),OUString()); pColumn->setFunction(true); pColumn->setAggregateFunction(bAggFkt); pColumn->setRealName(rColumnName); - Reference< XPropertySet> xCol = pColumn; - _rColumns->push_back(xCol); + m_aSelectColumns->push_back(pColumn); } } else // ColumnName and TableName exist @@ -1672,9 +1670,9 @@ void OSQLParseTreeIterator::setSelectColumnName(::rtl::Reference<OSQLColumns> co { if (bFkt) { - OUString aNewColName(getUniqueColumnName(rColumnAlias)); + OUString aNewColName(getUniqueColumnName(getSelectColumnNames(), rColumnAlias)); - OParseColumn* pColumn = new OParseColumn(aNewColName,OUString(),OUString(),OUString(), + rtl::Reference<OParseColumn> pColumn = new OParseColumn(aNewColName,OUString(),OUString(),OUString(), ColumnValue::NULLABLE_UNKNOWN,0,0,_nType,false,false,isCaseSensitive(), OUString(),OUString(),OUString()); pColumn->setFunction(true); @@ -1684,23 +1682,21 @@ void OSQLParseTreeIterator::setSelectColumnName(::rtl::Reference<OSQLColumns> co assert(false); pColumn->setTableName(aFind->first); - Reference< XPropertySet> xCol = pColumn; - _rColumns->push_back(xCol); + m_aSelectColumns->push_back(pColumn); } else { Reference< XPropertySet > xColumn; if (aFind->second->getColumns()->hasByName(rColumnName) && (aFind->second->getColumns()->getByName(rColumnName) >>= xColumn)) { - OUString aNewColName(getUniqueColumnName(rColumnAlias)); + OUString aNewColName(getUniqueColumnName(getSelectColumnNames(), rColumnAlias)); - OParseColumn* pColumn = new OParseColumn(xColumn,isCaseSensitive()); + rtl::Reference<OParseColumn> pColumn = new OParseColumn(xColumn,isCaseSensitive()); pColumn->setName(aNewColName); pColumn->setRealName(rColumnName); pColumn->setTableName(aFind->first); - Reference< XPropertySet> xCol = pColumn; - _rColumns->push_back(xCol); + m_aSelectColumns->push_back(pColumn); } else bError = true; @@ -1712,41 +1708,45 @@ void OSQLParseTreeIterator::setSelectColumnName(::rtl::Reference<OSQLColumns> co // Table does not exist or lacking field if (bError) { - OUString aNewColName(getUniqueColumnName(rColumnAlias)); + OUString aNewColName(getUniqueColumnName(getSelectColumnNames(), rColumnAlias)); - OParseColumn* pColumn = new OParseColumn(aNewColName,OUString(),OUString(),OUString(), + rtl::Reference<OParseColumn> pColumn = new OParseColumn(aNewColName,OUString(),OUString(),OUString(), ColumnValue::NULLABLE_UNKNOWN,0,0,DataType::VARCHAR,false,false,isCaseSensitive(), OUString(),OUString(),OUString()); pColumn->setFunction(true); pColumn->setAggregateFunction(bAggFkt); - Reference< XPropertySet> xCol = pColumn; - _rColumns->push_back(xCol); + m_aSelectColumns->push_back(pColumn); } } } -OUString OSQLParseTreeIterator::getUniqueColumnName(const OUString & rColumnName) const +std::vector<OUString> OSQLParseTreeIterator::getSelectColumnNames() const { - OUString aAlias(rColumnName); + ::comphelper::UStringMixLess aCompare(isCaseSensitive()); - OSQLColumns::const_iterator aIter = find( - m_aSelectColumns->begin(), - m_aSelectColumns->end(), - aAlias, - ::comphelper::UStringMixEqual( isCaseSensitive() ) - ); + std::vector<OUString> aColumnNames; + OUString sPropertyName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME); + for (const auto& col : *m_aSelectColumns) + aColumnNames.push_back(getString(col->getPropertyValue(sPropertyName))); + std::sort(aColumnNames.begin(), aColumnNames.end(), aCompare); + + return aColumnNames; +} + +OUString OSQLParseTreeIterator::getUniqueColumnName(const std::vector<OUString>& rColumnNames, const OUString& rColumnName) const +{ + ::comphelper::UStringMixLess aCompare(isCaseSensitive()); + if (!std::binary_search(rColumnNames.begin(), rColumnNames.end(), rColumnName, aCompare)) + return rColumnName; + + OUString aAlias; sal_Int32 i=1; - while(aIter != m_aSelectColumns->end()) + do { aAlias = rColumnName + OUString::number(i++); - aIter = find( - m_aSelectColumns->begin(), - m_aSelectColumns->end(), - aAlias, - ::comphelper::UStringMixEqual( isCaseSensitive() ) - ); } + while (std::binary_search(rColumnNames.begin(), rColumnNames.end(), aAlias, aCompare)); return aAlias; } @@ -1760,7 +1760,7 @@ void OSQLParseTreeIterator::setOrderByColumnName(const OUString & rColumnName, O else { sal_Int32 nId = rColumnName.toInt32(); - if ( nId > 0 && nId < static_cast<sal_Int32>(m_aSelectColumns->size()) ) + if ( nId > 0 && o3tl::make_unsigned(nId) < m_aSelectColumns->size() ) m_aOrderColumns->push_back( new OOrderColumn( (*m_aSelectColumns)[nId-1], isCaseSensitive(), bAscending ) ); } @@ -1781,7 +1781,7 @@ void OSQLParseTreeIterator::setGroupByColumnName(const OUString & rColumnName, O else { sal_Int32 nId = rColumnName.toInt32(); - if ( nId > 0 && nId < static_cast<sal_Int32>(m_aSelectColumns->size()) ) + if ( nId > 0 && o3tl::make_unsigned(nId) < m_aSelectColumns->size() ) m_aGroupColumns->push_back(new OParseColumn((*m_aSelectColumns)[nId-1],isCaseSensitive())); } @@ -1831,12 +1831,29 @@ const OSQLParseNode* OSQLParseTreeIterator::getOrderTree() const // Analyse parse tree (depending on statement type) // and set pointer to ORDER clause: + + assert(SQL_ISRULE(m_pParseTree, select_statement) || SQL_ISRULE(m_pParseTree, union_statement)); + + auto pParseTree = m_pParseTree; + if(SQL_ISRULE(m_pParseTree, union_statement)) + { + assert(m_pParseTree->count() == 4); + pParseTree = pParseTree->getChild(3); + // since UNION is left-associative (at least in our grammar), + // possibly the left-hand (m_pParseTree->getChild(0)) is a union_statement, + // but the right hand cannot. + assert(SQL_ISRULE(pParseTree, select_statement)); + } + OSQLParseNode * pOrderClause = nullptr; - OSL_ENSURE(m_pParseTree->count() >= 4,"ParseTreeIterator: error in parse tree!"); - OSQLParseNode * pTableExp = m_pParseTree->getChild(3); - OSL_ENSURE(pTableExp != nullptr,"OSQLParseTreeIterator: error in parse tree!"); - OSL_ENSURE(SQL_ISRULE(pTableExp,table_exp),"OSQLParseTreeIterator: error in parse tree!"); - OSL_ENSURE(pTableExp->count() == TABLE_EXPRESSION_CHILD_COUNT,"OSQLParseTreeIterator: error in parse tree!"); + OSL_ENSURE(pParseTree->count() == 4, "OSQLParseTreeIterator::getOrderTree: expected a SELECT, and a SELECT must have exactly four children"); + OSQLParseNode * pTableExp = pParseTree->getChild(3); + OSL_ENSURE(pTableExp != nullptr, "OSQLParseTreeIterator::getOrderTree: got NULL table_exp"); + OSL_ENSURE(SQL_ISRULE(pTableExp, table_exp), "OSQLParseTreeIterator::getOrderTree: expected table_exp but got something else"); + OSL_ENSURE(pTableExp->count() == TABLE_EXPRESSION_CHILD_COUNT,"OSQLParseTreeIterator::getOrderTree: table_exp doesn't have the expected number of children"); + // tdf#141115 upgrade the above to an assert; + // this cannot go well if there are too few children + assert(pTableExp->count() == TABLE_EXPRESSION_CHILD_COUNT); pOrderClause = pTableExp->getChild(ORDER_BY_CHILD_POS); // If it is an order_by, it must not be empty @@ -1919,7 +1936,7 @@ const OSQLParseNode* OSQLParseTreeIterator::getSimpleHavingTree() const } -Reference< XPropertySet > OSQLParseTreeIterator::findSelectColumn( const OUString & rColumnName ) +Reference< XPropertySet > OSQLParseTreeIterator::findSelectColumn( std::u16string_view rColumnName ) { for (auto const& lookupColumn : *m_aSelectColumns) { @@ -2092,7 +2109,11 @@ sal_Int32 OSQLParseTreeIterator::getFunctionReturnType(const OSQLParseNode* _pNo nType = DataType::DOUBLE; } else + { nType = ::connectivity::OSQLParser::getFunctionReturnType( sFunctionName, &m_rParser.getContext() ); + if (nType == DataType::SQLNULL) + nType = ::connectivity::OSQLParser::getFunctionReturnType( sFunctionName, m_rParser.getNeutral() ); + } } return nType; diff --git a/connectivity/source/parse/sqlnode.cxx b/connectivity/source/parse/sqlnode.cxx index d31bcd2a9ada..ad8f6c9edeff 100644 --- a/connectivity/source/parse/sqlnode.cxx +++ b/connectivity/source/parse/sqlnode.cxx @@ -50,13 +50,16 @@ #include <comphelper/numbers.hxx> #include <connectivity/dbtools.hxx> #include <connectivity/dbmetadata.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <string.h> #include <algorithm> #include <functional> #include <memory> +#include <string_view> + #include <rtl/ustrbuf.hxx> #include <sal/log.hxx> +#include <utility> using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::util; @@ -89,39 +92,26 @@ namespace void replaceAndReset(connectivity::OSQLParseNode*& _pResetNode,connectivity::OSQLParseNode* _pNewNode) { - _pResetNode->getParent()->replace(_pResetNode, _pNewNode); - delete _pResetNode; + _pResetNode->getParent()->replaceAndDelete(_pResetNode, _pNewNode); _pResetNode = _pNewNode; } /** quotes a string and search for quotes inside the string and replace them with the new quote @param rValue The value to be quoted. - @param rQuot + @param rQuote The quote - @param rQuotToReplace + @param rQuoteToReplace The quote to replace with @return The quoted string. */ - OUString SetQuotation(const OUString& rValue, const OUString& rQuot, const OUString& rQuotToReplace) + OUString SetQuotation(const OUString& rValue, std::u16string_view rQuote, std::u16string_view rQuoteToReplace) { - OUString rNewValue = rQuot + rValue; - sal_Int32 nIndex = sal_Int32(-1); // Replace quotes with double quotes or the parser gets into problems - - if (!rQuot.isEmpty()) - { - do - { - nIndex += 2; - nIndex = rNewValue.indexOf(rQuot,nIndex); - if(nIndex != -1) - rNewValue = rNewValue.replaceAt(nIndex,rQuot.getLength(),rQuotToReplace); - } while (nIndex != -1); - } - - rNewValue += rQuot; - return rNewValue; + // Replace quotes with double quotes or the parser gets into problems + if (!rQuote.empty()) + return rQuote + rValue.replaceAll(rQuote, rQuoteToReplace) + rQuote; + return rValue; } bool columnMatchP(const connectivity::OSQLParseNode* pSubTree, const connectivity::SQLParseNodeParameter& rParam) @@ -145,41 +135,41 @@ namespace { } - if(pSubTree->count()) + if(!pSubTree->count()) + return false; + + const OSQLParseNode* pCol = pSubTree->getChild(pSubTree->count()-1); + if (SQL_ISRULE(pCol,column_val)) { - const OSQLParseNode* pCol = pSubTree->getChild(pSubTree->count()-1); - if (SQL_ISRULE(pCol,column_val)) - { - assert(pCol->count() == 1); - pCol = pCol->getChild(0); - } - const OSQLParseNode* pTable(nullptr); - switch (pSubTree->count()) - { - case 1: - break; - case 3: - pTable = pSubTree->getChild(0); - break; - case 5: - case 7: - SAL_WARN("connectivity.parse", "SQL: catalog and/or schema in column_ref in predicate"); - break; - default: - SAL_WARN("connectivity.parse", "columnMatchP: SQL grammar changed; column_ref has " << pSubTree->count() << " children"); - assert(false); - break; - } - // TODO: not all DBMS match column names case-insensitively... - // see XDatabaseMetaData::supportsMixedCaseIdentifiers() - // and XDatabaseMetaData::supportsMixedCaseQuotedIdentifiers() - if ( // table name matches (or no table name)? - ( !pTable || pTable->getTokenValue().equalsIgnoreAsciiCase(rParam.sPredicateTableAlias) ) - && // column name matches? - pCol->getTokenValue().equalsIgnoreAsciiCase(aFieldName) - ) - return true; + assert(pCol->count() == 1); + pCol = pCol->getChild(0); } + const OSQLParseNode* pTable(nullptr); + switch (pSubTree->count()) + { + case 1: + break; + case 3: + pTable = pSubTree->getChild(0); + break; + case 5: + case 7: + SAL_WARN("connectivity.parse", "SQL: catalog and/or schema in column_ref in predicate"); + break; + default: + SAL_WARN("connectivity.parse", "columnMatchP: SQL grammar changed; column_ref has " << pSubTree->count() << " children"); + assert(false); + break; + } + // TODO: not all DBMS match column names case-insensitively... + // see XDatabaseMetaData::supportsMixedCaseIdentifiers() + // and XDatabaseMetaData::supportsMixedCaseQuotedIdentifiers() + if ( // table name matches (or no table name)? + ( !pTable || pTable->getTokenValue().equalsIgnoreAsciiCase(rParam.sPredicateTableAlias) ) + && // column name matches? + pCol->getTokenValue().equalsIgnoreAsciiCase(aFieldName) + ) + return true; return false; } } @@ -189,7 +179,7 @@ namespace connectivity SQLParseNodeParameter::SQLParseNodeParameter( const Reference< XConnection >& _rxConnection, const Reference< XNumberFormatter >& _xFormatter, const Reference< XPropertySet >& _xField, - const OUString &_sPredicateTableAlias, + OUString _sPredicateTableAlias, const Locale& _rLocale, const IParseContext* _pContext, bool _bIntl, bool _bQuote, OUString _sDecSep, bool _bPredicate, bool _bParseToSDBC ) :rLocale(_rLocale) @@ -198,9 +188,9 @@ SQLParseNodeParameter::SQLParseNodeParameter( const Reference< XConnection >& _r ,pSubQueryHistory( std::make_shared<QueryNameSet>() ) ,xFormatter(_xFormatter) ,xField(_xField) - ,sPredicateTableAlias(_sPredicateTableAlias) + ,sPredicateTableAlias(std::move(_sPredicateTableAlias)) ,m_rContext( _pContext ? *_pContext : OSQLParser::s_aDefaultContext ) - ,sDecSep(_sDecSep) + ,sDecSep(std::move(_sDecSep)) ,bQuote(_bQuote) ,bInternational(_bIntl) ,bPredicate(_bPredicate) @@ -208,14 +198,14 @@ SQLParseNodeParameter::SQLParseNodeParameter( const Reference< XConnection >& _r { } -OUString OSQLParseNode::convertDateString(const SQLParseNodeParameter& rParam, const OUString& rString) +OUString OSQLParseNode::convertDateString(const SQLParseNodeParameter& rParam, std::u16string_view rString) { Date aDate = DBTypeConversion::toDate(rString); Reference< XNumberFormatsSupplier > xSupplier(rParam.xFormatter->getNumberFormatsSupplier()); Reference< XNumberFormatTypes > xTypes(xSupplier->getNumberFormats(), UNO_QUERY); double fDate = DBTypeConversion::toDouble(aDate,DBTypeConversion::getNULLDate(xSupplier)); - sal_Int32 nKey = xTypes->getStandardIndex(rParam.rLocale) + 36; // XXX hack + sal_Int32 nKey = xTypes->getFormatIndex(NumberFormatIndex::DATE_SYS_DDMMYYYY, rParam.rLocale); return rParam.xFormatter->convertNumberToString(nKey, fDate); } @@ -227,12 +217,12 @@ OUString OSQLParseNode::convertDateTimeString(const SQLParseNodeParameter& rPara Reference< XNumberFormatTypes > xTypes(xSupplier->getNumberFormats(), UNO_QUERY); double fDateTime = DBTypeConversion::toDouble(aDate,DBTypeConversion::getNULLDate(xSupplier)); - sal_Int32 nKey = xTypes->getStandardIndex(rParam.rLocale) + 51; // XXX hack + sal_Int32 nKey = xTypes->getFormatIndex(NumberFormatIndex::DATETIME_SYS_DDMMYYYY_HHMMSS, rParam.rLocale); return rParam.xFormatter->convertNumberToString(nKey, fDateTime); } -OUString OSQLParseNode::convertTimeString(const SQLParseNodeParameter& rParam, const OUString& rString) +OUString OSQLParseNode::convertTimeString(const SQLParseNodeParameter& rParam, std::u16string_view rString) { css::util::Time aTime = DBTypeConversion::toTime(rString); Reference< XNumberFormatsSupplier > xSupplier(rParam.xFormatter->getNumberFormatsSupplier()); @@ -240,7 +230,7 @@ OUString OSQLParseNode::convertTimeString(const SQLParseNodeParameter& rParam, c Reference< XNumberFormatTypes > xTypes(xSupplier->getNumberFormats(), UNO_QUERY); double fTime = DBTypeConversion::toDouble(aTime); - sal_Int32 nKey = xTypes->getStandardIndex(rParam.rLocale) + 41; // XXX hack + sal_Int32 nKey = xTypes->getFormatIndex(NumberFormatIndex::TIME_HHMMSS, rParam.rLocale); return rParam.xFormatter->convertNumberToString(nKey, fTime); } @@ -254,7 +244,7 @@ void OSQLParseNode::parseNodeToStr(OUString& rString, parseNodeToStr( rString, _rxConnection, nullptr, nullptr, OUString(), pContext ? pContext->getPreferredLocale() : OParseContext::getDefaultLocale(), - pContext, _bIntl, _bQuote, OUString("."), false ); + pContext, _bIntl, _bQuote, ".", false ); } @@ -262,13 +252,13 @@ void OSQLParseNode::parseNodeToPredicateStr(OUString& rString, const Reference< XConnection >& _rxConnection, const Reference< XNumberFormatter > & xFormatter, const css::lang::Locale& rIntl, - OUString _sDec, + const OUString& rDec, const IParseContext* pContext ) const { OSL_ENSURE(xFormatter.is(), "OSQLParseNode::parseNodeToPredicateStr:: no formatter!"); if (xFormatter.is()) - parseNodeToStr(rString, _rxConnection, xFormatter, nullptr, OUString(), rIntl, pContext, true, true, _sDec, true); + parseNodeToStr(rString, _rxConnection, xFormatter, nullptr, OUString(), rIntl, pContext, true, true, rDec, true); } @@ -278,13 +268,13 @@ void OSQLParseNode::parseNodeToPredicateStr(OUString& rString, const Reference< XPropertySet > & _xField, const OUString &_sPredicateTableAlias, const css::lang::Locale& rIntl, - OUString _sDec, + const OUString& rDec, const IParseContext* pContext ) const { OSL_ENSURE(xFormatter.is(), "OSQLParseNode::parseNodeToPredicateStr:: no formatter!"); if (xFormatter.is()) - parseNodeToStr( rString, _rxConnection, xFormatter, _xField, _sPredicateTableAlias, rIntl, pContext, true, true, _sDec, true ); + parseNodeToStr( rString, _rxConnection, xFormatter, _xField, _sPredicateTableAlias, rIntl, pContext, true, true, rDec, true ); } @@ -297,7 +287,7 @@ void OSQLParseNode::parseNodeToStr(OUString& rString, const IParseContext* pContext, bool _bIntl, bool _bQuote, - OUString _sDecSep, + const OUString& _rDecSep, bool _bPredicate) const { OSL_ENSURE( _rxConnection.is(), "OSQLParseNode::parseNodeToStr: invalid connection!" ); @@ -305,13 +295,13 @@ void OSQLParseNode::parseNodeToStr(OUString& rString, if ( !_rxConnection.is() ) return; - OUStringBuffer sBuffer = rString; + OUStringBuffer sBuffer(rString); try { OSQLParseNode::impl_parseNodeToString_throw( sBuffer, SQLParseNodeParameter( _rxConnection, xFormatter, _xField, _sPredicateTableAlias, rIntl, pContext, - _bIntl, _bQuote, _sDecSep, _bPredicate, false + _bIntl, _bQuote, _rDecSep, _bPredicate, false ) ); } catch( const SQLException& ) @@ -351,7 +341,7 @@ bool OSQLParseNode::parseNodeToExecutableStatement( OUString& _out_rString, cons || xMeta->getURL().startsWithIgnoreAsciiCase("sdbc:firebird:"))) { sLimitValue = pTableExp->getChild(6)->getChild(1)->getTokenValue(); - pTableExp->removeAt(6); + delete pTableExp->removeAt(6); } _out_rString.clear(); @@ -372,7 +362,7 @@ bool OSQLParseNode::parseNodeToExecutableStatement( OUString& _out_rString, cons { constexpr char SELECT_KEYWORD[] = "SELECT"; sBuffer.insert(sBuffer.indexOf(SELECT_KEYWORD) + strlen(SELECT_KEYWORD), - " FIRST " + sLimitValue); + Concat2View(" FIRST " + sLimitValue)); } _out_rString = sBuffer.makeStringAndClear(); @@ -503,7 +493,7 @@ void OSQLParseNode::impl_parseNodeToString_throw(OUStringBuffer& rString, const else i++; } - rString.append(aStringPara.makeStringAndClear()); + rString.append(aStringPara); } bHandled = true; break; @@ -755,7 +745,7 @@ void OSQLParseNode::impl_parseLikeNodeToString_throw( OUStringBuffer& rString, c { OUString aStr = ConvertLikeToken(pParaNode, pEscNode, rParam.bInternational); rString.append(" "); - rString.append(SetQuotation(aStr,"\'","\'\'")); + rString.append(SetQuotation(aStr, u"\'", u"\'\'")); } else pParaNode->impl_parseNodeToString_throw( rString, aNewParam, false ); @@ -813,7 +803,7 @@ void OSQLParser::killThousandSeparator(OSQLParseNode* pLiteral) { if ( pLiteral ) { - if ( s_xLocaleData->getLocaleItem( m_pData->aLocale ).decimalSeparator.toChar() == ',' ) + if ( s_xLocaleData.get()->get()->getLocaleItem( m_pData->aLocale ).decimalSeparator.toChar() == ',' ) { pLiteral->m_aNodeValue = pLiteral->m_aNodeValue.replace('.', sal_Unicode()); // and replace decimal @@ -821,7 +811,7 @@ void OSQLParser::killThousandSeparator(OSQLParseNode* pLiteral) } else pLiteral->m_aNodeValue = pLiteral->m_aNodeValue.replace(',', sal_Unicode()); - } + } } OSQLParseNode* OSQLParser::convertNode(sal_Int32 nType, OSQLParseNode* pLiteral) @@ -1128,7 +1118,7 @@ OUString OSQLParser::stringToDouble(const OUString& _rValue,sal_Int16 _nScale) OUString aValue; if(!m_xCharClass.is()) m_xCharClass = CharacterClassification::create( m_xContext ); - if( s_xLocaleData.is() ) + if( s_xLocaleData.get() ) { try { @@ -1138,8 +1128,9 @@ OUString OSQLParser::stringToDouble(const OUString& _rValue,sal_Int16 _nScale) aValue = OUString::number(aResult.Value); sal_Int32 nPos = aValue.lastIndexOf('.'); if((nPos+_nScale) < aValue.getLength()) - aValue = aValue.replaceAt(nPos+_nScale,aValue.getLength()-nPos-_nScale,OUString()); - aValue = aValue.replaceAt(aValue.lastIndexOf('.'),1,s_xLocaleData->getLocaleItem(m_pData->aLocale).decimalSeparator); + aValue = aValue.replaceAt(nPos+_nScale,aValue.getLength()-nPos-_nScale, u""); + OUString sDecimalSeparator = s_xLocaleData.get()->get()->getLocaleItem(m_pData->aLocale).decimalSeparator; + aValue = aValue.replaceAt(aValue.lastIndexOf('.'), 1, sDecimalSeparator); return aValue; } } @@ -1151,9 +1142,9 @@ OUString OSQLParser::stringToDouble(const OUString& _rValue,sal_Int16 _nScale) } -::osl::Mutex& OSQLParser::getMutex() +std::mutex& OSQLParser::getMutex() { - static ::osl::Mutex aMutex; + static std::mutex aMutex; return aMutex; } @@ -1164,7 +1155,7 @@ std::unique_ptr<OSQLParseNode> OSQLParser::predicateTree(OUString& rErrorMessage bool bUseRealName) { // Guard the parsing - ::osl::MutexGuard aGuard(getMutex()); + std::unique_lock aGuard(getMutex()); // must be reset setParser(this); @@ -1257,7 +1248,7 @@ std::unique_ptr<OSQLParseNode> OSQLParser::predicateTree(OUString& rErrorMessage s_pScanner->SetRule(OSQLScanner::GetSTRINGRule()); break; default: - if ( s_xLocaleData->getLocaleItem( m_pData->aLocale ).decimalSeparator.toChar() == ',' ) + if ( s_xLocaleData.get()->get()->getLocaleItem( m_pData->aLocale ).decimalSeparator.toChar() == ',' ) s_pScanner->SetRule(OSQLScanner::GetGERRule()); else s_pScanner->SetRule(OSQLScanner::GetENGRule()); @@ -1292,7 +1283,8 @@ std::unique_ptr<OSQLParseNode> OSQLParser::predicateTree(OUString& rErrorMessage // clear the garbage collector (*s_pGarbageCollector)->clearAndDelete(); - m_pParseTree.release(); // because the garbage collector deleted it + // coverity[leaked_storage : FALSE] - because the garbage collector deleted it + m_pParseTree.release(); return nullptr; } else @@ -1314,12 +1306,15 @@ std::unique_ptr<OSQLParseNode> OSQLParser::predicateTree(OUString& rErrorMessage } -OSQLParser::OSQLParser(const css::uno::Reference< css::uno::XComponentContext >& rxContext, const IParseContext* _pContext) +OSQLParser::OSQLParser(css::uno::Reference< css::uno::XComponentContext > xContext, + const IParseContext* _pContext, + const IParseContext* _pNeutral) :m_pContext(_pContext) + ,m_pNeutral(_pNeutral) ,m_pData( new OSQLParser_Data ) ,m_nFormatKey(0) ,m_nDateFormatKey(0) - ,m_xContext(rxContext) + ,m_xContext(std::move(xContext)) { @@ -1331,7 +1326,7 @@ OSQLParser::OSQLParser(const css::uno::Reference< css::uno::XComponentContext >& #endif #endif - ::osl::MutexGuard aGuard(getMutex()); + std::unique_lock aGuard(getMutex()); // Do we have to initialize the data? if (s_nRefCount == 0) { @@ -1339,8 +1334,8 @@ OSQLParser::OSQLParser(const css::uno::Reference< css::uno::XComponentContext >& s_pScanner->setScanner(); s_pGarbageCollector = new OSQLParseNodesGarbageCollector(); - if(!s_xLocaleData.is()) - s_xLocaleData = LocaleData::create(m_xContext); + if(!s_xLocaleData.get()) + s_xLocaleData.set(LocaleData::create(m_xContext)); // reset to UNKNOWN_RULE static_assert(OSQLParseNode::UNKNOWN_RULE==0, "UNKNOWN_RULE must be 0 for memset to 0 to work"); @@ -1352,109 +1347,109 @@ OSQLParser::OSQLParser(const css::uno::Reference< css::uno::XComponentContext >& OString sRuleName; // the name of the rule ("select_statement") } aRuleDescriptions[] = { - { OSQLParseNode::select_statement, "select_statement" }, - { OSQLParseNode::table_exp, "table_exp" }, - { OSQLParseNode::table_ref_commalist, "table_ref_commalist" }, - { OSQLParseNode::table_ref, "table_ref" }, - { OSQLParseNode::catalog_name, "catalog_name" }, - { OSQLParseNode::schema_name, "schema_name" }, - { OSQLParseNode::table_name, "table_name" }, - { OSQLParseNode::opt_column_commalist, "opt_column_commalist" }, - { OSQLParseNode::column_commalist, "column_commalist" }, - { OSQLParseNode::column_ref_commalist, "column_ref_commalist" }, - { OSQLParseNode::column_ref, "column_ref" }, - { OSQLParseNode::opt_order_by_clause, "opt_order_by_clause" }, - { OSQLParseNode::ordering_spec_commalist, "ordering_spec_commalist" }, - { OSQLParseNode::ordering_spec, "ordering_spec" }, - { OSQLParseNode::opt_asc_desc, "opt_asc_desc" }, - { OSQLParseNode::where_clause, "where_clause" }, - { OSQLParseNode::opt_where_clause, "opt_where_clause" }, - { OSQLParseNode::search_condition, "search_condition" }, - { OSQLParseNode::comparison, "comparison" }, - { OSQLParseNode::comparison_predicate, "comparison_predicate" }, - { OSQLParseNode::between_predicate, "between_predicate" }, - { OSQLParseNode::like_predicate, "like_predicate" }, - { OSQLParseNode::opt_escape, "opt_escape" }, - { OSQLParseNode::test_for_null, "test_for_null" }, - { OSQLParseNode::scalar_exp_commalist, "scalar_exp_commalist" }, - { OSQLParseNode::scalar_exp, "scalar_exp" }, - { OSQLParseNode::parameter_ref, "parameter_ref" }, - { OSQLParseNode::parameter, "parameter" }, - { OSQLParseNode::general_set_fct, "general_set_fct" }, - { OSQLParseNode::range_variable, "range_variable" }, - { OSQLParseNode::column, "column" }, - { OSQLParseNode::delete_statement_positioned, "delete_statement_positioned" }, - { OSQLParseNode::delete_statement_searched, "delete_statement_searched" }, - { OSQLParseNode::update_statement_positioned, "update_statement_positioned" }, - { OSQLParseNode::update_statement_searched, "update_statement_searched" }, - { OSQLParseNode::assignment_commalist, "assignment_commalist" }, - { OSQLParseNode::assignment, "assignment" }, - { OSQLParseNode::values_or_query_spec, "values_or_query_spec" }, - { OSQLParseNode::insert_statement, "insert_statement" }, - { OSQLParseNode::insert_atom_commalist, "insert_atom_commalist" }, - { OSQLParseNode::insert_atom, "insert_atom" }, - { OSQLParseNode::from_clause, "from_clause" }, - { OSQLParseNode::qualified_join, "qualified_join" }, - { OSQLParseNode::cross_union, "cross_union" }, - { OSQLParseNode::select_sublist, "select_sublist" }, - { OSQLParseNode::derived_column, "derived_column" }, - { OSQLParseNode::column_val, "column_val" }, - { OSQLParseNode::set_fct_spec, "set_fct_spec" }, - { OSQLParseNode::boolean_term, "boolean_term" }, - { OSQLParseNode::boolean_primary, "boolean_primary" }, - { OSQLParseNode::num_value_exp, "num_value_exp" }, - { OSQLParseNode::join_type, "join_type" }, - { OSQLParseNode::position_exp, "position_exp" }, - { OSQLParseNode::extract_exp, "extract_exp" }, - { OSQLParseNode::length_exp, "length_exp" }, - { OSQLParseNode::char_value_fct, "char_value_fct" }, - { OSQLParseNode::odbc_call_spec, "odbc_call_spec" }, - { OSQLParseNode::in_predicate, "in_predicate" }, - { OSQLParseNode::existence_test, "existence_test" }, - { OSQLParseNode::unique_test, "unique_test" }, - { OSQLParseNode::all_or_any_predicate, "all_or_any_predicate" }, - { OSQLParseNode::named_columns_join, "named_columns_join" }, - { OSQLParseNode::join_condition, "join_condition" }, - { OSQLParseNode::joined_table, "joined_table" }, - { OSQLParseNode::boolean_factor, "boolean_factor" }, - { OSQLParseNode::sql_not, "sql_not" }, - { OSQLParseNode::manipulative_statement, "manipulative_statement" }, - { OSQLParseNode::subquery, "subquery" }, - { OSQLParseNode::value_exp_commalist, "value_exp_commalist" }, - { OSQLParseNode::odbc_fct_spec, "odbc_fct_spec" }, - { OSQLParseNode::union_statement, "union_statement" }, - { OSQLParseNode::outer_join_type, "outer_join_type" }, - { OSQLParseNode::char_value_exp, "char_value_exp" }, - { OSQLParseNode::term, "term" }, - { OSQLParseNode::value_exp_primary, "value_exp_primary" }, - { OSQLParseNode::value_exp, "value_exp" }, - { OSQLParseNode::selection, "selection" }, - { OSQLParseNode::fold, "fold" }, - { OSQLParseNode::char_substring_fct, "char_substring_fct" }, - { OSQLParseNode::factor, "factor" }, - { OSQLParseNode::base_table_def, "base_table_def" }, - { OSQLParseNode::base_table_element_commalist, "base_table_element_commalist" }, - { OSQLParseNode::data_type, "data_type" }, - { OSQLParseNode::column_def, "column_def" }, - { OSQLParseNode::table_node, "table_node" }, - { OSQLParseNode::as_clause, "as_clause" }, - { OSQLParseNode::opt_as, "opt_as" }, - { OSQLParseNode::op_column_commalist, "op_column_commalist" }, - { OSQLParseNode::table_primary_as_range_column, "table_primary_as_range_column" }, - { OSQLParseNode::datetime_primary, "datetime_primary" }, - { OSQLParseNode::concatenation, "concatenation" }, - { OSQLParseNode::char_factor, "char_factor" }, - { OSQLParseNode::bit_value_fct, "bit_value_fct" }, - { OSQLParseNode::comparison_predicate_part_2, "comparison_predicate_part_2" }, - { OSQLParseNode::parenthesized_boolean_value_expression, "parenthesized_boolean_value_expression" }, - { OSQLParseNode::character_string_type, "character_string_type" }, - { OSQLParseNode::other_like_predicate_part_2, "other_like_predicate_part_2" }, - { OSQLParseNode::between_predicate_part_2, "between_predicate_part_2" }, - { OSQLParseNode::null_predicate_part_2, "null_predicate_part_2" }, - { OSQLParseNode::cast_spec, "cast_spec" }, - { OSQLParseNode::window_function, "window_function" } + { OSQLParseNode::select_statement, "select_statement"_ostr }, + { OSQLParseNode::table_exp, "table_exp"_ostr }, + { OSQLParseNode::table_ref_commalist, "table_ref_commalist"_ostr }, + { OSQLParseNode::table_ref, "table_ref"_ostr }, + { OSQLParseNode::catalog_name, "catalog_name"_ostr }, + { OSQLParseNode::schema_name, "schema_name"_ostr }, + { OSQLParseNode::table_name, "table_name"_ostr }, + { OSQLParseNode::opt_column_commalist, "opt_column_commalist"_ostr }, + { OSQLParseNode::column_commalist, "column_commalist"_ostr }, + { OSQLParseNode::column_ref_commalist, "column_ref_commalist"_ostr }, + { OSQLParseNode::column_ref, "column_ref"_ostr }, + { OSQLParseNode::opt_order_by_clause, "opt_order_by_clause"_ostr }, + { OSQLParseNode::ordering_spec_commalist, "ordering_spec_commalist"_ostr }, + { OSQLParseNode::ordering_spec, "ordering_spec"_ostr }, + { OSQLParseNode::opt_asc_desc, "opt_asc_desc"_ostr }, + { OSQLParseNode::where_clause, "where_clause"_ostr }, + { OSQLParseNode::opt_where_clause, "opt_where_clause"_ostr }, + { OSQLParseNode::search_condition, "search_condition"_ostr }, + { OSQLParseNode::comparison, "comparison"_ostr }, + { OSQLParseNode::comparison_predicate, "comparison_predicate"_ostr }, + { OSQLParseNode::between_predicate, "between_predicate"_ostr }, + { OSQLParseNode::like_predicate, "like_predicate"_ostr }, + { OSQLParseNode::opt_escape, "opt_escape"_ostr }, + { OSQLParseNode::test_for_null, "test_for_null"_ostr }, + { OSQLParseNode::scalar_exp_commalist, "scalar_exp_commalist"_ostr }, + { OSQLParseNode::scalar_exp, "scalar_exp"_ostr }, + { OSQLParseNode::parameter_ref, "parameter_ref"_ostr }, + { OSQLParseNode::parameter, "parameter"_ostr }, + { OSQLParseNode::general_set_fct, "general_set_fct"_ostr }, + { OSQLParseNode::range_variable, "range_variable"_ostr }, + { OSQLParseNode::column, "column"_ostr }, + { OSQLParseNode::delete_statement_positioned, "delete_statement_positioned"_ostr }, + { OSQLParseNode::delete_statement_searched, "delete_statement_searched"_ostr }, + { OSQLParseNode::update_statement_positioned, "update_statement_positioned"_ostr }, + { OSQLParseNode::update_statement_searched, "update_statement_searched"_ostr }, + { OSQLParseNode::assignment_commalist, "assignment_commalist"_ostr }, + { OSQLParseNode::assignment, "assignment"_ostr }, + { OSQLParseNode::values_or_query_spec, "values_or_query_spec"_ostr }, + { OSQLParseNode::insert_statement, "insert_statement"_ostr }, + { OSQLParseNode::insert_atom_commalist, "insert_atom_commalist"_ostr }, + { OSQLParseNode::insert_atom, "insert_atom"_ostr }, + { OSQLParseNode::from_clause, "from_clause"_ostr }, + { OSQLParseNode::qualified_join, "qualified_join"_ostr }, + { OSQLParseNode::cross_union, "cross_union"_ostr }, + { OSQLParseNode::select_sublist, "select_sublist"_ostr }, + { OSQLParseNode::derived_column, "derived_column"_ostr }, + { OSQLParseNode::column_val, "column_val"_ostr }, + { OSQLParseNode::set_fct_spec, "set_fct_spec"_ostr }, + { OSQLParseNode::boolean_term, "boolean_term"_ostr }, + { OSQLParseNode::boolean_primary, "boolean_primary"_ostr }, + { OSQLParseNode::num_value_exp, "num_value_exp"_ostr }, + { OSQLParseNode::join_type, "join_type"_ostr }, + { OSQLParseNode::position_exp, "position_exp"_ostr }, + { OSQLParseNode::extract_exp, "extract_exp"_ostr }, + { OSQLParseNode::length_exp, "length_exp"_ostr }, + { OSQLParseNode::char_value_fct, "char_value_fct"_ostr }, + { OSQLParseNode::odbc_call_spec, "odbc_call_spec"_ostr }, + { OSQLParseNode::in_predicate, "in_predicate"_ostr }, + { OSQLParseNode::existence_test, "existence_test"_ostr }, + { OSQLParseNode::unique_test, "unique_test"_ostr }, + { OSQLParseNode::all_or_any_predicate, "all_or_any_predicate"_ostr }, + { OSQLParseNode::named_columns_join, "named_columns_join"_ostr }, + { OSQLParseNode::join_condition, "join_condition"_ostr }, + { OSQLParseNode::joined_table, "joined_table"_ostr }, + { OSQLParseNode::boolean_factor, "boolean_factor"_ostr }, + { OSQLParseNode::sql_not, "sql_not"_ostr }, + { OSQLParseNode::manipulative_statement, "manipulative_statement"_ostr }, + { OSQLParseNode::subquery, "subquery"_ostr }, + { OSQLParseNode::value_exp_commalist, "value_exp_commalist"_ostr }, + { OSQLParseNode::odbc_fct_spec, "odbc_fct_spec"_ostr }, + { OSQLParseNode::union_statement, "union_statement"_ostr }, + { OSQLParseNode::outer_join_type, "outer_join_type"_ostr }, + { OSQLParseNode::char_value_exp, "char_value_exp"_ostr }, + { OSQLParseNode::term, "term"_ostr }, + { OSQLParseNode::value_exp_primary, "value_exp_primary"_ostr }, + { OSQLParseNode::value_exp, "value_exp"_ostr }, + { OSQLParseNode::selection, "selection"_ostr }, + { OSQLParseNode::fold, "fold"_ostr }, + { OSQLParseNode::char_substring_fct, "char_substring_fct"_ostr }, + { OSQLParseNode::factor, "factor"_ostr }, + { OSQLParseNode::base_table_def, "base_table_def"_ostr }, + { OSQLParseNode::base_table_element_commalist, "base_table_element_commalist"_ostr }, + { OSQLParseNode::data_type, "data_type"_ostr }, + { OSQLParseNode::column_def, "column_def"_ostr }, + { OSQLParseNode::table_node, "table_node"_ostr }, + { OSQLParseNode::as_clause, "as_clause"_ostr }, + { OSQLParseNode::opt_as, "opt_as"_ostr }, + { OSQLParseNode::op_column_commalist, "op_column_commalist"_ostr }, + { OSQLParseNode::table_primary_as_range_column, "table_primary_as_range_column"_ostr }, + { OSQLParseNode::datetime_primary, "datetime_primary"_ostr }, + { OSQLParseNode::concatenation, "concatenation"_ostr }, + { OSQLParseNode::char_factor, "char_factor"_ostr }, + { OSQLParseNode::bit_value_fct, "bit_value_fct"_ostr }, + { OSQLParseNode::comparison_predicate_part_2, "comparison_predicate_part_2"_ostr }, + { OSQLParseNode::parenthesized_boolean_value_expression, "parenthesized_boolean_value_expression"_ostr }, + { OSQLParseNode::character_string_type, "character_string_type"_ostr }, + { OSQLParseNode::other_like_predicate_part_2, "other_like_predicate_part_2"_ostr }, + { OSQLParseNode::between_predicate_part_2, "between_predicate_part_2"_ostr }, + { OSQLParseNode::null_predicate_part_2, "null_predicate_part_2"_ostr }, + { OSQLParseNode::cast_spec, "cast_spec"_ostr }, + { OSQLParseNode::window_function, "window_function"_ostr } }; - const size_t nRuleMapCount = SAL_N_ELEMENTS( aRuleDescriptions ); + const size_t nRuleMapCount = std::size( aRuleDescriptions ); // added a new rule? Adjust this map! // +1 for UNKNOWN_RULE static_assert(nRuleMapCount + 1 == static_cast<size_t>(OSQLParseNode::rule_count), "must be equal"); @@ -1481,7 +1476,7 @@ OSQLParser::OSQLParser(const css::uno::Reference< css::uno::XComponentContext >& OSQLParser::~OSQLParser() { - ::osl::MutexGuard aGuard(getMutex()); + std::unique_lock aGuard(getMutex()); OSL_ENSURE(s_nRefCount > 0, "OSQLParser::~OSQLParser() : suspicious call : has a refcount of 0 !"); if (!--s_nRefCount) { @@ -1491,11 +1486,8 @@ OSQLParser::~OSQLParser() delete s_pGarbageCollector; s_pGarbageCollector = nullptr; - // Is only set the first time, so we should delete it only when there are no more instances - s_xLocaleData = nullptr; - RuleIDMap aEmpty; - s_aReverseRuleIDLookup.swap( aEmpty ); + RuleIDMap().swap(s_aReverseRuleIDLookup); } m_pParseTree = nullptr; } @@ -1509,7 +1501,7 @@ void OSQLParseNode::substituteParameterNames(OSQLParseNode const * _pNode) if(SQL_ISRULE(pChildNode,parameter) && pChildNode->count() > 1) { OSQLParseNode* pNewNode = new OSQLParseNode("?" ,SQLNodeType::Punctuation,0); - delete pChildNode->replace(pChildNode->getChild(0),pNewNode); + pChildNode->replaceAndDelete(pChildNode->getChild(0), pNewNode); sal_Int32 nChildCount = pChildNode->count(); for(sal_Int32 j=1;j < nChildCount;++j) delete pChildNode->removeAt(1); @@ -1599,7 +1591,7 @@ OSQLParseNode::OSQLParseNode(const char * pNewValue, OSL_ENSURE(m_eNodeType >= SQLNodeType::Rule && m_eNodeType <= SQLNodeType::Concat,"OSQLParseNode: created with invalid NodeType"); } -OSQLParseNode::OSQLParseNode(const OString &_rNewValue, +OSQLParseNode::OSQLParseNode(std::string_view _rNewValue, SQLNodeType eNewNodeType, sal_uInt32 nNewNodeID) :m_pParent(nullptr) @@ -1610,11 +1602,11 @@ OSQLParseNode::OSQLParseNode(const OString &_rNewValue, OSL_ENSURE(m_eNodeType >= SQLNodeType::Rule && m_eNodeType <= SQLNodeType::Concat,"OSQLParseNode: created with invalid NodeType"); } -OSQLParseNode::OSQLParseNode(const OUString &_rNewValue, +OSQLParseNode::OSQLParseNode(OUString _aNewValue, SQLNodeType eNewNodeType, sal_uInt32 nNewNodeID) :m_pParent(nullptr) - ,m_aNodeValue(_rNewValue) + ,m_aNodeValue(std::move(_aNewValue)) ,m_eNodeType(eNewNodeType) ,m_nNodeID(nNewNodeID) { @@ -1702,54 +1694,53 @@ void OSQLParseNode::append(OSQLParseNode* pNewNode) bool OSQLParseNode::addDateValue(OUStringBuffer& rString, const SQLParseNodeParameter& rParam) const { // special display for date/time values - if (SQL_ISRULE(this,set_fct_spec) && SQL_ISPUNCTUATION(m_aChildren[0],"{")) - { - const OSQLParseNode* pODBCNode = m_aChildren[1].get(); - const OSQLParseNode* pODBCNodeChild = pODBCNode->m_aChildren[0].get(); + if (!SQL_ISRULE(this,set_fct_spec) || !SQL_ISPUNCTUATION(m_aChildren[0],"{")) + return false; - if (pODBCNodeChild->getNodeType() == SQLNodeType::Keyword && ( - SQL_ISTOKEN(pODBCNodeChild, D) || - SQL_ISTOKEN(pODBCNodeChild, T) || - SQL_ISTOKEN(pODBCNodeChild, TS) )) - { - OUString suQuote("'"); - if (rParam.bPredicate) - { - if (rParam.aMetaData.shouldEscapeDateTime()) - { - suQuote = "#"; - } - } - else - { - if (rParam.aMetaData.shouldEscapeDateTime()) - { - // suQuote = "'"; - return false; - } - } + const OSQLParseNode* pODBCNode = m_aChildren[1].get(); + const OSQLParseNode* pODBCNodeChild = pODBCNode->m_aChildren[0].get(); - if (!rString.isEmpty()) - rString.append(" "); - rString.append(suQuote); - const OUString sTokenValue = pODBCNode->m_aChildren[1]->getTokenValue(); - if (SQL_ISTOKEN(pODBCNodeChild, D)) - { - rString.append(rParam.bPredicate ? convertDateString(rParam, sTokenValue) : sTokenValue); - } - else if (SQL_ISTOKEN(pODBCNodeChild, T)) - { - rString.append(rParam.bPredicate ? convertTimeString(rParam, sTokenValue) : sTokenValue); - } - else - { - rString.append(rParam.bPredicate ? convertDateTimeString(rParam, sTokenValue) : sTokenValue); - } - rString.append(suQuote); - return true; - } + if (pODBCNodeChild->getNodeType() != SQLNodeType::Keyword || !( + SQL_ISTOKEN(pODBCNodeChild, D) || + SQL_ISTOKEN(pODBCNodeChild, T) || + SQL_ISTOKEN(pODBCNodeChild, TS) )) + return false; + + OUString suQuote("'"); + if (rParam.bPredicate) + { + if (rParam.aMetaData.shouldEscapeDateTime()) + { + suQuote = "#"; + } } - return false; + else + { + if (rParam.aMetaData.shouldEscapeDateTime()) + { + // suQuote = "'"; + return false; + } + } + + if (!rString.isEmpty()) + rString.append(" "); + rString.append(suQuote); + const OUString sTokenValue = pODBCNode->m_aChildren[1]->getTokenValue(); + if (SQL_ISTOKEN(pODBCNodeChild, D)) + { + rString.append(rParam.bPredicate ? convertDateString(rParam, sTokenValue) : sTokenValue); + } + else if (SQL_ISTOKEN(pODBCNodeChild, T)) + { + rString.append(rParam.bPredicate ? convertTimeString(rParam, sTokenValue) : sTokenValue); + } + else + { + rString.append(rParam.bPredicate ? convertDateTimeString(rParam, sTokenValue) : sTokenValue); + } + rString.append(suQuote); + return true; } void OSQLParseNode::replaceNodeValue(const OUString& rTableAlias, const OUString& rColumnName) @@ -1843,10 +1834,11 @@ void OSQLParseNode::disjunctiveNormalForm(OSQLParseNode*& pSearchCondition) OSQLParseNode* pNewRight = nullptr; // cut right from parent - pSearchCondition->removeAt(2); + OSQLParseNode* pOldRight = pSearchCondition->removeAt(2); + assert(pOldRight == pRight); - pNewRight = MakeANDNode(pOr->removeAt(2) ,pRight); - pNewLeft = MakeANDNode(pOr->removeAt(sal_uInt32(0)) ,new OSQLParseNode(*pRight)); + pNewRight = MakeANDNode(pOr->removeAt(2), pOldRight); + pNewLeft = MakeANDNode(pOr->removeAt(sal_uInt32(0)), new OSQLParseNode(*pOldRight)); pNewNode = MakeORNode(pNewLeft,pNewRight); // and append new Node replaceAndReset(pSearchCondition,pNewNode); @@ -1862,10 +1854,11 @@ void OSQLParseNode::disjunctiveNormalForm(OSQLParseNode*& pSearchCondition) OSQLParseNode* pNewRight = nullptr; // cut left from parent - pSearchCondition->removeAt(sal_uInt32(0)); + OSQLParseNode* pOldLeft = pSearchCondition->removeAt(sal_uInt32(0)); + assert(pOldLeft == pLeft); - pNewRight = MakeANDNode(pLeft,pOr->removeAt(2)); - pNewLeft = MakeANDNode(new OSQLParseNode(*pLeft),pOr->removeAt(sal_uInt32(0))); + pNewRight = MakeANDNode(pOldLeft, pOr->removeAt(2)); + pNewLeft = MakeANDNode(new OSQLParseNode(*pOldLeft), pOr->removeAt(sal_uInt32(0))); pNewNode = MakeORNode(pNewLeft,pNewRight); // and append new Node @@ -1873,9 +1866,9 @@ void OSQLParseNode::disjunctiveNormalForm(OSQLParseNode*& pSearchCondition) disjunctiveNormalForm(pSearchCondition); } else if(SQL_ISRULE(pLeft,boolean_primary) && (!SQL_ISRULE(pLeft->getChild(1),search_condition) || !SQL_ISRULE(pLeft->getChild(1),boolean_term))) - pSearchCondition->replace(pLeft, pLeft->removeAt(1)); + pSearchCondition->replaceAndDelete(pLeft, pLeft->removeAt(1)); else if(SQL_ISRULE(pRight,boolean_primary) && (!SQL_ISRULE(pRight->getChild(1),search_condition) || !SQL_ISRULE(pRight->getChild(1),boolean_term))) - pSearchCondition->replace(pRight, pRight->removeAt(1)); + pSearchCondition->replaceAndDelete(pRight, pRight->removeAt(1)); } } @@ -1962,8 +1955,7 @@ void OSQLParseNode::negateSearchCondition(OSQLParseNode*& pSearchCondition, bool assert(SQL_ISTOKEN(pNot,NOT)); pNotNot = new OSQLParseNode(OUString(),SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::sql_not)); } - pComparison->replace(pNot, pNotNot); - delete pNot; + pComparison->replaceAndDelete(pNot, pNotNot); } else { @@ -1992,8 +1984,7 @@ void OSQLParseNode::negateSearchCondition(OSQLParseNode*& pSearchCondition, bool pNewComparison = new OSQLParseNode("=",SQLNodeType::Equal,SQL_EQUAL); break; } - pSearchCondition->replace(pComparison, pNewComparison); - delete pComparison; + pSearchCondition->replaceAndDelete(pComparison, pNewComparison); } } @@ -2015,8 +2006,7 @@ void OSQLParseNode::negateSearchCondition(OSQLParseNode*& pSearchCondition, bool assert(SQL_ISTOKEN(pNot,NOT)); pNotNot = new OSQLParseNode(OUString(),SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::sql_not)); } - pPart2->replace(pNot, pNotNot); - delete pNot; + pPart2->replaceAndDelete(pNot, pNotNot); } else if(bNegate && SQL_ISRULE(pSearchCondition,like_predicate)) { @@ -2026,8 +2016,7 @@ void OSQLParseNode::negateSearchCondition(OSQLParseNode*& pSearchCondition, bool pNotNot = new OSQLParseNode("NOT",SQLNodeType::Keyword,SQL_TOKEN_NOT); else pNotNot = new OSQLParseNode(OUString(),SQLNodeType::Rule,OSQLParser::RuleID(OSQLParseNode::sql_not)); - pSearchCondition->getChild( 1 )->replace(pNot, pNotNot); - delete pNot; + pSearchCondition->getChild( 1 )->replaceAndDelete(pNot, pNotNot); } } @@ -2363,7 +2352,7 @@ void OSQLParseNode::showParseTree( OUStringBuffer& _inout_rBuffer, sal_uInt32 nL void OSQLParseNode::insert(sal_uInt32 nPos, OSQLParseNode* pNewSubTree) { - OSL_ENSURE(pNewSubTree != nullptr, "OSQLParseNode: invalid NewSubTree"); + assert(pNewSubTree != nullptr && "OSQLParseNode: invalid NewSubTree"); OSL_ENSURE(pNewSubTree->getParent() == nullptr, "OSQLParseNode: Node is not an orphan"); // Create connection to getParent @@ -2375,7 +2364,7 @@ void OSQLParseNode::insert(sal_uInt32 nPos, OSQLParseNode* pNewSubTree) OSQLParseNode* OSQLParseNode::removeAt(sal_uInt32 nPos) { - OSL_ENSURE(nPos < m_aChildren.size(),"Illegal position for removeAt"); + assert(nPos < m_aChildren.size() && "Illegal position for removeAt"); auto aPos(m_aChildren.begin() + nPos); auto pNode = std::move(*aPos); @@ -2388,27 +2377,24 @@ OSQLParseNode* OSQLParseNode::removeAt(sal_uInt32 nPos) // Replace methods -OSQLParseNode* OSQLParseNode::replace(OSQLParseNode* pOldSubNode, OSQLParseNode* pNewSubNode ) +void OSQLParseNode::replaceAndDelete(OSQLParseNode* pOldSubNode, OSQLParseNode* pNewSubNode ) { - OSL_ENSURE(pOldSubNode != nullptr && pNewSubNode != nullptr, "OSQLParseNode: invalid nodes"); - OSL_ENSURE(pNewSubNode->getParent() == nullptr, "OSQLParseNode: node already has getParent"); - OSL_ENSURE(std::any_of(m_aChildren.begin(), m_aChildren.end(), - [&] (std::unique_ptr<OSQLParseNode> const & r) { return r.get() == pOldSubNode; }), - "OSQLParseNode::Replace() Node not element of parent"); - OSL_ENSURE(std::none_of(m_aChildren.begin(), m_aChildren.end(), - [&] (std::unique_ptr<OSQLParseNode> const & r) { return r.get() == pNewSubNode; }), - "OSQLParseNode::Replace() Node already element of parent"); + assert(pOldSubNode != nullptr && pNewSubNode != nullptr && "OSQLParseNode: invalid nodes"); + assert(pOldSubNode != pNewSubNode && "OSQLParseNode: same node"); + assert(pNewSubNode->getParent() == nullptr && "OSQLParseNode: node already has getParent"); + assert(std::any_of(m_aChildren.begin(), m_aChildren.end(), + [&] (std::unique_ptr<OSQLParseNode> const & r) { return r.get() == pOldSubNode; }) + && "OSQLParseNode::Replace() Node not element of parent"); + assert(std::none_of(m_aChildren.begin(), m_aChildren.end(), + [&] (std::unique_ptr<OSQLParseNode> const & r) { return r.get() == pNewSubNode; }) + && "OSQLParseNode::Replace() Node already element of parent"); pOldSubNode->setParent( nullptr ); pNewSubNode->setParent( this ); auto it = std::find_if(m_aChildren.begin(), m_aChildren.end(), [&pOldSubNode](const std::unique_ptr<OSQLParseNode>& rxChild) { return rxChild.get() == pOldSubNode; }); - if (it != m_aChildren.end()) - { - it->release(); - it->reset(pNewSubNode); - } - return pOldSubNode; + assert(it != m_aChildren.end()); + it->reset(pNewSubNode); } void OSQLParseNode::parseLeaf(OUStringBuffer& rString, const SQLParseNodeParameter& rParam) const @@ -2428,7 +2414,7 @@ void OSQLParseNode::parseLeaf(OUStringBuffer& rString, const SQLParseNodeParamet case SQLNodeType::String: if (!rString.isEmpty()) rString.append(" "); - rString.append(SetQuotation(m_aNodeValue,"\'","\'\'")); + rString.append(SetQuotation(m_aNodeValue, u"\'", u"\'\'")); break; case SQLNodeType::Name: if (!rString.isEmpty()) @@ -2472,7 +2458,7 @@ void OSQLParseNode::parseLeaf(OUStringBuffer& rString, const SQLParseNodeParamet case SQLNodeType::ApproxNum: { OUString aTmp = m_aNodeValue; - static OUString strPoint("."); + static constexpr OUString strPoint(u"."_ustr); if (rParam.bInternational && rParam.bPredicate && rParam.sDecSep != strPoint) aTmp = aTmp.replaceAll(strPoint, rParam.sDecSep); @@ -2508,9 +2494,9 @@ void OSQLParseNode::parseLeaf(OUStringBuffer& rString, const SQLParseNodeParamet } -sal_Int32 OSQLParser::getFunctionReturnType(const OUString& _sFunctionName, const IParseContext* pContext) +sal_Int32 OSQLParser::getFunctionReturnType(std::u16string_view _sFunctionName, const IParseContext* pContext) { - sal_Int32 nType = DataType::VARCHAR; + sal_Int32 nType = DataType::SQLNULL; OString sFunctionName(OUStringToOString(_sFunctionName,RTL_TEXTENCODING_UTF8)); if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_ASCII,pContext))) nType = DataType::INTEGER; @@ -2747,13 +2733,13 @@ OSQLParseNodesContainer::~OSQLParseNodesContainer() void OSQLParseNodesContainer::push_back(OSQLParseNode* _pNode) { - ::osl::MutexGuard aGuard(m_aMutex); + std::unique_lock aGuard(m_aMutex); m_aNodes.push_back(_pNode); } void OSQLParseNodesContainer::erase(OSQLParseNode* _pNode) { - ::osl::MutexGuard aGuard(m_aMutex); + std::unique_lock aGuard(m_aMutex); if ( !m_aNodes.empty() ) { std::vector< OSQLParseNode* >::iterator aFind = std::find(m_aNodes.begin(), m_aNodes.end(),_pNode); @@ -2764,13 +2750,13 @@ void OSQLParseNodesContainer::erase(OSQLParseNode* _pNode) void OSQLParseNodesContainer::clear() { - ::osl::MutexGuard aGuard(m_aMutex); + std::unique_lock aGuard(m_aMutex); m_aNodes.clear(); } void OSQLParseNodesContainer::clearAndDelete() { - ::osl::MutexGuard aGuard(m_aMutex); + std::unique_lock aGuard(m_aMutex); // clear the garbage collector while ( !m_aNodes.empty() ) { @@ -2779,7 +2765,9 @@ void OSQLParseNodesContainer::clearAndDelete() { pNode = pNode->getParent(); } + aGuard.unlock(); // can call back into this object during destruction delete pNode; + aGuard.lock(); } } } // namespace connectivity diff --git a/connectivity/source/resource/sharedresources.cxx b/connectivity/source/resource/sharedresources.cxx index 3f7062f6be52..cc6f65e64541 100644 --- a/connectivity/source/resource/sharedresources.cxx +++ b/connectivity/source/resource/sharedresources.cxx @@ -44,7 +44,7 @@ namespace connectivity static SharedResources_Impl& getInstance(); - OUString getResourceString(const char* pId); + OUString getResourceString(TranslateId pId) const; private: SharedResources_Impl(); @@ -66,7 +66,7 @@ namespace connectivity { } - OUString SharedResources_Impl::getResourceString(const char* pId) + OUString SharedResources_Impl::getResourceString(TranslateId pId) const { return Translate::get(pId, m_aLocale); } @@ -100,20 +100,13 @@ namespace connectivity namespace { - size_t lcl_substitute( OUString& _inout_rString, - const char* _pAsciiPattern, const OUString& _rReplace ) + bool lcl_substitute( OUString& _inout_rString, + const char* _pAsciiPattern, std::u16string_view _rReplace ) { - size_t nOccurrences = 0; - + OUString oldString = _inout_rString; OUString sPattern( OUString::createFromAscii( _pAsciiPattern ) ); - sal_Int32 nIndex = 0; - while ( ( nIndex = _inout_rString.indexOf( sPattern ) ) > -1 ) - { - ++nOccurrences; - _inout_rString = _inout_rString.replaceAt( nIndex, sPattern.getLength(), _rReplace ); - } - - return nOccurrences; + _inout_rString = _inout_rString.replaceAll(sPattern, _rReplace); + return oldString != _inout_rString; } } @@ -129,13 +122,13 @@ namespace connectivity } - OUString SharedResources::getResourceString(const char* pResId) const + OUString SharedResources::getResourceString(TranslateId pResId) const { return SharedResources_Impl::getInstance().getResourceString(pResId); } - OUString SharedResources::getResourceStringWithSubstitution(const char* pResId, + OUString SharedResources::getResourceStringWithSubstitution(TranslateId pResId, const char* _pAsciiPatternToReplace, const OUString& _rStringToSubstitute ) const { OUString sString( SharedResources_Impl::getInstance().getResourceString(pResId) ); @@ -145,7 +138,7 @@ namespace connectivity } - OUString SharedResources::getResourceStringWithSubstitution(const char* pResId, + OUString SharedResources::getResourceStringWithSubstitution(TranslateId pResId, const char* _pAsciiPatternToReplace1, const OUString& _rStringToSubstitute1, const char* _pAsciiPatternToReplace2, const OUString& _rStringToSubstitute2 ) const { @@ -158,7 +151,7 @@ namespace connectivity } - OUString SharedResources::getResourceStringWithSubstitution(const char* pResId, + OUString SharedResources::getResourceStringWithSubstitution(TranslateId pResId, const char* _pAsciiPatternToReplace1, const OUString& _rStringToSubstitute1, const char* _pAsciiPatternToReplace2, const OUString& _rStringToSubstitute2, const char* _pAsciiPatternToReplace3, const OUString& _rStringToSubstitute3 ) const @@ -173,7 +166,7 @@ namespace connectivity return sString; } - OUString SharedResources::getResourceStringWithSubstitution(const char* pResId, + OUString SharedResources::getResourceStringWithSubstitution(TranslateId pResId, const std::vector< std::pair<const char* , OUString > >& _rStringToSubstitutes) const { OUString sString( SharedResources_Impl::getInstance().getResourceString(pResId) ); diff --git a/connectivity/source/sdbcx/VCollection.cxx b/connectivity/source/sdbcx/VCollection.cxx index d7a716a59839..0fa6cace50e0 100644 --- a/connectivity/source/sdbcx/VCollection.cxx +++ b/connectivity/source/sdbcx/VCollection.cxx @@ -30,6 +30,7 @@ #include <comphelper/property.hxx> #include <comphelper/servicehelper.hxx> #include <cppuhelper/exc_hlp.hxx> +#include <o3tl/unreachable.hxx> #include <TConnection.hxx> #include <strings.hrc> #include <resource/sharedresources.hxx> @@ -301,7 +302,7 @@ Any SAL_CALL OCollection::getByIndex( sal_Int32 Index ) if (Index < 0 || Index >= m_pElements->size() ) throw IndexOutOfBoundsException(OUString::number(Index),static_cast<XTypeProvider*>(this)); - return makeAny(getObject(Index)); + return Any(getObject(Index)); } Any SAL_CALL OCollection::getByName( const OUString& aName ) @@ -318,7 +319,7 @@ Any SAL_CALL OCollection::getByName( const OUString& aName ) throw NoSuchElementException( sError, static_cast< XTypeProvider* >( this ) ); } - return makeAny(getObject(m_pElements->findColumn(aName))); + return Any(getObject(m_pElements->findColumn(aName))); } Sequence< OUString > SAL_CALL OCollection::getElementNames( ) @@ -373,7 +374,7 @@ void SAL_CALL OCollection::appendByDescriptor( const Reference< XPropertySet >& if ( !xNewlyCreated.is() ) throw RuntimeException(); - ODescriptor* pDescriptor = comphelper::getUnoTunnelImplementation<ODescriptor>( xNewlyCreated ); + ODescriptor* pDescriptor = dynamic_cast<ODescriptor*>( xNewlyCreated.get() ); if ( pDescriptor ) pDescriptor->setNew( false ); @@ -382,7 +383,7 @@ void SAL_CALL OCollection::appendByDescriptor( const Reference< XPropertySet >& m_pElements->insert( sName, xNewlyCreated ); // notify our container listeners - ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(sName), makeAny(xNewlyCreated), Any()); + ContainerEvent aEvent(static_cast<XContainer*>(this), Any(sName), Any(xNewlyCreated), Any()); aGuard.clear(); m_aContainerListeners.notifyEach( &XContainerListener::elementInserted, aEvent ); } @@ -422,11 +423,11 @@ void OCollection::dropImpl(sal_Int32 _nIndex, bool _bReallyDrop) void OCollection::notifyElementRemoved(const OUString& _sName) { - ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(_sName), Any(), Any()); + ContainerEvent aEvent(static_cast<XContainer*>(this), Any(_sName), Any(), Any()); // note that xExistent may be empty, in case somebody removed the data source while it is not alive at this moment - OInterfaceIteratorHelper2 aListenerLoop(m_aContainerListeners); + OInterfaceIteratorHelper3 aListenerLoop(m_aContainerListeners); while (aListenerLoop.hasMoreElements()) - static_cast<XContainerListener*>(aListenerLoop.next())->elementRemoved(aEvent); + aListenerLoop.next()->elementRemoved(aEvent); } sal_Int32 SAL_CALL OCollection::findColumn( const OUString& columnName ) @@ -434,9 +435,7 @@ sal_Int32 SAL_CALL OCollection::findColumn( const OUString& columnName ) if ( !m_pElements->exists(columnName) ) { ::dbtools::throwInvalidColumnException( columnName, static_cast< XIndexAccess*>(this) ); -#if !(defined(_MSC_VER) && defined(ENABLE_LTO)) - assert(false); -#endif + O3TL_UNREACHABLE; } return m_pElements->findColumn(columnName) + 1; // because columns start at one @@ -459,12 +458,12 @@ void SAL_CALL OCollection::removeContainerListener( const Reference< XContainerL m_aContainerListeners.removeInterface(_rxListener); } -void SAL_CALL OCollection::acquire() throw() +void SAL_CALL OCollection::acquire() noexcept { m_rParent.acquire(); } -void SAL_CALL OCollection::release() throw() +void SAL_CALL OCollection::release() noexcept { m_rParent.release(); } @@ -518,11 +517,11 @@ void OCollection::renameObject(const OUString& _sOldName, const OUString& _sNewN if ( m_pElements->rename(_sOldName,_sNewName) ) { - ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(_sNewName), makeAny(m_pElements->getObject(_sNewName)),makeAny(_sOldName)); + ContainerEvent aEvent(static_cast<XContainer*>(this), Any(_sNewName), Any(m_pElements->getObject(_sNewName)),Any(_sOldName)); // note that xExistent may be empty, in case somebody removed the data source while it is not alive at this moment - OInterfaceIteratorHelper2 aListenerLoop(m_aContainerListeners); + OInterfaceIteratorHelper3 aListenerLoop(m_aContainerListeners); while (aListenerLoop.hasMoreElements()) - static_cast<XContainerListener*>(aListenerLoop.next())->elementReplaced(aEvent); + aListenerLoop.next()->elementReplaced(aEvent); } } diff --git a/connectivity/source/sdbcx/VColumn.cxx b/connectivity/source/sdbcx/VColumn.cxx index 23993453101a..ad9a52ed12ed 100644 --- a/connectivity/source/sdbcx/VColumn.cxx +++ b/connectivity/source/sdbcx/VColumn.cxx @@ -23,6 +23,7 @@ #include <cppuhelper/supportsservice.hxx> #include <TConnection.hxx> #include <com/sun/star/sdbc/ColumnValue.hpp> +#include <utility> using namespace connectivity; using namespace connectivity::sdbcx; @@ -65,9 +66,9 @@ OColumn::OColumn(bool _bCase) } OColumn::OColumn( const OUString& Name, - const OUString& TypeName, - const OUString& DefaultValue, - const OUString& Description, + OUString TypeName, + OUString DefaultValue, + OUString Description, sal_Int32 IsNullable, sal_Int32 Precision, sal_Int32 Scale, @@ -76,14 +77,14 @@ OColumn::OColumn( const OUString& Name, bool IsRowVersion, bool IsCurrency, bool _bCase, - const OUString& CatalogName, - const OUString& SchemaName, - const OUString& TableName) + OUString CatalogName, + OUString SchemaName, + OUString TableName) :OColumnDescriptor_BASE(m_aMutex) ,ODescriptor(OColumnDescriptor_BASE::rBHelper,_bCase) - ,m_TypeName(TypeName) - ,m_Description(Description) - ,m_DefaultValue(DefaultValue) + ,m_TypeName(std::move(TypeName)) + ,m_Description(std::move(Description)) + ,m_DefaultValue(std::move(DefaultValue)) ,m_IsNullable(IsNullable) ,m_Precision(Precision) ,m_Scale(Scale) @@ -91,9 +92,9 @@ OColumn::OColumn( const OUString& Name, ,m_IsAutoIncrement(IsAutoIncrement) ,m_IsRowVersion(IsRowVersion) ,m_IsCurrency(IsCurrency) - ,m_CatalogName(CatalogName) - ,m_SchemaName(SchemaName) - ,m_TableName(TableName) + ,m_CatalogName(std::move(CatalogName)) + ,m_SchemaName(std::move(SchemaName)) + ,m_TableName(std::move(TableName)) { m_Name = Name; @@ -114,12 +115,12 @@ OColumn::~OColumn() return *OColumn_PROP::getArrayHelper(isNew() ? 1 : 0); } -void SAL_CALL OColumn::acquire() throw() +void SAL_CALL OColumn::acquire() noexcept { OColumnDescriptor_BASE::acquire(); } -void SAL_CALL OColumn::release() throw() +void SAL_CALL OColumn::release() noexcept { OColumnDescriptor_BASE::release(); } @@ -169,10 +170,6 @@ void OColumn::construct() void OColumn::disposing() { OPropertySetHelper::disposing(); - - ::osl::MutexGuard aGuard(m_aMutex); - checkDisposed(OColumnDescriptor_BASE::rBHelper.bDisposed); - } Reference< XPropertySet > SAL_CALL OColumn::createDataDescriptor( ) @@ -180,8 +177,7 @@ Reference< XPropertySet > SAL_CALL OColumn::createDataDescriptor( ) ::osl::MutexGuard aGuard(m_aMutex); checkDisposed(OColumnDescriptor_BASE::rBHelper.bDisposed); - - OColumn* pNewColumn = new OColumn( m_Name, + rtl::Reference<OColumn> pNewColumn = new OColumn( m_Name, m_TypeName, m_DefaultValue, m_Description, diff --git a/connectivity/source/sdbcx/VDescriptor.cxx b/connectivity/source/sdbcx/VDescriptor.cxx index 8a32a1b58b39..d6ceabc96837 100644 --- a/connectivity/source/sdbcx/VDescriptor.cxx +++ b/connectivity/source/sdbcx/VDescriptor.cxx @@ -28,7 +28,6 @@ namespace connectivity::sdbcx { using namespace ::com::sun::star::uno; - using namespace ::com::sun::star::lang; using namespace ::com::sun::star::beans; @@ -44,14 +43,6 @@ namespace connectivity::sdbcx // css::lang::XUnoTunnel - sal_Int64 SAL_CALL ODescriptor::getSomething( const Sequence< sal_Int8 >& rId ) - { - return (isUnoTunnelId<ODescriptor>(rId)) - ? reinterpret_cast< sal_Int64 >( this ) - : 0; - } - - namespace { struct ResetROAttribute @@ -76,10 +67,11 @@ namespace connectivity::sdbcx Sequence< Property > aProperties; describeProperties( aProperties ); + auto [begin, end] = asNonConstRange(aProperties); if ( isNew() ) - std::for_each( aProperties.begin(), aProperties.end(), ResetROAttribute() ); + std::for_each( begin, end, ResetROAttribute() ); else - std::for_each( aProperties.begin(), aProperties.end(), SetROAttribute() ); + std::for_each( begin, end, SetROAttribute() ); return new ::cppu::OPropertyArrayHelper( aProperties ); } @@ -87,26 +79,11 @@ namespace connectivity::sdbcx bool ODescriptor::isNew( const Reference< XInterface >& _rxDescriptor ) { - ODescriptor* pImplementation = comphelper::getUnoTunnelImplementation<ODescriptor>( _rxDescriptor ); + ODescriptor* pImplementation = dynamic_cast<ODescriptor*>( _rxDescriptor.get() ); return pImplementation && pImplementation->isNew(); } - Sequence< sal_Int8 > ODescriptor::getUnoTunnelId() - { - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); - } - - - Any SAL_CALL ODescriptor::queryInterface( const Type & rType ) - { - Any aRet = ::cppu::queryInterface(rType,static_cast< XUnoTunnel*> (this)); - return aRet.hasValue() ? aRet : ODescriptor_PBASE::queryInterface(rType); - } - - void ODescriptor::setNew(bool _bNew) { m_bNew = _bNew; @@ -117,8 +94,7 @@ namespace connectivity::sdbcx { ::cppu::OTypeCollection aTypes( cppu::UnoType<XMultiPropertySet>::get(), cppu::UnoType<XFastPropertySet>::get(), - cppu::UnoType<XPropertySet>::get(), - cppu::UnoType<XUnoTunnel>::get()); + cppu::UnoType<XPropertySet>::get()); return aTypes.getTypes(); } diff --git a/connectivity/source/sdbcx/VGroup.cxx b/connectivity/source/sdbcx/VGroup.cxx index ed11a617526f..7a37ea3e523d 100644 --- a/connectivity/source/sdbcx/VGroup.cxx +++ b/connectivity/source/sdbcx/VGroup.cxx @@ -26,7 +26,6 @@ using namespace ::connectivity::sdbcx; using namespace ::connectivity; using namespace ::dbtools; -using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::container; using namespace ::com::sun::star::lang; @@ -152,12 +151,12 @@ void SAL_CALL OGroup::setName( const OUString& /*aName*/ ) } // XInterface -void SAL_CALL OGroup::acquire() throw() +void SAL_CALL OGroup::acquire() noexcept { OGroup_BASE::acquire(); } -void SAL_CALL OGroup::release() throw() +void SAL_CALL OGroup::release() noexcept { OGroup_BASE::release(); } diff --git a/connectivity/source/sdbcx/VIndex.cxx b/connectivity/source/sdbcx/VIndex.cxx index 1649ff83ad97..48e26ae1140e 100644 --- a/connectivity/source/sdbcx/VIndex.cxx +++ b/connectivity/source/sdbcx/VIndex.cxx @@ -24,7 +24,8 @@ #include <connectivity/sdbcx/VCollection.hxx> #include <cppuhelper/supportsservice.hxx> #include <TConnection.hxx> -#include <tools/diagnose_ex.h> +#include <utility> +#include <comphelper/diagnose_ex.hxx> using namespace ::connectivity; using namespace ::dbtools; @@ -32,7 +33,6 @@ using namespace ::connectivity::sdbcx; using namespace ::cppu; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::container; using namespace ::com::sun::star::lang; @@ -64,13 +64,13 @@ OIndex::OIndex(bool _bCase) : ODescriptor_BASE(m_aMutex) } OIndex::OIndex( const OUString& Name, - const OUString& Catalog, + OUString Catalog, bool _isUnique, bool _isPrimaryKeyIndex, bool _isClustered, bool _bCase) : ODescriptor_BASE(m_aMutex) ,ODescriptor(ODescriptor_BASE::rBHelper, _bCase) - ,m_Catalog(Catalog) + ,m_Catalog(std::move(Catalog)) ,m_IsUnique(_isUnique) ,m_IsPrimaryKeyIndex(_isPrimaryKeyIndex) ,m_IsClustered(_isClustered) @@ -181,12 +181,12 @@ void SAL_CALL OIndex::setName( const OUString& /*aName*/ ) } // XInterface -void SAL_CALL OIndex::acquire() throw() +void SAL_CALL OIndex::acquire() noexcept { ODescriptor_BASE::acquire(); } -void SAL_CALL OIndex::release() throw() +void SAL_CALL OIndex::release() noexcept { ODescriptor_BASE::release(); } diff --git a/connectivity/source/sdbcx/VKey.cxx b/connectivity/source/sdbcx/VKey.cxx index 33e9340b51c7..140bd6160709 100644 --- a/connectivity/source/sdbcx/VKey.cxx +++ b/connectivity/source/sdbcx/VKey.cxx @@ -24,12 +24,12 @@ #include <cppuhelper/supportsservice.hxx> #include <connectivity/sdbcx/VCollection.hxx> #include <TConnection.hxx> +#include <utility> using namespace connectivity; using namespace connectivity::sdbcx; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::container; using namespace ::com::sun::star::lang; @@ -58,10 +58,10 @@ OKey::OKey(bool _bCase) : ODescriptor_BASE(m_aMutex) { } -OKey::OKey(const OUString& Name,const std::shared_ptr<KeyProperties>& _rProps, bool _bCase) +OKey::OKey(const OUString& Name,std::shared_ptr<KeyProperties> _xProps, bool _bCase) : ODescriptor_BASE(m_aMutex) ,ODescriptor(ODescriptor_BASE::rBHelper, _bCase) - ,m_aProps(_rProps) + ,m_aProps(std::move(_xProps)) { m_Name = Name; } @@ -188,12 +188,12 @@ void SAL_CALL OKey::setName( const OUString& /*aName*/ ) } // XInterface -void SAL_CALL OKey::acquire() throw() +void SAL_CALL OKey::acquire() noexcept { ODescriptor_BASE::acquire(); } -void SAL_CALL OKey::release() throw() +void SAL_CALL OKey::release() noexcept { ODescriptor_BASE::release(); } diff --git a/connectivity/source/sdbcx/VKeyColumn.cxx b/connectivity/source/sdbcx/VKeyColumn.cxx index b6f69e65c9de..e22620fb599d 100644 --- a/connectivity/source/sdbcx/VKeyColumn.cxx +++ b/connectivity/source/sdbcx/VKeyColumn.cxx @@ -21,6 +21,7 @@ #include <com/sun/star/beans/PropertyAttribute.hpp> #include <cppuhelper/supportsservice.hxx> #include <TConnection.hxx> +#include <utility> using namespace connectivity; using namespace connectivity::sdbcx; @@ -50,7 +51,7 @@ OKeyColumn::OKeyColumn(bool _bCase) : OColumn(_bCase) construct(); } -OKeyColumn::OKeyColumn( const OUString& ReferencedColumn, +OKeyColumn::OKeyColumn( OUString ReferencedColumn, const OUString& Name, const OUString& TypeName, const OUString& DefaultValue, @@ -77,7 +78,7 @@ OKeyColumn::OKeyColumn( const OUString& ReferencedColumn, CatalogName, SchemaName, TableName) - , m_ReferencedColumn(ReferencedColumn) + , m_ReferencedColumn(std::move(ReferencedColumn)) { construct(); } diff --git a/connectivity/source/sdbcx/VTable.cxx b/connectivity/source/sdbcx/VTable.cxx index 90c7427823c0..f569d01baef3 100644 --- a/connectivity/source/sdbcx/VTable.cxx +++ b/connectivity/source/sdbcx/VTable.cxx @@ -25,6 +25,7 @@ #include <connectivity/dbtools.hxx> #include <connectivity/dbexception.hxx> #include <cppuhelper/supportsservice.hxx> +#include <utility> using namespace ::connectivity; using namespace ::connectivity::sdbcx; @@ -65,14 +66,14 @@ OTable::OTable(OCollection* _pTables, OTable::OTable( OCollection* _pTables, bool _bCase, - const OUString& Name, const OUString& Type, - const OUString& Description,const OUString& SchemaName, - const OUString& CatalogName) : OTableDescriptor_BASE(m_aMutex) + const OUString& Name, OUString Type, + OUString Description, OUString SchemaName, + OUString CatalogName) : OTableDescriptor_BASE(m_aMutex) ,ODescriptor(OTableDescriptor_BASE::rBHelper,_bCase) - ,m_CatalogName(CatalogName) - ,m_SchemaName(SchemaName) - ,m_Description(Description) - ,m_Type(Type) + ,m_CatalogName(std::move(CatalogName)) + ,m_SchemaName(std::move(SchemaName)) + ,m_Description(std::move(Description)) + ,m_Type(std::move(Type)) ,m_pTables(_pTables) { m_Name = Name; @@ -94,12 +95,12 @@ void OTable::construct() registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE), PROPERTY_ID_TYPE, nAttrib,&m_Type, ::cppu::UnoType<OUString>::get()); } -void SAL_CALL OTable::acquire() throw() +void SAL_CALL OTable::acquire() noexcept { OTableDescriptor_BASE::acquire(); } -void SAL_CALL OTable::release() throw() +void SAL_CALL OTable::release() noexcept { OTableDescriptor_BASE::release(); } @@ -210,7 +211,7 @@ Reference< XPropertySet > SAL_CALL OTable::createDataDescriptor( ) ::osl::MutexGuard aGuard(m_aMutex); checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed); - OTable* pTable = new OTable(m_pTables,isCaseSensitive(),m_Name,m_Type,m_Description,m_SchemaName,m_CatalogName); + rtl::Reference<OTable> pTable = new OTable(m_pTables,isCaseSensitive(),m_Name,m_Type,m_Description,m_SchemaName,m_CatalogName); pTable->setNew(true); return pTable; } diff --git a/connectivity/source/sdbcx/VUser.cxx b/connectivity/source/sdbcx/VUser.cxx index 9cecd7dfdd46..85d09523c864 100644 --- a/connectivity/source/sdbcx/VUser.cxx +++ b/connectivity/source/sdbcx/VUser.cxx @@ -22,11 +22,11 @@ #include <connectivity/sdbcx/VCollection.hxx> #include <connectivity/dbexception.hxx> #include <comphelper/sequence.hxx> +#include <o3tl/unreachable.hxx> using namespace connectivity; using namespace connectivity::sdbcx; -using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::container; @@ -113,15 +113,12 @@ Reference< XNameAccess > SAL_CALL OUser::getGroups( ) return m_pGroups.get(); } - -SAL_WNOUNREACHABLE_CODE_PUSH - sal_Int32 SAL_CALL OUser::getPrivileges( const OUString& /*objName*/, sal_Int32 /*objType*/ ) { ::osl::MutexGuard aGuard(m_aMutex); checkDisposed(OUser_BASE::rBHelper.bDisposed); ::dbtools::throwFeatureNotImplementedSQLException( "XAuthorizable::changePassword", *this ); - return 0; + O3TL_UNREACHABLE; } sal_Int32 SAL_CALL OUser::getGrantablePrivileges( const OUString& /*objName*/, sal_Int32 /*objType*/ ) @@ -129,12 +126,9 @@ sal_Int32 SAL_CALL OUser::getGrantablePrivileges( const OUString& /*objName*/, s ::osl::MutexGuard aGuard(m_aMutex); checkDisposed(OUser_BASE::rBHelper.bDisposed); ::dbtools::throwFeatureNotImplementedSQLException( "XAuthorizable::getGrantablePrivileges", *this ); - return 0; + O3TL_UNREACHABLE; } -SAL_WNOUNREACHABLE_CODE_POP - - void SAL_CALL OUser::grantPrivileges( const OUString& /*objName*/, sal_Int32 /*objType*/, sal_Int32 /*objPrivileges*/ ) { ::osl::MutexGuard aGuard(m_aMutex); @@ -166,12 +160,12 @@ void SAL_CALL OUser::setName( const OUString& /*aName*/ ) } // XInterface -void SAL_CALL OUser::acquire() throw() +void SAL_CALL OUser::acquire() noexcept { OUser_BASE::acquire(); } -void SAL_CALL OUser::release() throw() +void SAL_CALL OUser::release() noexcept { OUser_BASE::release(); } diff --git a/connectivity/source/sdbcx/VView.cxx b/connectivity/source/sdbcx/VView.cxx index 317e985b5199..41828b5758cb 100644 --- a/connectivity/source/sdbcx/VView.cxx +++ b/connectivity/source/sdbcx/VView.cxx @@ -22,13 +22,13 @@ #include <comphelper/sequence.hxx> #include <connectivity/dbtools.hxx> #include <TConnection.hxx> +#include <utility> using namespace connectivity; using namespace connectivity::sdbcx; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::container; using namespace ::com::sun::star::lang; @@ -36,24 +36,24 @@ IMPLEMENT_SERVICE_INFO(OView,"com.sun.star.sdbcx.VView","com.sun.star.sdbcx.View OView::OView(bool _bCase, const OUString& Name, - const css::uno::Reference< css::sdbc::XDatabaseMetaData >& _xMetaData, - const OUString& Command, - const OUString& SchemaName, - const OUString& CatalogName) : ODescriptor(::comphelper::OMutexAndBroadcastHelper::m_aBHelper,_bCase) - ,m_CatalogName(CatalogName) - ,m_SchemaName(SchemaName) - ,m_Command(Command) + css::uno::Reference< css::sdbc::XDatabaseMetaData > _xMetaData, + OUString Command, + OUString SchemaName, + OUString CatalogName) : ODescriptor(::comphelper::OMutexAndBroadcastHelper::m_aBHelper,_bCase) + ,m_CatalogName(std::move(CatalogName)) + ,m_SchemaName(std::move(SchemaName)) + ,m_Command(std::move(Command)) ,m_CheckOption(0) - ,m_xMetaData(_xMetaData) + ,m_xMetaData(std::move(_xMetaData)) { m_Name = Name; construct(); } -OView::OView(bool _bCase, const css::uno::Reference< css::sdbc::XDatabaseMetaData >& _xMetaData) +OView::OView(bool _bCase, css::uno::Reference< css::sdbc::XDatabaseMetaData > _xMetaData) : ODescriptor(::comphelper::OMutexAndBroadcastHelper::m_aBHelper, _bCase, true) - ,m_xMetaData(_xMetaData) + ,m_xMetaData(std::move(_xMetaData)) { construct(); } @@ -118,12 +118,12 @@ void SAL_CALL OView::setName( const OUString& ) { } -void SAL_CALL OView::acquire() throw() +void SAL_CALL OView::acquire() noexcept { OView_BASE::acquire(); } -void SAL_CALL OView::release() throw() +void SAL_CALL OView::release() noexcept { OView_BASE::release(); } |