Branch data 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 : : #include "parse/sqlbison_exports.hxx"
21 : :
22 : : #include <sal/macros.h>
23 : : #include <connectivity/sqlnode.hxx>
24 : : #include <connectivity/sqlerror.hxx>
25 : : #include <internalnode.hxx>
26 : : #define YYBISON 1
27 : : #ifndef BISON_INCLUDED
28 : : #define BISON_INCLUDED
29 : : #include <sqlbison.hxx>
30 : : #endif
31 : : #include <connectivity/sqlparse.hxx>
32 : : #include <com/sun/star/lang/Locale.hpp>
33 : : #include <com/sun/star/util/XNumberFormatter.hpp>
34 : : #include <com/sun/star/util/XNumberFormatTypes.hpp>
35 : : #include <com/sun/star/i18n/NumberFormatIndex.hpp>
36 : : #include <com/sun/star/beans/XPropertySet.hpp>
37 : : #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
38 : : #include <com/sun/star/sdbc/DataType.hpp>
39 : : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
40 : : #include <com/sun/star/sdb/ErrorCondition.hpp>
41 : : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
42 : : #include <com/sun/star/util/XNumberFormats.hpp>
43 : : #include <com/sun/star/util/NumberFormat.hpp>
44 : : #include <com/sun/star/i18n/KParseType.hpp>
45 : : #include <com/sun/star/i18n/KParseTokens.hpp>
46 : : #include "connectivity/dbconversion.hxx"
47 : : #include <com/sun/star/util/DateTime.hpp>
48 : : #include <com/sun/star/util/Time.hpp>
49 : : #include <com/sun/star/util/Date.hpp>
50 : : #include "TConnection.hxx"
51 : : #include "sqlscan.hxx"
52 : : #include <comphelper/numbers.hxx>
53 : : #include <comphelper/processfactory.hxx>
54 : : #include <comphelper/stl_types.hxx>
55 : : #include "connectivity/dbtools.hxx"
56 : : #include "connectivity/dbmetadata.hxx"
57 : : #include <tools/diagnose_ex.h>
58 : : #include <string.h>
59 : : #include <boost/bind.hpp>
60 : : #include <algorithm>
61 : : #include <functional>
62 : : #include <rtl/logfile.hxx>
63 : : #include <rtl/ustrbuf.hxx>
64 : :
65 : : using namespace ::com::sun::star::sdbc;
66 : : using namespace ::com::sun::star::util;
67 : : using namespace ::com::sun::star::beans;
68 : : using namespace ::com::sun::star::sdb;
69 : : using namespace ::com::sun::star::uno;
70 : : using namespace ::com::sun::star::lang;
71 : : using namespace ::com::sun::star::i18n;
72 : : using namespace ::com::sun::star;
73 : : using namespace ::osl;
74 : : using namespace ::dbtools;
75 : : using namespace ::comphelper;
76 : :
77 : :
78 : : namespace
79 : : {
80 : : // -----------------------------------------------------------------------------
81 : 0 : sal_Bool lcl_saveConvertToNumber(const Reference< XNumberFormatter > & _xFormatter,sal_Int32 _nKey,const ::rtl::OUString& _sValue,double& _nrValue)
82 : : {
83 : 0 : sal_Bool bRet = sal_False;
84 : : try
85 : : {
86 [ # # ][ # # ]: 0 : _nrValue = _xFormatter->convertStringToNumber(_nKey, _sValue);
87 : 0 : bRet = sal_True;
88 : : }
89 : 0 : catch(Exception&)
90 : : {
91 : : }
92 [ # # ]: 0 : return bRet;
93 : : }
94 : : // -----------------------------------------------------------------------------
95 : 40 : void replaceAndReset(connectivity::OSQLParseNode*& _pResetNode,connectivity::OSQLParseNode* _pNewNode)
96 : : {
97 : 40 : _pResetNode->getParent()->replace(_pResetNode, _pNewNode);
98 [ + - ]: 40 : delete _pResetNode;
99 : 40 : _pResetNode = _pNewNode;
100 : 40 : }
101 : : // -----------------------------------------------------------------------------
102 : : /** quotes a string and search for quotes inside the string and replace them with the new quote
103 : : @param rValue
104 : : The value to be quoted.
105 : : @param rQuot
106 : : The quote
107 : : @param rQuotToReplace
108 : : The quote to replace with
109 : : @return
110 : : The quoted string.
111 : : */
112 : 5998 : ::rtl::OUString SetQuotation(const ::rtl::OUString& rValue, const ::rtl::OUString& rQuot, const ::rtl::OUString& rQuotToReplace)
113 : : {
114 : 5998 : ::rtl::OUString rNewValue = rQuot;
115 : 5998 : rNewValue += rValue;
116 : 5998 : sal_Int32 nIndex = (sal_Int32)-1; // Replace quotes with double quotes or the parser gets into problems
117 : :
118 [ + - ]: 5998 : if (!rQuot.isEmpty())
119 : : {
120 [ - + ]: 5998 : do
121 : : {
122 : 5998 : nIndex += 2;
123 : 5998 : nIndex = rNewValue.indexOf(rQuot,nIndex);
124 [ - + ]: 5998 : if(nIndex != -1)
125 : 0 : rNewValue = rNewValue.replaceAt(nIndex,rQuot.getLength(),rQuotToReplace);
126 : : } while (nIndex != -1);
127 : : }
128 : :
129 : 5998 : rNewValue += rQuot;
130 : 5998 : return rNewValue;
131 : : }
132 : : }
133 : :
134 : : namespace connectivity
135 : : {
136 : :
137 : : //=============================================================================
138 : : //= SQLParseNodeParameter
139 : : //=============================================================================
140 : : //-----------------------------------------------------------------------------
141 : 3206 : SQLParseNodeParameter::SQLParseNodeParameter( const Reference< XConnection >& _rxConnection,
142 : : const Reference< XNumberFormatter >& _xFormatter, const Reference< XPropertySet >& _xField,
143 : : const Locale& _rLocale, const IParseContext* _pContext,
144 : : bool _bIntl, bool _bQuote, sal_Char _cDecSep, bool _bPredicate, bool _bParseToSDBC )
145 : : :rLocale(_rLocale)
146 : : ,aMetaData( _rxConnection )
147 : : ,pParser( NULL )
148 [ + - ]: 3206 : ,pSubQueryHistory( new QueryNameSet )
149 : : ,xFormatter(_xFormatter)
150 : : ,xField(_xField)
151 : : ,m_rContext( _pContext ? (const IParseContext&)(*_pContext) : (const IParseContext&)OSQLParser::s_aDefaultContext )
152 : : ,cDecSep(_cDecSep)
153 : : ,bQuote(_bQuote)
154 : : ,bInternational(_bIntl)
155 : : ,bPredicate(_bPredicate)
156 [ + - ][ + - ]: 6412 : ,bParseToSDBCLevel( _bParseToSDBC )
[ + + ]
157 : : {
158 : 3206 : }
159 : :
160 : : //-----------------------------------------------------------------------------
161 [ + - ]: 25026 : SQLParseNodeParameter::~SQLParseNodeParameter()
162 : : {
163 : 25026 : }
164 : :
165 : : //=============================================================================
166 : : //= OSQLParseNode
167 : : //=============================================================================
168 : : //-----------------------------------------------------------------------------
169 : 0 : ::rtl::OUString OSQLParseNode::convertDateString(const SQLParseNodeParameter& rParam, const ::rtl::OUString& rString) const
170 : : {
171 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::convertDateString" );
172 [ # # ]: 0 : Date aDate = DBTypeConversion::toDate(rString);
173 [ # # ][ # # ]: 0 : Reference< XNumberFormatsSupplier > xSupplier(rParam.xFormatter->getNumberFormatsSupplier());
174 [ # # ][ # # ]: 0 : Reference< XNumberFormatTypes > xTypes(xSupplier->getNumberFormats(), UNO_QUERY);
[ # # ]
175 : :
176 [ # # ][ # # ]: 0 : double fDate = DBTypeConversion::toDouble(aDate,DBTypeConversion::getNULLDate(xSupplier));
177 [ # # ][ # # ]: 0 : sal_Int32 nKey = xTypes->getStandardIndex(rParam.rLocale) + 36; // XXX hack
178 [ # # ][ # # ]: 0 : return rParam.xFormatter->convertNumberToString(nKey, fDate);
179 : : }
180 : :
181 : : //-----------------------------------------------------------------------------
182 : 0 : ::rtl::OUString OSQLParseNode::convertDateTimeString(const SQLParseNodeParameter& rParam, const ::rtl::OUString& rString) const
183 : : {
184 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::convertDateTimeString" );
185 [ # # ]: 0 : DateTime aDate = DBTypeConversion::toDateTime(rString);
186 [ # # ][ # # ]: 0 : Reference< XNumberFormatsSupplier > xSupplier(rParam.xFormatter->getNumberFormatsSupplier());
187 [ # # ][ # # ]: 0 : Reference< XNumberFormatTypes > xTypes(xSupplier->getNumberFormats(), UNO_QUERY);
[ # # ]
188 : :
189 [ # # ][ # # ]: 0 : double fDateTime = DBTypeConversion::toDouble(aDate,DBTypeConversion::getNULLDate(xSupplier));
190 [ # # ][ # # ]: 0 : sal_Int32 nKey = xTypes->getStandardIndex(rParam.rLocale) + 51; // XXX hack
191 [ # # ][ # # ]: 0 : return rParam.xFormatter->convertNumberToString(nKey, fDateTime);
192 : : }
193 : :
194 : : //-----------------------------------------------------------------------------
195 : 0 : ::rtl::OUString OSQLParseNode::convertTimeString(const SQLParseNodeParameter& rParam, const ::rtl::OUString& rString) const
196 : : {
197 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::convertTimeString" );
198 [ # # ]: 0 : Time aTime = DBTypeConversion::toTime(rString);
199 [ # # ][ # # ]: 0 : Reference< XNumberFormatsSupplier > xSupplier(rParam.xFormatter->getNumberFormatsSupplier());
200 : :
201 [ # # ][ # # ]: 0 : Reference< XNumberFormatTypes > xTypes(xSupplier->getNumberFormats(), UNO_QUERY);
[ # # ]
202 : :
203 [ # # ]: 0 : double fTime = DBTypeConversion::toDouble(aTime);
204 [ # # ][ # # ]: 0 : sal_Int32 nKey = xTypes->getStandardIndex(rParam.rLocale) + 41; // XXX hack
205 [ # # ][ # # ]: 0 : return rParam.xFormatter->convertNumberToString(nKey, fTime);
206 : : }
207 : :
208 : : //-----------------------------------------------------------------------------
209 : 3024 : void OSQLParseNode::parseNodeToStr(::rtl::OUString& rString,
210 : : const Reference< XConnection >& _rxConnection,
211 : : const IParseContext* pContext,
212 : : sal_Bool _bIntl,
213 : : sal_Bool _bQuote) const
214 : : {
215 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::parseNodeToStr" );
216 : :
217 : : parseNodeToStr(
218 : : rString, _rxConnection, NULL, NULL,
219 : 2952 : pContext ? pContext->getPreferredLocale() : OParseContext::getDefaultLocale(),
220 [ + + ][ + - ]: 5976 : pContext, _bIntl, _bQuote, '.', false, false );
[ + - ][ + - ]
221 : 3024 : }
222 : :
223 : : //-----------------------------------------------------------------------------
224 : 72 : void OSQLParseNode::parseNodeToPredicateStr(::rtl::OUString& rString,
225 : : const Reference< XConnection >& _rxConnection,
226 : : const Reference< XNumberFormatter > & xFormatter,
227 : : const ::com::sun::star::lang::Locale& rIntl,
228 : : sal_Char _cDec,
229 : : const IParseContext* pContext ) const
230 : : {
231 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::parseNodeToPredicateStr" );
232 : :
233 : : OSL_ENSURE(xFormatter.is(), "OSQLParseNode::parseNodeToPredicateStr:: no formatter!");
234 : :
235 [ + - ]: 72 : if (xFormatter.is())
236 [ + - ]: 72 : parseNodeToStr(rString, _rxConnection, xFormatter, NULL, rIntl, pContext, sal_True, sal_True, _cDec, true, false);
237 : 72 : }
238 : :
239 : : //-----------------------------------------------------------------------------
240 : 0 : void OSQLParseNode::parseNodeToPredicateStr(::rtl::OUString& rString,
241 : : const Reference< XConnection > & _rxConnection,
242 : : const Reference< XNumberFormatter > & xFormatter,
243 : : const Reference< XPropertySet > & _xField,
244 : : const ::com::sun::star::lang::Locale& rIntl,
245 : : sal_Char _cDec,
246 : : const IParseContext* pContext ) const
247 : : {
248 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::parseNodeToPredicateStr" );
249 : :
250 : : OSL_ENSURE(xFormatter.is(), "OSQLParseNode::parseNodeToPredicateStr:: no formatter!");
251 : :
252 [ # # ]: 0 : if (xFormatter.is())
253 : 0 : parseNodeToStr( rString, _rxConnection, xFormatter, _xField, rIntl, pContext, true, true, _cDec, true, false );
254 : 0 : }
255 : :
256 : : //-----------------------------------------------------------------------------
257 : 3096 : void OSQLParseNode::parseNodeToStr(::rtl::OUString& rString,
258 : : const Reference< XConnection > & _rxConnection,
259 : : const Reference< XNumberFormatter > & xFormatter,
260 : : const Reference< XPropertySet > & _xField,
261 : : const ::com::sun::star::lang::Locale& rIntl,
262 : : const IParseContext* pContext,
263 : : bool _bIntl,
264 : : bool _bQuote,
265 : : sal_Char _cDecSep,
266 : : bool _bPredicate,
267 : : bool _bSubstitute) const
268 : : {
269 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::parseNodeToStr" );
270 : :
271 : : OSL_ENSURE( _rxConnection.is(), "OSQLParseNode::parseNodeToStr: invalid connection!" );
272 : :
273 [ + - ]: 3096 : if ( _rxConnection.is() )
274 : : {
275 [ + - ]: 3096 : ::rtl::OUStringBuffer sBuffer = rString;
276 : : try
277 : : {
278 : : OSQLParseNode::impl_parseNodeToString_throw( sBuffer,
279 : : SQLParseNodeParameter(
280 : : _rxConnection, xFormatter, _xField, rIntl, pContext,
281 : : _bIntl, _bQuote, _cDecSep, _bPredicate, _bSubstitute
282 [ + - ][ + - ]: 3096 : ) );
[ # # ][ + - ]
283 : : }
284 [ # # ]: 0 : catch( const SQLException& )
285 : : {
286 : : OSL_FAIL( "OSQLParseNode::parseNodeToStr: this should not throw!" );
287 : : // our callers don't expect this method to throw anything. The only known situation
288 : : // where impl_parseNodeToString_throw can throw is when there is a cyclic reference
289 : : // in the sub queries, but this cannot be the case here, as we do not parse to
290 : : // SDBC level.
291 : : }
292 [ + - ]: 3096 : rString = sBuffer.makeStringAndClear();
293 : : }
294 : 3096 : }
295 : : //-----------------------------------------------------------------------------
296 : 110 : bool OSQLParseNode::parseNodeToExecutableStatement( ::rtl::OUString& _out_rString, const Reference< XConnection >& _rxConnection,
297 : : OSQLParser& _rParser, ::com::sun::star::sdbc::SQLException* _pErrorHolder ) const
298 : : {
299 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::parseNodeToExecutableStatement" );
300 : : OSL_PRECOND( _rxConnection.is(), "OSQLParseNode::parseNodeToExecutableStatement: invalid connection!" );
301 : : SQLParseNodeParameter aParseParam( _rxConnection,
302 [ + - ][ + - ]: 110 : NULL, NULL, OParseContext::getDefaultLocale(), NULL, false, true, '.', false, true );
[ + - ][ + - ]
303 : :
304 [ - + ][ + - ]: 110 : if ( aParseParam.aMetaData.supportsSubqueriesInFrom() )
305 : : {
306 [ # # ]: 0 : Reference< XQueriesSupplier > xSuppQueries( _rxConnection, UNO_QUERY );
307 : : OSL_ENSURE( xSuppQueries.is(), "OSQLParseNode::parseNodeToExecutableStatement: cannot substitute everything without a QueriesSupplier!" );
308 [ # # ]: 0 : if ( xSuppQueries.is() )
309 [ # # ][ # # ]: 0 : aParseParam.xQueries = xSuppQueries->getQueries();
[ # # ]
310 : : }
311 : :
312 : 110 : aParseParam.pParser = &_rParser;
313 : :
314 : 110 : _out_rString = ::rtl::OUString();
315 : 110 : ::rtl::OUStringBuffer sBuffer;
316 : 110 : bool bSuccess = false;
317 : : try
318 : : {
319 [ + - ]: 110 : impl_parseNodeToString_throw( sBuffer, aParseParam );
320 : 110 : bSuccess = true;
321 : : }
322 [ # # # # ]: 0 : catch( const SQLException& e )
323 : : {
324 [ # # ]: 0 : if ( _pErrorHolder )
325 [ # # ]: 0 : *_pErrorHolder = e;
326 : : }
327 [ + - ]: 110 : _out_rString = sBuffer.makeStringAndClear();
328 [ + - ]: 110 : return bSuccess;
329 : : }
330 : :
331 : : //-----------------------------------------------------------------------------
332 : : namespace
333 : : {
334 : 0 : bool lcl_isAliasNamePresent( const OSQLParseNode& _rTableNameNode )
335 : : {
336 : 0 : return !OSQLParseNode::getTableRange(_rTableNameNode.getParent()).isEmpty();
337 : : }
338 : : }
339 : :
340 : : //-----------------------------------------------------------------------------
341 : 25968 : void OSQLParseNode::impl_parseNodeToString_throw(::rtl::OUStringBuffer& rString, const SQLParseNodeParameter& rParam) const
342 : : {
343 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::getTableRange" );
344 [ + + ]: 25968 : if ( isToken() )
345 : : {
346 : 13146 : parseLeaf(rString,rParam);
347 : 25968 : return;
348 : : }
349 : :
350 : : // Lets see how many nodes this subtree has
351 : 12822 : sal_uInt32 nCount = count();
352 : :
353 : 12822 : bool bHandled = false;
354 [ + + + - : 12822 : switch ( getKnownRuleID() )
- - + ]
355 : : {
356 : : // special handling for parameters
357 : : case parameter:
358 : : {
359 [ + + ]: 154 : if(rString.getLength())
360 : 78 : rString.appendAscii(" ");
361 [ - + ]: 154 : if (nCount == 1) // ?
362 : 0 : m_aChildren[0]->impl_parseNodeToString_throw( rString, rParam );
363 [ + - ]: 154 : else if (nCount == 2) // :Name
364 : : {
365 : 154 : m_aChildren[0]->impl_parseNodeToString_throw( rString, rParam );
366 : 154 : rString.append(m_aChildren[1]->m_aNodeValue);
367 : : } // [Name]
368 : : else
369 : : {
370 : 0 : m_aChildren[0]->impl_parseNodeToString_throw( rString, rParam );
371 : 0 : rString.append(m_aChildren[1]->m_aNodeValue);
372 : 0 : rString.append(m_aChildren[2]->m_aNodeValue);
373 : : }
374 : 154 : bHandled = true;
375 : : }
376 : 154 : break;
377 : :
378 : : // table refs
379 : : case table_ref:
380 [ - + ][ # # ]: 394 : if ( ( nCount == 2 ) || ( nCount == 3 ) || ( nCount == 5 ) )
[ # # ]
381 : : {
382 : 394 : impl_parseTableRangeNodeToString_throw( rString, rParam );
383 : 394 : bHandled = true;
384 : : }
385 : 394 : break;
386 : :
387 : : // table name - might be a query name
388 : : case table_name:
389 : 394 : bHandled = impl_parseTableNameNodeToString_throw( rString, rParam );
390 : 394 : break;
391 : :
392 : : case as:
393 [ # # ]: 0 : if ( rParam.aMetaData.generateASBeforeCorrelationName() )
394 [ # # ]: 0 : rString.append(::rtl::OUString(" AS"));
395 : 0 : bHandled = true;
396 : 0 : break;
397 : :
398 : : case like_predicate:
399 : : // Depending on whether international is given, LIKE is treated differently
400 : : // international: *, ? are placeholders
401 : : // else SQL92 conform: %, _
402 : 0 : impl_parseLikeNodeToString_throw( rString, rParam );
403 : 0 : bHandled = true;
404 : 0 : break;
405 : :
406 : : case general_set_fct:
407 : : case set_fct_spec:
408 : : case position_exp:
409 : : case extract_exp:
410 : : case length_exp:
411 : : case char_value_fct:
412 : : {
413 [ # # ]: 0 : if (!addDateValue(rString, rParam))
414 : : {
415 : : // Do not quote function name
416 [ # # ]: 0 : SQLParseNodeParameter aNewParam(rParam);
417 [ # # ][ # # ]: 0 : aNewParam.bQuote = ( SQL_ISRULE(this,length_exp) || SQL_ISRULE(this,char_value_fct) );
[ # # ][ # # ]
[ # # ][ # # ]
418 : :
419 [ # # ][ # # ]: 0 : m_aChildren[0]->impl_parseNodeToString_throw( rString, aNewParam );
420 : 0 : aNewParam.bQuote = rParam.bQuote;
421 : : //aNewParam.bPredicate = sal_False; // disable [ ] around names // look at i73215
422 : 0 : ::rtl::OUStringBuffer aStringPara;
423 [ # # ]: 0 : for (sal_uInt32 i=1; i<nCount; i++)
424 : : {
425 [ # # ]: 0 : const OSQLParseNode * pSubTree = m_aChildren[i];
426 [ # # ]: 0 : if (pSubTree)
427 : : {
428 [ # # ]: 0 : pSubTree->impl_parseNodeToString_throw( aStringPara, aNewParam );
429 : :
430 : : // In the comma lists, put commas in-between all subtrees
431 [ # # ][ # # ]: 0 : if ((m_eNodeType == SQL_NODE_COMMALISTRULE) && (i < (nCount - 1)))
432 [ # # ]: 0 : aStringPara.appendAscii(",");
433 : : }
434 : : else
435 : 0 : i++;
436 : : }
437 [ # # ][ # # ]: 0 : rString.append(aStringPara.makeStringAndClear());
[ # # ]
438 : : }
439 : 0 : bHandled = true;
440 : : }
441 : 0 : break;
442 : : default:
443 : 11880 : break;
444 : : } // switch ( getKnownRuleID() )
445 : :
446 [ + + ]: 12822 : if ( !bHandled )
447 : : {
448 [ + - ][ + + ]: 46368 : for (OSQLParseNodes::const_iterator i = m_aChildren.begin();
449 : 34094 : i != m_aChildren.end();)
450 : : {
451 : 21820 : const OSQLParseNode* pSubTree = *i;
452 [ - + ]: 21820 : if ( !pSubTree )
453 : : {
454 : 0 : ++i;
455 : 0 : continue;
456 : : }
457 : :
458 [ + - ]: 21820 : SQLParseNodeParameter aNewParam(rParam);
459 : :
460 : : // don't replace the field for subqueries
461 [ - + ][ # # ]: 21820 : if (rParam.xField.is() && SQL_ISRULE(pSubTree,subquery))
[ # # ][ # # ]
[ - + ]
462 [ # # ]: 0 : aNewParam.xField = NULL;
463 : :
464 : : // if there is a field given we don't display the fieldname, if there is any
465 [ - + ][ # # ]: 21820 : if (rParam.xField.is() && SQL_ISRULE(pSubTree,column_ref))
[ # # ][ # # ]
[ - + ]
466 : : {
467 : 0 : sal_Bool bFilter = sal_False;
468 : : // retrieve the fields name
469 : 0 : ::rtl::OUString aFieldName;
470 : : try
471 : : {
472 : 0 : sal_Int32 nNamePropertyId = PROPERTY_ID_NAME;
473 [ # # ][ # # ]: 0 : if ( rParam.xField->getPropertySetInfo()->hasPropertyByName( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_REALNAME ) ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
474 : 0 : nNamePropertyId = PROPERTY_ID_REALNAME;
475 [ # # ][ # # ]: 0 : rParam.xField->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex( nNamePropertyId ) ) >>= aFieldName;
[ # # ][ # # ]
[ # # ]
476 : : }
477 [ # # ]: 0 : catch ( Exception& )
478 : : {
479 : : }
480 : :
481 [ # # ]: 0 : if(pSubTree->count())
482 : : {
483 [ # # ]: 0 : const OSQLParseNode* pCol = pSubTree->m_aChildren[pSubTree->count()-1];
484 [ # # ][ # # ]: 0 : if ( ( SQL_ISRULE(pCol,column_val)
[ # # # #
# # ][ # # ]
485 [ # # ]: 0 : && pCol->getChild(0)->getTokenValue().equalsIgnoreAsciiCase(aFieldName)
486 : : )
487 : 0 : || pCol->getTokenValue().equalsIgnoreAsciiCase(aFieldName)
488 : : )
489 : 0 : bFilter = sal_True;
490 : : }
491 : :
492 : : // ok we found the field, if the following node is the
493 : : // comparision operator '=' we filter it as well
494 [ # # ]: 0 : if (bFilter)
495 : : {
496 [ # # ][ # # ]: 0 : if (SQL_ISRULE(this, comparison_predicate))
[ # # ][ # # ]
497 : : {
498 : 0 : ++i;
499 [ # # ][ # # ]: 0 : if(i != m_aChildren.end())
500 : : {
501 : 0 : pSubTree = *i;
502 [ # # ][ # # ]: 0 : if (pSubTree && pSubTree->getNodeType() == SQL_NODE_EQUAL)
[ # # ]
503 : 0 : ++i;
504 : : }
505 : : }
506 : : else
507 : 0 : ++i;
508 : : }
509 : : else
510 : : {
511 [ # # ]: 0 : pSubTree->impl_parseNodeToString_throw( rString, aNewParam );
512 : 0 : ++i;
513 : :
514 : : // In the comma lists, put commas in-between all subtrees
515 [ # # ][ # # ]: 0 : if ((m_eNodeType == SQL_NODE_COMMALISTRULE) && (i != m_aChildren.end()))
[ # # ]
[ # # # # ]
[ # # ]
516 [ # # ]: 0 : rString.appendAscii(",");
517 : 0 : }
518 : : }
519 : : else
520 : : {
521 [ + - ]: 21820 : pSubTree->impl_parseNodeToString_throw( rString, aNewParam );
522 : 21820 : ++i;
523 : :
524 : : // In the comma lists, put commas in-between all subtrees
525 [ + - ][ + + ]: 21820 : if ((m_eNodeType == SQL_NODE_COMMALISTRULE) && (i != m_aChildren.end()))
[ + + ]
[ + + # # ]
[ + + ]
526 : : {
527 [ + - ][ + - ]: 108 : if (SQL_ISRULE(this,value_exp_commalist) && rParam.bPredicate)
[ - + ][ # # ]
[ - + ]
528 [ # # ]: 0 : rString.appendAscii(";");
529 : : else
530 [ + - ]: 108 : rString.appendAscii(",");
531 : : }
532 : : }
533 [ + - ]: 21820 : }
534 : : }
535 : : }
536 : :
537 : : //-----------------------------------------------------------------------------
538 : 394 : bool OSQLParseNode::impl_parseTableNameNodeToString_throw( ::rtl::OUStringBuffer& rString, const SQLParseNodeParameter& rParam ) const
539 : : {
540 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::impl_parseTableNameNodeToString_throw" );
541 : : // is the table_name part of a table_ref?
542 : : OSL_ENSURE( getParent(), "OSQLParseNode::impl_parseTableNameNodeToString_throw: table_name without parent?" );
543 [ + - ][ - + ]: 394 : if ( !getParent() || ( getParent()->getKnownRuleID() != table_ref ) )
[ - + ]
544 : 0 : return false;
545 : :
546 : : // if it's a query, maybe we need to substitute the SQL statement ...
547 [ + + ]: 394 : if ( !rParam.bParseToSDBCLevel )
548 : 284 : return false;
549 : :
550 [ + - ]: 110 : if ( !rParam.xQueries.is() )
551 : : // connection does not support queries in queries, or was no query supplier
552 : 110 : return false;
553 : :
554 : : try
555 : : {
556 [ # # ]: 0 : ::rtl::OUString sTableOrQueryName( getChild(0)->getTokenValue() );
557 [ # # ][ # # ]: 0 : bool bIsQuery = rParam.xQueries->hasByName( sTableOrQueryName );
558 [ # # ]: 0 : if ( !bIsQuery )
559 : 0 : return false;
560 : :
561 : : // avoid recursion (e.g. "foo" defined as "SELECT * FROM bar" and "bar" defined as "SELECT * FROM foo".
562 [ # # ][ # # ]: 0 : if ( rParam.pSubQueryHistory->find( sTableOrQueryName ) != rParam.pSubQueryHistory->end() )
563 : : {
564 : : OSL_ENSURE( rParam.pParser, "OSQLParseNode::impl_parseTableNameNodeToString_throw: no parser?" );
565 [ # # ]: 0 : if ( rParam.pParser )
566 : : {
567 [ # # ]: 0 : const SQLError& rErrors( rParam.pParser->getErrorHelper() );
568 [ # # ][ # # ]: 0 : rErrors.raiseException( sdb::ErrorCondition::PARSER_CYCLIC_SUB_QUERIES );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
569 : : }
570 : : else
571 : : {
572 [ # # ][ # # ]: 0 : SQLError aErrors( ::comphelper::getProcessServiceFactory() );
[ # # ][ # # ]
573 [ # # ][ # # ]: 0 : aErrors.raiseException( sdb::ErrorCondition::PARSER_CYCLIC_SUB_QUERIES );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
574 : : }
575 : : }
576 [ # # ]: 0 : rParam.pSubQueryHistory->insert( sTableOrQueryName );
577 : :
578 [ # # ][ # # ]: 0 : Reference< XPropertySet > xQuery( rParam.xQueries->getByName( sTableOrQueryName ), UNO_QUERY_THROW );
[ # # ]
579 : :
580 : : // substitute the query name with the constituting command
581 : 0 : ::rtl::OUString sCommand;
582 [ # # ][ # # ]: 0 : OSL_VERIFY( xQuery->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_COMMAND ) ) >>= sCommand );
[ # # ][ # # ]
583 : :
584 : 0 : sal_Bool bEscapeProcessing = sal_False;
585 [ # # ][ # # ]: 0 : OSL_VERIFY( xQuery->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_ESCAPEPROCESSING ) ) >>= bEscapeProcessing );
[ # # ][ # # ]
586 : :
587 : : // the query we found here might itself be based on another query, so parse it recursively
588 : : OSL_ENSURE( rParam.pParser, "OSQLParseNode::impl_parseTableNameNodeToString_throw: cannot analyze sub queries without a parser!" );
589 [ # # ][ # # ]: 0 : if ( bEscapeProcessing && rParam.pParser )
590 : : {
591 : 0 : ::rtl::OUString sError;
592 [ # # ]: 0 : ::std::auto_ptr< OSQLParseNode > pSubQueryNode( rParam.pParser->parseTree( sError, sCommand, sal_False ) );
593 [ # # ]: 0 : if ( pSubQueryNode.get() )
594 : : {
595 : : // parse the sub-select to SDBC level, too
596 : 0 : ::rtl::OUStringBuffer sSubSelect;
597 [ # # ]: 0 : pSubQueryNode->impl_parseNodeToString_throw( sSubSelect, rParam );
598 [ # # ]: 0 : if ( sSubSelect.getLength() )
599 [ # # ]: 0 : sCommand = sSubSelect.makeStringAndClear();
600 [ # # ]: 0 : }
601 : : }
602 : :
603 [ # # ]: 0 : rString.appendAscii( " ( " );
604 [ # # ]: 0 : rString.append(sCommand);
605 [ # # ]: 0 : rString.appendAscii( " )" );
606 : :
607 : : // append the query name as table alias, since it might be referenced in other
608 : : // parts of the statement - but only if there's no other alias name present
609 [ # # ][ # # ]: 0 : if ( !lcl_isAliasNamePresent( *this ) )
610 : : {
611 [ # # ]: 0 : rString.appendAscii( " AS " );
612 [ # # ]: 0 : if ( rParam.bQuote )
613 : : rString.append(SetQuotation( sTableOrQueryName,
614 [ # # ][ # # ]: 0 : rParam.aMetaData.getIdentifierQuoteString(), rParam.aMetaData.getIdentifierQuoteString() ));
[ # # ]
615 : : }
616 : :
617 : : // don't forget to remove the query name from the history, else multiple inclusions
618 : : // won't work
619 : : // #i69227# / 2006-10-10 / frank.schoenheit@sun.com
620 [ # # ]: 0 : rParam.pSubQueryHistory->erase( sTableOrQueryName );
621 : :
622 : 394 : return true;
623 : : }
624 [ # # # ]: 0 : catch( const SQLException& )
625 : : {
626 : 0 : throw;
627 : : }
628 : 0 : catch( const Exception& )
629 : : {
630 : : DBG_UNHANDLED_EXCEPTION();
631 : : }
632 : 0 : return false;
633 : : }
634 : :
635 : : //-----------------------------------------------------------------------------
636 : 394 : void OSQLParseNode::impl_parseTableRangeNodeToString_throw(::rtl::OUStringBuffer& rString, const SQLParseNodeParameter& rParam) const
637 : : {
638 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::impl_parseTableRangeNodeToString_throw" );
639 : : OSL_PRECOND( ( count() == 2 ) || ( count() == 3 ) || ( count() == 5 ) ,"Illegal count");
640 : :
641 : : // rString += ::rtl::OUString(" ");
642 : : ::std::for_each(m_aChildren.begin(),m_aChildren.end(),
643 : 394 : boost::bind( &OSQLParseNode::impl_parseNodeToString_throw, _1, boost::ref( rString ), boost::cref( rParam ) ));
644 : 394 : }
645 : :
646 : : //-----------------------------------------------------------------------------
647 : 0 : void OSQLParseNode::impl_parseLikeNodeToString_throw( ::rtl::OUStringBuffer& rString, const SQLParseNodeParameter& rParam ) const
648 : : {
649 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::impl_parseLikeNodeToString_throw" );
650 : : OSL_ENSURE(count() == 2,"count != 2: Prepare for GPF");
651 : :
652 : 0 : const OSQLParseNode* pEscNode = NULL;
653 : 0 : const OSQLParseNode* pParaNode = NULL;
654 : :
655 [ # # ]: 0 : SQLParseNodeParameter aNewParam(rParam);
656 : : //aNewParam.bQuote = sal_True; // why setting this to true? @see http://www.openoffice.org/issues/show_bug.cgi?id=75557
657 : :
658 : : // if there is a field given we don't display the fieldname, if there are any
659 : 0 : sal_Bool bAddName = sal_True;
660 [ # # ]: 0 : if (rParam.xField.is())
661 : : {
662 : : // retrieve the fields name
663 : 0 : ::rtl::OUString aFieldName;
664 : : try
665 : : {
666 : : // retrieve the fields name
667 : 0 : rtl::OUString aString;
668 [ # # ][ # # ]: 0 : rParam.xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aString;
[ # # ][ # # ]
669 [ # # ]: 0 : aFieldName = aString.getStr();
670 : : }
671 [ # # ]: 0 : catch ( Exception& )
672 : : {
673 : : OSL_FAIL( "OSQLParseNode::impl_parseLikeNodeToString_throw Exception occurred!" );
674 : : }
675 [ # # ][ # # ]: 0 : if ( !m_aChildren[0]->isLeaf() )
676 : : {
677 [ # # ][ # # ]: 0 : const OSQLParseNode* pCol = m_aChildren[0]->getChild(m_aChildren[0]->count()-1);
[ # # ]
678 [ # # ][ # # ]: 0 : if ((SQL_ISRULE(pCol,column_val) && pCol->getChild(0)->getTokenValue().equalsIgnoreAsciiCase(aFieldName)) ||
[ # # ][ # # ]
[ # # # # ]
[ # # ]
679 : 0 : pCol->getTokenValue().equalsIgnoreAsciiCase(aFieldName) )
680 : 0 : bAddName = sal_False;
681 : 0 : }
682 : : }
683 : :
684 [ # # ]: 0 : if (bAddName)
685 [ # # ][ # # ]: 0 : m_aChildren[0]->impl_parseNodeToString_throw( rString, aNewParam );
686 : :
687 [ # # ]: 0 : const OSQLParseNode* pPart2 = m_aChildren[1];
688 [ # # ][ # # ]: 0 : pPart2->getChild(0)->impl_parseNodeToString_throw( rString, aNewParam );
689 [ # # ][ # # ]: 0 : pPart2->getChild(1)->impl_parseNodeToString_throw( rString, aNewParam );
690 [ # # ]: 0 : pParaNode = pPart2->getChild(2);
691 [ # # ]: 0 : pEscNode = pPart2->getChild(3);
692 : :
693 [ # # ]: 0 : if (pParaNode->isToken())
694 : : {
695 [ # # ]: 0 : ::rtl::OUString aStr = ConvertLikeToken(pParaNode, pEscNode, rParam.bInternational);
696 [ # # ]: 0 : rString.appendAscii(" ");
697 [ # # ]: 0 : rString.append(SetQuotation(aStr,::rtl::OUString("\'"),::rtl::OUString("\'\'")));
698 : : }
699 : : else
700 [ # # ]: 0 : pParaNode->impl_parseNodeToString_throw( rString, aNewParam );
701 : :
702 [ # # ][ # # ]: 0 : pEscNode->impl_parseNodeToString_throw( rString, aNewParam );
703 : 0 : }
704 : :
705 : :
706 : : // -----------------------------------------------------------------------------
707 : 408 : sal_Bool OSQLParseNode::getTableComponents(const OSQLParseNode* _pTableNode,
708 : : ::com::sun::star::uno::Any &_rCatalog,
709 : : ::rtl::OUString &_rSchema,
710 : : ::rtl::OUString &_rTable,
711 : : const Reference< XDatabaseMetaData >& _xMetaData)
712 : : {
713 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::getTableComponents" );
714 : : OSL_ENSURE(_pTableNode,"Wrong use of getTableComponents! _pTableNode is not allowed to be null!");
715 [ + - ]: 408 : if(_pTableNode)
716 : : {
717 [ + - ][ - + ]: 408 : const sal_Bool bSupportsCatalog = _xMetaData.is() && _xMetaData->supportsCatalogsInDataManipulation();
718 [ + - ][ - + ]: 408 : const sal_Bool bSupportsSchema = _xMetaData.is() && _xMetaData->supportsSchemasInDataManipulation();
719 : 408 : const OSQLParseNode* pTableNode = _pTableNode;
720 : : // clear the parameter given
721 : 408 : _rCatalog = Any();
722 : 408 : _rSchema = _rTable = ::rtl::OUString();
723 : : // see rule catalog_name: in sqlbison.y
724 [ - + ][ - + ]: 408 : if (SQL_ISRULE(pTableNode,catalog_name))
[ + - ]
725 : : {
726 : : OSL_ENSURE(pTableNode->getChild(0) && pTableNode->getChild(0)->isToken(),"Invalid parsenode!");
727 : 0 : _rCatalog <<= pTableNode->getChild(0)->getTokenValue();
728 : 0 : pTableNode = pTableNode->getChild(2);
729 : : }
730 : : // check if we have schema_name rule
731 [ + - ][ - + ]: 408 : if(SQL_ISRULE(pTableNode,schema_name))
[ - + ]
732 : : {
733 [ # # ][ # # ]: 0 : if ( bSupportsCatalog && !bSupportsSchema )
734 : 0 : _rCatalog <<= pTableNode->getChild(0)->getTokenValue();
735 : : else
736 : 0 : _rSchema = pTableNode->getChild(0)->getTokenValue();
737 : 0 : pTableNode = pTableNode->getChild(2);
738 : : }
739 : : // check if we have table_name rule
740 [ + - ][ + - ]: 408 : if(SQL_ISRULE(pTableNode,table_name))
[ + - ]
741 : : {
742 : 408 : _rTable = pTableNode->getChild(0)->getTokenValue();
743 : : }
744 : : else
745 : : {
746 : : OSL_FAIL("Error in parse tree!");
747 : : }
748 : : }
749 : 408 : return !_rTable.isEmpty();
750 : : }
751 : : // -----------------------------------------------------------------------------
752 : 0 : void OSQLParser::killThousandSeparator(OSQLParseNode* pLiteral)
753 : : {
754 [ # # ]: 0 : if ( pLiteral )
755 : : {
756 [ # # ]: 0 : if ( s_xLocaleData->getLocaleItem( m_pData->aLocale ).decimalSeparator.toChar() == ',' )
757 : : {
758 : 0 : pLiteral->m_aNodeValue = pLiteral->m_aNodeValue.replace('.', sal_Unicode());
759 : : // and replace decimal
760 : 0 : pLiteral->m_aNodeValue = pLiteral->m_aNodeValue.replace(',', '.');
761 : : }
762 : : else
763 : 0 : pLiteral->m_aNodeValue = pLiteral->m_aNodeValue.replace(',', sal_Unicode());
764 : : }
765 : 0 : }
766 : : // -----------------------------------------------------------------------------
767 : 144 : OSQLParseNode* OSQLParser::convertNode(sal_Int32 nType,OSQLParseNode*& pLiteral)
768 : : {
769 [ + + ]: 144 : if ( !pLiteral )
770 : 72 : return NULL;
771 : :
772 : 72 : OSQLParseNode* pReturn = pLiteral;
773 : :
774 [ - + ][ # # ]: 72 : if ( ( pLiteral->isRule() && !SQL_ISRULE(pLiteral,value_exp) ) || SQL_ISTOKEN(pLiteral,FALSE) || SQL_ISTOKEN(pLiteral,TRUE) )
[ # # ][ # # ]
[ + - ][ + - ]
[ + - ][ - + ]
[ - + ]
775 : : {
776 [ # # ]: 0 : switch(nType)
777 : : {
778 : : case DataType::CHAR:
779 : : case DataType::VARCHAR:
780 : : case DataType::LONGVARCHAR:
781 : : case DataType::CLOB:
782 [ # # ][ # # ]: 0 : if ( !SQL_ISRULE(pReturn,char_value_exp) && !buildStringNodes(pReturn) )
[ # # ][ # # ]
[ # # ][ # # ]
783 : 0 : pReturn = NULL;
784 : : default:
785 : 0 : break;
786 : : }
787 : : }
788 : : else
789 : : {
790 [ + - - - : 72 : switch(pLiteral->getNodeType())
- ]
791 : : {
792 : : case SQL_NODE_STRING:
793 [ + - - ]: 72 : switch(nType)
794 : : {
795 : : case DataType::CHAR:
796 : : case DataType::VARCHAR:
797 : : case DataType::LONGVARCHAR:
798 : : case DataType::CLOB:
799 : 72 : break;
800 : : case DataType::DATE:
801 : : case DataType::TIME:
802 : : case DataType::TIMESTAMP:
803 [ # # ]: 0 : if (m_xFormatter.is())
804 [ # # ]: 0 : pReturn = buildDate( nType, pReturn);
805 : 0 : break;
806 : : default:
807 [ # # ]: 0 : m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_COMPARE);
808 : 0 : break;
809 : : }
810 : 72 : break;
811 : : case SQL_NODE_ACCESS_DATE:
812 [ # # ]: 0 : switch(nType)
813 : : {
814 : : case DataType::DATE:
815 : : case DataType::TIME:
816 : : case DataType::TIMESTAMP:
817 [ # # ]: 0 : if ( m_xFormatter.is() )
818 [ # # ]: 0 : pReturn = buildDate( nType, pReturn);
819 : : else
820 [ # # ]: 0 : m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_DATE_COMPARE);
821 : 0 : break;
822 : : default:
823 [ # # ]: 0 : m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_COMPARE);
824 : 0 : break;
825 : : }
826 : 0 : break;
827 : : case SQL_NODE_INTNUM:
828 [ # # # ]: 0 : switch(nType)
829 : : {
830 : : case DataType::BIT:
831 : : case DataType::BOOLEAN:
832 : : case DataType::DECIMAL:
833 : : case DataType::NUMERIC:
834 : : case DataType::TINYINT:
835 : : case DataType::SMALLINT:
836 : : case DataType::INTEGER:
837 : : case DataType::BIGINT:
838 : : case DataType::FLOAT:
839 : : case DataType::REAL:
840 : : case DataType::DOUBLE:
841 : : // kill thousand seperators if any
842 [ # # ]: 0 : killThousandSeparator(pReturn);
843 : 0 : break;
844 : : case DataType::CHAR:
845 : : case DataType::VARCHAR:
846 : : case DataType::LONGVARCHAR:
847 : : case DataType::CLOB:
848 [ # # ]: 0 : pReturn = buildNode_STR_NUM(pReturn);
849 : 0 : break;
850 : : default:
851 [ # # ]: 0 : m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_INT_COMPARE);
852 : 0 : break;
853 : : }
854 : 0 : break;
855 : : case SQL_NODE_APPROXNUM:
856 [ # # # ]: 0 : switch(nType)
857 : : {
858 : : case DataType::DECIMAL:
859 : : case DataType::NUMERIC:
860 : : case DataType::FLOAT:
861 : : case DataType::REAL:
862 : : case DataType::DOUBLE:
863 : : // kill thousand seperators if any
864 [ # # ]: 0 : killThousandSeparator(pReturn);
865 : 0 : break;
866 : : case DataType::CHAR:
867 : : case DataType::VARCHAR:
868 : : case DataType::LONGVARCHAR:
869 : : case DataType::CLOB:
870 [ # # ]: 0 : pReturn = buildNode_STR_NUM(pReturn);
871 : 0 : break;
872 : : case DataType::INTEGER:
873 : : default:
874 [ # # ]: 0 : m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_REAL_COMPARE);
875 : 0 : break;
876 : : }
877 : 0 : break;
878 : : default:
879 : : ;
880 : : }
881 : : }
882 : 144 : return pReturn;
883 : : }
884 : : // -----------------------------------------------------------------------------
885 : 72 : sal_Int16 OSQLParser::buildPredicateRule(OSQLParseNode*& pAppend,OSQLParseNode* pLiteral,OSQLParseNode*& pCompare,OSQLParseNode* pLiteral2)
886 : : {
887 : : OSL_ENSURE(inPredicateCheck(),"Only in predicate check allowed!");
888 : 72 : sal_Int16 nErg = 0;
889 [ + - ]: 72 : if ( m_xField.is() )
890 : : {
891 : 72 : sal_Int32 nType = 0;
892 : : try
893 : : {
894 [ + - ][ + - ]: 72 : m_xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)) >>= nType;
[ + - ][ + - ]
[ # # ]
895 : : }
896 [ # # ]: 0 : catch( Exception& )
897 : : {
898 : 0 : return nErg;
899 : : }
900 : :
901 [ + - ]: 72 : OSQLParseNode* pNode1 = convertNode(nType,pLiteral);
902 [ + - ]: 72 : if ( pNode1 )
903 : : {
904 [ + - ]: 72 : OSQLParseNode* pNode2 = convertNode(nType,pLiteral2);
905 [ + - ]: 72 : if ( m_sErrorMessage.isEmpty() )
906 [ + - ]: 72 : nErg = buildNode(pAppend,pCompare,pNode1,pNode2);
907 : : }
908 : : }
909 [ - + ]: 72 : if (!pCompare->getParent()) // I have no parent so I was not used and I must die :-)
910 [ # # ]: 0 : delete pCompare;
911 : 72 : return nErg;
912 : : }
913 : : // -----------------------------------------------------------------------------
914 : 0 : sal_Int16 OSQLParser::buildLikeRule(OSQLParseNode*& pAppend, OSQLParseNode*& pLiteral, const OSQLParseNode* pEscape)
915 : : {
916 : 0 : sal_Int16 nErg = 0;
917 : 0 : sal_Int32 nType = 0;
918 : :
919 [ # # ]: 0 : if (!m_xField.is())
920 : 0 : return nErg;
921 : : try
922 : : {
923 : 0 : Any aValue;
924 : : {
925 [ # # ][ # # ]: 0 : aValue = m_xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE));
[ # # ][ # # ]
926 : 0 : aValue >>= nType;
927 [ # # ]: 0 : }
928 : : }
929 [ # # ]: 0 : catch( Exception& )
930 : : {
931 : 0 : return nErg;
932 : : }
933 : :
934 [ # # ]: 0 : switch (nType)
935 : : {
936 : : case DataType::CHAR:
937 : : case DataType::VARCHAR:
938 : : case DataType::LONGVARCHAR:
939 : : case DataType::CLOB:
940 [ # # ]: 0 : if(pLiteral->isRule())
941 : : {
942 [ # # ]: 0 : pAppend->append(pLiteral);
943 : 0 : nErg = 1;
944 : : }
945 : : else
946 : : {
947 [ # # # ]: 0 : switch(pLiteral->getNodeType())
948 : : {
949 : : case SQL_NODE_STRING:
950 [ # # ]: 0 : pLiteral->m_aNodeValue = ConvertLikeToken(pLiteral, pEscape, sal_False);
951 [ # # ]: 0 : pAppend->append(pLiteral);
952 : 0 : nErg = 1;
953 : 0 : break;
954 : : case SQL_NODE_APPROXNUM:
955 [ # # ][ # # ]: 0 : if (m_xFormatter.is() && m_nFormatKey)
[ # # ]
956 : : {
957 : 0 : sal_Int16 nScale = 0;
958 : : try
959 : : {
960 [ # # ][ # # ]: 0 : Any aValue = getNumberFormatProperty( m_xFormatter, m_nFormatKey, ::rtl::OUString("Decimals") );
961 : 0 : aValue >>= nScale;
962 : : }
963 [ # # ]: 0 : catch( Exception& )
964 : : {
965 : : }
966 : :
967 [ # # ][ # # ]: 0 : pAppend->append(new OSQLInternalNode(stringToDouble(pLiteral->getTokenValue(),nScale),SQL_NODE_STRING));
[ # # ][ # # ]
968 : : }
969 : : else
970 [ # # ][ # # ]: 0 : pAppend->append(new OSQLInternalNode(pLiteral->getTokenValue(),SQL_NODE_STRING));
[ # # ]
971 : :
972 [ # # ][ # # ]: 0 : delete pLiteral;
973 : 0 : nErg = 1;
974 : 0 : break;
975 : : default:
976 [ # # ]: 0 : m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_VALUE_NO_LIKE);
977 : 0 : m_sErrorMessage = m_sErrorMessage.replaceAt(m_sErrorMessage.indexOf("#1"),2,pLiteral->getTokenValue());
978 : 0 : break;
979 : : }
980 : : }
981 : 0 : break;
982 : : default:
983 [ # # ]: 0 : m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_FIELD_NO_LIKE);
984 : 0 : break;
985 : : }
986 : 0 : return nErg;
987 : : }
988 : : //-----------------------------------------------------------------------------
989 : 0 : OSQLParseNode* OSQLParser::buildNode_Date(const double& fValue, sal_Int32 nType)
990 : : {
991 : 0 : ::rtl::OUString aEmptyString;
992 [ # # ][ # # ]: 0 : OSQLParseNode* pNewNode = new OSQLInternalNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::set_fct_spec));
[ # # ]
993 [ # # ][ # # ]: 0 : pNewNode->append(new OSQLInternalNode(::rtl::OUString("{"), SQL_NODE_PUNCTUATION));
[ # # ]
994 [ # # ][ # # ]: 0 : OSQLParseNode* pDateNode = new OSQLInternalNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::odbc_fct_spec));
[ # # ]
995 [ # # ]: 0 : pNewNode->append(pDateNode);
996 [ # # ][ # # ]: 0 : pNewNode->append(new OSQLInternalNode(::rtl::OUString("}"), SQL_NODE_PUNCTUATION));
[ # # ]
997 : :
998 [ # # # # ]: 0 : switch (nType)
999 : : {
1000 : : case DataType::DATE:
1001 : : {
1002 [ # # ][ # # ]: 0 : Date aDate = DBTypeConversion::toDate(fValue,DBTypeConversion::getNULLDate(m_xFormatter->getNumberFormatsSupplier()));
[ # # ][ # # ]
1003 [ # # ]: 0 : ::rtl::OUString aString = DBTypeConversion::toDateString(aDate);
1004 [ # # ][ # # ]: 0 : pDateNode->append(new OSQLInternalNode(aEmptyString, SQL_NODE_KEYWORD, SQL_TOKEN_D));
[ # # ]
1005 [ # # ][ # # ]: 0 : pDateNode->append(new OSQLInternalNode(aString, SQL_NODE_STRING));
[ # # ]
1006 : 0 : break;
1007 : : }
1008 : : case DataType::TIME:
1009 : : {
1010 [ # # ]: 0 : Time aTime = DBTypeConversion::toTime(fValue);
1011 [ # # ]: 0 : ::rtl::OUString aString = DBTypeConversion::toTimeString(aTime);
1012 [ # # ][ # # ]: 0 : pDateNode->append(new OSQLInternalNode(aEmptyString, SQL_NODE_KEYWORD, SQL_TOKEN_T));
[ # # ]
1013 [ # # ][ # # ]: 0 : pDateNode->append(new OSQLInternalNode(aString, SQL_NODE_STRING));
[ # # ]
1014 : 0 : break;
1015 : : }
1016 : : case DataType::TIMESTAMP:
1017 : : {
1018 [ # # ][ # # ]: 0 : DateTime aDateTime = DBTypeConversion::toDateTime(fValue,DBTypeConversion::getNULLDate(m_xFormatter->getNumberFormatsSupplier()));
[ # # ][ # # ]
1019 [ # # ][ # # ]: 0 : if (aDateTime.Seconds || aDateTime.Minutes || aDateTime.Hours)
[ # # ]
1020 : : {
1021 [ # # ]: 0 : ::rtl::OUString aString = DBTypeConversion::toDateTimeString(aDateTime);
1022 [ # # ][ # # ]: 0 : pDateNode->append(new OSQLInternalNode(aEmptyString, SQL_NODE_KEYWORD, SQL_TOKEN_TS));
[ # # ]
1023 [ # # ][ # # ]: 0 : pDateNode->append(new OSQLInternalNode(aString, SQL_NODE_STRING));
[ # # ]
1024 : : }
1025 : : else
1026 : : {
1027 : 0 : Date aDate(aDateTime.Day,aDateTime.Month,aDateTime.Year);
1028 [ # # ][ # # ]: 0 : pDateNode->append(new OSQLInternalNode(aEmptyString, SQL_NODE_KEYWORD, SQL_TOKEN_D));
[ # # ]
1029 [ # # ][ # # ]: 0 : pDateNode->append(new OSQLInternalNode(DBTypeConversion::toDateString(aDate), SQL_NODE_STRING));
[ # # ][ # # ]
1030 : : }
1031 : : break;
1032 : : }
1033 : : }
1034 : :
1035 : 0 : return pNewNode;
1036 : : }
1037 : : // -----------------------------------------------------------------------------
1038 : 0 : OSQLParseNode* OSQLParser::buildNode_STR_NUM(OSQLParseNode*& _pLiteral)
1039 : : {
1040 : 0 : OSQLParseNode* pReturn = NULL;
1041 [ # # ]: 0 : if ( _pLiteral )
1042 : : {
1043 [ # # ]: 0 : if (m_nFormatKey)
1044 : : {
1045 : 0 : sal_Int16 nScale = 0;
1046 : : try
1047 : : {
1048 [ # # ][ # # ]: 0 : Any aValue = getNumberFormatProperty( m_xFormatter, m_nFormatKey, ::rtl::OUString("Decimals") );
1049 : 0 : aValue >>= nScale;
1050 : : }
1051 [ # # ]: 0 : catch( Exception& )
1052 : : {
1053 : : }
1054 : :
1055 [ # # ][ # # ]: 0 : pReturn = new OSQLInternalNode(stringToDouble(_pLiteral->getTokenValue(),nScale),SQL_NODE_STRING);
[ # # ]
1056 : : }
1057 : : else
1058 [ # # ]: 0 : pReturn = new OSQLInternalNode(_pLiteral->getTokenValue(),SQL_NODE_STRING);
1059 : :
1060 [ # # ]: 0 : delete _pLiteral;
1061 : 0 : _pLiteral = NULL;
1062 : : }
1063 : 0 : return pReturn;
1064 : : }
1065 : : // -----------------------------------------------------------------------------
1066 : 0 : ::rtl::OUString OSQLParser::stringToDouble(const ::rtl::OUString& _rValue,sal_Int16 _nScale)
1067 : : {
1068 : 0 : ::rtl::OUString aValue;
1069 [ # # ]: 0 : if(!m_xCharClass.is())
1070 [ # # ][ # # ]: 0 : m_xCharClass = Reference<XCharacterClassification>(m_xServiceFactory->createInstance(::rtl::OUString("com.sun.star.i18n.CharacterClassification")),UNO_QUERY);
[ # # ][ # # ]
1071 [ # # ][ # # ]: 0 : if(m_xCharClass.is() && s_xLocaleData.is())
[ # # ]
1072 : : {
1073 : : try
1074 : : {
1075 [ # # ][ # # ]: 0 : ParseResult aResult = m_xCharClass->parsePredefinedToken(KParseType::ANY_NUMBER,_rValue,0,m_pData->aLocale,0,::rtl::OUString(),KParseType::ANY_NUMBER,::rtl::OUString());
1076 [ # # ][ # # ]: 0 : if((aResult.TokenType & KParseType::IDENTNAME) && aResult.EndPos == _rValue.getLength())
[ # # ]
1077 : : {
1078 : 0 : aValue = ::rtl::OUString::valueOf(aResult.Value);
1079 : 0 : sal_Int32 nPos = aValue.lastIndexOf('.');
1080 [ # # ]: 0 : if((nPos+_nScale) < aValue.getLength())
1081 : 0 : aValue = aValue.replaceAt(nPos+_nScale,aValue.getLength()-nPos-_nScale,::rtl::OUString());
1082 [ # # ][ # # ]: 0 : aValue = aValue.replaceAt(aValue.lastIndexOf('.'),1,s_xLocaleData->getLocaleItem(m_pData->aLocale).decimalSeparator);
1083 : : return aValue;
1084 [ # # ][ # # ]: 0 : }
1085 : : }
1086 [ # # ]: 0 : catch(Exception&)
1087 : : {
1088 : : }
1089 : : }
1090 : 0 : return aValue;
1091 : : }
1092 : : // -----------------------------------------------------------------------------
1093 : :
1094 : 1550 : ::osl::Mutex& OSQLParser::getMutex()
1095 : : {
1096 [ + + ][ + - ]: 1550 : static ::osl::Mutex aMutex;
[ + - ][ # # ]
1097 : 1550 : return aMutex;
1098 : : }
1099 : :
1100 : : //-----------------------------------------------------------------------------
1101 : 72 : OSQLParseNode* OSQLParser::predicateTree(::rtl::OUString& rErrorMessage, const ::rtl::OUString& rStatement,
1102 : : const Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter,
1103 : : const Reference< XPropertySet > & xField)
1104 : : {
1105 : :
1106 : :
1107 : : // mutex for parsing
1108 [ + + ][ + - ]: 72 : static ::osl::Mutex aMutex;
[ + - ][ # # ]
1109 : :
1110 : : // Guard the parsing
1111 [ + - ][ + - ]: 72 : ::osl::MutexGuard aGuard(getMutex());
1112 : : // must be reset
1113 [ + - ]: 72 : setParser(this);
1114 : :
1115 : :
1116 : : // reset the parser
1117 [ + - ]: 72 : m_xField = xField;
1118 [ + - ]: 72 : m_xFormatter = xFormatter;
1119 : :
1120 [ + - ]: 72 : if (m_xField.is())
1121 : : {
1122 : 72 : sal_Int32 nType=0;
1123 : : try
1124 : : {
1125 : : // get the field name
1126 : 72 : rtl::OUString aString;
1127 : :
1128 : : // retrieve the fields name
1129 : : // #75243# use the RealName of the column if there is any otherwise the name which could be the alias
1130 : : // of the field
1131 [ + - ][ + - ]: 72 : Reference< XPropertySetInfo> xInfo = m_xField->getPropertySetInfo();
1132 [ + - ][ + - ]: 72 : if ( xInfo->hasPropertyByName(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME)))
[ + - ][ + - ]
[ + - ]
1133 [ + - ][ + - ]: 72 : m_xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME)) >>= aString;
[ + - ][ + - ]
1134 : : else
1135 [ # # ][ # # ]: 0 : m_xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aString;
[ # # ][ # # ]
1136 : :
1137 : 72 : m_sFieldName = aString;
1138 : :
1139 : : // get the field format key
1140 [ + - ][ + - ]: 72 : if ( xInfo->hasPropertyByName(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FORMATKEY)))
[ + - ][ - + ]
[ + - ]
1141 [ # # ][ # # ]: 0 : m_xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FORMATKEY)) >>= m_nFormatKey;
[ # # ][ # # ]
1142 : : else
1143 : 72 : m_nFormatKey = 0;
1144 : :
1145 : : // get the field type
1146 [ + - ][ + - ]: 72 : m_xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)) >>= nType;
[ + - ][ + - ]
[ # # ]
1147 : : }
1148 [ # # ]: 0 : catch ( Exception& )
1149 : : {
1150 : : OSL_ASSERT(0);
1151 : : }
1152 : :
1153 [ - + ][ # # ]: 72 : if (m_nFormatKey && m_xFormatter.is())
[ - + ]
1154 : : {
1155 [ # # ][ # # ]: 0 : Any aValue = getNumberFormatProperty( m_xFormatter, m_nFormatKey, OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_LOCALE) );
[ # # ]
1156 : : OSL_ENSURE(aValue.getValueType() == ::getCppuType((const ::com::sun::star::lang::Locale*)0), "OSQLParser::PredicateTree : invalid language property !");
1157 : :
1158 [ # # ][ # # ]: 0 : if (aValue.getValueType() == ::getCppuType((const ::com::sun::star::lang::Locale*)0))
1159 [ # # ]: 0 : aValue >>= m_pData->aLocale;
1160 : : }
1161 : : else
1162 [ + - ]: 72 : m_pData->aLocale = m_pContext->getPreferredLocale();
1163 : :
1164 [ + - ]: 72 : if ( m_xFormatter.is() )
1165 : : {
1166 : : try
1167 : : {
1168 [ + - ][ + - ]: 72 : Reference< ::com::sun::star::util::XNumberFormatsSupplier > xFormatSup = m_xFormatter->getNumberFormatsSupplier();
1169 [ + - ]: 72 : if ( xFormatSup.is() )
1170 : : {
1171 [ + - ][ + - ]: 72 : Reference< ::com::sun::star::util::XNumberFormats > xFormats = xFormatSup->getNumberFormats();
1172 [ + - ]: 72 : if ( xFormats.is() )
1173 : : {
1174 : 72 : ::com::sun::star::lang::Locale aLocale;
1175 : 72 : aLocale.Language = ::rtl::OUString("en");
1176 : 72 : aLocale.Country = ::rtl::OUString("US");
1177 : 72 : ::rtl::OUString sFormat("YYYY-MM-DD");
1178 [ + - ][ + - ]: 72 : m_nDateFormatKey = xFormats->queryKey(sFormat,aLocale,sal_False);
1179 [ - + ]: 72 : if ( m_nDateFormatKey == sal_Int32(-1) )
1180 [ # # ][ # # ]: 72 : m_nDateFormatKey = xFormats->addNew(sFormat, aLocale);
1181 : 72 : }
1182 [ # # ]: 72 : }
1183 : : }
1184 [ # # ]: 0 : catch ( Exception& )
1185 : : {
1186 : : OSL_FAIL("DateFormatKey");
1187 : : }
1188 : : }
1189 : :
1190 [ - + - ]: 72 : switch (nType)
1191 : : {
1192 : : case DataType::DATE:
1193 : : case DataType::TIME:
1194 : : case DataType::TIMESTAMP:
1195 [ # # ]: 0 : s_pScanner->SetRule(s_pScanner->GetDATERule());
1196 : 0 : break;
1197 : : case DataType::CHAR:
1198 : : case DataType::VARCHAR:
1199 : : case DataType::LONGVARCHAR:
1200 : : case DataType::CLOB:
1201 [ + - ]: 72 : s_pScanner->SetRule(s_pScanner->GetSTRINGRule());
1202 : 72 : break;
1203 : : default:
1204 [ # # ][ # # ]: 0 : if ( s_xLocaleData->getLocaleItem( m_pData->aLocale ).decimalSeparator.toChar() == ',' )
[ # # ]
1205 [ # # ]: 0 : s_pScanner->SetRule(s_pScanner->GetGERRule());
1206 : : else
1207 [ # # ]: 72 : s_pScanner->SetRule(s_pScanner->GetENGRule());
1208 : : }
1209 : :
1210 : : }
1211 : : else
1212 [ # # ]: 0 : s_pScanner->SetRule(s_pScanner->GetSQLRule());
1213 : :
1214 [ + - ]: 72 : s_pScanner->prepareScan(rStatement, m_pContext, sal_True);
1215 : :
1216 : 72 : SQLyylval.pParseNode = NULL;
1217 : : // SQLyypvt = NULL;
1218 : 72 : m_pParseTree = NULL;
1219 : 72 : m_sErrorMessage= ::rtl::OUString();
1220 : :
1221 : : // Start the parser
1222 [ - + ][ + - ]: 72 : if (SQLyyparse() != 0)
1223 : : {
1224 : 0 : m_sFieldName= ::rtl::OUString();
1225 : 0 : m_xField.clear();
1226 : 0 : m_xFormatter.clear();
1227 : 0 : m_nFormatKey = 0;
1228 : 0 : m_nDateFormatKey = 0;
1229 : :
1230 [ # # ]: 0 : if (m_sErrorMessage.isEmpty())
1231 : 0 : m_sErrorMessage = s_pScanner->getErrorMessage();
1232 [ # # ]: 0 : if (m_sErrorMessage.isEmpty())
1233 [ # # ]: 0 : m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_GENERAL);
1234 : :
1235 : 0 : rErrorMessage = m_sErrorMessage;
1236 : :
1237 : : // clear the garbage collector
1238 [ # # ][ # # ]: 0 : (*s_pGarbageCollector)->clearAndDelete();
1239 : 0 : return NULL;
1240 : : }
1241 : : else
1242 : : {
1243 [ + - ][ + - ]: 72 : (*s_pGarbageCollector)->clear();
1244 : :
1245 : 72 : m_sFieldName= ::rtl::OUString();
1246 : 72 : m_xField.clear();
1247 : 72 : m_xFormatter.clear();
1248 : 72 : m_nFormatKey = 0;
1249 : 72 : m_nDateFormatKey = 0;
1250 : :
1251 : : // Return the result (the root parse node):
1252 : :
1253 : : // Instead, the parse method sets the member pParseTree and simply returns that
1254 : : OSL_ENSURE(m_pParseTree != NULL,"OSQLParser: Parser did not return a ParseTree!");
1255 : 72 : return m_pParseTree;
1256 [ + - ]: 72 : }
1257 : : }
1258 : :
1259 : : //=============================================================================
1260 : : //-----------------------------------------------------------------------------
1261 : 216 : OSQLParser::OSQLParser(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xServiceFactory,const IParseContext* _pContext)
1262 : : :m_pContext(_pContext)
1263 : : ,m_pParseTree(NULL)
1264 [ + - ]: 216 : ,m_pData( new OSQLParser_Data( _xServiceFactory ) )
1265 : : ,m_nFormatKey(0)
1266 : : ,m_nDateFormatKey(0)
1267 : 432 : ,m_xServiceFactory(_xServiceFactory)
1268 : : {
1269 : :
1270 : :
1271 [ + - ]: 216 : setParser(this);
1272 : :
1273 : : #ifdef SQLYYDEBUG
1274 : : #ifdef SQLYYDEBUG_ON
1275 : : SQLyydebug = 1;
1276 : : #endif
1277 : : #endif
1278 : :
1279 [ + - ][ + - ]: 216 : ::osl::MutexGuard aGuard(getMutex());
1280 : : // Do we have to initialize the data?
1281 [ + + ]: 216 : if (s_nRefCount == 0)
1282 : : {
1283 [ + - ]: 52 : s_pScanner = new OSQLScanner();
1284 [ + - ]: 52 : s_pScanner->setScanner();
1285 [ + - ][ + - ]: 52 : s_pGarbageCollector = new OSQLParseNodesGarbageCollector();
1286 : :
1287 [ + - ]: 52 : if(!s_xLocaleData.is())
1288 [ + - ][ + - ]: 52 : s_xLocaleData = Reference<XLocaleData>(m_xServiceFactory->createInstance(::rtl::OUString("com.sun.star.i18n.LocaleData")),UNO_QUERY);
[ + - ][ + - ]
1289 : :
1290 : : // reset to 0
1291 : 52 : memset(OSQLParser::s_nRuleIDs,0,sizeof(OSQLParser::s_nRuleIDs[0]) * (OSQLParseNode::rule_count+1));
1292 : :
1293 : : struct
1294 : 5148 : {
1295 : : OSQLParseNode::Rule eRule; // the parse node's ID for the rule
1296 : : ::rtl::OString sRuleName; // the name of the rule ("select_statement")
1297 : : } aRuleDescriptions[] =
1298 : : {
1299 : : { OSQLParseNode::select_statement, "select_statement" },
1300 : : { OSQLParseNode::table_exp, "table_exp" },
1301 : : { OSQLParseNode::table_ref_commalist, "table_ref_commalist" },
1302 : : { OSQLParseNode::table_ref, "table_ref" },
1303 : : { OSQLParseNode::catalog_name, "catalog_name" },
1304 : : { OSQLParseNode::schema_name, "schema_name" },
1305 : : { OSQLParseNode::table_name, "table_name" },
1306 : : { OSQLParseNode::opt_column_commalist, "opt_column_commalist" },
1307 : : { OSQLParseNode::column_commalist, "column_commalist" },
1308 : : { OSQLParseNode::column_ref_commalist, "column_ref_commalist" },
1309 : : { OSQLParseNode::column_ref, "column_ref" },
1310 : : { OSQLParseNode::opt_order_by_clause, "opt_order_by_clause" },
1311 : : { OSQLParseNode::ordering_spec_commalist, "ordering_spec_commalist" },
1312 : : { OSQLParseNode::ordering_spec, "ordering_spec" },
1313 : : { OSQLParseNode::opt_asc_desc, "opt_asc_desc" },
1314 : : { OSQLParseNode::where_clause, "where_clause" },
1315 : : { OSQLParseNode::opt_where_clause, "opt_where_clause" },
1316 : : { OSQLParseNode::search_condition, "search_condition" },
1317 : : { OSQLParseNode::comparison_predicate, "comparison_predicate" },
1318 : : { OSQLParseNode::between_predicate, "between_predicate" },
1319 : : { OSQLParseNode::like_predicate, "like_predicate" },
1320 : : { OSQLParseNode::opt_escape, "opt_escape" },
1321 : : { OSQLParseNode::test_for_null, "test_for_null" },
1322 : : { OSQLParseNode::scalar_exp_commalist, "scalar_exp_commalist" },
1323 : : { OSQLParseNode::scalar_exp, "scalar_exp" },
1324 : : { OSQLParseNode::parameter_ref, "parameter_ref" },
1325 : : { OSQLParseNode::parameter, "parameter" },
1326 : : { OSQLParseNode::general_set_fct, "general_set_fct" },
1327 : : { OSQLParseNode::range_variable, "range_variable" },
1328 : : { OSQLParseNode::column, "column" },
1329 : : { OSQLParseNode::delete_statement_positioned, "delete_statement_positioned" },
1330 : : { OSQLParseNode::delete_statement_searched, "delete_statement_searched" },
1331 : : { OSQLParseNode::update_statement_positioned, "update_statement_positioned" },
1332 : : { OSQLParseNode::update_statement_searched, "update_statement_searched" },
1333 : : { OSQLParseNode::assignment_commalist, "assignment_commalist" },
1334 : : { OSQLParseNode::assignment, "assignment" },
1335 : : { OSQLParseNode::values_or_query_spec, "values_or_query_spec" },
1336 : : { OSQLParseNode::insert_statement, "insert_statement" },
1337 : : { OSQLParseNode::insert_atom_commalist, "insert_atom_commalist" },
1338 : : { OSQLParseNode::insert_atom, "insert_atom" },
1339 : : { OSQLParseNode::predicate_check, "predicate_check" },
1340 : : { OSQLParseNode::from_clause, "from_clause" },
1341 : : { OSQLParseNode::qualified_join, "qualified_join" },
1342 : : { OSQLParseNode::cross_union, "cross_union" },
1343 : : { OSQLParseNode::select_sublist, "select_sublist" },
1344 : : { OSQLParseNode::derived_column, "derived_column" },
1345 : : { OSQLParseNode::column_val, "column_val" },
1346 : : { OSQLParseNode::set_fct_spec, "set_fct_spec" },
1347 : : { OSQLParseNode::boolean_term, "boolean_term" },
1348 : : { OSQLParseNode::boolean_primary, "boolean_primary" },
1349 : : { OSQLParseNode::num_value_exp, "num_value_exp" },
1350 : : { OSQLParseNode::join_type, "join_type" },
1351 : : { OSQLParseNode::position_exp, "position_exp" },
1352 : : { OSQLParseNode::extract_exp, "extract_exp" },
1353 : : { OSQLParseNode::length_exp, "length_exp" },
1354 : : { OSQLParseNode::char_value_fct, "char_value_fct" },
1355 : : { OSQLParseNode::odbc_call_spec, "odbc_call_spec" },
1356 : : { OSQLParseNode::in_predicate, "in_predicate" },
1357 : : { OSQLParseNode::existence_test, "existence_test" },
1358 : : { OSQLParseNode::unique_test, "unique_test" },
1359 : : { OSQLParseNode::all_or_any_predicate, "all_or_any_predicate" },
1360 : : { OSQLParseNode::named_columns_join, "named_columns_join" },
1361 : : { OSQLParseNode::join_condition, "join_condition" },
1362 : : { OSQLParseNode::joined_table, "joined_table" },
1363 : : { OSQLParseNode::boolean_factor, "boolean_factor" },
1364 : : { OSQLParseNode::sql_not, "sql_not" },
1365 : : { OSQLParseNode::boolean_test, "boolean_test" },
1366 : : { OSQLParseNode::manipulative_statement, "manipulative_statement" },
1367 : : { OSQLParseNode::subquery, "subquery" },
1368 : : { OSQLParseNode::value_exp_commalist, "value_exp_commalist" },
1369 : : { OSQLParseNode::odbc_fct_spec, "odbc_fct_spec" },
1370 : : { OSQLParseNode::union_statement, "union_statement" },
1371 : : { OSQLParseNode::outer_join_type, "outer_join_type" },
1372 : : { OSQLParseNode::char_value_exp, "char_value_exp" },
1373 : : { OSQLParseNode::term, "term" },
1374 : : { OSQLParseNode::value_exp_primary, "value_exp_primary" },
1375 : : { OSQLParseNode::value_exp, "value_exp" },
1376 : : { OSQLParseNode::selection, "selection" },
1377 : : { OSQLParseNode::fold, "fold" },
1378 : : { OSQLParseNode::char_substring_fct, "char_substring_fct" },
1379 : : { OSQLParseNode::factor, "factor" },
1380 : : { OSQLParseNode::base_table_def, "base_table_def" },
1381 : : { OSQLParseNode::base_table_element_commalist, "base_table_element_commalist" },
1382 : : { OSQLParseNode::data_type, "data_type" },
1383 : : { OSQLParseNode::column_def, "column_def" },
1384 : : { OSQLParseNode::table_node, "table_node" },
1385 : : { OSQLParseNode::as, "as" },
1386 : : { OSQLParseNode::op_column_commalist, "op_column_commalist" },
1387 : : { OSQLParseNode::table_primary_as_range_column, "table_primary_as_range_column" },
1388 : : { OSQLParseNode::datetime_primary, "datetime_primary" },
1389 : : { OSQLParseNode::concatenation, "concatenation" },
1390 : : { OSQLParseNode::char_factor, "char_factor" },
1391 : : { OSQLParseNode::bit_value_fct, "bit_value_fct" },
1392 : : { OSQLParseNode::comparison_predicate_part_2, "comparison_predicate_part_2" },
1393 : : { OSQLParseNode::parenthesized_boolean_value_expression, "parenthesized_boolean_value_expression" },
1394 : : { OSQLParseNode::character_string_type, "character_string_type" },
1395 : : { OSQLParseNode::other_like_predicate_part_2, "other_like_predicate_part_2" },
1396 : : { OSQLParseNode::between_predicate_part_2, "between_predicate_part_2" },
1397 : : { OSQLParseNode::cast_spec, "cast_spec" }
1398 : 5200 : };
1399 : 52 : size_t nRuleMapCount = sizeof( aRuleDescriptions ) / sizeof( aRuleDescriptions[0] );
1400 : : OSL_ENSURE( nRuleMapCount == size_t( OSQLParseNode::rule_count ), "OSQLParser::OSQLParser: added a new rule? Adjust this map!" );
1401 : :
1402 [ + + ]: 5200 : for ( size_t mapEntry = 0; mapEntry < nRuleMapCount; ++mapEntry )
1403 : : {
1404 : : // look up the rule description in the our identifier map
1405 [ + - ]: 5148 : sal_uInt32 nParserRuleID = StrToRuleID( aRuleDescriptions[ mapEntry ].sRuleName );
1406 : : // map the parser's rule ID to the OSQLParseNode::Rule
1407 [ + - ]: 5148 : s_aReverseRuleIDLookup[ nParserRuleID ] = aRuleDescriptions[ mapEntry ].eRule;
1408 : : // and map the OSQLParseNode::Rule to the parser's rule ID
1409 : 5148 : s_nRuleIDs[ aRuleDescriptions[ mapEntry ].eRule ] = nParserRuleID;
1410 [ + + ][ # # ]: 5200 : }
1411 : : }
1412 : 216 : ++s_nRefCount;
1413 : :
1414 [ + - ]: 216 : if (m_pContext == NULL)
1415 : : // take the default context
1416 : 216 : m_pContext = &s_aDefaultContext;
1417 : :
1418 [ + - ][ + - ]: 216 : m_pData->aLocale = m_pContext->getPreferredLocale();
1419 : 216 : }
1420 : :
1421 : : //-----------------------------------------------------------------------------
1422 : 216 : OSQLParser::~OSQLParser()
1423 : : {
1424 : : {
1425 [ + - ][ + - ]: 216 : ::osl::MutexGuard aGuard(getMutex());
1426 : : OSL_ENSURE(s_nRefCount > 0, "OSQLParser::~OSQLParser() : suspicious call : has a refcount of 0 !");
1427 [ + + ]: 216 : if (!--s_nRefCount)
1428 : : {
1429 [ + - ]: 52 : s_pScanner->setScanner(sal_True);
1430 [ + - ][ + - ]: 52 : delete s_pScanner;
1431 : 52 : s_pScanner = NULL;
1432 : :
1433 [ + - ][ + - ]: 52 : delete s_pGarbageCollector;
1434 : 52 : s_pGarbageCollector = NULL;
1435 : : // Is only set the first time, so we should delete it only when there are no more instances
1436 [ + - ]: 52 : s_xLocaleData = NULL;
1437 : :
1438 [ + - ]: 52 : RuleIDMap aEmpty;
1439 [ + - ]: 52 : s_aReverseRuleIDLookup.swap( aEmpty );
1440 : : }
1441 [ + - ]: 216 : m_pParseTree = NULL;
1442 : : }
1443 : 216 : }
1444 : : // -----------------------------------------------------------------------------
1445 : 0 : void OSQLParseNode::substituteParameterNames(OSQLParseNode* _pNode)
1446 : : {
1447 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::substituteParameterNames" );
1448 : 0 : sal_Int32 nCount = _pNode->count();
1449 [ # # ]: 0 : for(sal_Int32 i=0;i < nCount;++i)
1450 : : {
1451 : 0 : OSQLParseNode* pChildNode = _pNode->getChild(i);
1452 [ # # ][ # # ]: 0 : if(SQL_ISRULE(pChildNode,parameter) && pChildNode->count() > 1)
[ # # ][ # # ]
1453 : : {
1454 [ # # ][ # # ]: 0 : OSQLParseNode* pNewNode = new OSQLParseNode(::rtl::OUString("?") ,SQL_NODE_PUNCTUATION,0);
1455 [ # # ]: 0 : delete pChildNode->replace(pChildNode->getChild(0),pNewNode);
1456 : 0 : sal_Int32 nChildCount = pChildNode->count();
1457 [ # # ]: 0 : for(sal_Int32 j=1;j < nChildCount;++j)
1458 [ # # ]: 0 : delete pChildNode->removeAt(1);
1459 : : }
1460 : : else
1461 : 0 : substituteParameterNames(pChildNode);
1462 : :
1463 : : }
1464 : 0 : }
1465 : : // -----------------------------------------------------------------------------
1466 : 0 : bool OSQLParser::extractDate(OSQLParseNode* pLiteral,double& _rfValue)
1467 : : {
1468 [ # # ][ # # ]: 0 : Reference< XNumberFormatsSupplier > xFormatSup = m_xFormatter->getNumberFormatsSupplier();
1469 : 0 : Reference< XNumberFormatTypes > xFormatTypes;
1470 [ # # ]: 0 : if ( xFormatSup.is() )
1471 [ # # ][ # # ]: 0 : xFormatTypes = xFormatTypes.query( xFormatSup->getNumberFormats() );
[ # # ][ # # ]
[ # # ]
1472 : :
1473 : : // if there is no format key, yet, make sure we have a feasible one for our locale
1474 : : try
1475 : : {
1476 [ # # ][ # # ]: 0 : if ( !m_nFormatKey && xFormatTypes.is() )
[ # # ]
1477 [ # # ]: 0 : m_nFormatKey = ::dbtools::getDefaultNumberFormat( m_xField, xFormatTypes, m_pData->aLocale );
1478 : : }
1479 [ # # # # ]: 0 : catch( Exception& ) { }
1480 : 0 : ::rtl::OUString sValue = pLiteral->getTokenValue();
1481 : 0 : sal_Int32 nTryFormat = m_nFormatKey;
1482 [ # # ]: 0 : bool bSuccess = lcl_saveConvertToNumber( m_xFormatter, nTryFormat, sValue, _rfValue );
1483 : :
1484 : : // If our format key didn't do, try the default date format for our locale.
1485 [ # # ][ # # ]: 0 : if ( !bSuccess && xFormatTypes.is() )
[ # # ]
1486 : : {
1487 : : try
1488 : : {
1489 [ # # ][ # # ]: 0 : nTryFormat = xFormatTypes->getStandardFormat( NumberFormat::DATE, m_pData->aLocale );
1490 : : }
1491 [ # # # # ]: 0 : catch( Exception& ) { }
1492 [ # # ]: 0 : bSuccess = lcl_saveConvertToNumber( m_xFormatter, nTryFormat, sValue, _rfValue );
1493 : : }
1494 : :
1495 : : // if this also didn't do, try ISO format
1496 [ # # ][ # # ]: 0 : if ( !bSuccess && xFormatTypes.is() )
[ # # ]
1497 : : {
1498 : : try
1499 : : {
1500 [ # # ][ # # ]: 0 : nTryFormat = xFormatTypes->getFormatIndex( NumberFormatIndex::DATE_DIN_YYYYMMDD, m_pData->aLocale );
1501 : : }
1502 [ # # ]: 0 : catch( Exception& ) { }
1503 [ # # ]: 0 : bSuccess = lcl_saveConvertToNumber( m_xFormatter, nTryFormat, sValue, _rfValue );
1504 : : }
1505 : :
1506 : : // if this also didn't do, try fallback date format (en-US)
1507 [ # # ]: 0 : if ( !bSuccess )
1508 : : {
1509 : 0 : nTryFormat = m_nDateFormatKey;
1510 [ # # ]: 0 : bSuccess = lcl_saveConvertToNumber( m_xFormatter, nTryFormat, sValue, _rfValue );
1511 : : }
1512 : 0 : return bSuccess;
1513 : : }
1514 : : // -----------------------------------------------------------------------------
1515 : 0 : OSQLParseNode* OSQLParser::buildDate(sal_Int32 _nType,OSQLParseNode*& pLiteral)
1516 : : {
1517 : : // try converting the string into a date, according to our format key
1518 : 0 : double fValue = 0.0;
1519 : 0 : OSQLParseNode* pFCTNode = NULL;
1520 : :
1521 [ # # ][ # # ]: 0 : if ( extractDate(pLiteral,fValue) )
1522 [ # # ]: 0 : pFCTNode = buildNode_Date( fValue, _nType);
1523 : :
1524 [ # # ][ # # ]: 0 : delete pLiteral;
1525 : 0 : pLiteral = NULL;
1526 : :
1527 [ # # ]: 0 : if ( !pFCTNode )
1528 [ # # ]: 0 : m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_DATE_COMPARE);
1529 : :
1530 : 0 : return pFCTNode;
1531 : : }
1532 : : // -----------------------------------------------------------------------------
1533 : : //-----------------------------------------------------------------------------
1534 : 2522 : OSQLParseNode::OSQLParseNode(const sal_Char * pNewValue,
1535 : : SQLNodeType eNewNodeType,
1536 : : sal_uInt32 nNewNodeID)
1537 : : :m_pParent(NULL)
1538 : 2522 : ,m_aNodeValue(pNewValue,strlen(pNewValue),RTL_TEXTENCODING_UTF8)
1539 : : ,m_eNodeType(eNewNodeType)
1540 [ + - ]: 2522 : ,m_nNodeID(nNewNodeID)
1541 : : {
1542 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::OSQLParseNode" );
1543 : :
1544 : : OSL_ENSURE(m_eNodeType >= SQL_NODE_RULE && m_eNodeType <= SQL_NODE_CONCAT,"OSQLParseNode: created with invalid NodeType");
1545 : 2522 : }
1546 : : //-----------------------------------------------------------------------------
1547 : 0 : OSQLParseNode::OSQLParseNode(const ::rtl::OString &_rNewValue,
1548 : : SQLNodeType eNewNodeType,
1549 : : sal_uInt32 nNewNodeID)
1550 : : :m_pParent(NULL)
1551 : : ,m_aNodeValue(rtl::OStringToOUString(_rNewValue,RTL_TEXTENCODING_UTF8))
1552 : : ,m_eNodeType(eNewNodeType)
1553 [ # # ]: 0 : ,m_nNodeID(nNewNodeID)
1554 : : {
1555 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::OSQLParseNode" );
1556 : :
1557 : : OSL_ENSURE(m_eNodeType >= SQL_NODE_RULE && m_eNodeType <= SQL_NODE_CONCAT,"OSQLParseNode: created with invalid NodeType");
1558 : 0 : }
1559 : : //-----------------------------------------------------------------------------
1560 : 24118 : OSQLParseNode::OSQLParseNode(const ::rtl::OUString &_rNewValue,
1561 : : SQLNodeType eNewNodeType,
1562 : : sal_uInt32 nNewNodeID)
1563 : : :m_pParent(NULL)
1564 : : ,m_aNodeValue(_rNewValue)
1565 : : ,m_eNodeType(eNewNodeType)
1566 : 24118 : ,m_nNodeID(nNewNodeID)
1567 : : {
1568 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::OSQLParseNode" );
1569 : :
1570 : : OSL_ENSURE(m_eNodeType >= SQL_NODE_RULE && m_eNodeType <= SQL_NODE_CONCAT,"OSQLParseNode: created with invalid NodeType");
1571 : 24118 : }
1572 : : //-----------------------------------------------------------------------------
1573 : 0 : OSQLParseNode::OSQLParseNode(const OSQLParseNode& rParseNode)
1574 : : {
1575 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::OSQLParseNode" );
1576 : :
1577 : : // Set the getParent to NULL
1578 : 0 : m_pParent = NULL;
1579 : :
1580 : : // Copy the members
1581 : 0 : m_aNodeValue = rParseNode.m_aNodeValue;
1582 : 0 : m_eNodeType = rParseNode.m_eNodeType;
1583 : 0 : m_nNodeID = rParseNode.m_nNodeID;
1584 : :
1585 : :
1586 : : // Remember that we derived from Container. According to SV-Help the Container's
1587 : : // copy ctor creates a new Container with the same pointers for content.
1588 : : // This means after copying the Container, for all non-NULL pointers a copy is
1589 : : // created and reattached instead of the old pointer.
1590 : :
1591 : : // If not a leaf, then process SubTrees
1592 [ # # ][ # # ]: 0 : for (OSQLParseNodes::const_iterator i = rParseNode.m_aChildren.begin();
1593 : 0 : i != rParseNode.m_aChildren.end(); ++i)
1594 [ # # ][ # # ]: 0 : append(new OSQLParseNode(**i));
[ # # ]
1595 : 0 : }
1596 : : // -----------------------------------------------------------------------------
1597 : : //-----------------------------------------------------------------------------
1598 : 0 : OSQLParseNode& OSQLParseNode::operator=(const OSQLParseNode& rParseNode)
1599 : : {
1600 [ # # ]: 0 : if (this != &rParseNode)
1601 : : {
1602 : : // Copy the members - pParent remains the same
1603 : 0 : m_aNodeValue = rParseNode.m_aNodeValue;
1604 : 0 : m_eNodeType = rParseNode.m_eNodeType;
1605 : 0 : m_nNodeID = rParseNode.m_nNodeID;
1606 : :
1607 [ # # ][ # # ]: 0 : for (OSQLParseNodes::const_iterator i = m_aChildren.begin();
[ # # ]
1608 : 0 : i != m_aChildren.end(); ++i)
1609 [ # # ][ # # ]: 0 : delete *i;
1610 : :
1611 : 0 : m_aChildren.clear();
1612 : :
1613 [ # # ][ # # ]: 0 : for (OSQLParseNodes::const_iterator j = rParseNode.m_aChildren.begin();
1614 : 0 : j != rParseNode.m_aChildren.end(); ++j)
1615 [ # # ][ # # ]: 0 : append(new OSQLParseNode(**j));
[ # # ]
1616 : : }
1617 : 0 : return *this;
1618 : : }
1619 : :
1620 : : //-----------------------------------------------------------------------------
1621 : 1008 : sal_Bool OSQLParseNode::operator==(OSQLParseNode& rParseNode) const
1622 : : {
1623 : : // The members must be equal
1624 : : sal_Bool bResult = (m_nNodeID == rParseNode.m_nNodeID) &&
1625 : : (m_eNodeType == rParseNode.m_eNodeType) &&
1626 : 744 : (m_aNodeValue == rParseNode.m_aNodeValue) &&
1627 [ + + ]: 1752 : count() == rParseNode.count();
[ + - + + ]
[ + - ]
1628 : :
1629 : : // Parameters are not equal!
1630 [ + + ][ + + ]: 1008 : bResult = bResult && !SQL_ISRULE(this, parameter);
[ + - ]
1631 : :
1632 : : // compare children
1633 [ + + ][ + + ]: 1544 : for (sal_uInt32 i=0; bResult && i < count(); i++)
[ + + ]
1634 : 536 : bResult = *getChild(i) == *rParseNode.getChild(i);
1635 : :
1636 : 1008 : return bResult;
1637 : : }
1638 : :
1639 : : //-----------------------------------------------------------------------------
1640 : 26640 : OSQLParseNode::~OSQLParseNode()
1641 : : {
1642 [ + - ][ + - ]: 105212 : for (OSQLParseNodes::const_iterator i = m_aChildren.begin();
[ + + ]
1643 : 52606 : i != m_aChildren.end(); ++i)
1644 [ + - ][ + - ]: 25966 : delete *i;
1645 : 26640 : m_aChildren.clear();
1646 [ - + ]: 26640 : }
1647 : :
1648 : : //-----------------------------------------------------------------------------
1649 : 26078 : void OSQLParseNode::append(OSQLParseNode* pNewNode)
1650 : : {
1651 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::append" );
1652 : :
1653 : : OSL_ENSURE(pNewNode != NULL, "OSQLParseNode: invalid NewSubTree");
1654 : : OSL_ENSURE(pNewNode->getParent() == NULL, "OSQLParseNode: Node is not an orphan");
1655 : : OSL_ENSURE(::std::find(m_aChildren.begin(), m_aChildren.end(), pNewNode) == m_aChildren.end(),
1656 : : "OSQLParseNode::append() Node already element of parent");
1657 : :
1658 : : // Create connection to getParent
1659 : 26078 : pNewNode->setParent( this );
1660 : : // and attach the SubTree at the end
1661 : 26078 : m_aChildren.push_back(pNewNode);
1662 : 26078 : }
1663 : : // -----------------------------------------------------------------------------
1664 : 0 : sal_Bool OSQLParseNode::addDateValue(::rtl::OUStringBuffer& rString, const SQLParseNodeParameter& rParam) const
1665 : : {
1666 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::addDateValue" );
1667 : : // special display for date/time values
1668 [ # # ][ # # ]: 0 : if (SQL_ISRULE(this,set_fct_spec) && SQL_ISPUNCTUATION(m_aChildren[0],"{"))
[ # # ][ # # ]
[ # # ]
1669 : : {
1670 : 0 : const OSQLParseNode* pODBCNode = m_aChildren[1];
1671 : 0 : const OSQLParseNode* pODBCNodeChild = pODBCNode->m_aChildren[0];
1672 : :
1673 [ # # ][ # # : 0 : if (pODBCNodeChild->getNodeType() == SQL_NODE_KEYWORD && (
# # # # #
# # # # #
# # ]
1674 : 0 : SQL_ISTOKEN(pODBCNodeChild, D) ||
1675 : 0 : SQL_ISTOKEN(pODBCNodeChild, T) ||
1676 : 0 : SQL_ISTOKEN(pODBCNodeChild, TS) ))
1677 : : {
1678 : 0 : ::rtl::OUString suQuote(::rtl::OUString("'"));
1679 [ # # ]: 0 : if (rParam.bPredicate)
1680 : : {
1681 [ # # ][ # # ]: 0 : if (rParam.aMetaData.shouldEscapeDateTime())
1682 : : {
1683 : 0 : suQuote = ::rtl::OUString("#");
1684 : : }
1685 : : }
1686 : : else
1687 : : {
1688 [ # # ][ # # ]: 0 : if (rParam.aMetaData.shouldEscapeDateTime())
1689 : : {
1690 : : // suQuote = ::rtl::OUString("'");
1691 : 0 : return sal_False;
1692 : : }
1693 : : }
1694 : :
1695 [ # # ]: 0 : if (rString.getLength())
1696 [ # # ]: 0 : rString.appendAscii(" ");
1697 [ # # ]: 0 : rString.append(suQuote);
1698 [ # # ]: 0 : const ::rtl::OUString sTokenValue = pODBCNode->m_aChildren[1]->getTokenValue();
1699 [ # # ][ # # ]: 0 : if (SQL_ISTOKEN(pODBCNodeChild, D))
[ # # ]
1700 : : {
1701 [ # # ][ # # ]: 0 : rString.append(rParam.bPredicate ? convertDateString(rParam, sTokenValue) : sTokenValue);
[ # # ]
1702 : : }
1703 [ # # ][ # # ]: 0 : else if (SQL_ISTOKEN(pODBCNodeChild, T))
[ # # ]
1704 : : {
1705 [ # # ][ # # ]: 0 : rString.append(rParam.bPredicate ? convertTimeString(rParam, sTokenValue) : sTokenValue);
[ # # ]
1706 : : }
1707 : : else
1708 : : {
1709 [ # # ][ # # ]: 0 : rString.append(rParam.bPredicate ? convertDateTimeString(rParam, sTokenValue) : sTokenValue);
[ # # ]
1710 : : }
1711 [ # # ]: 0 : rString.append(suQuote);
1712 : 0 : return sal_True;
1713 : : }
1714 : : }
1715 : 0 : return sal_False;
1716 : : }
1717 : : // -----------------------------------------------------------------------------
1718 : 0 : void OSQLParseNode::replaceNodeValue(const ::rtl::OUString& rTableAlias,const ::rtl::OUString& rColumnName)
1719 : : {
1720 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::replaceNodeValue" );
1721 [ # # ]: 0 : for (sal_uInt32 i=0;i<count();++i)
1722 : : {
1723 [ # # ][ # # ]: 0 : if (SQL_ISRULE(this,column_ref) && count() == 1 && getChild(0)->getTokenValue() == rColumnName)
[ # # ][ # # ]
[ # # ]
1724 : : {
1725 : 0 : OSQLParseNode * pCol = removeAt((sal_uInt32)0);
1726 [ # # ]: 0 : append(new OSQLParseNode(rTableAlias,SQL_NODE_NAME));
1727 [ # # ][ # # ]: 0 : append(new OSQLParseNode(::rtl::OUString("."),SQL_NODE_PUNCTUATION));
[ # # ]
1728 : 0 : append(pCol);
1729 : : }
1730 : : else
1731 : 0 : getChild(i)->replaceNodeValue(rTableAlias,rColumnName);
1732 : : }
1733 : 0 : }
1734 : : //-----------------------------------------------------------------------------
1735 : 360 : OSQLParseNode* OSQLParseNode::getByRule(OSQLParseNode::Rule eRule) const
1736 : : {
1737 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::getByRule" );
1738 : 360 : OSQLParseNode* pRetNode = 0;
1739 [ + + ][ - + ]: 360 : if (isRule() && OSQLParser::RuleID(eRule) == getRuleID())
[ - + ]
1740 : 0 : pRetNode = (OSQLParseNode*)this;
1741 : : else
1742 : : {
1743 [ + - ][ + + ]: 1944 : for (OSQLParseNodes::const_iterator i = m_aChildren.begin();
[ + + ]
1744 [ + - ][ + - ]: 1296 : !pRetNode && i != m_aChildren.end(); ++i)
[ # # ]
1745 [ + - ]: 288 : pRetNode = (*i)->getByRule(eRule);
1746 : : }
1747 : 360 : return pRetNode;
1748 : : }
1749 : : //-----------------------------------------------------------------------------
1750 : 0 : OSQLParseNode* MakeANDNode(OSQLParseNode *pLeftLeaf,OSQLParseNode *pRightLeaf)
1751 : : {
1752 [ # # ][ # # ]: 0 : OSQLParseNode* pNewNode = new OSQLParseNode(::rtl::OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::boolean_term));
[ # # ]
1753 : 0 : pNewNode->append(pLeftLeaf);
1754 [ # # ][ # # ]: 0 : pNewNode->append(new OSQLParseNode(::rtl::OUString("AND"),SQL_NODE_KEYWORD,SQL_TOKEN_AND));
[ # # ]
1755 : 0 : pNewNode->append(pRightLeaf);
1756 : 0 : return pNewNode;
1757 : : }
1758 : : //-----------------------------------------------------------------------------
1759 : 0 : OSQLParseNode* MakeORNode(OSQLParseNode *pLeftLeaf,OSQLParseNode *pRightLeaf)
1760 : : {
1761 [ # # ][ # # ]: 0 : OSQLParseNode* pNewNode = new OSQLParseNode(::rtl::OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::search_condition));
[ # # ]
1762 : 0 : pNewNode->append(pLeftLeaf);
1763 [ # # ][ # # ]: 0 : pNewNode->append(new OSQLParseNode(::rtl::OUString("OR"),SQL_NODE_KEYWORD,SQL_TOKEN_OR));
[ # # ]
1764 : 0 : pNewNode->append(pRightLeaf);
1765 : 0 : return pNewNode;
1766 : : }
1767 : : //-----------------------------------------------------------------------------
1768 : 136 : void OSQLParseNode::disjunctiveNormalForm(OSQLParseNode*& pSearchCondition)
1769 : : {
1770 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::disjunctiveNormalForm" );
1771 [ - + ]: 136 : if(!pSearchCondition) // no where condition at entry point
1772 : 136 : return;
1773 : :
1774 : 136 : OSQLParseNode::absorptions(pSearchCondition);
1775 : : // '(' search_condition ')'
1776 [ - + ][ - + ]: 136 : if (SQL_ISRULE(pSearchCondition,boolean_primary))
[ + - ]
1777 : : {
1778 [ # # ]: 0 : OSQLParseNode* pLeft = pSearchCondition->getChild(1);
1779 [ # # ]: 0 : disjunctiveNormalForm(pLeft);
1780 : : }
1781 : : // search_condition SQL_TOKEN_OR boolean_term
1782 [ + - ][ + + ]: 136 : else if (SQL_ISRULE(pSearchCondition,search_condition))
[ + + ]
1783 : : {
1784 [ + - ]: 32 : OSQLParseNode* pLeft = pSearchCondition->getChild(0);
1785 [ + - ]: 32 : disjunctiveNormalForm(pLeft);
1786 : :
1787 [ + - ]: 32 : OSQLParseNode* pRight = pSearchCondition->getChild(2);
1788 [ + - ]: 32 : disjunctiveNormalForm(pRight);
1789 : : }
1790 : : // boolean_term SQL_TOKEN_AND boolean_factor
1791 [ + - ][ + + ]: 104 : else if (SQL_ISRULE(pSearchCondition,boolean_term))
[ + + ]
1792 : : {
1793 [ + - ]: 32 : OSQLParseNode* pLeft = pSearchCondition->getChild(0);
1794 [ + - ]: 32 : disjunctiveNormalForm(pLeft);
1795 : :
1796 [ + - ]: 32 : OSQLParseNode* pRight = pSearchCondition->getChild(2);
1797 [ + - ]: 32 : disjunctiveNormalForm(pRight);
1798 : :
1799 : 32 : OSQLParseNode* pNewNode = NULL;
1800 : : // '(' search_condition ')' on left side
1801 [ + - ][ + - ]: 32 : if(pLeft->count() == 3 && SQL_ISRULE(pLeft,boolean_primary) && SQL_ISRULE(pLeft->getChild(1),search_condition))
[ + - ][ - + ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ - + ]
1802 : : {
1803 : : // and-or tree on left side
1804 [ # # ]: 0 : OSQLParseNode* pOr = pLeft->getChild(1);
1805 : 0 : OSQLParseNode* pNewLeft = NULL;
1806 : 0 : OSQLParseNode* pNewRight = NULL;
1807 : :
1808 : : // cut right from parent
1809 [ # # ]: 0 : pSearchCondition->removeAt(2);
1810 : :
1811 [ # # ][ # # ]: 0 : pNewRight = MakeANDNode(pOr->removeAt(2) ,pRight);
1812 [ # # ][ # # ]: 0 : pNewLeft = MakeANDNode(pOr->removeAt((sal_uInt32)0) ,new OSQLParseNode(*pRight));
[ # # ][ # # ]
1813 [ # # ]: 0 : pNewNode = MakeORNode(pNewLeft,pNewRight);
1814 : : // and append new Node
1815 [ # # ]: 0 : replaceAndReset(pSearchCondition,pNewNode);
1816 : :
1817 [ # # ]: 0 : disjunctiveNormalForm(pSearchCondition);
1818 : : }
1819 [ + - ][ + - ]: 32 : else if(pRight->count() == 3 && SQL_ISRULE(pRight,boolean_primary) && SQL_ISRULE(pRight->getChild(1),search_condition))
[ + - ][ - + ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ - + ]
1820 : : { // '(' search_condition ')' on right side
1821 : : // and-or tree on right side
1822 : : // a and (b or c)
1823 [ # # ]: 0 : OSQLParseNode* pOr = pRight->getChild(1);
1824 : 0 : OSQLParseNode* pNewLeft = NULL;
1825 : 0 : OSQLParseNode* pNewRight = NULL;
1826 : :
1827 : : // cut left from parent
1828 [ # # ]: 0 : pSearchCondition->removeAt((sal_uInt32)0);
1829 : :
1830 [ # # ][ # # ]: 0 : pNewRight = MakeANDNode(pLeft,pOr->removeAt(2));
1831 [ # # ][ # # ]: 0 : pNewLeft = MakeANDNode(new OSQLParseNode(*pLeft),pOr->removeAt((sal_uInt32)0));
[ # # ][ # # ]
1832 [ # # ]: 0 : pNewNode = MakeORNode(pNewLeft,pNewRight);
1833 : :
1834 : : // and append new Node
1835 [ # # ]: 0 : replaceAndReset(pSearchCondition,pNewNode);
1836 [ # # ]: 0 : disjunctiveNormalForm(pSearchCondition);
1837 : : }
1838 [ + - ][ + - ]: 32 : else if(SQL_ISRULE(pLeft,boolean_primary) && (!SQL_ISRULE(pLeft->getChild(1),search_condition) || !SQL_ISRULE(pLeft->getChild(1),boolean_term)))
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ - + ]
1839 [ # # ][ # # ]: 0 : pSearchCondition->replace(pLeft, pLeft->removeAt(1));
1840 [ + - ][ + - ]: 32 : else if(SQL_ISRULE(pRight,boolean_primary) && (!SQL_ISRULE(pRight->getChild(1),search_condition) || !SQL_ISRULE(pRight->getChild(1),boolean_term)))
[ - + ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ - + ]
1841 [ # # ][ # # ]: 32 : pSearchCondition->replace(pRight, pRight->removeAt(1));
1842 : : }
1843 : : }
1844 : : //-----------------------------------------------------------------------------
1845 : 176 : void OSQLParseNode::negateSearchCondition(OSQLParseNode*& pSearchCondition,sal_Bool bNegate)
1846 : : {
1847 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::negateSearchCondition" );
1848 [ - + ]: 176 : if(!pSearchCondition) // no where condition at entry point
1849 : 176 : return;
1850 : : // '(' search_condition ')'
1851 [ + - ][ + - ]: 176 : if (pSearchCondition->count() == 3 && SQL_ISRULE(pSearchCondition,boolean_primary))
[ + + ][ + + ]
1852 : : {
1853 [ + - ]: 40 : OSQLParseNode* pRight = pSearchCondition->getChild(1);
1854 [ + - ]: 40 : negateSearchCondition(pRight,bNegate);
1855 : : }
1856 : : // search_condition SQL_TOKEN_OR boolean_term
1857 [ + - ][ + + ]: 136 : else if (SQL_ISRULE(pSearchCondition,search_condition))
[ + + ]
1858 : : {
1859 [ + - ]: 32 : OSQLParseNode* pLeft = pSearchCondition->getChild(0);
1860 [ + - ]: 32 : OSQLParseNode* pRight = pSearchCondition->getChild(2);
1861 [ - + ]: 32 : if(bNegate)
1862 : : {
1863 [ # # ][ # # ]: 0 : OSQLParseNode* pNewNode = new OSQLParseNode(::rtl::OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::boolean_term));
[ # # ]
1864 [ # # ][ # # ]: 0 : pNewNode->append(pSearchCondition->removeAt((sal_uInt32)0));
1865 [ # # ][ # # ]: 0 : pNewNode->append(new OSQLParseNode(::rtl::OUString("AND"),SQL_NODE_KEYWORD,SQL_TOKEN_AND));
[ # # ]
1866 [ # # ][ # # ]: 0 : pNewNode->append(pSearchCondition->removeAt((sal_uInt32)1));
1867 [ # # ]: 0 : replaceAndReset(pSearchCondition,pNewNode);
1868 : :
1869 [ # # ]: 0 : pLeft = pNewNode->getChild(0);
1870 [ # # ]: 0 : pRight = pNewNode->getChild(2);
1871 : : }
1872 : :
1873 [ + - ]: 32 : negateSearchCondition(pLeft,bNegate);
1874 [ + - ]: 32 : negateSearchCondition(pRight,bNegate);
1875 : : }
1876 : : // boolean_term SQL_TOKEN_AND boolean_factor
1877 [ + - ][ + + ]: 104 : else if (SQL_ISRULE(pSearchCondition,boolean_term))
[ + + ]
1878 : : {
1879 [ + - ]: 32 : OSQLParseNode* pLeft = pSearchCondition->getChild(0);
1880 [ + - ]: 32 : OSQLParseNode* pRight = pSearchCondition->getChild(2);
1881 [ - + ]: 32 : if(bNegate)
1882 : : {
1883 [ # # ][ # # ]: 0 : OSQLParseNode* pNewNode = new OSQLParseNode(::rtl::OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::search_condition));
[ # # ]
1884 [ # # ][ # # ]: 0 : pNewNode->append(pSearchCondition->removeAt((sal_uInt32)0));
1885 [ # # ][ # # ]: 0 : pNewNode->append(new OSQLParseNode(::rtl::OUString("OR"),SQL_NODE_KEYWORD,SQL_TOKEN_OR));
[ # # ]
1886 [ # # ][ # # ]: 0 : pNewNode->append(pSearchCondition->removeAt((sal_uInt32)1));
1887 [ # # ]: 0 : replaceAndReset(pSearchCondition,pNewNode);
1888 : :
1889 [ # # ]: 0 : pLeft = pNewNode->getChild(0);
1890 [ # # ]: 0 : pRight = pNewNode->getChild(2);
1891 : : }
1892 : :
1893 [ + - ]: 32 : negateSearchCondition(pLeft,bNegate);
1894 [ + - ]: 32 : negateSearchCondition(pRight,bNegate);
1895 : : }
1896 : : // SQL_TOKEN_NOT ( boolean_test )
1897 [ + - ][ - + ]: 72 : else if (SQL_ISRULE(pSearchCondition,boolean_factor))
[ - + ]
1898 : : {
1899 : 0 : OSQLParseNode *pNot = pSearchCondition->removeAt((sal_uInt32)0);
1900 [ # # ]: 0 : delete pNot;
1901 : 0 : OSQLParseNode *pBooleanTest = pSearchCondition->removeAt((sal_uInt32)0);
1902 : : // TODO is this needed // pBooleanTest->setParent(NULL);
1903 : 0 : replaceAndReset(pSearchCondition,pBooleanTest);
1904 : :
1905 [ # # ]: 0 : if (!bNegate)
1906 : 0 : negateSearchCondition(pSearchCondition,sal_True); // negate all deeper values
1907 : : }
1908 : : // row_value_constructor comparison row_value_constructor
1909 : : // row_value_constructor comparison any_all_some subquery
1910 [ - + ][ # # ]: 72 : else if(bNegate && (SQL_ISRULE(pSearchCondition,comparison_predicate) || SQL_ISRULE(pSearchCondition,all_or_any_predicate)))
[ # # ][ # # ]
[ # # ][ - + ]
1911 : : {
1912 : 0 : OSQLParseNode* pComparison = pSearchCondition->getChild(1);
1913 : 0 : OSQLParseNode* pNewComparison = NULL;
1914 [ # # # # : 0 : switch(pComparison->getNodeType())
# # # ]
1915 : : {
1916 : : case SQL_NODE_EQUAL:
1917 [ # # ][ # # ]: 0 : pNewComparison = new OSQLParseNode(::rtl::OUString("<>"),SQL_NODE_NOTEQUAL,SQL_NOTEQUAL);
1918 : 0 : break;
1919 : : case SQL_NODE_LESS:
1920 [ # # ][ # # ]: 0 : pNewComparison = new OSQLParseNode(::rtl::OUString(">="),SQL_NODE_GREATEQ,SQL_GREATEQ);
1921 : 0 : break;
1922 : : case SQL_NODE_GREAT:
1923 [ # # ][ # # ]: 0 : pNewComparison = new OSQLParseNode(::rtl::OUString("<="),SQL_NODE_LESSEQ,SQL_LESSEQ);
1924 : 0 : break;
1925 : : case SQL_NODE_LESSEQ:
1926 [ # # ][ # # ]: 0 : pNewComparison = new OSQLParseNode(::rtl::OUString(">"),SQL_NODE_GREAT,SQL_GREAT);
1927 : 0 : break;
1928 : : case SQL_NODE_GREATEQ:
1929 [ # # ][ # # ]: 0 : pNewComparison = new OSQLParseNode(::rtl::OUString("<"),SQL_NODE_LESS,SQL_LESS);
1930 : 0 : break;
1931 : : case SQL_NODE_NOTEQUAL:
1932 [ # # ][ # # ]: 0 : pNewComparison = new OSQLParseNode(::rtl::OUString("="),SQL_NODE_EQUAL,SQL_EQUAL);
1933 : 0 : break;
1934 : : default:
1935 : : OSL_FAIL( "OSQLParseNode::negateSearchCondition: unexpected node type!" );
1936 : 0 : break;
1937 : : }
1938 : 0 : pSearchCondition->replace(pComparison, pNewComparison);
1939 [ # # ]: 0 : delete pComparison;
1940 : : }
1941 : :
1942 [ - + ][ # # ]: 72 : else if(bNegate && (SQL_ISRULE(pSearchCondition,test_for_null) || SQL_ISRULE(pSearchCondition,in_predicate) ||
[ # # ][ # # ]
[ # # # #
# # # # #
# ][ - + ]
1943 : 0 : SQL_ISRULE(pSearchCondition,between_predicate) || SQL_ISRULE(pSearchCondition,boolean_test) ))
1944 : : {
1945 : 0 : OSQLParseNode* pPart2 = pSearchCondition;
1946 [ # # ][ # # ]: 0 : if ( !SQL_ISRULE(pSearchCondition,boolean_test) )
[ # # ]
1947 : 0 : pPart2 = pSearchCondition->getChild(1);
1948 : 0 : sal_uInt32 nNotPos = 0;
1949 [ # # ][ # # ]: 0 : if ( SQL_ISRULE( pSearchCondition, test_for_null ) )
[ # # ]
1950 : 0 : nNotPos = 1;
1951 [ # # ][ # # ]: 0 : else if ( SQL_ISRULE( pSearchCondition, boolean_test ) )
[ # # ]
1952 : 0 : nNotPos = 2;
1953 : :
1954 : 0 : OSQLParseNode* pNot = pPart2->getChild(nNotPos);
1955 : 0 : OSQLParseNode* pNotNot = NULL;
1956 [ # # ]: 0 : if(pNot->isRule())
1957 [ # # ][ # # ]: 0 : pNotNot = new OSQLParseNode(::rtl::OUString("NOT"),SQL_NODE_KEYWORD,SQL_TOKEN_NOT);
1958 : : else
1959 [ # # ][ # # ]: 0 : pNotNot = new OSQLParseNode(::rtl::OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::sql_not));
[ # # ]
1960 : 0 : pPart2->replace(pNot, pNotNot);
1961 [ # # ]: 0 : delete pNot;
1962 : : }
1963 [ - + ][ # # ]: 72 : else if(bNegate && (SQL_ISRULE(pSearchCondition,like_predicate)))
[ # # ][ - + ]
1964 : : {
1965 : 0 : OSQLParseNode* pNot = pSearchCondition->getChild( 1 )->getChild( 0 );
1966 : 0 : OSQLParseNode* pNotNot = NULL;
1967 [ # # ]: 0 : if(pNot->isRule())
1968 [ # # ][ # # ]: 0 : pNotNot = new OSQLParseNode(::rtl::OUString("NOT"),SQL_NODE_KEYWORD,SQL_TOKEN_NOT);
1969 : : else
1970 [ # # ][ # # ]: 0 : pNotNot = new OSQLParseNode(::rtl::OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::sql_not));
[ # # ]
1971 : 0 : pSearchCondition->getChild( 1 )->replace(pNot, pNotNot);
1972 [ # # ]: 0 : delete pNot;
1973 : : }
1974 : : }
1975 : : //-----------------------------------------------------------------------------
1976 : 1680 : void OSQLParseNode::eraseBraces(OSQLParseNode*& pSearchCondition)
1977 : : {
1978 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::eraseBraces" );
1979 [ + - ][ + - ]: 1680 : if (pSearchCondition && (SQL_ISRULE(pSearchCondition,boolean_primary) || (pSearchCondition->count() == 3 && SQL_ISPUNCTUATION(pSearchCondition->getChild(0),"(") &&
[ + + ][ + - ]
[ - + ][ # #
# # # # ]
[ + + ]
1980 : 0 : SQL_ISPUNCTUATION(pSearchCondition->getChild(2),")"))))
1981 : : {
1982 [ + - ]: 40 : OSQLParseNode* pRight = pSearchCondition->getChild(1);
1983 [ + - ]: 40 : absorptions(pRight);
1984 : : // if child is not a or or and tree then delete () around child
1985 [ + - ][ + - ]: 88 : if(!(SQL_ISRULE(pSearchCondition->getChild(1),boolean_term) || SQL_ISRULE(pSearchCondition->getChild(1),search_condition)) ||
[ + - ][ + - ]
[ + + ][ + - ]
[ + - ][ + - ]
[ + - ]
[ - + + - ]
[ - + # # ]
[ # # # # ]
[ # # ][ + - ]
1986 [ + - ][ + - ]: 48 : SQL_ISRULE(pSearchCondition->getChild(1),boolean_term) || // and can always stand without ()
[ + - ]
1987 [ # # ][ # # ]: 0 : (SQL_ISRULE(pSearchCondition->getChild(1),search_condition) && SQL_ISRULE(pSearchCondition->getParent(),search_condition)))
[ # # ][ # # ]
1988 : : {
1989 [ + - ]: 40 : OSQLParseNode* pNode = pSearchCondition->removeAt(1);
1990 [ + - ]: 40 : replaceAndReset(pSearchCondition,pNode);
1991 : : }
1992 : : }
1993 : 1680 : }
1994 : : //-----------------------------------------------------------------------------
1995 : 840 : void OSQLParseNode::absorptions(OSQLParseNode*& pSearchCondition)
1996 : : {
1997 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::absorptions" );
1998 [ - + ]: 840 : if(!pSearchCondition) // no where condition at entry point
1999 : 840 : return;
2000 : :
2001 : 840 : eraseBraces(pSearchCondition);
2002 : :
2003 [ + + ][ + - ]: 840 : if(SQL_ISRULE(pSearchCondition,boolean_term) || SQL_ISRULE(pSearchCondition,search_condition))
[ + + ][ + + ]
[ + - ]
2004 : : {
2005 [ + - ]: 328 : OSQLParseNode* pLeft = pSearchCondition->getChild(0);
2006 [ + - ]: 328 : absorptions(pLeft);
2007 [ + - ]: 328 : OSQLParseNode* pRight = pSearchCondition->getChild(2);
2008 [ + - ]: 328 : absorptions(pRight);
2009 : : }
2010 : :
2011 : 840 : sal_uInt32 nPos = 0;
2012 : : // a and a || a or a
2013 : 840 : OSQLParseNode* pNewNode = NULL;
2014 [ + - ][ + + ]: 1168 : if(( SQL_ISRULE(pSearchCondition,boolean_term) || SQL_ISRULE(pSearchCondition,search_condition))
[ + - ]
[ + + - + ]
[ - + ]
2015 : 328 : && *pSearchCondition->getChild(0) == *pSearchCondition->getChild(2))
2016 : : {
2017 : 0 : pNewNode = pSearchCondition->removeAt((sal_uInt32)0);
2018 : 0 : replaceAndReset(pSearchCondition,pNewNode);
2019 : : }
2020 : : // (a or b) and a || ( b or c ) and a
2021 : : // a and ( a or b) || a and ( b or c )
2022 [ + - ][ + + : 2568 : else if ( SQL_ISRULE(pSearchCondition,boolean_term)
+ - + - +
- + - + -
+ - + - -
+ ][ - + ]
2023 : : && (
2024 : 432 : ( SQL_ISRULE(pSearchCondition->getChild(nPos = 0),boolean_primary)
2025 : 432 : || SQL_ISRULE(pSearchCondition->getChild(nPos),search_condition)
2026 : : )
2027 : 432 : || ( SQL_ISRULE(pSearchCondition->getChild(nPos = 2),boolean_primary)
2028 : 432 : || SQL_ISRULE(pSearchCondition->getChild(nPos),search_condition)
2029 : : )
2030 : : )
2031 : : )
2032 : : {
2033 : 0 : OSQLParseNode* p2ndSearch = pSearchCondition->getChild(nPos);
2034 [ # # ][ # # ]: 0 : if ( SQL_ISRULE(p2ndSearch,boolean_primary) )
[ # # ]
2035 : 0 : p2ndSearch = p2ndSearch->getChild(1);
2036 : :
2037 [ # # ]: 0 : if ( *p2ndSearch->getChild(0) == *pSearchCondition->getChild(2-nPos) ) // a and ( a or b) -> a or b
2038 : : {
2039 : 0 : pNewNode = pSearchCondition->removeAt((sal_uInt32)0);
2040 : 0 : replaceAndReset(pSearchCondition,pNewNode);
2041 : :
2042 : : }
2043 [ # # ]: 0 : else if ( *p2ndSearch->getChild(2) == *pSearchCondition->getChild(2-nPos) ) // a and ( b or a) -> a or b
2044 : : {
2045 : 0 : pNewNode = pSearchCondition->removeAt((sal_uInt32)2);
2046 : 0 : replaceAndReset(pSearchCondition,pNewNode);
2047 : : }
2048 [ # # ]: 0 : else if ( p2ndSearch->getByRule(OSQLParseNode::search_condition) )
2049 : : {
2050 : : // a and ( b or c ) -> ( a and b ) or ( a and c )
2051 : : // ( b or c ) and a -> ( a and b ) or ( a and c )
2052 [ # # ]: 0 : OSQLParseNode* pC = p2ndSearch->removeAt((sal_uInt32)2);
2053 [ # # ]: 0 : OSQLParseNode* pB = p2ndSearch->removeAt((sal_uInt32)0);
2054 [ # # ]: 0 : OSQLParseNode* pA = pSearchCondition->removeAt((sal_uInt32)2-nPos);
2055 : :
2056 [ # # ]: 0 : OSQLParseNode* p1stAnd = MakeANDNode(pA,pB);
2057 [ # # ][ # # ]: 0 : OSQLParseNode* p2ndAnd = MakeANDNode(new OSQLParseNode(*pA),pC);
[ # # ]
2058 [ # # ]: 0 : pNewNode = MakeORNode(p1stAnd,p2ndAnd);
2059 [ # # ][ # # ]: 0 : OSQLParseNode* pNode = new OSQLParseNode(::rtl::OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::boolean_primary));
[ # # ]
2060 [ # # ][ # # ]: 0 : pNode->append(new OSQLParseNode(::rtl::OUString("("),SQL_NODE_PUNCTUATION));
[ # # ]
2061 [ # # ]: 0 : pNode->append(pNewNode);
2062 [ # # ][ # # ]: 0 : pNode->append(new OSQLParseNode(::rtl::OUString(")"),SQL_NODE_PUNCTUATION));
[ # # ]
2063 [ # # ]: 0 : OSQLParseNode::eraseBraces(p1stAnd);
2064 [ # # ]: 0 : OSQLParseNode::eraseBraces(p2ndAnd);
2065 [ # # ]: 0 : replaceAndReset(pSearchCondition,pNode);
2066 : : }
2067 : : }
2068 : : // a or a and b || a or b and a
2069 [ + - ][ + + ]: 840 : else if(SQL_ISRULE(pSearchCondition,search_condition) && SQL_ISRULE(pSearchCondition->getChild(2),boolean_term))
[ + - ][ + + ]
[ + + ]
2070 : : {
2071 [ - + ]: 72 : if(*pSearchCondition->getChild(2)->getChild(0) == *pSearchCondition->getChild(0))
2072 : : {
2073 : 0 : pNewNode = pSearchCondition->removeAt((sal_uInt32)0);
2074 : 0 : replaceAndReset(pSearchCondition,pNewNode);
2075 : : }
2076 [ - + ]: 72 : else if(*pSearchCondition->getChild(2)->getChild(2) == *pSearchCondition->getChild(0))
2077 : : {
2078 : 0 : pNewNode = pSearchCondition->removeAt((sal_uInt32)0);
2079 : 0 : replaceAndReset(pSearchCondition,pNewNode);
2080 : : }
2081 : : }
2082 : : // a and b or a || b and a or a
2083 [ + - ][ + + ]: 768 : else if(SQL_ISRULE(pSearchCondition,search_condition) && SQL_ISRULE(pSearchCondition->getChild(0),boolean_term))
[ + - ][ - + ]
[ - + ]
2084 : : {
2085 [ # # ]: 0 : if(*pSearchCondition->getChild(0)->getChild(0) == *pSearchCondition->getChild(2))
2086 : : {
2087 : 0 : pNewNode = pSearchCondition->removeAt((sal_uInt32)2);
2088 : 0 : replaceAndReset(pSearchCondition,pNewNode);
2089 : : }
2090 [ # # ]: 0 : else if(*pSearchCondition->getChild(0)->getChild(2) == *pSearchCondition->getChild(2))
2091 : : {
2092 : 0 : pNewNode = pSearchCondition->removeAt((sal_uInt32)2);
2093 : 0 : replaceAndReset(pSearchCondition,pNewNode);
2094 : : }
2095 : : }
2096 : 840 : eraseBraces(pSearchCondition);
2097 : : }
2098 : : //-----------------------------------------------------------------------------
2099 : 0 : void OSQLParseNode::compress(OSQLParseNode *&pSearchCondition)
2100 : : {
2101 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::compress" );
2102 [ # # ]: 0 : if(!pSearchCondition) // no WHERE condition at entry point
2103 : 0 : return;
2104 : :
2105 : 0 : OSQLParseNode::eraseBraces(pSearchCondition);
2106 : :
2107 [ # # ][ # # ]: 0 : if(SQL_ISRULE(pSearchCondition,boolean_term) || SQL_ISRULE(pSearchCondition,search_condition))
[ # # ][ # # ]
[ # # ]
2108 : : {
2109 [ # # ]: 0 : OSQLParseNode* pLeft = pSearchCondition->getChild(0);
2110 [ # # ]: 0 : compress(pLeft);
2111 : :
2112 [ # # ]: 0 : OSQLParseNode* pRight = pSearchCondition->getChild(2);
2113 [ # # ]: 0 : compress(pRight);
2114 : : }
2115 [ # # ][ # # ]: 0 : else if( SQL_ISRULE(pSearchCondition,boolean_primary) || (pSearchCondition->count() == 3 && SQL_ISPUNCTUATION(pSearchCondition->getChild(0),"(") &&
[ # # ][ # # ]
[ # # # #
# # ][ # # ]
2116 : 0 : SQL_ISPUNCTUATION(pSearchCondition->getChild(2),")")))
2117 : : {
2118 [ # # ]: 0 : OSQLParseNode* pRight = pSearchCondition->getChild(1);
2119 [ # # ]: 0 : compress(pRight);
2120 : : // if child is not a or or and tree then delete () around child
2121 [ # # ][ # # ]: 0 : if(!(SQL_ISRULE(pSearchCondition->getChild(1),boolean_term) || SQL_ISRULE(pSearchCondition->getChild(1),search_condition)) ||
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
[ # # # # ]
[ # # # # ]
[ # # # # ]
[ # # # # ]
[ # # ][ # # ]
2122 [ # # ][ # # ]: 0 : (SQL_ISRULE(pSearchCondition->getChild(1),boolean_term) && SQL_ISRULE(pSearchCondition->getParent(),boolean_term)) ||
[ # # ][ # # ]
2123 [ # # ][ # # ]: 0 : (SQL_ISRULE(pSearchCondition->getChild(1),search_condition) && SQL_ISRULE(pSearchCondition->getParent(),search_condition)))
[ # # ][ # # ]
2124 : : {
2125 [ # # ]: 0 : OSQLParseNode* pNode = pSearchCondition->removeAt(1);
2126 [ # # ]: 0 : replaceAndReset(pSearchCondition,pNode);
2127 : : }
2128 : : }
2129 : :
2130 : : // or with two and trees where one element of the and trees are equal
2131 [ # # ][ # # ]: 0 : if(SQL_ISRULE(pSearchCondition,search_condition) && SQL_ISRULE(pSearchCondition->getChild(0),boolean_term) && SQL_ISRULE(pSearchCondition->getChild(2),boolean_term))
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
2132 : : {
2133 [ # # ]: 0 : if(*pSearchCondition->getChild(0)->getChild(0) == *pSearchCondition->getChild(2)->getChild(0))
2134 : : {
2135 [ # # ][ # # ]: 0 : OSQLParseNode* pLeft = pSearchCondition->getChild(0)->removeAt(2);
2136 [ # # ][ # # ]: 0 : OSQLParseNode* pRight = pSearchCondition->getChild(2)->removeAt(2);
2137 [ # # ]: 0 : OSQLParseNode* pNode = MakeORNode(pLeft,pRight);
2138 : :
2139 [ # # ][ # # ]: 0 : OSQLParseNode* pNewRule = new OSQLParseNode(::rtl::OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::boolean_primary));
[ # # ]
2140 [ # # ][ # # ]: 0 : pNewRule->append(new OSQLParseNode(::rtl::OUString("("),SQL_NODE_PUNCTUATION));
[ # # ]
2141 [ # # ]: 0 : pNewRule->append(pNode);
2142 [ # # ][ # # ]: 0 : pNewRule->append(new OSQLParseNode(::rtl::OUString(")"),SQL_NODE_PUNCTUATION));
[ # # ]
2143 : :
2144 [ # # ]: 0 : OSQLParseNode::eraseBraces(pLeft);
2145 [ # # ]: 0 : OSQLParseNode::eraseBraces(pRight);
2146 : :
2147 [ # # ][ # # ]: 0 : pNode = MakeANDNode(pSearchCondition->getChild(0)->removeAt((sal_uInt32)0),pNewRule);
[ # # ]
2148 [ # # ]: 0 : replaceAndReset(pSearchCondition,pNode);
2149 : : }
2150 [ # # ]: 0 : else if(*pSearchCondition->getChild(0)->getChild(2) == *pSearchCondition->getChild(2)->getChild(0))
2151 : : {
2152 [ # # ][ # # ]: 0 : OSQLParseNode* pLeft = pSearchCondition->getChild(0)->removeAt((sal_uInt32)0);
2153 [ # # ][ # # ]: 0 : OSQLParseNode* pRight = pSearchCondition->getChild(2)->removeAt(2);
2154 [ # # ]: 0 : OSQLParseNode* pNode = MakeORNode(pLeft,pRight);
2155 : :
2156 [ # # ][ # # ]: 0 : OSQLParseNode* pNewRule = new OSQLParseNode(::rtl::OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::boolean_primary));
[ # # ]
2157 [ # # ][ # # ]: 0 : pNewRule->append(new OSQLParseNode(::rtl::OUString("("),SQL_NODE_PUNCTUATION));
[ # # ]
2158 [ # # ]: 0 : pNewRule->append(pNode);
2159 [ # # ][ # # ]: 0 : pNewRule->append(new OSQLParseNode(::rtl::OUString(")"),SQL_NODE_PUNCTUATION));
[ # # ]
2160 : :
2161 [ # # ]: 0 : OSQLParseNode::eraseBraces(pLeft);
2162 [ # # ]: 0 : OSQLParseNode::eraseBraces(pRight);
2163 : :
2164 [ # # ][ # # ]: 0 : pNode = MakeANDNode(pSearchCondition->getChild(0)->removeAt(1),pNewRule);
[ # # ]
2165 [ # # ]: 0 : replaceAndReset(pSearchCondition,pNode);
2166 : : }
2167 [ # # ]: 0 : else if(*pSearchCondition->getChild(0)->getChild(0) == *pSearchCondition->getChild(2)->getChild(2))
2168 : : {
2169 [ # # ][ # # ]: 0 : OSQLParseNode* pLeft = pSearchCondition->getChild(0)->removeAt(2);
2170 [ # # ][ # # ]: 0 : OSQLParseNode* pRight = pSearchCondition->getChild(2)->removeAt((sal_uInt32)0);
2171 [ # # ]: 0 : OSQLParseNode* pNode = MakeORNode(pLeft,pRight);
2172 : :
2173 [ # # ][ # # ]: 0 : OSQLParseNode* pNewRule = new OSQLParseNode(::rtl::OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::boolean_primary));
[ # # ]
2174 [ # # ][ # # ]: 0 : pNewRule->append(new OSQLParseNode(::rtl::OUString("("),SQL_NODE_PUNCTUATION));
[ # # ]
2175 [ # # ]: 0 : pNewRule->append(pNode);
2176 [ # # ][ # # ]: 0 : pNewRule->append(new OSQLParseNode(::rtl::OUString(")"),SQL_NODE_PUNCTUATION));
[ # # ]
2177 : :
2178 [ # # ]: 0 : OSQLParseNode::eraseBraces(pLeft);
2179 [ # # ]: 0 : OSQLParseNode::eraseBraces(pRight);
2180 : :
2181 [ # # ][ # # ]: 0 : pNode = MakeANDNode(pSearchCondition->getChild(0)->removeAt((sal_uInt32)0),pNewRule);
[ # # ]
2182 [ # # ]: 0 : replaceAndReset(pSearchCondition,pNode);
2183 : : }
2184 [ # # ]: 0 : else if(*pSearchCondition->getChild(0)->getChild(2) == *pSearchCondition->getChild(2)->getChild(2))
2185 : : {
2186 [ # # ][ # # ]: 0 : OSQLParseNode* pLeft = pSearchCondition->getChild(0)->removeAt((sal_uInt32)0);
2187 [ # # ][ # # ]: 0 : OSQLParseNode* pRight = pSearchCondition->getChild(2)->removeAt((sal_uInt32)0);
2188 [ # # ]: 0 : OSQLParseNode* pNode = MakeORNode(pLeft,pRight);
2189 : :
2190 [ # # ][ # # ]: 0 : OSQLParseNode* pNewRule = new OSQLParseNode(::rtl::OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::boolean_primary));
[ # # ]
2191 [ # # ][ # # ]: 0 : pNewRule->append(new OSQLParseNode(::rtl::OUString("("),SQL_NODE_PUNCTUATION));
[ # # ]
2192 [ # # ]: 0 : pNewRule->append(pNode);
2193 [ # # ][ # # ]: 0 : pNewRule->append(new OSQLParseNode(::rtl::OUString(")"),SQL_NODE_PUNCTUATION));
[ # # ]
2194 : :
2195 [ # # ]: 0 : OSQLParseNode::eraseBraces(pLeft);
2196 [ # # ]: 0 : OSQLParseNode::eraseBraces(pRight);
2197 : :
2198 [ # # ][ # # ]: 0 : pNode = MakeANDNode(pSearchCondition->getChild(0)->removeAt(1),pNewRule);
[ # # ]
2199 [ # # ]: 0 : replaceAndReset(pSearchCondition,pNode);
2200 : : }
2201 : : }
2202 : : }
2203 : : #if OSL_DEBUG_LEVEL > 1
2204 : : // -----------------------------------------------------------------------------
2205 : : void OSQLParseNode::showParseTree( ::rtl::OUString& rString ) const
2206 : : {
2207 : : ::rtl::OUStringBuffer aBuf;
2208 : : showParseTree( aBuf, 0 );
2209 : : rString = aBuf.makeStringAndClear();
2210 : : }
2211 : :
2212 : : // -----------------------------------------------------------------------------
2213 : : void OSQLParseNode::showParseTree( ::rtl::OUStringBuffer& _inout_rBuffer, sal_uInt32 nLevel ) const
2214 : : {
2215 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::showParseTree" );
2216 : :
2217 : : for ( sal_uInt32 j=0; j<nLevel; ++j)
2218 : : _inout_rBuffer.appendAscii( " " );
2219 : :
2220 : : if ( !isToken() )
2221 : : {
2222 : : // Rule name as rule
2223 : : _inout_rBuffer.appendAscii( "RULE_ID: " );
2224 : : _inout_rBuffer.append( (sal_Int32)getRuleID() );
2225 : : _inout_rBuffer.append( sal_Unicode( '(' ) );
2226 : : _inout_rBuffer.append( OSQLParser::RuleIDToStr( getRuleID() ) );
2227 : : _inout_rBuffer.append( sal_Unicode( ')' ) );
2228 : : _inout_rBuffer.append( sal_Unicode( '\n' ) );
2229 : :
2230 : : // Get the first sub tree
2231 : : for ( OSQLParseNodes::const_iterator i = m_aChildren.begin();
2232 : : i != m_aChildren.end();
2233 : : ++i
2234 : : )
2235 : : (*i)->showParseTree( _inout_rBuffer, nLevel+1 );
2236 : : }
2237 : : else
2238 : : {
2239 : : // Found a token
2240 : : switch (m_eNodeType)
2241 : : {
2242 : :
2243 : : case SQL_NODE_KEYWORD:
2244 : : _inout_rBuffer.appendAscii( "SQL_KEYWORD: " );
2245 : : _inout_rBuffer.append( ::rtl::OStringToOUString( OSQLParser::TokenIDToStr( getTokenID() ), RTL_TEXTENCODING_UTF8 ) );
2246 : : _inout_rBuffer.append( sal_Unicode( '\n' ) );
2247 : : break;
2248 : :
2249 : : case SQL_NODE_COMPARISON:
2250 : : _inout_rBuffer.appendAscii( "SQL_COMPARISON: " );
2251 : : _inout_rBuffer.append( m_aNodeValue );
2252 : : _inout_rBuffer.append( sal_Unicode( '\n' ) );
2253 : : break;
2254 : :
2255 : : case SQL_NODE_NAME:
2256 : : _inout_rBuffer.appendAscii( "SQL_NAME: " );
2257 : : _inout_rBuffer.append( sal_Unicode( '"' ) );
2258 : : _inout_rBuffer.append( m_aNodeValue );
2259 : : _inout_rBuffer.append( sal_Unicode( '"' ) );
2260 : : _inout_rBuffer.append( sal_Unicode( '\n' ) );
2261 : : break;
2262 : :
2263 : : case SQL_NODE_STRING:
2264 : : _inout_rBuffer.appendAscii( "SQL_STRING: " );
2265 : : _inout_rBuffer.append( sal_Unicode( '\'' ) );
2266 : : _inout_rBuffer.append( m_aNodeValue );
2267 : : _inout_rBuffer.append( sal_Unicode( '\'' ) );
2268 : : _inout_rBuffer.append( sal_Unicode( '\n' ) );
2269 : : break;
2270 : :
2271 : : case SQL_NODE_INTNUM:
2272 : : _inout_rBuffer.appendAscii( "SQL_INTNUM: " );
2273 : : _inout_rBuffer.append( m_aNodeValue );
2274 : : _inout_rBuffer.append( sal_Unicode( '\n' ) );
2275 : : break;
2276 : :
2277 : : case SQL_NODE_APPROXNUM:
2278 : : _inout_rBuffer.appendAscii( "SQL_APPROXNUM: " );
2279 : : _inout_rBuffer.append( m_aNodeValue );
2280 : : _inout_rBuffer.append( sal_Unicode( '\n' ) );
2281 : : break;
2282 : :
2283 : : case SQL_NODE_PUNCTUATION:
2284 : : _inout_rBuffer.appendAscii( "SQL_PUNCTUATION: " );
2285 : : _inout_rBuffer.append( m_aNodeValue );
2286 : : _inout_rBuffer.append( sal_Unicode( '\n' ) );
2287 : : break;
2288 : :
2289 : : case SQL_NODE_AMMSC:
2290 : : _inout_rBuffer.appendAscii( "SQL_AMMSC: " );
2291 : : _inout_rBuffer.append( m_aNodeValue );
2292 : : _inout_rBuffer.append( sal_Unicode( '\n' ) );
2293 : : break;
2294 : :
2295 : : case SQL_NODE_EQUAL:
2296 : : case SQL_NODE_LESS:
2297 : : case SQL_NODE_GREAT:
2298 : : case SQL_NODE_LESSEQ:
2299 : : case SQL_NODE_GREATEQ:
2300 : : case SQL_NODE_NOTEQUAL:
2301 : : _inout_rBuffer.append( m_aNodeValue );
2302 : : _inout_rBuffer.append( sal_Unicode( '\n' ) );
2303 : : break;
2304 : :
2305 : : case SQL_NODE_ACCESS_DATE:
2306 : : _inout_rBuffer.appendAscii( "SQL_ACCESS_DATE: " );
2307 : : _inout_rBuffer.append( m_aNodeValue );
2308 : : _inout_rBuffer.append( sal_Unicode( '\n' ) );
2309 : : break;
2310 : :
2311 : : case SQL_NODE_DATE:
2312 : : _inout_rBuffer.appendAscii( "SQL_DATE: " );
2313 : : _inout_rBuffer.append( m_aNodeValue );
2314 : : _inout_rBuffer.append( sal_Unicode( '\n' ) );
2315 : : break;
2316 : :
2317 : : case SQL_NODE_CONCAT:
2318 : : _inout_rBuffer.appendAscii( "||" );
2319 : : _inout_rBuffer.append( sal_Unicode( '\n' ) );
2320 : : break;
2321 : :
2322 : : default:
2323 : : OSL_TRACE( "-- %i", int( m_eNodeType ) );
2324 : : OSL_FAIL( "OSQLParser::ShowParseTree: unzulaessiger NodeType" );
2325 : : }
2326 : : }
2327 : : }
2328 : : #endif // OSL_DEBUG_LEVEL > 0
2329 : : // -----------------------------------------------------------------------------
2330 : : // Insert methods
2331 : : //-----------------------------------------------------------------------------
2332 : 0 : void OSQLParseNode::insert(sal_uInt32 nPos, OSQLParseNode* pNewSubTree)
2333 : : {
2334 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::insert" );
2335 : : OSL_ENSURE(pNewSubTree != NULL, "OSQLParseNode: invalid NewSubTree");
2336 : : OSL_ENSURE(pNewSubTree->getParent() == NULL, "OSQLParseNode: Node is not an orphan");
2337 : :
2338 : : // Create connection to getParent
2339 : 0 : pNewSubTree->setParent( this );
2340 [ # # ][ # # ]: 0 : m_aChildren.insert(m_aChildren.begin() + nPos, pNewSubTree);
2341 : 0 : }
2342 : :
2343 : : // removeAt methods
2344 : : //-----------------------------------------------------------------------------
2345 : 112 : OSQLParseNode* OSQLParseNode::removeAt(sal_uInt32 nPos)
2346 : : {
2347 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::removeAt" );
2348 : : OSL_ENSURE(nPos < m_aChildren.size(),"Illegal position for removeAt");
2349 [ + - ]: 112 : OSQLParseNodes::iterator aPos(m_aChildren.begin() + nPos);
2350 : 112 : OSQLParseNode* pNode = *aPos;
2351 : :
2352 : : // Set the getParent of the removed node to NULL
2353 : 112 : pNode->setParent( NULL );
2354 : :
2355 [ + - ]: 112 : m_aChildren.erase(aPos);
2356 : 112 : return pNode;
2357 : : }
2358 : :
2359 : : // Replace methods
2360 : : //-----------------------------------------------------------------------------
2361 : 40 : OSQLParseNode* OSQLParseNode::replace (OSQLParseNode* pOldSubNode, OSQLParseNode* pNewSubNode )
2362 : : {
2363 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::replace " );
2364 : : OSL_ENSURE(pOldSubNode != NULL && pNewSubNode != NULL, "OSQLParseNode: invalid nodes");
2365 : : OSL_ENSURE(pNewSubNode->getParent() == NULL, "OSQLParseNode: node already has getParent");
2366 : : OSL_ENSURE(::std::find(m_aChildren.begin(), m_aChildren.end(), pOldSubNode) != m_aChildren.end(),
2367 : : "OSQLParseNode::Replace() Node not element of parent");
2368 : : OSL_ENSURE(::std::find(m_aChildren.begin(), m_aChildren.end(), pNewSubNode) == m_aChildren.end(),
2369 : : "OSQLParseNode::Replace() Node already element of parent");
2370 : :
2371 : 40 : pOldSubNode->setParent( NULL );
2372 : 40 : pNewSubNode->setParent( this );
2373 : 40 : ::std::replace(m_aChildren.begin(), m_aChildren.end(), pOldSubNode, pNewSubNode);
2374 : 40 : return pOldSubNode;
2375 : : }
2376 : : // -----------------------------------------------------------------------------
2377 : 13146 : void OSQLParseNode::parseLeaf(::rtl::OUStringBuffer& rString, const SQLParseNodeParameter& rParam) const
2378 : : {
2379 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::parseLeaf" );
2380 : : // Found a leaf
2381 : : // Append content to the output string
2382 [ + + + - : 13146 : switch (m_eNodeType)
+ + + ]
2383 : : {
2384 : : case SQL_NODE_KEYWORD:
2385 : : {
2386 [ + + ]: 2330 : if (rString.getLength())
2387 [ + - ]: 2074 : rString.appendAscii(" ");
2388 : :
2389 [ - + ][ + - ]: 2330 : const ::rtl::OString sT = OSQLParser::TokenIDToStr(m_nNodeID, rParam.bInternational ? &rParam.m_rContext : NULL);
2390 [ + - ][ + - ]: 2330 : rString.append(::rtl::OStringToOUString(sT,RTL_TEXTENCODING_UTF8));
2391 : 2330 : } break;
2392 : : case SQL_NODE_STRING:
2393 [ + + ]: 3392 : if (rString.getLength())
2394 : 1424 : rString.appendAscii(" ");
2395 [ + - ]: 3392 : rString.append(SetQuotation(m_aNodeValue,::rtl::OUString("\'"),::rtl::OUString("\'\'")));
2396 : 3392 : break;
2397 : : case SQL_NODE_NAME:
2398 [ + + ]: 2630 : if (rString.getLength() > 0)
2399 : : {
2400 [ + + ]: 2512 : switch(rString[rString.getLength()-1])
2401 : : {
2402 : : case ' ' :
2403 : 380 : case '.' : break;
2404 : : default :
2405 [ - + # # ]: 2132 : if ( rParam.aMetaData.getCatalogSeparator().isEmpty()
[ + - ]
2406 : 0 : || rString[rString.getLength() - 1] != rParam.aMetaData.getCatalogSeparator().toChar()
2407 : : )
2408 : 2512 : rString.appendAscii(" "); break;
2409 : : }
2410 : : }
2411 [ + + ]: 2630 : if (rParam.bQuote)
2412 : : {
2413 [ - + ]: 2606 : if (rParam.bPredicate)
2414 : : {
2415 : 0 : rString.appendAscii("[");
2416 : 0 : rString.append(m_aNodeValue);
2417 : 0 : rString.appendAscii("]");
2418 : : }
2419 : : else
2420 : : rString.append(SetQuotation(m_aNodeValue,
2421 [ + - ]: 2606 : rParam.aMetaData.getIdentifierQuoteString(), rParam.aMetaData.getIdentifierQuoteString() ));
2422 : : }
2423 : : else
2424 : 24 : rString.append(m_aNodeValue);
2425 : 2630 : break;
2426 : : case SQL_NODE_ACCESS_DATE:
2427 [ # # ]: 0 : if (rString.getLength())
2428 : 0 : rString.appendAscii(" ");
2429 : 0 : rString.appendAscii("#");
2430 : 0 : rString.append(m_aNodeValue);
2431 : 0 : rString.appendAscii("#");
2432 : 0 : break;
2433 : :
2434 : : case SQL_NODE_INTNUM:
2435 : : case SQL_NODE_APPROXNUM:
2436 : : {
2437 : 332 : ::rtl::OUString aTmp = m_aNodeValue;
2438 [ # # ][ # # ]: 332 : if (rParam.bInternational && rParam.bPredicate && rParam.cDecSep != '.')
[ - + ]
2439 : 0 : aTmp = aTmp.replace('.', rParam.cDecSep);
2440 : :
2441 [ + + ]: 332 : if (rString.getLength())
2442 [ + - ]: 140 : rString.appendAscii(" ");
2443 [ + - ]: 332 : rString.append(aTmp);
2444 : :
2445 : 332 : } break;
2446 : : case SQL_NODE_PUNCTUATION:
2447 [ + - ][ + - ]: 2890 : if ( getParent() && SQL_ISRULE(getParent(),cast_spec) && m_aNodeValue.toChar() == '(' ) // no spaces in front of '('
[ - + ][ # # ]
[ - + ]
2448 : : {
2449 : 0 : rString.append(m_aNodeValue);
2450 : 0 : break;
2451 : : }
2452 : : // fall through
2453 : : default:
2454 [ + + ][ + + ]: 4462 : if (rString.getLength() > 0 && m_aNodeValue.toChar() != '.' && m_aNodeValue.toChar() != ':' )
[ + + ][ + + ]
2455 : : {
2456 [ + + ]: 3956 : switch( rString[rString.getLength() - 1] )
2457 : : {
2458 : : case ' ' :
2459 : 66 : case '.' : break;
2460 : : default :
2461 [ - + # # ]: 3890 : if ( rParam.aMetaData.getCatalogSeparator().isEmpty()
[ + - ]
2462 : 0 : || rString[rString.getLength() - 1] != rParam.aMetaData.getCatalogSeparator().toChar()
2463 : : )
2464 : 3956 : rString.appendAscii(" "); break;
2465 : : }
2466 : : }
2467 : 4462 : rString.append(m_aNodeValue);
2468 : : }
2469 : 13146 : }
2470 : :
2471 : : // -----------------------------------------------------------------------------
2472 : 0 : sal_Int32 OSQLParser::getFunctionReturnType(const ::rtl::OUString& _sFunctionName, const IParseContext* pContext)
2473 : : {
2474 : 0 : sal_Int32 nType = DataType::VARCHAR;
2475 [ # # ]: 0 : ::rtl::OString sFunctionName(::rtl::OUStringToOString(_sFunctionName,RTL_TEXTENCODING_UTF8));
2476 : :
2477 [ # # ][ # # ]: 0 : if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_ASCII,pContext))) nType = DataType::INTEGER;
2478 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_BIT_LENGTH,pContext))) nType = DataType::INTEGER;
2479 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_CHAR,pContext))) nType = DataType::VARCHAR;
2480 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_CHAR_LENGTH,pContext))) nType = DataType::INTEGER;
2481 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_CONCAT,pContext))) nType = DataType::VARCHAR;
2482 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_DIFFERENCE,pContext))) nType = DataType::VARCHAR;
2483 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_INSERT,pContext))) nType = DataType::VARCHAR;
2484 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LCASE,pContext))) nType = DataType::VARCHAR;
2485 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LEFT,pContext))) nType = DataType::VARCHAR;
2486 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LENGTH,pContext))) nType = DataType::INTEGER;
2487 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LOCATE,pContext))) nType = DataType::VARCHAR;
2488 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LOCATE_2,pContext))) nType = DataType::VARCHAR;
2489 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LTRIM,pContext))) nType = DataType::VARCHAR;
2490 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_OCTET_LENGTH,pContext))) nType = DataType::INTEGER;
2491 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_POSITION,pContext))) nType = DataType::INTEGER;
2492 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_REPEAT,pContext))) nType = DataType::VARCHAR;
2493 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_REPLACE,pContext))) nType = DataType::VARCHAR;
2494 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_RIGHT,pContext))) nType = DataType::VARCHAR;
2495 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_RTRIM,pContext))) nType = DataType::VARCHAR;
2496 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_SOUNDEX,pContext))) nType = DataType::VARCHAR;
2497 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_SPACE,pContext))) nType = DataType::VARCHAR;
2498 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_SUBSTRING,pContext))) nType = DataType::VARCHAR;
2499 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_UCASE,pContext))) nType = DataType::VARCHAR;
2500 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_CURRENT_DATE,pContext))) nType = DataType::DATE;
2501 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_CURRENT_TIME,pContext))) nType = DataType::TIME;
2502 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_CURRENT_TIMESTAMP,pContext))) nType = DataType::TIMESTAMP;
2503 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_CURDATE,pContext))) nType = DataType::DATE;
2504 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_DATEDIFF,pContext))) nType = DataType::INTEGER;
2505 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_DATEVALUE,pContext))) nType = DataType::DATE;
2506 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_CURTIME,pContext))) nType = DataType::TIME;
2507 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_DAYNAME,pContext))) nType = DataType::VARCHAR;
2508 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_DAYOFMONTH,pContext))) nType = DataType::INTEGER;
2509 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_DAYOFWEEK,pContext))) nType = DataType::INTEGER;
2510 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_DAYOFYEAR,pContext))) nType = DataType::INTEGER;
2511 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_EXTRACT,pContext))) nType = DataType::VARCHAR;
2512 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_HOUR,pContext))) nType = DataType::INTEGER;
2513 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_MINUTE,pContext))) nType = DataType::INTEGER;
2514 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_MONTH,pContext))) nType = DataType::INTEGER;
2515 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_MONTHNAME,pContext))) nType = DataType::VARCHAR;
2516 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_NOW,pContext))) nType = DataType::TIMESTAMP;
2517 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_QUARTER,pContext))) nType = DataType::INTEGER;
2518 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_SECOND,pContext))) nType = DataType::INTEGER;
2519 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_TIMESTAMPADD,pContext))) nType = DataType::TIMESTAMP;
2520 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_TIMESTAMPDIFF,pContext))) nType = DataType::TIMESTAMP;
2521 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_TIMEVALUE,pContext))) nType = DataType::TIMESTAMP;
2522 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_WEEK,pContext))) nType = DataType::INTEGER;
2523 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_YEAR,pContext))) nType = DataType::INTEGER;
2524 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_ABS,pContext))) nType = DataType::DOUBLE;
2525 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_ACOS,pContext))) nType = DataType::DOUBLE;
2526 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_ASIN,pContext))) nType = DataType::DOUBLE;
2527 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_ATAN,pContext))) nType = DataType::DOUBLE;
2528 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_ATAN2,pContext))) nType = DataType::DOUBLE;
2529 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_CEILING,pContext))) nType = DataType::DOUBLE;
2530 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_COS,pContext))) nType = DataType::DOUBLE;
2531 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_COT,pContext))) nType = DataType::DOUBLE;
2532 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_DEGREES,pContext))) nType = DataType::DOUBLE;
2533 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_EXP,pContext))) nType = DataType::DOUBLE;
2534 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_FLOOR,pContext))) nType = DataType::DOUBLE;
2535 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LOGF,pContext))) nType = DataType::DOUBLE;
2536 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LOG,pContext))) nType = DataType::DOUBLE;
2537 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LOG10,pContext))) nType = DataType::DOUBLE;
2538 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LN,pContext))) nType = DataType::DOUBLE;
2539 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_MOD,pContext))) nType = DataType::DOUBLE;
2540 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_PI,pContext))) nType = DataType::DOUBLE;
2541 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_POWER,pContext))) nType = DataType::DOUBLE;
2542 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_RADIANS,pContext))) nType = DataType::DOUBLE;
2543 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_RAND,pContext))) nType = DataType::DOUBLE;
2544 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_ROUND,pContext))) nType = DataType::DOUBLE;
2545 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_ROUNDMAGIC,pContext))) nType = DataType::DOUBLE;
2546 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_SIGN,pContext))) nType = DataType::DOUBLE;
2547 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_SIN,pContext))) nType = DataType::DOUBLE;
2548 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_SQRT,pContext))) nType = DataType::DOUBLE;
2549 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_TAN,pContext))) nType = DataType::DOUBLE;
2550 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_TRUNCATE,pContext))) nType = DataType::DOUBLE;
2551 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_COUNT,pContext))) nType = DataType::INTEGER;
2552 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_MAX,pContext))) nType = DataType::DOUBLE;
2553 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_MIN,pContext))) nType = DataType::DOUBLE;
2554 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_AVG,pContext))) nType = DataType::DOUBLE;
2555 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_SUM,pContext))) nType = DataType::DOUBLE;
2556 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LOWER,pContext))) nType = DataType::VARCHAR;
2557 [ # # ][ # # ]: 0 : else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_UPPER,pContext))) nType = DataType::VARCHAR;
2558 : :
2559 : 0 : return nType;
2560 : : }
2561 : : // -----------------------------------------------------------------------------
2562 : 0 : sal_Int32 OSQLParser::getFunctionParameterType(sal_uInt32 _nTokenId, sal_uInt32 _nPos)
2563 : : {
2564 : 0 : sal_Int32 nType = DataType::VARCHAR;
2565 : :
2566 [ # # ]: 0 : if(_nTokenId == SQL_TOKEN_CHAR) nType = DataType::INTEGER;
2567 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_INSERT)
2568 : : {
2569 [ # # ][ # # ]: 0 : if ( _nPos == 2 || _nPos == 3 )
2570 : 0 : nType = DataType::INTEGER;
2571 : : }
2572 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_LEFT)
2573 : : {
2574 [ # # ]: 0 : if ( _nPos == 2 )
2575 : 0 : nType = DataType::INTEGER;
2576 : : }
2577 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_LOCATE)
2578 : : {
2579 [ # # ]: 0 : if ( _nPos == 3 )
2580 : 0 : nType = DataType::INTEGER;
2581 : : }
2582 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_LOCATE_2)
2583 : : {
2584 [ # # ]: 0 : if ( _nPos == 3 )
2585 : 0 : nType = DataType::INTEGER;
2586 : : }
2587 [ # # ][ # # ]: 0 : else if( _nTokenId == SQL_TOKEN_REPEAT || _nTokenId == SQL_TOKEN_RIGHT )
2588 : : {
2589 [ # # ]: 0 : if ( _nPos == 2 )
2590 : 0 : nType = DataType::INTEGER;
2591 : : }
2592 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_SPACE )
2593 : : {
2594 : 0 : nType = DataType::INTEGER;
2595 : : }
2596 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_SUBSTRING)
2597 : : {
2598 [ # # ]: 0 : if ( _nPos != 1 )
2599 : 0 : nType = DataType::INTEGER;
2600 : : }
2601 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_DATEDIFF)
2602 : : {
2603 [ # # ]: 0 : if ( _nPos != 1 )
2604 : 0 : nType = DataType::TIMESTAMP;
2605 : : }
2606 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_DATEVALUE)
2607 : 0 : nType = DataType::DATE;
2608 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_DAYNAME)
2609 : 0 : nType = DataType::DATE;
2610 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_DAYOFMONTH)
2611 : 0 : nType = DataType::DATE;
2612 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_DAYOFWEEK)
2613 : 0 : nType = DataType::DATE;
2614 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_DAYOFYEAR)
2615 : 0 : nType = DataType::DATE;
2616 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_EXTRACT) nType = DataType::VARCHAR;
2617 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_HOUR) nType = DataType::TIME;
2618 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_MINUTE) nType = DataType::TIME;
2619 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_MONTH) nType = DataType::DATE;
2620 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_MONTHNAME) nType = DataType::DATE;
2621 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_NOW) nType = DataType::TIMESTAMP;
2622 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_QUARTER) nType = DataType::DATE;
2623 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_SECOND) nType = DataType::TIME;
2624 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_TIMESTAMPADD) nType = DataType::TIMESTAMP;
2625 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_TIMESTAMPDIFF) nType = DataType::TIMESTAMP;
2626 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_TIMEVALUE) nType = DataType::TIMESTAMP;
2627 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_WEEK) nType = DataType::DATE;
2628 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_YEAR) nType = DataType::DATE;
2629 : :
2630 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_ABS) nType = DataType::DOUBLE;
2631 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_ACOS) nType = DataType::DOUBLE;
2632 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_ASIN) nType = DataType::DOUBLE;
2633 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_ATAN) nType = DataType::DOUBLE;
2634 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_ATAN2) nType = DataType::DOUBLE;
2635 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_CEILING) nType = DataType::DOUBLE;
2636 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_COS) nType = DataType::DOUBLE;
2637 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_COT) nType = DataType::DOUBLE;
2638 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_DEGREES) nType = DataType::DOUBLE;
2639 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_EXP) nType = DataType::DOUBLE;
2640 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_FLOOR) nType = DataType::DOUBLE;
2641 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_LOGF) nType = DataType::DOUBLE;
2642 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_LOG) nType = DataType::DOUBLE;
2643 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_LOG10) nType = DataType::DOUBLE;
2644 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_LN) nType = DataType::DOUBLE;
2645 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_MOD) nType = DataType::DOUBLE;
2646 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_PI) nType = DataType::DOUBLE;
2647 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_POWER) nType = DataType::DOUBLE;
2648 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_RADIANS) nType = DataType::DOUBLE;
2649 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_RAND) nType = DataType::DOUBLE;
2650 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_ROUND) nType = DataType::DOUBLE;
2651 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_ROUNDMAGIC) nType = DataType::DOUBLE;
2652 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_SIGN) nType = DataType::DOUBLE;
2653 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_SIN) nType = DataType::DOUBLE;
2654 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_SQRT) nType = DataType::DOUBLE;
2655 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_TAN) nType = DataType::DOUBLE;
2656 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_TRUNCATE) nType = DataType::DOUBLE;
2657 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_COUNT) nType = DataType::INTEGER;
2658 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_MAX) nType = DataType::DOUBLE;
2659 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_MIN) nType = DataType::DOUBLE;
2660 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_AVG) nType = DataType::DOUBLE;
2661 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_SUM) nType = DataType::DOUBLE;
2662 : :
2663 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_LOWER) nType = DataType::VARCHAR;
2664 [ # # ]: 0 : else if(_nTokenId == SQL_TOKEN_UPPER) nType = DataType::VARCHAR;
2665 : :
2666 : 0 : return nType;
2667 : : }
2668 : :
2669 : : // -----------------------------------------------------------------------------
2670 : 0 : const SQLError& OSQLParser::getErrorHelper() const
2671 : : {
2672 : 0 : return m_pData->aErrors;
2673 : : }
2674 : :
2675 : : // -----------------------------------------------------------------------------
2676 : 13216 : OSQLParseNode::Rule OSQLParseNode::getKnownRuleID() const
2677 : : {
2678 [ - + ]: 13216 : if ( !isRule() )
2679 : 0 : return UNKNOWN_RULE;
2680 : 13216 : return OSQLParser::RuleIDToRule( getRuleID() );
2681 : : }
2682 : : // -----------------------------------------------------------------------------
2683 : 408 : ::rtl::OUString OSQLParseNode::getTableRange(const OSQLParseNode* _pTableRef)
2684 : : {
2685 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::getTableRange" );
2686 : : OSL_ENSURE(_pTableRef && _pTableRef->count() > 1 && _pTableRef->getKnownRuleID() == OSQLParseNode::table_ref,"Invalid node give, only table ref is allowed!");
2687 : 408 : const sal_uInt32 nCount = _pTableRef->count();
2688 : 408 : ::rtl::OUString sTableRange;
2689 [ # # ][ # # ]: 408 : if ( nCount == 2 || (nCount == 3 && !_pTableRef->getChild(0)->isToken()) || nCount == 5 )
[ # # ][ # # ]
[ + - ][ - + ]
2690 : : {
2691 [ + - ][ + - ]: 408 : const OSQLParseNode* pNode = _pTableRef->getChild(nCount - (nCount == 2 ? 1 : 2));
2692 : : OSL_ENSURE(pNode && (pNode->getKnownRuleID() == OSQLParseNode::table_primary_as_range_column
2693 : : || pNode->getKnownRuleID() == OSQLParseNode::range_variable)
2694 : : ,"SQL grammar changed!");
2695 [ + + ]: 408 : if ( !pNode->isLeaf() )
2696 [ + - ]: 104 : sTableRange = pNode->getChild(1)->getTokenValue();
2697 : : } // if ( nCount == 2 || nCount == 3 || nCount == 5)
2698 : :
2699 : 408 : return sTableRange;
2700 : : }
2701 : : // -----------------------------------------------------------------------------
2702 [ + - ]: 52 : OSQLParseNodesContainer::OSQLParseNodesContainer()
2703 : : {
2704 : 52 : }
2705 : : // -----------------------------------------------------------------------------
2706 : 52 : OSQLParseNodesContainer::~OSQLParseNodesContainer()
2707 : : {
2708 : 52 : }
2709 : : // -----------------------------------------------------------------------------
2710 : 26640 : void OSQLParseNodesContainer::push_back(OSQLParseNode* _pNode)
2711 : : {
2712 [ + - ]: 26640 : ::osl::MutexGuard aGuard(m_aMutex);
2713 [ + - ][ + - ]: 26640 : m_aNodes.push_back(_pNode);
2714 : 26640 : }
2715 : : // -----------------------------------------------------------------------------
2716 : 26640 : void OSQLParseNodesContainer::erase(OSQLParseNode* _pNode)
2717 : : {
2718 [ + - ]: 26640 : ::osl::MutexGuard aGuard(m_aMutex);
2719 [ + + ]: 26640 : if ( !m_aNodes.empty() )
2720 : : {
2721 [ + - ]: 90 : ::std::vector< OSQLParseNode* >::iterator aFind = ::std::find(m_aNodes.begin(), m_aNodes.end(),_pNode);
2722 [ + - ][ + - ]: 90 : if ( aFind != m_aNodes.end() )
2723 [ + - ]: 90 : m_aNodes.erase(aFind);
2724 [ + - ]: 26640 : }
2725 : 26640 : }
2726 : : // -----------------------------------------------------------------------------
2727 : 558 : void OSQLParseNodesContainer::clear()
2728 : : {
2729 [ + - ]: 558 : ::osl::MutexGuard aGuard(m_aMutex);
2730 [ + - ]: 558 : m_aNodes.clear();
2731 : 558 : }
2732 : : // -----------------------------------------------------------------------------
2733 : 2 : void OSQLParseNodesContainer::clearAndDelete()
2734 : : {
2735 [ + - ]: 2 : ::osl::MutexGuard aGuard(m_aMutex);
2736 : : // clear the garbage collector
2737 [ + + ]: 6 : while ( !m_aNodes.empty() )
2738 : : {
2739 [ + - ]: 4 : OSQLParseNode* pNode = m_aNodes[0];
2740 [ + + ]: 8 : while ( pNode->getParent() )
2741 : : {
2742 : 4 : pNode = pNode->getParent();
2743 : : }
2744 [ + - ][ + - ]: 4 : delete pNode;
2745 [ + - ]: 2 : }
2746 : 2 : }
2747 [ + - ][ + - ]: 168 : } // namespace connectivity
2748 : :
2749 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|