/*
 * vl_merch_query_dbio.pgc - 가맹점 상태 조회 (libvldbio.a).
 * ECPG functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "vl_merch_query_dbio.h"

int vldb_merch_status(const char *merch, char *status_out)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_merch[64], h_status[16];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_merch, merch, sizeof(h_merch)-1); h_merch[sizeof(h_merch)-1] = 0;
    /* base merchant 원장에서 상태를 집계 조회(없으면 NONE)하여 항상 한 행을 얻는다. */
    EXEC SQL SELECT coalesce(max(status), 'NONE') INTO :h_status
        FROM merchant WHERE merchant_id = :h_merch;
    if (sqlca.sqlcode < 0) { userlog("vldb_merch_status FAIL [%d]", sqlca.sqlcode); return -1; }
    strncpy(status_out, h_status, 15); status_out[15] = 0;
    return 0;
}
