/*
 * vl_errdistinct_dbio.pgc - vl 모듈 DB 접근 함수 (vl_errdistinct_dbio), archived into libvldbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 당일 의심거래에서 발화한 고유 규칙 수 (count DISTINCT).
 */
#include <string.h>
#include <userlog.h>
#include "vl_errdistinct_dbio.h"

long vldb_distinct_rules(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(DISTINCT rule_code) INTO :h_v
        FROM vl_suspect WHERE biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) { userlog("vldb_distinct_rules FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_v;
}
