/*
 * vl_dup_query_dbio.pgc - 중복 매입 건수 (가맹점/금액/영업일) (libvldbio.a).
 * ECPG functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "vl_dup_query_dbio.h"

long vldb_dup_count(const char *merch, long amt, const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_amt = amt, h_cnt; char h_merch[64], h_bizdate[16];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_merch, merch, sizeof(h_merch)-1); h_merch[sizeof(h_merch)-1] = 0;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL SELECT count(*) INTO :h_cnt FROM purchase
        WHERE merchant_id = :h_merch AND amount = :h_amt AND biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) { userlog("vldb_dup_count FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_cnt;
}
