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 "QueryDesignView.hxx"
21 : : #include "QueryTableView.hxx"
22 : : #include "QTableWindow.hxx"
23 : : #include <vcl/toolbox.hxx>
24 : : #include "querycontroller.hxx"
25 : : #include <vcl/split.hxx>
26 : : #include <svl/undo.hxx>
27 : : #include <tools/diagnose_ex.h>
28 : : #include <osl/diagnose.h>
29 : : #include "adtabdlg.hxx"
30 : : #include <vcl/svapp.hxx>
31 : : #include <vcl/combobox.hxx>
32 : : #include <vcl/msgbox.hxx>
33 : : #include "browserids.hxx"
34 : : #include "SelectionBrowseBox.hxx"
35 : : #include "dbu_qry.hrc"
36 : : #include <unotools/configmgr.hxx>
37 : : #include <comphelper/extract.hxx>
38 : : #include <comphelper/string.hxx>
39 : : #include <comphelper/types.hxx>
40 : : #include <connectivity/dbtools.hxx>
41 : : #include <connectivity/dbexception.hxx>
42 : : #include <com/sun/star/i18n/XLocaleData.hpp>
43 : : #include <com/sun/star/sdbc/DataType.hpp>
44 : : #include <com/sun/star/container/XNameAccess.hpp>
45 : : #include <com/sun/star/sdbc/ColumnValue.hpp>
46 : : #include <connectivity/PColumn.hxx>
47 : : #include "QTableConnection.hxx"
48 : : #include "ConnectionLine.hxx"
49 : : #include "ConnectionLineData.hxx"
50 : : #include "QTableConnectionData.hxx"
51 : : #include "dbustrings.hrc"
52 : : #include "UITools.hxx"
53 : : #include "querycontainerwindow.hxx"
54 : : #include "sqlmessage.hxx"
55 : : #include <unotools/syslocale.hxx>
56 : :
57 : : using namespace ::dbaui;
58 : : using namespace ::utl;
59 : : using namespace ::connectivity;
60 : : using namespace ::dbtools;
61 : : using namespace ::com::sun::star::uno;
62 : : using namespace ::com::sun::star::lang;
63 : : using namespace ::com::sun::star::i18n;
64 : : using namespace ::com::sun::star::sdbc;
65 : : using namespace ::com::sun::star::beans;
66 : : using namespace ::com::sun::star::container;
67 : :
68 : : // here we define our functions used in the anonymous namespace to get our header file smaller
69 : : // please look at the book LargeScale C++ to know why
70 : : namespace
71 : : {
72 : 14 : static const ::rtl::OUString C_AND(RTL_CONSTASCII_USTRINGPARAM(" AND "));
73 : 14 : static const ::rtl::OUString C_OR(RTL_CONSTASCII_USTRINGPARAM(" OR "));
74 : :
75 : : // forward declarations
76 : : sal_Bool InsertJoin( const OQueryDesignView* _pView,
77 : : const ::connectivity::OSQLParseNode *pNode);
78 : :
79 : : SqlParseError InstallFields(OQueryDesignView* _pView,
80 : : const ::connectivity::OSQLParseNode* pNode,
81 : : OJoinTableView::OTableWindowMap* pTabList );
82 : :
83 : : SqlParseError GetGroupCriteria( OQueryDesignView* _pView,
84 : : OSelectionBrowseBox* _pSelectionBrw,
85 : : const ::connectivity::OSQLParseNode* pSelectRoot );
86 : :
87 : : SqlParseError GetHavingCriteria(OQueryDesignView* _pView,
88 : : OSelectionBrowseBox* _pSelectionBrw,
89 : : const ::connectivity::OSQLParseNode* pSelectRoot,
90 : : sal_uInt16& rLevel );
91 : :
92 : : SqlParseError GetOrderCriteria( OQueryDesignView* _pView,
93 : : OSelectionBrowseBox* _pSelectionBrw,
94 : : const ::connectivity::OSQLParseNode* pParseRoot );
95 : :
96 : : SqlParseError AddFunctionCondition(OQueryDesignView* _pView,
97 : : OSelectionBrowseBox* _pSelectionBrw,
98 : : const ::connectivity::OSQLParseNode * pCondition,
99 : : const sal_uInt16 nLevel,
100 : : sal_Bool bHaving,
101 : : bool _bAddOrOnOneLine);
102 : :
103 : : //------------------------------------------------------------------------------
104 : 0 : ::rtl::OUString quoteTableAlias(sal_Bool _bQuote, const ::rtl::OUString& _sAliasName, const ::rtl::OUString& _sQuote)
105 : : {
106 : 0 : ::rtl::OUString sRet;
107 [ # # ][ # # ]: 0 : if ( _bQuote && !_sAliasName.isEmpty() )
[ # # ]
108 : : {
109 [ # # ]: 0 : sRet = ::dbtools::quoteName(_sQuote,_sAliasName);
110 [ # # ][ # # ]: 0 : const static ::rtl::OUString sTableSeparater('.');
111 : 0 : sRet += sTableSeparater;
112 : : }
113 : 0 : return sRet;
114 : : }
115 : : //------------------------------------------------------------------------------
116 : 0 : ::rtl::OUString getTableRange(const OQueryDesignView* _pView,const ::connectivity::OSQLParseNode* _pTableRef)
117 : : {
118 [ # # ]: 0 : Reference< XConnection> xConnection = static_cast<OQueryController&>(_pView->getController()).getConnection();
119 : 0 : ::rtl::OUString sTableRange;
120 [ # # ]: 0 : if ( _pTableRef )
121 : : {
122 [ # # ]: 0 : sTableRange = ::connectivity::OSQLParseNode::getTableRange(_pTableRef);
123 [ # # ]: 0 : if ( sTableRange.isEmpty() )
124 [ # # ]: 0 : _pTableRef->parseNodeToStr(sTableRange,xConnection,NULL,sal_False,sal_False);
125 : : }
126 : 0 : return sTableRange;
127 : : }
128 : : //------------------------------------------------------------------------------
129 : 0 : void insertConnection(const OQueryDesignView* _pView,const EJoinType& _eJoinType,OTableFieldDescRef _aDragLeft,OTableFieldDescRef _aDragRight,bool _bNatural = false)
130 : : {
131 : 0 : OQueryTableView* pTableView = static_cast<OQueryTableView*>(_pView->getTableView());
132 [ # # ][ # # ]: 0 : OQueryTableConnection* pConn = static_cast<OQueryTableConnection*>( pTableView->GetTabConn(static_cast<OTableWindow*>(_aDragLeft->GetTabWindow()),static_cast<OTableWindow*>(_aDragRight->GetTabWindow()),true));
133 : :
134 [ # # ]: 0 : if ( !pConn )
135 : : {
136 [ # # ][ # # ]: 0 : OQueryTableConnectionData* pInfoData = new OQueryTableConnectionData();
137 [ # # ]: 0 : TTableConnectionData::value_type aInfoData(pInfoData);
138 [ # # ]: 0 : pInfoData->InitFromDrag(_aDragLeft, _aDragRight);
139 : 0 : pInfoData->SetJoinType(_eJoinType);
140 : :
141 [ # # ]: 0 : if ( _bNatural )
142 : : {
143 [ # # ]: 0 : aInfoData->ResetConnLines();
144 : 0 : pInfoData->setNatural(_bNatural);
145 : : try
146 : : {
147 [ # # ][ # # ]: 0 : Reference<XNameAccess> xReferencedTableColumns(aInfoData->getReferencedTable()->getColumns());
[ # # ]
148 [ # # ][ # # ]: 0 : Sequence< ::rtl::OUString> aSeq = aInfoData->getReferencingTable()->getColumns()->getElementNames();
[ # # ][ # # ]
[ # # ]
149 : 0 : const ::rtl::OUString* pIter = aSeq.getConstArray();
150 : 0 : const ::rtl::OUString* pEnd = pIter + aSeq.getLength();
151 [ # # ]: 0 : for(;pIter != pEnd;++pIter)
152 : : {
153 [ # # ][ # # ]: 0 : if ( xReferencedTableColumns->hasByName(*pIter) )
[ # # ]
154 [ # # ]: 0 : aInfoData->AppendConnLine(*pIter,*pIter);
155 [ # # ][ # # ]: 0 : }
156 : : }
157 [ # # ]: 0 : catch( const Exception& )
158 : : {
159 : : DBG_UNHANDLED_EXCEPTION();
160 : : }
161 : : }
162 : :
163 [ # # ]: 0 : OQueryTableConnection aInfo(pTableView, aInfoData);
164 : : // da ein OQueryTableConnection-Objekt nie den Besitz der uebergebenen Daten uebernimmt, sondern sich nur den Zeiger merkt,
165 : : // ist dieser Zeiger auf eine lokale Variable hier unkritisch, denn aInfoData und aInfo haben die selbe Lebensdauer
166 [ # # ][ # # ]: 0 : pTableView->NotifyTabConnection( aInfo );
[ # # ]
167 : : }
168 : : else
169 : : {
170 : 0 : ::rtl::OUString aSourceFieldName(_aDragLeft->GetField());
171 : 0 : ::rtl::OUString aDestFieldName(_aDragRight->GetField());
172 : : // the connection could point on the other side
173 [ # # ][ # # ]: 0 : if(pConn->GetSourceWin() == _aDragRight->GetTabWindow())
[ # # ]
174 : : {
175 : 0 : ::rtl::OUString aTmp(aSourceFieldName);
176 : 0 : aSourceFieldName = aDestFieldName;
177 : 0 : aDestFieldName = aTmp;
178 : : }
179 [ # # ][ # # ]: 0 : pConn->GetData()->AppendConnLine( aSourceFieldName,aDestFieldName);
[ # # ]
180 [ # # ]: 0 : pConn->UpdateLineList();
181 : : // Modified-Flag
182 : : // SetModified();
183 : : // und neu zeichnen
184 [ # # ]: 0 : pConn->RecalcLines();
185 : : // fuer das unten folgende Invalidate muss ich dieser neuen Connection erst mal die Moeglichkeit geben,
186 : : // ihr BoundingRect zu ermitteln
187 [ # # ]: 0 : pConn->InvalidateConnection();
188 : : }
189 : 0 : }
190 : : //------------------------------------------------------------------------------
191 : 0 : ::rtl::OUString ParseCondition( OQueryController& rController
192 : : ,const ::connectivity::OSQLParseNode* pCondition
193 : : ,const ::rtl::OUString _sDecimal
194 : : ,const ::com::sun::star::lang::Locale& _rLocale
195 : : ,sal_uInt32 _nStartIndex)
196 : : {
197 : 0 : ::rtl::OUString aCondition;
198 [ # # ]: 0 : Reference< XConnection> xConnection = rController.getConnection();
199 [ # # ]: 0 : if ( xConnection.is() )
200 : : {
201 : 0 : sal_uInt32 nCount = pCondition->count();
202 [ # # ]: 0 : for(sal_uInt32 i = _nStartIndex ; i < nCount ; ++i)
203 : : pCondition->getChild(i)->parseNodeToPredicateStr(aCondition,
204 : : xConnection,
205 : : rController.getNumberFormatter(),
206 : : _rLocale,
207 : 0 : static_cast<sal_Char>(_sDecimal.toChar()),
208 [ # # ][ # # ]: 0 : &rController.getParser().getContext());
[ # # ]
209 : : }
210 : 0 : return aCondition;
211 : : }
212 : : //------------------------------------------------------------------------------
213 : 0 : SqlParseError FillOuterJoins(OQueryDesignView* _pView,
214 : : const ::connectivity::OSQLParseNode* pTableRefList)
215 : : {
216 : 0 : SqlParseError eErrorCode = eOk;
217 : 0 : sal_uInt32 nCount = pTableRefList->count();
218 : 0 : sal_Bool bError = sal_False;
219 [ # # ][ # # ]: 0 : for (sal_uInt32 i=0; !bError && i < nCount; ++i)
[ # # ]
220 : : {
221 : 0 : const ::connectivity::OSQLParseNode* pParseNode = pTableRefList->getChild(i);
222 : 0 : const ::connectivity::OSQLParseNode* pJoinNode = NULL;
223 : :
224 [ # # ][ # # ]: 0 : if ( SQL_ISRULE( pParseNode, qualified_join ) || SQL_ISRULE( pParseNode, joined_table ) || SQL_ISRULE( pParseNode, cross_union ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
225 : 0 : pJoinNode = pParseNode;
226 [ # # ]: 0 : else if( SQL_ISRULE(pParseNode,table_ref)
[ # # # # ]
[ # # ]
227 : 0 : && pParseNode->count() == 4 ) // '{' SQL_TOKEN_OJ joined_table '}'
228 : 0 : pJoinNode = pParseNode->getChild(2);
229 : :
230 [ # # ]: 0 : if ( pJoinNode )
231 : : {
232 [ # # ]: 0 : if ( !InsertJoin(_pView,pJoinNode) )
233 : 0 : bError = sal_True;
234 : : }
235 : : }
236 : : // check if error occurred
237 [ # # ]: 0 : if ( bError )
238 : 0 : eErrorCode = eIllegalJoin;
239 : :
240 : 0 : return eErrorCode;
241 : : }
242 : : // -----------------------------------------------------------------------------
243 : :
244 : : /** FillDragInfo fills the field description out of the table
245 : : */
246 : : //------------------------------------------------------------------------------
247 : 0 : SqlParseError FillDragInfo( const OQueryDesignView* _pView,
248 : : const ::connectivity::OSQLParseNode* pColumnRef,
249 : : OTableFieldDescRef& _rDragInfo)
250 : : {
251 : 0 : SqlParseError eErrorCode = eOk;
252 : :
253 : 0 : sal_Bool bErg = sal_False;
254 : :
255 : 0 : ::rtl::OUString aTableRange,aColumnName;
256 : : sal_uInt16 nCntAccount;
257 : 0 : ::connectivity::OSQLParseTreeIterator& rParseIter = static_cast<OQueryController&>(_pView->getController()).getParseIterator();
258 [ # # ]: 0 : rParseIter.getColumnRange( pColumnRef, aColumnName, aTableRange );
259 : :
260 [ # # ]: 0 : if ( !aTableRange.isEmpty() )
261 : : {
262 [ # # ][ # # ]: 0 : OQueryTableWindow* pSTW = static_cast<OQueryTableView*>(_pView->getTableView())->FindTable( aTableRange );
[ # # ]
263 [ # # ][ # # ]: 0 : bErg = (pSTW && pSTW->ExistsField( aColumnName, _rDragInfo ) );
[ # # ]
264 : : }
265 [ # # ]: 0 : if ( !bErg )
266 : : {
267 [ # # ][ # # ]: 0 : bErg = static_cast<OQueryTableView*>(_pView->getTableView())->FindTableFromField(aColumnName, _rDragInfo, nCntAccount);
[ # # ]
268 [ # # ]: 0 : if ( !bErg )
269 [ # # ]: 0 : bErg = _pView->HasFieldByAliasName(aColumnName, _rDragInfo);
270 : : }
271 [ # # ]: 0 : if ( !bErg )
272 : : {
273 : 0 : eErrorCode = eColumnNotFound;
274 [ # # ][ # # ]: 0 : String sError(ModuleRes(STR_QRY_COLUMN_NOT_FOUND));
275 [ # # ][ # # ]: 0 : sError.SearchAndReplaceAscii("$name$",aColumnName);
[ # # ]
276 [ # # ][ # # ]: 0 : _pView->getController().appendError( sError );
277 : :
278 : : try
279 : : {
280 [ # # ][ # # ]: 0 : Reference<XDatabaseMetaData> xMeta = _pView->getController().getConnection()->getMetaData();
[ # # ]
281 [ # # ][ # # ]: 0 : if ( xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers() )
[ # # ][ # # ]
[ # # ]
282 [ # # ][ # # ]: 0 : _pView->getController().appendError( String( ModuleRes( STR_QRY_CHECK_CASESENSITIVE ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
283 : : }
284 [ # # ]: 0 : catch(Exception&)
285 : : {
286 [ # # ]: 0 : }
287 : : }
288 : :
289 : 0 : return eErrorCode;
290 : : }
291 : : //------------------------------------------------------------------------------
292 : 0 : ::rtl::OUString BuildJoinCriteria( const Reference< XConnection>& _xConnection,
293 : : OConnectionLineDataVec* pLineDataList,
294 : : OQueryTableConnectionData* pData)
295 : : {
296 : 0 : ::rtl::OUStringBuffer aCondition;
297 [ # # ]: 0 : if ( _xConnection.is() )
298 : : {
299 : 0 : OConnectionLineDataVec::iterator aIter = pLineDataList->begin();
300 : 0 : OConnectionLineDataVec::iterator aEnd = pLineDataList->end();
301 : : try
302 : : {
303 [ # # ][ # # ]: 0 : const Reference< XDatabaseMetaData > xMetaData = _xConnection->getMetaData();
304 [ # # ][ # # ]: 0 : const ::rtl::OUString aQuote = xMetaData->getIdentifierQuoteString();
305 [ # # ]: 0 : const ::rtl::OUString sEqual(RTL_CONSTASCII_USTRINGPARAM(" = "));
306 : :
307 [ # # ][ # # ]: 0 : for(;aIter != aEnd;++aIter)
308 : : {
309 [ # # ]: 0 : OConnectionLineDataRef pLineData = *aIter;
310 [ # # ]: 0 : if(aCondition.getLength())
311 [ # # ]: 0 : aCondition.append(C_AND);
312 [ # # ][ # # ]: 0 : aCondition.append(quoteTableAlias(sal_True,pData->GetAliasName(JTCS_FROM),aQuote));
[ # # ]
313 [ # # ][ # # ]: 0 : aCondition.append(::dbtools::quoteName(aQuote, pLineData->GetFieldName(JTCS_FROM) ));
314 [ # # ]: 0 : aCondition.append(sEqual);
315 [ # # ][ # # ]: 0 : aCondition.append(quoteTableAlias(sal_True,pData->GetAliasName(JTCS_TO),aQuote));
[ # # ]
316 [ # # ][ # # ]: 0 : aCondition.append(::dbtools::quoteName(aQuote, pLineData->GetFieldName(JTCS_TO) ));
317 [ # # ][ # # ]: 0 : }
318 : : }
319 [ # # ]: 0 : catch(SQLException&)
320 : : {
321 : : OSL_FAIL("Failure while building Join criteria!");
322 : : }
323 : : }
324 : :
325 [ # # ]: 0 : return aCondition.makeStringAndClear();
326 : : }
327 : : //------------------------------------------------------------------------------
328 : : /** JoinCycle looks for a join cycle and append it to the string
329 : : @param _xConnection the connection
330 : : @param _pEntryConn the table connection which holds the data
331 : : @param _pEntryTabTo the corresponding table window
332 : : @param _rJoin the String which will contain the resulting string
333 : : */
334 : 0 : void JoinCycle( const Reference< XConnection>& _xConnection,
335 : : OQueryTableConnection* _pEntryConn,
336 : : const OQueryTableWindow* _pEntryTabTo,
337 : : ::rtl::OUString& _rJoin )
338 : : {
339 : : OSL_ENSURE(_pEntryConn,"TableConnection can not be null!");
340 : :
341 : 0 : OQueryTableConnectionData* pData = static_cast< OQueryTableConnectionData*>(_pEntryConn->GetData().get());
342 [ # # ][ # # ]: 0 : if ( pData->GetJoinType() != INNER_JOIN && _pEntryTabTo->ExistsAVisitedConn() )
[ # # ]
343 : : {
344 : 0 : sal_Bool bBrace = sal_False;
345 [ # # ][ # # ]: 0 : if(!_rJoin.isEmpty() && _rJoin.lastIndexOf(')') == (_rJoin.getLength()-1))
[ # # ]
346 : : {
347 : 0 : bBrace = sal_True;
348 : 0 : _rJoin = _rJoin.replaceAt(_rJoin.getLength()-1,1,::rtl::OUString(' '));
349 : : }
350 : 0 : (_rJoin += C_AND) += BuildJoinCriteria(_xConnection,pData->GetConnLineDataList(),pData);
351 [ # # ]: 0 : if(bBrace)
352 : 0 : _rJoin += ::rtl::OUString(')');
353 : 0 : _pEntryConn->SetVisited(sal_True);
354 : : }
355 : 0 : }
356 : : //------------------------------------------------------------------------------
357 : 0 : ::rtl::OUString BuildTable( const Reference< XConnection>& _xConnection,
358 : : const OQueryTableWindow* pEntryTab,
359 : : bool _bForce = false
360 : : )
361 : : {
362 : 0 : ::rtl::OUString aDBName(pEntryTab->GetComposedName());
363 : :
364 [ # # ]: 0 : if( _xConnection.is() )
365 : : {
366 : : try
367 : : {
368 [ # # ][ # # ]: 0 : Reference< XDatabaseMetaData > xMetaData = _xConnection->getMetaData();
369 : :
370 : 0 : ::rtl::OUString sCatalog, sSchema, sTable;
371 [ # # ]: 0 : ::dbtools::qualifiedNameComponents( xMetaData, aDBName, sCatalog, sSchema, sTable, ::dbtools::eInDataManipulation );
372 [ # # ]: 0 : ::rtl::OUString aTableListStr = ::dbtools::composeTableNameForSelect( _xConnection, sCatalog, sSchema, sTable );
373 : :
374 [ # # ][ # # ]: 0 : ::rtl::OUString aQuote = xMetaData->getIdentifierQuoteString();
375 [ # # ][ # # ]: 0 : if ( _bForce || isAppendTableAliasEnabled( _xConnection ) || pEntryTab->GetAliasName() != aDBName )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
376 : : {
377 [ # # ]: 0 : aTableListStr += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" "));
378 [ # # ][ # # ]: 0 : if ( generateAsBeforeTableAlias( _xConnection ) )
379 [ # # ]: 0 : aTableListStr += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AS "));
380 [ # # ][ # # ]: 0 : aTableListStr += ::dbtools::quoteName( aQuote, pEntryTab->GetAliasName() );
381 : : }
382 [ # # ]: 0 : aDBName = aTableListStr;
383 : : }
384 [ # # ]: 0 : catch(const SQLException&)
385 : : {
386 : : DBG_UNHANDLED_EXCEPTION();
387 : : }
388 : : }
389 : 0 : return aDBName;
390 : : }
391 : : //------------------------------------------------------------------------------
392 : 0 : ::rtl::OUString BuildJoin( const Reference< XConnection>& _xConnection,
393 : : const ::rtl::OUString& rLh,
394 : : const ::rtl::OUString& rRh,
395 : : OQueryTableConnectionData* pData)
396 : : {
397 : :
398 [ # # ]: 0 : String aErg(rLh);
399 [ # # ][ # # ]: 0 : if ( pData->isNatural() && pData->GetJoinType() != CROSS_JOIN )
[ # # ]
400 [ # # ]: 0 : aErg.AppendAscii(" NATURAL ");
401 [ # # # # : 0 : switch(pData->GetJoinType())
# ]
402 : : {
403 : : case LEFT_JOIN:
404 [ # # ]: 0 : aErg.AppendAscii(" LEFT OUTER ");
405 : 0 : break;
406 : : case RIGHT_JOIN:
407 [ # # ]: 0 : aErg.AppendAscii(" RIGHT OUTER ");
408 : 0 : break;
409 : : case CROSS_JOIN:
410 : : OSL_ENSURE(!pData->isNatural(),"OQueryDesignView::BuildJoin: This should not happen!");
411 [ # # ]: 0 : aErg.AppendAscii(" CROSS ");
412 : 0 : break;
413 : : case INNER_JOIN:
414 : : OSL_ENSURE(pData->isNatural(),"OQueryDesignView::BuildJoin: This should not happen!");
415 [ # # ]: 0 : aErg.AppendAscii(" INNER ");
416 : 0 : break;
417 : : default:
418 [ # # ]: 0 : aErg.AppendAscii(" FULL OUTER ");
419 : 0 : break;
420 : : }
421 [ # # ]: 0 : aErg.AppendAscii("JOIN ");
422 [ # # ][ # # ]: 0 : aErg += String(rRh);
[ # # ]
423 [ # # ][ # # ]: 0 : if ( CROSS_JOIN != pData->GetJoinType() && !pData->isNatural() )
[ # # ]
424 : : {
425 [ # # ]: 0 : aErg.AppendAscii(" ON ");
426 [ # # ][ # # ]: 0 : aErg += String(BuildJoinCriteria(_xConnection,pData->GetConnLineDataList(),pData));
[ # # ][ # # ]
427 : : }
428 : :
429 [ # # ][ # # ]: 0 : return aErg;
430 : : }
431 : : //------------------------------------------------------------------------------
432 : 0 : ::rtl::OUString BuildJoin( const Reference< XConnection>& _xConnection,
433 : : OQueryTableWindow* pLh,
434 : : OQueryTableWindow* pRh,
435 : : OQueryTableConnectionData* pData
436 : : )
437 : : {
438 [ # # ][ # # ]: 0 : bool bForce = pData->GetJoinType() == CROSS_JOIN || pData->isNatural();
439 [ # # ][ # # ]: 0 : return BuildJoin(_xConnection,BuildTable(_xConnection,pLh,bForce),BuildTable(_xConnection,pRh,bForce),pData);
440 : : }
441 : : //------------------------------------------------------------------------------
442 : 0 : ::rtl::OUString BuildJoin( const Reference< XConnection>& _xConnection,
443 : : const ::rtl::OUString &rLh,
444 : : OQueryTableWindow* pRh,
445 : : OQueryTableConnectionData* pData
446 : : )
447 : : {
448 [ # # ]: 0 : return BuildJoin(_xConnection,rLh,BuildTable(_xConnection,pRh),pData);
449 : : }
450 : : //------------------------------------------------------------------------------
451 : 0 : ::rtl::OUString BuildJoin( const Reference< XConnection>& _xConnection,
452 : : OQueryTableWindow* pLh,
453 : : const ::rtl::OUString &rRh,
454 : : OQueryTableConnectionData* pData
455 : : )
456 : : {
457 [ # # ]: 0 : return BuildJoin(_xConnection,BuildTable(_xConnection,pLh),rRh,pData);
458 : : }
459 : : //------------------------------------------------------------------------------
460 : 0 : void GetNextJoin( const Reference< XConnection>& _xConnection,
461 : : OQueryTableConnection* pEntryConn,
462 : : OQueryTableWindow* pEntryTabTo,
463 : : ::rtl::OUString &aJoin)
464 : : {
465 [ # # ][ # # ]: 0 : OQueryTableConnectionData* pEntryConnData = static_cast<OQueryTableConnectionData*>(pEntryConn->GetData().get());
466 [ # # ][ # # ]: 0 : if ( pEntryConnData->GetJoinType() == INNER_JOIN && !pEntryConnData->isNatural() )
[ # # ]
467 : 0 : return;
468 : :
469 [ # # ]: 0 : if(aJoin.isEmpty())
470 : : {
471 [ # # ]: 0 : OQueryTableWindow* pEntryTabFrom = static_cast<OQueryTableWindow*>(pEntryConn->GetSourceWin());
472 [ # # ]: 0 : aJoin = BuildJoin(_xConnection,pEntryTabFrom,pEntryTabTo,pEntryConnData);
473 : : }
474 [ # # ][ # # ]: 0 : else if(pEntryTabTo == pEntryConn->GetDestWin())
475 : : {
476 [ # # ]: 0 : aJoin = BuildJoin(_xConnection,aJoin,pEntryTabTo,pEntryConnData);
477 : : }
478 [ # # ][ # # ]: 0 : else if(pEntryTabTo == pEntryConn->GetSourceWin())
479 : : {
480 [ # # ]: 0 : aJoin = BuildJoin(_xConnection,pEntryTabTo,aJoin,pEntryConnData);
481 : : }
482 : :
483 : 0 : pEntryConn->SetVisited(sal_True);
484 : :
485 : : // first search for the "to" window
486 : 0 : const ::std::vector<OTableConnection*>* pConnections = pEntryConn->GetParent()->getTableConnections();
487 : 0 : ::std::vector<OTableConnection*>::const_iterator aIter = pConnections->begin();
488 : 0 : ::std::vector<OTableConnection*>::const_iterator aEnd = pConnections->end();
489 [ # # ][ # # ]: 0 : for(;aIter != aEnd;++aIter)
490 : : {
491 : 0 : OQueryTableConnection* pNext = static_cast<OQueryTableConnection*>(*aIter);
492 [ # # ][ # # ]: 0 : if(!pNext->IsVisited() && (pNext->GetSourceWin() == pEntryTabTo || pNext->GetDestWin() == pEntryTabTo))
[ # # ][ # # ]
[ # # ][ # # ]
493 : : {
494 [ # # ][ # # ]: 0 : OQueryTableWindow* pEntryTab = pNext->GetSourceWin() == pEntryTabTo ? static_cast<OQueryTableWindow*>(pNext->GetDestWin()) : static_cast<OQueryTableWindow*>(pNext->GetSourceWin());
[ # # ][ # # ]
495 : : // exists there a connection to a OQueryTableWindow that holds a connection that has been already visited
496 [ # # ]: 0 : JoinCycle(_xConnection,pNext,pEntryTab,aJoin);
497 [ # # ]: 0 : if(!pNext->IsVisited())
498 [ # # ]: 0 : GetNextJoin(_xConnection,pNext,pEntryTab,aJoin);
499 : : }
500 : : }
501 : :
502 : : // when nothing found found look for the "from" window
503 [ # # ][ # # ]: 0 : if(aIter == aEnd)
504 : : {
505 [ # # ]: 0 : OQueryTableWindow* pEntryTabFrom = static_cast<OQueryTableWindow*>(pEntryConn->GetSourceWin());
506 : 0 : aIter = pConnections->begin();
507 [ # # ][ # # ]: 0 : for(;aIter != aEnd;++aIter)
508 : : {
509 : 0 : OQueryTableConnection* pNext = static_cast<OQueryTableConnection*>(*aIter);
510 [ # # ][ # # ]: 0 : if(!pNext->IsVisited() && (pNext->GetSourceWin() == pEntryTabFrom || pNext->GetDestWin() == pEntryTabFrom))
[ # # ][ # # ]
[ # # ][ # # ]
511 : : {
512 [ # # ][ # # ]: 0 : OQueryTableWindow* pEntryTab = pNext->GetSourceWin() == pEntryTabFrom ? static_cast<OQueryTableWindow*>(pNext->GetDestWin()) : static_cast<OQueryTableWindow*>(pNext->GetSourceWin());
[ # # ][ # # ]
513 : : // exists there a connection to a OQueryTableWindow that holds a connection that has been already visited
514 [ # # ]: 0 : JoinCycle(_xConnection,pNext,pEntryTab,aJoin);
515 [ # # ]: 0 : if(!pNext->IsVisited())
516 [ # # ]: 0 : GetNextJoin(_xConnection,pNext,pEntryTab,aJoin);
517 : : }
518 : : }
519 : : }
520 : : }
521 : : //------------------------------------------------------------------------------
522 : 0 : SqlParseError InsertJoinConnection( const OQueryDesignView* _pView,
523 : : const ::connectivity::OSQLParseNode *pNode,
524 : : const EJoinType& _eJoinType,
525 : : const ::connectivity::OSQLParseNode *pLeftTable,
526 : : const ::connectivity::OSQLParseNode *pRightTable)
527 : : {
528 : 0 : SqlParseError eErrorCode = eOk;
529 [ # # # # : 0 : if (pNode->count() == 3 && // Ausdruck is geklammert
# # # # #
# ][ # # ]
530 : 0 : SQL_ISPUNCTUATION(pNode->getChild(0),"(") &&
531 : 0 : SQL_ISPUNCTUATION(pNode->getChild(2),")"))
532 : : {
533 : 0 : eErrorCode = InsertJoinConnection(_pView,pNode->getChild(1), _eJoinType,pLeftTable,pRightTable);
534 : : }
535 [ # # ][ # # ]: 0 : else if (SQL_ISRULEOR2(pNode,search_condition,boolean_term) && // AND/OR-Verknuepfung:
[ # # # # ]
[ # # ]
536 : 0 : pNode->count() == 3)
537 : : {
538 : : // nur AND Verkn�pfung zulassen
539 [ # # ][ # # ]: 0 : if (!SQL_ISTOKEN(pNode->getChild(1),AND))
[ # # ]
540 : 0 : eErrorCode = eIllegalJoinCondition;
541 [ # # ]: 0 : else if ( eOk == (eErrorCode = InsertJoinConnection(_pView,pNode->getChild(0), _eJoinType,pLeftTable,pRightTable)) )
542 : 0 : eErrorCode = InsertJoinConnection(_pView,pNode->getChild(2), _eJoinType,pLeftTable,pRightTable);
543 : : }
544 [ # # ][ # # ]: 0 : else if (SQL_ISRULE(pNode,comparison_predicate))
[ # # ]
545 : : {
546 : : // only the comparison of columns is allowed
547 : : OSL_ENSURE(pNode->count() == 3,"OQueryDesignView::InsertJoinConnection: Fehler im Parse Tree");
548 [ # # ][ # # ]: 0 : if (!(SQL_ISRULE(pNode->getChild(0),column_ref) &&
[ # # ][ # # ]
549 [ # # ][ # # ]: 0 : SQL_ISRULE(pNode->getChild(2),column_ref) &&
[ # # ]
550 [ # # # # ]: 0 : pNode->getChild(1)->getNodeType() == SQL_NODE_EQUAL))
[ # # ][ # # ]
[ # # ][ # # ]
551 : : {
552 [ # # ][ # # ]: 0 : String sError(ModuleRes(STR_QRY_JOIN_COLUMN_COMPARE));
553 [ # # ][ # # ]: 0 : _pView->getController().appendError( sError );
554 [ # # ]: 0 : return eIllegalJoin;
555 : : }
556 : :
557 [ # # ][ # # ]: 0 : OTableFieldDescRef aDragLeft = new OTableFieldDesc();
[ # # ]
558 [ # # ][ # # ]: 0 : OTableFieldDescRef aDragRight = new OTableFieldDesc();
[ # # ]
559 [ # # ][ # # ]: 0 : if ( eOk != ( eErrorCode = FillDragInfo(_pView,pNode->getChild(0),aDragLeft)) ||
[ # # ][ # # ]
[ # # ][ # # ]
560 [ # # ]: 0 : eOk != ( eErrorCode = FillDragInfo(_pView,pNode->getChild(2),aDragRight)))
561 : 0 : return eErrorCode;
562 : :
563 [ # # ]: 0 : if ( pLeftTable )
564 : : {
565 [ # # ][ # # ]: 0 : OQueryTableWindow* pLeftWindow = static_cast<OQueryTableView*>(_pView->getTableView())->FindTable( getTableRange(_pView,pLeftTable->getByRule(OSQLParseNode::table_ref) ));
[ # # ][ # # ]
[ # # ]
566 [ # # ][ # # ]: 0 : if ( pLeftWindow == aDragLeft->GetTabWindow() )
567 [ # # ][ # # ]: 0 : insertConnection(_pView,_eJoinType,aDragLeft,aDragRight);
[ # # ][ # # ]
[ # # ]
568 : : else
569 [ # # ][ # # ]: 0 : insertConnection(_pView,_eJoinType,aDragRight,aDragLeft);
[ # # ][ # # ]
[ # # ]
570 : : }
571 : : else
572 [ # # ][ # # ]: 0 : insertConnection(_pView,_eJoinType,aDragLeft,aDragRight);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
573 : : }
574 : : else
575 : 0 : eErrorCode = eIllegalJoin;
576 : 0 : return eErrorCode;
577 : : }
578 : : //------------------------------------------------------------------------------
579 : 0 : sal_Bool GetInnerJoinCriteria( const OQueryDesignView* _pView,
580 : : const ::connectivity::OSQLParseNode *pCondition)
581 : : {
582 [ # # ]: 0 : return InsertJoinConnection(_pView,pCondition, INNER_JOIN,NULL,NULL) != eOk;
583 : : }
584 : : //------------------------------------------------------------------------------
585 : 0 : ::rtl::OUString GenerateSelectList( const OQueryDesignView* _pView,
586 : : OTableFields& _rFieldList,
587 : : sal_Bool bAlias)
588 : : {
589 [ # # ]: 0 : Reference< XConnection> xConnection = static_cast<OQueryController&>(_pView->getController()).getConnection();
590 [ # # ]: 0 : if ( !xConnection.is() )
591 : 0 : return ::rtl::OUString();
592 : :
593 : 0 : ::rtl::OUStringBuffer aTmpStr,aFieldListStr;
594 : :
595 : 0 : sal_Bool bAsterix = sal_False;
596 : 0 : int nVis = 0;
597 : 0 : OTableFields::iterator aIter = _rFieldList.begin();
598 : 0 : OTableFields::iterator aEnd = _rFieldList.end();
599 [ # # ][ # # ]: 0 : for(;aIter != aEnd;++aIter)
600 : : {
601 [ # # ]: 0 : OTableFieldDescRef pEntryField = *aIter;
602 [ # # ]: 0 : if ( pEntryField->IsVisible() )
603 : : {
604 [ # # ]: 0 : if ( pEntryField->GetField().toChar() == '*' )
605 : 0 : bAsterix = sal_True;
606 : 0 : ++nVis;
607 : : }
608 [ # # ]: 0 : }
609 [ # # ]: 0 : if(nVis == 1)
610 : 0 : bAsterix = sal_False;
611 : :
612 : : try
613 : : {
614 [ # # ][ # # ]: 0 : const Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
615 [ # # ][ # # ]: 0 : const ::rtl::OUString aQuote = xMetaData->getIdentifierQuoteString();
616 : :
617 : 0 : OJoinTableView::OTableWindowMap* pTabList = _pView->getTableView()->GetTabWinMap();
618 : :
619 [ # # ][ # # ]: 0 : const static ::rtl::OUString sFieldSeparator(RTL_CONSTASCII_USTRINGPARAM(", "));
[ # # ][ # # ]
620 [ # # ][ # # ]: 0 : const static ::rtl::OUString s_sAs(RTL_CONSTASCII_USTRINGPARAM(" AS "));
[ # # ][ # # ]
621 : :
622 : 0 : aIter = _rFieldList.begin();
623 [ # # ][ # # ]: 0 : for(;aIter != aEnd;++aIter)
624 : : {
625 [ # # ]: 0 : OTableFieldDescRef pEntryField = *aIter;
626 : 0 : ::rtl::OUString rFieldName = pEntryField->GetField();
627 [ # # ][ # # ]: 0 : if ( !rFieldName.isEmpty() && pEntryField->IsVisible() )
[ # # ]
628 : : {
629 [ # # ][ # # ]: 0 : aTmpStr = ::rtl::OUString();
630 : 0 : const ::rtl::OUString rAlias = pEntryField->GetAlias();
631 : 0 : const ::rtl::OUString rFieldAlias = pEntryField->GetFieldAlias();
632 : :
633 [ # # ][ # # ]: 0 : aTmpStr.append(quoteTableAlias((bAlias || bAsterix),rAlias,aQuote));
[ # # ][ # # ]
634 : :
635 : : // if we have a none numeric field, the table alias could be in the name
636 : : // otherwise we are not allowed to do this (e.g. 0.1 * PRICE )
637 [ # # ]: 0 : if ( !pEntryField->isOtherFunction() )
638 : : {
639 : : // we have to look if we have alias.* here but before we have to check if the column doesn't already exist
640 [ # # ]: 0 : String sTemp = rFieldName;
641 [ # # ][ # # ]: 0 : OTableFieldDescRef aInfo = new OTableFieldDesc();
[ # # ]
642 : 0 : OJoinTableView::OTableWindowMap::iterator tableIter = pTabList->begin();
643 : 0 : OJoinTableView::OTableWindowMap::iterator tableEnd = pTabList->end();
644 : 0 : sal_Bool bFound = sal_False;
645 [ # # ][ # # ]: 0 : for(;!bFound && tableIter != tableEnd ;++tableIter)
[ # # ]
646 : : {
647 : 0 : OQueryTableWindow* pTabWin = static_cast<OQueryTableWindow*>(tableIter->second);
648 : :
649 [ # # ]: 0 : bFound = pTabWin->ExistsField( rFieldName, aInfo );
650 [ # # ]: 0 : if ( bFound )
651 : 0 : rFieldName = aInfo->GetField();
652 : : }
653 [ # # ][ # # ]: 0 : if ( ( rFieldName.toChar() != '*' ) && ( rFieldName.indexOf( aQuote ) == -1 ) )
[ # # ]
654 : : {
655 : : OSL_ENSURE(!pEntryField->GetTable().isEmpty(),"No table field name!");
656 [ # # ][ # # ]: 0 : aTmpStr.append(::dbtools::quoteName(aQuote, rFieldName));
657 : : }
658 : : else
659 [ # # ][ # # ]: 0 : aTmpStr.append(rFieldName);
[ # # ]
660 : : }
661 : : else
662 [ # # ]: 0 : aTmpStr.append(rFieldName);
663 : :
664 [ # # ]: 0 : if ( pEntryField->isAggreateFunction() )
665 : : {
666 : : OSL_ENSURE(!pEntryField->GetFunction().isEmpty(),"Functionname darf hier nicht leer sein! ;-(");
667 [ # # ]: 0 : ::rtl::OUStringBuffer aTmpStr2( pEntryField->GetFunction());
668 [ # # ]: 0 : aTmpStr2.appendAscii("(");
669 [ # # ][ # # ]: 0 : aTmpStr2.append(aTmpStr.makeStringAndClear());
670 [ # # ]: 0 : aTmpStr2.appendAscii(")");
671 [ # # ]: 0 : aTmpStr = aTmpStr2;
672 : : }
673 : :
674 [ # # # # : 0 : if (!rFieldAlias.isEmpty() &&
# # # # ]
[ # # ]
675 : 0 : (rFieldName.toChar() != '*' ||
676 : 0 : pEntryField->isNumericOrAggreateFunction() ||
677 : 0 : pEntryField->isOtherFunction()))
678 : : {
679 [ # # ]: 0 : aTmpStr.append(s_sAs);
680 [ # # ][ # # ]: 0 : aTmpStr.append(::dbtools::quoteName(aQuote, rFieldAlias));
681 : : }
682 [ # # ][ # # ]: 0 : aFieldListStr.append(aTmpStr.makeStringAndClear());
683 [ # # ]: 0 : aFieldListStr.append(sFieldSeparator);
684 : : }
685 [ # # ]: 0 : }
686 [ # # ]: 0 : if(aFieldListStr.getLength())
687 [ # # ][ # # ]: 0 : aFieldListStr.setLength(aFieldListStr.getLength()-2);
688 : : }
689 [ # # ]: 0 : catch(SQLException&)
690 : : {
691 : : OSL_FAIL("Failure while building select list!");
692 : : }
693 [ # # ]: 0 : return aFieldListStr.makeStringAndClear();
694 : : }
695 : : //------------------------------------------------------------------------------
696 : 0 : sal_Bool GenerateCriterias( OQueryDesignView* _pView,
697 : : ::rtl::OUStringBuffer& rRetStr,
698 : : ::rtl::OUStringBuffer& rHavingStr,
699 : : OTableFields& _rFieldList,
700 : : sal_Bool bMulti )
701 : : {
702 : : // * darf keine Filter enthalten : habe ich die entsprechende Warnung schon angezeigt ?
703 : 0 : sal_Bool bCritsOnAsterikWarning = sal_False; // ** TMFS **
704 : :
705 : 0 : ::rtl::OUString aFieldName,aCriteria,aWhereStr,aHavingStr,aWork/*,aOrderStr*/;
706 : : // Zeilenweise werden die Ausdr"ucke mit AND verknuepft
707 : 0 : sal_uInt16 nMaxCriteria = 0;
708 : 0 : OTableFields::iterator aIter = _rFieldList.begin();
709 : 0 : OTableFields::iterator aEnd = _rFieldList.end();
710 [ # # ][ # # ]: 0 : for(;aIter != aEnd;++aIter)
711 : : {
712 [ # # ]: 0 : nMaxCriteria = ::std::max<sal_uInt16>(nMaxCriteria,(sal_uInt16)(*aIter)->GetCriteria().size());
713 : : }
714 [ # # ]: 0 : Reference< XConnection> xConnection = static_cast<OQueryController&>(_pView->getController()).getConnection();
715 [ # # ]: 0 : if(!xConnection.is())
716 : 0 : return sal_False;
717 : : try
718 : : {
719 [ # # ][ # # ]: 0 : const Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
720 [ # # ][ # # ]: 0 : const ::rtl::OUString aQuote = xMetaData->getIdentifierQuoteString();
721 : 0 : const IParseContext& rContext = static_cast<OQueryController&>(_pView->getController()).getParser().getContext();
722 : :
723 [ # # ]: 0 : for (sal_uInt16 i=0 ; i < nMaxCriteria ; i++)
724 : : {
725 : 0 : aHavingStr = aWhereStr = ::rtl::OUString();
726 : :
727 [ # # ][ # # ]: 0 : for(aIter = _rFieldList.begin();aIter != aEnd;++aIter)
728 : : {
729 [ # # ]: 0 : OTableFieldDescRef pEntryField = *aIter;
730 : 0 : aFieldName = pEntryField->GetField();
731 : :
732 [ # # ]: 0 : if (aFieldName.isEmpty())
733 : 0 : continue;
734 [ # # ]: 0 : aCriteria = pEntryField->GetCriteria( i );
735 [ # # ]: 0 : if ( !aCriteria.isEmpty() )
736 : : {
737 : : // * is not allowed to contain any filter, only when used in combination an aggregate function
738 [ # # ][ # # ]: 0 : if ( aFieldName.toChar() == '*' && pEntryField->isNoneFunction() )
[ # # ]
739 : : {
740 : : // only show the messagebox the first time
741 [ # # ]: 0 : if (!bCritsOnAsterikWarning)
742 [ # # ][ # # ]: 0 : ErrorBox(_pView, ModuleRes( ERR_QRY_CRITERIA_ON_ASTERISK)).Execute();
[ # # ][ # # ]
743 : 0 : bCritsOnAsterikWarning = sal_True;
744 : 0 : continue;
745 : : }
746 : 0 : aWork = ::rtl::OUString();
747 : :
748 : :
749 [ # # ]: 0 : aWork += quoteTableAlias(bMulti,pEntryField->GetAlias(),aQuote);
750 : :
751 [ # # ][ # # ]: 0 : if ( (pEntryField->GetFunctionType() & (FKT_OTHER|FKT_NUMERIC)) || (aFieldName.toChar() == '*') )
[ # # ]
752 : 0 : aWork += aFieldName;
753 : : else
754 [ # # ]: 0 : aWork += ::dbtools::quoteName(aQuote, aFieldName);
755 : :
756 [ # # ][ # # ]: 0 : if ( pEntryField->isAggreateFunction() || pEntryField->IsGroupBy() )
[ # # ]
757 : : {
758 [ # # ]: 0 : if (aHavingStr.isEmpty()) // noch keine Kriterien
759 : 0 : aHavingStr += ::rtl::OUString('('); // Klammern
760 : : else
761 : 0 : aHavingStr += C_AND;
762 : :
763 [ # # ]: 0 : if ( pEntryField->isAggreateFunction() )
764 : : {
765 : : OSL_ENSURE(!pEntryField->GetFunction().isEmpty(),"No function name for aggregate given!");
766 : 0 : aHavingStr += pEntryField->GetFunction();
767 : 0 : aHavingStr += ::rtl::OUString('('); // Klammern
768 : 0 : aHavingStr += aWork;
769 : 0 : aHavingStr += ::rtl::OUString(')'); // Klammern
770 : : }
771 : : else
772 : 0 : aHavingStr += aWork;
773 : :
774 : 0 : ::rtl::OUString aTmp = aCriteria;
775 : 0 : ::rtl::OUString aErrorMsg;
776 : 0 : Reference<XPropertySet> xColumn;
777 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
778 [ # # ][ # # ]: 0 : ::std::auto_ptr< ::connectivity::OSQLParseNode> pParseNode(_pView->getPredicateTreeFromEntry(pEntryField,aTmp,aErrorMsg,xColumn));
[ # # ][ # # ]
[ # # ]
779 : : SAL_WNODEPRECATED_DECLARATIONS_POP
780 [ # # ]: 0 : if (pParseNode.get())
781 : : {
782 [ # # ][ # # ]: 0 : if (bMulti && !(pEntryField->isOtherFunction() || (aFieldName.toChar() == '*')))
[ # # ][ # # ]
783 [ # # ]: 0 : pParseNode->replaceNodeValue(pEntryField->GetAlias(),aFieldName);
784 : 0 : ::rtl::OUString sHavingStr = aHavingStr;
785 : :
786 : 0 : sal_uInt32 nCount = pParseNode->count();
787 [ # # ]: 0 : for( sal_uInt32 node = 1 ; node < nCount ; ++node)
788 : : pParseNode->getChild(node)->parseNodeToStr( sHavingStr,
789 : : xConnection,
790 : : &rContext,
791 : : sal_False,
792 [ # # ][ # # ]: 0 : !pEntryField->isOtherFunction());
793 : 0 : aHavingStr = sHavingStr;
794 : : }
795 : : else
796 [ # # ]: 0 : aHavingStr += aCriteria;
797 : : }
798 : : else
799 : : {
800 [ # # ]: 0 : if ( aWhereStr.isEmpty() ) // noch keine Kriterien
801 : 0 : aWhereStr += ::rtl::OUString('('); // Klammern
802 : : else
803 : 0 : aWhereStr += C_AND;
804 : :
805 : 0 : aWhereStr += ::rtl::OUString(' ');
806 : : // aCriteria could have some german numbers so I have to be sure here
807 : 0 : ::rtl::OUString aTmp = aCriteria;
808 : 0 : ::rtl::OUString aErrorMsg;
809 : 0 : Reference<XPropertySet> xColumn;
810 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
811 [ # # ][ # # ]: 0 : ::std::auto_ptr< ::connectivity::OSQLParseNode> pParseNode( _pView->getPredicateTreeFromEntry(pEntryField,aTmp,aErrorMsg,xColumn));
[ # # ][ # # ]
[ # # ]
812 : : SAL_WNODEPRECATED_DECLARATIONS_POP
813 [ # # ]: 0 : if (pParseNode.get())
814 : : {
815 [ # # ][ # # ]: 0 : if (bMulti && !(pEntryField->isOtherFunction() || (aFieldName.toChar() == '*')))
[ # # ][ # # ]
816 [ # # ]: 0 : pParseNode->replaceNodeValue(pEntryField->GetAlias(),aFieldName);
817 : 0 : ::rtl::OUString aWhere = aWhereStr;
818 : : pParseNode->parseNodeToStr( aWhere,
819 : : xConnection,
820 : : &rContext,
821 : : sal_False,
822 [ # # ]: 0 : !pEntryField->isOtherFunction() );
823 : 0 : aWhereStr = aWhere;
824 : : }
825 : : else
826 : : {
827 : 0 : aWhereStr += aWork;
828 [ # # ]: 0 : aWhereStr += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("="));
829 : 0 : aWhereStr += aCriteria;
830 [ # # ]: 0 : }
831 : : }
832 : : }
833 : : // nur einmal f�r jedes Feld
834 [ # # ][ # # ]: 0 : else if ( !i && pEntryField->isCondition() )
[ # # ]
835 : : {
836 [ # # ]: 0 : if (aWhereStr.isEmpty()) // noch keine Kriterien
837 : 0 : aWhereStr += ::rtl::OUString('('); // Klammern
838 : : else
839 : 0 : aWhereStr += C_AND;
840 : 0 : aWhereStr += pEntryField->GetField();
841 : : }
842 [ # # ][ # # ]: 0 : }
843 [ # # ]: 0 : if (!aWhereStr.isEmpty())
844 : : {
845 : 0 : aWhereStr += ::rtl::OUString(')'); // Klammern zu fuer 'AND' Zweig
846 [ # # ]: 0 : if (rRetStr.getLength()) // schon Feldbedingungen ?
847 [ # # ]: 0 : rRetStr.append(C_OR);
848 : : else // Klammern auf fuer 'OR' Zweig
849 [ # # ]: 0 : rRetStr.append(sal_Unicode('('));
850 [ # # ]: 0 : rRetStr.append(aWhereStr);
851 : : }
852 [ # # ]: 0 : if (!aHavingStr.isEmpty())
853 : : {
854 : 0 : aHavingStr += ::rtl::OUString(')'); // Klammern zu fuer 'AND' Zweig
855 [ # # ]: 0 : if (rHavingStr.getLength()) // schon Feldbedingungen ?
856 [ # # ]: 0 : rHavingStr.append(C_OR);
857 : : else // Klammern auf fuer 'OR' Zweig
858 [ # # ]: 0 : rHavingStr.append(sal_Unicode('('));
859 [ # # ]: 0 : rHavingStr.append(aHavingStr);
860 : : }
861 : : }
862 : :
863 [ # # ]: 0 : if (rRetStr.getLength())
864 [ # # ]: 0 : rRetStr.append(sal_Unicode(')')); // Klammern zu fuer 'OR' Zweig
865 [ # # ]: 0 : if (rHavingStr.getLength())
866 [ # # ][ # # ]: 0 : rHavingStr.append(sal_Unicode(')')); // Klammern zu fuer 'OR' Zweig
867 : : }
868 [ # # ]: 0 : catch(SQLException&)
869 : : {
870 : : OSL_FAIL("Failure while building where clause!");
871 : : }
872 : 0 : return sal_True;
873 : : }
874 : : //------------------------------------------------------------------------------
875 : 0 : SqlParseError GenerateOrder( OQueryDesignView* _pView,
876 : : OTableFields& _rFieldList,
877 : : sal_Bool bMulti,
878 : : ::rtl::OUString& _rsRet)
879 : : {
880 : 0 : const OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
881 [ # # ]: 0 : Reference< XConnection> xConnection = rController.getConnection();
882 [ # # ]: 0 : if ( !xConnection.is() )
883 : 0 : return eNoConnection;
884 : :
885 : 0 : SqlParseError eErrorCode = eOk;
886 : :
887 : 0 : ::rtl::OUString aColumnName;
888 : 0 : ::rtl::OUString aWorkStr;
889 : : try
890 : : {
891 [ # # ][ # # ]: 0 : const bool bColumnAliasInOrderBy = rController.getSdbMetaData().supportsColumnAliasInOrderBy();
892 [ # # ][ # # ]: 0 : Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
893 [ # # ][ # # ]: 0 : ::rtl::OUString aQuote = xMetaData->getIdentifierQuoteString();
894 : : // * darf keine Filter enthalten : habe ich die entsprechende Warnung schon angezeigt ?
895 : 0 : sal_Bool bCritsOnAsterikWarning = sal_False; // ** TMFS **
896 : 0 : OTableFields::iterator aIter = _rFieldList.begin();
897 : 0 : OTableFields::iterator aEnd = _rFieldList.end();
898 [ # # ][ # # ]: 0 : for(;aIter != aEnd;++aIter)
899 : : {
900 [ # # ]: 0 : OTableFieldDescRef pEntryField = *aIter;
901 : 0 : EOrderDir eOrder = pEntryField->GetOrderDir();
902 : :
903 : : // nur wenn eine Sortierung und ein Tabellenname vorhanden ist-> erzeugen
904 : : // sonst werden die Expressions vom Order By im GenerateCriteria mit erzeugt
905 [ # # ]: 0 : if ( eOrder != ORDER_NONE )
906 : : {
907 : 0 : aColumnName = pEntryField->GetField();
908 [ # # ]: 0 : if(aColumnName.toChar() == '*')
909 : : {
910 : : // die entsprechende MessageBox nur beim ersten mal anzeigen
911 [ # # ]: 0 : if (!bCritsOnAsterikWarning)
912 [ # # ][ # # ]: 0 : ErrorBox(_pView, ModuleRes( ERR_QRY_ORDERBY_ON_ASTERISK)).Execute();
[ # # ][ # # ]
913 : 0 : bCritsOnAsterikWarning = sal_True;
914 : 0 : continue;
915 : : }
916 : :
917 [ # # ][ # # ]: 0 : if ( bColumnAliasInOrderBy && !pEntryField->GetFieldAlias().isEmpty() )
[ # # ][ # # ]
918 : : {
919 [ # # ]: 0 : aWorkStr += ::dbtools::quoteName(aQuote, pEntryField->GetFieldAlias());
920 : : }
921 [ # # ]: 0 : else if ( pEntryField->isNumericOrAggreateFunction() )
922 : : {
923 : : OSL_ENSURE(!pEntryField->GetFunction().isEmpty(),"Functionname darf hier nicht leer sein! ;-(");
924 : 0 : aWorkStr += pEntryField->GetFunction();
925 : 0 : aWorkStr += ::rtl::OUString('(');
926 [ # # ]: 0 : aWorkStr += quoteTableAlias(bMulti,pEntryField->GetAlias(),aQuote);
927 : : // only quote column name when we don't have a numeric
928 [ # # ]: 0 : if ( pEntryField->isNumeric() )
929 : 0 : aWorkStr += aColumnName;
930 : : else
931 [ # # ]: 0 : aWorkStr += ::dbtools::quoteName(aQuote, aColumnName);
932 : :
933 : 0 : aWorkStr += ::rtl::OUString(')');
934 : : }
935 [ # # ]: 0 : else if ( pEntryField->isOtherFunction() )
936 : : {
937 : 0 : aWorkStr += aColumnName;
938 : : }
939 : : else
940 : : {
941 [ # # ]: 0 : aWorkStr += quoteTableAlias(bMulti,pEntryField->GetAlias(),aQuote);
942 [ # # ]: 0 : aWorkStr += ::dbtools::quoteName(aQuote, aColumnName);
943 : : }
944 : 0 : aWorkStr += rtl::OUString(' ');
945 : 0 : aWorkStr += rtl::OUString( ";ASC;DESC" ).getToken( (sal_uInt16)eOrder, ';' );
946 : 0 : aWorkStr += rtl::OUString(',');
947 : : }
948 [ # # ][ # # ]: 0 : }
949 : :
950 : : {
951 [ # # ][ # # ]: 0 : String sTemp(comphelper::string::stripEnd(aWorkStr, ','));
952 [ # # ][ # # ]: 0 : aWorkStr = sTemp;
953 : : }
954 : :
955 [ # # ]: 0 : if ( !aWorkStr.isEmpty() )
956 : : {
957 [ # # ][ # # ]: 0 : const sal_Int32 nMaxOrder = xMetaData->getMaxColumnsInOrderBy();
958 [ # # ]: 0 : String sToken(aWorkStr);
959 [ # # ][ # # ]: 0 : if ( nMaxOrder && nMaxOrder < comphelper::string::getTokenCount(sToken, ',') )
[ # # ][ # # ]
[ # # ]
[ # # # # ]
960 : 0 : eErrorCode = eStatementTooLong;
961 : : else
962 : : {
963 [ # # ]: 0 : _rsRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ORDER BY "));
964 : 0 : _rsRet += aWorkStr;
965 [ # # ]: 0 : }
966 [ # # ]: 0 : }
967 : : }
968 [ # # ]: 0 : catch(SQLException&)
969 : : {
970 : : OSL_FAIL("Failure while building group by!");
971 : : }
972 : :
973 : 0 : return eErrorCode;
974 : : }
975 : :
976 : : //------------------------------------------------------------------------------
977 : 0 : void GenerateInnerJoinCriterias(const Reference< XConnection>& _xConnection,
978 : : ::rtl::OUString& _rJoinCrit,
979 : : const ::std::vector<OTableConnection*>* _pConnList)
980 : : {
981 : 0 : ::std::vector<OTableConnection*>::const_iterator aIter = _pConnList->begin();
982 : 0 : ::std::vector<OTableConnection*>::const_iterator aEnd = _pConnList->end();
983 [ # # ][ # # ]: 0 : for(;aIter != aEnd;++aIter)
984 : : {
985 : 0 : const OQueryTableConnection* pEntryConn = static_cast<const OQueryTableConnection*>(*aIter);
986 [ # # ][ # # ]: 0 : OQueryTableConnectionData* pEntryConnData = static_cast<OQueryTableConnectionData*>(pEntryConn->GetData().get());
987 [ # # ][ # # ]: 0 : if ( pEntryConnData->GetJoinType() == INNER_JOIN && !pEntryConnData->isNatural() )
[ # # ]
988 : : {
989 [ # # ]: 0 : if(!_rJoinCrit.isEmpty())
990 : 0 : _rJoinCrit += C_AND;
991 [ # # ]: 0 : _rJoinCrit += BuildJoinCriteria(_xConnection,pEntryConnData->GetConnLineDataList(),pEntryConnData);
992 : : }
993 : : }
994 : 0 : }
995 : : //------------------------------------------------------------------------------
996 : 0 : void searchAndAppendName(const Reference< XConnection>& _xConnection,
997 : : const OQueryTableWindow* _pTableWindow,
998 : : ::std::map< ::rtl::OUString,sal_Bool,::comphelper::UStringMixLess>& _rTableNames,
999 : : ::rtl::OUString& _rsTableListStr
1000 : : )
1001 : : {
1002 [ # # ]: 0 : ::rtl::OUString sTabName(BuildTable(_xConnection,_pTableWindow));
1003 : :
1004 [ # # ][ # # ]: 0 : if(_rTableNames.find(sTabName) == _rTableNames.end())
1005 : : {
1006 [ # # ]: 0 : _rTableNames[sTabName] = sal_True;
1007 : 0 : _rsTableListStr += sTabName;
1008 : 0 : _rsTableListStr += ::rtl::OUString(',');
1009 : 0 : }
1010 : 0 : }
1011 : : //------------------------------------------------------------------------------
1012 : 0 : ::rtl::OUString GenerateFromClause( const Reference< XConnection>& _xConnection,
1013 : : const OQueryTableView::OTableWindowMap* pTabList,
1014 : : const ::std::vector<OTableConnection*>* pConnList
1015 : : )
1016 : : {
1017 : :
1018 : 0 : ::rtl::OUString aTableListStr;
1019 : : // wird gebraucht um sicher zustelllen das eine Tabelle nicht doppelt vorkommt
1020 [ # # ]: 0 : ::std::map< ::rtl::OUString,sal_Bool,::comphelper::UStringMixLess> aTableNames;
1021 : :
1022 : : // generate outer join clause in from
1023 [ # # ]: 0 : if(!pConnList->empty())
1024 : : {
1025 : 0 : ::std::vector<OTableConnection*>::const_iterator aIter = pConnList->begin();
1026 : 0 : ::std::vector<OTableConnection*>::const_iterator aEnd = pConnList->end();
1027 [ # # ]: 0 : ::std::map<OTableWindow*,sal_Int32> aConnectionCount;
1028 [ # # ][ # # ]: 0 : for(;aIter != aEnd;++aIter)
1029 : : {
1030 : 0 : static_cast<OQueryTableConnection*>(*aIter)->SetVisited(sal_False);
1031 [ # # ][ # # ]: 0 : if ( aConnectionCount.find((*aIter)->GetSourceWin()) == aConnectionCount.end() )
[ # # ]
1032 [ # # ][ # # ]: 0 : aConnectionCount.insert(::std::map<OTableWindow*,sal_Int32>::value_type((*aIter)->GetSourceWin(),0));
1033 : : else
1034 [ # # ][ # # ]: 0 : aConnectionCount[(*aIter)->GetSourceWin()]++;
1035 [ # # ][ # # ]: 0 : if ( aConnectionCount.find((*aIter)->GetDestWin()) == aConnectionCount.end() )
[ # # ]
1036 [ # # ][ # # ]: 0 : aConnectionCount.insert(::std::map<OTableWindow*,sal_Int32>::value_type((*aIter)->GetDestWin(),0));
1037 : : else
1038 [ # # ][ # # ]: 0 : aConnectionCount[(*aIter)->GetDestWin()]++;
1039 : : }
1040 [ # # ]: 0 : ::std::multimap<sal_Int32 , OTableWindow*> aMulti;
1041 : 0 : ::std::map<OTableWindow*,sal_Int32>::iterator aCountIter = aConnectionCount.begin();
1042 : 0 : ::std::map<OTableWindow*,sal_Int32>::iterator aCountEnd = aConnectionCount.end();
1043 [ # # ]: 0 : for(;aCountIter != aCountEnd;++aCountIter)
1044 : : {
1045 [ # # ][ # # ]: 0 : aMulti.insert(::std::multimap<sal_Int32 , OTableWindow*>::value_type(aCountIter->second,aCountIter->first));
1046 : : }
1047 : :
1048 [ # # ]: 0 : const sal_Bool bUseEscape = ::dbtools::getBooleanDataSourceSetting( _xConnection, PROPERTY_OUTERJOINESCAPE.ascii );
1049 : 0 : ::std::multimap<sal_Int32 , OTableWindow*>::reverse_iterator aRIter = aMulti.rbegin();
1050 : 0 : ::std::multimap<sal_Int32 , OTableWindow*>::reverse_iterator aREnd = aMulti.rend();
1051 [ # # ][ # # ]: 0 : for(;aRIter != aREnd;++aRIter)
[ # # ]
1052 : : {
1053 [ # # ][ # # ]: 0 : ::std::vector<OTableConnection*>::const_iterator aConIter = aRIter->second->getTableView()->getTableConnections(aRIter->second);
[ # # ][ # # ]
1054 [ # # ][ # # ]: 0 : for(;aConIter != aEnd;++aConIter)
1055 : : {
1056 : 0 : OQueryTableConnection* pEntryConn = static_cast<OQueryTableConnection*>(*aConIter);
1057 [ # # ][ # # ]: 0 : if(!pEntryConn->IsVisited() && pEntryConn->GetSourceWin() == aRIter->second )
[ # # ][ # # ]
[ # # ]
1058 : : {
1059 : 0 : ::rtl::OUString aJoin;
1060 [ # # ][ # # ]: 0 : GetNextJoin(_xConnection,pEntryConn,static_cast<OQueryTableWindow*>(pEntryConn->GetDestWin()),aJoin);
1061 : :
1062 [ # # ]: 0 : if(!aJoin.isEmpty())
1063 : : {
1064 : : // insert tables into table list to avoid double entries
1065 [ # # ]: 0 : OQueryTableWindow* pEntryTabFrom = static_cast<OQueryTableWindow*>(pEntryConn->GetSourceWin());
1066 [ # # ]: 0 : OQueryTableWindow* pEntryTabTo = static_cast<OQueryTableWindow*>(pEntryConn->GetDestWin());
1067 : :
1068 [ # # ]: 0 : ::rtl::OUString sTabName(BuildTable(_xConnection,pEntryTabFrom));
1069 [ # # ][ # # ]: 0 : if(aTableNames.find(sTabName) == aTableNames.end())
1070 [ # # ]: 0 : aTableNames[sTabName] = sal_True;
1071 [ # # ]: 0 : sTabName = BuildTable(_xConnection,pEntryTabTo);
1072 [ # # ][ # # ]: 0 : if(aTableNames.find(sTabName) == aTableNames.end())
1073 [ # # ]: 0 : aTableNames[sTabName] = sal_True;
1074 : :
1075 : 0 : ::rtl::OUString aStr;
1076 [ # # ][ # # ]: 0 : switch(static_cast<OQueryTableConnectionData*>(pEntryConn->GetData().get())->GetJoinType())
[ # # ]
1077 : : {
1078 : : case LEFT_JOIN:
1079 : : case RIGHT_JOIN:
1080 : : case FULL_JOIN:
1081 : : {
1082 : : // create outer join
1083 [ # # ]: 0 : if ( bUseEscape )
1084 [ # # ]: 0 : aStr += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("{ OJ "));
1085 : 0 : aStr += aJoin;
1086 [ # # ]: 0 : if ( bUseEscape )
1087 [ # # ]: 0 : aStr += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" }"));
1088 : : }
1089 : 0 : break;
1090 : : default:
1091 : 0 : aStr += aJoin;
1092 : 0 : break;
1093 : : }
1094 [ # # ]: 0 : aStr += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(","));
1095 : 0 : aTableListStr += aStr;
1096 : 0 : }
1097 : : }
1098 : : }
1099 : : }
1100 : :
1101 : : // and now all inner joins
1102 : 0 : aIter = pConnList->begin();
1103 [ # # ][ # # ]: 0 : for(;aIter != aEnd;++aIter)
1104 : : {
1105 : 0 : OQueryTableConnection* pEntryConn = static_cast<OQueryTableConnection*>(*aIter);
1106 [ # # ]: 0 : if(!pEntryConn->IsVisited())
1107 : : {
1108 : : searchAndAppendName(_xConnection,
1109 [ # # ]: 0 : static_cast<OQueryTableWindow*>(pEntryConn->GetSourceWin()),
1110 : : aTableNames,
1111 [ # # ]: 0 : aTableListStr);
1112 : :
1113 : : searchAndAppendName(_xConnection,
1114 [ # # ]: 0 : static_cast<OQueryTableWindow*>(pEntryConn->GetDestWin()),
1115 : : aTableNames,
1116 [ # # ]: 0 : aTableListStr);
1117 : : }
1118 : 0 : }
1119 : : }
1120 : : // all tables that haven't a connection to anyone
1121 : 0 : OQueryTableView::OTableWindowMap::const_iterator aTabIter = pTabList->begin();
1122 : 0 : OQueryTableView::OTableWindowMap::const_iterator aTabEnd = pTabList->end();
1123 [ # # ]: 0 : for(;aTabIter != aTabEnd;++aTabIter)
1124 : : {
1125 : 0 : const OQueryTableWindow* pEntryTab = static_cast<const OQueryTableWindow*>(aTabIter->second);
1126 [ # # ][ # # ]: 0 : if(!pEntryTab->ExistsAConn())
1127 : : {
1128 [ # # ]: 0 : aTableListStr += BuildTable(_xConnection,pEntryTab);
1129 : 0 : aTableListStr += ::rtl::OUString(',');
1130 : : }
1131 : : }
1132 : :
1133 [ # # ]: 0 : if(!aTableListStr.isEmpty())
1134 : 0 : aTableListStr = aTableListStr.replaceAt(aTableListStr.getLength()-1,1, ::rtl::OUString() );
1135 : 0 : return aTableListStr;
1136 : : }
1137 : : //------------------------------------------------------------------------------
1138 : 0 : ::rtl::OUString GenerateGroupBy(const OQueryDesignView* _pView,OTableFields& _rFieldList, sal_Bool bMulti )
1139 : : {
1140 : 0 : OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
1141 [ # # ]: 0 : const Reference< XConnection> xConnection = rController.getConnection();
1142 [ # # ]: 0 : if(!xConnection.is())
1143 : 0 : return ::rtl::OUString();
1144 : :
1145 [ # # ]: 0 : ::std::map< rtl::OUString,bool> aGroupByNames;
1146 : :
1147 : 0 : ::rtl::OUString aGroupByStr;
1148 : : try
1149 : : {
1150 [ # # ][ # # ]: 0 : const Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
1151 [ # # ][ # # ]: 0 : const ::rtl::OUString aQuote = xMetaData->getIdentifierQuoteString();
1152 : :
1153 : 0 : OTableFields::iterator aIter = _rFieldList.begin();
1154 : 0 : OTableFields::iterator aEnd = _rFieldList.end();
1155 [ # # ][ # # ]: 0 : for(;aIter != aEnd;++aIter)
1156 : : {
1157 [ # # ]: 0 : OTableFieldDescRef pEntryField = *aIter;
1158 [ # # ]: 0 : if ( pEntryField->IsGroupBy() )
1159 : : {
1160 : : OSL_ENSURE(!pEntryField->GetField().isEmpty(),"Kein FieldName vorhanden!;-(");
1161 [ # # ]: 0 : ::rtl::OUString sGroupByPart = quoteTableAlias(bMulti,pEntryField->GetAlias(),aQuote);
1162 : :
1163 : : // only quote the field name when it isn't calculated
1164 [ # # ]: 0 : if ( pEntryField->isNoneFunction() )
1165 : : {
1166 [ # # ]: 0 : sGroupByPart += ::dbtools::quoteName(aQuote, pEntryField->GetField());
1167 : : }
1168 : : else
1169 : : {
1170 : 0 : ::rtl::OUString aTmp = pEntryField->GetField();
1171 : 0 : ::rtl::OUString aErrorMsg;
1172 : 0 : Reference<XPropertySet> xColumn;
1173 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
1174 [ # # ][ # # ]: 0 : ::std::auto_ptr< ::connectivity::OSQLParseNode> pParseNode(_pView->getPredicateTreeFromEntry(pEntryField,aTmp,aErrorMsg,xColumn));
[ # # ][ # # ]
[ # # ]
1175 : : SAL_WNODEPRECATED_DECLARATIONS_POP
1176 [ # # ]: 0 : if (pParseNode.get())
1177 : : {
1178 : 0 : ::rtl::OUString sGroupBy;
1179 : : pParseNode->getChild(0)->parseNodeToStr( sGroupBy,
1180 : : xConnection,
1181 : 0 : &rController.getParser().getContext(),
1182 : : sal_False,
1183 [ # # ][ # # ]: 0 : !pEntryField->isOtherFunction());
1184 : 0 : sGroupByPart += sGroupBy;
1185 : : }
1186 : : else
1187 [ # # ]: 0 : sGroupByPart += pEntryField->GetField();
1188 : : }
1189 [ # # ][ # # ]: 0 : if ( aGroupByNames.find(sGroupByPart) == aGroupByNames.end() )
1190 : : {
1191 [ # # ]: 0 : aGroupByNames.insert(::std::map< rtl::OUString,bool>::value_type(sGroupByPart,true));
1192 : 0 : aGroupByStr += sGroupByPart;
1193 : 0 : aGroupByStr += ::rtl::OUString(',');
1194 : 0 : }
1195 : : }
1196 [ # # ]: 0 : }
1197 [ # # ]: 0 : if ( !aGroupByStr.isEmpty() )
1198 : : {
1199 : 0 : aGroupByStr = aGroupByStr.replaceAt(aGroupByStr.getLength()-1,1, ::rtl::OUString(' ') );
1200 [ # # ]: 0 : ::rtl::OUString aGroupByStr2(RTL_CONSTASCII_USTRINGPARAM(" GROUP BY "));
1201 : 0 : aGroupByStr2 += aGroupByStr;
1202 : 0 : aGroupByStr = aGroupByStr2;
1203 [ # # ]: 0 : }
1204 : : }
1205 [ # # ]: 0 : catch(SQLException&)
1206 : : {
1207 : : OSL_FAIL("Failure while building group by!");
1208 : : }
1209 : 0 : return aGroupByStr;
1210 : : }
1211 : : // -----------------------------------------------------------------------------
1212 : : SqlParseError GetORCriteria(OQueryDesignView* _pView,
1213 : : OSelectionBrowseBox* _pSelectionBrw,
1214 : : const ::connectivity::OSQLParseNode * pCondition,
1215 : : sal_uInt16& nLevel ,
1216 : : sal_Bool bHaving = sal_False,
1217 : : bool bAddOrOnOneLine = false);
1218 : : // -----------------------------------------------------------------------------
1219 : 0 : SqlParseError GetSelectionCriteria( OQueryDesignView* _pView,
1220 : : OSelectionBrowseBox* _pSelectionBrw,
1221 : : const ::connectivity::OSQLParseNode* pNode,
1222 : : sal_uInt16& rLevel )
1223 : : {
1224 [ # # ][ # # ]: 0 : if (!SQL_ISRULE(pNode, select_statement))
[ # # ][ # # ]
1225 : 0 : return eNoSelectStatement;
1226 : :
1227 : : // nyi: mehr Pruefung auf korrekte Struktur!
1228 [ # # ][ # # ]: 0 : pNode = pNode ? pNode->getChild(3)->getChild(1) : NULL;
[ # # ]
1229 : : // no where clause found
1230 [ # # ][ # # ]: 0 : if (!pNode || pNode->isLeaf())
[ # # ]
1231 : 0 : return eOk;
1232 : :
1233 : : // Naechster freier Satz ...
1234 : 0 : SqlParseError eErrorCode = eOk;
1235 [ # # ]: 0 : ::connectivity::OSQLParseNode * pCondition = pNode->getChild(1);
1236 [ # # ]: 0 : if ( pCondition ) // no where clause
1237 : : {
1238 : : // now we have to chech the other conditions
1239 : : // first make the logical easier
1240 [ # # ]: 0 : ::connectivity::OSQLParseNode::negateSearchCondition(pCondition);
1241 [ # # ]: 0 : ::connectivity::OSQLParseNode *pNodeTmp = pNode->getChild(1);
1242 : :
1243 [ # # ]: 0 : ::connectivity::OSQLParseNode::disjunctiveNormalForm(pNodeTmp);
1244 [ # # ]: 0 : pNodeTmp = pNode->getChild(1);
1245 [ # # ]: 0 : ::connectivity::OSQLParseNode::absorptions(pNodeTmp);
1246 [ # # ]: 0 : pNodeTmp = pNode->getChild(1);
1247 : : // compress sort the criteria @see http://www.openoffice.org/issues/show_bug.cgi?id=24079
1248 [ # # ]: 0 : OSQLParseNode::compress(pNodeTmp);
1249 [ # # ]: 0 : pNodeTmp = pNode->getChild(1);
1250 : :
1251 : : // first extract the inner joins conditions
1252 [ # # ]: 0 : GetInnerJoinCriteria(_pView,pNodeTmp);
1253 : : // now simplify again, join are checked in ComparisonPredicate
1254 [ # # ]: 0 : ::connectivity::OSQLParseNode::absorptions(pNodeTmp);
1255 [ # # ]: 0 : pNodeTmp = pNode->getChild(1);
1256 : :
1257 : : // it could happen that pCondition is not more valid
1258 [ # # ]: 0 : eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pNodeTmp, rLevel);
1259 : : }
1260 : 0 : return eErrorCode;
1261 : : }
1262 : : //------------------------------------------------------------------------------
1263 : : SqlParseError GetANDCriteria( OQueryDesignView* _pView,
1264 : : OSelectionBrowseBox* _pSelectionBrw,
1265 : : const ::connectivity::OSQLParseNode * pCondition,
1266 : : sal_uInt16& nLevel,
1267 : : sal_Bool bHaving,
1268 : : bool bAddOrOnOneLine);
1269 : : //------------------------------------------------------------------------------
1270 : : SqlParseError ComparisonPredicate(OQueryDesignView* _pView,
1271 : : OSelectionBrowseBox* _pSelectionBrw,
1272 : : const ::connectivity::OSQLParseNode * pCondition,
1273 : : const sal_uInt16 nLevel,
1274 : : sal_Bool bHaving,
1275 : : bool bAddOrOnOneLine);
1276 : : //------------------------------------------------------------------------------
1277 : 0 : SqlParseError GetORCriteria(OQueryDesignView* _pView,
1278 : : OSelectionBrowseBox* _pSelectionBrw,
1279 : : const ::connectivity::OSQLParseNode * pCondition,
1280 : : sal_uInt16& nLevel ,
1281 : : sal_Bool bHaving,
1282 : : bool bAddOrOnOneLine)
1283 : : {
1284 : 0 : SqlParseError eErrorCode = eOk;
1285 : :
1286 : : // Runde Klammern um den Ausdruck
1287 [ # # # # : 0 : if (pCondition->count() == 3 &&
# # # # #
# ][ # # ]
1288 : 0 : SQL_ISPUNCTUATION(pCondition->getChild(0),"(") &&
1289 : 0 : SQL_ISPUNCTUATION(pCondition->getChild(2),")"))
1290 : : {
1291 : 0 : eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pCondition->getChild(1),nLevel,bHaving,bAddOrOnOneLine);
1292 : : }
1293 : : // oder Verknuepfung
1294 : : // a searchcondition can only look like this: search_condition SQL_TOKEN_OR boolean_term
1295 [ # # ][ # # ]: 0 : else if (SQL_ISRULE(pCondition,search_condition))
[ # # ]
1296 : : {
1297 [ # # ][ # # ]: 0 : for (int i = 0; i < 3 && eErrorCode == eOk ; i+=2)
[ # # ]
1298 : : {
1299 : 0 : const ::connectivity::OSQLParseNode* pChild = pCondition->getChild(i);
1300 [ # # ][ # # ]: 0 : if ( SQL_ISRULE(pChild,search_condition) )
[ # # ]
1301 : 0 : eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pChild,nLevel,bHaving,bAddOrOnOneLine);
1302 : : else
1303 : : {
1304 [ # # ]: 0 : eErrorCode = GetANDCriteria(_pView,_pSelectionBrw,pChild, nLevel,bHaving, i == 0 ? false : bAddOrOnOneLine);
1305 [ # # ]: 0 : if ( !bAddOrOnOneLine)
1306 : 0 : nLevel++;
1307 : : }
1308 : : }
1309 : : }
1310 : : else
1311 : 0 : eErrorCode = GetANDCriteria( _pView,_pSelectionBrw,pCondition, nLevel, bHaving,bAddOrOnOneLine );
1312 : :
1313 : 0 : return eErrorCode;
1314 : : }
1315 : : //--------------------------------------------------------------------------------------------------
1316 : 0 : bool CheckOrCriteria(const ::connectivity::OSQLParseNode* _pCondition,::connectivity::OSQLParseNode* _pFirstColumnRef)
1317 : : {
1318 : 0 : bool bRet = true;
1319 : 0 : ::connectivity::OSQLParseNode* pFirstColumnRef = _pFirstColumnRef;
1320 [ # # ][ # # ]: 0 : for (int i = 0; i < 3 && bRet; i+=2)
[ # # ]
1321 : : {
1322 : 0 : const ::connectivity::OSQLParseNode* pChild = _pCondition->getChild(i);
1323 [ # # ][ # # ]: 0 : if ( SQL_ISRULE(pChild,search_condition) )
[ # # ]
1324 : 0 : bRet = CheckOrCriteria(pChild,pFirstColumnRef);
1325 : : else
1326 : : {
1327 : : // this is a simple way to test columns are the same, may be we have to adjust this algo a little bit in future. :-)
1328 : 0 : ::connectivity::OSQLParseNode* pSecondColumnRef = pChild->getByRule(::connectivity::OSQLParseNode::column_ref);
1329 [ # # ][ # # ]: 0 : if ( pFirstColumnRef && pSecondColumnRef )
1330 : 0 : bRet = *pFirstColumnRef == *pSecondColumnRef;
1331 [ # # ]: 0 : else if ( !pFirstColumnRef )
1332 : 0 : pFirstColumnRef = pSecondColumnRef;
1333 : : }
1334 : : }
1335 : 0 : return bRet;
1336 : : }
1337 : : //--------------------------------------------------------------------------------------------------
1338 : 0 : SqlParseError GetANDCriteria( OQueryDesignView* _pView,
1339 : : OSelectionBrowseBox* _pSelectionBrw,
1340 : : const ::connectivity::OSQLParseNode * pCondition,
1341 : : sal_uInt16& nLevel,
1342 : : sal_Bool bHaving,
1343 : : bool bAddOrOnOneLine)
1344 : : {
1345 : 0 : const ::com::sun::star::lang::Locale aLocale = _pView->getLocale();
1346 : 0 : const ::rtl::OUString sDecimal = _pView->getDecimalSeparator();
1347 : :
1348 : : // ich werde ein paar Mal einen gecasteten Pointer auf meinen ::com::sun::star::sdbcx::Container brauchen
1349 : 0 : OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
1350 : 0 : SqlParseError eErrorCode = eOk;
1351 : :
1352 : : // Runde Klammern
1353 [ # # ][ # # ]: 0 : if (SQL_ISRULE(pCondition,boolean_primary))
[ # # ][ # # ]
1354 : : {
1355 : : // check if we have to put the or criteria on one line.
1356 [ # # ]: 0 : const ::connectivity::OSQLParseNode* pSearchCondition = pCondition->getChild(1);
1357 [ # # ]: 0 : bool bMustAddOrOnOneLine = CheckOrCriteria(pSearchCondition,NULL);
1358 [ # # ][ # # ]: 0 : if ( SQL_ISRULE( pSearchCondition, search_condition) ) // we have a or
[ # # ][ # # ]
1359 : : {
1360 [ # # ]: 0 : _pSelectionBrw->DuplicateConditionLevel( nLevel);
1361 [ # # ][ # # ]: 0 : eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pSearchCondition->getChild(0), nLevel,bHaving,bMustAddOrOnOneLine );
1362 : 0 : ++nLevel;
1363 [ # # ][ # # ]: 0 : eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pSearchCondition->getChild(2), nLevel,bHaving,bMustAddOrOnOneLine );
1364 : : }
1365 : : else
1366 [ # # ]: 0 : eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pSearchCondition, nLevel,bHaving,bMustAddOrOnOneLine );
1367 : : }
1368 : : // Das erste Element ist (wieder) eine AND-Verknuepfung
1369 [ # # ][ # # ]: 0 : else if ( SQL_ISRULE(pCondition,boolean_term) )
[ # # ][ # # ]
1370 : : {
1371 : : OSL_ENSURE(pCondition->count() == 3,"Illegal definifiton of boolean_term");
1372 [ # # ][ # # ]: 0 : eErrorCode = GetANDCriteria(_pView,_pSelectionBrw,pCondition->getChild(0), nLevel,bHaving,bAddOrOnOneLine );
1373 [ # # ]: 0 : if ( eErrorCode == eOk )
1374 [ # # ][ # # ]: 0 : eErrorCode = GetANDCriteria(_pView,_pSelectionBrw,pCondition->getChild(2), nLevel,bHaving,bAddOrOnOneLine );
1375 : : }
1376 [ # # ][ # # ]: 0 : else if (SQL_ISRULE( pCondition, comparison_predicate))
[ # # ][ # # ]
1377 : : {
1378 [ # # ]: 0 : eErrorCode = ComparisonPredicate(_pView,_pSelectionBrw,pCondition,nLevel,bHaving,bAddOrOnOneLine);
1379 : : }
1380 [ # # ][ # # ]: 0 : else if( SQL_ISRULE(pCondition,like_predicate) )
[ # # ][ # # ]
1381 : : {
1382 [ # # ]: 0 : const ::connectivity::OSQLParseNode* pValueExp = pCondition->getChild(0);
1383 [ # # ][ # # ]: 0 : if (SQL_ISRULE(pValueExp, column_ref ) )
[ # # ][ # # ]
1384 : : {
1385 : 0 : ::rtl::OUString aColumnName;
1386 : 0 : ::rtl::OUString aCondition;
1387 [ # # ]: 0 : Reference< XConnection> xConnection = rController.getConnection();
1388 [ # # ]: 0 : if ( xConnection.is() )
1389 : : {
1390 [ # # ][ # # ]: 0 : Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
1391 : : // the international doesn't matter I have a string
1392 : : pCondition->parseNodeToPredicateStr(aCondition,
1393 : : xConnection,
1394 : : rController.getNumberFormatter(),
1395 : : aLocale,
1396 : 0 : static_cast<sal_Char>(sDecimal.toChar()),
1397 [ # # ][ # # ]: 0 : &rController.getParser().getContext());
1398 : :
1399 : : pValueExp->parseNodeToPredicateStr( aColumnName,
1400 : : xConnection,
1401 : : rController.getNumberFormatter(),
1402 : : aLocale,
1403 : 0 : static_cast<sal_Char>(sDecimal.toChar()),
1404 [ # # ][ # # ]: 0 : &rController.getParser().getContext());
1405 : :
1406 : : // don't display the column name
1407 : 0 : aCondition = aCondition.copy(aColumnName.getLength());
1408 : 0 : aCondition = aCondition.trim();
1409 : : }
1410 : :
1411 [ # # ][ # # ]: 0 : OTableFieldDescRef aDragLeft = new OTableFieldDesc();
[ # # ]
1412 [ # # ][ # # ]: 0 : if ( eOk == ( eErrorCode = FillDragInfo(_pView,pValueExp,aDragLeft) ))
1413 : : {
1414 [ # # ]: 0 : if ( bHaving )
1415 : 0 : aDragLeft->SetGroupBy(sal_True);
1416 [ # # ][ # # ]: 0 : _pSelectionBrw->AddCondition(aDragLeft, aCondition, nLevel,bAddOrOnOneLine);
[ # # ]
1417 [ # # ]: 0 : }
1418 : : }
1419 [ # # ][ # # ]: 0 : else if(SQL_ISRULEOR3(pValueExp, general_set_fct, set_fct_spec, position_exp) ||
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
[ # # ][ # # ]
[ # # # # ]
[ # # ][ # # ]
[ # # ]
1420 [ # # ][ # # ]: 0 : SQL_ISRULEOR3(pValueExp, extract_exp, fold, char_substring_fct) ||
[ # # ]
1421 [ # # ][ # # ]: 0 : SQL_ISRULEOR2(pValueExp, length_exp, char_value_fct))
1422 : : {
1423 : : AddFunctionCondition( _pView,
1424 : : _pSelectionBrw,
1425 : : pCondition,
1426 : : nLevel,
1427 : : bHaving,
1428 [ # # ]: 0 : bAddOrOnOneLine);
1429 : : }
1430 : : else
1431 : : {
1432 : 0 : eErrorCode = eNoColumnInLike;
1433 [ # # ][ # # ]: 0 : String sError(ModuleRes(STR_QRY_LIKE_LEFT_NO_COLUMN));
1434 [ # # ][ # # ]: 0 : _pView->getController().appendError( sError );
[ # # ]
1435 : : }
1436 : : }
1437 [ # # ][ # # ]: 0 : else if( SQL_ISRULEOR2(pCondition,test_for_null,in_predicate)
[ # # ][ # # ]
[ # # # # ]
[ # # ][ # # ]
[ # # ]
1438 [ # # ][ # # ]: 0 : || SQL_ISRULEOR2(pCondition,all_or_any_predicate,between_predicate))
1439 : : {
1440 [ # # ][ # # ]: 0 : if ( SQL_ISRULEOR2(pCondition->getChild(0), set_fct_spec , general_set_fct ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1441 : : {
1442 : : AddFunctionCondition( _pView,
1443 : : _pSelectionBrw,
1444 : : pCondition,
1445 : : nLevel,
1446 : : bHaving,
1447 [ # # ]: 0 : bAddOrOnOneLine);
1448 : : }
1449 [ # # ][ # # ]: 0 : else if ( SQL_ISRULE(pCondition->getChild(0), column_ref ) )
[ # # ][ # # ]
[ # # ][ # # ]
1450 : : {
1451 : : // parse condition
1452 [ # # ]: 0 : ::rtl::OUString sCondition = ParseCondition(rController,pCondition,sDecimal,aLocale,1);
1453 [ # # ][ # # ]: 0 : OTableFieldDescRef aDragLeft = new OTableFieldDesc();
[ # # ]
1454 [ # # ][ # # ]: 0 : if ( eOk == ( eErrorCode = FillDragInfo(_pView,pCondition->getChild(0),aDragLeft)) )
[ # # ]
1455 : : {
1456 [ # # ]: 0 : if ( bHaving )
1457 : 0 : aDragLeft->SetGroupBy(sal_True);
1458 [ # # ][ # # ]: 0 : _pSelectionBrw->AddCondition(aDragLeft, sCondition, nLevel,bAddOrOnOneLine);
[ # # ]
1459 [ # # ]: 0 : }
1460 : : }
1461 : : else
1462 : : {
1463 : : // Funktions-Bedingung parsen
1464 [ # # ]: 0 : ::rtl::OUString sCondition = ParseCondition(rController,pCondition,sDecimal,aLocale,1);
1465 [ # # ]: 0 : Reference< XConnection> xConnection = rController.getConnection();
1466 [ # # ][ # # ]: 0 : Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
1467 : : // the international doesn't matter I have a string
1468 : 0 : ::rtl::OUString sName;
1469 : : pCondition->getChild(0)->parseNodeToPredicateStr(sName,
1470 : : xConnection,
1471 : : rController.getNumberFormatter(),
1472 : : aLocale,
1473 : 0 : static_cast<sal_Char>(sDecimal.toChar()),
1474 [ # # ][ # # ]: 0 : &rController.getParser().getContext());
[ # # ]
1475 : :
1476 [ # # ][ # # ]: 0 : OTableFieldDescRef aDragLeft = new OTableFieldDesc();
[ # # ]
1477 : 0 : aDragLeft->SetField(sName);
1478 : 0 : aDragLeft->SetFunctionType(FKT_OTHER);
1479 : :
1480 [ # # ]: 0 : if ( bHaving )
1481 : 0 : aDragLeft->SetGroupBy(sal_True);
1482 [ # # ][ # # ]: 0 : _pSelectionBrw->AddCondition(aDragLeft, sCondition, nLevel,bAddOrOnOneLine);
[ # # ][ # # ]
1483 : : }
1484 : : }
1485 [ # # ][ # # ]: 0 : else if( SQL_ISRULEOR2(pCondition,existence_test,unique_test) )
[ # # ][ # # ]
[ # # ][ # # ]
1486 : : {
1487 : : // Funktions-Bedingung parsen
1488 [ # # ]: 0 : ::rtl::OUString aCondition = ParseCondition(rController,pCondition,sDecimal,aLocale,0);
1489 : :
1490 [ # # ][ # # ]: 0 : OTableFieldDescRef aDragLeft = new OTableFieldDesc();
[ # # ]
1491 : 0 : aDragLeft->SetField(aCondition);
1492 : 0 : aDragLeft->SetFunctionType(FKT_CONDITION);
1493 : :
1494 [ # # ][ # # ]: 0 : eErrorCode = _pSelectionBrw->InsertField(aDragLeft,BROWSER_INVALIDID,sal_False,sal_True).is() ? eOk : eTooManyColumns;
[ # # ][ # # ]
1495 : : }
1496 : : else //! TODO not supported yet
1497 : 0 : eErrorCode = eStatementTooComplex;
1498 : : // Fehler einfach weiterreichen.
1499 : 0 : return eErrorCode;
1500 : : }
1501 : : //------------------------------------------------------------------------------
1502 : 0 : SqlParseError AddFunctionCondition(OQueryDesignView* _pView,
1503 : : OSelectionBrowseBox* _pSelectionBrw,
1504 : : const ::connectivity::OSQLParseNode * pCondition,
1505 : : const sal_uInt16 nLevel,
1506 : : sal_Bool bHaving,
1507 : : bool bAddOrOnOneLine)
1508 : : {
1509 : 0 : SqlParseError eErrorCode = eOk;
1510 : 0 : OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
1511 : :
1512 [ # # ]: 0 : OSQLParseNode* pFunction = pCondition->getChild(0);
1513 : :
1514 : : OSL_ENSURE(SQL_ISRULEOR3(pFunction, general_set_fct, set_fct_spec, position_exp) ||
1515 : : SQL_ISRULEOR3(pFunction, extract_exp, fold, char_substring_fct) ||
1516 : : SQL_ISRULEOR2(pFunction,length_exp,char_value_fct),
1517 : : "Illegal call!");
1518 : 0 : ::rtl::OUString aCondition;
1519 [ # # ][ # # ]: 0 : OTableFieldDescRef aDragLeft = new OTableFieldDesc();
[ # # ]
1520 : :
1521 : 0 : ::rtl::OUString aColumnName;
1522 [ # # ]: 0 : Reference< XConnection> xConnection = rController.getConnection();
1523 [ # # ]: 0 : if(xConnection.is())
1524 : : {
1525 [ # # ][ # # ]: 0 : Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
1526 : : pCondition->parseNodeToPredicateStr(aCondition,
1527 : : xConnection,
1528 : : rController.getNumberFormatter(),
1529 : : _pView->getLocale(),
1530 : 0 : static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
1531 [ # # ][ # # ]: 0 : &rController.getParser().getContext());
1532 : :
1533 : : pFunction->parseNodeToStr( aColumnName,
1534 : : xConnection,
1535 : 0 : &rController.getParser().getContext(),
1536 : : sal_True,
1537 [ # # ]: 0 : sal_True); // quote is to true because we need quoted elements inside the function
1538 : : // don't display the column name
1539 : 0 : aCondition = aCondition.copy(aColumnName.getLength());
1540 : 0 : aCondition = aCondition.trim();
1541 [ # # ]: 0 : if ( aCondition.indexOf('=',0) == 0 ) // ignore the equal sign
1542 : 0 : aCondition = aCondition.copy(1);
1543 : :
1544 : :
1545 [ # # ][ # # ]: 0 : if ( SQL_ISRULE(pFunction, general_set_fct ) )
[ # # ][ # # ]
1546 : : {
1547 : 0 : sal_Int32 nFunctionType = FKT_AGGREGATE;
1548 [ # # ]: 0 : OSQLParseNode* pParamNode = pFunction->getChild(pFunction->count()-2);
1549 [ # # ][ # # ]: 0 : if ( pParamNode && pParamNode->getTokenValue().toChar() == '*' )
[ # # ]
1550 : : {
1551 : 0 : OJoinTableView::OTableWindowMap* pTabList = _pView->getTableView()->GetTabWinMap();
1552 : 0 : OJoinTableView::OTableWindowMap::iterator aIter = pTabList->begin();
1553 : 0 : OJoinTableView::OTableWindowMap::iterator aTabEnd = pTabList->end();
1554 [ # # ]: 0 : for(;aIter != aTabEnd;++aIter)
1555 : : {
1556 : 0 : OQueryTableWindow* pTabWin = static_cast<OQueryTableWindow*>(aIter->second);
1557 [ # # ][ # # ]: 0 : if (pTabWin->ExistsField( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("*")), aDragLeft ))
[ # # ]
1558 : : {
1559 [ # # ][ # # ]: 0 : aDragLeft->SetAlias(String());
[ # # ]
1560 [ # # ][ # # ]: 0 : aDragLeft->SetTable(String());
[ # # ]
1561 : 0 : break;
1562 : : }
1563 : : }
1564 : : }
1565 [ # # ]: 0 : else if( eOk != ( eErrorCode = FillDragInfo(_pView,pParamNode,aDragLeft))
[ # # # # ]
[ # # ][ # # ]
1566 [ # # ]: 0 : && SQL_ISRULE(pParamNode,num_value_exp) )
1567 : : {
1568 : 0 : ::rtl::OUString sParameterValue;
1569 : : pParamNode->parseNodeToStr( sParameterValue,
1570 : : xConnection,
1571 [ # # ]: 0 : &rController.getParser().getContext());
1572 : 0 : nFunctionType |= FKT_NUMERIC;
1573 : 0 : aDragLeft->SetField(sParameterValue);
1574 : 0 : eErrorCode = eOk;
1575 : : }
1576 : 0 : aDragLeft->SetFunctionType(nFunctionType);
1577 [ # # ]: 0 : if ( bHaving )
1578 : 0 : aDragLeft->SetGroupBy(sal_True);
1579 : 0 : sal_Int32 nIndex = 0;
1580 : 0 : aDragLeft->SetFunction(aColumnName.getToken(0,'(',nIndex));
1581 : : }
1582 : : else
1583 : : {
1584 : : // bei unbekannten Funktionen wird der gesamte Text in das Field gechrieben
1585 : 0 : aDragLeft->SetField(aColumnName);
1586 [ # # ]: 0 : if(bHaving)
1587 : 0 : aDragLeft->SetGroupBy(sal_True);
1588 : 0 : aDragLeft->SetFunctionType(FKT_OTHER|FKT_NUMERIC);
1589 : : }
1590 [ # # ][ # # ]: 0 : _pSelectionBrw->AddCondition(aDragLeft, aCondition, nLevel,bAddOrOnOneLine);
[ # # ]
1591 : : }
1592 : :
1593 [ # # ]: 0 : return eErrorCode;
1594 : : }
1595 : : //------------------------------------------------------------------------------
1596 : 0 : SqlParseError ComparisonPredicate(OQueryDesignView* _pView,
1597 : : OSelectionBrowseBox* _pSelectionBrw,
1598 : : const ::connectivity::OSQLParseNode * pCondition,
1599 : : const sal_uInt16 nLevel,
1600 : : sal_Bool bHaving
1601 : : ,bool bAddOrOnOneLine)
1602 : : {
1603 : 0 : SqlParseError eErrorCode = eOk;
1604 : 0 : OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
1605 : :
1606 : : OSL_ENSURE(SQL_ISRULE( pCondition, comparison_predicate),"ComparisonPredicate: pCondition ist kein ComparisonPredicate");
1607 [ # # # # : 0 : if ( SQL_ISRULE(pCondition->getChild(0), column_ref )
# # ][ # # ]
[ # # ]
1608 : 0 : || SQL_ISRULE(pCondition->getChild(pCondition->count()-1), column_ref) )
1609 : : {
1610 : 0 : ::rtl::OUString aCondition;
1611 [ # # ][ # # ]: 0 : OTableFieldDescRef aDragLeft = new OTableFieldDesc();
[ # # ]
1612 : :
1613 [ # # ][ # # ]: 0 : if ( SQL_ISRULE(pCondition->getChild(0), column_ref ) && SQL_ISRULE(pCondition->getChild(pCondition->count()-1), column_ref ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1614 : : {
1615 [ # # ][ # # ]: 0 : OTableFieldDescRef aDragRight = new OTableFieldDesc();
[ # # ]
1616 [ # # ][ # # ]: 0 : if (eOk != ( eErrorCode = FillDragInfo(_pView,pCondition->getChild(0),aDragLeft)) ||
[ # # ][ # # ]
[ # # ][ # # ]
1617 [ # # ]: 0 : eOk != ( eErrorCode = FillDragInfo(_pView,pCondition->getChild(2),aDragRight)))
1618 : 0 : return eErrorCode;
1619 : :
1620 : : OQueryTableConnection* pConn = static_cast<OQueryTableConnection*>(
1621 : 0 : _pView->getTableView()->GetTabConn(static_cast<OQueryTableWindow*>(aDragLeft->GetTabWindow()),
1622 : 0 : static_cast<OQueryTableWindow*>(aDragRight->GetTabWindow()),
1623 [ # # ][ # # ]: 0 : true));
[ # # ]
1624 [ # # ]: 0 : if ( pConn )
1625 : : {
1626 [ # # ][ # # ]: 0 : OConnectionLineDataVec* pLineDataList = pConn->GetData()->GetConnLineDataList();
1627 : 0 : OConnectionLineDataVec::iterator aIter = pLineDataList->begin();
1628 : 0 : OConnectionLineDataVec::iterator aEnd = pLineDataList->end();
1629 [ # # ][ # # ]: 0 : for(;aIter != aEnd;++aIter)
1630 : : {
1631 [ # # # # ]: 0 : if((*aIter)->GetSourceFieldName() == aDragLeft->GetField() ||
[ # # ][ # # ]
[ # # ]
1632 [ # # ][ # # ]: 0 : (*aIter)->GetDestFieldName() == aDragLeft->GetField() )
1633 : 0 : break;
1634 : : }
1635 [ # # ][ # # ]: 0 : if(aIter != aEnd)
1636 : 0 : return eOk;
1637 [ # # ][ # # ]: 0 : }
1638 : : }
1639 : :
1640 : 0 : sal_uInt32 nPos = 0;
1641 [ # # ][ # # ]: 0 : if(SQL_ISRULE(pCondition->getChild(0), column_ref ))
[ # # ][ # # ]
[ # # ][ # # ]
1642 : : {
1643 : 0 : nPos = 0;
1644 : 0 : sal_uInt32 i=1;
1645 : :
1646 : : // don't display the equal
1647 [ # # ][ # # ]: 0 : if (pCondition->getChild(i)->getNodeType() == SQL_NODE_EQUAL)
1648 : 0 : i++;
1649 : :
1650 : : // Bedingung parsen
1651 : : aCondition = ParseCondition(rController
1652 : : ,pCondition
1653 : : ,_pView->getDecimalSeparator()
1654 : : ,_pView->getLocale()
1655 [ # # ]: 0 : ,i);
1656 : : }
1657 [ # # ][ # # ]: 0 : else if( SQL_ISRULE(pCondition->getChild(pCondition->count()-1), column_ref ) )
[ # # ][ # # ]
[ # # ][ # # ]
1658 : : {
1659 : 0 : nPos = pCondition->count()-1;
1660 : :
1661 : 0 : sal_Int32 i = static_cast<sal_Int32>(pCondition->count() - 2);
1662 [ # # # # : 0 : switch (pCondition->getChild(i)->getNodeType())
# # ][ # # ]
1663 : : {
1664 : : case SQL_NODE_EQUAL:
1665 : : // don't display the equal
1666 : 0 : i--;
1667 : 0 : break;
1668 : : case SQL_NODE_LESS:
1669 : : // take the opposite as we change the order
1670 : 0 : i--;
1671 [ # # ]: 0 : aCondition = aCondition + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(">"));
1672 : 0 : break;
1673 : : case SQL_NODE_LESSEQ:
1674 : : // take the opposite as we change the order
1675 : 0 : i--;
1676 [ # # ]: 0 : aCondition = aCondition + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(">="));
1677 : 0 : break;
1678 : : case SQL_NODE_GREAT:
1679 : : // take the opposite as we change the order
1680 : 0 : i--;
1681 [ # # ]: 0 : aCondition = aCondition + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("<"));
1682 : 0 : break;
1683 : : case SQL_NODE_GREATEQ:
1684 : : // take the opposite as we change the order
1685 : 0 : i--;
1686 [ # # ]: 0 : aCondition = aCondition + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("<="));
1687 : 0 : break;
1688 : : default:
1689 : 0 : break;
1690 : : }
1691 : :
1692 : : // go backward
1693 [ # # ]: 0 : Reference< XConnection> xConnection = rController.getConnection();
1694 [ # # ]: 0 : if(xConnection.is())
1695 : : {
1696 [ # # ][ # # ]: 0 : Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
1697 [ # # ]: 0 : for (; i >= 0; i--)
1698 : : pCondition->getChild(i)->parseNodeToPredicateStr(aCondition,
1699 : : xConnection,
1700 : : rController.getNumberFormatter(),
1701 : : _pView->getLocale(),
1702 : 0 : static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
1703 [ # # ][ # # ]: 0 : &rController.getParser().getContext());
[ # # ]
1704 : 0 : }
1705 : : }
1706 : : // else ???
1707 : :
1708 : :
1709 [ # # ][ # # ]: 0 : if( eOk == ( eErrorCode = FillDragInfo(_pView,pCondition->getChild(nPos),aDragLeft)))
[ # # ]
1710 : : {
1711 [ # # ]: 0 : if(bHaving)
1712 : 0 : aDragLeft->SetGroupBy(sal_True);
1713 [ # # ][ # # ]: 0 : _pSelectionBrw->AddCondition(aDragLeft, aCondition, nLevel,bAddOrOnOneLine);
[ # # ]
1714 [ # # ][ # # ]: 0 : }
[ # # ]
1715 : : }
1716 [ # # ][ # # ]: 0 : else if( SQL_ISRULEOR2(pCondition->getChild(0), set_fct_spec , general_set_fct ) )
[ # # ][ # # ]
1717 : : {
1718 : : AddFunctionCondition( _pView,
1719 : : _pSelectionBrw,
1720 : : pCondition,
1721 : : nLevel,
1722 : : bHaving,
1723 : 0 : bAddOrOnOneLine);
1724 : : }
1725 : : else // kann sich nur um einen Expr. Ausdruck handeln
1726 : : {
1727 : 0 : ::rtl::OUString aName,aCondition;
1728 : :
1729 [ # # ]: 0 : ::connectivity::OSQLParseNode *pLhs = pCondition->getChild(0);
1730 [ # # ]: 0 : ::connectivity::OSQLParseNode *pRhs = pCondition->getChild(2);
1731 : : // Feldnamen
1732 [ # # ]: 0 : Reference< XConnection> xConnection = rController.getConnection();
1733 [ # # ]: 0 : if(xConnection.is())
1734 : : {
1735 : : pLhs->parseNodeToStr(aName,
1736 : : xConnection,
1737 : 0 : &rController.getParser().getContext(),
1738 [ # # ]: 0 : sal_True);
1739 : : // Kriterium
1740 [ # # ]: 0 : aCondition = pCondition->getChild(1)->getTokenValue();
1741 : : pRhs->parseNodeToPredicateStr(aCondition,
1742 : : xConnection,
1743 : : rController.getNumberFormatter(),
1744 : : _pView->getLocale(),
1745 : 0 : static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
1746 [ # # ][ # # ]: 0 : &rController.getParser().getContext());
1747 : : }
1748 : :
1749 [ # # ][ # # ]: 0 : OTableFieldDescRef aDragLeft = new OTableFieldDesc();
[ # # ]
1750 : 0 : aDragLeft->SetField(aName);
1751 : 0 : aDragLeft->SetFunctionType(FKT_OTHER|FKT_NUMERIC);
1752 : : // und anh"angen
1753 [ # # ][ # # ]: 0 : _pSelectionBrw->AddCondition(aDragLeft, aCondition, nLevel,bAddOrOnOneLine);
[ # # ][ # # ]
1754 : : }
1755 : 0 : return eErrorCode;
1756 : : }
1757 : :
1758 : : //------------------------------------------------------------------------------
1759 : : namespace
1760 : : {
1761 : 0 : OQueryTableWindow* lcl_findColumnInTables( const ::rtl::OUString& _rColumName, const OJoinTableView::OTableWindowMap& _rTabList, OTableFieldDescRef& _rInfo )
1762 : : {
1763 : 0 : OJoinTableView::OTableWindowMap::const_iterator aIter = _rTabList.begin();
1764 : 0 : OJoinTableView::OTableWindowMap::const_iterator aEnd = _rTabList.end();
1765 [ # # ]: 0 : for ( ; aIter != aEnd; ++aIter )
1766 : : {
1767 : 0 : OQueryTableWindow* pTabWin = static_cast< OQueryTableWindow* >( aIter->second );
1768 [ # # ][ # # ]: 0 : if ( pTabWin && pTabWin->ExistsField( _rColumName, _rInfo ) )
[ # # ][ # # ]
1769 : 0 : return pTabWin;
1770 : : }
1771 : 0 : return NULL;
1772 : : }
1773 : : }
1774 : :
1775 : : //------------------------------------------------------------------------------
1776 : 0 : void InsertColumnRef(const OQueryDesignView* _pView,
1777 : : const ::connectivity::OSQLParseNode * pColumnRef,
1778 : : ::rtl::OUString& aColumnName,
1779 : : const ::rtl::OUString& aColumnAlias,
1780 : : ::rtl::OUString& aTableRange,
1781 : : OTableFieldDescRef& _raInfo,
1782 : : OJoinTableView::OTableWindowMap* pTabList)
1783 : : {
1784 : :
1785 : : // Tabellennamen zusammen setzen
1786 : 0 : ::connectivity::OSQLParseTreeIterator& rParseIter = static_cast<OQueryController&>(_pView->getController()).getParseIterator();
1787 : 0 : rParseIter.getColumnRange( pColumnRef, aColumnName, aTableRange );
1788 : :
1789 : 0 : sal_Bool bFound(sal_False);
1790 : : OSL_ENSURE(!aColumnName.isEmpty(),"Columnname darf nicht leer sein");
1791 [ # # ]: 0 : if (aTableRange.isEmpty())
1792 : : {
1793 : : // SELECT column, ...
1794 : 0 : bFound = NULL != lcl_findColumnInTables( aColumnName, *pTabList, _raInfo );
1795 [ # # ][ # # ]: 0 : if ( bFound && ( aColumnName.toChar() != '*' ) )
[ # # ]
1796 : 0 : _raInfo->SetFieldAlias(aColumnAlias);
1797 : : }
1798 : : else
1799 : : {
1800 : : // SELECT range.column, ...
1801 [ # # ]: 0 : OQueryTableWindow* pTabWin = static_cast<OQueryTableView*>(_pView->getTableView())->FindTable(aTableRange);
1802 : :
1803 [ # # ][ # # ]: 0 : if (pTabWin && pTabWin->ExistsField(aColumnName, _raInfo))
[ # # ]
1804 : : {
1805 [ # # ]: 0 : if(aColumnName.toChar() != '*')
1806 : 0 : _raInfo->SetFieldAlias(aColumnAlias);
1807 : 0 : bFound = sal_True;
1808 : : }
1809 : : }
1810 [ # # ]: 0 : if (!bFound)
1811 : : {
1812 : 0 : _raInfo->SetTable(::rtl::OUString());
1813 : 0 : _raInfo->SetAlias(::rtl::OUString());
1814 : 0 : _raInfo->SetField(aColumnName);
1815 : 0 : _raInfo->SetFieldAlias(aColumnAlias); // nyi : hier ein fortlaufendes Expr_1, Expr_2 ...
1816 : 0 : _raInfo->SetFunctionType(FKT_OTHER);
1817 : : }
1818 : 0 : }
1819 : : //-----------------------------------------------------------------------------
1820 : 0 : sal_Bool checkJoinConditions( const OQueryDesignView* _pView,
1821 : : const ::connectivity::OSQLParseNode* _pNode )
1822 : : {
1823 : 0 : const ::connectivity::OSQLParseNode* pJoinNode = NULL;
1824 : 0 : sal_Bool bRet = sal_True;
1825 [ # # ][ # # ]: 0 : if (SQL_ISRULE(_pNode,qualified_join))
[ # # ]
1826 : 0 : pJoinNode = _pNode;
1827 [ # # ][ # # : 0 : else if (SQL_ISRULE(_pNode,table_ref)
# # # # #
# # # #
# ][ # # ]
1828 : 0 : && _pNode->count() == 3
1829 : 0 : && SQL_ISPUNCTUATION(_pNode->getChild(0),"(")
1830 : 0 : && SQL_ISPUNCTUATION(_pNode->getChild(2),")") ) // '(' joined_table ')'
1831 : 0 : pJoinNode = _pNode->getChild(1);
1832 [ # # ][ # # ]: 0 : else if (! ( SQL_ISRULE(_pNode, table_ref) && _pNode->count() == 2) ) // table_node table_primary_as_range_column
[ # # ][ # # ]
1833 : 0 : bRet = sal_False;
1834 : :
1835 [ # # ][ # # ]: 0 : if (pJoinNode && !InsertJoin(_pView,pJoinNode))
[ # # ]
1836 : 0 : bRet = sal_False;
1837 : 0 : return bRet;
1838 : : }
1839 : : //-----------------------------------------------------------------------------
1840 : 0 : sal_Bool InsertJoin(const OQueryDesignView* _pView,
1841 : : const ::connectivity::OSQLParseNode *pNode)
1842 : : {
1843 : : OSL_ENSURE( SQL_ISRULE( pNode, qualified_join ) || SQL_ISRULE( pNode, joined_table ) || SQL_ISRULE( pNode, cross_union ),
1844 : : "OQueryDesignView::InsertJoin: Fehler im Parse Tree");
1845 : :
1846 [ # # ][ # # ]: 0 : if (SQL_ISRULE(pNode,joined_table))
[ # # ][ # # ]
1847 [ # # ][ # # ]: 0 : return InsertJoin(_pView,pNode->getChild(1));
1848 : :
1849 : : // first check the left and right side
1850 [ # # ]: 0 : const ::connectivity::OSQLParseNode* pRightTableRef = pNode->getChild(3); // table_ref
1851 [ # # ][ # # ]: 0 : if ( SQL_ISRULE(pNode, qualified_join) && SQL_ISTOKEN(pNode->getChild(1),NATURAL) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
1852 [ # # ]: 0 : pRightTableRef = pNode->getChild(4); // table_ref
1853 : :
1854 [ # # ][ # # ]: 0 : if ( !checkJoinConditions(_pView,pNode->getChild(0)) || !checkJoinConditions(_pView,pRightTableRef))
[ # # ][ # # ]
[ # # ][ # # ]
1855 : 0 : return sal_False;
1856 : :
1857 : : // named column join wird sp�ter vieleicht noch implementiert
1858 : : // SQL_ISRULE(pNode->getChild(4),named_columns_join)
1859 : 0 : EJoinType eJoinType = INNER_JOIN;
1860 : 0 : bool bNatural = false;
1861 [ # # ][ # # ]: 0 : if ( SQL_ISRULE(pNode, qualified_join) )
[ # # ][ # # ]
1862 : : {
1863 [ # # ]: 0 : ::connectivity::OSQLParseNode* pJoinType = pNode->getChild(1); // join_type
1864 [ # # ][ # # ]: 0 : if ( SQL_ISTOKEN(pJoinType,NATURAL) )
[ # # ]
1865 : : {
1866 : 0 : bNatural = true;
1867 [ # # ]: 0 : pJoinType = pNode->getChild(2);
1868 : : }
1869 : :
1870 [ # # ][ # # ]: 0 : if (SQL_ISRULE(pJoinType,join_type) && (!pJoinType->count() || SQL_ISTOKEN(pJoinType->getChild(0),INNER)))
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1871 : : {
1872 : 0 : eJoinType = INNER_JOIN;
1873 : : }
1874 : : else
1875 : : {
1876 [ # # ][ # # ]: 0 : if (SQL_ISRULE(pJoinType,join_type)) // eine Ebene tiefer
[ # # ][ # # ]
1877 [ # # ]: 0 : pJoinType = pJoinType->getChild(0);
1878 : :
1879 [ # # ][ # # ]: 0 : if (SQL_ISTOKEN(pJoinType->getChild(0),LEFT))
[ # # ][ # # ]
[ # # ]
1880 : 0 : eJoinType = LEFT_JOIN;
1881 [ # # ][ # # ]: 0 : else if(SQL_ISTOKEN(pJoinType->getChild(0),RIGHT))
[ # # ][ # # ]
[ # # ]
1882 : 0 : eJoinType = RIGHT_JOIN;
1883 : : else
1884 : 0 : eJoinType = FULL_JOIN;
1885 : : }
1886 [ # # ][ # # ]: 0 : if ( SQL_ISRULE(pNode->getChild(4),join_condition) )
[ # # ][ # # ]
[ # # ][ # # ]
1887 : : {
1888 [ # # ][ # # ]: 0 : if ( InsertJoinConnection(_pView,pNode->getChild(4)->getChild(1), eJoinType,pNode->getChild(0),pRightTableRef) != eOk )
[ # # ][ # # ]
[ # # ]
1889 : 0 : return sal_False;
1890 : : }
1891 : : }
1892 [ # # ][ # # ]: 0 : else if ( SQL_ISRULE(pNode, cross_union) )
[ # # ][ # # ]
1893 : : {
1894 : 0 : eJoinType = CROSS_JOIN;
1895 [ # # ]: 0 : pRightTableRef = pNode->getChild(pNode->count() - 1);
1896 : : }
1897 : : else
1898 : 0 : return sal_False;
1899 : :
1900 [ # # ][ # # ]: 0 : if ( eJoinType == CROSS_JOIN || bNatural )
1901 : : {
1902 : :
1903 [ # # ][ # # ]: 0 : OQueryTableWindow* pLeftWindow = static_cast<OQueryTableView*>(_pView->getTableView())->FindTable( getTableRange(_pView,pNode->getChild(0)) );
[ # # ][ # # ]
[ # # ]
1904 [ # # ][ # # ]: 0 : OQueryTableWindow* pRightWindow = static_cast<OQueryTableView*>(_pView->getTableView())->FindTable( getTableRange(_pView,pRightTableRef) );
[ # # ][ # # ]
1905 : : OSL_ENSURE(pLeftWindow && pRightWindow,"Table Windows could not be found!");
1906 [ # # ][ # # ]: 0 : if ( !pLeftWindow || !pRightWindow )
1907 : 0 : return sal_False;
1908 : :
1909 [ # # ][ # # ]: 0 : OTableFieldDescRef aDragLeft = new OTableFieldDesc();
[ # # ]
1910 [ # # ]: 0 : aDragLeft->SetTabWindow(pLeftWindow);
1911 [ # # ]: 0 : aDragLeft->SetTable(pLeftWindow->GetTableName());
1912 [ # # ]: 0 : aDragLeft->SetAlias(pLeftWindow->GetAliasName());
1913 : :
1914 [ # # ][ # # ]: 0 : OTableFieldDescRef aDragRight = new OTableFieldDesc();
[ # # ]
1915 [ # # ]: 0 : aDragRight->SetTabWindow(pRightWindow);
1916 [ # # ]: 0 : aDragRight->SetTable(pRightWindow->GetTableName());
1917 [ # # ]: 0 : aDragRight->SetAlias(pRightWindow->GetAliasName());
1918 : :
1919 [ # # ][ # # ]: 0 : insertConnection(_pView,eJoinType,aDragLeft,aDragRight,bNatural);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1920 : : }
1921 : :
1922 : :
1923 : 0 : return sal_True;
1924 : : }
1925 : : //------------------------------------------------------------------------------
1926 : 0 : void insertUnUsedFields(OQueryDesignView* _pView,OSelectionBrowseBox* _pSelectionBrw)
1927 : : {
1928 : : // now we have to insert the fields which aren't in the statement
1929 : 0 : OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
1930 : 0 : OTableFields& rUnUsedFields = rController.getUnUsedFields();
1931 : 0 : OTableFields::iterator aEnd = rUnUsedFields.end();
1932 [ # # ][ # # ]: 0 : for(OTableFields::iterator aIter = rUnUsedFields.begin();aIter != aEnd;++aIter)
1933 [ # # ][ # # ]: 0 : if(_pSelectionBrw->InsertField(*aIter,BROWSER_INVALIDID,sal_False,sal_False).is())
[ # # ]
1934 [ # # ]: 0 : (*aIter) = NULL;
1935 [ # # ]: 0 : OTableFields().swap( rUnUsedFields );
1936 : 0 : }
1937 : :
1938 : : //------------------------------------------------------------------------------
1939 : 0 : SqlParseError InitFromParseNodeImpl(OQueryDesignView* _pView,OSelectionBrowseBox* _pSelectionBrw)
1940 : : {
1941 : 0 : SqlParseError eErrorCode = eOk;
1942 : :
1943 : 0 : OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
1944 : :
1945 : 0 : _pSelectionBrw->PreFill();
1946 : 0 : _pSelectionBrw->SetReadOnly(rController.isReadOnly());
1947 : 0 : _pSelectionBrw->Fill();
1948 : :
1949 : :
1950 : 0 : ::connectivity::OSQLParseTreeIterator& aIterator = rController.getParseIterator();
1951 : 0 : const ::connectivity::OSQLParseNode* pParseTree = aIterator.getParseTree();
1952 : :
1953 : : do
1954 : : {
1955 [ # # ]: 0 : if ( !pParseTree )
1956 : : {
1957 : : // now we have to insert the fields which aren't in the statement
1958 [ # # ]: 0 : insertUnUsedFields(_pView,_pSelectionBrw);
1959 : : break;
1960 : : }
1961 : :
1962 [ # # ]: 0 : if ( !rController.isEsacpeProcessing() ) // not allowed in this mode
1963 : : {
1964 : 0 : eErrorCode = eNativeMode;
1965 : : break;
1966 : : }
1967 : :
1968 [ # # ][ # # ]: 0 : if ( !( SQL_ISRULE( pParseTree, select_statement ) ) )
[ # # ][ # # ]
1969 : : {
1970 : 0 : eErrorCode = eNoSelectStatement;
1971 : : break;
1972 : : }
1973 : :
1974 [ # # ]: 0 : const OSQLParseNode* pTableExp = pParseTree->getChild(3);
1975 [ # # ][ # # ]: 0 : if ( pTableExp->getChild(6)->count() > 0 || pTableExp->getChild(7)->count() > 0 || pTableExp->getChild(8)->count() > 0)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1976 : : {
1977 : 0 : eErrorCode = eStatementTooComplex;
1978 : : break;
1979 : : }
1980 : :
1981 [ # # ]: 0 : Reference< XConnection> xConnection = rController.getConnection();
1982 [ # # ]: 0 : if ( !xConnection.is() )
1983 : : {
1984 : : OSL_FAIL( "InitFromParseNodeImpl: no connection? no connection!" );
1985 : : break;
1986 : : }
1987 : :
1988 [ # # ]: 0 : const OSQLTables& aMap = aIterator.getTables();
1989 [ # # ]: 0 : ::comphelper::UStringMixLess aTmp(aMap.key_comp());
1990 : 0 : ::comphelper::UStringMixEqual aKeyComp( aTmp.isCaseSensitive() );
1991 : :
1992 [ # # ][ # # ]: 0 : Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
1993 : : try
1994 : : {
1995 [ # # ][ # # ]: 0 : sal_Int32 nMax = xMetaData->getMaxTablesInSelect();
1996 [ # # ][ # # ]: 0 : if ( nMax && nMax < (sal_Int32)aMap.size() )
[ # # ]
1997 : : {
1998 : 0 : eErrorCode = eTooManyTables;
1999 : : break;
2000 : : }
2001 : :
2002 : 0 : ::rtl::OUString sComposedName;
2003 : 0 : ::rtl::OUString sAlias;
2004 : :
2005 : 0 : OQueryTableView* pTableView = static_cast<OQueryTableView*>(_pView->getTableView());
2006 [ # # ]: 0 : pTableView->clearLayoutInformation();
2007 : 0 : OSQLTables::const_iterator aIter = aMap.begin();
2008 : 0 : OSQLTables::const_iterator aEnd = aMap.end();
2009 [ # # ]: 0 : for(;aIter != aEnd;++aIter)
2010 : : {
2011 : 0 : OSQLTable xTable = aIter->second;
2012 [ # # ]: 0 : Reference< XPropertySet > xTableProps( xTable, UNO_QUERY_THROW );
2013 : :
2014 : 0 : sAlias = aIter->first;
2015 : :
2016 : : // check whether this is a query
2017 [ # # ][ # # ]: 0 : Reference< XPropertySetInfo > xPSI = xTableProps->getPropertySetInfo();
2018 [ # # ][ # # ]: 0 : bool bIsQuery = xPSI.is() && xPSI->hasPropertyByName( PROPERTY_COMMAND );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
2019 : :
2020 [ # # ]: 0 : if ( bIsQuery )
2021 [ # # ][ # # ]: 0 : OSL_VERIFY( xTableProps->getPropertyValue( PROPERTY_NAME ) >>= sComposedName );
[ # # ]
2022 : : else
2023 : : {
2024 [ # # ]: 0 : sComposedName = ::dbtools::composeTableName( xMetaData, xTableProps, ::dbtools::eInDataManipulation, false, false, false );
2025 : :
2026 : : // if the alias is the complete (composed) table, then shorten it
2027 [ # # ]: 0 : if ( aKeyComp( sComposedName, aIter->first ) )
2028 : : {
2029 : 0 : ::rtl::OUString sCatalog, sSchema, sTable;
2030 [ # # ]: 0 : ::dbtools::qualifiedNameComponents( xMetaData, sComposedName, sCatalog, sSchema, sTable, ::dbtools::eInDataManipulation );
2031 : 0 : sAlias = sTable;
2032 : : }
2033 : : }
2034 : :
2035 : : // find the existent window for this alias
2036 [ # # ][ # # ]: 0 : OQueryTableWindow* pExistentWin = pTableView->FindTable( sAlias );
[ # # ]
2037 [ # # ]: 0 : if ( !pExistentWin )
2038 : : {
2039 [ # # ]: 0 : pTableView->AddTabWin( sComposedName, sAlias, sal_False ); // don't create data here
2040 : : }
2041 : : else
2042 : : {
2043 : : // there already exists a window for this alias ....
2044 [ # # ][ # # ]: 0 : if ( !aKeyComp( pExistentWin->GetData()->GetComposedName(), sComposedName ) )
[ # # ]
2045 : : // ... but for another complete table name -> new window
2046 [ # # ]: 0 : pTableView->AddTabWin(sComposedName, sAlias);
2047 : : }
2048 : 0 : }
2049 : :
2050 : : // now delete the data for which we haven't any tablewindow
2051 [ # # ]: 0 : OJoinTableView::OTableWindowMap aTableMap(*pTableView->GetTabWinMap());
2052 : 0 : OJoinTableView::OTableWindowMap::iterator aIterTableMap = aTableMap.begin();
2053 : 0 : OJoinTableView::OTableWindowMap::iterator aIterTableEnd = aTableMap.end();
2054 [ # # ]: 0 : for(;aIterTableMap != aIterTableEnd;++aIterTableMap)
2055 : : {
2056 [ # # ][ # # ]: 0 : if(aMap.find(aIterTableMap->second->GetComposedName()) == aMap.end() &&
[ # # # # ]
[ # # ][ # # ]
[ # # ][ # #
# # # # #
# ]
2057 [ # # ][ # # ]: 0 : aMap.find(aIterTableMap->first) == aMap.end())
[ # # ]
[ # # # # ]
2058 [ # # ]: 0 : pTableView->RemoveTabWin(aIterTableMap->second);
2059 : : }
2060 : :
2061 [ # # ][ # # ]: 0 : if ( eOk == (eErrorCode = FillOuterJoins(_pView,pTableExp->getChild(0)->getChild(1))) )
[ # # ][ # # ]
2062 : : {
2063 : : // check if we have a distinct statement
2064 [ # # ][ # # ]: 0 : if(SQL_ISTOKEN(pParseTree->getChild(1),DISTINCT))
[ # # ][ # # ]
[ # # ]
2065 : : {
2066 : 0 : rController.setDistinct(sal_True);
2067 [ # # ][ # # ]: 0 : rController.InvalidateFeature(SID_QUERY_DISTINCT_VALUES);
2068 : : }
2069 [ # # ][ # # ]: 0 : if ( (eErrorCode = InstallFields(_pView,pParseTree, pTableView->GetTabWinMap())) == eOk )
2070 : : {
2071 : : // GetSelectionCriteria must be called before GetHavingCriteria
2072 : 0 : sal_uInt16 nLevel=0;
2073 : :
2074 [ # # ][ # # ]: 0 : if ( eOk == (eErrorCode = GetSelectionCriteria(_pView,_pSelectionBrw,pParseTree,nLevel)) )
2075 : : {
2076 [ # # ][ # # ]: 0 : if ( eOk == (eErrorCode = GetGroupCriteria(_pView,_pSelectionBrw,pParseTree)) )
2077 : : {
2078 [ # # ][ # # ]: 0 : if ( eOk == (eErrorCode = GetHavingCriteria(_pView,_pSelectionBrw,pParseTree,nLevel)) )
2079 : : {
2080 [ # # ][ # # ]: 0 : if ( eOk == (eErrorCode = GetOrderCriteria(_pView,_pSelectionBrw,pParseTree)) )
2081 [ # # ]: 0 : insertUnUsedFields(_pView,_pSelectionBrw);
2082 : : }
2083 : : }
2084 : : }
2085 : : }
2086 [ # # ]: 0 : }
2087 : : }
2088 [ # # ]: 0 : catch(SQLException&)
2089 : : {
2090 : : OSL_FAIL("getMaxTablesInSelect!");
2091 [ # # ][ # # ]: 0 : }
2092 : : }
2093 : : while ( false );
2094 : :
2095 : : // Durch das Neuerzeugen wurden wieder Undo-Actions in den Manager gestellt
2096 : 0 : rController.ClearUndoManager();
2097 : 0 : _pSelectionBrw->Invalidate();
2098 : 0 : return eErrorCode;
2099 : : }
2100 : : //------------------------------------------------------------------------------
2101 : : /** fillSelectSubList
2102 : : @return
2103 : : <TRUE/> when columns could be inserted otherwise <FALSE/>
2104 : : */
2105 : : //------------------------------------------------------------------------------
2106 : 0 : SqlParseError fillSelectSubList( OQueryDesignView* _pView,
2107 : : OJoinTableView::OTableWindowMap* _pTabList)
2108 : : {
2109 : 0 : SqlParseError eErrorCode = eOk;
2110 : 0 : sal_Bool bFirstField = sal_True;
2111 [ # # ]: 0 : ::rtl::OUString sAsterix(RTL_CONSTASCII_USTRINGPARAM("*"));
2112 : 0 : OJoinTableView::OTableWindowMap::iterator aIter = _pTabList->begin();
2113 : 0 : OJoinTableView::OTableWindowMap::iterator aEnd = _pTabList->end();
2114 [ # # ][ # # ]: 0 : for(;aIter != aEnd && eOk == eErrorCode ;++aIter)
[ # # ]
2115 : : {
2116 : 0 : OQueryTableWindow* pTabWin = static_cast<OQueryTableWindow*>(aIter->second);
2117 [ # # ][ # # ]: 0 : OTableFieldDescRef aInfo = new OTableFieldDesc();
[ # # ]
2118 [ # # ][ # # ]: 0 : if (pTabWin->ExistsField( sAsterix, aInfo ))
2119 : : {
2120 [ # # ]: 0 : eErrorCode = _pView->InsertField(aInfo, sal_True, bFirstField);
2121 : 0 : bFirstField = sal_False;
2122 : : }
2123 [ # # ]: 0 : }
2124 : 0 : return eErrorCode;
2125 : : }
2126 : : //------------------------------------------------------------------------------
2127 : 0 : SqlParseError InstallFields(OQueryDesignView* _pView,
2128 : : const ::connectivity::OSQLParseNode* pNode,
2129 : : OJoinTableView::OTableWindowMap* pTabList )
2130 : : {
2131 [ # # ][ # # ]: 0 : if( pNode==0 || !SQL_ISRULE(pNode,select_statement))
[ # # ][ # # ]
2132 : 0 : return eNoSelectStatement;
2133 : :
2134 : 0 : ::connectivity::OSQLParseNode* pParseTree = pNode->getChild(2); // selection
2135 : 0 : sal_Bool bFirstField = sal_True; // bei der Initialisierung mu� auf alle Faelle das erste Feld neu aktiviert werden
2136 : :
2137 : 0 : SqlParseError eErrorCode = eOk;
2138 : :
2139 [ # # ][ # # ]: 0 : if ( pParseTree->isRule() && SQL_ISPUNCTUATION(pParseTree->getChild(0),"*") )
[ # # ][ # # ]
2140 : : {
2141 : : // SELECT * ...
2142 : 0 : eErrorCode = fillSelectSubList(_pView,pTabList);
2143 : : }
2144 [ # # ][ # # ]: 0 : else if (SQL_ISRULE(pParseTree,scalar_exp_commalist) )
[ # # ]
2145 : : {
2146 : : // SELECT column, ...
2147 : 0 : OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
2148 [ # # ]: 0 : Reference< XConnection> xConnection = rController.getConnection();
2149 : :
2150 : 0 : ::rtl::OUString aColumnName,aTableRange;
2151 [ # # ][ # # ]: 0 : for (sal_uInt32 i = 0; i < pParseTree->count() && eOk == eErrorCode ; ++i)
[ # # ]
2152 : : {
2153 [ # # ]: 0 : ::connectivity::OSQLParseNode * pColumnRef = pParseTree->getChild(i);
2154 : :
2155 : : do {
2156 : :
2157 [ # # ][ # # ]: 0 : if ( SQL_ISRULE(pColumnRef,select_sublist) )
[ # # ][ # # ]
2158 : : {
2159 [ # # ]: 0 : eErrorCode = fillSelectSubList(_pView,pTabList);
2160 : 0 : break;
2161 : : }
2162 : :
2163 [ # # ][ # # ]: 0 : if ( SQL_ISRULE(pColumnRef,derived_column) )
[ # # ][ # # ]
2164 : : {
2165 [ # # ]: 0 : ::rtl::OUString aColumnAlias(rController.getParseIterator().getColumnAlias(pColumnRef)); // kann leer sein
2166 [ # # ]: 0 : pColumnRef = pColumnRef->getChild(0);
2167 [ # # ][ # # ]: 0 : OTableFieldDescRef aInfo = new OTableFieldDesc();
[ # # ]
2168 : :
2169 [ # # # # : 0 : if ( pColumnRef->count() == 3 &&
# # # # #
# ][ # # ]
2170 [ # # ][ # # ]: 0 : SQL_ISPUNCTUATION(pColumnRef->getChild(0),"(") &&
2171 [ # # ][ # # ]: 0 : SQL_ISPUNCTUATION(pColumnRef->getChild(2),")")
2172 : : )
2173 [ # # ]: 0 : pColumnRef = pColumnRef->getChild(1);
2174 : :
2175 [ # # ][ # # ]: 0 : if (SQL_ISRULE(pColumnRef,column_ref))
[ # # ][ # # ]
2176 : : {
2177 [ # # ]: 0 : InsertColumnRef(_pView,pColumnRef,aColumnName,aColumnAlias,aTableRange,aInfo,pTabList);
2178 [ # # ]: 0 : eErrorCode = _pView->InsertField(aInfo, sal_True, bFirstField);
2179 : 0 : bFirstField = sal_False;
2180 : : }
2181 [ # # ][ # # ]: 0 : else if(SQL_ISRULEOR3(pColumnRef, general_set_fct, set_fct_spec, position_exp) ||
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
[ # # ][ # # ]
[ # # # # ]
[ # # ][ # # ]
[ # # ]
2182 [ # # ][ # # ]: 0 : SQL_ISRULEOR3(pColumnRef, extract_exp, fold, char_substring_fct) ||
[ # # ]
2183 [ # # ][ # # ]: 0 : SQL_ISRULEOR2(pColumnRef,length_exp,char_value_fct))
2184 : : {
2185 : 0 : ::rtl::OUString aColumns;
2186 : : pColumnRef->parseNodeToPredicateStr(aColumns,
2187 : : xConnection,
2188 : : rController.getNumberFormatter(),
2189 : : _pView->getLocale(),
2190 : 0 : static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
2191 [ # # ][ # # ]: 0 : &rController.getParser().getContext());
2192 : :
2193 : 0 : sal_Int32 nFunctionType = FKT_NONE;
2194 : 0 : ::connectivity::OSQLParseNode* pParamRef = NULL;
2195 : 0 : sal_Int32 nColumnRefPos = pColumnRef->count() - 2;
2196 [ # # ][ # # ]: 0 : if ( nColumnRefPos >= 0 && static_cast<sal_uInt32>(nColumnRefPos) < pColumnRef->count() )
[ # # ]
2197 [ # # ]: 0 : pParamRef = pColumnRef->getChild(nColumnRefPos);
2198 : :
2199 [ # # ][ # # ]: 0 : if ( SQL_ISRULE(pColumnRef,general_set_fct)
[ # # # # ]
[ # # ][ # # ]
2200 [ # # ]: 0 : && SQL_ISRULE(pParamRef,column_ref) )
2201 : : {
2202 : : // Parameter auf Columnref pr"ufen
2203 [ # # ]: 0 : InsertColumnRef(_pView,pParamRef,aColumnName,aColumnAlias,aTableRange,aInfo,pTabList);
2204 : : }
2205 [ # # ][ # # ]: 0 : else if ( SQL_ISRULE(pColumnRef,general_set_fct) )
[ # # ][ # # ]
2206 : : {
2207 [ # # ][ # # ]: 0 : if ( pParamRef && pParamRef->getTokenValue().toChar() == '*' )
[ # # ]
2208 : : {
2209 : 0 : OJoinTableView::OTableWindowMap::iterator aIter = pTabList->begin();
2210 : 0 : const OJoinTableView::OTableWindowMap::const_iterator aEnd = pTabList->end();
2211 [ # # ]: 0 : for(;aIter != aEnd;++aIter)
2212 : : {
2213 : 0 : OQueryTableWindow* pTabWin = static_cast<OQueryTableWindow*>(aIter->second);
2214 [ # # ][ # # ]: 0 : if (pTabWin->ExistsField( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("*")), aInfo ))
[ # # ]
2215 : : {
2216 [ # # ][ # # ]: 0 : aInfo->SetAlias(String());
[ # # ]
2217 [ # # ][ # # ]: 0 : aInfo->SetTable(String());
[ # # ]
2218 : 0 : break;
2219 : : }
2220 : : }
2221 : : }
2222 : : else
2223 : : {
2224 : 0 : ::rtl::OUString sFieldName = aColumns;
2225 [ # # ]: 0 : if ( pParamRef )
2226 : : { // we got an aggregate function but without column name inside
2227 : : // so we set the whole argument of the function as field name
2228 : 0 : nFunctionType |= FKT_NUMERIC;
2229 : 0 : sFieldName = ::rtl::OUString();
2230 : : pParamRef->parseNodeToStr( sFieldName,
2231 : : xConnection,
2232 : 0 : &rController.getParser().getContext(),
2233 : : sal_True,
2234 [ # # ]: 0 : sal_True); // quote is to true because we need quoted elements inside the function
2235 : : }
2236 : 0 : aInfo->SetDataType(DataType::DOUBLE);
2237 : 0 : aInfo->SetFieldType(TAB_NORMAL_FIELD);
2238 : 0 : aInfo->SetField(sFieldName);
2239 : : }
2240 : 0 : aInfo->SetTabWindow(NULL);
2241 : 0 : aInfo->SetFieldAlias(aColumnAlias);
2242 : : }
2243 : : else
2244 : : {
2245 [ # # ]: 0 : _pView->fillFunctionInfo(pColumnRef,aColumns,aInfo);
2246 : 0 : aInfo->SetFieldAlias(aColumnAlias);
2247 : : }
2248 : :
2249 [ # # ][ # # ]: 0 : if ( SQL_ISRULE(pColumnRef,general_set_fct) )
[ # # ][ # # ]
2250 : : {
2251 : 0 : aInfo->SetFunctionType(nFunctionType|FKT_AGGREGATE);
2252 [ # # ]: 0 : String aCol(aColumns);
2253 [ # # ][ # # ]: 0 : aInfo->SetFunction(comphelper::string::stripEnd(aCol.GetToken(0,'('), ' '));
[ # # ][ # # ]
[ # # ]
2254 : : }
2255 : : else
2256 : 0 : aInfo->SetFunctionType(nFunctionType|FKT_OTHER);
2257 : :
2258 [ # # ]: 0 : eErrorCode = _pView->InsertField(aInfo, sal_True, bFirstField);
2259 : 0 : bFirstField = sal_False;
2260 : : }
2261 : : else
2262 : : {
2263 : 0 : ::rtl::OUString aColumns;
2264 : : pColumnRef->parseNodeToStr( aColumns,
2265 : : xConnection,
2266 : 0 : &rController.getParser().getContext(),
2267 : : sal_True,
2268 [ # # ]: 0 : sal_True); // quote is to true because we need quoted elements inside the function
2269 : :
2270 : 0 : aInfo->SetTabWindow( NULL );
2271 : :
2272 : : // since we support queries in queries, the thingie might belong to an existing "table"
2273 [ # # ]: 0 : OQueryTableWindow* pExistingTable = lcl_findColumnInTables( aColumns, *pTabList, aInfo );
2274 [ # # ]: 0 : if ( pExistingTable )
2275 : : {
2276 [ # # ]: 0 : aInfo->SetTabWindow( pExistingTable );
2277 [ # # ]: 0 : aInfo->SetTable( pExistingTable->GetTableName() );
2278 [ # # ]: 0 : aInfo->SetAlias( pExistingTable->GetAliasName() );
2279 : : }
2280 : :
2281 : 0 : aInfo->SetDataType(DataType::DOUBLE);
2282 : 0 : aInfo->SetFieldType(TAB_NORMAL_FIELD);
2283 : 0 : aInfo->SetField(aColumns);
2284 : 0 : aInfo->SetFieldAlias(aColumnAlias);
2285 : 0 : aInfo->SetFunctionType(FKT_NUMERIC | FKT_OTHER);
2286 : :
2287 [ # # ]: 0 : eErrorCode = _pView->InsertField(aInfo, sal_True, bFirstField);
2288 : 0 : bFirstField = sal_False;
2289 : : }
2290 : :
2291 [ # # ]: 0 : break;
2292 : : }
2293 : :
2294 : : OSL_FAIL( "InstallFields: don't know how to interpret this parse node!" );
2295 : :
2296 : : } while ( false );
2297 : 0 : }
2298 : : }
2299 : : else
2300 : 0 : eErrorCode = eStatementTooComplex;
2301 : :
2302 : 0 : return eErrorCode;
2303 : : }
2304 : : //------------------------------------------------------------------------------
2305 : 0 : SqlParseError GetOrderCriteria( OQueryDesignView* _pView,
2306 : : OSelectionBrowseBox* _pSelectionBrw,
2307 : : const ::connectivity::OSQLParseNode* pParseRoot )
2308 : : {
2309 : 0 : SqlParseError eErrorCode = eOk;
2310 [ # # ]: 0 : if (!pParseRoot->getChild(3)->getChild(ORDER_BY_CHILD_POS)->isLeaf())
2311 : : {
2312 : 0 : ::connectivity::OSQLParseNode* pNode = pParseRoot->getChild(3)->getChild(ORDER_BY_CHILD_POS)->getChild(2);
2313 : 0 : ::connectivity::OSQLParseNode* pParamRef = NULL;
2314 : :
2315 : 0 : OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
2316 : : EOrderDir eOrderDir;
2317 [ # # ]: 0 : for( sal_uInt32 i=0 ; i<pNode->count() ; i++ )
2318 : : {
2319 [ # # ][ # # ]: 0 : OTableFieldDescRef aDragLeft = new OTableFieldDesc();
[ # # ]
2320 : 0 : eOrderDir = ORDER_ASC;
2321 [ # # ]: 0 : ::connectivity::OSQLParseNode* pChild = pNode->getChild( i );
2322 : :
2323 [ # # ][ # # ]: 0 : if (SQL_ISTOKEN( pChild->getChild(1), DESC ) )
[ # # ][ # # ]
[ # # ]
2324 : 0 : eOrderDir = ORDER_DESC;
2325 : :
2326 [ # # ]: 0 : ::connectivity::OSQLParseNode* pArgument = pChild->getChild(0);
2327 : :
2328 [ # # ][ # # ]: 0 : if(SQL_ISRULE(pArgument,column_ref))
[ # # ][ # # ]
2329 : : {
2330 [ # # ][ # # ]: 0 : if( eOk == FillDragInfo(_pView,pArgument,aDragLeft))
2331 [ # # ]: 0 : _pSelectionBrw->AddOrder( aDragLeft, eOrderDir, i);
2332 : : else // it could be a alias name for a field
2333 : : {
2334 : 0 : ::rtl::OUString aTableRange,aColumnName;
2335 : 0 : ::connectivity::OSQLParseTreeIterator& rParseIter = rController.getParseIterator();
2336 [ # # ]: 0 : rParseIter.getColumnRange( pArgument, aColumnName, aTableRange );
2337 : :
2338 : 0 : OTableFields& aList = rController.getTableFieldDesc();
2339 : 0 : OTableFields::iterator aIter = aList.begin();
2340 : 0 : OTableFields::iterator aEnd = aList.end();
2341 [ # # ][ # # ]: 0 : for(;aIter != aEnd;++aIter)
2342 : : {
2343 [ # # ]: 0 : OTableFieldDescRef pEntry = *aIter;
2344 [ # # ][ # # ]: 0 : if(pEntry.is() && pEntry->GetFieldAlias() == aColumnName)
[ # # ][ # # ]
2345 : 0 : pEntry->SetOrderDir( eOrderDir );
2346 [ # # ]: 0 : }
2347 : : }
2348 : : }
2349 [ # # ][ # # ]: 0 : else if(SQL_ISRULE(pArgument, general_set_fct ) &&
[ # # # #
# # # # ]
[ # # ][ # # ]
[ # # ]
2350 [ # # ]: 0 : SQL_ISRULE(pParamRef = pArgument->getChild(pArgument->count()-2),column_ref) &&
2351 [ # # ]: 0 : eOk == FillDragInfo(_pView,pParamRef,aDragLeft))
2352 [ # # ]: 0 : _pSelectionBrw->AddOrder( aDragLeft, eOrderDir, i );
2353 [ # # ][ # # ]: 0 : else if( SQL_ISRULE(pArgument, set_fct_spec ) )
[ # # ][ # # ]
2354 : : {
2355 : :
2356 [ # # ]: 0 : Reference< XConnection> xConnection = rController.getConnection();
2357 [ # # ]: 0 : if(xConnection.is())
2358 : : {
2359 : 0 : ::rtl::OUString sCondition;
2360 : : pArgument->parseNodeToPredicateStr(sCondition,
2361 : : xConnection,
2362 : : rController.getNumberFormatter(),
2363 : : _pView->getLocale(),
2364 : 0 : static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
2365 [ # # ][ # # ]: 0 : &rController.getParser().getContext());
2366 [ # # ]: 0 : _pView->fillFunctionInfo(pArgument,sCondition,aDragLeft);
2367 : 0 : aDragLeft->SetFunctionType(FKT_OTHER);
2368 : 0 : aDragLeft->SetOrderDir(eOrderDir);
2369 : 0 : aDragLeft->SetVisible(sal_False);
2370 [ # # ]: 0 : _pSelectionBrw->AddOrder( aDragLeft, eOrderDir, i );
2371 : : }
2372 : : else
2373 : 0 : eErrorCode = eColumnNotFound;
2374 : : }
2375 : : else
2376 : 0 : eErrorCode = eColumnNotFound;
2377 [ # # ]: 0 : }
2378 : : }
2379 : 0 : return eErrorCode;
2380 : : }
2381 : : //------------------------------------------------------------------------------
2382 : 0 : SqlParseError GetHavingCriteria( OQueryDesignView* _pView,
2383 : : OSelectionBrowseBox* _pSelectionBrw,
2384 : : const ::connectivity::OSQLParseNode* pSelectRoot,
2385 : : sal_uInt16& rLevel )
2386 : : {
2387 : 0 : SqlParseError eErrorCode = eOk;
2388 [ # # ]: 0 : if (!pSelectRoot->getChild(3)->getChild(3)->isLeaf())
2389 : 0 : eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pSelectRoot->getChild(3)->getChild(3)->getChild(1),rLevel, sal_True);
2390 : 0 : return eErrorCode;
2391 : : }
2392 : : //------------------------------------------------------------------------------
2393 : 0 : SqlParseError GetGroupCriteria( OQueryDesignView* _pView,
2394 : : OSelectionBrowseBox* _pSelectionBrw,
2395 : : const ::connectivity::OSQLParseNode* pSelectRoot )
2396 : : {
2397 : 0 : SqlParseError eErrorCode = eOk;
2398 [ # # ]: 0 : if (!pSelectRoot->getChild(3)->getChild(2)->isLeaf()) // opt_group_by_clause
2399 : : {
2400 : 0 : OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
2401 : 0 : ::connectivity::OSQLParseNode* pGroupBy = pSelectRoot->getChild(3)->getChild(2)->getChild(2);
2402 : :
2403 [ # # ][ # # ]: 0 : for( sal_uInt32 i=0 ; i < pGroupBy->count() && eOk == eErrorCode; ++i )
[ # # ]
2404 : : {
2405 [ # # ][ # # ]: 0 : OTableFieldDescRef aDragInfo = new OTableFieldDesc();
[ # # ]
2406 : 0 : ::connectivity::OSQLParseNode* pParamRef = NULL;
2407 [ # # ]: 0 : ::connectivity::OSQLParseNode* pArgument = pGroupBy->getChild( i );
2408 [ # # ][ # # ]: 0 : if(SQL_ISRULE(pArgument,column_ref))
[ # # ][ # # ]
2409 : : {
2410 [ # # ][ # # ]: 0 : if ( eOk == (eErrorCode = FillDragInfo(_pView,pArgument,aDragInfo)) )
2411 : : {
2412 : 0 : aDragInfo->SetGroupBy(sal_True);
2413 [ # # ]: 0 : _pSelectionBrw->AddGroupBy(aDragInfo,i);
2414 : : }
2415 : : }
2416 [ # # ][ # # ]: 0 : else if(SQL_ISRULE(pArgument, general_set_fct ) &&
[ # # # #
# # # # ]
[ # # ][ # # ]
[ # # ]
2417 [ # # ]: 0 : SQL_ISRULE(pParamRef = pArgument->getChild(pArgument->count()-2),column_ref) &&
2418 [ # # ]: 0 : eOk == FillDragInfo(_pView,pParamRef,aDragInfo))
2419 : : {
2420 : 0 : aDragInfo->SetGroupBy(sal_True);
2421 [ # # ]: 0 : _pSelectionBrw->AddGroupBy( aDragInfo, i );
2422 : : }
2423 [ # # ][ # # ]: 0 : else if( SQL_ISRULE(pArgument, set_fct_spec ) )
[ # # ][ # # ]
2424 : : {
2425 [ # # ]: 0 : Reference< XConnection> xConnection = rController.getConnection();
2426 [ # # ]: 0 : if(xConnection.is())
2427 : : {
2428 : 0 : ::rtl::OUString sGroupByExpression;
2429 : : pArgument->parseNodeToStr( sGroupByExpression,
2430 : : xConnection,
2431 : 0 : &rController.getParser().getContext(),
2432 : : sal_True,
2433 [ # # ]: 0 : sal_True); // quote is to true because we need quoted elements inside the function
2434 [ # # ]: 0 : _pView->fillFunctionInfo(pArgument,sGroupByExpression,aDragInfo);
2435 : 0 : aDragInfo->SetFunctionType(FKT_OTHER);
2436 : 0 : aDragInfo->SetGroupBy(sal_True);
2437 : 0 : aDragInfo->SetVisible(sal_False);
2438 [ # # ]: 0 : _pSelectionBrw->AddGroupBy( aDragInfo, i );
2439 : : }
2440 : : else
2441 : 0 : eErrorCode = eColumnNotFound;
2442 : : }
2443 [ # # ]: 0 : }
2444 : : }
2445 : 0 : return eErrorCode;
2446 : : }
2447 : :
2448 : : //------------------------------------------------------------------------------
2449 : 0 : String getParseErrorMessage( SqlParseError _eErrorCode )
2450 : : {
2451 : : sal_uInt16 nResId;
2452 [ # # # # : 0 : switch(_eErrorCode)
# # # # #
# # # # ]
2453 : : {
2454 : : case eIllegalJoin:
2455 : 0 : nResId = STR_QRY_ILLEGAL_JOIN;
2456 : 0 : break;
2457 : : case eStatementTooLong:
2458 : 0 : nResId = STR_QRY_TOO_LONG_STATEMENT;
2459 : 0 : break;
2460 : : case eNoConnection:
2461 : 0 : nResId = STR_QRY_SYNTAX;
2462 : 0 : break;
2463 : : case eNoSelectStatement:
2464 : 0 : nResId = STR_QRY_NOSELECT;
2465 : 0 : break;
2466 : : case eColumnInLikeNotFound:
2467 : 0 : nResId = STR_QRY_SYNTAX;
2468 : 0 : break;
2469 : : case eNoColumnInLike:
2470 : 0 : nResId = STR_QRY_SYNTAX;
2471 : 0 : break;
2472 : : case eColumnNotFound:
2473 : 0 : nResId = STR_QRY_SYNTAX;
2474 : 0 : break;
2475 : : case eNativeMode:
2476 : 0 : nResId = STR_QRY_NATIVE;
2477 : 0 : break;
2478 : : case eTooManyTables:
2479 : 0 : nResId = STR_QRY_TOO_MANY_TABLES;
2480 : 0 : break;
2481 : : case eTooManyConditions:
2482 : 0 : nResId = STR_QRY_TOOMANYCOND;
2483 : 0 : break;
2484 : : case eTooManyColumns:
2485 : 0 : nResId = STR_QRY_TOO_MANY_COLUMNS;
2486 : 0 : break;
2487 : : case eStatementTooComplex:
2488 : 0 : nResId = STR_QRY_TOOCOMPLEX;
2489 : 0 : break;
2490 : : default:
2491 : 0 : nResId = STR_QRY_SYNTAX;
2492 : 0 : break;
2493 : : }
2494 : : ;
2495 [ # # ]: 0 : return String( ModuleRes( nResId ) );
2496 : : }
2497 : :
2498 : : //------------------------------------------------------------------------------
2499 : : //------------------------------------------------------------------------------
2500 : : }
2501 : : // end of anonymouse namespace
2502 : : DBG_NAME(OQueryDesignView)
2503 : :
2504 : 0 : OQueryDesignView::OQueryDesignView( OQueryContainerWindow* _pParent,
2505 : : OQueryController& _rController,
2506 : : const Reference< XMultiServiceFactory >& _rFactory)
2507 : : :OQueryView( _pParent, _rController, _rFactory )
2508 : : ,m_aSplitter( this )
2509 : : ,m_eChildFocus(NONE)
2510 : : ,m_bInKeyEvent(sal_False)
2511 [ # # ]: 0 : ,m_bInSplitHandler( sal_False )
2512 : : {
2513 : : DBG_CTOR(OQueryDesignView,NULL);
2514 : :
2515 : : try
2516 : : {
2517 [ # # ]: 0 : SvtSysLocale aSysLocale;
2518 [ # # ][ # # ]: 0 : m_aLocale = aSysLocale.GetLocaleData().getLocale();
2519 [ # # ][ # # ]: 0 : m_sDecimalSep = aSysLocale.GetLocaleData().getNumDecimalSep();
[ # # ][ # # ]
2520 : : }
2521 [ # # ]: 0 : catch(Exception&)
2522 : : {
2523 : : }
2524 : :
2525 [ # # ][ # # ]: 0 : m_pSelectionBox = new OSelectionBrowseBox(this);
2526 : :
2527 [ # # ]: 0 : setNoneVisbleRow(static_cast<OQueryController&>(getController()).getVisibleRows());
2528 [ # # ]: 0 : m_pSelectionBox->Show();
2529 : : // Splitter einrichten
2530 [ # # ]: 0 : m_aSplitter.SetSplitHdl(LINK(this, OQueryDesignView,SplitHdl));
2531 [ # # ]: 0 : m_aSplitter.Show();
2532 : :
2533 : 0 : }
2534 : : // -----------------------------------------------------------------------------
2535 [ # # ]: 0 : OQueryDesignView::~OQueryDesignView()
2536 : : {
2537 [ # # ]: 0 : if ( m_pTableView )
2538 [ # # ][ # # ]: 0 : ::dbaui::notifySystemWindow(this,m_pTableView,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
2539 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
2540 : 0 : ::std::auto_ptr<Window> aTemp(m_pSelectionBox);
2541 : : SAL_WNODEPRECATED_DECLARATIONS_POP
2542 : 0 : m_pSelectionBox = NULL;
2543 : :
2544 [ # # ]: 0 : DBG_DTOR(OQueryDesignView,NULL);
2545 [ # # ]: 0 : }
2546 : : //------------------------------------------------------------------------------
2547 : 0 : IMPL_LINK( OQueryDesignView, SplitHdl, void*, /*p*/ )
2548 : : {
2549 [ # # ]: 0 : if (!getController().isReadOnly())
2550 : : {
2551 : 0 : m_bInSplitHandler = sal_True;
2552 [ # # ]: 0 : m_aSplitter.SetPosPixel( Point( m_aSplitter.GetPosPixel().X(),m_aSplitter.GetSplitPosPixel() ) );
2553 : 0 : static_cast<OQueryController&>(getController()).setSplitPos(m_aSplitter.GetSplitPosPixel());
2554 : 0 : static_cast<OQueryController&>(getController()).setModified( sal_True );
2555 : 0 : Resize();
2556 : 0 : m_bInSplitHandler = sal_True;
2557 : : }
2558 : 0 : return 0L;
2559 : : }
2560 : : // -------------------------------------------------------------------------
2561 : 0 : void OQueryDesignView::Construct()
2562 : : {
2563 [ # # ]: 0 : m_pTableView = new OQueryTableView(m_pScrollWindow,this);
2564 : 0 : ::dbaui::notifySystemWindow(this,m_pTableView,::comphelper::mem_fun(&TaskPaneList::AddWindow));
2565 : 0 : OQueryView::Construct();
2566 : 0 : }
2567 : : // -----------------------------------------------------------------------------
2568 : 0 : void OQueryDesignView::initialize()
2569 : : {
2570 [ # # ]: 0 : if(static_cast<OQueryController&>(getController()).getSplitPos() != -1)
2571 : : {
2572 [ # # ]: 0 : m_aSplitter.SetPosPixel( Point( m_aSplitter.GetPosPixel().X(),static_cast<OQueryController&>(getController()).getSplitPos() ) );
2573 : 0 : m_aSplitter.SetSplitPosPixel(static_cast<OQueryController&>(getController()).getSplitPos());
2574 : : }
2575 : 0 : m_pSelectionBox->initialize();
2576 : 0 : reset();
2577 : 0 : }
2578 : : // -------------------------------------------------------------------------
2579 : 0 : void OQueryDesignView::resizeDocumentView(Rectangle& _rPlayground)
2580 : : {
2581 : 0 : Point aPlaygroundPos( _rPlayground.TopLeft() );
2582 [ # # ]: 0 : Size aPlaygroundSize( _rPlayground.GetSize() );
2583 : :
2584 : : // calc the split pos, and forward it to the controller
2585 : 0 : sal_Int32 nSplitPos = static_cast<OQueryController&>(getController()).getSplitPos();
2586 [ # # ]: 0 : if ( 0 != aPlaygroundSize.Height() )
2587 : : {
2588 [ # # # # ]: 0 : if ( ( -1 == nSplitPos )
[ # # ]
2589 : 0 : || ( nSplitPos >= aPlaygroundSize.Height() )
2590 : : )
2591 : : {
2592 : : // let the selection browse box determine an optimal size
2593 [ # # ]: 0 : Size aSelectionBoxSize = m_pSelectionBox->CalcOptimalSize( aPlaygroundSize );
2594 [ # # ]: 0 : nSplitPos = aPlaygroundSize.Height() - aSelectionBoxSize.Height() - m_aSplitter.GetSizePixel().Height();
2595 : : // still an invalid size?
2596 [ # # ][ # # ]: 0 : if ( nSplitPos == -1 || nSplitPos >= aPlaygroundSize.Height() )
[ # # ]
2597 : 0 : nSplitPos = sal_Int32(aPlaygroundSize.Height()*0.6);
2598 : :
2599 : 0 : static_cast<OQueryController&>(getController()).setSplitPos(nSplitPos);
2600 : : }
2601 : :
2602 [ # # ]: 0 : if ( !m_bInSplitHandler )
2603 : : { // the resize is triggered by something else than the split handler
2604 : : // our main focus is to try to preserve the size of the selectionbrowse box
2605 [ # # ]: 0 : Size aSelBoxSize = m_pSelectionBox->GetSizePixel();
2606 [ # # ]: 0 : if ( aSelBoxSize.Height() )
2607 : : {
2608 : : // keep the size of the sel box constant
2609 [ # # ]: 0 : nSplitPos = aPlaygroundSize.Height() - m_aSplitter.GetSizePixel().Height() - aSelBoxSize.Height();
2610 : :
2611 : : // and if the box is smaller than the optimal size, try to do something about it
2612 [ # # ]: 0 : Size aSelBoxOptSize = m_pSelectionBox->CalcOptimalSize( aPlaygroundSize );
2613 [ # # ]: 0 : if ( aSelBoxOptSize.Height() > aSelBoxSize.Height() )
2614 : : {
2615 [ # # ]: 0 : nSplitPos = aPlaygroundSize.Height() - m_aSplitter.GetSizePixel().Height() - aSelBoxOptSize.Height();
2616 : : }
2617 : :
2618 : 0 : static_cast< OQueryController& >(getController()).setSplitPos( nSplitPos );
2619 : : }
2620 : : }
2621 : : }
2622 : :
2623 : : // normalize the split pos
2624 : 0 : Point aSplitPos = Point( _rPlayground.Left(), nSplitPos );
2625 [ # # ][ # # ]: 0 : Size aSplitSize = Size( _rPlayground.GetSize().Width(), m_aSplitter.GetSizePixel().Height() );
2626 : :
2627 [ # # ]: 0 : if( ( aSplitPos.Y() + aSplitSize.Height() ) > ( aPlaygroundSize.Height() ))
2628 : 0 : aSplitPos.Y() = aPlaygroundSize.Height() - aSplitSize.Height();
2629 : :
2630 [ # # ]: 0 : if( aSplitPos.Y() <= aPlaygroundPos.Y() )
2631 : 0 : aSplitPos.Y() = aPlaygroundPos.Y() + sal_Int32(aPlaygroundSize.Height() * 0.2);
2632 : :
2633 : : // position the table
2634 : 0 : Size aTableViewSize(aPlaygroundSize.Width(), aSplitPos.Y() - aPlaygroundPos.Y());
2635 [ # # ]: 0 : m_pScrollWindow->SetPosSizePixel(aPlaygroundPos, aTableViewSize);
2636 : :
2637 : : // position the selection browse box
2638 : 0 : Point aPos( aPlaygroundPos.X(), aSplitPos.Y() + aSplitSize.Height() );
2639 [ # # ]: 0 : m_pSelectionBox->SetPosSizePixel( aPos, Size( aPlaygroundSize.Width(), aPlaygroundSize.Height() - aSplitSize.Height() - aTableViewSize.Height() ));
2640 : :
2641 : : // set the size of the splitter
2642 [ # # ]: 0 : m_aSplitter.SetPosSizePixel( aSplitPos, aSplitSize );
2643 [ # # ]: 0 : m_aSplitter.SetDragRectPixel( _rPlayground );
2644 : :
2645 : : // just for completeness: there is no space left, we occupied it all ...
2646 [ # # ]: 0 : _rPlayground.SetPos( _rPlayground.BottomRight() );
2647 [ # # ]: 0 : _rPlayground.SetSize( Size( 0, 0 ) );
2648 : 0 : }
2649 : : // -----------------------------------------------------------------------------
2650 : 0 : void OQueryDesignView::setReadOnly(sal_Bool _bReadOnly)
2651 : : {
2652 : 0 : m_pSelectionBox->SetReadOnly(_bReadOnly);
2653 : 0 : }
2654 : : // -----------------------------------------------------------------------------
2655 : 0 : void OQueryDesignView::clear()
2656 : : {
2657 : 0 : m_pSelectionBox->ClearAll(); // clear the whole selection
2658 : 0 : m_pTableView->ClearAll();
2659 : 0 : }
2660 : : // -----------------------------------------------------------------------------
2661 : 0 : void OQueryDesignView::setStatement(const ::rtl::OUString& /*_rsStatement*/)
2662 : : {
2663 : 0 : }
2664 : : // -----------------------------------------------------------------------------
2665 : 0 : void OQueryDesignView::copy()
2666 : : {
2667 [ # # ]: 0 : if( m_eChildFocus == SELECTION)
2668 : 0 : m_pSelectionBox->copy();
2669 : 0 : }
2670 : : // -----------------------------------------------------------------------------
2671 : 0 : sal_Bool OQueryDesignView::isCutAllowed()
2672 : : {
2673 : 0 : sal_Bool bAllowed = sal_False;
2674 [ # # ]: 0 : if ( SELECTION == m_eChildFocus )
2675 : 0 : bAllowed = m_pSelectionBox->isCutAllowed();
2676 : 0 : return bAllowed;
2677 : : }
2678 : : // -----------------------------------------------------------------------------
2679 : 0 : sal_Bool OQueryDesignView::isPasteAllowed()
2680 : : {
2681 : 0 : sal_Bool bAllowed = sal_False;
2682 [ # # ]: 0 : if ( SELECTION == m_eChildFocus )
2683 : 0 : bAllowed = m_pSelectionBox->isPasteAllowed();
2684 : 0 : return bAllowed;
2685 : : }
2686 : : // -----------------------------------------------------------------------------
2687 : 0 : sal_Bool OQueryDesignView::isCopyAllowed()
2688 : : {
2689 : 0 : sal_Bool bAllowed = sal_False;
2690 [ # # ]: 0 : if ( SELECTION == m_eChildFocus )
2691 : 0 : bAllowed = m_pSelectionBox->isCopyAllowed();
2692 : 0 : return bAllowed;
2693 : : }
2694 : : // -----------------------------------------------------------------------------
2695 : 0 : void OQueryDesignView::stopTimer()
2696 : : {
2697 : 0 : m_pSelectionBox->stopTimer();
2698 : 0 : }
2699 : : // -----------------------------------------------------------------------------
2700 : 0 : void OQueryDesignView::startTimer()
2701 : : {
2702 : 0 : m_pSelectionBox->startTimer();
2703 : 0 : }
2704 : : // -----------------------------------------------------------------------------
2705 : 0 : void OQueryDesignView::cut()
2706 : : {
2707 [ # # ]: 0 : if( m_eChildFocus == SELECTION)
2708 : : {
2709 : 0 : m_pSelectionBox->cut();
2710 : 0 : static_cast<OQueryController&>(getController()).setModified(sal_True);
2711 : : }
2712 : 0 : }
2713 : : // -----------------------------------------------------------------------------
2714 : 0 : void OQueryDesignView::paste()
2715 : : {
2716 [ # # ]: 0 : if( m_eChildFocus == SELECTION)
2717 : : {
2718 : 0 : m_pSelectionBox->paste();
2719 : 0 : static_cast<OQueryController&>(getController()).setModified(sal_True);
2720 : : }
2721 : 0 : }
2722 : : // -----------------------------------------------------------------------------
2723 : 0 : void OQueryDesignView::TableDeleted(const ::rtl::OUString& rAliasName)
2724 : : {
2725 : : // Nachricht, dass Tabelle aus dem Fenster gel"oscht wurde
2726 : 0 : DeleteFields(rAliasName);
2727 [ # # ]: 0 : static_cast<OQueryController&>(getController()).InvalidateFeature(ID_BROWSER_ADDTABLE); // view nochmal bescheid sagen
2728 : 0 : }
2729 : : //------------------------------------------------------------------------------
2730 : 0 : void OQueryDesignView::DeleteFields( const ::rtl::OUString& rAliasName )
2731 : : {
2732 [ # # ]: 0 : m_pSelectionBox->DeleteFields( rAliasName );
2733 : 0 : }
2734 : : // -----------------------------------------------------------------------------
2735 : 0 : bool OQueryDesignView::HasFieldByAliasName(const ::rtl::OUString& rFieldName, OTableFieldDescRef& rInfo) const
2736 : : {
2737 : 0 : return m_pSelectionBox->HasFieldByAliasName( rFieldName, rInfo);
2738 : : }
2739 : : // -----------------------------------------------------------------------------
2740 : 0 : SqlParseError OQueryDesignView::InsertField( const OTableFieldDescRef& rInfo, sal_Bool bVis, sal_Bool bActivate)
2741 : : {
2742 [ # # ]: 0 : return m_pSelectionBox->InsertField( rInfo, BROWSER_INVALIDID,bVis, bActivate ).is() ? eOk : eTooManyColumns;
2743 : : }
2744 : : // -----------------------------------------------------------------------------
2745 : 0 : sal_Int32 OQueryDesignView::getColWidth(sal_uInt16 _nColPos) const
2746 : : {
2747 [ # # ][ # # ]: 0 : static sal_Int32 s_nDefaultWidth = GetTextWidth(String(RTL_CONSTASCII_USTRINGPARAM("0"))) * 15;
[ # # ][ # # ]
[ # # ][ # # ]
2748 : 0 : sal_Int32 nWidth = static_cast<OQueryController&>(getController()).getColWidth(_nColPos);
2749 [ # # ]: 0 : if ( !nWidth )
2750 : 0 : nWidth = s_nDefaultWidth;
2751 : 0 : return nWidth;
2752 : : }
2753 : : //------------------------------------------------------------------------------
2754 : 0 : void OQueryDesignView::fillValidFields(const ::rtl::OUString& sAliasName, ComboBox* pFieldList)
2755 : : {
2756 : : OSL_ENSURE(pFieldList != NULL, "OQueryDesignView::FillValidFields : What the hell do you think I can do with a NULL-ptr ? This will crash !");
2757 [ # # ]: 0 : pFieldList->Clear();
2758 : :
2759 : 0 : sal_Bool bAllTables = sAliasName.isEmpty();
2760 : :
2761 : 0 : OJoinTableView::OTableWindowMap* pTabWins = m_pTableView->GetTabWinMap();
2762 : 0 : ::rtl::OUString strCurrentPrefix;
2763 [ # # ]: 0 : ::std::vector< ::rtl::OUString> aFields;
2764 : 0 : OJoinTableView::OTableWindowMap::iterator aIter = pTabWins->begin();
2765 : 0 : OJoinTableView::OTableWindowMap::iterator aEnd = pTabWins->end();
2766 [ # # ]: 0 : for(;aIter != aEnd;++aIter)
2767 : : {
2768 : 0 : OQueryTableWindow* pCurrentWin = static_cast<OQueryTableWindow*>(aIter->second);
2769 [ # # ][ # # ]: 0 : if (bAllTables || (pCurrentWin->GetAliasName() == sAliasName))
[ # # ]
[ # # # # ]
[ # # ]
2770 : : {
2771 [ # # ]: 0 : strCurrentPrefix = pCurrentWin->GetAliasName();
2772 : 0 : strCurrentPrefix += ::rtl::OUString('.');
2773 : :
2774 [ # # ]: 0 : pCurrentWin->EnumValidFields(aFields);
2775 : :
2776 : 0 : ::std::vector< ::rtl::OUString>::iterator aStrIter = aFields.begin();
2777 : 0 : ::std::vector< ::rtl::OUString>::iterator aStrEnd = aFields.end();
2778 [ # # ][ # # ]: 0 : for(;aStrIter != aStrEnd;++aStrIter)
2779 : : {
2780 [ # # ][ # # ]: 0 : if (bAllTables || aStrIter->toChar() == '*')
[ # # ]
2781 [ # # ][ # # ]: 0 : pFieldList->InsertEntry(::rtl::OUString(strCurrentPrefix) += *aStrIter);
[ # # ]
2782 : : else
2783 [ # # ][ # # ]: 0 : pFieldList->InsertEntry(*aStrIter);
[ # # ]
2784 : : }
2785 : :
2786 [ # # ]: 0 : if (!bAllTables)
2787 : : // das heisst, dass ich in diesen Block kam, weil der Tabellenname genau der gesuchte war, also bin ich fertig
2788 : : // (dadurch verhindere ich auch das doppelte Einfuegen von Feldern, wenn eine Tabelle mehrmals als TabWin vorkommt)
2789 : : break;
2790 : : }
2791 : 0 : }
2792 : 0 : }
2793 : : // -----------------------------------------------------------------------------
2794 : 0 : long OQueryDesignView::PreNotify(NotifyEvent& rNEvt)
2795 : : {
2796 [ # # ]: 0 : switch (rNEvt.GetType())
2797 : : {
2798 : : case EVENT_GETFOCUS:
2799 : : #if OSL_DEBUG_LEVEL > 0
2800 : : {
2801 : : Window* pFocus = Application::GetFocusWindow();
2802 : : (void)pFocus;
2803 : : }
2804 : : #endif
2805 : :
2806 [ # # ][ # # ]: 0 : if ( m_pSelectionBox && m_pSelectionBox->HasChildPathFocus() )
[ # # ]
2807 : 0 : m_eChildFocus = SELECTION;
2808 : : else
2809 : 0 : m_eChildFocus = TABLEVIEW;
2810 : 0 : break;
2811 : : }
2812 : :
2813 : 0 : return OQueryView::PreNotify(rNEvt);
2814 : : }
2815 : : //------------------------------------------------------------------------------
2816 : :
2817 : :
2818 : : // -----------------------------------------------------------------------------
2819 : : // check if the statement is correct when not returning false
2820 : 0 : sal_Bool OQueryDesignView::checkStatement()
2821 : : {
2822 : 0 : sal_Bool bRet = sal_True;
2823 [ # # ]: 0 : if ( m_pSelectionBox )
2824 : 0 : bRet = m_pSelectionBox->Save(); // an error occurred so we return no
2825 : 0 : return bRet;
2826 : : }
2827 : : //-------------------------------------------------------------------------------
2828 : 0 : ::rtl::OUString OQueryDesignView::getStatement()
2829 : : {
2830 : 0 : OQueryController& rController = static_cast<OQueryController&>(getController());
2831 [ # # ]: 0 : m_rController.clearError();
2832 : : // used for fields which aren't any longer in the statement
2833 : 0 : OTableFields& rUnUsedFields = rController.getUnUsedFields();
2834 [ # # ]: 0 : OTableFields().swap( rUnUsedFields );
2835 : :
2836 : : // create the select columns
2837 : 0 : sal_uInt32 nFieldcount = 0;
2838 : 0 : OTableFields& rFieldList = rController.getTableFieldDesc();
2839 : 0 : OTableFields::iterator aIter = rFieldList.begin();
2840 : 0 : OTableFields::iterator aEnd = rFieldList.end();
2841 [ # # ][ # # ]: 0 : for(;aIter != aEnd;++aIter)
2842 : : {
2843 [ # # ]: 0 : OTableFieldDescRef pEntryField = *aIter;
2844 [ # # ][ # # ]: 0 : if (!pEntryField->GetField().isEmpty() && pEntryField->IsVisible() )
[ # # ][ # # ]
2845 : 0 : ++nFieldcount;
2846 [ # # ][ # # : 0 : else if (!pEntryField->GetField().isEmpty() &&
# # # # #
# # # ]
[ # # ]
[ # # # # ]
2847 [ # # ]: 0 : !pEntryField->HasCriteria() &&
2848 : 0 : pEntryField->isNoneFunction() &&
2849 : 0 : pEntryField->GetOrderDir() == ORDER_NONE &&
2850 : 0 : !pEntryField->IsGroupBy() &&
2851 [ # # ][ # # ]: 0 : pEntryField->GetFunction().isEmpty() )
2852 [ # # ]: 0 : rUnUsedFields.push_back(pEntryField);
2853 [ # # ]: 0 : }
2854 [ # # ]: 0 : if ( !nFieldcount ) // keine Felder sichtbar also zur"uck
2855 : : {
2856 [ # # ]: 0 : rUnUsedFields = rFieldList;
2857 : 0 : return ::rtl::OUString();
2858 : : }
2859 : :
2860 : 0 : OQueryTableView::OTableWindowMap* pTabList = m_pTableView->GetTabWinMap();
2861 : 0 : sal_uInt32 nTabcount = pTabList->size();
2862 : :
2863 [ # # ]: 0 : ::rtl::OUString aFieldListStr(GenerateSelectList(this,rFieldList,nTabcount>1));
2864 [ # # ]: 0 : if( aFieldListStr.isEmpty() )
2865 : 0 : return ::rtl::OUString();
2866 : : // Ausnahmebehandlung, wenn keine Felder angegeben worden sind
2867 : : // Dann darf die Tabpage nicht gewechselt werden
2868 : : // Im TabBarSelectHdl wird der SQL-::rtl::OUString auf STATEMENT_NOFIELDS abgefragt
2869 : : // und eine Errormeldung erzeugt
2870 : : // ----------------- Tabellenliste aufbauen ----------------------
2871 : :
2872 : 0 : const ::std::vector<OTableConnection*>* pConnList = m_pTableView->getTableConnections();
2873 [ # # ]: 0 : Reference< XConnection> xConnection = rController.getConnection();
2874 [ # # ]: 0 : ::rtl::OUString aTableListStr(GenerateFromClause(xConnection,pTabList,pConnList));
2875 : : OSL_ENSURE(!aTableListStr.isEmpty(), "OQueryDesignView::getStatement() : unerwartet : habe Felder, aber keine Tabellen !");
2876 : : // wenn es Felder gibt, koennen die nur durch Einfuegen aus einer schon existenten Tabelle entstanden sein; wenn andererseits
2877 : : // eine Tabelle geloescht wird, verschwinden auch die zugehoerigen Felder -> ergo KANN es das nicht geben, dass Felder
2878 : : // existieren, aber keine Tabellen (und aFieldListStr hat schon eine Laenge, das stelle ich oben sicher)
2879 : 0 : ::rtl::OUStringBuffer aHavingStr,aCriteriaListStr;
2880 : : // ----------------- Kriterien aufbauen ----------------------
2881 [ # # ][ # # ]: 0 : if (!GenerateCriterias(this,aCriteriaListStr,aHavingStr,rFieldList, nTabcount > 1))
2882 : 0 : return ::rtl::OUString();
2883 : :
2884 : 0 : ::rtl::OUString aJoinCrit;
2885 [ # # ]: 0 : GenerateInnerJoinCriterias(xConnection,aJoinCrit,pConnList);
2886 [ # # ]: 0 : if(!aJoinCrit.isEmpty())
2887 : : {
2888 [ # # ]: 0 : ::rtl::OUString aTmp(RTL_CONSTASCII_USTRINGPARAM("( "));
2889 : 0 : aTmp += aJoinCrit;
2890 [ # # ]: 0 : aTmp += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" )"));
2891 [ # # ]: 0 : if(aCriteriaListStr.getLength())
2892 : : {
2893 : 0 : aTmp += C_AND;
2894 [ # # ]: 0 : aTmp += aCriteriaListStr.makeStringAndClear();
2895 : : }
2896 [ # # ][ # # ]: 0 : aCriteriaListStr = aTmp;
2897 : : }
2898 : : // ----------------- Statement aufbauen ----------------------
2899 [ # # ][ # # ]: 0 : ::rtl::OUStringBuffer aSqlCmd(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SELECT ")));
2900 [ # # ]: 0 : if(static_cast<OQueryController&>(getController()).isDistinct())
2901 [ # # ][ # # ]: 0 : aSqlCmd.append(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" DISTINCT ")));
2902 [ # # ]: 0 : aSqlCmd.append(aFieldListStr);
2903 [ # # ][ # # ]: 0 : aSqlCmd.append(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" FROM ")));
2904 [ # # ]: 0 : aSqlCmd.append(aTableListStr);
2905 : :
2906 [ # # ]: 0 : if (aCriteriaListStr.getLength())
2907 : : {
2908 [ # # ][ # # ]: 0 : aSqlCmd.append(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" WHERE ")));
2909 [ # # ][ # # ]: 0 : aSqlCmd.append(aCriteriaListStr.makeStringAndClear());
2910 : : }
2911 : : // ----------------- GroupBy aufbauen und Anh"angen ------------
2912 : 0 : Reference<XDatabaseMetaData> xMeta;
2913 [ # # ]: 0 : if ( xConnection.is() )
2914 [ # # ][ # # ]: 0 : xMeta = xConnection->getMetaData();
[ # # ]
2915 : 0 : sal_Bool bUseAlias = nTabcount > 1;
2916 [ # # ]: 0 : if ( xMeta.is() )
2917 [ # # ][ # # ]: 0 : bUseAlias = bUseAlias || !xMeta->supportsGroupByUnrelated();
[ # # ][ # # ]
2918 : :
2919 [ # # ][ # # ]: 0 : aSqlCmd.append(GenerateGroupBy(this,rFieldList,bUseAlias));
2920 : : // ----------------- having Anh"angen ------------
2921 [ # # ]: 0 : if(aHavingStr.getLength())
2922 : : {
2923 [ # # ][ # # ]: 0 : aSqlCmd.append(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" HAVING ")));
2924 [ # # ][ # # ]: 0 : aSqlCmd.append(aHavingStr.makeStringAndClear());
2925 : : }
2926 : : // ----------------- Sortierung aufbauen und Anh"angen ------------
2927 : 0 : ::rtl::OUString sOrder;
2928 : 0 : SqlParseError eErrorCode = eOk;
2929 [ # # ][ # # ]: 0 : if ( (eErrorCode = GenerateOrder(this,rFieldList,nTabcount > 1,sOrder)) == eOk)
2930 [ # # ]: 0 : aSqlCmd.append(sOrder);
2931 : : else
2932 : : {
2933 [ # # ][ # # ]: 0 : if ( !m_rController.hasError() )
2934 [ # # ][ # # ]: 0 : m_rController.appendError( getParseErrorMessage( eErrorCode ) );
[ # # ][ # # ]
2935 : :
2936 [ # # ]: 0 : m_rController.displayError();
2937 : : }
2938 : :
2939 [ # # ]: 0 : ::rtl::OUString sSQL = aSqlCmd.makeStringAndClear();
2940 [ # # ]: 0 : if ( xConnection.is() )
2941 : : {
2942 : 0 : ::connectivity::OSQLParser& rParser( rController.getParser() );
2943 : 0 : ::rtl::OUString sErrorMessage;
2944 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
2945 [ # # ]: 0 : ::std::auto_ptr<OSQLParseNode> pParseNode( rParser.parseTree( sErrorMessage, sSQL, sal_True ) );
2946 : : SAL_WNODEPRECATED_DECLARATIONS_POP
2947 [ # # ]: 0 : if ( pParseNode.get() )
2948 : : {
2949 [ # # ][ # # ]: 0 : OSQLParseNode* pNode = pParseNode->getChild(3)->getChild(1);
2950 [ # # ]: 0 : if ( pNode->count() > 1 )
2951 : : {
2952 [ # # ]: 0 : ::connectivity::OSQLParseNode * pCondition = pNode->getChild(1);
2953 [ # # ]: 0 : if ( pCondition ) // no where clause
2954 : : {
2955 [ # # ]: 0 : OSQLParseNode::compress(pCondition);
2956 : 0 : ::rtl::OUString sTemp;
2957 [ # # ]: 0 : pParseNode->parseNodeToStr(sTemp,xConnection);
2958 : 0 : sSQL = sTemp;
2959 : : }
2960 : : }
2961 [ # # ]: 0 : }
2962 : : }
2963 : 0 : return sSQL;
2964 : : }
2965 : : // -----------------------------------------------------------------------------
2966 : : // -----------------------------------------------------------------------------
2967 : 0 : void OQueryDesignView::setSlotEnabled(sal_Int32 _nSlotId,sal_Bool _bEnable)
2968 : : {
2969 : : sal_uInt16 nRow;
2970 [ # # # # ]: 0 : switch (_nSlotId)
2971 : : {
2972 : : case SID_QUERY_VIEW_FUNCTIONS:
2973 : 0 : nRow = BROW_FUNCTION_ROW;
2974 : 0 : break;
2975 : : case SID_QUERY_VIEW_TABLES:
2976 : 0 : nRow = BROW_TABLE_ROW;
2977 : 0 : break;
2978 : : case SID_QUERY_VIEW_ALIASES:
2979 : 0 : nRow = BROW_COLUMNALIAS_ROW;
2980 : 0 : break;
2981 : : default:
2982 : : // ????????????
2983 : 0 : nRow = 0;
2984 : 0 : break;
2985 : : }
2986 : 0 : m_pSelectionBox->SetRowVisible(nRow,_bEnable);
2987 : 0 : m_pSelectionBox->Invalidate();
2988 : 0 : }
2989 : : // -----------------------------------------------------------------------------
2990 : 0 : sal_Bool OQueryDesignView::isSlotEnabled(sal_Int32 _nSlotId)
2991 : : {
2992 : : sal_uInt16 nRow;
2993 [ # # # # ]: 0 : switch (_nSlotId)
2994 : : {
2995 : : case SID_QUERY_VIEW_FUNCTIONS:
2996 : 0 : nRow = BROW_FUNCTION_ROW;
2997 : 0 : break;
2998 : : case SID_QUERY_VIEW_TABLES:
2999 : 0 : nRow = BROW_TABLE_ROW;
3000 : 0 : break;
3001 : : case SID_QUERY_VIEW_ALIASES:
3002 : 0 : nRow = BROW_COLUMNALIAS_ROW;
3003 : 0 : break;
3004 : : default:
3005 : : // ?????????
3006 : 0 : nRow = 0;
3007 : 0 : break;
3008 : : }
3009 : 0 : return m_pSelectionBox->IsRowVisible(nRow);
3010 : : }
3011 : : // -----------------------------------------------------------------------------
3012 : 0 : void OQueryDesignView::SaveUIConfig()
3013 : : {
3014 : 0 : OQueryController& rCtrl = static_cast<OQueryController&>(getController());
3015 : 0 : rCtrl.SaveTabWinsPosSize( m_pTableView->GetTabWinMap(), m_pScrollWindow->GetHScrollBar()->GetThumbPos(), m_pScrollWindow->GetVScrollBar()->GetThumbPos() );
3016 : 0 : rCtrl.setVisibleRows( m_pSelectionBox->GetNoneVisibleRows() );
3017 [ # # ]: 0 : if ( m_aSplitter.GetSplitPosPixel() != 0 )
3018 : 0 : rCtrl.setSplitPos( m_aSplitter.GetSplitPosPixel() );
3019 : 0 : }
3020 : : // -----------------------------------------------------------------------------
3021 : 0 : OSQLParseNode* OQueryDesignView::getPredicateTreeFromEntry(OTableFieldDescRef pEntry,
3022 : : const String& _sCriteria,
3023 : : ::rtl::OUString& _rsErrorMessage,
3024 : : Reference<XPropertySet>& _rxColumn) const
3025 : : {
3026 : : OSL_ENSURE(pEntry.is(),"Entry is null!");
3027 [ # # ]: 0 : if(!pEntry.is())
3028 : 0 : return NULL;
3029 [ # # ]: 0 : Reference< XConnection> xConnection = static_cast<OQueryController&>(getController()).getConnection();
3030 [ # # ]: 0 : if(!xConnection.is())
3031 : 0 : return NULL;
3032 : :
3033 : 0 : ::connectivity::OSQLParser& rParser( static_cast<OQueryController&>(getController()).getParser() );
3034 [ # # ]: 0 : OQueryTableWindow* pWin = static_cast<OQueryTableWindow*>(pEntry->GetTabWindow());
3035 : :
3036 [ # # ]: 0 : String sTest(_sCriteria);
3037 : : // special handling for functions
3038 [ # # ]: 0 : if ( pEntry->GetFunctionType() & (FKT_OTHER | FKT_AGGREGATE | FKT_NUMERIC) )
3039 : : {
3040 : : // we have a function here so we have to distinguish the type of return value
3041 [ # # ]: 0 : String sFunction;
3042 [ # # ]: 0 : if ( pEntry->isNumericOrAggreateFunction() )
3043 [ # # ]: 0 : sFunction = pEntry->GetFunction();
3044 : :
3045 [ # # ]: 0 : if ( !sFunction.Len() )
3046 [ # # ]: 0 : sFunction = pEntry->GetField();
3047 : :
3048 [ # # ][ # # ]: 0 : if (comphelper::string::getTokenCount(sFunction, '(') > 1)
[ # # ]
3049 [ # # ][ # # ]: 0 : sFunction = sFunction.GetToken(0,'('); // this should be the name of the function
[ # # ]
3050 : :
3051 [ # # ][ # # ]: 0 : sal_Int32 nType = ::connectivity::OSQLParser::getFunctionReturnType(sFunction,&rParser.getContext());
3052 [ # # ][ # # ]: 0 : if ( nType == DataType::OTHER || (!sFunction.Len() && pEntry->isNumericOrAggreateFunction()) )
[ # # ][ # # ]
3053 : : {
3054 : : // first try the international version
3055 : 0 : ::rtl::OUString sSql;
3056 [ # # ]: 0 : sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SELECT * "));
3057 [ # # ]: 0 : sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" FROM x WHERE "));
3058 : 0 : sSql += pEntry->GetField();
3059 [ # # ]: 0 : sSql += _sCriteria;
3060 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
3061 [ # # ]: 0 : ::std::auto_ptr<OSQLParseNode> pParseNode( rParser.parseTree( _rsErrorMessage, sSql, sal_True ) );
3062 : : SAL_WNODEPRECATED_DECLARATIONS_POP
3063 : 0 : nType = DataType::DOUBLE;
3064 [ # # ]: 0 : if ( pParseNode.get() )
3065 : : {
3066 [ # # ]: 0 : OSQLParseNode* pColumnRef = pParseNode->getByRule(OSQLParseNode::column_ref);
3067 [ # # ]: 0 : if ( pColumnRef )
3068 : : {
3069 [ # # ][ # # ]: 0 : OTableFieldDescRef aField = new OTableFieldDesc();
[ # # ]
3070 [ # # ][ # # ]: 0 : if ( eOk == FillDragInfo(this,pColumnRef,aField) )
3071 : : {
3072 : 0 : nType = aField->GetDataType();
3073 [ # # ]: 0 : }
3074 : : }
3075 [ # # ]: 0 : }
3076 : : }
3077 : :
3078 [ # # ][ # # ]: 0 : Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
3079 : : parse::OParseColumn* pColumn = new parse::OParseColumn( pEntry->GetField(),
3080 : : ::rtl::OUString(),
3081 : : ::rtl::OUString(),
3082 : : ::rtl::OUString(),
3083 : : ColumnValue::NULLABLE_UNKNOWN,
3084 : : 0,
3085 : : 0,
3086 : : nType,
3087 : : sal_False,
3088 : : sal_False,
3089 [ # # ][ # # ]: 0 : xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers());
[ # # ][ # # ]
[ # # ]
3090 [ # # ][ # # ]: 0 : _rxColumn = pColumn;
3091 : 0 : pColumn->setFunction(sal_True);
3092 [ # # ]: 0 : pColumn->setRealName(pEntry->GetField());
3093 : : }
3094 : : else
3095 : : {
3096 [ # # ]: 0 : if (pWin)
3097 : : {
3098 [ # # ]: 0 : Reference<XNameAccess> xColumns = pWin->GetOriginalColumns();
3099 [ # # ][ # # ]: 0 : if (xColumns.is() && xColumns->hasByName(pEntry->GetField()))
[ # # ][ # # ]
[ # # ]
[ # # # # ]
3100 [ # # ][ # # ]: 0 : xColumns->getByName(pEntry->GetField()) >>= _rxColumn;
[ # # ]
3101 : : }
3102 : : }
3103 : :
3104 : : OSQLParseNode* pParseNode = rParser.predicateTree( _rsErrorMessage,
3105 : : sTest,
3106 : 0 : static_cast<OQueryController&>(getController()).getNumberFormatter(),
3107 [ # # ][ # # ]: 0 : _rxColumn);
[ # # ]
3108 [ # # ]: 0 : return pParseNode;
3109 : : }
3110 : : // -----------------------------------------------------------------------------
3111 : 0 : void OQueryDesignView::GetFocus()
3112 : : {
3113 : 0 : OQueryView::GetFocus();
3114 [ # # ][ # # ]: 0 : if ( m_pSelectionBox && !m_pSelectionBox->HasChildPathFocus() )
[ # # ]
3115 : : {
3116 : : // first we have to deactivate the current cell to refill when necessary
3117 : 0 : m_pSelectionBox->DeactivateCell();
3118 : 0 : m_pSelectionBox->ActivateCell(m_pSelectionBox->GetCurRow(), m_pSelectionBox->GetCurColumnId());
3119 : 0 : m_pSelectionBox->GrabFocus();
3120 : : }
3121 : 0 : }
3122 : : // -----------------------------------------------------------------------------
3123 : 0 : void OQueryDesignView::reset()
3124 : : {
3125 : 0 : m_pTableView->ClearAll();
3126 : 0 : m_pTableView->ReSync();
3127 : 0 : }
3128 : : // -----------------------------------------------------------------------------
3129 : 0 : void OQueryDesignView::setNoneVisbleRow(sal_Int32 _nRows)
3130 : : {
3131 : 0 : m_pSelectionBox->SetNoneVisbleRow(_nRows);
3132 : 0 : }
3133 : :
3134 : : // -----------------------------------------------------------------------------
3135 : 0 : void OQueryDesignView::initByFieldDescriptions( const Sequence< PropertyValue >& i_rFieldDescriptions )
3136 : : {
3137 : 0 : OQueryController& rController = static_cast< OQueryController& >( getController() );
3138 : :
3139 : 0 : m_pSelectionBox->PreFill();
3140 : 0 : m_pSelectionBox->SetReadOnly( rController.isReadOnly() );
3141 : 0 : m_pSelectionBox->Fill();
3142 : :
3143 [ # # ]: 0 : for ( const PropertyValue* field = i_rFieldDescriptions.getConstArray();
3144 : 0 : field != i_rFieldDescriptions.getConstArray() + i_rFieldDescriptions.getLength();
3145 : : ++field
3146 : : )
3147 : : {
3148 [ # # ][ # # ]: 0 : ::rtl::Reference< OTableFieldDesc > pField( new OTableFieldDesc() );
[ # # ]
3149 [ # # ]: 0 : pField->Load( *field, true );
3150 [ # # ]: 0 : InsertField( pField, sal_True, sal_False );
3151 [ # # ]: 0 : }
3152 : :
3153 : 0 : rController.ClearUndoManager();
3154 : 0 : m_pSelectionBox->Invalidate();
3155 : 0 : }
3156 : :
3157 : : // -----------------------------------------------------------------------------
3158 : 0 : bool OQueryDesignView::initByParseIterator( ::dbtools::SQLExceptionInfo* _pErrorInfo )
3159 : : {
3160 : 0 : SqlParseError eErrorCode = eNativeMode;
3161 : 0 : m_rController.clearError();
3162 : :
3163 : : try
3164 : : {
3165 [ # # ]: 0 : eErrorCode = InitFromParseNodeImpl( this, m_pSelectionBox );
3166 : :
3167 [ # # ]: 0 : if ( eErrorCode != eOk )
3168 : : {
3169 [ # # ][ # # ]: 0 : if ( !m_rController.hasError() )
3170 [ # # ][ # # ]: 0 : m_rController.appendError( getParseErrorMessage( eErrorCode ) );
[ # # ][ # # ]
[ # # ]
3171 : :
3172 [ # # ]: 0 : if ( _pErrorInfo )
3173 : : {
3174 [ # # ][ # # ]: 0 : *_pErrorInfo = m_rController.getError();
3175 : : }
3176 : : else
3177 : : {
3178 [ # # ]: 0 : m_rController.displayError();
3179 : : }
3180 : : }
3181 : : }
3182 : 0 : catch ( const Exception& )
3183 : : {
3184 : : DBG_UNHANDLED_EXCEPTION();
3185 : : }
3186 : 0 : return eErrorCode == eOk;
3187 : : }
3188 : :
3189 : : // Utility function for fillFunctionInfo
3190 : : namespace {
3191 : 0 : sal_Int32 char_datatype(const::connectivity::OSQLParseNode* pDataType, const unsigned int offset) {
3192 : 0 : int cnt = pDataType->count() - offset;
3193 [ # # ]: 0 : if ( cnt < 0 )
3194 : : {
3195 : : OSL_FAIL("internal error in decoding character datatype specification");
3196 : 0 : return DataType::VARCHAR;
3197 : : }
3198 [ # # ]: 0 : else if ( cnt == 0 )
3199 : : {
3200 [ # # ]: 0 : if ( offset == 0 )
3201 : : {
3202 : : // The datatype is the node itself
3203 [ # # ][ # # ]: 0 : if ( SQL_ISTOKENOR2 (pDataType, CHARACTER, CHAR) )
[ # # ][ # # ]
3204 : 0 : return DataType::CHAR;
3205 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN (pDataType, VARCHAR) )
[ # # ]
3206 : 0 : return DataType::VARCHAR;
3207 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN (pDataType, CLOB) )
[ # # ]
3208 : 0 : return DataType::CLOB;
3209 : : else
3210 : : {
3211 : : OSL_FAIL("unknown/unexpected token in decoding character datatype specification");
3212 : 0 : return DataType::VARCHAR;
3213 : : }
3214 : : }
3215 : : else
3216 : : {
3217 : : // No child left to read!
3218 : : OSL_FAIL("incomplete datatype in decoding character datatype specification");
3219 : 0 : return DataType::VARCHAR;
3220 : : }
3221 : : }
3222 : :
3223 [ # # ][ # # ]: 0 : if ( SQL_ISTOKEN(pDataType->getChild(offset), NATIONAL) )
[ # # ]
3224 : 0 : return char_datatype(pDataType, offset+1);
3225 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKENOR3(pDataType->getChild(offset), CHARACTER, CHAR, NCHAR) )
[ # # ][ # # ]
[ # # ]
3226 : : {
3227 [ # # ][ # # ]: 0 : if ( cnt > 2 && SQL_ISTOKEN(pDataType->getChild(offset+1), LARGE) && SQL_ISTOKEN(pDataType->getChild(offset+2), OBJECT) )
[ # # ][ # # ]
[ # # ][ # # ]
3228 : 0 : return DataType::CLOB;
3229 [ # # ][ # # ]: 0 : else if ( cnt > 1 && SQL_ISTOKEN(pDataType->getChild(offset+1), VARYING) )
[ # # ][ # # ]
3230 : 0 : return DataType::VARCHAR;
3231 : : else
3232 : 0 : return DataType::CHAR;
3233 : : }
3234 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN (pDataType->getChild(offset), VARCHAR) )
[ # # ]
3235 : 0 : return DataType::VARCHAR;
3236 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKENOR2 (pDataType->getChild(offset), CLOB, NCLOB) )
[ # # ][ # # ]
3237 : 0 : return DataType::CLOB;
3238 : :
3239 : : OSL_FAIL("unrecognised character datatype");
3240 : 0 : return DataType::VARCHAR;
3241 : : }
3242 : : }
3243 : :
3244 : : //------------------------------------------------------------------------------
3245 : : // Try to guess the type of an expression in simple cases.
3246 : : // Originally meant to be called only on a function call (hence the misnomer),
3247 : : // but now tries to do the best it can also in other cases.
3248 : : // Don't completely rely on fillFunctionInfo,
3249 : : // it won't look at the function's arguments to find the return type
3250 : : // (in particular, in the case of general_set_fct,
3251 : : // the return type is the type of the argument;
3252 : : // if that is (as is typical) a column reference,
3253 : : // it is the type of the column).
3254 : : // TODO: There is similar "guess the expression's type" code in several places:
3255 : : // SelectionBrowseBox.cxx: OSelectionBrowseBox::saveField
3256 : : // QueryDesignView.cxx: InstallFields, GetOrderCriteria, GetGroupCriteria
3257 : : // If possible, they should be factorised into this function
3258 : : // (which should then be renamed...)
3259 : :
3260 : 0 : void OQueryDesignView::fillFunctionInfo( const ::connectivity::OSQLParseNode* pNode
3261 : : ,const ::rtl::OUString& sFunctionTerm
3262 : : ,OTableFieldDescRef& aInfo)
3263 : : {
3264 : : // get the type of the expression, as far as easily possible
3265 : 0 : OQueryController& rController = static_cast<OQueryController&>(getController());
3266 : 0 : sal_Int32 nDataType = DataType::DOUBLE;
3267 [ # # # # : 0 : switch(pNode->getNodeType())
# # # # ]
3268 : : {
3269 : : case SQL_NODE_CONCAT:
3270 : : case SQL_NODE_STRING:
3271 : 0 : nDataType = DataType::VARCHAR;
3272 : 0 : break;
3273 : : case SQL_NODE_INTNUM:
3274 : 0 : nDataType = DataType::INTEGER;
3275 : 0 : break;
3276 : : case SQL_NODE_APPROXNUM:
3277 : 0 : nDataType = DataType::DOUBLE;
3278 : 0 : break;
3279 : : case SQL_NODE_DATE:
3280 : : case SQL_NODE_ACCESS_DATE:
3281 : 0 : nDataType = DataType::TIMESTAMP;
3282 : 0 : break;
3283 : : case SQL_NODE_COMPARISON:
3284 : : case SQL_NODE_EQUAL:
3285 : : case SQL_NODE_LESS:
3286 : : case SQL_NODE_GREAT:
3287 : : case SQL_NODE_LESSEQ:
3288 : : case SQL_NODE_GREATEQ:
3289 : : case SQL_NODE_NOTEQUAL:
3290 : 0 : nDataType = DataType::BOOLEAN;
3291 : 0 : break;
3292 : : case SQL_NODE_NAME:
3293 : : case SQL_NODE_LISTRULE:
3294 : : case SQL_NODE_COMMALISTRULE:
3295 : : case SQL_NODE_KEYWORD:
3296 : : case SQL_NODE_AMMSC: //??
3297 : : case SQL_NODE_PUNCTUATION:
3298 : : OSL_FAIL("Unexpected SQL Node Type");
3299 : 0 : break;
3300 : : case SQL_NODE_RULE:
3301 [ # # # # : 0 : switch(pNode->getKnownRuleID())
# # # # #
# # # # #
# # ]
3302 : : {
3303 : : case OSQLParseNode::select_statement:
3304 : : case OSQLParseNode::table_exp:
3305 : : case OSQLParseNode::table_ref_commalist:
3306 : : case OSQLParseNode::table_ref:
3307 : : case OSQLParseNode::catalog_name:
3308 : : case OSQLParseNode::schema_name:
3309 : : case OSQLParseNode::table_name:
3310 : : case OSQLParseNode::opt_column_commalist:
3311 : : case OSQLParseNode::column_commalist:
3312 : : case OSQLParseNode::column_ref_commalist:
3313 : : case OSQLParseNode::column_ref:
3314 : : case OSQLParseNode::opt_order_by_clause:
3315 : : case OSQLParseNode::ordering_spec_commalist:
3316 : : case OSQLParseNode::ordering_spec:
3317 : : case OSQLParseNode::opt_asc_desc:
3318 : : case OSQLParseNode::where_clause:
3319 : : case OSQLParseNode::opt_where_clause:
3320 : : case OSQLParseNode::opt_escape:
3321 : : case OSQLParseNode::scalar_exp_commalist:
3322 : : case OSQLParseNode::scalar_exp: // Seems to never be generated?
3323 : : case OSQLParseNode::parameter_ref:
3324 : : case OSQLParseNode::parameter:
3325 : : case OSQLParseNode::range_variable:
3326 : : case OSQLParseNode::delete_statement_positioned:
3327 : : case OSQLParseNode::delete_statement_searched:
3328 : : case OSQLParseNode::update_statement_positioned:
3329 : : case OSQLParseNode::update_statement_searched:
3330 : : case OSQLParseNode::assignment_commalist:
3331 : : case OSQLParseNode::assignment:
3332 : : case OSQLParseNode::insert_statement:
3333 : : case OSQLParseNode::insert_atom_commalist:
3334 : : case OSQLParseNode::insert_atom:
3335 : : case OSQLParseNode::from_clause:
3336 : : case OSQLParseNode::qualified_join:
3337 : : case OSQLParseNode::cross_union:
3338 : : case OSQLParseNode::select_sublist:
3339 : : case OSQLParseNode::join_type:
3340 : : case OSQLParseNode::named_columns_join:
3341 : : case OSQLParseNode::joined_table:
3342 : : case OSQLParseNode::sql_not:
3343 : : case OSQLParseNode::manipulative_statement:
3344 : : case OSQLParseNode::value_exp_commalist:
3345 : : case OSQLParseNode::union_statement:
3346 : : case OSQLParseNode::outer_join_type:
3347 : : case OSQLParseNode::selection:
3348 : : case OSQLParseNode::base_table_def:
3349 : : case OSQLParseNode::base_table_element_commalist:
3350 : : case OSQLParseNode::data_type:
3351 : : case OSQLParseNode::column_def:
3352 : : case OSQLParseNode::table_node:
3353 : : case OSQLParseNode::as: // Seems to never be generated?
3354 : : case OSQLParseNode::op_column_commalist:
3355 : : case OSQLParseNode::table_primary_as_range_column:
3356 : : case OSQLParseNode::character_string_type:
3357 : : OSL_FAIL("Unexpected SQL RuleID");
3358 : 0 : break;
3359 : : case OSQLParseNode::column:
3360 : : case OSQLParseNode::column_val:
3361 : : OSL_FAIL("Cannot guess column type");
3362 : 0 : break;
3363 : : case OSQLParseNode::values_or_query_spec:
3364 : : OSL_FAIL("Cannot guess VALUES type");
3365 : 0 : break;
3366 : : case OSQLParseNode::derived_column:
3367 : : OSL_FAIL("Cannot guess computed column type");
3368 : 0 : break;
3369 : : case OSQLParseNode::subquery:
3370 : : OSL_FAIL("Cannot guess subquery return type");
3371 : 0 : break;
3372 : : case OSQLParseNode::search_condition:
3373 : : case OSQLParseNode::comparison_predicate:
3374 : : case OSQLParseNode::between_predicate:
3375 : : case OSQLParseNode::like_predicate:
3376 : : case OSQLParseNode::test_for_null:
3377 : : case OSQLParseNode::predicate_check: // Seems to never be generated?
3378 : : case OSQLParseNode::boolean_term:
3379 : : case OSQLParseNode::boolean_primary:
3380 : : case OSQLParseNode::in_predicate:
3381 : : case OSQLParseNode::existence_test:
3382 : : case OSQLParseNode::unique_test:
3383 : : case OSQLParseNode::all_or_any_predicate:
3384 : : case OSQLParseNode::join_condition:
3385 : : case OSQLParseNode::boolean_factor:
3386 : : case OSQLParseNode::boolean_test:
3387 : : case OSQLParseNode::comparison_predicate_part_2:
3388 : : case OSQLParseNode::parenthesized_boolean_value_expression:
3389 : : case OSQLParseNode::other_like_predicate_part_2:
3390 : : case OSQLParseNode::between_predicate_part_2:
3391 : 0 : nDataType = DataType::BOOLEAN;
3392 : 0 : break;
3393 : : case OSQLParseNode::num_value_exp:
3394 : : case OSQLParseNode::extract_exp:
3395 : : case OSQLParseNode::term:
3396 : : case OSQLParseNode::factor:
3397 : : // Might by an integer or a float; take the most generic
3398 : 0 : nDataType = DataType::DOUBLE;
3399 : 0 : break;
3400 : : case OSQLParseNode::value_exp_primary:
3401 : : case OSQLParseNode::value_exp:
3402 : : case OSQLParseNode::odbc_call_spec:
3403 : : // Really, we don't know. Let the default.
3404 : 0 : break;
3405 : : case OSQLParseNode::position_exp:
3406 : : case OSQLParseNode::length_exp:
3407 : 0 : nDataType = DataType::INTEGER;
3408 : 0 : break;
3409 : : case OSQLParseNode::char_value_exp:
3410 : : case OSQLParseNode::char_value_fct:
3411 : : case OSQLParseNode::fold:
3412 : : case OSQLParseNode::char_substring_fct:
3413 : : case OSQLParseNode::char_factor:
3414 : : case OSQLParseNode::concatenation:
3415 : 0 : nDataType = DataType::VARCHAR;
3416 : 0 : break;
3417 : : case OSQLParseNode::datetime_primary:
3418 : 0 : nDataType = DataType::TIMESTAMP;
3419 : 0 : break;
3420 : : case OSQLParseNode::bit_value_fct:
3421 : 0 : nDataType = DataType::BINARY;
3422 : 0 : break;
3423 : : case OSQLParseNode::general_set_fct: // May depend on argument; ignore that for now
3424 : : case OSQLParseNode::set_fct_spec:
3425 : : {
3426 [ # # ]: 0 : if (pNode->count() == 0)
3427 : : {
3428 : : // This is not a function call, no sense to continue with a function return type lookup
3429 : : OSL_FAIL("Got leaf SQL node where non-leaf expected");
3430 : 0 : break;
3431 : : }
3432 : 0 : const OSQLParseNode* pFunctionName = pNode->getChild(0);
3433 [ # # ][ # # ]: 0 : if ( SQL_ISPUNCTUATION(pFunctionName,"{") )
[ # # ]
3434 : : {
3435 [ # # ]: 0 : if ( pNode->count() == 3 )
3436 : 0 : return fillFunctionInfo( pNode->getChild(1), sFunctionTerm, aInfo );
3437 : : else
3438 : : OSL_FAIL("ODBC escape not in recognised form");
3439 : 0 : break;
3440 : : }
3441 : : else
3442 : : {
3443 [ # # ][ # # ]: 0 : if ( SQL_ISRULEOR2(pNode,length_exp,char_value_fct) )
[ # # ][ # # ]
[ # # ][ # # ]
3444 [ # # ]: 0 : pFunctionName = pFunctionName->getChild(0);
3445 : :
3446 : 0 : ::rtl::OUString sFunctionName = pFunctionName->getTokenValue();
3447 [ # # ]: 0 : if ( sFunctionName.isEmpty() )
3448 [ # # ][ # # ]: 0 : sFunctionName = ::rtl::OStringToOUString(OSQLParser::TokenIDToStr(pFunctionName->getTokenID()),RTL_TEXTENCODING_UTF8);
3449 : :
3450 : : nDataType = OSQLParser::getFunctionReturnType(
3451 : : sFunctionName
3452 [ # # ]: 0 : ,&rController.getParser().getContext());
3453 : : }
3454 : 0 : break;
3455 : : }
3456 : : case OSQLParseNode::odbc_fct_spec:
3457 : : {
3458 [ # # ]: 0 : if (pNode->count() != 2)
3459 : : {
3460 : : OSL_FAIL("interior of ODBC escape not in recognised shape");
3461 : 0 : break;
3462 : : }
3463 : :
3464 : 0 : const OSQLParseNode* const pEscapeType = pNode->getChild(0);
3465 [ # # ][ # # ]: 0 : if (SQL_ISTOKEN(pEscapeType, TS))
[ # # ]
3466 : 0 : nDataType = DataType::TIMESTAMP;
3467 [ # # ][ # # ]: 0 : else if (SQL_ISTOKEN(pEscapeType, D))
[ # # ]
3468 : 0 : nDataType = DataType::DATE;
3469 [ # # ][ # # ]: 0 : else if (SQL_ISTOKEN(pEscapeType, T))
[ # # ]
3470 : 0 : nDataType = DataType::TIME;
3471 [ # # ][ # # ]: 0 : else if (SQL_ISTOKEN(pEscapeType, FN))
[ # # ]
3472 : 0 : return fillFunctionInfo( pNode->getChild(1), sFunctionTerm, aInfo );
3473 : : else
3474 : : OSL_FAIL("Unknown ODBC escape");
3475 : 0 : break;
3476 : : }
3477 : : case OSQLParseNode::cast_spec:
3478 : : {
3479 [ # # ][ # # ]: 0 : if ( pNode->count() != 6 || !SQL_ISTOKEN(pNode->getChild(3), AS) )
[ # # ][ # # ]
3480 : : {
3481 : : OSL_FAIL("CAST not in recognised shape");
3482 : 0 : break;
3483 : : }
3484 : 0 : const OSQLParseNode *pCastTarget = pNode->getChild(4);
3485 [ # # ][ # # ]: 0 : if ( SQL_ISTOKENOR2(pCastTarget, INTEGER, INT) )
[ # # ][ # # ]
3486 : 0 : nDataType = DataType::INTEGER;
3487 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN(pCastTarget, SMALLINT) )
[ # # ]
3488 : 0 : nDataType = DataType::SMALLINT;
3489 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN(pCastTarget, BIGINT) )
[ # # ]
3490 : 0 : nDataType = DataType::BIGINT;
3491 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN(pCastTarget, FLOAT) )
[ # # ]
3492 : 0 : nDataType = DataType::FLOAT;
3493 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN(pCastTarget, REAL) )
[ # # ]
3494 : 0 : nDataType = DataType::REAL;
3495 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN(pCastTarget, DOUBLE) )
[ # # ]
3496 : 0 : nDataType = DataType::DOUBLE;
3497 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN(pCastTarget, BOOLEAN) )
[ # # ]
3498 : 0 : nDataType = DataType::BOOLEAN;
3499 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN(pCastTarget, DATE) )
[ # # ]
3500 : 0 : nDataType = DataType::DATE;
3501 [ # # ]: 0 : else if ( pCastTarget->count() > 0 )
3502 : : {
3503 : 0 : const OSQLParseNode *pDataType = pCastTarget->getChild(0);
3504 [ # # ]: 0 : while (pDataType->count() > 0)
3505 : : {
3506 : 0 : pCastTarget = pDataType;
3507 : 0 : pDataType = pDataType->getChild(0);
3508 : : }
3509 [ # # ][ # # ]: 0 : if ( SQL_ISTOKEN (pDataType, TIME) )
[ # # ]
3510 : 0 : nDataType = DataType::TIME;
3511 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN (pDataType, TIMESTAMP) )
[ # # ]
3512 : 0 : nDataType = DataType::TIMESTAMP;
3513 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKENOR3 (pDataType, CHARACTER, CHAR, NCHAR) )
[ # # ][ # # ]
[ # # ]
3514 : 0 : nDataType = char_datatype(pCastTarget, 0);
3515 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN (pDataType, VARCHAR) )
[ # # ]
3516 : 0 : nDataType = DataType::VARCHAR;
3517 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN (pDataType, CLOB) )
[ # # ]
3518 : 0 : nDataType = DataType::CLOB;
3519 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN (pDataType, NATIONAL) )
[ # # ]
3520 : 0 : nDataType = char_datatype(pCastTarget, 1);
3521 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN (pDataType, BINARY) )
[ # # ]
3522 : : {
3523 [ # # ][ # # ]: 0 : if ( pCastTarget->count() > 2 && SQL_ISTOKEN(pCastTarget->getChild(1), LARGE) && SQL_ISTOKEN(pCastTarget->getChild(2), OBJECT) )
[ # # ][ # # ]
[ # # ][ # # ]
3524 : 0 : nDataType = DataType::BLOB;
3525 [ # # ][ # # ]: 0 : else if ( pCastTarget->count() > 1 && SQL_ISTOKEN(pCastTarget->getChild(1), VARYING) )
[ # # ][ # # ]
3526 : 0 : nDataType = DataType::VARBINARY;
3527 : : else
3528 : 0 : nDataType = DataType::BINARY;
3529 : : }
3530 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN (pDataType, VARBINARY) )
[ # # ]
3531 : 0 : nDataType = DataType::VARBINARY;
3532 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN (pDataType, BLOB) )
[ # # ]
3533 : 0 : nDataType = DataType::BLOB;
3534 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN (pDataType, NUMERIC) )
[ # # ]
3535 : 0 : nDataType = DataType::NUMERIC;
3536 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKENOR2 (pDataType, DECIMAL, DEC) )
[ # # ][ # # ]
3537 : 0 : nDataType = DataType::DECIMAL;
3538 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN (pDataType, FLOAT) )
[ # # ]
3539 : 0 : nDataType = DataType::FLOAT;
3540 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN (pDataType, DOUBLE) )
[ # # ]
3541 : 0 : nDataType = DataType::DOUBLE;
3542 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN (pDataType, TIME) )
[ # # ]
3543 : 0 : nDataType = DataType::TIME;
3544 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN (pDataType, TIMESTAMP) )
[ # # ]
3545 : 0 : nDataType = DataType::TIMESTAMP;
3546 [ # # ][ # # ]: 0 : else if ( SQL_ISTOKEN (pDataType, INTERVAL) )
[ # # ]
3547 : : // Not in DataType published constant (because not in JDBC...)
3548 : 0 : nDataType = DataType::VARCHAR;
3549 : : else
3550 : : OSL_FAIL("Failed to decode CAST target");
3551 : : }
3552 : : else
3553 : : OSL_FAIL("Could not decipher CAST target");
3554 : 0 : break;
3555 : : }
3556 : : default:
3557 : : OSL_FAIL("Unknown SQL RuleID");
3558 : 0 : break;
3559 : : }
3560 : 0 : break;
3561 : : default:
3562 : : OSL_FAIL("Unknown SQL Node Type");
3563 : 0 : break;
3564 : : }
3565 : :
3566 : 0 : aInfo->SetDataType(nDataType);
3567 : 0 : aInfo->SetFieldType(TAB_NORMAL_FIELD);
3568 : 0 : aInfo->SetField(sFunctionTerm);
3569 : 0 : aInfo->SetTabWindow(NULL);
3570 [ + - ][ + - ]: 42 : }
3571 : : // -----------------------------------------------------------------------------
3572 : :
3573 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|