summaryrefslogtreecommitdiff
path: root/connectivity
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2012-01-19 15:25:07 +0100
committerLionel Elie Mamane <lionel@mamane.lu>2012-01-23 15:54:23 +0100
commit48c33e89fe7398c05f2af6c49c75fa2bedf36859 (patch)
tree59faa960da2fb497bd7a865c458870057dec895f /connectivity
parent95372ec15484a74c8956cda869c55138dc318daf (diff)
connectivity: fdo#43479: fix crash on DISTINCT:
Since commit f89f2b8bf506de0cc547ad596c75cbe1a0cf1ef1, 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: Lionel Elie Mamane <lionel@mamane.lu>
Diffstat (limited to 'connectivity')
-rw-r--r--connectivity/source/drivers/file/FResultSet.cxx48
1 files changed, 17 insertions, 31 deletions
diff --git a/connectivity/source/drivers/file/FResultSet.cxx b/connectivity/source/drivers/file/FResultSet.cxx
index 43b7827beeb2..3316e3712ec7 100644
--- a/connectivity/source/drivers/file/FResultSet.cxx
+++ b/connectivity/source/drivers/file/FResultSet.cxx
@@ -1438,26 +1438,29 @@ sal_Bool OResultSet::OpenImpl()
else
{
sal_Bool bDistinct = sal_False;
- sal_Bool bWasSorted = sal_False;
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 )
{
- // Sort on all columns, saving original order for later
- if(IsSorted())
+ // To eliminate duplicates we need to sort on all columns.
+ // 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;
- m_aOrderbyColumnNumber.clear();
- aOrderbyAscendingSave.assign(m_aOrderbyAscending.begin(), m_aOrderbyAscending.end());
- bWasSorted = sal_True;
+ if (::std::find(m_aOrderbyColumnNumber.begin(),
+ m_aOrderbyColumnNumber.end(), i)
+ == m_aOrderbyColumnNumber.end())
+ {
+ 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;
}
@@ -1539,23 +1542,6 @@ sal_Bool OResultSet::OpenImpl()
m_pFileSet->get().erase(::std::remove_if(m_pFileSet->get().begin(),m_pFileSet->get().end(),
::std::bind2nd(::std::equal_to<sal_Int32>(),0))
,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());
- }
}
}
}