---
name: Query Builder
slug: query-builder
category: AI Engineering
description: Query Builder helps build, choose, and optimize SQL against Protheus ERP tables. It covers DbSeek versus Embedded SQL, mandatory D_E_L_E_T_/xFilial filters, index-aligned WHERE clauses, and parameterized queries for safer cross-database use.
github: "https://github.com/thalysjuvenal/advpl-specialist/tree/main/skills/query-builder"
language: Shell
stars: 186
forks: 37
install: "npx degit https://github.com/thalysjuvenal/advpl-specialist/tree/main/skills/query-builder ~/.claude/skills/query-builder"
installs_to: ~/.claude/skills/query-builder
source_path: skills/query-builder/SKILL.md
collection_size: 18
category_size: 3278
collection_url: "https://dirskills.com/collections/thalysjuvenal/advpl-specialist"
added: 2026-09-06T05:20:29.820Z
last_synced: 2026-09-06T05:20:29.820Z
canonical_url: "https://dirskills.com/skills/query-builder"
---

# Query Builder

Query Builder helps build, choose, and optimize SQL against Protheus ERP tables. It covers DbSeek versus Embedded SQL, mandatory D_E_L_E_T_/xFilial filters, index-aligned WHERE clauses, and parameterized queries for safer cross-database use.

**Install:**

```bash
npx degit https://github.com/thalysjuvenal/advpl-specialist/tree/main/skills/query-builder ~/.claude/skills/query-builder
```

## README

# Protheus Query Builder

This skill helps build correct, safe, and optimized SQL against Protheus ERP tables, respecting the platform's database conventions: mandatory soft-delete (`D_E_L_E_T_`) and multi-branch (`xFilial`) filters, Hungarian-notation field names, dictionary-driven physical schemas (`RetSqlName()`), and SIX index alignment. It guides the agent to choose the right access pattern -- Workarea navigation vs Embedded SQL vs raw `TCSqlExec` -- enforce mandatory filters, order `WHERE` clauses to match available indexes, and parameterize every dynamic value with `FWPreparedStatement` to eliminate injection risk.

Activate this skill when building any query against Protheus tables (standard `SA*`/`SE*`/`SF*` or custom `Z*`), deciding between `DbSelectArea`/`DbSeek` and Embedded SQL, reviewing code for missing mandatory filters, adding parameterized queries, diagnosing slow queries via index misalignment, or writing cross-database code. It does not cover `BeginSQL`/`EndSQL` macro syntax itself (see `embedded-sql`, its companion skill for macro details), nor record locking semantics during writes (see `protheus-locks-deadlocks`).

| Reference file | Read when |
|---|---|
| reference.md | Always -- database conventions, table/field naming, mandatory filters, pattern-choice overview |
| patterns-workarea.md | Generating record-by-record code with `DbSelectArea` + `DbSeek` + `RecLock` |
| patterns-fwpreparedstatement.md | Building parameterized `TCQuery`/`TCSqlExec`, LIKE clauses, INSERT/UPDATE/DELETE |
| index-awareness.md | Choosing/validating an index, ordering WHERE clauses, common SIX key expressions |
| cross-database.md | Using `ChangeQuery()`, `TCGetDB()`, DBAccess macros, MSSQL/PostgreSQL/Oracle equivalents |
