/*
 * vl_sevcase_dbio.pgc - vl 모듈 DB 접근 함수 (vl_sevcase_dbio), archived into libvldbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 심각도 가중합 (CRIT8/ERROR4/WARN2/그외1) - CASE 식.
 */
#include <string.h>
#include <userlog.h>
#include "vl_sevcase_dbio.h"

long vldb_severity_weighted(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 coalesce(sum(CASE severity
                WHEN 'CRIT'  THEN 8
                WHEN 'ERROR' THEN 4
                WHEN 'WARN'  THEN 2
                ELSE 1 END), 0)
        INTO :h_v FROM vl_suspect WHERE biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}
