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

long acdb_merchant_limit(const char *merch)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_v = 0; 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 daily_limit INTO :h_v FROM merchant WHERE merchant_id = :h_merch;
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) { userlog("acdb_merchant_limit FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_v;
}

int acdb_merchant_active(const char *merch)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_v = 0; 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 count(*) INTO :h_v FROM merchant WHERE merchant_id = :h_merch AND status = 'ACTIVE';
    if (sqlca.sqlcode < 0) return -1;
    return (int)h_v;
}
