Tag: cws_src680_dba24c User: fs Date: 2007-10-25 08:43:41+0000 Modified: dba/dbaccess/source/core/api/SingleSelectQueryComposer.cxx
Log: #i81658# BoolComparison replaced with css.sdb.BooleanComparisonMode / creation of the boolean comparison predicate outsourced to a dbtools-method File Changes: Directory: /dba/dbaccess/source/core/api/ ========================================= File [changed]: SingleSelectQueryComposer.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/api/SingleSelectQueryComposer.cxx?r1=1.23.76.4&r2=1.23.76.5 Delta lines: +57 -145 ---------------------- --- SingleSelectQueryComposer.cxx 2007-10-16 08:10:46+0000 1.23.76.4 +++ SingleSelectQueryComposer.cxx 2007-10-25 08:43:38+0000 1.23.76.5 @@ -4,9 +4,9 @@ * * $RCSfile: SingleSelectQueryComposer.cxx,v $ * - * $Revision: 1.23.76.4 $ + * $Revision: 1.23.76.5 $ * - * last change: $Author: fs $ $Date: 2007/10/16 08:10:46 $ + * last change: $Author: fs $ $Date: 2007/10/25 08:43:38 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -36,95 +36,45 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_dbaccess.hxx" +#include "composertools.hxx" +#include "core_resource.hrc" +#include "core_resource.hxx" +#include "dbastrings.hrc" +#include "HelperCollections.hxx" #include "SingleSelectQueryComposer.hxx" -#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +/** === begin UNO includes === **/ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/container/XChild.hpp> +#include <com/sun/star/i18n/XLocaleData.hpp> #include <com/sun/star/lang/DisposedException.hpp> -#endif -#ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATTER_HPP_ -#include <com/sun/star/util/XNumberFormatter.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_COLUMNSEARCH_HPP_ +#include <com/sun/star/sdb/BooleanComparisonMode.hpp> +#include <com/sun/star/sdb/SQLFilterOperator.hpp> #include <com/sun/star/sdbc/ColumnSearch.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ #include <com/sun/star/sdbc/DataType.hpp> -#endif -#ifndef _COM_SUN_STAR_SDB_SQLFILTEROPERATOR_HPP_ -#include <com/sun/star/sdb/SQLFilterOperator.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATASUPPLIER_HPP_ -#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> -#endif -#ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATA_HPP_ #include <com/sun/star/sdbc/XResultSetMetaData.hpp> -#endif -#ifndef _COMPHELPER_SEQUENCE_HXX_ -#include <comphelper/sequence.hxx> -#endif -#ifndef _COM_SUN_STAR_UNO_XAGGREGATION_HPP_ +#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> #include <com/sun/star/uno/XAggregation.hpp> -#endif -#ifndef _COMPHELPER_SEQUENCE_HXX_ -#include <comphelper/sequence.hxx> -#endif -#ifndef _COMPHELPER_PROCESSFACTORY_HXX_ +#include <com/sun/star/util/XNumberFormatter.hpp> +/** === end UNO includes === **/ + #include <comphelper/processfactory.hxx> -#endif -#ifndef DBACCESS_SHARED_DBASTRINGS_HRC -#include "dbastrings.hrc" -#endif -#ifndef _DBA_CORE_RESOURCE_HXX_ -#include "core_resource.hxx" -#endif -#ifndef _DBA_CORE_RESOURCE_HRC_ -#include "core_resource.hrc" -#endif -#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ -#include <cppuhelper/typeprovider.hxx> -#endif -#ifndef _UTL_CONFIGMGR_HXX_ -#include <unotools/configmgr.hxx> -#endif -#ifndef UNOTOOLS_INC_SHAREDUNOCOMPONENT_HXX -#include <unotools/sharedunocomponent.hxx> -#endif -#ifndef _COMPHELPER_TYPES_HXX_ +#include <comphelper/sequence.hxx> #include <comphelper/types.hxx> -#endif -#ifndef _TOOLS_DEBUG_HXX +#include <cppuhelper/typeprovider.hxx> +#include <rtl/logfile.hxx> +#include <svtools/syslocale.hxx> #include <tools/debug.hxx> -#endif -#ifndef TOOLS_DIAGNOSE_EX_H #include <tools/diagnose_ex.h> -#endif -#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ -#include <com/sun/star/beans/PropertyAttribute.hpp> -#endif -#ifndef _COM_SUN_STAR_I18N_XLOCALEDATA_HPP_ -#include <com/sun/star/i18n/XLocaleData.hpp> -#endif -#ifndef DBA_HELPERCOLLECTIONS_HXX -#include "HelperCollections.hxx" -#endif -#ifndef INCLUDED_SVTOOLS_SYSLOCALE_HXX -#include <svtools/syslocale.hxx> -#endif -#ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_ -#include <com/sun/star/container/XChild.hpp> -#endif -#ifndef DBACCESS_SOURCE_CORE_INC_COMPOSERTOOLS_HXX -#include "composertools.hxx" -#endif -#ifndef _RTL_LOGFILE_HXX_ -#include <rtl/logfile.hxx> -#endif +#include <unotools/configmgr.hxx> +#include <unotools/sharedunocomponent.hxx> + #include <memory> -using namespace dbaccess; -using namespace dbtools; -using namespace comphelper; -using namespace connectivity; +using namespace ::dbaccess; +using namespace ::dbtools; +using namespace ::comphelper; +using namespace ::connectivity; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbc; @@ -139,6 +89,8 @@ using namespace ::osl; using namespace ::utl; +namespace BooleanComparisonMode = ::com::sun::star::sdb::BooleanComparisonMode; + #define STR_SELECT ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SELECT ")) #define STR_FROM ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" FROM ")) #define STR_WHERE ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" WHERE ")) @@ -258,7 +210,7 @@ ,m_xConnectionTables( _rxTables ) ,m_aContext( _rContext ) ,m_pTables(NULL) - ,m_nBoolCompareMode(BOOL_COMPARISON_DEFAULT) + ,m_nBoolCompareMode( BooleanComparisonMode::EQUAL_INTEGER ) { DBG_CTOR(OSingleSelectQueryComposer,NULL); @@ -1504,7 +1456,7 @@ Any aValue; column->getPropertyValue(PROPERTY_VALUE) >>= aValue; - ::rtl::OUString aSql; + ::rtl::OUStringBuffer aSQL; ::rtl::OUString aQuote = m_xMetaData->getIdentifierQuoteString(); if ( m_aCurrentColumns[SelectColumns] && m_aCurrentColumns[SelectColumns]->hasByName(aName) ) @@ -1529,16 +1481,19 @@ if ( !::comphelper::getBOOL(xColumn->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Function")))) ) { - aSql = sTableName; - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".")); - aSql += ::dbtools::quoteName(aQuote,sRealName); + aSQL = sTableName; + aSQL.appendAscii( "." ); + aSQL.append( ::dbtools::quoteName( aQuote, sRealName ) ); } else - aSql += sRealName; + aSQL = sRealName; } else - aSql = getTableAlias(column) + ::dbtools::quoteName(aQuote,aName); + { + aSQL = getTableAlias( column ); + aSQL.append( ::dbtools::quoteName( aQuote, aName ) ); + } if ( aValue.hasValue() ) { @@ -1551,8 +1506,8 @@ case DataType::VARCHAR: case DataType::CHAR: case DataType::LONGVARCHAR: - aSql += STR_LIKE; - aSql += DBTypeConversion::toSQLString(nType,aValue,sal_True,m_xTypeConverter); + aSQL.append( STR_LIKE ); + aSQL.append( DBTypeConversion::toSQLString( nType, aValue, sal_True, m_xTypeConverter ) ); break; case DataType::VARBINARY: case DataType::BINARY: @@ -1563,20 +1518,20 @@ { if(nSearchable == ColumnSearch::CHAR) { - aSql += STR_LIKE; - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\'")); + aSQL.append( STR_LIKE ); + aSQL.appendAscii( "\'" ); } else - aSql += STR_EQUAL; - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0x")); + aSQL.append( STR_EQUAL ); + aSQL.appendAscii( "0x" ); const sal_Int8* pBegin = aSeq.getConstArray(); const sal_Int8* pEnd = pBegin + aSeq.getLength(); for(;pBegin != pEnd;++pBegin) { - aSql += ::rtl::OUString::valueOf((sal_Int32)*pBegin,16).getStr(); + aSQL.append( (sal_Int32)*pBegin, 16 ).getStr(); } - if(nSearchable == ColumnSearch::NONE) - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\'")); + if(nSearchable == ColumnSearch::CHAR) + aSQL.appendAscii( "\'" ); } else throw SQLException(DBACORE_RESSTRING(RID_STR_NOT_SEQUENCE_INT8),*this,SQLSTATE_GENERAL,1000,Any() ); @@ -1585,69 +1540,26 @@ case DataType::BIT: case DataType::BOOLEAN: { - ::rtl::OUString sTmpName = aSql; - - sal_Bool bValue = sal_False; m_xTypeConverter->convertToSimpleType(aValue, TypeClass_BOOLEAN) >>= bValue; - switch ( m_nBoolCompareMode ) - { - case BOOL_COMPARISON_SQL: - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" IS ")); - if ( bValue ) - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" TRUE ")); - else - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" FALSE ")); - break; - case BOOL_COMPARISON_MISC: - aSql += STR_EQUAL; - if ( bValue ) - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" TRUE ")); - else - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" FALSE ")); - break; - case BOOL_COMPARISON_ACCESS: - if ( bValue ) - { - aSql = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" NOT ( ")); - aSql += sTmpName; - aSql += STR_EQUAL; - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0")); - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" OR ")); - aSql += sTmpName; - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" IS NULL )")) ; - } - else - { - aSql += STR_EQUAL; - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0")); - } - break; - case BOOL_COMPARISON_DEFAULT: // fall through - default: - aSql += STR_EQUAL; - if ( bValue ) - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("1")); - else - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0")); - - } - break; + ::rtl::OUString sColumnExp = aSQL.makeStringAndClear(); + getBoleanComparisonPredicate( sColumnExp, bValue, m_nBoolCompareMode, aSQL ); } default: - aSql += STR_EQUAL; - aSql += DBTypeConversion::toSQLString(nType,aValue,sal_True,m_xTypeConverter); + aSQL.append( STR_EQUAL ); + aSQL.append( DBTypeConversion::toSQLString( nType, aValue, sal_True, m_xTypeConverter ) ); + break; } } else - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" IS NULL")) ; + aSQL.appendAscii( " IS NULL" ) ; // filter anhaengen // select ohne where und order by aufbauen ::rtl::OUString sFilter = getFilter(); - if ( (sFilter.getLength() != 0) && (aSql.getLength() != 0) ) + if ( sFilter.getLength() && aSQL.getLength() ) { ::rtl::OUString sTemp(L_BRACKET); sTemp += sFilter; @@ -1655,7 +1567,7 @@ sTemp += andCriteria ? STR_AND : STR_OR; sFilter = sTemp; } - sFilter += aSql; + sFilter += aSQL.makeStringAndClear(); // add the filter and the sort order _aSetFunctor(this,sFilter); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
