LCOV - code coverage report
Current view: top level - libreoffice/dbaccess/source/core/inc - SingleSelectQueryComposer.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 3 0.0 %
Date: 2012-12-27 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #ifndef DBACCESS_CORE_API_SINGLESELECTQUERYCOMPOSER_HXX
      20             : #define DBACCESS_CORE_API_SINGLESELECTQUERYCOMPOSER_HXX
      21             : 
      22             : #include <com/sun/star/sdb/XParametersSupplier.hpp>
      23             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      24             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      25             : #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
      26             : #include <com/sun/star/lang/XServiceInfo.hpp>
      27             : #include <com/sun/star/script/XTypeConverter.hpp>
      28             : #include <cppuhelper/implbase5.hxx>
      29             : #include <connectivity/sqliterator.hxx>
      30             : #include <connectivity/sqlparse.hxx>
      31             : #include "apitools.hxx"
      32             : #include <comphelper/broadcasthelper.hxx>
      33             : #include <comphelper/uno3.hxx>
      34             : #include <comphelper/proparrhlp.hxx>
      35             : #include <comphelper/propertycontainer.hxx>
      36             : #include <comphelper/componentcontext.hxx>
      37             : 
      38             : #include <memory>
      39             : 
      40             : namespace com { namespace sun { namespace star { namespace util {
      41             :     class XNumberFormatsSupplier;
      42             :     class XNumberFormatter;
      43             : }}}}
      44             : 
      45             : namespace dbaccess
      46             : {
      47             :     typedef ::cppu::ImplHelper5<    ::com::sun::star::sdb::XSingleSelectQueryComposer,
      48             :                                     ::com::sun::star::sdb::XParametersSupplier,
      49             :                                     ::com::sun::star::sdbcx::XColumnsSupplier,
      50             :                                     ::com::sun::star::sdbcx::XTablesSupplier,
      51             :                                     ::com::sun::star::lang::XServiceInfo    > OSingleSelectQueryComposer_BASE;
      52             : 
      53             :     class OPrivateColumns;
      54             :     class OPrivateTables;
      55             : 
      56             :     class OSingleSelectQueryComposer :   public ::comphelper::OMutexAndBroadcastHelper
      57             :                                         ,public OSubComponent
      58             :                                         ,public ::comphelper::OPropertyContainer
      59             :                                         ,public ::comphelper::OPropertyArrayUsageHelper < OSingleSelectQueryComposer >
      60             :                                         ,public OSingleSelectQueryComposer_BASE
      61             :     {
      62             :         enum SQLPart
      63             :         {
      64             :             Where = 0,      // the 0 is important, as it will be used as index into arrays
      65             :             Group,
      66             :             Having,
      67             :             Order,
      68             : 
      69             :             SQLPartCount
      70             :         };
      71           0 :         inline void incSQLPart( SQLPart& e ) { e = (SQLPart)(1 + (size_t)e); }
      72             :         enum EColumnType
      73             :         {
      74             :             SelectColumns       = 0,
      75             :             GroupByColumns      = 1,
      76             :             OrderColumns        = 2,
      77             :             ParameterColumns    = 3
      78             :         };
      79             :         typedef ::std::const_mem_fun_t< const ::connectivity::OSQLParseNode*, ::connectivity::OSQLParseTreeIterator >
      80             :                                                 TGetParseNode;
      81             :         ::connectivity::OSQLParser              m_aSqlParser;
      82             :         ::connectivity::OSQLParseTreeIterator   m_aSqlIterator;         // the iterator for the complete statement
      83             :         ::connectivity::OSQLParseTreeIterator   m_aAdditiveIterator;    // the iterator for the "additive statement" (means without the clauses of the elementary statement)
      84             :         ::std::vector<OPrivateColumns*>         m_aColumnsCollection;   // used for columns and parameters of old queries
      85             :         ::std::vector<OPrivateTables*>          m_aTablesCollection;
      86             : 
      87             :         ::std::vector< ::rtl::OUString >        m_aElementaryParts;     // the filter/groupby/having/order of the elementary statement
      88             : 
      89             :         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>              m_xConnection;
      90             :         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData>        m_xMetaData;
      91             :         ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>         m_xConnectionTables;
      92             :         ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>         m_xConnectionQueries;
      93             :         ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >  m_xNumberFormatsSupplier;
      94             :         ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>         m_xColumns;
      95             :         ::comphelper::ComponentContext                                                      m_aContext;
      96             :         ::com::sun::star::uno::Reference< ::com::sun::star::script::XTypeConverter >        m_xTypeConverter;
      97             : 
      98             :         ::std::vector<OPrivateColumns*>         m_aCurrentColumns;
      99             :         OPrivateTables*                         m_pTables;      // currently used tables
     100             : 
     101             :         ::rtl::OUString                         m_aPureSelectSQL;   // the pure select statement, without filter/order/groupby/having
     102             :         ::rtl::OUString                         m_sDecimalSep;
     103             :         ::rtl::OUString                         m_sCommand;
     104             :         ::com::sun::star::lang::Locale          m_aLocale;
     105             :         sal_Int32                               m_nBoolCompareMode; // how to compare bool values
     106             :         sal_Int32                               m_nCommandType;
     107             : 
     108             :         // <properties>
     109             :         ::rtl::OUString                         m_sOrignal;
     110             :         // </properties>
     111             : 
     112             : 
     113             :         sal_Bool setORCriteria(::connectivity::OSQLParseNode* pCondition, ::connectivity::OSQLParseTreeIterator& _rIterator,
     114             :             ::std::vector< ::std::vector < ::com::sun::star::beans::PropertyValue > >& rFilters, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter) const;
     115             :         sal_Bool setANDCriteria(::connectivity::OSQLParseNode* pCondition, ::connectivity::OSQLParseTreeIterator& _rIterator,
     116             :             ::std::vector < ::com::sun::star::beans::PropertyValue > & rFilters, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter) const;
     117             :         sal_Bool setComparsionPredicate(::connectivity::OSQLParseNode* pCondition, ::connectivity::OSQLParseTreeIterator& _rIterator,
     118             :             ::std::vector < ::com::sun::star::beans::PropertyValue > & rFilters, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter) const;
     119             : 
     120             :         ::rtl::OUString getColumnName(::connectivity::OSQLParseNode* pColumnRef,::connectivity::OSQLParseTreeIterator& _rIterator) const;
     121             :         ::rtl::OUString getTableAlias(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column ) const;
     122             :         sal_Int32 getPredicateType(::connectivity::OSQLParseNode * _pPredicate) const;
     123             :         // clears all Columns,Parameters and tables and insert it to their vectors
     124             :         void clearCurrentCollections();
     125             :         // clears the columns collection given by EColumnType
     126             :         void clearColumns( const EColumnType _eType );
     127             : 
     128             :         /** retrieves a particular part of a statement
     129             :             @param _rIterator
     130             :                 the iterator to use.
     131             :         */
     132             :         ::rtl::OUString getStatementPart( TGetParseNode& _aGetFunctor, ::connectivity::OSQLParseTreeIterator& _rIterator );
     133             :         void setQuery_Impl( const ::rtl::OUString& command );
     134             : 
     135             :         void setConditionByColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column
     136             :                                 , sal_Bool andCriteria
     137             :                                 ,::std::mem_fun1_t<bool,OSingleSelectQueryComposer,::rtl::OUString>& _aSetFunctor
     138             :                                 ,sal_Int32 filterOperator);
     139             : 
     140             :         /** getStructuredCondition returns the structured condition for the where or having clause
     141             :             @param  _aGetFunctor
     142             :                 A member function to get the correct parse node.
     143             : 
     144             :             @return
     145             :                 The structured filter
     146             :         */
     147             :         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >
     148             :                     getStructuredCondition( TGetParseNode& _aGetFunctor );
     149             : 
     150             :         ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >
     151             :                     setCurrentColumns( EColumnType _eType, const ::rtl::Reference< ::connectivity::OSQLColumns >& _rCols );
     152             : 
     153             :         //helper methods for mem_fun_t
     154           0 :         inline bool implSetFilter(::rtl::OUString _sFilter) { setFilter(_sFilter); return true;}
     155           0 :         inline bool implSetHavingClause(::rtl::OUString _sFilter) { setHavingClause(_sFilter); return true;}
     156             : 
     157             :         /** returns the part of the seelect statement
     158             :             @param  _ePart
     159             :                 Which part should be returned.
     160             :             @param  _bWithKeyword
     161             :                 If <TRUE/> the keyword will be added too. Otherwise not.
     162             :             @param _rIterator
     163             :                 The iterator to use.
     164             : 
     165             :             @return
     166             :                 The part of the select statement.
     167             :         */
     168             :         ::rtl::OUString getSQLPart( SQLPart _ePart, ::connectivity::OSQLParseTreeIterator& _rIterator, sal_Bool _bWithKeyword );
     169             : 
     170             :         /** retrieves the keyword for the given SQLPart
     171             :         */
     172             :         ::rtl::OUString getKeyword( SQLPart _ePart ) const;
     173             : 
     174             :         /** sets a single "additive" clause, means a filter/groupby/having/order clause
     175             :         */
     176             :         void setSingleAdditiveClause( SQLPart _ePart, const ::rtl::OUString& _rClause );
     177             : 
     178             :         /** composes a statement from m_aPureSelectSQL and the 4 usual clauses
     179             :         */
     180             :         ::rtl::OUString composeStatementFromParts( const ::std::vector< ::rtl::OUString >& _rParts );
     181             : 
     182             :         /** return the name of the column.
     183             :         */
     184             :         ::rtl::OUString impl_getColumnName_throw(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column);
     185             : 
     186             :     protected:
     187             :         virtual ~OSingleSelectQueryComposer();
     188             :     public:
     189             : 
     190             :         OSingleSelectQueryComposer( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _xTableSupplier,
     191             :                         const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,
     192             :                         const ::comphelper::ComponentContext& _rContext);
     193             : 
     194             : 
     195             :         void SAL_CALL disposing(void);
     196             :         // ::com::sun::star::lang::XTypeProvider
     197             :         DECLARE_TYPEPROVIDER( );
     198             : 
     199             :         // com::sun::star::lang::XUnoTunnel
     200             :         virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
     201             :         // ::com::sun::star::uno::XInterface
     202             :         DECLARE_XINTERFACE( )
     203             : 
     204             :         // XServiceInfo
     205             :         DECLARE_SERVICE_INFO();
     206             : 
     207             :         DECLARE_PROPERTYCONTAINER_DEFAULTS();
     208             : 
     209             :         // ::com::sun::star::sdb::XSingleSelectQueryComposer
     210             :         virtual ::rtl::OUString SAL_CALL getElementaryQuery() throw (::com::sun::star::uno::RuntimeException);
     211             :         virtual void SAL_CALL setElementaryQuery( const ::rtl::OUString& _rElementary ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     212             :         virtual void SAL_CALL setFilter( const ::rtl::OUString& filter ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     213             :         virtual void SAL_CALL setStructuredFilter( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& filter ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
     214             :         virtual void SAL_CALL appendFilterByColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column, sal_Bool andCriteria,sal_Int32 filterOperator ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     215             :         virtual void SAL_CALL appendGroupByColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     216             :         virtual void SAL_CALL setGroup( const ::rtl::OUString& group ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     217             :         virtual void SAL_CALL setHavingClause( const ::rtl::OUString& filter ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     218             :         virtual void SAL_CALL setStructuredHavingClause( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& filter ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     219             :         virtual void SAL_CALL appendHavingClauseByColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column, sal_Bool andCriteria,sal_Int32 filterOperator ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     220             :         virtual void SAL_CALL appendOrderByColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column, sal_Bool ascending ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     221             :         virtual void SAL_CALL setOrder( const ::rtl::OUString& order ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     222             : 
     223             :         // XSingleSelectQueryAnalyzer
     224             :         virtual ::rtl::OUString SAL_CALL getQuery(  ) throw (::com::sun::star::uno::RuntimeException);
     225             :         virtual void SAL_CALL setQuery( const ::rtl::OUString& command ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     226             :         virtual void SAL_CALL setCommand( const ::rtl::OUString& command,sal_Int32 CommandType ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     227             :         virtual ::rtl::OUString SAL_CALL getFilter(  ) throw (::com::sun::star::uno::RuntimeException);
     228             :         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > SAL_CALL getStructuredFilter(  ) throw (::com::sun::star::uno::RuntimeException);
     229             :         virtual ::rtl::OUString SAL_CALL getGroup(  ) throw (::com::sun::star::uno::RuntimeException);
     230             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > SAL_CALL getGroupColumns(  ) throw (::com::sun::star::uno::RuntimeException);
     231             :         virtual ::rtl::OUString SAL_CALL getHavingClause(  ) throw (::com::sun::star::uno::RuntimeException);
     232             :         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > SAL_CALL getStructuredHavingClause(  ) throw (::com::sun::star::uno::RuntimeException);
     233             :         virtual ::rtl::OUString SAL_CALL getOrder(  ) throw (::com::sun::star::uno::RuntimeException);
     234             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > SAL_CALL getOrderColumns(  ) throw (::com::sun::star::uno::RuntimeException);
     235             :         virtual ::rtl::OUString SAL_CALL getQueryWithSubstitution(  ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     236             : 
     237             :         // XColumnsSupplier
     238             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getColumns(  ) throw(::com::sun::star::uno::RuntimeException);
     239             :         // XTablesSupplier
     240             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getTables(  ) throw(::com::sun::star::uno::RuntimeException);
     241             :         // XParametersSupplier
     242             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > SAL_CALL getParameters(  ) throw(::com::sun::star::uno::RuntimeException);
     243             :     };
     244             : }
     245             : #endif // DBACCESS_CORE_API_SINGLESELECTQUERYCOMPOSER_HXX
     246             : 
     247             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10