Give us feedback
encodingsortforsql
Service icon

EncodingSortForSQL

Stable version 1.2.0 (Compatible with OutSystems 11)
Uploaded on 31 October 2023 by 
5.0
 (1 rating)
encodingsortforsql

EncodingSortForSQL

Documentation
1.2.0

Installation

To install EncodingSortForSQL and use it in your project, you just need to follow the steps below:

  1. Install the component from the OutSystems Forge.
  2. Add a dependency to the module called EncodingSortForSQL_Lib.
  3. Check BuildSafe_SortClause to sanitize dynamic sort orders.
  4. Additionally check TextToSortAttributes if you need to parse a string to SortAttributes to be sanitizes with BuildSafe_SortClause.
  5. Click on “Apply”.

Both server actions use the structure SortAttribute which should be checked automatically, otherwise check it manually.

The sever action DEPRECATED_EncodingSortForSQL is only required if you are upgrading from a former version of this component for backward compatibility, but you should consider replacing it soon.

Usage

There are two options to use the library:

As function call in an expression

If no manipulation of the sort criteria is desired, the new server actions can be used directly as a function in an expression, as was possible with EncodingSortForSQL.

BuildSafe_SortClause(
  TextToSortAttributes(Text, Default)
)
  • The first parameter Text (former name: SortForAggregate) is the dynamic sort string received from the UI table control.
  • The second parameter Default allows passing a fallback sort in case the first parameter is an empty string. This suppresses SQL errors due to an invalid sort clause.
  • Both parameters allow using multiple columns, separated by a comma (e.g. "LastName, FirstName").


As separate elements in a flow

Alternatively, both server actions can also be used as individual elements in a flow. This allows to access the list generated with TextToSortAttributes and manipulate the sort order before using BuildSafe_SortClause to generate the sanitized text to be used in the advanced SQL. This is useful to add or remove attributes or to force a special order, for example.

Demo App

This component also comes with a demo app that lets you try out both functions and shows how to use them.


1.1.0

EncodingSortForSQL is a simple function to encode a dynamic sort string that can be used in an advanced SQL query. The implementation is based on the article How to enable dynamic sorting in a table fed by a SQL query. Since the component provides a function, it can be called directly in the parameter of the advanced SQL action as an expression:

  • The first parameter is the dynamic sort string received from the UI table control.
  • The second parameter allows passing a fallback sort in case the first parameter is an empty string. This suppresses SQL errors due to an invalid sort clause.
  • Both parameters allow using multiple columns, separated by a comma (e.g. "LastName, FirstName").