/*
 * mm_mcc_dbio.pgc - MCC 업종 위험도 조회 (libmmdbio.a).
 * ECPG functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "mm_mcc_dbio.h"

long mmdb_mcc_risk(const char *mcc)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_risk; char h_mcc[16];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_mcc, mcc, sizeof(h_mcc)-1); h_mcc[sizeof(h_mcc)-1] = 0;
    EXEC SQL SELECT risk_level INTO :h_risk FROM mm_mcc WHERE mcc = :h_mcc;
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) { userlog("mmdb_mcc_risk FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_risk;
}

int mmdb_mcc_name(const char *mcc, char *name_out)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_mcc[16], h_name[64];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_mcc, mcc, sizeof(h_mcc)-1); h_mcc[sizeof(h_mcc)-1] = 0;
    EXEC SQL SELECT mcc_name INTO :h_name FROM mm_mcc WHERE mcc = :h_mcc;
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) { userlog("mmdb_mcc_name FAIL [%d]", sqlca.sqlcode); return -1; }
    strncpy(name_out, h_name, 63); name_out[63] = 0;
    return 0;
}
