/*
 * cl_period_locked_dbio.pgc - cl 모듈 DB 접근 함수 (cl_period_locked_dbio), archived into libcldbio.a.
 * 기간 잠금 여부 조회 (1=잠김).
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "cl_period_locked_dbio.h"

/* period_key 가 잠겨있으면 1, 아니면 0, 없으면 0. */
int clqdb_period_locked(const char *period)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_period[16];
    int  h_locked;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_period, period, sizeof(h_period)-1); h_period[sizeof(h_period)-1] = 0;
    EXEC SQL SELECT CASE WHEN locked THEN 1 ELSE 0 END INTO :h_locked
        FROM cl_period_lock WHERE period_key = :h_period;
    if (sqlca.sqlcode == 100) return 0;
    if (sqlca.sqlcode < 0) { userlog("clqdb_period_locked FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_locked;
}
