1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
30 #include <sal/macros.h>
31 #include "svx/ParseContext.hxx"
32 #include "stringlistresource.hxx"
33 #include "svx/fmresids.hrc"
35 #include <svx/dialmgr.hxx>
37 #include <unotools/syslocale.hxx>
38 #include <vcl/svapp.hxx>
39 #include <tools/debug.hxx>
40 #include <osl/mutex.hxx>
42 using namespace svxform
;
43 using namespace ::connectivity
;
44 //==========================================================================
45 //= OSystemParseContext
46 //==========================================================================
47 DBG_NAME(OSystemParseContext
)
48 //-----------------------------------------------------------------------------
49 OSystemParseContext::OSystemParseContext() : IParseContext()
51 DBG_CTOR(OSystemParseContext
,NULL
);
52 SolarMutexGuard aGuard
;
54 ::svx::StringListResource
aKeywords( SVX_RES( RID_RSC_SQL_INTERNATIONAL
) );
55 aKeywords
.get( m_aLocalizedKeywords
);
58 //-----------------------------------------------------------------------------
59 OSystemParseContext::~OSystemParseContext()
61 DBG_DTOR(OSystemParseContext
,NULL
);
64 //-----------------------------------------------------------------------------
65 ::com::sun::star::lang::Locale
OSystemParseContext::getPreferredLocale( ) const
67 return SvtSysLocale().GetLocaleData().getLocale();
70 //-----------------------------------------------------------------------------
71 ::rtl::OUString
OSystemParseContext::getErrorMessage(ErrorCode _eCode
) const
74 SolarMutexGuard aGuard
;
77 case ERROR_GENERAL
: aMsg
= SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_ERROR
); break;
78 case ERROR_VALUE_NO_LIKE
: aMsg
= SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_VALUE_NO_LIKE
); break;
79 case ERROR_FIELD_NO_LIKE
: aMsg
= SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_FIELD_NO_LIKE
); break;
80 case ERROR_INVALID_COMPARE
: aMsg
= SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_CRIT_NO_COMPARE
); break;
81 case ERROR_INVALID_INT_COMPARE
: aMsg
= SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_INT_NO_VALID
); break;
82 case ERROR_INVALID_DATE_COMPARE
: aMsg
= SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_ACCESS_DAT_NO_VALID
); break;
83 case ERROR_INVALID_REAL_COMPARE
: aMsg
= SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_REAL_NO_VALID
); break;
84 case ERROR_INVALID_TABLE
: aMsg
= SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_TABLE
); break;
85 case ERROR_INVALID_TABLE_OR_QUERY
: aMsg
= SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_TABLE_OR_QUERY
); break;
86 case ERROR_INVALID_COLUMN
: aMsg
= SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_COLUMN
); break;
87 case ERROR_INVALID_TABLE_EXIST
: aMsg
= SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_TABLE_EXISTS
); break;
88 case ERROR_INVALID_QUERY_EXIST
: aMsg
= SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_QUERY_EXISTS
); break;
89 case ERROR_NONE
: break;
94 //-----------------------------------------------------------------------------
95 ::rtl::OString
OSystemParseContext::getIntlKeywordAscii(InternationalKeyCode _eKey
) const
100 case KEY_LIKE
: nIndex
= 0; break;
101 case KEY_NOT
: nIndex
= 1; break;
102 case KEY_NULL
: nIndex
= 2; break;
103 case KEY_TRUE
: nIndex
= 3; break;
104 case KEY_FALSE
: nIndex
= 4; break;
105 case KEY_IS
: nIndex
= 5; break;
106 case KEY_BETWEEN
: nIndex
= 6; break;
107 case KEY_OR
: nIndex
= 7; break;
108 case KEY_AND
: nIndex
= 8; break;
109 case KEY_AVG
: nIndex
= 9; break;
110 case KEY_COUNT
: nIndex
= 10; break;
111 case KEY_MAX
: nIndex
= 11; break;
112 case KEY_MIN
: nIndex
= 12; break;
113 case KEY_SUM
: nIndex
= 13; break;
114 case KEY_EVERY
: nIndex
= 14; break;
115 case KEY_ANY
: nIndex
= 15; break;
116 case KEY_SOME
: nIndex
= 16; break;
117 case KEY_STDDEV_POP
: nIndex
= 17; break;
118 case KEY_STDDEV_SAMP
: nIndex
= 18; break;
119 case KEY_VAR_SAMP
: nIndex
= 19; break;
120 case KEY_VAR_POP
: nIndex
= 20; break;
121 case KEY_COLLECT
: nIndex
= 21; break;
122 case KEY_FUSION
: nIndex
= 22; break;
123 case KEY_INTERSECTION
: nIndex
= 23; break;
125 OSL_FAIL( "OSystemParseContext::getIntlKeywordAscii: illegal argument!" );
129 OSL_ENSURE( nIndex
< m_aLocalizedKeywords
.size(), "OSystemParseContext::getIntlKeywordAscii: invalid index!" );
131 rtl::OString sKeyword
;
132 if ( nIndex
< m_aLocalizedKeywords
.size() )
133 sKeyword
= rtl::OUStringToOString(m_aLocalizedKeywords
[nIndex
], RTL_TEXTENCODING_UTF8
);
137 // -----------------------------------------------------------------------------
138 IParseContext::InternationalKeyCode
OSystemParseContext::getIntlKeyCode(const ::rtl::OString
& rToken
) const
140 static IParseContext::InternationalKeyCode Intl_TokenID
[] =
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
151 sal_uInt32 nCount
= sizeof Intl_TokenID
/ sizeof Intl_TokenID
[0];
152 for (sal_uInt32 i
= 0; i
< nCount
; i
++)
154 ::rtl::OString aKey
= getIntlKeywordAscii(Intl_TokenID
[i
]);
155 if (rToken
.equalsIgnoreAsciiCase(aKey
))
156 return Intl_TokenID
[i
];
163 // =============================================================================
164 // =============================================================================
167 // -----------------------------------------------------------------------------
168 ::osl::Mutex
& getSafteyMutex()
170 static ::osl::Mutex s_aSafety
;
173 // -----------------------------------------------------------------------------
174 oslInterlockedCount
& getCounter()
176 static oslInterlockedCount s_nCounter
;
179 // -----------------------------------------------------------------------------
180 OSystemParseContext
* getSharedContext(OSystemParseContext
* _pContext
= NULL
,sal_Bool _bSet
= sal_False
)
182 static OSystemParseContext
* s_pSharedContext
= NULL
;
183 if ( _pContext
&& !s_pSharedContext
)
185 s_pSharedContext
= _pContext
;
186 return s_pSharedContext
;
190 OSystemParseContext
* pReturn
= _pContext
? _pContext
: s_pSharedContext
;
191 s_pSharedContext
= _pContext
;
194 return s_pSharedContext
;
196 // -----------------------------------------------------------------------------
198 // -----------------------------------------------------------------------------
199 OParseContextClient::OParseContextClient()
201 ::osl::MutexGuard
aGuard( getSafteyMutex() );
202 if ( 1 == osl_incrementInterlockedCount( &getCounter() ) )
204 getSharedContext( new OSystemParseContext
);
208 // -----------------------------------------------------------------------------
209 OParseContextClient::~OParseContextClient()
212 ::osl::MutexGuard
aGuard( getSafteyMutex() );
213 if ( 0 == osl_decrementInterlockedCount( &getCounter() ) )
214 delete getSharedContext(NULL
,sal_True
);
217 // -----------------------------------------------------------------------------
218 const OSystemParseContext
* OParseContextClient::getParseContext() const
220 return getSharedContext();
222 // -----------------------------------------------------------------------------
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */