LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/dbaccess/source/core/inc - SingleSelectQueryComposer.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 3 100.0 %
Date: 2013-07-09 Functions: 3 3 100.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 <svx/ParseContext.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         932 :         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             :         ::svxform::OSystemParseContext          m_aParseContext;
      82             :         ::connectivity::OSQLParser              m_aSqlParser;
      83             :         ::connectivity::OSQLParseTreeIterator   m_aSqlIterator;         // the iterator for the complete statement
      84             :         ::connectivity::OSQLParseTreeIterator   m_aAdditiveIterator;    // the iterator for the "additive statement" (means without the clauses of the elementary statement)
      85             :         ::std::vector<OPrivateColumns*>         m_aColumnsCollection;   // used for columns and parameters of old queries
      86             :         ::std::vector<OPrivateTables*>          m_aTablesCollection;
      87             : 
      88             :         ::std::vector< OUString >        m_aElementaryParts;     // the filter/groupby/having/order of the elementary statement
      89             : 
      90             :         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>              m_xConnection;
      91             :         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData>        m_xMetaData;
      92             :         ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>         m_xConnectionTables;
      93             :         ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>         m_xConnectionQueries;
      94             :         ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >  m_xNumberFormatsSupplier;
      95             :         ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>         m_xColumns;
      96             :         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext>         m_aContext;
      97             :         ::com::sun::star::uno::Reference< ::com::sun::star::script::XTypeConverter >        m_xTypeConverter;
      98             : 
      99             :         ::std::vector<OPrivateColumns*>         m_aCurrentColumns;
     100             :         OPrivateTables*                         m_pTables;      // currently used tables
     101             : 
     102             :         OUString                         m_aPureSelectSQL;   // the pure select statement, without filter/order/groupby/having
     103             :         OUString                         m_sDecimalSep;
     104             :         OUString                         m_sCommand;
     105             :         ::com::sun::star::lang::Locale          m_aLocale;
     106             :         sal_Int32                               m_nBoolCompareMode; // how to compare bool values
     107             :         sal_Int32                               m_nCommandType;
     108             : 
     109             :         // <properties>
     110             :         OUString                         m_sOrignal;
     111             :         // </properties>
     112             : 
     113             : 
     114             :         sal_Bool setORCriteria(::connectivity::OSQLParseNode* pCondition, ::connectivity::OSQLParseTreeIterator& _rIterator,
     115             :             ::std::vector< ::std::vector < ::com::sun::star::beans::PropertyValue > >& rFilters, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter) const;
     116             :         sal_Bool setANDCriteria(::connectivity::OSQLParseNode* pCondition, ::connectivity::OSQLParseTreeIterator& _rIterator,
     117             :             ::std::vector < ::com::sun::star::beans::PropertyValue > & rFilters, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter) const;
     118             :         sal_Bool setComparsionPredicate(::connectivity::OSQLParseNode* pCondition, ::connectivity::OSQLParseTreeIterator& _rIterator,
     119             :             ::std::vector < ::com::sun::star::beans::PropertyValue > & rFilters, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter) const;
     120             : 
     121             :         OUString getColumnName(::connectivity::OSQLParseNode* pColumnRef,::connectivity::OSQLParseTreeIterator& _rIterator) const;
     122             :         OUString getTableAlias(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column ) const;
     123             :         sal_Int32 getPredicateType(::connectivity::OSQLParseNode * _pPredicate) const;
     124             :         // clears all Columns,Parameters and tables and insert it to their vectors
     125             :         void clearCurrentCollections();
     126             :         // clears the columns collection given by EColumnType
     127             :         void clearColumns( const EColumnType _eType );
     128             : 
     129             :         /** retrieves a particular part of a statement
     130             :             @param _rIterator
     131             :                 the iterator to use.
     132             :         */
     133             :         OUString getStatementPart( TGetParseNode& _aGetFunctor, ::connectivity::OSQLParseTreeIterator& _rIterator );
     134             :         void setQuery_Impl( const OUString& command );
     135             : 
     136             :         void setConditionByColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column
     137             :                                 , sal_Bool andCriteria
     138             :                                 ,::std::mem_fun1_t<bool,OSingleSelectQueryComposer,OUString>& _aSetFunctor
     139             :                                 ,sal_Int32 filterOperator);
     140             : 
     141             :         /** getStructuredCondition returns the structured condition for the where or having clause
     142             :             @param  _aGetFunctor
     143             :                 A member function to get the correct parse node.
     144             : 
     145             :             @return
     146             :                 The structured filter
     147             :         */
     148             :         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >
     149             :                     getStructuredCondition( TGetParseNode& _aGetFunctor );
     150             : 
     151             :         ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >
     152             :                     setCurrentColumns( EColumnType _eType, const ::rtl::Reference< ::connectivity::OSQLColumns >& _rCols );
     153             : 
     154             :         //helper methods for mem_fun_t
     155           2 :         inline bool implSetFilter(OUString _sFilter) { setFilter(_sFilter); return true;}
     156           1 :         inline bool implSetHavingClause(OUString _sFilter) { setHavingClause(_sFilter); return true;}
     157             : 
     158             :         /** returns the part of the seelect statement
     159             :             @param  _ePart
     160             :                 Which part should be returned.
     161             :             @param  _bWithKeyword
     162             :                 If <TRUE/> the keyword will be added too. Otherwise not.
     163             :             @param _rIterator
     164             :                 The iterator to use.
     165             : 
     166             :             @return
     167             :                 The part of the select statement.
     168             :         */
     169             :         OUString getSQLPart( SQLPart _ePart, ::connectivity::OSQLParseTreeIterator& _rIterator, sal_Bool _bWithKeyword );
     170             : 
     171             :         /** retrieves the keyword for the given SQLPart
     172             :         */
     173             :         OUString getKeyword( SQLPart _ePart ) const;
     174             : 
     175             :         /** sets a single "additive" clause, means a filter/groupby/having/order clause
     176             :         */
     177             :         void setSingleAdditiveClause( SQLPart _ePart, const OUString& _rClause );
     178             : 
     179             :         /** composes a statement from m_aPureSelectSQL and the 4 usual clauses
     180             :         */
     181             :         OUString composeStatementFromParts( const ::std::vector< OUString >& _rParts );
     182             : 
     183             :         /** return the name of the column.
     184             :         */
     185             :         OUString impl_getColumnName_throw(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column);
     186             : 
     187             :     protected:
     188             :         virtual ~OSingleSelectQueryComposer();
     189             :     public:
     190             : 
     191             :         OSingleSelectQueryComposer( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _xTableSupplier,
     192             :                         const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,
     193             :                         const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext>& _rContext);
     194             : 
     195             : 
     196             :         void SAL_CALL disposing(void);
     197             :         // ::com::sun::star::lang::XTypeProvider
     198             :         DECLARE_TYPEPROVIDER( );
     199             : 
     200             :         // com::sun::star::lang::XUnoTunnel
     201             :         virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
     202             :         // ::com::sun::star::uno::XInterface
     203             :         DECLARE_XINTERFACE( )
     204             : 
     205             :         // XServiceInfo
     206             :         DECLARE_SERVICE_INFO();
     207             : 
     208             :         DECLARE_PROPERTYCONTAINER_DEFAULTS();
     209             : 
     210             :         // ::com::sun::star::sdb::XSingleSelectQueryComposer
     211             :         virtual OUString SAL_CALL getElementaryQuery() throw (::com::sun::star::uno::RuntimeException);
     212             :         virtual void SAL_CALL setElementaryQuery( const OUString& _rElementary ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     213             :         virtual void SAL_CALL setFilter( const OUString& filter ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     214             :         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);
     215             :         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);
     216             :         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);
     217             :         virtual void SAL_CALL setGroup( const OUString& group ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     218             :         virtual void SAL_CALL setHavingClause( const OUString& filter ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     219             :         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);
     220             :         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);
     221             :         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);
     222             :         virtual void SAL_CALL setOrder( const OUString& order ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     223             : 
     224             :         // XSingleSelectQueryAnalyzer
     225             :         virtual OUString SAL_CALL getQuery(  ) throw (::com::sun::star::uno::RuntimeException);
     226             :         virtual void SAL_CALL setQuery( const OUString& command ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     227             :         virtual void SAL_CALL setCommand( const OUString& command,sal_Int32 CommandType ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     228             :         virtual OUString SAL_CALL getFilter(  ) throw (::com::sun::star::uno::RuntimeException);
     229             :         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);
     230             :         virtual OUString SAL_CALL getGroup(  ) throw (::com::sun::star::uno::RuntimeException);
     231             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > SAL_CALL getGroupColumns(  ) throw (::com::sun::star::uno::RuntimeException);
     232             :         virtual OUString SAL_CALL getHavingClause(  ) throw (::com::sun::star::uno::RuntimeException);
     233             :         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);
     234             :         virtual OUString SAL_CALL getOrder(  ) throw (::com::sun::star::uno::RuntimeException);
     235             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > SAL_CALL getOrderColumns(  ) throw (::com::sun::star::uno::RuntimeException);
     236             :         virtual OUString SAL_CALL getQueryWithSubstitution(  ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
     237             : 
     238             :         // XColumnsSupplier
     239             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getColumns(  ) throw(::com::sun::star::uno::RuntimeException);
     240             :         // XTablesSupplier
     241             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getTables(  ) throw(::com::sun::star::uno::RuntimeException);
     242             :         // XParametersSupplier
     243             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > SAL_CALL getParameters(  ) throw(::com::sun::star::uno::RuntimeException);
     244             :     };
     245             : }
     246             : #endif // DBACCESS_CORE_API_SINGLESELECTQUERYCOMPOSER_HXX
     247             : 
     248             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10