/*
 * mm_term_join_dbio.pgc - mm 모듈 DB 접근 함수 (mm_term_join_dbio), archived into libmmdbio.a.
 * 활성 가맹점의 활성 단말 수 (JOIN).
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "mm_term_join_dbio.h"

/* mm_terminal 을 mm_merchant_ext 와 조인해 활성 가맹점의 활성 단말 수. */
long mmdb_active_terminals(void)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_v = 0;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT count(*) INTO :h_v
        FROM mm_terminal t JOIN mm_merchant_ext m ON t.merchant_id = m.merchant_id
        WHERE t.status = 'ACTIVE' AND m.status = 'ACTIVE';
    if (sqlca.sqlcode < 0) { userlog("mmdb_active_terminals FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_v;
}
