/*
 * MG_LOG.pgc - mg 모듈 서비스 MG_LOG (one service = one file).
 * Split out of the former inline mg_svr.pgc; runs on the caller's XA
 * branch (no EXEC SQL CONNECT). Advertised by mg_svr at tpsvrinit.
 */
#include "MG_LOG.h"

/* 10. MG_LOG - 채널 당일 전문 로그 건수 조회. */
void MG_LOG(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char chan[16], bizdate[16];
    EXEC SQL BEGIN DECLARE SECTION;
    long h_cnt;
    char h_chan[16], h_bizdate[16];
    EXEC SQL END DECLARE SECTION;
    gets_(b, T_CHANNEL, chan, sizeof(chan)); if (chan[0] == 0) strcpy(chan, "CH01");
    gets_(b, T_BIZDATE, bizdate, sizeof(bizdate));
    strncpy(h_chan, chan, sizeof(h_chan)-1); h_chan[sizeof(h_chan)-1] = 0;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;

    EXEC SQL SELECT count(*) INTO :h_cnt FROM mg_msg_log
        WHERE channel = :h_chan AND biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) FAIL(b);
    setl(b, T_COUNT, h_cnt);
    OK(b);
}
