/*
 * mm_bin_distinct_dbio.pgc - mm 모듈 DB 접근 함수 (mm_bin_distinct_dbio), archived into libmmdbio.a.
 * 카드브랜드별 고유 발급사 수 (count DISTINCT).
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "mm_bin_distinct_dbio.h"

/* card_brand 의 BIN 에서 고유 issuer_cd 수. */
long mmdb_bin_distinct_issuer(const char *brand)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_brand[16];
    long h_v = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_brand, brand, sizeof(h_brand)-1); h_brand[sizeof(h_brand)-1] = 0;
    EXEC SQL SELECT count(DISTINCT issuer_cd) INTO :h_v FROM mm_bin
        WHERE card_brand = :h_brand AND status = 'ACTIVE';
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}
