From df6c925fafabbc55693a945b47757bd799baac99 Mon Sep 17 00:00:00 2001 From: Lionel Elie Mamane Date: Fri, 2 Aug 2013 12:08:16 +0200 Subject: SingleSelectQueryComposer: the name of a non-SELECT column is its "real" name That is, the name in the table. Change-Id: I95326915f381ec0cf72c66f13352ce76d82e9517 Reviewed-on: https://gerrit.libreoffice.org/5247 Reviewed-by: Miklos Vajna Tested-by: Miklos Vajna --- .../source/core/api/SingleSelectQueryComposer.cxx | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx index 32035e74e72b..22ae0e736c8e 100644 --- a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx +++ b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx @@ -542,21 +542,29 @@ OUString OSingleSelectQueryComposer::impl_getColumnName_throw(const Reference< X throw SQLException(DBACORE_RESSTRING(RID_STR_COLUMN_NOT_VALID),*this,SQLSTATE_GENERAL,1000,makeAny(aErr) ); } - OUString aName, aNewName; + OUString aName; column->getPropertyValue(PROPERTY_NAME) >>= aName; + const OUString aQuote = m_xMetaData->getIdentifierQuoteString(); + + if ( m_aCurrentColumns[SelectColumns] && + m_aCurrentColumns[SelectColumns]->hasByName(aName) ) + { + // It is a column from the SELECT list, use it as such. + return ::dbtools::quoteName(aQuote,aName); + } + + // Nope, it is an unrelated column. + // Is that supported? if ( bOrderBy && - !m_xMetaData->supportsOrderByUnrelated() && - m_aCurrentColumns[SelectColumns] && - !m_aCurrentColumns[SelectColumns]->hasByName(aName) ) + !m_xMetaData->supportsOrderByUnrelated() ) { OUString sError(DBACORE_RESSTRING(RID_STR_COLUMN_MUST_VISIBLE)); throw SQLException(sError.replaceAll("%name", aName),*this,SQLSTATE_GENERAL,1000,Any() ); } - const OUString aQuote = m_xMetaData->getIdentifierQuoteString(); - aNewName = ::dbtools::quoteName(aQuote,aName); - return aNewName; + // We need to refer to it by its "real" name, that is by schemaName.tableName.columnNameInTable + return impl_getColumnRealName_throw(column, false); } void SAL_CALL OSingleSelectQueryComposer::appendOrderByColumn( const Reference< XPropertySet >& column, sal_Bool ascending ) throw(SQLException, RuntimeException) -- cgit v1.2.3