Usina BRAdvPL Guide
Sign in
← All topics
PRACTICAL GUIDEUnder review

ChangeQuery and database compatibility

Adapts query syntax before opening it through DBAccess.

ChangeQuery and database compatibilityAdvPL
01 · OVERVIEW

Overview

ChangeQuery(cQuery) returns SQL text adapted to the current database without opening a cursor or executing the query. Documentation requires ANSI syntax, recommends WHERE and describes parser limits: it does not guarantee compatibility for every database-native function. The community TCGenQry.PRW transforms text before TCGenQry/DbUseArea; that example does not explicitly constrain branch, so it must not be copied as an access policy. The editorial example uses a fictional table and only measures returned text. For actual queries, review RetSqlName, branch and logical-deletion filters and bound parameters. (TOTVS, n.d., ref. 1; EURAI, n.d., ref. 2)

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"
User Function Ed299()
    Local cSql := "SELECT CODIGO FROM LIVROS WHERE 1 = 1"
    Local cAdapted
    // Fictional table; no query is opened.
    cAdapted := ChangeQuery(cSql)
    ConOut(cValToChar(Len(cAdapted)))
Return Nil
Expected result

Length depends on parser and database; there is no record set or fixed numeric result. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Do not use ChangeQuery as input sanitization or authorization. Test the query and plan on supported target databases.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. ChangeQuery. TDN. Accessed on 2026-10-26.
  2. EURAI. TCGenQry.PRW. universo_do_desenvolvedor_site, commit a5c83e9490302bdb4a0fc5a9d92c2d569a60773c. Exemplo analisado, sem reprodução integral. Accessed on 2026-10-26.
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