Database operations
RetSqlName(cAlias); xFilial(cAlias); ChangeQuery(cSQL)Separates reading, writing and access context in Protheus.
Overview
DBAccess access retains Protheus conventions: physical names from RetSqlName, per-table branches from xFilial and logical deletion through D_E_L_E_T_. SQL reads need explicit fields, type adjustment when necessary and cursor cleanup. Writes must follow process rules, permissions and APIs; a direct UPDATE does not execute business logic. This example only builds SQL without opening a cursor or modifying data. (Sources: refs. 1–1.)
Syntax
RetSqlName(cAlias); xFilial(cAlias); ChangeQuery(cSQL)Commented example
#Include "Protheus.ch"
User Function Ed516()
Local cSQL := "SELECT A1_COD,A1_LOJA FROM "+RetSqlName("SA1")
// Build only; no query or write is executed.
cSQL += " WHERE A1_FILIAL = '"+xFilial("SA1")+"'"
cSQL += " AND D_E_L_E_T_ = ' '"
ConOut(ValType(cSQL))
Return NilPrints C. Reading data requires controlled execution and cursor handling. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Do not concatenate untrusted input into SQL. Validate permissions, branch scope, transactions and write errors. Save and restore work areas.
- Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.