/*
 * rc_diffkind_dbio.pgc - rc 모듈 DB 접근 함수 세트 (rc_diffkind_dbio), archived into librcdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * AMT/CNT 차이 종류별 FILTER 건수 - AMT 건수 반환.
 */
#include <string.h>
#include <userlog.h>
#include "rc_diffkind_dbio.h"

long rcdb_diff_amt_kind_count(const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16];
    long h_amt = 0, h_cnt = 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(*) FILTER (WHERE diff_kind = 'AMT'),
        count(*) FILTER (WHERE diff_kind = 'CNT')
        INTO :h_amt, :h_cnt FROM rc_diff WHERE biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) return -1;
    userlog("rcdb_diff_amt_kind_count cnt_kind=%ld", h_cnt);
    return h_amt;
}
