23#include <sqlbison.hxx>
26#include <com/sun/star/sdbc/ColumnValue.hpp>
27#include <com/sun/star/sdbc/DataType.hpp>
28#include <com/sun/star/sdbc/XRow.hpp>
29#include <com/sun/star/sdb/XQueriesSupplier.hpp>
30#include <com/sun/star/sdb/ErrorCondition.hpp>
31#ifdef SQL_TEST_PARSETREEITERATOR
39#include <com/sun/star/sdb/SQLFilterOperator.hpp>
83 OSL_PRECOND(
m_xConnection.is(),
"OSQLParseTreeIteratorImpl::OSQLParseTreeIteratorImpl: invalid connection!" );
97 Reference< XQueriesSupplier > xSuppQueries(
m_xConnection, UNO_QUERY );
98 if ( xSuppQueries.is() )
118 class ForbidQueryName
124 ForbidQueryName( OSQLParseTreeIteratorImpl& _rIteratorImpl, OUString _aForbiddenQueryName )
142OSQLParseTreeIterator::OSQLParseTreeIterator(
const Reference< XConnection >& _rxConnection,
143 const Reference< XNameAccess >& _rxTables,
144 const OSQLParser& _rParser )
146 ,
m_pImpl( new OSQLParseTreeIteratorImpl( _rxConnection, _rxTables ) )
148 setParseTree(
nullptr);
156 m_pImpl->m_pForbiddenQueryNames = _rParentIterator.
m_pImpl->m_pForbiddenQueryNames;
175 return m_pImpl->m_bIsCaseSensitive;
185 m_pImpl->m_xTableContainer =
nullptr;
186 m_pImpl->m_xDatabaseMetaData =
nullptr;
189 m_pImpl->m_pSubTables->clear();
195 m_pImpl->m_pSubTables->clear();
211 if ( !
m_pImpl->m_xTableContainer.is() )
255 void impl_getRowString(
const Reference< XRow >& _rxRow,
const sal_Int32 _nColumnIndex, OUString& _out_rString )
257 _out_rString = _rxRow->getString( _nColumnIndex );
258 if ( _rxRow->wasNull() )
259 _out_rString.clear();
263 OUString lcl_findTableInMetaData(
264 const Reference< XDatabaseMetaData >& _rxDBMeta,
const OUString& _rCatalog,
265 const OUString& _rSchema,
const OUString& _rTableName )
269 static constexpr OUStringLiteral s_sWildcard =
u"%" ;
272 Sequence< OUString > sTableTypes {
"VIEW",
"TABLE", s_sWildcard };
274 if ( _rxDBMeta.is() )
278 Reference< XResultSet> xRes = _rxDBMeta->getTables(
279 !_rCatalog.isEmpty() ?
Any( _rCatalog ) :
Any(), !_rSchema.isEmpty() ? _rSchema : s_sWildcard, _rTableName, sTableTypes );
281 Reference< XRow > xCurrentRow( xRes, UNO_QUERY );
282 if ( xCurrentRow.is() && xRes->next() )
286 impl_getRowString( xCurrentRow, 1, sCatalog );
287 impl_getRowString( xCurrentRow, 2, sSchema );
288 impl_getRowString( xCurrentRow, 3, sName );
296 ::dbtools::EComposeRule::InDataManipulation
314 OUString sSubQueryCommand;
315 bool bEscapeProcessing =
false;
318 Reference< XPropertySet > xQueryProperties( _rQuery, UNO_QUERY_THROW );
330 if ( !bEscapeProcessing || ( sSubQueryCommand.isEmpty() ) )
334 std::unique_ptr< OSQLParseNode > pSubQueryNode(
const_cast< OSQLParser&
>(
m_rParser ).parseTree( sError, sSubQueryCommand ) );
341 pSubQueryParameterColumns = aSubQueryIterator.
getParameters();
353 if ( _rComposedName.isEmpty() )
355 SAL_WARN(
"connectivity.parse",
"OSQLParseTreeIterator::impl_locateRecordSource: no object name at all?" );
381 if ( bQueryDoesExist )
383 else if ( bTableDoesExist )
392 if ( bQueryDoesExist )
406 else if ( bTableDoesExist )
410 if (
m_pImpl->m_xQueryContainer.is() )
434 OSL_ENSURE(pTableName !=
nullptr,
"OSQLParseTreeIterator::traverseOneTableName: pTableName == NULL");
437 OUString aSchema,aTableName,aComposedName;
438 OUString aTableRange(rTableRange);
445 aCatalog.hasValue() ? ::comphelper::getString(aCatalog) : OUString(),
449 ::dbtools::EComposeRule::InDataManipulation);
452 if ( aTableRange.isEmpty() )
453 aTableRange = aComposedName;
458 _rTables[ aTableRange ] = aTable;
463 if (i_pJoinCondition->
count() == 3 &&
469 else if (
SQL_ISRULEOR2(i_pJoinCondition,search_condition,boolean_term) &&
470 i_pJoinCondition->
count() == 3)
479 else if (
SQL_ISRULE(i_pJoinCondition,comparison_predicate))
482 OSL_ENSURE(i_pJoinCondition->
count() == 3,
"OQueryDesignView::InsertJoinConnection: error in the parse tree");
494 return m_pImpl->m_aJoinConditions;
500 "OSQLParseTreeIterator::getQualified_join: illegal node!" );
513 if (
SQL_ISRULE( pTableRef, qualified_join ) )
516 if (
SQL_ISRULE( pJoin_spec, join_condition ) )
524 for (
size_t i = 0;
i < pColumnCommalist->
count();
i++)
543 "OSQLParseTreeIterator::getTableNode: only to be called for table_ref nodes!" );
558 if ( ( pTableRef->
count() == 4 )
559 || ( pTableRef->
count() == 5 )
564 else if ( pTableRef->
count() == 3 )
573 OSL_ENSURE( pSubQuery->
count() == 3,
"sub queries should have 3 children!" );
575 if (
SQL_ISRULE( pQueryExpression, select_statement ) )
588 SAL_WARN(
"connectivity.parse",
"OSQLParseTreeIterator::getTableNode: subquery which is no select_statement: not yet implemented!" );
592 else if ( pTableRef->
count() == 2 )
594 pTableNameNode = pTableRef->
getChild(0);
597 SAL_WARN(
"connectivity.parse",
"OSQLParseTreeIterator::getTableNode: unhandled case!" );
600 return pTableNameNode;
613 OSL_ENSURE(pTableRefCommalist !=
nullptr,
"OSQLParseTreeIterator: error in parse tree!");
614 OSL_ENSURE(
SQL_ISRULE(pTableRefCommalist,table_ref_commalist),
"OSQLParseTreeIterator: error in parse tree!");
617 OUString aTableRange;
618 for (
size_t i = 0;
i < pTableRefCommalist->
count();
i++)
627 else if (
SQL_ISRULE( pTableListElement, table_ref ) )
630 pTableName = pTableListElement->
getChild(0);
642 getTableNode( _rTables, pTableListElement, aTableRange );
645 else if (
SQL_ISRULE( pTableListElement, qualified_join ) ||
SQL_ISRULE( pTableListElement, cross_union ) )
649 else if (
SQL_ISRULE( pTableListElement, joined_table ) )
694 OSL_ENSURE(
SQL_ISRULE(_pDerivedColumn,derived_column),
"No derived column!");
695 OUString sColumnAlias;
706 void lcl_getColumnRange(
const OSQLParseNode* _pColumnRef,
const Reference< XConnection >& _rxConnection,
707 OUString& _out_rColumnName, OUString& _out_rTableRange,
708 const OSQLColumns* _pSelectColumns, OUString& _out_rColumnAliasIfPresent )
710 _out_rColumnName.clear();
711 _out_rTableRange.clear();
712 _out_rColumnAliasIfPresent.clear();
715 if( _pColumnRef->
count() > 1 )
717 for ( sal_Int32 i=0; i<static_cast<sal_Int32>(_pColumnRef->
count())-2; ++
i )
725 if ( _pSelectColumns )
727 for (
const Reference< XPropertySet >& xColumn : *_pSelectColumns)
731 OUString
sName, sTableName;
734 if ( sName == _out_rColumnName && ( _out_rTableRange.isEmpty() || sTableName == _out_rTableRange ) )
740 catch(
const Exception& )
758 OUString& _rColumnName,
759 OUString& _rTableRange)
const
762 lcl_getColumnRange( _pColumnRef,
m_pImpl->m_xConnection, _rColumnName, _rTableRange,
nullptr, sDummy );
767 OUString& _rColumnName,
768 OUString& _rTableRange,
769 OUString& _out_rColumnAliasIfPresent )
const
771 lcl_getColumnRange( _pColumnRef,
m_pImpl->m_xConnection, _rColumnName, _rTableRange, &*
m_aSelectColumns, _out_rColumnAliasIfPresent );
776 const Reference< XConnection >& _rxConnection, OUString& _out_rColumnName, OUString& _out_rTableRange )
779 lcl_getColumnRange( _pColumnRef, _rxConnection, _out_rColumnName, _out_rTableRange,
nullptr, sDummy );
792 if (!
SQL_ISRULE(pSelectNode,base_table_element_commalist))
795 for (
size_t i = 0;
i < pSelectNode->
count();
i++)
801 OUString aColumnName;
803 sal_Int32
nType = DataType::VARCHAR;
807 if (pDatatype &&
SQL_ISRULE(pDatatype,character_string_type))
812 nType = DataType::CHAR;
816 aTypeName =
"VARCHAR";
819 if (!aTypeName.isEmpty())
824 OUString(),OUString(),OUString());
825 pColumn->setFunction(
false);
826 pColumn->setRealName(aColumnName);
863 for (
size_t i = 0;
i < pSelection->
count();
i++)
874 OUString aTableRange;
879 else if (
SQL_ISRULE(pColumnRef,derived_column))
882 OUString sColumnName;
883 OUString aTableRange;
884 sal_Int32
nType = DataType::VARCHAR;
886 pColumnRef = pColumnRef->
getChild(0);
889 pColumnRef->
count() == 3 &&
893 pColumnRef = pColumnRef->
getChild(1);
898 OSL_ENSURE(!sColumnName.isEmpty(),
"Column name must not be empty!");
910 if ( pColumnRef->
isRule() )
926 if(aColumnAlias.isEmpty())
927 aColumnAlias = sColumnName;
947 if (pSelectNode ==
nullptr)
965 OSL_ENSURE(pSelectNode->
count() >= 4,
"OSQLParseTreeIterator: error in parse tree!");
968 OSL_ENSURE(pTableExp !=
nullptr,
"OSQLParseTreeIterator: error in parse tree!");
969 OSL_ENSURE(
SQL_ISRULE(pTableExp,table_exp),
"OSQLParseTreeIterator:table_exp error in parse tree!");
975 OSL_ENSURE(pOptByClause !=
nullptr,
"OSQLParseTreeIterator: error in parse tree!");
976 if ( pOptByClause->
count() == 0 )
979 OSL_ENSURE(pOptByClause->
count() == 3,
"OSQLParseTreeIterator: error in parse tree!");
982 OSL_ENSURE(pOrderingSpecCommalist !=
nullptr,
"OSQLParseTreeIterator: error in parse tree!");
983 OSL_ENSURE(!_bOrder ||
SQL_ISRULE(pOrderingSpecCommalist,ordering_spec_commalist),
"OSQLParseTreeIterator:ordering_spec_commalist error in parse tree!");
984 OSL_ENSURE(pOrderingSpecCommalist->
count() > 0,
"OSQLParseTreeIterator: error in parse tree!");
986 OUString sColumnName;
987 OUString aTableRange;
988 sal_uInt32
nCount = pOrderingSpecCommalist->
count();
992 OSL_ENSURE(pColumnRef !=
nullptr,
"OSQLParseTreeIterator: error in parse tree!");
995 OSL_ENSURE(
SQL_ISRULE(pColumnRef,ordering_spec),
"OSQLParseTreeIterator:ordering_spec error in parse tree!");
996 OSL_ENSURE(pColumnRef->
count() == 2,
"OSQLParseTreeIterator: error in parse tree!");
998 pColumnRef = pColumnRef->
getChild(0);
1000 OSL_ENSURE(pColumnRef !=
nullptr,
"OSQLParseTreeIterator: error in parse tree!");
1001 aTableRange.clear();
1002 sColumnName.clear();
1012 OSL_ENSURE(!sColumnName.isEmpty(),
"sColumnName must not be empty!");
1017 OSL_ENSURE(pOptAscDesc !=
nullptr,
"OSQLParseTreeIterator: error in parse tree!");
1038 OUString sColumnName(
"param" );
1039 const sal_Int32
nCount =
static_cast<sal_Int32
>(_rParentNode.
count());
1040 for ( sal_Int32 i = 0;
i <
nCount; ++
i )
1042 if ( _rParentNode.
getChild(i) == &_rParamNode )
1044 sColumnName += OUString::number( i+1 );
1055 if ( _pNode ==
nullptr )
1058 OUString sColumnName, sTableRange, aColumnAlias;
1060 if ( pParent !=
nullptr )
1062 if (
SQL_ISRULE(pParent,comparison_predicate) )
1064 sal_uInt32
nPos = 0;
1073 else if (
SQL_ISRULE(pParent,other_like_predicate_part_2) )
1081 else if (
SQL_ISRULE(pParent,between_predicate_part_2) )
1089 lcl_generateParameterName( *pParent, *_pNode );
1094 lcl_generateParameterName( *pParent, *_pNode );
1108 if ( pSelectNode ==
nullptr )
1123 OSL_ENSURE(pSelectNode->
count() >= 4,
"OSQLParseTreeIterator: error in parse tree!");
1126 OSL_ENSURE(pTableExp !=
nullptr,
"OSQLParseTreeIterator: error in parse tree!");
1127 OSL_ENSURE(
SQL_ISRULE(pTableExp,table_exp),
"OSQLParseTreeIterator: error in parse tree!");
1130 pWhereClause = pTableExp->
getChild(1);
1131 }
else if (
SQL_ISRULE(pSelectNode,update_statement_searched)) {
1132 OSL_ENSURE(pSelectNode->
count() == 5,
"OSQLParseTreeIterator: error in parse tree!");
1133 pWhereClause = pSelectNode->
getChild(4);
1134 }
else if (
SQL_ISRULE(pSelectNode,delete_statement_searched)) {
1135 OSL_ENSURE(pSelectNode->
count() == 4,
"OSQLParseTreeIterator: error in parse tree!");
1136 pWhereClause = pSelectNode->
getChild(3);
1137 }
else if (
SQL_ISRULE(pSelectNode,delete_statement_positioned)) {
1139 SAL_WARN(
"connectivity.parse",
"OSQLParseTreeIterator::getSelectionCriteria: positioned nyi");
1145 if (!pWhereClause || !
SQL_ISRULE(pWhereClause,where_clause))
1148 OSL_ENSURE(pWhereClause &&
SQL_ISRULE(pWhereClause,opt_where_clause),
"OSQLParseTreeIterator: error in parse tree!");
1153 OSL_ENSURE(pWhereClause->
count() == 2,
"OSQLParseTreeIterator: error in parse tree!");
1156 OSL_ENSURE(pComparisonPredicate !=
nullptr,
"OSQLParseTreeIterator: error in parse tree!");
1171 SQL_ISRULE(pSearchCondition,boolean_primary) &&
1172 pSearchCondition->
count() == 3 &&
1181 else if (
SQL_ISRULE(pSearchCondition,search_condition) && pSearchCondition->
count() == 3 )
1194 else if (
SQL_ISRULE(pSearchCondition,boolean_term) && pSearchCondition->
count() == 3 )
1205 else if (
SQL_ISRULE(pSearchCondition,comparison_predicate) )
1214 else if (
SQL_ISRULE(pSearchCondition,like_predicate) )
1216 OSL_ENSURE(pSearchCondition->
count() == 2,
"OSQLParseTreeIterator: error in parse tree!");
1219 sal_Int32 nCurrentPos = pPart2->
count()-2;
1224 OSL_ENSURE(pNum_value_exp !=
nullptr,
"OSQLParseTreeIterator: error in parse tree!");
1225 OSL_ENSURE(pOptEscape !=
nullptr,
"OSQLParseTreeIterator: error in parse tree!");
1227 if (pOptEscape->
count() != 0)
1236 pParam = pNum_value_exp;
1237 else if(pNum_value_exp->
isToken())
1243 pParam = pNum_value_exp;
1250 else if (
SQL_ISRULE(pSearchCondition,in_predicate))
1252 OSL_ENSURE(pSearchCondition->
count() == 2,
"OSQLParseTreeIterator: error in parse tree!");
1274 else if (
SQL_ISRULE(pSearchCondition,test_for_null) )
1276 OSL_ENSURE(pSearchCondition->
count() == 2,
"OSQLParseTreeIterator: error in parse tree!");
1295 ,
const OUString& _aColumnName
1296 ,OUString& _aTableRange
1297 ,
const OUString& _rColumnAlias)
1306 OSL_ENSURE(_pParseNode->
count() > 0,
"OSQLParseTreeIterator: error in parse tree!");
1308 OUString sParameterName;
1312 sParameterName = !_rColumnAlias.isEmpty()
1314 : !_aColumnName.isEmpty()
1328 SAL_WARN(
"connectivity.parse",
"OSQLParseTreeIterator: error in parse tree!");
1332 if ( _pParentNode && (
SQL_ISRULE(_pParentNode,general_set_fct) ||
SQL_ISRULE(_pParentNode,set_fct_spec)) )
1334 OUString sFunctionName;
1340 if ( _pParentNode->
getChild(
i) == _pParseNode )
1349 ColumnValue::NULLABLE_UNKNOWN,
1359 pColumn->setFunction(
true);
1360 pColumn->setAggregateFunction(
true);
1361 pColumn->setRealName(sFunctionName);
1366 bool bNotFound =
true;
1367 OSQLColumns::const_iterator aIter = ::connectivity::find(
1375 pNewColumn->setName(sParameterName);
1376 pNewColumn->setRealName(_aColumnName);
1380 else if(!_aColumnName.isEmpty())
1383 Reference<XPropertySet>
xColumn =
findColumn( _aColumnName, _aTableRange,
true );
1388 pNewColumn->setName(sParameterName);
1389 pNewColumn->setRealName(_aColumnName);
1396 sal_Int32
nType = DataType::VARCHAR;
1404 if ( _pParentNode->
getChild(
i) == _pParseNode )
1416 ColumnValue::NULLABLE_UNKNOWN,
1426 pColumn->setName(aNewColName);
1427 pColumn->setRealName(sParameterName);
1442 OUString aColumnName, aTableRange, sColumnAlias;
1443 getColumnRange( pColumnRef, aColumnName, aTableRange, sColumnAlias);
1470 m_pImpl->m_nIncludeMask = _nIncludeMask;
1508 const OUString& rCatalogName,
const OUString& rSchemaName )
1511 "OSQLParseTreeIterator::impl_createTableObject: only to be called for CREATE TABLE statements!" );
1520 "New Created Table",
1524 return aReturnTable;
1532 Reference<XNameAccess> xColumns = _rTable->getColumns();
1533 if ( !xColumns.is() )
1536 Sequence< OUString >
aColNames = xColumns->getElementNames();
1537 const OUString* pBegin =
aColNames.getConstArray();
1538 const OUString* pEnd = pBegin +
aColNames.getLength();
1543 for(;pBegin != pEnd;++pBegin)
1546 Reference< XPropertySet >
xColumn;
1547 if(xColumns->hasByName(*pBegin) && (xColumns->getByName(*pBegin) >>=
xColumn) &&
xColumn.is())
1564 pColumn->setTableName(_rTableAlias);
1565 pColumn->setRealName(*pBegin);
1568 aSelectColumnNames.insert(std::upper_bound(aSelectColumnNames.begin(), aSelectColumnNames.end(),
aName, aCompare),
aName);
1577 if(rColumnName.toChar() ==
'*' && rTableRange.isEmpty())
1582 else if( rColumnName.toChar() ==
'*' && !rTableRange.isEmpty() )
1584 OSQLTables::const_iterator aFind =
m_pImpl->m_pTables->find(rTableRange);
1586 if(aFind !=
m_pImpl->m_pTables->end())
1589 else if ( rTableRange.isEmpty() )
1594 Reference< XPropertySet> xNewColumn;
1598 if ( !
table.second.is() )
1601 Reference<XNameAccess> xColumns =
table.second->getColumns();
1602 Reference< XPropertySet >
xColumn;
1603 if ( !xColumns->hasByName( rColumnName )
1604 || !( xColumns->getByName( rColumnName ) >>=
xColumn )
1611 xNewColumn = pColumn;
1612 pColumn->setTableName(
table.first);
1613 pColumn->setName(aNewColName);
1614 pColumn->setRealName(rColumnName);
1619 if ( !xNewColumn.is() )
1632 ColumnValue::NULLABLE_UNKNOWN,
1644 xNewColumn = pColumn;
1645 pColumn->setRealName( rColumnName );
1655 ColumnValue::NULLABLE_UNKNOWN,0,0,_nType,
false,
false,
isCaseSensitive(),
1656 OUString(),OUString(),OUString());
1657 pColumn->setFunction(
true);
1658 pColumn->setAggregateFunction(bAggFkt);
1659 pColumn->setRealName(rColumnName);
1666 OSQLTables::const_iterator aFind =
m_pImpl->m_pTables->find(rTableRange);
1668 bool bError =
false;
1669 if (aFind !=
m_pImpl->m_pTables->end() && aFind->second.is())
1676 ColumnValue::NULLABLE_UNKNOWN,0,0,_nType,
false,
false,
isCaseSensitive(),
1677 OUString(),OUString(),OUString());
1678 pColumn->setFunction(
true);
1679 pColumn->setAggregateFunction(bAggFkt);
1680 pColumn->setRealName(rColumnName);
1681 SAL_WARN(
"connectivity.parse",
"Trying to construct a column with Function==true and a TableName; this makes no sense.");
1683 pColumn->setTableName(aFind->first);
1689 Reference< XPropertySet >
xColumn;
1690 if (aFind->second->getColumns()->hasByName(rColumnName) && (aFind->second->getColumns()->getByName(rColumnName) >>=
xColumn))
1695 pColumn->setName(aNewColName);
1696 pColumn->setRealName(rColumnName);
1697 pColumn->setTableName(aFind->first);
1714 ColumnValue::NULLABLE_UNKNOWN,0,0,DataType::VARCHAR,
false,
false,
isCaseSensitive(),
1715 OUString(),OUString(),OUString());
1716 pColumn->setFunction(
true);
1717 pColumn->setAggregateFunction(bAggFkt);
1728 std::vector<OUString> aColumnNames;
1731 aColumnNames.push_back(
getString(
col->getPropertyValue(sPropertyName)));
1732 std::sort(aColumnNames.begin(), aColumnNames.end(), aCompare);
1734 return aColumnNames;
1740 if (!std::binary_search(rColumnNames.begin(), rColumnNames.end(), rColumnName, aCompare))
1747 aAlias = rColumnName + OUString::number(
i++);
1749 while (std::binary_search(rColumnNames.begin(), rColumnNames.end(), aAlias, aCompare));
1762 sal_Int32
nId = rColumnName.toInt32();
1767#ifdef SQL_TEST_PARSETREEITERATOR
1768 cout <<
"OSQLParseTreeIterator::setOrderByColumnName: "
1769 << (
const char *) rColumnName <<
", "
1770 << (
const char *) rTableRange <<
", "
1771 << (bAscending ?
"true" :
"false")
1778 Reference<XPropertySet>
xColumn =
findColumn( rColumnName, rTableRange,
false );
1783 sal_Int32
nId = rColumnName.toInt32();
1788#ifdef SQL_TEST_PARSETREEITERATOR
1789 cout <<
"OSQLParseTreeIterator::setGroupByColumnName: "
1790 << (
const char *) rColumnName <<
", "
1791 << (
const char *) rTableRange <<
", "
1792 << (bAscending ?
"true" :
"false")
1808 OSL_ENSURE(
m_pParseTree->
count() >= 4,
"ParseTreeIterator: error in parse tree!");
1810 OSL_ENSURE(pTableExp !=
nullptr,
"OSQLParseTreeIterator: error in parse tree!");
1811 OSL_ENSURE(
SQL_ISRULE(pTableExp,table_exp),
"OSQLParseTreeIterator: error in parse tree!");
1814 pWhereClause = pTableExp->
getChild(1);
1821 if(pWhereClause && pWhereClause->
count() != 2)
1822 pWhereClause =
nullptr;
1823 return pWhereClause;
1841 pParseTree = pParseTree->getChild(3);
1845 assert(
SQL_ISRULE(pParseTree, select_statement));
1849 OSL_ENSURE(pParseTree->count() == 4,
"OSQLParseTreeIterator::getOrderTree: expected a SELECT, and a SELECT must have exactly four children");
1851 OSL_ENSURE(pTableExp !=
nullptr,
"OSQLParseTreeIterator::getOrderTree: got NULL table_exp");
1852 OSL_ENSURE(
SQL_ISRULE(pTableExp, table_exp),
"OSQLParseTreeIterator::getOrderTree: expected table_exp but got something else");
1860 if(pOrderClause->
count() != 3)
1861 pOrderClause =
nullptr;
1862 return pOrderClause;
1873 OSL_ENSURE(
m_pParseTree->
count() >= 4,
"ParseTreeIterator: error in parse tree!");
1875 OSL_ENSURE(pTableExp !=
nullptr,
"OSQLParseTreeIterator: error in parse tree!");
1876 OSL_ENSURE(
SQL_ISRULE(pTableExp,table_exp),
"OSQLParseTreeIterator: error in parse tree!");
1879 pGroupClause = pTableExp->
getChild(2);
1881 if(pGroupClause->
count() != 3)
1882 pGroupClause =
nullptr;
1883 return pGroupClause;
1894 OSL_ENSURE(
m_pParseTree->
count() >= 4,
"ParseTreeIterator: error in parse tree!");
1896 OSL_ENSURE(pTableExp !=
nullptr,
"OSQLParseTreeIterator: error in parse tree!");
1897 OSL_ENSURE(
SQL_ISRULE(pTableExp,table_exp),
"OSQLParseTreeIterator: error in parse tree!");
1900 pHavingClause = pTableExp->
getChild(3);
1902 if(pHavingClause->
count() < 1)
1903 pHavingClause =
nullptr;
1904 return pHavingClause;
1909 return _pTableNode && (
SQL_ISRULE(_pTableNode,catalog_name) ||
1917 return pNode ? pNode->
getChild(1) :
nullptr;
1923 return pNode ? pNode->
getChild(2) :
nullptr;
1929 return pNode ? pNode->
getChild(2) :
nullptr;
1935 return pNode ? pNode->
getChild(1) :
nullptr;
1943 Reference< XPropertySet >
xColumn( lookupColumn );
1948 if (
sName == rColumnName )
1963 if ( !
xColumn.is() && _bLookInSubTables )
1971 Reference< XPropertySet >
xColumn;
1972 if ( !rTableRange.isEmpty() )
1974 OSQLTables::const_iterator aFind = _rTables.find(rTableRange);
1976 if ( aFind != _rTables.end()
1977 && aFind->second.is()
1978 && aFind->second->getColumns().is()
1979 && aFind->second->getColumns()->hasByName(rColumnName) )
1980 aFind->second->getColumns()->getByName(rColumnName) >>=
xColumn;
1984 for (
auto const&
table : _rTables)
1986 if (
table.second.is() )
1988 Reference<XNameAccess> xColumns =
table.second->getColumns();
1989 if( xColumns.is() && xColumns->hasByName(rColumnName) && (xColumns->getByName(rColumnName) >>=
xColumn) )
1991 OSL_ENSURE(
xColumn.is(),
"Column isn't a propertyset!");
2007 if ( _pReplaceToken1 )
2009 bool bTwoTokens = ( _pReplaceToken2 != nullptr );
2010 const char* pPlaceHolder1 = bTwoTokens ?
"#1" :
"#";
2011 const OUString sPlaceHolder1 = OUString::createFromAscii( pPlaceHolder1 );
2013 sErrorMessage = sErrorMessage.replaceFirst( sPlaceHolder1, *_pReplaceToken1 );
2014 if ( _pReplaceToken2 )
2015 sErrorMessage = sErrorMessage.replaceFirst(
"#2" , *_pReplaceToken2 );
2028 SQLException* pErrorChain = &*
m_xErrors;
2029 while ( pErrorChain->NextException.hasValue() )
2030 pErrorChain =
static_cast< SQLException*
>( pErrorChain->NextException.pData );
2031 pErrorChain->NextException <<= _rError;
2039 sal_Int32
nType = DataType::OTHER;
2040 OUString sFunctionName;
2048 nType = DataType::DOUBLE;
2061 OUString sColumnName;
2062 OUString aTableRange;
2064 OSL_ENSURE(!sColumnName.isEmpty(),
"Columnname must not be empty!");
2076 nType = DataType::DOUBLE;
2078 else if (
SQL_ISRULE(pValueExp,datetime_primary) )
2082 case SQL_TOKEN_CURRENT_DATE:
2083 nType = DataType::DATE;
2085 case SQL_TOKEN_CURRENT_TIME:
2086 nType = DataType::TIME;
2088 case SQL_TOKEN_CURRENT_TIMESTAMP:
2089 nType = DataType::TIMESTAMP;
2093 else if (
SQL_ISRULE(pValueExp,value_exp_primary) )
2097 else if (
SQL_ISRULE(pValueExp,concatenation)
2105 nType = DataType::VARCHAR;
2108 if (
nType == DataType::OTHER )
2109 nType = DataType::DOUBLE;
OptionalString sComposedName
virtual OUString getErrorMessage(ErrorCode _eCodes) const =0
void parseNodeToStr(OUString &rString, const css::uno::Reference< css::sdbc::XConnection > &_rxConnection, const IParseContext *pContext=nullptr, bool _bIntl=false, bool _bQuote=true) const
sal_uInt32 getTokenID() const
static OUString getTableRange(const OSQLParseNode *_pTableRef)
return a table range when it exists.
Rule getKnownRuleID() const
returns the ID of the rule represented by the node If the node does not represent a rule,...
static bool getTableComponents(const OSQLParseNode *_pTableNode, css::uno::Any &_rCatalog, OUString &_rSchema, OUString &_rTable, const css::uno::Reference< css::sdbc::XDatabaseMetaData > &_xMetaData)
const OUString & getTokenValue() const
OSQLParseNode * getParent() const
OSQLParseNode * getChild(sal_uInt32 nPos) const
SQLNodeType getNodeType() const
OSQLTable impl_locateRecordSource(const OUString &_rComposedName)
locates a record source (a table or query) with the given name
OSQLStatementType m_eStatementType
::std::unique_ptr< OSQLParseTreeIteratorImpl > m_pImpl
void impl_appendError(IParseContext::ErrorCode _eError, const OUString *_pReplaceToken1=nullptr, const OUString *_pReplaceToken2=nullptr)
appends an SQLException corresponding to the given error code to our error collection
void setSelectColumnName(const OUString &rColumnName, const OUString &rColumnAlias, const OUString &rTableRange, bool bFkt=false, sal_Int32 _nType=css::sdbc::DataType::VARCHAR, bool bAggFkt=false)
void impl_fillJoinConditions(const OSQLParseNode *i_pJoinCondition)
void getSelect_statement(OSQLTables &_rTables, const OSQLParseNode *pSelect)
const ::rtl::Reference< OSQLColumns > & getParameters() const
::rtl::Reference< OSQLColumns > m_aSelectColumns
const OSQLParseNode * getHavingTree() const
::rtl::Reference< OSQLColumns > m_aCreateColumns
static css::uno::Reference< css::beans::XPropertySet > findColumn(const OSQLTables &_rTables, const OUString &rColumnName, OUString &rTableRange)
finds the column with a given name, belonging to a given table, in a given tables collection
static OUString getColumnAlias(const OSQLParseNode *_pDerivedColumn)
return the alias name of a column
bool traverseOrderByColumnNames(const OSQLParseNode *pSelectNode)
::rtl::Reference< OSQLColumns > m_aParameters
void setGroupByColumnName(const OUString &rColumnName, OUString &rTableRange)
std::vector< OUString > getSelectColumnNames() const
void setOrderByColumnName(const OUString &rColumnName, OUString &rTableRange, bool bAscending)
const OSQLParseNode * getSimpleGroupByTree() const
css::uno::Reference< css::beans::XPropertySet > findSelectColumn(std::u16string_view rColumnName)
finds a column with a given name among the select columns
const OSQLParseNode * getGroupByTree() const
void traverseOnePredicate(OSQLParseNode const *pColumnRef, OUString &aValue, OSQLParseNode const *pParameter)
OUString getUniqueColumnName(const std::vector< OUString > &rColumnNames, const OUString &rColumnName) const
void traverseOneTableName(OSQLTables &_rTables, const OSQLParseNode *pTableName, const OUString &rTableRange)
void appendColumns(const OUString &_rTableAlias, const OSQLTable &_rTable)
bool traverseGroupByColumnNames(const OSQLParseNode *pSelectNode)
bool traverseSelectionCriteria(const OSQLParseNode *pSelectNode)
const OSQLTables & getTables() const
void traverseByColumnNames(const OSQLParseNode *pSelectNode, bool _bOrder)
void getColumnRange(const OSQLParseNode *_pColumnRef, OUString &_rColumnName, OUString &_rTableRange) const
return the columname and the table range
void setParseTree(const OSQLParseNode *pNewParseTree)
const OSQLParseNode * getOrderTree() const
const OSQLParser & m_rParser
void impl_getQueryParameterColumns(const OSQLTable &_rQuery)
retrieves the parameter columns of the given query
const OSQLParseNode * getSimpleHavingTree() const
static bool isTableNode(const OSQLParseNode *_pTableNode)
bool traverseSelectColumnNames(const OSQLParseNode *pSelectNode)
traverses columns in a SELECT statement
::std::vector< TNodePair > & getJoinConditions() const
sal_Int32 getFunctionReturnType(const OSQLParseNode *_pNode)
void impl_traverse(TraversalParts _nIncludeMask)
implementation for both traverseAll and traverseSome
void traverseCreateColumns(const OSQLParseNode *pSelectNode)
traverses columns in a CREATE TABLE statement
void traverseParameters(const OSQLParseNode *pSelectNode)
std::optional< css::sdbc::SQLException > m_xErrors
OSQLTable impl_createTableObject(const OUString &rTableName, const OUString &rCatalogName, const OUString &rSchemaName)
creates a table object and inserts it into our tables collection
bool isCaseSensitive() const
void getQualified_join(OSQLTables &_rTables, const OSQLParseNode *pTableRef, OUString &aTableRange)
void traverseSearchCondition(OSQLParseNode const *pSearchCondition)
const OSQLParseNode * getSimpleWhereTree() const
OSQLStatementType getStatementType() const
void traverseAll()
traverses the complete statement tree, and fills all our data with the information obatined during tr...
void traverseParameter(const OSQLParseNode *_pParseNode, const OSQLParseNode *_pColumnRef, const OUString &_aColumnName, OUString &_aTableRange, const OUString &_rColumnAlias)
::rtl::Reference< OSQLColumns > m_aGroupColumns
const OSQLParseNode * m_pParseTree
const OSQLParseNode * getWhereTree() const
::rtl::Reference< OSQLColumns > m_aOrderColumns
bool traverseTableNames(OSQLTables &_rTables)
traverses the list of table names, and fills _rTables
const OSQLParseNode * getSimpleOrderTree() const
const OSQLParseNode * getTableNode(OSQLTables &_rTables, const OSQLParseNode *pTableRef, OUString &aTableRange)
static sal_Int32 getFunctionParameterType(sal_uInt32 _nTokenId, sal_uInt32 _nPos)
static sal_Int32 getFunctionReturnType(std::u16string_view _sFunctionName, const IParseContext *pContext)
const SQLError & getErrorHelper() const
access to the SQLError instance owned by this parser
const IParseContext & getContext() const
css::sdbc::SQLException getSQLException(const ErrorCondition _eCondition, const css::uno::Reference< css::uno::XInterface > &_rxContext, const std::optional< OUString > &_rParamValue1=std::nullopt, const std::optional< OUString > &_rParamValue2=std::nullopt, const std::optional< OUString > &_rParamValue3=std::nullopt) const
retrieves an SQLException object which contains information about the given error condition
OString exceptionToString(const css::uno::Any &caught)
#define DBG_UNHANDLED_EXCEPTION(...)
FastSaxParserImpl & m_rParser
#define SAL_WARN(area, stream)
RttiCompleteObjectLocator col
bool getBOOL(const Any &_rAny)
sal_Int32 getINT32(const Any &_rAny)
OUString getString(const Any &_rAny)
std::map< OUString, OSQLTable, comphelper::UStringMixLess > OSQLTables
ORefVector< css::uno::Reference< css::beans::XPropertySet > > OSQLColumns
css::uno::Reference< css::sdbcx::XColumnsSupplier > OSQLTable
::std::pair< const OSQLParseNode *, const OSQLParseNode * > TNodePair
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
Reference< XConnection > m_xConnection
#define PROPERTY_ID_TABLENAME
#define PROPERTY_ID_DESCRIPTION
#define PROPERTY_ID_CATALOGNAME
#define PROPERTY_ID_ISNULLABLE
#define PROPERTY_ID_COMMAND
#define PROPERTY_ID_PRECISION
#define PROPERTY_ID_SCHEMANAME
#define PROPERTY_ID_ISAUTOINCREMENT
#define PROPERTY_ID_ISCURRENCY
#define PROPERTY_ID_TYPENAME
#define PROPERTY_ID_DEFAULTVALUE
#define PROPERTY_ID_REALNAME
#define PROPERTY_ID_ESCAPEPROCESSING
#define PROPERTY_ID_SCALE
const Color aColNames[SC_RANGECOLORS]
std::shared_ptr< QueryNameSet > & m_rpAllForbiddenNames
OUString m_sForbiddenQueryName
#define SQL_ISRULE(pParseNode, eRule)
#define ORDER_BY_CHILD_POS
#define TABLE_EXPRESSION_CHILD_COUNT
#define SQL_ISPUNCTUATION(pParseNode, aString)
#define SQL_ISTOKEN(pParseNode, token)
#define SQL_ISRULEOR2(pParseNode, e1, e2)
TraversalParts m_nIncludeMask
bool isQueryAllowed(const OUString &_rQueryName)
std::vector< TNodePair > m_aJoinConditions
OSQLParseTreeIteratorImpl(const Reference< XConnection > &_rxConnection, const Reference< XNameAccess > &_rxTables)
Reference< XDatabaseMetaData > m_xDatabaseMetaData
std::shared_ptr< OSQLTables > m_pTables
std::shared_ptr< QueryNameSet > m_pForbiddenQueryNames
Reference< XNameAccess > m_xQueryContainer
Reference< XConnection > m_xConnection
Reference< XNameAccess > m_xTableContainer
std::shared_ptr< OSQLTables > m_pSubTables