/*
 * st_distinctmerch_dbio.pgc - st 모듈 DB 접근 함수 세트 (st_distinctmerch_dbio), archived into libstdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 정산 대상 고유 가맹점 수 - count(distinct).
 */
#include <string.h>
#include <userlog.h>
#include "st_distinctmerch_dbio.h"

long stdb_distinct_merchants(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(DISTINCT merchant_id) INTO :h_v FROM settlement WHERE biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}
