embedded-sql

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Embedded SQL in ADVPL/TLPP

ADVPL/TLPP 中的嵌入式 SQL

This skill covers writing SQL inside ADVPL/TLPP using
BeginSQL ... EndSQL
blocks and their special macro expressions --
%table:TABLE%
for physical table resolution,
%xfilial:TABLE%
for branch filtering,
%notDel%
for logical-deletion filtering,
%exp:EXPRESSION%
for safe variable binding, and
%Order:TABLE%
for primary-key ordering. It also covers
column
type declarations, JOIN and aggregation patterns, subqueries, and migrating legacy
TCQuery
string-concatenation code to Embedded SQL.
Activate this skill whenever the user is writing a new query, reviewing an existing one for correctness/safety, or converting old concatenated-string SQL to the modern BeginSQL syntax. It also covers the restrictions and gotchas of BeginSQL (no
*
at line start, always include
%notDel%
and filial filtering, use
GetNextAlias()
, close aliases) and when to use
TCSqlExec
instead for INSERT/UPDATE/DELETE.
It does not cover general native function lookups unrelated to SQL (see
protheus-reference
), business-process context for which tables/fields to query (see
protheus-business
), or generating documentation for a routine that happens to contain SQL (see
documentation-patterns
).
Reference fileRead when
reference.mdAlways -- BeginSQL syntax, macro expressions, JOIN/aggregation/subquery patterns, DML via TCSqlExec, performance tips, and TCQuery migration
本技能涵盖在ADVPL/TLPP中使用
BeginSQL ... EndSQL
块及其特殊宏表达式编写SQL的相关内容——包括用于物理表解析的
%table:TABLE%
、用于分支过滤的
%xfilial:TABLE%
、用于逻辑删除过滤的
%notDel%
、用于安全变量绑定的
%exp:EXPRESSION%
,以及用于主键排序的
%Order:TABLE%
。同时还涵盖
column
类型声明、JOIN与聚合模式、子查询,以及将遗留
TCQuery
字符串拼接代码迁移至嵌入式SQL的方法。
当用户编写新查询、审查现有查询的正确性与安全性,或将旧的字符串拼接SQL转换为现代BeginSQL语法时,均可激活本技能。本技能还涵盖BeginSQL的限制与常见陷阱(行首不能出现
*
、必须包含
%notDel%
和分支过滤条件、使用
GetNextAlias()
、及时关闭别名),以及何时改用
TCSqlExec
执行INSERT/UPDATE/DELETE操作。
本技能不涵盖与SQL无关的通用原生函数查询(参见
protheus-reference
)、涉及待查询表/字段选择的业务流程上下文(参见
protheus-business
),或为包含SQL的例程生成文档的相关内容(参见
documentation-patterns
)。
参考文件阅读场景
reference.md始终阅读——包含BeginSQL语法、宏表达式、JOIN/聚合/子查询模式、通过TCSqlExec执行DML、性能优化技巧以及TCQuery迁移相关内容