/*
 * mm_merch_total_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_merch_total_dbio.h"

long mmdb_merch_total(void)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_cnt;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT count(*) INTO :h_cnt FROM mm_merchant_ext;
    if (sqlca.sqlcode < 0) { userlog("mmdb_merch_total FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_cnt;
}

long mmdb_merch_by_status(const char *status)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_cnt; char h_status[16];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_status, status, sizeof(h_status)-1); h_status[sizeof(h_status)-1] = 0;
    EXEC SQL SELECT count(*) INTO :h_cnt FROM mm_merchant_ext WHERE status = :h_status;
    if (sqlca.sqlcode < 0) { userlog("mmdb_merch_by_status FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_cnt;
}
