Kaydet (Commit) 48c33e89 authored tarafından Michael Stahl's avatar Michael Stahl Kaydeden (comit) Lionel Elie Mamane

connectivity: fdo#43479: fix crash on DISTINCT:

Since commit f89f2b8b,
OResultSet::sortRows() works on the rows after SELECT, not on full rows.
So OResultSet::OpenImpl() has to be adapted to not use the mapping from
selected columns to entries rows in m_aColMapping any more; instead,
use the given ORDER BY clause for sorting.
But first extend the sort order to cover all columns, so it is no longer
necessary to call sortRows twice (this should be legal, because SQL says
the order of rows that are equal in ORDER BY columns is unspecified).
Signed-off-by: 's avatarLionel Elie Mamane <lionel@mamane.lu>
üst 95372ec1
...@@ -1438,26 +1438,29 @@ sal_Bool OResultSet::OpenImpl() ...@@ -1438,26 +1438,29 @@ sal_Bool OResultSet::OpenImpl()
else else
{ {
sal_Bool bDistinct = sal_False; sal_Bool bDistinct = sal_False;
sal_Bool bWasSorted = sal_False;
OSQLParseNode *pDistinct = m_pParseTree->getChild(1); OSQLParseNode *pDistinct = m_pParseTree->getChild(1);
::std::vector<sal_Int32> aOrderbyColumnNumberSave;
::std::vector<TAscendingOrder> aOrderbyAscendingSave;
assert(m_aOrderbyColumnNumber.size() ==
m_aOrderbyAscending.size());
if (pDistinct && pDistinct->getTokenID() == SQL_TOKEN_DISTINCT ) if (pDistinct && pDistinct->getTokenID() == SQL_TOKEN_DISTINCT )
{ {
// Sort on all columns, saving original order for later // To eliminate duplicates we need to sort on all columns.
if(IsSorted()) // This is not a problem because the SQL spec says that the
// order of columns that are not specified in ORDER BY
// clause is undefined, so it doesn't hurt to sort on
// these; pad the vectors to include them.
for (sal_Int32 i = 1; // 0: bookmark (see setBoundedColumns)
static_cast<size_t>(i) < m_aColMapping.size(); ++i)
{ {
aOrderbyColumnNumberSave = m_aOrderbyColumnNumber; if (::std::find(m_aOrderbyColumnNumber.begin(),
m_aOrderbyColumnNumber.clear(); m_aOrderbyColumnNumber.end(), i)
aOrderbyAscendingSave.assign(m_aOrderbyAscending.begin(), m_aOrderbyAscending.end()); == m_aOrderbyColumnNumber.end())
bWasSorted = sal_True; {
m_aOrderbyColumnNumber.push_back(i);
// ASC or DESC doesn't matter
m_aOrderbyAscending.push_back(SQL_ASC);
}
} }
// the first column is the bookmark column
::std::vector<sal_Int32>::iterator aColStart = (m_aColMapping.begin()+1);
::std::copy(aColStart, m_aColMapping.end(),::std::back_inserter(m_aOrderbyColumnNumber));
m_aOrderbyAscending.assign(m_aColMapping.size()-1, SQL_ASC);
bDistinct = sal_True; bDistinct = sal_True;
} }
...@@ -1539,23 +1542,6 @@ sal_Bool OResultSet::OpenImpl() ...@@ -1539,23 +1542,6 @@ sal_Bool OResultSet::OpenImpl()
m_pFileSet->get().erase(::std::remove_if(m_pFileSet->get().begin(),m_pFileSet->get().end(), m_pFileSet->get().erase(::std::remove_if(m_pFileSet->get().begin(),m_pFileSet->get().end(),
::std::bind2nd(::std::equal_to<sal_Int32>(),0)) ::std::bind2nd(::std::equal_to<sal_Int32>(),0))
,m_pFileSet->get().end()); ,m_pFileSet->get().end());
if (bWasSorted)
{
// Re-sort on original requested order
m_aOrderbyColumnNumber = aOrderbyColumnNumberSave;
m_aOrderbyAscending.assign(aOrderbyAscendingSave.begin(), aOrderbyAscendingSave.end());
TIntVector aEvaluationKeySet(m_pFileSet->get());
m_pEvaluationKeySet = &aEvaluationKeySet;
sortRows();
}
else
{
m_aOrderbyColumnNumber.clear();
m_aOrderbyAscending.clear();
::std::sort(m_pFileSet->get().begin(),m_pFileSet->get().end());
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment