/*
 * mm_terminal_query_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_terminal_query_dbio.h"

int mmdb_terminal_merch(const char *term, char *merch_out)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_term[32], h_merch[64];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_term, term, sizeof(h_term)-1); h_term[sizeof(h_term)-1] = 0;
    EXEC SQL SELECT merchant_id INTO :h_merch FROM mm_terminal WHERE terminal_id = :h_term;
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) { userlog("mmdb_terminal_merch FAIL [%d]", sqlca.sqlcode); return -1; }
    strncpy(merch_out, h_merch, 63); merch_out[63] = 0;
    return 0;
}
