/*
 * cm_login_dbio.pgc - cm 모듈 DB 접근 함수 (cm_login_dbio), archived into libcmdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 오류 로그를 남긴 서비스가 낸 전체 로그 건수 (IN 서브셀렉트).
 */
#include <string.h>
#include <userlog.h>
#include "cm_login_dbio.h"

long cmdb_log_for_errsvc(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 cm_log
        WHERE biz_date = :h_bizdate
          AND svc_name IN (SELECT svc_name FROM cm_log
                           WHERE biz_date = :h_bizdate AND log_level = 'E');
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}
