diff options
Diffstat (limited to 'dbaccess/source/core/api/SingleSelectQueryComposer.cxx')
-rw-r--r-- | dbaccess/source/core/api/SingleSelectQueryComposer.cxx | 158 |
1 files changed, 99 insertions, 59 deletions
diff --git a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx index f3f401b3cb99..f6dffbd1314a 100644 --- a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx +++ b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx @@ -21,6 +21,7 @@ #include <sal/log.hxx> #include <composertools.hxx> #include <strings.hrc> +#include <strings.hxx> #include <core_resource.hxx> #include <stringconstants.hxx> #include "HelperCollections.hxx" @@ -48,7 +49,7 @@ #include <connectivity/dbtools.hxx> #include <connectivity/PColumn.hxx> #include <connectivity/predicateinput.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <osl/diagnose.h> #include <unotools/sharedunocomponent.hxx> @@ -77,18 +78,18 @@ namespace dbaccess { namespace BooleanComparisonMode = ::com::sun::star::sdb::BooleanComparisonMode; } -#define STR_SELECT "SELECT " -#define STR_FROM " FROM " -#define STR_WHERE " WHERE " -#define STR_GROUP_BY " GROUP BY " -#define STR_HAVING " HAVING " -#define STR_ORDER_BY " ORDER BY " -#define STR_AND " AND " -#define STR_OR " OR " -#define STR_LIKE OUString(" LIKE ") -#define L_BRACKET "(" -#define R_BRACKET ")" -#define COMMA "," +constexpr OUStringLiteral STR_SELECT = u"SELECT "; +constexpr OUStringLiteral STR_FROM = u" FROM "; +constexpr OUString STR_WHERE = u" WHERE "_ustr; +constexpr OUStringLiteral STR_GROUP_BY = u" GROUP BY "; +constexpr OUStringLiteral STR_HAVING = u" HAVING "; +constexpr OUStringLiteral STR_ORDER_BY = u" ORDER BY "; +constexpr OUString STR_AND = u" AND "_ustr; +constexpr OUString STR_OR = u" OR "_ustr; +constexpr OUStringLiteral STR_LIKE = u" LIKE "; +constexpr OUString L_BRACKET = u"("_ustr; +constexpr OUString R_BRACKET = u")"_ustr; +constexpr OUStringLiteral COMMA = u","; namespace { @@ -105,8 +106,8 @@ namespace { OUString sSQLStateGeneralError( getStandardSQLState( StandardSQLState::GENERAL_ERROR ) ); SQLException aError2( aErrorMsg, _rxContext, sSQLStateGeneralError, 1000, Any() ); - SQLException aError1( _rStatement, _rxContext, sSQLStateGeneralError, 1000, makeAny( aError2 ) ); - throw SQLException(_rParser.getContext().getErrorMessage(OParseContext::ErrorCode::General),_rxContext,sSQLStateGeneralError,1000,makeAny(aError1)); + SQLException aError1( _rStatement, _rxContext, sSQLStateGeneralError, 1000, Any( aError2 ) ); + throw SQLException(_rParser.getContext().getErrorMessage(OParseContext::ErrorCode::General),_rxContext,sSQLStateGeneralError,1000,Any(aError1)); } return pNewSqlParseNode; } @@ -132,7 +133,7 @@ namespace // and now really ... SQLException aError1( _rOriginatingCommand, _rxContext, getStandardSQLState( StandardSQLState::GENERAL_ERROR ), 1000, Any() ); throw SQLException( DBA_RES( RID_STR_ONLY_QUERY ), _rxContext, - getStandardSQLState( StandardSQLState::GENERAL_ERROR ), 1000, makeAny( aError1 ) ); + getStandardSQLState( StandardSQLState::GENERAL_ERROR ), 1000, Any( aError1 ) ); } delete pOldNode; @@ -169,33 +170,33 @@ namespace delete pSqlParseNode; _rIterator.dispose(); } - void lcl_addFilterCriteria_throw(sal_Int32 i_nFilterOperator,const OUString& i_sValue,OUStringBuffer& o_sRet) + void lcl_addFilterCriteria_throw(sal_Int32 i_nFilterOperator,std::u16string_view i_sValue,OUStringBuffer& o_sRet) { switch( i_nFilterOperator ) { case SQLFilterOperator::EQUAL: - o_sRet.append(" = " ).append( i_sValue); + o_sRet.append(OUString::Concat(" = ") + i_sValue); break; case SQLFilterOperator::NOT_EQUAL: - o_sRet.append(" <> " ).append( i_sValue); + o_sRet.append(OUString::Concat(" <> ") + i_sValue); break; case SQLFilterOperator::LESS: - o_sRet.append(" < " ).append( i_sValue); + o_sRet.append(OUString::Concat(" < ") + i_sValue); break; case SQLFilterOperator::GREATER: - o_sRet.append(" > " ).append( i_sValue); + o_sRet.append(OUString::Concat(" > ") + i_sValue); break; case SQLFilterOperator::LESS_EQUAL: - o_sRet.append(" <= " ).append( i_sValue); + o_sRet.append(OUString::Concat(" <= ") + i_sValue); break; case SQLFilterOperator::GREATER_EQUAL: - o_sRet.append(" >= " ).append( i_sValue); + o_sRet.append(OUString::Concat(" >= ") + i_sValue); break; case SQLFilterOperator::LIKE: - o_sRet.append(" LIKE " ).append( i_sValue); + o_sRet.append(OUString::Concat(" LIKE ") + i_sValue); break; case SQLFilterOperator::NOT_LIKE: - o_sRet.append(" NOT LIKE " ).append( i_sValue); + o_sRet.append(OUString::Concat(" NOT LIKE ") + i_sValue); break; case SQLFilterOperator::SQLNULL: o_sRet.append(" IS NULL"); @@ -216,7 +217,7 @@ OSingleSelectQueryComposer::OSingleSelectQueryComposer(const Reference< XNameAcc const Reference<XComponentContext>& _rContext ) :OSubComponent(m_aMutex,_xConnection) ,OPropertyContainer(m_aBHelper) - ,m_aSqlParser( _rContext, &m_aParseContext ) + ,m_aSqlParser( _rContext, &m_aParseContext, &m_aNeutralContext ) ,m_aSqlIterator( _xConnection, _rxTables, m_aSqlParser ) ,m_aAdditiveIterator( _xConnection, _rxTables, m_aSqlParser ) ,m_aElementaryParts( size_t(SQLPartCount) ) @@ -244,7 +245,7 @@ OSingleSelectQueryComposer::OSingleSelectQueryComposer(const Reference< XNameAcc { Any aValue; Reference<XInterface> xDs = dbaccess::getDataSource(_xConnection); - if ( dbtools::getDataSourceSetting(xDs,static_cast <OUString> (PROPERTY_BOOLEANCOMPARISONMODE),aValue) ) + if ( dbtools::getDataSourceSetting(xDs,PROPERTY_BOOLEANCOMPARISONMODE,aValue) ) { OSL_VERIFY( aValue >>= m_nBoolCompareMode ); } @@ -278,15 +279,54 @@ void SAL_CALL OSingleSelectQueryComposer::disposing() } IMPLEMENT_FORWARD_XINTERFACE3(OSingleSelectQueryComposer,OSubComponent,OSingleSelectQueryComposer_BASE,OPropertyContainer) -IMPLEMENT_SERVICE_INFO1(OSingleSelectQueryComposer,"org.openoffice.comp.dba.OSingleSelectQueryComposer",SERVICE_NAME_SINGLESELECTQUERYCOMPOSER) +OUString SAL_CALL OSingleSelectQueryComposer::getImplementationName() + { + return "org.openoffice.comp.dba.OSingleSelectQueryComposer"; + } +sal_Bool SAL_CALL OSingleSelectQueryComposer::supportsService(const OUString& _rServiceName) + { + const css::uno::Sequence< OUString > aSupported(getSupportedServiceNames()); + for (const OUString& s : aSupported) + if (s == _rServiceName) + return true; + + return false; + } +css::uno::Sequence< OUString > SAL_CALL OSingleSelectQueryComposer::getSupportedServiceNames() +{ + return { SERVICE_NAME_SINGLESELECTQUERYCOMPOSER }; +} css::uno::Sequence<sal_Int8> OSingleSelectQueryComposer::getImplementationId() { return css::uno::Sequence<sal_Int8>(); } -IMPLEMENT_GETTYPES3(OSingleSelectQueryComposer,OSubComponent,OSingleSelectQueryComposer_BASE,OPropertyContainer) -IMPLEMENT_PROPERTYCONTAINER_DEFAULTS(OSingleSelectQueryComposer) +css::uno::Sequence< css::uno::Type > OSingleSelectQueryComposer::getTypes() +{ + return ::comphelper::concatSequences( + OSubComponent::getTypes( ), + OSingleSelectQueryComposer_BASE::getTypes( ), + OPropertyContainer::getTypes( ) + ); +} + +css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL OSingleSelectQueryComposer::getPropertySetInfo() +{ + Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + return xInfo; +} +::cppu::IPropertyArrayHelper& OSingleSelectQueryComposer::getInfoHelper() +{ + return *OSingleSelectQueryComposer::getArrayHelper(); +} +::cppu::IPropertyArrayHelper* OSingleSelectQueryComposer::createArrayHelper( ) const +{ + css::uno::Sequence< css::beans::Property > aProps; + describeProperties(aProps); + return new ::cppu::OPropertyArrayHelper(aProps); +} + // XSingleSelectQueryAnalyzer OUString SAL_CALL OSingleSelectQueryComposer::getQuery( ) @@ -431,11 +471,11 @@ OUString OSingleSelectQueryComposer::impl_getColumnRealName_throw(const Referenc || !m_aCurrentColumns[SelectColumns] || !column->getPropertySetInfo()->hasPropertyByName(PROPERTY_NAME) ) - { - OUString sError(DBA_RES(RID_STR_COLUMN_UNKNOWN_PROP)); - SQLException aErr(sError.replaceAll("%value", PROPERTY_NAME),*this,SQLSTATE_GENERAL,1000,Any() ); - throw SQLException(DBA_RES(RID_STR_COLUMN_NOT_VALID),*this,SQLSTATE_GENERAL,1000,makeAny(aErr) ); - } + { + OUString sError(DBA_RES(RID_STR_COLUMN_UNKNOWN_PROP)); + SQLException aErr(sError.replaceAll("%value", PROPERTY_NAME),*this,SQLSTATE_GENERAL,1000,Any() ); + throw SQLException(DBA_RES(RID_STR_COLUMN_NOT_VALID),*this,SQLSTATE_GENERAL,1000,Any(aErr) ); + } OUString aName, aNewName; column->getPropertyValue(PROPERTY_NAME) >>= aName; @@ -471,9 +511,9 @@ OUString OSingleSelectQueryComposer::impl_getColumnRealName_throw(const Referenc { if(sTableName.indexOf('.') != -1) { - OUString aCatlog,aSchema,aTable; - ::dbtools::qualifiedNameComponents(m_xMetaData,sTableName,aCatlog,aSchema,aTable,::dbtools::EComposeRule::InDataManipulation); - sTableName = ::dbtools::composeTableName( m_xMetaData, aCatlog, aSchema, aTable, true, ::dbtools::EComposeRule::InDataManipulation ); + OUString aCatalog,aSchema,aTable; + ::dbtools::qualifiedNameComponents(m_xMetaData,sTableName,aCatalog,aSchema,aTable,::dbtools::EComposeRule::InDataManipulation); + sTableName = ::dbtools::composeTableName( m_xMetaData, aCatalog, aSchema, aTable, true, ::dbtools::EComposeRule::InDataManipulation ); } else if (!sTableName.isEmpty()) sTableName = ::dbtools::quoteName(aQuote,sTableName); @@ -501,11 +541,11 @@ OUString OSingleSelectQueryComposer::impl_getColumnNameOrderBy_throw(const Refer || !m_aCurrentColumns[SelectColumns] || !column->getPropertySetInfo()->hasPropertyByName(PROPERTY_NAME) ) - { - OUString sError(DBA_RES(RID_STR_COLUMN_UNKNOWN_PROP)); - SQLException aErr(sError.replaceAll("%value", PROPERTY_NAME),*this,SQLSTATE_GENERAL,1000,Any() ); - throw SQLException(DBA_RES(RID_STR_COLUMN_NOT_VALID),*this,SQLSTATE_GENERAL,1000,makeAny(aErr) ); - } + { + OUString sError(DBA_RES(RID_STR_COLUMN_UNKNOWN_PROP)); + SQLException aErr(sError.replaceAll("%value", PROPERTY_NAME),*this,SQLSTATE_GENERAL,1000,Any() ); + throw SQLException(DBA_RES(RID_STR_COLUMN_NOT_VALID),*this,SQLSTATE_GENERAL,1000,Any(aErr) ); + } OUString aName; column->getPropertyValue(PROPERTY_NAME) >>= aName; @@ -717,7 +757,7 @@ Reference< XNameAccess > SAL_CALL OSingleSelectQueryComposer::getTables( ) for (auto const& elem : aTables) aNames.push_back(elem.first); - m_pTables.reset( new OPrivateTables(aTables,m_xMetaData->supportsMixedCaseQuotedIdentifiers(),*this,m_aMutex,aNames) ); + m_pTables.reset( new OPrivateTables(aTables,m_xMetaData->supportsMixedCaseQuotedIdentifiers(),*this,m_aMutex,std::move(aNames)) ); } return m_pTables.get(); @@ -752,14 +792,14 @@ Reference< XNameAccess > SAL_CALL OSingleSelectQueryComposer::getColumns( ) bCase = m_xMetaData->supportsMixedCaseQuotedIdentifiers(); aSelectColumns = m_aSqlIterator.getSelectColumns(); - OUStringBuffer aSQL( m_aPureSelectSQL + STR_WHERE " ( 0 = 1 )"); + OUStringBuffer aSQL( m_aPureSelectSQL + STR_WHERE + " ( 0 = 1 )"); // preserve the original WHERE clause // #i102234# OUString sOriginalWhereClause = getSQLPart( Where, m_aSqlIterator, false ); if ( !sOriginalWhereClause.isEmpty() ) { - aSQL.append( " AND ( " ).append( sOriginalWhereClause ).append( " ) " ); + aSQL.append( " AND ( " + sOriginalWhereClause + " ) " ); } OUString sGroupBy = getSQLPart( Group, m_aSqlIterator, true ); @@ -807,7 +847,7 @@ Reference< XNameAccess > SAL_CALL OSingleSelectQueryComposer::getColumns( ) { xStatement.reset( Reference< XStatement >( m_xConnection->createStatement(), UNO_SET_THROW ) ); Reference< XPropertySet > xStatementProps( xStatement, UNO_QUERY_THROW ); - try { xStatementProps->setPropertyValue( PROPERTY_ESCAPE_PROCESSING, makeAny( false ) ); } + try { xStatementProps->setPropertyValue( PROPERTY_ESCAPE_PROCESSING, Any( false ) ); } catch ( const Exception& ) { DBG_UNHANDLED_EXCEPTION("dbaccess"); } xResMetaDataSup.set( xStatement->executeQuery( sSQL ), UNO_QUERY_THROW ); xResultSetMeta.set( xResMetaDataSup->getMetaData(), UNO_SET_THROW ); @@ -890,7 +930,7 @@ Reference< XNameAccess > SAL_CALL OSingleSelectQueryComposer::getColumns( ) if ( !xProp.is() || !xProp->getPropertySetInfo()->hasPropertyByName( PROPERTY_REALNAME ) ) continue; - ::connectivity::parse::OParseColumn* pColumn = new ::connectivity::parse::OParseColumn(xProp,bCase); + rtl::Reference<::connectivity::parse::OParseColumn> pColumn = new ::connectivity::parse::OParseColumn(xProp,bCase); pColumn->setFunction(::comphelper::getBOOL(xProp->getPropertyValue("Function"))); pColumn->setAggregateFunction(::comphelper::getBOOL(xProp->getPropertyValue("AggregateFunction"))); @@ -1484,9 +1524,9 @@ OUString OSingleSelectQueryComposer::getStatementPart( TGetParseNode const & _aG namespace { - OUString lcl_getDecomposedColumnName(const OUString& rComposedName, const OUString& rQuoteString) + OUString lcl_getDecomposedColumnName(const OUString& rComposedName, std::u16string_view rQuoteString) { - const sal_Int32 nQuoteLength = rQuoteString.getLength(); + const size_t nQuoteLength = rQuoteString.size(); OUString sName = rComposedName.trim(); OUString sColumnName; sal_Int32 nPos, nRPos = 0; @@ -1499,7 +1539,7 @@ namespace nRPos = sName.indexOf( rQuoteString, nPos + nQuoteLength ); if ( nRPos > nPos ) { - if ( nRPos + nQuoteLength < sName.getLength() ) + if ( static_cast<sal_Int32>(nRPos + nQuoteLength) < sName.getLength() ) { nRPos += nQuoteLength; // -1 + 1 skip dot } @@ -1521,7 +1561,7 @@ namespace OUString lcl_getCondition(const Sequence< Sequence< PropertyValue > >& filter, const OPredicateInputController& i_aPredicateInputController, const Reference< XNameAccess >& i_xSelectColumns, - const OUString& rQuoteString) + std::u16string_view rQuoteString) { OUStringBuffer sRet; const Sequence< PropertyValue >* pOrIter = filter.getConstArray(); @@ -1620,9 +1660,9 @@ void OSingleSelectQueryComposer::setConditionByColumn( const Reference< XPropert xColumn->getPropertyValue(PROPERTY_TABLENAME) >>= sTableName; if(sTableName.indexOf('.') != -1) { - OUString aCatlog,aSchema,aTable; - ::dbtools::qualifiedNameComponents(m_xMetaData,sTableName,aCatlog,aSchema,aTable,::dbtools::EComposeRule::InDataManipulation); - sTableName = ::dbtools::composeTableName( m_xMetaData, aCatlog, aSchema, aTable, true, ::dbtools::EComposeRule::InDataManipulation ); + OUString aCatalog,aSchema,aTable; + ::dbtools::qualifiedNameComponents(m_xMetaData,sTableName,aCatalog,aSchema,aTable,::dbtools::EComposeRule::InDataManipulation); + sTableName = ::dbtools::composeTableName( m_xMetaData, aCatalog, aSchema, aTable, true, ::dbtools::EComposeRule::InDataManipulation ); } else sTableName = ::dbtools::quoteName(aQuote,sTableName); @@ -1647,7 +1687,7 @@ void OSingleSelectQueryComposer::setConditionByColumn( const Reference< XPropert if ( nType != DataType::BOOLEAN && DataType::BIT != nType ) { - lcl_addFilterCriteria_throw(filterOperator,"",aSQL); + lcl_addFilterCriteria_throw(filterOperator,u"",aSQL); } switch(nType) @@ -1665,7 +1705,7 @@ void OSingleSelectQueryComposer::setConditionByColumn( const Reference< XPropert const ::sal_Int64 nLength = xClob->length(); if ( sal_Int64(nLength + aSQL.getLength() + STR_LIKE.getLength() ) < sal_Int64(SAL_MAX_INT32) ) { - aSQL.append("'").append(xClob->getSubString(1,static_cast<sal_Int32>(nLength))).append("'"); + aSQL.append("'" + xClob->getSubString(1,static_cast<sal_Int32>(nLength)) + "'"); } } else @@ -1716,7 +1756,7 @@ void OSingleSelectQueryComposer::setConditionByColumn( const Reference< XPropert sal_Int32 nFilterOp = filterOperator; if ( filterOperator != SQLFilterOperator::SQLNULL && filterOperator != SQLFilterOperator::NOT_SQLNULL ) nFilterOp = SQLFilterOperator::SQLNULL; - lcl_addFilterCriteria_throw(nFilterOp,"",aSQL); + lcl_addFilterCriteria_throw(nFilterOp,u"",aSQL); } // Attach filter @@ -1726,7 +1766,7 @@ void OSingleSelectQueryComposer::setConditionByColumn( const Reference< XPropert if ( !sFilter.isEmpty() && !aSQL.isEmpty() ) { sFilter = L_BRACKET + sFilter + R_BRACKET + - (andCriteria ? std::u16string_view(u"" STR_AND) : std::u16string_view(u"" STR_OR)); + (andCriteria ? std::u16string_view(STR_AND) : std::u16string_view(STR_OR)); } sFilter += aSQL; |