LCOV - code coverage report
Current view: top level - svx/source/form - ParseContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 79 95 83.2 %
Date: 2014-11-03 Functions: 14 16 87.5 %
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             : 
      20             : 
      21             : #include <sal/macros.h>
      22             : #include "svx/ParseContext.hxx"
      23             : #include "stringlistresource.hxx"
      24             : #include "svx/fmresids.hrc"
      25             : 
      26             : #include <svx/dialmgr.hxx>
      27             : 
      28             : #include <unotools/syslocale.hxx>
      29             : #include <vcl/svapp.hxx>
      30             : #include <osl/mutex.hxx>
      31             : 
      32             : using namespace svxform;
      33             : using namespace ::connectivity;
      34             : 
      35         224 : OSystemParseContext::OSystemParseContext() : IParseContext()
      36             : {
      37         224 :     SolarMutexGuard aGuard;
      38             : 
      39         448 :     ::svx::StringListResource aKeywords( SVX_RES( RID_RSC_SQL_INTERNATIONAL ) );
      40         448 :     aKeywords.get( m_aLocalizedKeywords );
      41         224 : }
      42             : 
      43             : 
      44         366 : OSystemParseContext::~OSystemParseContext()
      45             : {
      46         366 : }
      47             : 
      48             : 
      49         240 : ::com::sun::star::lang::Locale OSystemParseContext::getPreferredLocale( ) const
      50             : {
      51         240 :     return SvtSysLocale().GetLanguageTag().getLocale();
      52             : }
      53             : 
      54             : 
      55          48 : OUString OSystemParseContext::getErrorMessage(ErrorCode _eCode) const
      56             : {
      57          48 :     OUString aMsg;
      58          96 :     SolarMutexGuard aGuard;
      59          48 :     switch (_eCode)
      60             :     {
      61           4 :         case ERROR_GENERAL:                 aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_ERROR); break;
      62           0 :         case ERROR_VALUE_NO_LIKE:           aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_VALUE_NO_LIKE); break;
      63           0 :         case ERROR_FIELD_NO_LIKE:           aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_FIELD_NO_LIKE); break;
      64           0 :         case ERROR_INVALID_COMPARE:         aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_CRIT_NO_COMPARE); break;
      65           0 :         case ERROR_INVALID_INT_COMPARE:     aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_INT_NO_VALID); break;
      66           0 :         case ERROR_INVALID_DATE_COMPARE:    aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_ACCESS_DAT_NO_VALID); break;
      67           0 :         case ERROR_INVALID_REAL_COMPARE:    aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_REAL_NO_VALID); break;
      68          44 :         case ERROR_INVALID_TABLE_NOSUCH:    aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_TABLE); break;
      69           0 :         case ERROR_INVALID_TABLE_OR_QUERY:  aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_TABLE_OR_QUERY); break;
      70           0 :         case ERROR_INVALID_COLUMN:          aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_COLUMN); break;
      71           0 :         case ERROR_INVALID_TABLE_EXIST:     aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_TABLE_EXISTS); break;
      72           0 :         case ERROR_INVALID_QUERY_EXIST:     aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_QUERY_EXISTS); break;
      73           0 :         case ERROR_NONE: break;
      74             :     }
      75          96 :     return aMsg;
      76             : }
      77             : 
      78             : 
      79         864 : OString OSystemParseContext::getIntlKeywordAscii(InternationalKeyCode _eKey) const
      80             : {
      81         864 :     size_t nIndex = 0;
      82         864 :     switch ( _eKey )
      83             :     {
      84          36 :         case KEY_LIKE:      nIndex = 0; break;
      85          36 :         case KEY_NOT:       nIndex = 1; break;
      86          36 :         case KEY_NULL:      nIndex = 2; break;
      87          36 :         case KEY_TRUE:      nIndex = 3; break;
      88          36 :         case KEY_FALSE:     nIndex = 4; break;
      89          36 :         case KEY_IS:        nIndex = 5; break;
      90          36 :         case KEY_BETWEEN:   nIndex = 6; break;
      91          36 :         case KEY_OR:        nIndex = 7; break;
      92          36 :         case KEY_AND:       nIndex = 8; break;
      93          36 :         case KEY_AVG:       nIndex = 9; break;
      94          36 :         case KEY_COUNT:     nIndex = 10; break;
      95          36 :         case KEY_MAX:       nIndex = 11; break;
      96          36 :         case KEY_MIN:       nIndex = 12; break;
      97          36 :         case KEY_SUM:       nIndex = 13; break;
      98          36 :         case KEY_EVERY:     nIndex = 14; break;
      99          36 :         case KEY_ANY:       nIndex = 15; break;
     100          36 :         case KEY_SOME:      nIndex = 16; break;
     101          36 :         case KEY_STDDEV_POP: nIndex = 17; break;
     102          36 :         case KEY_STDDEV_SAMP: nIndex = 18; break;
     103          36 :         case KEY_VAR_SAMP:  nIndex = 19; break;
     104          36 :         case KEY_VAR_POP:   nIndex = 20; break;
     105          36 :         case KEY_COLLECT:   nIndex = 21; break;
     106          36 :         case KEY_FUSION:    nIndex = 22; break;
     107          36 :         case KEY_INTERSECTION: nIndex = 23; break;
     108             :         case KEY_NONE:
     109             :             OSL_FAIL( "OSystemParseContext::getIntlKeywordAscii: illegal argument!" );
     110           0 :             break;
     111             :     }
     112             : 
     113             :     OSL_ENSURE( nIndex < m_aLocalizedKeywords.size(), "OSystemParseContext::getIntlKeywordAscii: invalid index!" );
     114             : 
     115         864 :     OString sKeyword;
     116         864 :     if ( nIndex < m_aLocalizedKeywords.size() )
     117         864 :         sKeyword = OUStringToOString(m_aLocalizedKeywords[nIndex], RTL_TEXTENCODING_UTF8);
     118         864 :     return sKeyword;
     119             : }
     120             : 
     121             : 
     122          36 : IParseContext::InternationalKeyCode OSystemParseContext::getIntlKeyCode(const OString& rToken) const
     123             : {
     124             :     static const IParseContext::InternationalKeyCode Intl_TokenID[] =
     125             :     {
     126             :         KEY_LIKE, KEY_NOT, KEY_NULL, KEY_TRUE,
     127             :         KEY_FALSE, KEY_IS, KEY_BETWEEN, KEY_OR,
     128             :         KEY_AND, KEY_AVG, KEY_COUNT, KEY_MAX,
     129             :         KEY_MIN, KEY_SUM, KEY_EVERY,
     130             :         KEY_ANY, KEY_SOME, KEY_STDDEV_POP,
     131             :         KEY_STDDEV_SAMP, KEY_VAR_SAMP, KEY_VAR_POP,
     132             :         KEY_COLLECT, KEY_FUSION, KEY_INTERSECTION
     133             :     };
     134             : 
     135          36 :     sal_uInt32 nCount = sizeof Intl_TokenID / sizeof Intl_TokenID[0];
     136         900 :     for (sal_uInt32 i = 0; i < nCount; i++)
     137             :     {
     138         864 :         OString aKey = getIntlKeywordAscii(Intl_TokenID[i]);
     139         864 :         if (rToken.equalsIgnoreAsciiCase(aKey))
     140           0 :             return Intl_TokenID[i];
     141         864 :     }
     142             : 
     143          36 :     return KEY_NONE;
     144             : }
     145             : 
     146             : 
     147             : 
     148             : 
     149             : namespace
     150             : {
     151             : 
     152         296 :     ::osl::Mutex& getSafteyMutex()
     153             :     {
     154         296 :         static ::osl::Mutex s_aSafety;
     155         296 :         return s_aSafety;
     156             :     }
     157             : 
     158         296 :     oslInterlockedCount& getCounter()
     159             :     {
     160             :         static oslInterlockedCount s_nCounter;
     161         296 :         return s_nCounter;
     162             :     }
     163             : 
     164         284 :     OSystemParseContext* getSharedContext(OSystemParseContext* _pContext = NULL,bool _bSet = false)
     165             :     {
     166             :         static OSystemParseContext* s_pSharedContext = NULL;
     167         284 :         if ( _pContext && !s_pSharedContext )
     168             :         {
     169         142 :             s_pSharedContext = _pContext;
     170         142 :             return s_pSharedContext;
     171             :         }
     172         142 :         if ( _bSet )
     173             :         {
     174         142 :             OSystemParseContext* pReturn = _pContext ? _pContext : s_pSharedContext;
     175         142 :             s_pSharedContext = _pContext;
     176         142 :             return pReturn;
     177             :         }
     178           0 :         return s_pSharedContext;
     179             :     }
     180             : 
     181             : }
     182             : 
     183         148 : OParseContextClient::OParseContextClient()
     184             : {
     185         148 :     ::osl::MutexGuard aGuard( getSafteyMutex() );
     186         148 :     if ( 1 == osl_atomic_increment( &getCounter() ) )
     187             :     {   // first instance
     188         142 :         getSharedContext( new OSystemParseContext );
     189         148 :     }
     190         148 : }
     191             : 
     192             : 
     193         148 : OParseContextClient::~OParseContextClient()
     194             : {
     195             :     {
     196         148 :         ::osl::MutexGuard aGuard( getSafteyMutex() );
     197         148 :         if ( 0 == osl_atomic_decrement( &getCounter() ) )
     198         142 :             delete getSharedContext(NULL,true);
     199             :     }
     200         148 : }
     201             : 
     202           0 : const OSystemParseContext* OParseContextClient::getParseContext() const
     203             : {
     204           0 :     return getSharedContext();
     205         651 : }
     206             : 
     207             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10