/*
 * cl_close_count_dbio.pgc - cl 모듈 DB 접근 함수 (cl_close_count_dbio), archived into libcldbio.a.
 * 마감유형별 유효 마감 건수.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "cl_close_count_dbio.h"

/* close_type 별 취소되지 않은 마감 수. */
long clqdb_close_count(const char *ctype)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_type[16];
    long h_cnt = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_type, ctype, sizeof(h_type)-1); h_type[sizeof(h_type)-1] = 0;
    EXEC SQL SELECT count(*) INTO :h_cnt FROM cl_close_log
        WHERE close_type = :h_type AND status <> 'X';
    if (sqlca.sqlcode < 0) { userlog("clqdb_close_count FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_cnt;
}
