/*
 * vl_threshold_dbio.pgc - 규칙 임계치 조회 (libvldbio.a).
 * ECPG functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "vl_threshold_dbio.h"

long vldb_rule_threshold(const char *rule_code)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_thr; char h_rule[32];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_rule, rule_code, sizeof(h_rule)-1); h_rule[sizeof(h_rule)-1] = 0;
    EXEC SQL SELECT threshold INTO :h_thr FROM vl_rule
        WHERE rule_code = :h_rule AND status = 'ACTIVE';
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) { userlog("vldb_rule_threshold FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_thr;
}
