/*
 * mm_feerate_stat_dbio.pgc - 가맹점 평균 수수료율 (libmmdbio.a).
 * ECPG functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "mm_feerate_stat_dbio.h"

long mmdb_feerate_avg(const char *merch)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_avg; char h_merch[64];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_merch, merch, sizeof(h_merch)-1); h_merch[sizeof(h_merch)-1] = 0;
    EXEC SQL SELECT coalesce(round(avg(rate_bps)),0) INTO :h_avg FROM mm_fee_rate
        WHERE merchant_id = :h_merch;
    if (sqlca.sqlcode < 0) { userlog("mmdb_feerate_avg FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_avg;
}
