/*
 * mm_code_active_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_code_active_dbio.h"

long mmdb_code_active_count(const char *grp)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_cnt; char h_grp[32];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_grp, grp, sizeof(h_grp)-1); h_grp[sizeof(h_grp)-1] = 0;
    EXEC SQL SELECT count(*) INTO :h_cnt FROM mm_code
        WHERE code_group = :h_grp AND status = 'ACTIVE';
    if (sqlca.sqlcode < 0) { userlog("mmdb_code_active_count FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_cnt;
}
