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

Generated by: LCOV version 1.10