/*
 * py_payout_merch_dbio.pgc - py 모듈 DB 접근 함수 세트 (py_payout_merch_dbio), archived into libpydbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "py_payout_merch_dbio.h"

/* 가맹점 전체 지급 건수. */
long pydb_payout_merch_count(const char *merch)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_merch[64];
    long h_v = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_merch, merch, sizeof(h_merch)-1); h_merch[sizeof(h_merch)-1] = 0;
    EXEC SQL SELECT count(*) INTO :h_v FROM py_payout WHERE merchant_id = :h_merch;
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}

/* 가맹점 전체 지급 총액. */
long pydb_payout_merch_gross(const char *merch)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_merch[64];
    long h_v = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_merch, merch, sizeof(h_merch)-1); h_merch[sizeof(h_merch)-1] = 0;
    EXEC SQL SELECT coalesce(sum(amount),0) INTO :h_v FROM py_payout WHERE merchant_id = :h_merch;
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}
