/*
 * cm_nofx_dbio.pgc - cm 모듈 DB 접근 함수 (cm_nofx_dbio), archived into libcmdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 당일 환율이 등록되지 않은 통화코드 수 (NOT EXISTS cm_fx_rate).
 */
#include <string.h>
#include <userlog.h>
#include "cm_nofx_dbio.h"

long cmdb_code_no_fx(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_code c
        WHERE c.code_grp = 'CCY' AND c.code <> 'KRW'
          AND NOT EXISTS (SELECT 1 FROM cm_fx_rate f
                          WHERE f.ccy = c.code AND f.base_date = :h_bizdate);
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}
