/*
 * mm_terminal_count_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_count_dbio.h"

long mmdb_terminal_count(const char *merch)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_cnt; 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_cnt FROM mm_terminal
        WHERE merchant_id = :h_merch AND status = 'ACTIVE';
    if (sqlca.sqlcode < 0) { userlog("mmdb_terminal_count FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_cnt;
}
