LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/connectivity - sqlparse.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 7 42.9 %
Date: 2012-12-27 Functions: 1 5 20.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 _CONNECTIVITY_SQLPARSE_HXX
      20             : #define _CONNECTIVITY_SQLPARSE_HXX
      21             : 
      22             : #include <com/sun/star/uno/Reference.h>
      23             : #include <osl/mutex.hxx>
      24             : #include <connectivity/sqlnode.hxx>
      25             : #ifndef DISABLE_DBCONNECTIVITY
      26             : #ifndef YYBISON
      27             : #ifndef FLEX_SCANNER
      28             : #ifndef BISON_INCLUDED
      29             : #define BISON_INCLUDED
      30             : #include "sqlbison.hxx"
      31             : #endif
      32             : #endif
      33             : #endif
      34             : #endif
      35             : #include <com/sun/star/i18n/XCharacterClassification.hpp>
      36             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      37             : #include <com/sun/star/i18n/XLocaleData4.hpp>
      38             : #include "connectivity/IParseContext.hxx"
      39             : #include "connectivity/dbtoolsdllapi.hxx"
      40             : #include "connectivity/sqlerror.hxx"
      41             : #include <salhelper/singletonref.hxx>
      42             : 
      43             : #include <map>
      44             : 
      45             : // forward declarations
      46             : namespace com
      47             : {
      48             :     namespace sun
      49             :     {
      50             :         namespace star
      51             :         {
      52             :             namespace beans
      53             :             {
      54             :                 class XPropertySet;
      55             :             }
      56             :             namespace util
      57             :             {
      58             :                 class XNumberFormatter;
      59             :             }
      60             :             namespace lang
      61             :             {
      62             :                 struct Locale;
      63             :             }
      64             :         }
      65             :     }
      66             : }
      67             : namespace connectivity
      68             : {
      69             :     class OSQLScanner;
      70             :     class SQLError;
      71             : 
      72             :     //==========================================================================
      73             :     //= OParseContext
      74             :     //==========================================================================
      75             :     class OOO_DLLPUBLIC_DBTOOLS OParseContext : public IParseContext
      76             :     {
      77             :     public:
      78             :         OParseContext();
      79             : 
      80             :         virtual ~OParseContext();
      81             :         // retrieves language specific error messages
      82             :         virtual ::rtl::OUString getErrorMessage(ErrorCode _eCodes) const;
      83             : 
      84             :         // retrieves language specific keyword strings (only ASCII allowed)
      85             :         virtual ::rtl::OString getIntlKeywordAscii(InternationalKeyCode _eKey) const;
      86             : 
      87             :         // finds out, if we have an international keyword (only ASCII allowed)
      88             :         virtual InternationalKeyCode getIntlKeyCode(const ::rtl::OString& rToken) const;
      89             : 
      90             :         // determines the default international setting
      91             :         static const ::com::sun::star::lang::Locale& getDefaultLocale();
      92             : 
      93             :         /** get's a locale instance which should be used when parsing in the context specified by this instance
      94             :             <p>if this is not overridden by derived classes, it returns the static default locale.</p>
      95             :         */
      96             :         virtual ::com::sun::star::lang::Locale getPreferredLocale( ) const;
      97             :     };
      98             : 
      99             :     //==========================================================================
     100             :     // OSQLParseNodesContainer
     101             :     // grabage collection of nodes
     102             :     //==========================================================================
     103             :     class OSQLParseNodesContainer
     104             :     {
     105             :         ::osl::Mutex m_aMutex;
     106             :         ::std::vector< OSQLParseNode* > m_aNodes;
     107             :     public:
     108             :         OSQLParseNodesContainer();
     109             :         ~OSQLParseNodesContainer();
     110             : 
     111             :         void push_back(OSQLParseNode* _pNode);
     112             :         void erase(OSQLParseNode* _pNode);
     113             :         void clear();
     114             :         void clearAndDelete();
     115             :     };
     116             : 
     117             :     typedef salhelper::SingletonRef<OSQLParseNodesContainer> OSQLParseNodesGarbageCollector;
     118             : 
     119             :     //==========================================================================
     120             :     //= OSQLParser
     121             :     //==========================================================================
     122           0 :     struct OSQLParser_Data
     123             :     {
     124             :         ::com::sun::star::lang::Locale  aLocale;
     125             :         ::connectivity::SQLError        aErrors;
     126             : 
     127           2 :         OSQLParser_Data( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext )
     128           2 :             :aErrors( _rxContext )
     129             :         {
     130           2 :         }
     131             :     };
     132             : 
     133             :     /** Parser for SQL92
     134             :     */
     135             :     class OOO_DLLPUBLIC_DBTOOLS OSQLParser
     136             :     {
     137             :         friend class OSQLParseNode;
     138             :         friend class OSQLInternalNode;
     139             :         friend struct SQLParseNodeParameter;
     140             : 
     141             :     private:
     142             :         typedef ::std::map< sal_uInt32, OSQLParseNode::Rule >   RuleIDMap;
     143             :     //  static parts for parsers
     144             :         static sal_uInt32           s_nRuleIDs[OSQLParseNode::rule_count + 1];
     145             :         static RuleIDMap            s_aReverseRuleIDLookup;
     146             :         static OParseContext        s_aDefaultContext;
     147             : 
     148             :         static OSQLScanner*                     s_pScanner;
     149             :         static OSQLParseNodesGarbageCollector*  s_pGarbageCollector;
     150             :         static sal_Int32                        s_nRefCount;
     151             : 
     152             :     // informations on the current parse action
     153             :         const IParseContext*        m_pContext;
     154             :         OSQLParseNode*              m_pParseTree;   // result from parsing
     155             :         ::std::auto_ptr< OSQLParser_Data >
     156             :                                     m_pData;
     157             :         ::rtl::OUString                     m_sFieldName;   // current field name for a predicate
     158             :         ::rtl::OUString                     m_sErrorMessage;// current error msg
     159             : 
     160             :         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
     161             :                                     m_xField;       // current field
     162             :         ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >
     163             :                                     m_xFormatter;   // current number formatter
     164             :         sal_Int32                   m_nFormatKey;   // numberformat, which should be used
     165             :         sal_Int32                   m_nDateFormatKey;
     166             :         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >    m_xContext;
     167             :         ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCharacterClassification> m_xCharClass;
     168             :         static ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XLocaleData4>       s_xLocaleData;
     169             :         ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XLocaleData>      xDummy; // can be deleted after 627
     170             : 
     171             :         // convert a string into double trim it to scale of _nscale and than transform it back to string
     172             :         ::rtl::OUString stringToDouble(const ::rtl::OUString& _rValue,sal_Int16 _nScale);
     173             :         OSQLParseNode*  buildDate(sal_Int32 _nType,OSQLParseNode*& pLiteral);
     174             :         bool            extractDate(OSQLParseNode* pLiteral,double& _rfValue);
     175             :         void            killThousandSeparator(OSQLParseNode* pLiteral);
     176             :         OSQLParseNode*  convertNode(sal_Int32 nType,OSQLParseNode*& pLiteral);
     177             :         // makes a string out of a number, pLiteral will be deleted
     178             :         OSQLParseNode*  buildNode_STR_NUM(OSQLParseNode*& pLiteral);
     179             :         OSQLParseNode*  buildNode_Date(const double& fValue, sal_Int32 nType);
     180             : 
     181             :         static ::osl::Mutex& getMutex();
     182             : 
     183             :     public:
     184             :         // if NULL, a default context will be used
     185             :         // the context must live as long as the parser
     186             :         OSQLParser(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, const IParseContext* _pContext = NULL);
     187             :         ~OSQLParser();
     188             : 
     189             :         // Parsing an SQLStatement
     190             :         OSQLParseNode* parseTree(::rtl::OUString& rErrorMessage,
     191             :                        const ::rtl::OUString& rStatement,
     192             :                        sal_Bool bInternational = sal_False);
     193             : 
     194             :         // Check a Predicate
     195             :         OSQLParseNode* predicateTree(::rtl::OUString& rErrorMessage, const ::rtl::OUString& rStatement,
     196             :                        const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter,
     197             :                        const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & xField);
     198             : 
     199             :         // Access to the context
     200           0 :         const IParseContext& getContext() const {return *m_pContext;}
     201             : 
     202             :         /// access to the SQLError instance owned by this parser
     203             :         const SQLError& getErrorHelper() const;
     204             : 
     205             :         // TokenIDToStr: token name belonging to a token number.
     206             :         static ::rtl::OString TokenIDToStr(sal_uInt32 nTokenID, const IParseContext* pContext = NULL);
     207             : 
     208             : #if OSL_DEBUG_LEVEL > 1
     209             :         // (empty string if not found)
     210             :         static ::rtl::OUString RuleIDToStr(sal_uInt32 nRuleID);
     211             : #endif
     212             : 
     213             :         // StrToRuleID calculates the RuleID for a ::rtl::OUString (that is, ::com::sun::star::sdbcx::Index in yytname)
     214             :         // (0 if not found). The search for an ID based on a String is
     215             :         // extremely inefficient (sequential search for ::rtl::OUString)!
     216             :         static sal_uInt32 StrToRuleID(const ::rtl::OString & rValue);
     217             : 
     218             :         static OSQLParseNode::Rule RuleIDToRule( sal_uInt32 _nRule );
     219             : 
     220             :         // RuleId with enum, far more efficient
     221             :         static sal_uInt32 RuleID(OSQLParseNode::Rule eRule);
     222             :         // compares the _sFunctionName with all known function names and return the DataType of the return value
     223             :         static sal_Int32 getFunctionReturnType(const ::rtl::OUString& _sFunctionName, const IParseContext* pContext = NULL);
     224             : 
     225             :         // returns the type for a parameter in a given function name
     226             :         static sal_Int32 getFunctionParameterType(sal_uInt32 _nTokenId,sal_uInt32 _nPos);
     227             : 
     228             :         void error(const sal_Char *fmt);
     229             :         int SQLlex();
     230             : #ifdef YYBISON
     231             :         void setParseTree(OSQLParseNode * pNewParseTree);
     232             : 
     233             :         // Is the parse in a special mode?
     234             :         // Predicate chack is used to check a condition for a field
     235           0 :         sal_Bool inPredicateCheck() const {return m_xField.is();}
     236           0 :         const ::rtl::OUString& getFieldName() const {return m_sFieldName;}
     237             : 
     238             :         void reduceLiteral(OSQLParseNode*& pLiteral, sal_Bool bAppendBlank);
     239             :          // does not change the pLiteral argument
     240             :         sal_Int16 buildNode(OSQLParseNode*& pAppend,OSQLParseNode* pCompare,OSQLParseNode* pLiteral,OSQLParseNode* pLiteral2);
     241             : 
     242             :         sal_Int16 buildComparsionRule(OSQLParseNode*& pAppend,OSQLParseNode* pLiteral);
     243             :         // pCompre will be deleted if it is not used
     244             :         sal_Int16 buildPredicateRule(OSQLParseNode*& pAppend,OSQLParseNode* pLiteral,OSQLParseNode*& pCompare,OSQLParseNode* pLiteral2 = NULL);
     245             : 
     246             :         sal_Int16 buildLikeRule(OSQLParseNode*& pAppend,OSQLParseNode*& pLiteral,const OSQLParseNode* pEscape);
     247             :         sal_Int16 buildStringNodes(OSQLParseNode*& pLiteral);
     248             : #else
     249             : #endif
     250             :     };
     251             : }
     252             : 
     253             : 
     254             : #endif //_CONNECTIVITY_SQLPARSE_HXX
     255             : 
     256             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10