1*f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f6e50924SAndrew Rist * distributed with this work for additional information 6*f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9*f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10*f6e50924SAndrew Rist * 11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*f6e50924SAndrew Rist * 13*f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f6e50924SAndrew Rist * software distributed under the License is distributed on an 15*f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17*f6e50924SAndrew Rist * specific language governing permissions and limitations 18*f6e50924SAndrew Rist * under the License. 19*f6e50924SAndrew Rist * 20*f6e50924SAndrew Rist *************************************************************/ 21*f6e50924SAndrew Rist 22*f6e50924SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svx.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "svx/ParseContext.hxx" 28cdf0e10cSrcweir #include "stringlistresource.hxx" 29cdf0e10cSrcweir #include "svx/fmresids.hrc" 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <svx/dialmgr.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <unotools/syslocale.hxx> 34cdf0e10cSrcweir #include <vcl/svapp.hxx> 35cdf0e10cSrcweir #include <tools/debug.hxx> 36cdf0e10cSrcweir #include <vos/mutex.hxx> 37cdf0e10cSrcweir 38cdf0e10cSrcweir using namespace svxform; 39cdf0e10cSrcweir using namespace ::connectivity; 40cdf0e10cSrcweir //========================================================================== 41cdf0e10cSrcweir //= OSystemParseContext 42cdf0e10cSrcweir //========================================================================== 43cdf0e10cSrcweir DBG_NAME(OSystemParseContext) 44cdf0e10cSrcweir //----------------------------------------------------------------------------- 45cdf0e10cSrcweir OSystemParseContext::OSystemParseContext() : IParseContext() 46cdf0e10cSrcweir { 47cdf0e10cSrcweir DBG_CTOR(OSystemParseContext,NULL); 48cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 49cdf0e10cSrcweir 50cdf0e10cSrcweir ::svx::StringListResource aKeywords( SVX_RES( RID_RSC_SQL_INTERNATIONAL ) ); 51cdf0e10cSrcweir aKeywords.get( m_aLocalizedKeywords ); 52cdf0e10cSrcweir } 53cdf0e10cSrcweir 54cdf0e10cSrcweir //----------------------------------------------------------------------------- 55cdf0e10cSrcweir OSystemParseContext::~OSystemParseContext() 56cdf0e10cSrcweir { 57cdf0e10cSrcweir DBG_DTOR(OSystemParseContext,NULL); 58cdf0e10cSrcweir } 59cdf0e10cSrcweir 60cdf0e10cSrcweir //----------------------------------------------------------------------------- 61cdf0e10cSrcweir ::com::sun::star::lang::Locale OSystemParseContext::getPreferredLocale( ) const 62cdf0e10cSrcweir { 63cdf0e10cSrcweir return SvtSysLocale().GetLocaleData().getLocale(); 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir //----------------------------------------------------------------------------- 67cdf0e10cSrcweir ::rtl::OUString OSystemParseContext::getErrorMessage(ErrorCode _eCode) const 68cdf0e10cSrcweir { 69cdf0e10cSrcweir String aMsg; 70cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 71cdf0e10cSrcweir switch (_eCode) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir case ERROR_GENERAL: aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_ERROR); break; 74cdf0e10cSrcweir case ERROR_VALUE_NO_LIKE: aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_VALUE_NO_LIKE); break; 75cdf0e10cSrcweir case ERROR_FIELD_NO_LIKE: aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_FIELD_NO_LIKE); break; 76cdf0e10cSrcweir case ERROR_INVALID_COMPARE: aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_CRIT_NO_COMPARE); break; 77cdf0e10cSrcweir case ERROR_INVALID_INT_COMPARE: aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_INT_NO_VALID); break; 78cdf0e10cSrcweir case ERROR_INVALID_DATE_COMPARE: aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_ACCESS_DAT_NO_VALID); break; 79cdf0e10cSrcweir case ERROR_INVALID_REAL_COMPARE: aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_REAL_NO_VALID); break; 80cdf0e10cSrcweir case ERROR_INVALID_TABLE: aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_TABLE); break; 81cdf0e10cSrcweir case ERROR_INVALID_TABLE_OR_QUERY: aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_TABLE_OR_QUERY); break; 82cdf0e10cSrcweir case ERROR_INVALID_COLUMN: aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_COLUMN); break; 83cdf0e10cSrcweir case ERROR_INVALID_TABLE_EXIST: aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_TABLE_EXISTS); break; 84cdf0e10cSrcweir case ERROR_INVALID_QUERY_EXIST: aMsg = SVX_RES(RID_STR_SVT_SQL_SYNTAX_QUERY_EXISTS); break; 85cdf0e10cSrcweir case ERROR_NONE: break; 86cdf0e10cSrcweir } 87cdf0e10cSrcweir return aMsg; 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir //----------------------------------------------------------------------------- 91cdf0e10cSrcweir ::rtl::OString OSystemParseContext::getIntlKeywordAscii(InternationalKeyCode _eKey) const 92cdf0e10cSrcweir { 93cdf0e10cSrcweir size_t nIndex = 0; 94cdf0e10cSrcweir switch ( _eKey ) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir case KEY_LIKE: nIndex = 0; break; 97cdf0e10cSrcweir case KEY_NOT: nIndex = 1; break; 98cdf0e10cSrcweir case KEY_NULL: nIndex = 2; break; 99cdf0e10cSrcweir case KEY_TRUE: nIndex = 3; break; 100cdf0e10cSrcweir case KEY_FALSE: nIndex = 4; break; 101cdf0e10cSrcweir case KEY_IS: nIndex = 5; break; 102cdf0e10cSrcweir case KEY_BETWEEN: nIndex = 6; break; 103cdf0e10cSrcweir case KEY_OR: nIndex = 7; break; 104cdf0e10cSrcweir case KEY_AND: nIndex = 8; break; 105cdf0e10cSrcweir case KEY_AVG: nIndex = 9; break; 106cdf0e10cSrcweir case KEY_COUNT: nIndex = 10; break; 107cdf0e10cSrcweir case KEY_MAX: nIndex = 11; break; 108cdf0e10cSrcweir case KEY_MIN: nIndex = 12; break; 109cdf0e10cSrcweir case KEY_SUM: nIndex = 13; break; 110cdf0e10cSrcweir case KEY_EVERY: nIndex = 14; break; 111cdf0e10cSrcweir case KEY_ANY: nIndex = 15; break; 112cdf0e10cSrcweir case KEY_SOME: nIndex = 16; break; 113cdf0e10cSrcweir case KEY_STDDEV_POP: nIndex = 17; break; 114cdf0e10cSrcweir case KEY_STDDEV_SAMP: nIndex = 18; break; 115cdf0e10cSrcweir case KEY_VAR_SAMP: nIndex = 19; break; 116cdf0e10cSrcweir case KEY_VAR_POP: nIndex = 20; break; 117cdf0e10cSrcweir case KEY_COLLECT: nIndex = 21; break; 118cdf0e10cSrcweir case KEY_FUSION: nIndex = 22; break; 119cdf0e10cSrcweir case KEY_INTERSECTION: nIndex = 23; break; 120cdf0e10cSrcweir case KEY_NONE: 121cdf0e10cSrcweir DBG_ERROR( "OSystemParseContext::getIntlKeywordAscii: illegal argument!" ); 122cdf0e10cSrcweir break; 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir OSL_ENSURE( nIndex < m_aLocalizedKeywords.size(), "OSystemParseContext::getIntlKeywordAscii: invalid index!" ); 126cdf0e10cSrcweir 127cdf0e10cSrcweir ByteString sKeyword; 128cdf0e10cSrcweir if ( nIndex < m_aLocalizedKeywords.size() ) 129cdf0e10cSrcweir sKeyword = ByteString( m_aLocalizedKeywords[nIndex], RTL_TEXTENCODING_UTF8 ); 130cdf0e10cSrcweir return sKeyword; 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir //----------------------------------------------------------------------------- 134cdf0e10cSrcweir static sal_Unicode lcl_getSeparatorChar( const String& _rSeparator, sal_Unicode _nFallback ) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir DBG_ASSERT( 0 < _rSeparator.Len(), "::lcl_getSeparatorChar: invalid decimal separator!" ); 137cdf0e10cSrcweir 138cdf0e10cSrcweir sal_Unicode nReturn( _nFallback ); 139cdf0e10cSrcweir if ( _rSeparator.Len() ) 140cdf0e10cSrcweir nReturn = static_cast< sal_Char >( _rSeparator.GetBuffer( )[0] ); 141cdf0e10cSrcweir return nReturn; 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144cdf0e10cSrcweir //----------------------------------------------------------------------------- 145cdf0e10cSrcweir sal_Unicode OSystemParseContext::getNumDecimalSep( ) const 146cdf0e10cSrcweir { 147cdf0e10cSrcweir return lcl_getSeparatorChar( SvtSysLocale().GetLocaleData().getNumDecimalSep(), '.' ); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir //----------------------------------------------------------------------------- 151cdf0e10cSrcweir sal_Unicode OSystemParseContext::getNumThousandSep( ) const 152cdf0e10cSrcweir { 153cdf0e10cSrcweir return lcl_getSeparatorChar( SvtSysLocale().GetLocaleData().getNumThousandSep(), ',' ); 154cdf0e10cSrcweir } 155cdf0e10cSrcweir // ----------------------------------------------------------------------------- 156cdf0e10cSrcweir IParseContext::InternationalKeyCode OSystemParseContext::getIntlKeyCode(const ::rtl::OString& rToken) const 157cdf0e10cSrcweir { 158cdf0e10cSrcweir static IParseContext::InternationalKeyCode Intl_TokenID[] = 159cdf0e10cSrcweir { 160cdf0e10cSrcweir KEY_LIKE, KEY_NOT, KEY_NULL, KEY_TRUE, 161cdf0e10cSrcweir KEY_FALSE, KEY_IS, KEY_BETWEEN, KEY_OR, 162cdf0e10cSrcweir KEY_AND, KEY_AVG, KEY_COUNT, KEY_MAX, 163cdf0e10cSrcweir KEY_MIN, KEY_SUM, KEY_EVERY, 164cdf0e10cSrcweir KEY_ANY, KEY_SOME, KEY_STDDEV_POP, 165cdf0e10cSrcweir KEY_STDDEV_SAMP, KEY_VAR_SAMP, KEY_VAR_POP, 166cdf0e10cSrcweir KEY_COLLECT, KEY_FUSION, KEY_INTERSECTION 167cdf0e10cSrcweir }; 168cdf0e10cSrcweir 169cdf0e10cSrcweir sal_uInt32 nCount = sizeof Intl_TokenID / sizeof Intl_TokenID[0]; 170cdf0e10cSrcweir for (sal_uInt32 i = 0; i < nCount; i++) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir ::rtl::OString aKey = getIntlKeywordAscii(Intl_TokenID[i]); 173cdf0e10cSrcweir if (rToken.equalsIgnoreAsciiCase(aKey)) 174cdf0e10cSrcweir return Intl_TokenID[i]; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir return KEY_NONE; 178cdf0e10cSrcweir } 179cdf0e10cSrcweir 180cdf0e10cSrcweir 181cdf0e10cSrcweir // ============================================================================= 182cdf0e10cSrcweir // ============================================================================= 183cdf0e10cSrcweir namespace 184cdf0e10cSrcweir { 185cdf0e10cSrcweir // ----------------------------------------------------------------------------- 186cdf0e10cSrcweir ::osl::Mutex& getSafteyMutex() 187cdf0e10cSrcweir { 188cdf0e10cSrcweir static ::osl::Mutex s_aSafety; 189cdf0e10cSrcweir return s_aSafety; 190cdf0e10cSrcweir } 191cdf0e10cSrcweir // ----------------------------------------------------------------------------- 192cdf0e10cSrcweir oslInterlockedCount& getCounter() 193cdf0e10cSrcweir { 194cdf0e10cSrcweir static oslInterlockedCount s_nCounter; 195cdf0e10cSrcweir return s_nCounter; 196cdf0e10cSrcweir } 197cdf0e10cSrcweir // ----------------------------------------------------------------------------- 198cdf0e10cSrcweir OSystemParseContext* getSharedContext(OSystemParseContext* _pContext = NULL,sal_Bool _bSet = sal_False) 199cdf0e10cSrcweir { 200cdf0e10cSrcweir static OSystemParseContext* s_pSharedContext = NULL; 201cdf0e10cSrcweir if ( _pContext && !s_pSharedContext ) 202cdf0e10cSrcweir { 203cdf0e10cSrcweir s_pSharedContext = _pContext; 204cdf0e10cSrcweir return s_pSharedContext; 205cdf0e10cSrcweir } 206cdf0e10cSrcweir if ( _bSet ) 207cdf0e10cSrcweir { 208cdf0e10cSrcweir OSystemParseContext* pReturn = _pContext ? _pContext : s_pSharedContext; 209cdf0e10cSrcweir s_pSharedContext = _pContext; 210cdf0e10cSrcweir return pReturn; 211cdf0e10cSrcweir } 212cdf0e10cSrcweir return s_pSharedContext; 213cdf0e10cSrcweir } 214cdf0e10cSrcweir // ----------------------------------------------------------------------------- 215cdf0e10cSrcweir } 216cdf0e10cSrcweir // ----------------------------------------------------------------------------- 217cdf0e10cSrcweir OParseContextClient::OParseContextClient() 218cdf0e10cSrcweir { 219cdf0e10cSrcweir ::osl::MutexGuard aGuard( getSafteyMutex() ); 220cdf0e10cSrcweir if ( 1 == osl_incrementInterlockedCount( &getCounter() ) ) 221cdf0e10cSrcweir { // first instance 222cdf0e10cSrcweir getSharedContext( new OSystemParseContext ); 223cdf0e10cSrcweir } 224cdf0e10cSrcweir } 225cdf0e10cSrcweir 226cdf0e10cSrcweir // ----------------------------------------------------------------------------- 227cdf0e10cSrcweir OParseContextClient::~OParseContextClient() 228cdf0e10cSrcweir { 229cdf0e10cSrcweir { 230cdf0e10cSrcweir ::osl::MutexGuard aGuard( getSafteyMutex() ); 231cdf0e10cSrcweir if ( 0 == osl_decrementInterlockedCount( &getCounter() ) ) 232cdf0e10cSrcweir delete getSharedContext(NULL,sal_True); 233cdf0e10cSrcweir } 234cdf0e10cSrcweir } 235cdf0e10cSrcweir // ----------------------------------------------------------------------------- 236cdf0e10cSrcweir const OSystemParseContext* OParseContextClient::getParseContext() const 237cdf0e10cSrcweir { 238cdf0e10cSrcweir return getSharedContext(); 239cdf0e10cSrcweir } 240cdf0e10cSrcweir // ----------------------------------------------------------------------------- 241cdf0e10cSrcweir 242cdf0e10cSrcweir 243cdf0e10cSrcweir 244cdf0e10cSrcweir 245cdf0e10cSrcweir 246