Skip to content

Commit 516a492

Browse files
authored
Merge pull request #3828 from ricardopintottrdata/fix_issue_887
fix 'filter with empty name' error
2 parents 88330e5 + 94ad3ae commit 516a492

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/searchdsql.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,8 +1806,25 @@ bool SqlParser_c::AddNullFilter ( const SqlNode_t & tCol, bool bEqualsNull )
18061806

18071807
void SqlParser_c::AddHaving ()
18081808
{
1809-
assert ( m_pQuery->m_dFilters.GetLength() );
1810-
m_pQuery->m_tHaving = m_pQuery->m_dFilters.Pop();
1809+
assert ( m_pQuery->m_dFilters.GetLength() );
1810+
1811+
// The filter we are about to move to HAVING has index (length-1).
1812+
// After Pop(), GetLength() equals that index.
1813+
const int iExpectHavingIdx = m_pQuery->m_dFilters.GetLength() - 1;
1814+
m_pQuery->m_tHaving = m_pQuery->m_dFilters.Pop();
1815+
1816+
// FIX(#887): The filter tree still contains a leaf for the just-moved HAVING filter.
1817+
// That leaf must be the *last* tree item and must reference the same filter index.
1818+
if ( m_dFilterTree.GetLength() > 0 )
1819+
{
1820+
const int iLastFilterItem = m_dFilterTree.Last().m_iFilterItem;
1821+
// Assert the tree's last leaf matches the moved filter.
1822+
assert ( iLastFilterItem == iExpectHavingIdx && "HAVING leaf must be the last filter-tree item" );
1823+
1824+
// Remove that dangling leaf so WHERE's CreateFilterTree() won't see an empty-name filter.
1825+
if ( iLastFilterItem == iExpectHavingIdx )
1826+
m_dFilterTree.Pop();
1827+
}
18111828
}
18121829

18131830

0 commit comments

Comments
 (0)