/*
 * mg_routed_amt_dbio.pgc - mg 모듈 DB 접근 함수 (mg_routed_amt_dbio), archived into libmgdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 라우팅 매칭 전문 금액(조인).
 */
#include <string.h>
#include <userlog.h>
#include "mg_routed_amt_dbio.h"

long mgdb_msg_routed_amount(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(a.amount),0) INTO :h_v
        FROM mg_msg_log a JOIN mg_route b ON a.channel = b.channel
        WHERE a.biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}
