/*
 * st_merchdistinct_dbio.pgc - 고유 가맹점/수수료종류 수 (st_merchdistinct_dbio), libstdbio.a.
 * ECPG; count(DISTINCT merchant_id) 와 count(DISTINCT fee_type) 를 한 SELECT 로 반환.
 */
#include <string.h>
#include <userlog.h>
#include "st_merchdistinct_dbio.h"

long stdb_distinct_merch(const char *bizdate, long *feetypes_out)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16];
    long h_m = 0, h_ft = 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), count(DISTINCT fee_type)
        INTO :h_m, :h_ft FROM st_settle_dtl WHERE biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) { userlog("stdb_distinct_merch FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    if (feetypes_out) *feetypes_out = h_ft;
    return h_m;
}
