LCOV - code coverage report
Current view: top level - svx/source/form - ParseContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 32 94 34.0 %
Date: 2012-08-25 Functions: 8 14 57.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 34 204 16.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <sal/macros.h>
      31                 :            : #include "svx/ParseContext.hxx"
      32                 :            : #include "stringlistresource.hxx"
      33                 :            : #include "svx/fmresids.hrc"
      34                 :            : 
      35                 :            : #include <svx/dialmgr.hxx>
      36                 :            : 
      37                 :            : #include <unotools/syslocale.hxx>
      38                 :            : #include <vcl/svapp.hxx>
      39                 :            : #include <tools/debug.hxx>
      40                 :            : #include <osl/mutex.hxx>
      41                 :            : 
      42                 :            : using namespace svxform;
      43                 :            : using namespace ::connectivity;
      44                 :            : //==========================================================================
      45                 :            : //= OSystemParseContext
      46                 :            : //==========================================================================
      47                 :            : DBG_NAME(OSystemParseContext)
      48                 :            : //-----------------------------------------------------------------------------
      49         [ +  - ]:         17 : OSystemParseContext::OSystemParseContext() : IParseContext()
      50                 :            : {
      51                 :            :     DBG_CTOR(OSystemParseContext,NULL);
      52         [ +  - ]:         17 :     SolarMutexGuard aGuard;
      53                 :            : 
      54 [ +  - ][ +  - ]:         17 :     ::svx::StringListResource aKeywords( SVX_RES( RID_RSC_SQL_INTERNATIONAL ) );
      55 [ +  - ][ +  - ]:         17 :     aKeywords.get( m_aLocalizedKeywords );
                 [ +  - ]
      56                 :         17 : }
      57                 :            : 
      58                 :            : //-----------------------------------------------------------------------------
      59                 :         14 : OSystemParseContext::~OSystemParseContext()
      60                 :            : {
      61                 :            :     DBG_DTOR(OSystemParseContext,NULL);
      62         [ -  + ]:         28 : }
      63                 :            : 
      64                 :            : //-----------------------------------------------------------------------------
      65                 :          0 : ::com::sun::star::lang::Locale OSystemParseContext::getPreferredLocale( ) const
      66                 :            : {
      67 [ #  # ][ #  # ]:          0 :     return SvtSysLocale().GetLocaleData().getLocale();
      68                 :            : }
      69                 :            : 
      70                 :            : //-----------------------------------------------------------------------------
      71                 :          0 : ::rtl::OUString OSystemParseContext::getErrorMessage(ErrorCode _eCode) const
      72                 :            : {
      73         [ #  # ]:          0 :     String aMsg;
      74         [ #  # ]:          0 :     SolarMutexGuard aGuard;
      75   [ #  #  #  #  :          0 :     switch (_eCode)
          #  #  #  #  #  
             #  #  #  #  
                      # ]
      76                 :            :     {
      77 [ #  # ][ #  # ]:          0 :         case ERROR_GENERAL:                 aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_ERROR); break;
                 [ #  # ]
      78 [ #  # ][ #  # ]:          0 :         case ERROR_VALUE_NO_LIKE:           aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_VALUE_NO_LIKE); break;
                 [ #  # ]
      79 [ #  # ][ #  # ]:          0 :         case ERROR_FIELD_NO_LIKE:           aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_FIELD_NO_LIKE); break;
                 [ #  # ]
      80 [ #  # ][ #  # ]:          0 :         case ERROR_INVALID_COMPARE:         aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_CRIT_NO_COMPARE); break;
                 [ #  # ]
      81 [ #  # ][ #  # ]:          0 :         case ERROR_INVALID_INT_COMPARE:     aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_INT_NO_VALID); break;
                 [ #  # ]
      82 [ #  # ][ #  # ]:          0 :         case ERROR_INVALID_DATE_COMPARE:    aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_ACCESS_DAT_NO_VALID); break;
                 [ #  # ]
      83 [ #  # ][ #  # ]:          0 :         case ERROR_INVALID_REAL_COMPARE:    aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_REAL_NO_VALID); break;
                 [ #  # ]
      84 [ #  # ][ #  # ]:          0 :         case ERROR_INVALID_TABLE:           aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_TABLE); break;
                 [ #  # ]
      85 [ #  # ][ #  # ]:          0 :         case ERROR_INVALID_TABLE_OR_QUERY:  aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_TABLE_OR_QUERY); break;
                 [ #  # ]
      86 [ #  # ][ #  # ]:          0 :         case ERROR_INVALID_COLUMN:          aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_COLUMN); break;
                 [ #  # ]
      87 [ #  # ][ #  # ]:          0 :         case ERROR_INVALID_TABLE_EXIST:     aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_TABLE_EXISTS); break;
                 [ #  # ]
      88 [ #  # ][ #  # ]:          0 :         case ERROR_INVALID_QUERY_EXIST:     aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_QUERY_EXISTS); break;
                 [ #  # ]
      89                 :          0 :         case ERROR_NONE: break;
      90                 :            :     }
      91 [ #  # ][ #  # ]:          0 :     return aMsg;
                 [ #  # ]
      92                 :            : }
      93                 :            : 
      94                 :            : //-----------------------------------------------------------------------------
      95                 :          0 : ::rtl::OString OSystemParseContext::getIntlKeywordAscii(InternationalKeyCode _eKey) const
      96                 :            : {
      97                 :          0 :     size_t nIndex = 0;
      98   [ #  #  #  #  :          0 :     switch ( _eKey )
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
      99                 :            :     {
     100                 :          0 :         case KEY_LIKE:      nIndex = 0; break;
     101                 :          0 :         case KEY_NOT:       nIndex = 1; break;
     102                 :          0 :         case KEY_NULL:      nIndex = 2; break;
     103                 :          0 :         case KEY_TRUE:      nIndex = 3; break;
     104                 :          0 :         case KEY_FALSE:     nIndex = 4; break;
     105                 :          0 :         case KEY_IS:        nIndex = 5; break;
     106                 :          0 :         case KEY_BETWEEN:   nIndex = 6; break;
     107                 :          0 :         case KEY_OR:        nIndex = 7; break;
     108                 :          0 :         case KEY_AND:       nIndex = 8; break;
     109                 :          0 :         case KEY_AVG:       nIndex = 9; break;
     110                 :          0 :         case KEY_COUNT:     nIndex = 10; break;
     111                 :          0 :         case KEY_MAX:       nIndex = 11; break;
     112                 :          0 :         case KEY_MIN:       nIndex = 12; break;
     113                 :          0 :         case KEY_SUM:       nIndex = 13; break;
     114                 :          0 :         case KEY_EVERY:     nIndex = 14; break;
     115                 :          0 :         case KEY_ANY:       nIndex = 15; break;
     116                 :          0 :         case KEY_SOME:      nIndex = 16; break;
     117                 :          0 :         case KEY_STDDEV_POP: nIndex = 17; break;
     118                 :          0 :         case KEY_STDDEV_SAMP: nIndex = 18; break;
     119                 :          0 :         case KEY_VAR_SAMP:  nIndex = 19; break;
     120                 :          0 :         case KEY_VAR_POP:   nIndex = 20; break;
     121                 :          0 :         case KEY_COLLECT:   nIndex = 21; break;
     122                 :          0 :         case KEY_FUSION:    nIndex = 22; break;
     123                 :          0 :         case KEY_INTERSECTION: nIndex = 23; break;
     124                 :            :         case KEY_NONE:
     125                 :            :             OSL_FAIL( "OSystemParseContext::getIntlKeywordAscii: illegal argument!" );
     126                 :          0 :             break;
     127                 :            :     }
     128                 :            : 
     129                 :            :     OSL_ENSURE( nIndex < m_aLocalizedKeywords.size(), "OSystemParseContext::getIntlKeywordAscii: invalid index!" );
     130                 :            : 
     131                 :          0 :     rtl::OString sKeyword;
     132         [ #  # ]:          0 :     if ( nIndex < m_aLocalizedKeywords.size() )
     133 [ #  # ][ #  # ]:          0 :         sKeyword = rtl::OUStringToOString(m_aLocalizedKeywords[nIndex], RTL_TEXTENCODING_UTF8);
                 [ #  # ]
     134                 :          0 :     return sKeyword;
     135                 :            : }
     136                 :            : 
     137                 :            : // -----------------------------------------------------------------------------
     138                 :          0 : IParseContext::InternationalKeyCode OSystemParseContext::getIntlKeyCode(const ::rtl::OString& rToken) const
     139                 :            : {
     140                 :            :     static IParseContext::InternationalKeyCode Intl_TokenID[] =
     141                 :            :     {
     142                 :            :         KEY_LIKE, KEY_NOT, KEY_NULL, KEY_TRUE,
     143                 :            :         KEY_FALSE, KEY_IS, KEY_BETWEEN, KEY_OR,
     144                 :            :         KEY_AND, KEY_AVG, KEY_COUNT, KEY_MAX,
     145                 :            :         KEY_MIN, KEY_SUM, KEY_EVERY,
     146                 :            :         KEY_ANY, KEY_SOME, KEY_STDDEV_POP,
     147                 :            :         KEY_STDDEV_SAMP, KEY_VAR_SAMP, KEY_VAR_POP,
     148                 :            :         KEY_COLLECT, KEY_FUSION, KEY_INTERSECTION
     149                 :            :     };
     150                 :            : 
     151                 :          0 :     sal_uInt32 nCount = sizeof Intl_TokenID / sizeof Intl_TokenID[0];
     152         [ #  # ]:          0 :     for (sal_uInt32 i = 0; i < nCount; i++)
     153                 :            :     {
     154         [ #  # ]:          0 :         ::rtl::OString aKey = getIntlKeywordAscii(Intl_TokenID[i]);
     155         [ #  # ]:          0 :         if (rToken.equalsIgnoreAsciiCase(aKey))
     156                 :          0 :             return Intl_TokenID[i];
     157         [ #  # ]:          0 :     }
     158                 :            : 
     159                 :          0 :     return KEY_NONE;
     160                 :            : }
     161                 :            : 
     162                 :            : 
     163                 :            : // =============================================================================
     164                 :            : // =============================================================================
     165                 :            : namespace
     166                 :            : {
     167                 :            :     // -----------------------------------------------------------------------------
     168                 :         37 :     ::osl::Mutex& getSafteyMutex()
     169                 :            :     {
     170 [ +  + ][ +  - ]:         37 :         static ::osl::Mutex s_aSafety;
         [ +  - ][ #  # ]
     171                 :         37 :         return s_aSafety;
     172                 :            :     }
     173                 :            :     // -----------------------------------------------------------------------------
     174                 :         37 :     oslInterlockedCount& getCounter()
     175                 :            :     {
     176                 :            :         static oslInterlockedCount s_nCounter;
     177                 :         37 :         return s_nCounter;
     178                 :            :     }
     179                 :            :     // -----------------------------------------------------------------------------
     180                 :         31 :     OSystemParseContext* getSharedContext(OSystemParseContext* _pContext = NULL,sal_Bool _bSet = sal_False)
     181                 :            :     {
     182                 :            :         static OSystemParseContext* s_pSharedContext = NULL;
     183 [ +  + ][ +  - ]:         31 :         if ( _pContext && !s_pSharedContext )
     184                 :            :         {
     185                 :         17 :             s_pSharedContext = _pContext;
     186                 :         17 :             return s_pSharedContext;
     187                 :            :         }
     188         [ +  - ]:         14 :         if ( _bSet )
     189                 :            :         {
     190         [ -  + ]:         14 :             OSystemParseContext* pReturn = _pContext ? _pContext : s_pSharedContext;
     191                 :         14 :             s_pSharedContext = _pContext;
     192                 :         14 :             return pReturn;
     193                 :            :         }
     194                 :         31 :         return s_pSharedContext;
     195                 :            :     }
     196                 :            :     // -----------------------------------------------------------------------------
     197                 :            : }
     198                 :            : // -----------------------------------------------------------------------------
     199                 :         20 : OParseContextClient::OParseContextClient()
     200                 :            : {
     201 [ +  - ][ +  - ]:         20 :     ::osl::MutexGuard aGuard( getSafteyMutex() );
     202 [ +  - ][ +  + ]:         20 :     if ( 1 == osl_incrementInterlockedCount( &getCounter() ) )
     203                 :            :     {   // first instance
     204 [ +  - ][ +  - ]:         17 :         getSharedContext( new OSystemParseContext );
     205         [ +  - ]:         20 :     }
     206                 :         20 : }
     207                 :            : 
     208                 :            : // -----------------------------------------------------------------------------
     209                 :         17 : OParseContextClient::~OParseContextClient()
     210                 :            : {
     211                 :            :     {
     212 [ +  - ][ +  - ]:         17 :         ::osl::MutexGuard aGuard( getSafteyMutex() );
     213 [ +  - ][ +  + ]:         17 :         if ( 0 == osl_decrementInterlockedCount( &getCounter() ) )
     214 [ +  - ][ +  - ]:         17 :             delete getSharedContext(NULL,sal_True);
                 [ +  - ]
     215                 :            :     }
     216         [ -  + ]:         17 : }
     217                 :            : // -----------------------------------------------------------------------------
     218                 :          0 : const OSystemParseContext* OParseContextClient::getParseContext() const
     219                 :            : {
     220                 :          0 :     return getSharedContext();
     221                 :            : }
     222                 :            : // -----------------------------------------------------------------------------
     223                 :            : 
     224                 :            : 
     225                 :            : 
     226                 :            : 
     227                 :            : 
     228                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10