/*
 * ac_issuer_dbio.pgc - ac 모듈 DB 접근 함수 세트 (ac_issuer_dbio), archived into libacdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "ac_issuer_dbio.h"

/* 발급사 'BC' 점유율(bps) = BC건수 * 10000 / 전체건수 (FILTER 비교). */
long acdb_issuer_bc_share_bps(const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16];
    long h_bc = 0, h_all = 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 issuer = 'BC'), count(*)
        INTO :h_bc, :h_all FROM purchase WHERE biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) return -1;
    if (h_all <= 0) return 0;
    return h_bc * 10000 / h_all;
}
