/*
 * rc_alertcnt_dbio.pgc - rc 모듈 DB 접근 함수 세트 (rc_alertcnt_dbio), archived into librcdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 경보 레벨별 건수 조회.
 */
#include <string.h>
#include <userlog.h>
#include "rc_alertcnt_dbio.h"

long rcdb_alert_level_count(const char *bizdate, const char *lvl)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16], h_lvl[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;
    strncpy(h_lvl, lvl, sizeof(h_lvl)-1); h_lvl[sizeof(h_lvl)-1] = 0;
    EXEC SQL SELECT count(*) INTO :h_v FROM rc_alert
        WHERE biz_date = :h_bizdate AND lvl = :h_lvl;
    if (sqlca.sqlcode < 0) { userlog("rcdb_alert_level_count FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return h_v;
}
