/*
 * rc_distinctpid_dbio.pgc - rc 모듈 DB 접근 함수 세트 (rc_distinctpid_dbio), archived into librcdbio.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 "rc_distinctpid_dbio.h"

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