LCOV - code coverage report
Current view: top level - svx/source/form - ParseContext.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 94 0.0 %
Date: 2014-04-14 Functions: 0 14 0.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             : 
      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           0 : OSystemParseContext::OSystemParseContext() : IParseContext()
      40             : {
      41           0 :     SolarMutexGuard aGuard;
      42             : 
      43           0 :     ::svx::StringListResource aKeywords( SVX_RES( RID_RSC_SQL_INTERNATIONAL ) );
      44           0 :     aKeywords.get( m_aLocalizedKeywords );
      45           0 : }
      46             : 
      47             : 
      48           0 : OSystemParseContext::~OSystemParseContext()
      49             : {
      50           0 : }
      51             : 
      52             : 
      53           0 : ::com::sun::star::lang::Locale OSystemParseContext::getPreferredLocale( ) const
      54             : {
      55           0 :     return SvtSysLocale().GetLanguageTag().getLocale();
      56             : }
      57             : 
      58             : 
      59           0 : OUString OSystemParseContext::getErrorMessage(ErrorCode _eCode) const
      60             : {
      61           0 :     OUString aMsg;
      62           0 :     SolarMutexGuard aGuard;
      63           0 :     switch (_eCode)
      64             :     {
      65           0 :         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           0 :         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           0 :     return aMsg;
      80             : }
      81             : 
      82             : 
      83           0 : OString OSystemParseContext::getIntlKeywordAscii(InternationalKeyCode _eKey) const
      84             : {
      85           0 :     size_t nIndex = 0;
      86           0 :     switch ( _eKey )
      87             :     {
      88           0 :         case KEY_LIKE:      nIndex = 0; break;
      89           0 :         case KEY_NOT:       nIndex = 1; break;
      90           0 :         case KEY_NULL:      nIndex = 2; break;
      91           0 :         case KEY_TRUE:      nIndex = 3; break;
      92           0 :         case KEY_FALSE:     nIndex = 4; break;
      93           0 :         case KEY_IS:        nIndex = 5; break;
      94           0 :         case KEY_BETWEEN:   nIndex = 6; break;
      95           0 :         case KEY_OR:        nIndex = 7; break;
      96           0 :         case KEY_AND:       nIndex = 8; break;
      97           0 :         case KEY_AVG:       nIndex = 9; break;
      98           0 :         case KEY_COUNT:     nIndex = 10; break;
      99           0 :         case KEY_MAX:       nIndex = 11; break;
     100           0 :         case KEY_MIN:       nIndex = 12; break;
     101           0 :         case KEY_SUM:       nIndex = 13; break;
     102           0 :         case KEY_EVERY:     nIndex = 14; break;
     103           0 :         case KEY_ANY:       nIndex = 15; break;
     104           0 :         case KEY_SOME:      nIndex = 16; break;
     105           0 :         case KEY_STDDEV_POP: nIndex = 17; break;
     106           0 :         case KEY_STDDEV_SAMP: nIndex = 18; break;
     107           0 :         case KEY_VAR_SAMP:  nIndex = 19; break;
     108           0 :         case KEY_VAR_POP:   nIndex = 20; break;
     109           0 :         case KEY_COLLECT:   nIndex = 21; break;
     110           0 :         case KEY_FUSION:    nIndex = 22; break;
     111           0 :         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           0 :     OString sKeyword;
     120           0 :     if ( nIndex < m_aLocalizedKeywords.size() )
     121           0 :         sKeyword = OUStringToOString(m_aLocalizedKeywords[nIndex], RTL_TEXTENCODING_UTF8);
     122           0 :     return sKeyword;
     123             : }
     124             : 
     125             : 
     126           0 : 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           0 :     sal_uInt32 nCount = sizeof Intl_TokenID / sizeof Intl_TokenID[0];
     140           0 :     for (sal_uInt32 i = 0; i < nCount; i++)
     141             :     {
     142           0 :         OString aKey = getIntlKeywordAscii(Intl_TokenID[i]);
     143           0 :         if (rToken.equalsIgnoreAsciiCase(aKey))
     144           0 :             return Intl_TokenID[i];
     145           0 :     }
     146             : 
     147           0 :     return KEY_NONE;
     148             : }
     149             : 
     150             : 
     151             : 
     152             : 
     153             : namespace
     154             : {
     155             : 
     156           0 :     ::osl::Mutex& getSafteyMutex()
     157             :     {
     158           0 :         static ::osl::Mutex s_aSafety;
     159           0 :         return s_aSafety;
     160             :     }
     161             : 
     162           0 :     oslInterlockedCount& getCounter()
     163             :     {
     164             :         static oslInterlockedCount s_nCounter;
     165           0 :         return s_nCounter;
     166             :     }
     167             : 
     168           0 :     OSystemParseContext* getSharedContext(OSystemParseContext* _pContext = NULL,sal_Bool _bSet = sal_False)
     169             :     {
     170             :         static OSystemParseContext* s_pSharedContext = NULL;
     171           0 :         if ( _pContext && !s_pSharedContext )
     172             :         {
     173           0 :             s_pSharedContext = _pContext;
     174           0 :             return s_pSharedContext;
     175             :         }
     176           0 :         if ( _bSet )
     177             :         {
     178           0 :             OSystemParseContext* pReturn = _pContext ? _pContext : s_pSharedContext;
     179           0 :             s_pSharedContext = _pContext;
     180           0 :             return pReturn;
     181             :         }
     182           0 :         return s_pSharedContext;
     183             :     }
     184             : 
     185             : }
     186             : 
     187           0 : OParseContextClient::OParseContextClient()
     188             : {
     189           0 :     ::osl::MutexGuard aGuard( getSafteyMutex() );
     190           0 :     if ( 1 == osl_atomic_increment( &getCounter() ) )
     191             :     {   // first instance
     192           0 :         getSharedContext( new OSystemParseContext );
     193           0 :     }
     194           0 : }
     195             : 
     196             : 
     197           0 : OParseContextClient::~OParseContextClient()
     198             : {
     199             :     {
     200           0 :         ::osl::MutexGuard aGuard( getSafteyMutex() );
     201           0 :         if ( 0 == osl_atomic_decrement( &getCounter() ) )
     202           0 :             delete getSharedContext(NULL,sal_True);
     203             :     }
     204           0 : }
     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