/*
 * mm_status_filter_dbio.pgc - mm 모듈 DB 접근 함수 (mm_status_filter_dbio), archived into libmmdbio.a.
 * 가맹점 상태별 건수 한 행 분리집계 (FILTER).
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "mm_status_filter_dbio.h"

/* ACTIVE/HOLD/DELETED 건수를 FILTER 로 한 번에 반환. */
int mmdb_status_filter(long *active, long *hold, long *deleted)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_a = 0, h_h = 0, h_d = 0;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT
        count(*) FILTER (WHERE status = 'ACTIVE'),
        count(*) FILTER (WHERE status = 'HOLD'),
        count(*) FILTER (WHERE status = 'DELETED')
        INTO :h_a, :h_h, :h_d FROM mm_merchant_ext;
    if (sqlca.sqlcode < 0) return -1;
    *active = h_a; *hold = h_h; *deleted = h_d;
    return 0;
}
