/*
 * st_minband_dbio.pgc - st 모듈 DB 접근 함수 세트 (st_minband_dbio), archived into libstdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 수수료 유형의 최저 구간 요율(bps) - min() 스칼라.
 */
#include <string.h>
#include <userlog.h>
#include "st_minband_dbio.h"

long stdb_min_band_rate(const char *fee_type)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_type[16];
    long h_v = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_type, fee_type, sizeof(h_type)-1); h_type[sizeof(h_type)-1] = 0;
    EXEC SQL SELECT coalesce(min(rate_bps),0) INTO :h_v FROM st_fee_rate WHERE fee_type = :h_type;
    if (sqlca.sqlcode < 0) { userlog("stdb_min_band_rate FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return h_v;
}
