/*
 * cl_snap_distinct_dbio.pgc - cl 모듈 DB 접근 함수 (cl_snap_distinct_dbio), archived into libcldbio.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 "cl_snap_distinct_dbio.h"

/* close_id 스냅샷의 고유 가맹점 수. */
long clqdb_snap_distinct(long cid)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_cid = cid, h_v = 0;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT count(DISTINCT merchant_id) INTO :h_v FROM cl_snapshot
        WHERE close_id = :h_cid;
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}
