/*
 * vl_corr_dbio.pgc - vl 모듈 DB 접근 함수 (vl_corr_dbio), archived into libvldbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 규칙 기본심각도와 일치하는 의심거래 건수 (상관 서브쿼리).
 */
#include <string.h>
#include <userlog.h>
#include "vl_corr_dbio.h"

long vldb_rule_consistent(const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16];
    long h_v = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL SELECT count(*) INTO :h_v FROM vl_suspect s
        WHERE s.biz_date = :h_bizdate
          AND s.severity = (SELECT r.severity FROM vl_rule r WHERE r.rule_code = s.rule_code);
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}
