本文说明 src/op/RCP.h 中 RcpMgr 的配方定义、获取和控件绑定接口。当前实现仍有未完成方法与 SQL 安全限制,使用前请完整阅读注意事项。
#include "op/RCP.h"
using namespace stt;
using namespace stt::op;
using namespace stt::data;
使用前需要:
| API | 作用 | 当前状态 |
|---|---|---|
| allRecipes | 查询全部配方定义 | 可用 |
| add | 新增配方定义和数据表 | 可用但错误检查不足 |
| remove | 删除定义及底层表 | 可用,破坏性 |
| get | 获取已有 TRecipe 或按定义创建 | 所有权约定需谨慎 |
| bind | 把已注册的配方变量绑定到控件 | 仅适合 STTTable |
| exportAs | 导出配方 | TODO,始终 false |
| importFrom | 导入配方 | TODO,始终 false |
static TTable allRecipes();
返回列为 RID、RNAME、RTBL:
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);
}
默认数据库为空或尚未初始化时不能可靠调用。
static int add(
const string& name,
const string& defs,
const string& vars
);
返回值:
| 值 | 含义 |
|---|---|
| 0 | 当前实现认为成功 |
| 1 | 同名配方已存在 |
| 2 | name 或 defs 为空 |
示例:
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 是“列名:变量名”的逗号列表。
当前实现限制: