/*
 * rc_pidcount_dbio.pgc - 고유 매입/대사유형 수 (rc_pidcount_dbio), librcdbio.a.
 * ECPG; count(DISTINCT purchase_id) 와 count(DISTINCT match_type) 를 한 SELECT 로 반환.
 */
#include <string.h>
#include <userlog.h>
#include "rc_pidcount_dbio.h"

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