24#include <sqlbison.hxx>
29#include <osl/diagnose.h>
39#include <com/sun/star/sdbc/DataType.hpp>
40#include <com/sun/star/container/XNameAccess.hpp>
41#include <com/sun/star/sdbc/ColumnValue.hpp>
46#include <core_resource.hxx>
55using namespace ::
dbaui;
70 const char C_AND[] =
" AND ";
71 const char C_OR[] =
" OR ";
73 bool InsertJoin(
const OQueryDesignView* _pView,
74 const ::connectivity::OSQLParseNode *pNode);
77 const ::connectivity::OSQLParseNode* pNode,
78 OJoinTableView::OTableWindowMap* pTabList );
81 OSelectionBrowseBox* _pSelectionBrw,
82 const ::connectivity::OSQLParseNode* pSelectRoot );
85 OSelectionBrowseBox* _pSelectionBrw,
86 const ::connectivity::OSQLParseNode* pSelectRoot,
90 OSelectionBrowseBox* _pSelectionBrw,
91 const ::connectivity::OSQLParseNode* pParseRoot );
93 SqlParseError AddFunctionCondition(OQueryDesignView
const * _pView,
94 OSelectionBrowseBox* _pSelectionBrw,
95 const ::connectivity::OSQLParseNode * pCondition,
96 const sal_uInt16 nLevel,
98 bool _bAddOrOnOneLine);
100 OUString quoteTableAlias(
bool _bQuote,
const OUString& _sAliasName, std::u16string_view _sQuote)
103 if ( _bQuote && !_sAliasName.isEmpty() )
105 sRet = ::dbtools::quoteName(_sQuote,_sAliasName) +
".";
109 OUString getTableRange(
const OQueryDesignView* _pView,const ::connectivity::OSQLParseNode* _pTableRef)
111 Reference< XConnection> xConnection =
static_cast<OQueryController&
>(_pView->getController()).
getConnection();
112 OUString sTableRange;
116 if ( sTableRange.isEmpty() )
117 _pTableRef->parseNodeToStr(sTableRange,xConnection,
nullptr,
false,
false);
123 OQueryTableView* pTableView =
static_cast<OQueryTableView*
>(_pView->getTableView());
124 OQueryTableConnection* pConn =
static_cast<OQueryTableConnection*
>( pTableView->GetTabConn(
static_cast<OTableWindow*
>(_aDragLeft->GetTabWindow()),
static_cast<OTableWindow*
>(_aDragRight->GetTabWindow()),
true));
128 auto xInfoData = std::make_shared<OQueryTableConnectionData>();
129 xInfoData->InitFromDrag(_aDragLeft, _aDragRight);
130 xInfoData->SetJoinType(_eJoinType);
134 xInfoData->ResetConnLines();
135 xInfoData->setNatural(_bNatural);
138 Reference<XNameAccess> xReferencedTableColumns(xInfoData->getReferencedTable()->getColumns());
139 Sequence< OUString>
aSeq = xInfoData->getReferencingTable()->getColumns()->getElementNames();
140 const OUString* pIter =
aSeq.getConstArray();
141 const OUString* pEnd = pIter +
aSeq.getLength();
142 for(;pIter != pEnd;++pIter)
144 if ( xReferencedTableColumns->hasByName(*pIter) )
145 xInfoData->AppendConnLine(*pIter,*pIter);
148 catch(
const Exception& )
157 pTableView->NotifyTabConnection( *aInfo );
161 OUString aSourceFieldName(_aDragLeft->GetField());
162 OUString aDestFieldName(_aDragRight->GetField());
164 if(pConn->GetSourceWin() == _aDragRight->GetTabWindow())
166 OUString aTmp(aSourceFieldName);
167 aSourceFieldName = aDestFieldName;
168 aDestFieldName = aTmp;
170 pConn->GetData()->AppendConnLine( aSourceFieldName,aDestFieldName);
171 pConn->UpdateLineList();
175 pConn->RecalcLines();
178 pConn->InvalidateConnection();
181 OUString ParseCondition( OQueryController& rController
182 ,const ::connectivity::OSQLParseNode* pCondition
183 ,
const OUString& _sDecimal
184 ,
const css::lang::Locale& _rLocale
185 ,sal_uInt32 _nStartIndex)
188 Reference< XConnection> xConnection = rController.getConnection();
189 if ( xConnection.is() )
191 sal_uInt32
nCount = pCondition->count();
192 for(sal_uInt32 i = _nStartIndex ;
i <
nCount ; ++
i)
193 pCondition->getChild(i)->parseNodeToPredicateStr(aCondition,
195 rController.getNumberFormatter(),
198 &rController.getParser().getContext());
202 SqlParseError FillOuterJoins(OQueryDesignView
const * _pView,
203 const ::connectivity::OSQLParseNode* pTableRefList)
206 sal_uInt32
nCount = pTableRefList->count();
208 for (sal_uInt32 i=0; !bError &&
i <
nCount; ++
i)
210 const ::connectivity::OSQLParseNode* pParseNode = pTableRefList->getChild(i);
211 const ::connectivity::OSQLParseNode* pJoinNode =
nullptr;
214 pJoinNode = pParseNode;
216 && pParseNode->count() == 4 )
217 pJoinNode = pParseNode->getChild(2);
221 if ( !InsertJoin(_pView,pJoinNode) )
235 const ::connectivity::OSQLParseNode* pColumnRef,
242 OUString aTableRange,aColumnName;
244 rParseIter.
getColumnRange( pColumnRef, aColumnName, aTableRange );
246 if ( !aTableRange.isEmpty() )
248 OQueryTableWindow* pSTW =
static_cast<OQueryTableView*
>(_pView->getTableView())->FindTable( aTableRange );
249 bErg = (pSTW && pSTW->ExistsField( aColumnName, _rDragInfo ) );
253 sal_uInt16 nCntAccount;
254 bErg =
static_cast<OQueryTableView*
>(_pView->getTableView())->FindTableFromField(aColumnName, _rDragInfo, nCntAccount);
256 bErg = _pView->HasFieldByAliasName(aColumnName, _rDragInfo);
261 OUString sError(
DBA_RES(STR_QRY_COLUMN_NOT_FOUND));
262 sError = sError.replaceFirst(
"$name$",aColumnName);
263 _pView->getController().appendError( sError );
267 Reference<XDatabaseMetaData> xMeta = _pView->getController().getConnection()->getMetaData();
268 if ( xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers() )
269 _pView->getController().appendError(
DBA_RES(STR_QRY_CHECK_CASESENSITIVE));
278 OUString BuildJoinCriteria(
const Reference< XConnection>& _xConnection,
280 const OQueryTableConnectionData* pData)
282 OUStringBuffer aCondition;
283 if ( _xConnection.is() )
287 const Reference< XDatabaseMetaData > xMetaData = _xConnection->getMetaData();
288 const OUString aQuote = xMetaData->getIdentifierQuoteString();
290 for (
auto const& lineData : *pLineDataList)
292 if(!aCondition.isEmpty())
293 aCondition.append(C_AND);
296 + ::dbtools::quoteName(aQuote, lineData->GetFieldName(
JTCS_FROM) )
298 + quoteTableAlias(
true,
pData->GetAliasName(
JTCS_TO),aQuote)
299 + ::dbtools::quoteName(aQuote, lineData->GetFieldName(
JTCS_TO) ));
304 OSL_FAIL(
"Failure while building Join criteria!");
308 return aCondition.makeStringAndClear();
316 void JoinCycle(
const Reference< XConnection>& _xConnection,
317 OQueryTableConnection* _pEntryConn,
318 const OQueryTableWindow* _pEntryTabTo,
321 OSL_ENSURE(_pEntryConn,
"TableConnection can not be null!");
323 OQueryTableConnectionData*
pData =
static_cast< OQueryTableConnectionData*
>(_pEntryConn->GetData().get());
324 if ( !(
pData->GetJoinType() !=
INNER_JOIN && _pEntryTabTo->ExistsAVisitedConn()) )
328 if(_rJoin.endsWith(
")"))
331 _rJoin = _rJoin.replaceAt(_rJoin.getLength()-1,1,
u" ");
333 _rJoin += C_AND + BuildJoinCriteria(_xConnection,&
pData->GetConnLineDataList(),pData);
336 _pEntryConn->SetVisited(
true);
338 OUString BuildTable(
const Reference< XConnection>& _xConnection,
339 const OQueryTableWindow* pEntryTab,
343 OUString aDBName(pEntryTab->GetComposedName());
345 if( _xConnection.is() )
349 Reference< XDatabaseMetaData > xMetaData = _xConnection->getMetaData();
352 ::dbtools::qualifiedNameComponents( xMetaData, aDBName,
sCatalog,
sSchema, sTable, ::dbtools::EComposeRule::InDataManipulation );
353 OUString aTableListStr = ::dbtools::composeTableNameForSelect( _xConnection,
sCatalog,
sSchema, sTable );
355 OUString aQuote = xMetaData->getIdentifierQuoteString();
358 aTableListStr +=
" ";
360 aTableListStr +=
"AS ";
361 aTableListStr += ::dbtools::quoteName( aQuote, pEntryTab->GetAliasName() );
363 aDBName = aTableListStr;
365 catch(
const SQLException&)
372 OUString BuildJoin(
const Reference< XConnection>& _xConnection,
374 std::u16string_view rRh,
375 const OQueryTableConnectionData* pData)
381 switch(
pData->GetJoinType())
384 aErg +=
" LEFT OUTER ";
387 aErg +=
" RIGHT OUTER ";
390 OSL_ENSURE(!
pData->isNatural(),
"OQueryDesignView::BuildJoin: This should not happen!");
394 OSL_ENSURE(
pData->isNatural(),
"OQueryDesignView::BuildJoin: This should not happen!");
398 aErg +=
" FULL OUTER ";
401 aErg += OUString::Concat(
"JOIN ") + rRh;
404 aErg +=
" ON " + BuildJoinCriteria(_xConnection,&
pData->GetConnLineDataList(),pData);
409 OUString BuildJoin(
const Reference< XConnection>& _xConnection,
410 const OQueryTableWindow* pLh,
411 const OQueryTableWindow* pRh,
412 const OQueryTableConnectionData* pData
416 return BuildJoin(_xConnection,BuildTable(_xConnection,pLh,bForce),BuildTable(_xConnection,pRh,bForce),pData);
418 OUString BuildJoin(
const Reference< XConnection>& _xConnection,
420 const OQueryTableWindow* pRh,
421 const OQueryTableConnectionData* pData
424 return BuildJoin(_xConnection,rLh,BuildTable(_xConnection,pRh),pData);
426 OUString BuildJoin(
const Reference< XConnection>& _xConnection,
427 const OQueryTableWindow* pLh,
429 const OQueryTableConnectionData* pData
438 OQueryTableConnectionData data(*pData);
439 switch (data.GetJoinType())
451 return BuildJoin(_xConnection, rRh, BuildTable(_xConnection,pLh), &data);
453 void addConnectionTableNames(
const Reference< XConnection>& _xConnection,
454 const OQueryTableConnection*
const pEntryConn,
455 std::set<OUString> &_rTableNames )
458 const OQueryTableWindow*
const pEntryTabFrom =
static_cast<OQueryTableWindow*
>(pEntryConn->GetSourceWin());
459 const OQueryTableWindow*
const pEntryTabTo =
static_cast<OQueryTableWindow*
>(pEntryConn->GetDestWin());
460 _rTableNames.insert(BuildTable(_xConnection,pEntryTabFrom));
461 _rTableNames.insert(BuildTable(_xConnection,pEntryTabTo));
463 void GetNextJoin(
const Reference< XConnection>& _xConnection,
464 OQueryTableConnection* pEntryConn,
465 OQueryTableWindow
const * pEntryTabTo,
467 std::set<OUString> &_rTableNames)
469 OQueryTableConnectionData* pEntryConnData =
static_cast<OQueryTableConnectionData*
>(pEntryConn->GetData().get());
470 if ( pEntryConnData->GetJoinType() ==
INNER_JOIN && !pEntryConnData->isNatural() )
475 addConnectionTableNames(_xConnection, pEntryConn, _rTableNames);
476 OQueryTableWindow* pEntryTabFrom =
static_cast<OQueryTableWindow*
>(pEntryConn->GetSourceWin());
477 aJoin = BuildJoin(_xConnection,pEntryTabFrom,pEntryTabTo,pEntryConnData);
479 else if(pEntryTabTo == pEntryConn->GetDestWin())
481 addConnectionTableNames(_xConnection, pEntryConn, _rTableNames);
482 aJoin = BuildJoin(_xConnection,aJoin,pEntryTabTo,pEntryConnData);
484 else if(pEntryTabTo == pEntryConn->GetSourceWin())
486 addConnectionTableNames(_xConnection, pEntryConn, _rTableNames);
487 aJoin = BuildJoin(_xConnection,pEntryTabTo,aJoin,pEntryConnData);
490 pEntryConn->SetVisited(
true);
493 const auto& rConnections = pEntryConn->GetParent()->getTableConnections();
495 for (
auto const& connection : rConnections)
497 OQueryTableConnection* pNext =
static_cast<OQueryTableConnection*
>(connection.get());
498 if(!pNext->IsVisited() && (pNext->GetSourceWin() == pEntryTabTo || pNext->GetDestWin() == pEntryTabTo))
500 OQueryTableWindow* pEntryTab = pNext->GetSourceWin() == pEntryTabTo ?
static_cast<OQueryTableWindow*
>(pNext->GetDestWin()) :
static_cast<OQueryTableWindow*
>(pNext->GetSourceWin());
502 JoinCycle(_xConnection,pNext,pEntryTab,aJoin);
503 if(!pNext->IsVisited())
504 GetNextJoin(_xConnection, pNext, pEntryTab, aJoin, _rTableNames);
513 OQueryTableWindow* pEntryTabFrom =
static_cast<OQueryTableWindow*
>(pEntryConn->GetSourceWin());
514 for (
auto const& connection : rConnections)
516 OQueryTableConnection* pNext =
static_cast<OQueryTableConnection*
>(connection.get());
517 if(!pNext->IsVisited() && (pNext->GetSourceWin() == pEntryTabFrom || pNext->GetDestWin() == pEntryTabFrom))
519 OQueryTableWindow* pEntryTab = pNext->GetSourceWin() == pEntryTabFrom ?
static_cast<OQueryTableWindow*
>(pNext->GetDestWin()) :
static_cast<OQueryTableWindow*
>(pNext->GetSourceWin());
521 JoinCycle(_xConnection,pNext,pEntryTab,aJoin);
522 if(!pNext->IsVisited())
523 GetNextJoin(_xConnection, pNext, pEntryTab, aJoin, _rTableNames);
527 SqlParseError InsertJoinConnection(
const OQueryDesignView* _pView,
528 const ::connectivity::OSQLParseNode *pNode,
530 const ::connectivity::OSQLParseNode *pLeftTable,
531 const ::connectivity::OSQLParseNode *pRightTable)
534 if (pNode->count() == 3 &&
538 eErrorCode = InsertJoinConnection(_pView,pNode->getChild(1), _eJoinType,pLeftTable,pRightTable);
540 else if (
SQL_ISRULEOR2(pNode,search_condition,boolean_term) &&
546 else if (
eOk == (eErrorCode = InsertJoinConnection(_pView,pNode->getChild(0), _eJoinType,pLeftTable,pRightTable)) )
547 eErrorCode = InsertJoinConnection(_pView,pNode->getChild(2), _eJoinType,pLeftTable,pRightTable);
549 else if (
SQL_ISRULE(pNode,comparison_predicate))
552 OSL_ENSURE(pNode->count() == 3,
"OQueryDesignView::InsertJoinConnection: Error in Parse Tree");
553 if (!(
SQL_ISRULE(pNode->getChild(0),column_ref) &&
555 pNode->getChild(1)->getNodeType() == SQLNodeType::Equal))
557 OUString sError(
DBA_RES(STR_QRY_JOIN_COLUMN_COMPARE));
558 _pView->getController().appendError( sError );
564 eErrorCode = FillDragInfo(_pView,pNode->getChild(0),aDragLeft);
565 if (
eOk != eErrorCode )
567 eErrorCode = FillDragInfo(_pView,pNode->getChild(2),aDragRight);
568 if (
eOk != eErrorCode )
573 OQueryTableWindow* pLeftWindow =
static_cast<OQueryTableView*
>(_pView->getTableView())->FindTable( getTableRange(_pView,pLeftTable->getByRule(OSQLParseNode::table_ref) ));
574 if ( pLeftWindow == aDragLeft->GetTabWindow() )
575 insertConnection(_pView,_eJoinType,aDragLeft,aDragRight);
577 insertConnection(_pView,_eJoinType,aDragRight,aDragLeft);
580 insertConnection(_pView,_eJoinType,aDragLeft,aDragRight);
586 bool GetInnerJoinCriteria(
const OQueryDesignView* _pView,
587 const ::connectivity::OSQLParseNode *pCondition)
589 return InsertJoinConnection(_pView,pCondition,
INNER_JOIN,
nullptr,
nullptr) !=
eOk;
591 OUString GenerateSelectList(
const OQueryDesignView* _pView,
595 Reference< XConnection> xConnection =
static_cast<OQueryController&
>(_pView->getController()).
getConnection();
596 if ( !xConnection.is() )
599 OUStringBuffer aTmpStr,aFieldListStr;
601 bool bAsterisk =
false;
603 for (
auto const& field : _rFieldList)
605 if ( field->IsVisible() )
607 if ( field->GetField().toChar() ==
'*' )
617 const Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
618 const OUString aQuote = xMetaData->getIdentifierQuoteString();
620 OJoinTableView::OTableWindowMap& rTabList = _pView->getTableView()->GetTabWinMap();
622 for (
auto const& field : _rFieldList)
624 OUString rFieldName = field->GetField();
625 if ( !rFieldName.isEmpty() && field->IsVisible() )
628 const OUString rAlias = field->GetAlias();
629 const OUString rFieldAlias = field->GetFieldAlias();
631 aTmpStr.append(quoteTableAlias((bAlias || bAsterisk),rAlias,aQuote));
635 if ( !field->isOtherFunction() )
639 for (
auto const& table : rTabList)
641 OQueryTableWindow* pTabWin =
static_cast<OQueryTableWindow*
>(
table.second.get());
643 if ( pTabWin->ExistsField( rFieldName, aInfo ) )
645 rFieldName = aInfo->GetField();
649 if ( ( rFieldName.toChar() !=
'*' ) && ( rFieldName.indexOf( aQuote ) == -1 ) )
651 OSL_ENSURE(!field->GetTable().isEmpty(),
"No table field name!");
652 aTmpStr.append(::dbtools::quoteName(aQuote, rFieldName));
655 aTmpStr.append(rFieldName);
658 aTmpStr.append(rFieldName);
660 if ( field->isAggregateFunction() )
662 OSL_ENSURE(!field->GetFunction().isEmpty(),
"Function name must not be empty! ;-(");
663 OUStringBuffer aTmpStr2( field->GetFunction() +
"(" + aTmpStr +
")");
667 if (!rFieldAlias.isEmpty() &&
668 (rFieldName.toChar() !=
'*' ||
669 field->isNumericOrAggregateFunction() ||
670 field->isOtherFunction()))
672 aTmpStr.append(
" AS " + ::dbtools::quoteName(aQuote, rFieldAlias));
674 aFieldListStr.append(aTmpStr);
675 aTmpStr.setLength(0);
676 aFieldListStr.append(
", ");
679 if(!aFieldListStr.isEmpty())
680 aFieldListStr.setLength(aFieldListStr.getLength()-2);
684 OSL_FAIL(
"Failure while building select list!");
686 return aFieldListStr.makeStringAndClear();
688 bool GenerateCriterias( OQueryDesignView
const * _pView,
689 OUStringBuffer& rRetStr,
690 OUStringBuffer& rHavingStr,
694 Reference< XConnection> xConnection =
static_cast<OQueryController&
>(_pView->getController()).
getConnection();
695 if(!xConnection.is())
698 OUString aFieldName,aCriteria,aWhereStr,aHavingStr,aWork;
700 sal_uInt16 nMaxCriteria = 0;
701 for (
auto const& field : _rFieldList)
703 nMaxCriteria = std::max<sal_uInt16>(nMaxCriteria,
static_cast<sal_uInt16
>(field->GetCriteria().size()));
707 const Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
708 const OUString aQuote = xMetaData->getIdentifierQuoteString();
709 const IParseContext& rContext =
static_cast<OQueryController&
>(_pView->getController()).getParser().getContext();
711 bool bCritsOnAsteriskWarning =
false;
713 for (sal_uInt16 i=0 ;
i < nMaxCriteria ;
i++)
718 for (
auto const& field : _rFieldList)
720 aFieldName = field->GetField();
722 if (aFieldName.isEmpty())
724 aCriteria = field->GetCriteria( i );
725 if ( !aCriteria.isEmpty() )
728 if ( aFieldName.toChar() ==
'*' && field->isNoneFunction() )
731 if (!bCritsOnAsteriskWarning)
734 VclMessageType::Warning, VclButtonsType::Ok,
735 DBA_RES(STR_QRY_CRITERIA_ON_ASTERISK)));
738 bCritsOnAsteriskWarning =
true;
741 aWork = quoteTableAlias(bMulti,field->GetAlias(),aQuote);
746 aWork += ::dbtools::quoteName(aQuote, aFieldName);
748 if ( field->isAggregateFunction() || field->IsGroupBy() )
750 if (aHavingStr.isEmpty())
755 if ( field->isAggregateFunction() )
757 OSL_ENSURE(!field->GetFunction().isEmpty(),
"No function name for aggregate given!");
758 aHavingStr += field->GetFunction() +
"(" + aWork +
")";
764 Reference<XPropertySet>
xColumn;
765 std::unique_ptr< ::connectivity::OSQLParseNode> pParseNode(_pView->getPredicateTreeFromEntry(field,aCriteria,aErrorMsg,xColumn));
768 if (bMulti && !(field->isOtherFunction() || (aFieldName.toChar() ==
'*')))
769 pParseNode->replaceNodeValue(field->GetAlias(),aFieldName);
770 OUString sHavingStr = aHavingStr;
772 sal_uInt32
nCount = pParseNode->count();
773 for( sal_uInt32 node = 1 ; node <
nCount ; ++node)
774 pParseNode->getChild(node)->parseNodeToStr( sHavingStr,
778 !field->isOtherFunction());
779 aHavingStr = sHavingStr;
782 aHavingStr += aCriteria;
786 if ( aWhereStr.isEmpty() )
794 Reference<XPropertySet>
xColumn;
795 std::unique_ptr< ::connectivity::OSQLParseNode> pParseNode( _pView->getPredicateTreeFromEntry(field,aCriteria,aErrorMsg,xColumn));
798 if (bMulti && !(field->isOtherFunction() || (aFieldName.toChar() ==
'*')))
799 pParseNode->replaceNodeValue(field->GetAlias(),aFieldName);
800 OUString aWhere = aWhereStr;
801 pParseNode->parseNodeToStr( aWhere,
805 !field->isOtherFunction() );
810 aWhereStr += aWork +
"=" + aCriteria;
815 else if ( !i && field->isCondition() )
817 if (aWhereStr.isEmpty())
821 aWhereStr += field->GetField();
824 if (!aWhereStr.isEmpty())
827 if (!rRetStr.isEmpty())
828 rRetStr.append(C_OR);
831 rRetStr.append(aWhereStr);
833 if (!aHavingStr.isEmpty())
836 if (!rHavingStr.isEmpty())
837 rHavingStr.append(C_OR);
839 rHavingStr.append(
'(');
840 rHavingStr.append(aHavingStr);
844 if (!rRetStr.isEmpty())
846 if (!rHavingStr.isEmpty())
847 rHavingStr.append(
')');
851 OSL_FAIL(
"Failure while building where clause!");
855 SqlParseError GenerateOrder( OQueryDesignView
const * _pView,
860 const OQueryController& rController =
static_cast<OQueryController&
>(_pView->getController());
861 const Reference< XConnection>& xConnection = rController.getConnection();
862 if ( !xConnection.is() )
867 OUString aColumnName;
871 const bool bColumnAliasInOrderBy = rController.getSdbMetaData().supportsColumnAliasInOrderBy();
872 Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
873 OUString aQuote = xMetaData->getIdentifierQuoteString();
875 bool bCritsOnAsteriskWarning =
false;
876 for (
auto const& field : _rFieldList)
883 aColumnName = field->GetField();
884 if(aColumnName.toChar() ==
'*')
887 if (!bCritsOnAsteriskWarning)
890 VclMessageType::Warning, VclButtonsType::Ok,
891 DBA_RES(STR_QRY_ORDERBY_ON_ASTERISK)));
894 bCritsOnAsteriskWarning =
true;
898 if ( bColumnAliasInOrderBy && !field->GetFieldAlias().isEmpty() )
900 aWorkStr += ::dbtools::quoteName(aQuote, field->GetFieldAlias());
902 else if ( field->isNumericOrAggregateFunction() )
904 OSL_ENSURE(!field->GetFunction().isEmpty(),
"Function name cannot be empty! ;-(");
905 aWorkStr += field->GetFunction() +
"("
907 bMulti, field->GetAlias(), aQuote);
909 if ( field->isNumeric() )
910 aWorkStr += aColumnName;
912 aWorkStr += ::dbtools::quoteName(aQuote, aColumnName);
916 else if ( field->isOtherFunction() )
918 aWorkStr += aColumnName;
922 aWorkStr += quoteTableAlias(bMulti,field->GetAlias(),aQuote) + ::dbtools::quoteName(aQuote, aColumnName);
924 aWorkStr += OUString::Concat(
" ") +
o3tl::getToken( u
";ASC;DESC",
static_cast<sal_uInt16
>(eOrder),
';' ) +
",";
933 if ( !aWorkStr.isEmpty() )
935 const sal_Int32 nMaxOrder = xMetaData->getMaxColumnsInOrderBy();
940 _rsRet =
" ORDER BY " + aWorkStr;
946 OSL_FAIL(
"Failure while building group by!");
952 void GenerateInnerJoinCriterias(
const Reference< XConnection>& _xConnection,
953 OUString& _rJoinCrit,
956 for (
auto const& connection : _rConnList)
958 const OQueryTableConnection* pEntryConn =
static_cast<const OQueryTableConnection*
>(connection.get());
959 OQueryTableConnectionData* pEntryConnData =
static_cast<OQueryTableConnectionData*
>(pEntryConn->GetData().get());
960 if ( pEntryConnData->GetJoinType() ==
INNER_JOIN && !pEntryConnData->isNatural() )
962 if(!_rJoinCrit.isEmpty())
964 _rJoinCrit += BuildJoinCriteria(_xConnection,&pEntryConnData->GetConnLineDataList(),pEntryConnData);
968 void searchAndAppendName(
const Reference< XConnection>& _xConnection,
969 const OQueryTableWindow* _pTableWindow,
970 std::set<OUString>& _rTableNames,
971 OUString& _rsTableListStr
974 OUString sTabName(BuildTable(_xConnection,_pTableWindow));
976 if(_rTableNames.insert(sTabName).second)
978 _rsTableListStr += sTabName +
",";
981 OUString GenerateFromClause(
const Reference< XConnection>& _xConnection,
982 const OQueryTableView::OTableWindowMap* pTabList,
987 OUString aTableListStr;
989 std::set<OUString> aTableNames;
992 if(!rConnList.empty())
994 std::map<OTableWindow*,sal_Int32> aConnectionCount;
995 auto aEnd = rConnList.end();
996 for (
auto const& connection : rConnList)
998 static_cast<OQueryTableConnection*
>(connection.get())->SetVisited(
false);
999 ++aConnectionCount[connection->GetSourceWin()];
1000 ++aConnectionCount[connection->GetDestWin()];
1002 std::multimap<sal_Int32 , OTableWindow*> aMulti;
1003 for (
auto const& elem : aConnectionCount)
1005 aMulti.emplace(elem.second,elem.first);
1009 std::multimap<sal_Int32 , OTableWindow*>::const_reverse_iterator aRIter = aMulti.rbegin();
1010 std::multimap<sal_Int32 , OTableWindow*>::const_reverse_iterator aREnd = aMulti.rend();
1011 for(;aRIter != aREnd;++aRIter)
1013 auto aConIter = aRIter->second->getTableView()->getTableConnections(aRIter->second);
1014 for(;aConIter != aEnd;++aConIter)
1016 OQueryTableConnection* pEntryConn =
static_cast<OQueryTableConnection*
>((*aConIter).get());
1017 if(!pEntryConn->IsVisited() && pEntryConn->GetSourceWin() == aRIter->second )
1020 GetNextJoin(_xConnection,
1022 static_cast<OQueryTableWindow*
>(pEntryConn->GetDestWin()),
1026 if(!aJoin.isEmpty())
1029 switch(
static_cast<OQueryTableConnectionData*
>(pEntryConn->GetData().get())->GetJoinType())
1048 aTableListStr +=
aStr;
1059 for (
auto const& connection : rConnList)
1061 OQueryTableConnection* pEntryConn =
static_cast<OQueryTableConnection*
>(connection.get());
1062 if(!pEntryConn->IsVisited())
1064 searchAndAppendName(_xConnection,
1065 static_cast<OQueryTableWindow*
>(pEntryConn->GetSourceWin()),
1069 searchAndAppendName(_xConnection,
1070 static_cast<OQueryTableWindow*
>(pEntryConn->GetDestWin()),
1077 for (
auto const& table : *pTabList)
1079 const OQueryTableWindow* pEntryTab =
static_cast<const OQueryTableWindow*
>(
table.second.get());
1080 if(!pEntryTab->ExistsAConn())
1082 aTableListStr += BuildTable(_xConnection,pEntryTab) +
",";
1086 if(!aTableListStr.isEmpty())
1087 aTableListStr = aTableListStr.replaceAt(aTableListStr.getLength()-1,1, u
"" );
1088 return aTableListStr;
1090 OUString GenerateGroupBy(
const OQueryDesignView* _pView,
OTableFields& _rFieldList,
bool bMulti )
1092 OQueryController& rController =
static_cast<OQueryController&
>(_pView->getController());
1093 const Reference< XConnection> xConnection = rController.getConnection();
1094 if(!xConnection.is())
1097 std::map< OUString,bool> aGroupByNames;
1099 OUString aGroupByStr;
1102 const Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
1103 const OUString aQuote = xMetaData->getIdentifierQuoteString();
1105 for (
auto const& field : _rFieldList)
1107 if ( field->IsGroupBy() )
1109 OSL_ENSURE(!field->GetField().isEmpty(),
"No Field Name available!;-(");
1110 OUString sGroupByPart = quoteTableAlias(bMulti,field->GetAlias(),aQuote);
1113 if ( field->isNoneFunction() )
1115 sGroupByPart += ::dbtools::quoteName(aQuote, field->GetField());
1119 OUString aTmp = field->GetField();
1121 Reference<XPropertySet>
xColumn;
1122 std::unique_ptr< ::connectivity::OSQLParseNode> pParseNode(_pView->getPredicateTreeFromEntry(field,aTmp,aErrorMsg,xColumn));
1126 pParseNode->getChild(0)->parseNodeToStr( sGroupBy,
1128 &rController.getParser().getContext(),
1130 !field->isOtherFunction());
1131 sGroupByPart += sGroupBy;
1134 sGroupByPart += field->GetField();
1136 if ( aGroupByNames.find(sGroupByPart) == aGroupByNames.end() )
1138 aGroupByNames.emplace(sGroupByPart,
true);
1139 aGroupByStr += sGroupByPart +
",";
1143 if ( !aGroupByStr.isEmpty() )
1145 aGroupByStr = aGroupByStr.replaceAt(aGroupByStr.getLength()-1,1, u
" " );
1146 OUString aGroupByStr2 =
" GROUP BY " + aGroupByStr;
1147 aGroupByStr = aGroupByStr2;
1150 catch(SQLException&)
1152 OSL_FAIL(
"Failure while building group by!");
1157 OSelectionBrowseBox* _pSelectionBrw,
1158 const ::connectivity::OSQLParseNode * pCondition,
1159 sal_uInt16& nLevel ,
1160 bool bHaving =
false,
1161 bool bAddOrOnOneLine =
false);
1162 SqlParseError GetSelectionCriteria( OQueryDesignView* _pView,
1163 OSelectionBrowseBox* _pSelectionBrw,
1164 const ::connectivity::OSQLParseNode* pNode,
1165 sal_uInt16& rLevel )
1167 if (!pNode || !
SQL_ISRULE(pNode, select_statement))
1171 pNode = pNode->getChild(3)->getChild(1);
1173 if (!pNode || pNode->isLeaf())
1191 OSQLParseNode::compress(pNodeTmp);
1195 GetInnerJoinCriteria(_pView,pNodeTmp);
1201 eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pNodeTmp, rLevel);
1206 OSelectionBrowseBox* _pSelectionBrw,
1207 const ::connectivity::OSQLParseNode * pCondition,
1210 bool bAddOrOnOneLine);
1211 SqlParseError ComparisonPredicate(OQueryDesignView
const * _pView,
1212 OSelectionBrowseBox* _pSelectionBrw,
1213 const ::connectivity::OSQLParseNode * pCondition,
1214 const sal_uInt16 nLevel,
1216 bool bAddOrOnOneLine);
1218 OSelectionBrowseBox* _pSelectionBrw,
1219 const ::connectivity::OSQLParseNode * pCondition,
1220 sal_uInt16& nLevel ,
1222 bool bAddOrOnOneLine)
1227 if (pCondition->count() == 3 &&
1231 eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pCondition->getChild(1),nLevel,bHaving,bAddOrOnOneLine);
1235 else if (
SQL_ISRULE(pCondition,search_condition))
1237 for (
int i = 0;
i < 3 && eErrorCode ==
eOk ;
i+=2)
1239 const ::connectivity::OSQLParseNode* pChild = pCondition->getChild(i);
1241 eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pChild,nLevel,bHaving,bAddOrOnOneLine);
1244 eErrorCode = GetANDCriteria(_pView,_pSelectionBrw,pChild, nLevel,bHaving, i != 0 && bAddOrOnOneLine);
1245 if ( !bAddOrOnOneLine)
1251 eErrorCode = GetANDCriteria( _pView,_pSelectionBrw,pCondition, nLevel, bHaving,bAddOrOnOneLine );
1259 for (
size_t i = 0; bRet &&
i < _pCondition->count(); ++
i)
1261 const ::connectivity::OSQLParseNode* pChild = _pCondition->
getChild(i);
1262 if ( pChild->isToken() )
1264 else if (
SQL_ISRULE(pChild,search_condition) )
1265 bRet = CheckOrCriteria(pChild,pFirstColumnRef);
1270 if ( pFirstColumnRef && pSecondColumnRef )
1271 bRet = *pFirstColumnRef == *pSecondColumnRef;
1272 else if ( !pFirstColumnRef )
1273 pFirstColumnRef = pSecondColumnRef;
1279 OSelectionBrowseBox* _pSelectionBrw,
1280 const ::connectivity::OSQLParseNode * pCondition,
1283 bool bAddOrOnOneLine)
1285 const css::lang::Locale aLocale = _pView->getLocale();
1286 const OUString sDecimal = _pView->getDecimalSeparator();
1289 OQueryController& rController =
static_cast<OQueryController&
>(_pView->getController());
1296 const ::connectivity::OSQLParseNode* pSearchCondition = pCondition->getChild(1);
1297 bool bMustAddOrOnOneLine = CheckOrCriteria(pSearchCondition,
nullptr);
1298 if (
SQL_ISRULE( pSearchCondition, search_condition) )
1300 _pSelectionBrw->DuplicateConditionLevel( nLevel);
1301 eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pSearchCondition->getChild(0), nLevel,bHaving,bMustAddOrOnOneLine );
1302 if ( eErrorCode ==
eOk )
1305 eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pSearchCondition->getChild(2), nLevel,bHaving,bMustAddOrOnOneLine );
1309 eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pSearchCondition, nLevel,bHaving,bMustAddOrOnOneLine );
1312 else if (
SQL_ISRULE(pCondition,boolean_term) )
1314 OSL_ENSURE(pCondition->count() == 3,
"Illegal definition of boolean_term");
1315 eErrorCode = GetANDCriteria(_pView,_pSelectionBrw,pCondition->getChild(0), nLevel,bHaving,bAddOrOnOneLine );
1316 if ( eErrorCode ==
eOk )
1317 eErrorCode = GetANDCriteria(_pView,_pSelectionBrw,pCondition->getChild(2), nLevel,bHaving,bAddOrOnOneLine );
1319 else if (
SQL_ISRULE( pCondition, comparison_predicate))
1321 eErrorCode = ComparisonPredicate(_pView,_pSelectionBrw,pCondition,nLevel,bHaving,bAddOrOnOneLine);
1323 else if(
SQL_ISRULE(pCondition,like_predicate) )
1325 const ::connectivity::OSQLParseNode* pValueExp = pCondition->getChild(0);
1328 OUString aCondition;
1329 Reference< XConnection> xConnection = rController.getConnection();
1330 if ( xConnection.is() )
1332 OUString aColumnName;
1334 pCondition->parseNodeToPredicateStr(aCondition,
1336 rController.getNumberFormatter(),
1339 &rController.getParser().getContext());
1341 pValueExp->parseNodeToPredicateStr( aColumnName,
1343 rController.getNumberFormatter(),
1346 &rController.getParser().getContext());
1349 aCondition = aCondition.copy(aColumnName.getLength());
1350 aCondition = aCondition.trim();
1354 if (
eOk == ( eErrorCode = FillDragInfo(_pView,pValueExp,aDragLeft) ))
1357 aDragLeft->SetGroupBy(
true);
1358 _pSelectionBrw->AddCondition(aDragLeft, aCondition, nLevel,bAddOrOnOneLine);
1361 else if(
SQL_ISRULEOR3(pValueExp, general_set_fct, set_fct_spec, position_exp) ||
1362 SQL_ISRULEOR3(pValueExp, extract_exp, fold, char_substring_fct) ||
1365 AddFunctionCondition( _pView,
1375 OUString sError(
DBA_RES(STR_QRY_LIKE_LEFT_NO_COLUMN));
1376 _pView->getController().appendError( sError );
1379 else if(
SQL_ISRULEOR2(pCondition,test_for_null,in_predicate)
1380 ||
SQL_ISRULEOR2(pCondition,all_or_any_predicate,between_predicate))
1382 if (
SQL_ISRULEOR2(pCondition->getChild(0), set_fct_spec , general_set_fct ) )
1384 AddFunctionCondition( _pView,
1391 else if (
SQL_ISRULE(pCondition->getChild(0), column_ref ) )
1394 OUString sCondition = ParseCondition(rController,pCondition,sDecimal,aLocale,1);
1396 if (
eOk == ( eErrorCode = FillDragInfo(_pView,pCondition->getChild(0),aDragLeft)) )
1399 aDragLeft->SetGroupBy(
true);
1400 _pSelectionBrw->AddCondition(aDragLeft, sCondition, nLevel,bAddOrOnOneLine);
1406 OUString sCondition = ParseCondition(rController,pCondition,sDecimal,aLocale,1);
1407 Reference< XConnection> xConnection = rController.getConnection();
1410 pCondition->getChild(0)->parseNodeToPredicateStr(
sName,
1412 rController.getNumberFormatter(),
1415 &rController.getParser().getContext());
1418 aDragLeft->SetField(
sName);
1422 aDragLeft->SetGroupBy(
true);
1423 _pSelectionBrw->AddCondition(aDragLeft, sCondition, nLevel,bAddOrOnOneLine);
1426 else if(
SQL_ISRULEOR2(pCondition,existence_test,unique_test) )
1429 OUString aCondition = ParseCondition(rController,pCondition,sDecimal,aLocale,0);
1432 aDragLeft->SetField(aCondition);
1435 eErrorCode = _pSelectionBrw->InsertField(aDragLeft,BROWSER_INVALIDID,
false).is() ?
eOk :
eTooManyColumns;
1442 SqlParseError AddFunctionCondition(OQueryDesignView
const * _pView,
1443 OSelectionBrowseBox* _pSelectionBrw,
1444 const ::connectivity::OSQLParseNode * pCondition,
1445 const sal_uInt16 nLevel,
1447 bool bAddOrOnOneLine)
1450 OQueryController& rController =
static_cast<OQueryController&
>(_pView->getController());
1452 OSQLParseNode* pFunction = pCondition->getChild(0);
1454 OSL_ENSURE(
SQL_ISRULEOR3(pFunction, general_set_fct, set_fct_spec, position_exp) ||
1455 SQL_ISRULEOR3(pFunction, extract_exp, fold, char_substring_fct) ||
1459 Reference< XConnection> xConnection = rController.getConnection();
1460 if(xConnection.is())
1462 OUString aCondition;
1463 OUString aColumnName;
1465 pCondition->parseNodeToPredicateStr(aCondition,
1467 rController.getNumberFormatter(),
1468 _pView->getLocale(),
1469 _pView->getDecimalSeparator(),
1470 &rController.getParser().getContext());
1472 pFunction->parseNodeToStr( aColumnName,
1474 &rController.getParser().getContext(),
1477 aCondition = aCondition.copy(aColumnName.getLength());
1478 aCondition = aCondition.trim();
1479 if ( aCondition.startsWith(
"=") )
1480 aCondition = aCondition.copy(1);
1482 if (
SQL_ISRULE(pFunction, general_set_fct ) )
1485 OSQLParseNode* pParamNode = pFunction->getChild(pFunction->count()-2);
1486 if ( pParamNode && pParamNode->getTokenValue().toChar() ==
'*' )
1488 OJoinTableView::OTableWindowMap& rTabList = _pView->getTableView()->GetTabWinMap();
1489 for (
auto const& table : rTabList)
1491 OQueryTableWindow* pTabWin =
static_cast<OQueryTableWindow*
>(
table.second.get());
1492 if (pTabWin->ExistsField(
"*", aDragLeft ))
1494 aDragLeft->SetAlias(OUString());
1495 aDragLeft->SetTable(OUString());
1500 else if (pParamNode)
1502 eErrorCode = FillDragInfo(_pView,pParamNode,aDragLeft);
1503 if (
eOk != eErrorCode &&
SQL_ISRULE(pParamNode,num_value_exp))
1505 OUString sParameterValue;
1506 pParamNode->parseNodeToStr( sParameterValue,
1508 &rController.getParser().getContext());
1510 aDragLeft->SetField(sParameterValue);
1514 aDragLeft->SetFunctionType(nFunctionType);
1516 aDragLeft->SetGroupBy(
true);
1517 aDragLeft->SetFunction(aColumnName.getToken(0,
'('));
1522 aDragLeft->SetField(aColumnName);
1524 aDragLeft->SetGroupBy(
true);
1527 _pSelectionBrw->AddCondition(aDragLeft, aCondition, nLevel,bAddOrOnOneLine);
1532 SqlParseError ComparisonPredicate(OQueryDesignView
const * _pView,
1533 OSelectionBrowseBox* _pSelectionBrw,
1534 const ::connectivity::OSQLParseNode * pCondition,
1535 const sal_uInt16 nLevel,
1537 ,
bool bAddOrOnOneLine)
1540 OQueryController& rController =
static_cast<OQueryController&
>(_pView->getController());
1542 OSL_ENSURE(
SQL_ISRULE( pCondition, comparison_predicate),
"ComparisonPredicate: pCondition is not a Comparison Predicate");
1543 if (
SQL_ISRULE(pCondition->getChild(0), column_ref )
1544 ||
SQL_ISRULE(pCondition->getChild(pCondition->count()-1), column_ref) )
1546 OUString aCondition;
1549 if (
SQL_ISRULE(pCondition->getChild(0), column_ref ) &&
SQL_ISRULE(pCondition->getChild(pCondition->count()-1), column_ref ) )
1552 eErrorCode = FillDragInfo(_pView,pCondition->getChild(0),aDragLeft);
1553 if (
eOk != eErrorCode)
1555 eErrorCode = FillDragInfo(_pView,pCondition->getChild(2),aDragRight);
1556 if (
eOk != eErrorCode)
1559 OQueryTableConnection* pConn =
static_cast<OQueryTableConnection*
>(
1560 _pView->getTableView()->GetTabConn(
static_cast<OQueryTableWindow*
>(aDragLeft->GetTabWindow()),
1561 static_cast<OQueryTableWindow*
>(aDragRight->GetTabWindow()),
1566 for (
auto const& lineData : rLineDataList)
1568 if(lineData->GetSourceFieldName() == aDragLeft->GetField() ||
1569 lineData->GetDestFieldName() == aDragLeft->GetField() )
1575 sal_uInt32
nPos = 0;
1576 if(
SQL_ISRULE(pCondition->getChild(0), column_ref ))
1582 if (pCondition->getChild(i)->getNodeType() == SQLNodeType::Equal)
1586 aCondition = ParseCondition(rController
1588 ,_pView->getDecimalSeparator()
1589 ,_pView->getLocale()
1592 else if(
SQL_ISRULE(pCondition->getChild(pCondition->count()-1), column_ref ) )
1594 nPos = pCondition->count()-1;
1596 sal_Int32
i =
static_cast<sal_Int32
>(pCondition->count() - 2);
1597 switch (pCondition->getChild(i)->getNodeType())
1599 case SQLNodeType::Equal:
1603 case SQLNodeType::Less:
1608 case SQLNodeType::LessEq:
1613 case SQLNodeType::Great:
1618 case SQLNodeType::GreatEq:
1628 Reference< XConnection> xConnection = rController.getConnection();
1629 if(xConnection.is())
1632 pCondition->getChild(i)->parseNodeToPredicateStr(aCondition,
1634 rController.getNumberFormatter(),
1635 _pView->getLocale(),
1636 _pView->getDecimalSeparator(),
1637 &rController.getParser().getContext());
1642 if(
eOk == ( eErrorCode = FillDragInfo(_pView,pCondition->getChild(nPos),aDragLeft)))
1645 aDragLeft->SetGroupBy(
true);
1646 _pSelectionBrw->AddCondition(aDragLeft, aCondition, nLevel,bAddOrOnOneLine);
1649 else if(
SQL_ISRULEOR2(pCondition->getChild(0), set_fct_spec , general_set_fct ) )
1651 AddFunctionCondition( _pView,
1660 OUString
aName,aCondition;
1663 Reference< XConnection> xConnection = rController.getConnection();
1664 if(xConnection.is())
1670 &rController.getParser().getContext(),
1673 aCondition = pCondition->getChild(1)->getTokenValue();
1676 rController.getNumberFormatter(),
1677 _pView->getLocale(),
1678 _pView->getDecimalSeparator(),
1679 &rController.getParser().getContext());
1683 aDragLeft->SetField(aName);
1686 _pSelectionBrw->AddCondition(aDragLeft, aCondition, nLevel,bAddOrOnOneLine);
1691 OQueryTableWindow* lcl_findColumnInTables(
const OUString& _rColumName,
const OJoinTableView::OTableWindowMap& _rTabList,
OTableFieldDescRef const & _rInfo )
1693 for (
auto const& table : _rTabList)
1695 OQueryTableWindow* pTabWin =
static_cast< OQueryTableWindow*
>(
table.second.get() );
1696 if ( pTabWin && pTabWin->ExistsField( _rColumName, _rInfo ) )
1702 void InsertColumnRef(
const OQueryDesignView* _pView,
1703 const ::connectivity::OSQLParseNode * pColumnRef,
1704 OUString& aColumnName,
1705 const OUString& aColumnAlias,
1706 OUString& aTableRange,
1708 OJoinTableView::OTableWindowMap
const * pTabList)
1713 rParseIter.
getColumnRange( pColumnRef, aColumnName, aTableRange );
1716 OSL_ENSURE(!aColumnName.isEmpty(),
"Column name must not be empty");
1717 if (aTableRange.isEmpty())
1720 bFound =
nullptr != lcl_findColumnInTables( aColumnName, *pTabList, _raInfo );
1721 if ( bFound && ( aColumnName.toChar() !=
'*' ) )
1722 _raInfo->SetFieldAlias(aColumnAlias);
1727 OQueryTableWindow* pTabWin =
static_cast<OQueryTableView*
>(_pView->getTableView())->FindTable(aTableRange);
1729 if (pTabWin && pTabWin->ExistsField(aColumnName, _raInfo))
1731 if(aColumnName.toChar() !=
'*')
1732 _raInfo->SetFieldAlias(aColumnAlias);
1738 _raInfo->SetTable(OUString());
1739 _raInfo->SetAlias(OUString());
1740 _raInfo->SetField(aColumnName);
1741 _raInfo->SetFieldAlias(aColumnAlias);
1745 bool checkJoinConditions(
const OQueryDesignView* _pView,
1746 const ::connectivity::OSQLParseNode* _pNode )
1748 const ::connectivity::OSQLParseNode* pJoinNode =
nullptr;
1753 && _pNode->count() == 3
1756 pJoinNode = _pNode->getChild(1);
1757 else if (! (
SQL_ISRULE(_pNode, table_ref) && _pNode->count() == 2) )
1760 if (pJoinNode && !InsertJoin(_pView,pJoinNode))
1764 bool InsertJoin(
const OQueryDesignView* _pView,
1765 const ::connectivity::OSQLParseNode *pNode)
1768 "OQueryDesignView::InsertJoin: Error in the Parse Tree");
1771 return InsertJoin(_pView,pNode->getChild(1));
1774 const ::connectivity::OSQLParseNode* pRightTableRef = pNode->getChild(3);
1776 pRightTableRef = pNode->getChild(4);
1778 if ( !checkJoinConditions(_pView,pNode->getChild(0)) || !checkJoinConditions(_pView,pRightTableRef))
1784 bool bNatural =
false;
1801 pJoinType = pJoinType->
getChild(0);
1810 if (
SQL_ISRULE(pNode->getChild(4),join_condition) )
1812 if ( InsertJoinConnection(_pView,pNode->getChild(4)->getChild(1), eJoinType,pNode->getChild(0),pRightTableRef) !=
eOk )
1819 pRightTableRef = pNode->getChild(pNode->count() - 1);
1827 OQueryTableWindow* pLeftWindow =
static_cast<OQueryTableView*
>(_pView->getTableView())->FindTable( getTableRange(_pView,pNode->getChild(0)) );
1828 OQueryTableWindow* pRightWindow =
static_cast<OQueryTableView*
>(_pView->getTableView())->FindTable( getTableRange(_pView,pRightTableRef) );
1829 OSL_ENSURE(pLeftWindow && pRightWindow,
"Table Windows could not be found!");
1830 if ( !pLeftWindow || !pRightWindow )
1834 aDragLeft->SetTabWindow(pLeftWindow);
1835 aDragLeft->SetTable(pLeftWindow->GetTableName());
1836 aDragLeft->SetAlias(pLeftWindow->GetAliasName());
1839 aDragRight->SetTabWindow(pRightWindow);
1840 aDragRight->SetTable(pRightWindow->GetTableName());
1841 aDragRight->SetAlias(pRightWindow->GetAliasName());
1843 insertConnection(_pView,eJoinType,aDragLeft,aDragRight,bNatural);
1847 void insertUnUsedFields(OQueryDesignView
const * _pView,OSelectionBrowseBox* _pSelectionBrw)
1850 OQueryController& rController =
static_cast<OQueryController&
>(_pView->getController());
1851 OTableFields& rUnUsedFields = rController.getUnUsedFields();
1852 for (
auto & unusedField : rUnUsedFields)
1853 if(_pSelectionBrw->InsertField(unusedField,BROWSER_INVALIDID,
false,
false).is())
1854 unusedField =
nullptr;
1858 SqlParseError InitFromParseNodeImpl(OQueryDesignView* _pView,OSelectionBrowseBox* _pSelectionBrw)
1862 OQueryController& rController =
static_cast<OQueryController&
>(_pView->getController());
1864 _pSelectionBrw->PreFill();
1865 _pSelectionBrw->SetReadOnly(rController.isReadOnly());
1866 _pSelectionBrw->Fill();
1869 const ::connectivity::OSQLParseNode* pParseTree = aIterator.
getParseTree();
1876 insertUnUsedFields(_pView,_pSelectionBrw);
1880 if ( !rController.isEscapeProcessing() )
1886 if ( !(
SQL_ISRULE( pParseTree, select_statement ) ) )
1892 const OSQLParseNode* pTableExp = pParseTree->getChild(3);
1893 if ( pTableExp->getChild(7)->count() > 0 || pTableExp->getChild(8)->count() > 0)
1899 Reference< XConnection> xConnection = rController.getConnection();
1900 if ( !xConnection.is() )
1902 OSL_FAIL(
"InitFromParseNodeImpl: no connection? no connection!" );
1910 Reference< XDatabaseMetaData > xMetaData = xConnection->getMetaData();
1913 sal_Int32 nMax = xMetaData->getMaxTablesInSelect();
1914 if ( nMax && nMax <
static_cast<sal_Int32
>(
aMap.size()) )
1923 OQueryTableView* pTableView =
static_cast<OQueryTableView*
>(_pView->getTableView());
1924 pTableView->clearLayoutInformation();
1925 for (
auto const& elem : aMap)
1928 Reference< XPropertySet > xTableProps( xTable, UNO_QUERY_THROW );
1930 sAlias = elem.first;
1933 Reference< XPropertySetInfo > xPSI = xTableProps->getPropertySetInfo();
1940 sComposedName = ::dbtools::composeTableName( xMetaData, xTableProps, ::dbtools::EComposeRule::InDataManipulation,
false );
1946 ::dbtools::qualifiedNameComponents( xMetaData,
sComposedName,
sCatalog,
sSchema, sTable, ::dbtools::EComposeRule::InDataManipulation );
1952 OQueryTableWindow* pExistentWin = pTableView->FindTable( sAlias );
1953 if ( !pExistentWin )
1960 if ( !aKeyComp( pExistentWin->GetData()->GetComposedName(),
sComposedName ) )
1967 OJoinTableView::OTableWindowMap aTableMap(pTableView->GetTabWinMap());
1968 for (
auto const& table : aTableMap)
1970 if(
aMap.find(
table.second->GetComposedName()) ==
aMap.end() &&
1972 pTableView->RemoveTabWin(
table.second);
1975 if (
eOk == (eErrorCode = FillOuterJoins(_pView,pTableExp->getChild(0)->getChild(1))) )
1980 rController.setDistinct(
true);
1981 rController.InvalidateFeature(SID_QUERY_DISTINCT_VALUES);
1985 rController.setDistinct(
false);
1989 if( pTableExp->getChild(6)->count() >= 2 && pTableExp->getChild(6)->getChild(1) )
1991 rController.setLimit(
1992 pTableExp->getChild(6)->getChild(1)->getTokenValue().toInt64() );
1996 rController.setLimit(-1);
1999 if ( (eErrorCode = InstallFields(_pView, pParseTree, &pTableView->GetTabWinMap())) ==
eOk )
2002 sal_uInt16 nLevel=0;
2004 if (
eOk == (eErrorCode = GetSelectionCriteria(_pView,_pSelectionBrw,pParseTree,nLevel)) )
2006 if (
eOk == (eErrorCode = GetGroupCriteria(_pView,_pSelectionBrw,pParseTree)) )
2008 if (
eOk == (eErrorCode = GetHavingCriteria(_pView,_pSelectionBrw,pParseTree,nLevel)) )
2010 if (
eOk == (eErrorCode = GetOrderCriteria(_pView,_pSelectionBrw,pParseTree)) )
2011 insertUnUsedFields(_pView,_pSelectionBrw);
2018 catch(SQLException&)
2020 OSL_FAIL(
"getMaxTablesInSelect!");
2026 rController.ClearUndoManager();
2027 _pSelectionBrw->Invalidate();
2035 OJoinTableView::OTableWindowMap* _pTabList)
2038 bool bFirstField =
true;
2039 for (
auto const& table : *_pTabList)
2041 OQueryTableWindow* pTabWin =
static_cast<OQueryTableWindow*
>(
table.second.get());
2043 if (pTabWin->ExistsField(
"*", aInfo ))
2045 eErrorCode = _pView->InsertField(aInfo, bFirstField);
2046 bFirstField =
false;
2047 if (eErrorCode !=
eOk)
2054 const ::connectivity::OSQLParseNode* pNode,
2055 OJoinTableView::OTableWindowMap* pTabList )
2057 if( pNode==
nullptr || !
SQL_ISRULE(pNode,select_statement))
2061 bool bFirstField =
true;
2068 eErrorCode = fillSelectSubList(_pView,pTabList);
2070 else if (
SQL_ISRULE(pParseTree,scalar_exp_commalist) )
2073 OQueryController& rController =
static_cast<OQueryController&
>(_pView->getController());
2074 Reference< XConnection> xConnection = rController.getConnection();
2076 OUString aColumnName,aTableRange;
2077 for (
size_t i = 0;
i < pParseTree->
count() &&
eOk == eErrorCode ; ++
i)
2085 eErrorCode = fillSelectSubList(_pView,pTabList);
2092 pColumnRef = pColumnRef->
getChild(0);
2096 pColumnRef->
count() == 3 &&
2100 pColumnRef = pColumnRef->
getChild(1);
2104 InsertColumnRef(_pView,pColumnRef,aColumnName,aColumnAlias,aTableRange,aInfo,pTabList);
2105 eErrorCode = _pView->InsertField(aInfo, bFirstField);
2106 bFirstField =
false;
2108 else if(
SQL_ISRULEOR3(pColumnRef, general_set_fct, set_fct_spec, position_exp) ||
2109 SQL_ISRULEOR3(pColumnRef, extract_exp, fold, char_substring_fct) ||
2115 rController.getNumberFormatter(),
2116 _pView->getLocale(),
2117 _pView->getDecimalSeparator(),
2118 &rController.getParser().getContext());
2120 sal_Int32 nFunctionType =
FKT_NONE;
2122 sal_Int32 nColumnRefPos = pColumnRef->
count() - 2;
2124 pParamRef = pColumnRef->
getChild(nColumnRefPos);
2127 && pParamRef &&
SQL_ISRULE(pParamRef,column_ref) )
2130 InsertColumnRef(_pView,pParamRef,aColumnName,aColumnAlias,aTableRange,aInfo,pTabList);
2132 else if (
SQL_ISRULE(pColumnRef,general_set_fct) )
2134 if ( pParamRef && pParamRef->
getTokenValue().toChar() ==
'*' )
2136 for (
auto const& table : *pTabList)
2138 OQueryTableWindow* pTabWin =
static_cast<OQueryTableWindow*
>(
table.second.get());
2139 if (pTabWin->ExistsField(
"*", aInfo ))
2141 aInfo->SetAlias(OUString());
2142 aInfo->SetTable(OUString());
2149 OUString sFieldName = aColumns;
2157 &rController.getParser().getContext(),
2160 aInfo->SetDataType(DataType::DOUBLE);
2162 aInfo->SetField(sFieldName);
2164 aInfo->SetTabWindow(
nullptr);
2165 aInfo->SetFieldAlias(aColumnAlias);
2169 _pView->fillFunctionInfo(pColumnRef,aColumns,aInfo);
2170 aInfo->SetFieldAlias(aColumnAlias);
2173 if (
SQL_ISRULE(pColumnRef,general_set_fct) )
2179 aInfo->SetFunctionType(nFunctionType|
FKT_OTHER);
2181 eErrorCode = _pView->InsertField(aInfo, bFirstField);
2182 bFirstField =
false;
2189 &rController.getParser().getContext(),
2192 aInfo->SetTabWindow(
nullptr );
2195 OQueryTableWindow* pExistingTable = lcl_findColumnInTables( aColumns, *pTabList, aInfo );
2196 if ( pExistingTable )
2198 aInfo->SetTabWindow( pExistingTable );
2199 aInfo->SetTable( pExistingTable->GetTableName() );
2200 aInfo->SetAlias( pExistingTable->GetAliasName() );
2203 aInfo->SetDataType(DataType::DOUBLE);
2205 aInfo->SetField(aColumns);
2206 aInfo->SetFieldAlias(aColumnAlias);
2209 eErrorCode = _pView->InsertField(aInfo, bFirstField);
2210 bFirstField =
false;
2216 OSL_FAIL(
"InstallFields: don't know how to interpret this parse node!" );
2227 OSelectionBrowseBox* _pSelectionBrw,
2228 const ::connectivity::OSQLParseNode* pParseRoot )
2231 if (!pParseRoot->getChild(3)->getChild(ORDER_BY_CHILD_POS)->isLeaf())
2236 OQueryController& rController =
static_cast<OQueryController&
>(_pView->getController());
2238 for(
size_t i=0 ;
i<pNode->
count() ;
i++ )
2251 if(
eOk == FillDragInfo(_pView,pArgument,aDragLeft))
2252 _pSelectionBrw->AddOrder( aDragLeft, eOrderDir, i);
2255 OUString aTableRange,aColumnName;
2257 rParseIter.
getColumnRange( pArgument, aColumnName, aTableRange );
2260 for (
auto const& elem : aList)
2262 if(elem.is() && elem->GetFieldAlias() == aColumnName)
2263 elem->SetOrderDir( eOrderDir );
2267 else if(
SQL_ISRULE(pArgument, general_set_fct ) &&
2269 eOk == FillDragInfo(_pView,pParamRef,aDragLeft))
2270 _pSelectionBrw->AddOrder( aDragLeft, eOrderDir, i );
2271 else if(
SQL_ISRULE(pArgument, set_fct_spec ) )
2274 Reference< XConnection> xConnection = rController.getConnection();
2275 if(xConnection.is())
2277 OUString sCondition;
2280 rController.getNumberFormatter(),
2281 _pView->getLocale(),
2282 _pView->getDecimalSeparator(),
2283 &rController.getParser().getContext());
2284 _pView->fillFunctionInfo(pArgument,sCondition,aDragLeft);
2286 aDragLeft->SetOrderDir(eOrderDir);
2287 aDragLeft->SetVisible(
false);
2288 _pSelectionBrw->AddOrder( aDragLeft, eOrderDir, i );
2300 OSelectionBrowseBox* _pSelectionBrw,
2301 const ::connectivity::OSQLParseNode* pSelectRoot,
2302 sal_uInt16& rLevel )
2305 if (!pSelectRoot->getChild(3)->getChild(3)->isLeaf())
2306 eErrorCode = GetORCriteria(_pView,_pSelectionBrw,pSelectRoot->getChild(3)->getChild(3)->getChild(1),rLevel,
true);
2310 OSelectionBrowseBox* _pSelectionBrw,
2311 const ::connectivity::OSQLParseNode* pSelectRoot )
2314 if (!pSelectRoot->getChild(3)->getChild(2)->isLeaf())
2316 OQueryController& rController =
static_cast<OQueryController&
>(_pView->getController());
2319 for(
size_t i=0 ;
i < pGroupBy->
count() &&
eOk == eErrorCode; ++
i )
2326 if (
eOk == (eErrorCode = FillDragInfo(_pView,pArgument,aDragInfo)) )
2328 aDragInfo->SetGroupBy(
true);
2329 _pSelectionBrw->AddGroupBy(aDragInfo);
2332 else if(
SQL_ISRULE(pArgument, general_set_fct ) &&
2334 eOk == FillDragInfo(_pView,pParamRef,aDragInfo))
2336 aDragInfo->SetGroupBy(
true);
2337 _pSelectionBrw->AddGroupBy( aDragInfo );
2339 else if(
SQL_ISRULE(pArgument, set_fct_spec ) )
2341 Reference< XConnection> xConnection = rController.getConnection();
2342 if(xConnection.is())
2344 OUString sGroupByExpression;
2347 &rController.getParser().getContext(),
2349 _pView->fillFunctionInfo(pArgument,sGroupByExpression,aDragInfo);
2351 aDragInfo->SetGroupBy(
true);
2352 aDragInfo->SetVisible(
false);
2353 _pSelectionBrw->AddGroupBy( aDragInfo );
2366 switch (_eErrorCode)
2369 pResId = STR_QRY_ILLEGAL_JOIN;
2372 pResId = STR_QRY_TOO_LONG_STATEMENT;
2375 pResId = STR_QRY_SYNTAX;
2378 pResId = STR_QRY_NOSELECT;
2381 pResId = STR_QRY_SYNTAX;
2384 pResId = STR_QRY_SYNTAX;
2387 pResId = STR_QRY_NATIVE;
2390 pResId = STR_QRY_TOO_MANY_TABLES;
2393 pResId = STR_QRY_TOO_MANY_COLUMNS;
2396 pResId = STR_QRY_TOOCOMPLEX;
2399 pResId = STR_QRY_SYNTAX;
2413 ,m_eChildFocus(
NONE)
2414 ,m_bInSplitHandler( false )
2453 if (!getController().isReadOnly())
2455 m_bInSplitHandler =
true;
2456 m_aSplitter->SetPosPixel(
Point( m_aSplitter->GetPosPixel().X(),m_aSplitter->GetSplitPosPixel() ) );
2457 static_cast<OQueryController&
>(getController()).setSplitPos(m_aSplitter->GetSplitPosPixel());
2458 static_cast<OQueryController&
>(getController()).setModified(
true );
2460 m_bInSplitHandler =
true;
2489 if ( 0 != aPlaygroundSize.
Height() )
2491 if ( ( -1 == nSplitPos )
2492 || ( nSplitPos >= aPlaygroundSize.
Height() )
2499 if ( nSplitPos == -1 || nSplitPos >= aPlaygroundSize.
Height() )
2500 nSplitPos = sal_Int32(aPlaygroundSize.
Height()*0.6);
2509 if ( aSelBoxSize.
Height() )
2527 Point aSplitPos( _rPlayground.
Left(), nSplitPos );
2530 if( ( aSplitPos.
Y() + aSplitSize.
Height() ) > ( aPlaygroundSize.
Height() ))
2533 if( aSplitPos.
Y() <= aPlaygroundPos.
Y() )
2534 aSplitPos.
setY( aPlaygroundPos.
Y() + sal_Int32(aPlaygroundSize.
Height() * 0.2) );
2537 Size aTableViewSize(aPlaygroundSize.
Width(), aSplitPos.
Y() - aPlaygroundPos.
Y());
2541 Point aPos( aPlaygroundPos.
X(), aSplitPos.
Y() + aSplitSize.
Height() );
2545 m_aSplitter->SetPosSizePixel( aSplitPos, aSplitSize );
2572 bool bAllowed =
false;
2580 bool bAllowed =
false;
2588 bool bAllowed =
false;
2641 static sal_Int32 s_nDefaultWidth =
GetTextWidth(
"0") * 15;
2644 nWidth = s_nDefaultWidth;
2652 bool bAllTables = sAliasName.empty();
2655 OUString strCurrentPrefix;
2656 std::vector< OUString> aFields;
2657 for (
auto const& tabWin : rTabWins)
2660 if (bAllTables || (pCurrentWin->
GetAliasName() == sAliasName))
2666 for (
auto const& field : aFields)
2668 if (bAllTables || field.toChar() ==
'*')
2684 if (rNEvt.
GetType() == NotifyEventType::GETFOCUS)
2713 sal_uInt32 nFieldcount = 0;
2715 for (
auto const& field : rFieldList)
2717 if (!field->GetField().isEmpty() && field->IsVisible() )
2719 else if (!field->GetField().isEmpty() &&
2720 !field->HasCriteria() &&
2721 field->isNoneFunction() &&
2723 !field->IsGroupBy() &&
2724 field->GetFunction().isEmpty() )
2725 rUnUsedFields.push_back(field);
2729 rUnUsedFields = rFieldList;
2734 sal_uInt32 nTabcount = rTabList.size();
2736 OUString aFieldListStr(GenerateSelectList(
this,rFieldList,nTabcount>1));
2737 if( aFieldListStr.isEmpty() )
2746 const auto& rConnList =
m_pTableView->getTableConnections();
2748 OUString aTableListStr(GenerateFromClause(xConnection,&rTabList,rConnList));
2749 OSL_ENSURE(!aTableListStr.isEmpty(),
"OQueryDesignView::getStatement() : unexpected : have Fields, but no Tables !");
2753 OUStringBuffer aHavingStr,aCriteriaListStr;
2756 if (!GenerateCriterias(
this,aCriteriaListStr,aHavingStr,rFieldList, nTabcount > 1))
2760 GenerateInnerJoinCriterias(xConnection,aJoinCrit,rConnList);
2761 if(!aJoinCrit.isEmpty())
2763 OUString aTmp =
"( " + aJoinCrit +
" )";
2764 if(!aCriteriaListStr.isEmpty())
2768 aCriteriaListStr.insert(0, aTmp);
2771 OUStringBuffer aSqlCmd(
"SELECT ");
2773 aSqlCmd.append(
" DISTINCT ");
2774 aSqlCmd.append(aFieldListStr +
" FROM " + aTableListStr);
2776 if (!aCriteriaListStr.isEmpty())
2778 aSqlCmd.append(
" WHERE " + aCriteriaListStr);
2781 if ( xConnection.is() )
2782 xMeta = xConnection->getMetaData();
2783 bool bUseAlias = nTabcount > 1;
2785 bUseAlias = bUseAlias || !xMeta->supportsGroupByUnrelated();
2787 aSqlCmd.append(GenerateGroupBy(
this,rFieldList,bUseAlias));
2789 if(!aHavingStr.isEmpty())
2791 aSqlCmd.append(
" HAVING " + aHavingStr);
2796 if ( (eErrorCode = GenerateOrder(
this,rFieldList,nTabcount > 1,sOrder)) ==
eOk)
2797 aSqlCmd.append(sOrder);
2801 m_rController.appendError( getParseErrorMessage( eErrorCode ) );
2807 const sal_Int64 nLimit = rController.
getLimit();
2810 aSqlCmd.append(
" LIMIT " + OUString::number(nLimit) );
2814 OUString sSQL = aSqlCmd.makeStringAndClear();
2815 if ( xConnection.is() )
2818 OUString sErrorMessage;
2819 std::unique_ptr<OSQLParseNode> pParseNode( rParser.
parseTree( sErrorMessage, sSQL,
true ) );
2823 if ( pNode->
count() > 1 )
2830 pParseNode->parseNodeToStr(sTemp,xConnection);
2844 case SID_QUERY_VIEW_FUNCTIONS:
2847 case SID_QUERY_VIEW_TABLES:
2850 case SID_QUERY_VIEW_ALIASES:
2867 case SID_QUERY_VIEW_FUNCTIONS:
2870 case SID_QUERY_VIEW_TABLES:
2873 case SID_QUERY_VIEW_ALIASES:
2894 const OUString& _sCriteria,
2895 OUString& _rsErrorMessage,
2898 OSL_ENSURE(pEntry.is(),
"Entry is null!");
2902 if(!xConnection.is())
2913 if ( pEntry->isNumericOrAggregateFunction() )
2914 sFunction = pEntry->GetFunction().getToken(0,
'(');
2916 if ( sFunction.isEmpty() )
2917 sFunction = pEntry->GetField().getToken(0,
'(');
2920 if (
nType == DataType::OTHER || (sFunction.isEmpty() && pEntry->isNumericOrAggregateFunction()) )
2923 OUString sSql =
"SELECT * FROM x WHERE " + pEntry->GetField() + _sCriteria;
2924 std::unique_ptr<OSQLParseNode> pParseNode( rParser.
parseTree( _rsErrorMessage, sSql,
true ) );
2925 nType = DataType::DOUBLE;
2932 if (
eOk == FillDragInfo(
this,pColumnRef,aField) )
2934 nType = aField->GetDataType();
2945 ColumnValue::NULLABLE_UNKNOWN,
2951 xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers(),
2955 _rxColumn = pColumn;
2956 pColumn->setFunction(
true);
2957 pColumn->setRealName(pEntry->GetField());
2964 if (xColumns.is() && xColumns->hasByName(pEntry->GetField()))
2965 xColumns->getByName(pEntry->GetField()) >>= _rxColumn;
2981 std::unique_ptr<OSQLParseNode> pParseNode = rParser.
predicateTree( _rsErrorMessage,
3020 for (
auto const & field : i_rFieldDescriptions )
3023 pField->Load( field,
true );
3040 if ( eErrorCode !=
eOk )
3043 m_rController.appendError( getParseErrorMessage( eErrorCode ) );
3059 return eErrorCode ==
eOk;
3064 sal_Int32 char_datatype(const::connectivity::OSQLParseNode* pDataType,
const unsigned int offset) {
3065 int cnt = pDataType->count() - offset;
3068 OSL_FAIL(
"internal error in decoding character datatype specification");
3069 return DataType::VARCHAR;
3071 else if ( cnt == 0 )
3076 if ( SQL_ISTOKENOR2 (pDataType, CHARACTER, CHAR) )
3077 return DataType::CHAR;
3078 else if ( SQL_ISTOKEN (pDataType, VARCHAR) )
3079 return DataType::VARCHAR;
3080 else if ( SQL_ISTOKEN (pDataType, CLOB) )
3081 return DataType::CLOB;
3084 OSL_FAIL(
"unknown/unexpected token in decoding character datatype specification");
3085 return DataType::VARCHAR;
3091 OSL_FAIL(
"incomplete datatype in decoding character datatype specification");
3092 return DataType::VARCHAR;
3096 if (
SQL_ISTOKEN(pDataType->getChild(offset), NATIONAL) )
3097 return char_datatype(pDataType, offset+1);
3098 else if (
SQL_ISTOKENOR3(pDataType->getChild(offset), CHARACTER, CHAR, NCHAR) )
3100 if ( cnt > 2 &&
SQL_ISTOKEN(pDataType->getChild(offset+1), LARGE) &&
SQL_ISTOKEN(pDataType->getChild(offset+2), OBJECT) )
3101 return DataType::CLOB;
3102 else if ( cnt > 1 &&
SQL_ISTOKEN(pDataType->getChild(offset+1), VARYING) )
3103 return DataType::VARCHAR;
3105 return DataType::CHAR;
3107 else if ( SQL_ISTOKEN (pDataType->getChild(offset), VARCHAR) )
3108 return DataType::VARCHAR;
3109 else if ( SQL_ISTOKENOR2 (pDataType->getChild(offset), CLOB, NCLOB) )
3110 return DataType::CLOB;
3112 OSL_FAIL(
"unrecognised character datatype");
3113 return DataType::VARCHAR;
3133 ,
const OUString& sFunctionTerm
3139 switch(pNode->getNodeType())
3145 case SQLNodeType::IntNum:
3148 case SQLNodeType::ApproxNum:
3151 case SQLNodeType::AccessDate:
3155 case SQLNodeType::Less:
3156 case SQLNodeType::Great:
3157 case SQLNodeType::LessEq:
3158 case SQLNodeType::GreatEq:
3163 case SQLNodeType::ListRule:
3164 case SQLNodeType::CommaListRule:
3165 case SQLNodeType::Keyword:
3166 case SQLNodeType::Punctuation:
3167 OSL_FAIL(
"Unexpected SQL Node Type");
3170 switch(pNode->getKnownRuleID())
3228 OSL_FAIL(
"Unexpected SQL RuleID");
3232 OSL_FAIL(
"Cannot guess column type");
3235 OSL_FAIL(
"Cannot guess VALUES type");
3238 OSL_FAIL(
"Cannot guess computed column type");
3241 OSL_FAIL(
"Cannot guess subquery return type");
3295 if (pNode->count() == 0)
3298 OSL_FAIL(
"Got leaf SQL node where non-leaf expected");
3304 if ( pNode->count() == 3 )
3307 OSL_FAIL(
"ODBC escape not in recognised form");
3313 pFunctionName = pFunctionName->
getChild(0);
3316 if ( sFunctionName.isEmpty() )
3327 if (pNode->count() != 2)
3329 OSL_FAIL(
"interior of ODBC escape not in recognised shape");
3343 OSL_FAIL(
"Unknown ODBC escape");
3348 if ( pNode->count() != 6 || !
SQL_ISTOKEN(pNode->getChild(3),
AS) )
3350 OSL_FAIL(
"CAST not in recognised shape");
3370 else if ( pCastTarget->
count() > 0 )
3373 while (pDataType->
count() > 0)
3375 pCastTarget = pDataType;
3376 pDataType = pDataType->
getChild(0);
3383 nDataType = char_datatype(pCastTarget, 0);
3389 nDataType = char_datatype(pCastTarget, 1);
3415 OSL_FAIL(
"Failed to decode CAST target");
3418 OSL_FAIL(
"Could not decipher CAST target");
3422 OSL_FAIL(
"Unknown SQL RuleID");
3427 OSL_FAIL(
"Unknown SQL Node Type");
3433 aInfo->SetField(sFunctionTerm);
3434 aInfo->SetTabWindow(
nullptr);
OptionalString sComposedName
#define BROW_COLUMNALIAS_ROW
#define BROW_FUNCTION_ROW
#define ID_BROWSER_ADDTABLE
#define BROWSER_INVALIDID
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
const OUString & getNumDecimalSep() const
NotifyEventType GetType() const
constexpr tools::Long Y() const
void setY(tools::Long nY)
constexpr tools::Long X() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
const LanguageTag & GetLanguageTag() const
const LocaleDataWrapper & GetLocaleData() const
void AddWindow(vcl::Window *pWindow)
void RemoveWindow(vcl::Window *pWindow)
static VclPtr< reference_type > Create(Arg &&... arg)
static void absorptions(OSQLParseNode *&pSearchCondition)
static void negateSearchCondition(OSQLParseNode *&pSearchCondition, bool bNegate=false)
static void disjunctiveNormalForm(OSQLParseNode *&pSearchCondition)
void parseNodeToStr(OUString &rString, const css::uno::Reference< css::sdbc::XConnection > &_rxConnection, const IParseContext *pContext=nullptr, bool _bIntl=false, bool _bQuote=true) const
base_table_element_commalist
delete_statement_searched
other_like_predicate_part_2
table_primary_as_range_column
update_statement_searched
parenthesized_boolean_value_expression
comparison_predicate_part_2
delete_statement_positioned
update_statement_positioned
sal_uInt32 getTokenID() const
static OUString getTableRange(const OSQLParseNode *_pTableRef)
Rule getKnownRuleID() const
void parseNodeToPredicateStr(OUString &rString, const css::uno::Reference< css::sdbc::XConnection > &_rxConnection, const css::uno::Reference< css::util::XNumberFormatter > &xFormatter, const css::lang::Locale &rIntl, OUString _sDec, const IParseContext *pContext=nullptr) const
const OUString & getTokenValue() const
OSQLParseNode * getChild(sal_uInt32 nPos) const
static void compress(OSQLParseNode *&pSearchCondition)
OSQLParseNode * getByRule(OSQLParseNode::Rule eRule) const
static OUString getColumnAlias(const OSQLParseNode *_pDerivedColumn)
const OSQLTables & getTables() const
void getColumnRange(const OSQLParseNode *_pColumnRef, OUString &_rColumnName, OUString &_rTableRange) const
const OSQLParseNode * getParseTree() const
static sal_Int32 getFunctionReturnType(std::u16string_view _sFunctionName, const IParseContext *pContext)
static OString TokenIDToStr(sal_uInt32 nTokenID, const IParseContext *pContext=nullptr)
std::unique_ptr< OSQLParseNode > predicateTree(OUString &rErrorMessage, const OUString &rStatement, const css::uno::Reference< css::util::XNumberFormatter > &xFormatter, const css::uno::Reference< css::beans::XPropertySet > &xField, bool bUseRealName=true)
std::unique_ptr< OSQLParseNode > parseTree(OUString &rErrorMessage, const OUString &rStatement, bool bInternational=false)
const IParseContext & getContext() const
virtual bool PreNotify(NotifyEvent &rNEvt) override
void SaveTabWinsPosSize(OJoinTableView::OTableWindowMap *pTabWinList, tools::Long nOffsetX, tools::Long nOffsetY)
VclPtr< OJoinTableView > m_pTableView
OJoinController & m_rController
VclPtr< OScrollWindowHelper > m_pScrollWindow
virtual void Construct() override
late construction
virtual void dispose() override
OJoinController & getController() const
std::map< OUString, VclPtr< OTableWindow > > OTableWindowMap
void setVisibleRows(sal_Int32 _nVisibleRows)
OTableFields & getUnUsedFields()
::connectivity::OSQLParser & getParser()
OTableFields & getTableFieldDesc()
void setSplitPos(sal_Int32 _nSplitPos)
sal_Int64 getLimit() const
sal_Int32 getColWidth(sal_uInt16 _nColPos) const
virtual void setReadOnly(bool _bReadOnly) override
bool isCopyAllowed() const
VclPtr< Splitter > m_aSplitter
virtual void GetFocus() override
void fillFunctionInfo(const ::connectivity::OSQLParseNode *pNode, const OUString &sFunctionTerm, OTableFieldDescRef &aInfo)
bool isCutAllowed() const
void setSlotEnabled(sal_Int32 _nSlotId, bool _bEnable)
VclPtr< OSelectionBrowseBox > m_pSelectionBox
virtual ~OQueryDesignView() override
void initByFieldDescriptions(const css::uno::Sequence< css::beans::PropertyValue > &i_rFieldDescriptions)
virtual void resizeDocumentView(tools::Rectangle &rRect) override
bool isSlotEnabled(sal_Int32 _nSlotId)
std::unique_ptr<::connectivity::OSQLParseNode > getPredicateTreeFromEntry(const OTableFieldDescRef &pEntry, const OUString &_sCriteria, OUString &_rsErrorMessage, css::uno::Reference< css::beans::XPropertySet > &_rxColumn) const
css::lang::Locale m_aLocale
bool HasFieldByAliasName(std::u16string_view rFieldName, OTableFieldDescRef const &rInfo) const
virtual void Construct() override
late construction
bool isPasteAllowed() const
virtual void dispose() override
virtual void initialize() override
SqlParseError InsertField(const OTableFieldDescRef &rInfo, bool bActivate=true)
void setNoneVisibleRow(sal_Int32 _nRows)
void TableDeleted(const OUString &rAliasName)
virtual bool PreNotify(NotifyEvent &rNEvt) override
ChildFocusState m_eChildFocus
void fillValidFields(std::u16string_view strTableName, weld::ComboBox &rFieldList)
bool initByParseIterator(::dbtools::SQLExceptionInfo *_pErrorInfo)
initializes the view from the current parser / parse iterator of the controller
OUString const & GetAliasName() const
void ClearUndoManager()
complete clears the Undo/Redo stacks
css::uno::Reference< css::container::XNameAccess > GetOriginalColumns() const
void EnumValidFields(std::vector< OUString > &arrstrFields)
tools::Long GetTextWidth(const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, vcl::text::TextLayoutCache const *=nullptr, SalLayoutGlyphs const *const pLayoutCache=nullptr) const
void append_text(const OUString &rStr)
#define DBG_UNHANDLED_EXCEPTION(...)
#define LINK(Instance, Class, Member)
Sequence< sal_Int8 > aSeq
std::unique_ptr< sal_Int32[]> pData
OString stripEnd(const OString &rIn, char c)
sal_Int32 getTokenCount(std::string_view rIn, char cTok)
std::map< OUString, OSQLTable, comphelper::UStringMixLess > OSQLTables
css::uno::Reference< css::sdbcx::XColumnsSupplier > OSQLTable
::rtl::Reference< OTableFieldDesc > OTableFieldDescRef
IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged, TransferableDataHelper *, void)
std::vector< OConnectionLineDataRef > OConnectionLineDataVec
bool generateAsBeforeTableAlias(const css::uno::Reference< css::sdbc::XConnection > &_rxConnection)
determines whether when generating SQL statements, AS should be placed before a table alias
css::uno::Reference< css::util::XNumberFormatter > getNumberFormatter(const css::uno::Reference< css::sdbc::XConnection > &_rxConnection, const css::uno::Reference< css::uno::XComponentContext > &_rxContext)
creates a number formatter
bool isAppendTableAliasEnabled(const css::uno::Reference< css::sdbc::XConnection > &_xConnection)
check if the alias name of the table should be added at select statements
void notifySystemWindow(vcl::Window const *_pWindow, vcl::Window *_pToRegister, const ::comphelper::mem_fun1_t< TaskPaneList, vcl::Window * > &_rMemFunc)
notifySystemWindow adds or remove the given window _pToRegister at the Systemwindow found when search...
std::vector< OTableFieldDescRef > OTableFields
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
HashMap_OWString_Interface aMap
#define SQL_ISRULE(pParseNode, eRule)
#define SQL_ISPUNCTUATION(pParseNode, aString)
#define SQL_ISRULEOR3(pParseNode, e1, e2, e3)
#define SQL_ISTOKEN(pParseNode, token)
#define SQL_ISTOKENOR3(pParseNode, tok0, tok1, tok2)
#define SQL_ISRULEOR2(pParseNode, e1, e2)
#define SQL_ISTOKENOR2(pParseNode, tok0, tok1)
constexpr OUStringLiteral PROPERTY_COMMAND(u"Command")
constexpr OUStringLiteral PROPERTY_OUTERJOINESCAPE(u"EnableOuterJoinEscape")
constexpr OUStringLiteral PROPERTY_NAME(u"Name")