Search code examples
mysqlprepared-statementballerina

Parameterising order column name and sort order for MySQL queries in Ballerina


I need to parameterise the ordering column name and sort order (ASC/DESC) in a sql:ParameterizedQuery.

i.e:

`SELECT * FROM <TABLE_NAME> ORDER BY ${<COLUMN_NAME>} ${<SORT_ORDER>}`

Here is the code I tried to use, but this doesn't seems to be working.

sqlQuery = sql:queryConcat( sqlQuery, ` ORDER BY ${'order.columnName} ${'order.sortOrder}`)

I guess only the values are supported as params in sql:ParameterizedQuery.


Solution

  • Yes, only values are supported as params. For this use case, multiple sql:ParameterizedQuery needs to be defined.

    The specific query can be selected using a match case.