Usina BRAdvPL Guide
Sign in
← All topics
CLASSUnder review

FWPreparedStatement

FWPreparedStatement():New([cQuery])

Binds typed values to query parameters.

FWPreparedStatementAdvPL
01 · OVERVIEW

Overview

SetQuery accepts ? markers and SetString/SetDate/SetNumeric bind one-based positions. GetFixQuery returns SQL with treated/substituted values rather than executing it. Table identifiers are not values and need controlled sources; SetUnsafe must not receive HTTP input. thalysjuvenal demonstrates this pattern on business tables; the adaptation only prepares a teaching-table SELECT without executing SQL or accessing records. Its claim that lists lack native expansion is not universal: TDN documents SetIn. (Sources: refs. 1–2.)

02 · SYNTAX

Syntax

FWPreparedStatement():New([cQuery])

Methods

SetQuerySets SQL with ? markers.o:SetQuery(cQuery)
SetStringText value without adding SQL quotes manually.o:SetString(nParam,cValue)
GetFixQueryGets the treated query rather than executing it.o:GetFixQuery() --> cQuery
DestroyReleases the statement object.o:Destroy()
03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed444()
    Local oStatement := FWPreparedStatement():New()
    // Teaching table; prepare only without execution.
    oStatement:SetQuery("SELECT ED_CODE FROM ED_TEST WHERE ED_CODE = ?")
    oStatement:SetString(1,"ED01")
    // No ExecuteQuery or TCSqlExec.
    oStatement:Destroy()
Return Nil
Expected result

Object with one bound parameter then destroyed; no query executed. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Check LIB version, lifecycle and context before integration. These methods are a documented subset rather than the complete API.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. FWPreparedStatement. TDN. Accessed on 2026-10-27.
  2. thalysjuvenal/advpl-specialist. patterns-fwpreparedstatement.md, commit d80599b75e30e7f559218b453d72b84999f138a4. Referência e exemplos analisados. Accessed on 2026-10-27.
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