Usina BRAdvPL Guide
Sign in
← All topics
PRACTICAL GUIDEUnder review

SqlOrder and conversion of AdvPL index expressions to SQL

SqlOrder(cIndexExpression) -> cSqlFields

Examines conversion of an index expression for ORDER BY.

SqlOrder and conversion of AdvPL index expressions to SQLAdvPL
01 · OVERVIEW

Overview

Atilio’s example passes IndexKey to SqlOrder and describes concatenated fields becoming an SQL list. This is community evidence, not a universal AdvPL-expression translator: functions, qualifiers, collation and DBMS rules need checks. It neither creates a physical index nor independently adds ORDER BY. The block uses a fixed teaching expression without changing table order or interpolating external input. (Sources: refs. 1–1.)

02 · SYNTAX

Syntax

SqlOrder(cIndexExpression) -> cSqlFields
03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed672()
    // Uninvoked block: verify conversion before embedding it in SQL.
    Local bConvert := {|| SqlOrder("B1_FILIAL+B1_COD")}
    ConOut(ValType(bConvert))
Return Nil
Expected result

Creates block B; B1_FILIAL, B1_COD is source-described behavior, not measured here. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Do not concatenate user-provided sort expressions. Allowlist fields and validate SQL on the target DBMS.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. Atilio. dan-atilio/AdvPL. Maratona de Exemplos/Exemplo_454_Funcao_SqlOrder.prw. Arquivo completo consultado; adaptação editorial. Accessed on 2026-10-28.
Status
Under review
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha