/*
 * vl_codeval_dbio.pgc - 공통코드 유효성 (mm_code 활성) (libvldbio.a).
 * ECPG functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "vl_codeval_dbio.h"

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