/*
 * mm_dormant_dbio.pgc - 휴면 가맹점 수 (N일 미갱신) (libmmdbio.a).
 * ECPG functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "mm_dormant_dbio.h"

long mmdb_dormant_count(long days)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_cnt, h_days = days;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT count(*) INTO :h_cnt FROM mm_merchant_ext
        WHERE status = 'ACTIVE' AND updated_at < now() - (:h_days || ' days')::interval;
    if (sqlca.sqlcode < 0) { userlog("mmdb_dormant_count FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_cnt;
}
