Mercurial > hg > orthanc
comparison OrthancServer/Sources/Search/ISqlLookupFormatter.cpp @ 5830:40f236ad829c find-refactoring
SQLite 3.46 + push NULL values at the end of the order by clauses
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 08 Oct 2024 17:05:18 +0200 |
parents | 7030fa489669 |
children |
comparison
equal
deleted
inserted
replaced
5829:963945d780d6 | 5830:40f236ad829c |
---|---|
757 default: | 757 default: |
758 throw OrthancException(ErrorCode_InternalError); | 758 throw OrthancException(ErrorCode_InternalError); |
759 } | 759 } |
760 orderingJoins += orderingJoin; | 760 orderingJoins += orderingJoin; |
761 | 761 |
762 std::string orderByField = "order" + boost::lexical_cast<std::string>(counter) + ".value"; | 762 std::string orderByField; |
763 | |
764 #if ORTHANC_SQLITE_VERSION < 3030001 | |
765 // this is a way to push NULL values at the end before "NULLS LAST" was introduced: | |
766 // first filter by 0/1 and then by the column value itself | |
767 orderByField += "order" + boost::lexical_cast<std::string>(counter) + ".value IS NULL, "; | |
768 #endif | |
769 orderByField += "order" + boost::lexical_cast<std::string>(counter) + ".value"; | |
770 | |
763 if ((*it)->GetDirection() == FindRequest::OrderingDirection_Ascending) | 771 if ((*it)->GetDirection() == FindRequest::OrderingDirection_Ascending) |
764 { | 772 { |
765 orderByField += " ASC"; | 773 orderByField += " ASC"; |
766 } | 774 } |
767 else | 775 else |
772 ++counter; | 780 ++counter; |
773 } | 781 } |
774 | 782 |
775 std::string orderByFieldsString; | 783 std::string orderByFieldsString; |
776 Toolbox::JoinStrings(orderByFieldsString, orderByFields, ", "); | 784 Toolbox::JoinStrings(orderByFieldsString, orderByFields, ", "); |
777 ordering = "ROW_NUMBER() OVER (ORDER BY " + orderByFieldsString + ") AS rowNumber"; | 785 |
786 ordering = "ROW_NUMBER() OVER (ORDER BY " + orderByFieldsString; | |
787 #if ORTHANC_SQLITE_VERSION >= 3030001 | |
788 ordering += " NULLS LAST"; | |
789 #endif | |
790 ordering += ") AS rowNumber"; | |
778 } | 791 } |
779 else | 792 else |
780 { | 793 { |
781 ordering = "ROW_NUMBER() OVER (ORDER BY " + strQueryLevel + ".publicId) AS rowNumber"; // we need a default ordering in order to make default queries repeatable when using since&limit | 794 ordering = "ROW_NUMBER() OVER (ORDER BY " + strQueryLevel + ".publicId) AS rowNumber"; // we need a default ordering in order to make default queries repeatable when using since&limit |
782 } | 795 } |