/*
 * cm_logfromfx_dbio.pgc - cm 모듈 DB 접근 함수 (cm_logfromfx_dbio), archived into libcmdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 당일 환율을 공통로그로 기록 (INSERT..SELECT).
 */
#include <string.h>
#include <userlog.h>
#include "cm_logfromfx_dbio.h"

long cmdb_log_from_fx(const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL INSERT INTO cm_log
        (log_id, svc_name, log_level, msg, biz_date)
        SELECT nextval('cm_log_seq'), 'CM_FX', 'I', f.ccy, f.base_date
        FROM cm_fx_rate f WHERE f.base_date = :h_bizdate;
    if (sqlca.sqlcode < 0) { userlog("cmdb_log_from_fx FAIL [%d]", sqlca.sqlcode); return -1; }
    return (long) sqlca.sqlerrd[2];
}
