菜单

RCP.h 使用手册

下载

RCP.h 使用手册

本文说明 src/op/RCP.h 中 RcpMgr 的配方定义、获取和控件绑定接口。当前实现仍有未完成方法与 SQL 安全限制,使用前请完整阅读注意事项。

1. 引入与前提

cpp 复制代码
#include "op/RCP.h"

using namespace stt;
using namespace stt::op;
using namespace stt::data;

使用前需要:

  • 全局 Runtime 已初始化。
  • 默认数据库可用。
  • 变量管理器中存在配方映射所引用的变量。
  • 页面表格若用于绑定,应为 STTTable。

2. API 总览

API 作用 当前状态
allRecipes 查询全部配方定义 可用
add 新增配方定义和数据表 可用但错误检查不足
remove 删除定义及底层表 可用,破坏性
get 获取已有 TRecipe 或按定义创建 所有权约定需谨慎
bind 把已注册的配方变量绑定到控件 仅适合 STTTable
exportAs 导出配方 TODO,始终 false
importFrom 导入配方 TODO,始终 false

3. 查询全部配方

cpp 复制代码
static TTable allRecipes();

返回列为 RID、RNAME、RTBL:

cpp 复制代码
TTable recipes = RcpMgr::allRecipes();
for (int row = 0; row < recipes.getRowCount(); ++row) {
    string id        = recipes.getValue(row, 0);
    string name      = recipes.getValue(row, 1);
    string tableName = recipes.getValue(row, 2);
}

默认数据库为空或尚未初始化时不能可靠调用。

4. 新增配方

cpp 复制代码
static int add(
    const string& name,
    const string& defs,
    const string& vars
);

返回值:

值 含义
0 当前实现认为成功
1 同名配方已存在
2 name 或 defs 为空

示例:

cpp 复制代码
int rc = RcpMgr::add(
    "ProductA",
    "Speed,Temperature,Duration",
    "Speed:PLC.Speed,Temperature:PLC.Temp,Duration:PLC.Time"
);

if (rc == 1) {
    // 同名
} else if (rc == 2) {
    // 参数为空
}

defs 是逗号分隔的 SQL 列名,vars 是“列名:变量名”的逗号列表。

当前实现限制:

  • defs 直接拼入 CREATE TABLE,没有标识符校验或引号保护。只能使用受控的简单列名,建议限定为英文字母、数字和下划线,且不能以数字开头。
  • vars 中不是恰好由一个冒号拆成两段的项会被静默忽略。
  • 不验证 vars 左侧列名是否真的存在于 defs。
  • 重名查询会转义 name,但后续 INSERT 直接使用原 name;name 或变量名含单引号会破坏 SQL。
  • 代码开始事务后没有显式 commit/rollback,并忽略批量 execute 的结果,最后仍可能返回 0。
最近修改: 2026-10-21Powered by