/*
 * cl_snap_merch_dbio.pgc - cl 모듈 DB 접근 함수 (cl_snap_merch_dbio), archived into libcldbio.a.
 * 마감 스냅샷 가맹점 수.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "cl_snap_merch_dbio.h"

/* 특정 마감에 포함된 가맹점(스냅샷 행) 수. */
long clqdb_snap_merch(long cid)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_cid = cid, h_cnt = 0;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT count(DISTINCT merchant_id) INTO :h_cnt
        FROM cl_snapshot WHERE close_id = :h_cid;
    if (sqlca.sqlcode < 0) { userlog("clqdb_snap_merch FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_cnt;
}
