/*
 * cl_restore_count_dbio.pgc - cl 모듈 DB 접근 함수 (cl_restore_count_dbio), archived into libcldbio.a.
 * 취소(X) 마감 개시(O) 복원 (update count).
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "cl_restore_count_dbio.h"

/* 당일 취소(X) 마감을 개시(O) 로 복원, 복원 건수 반환. */
long clqdb_restore_count(const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL UPDATE cl_close_log SET status = 'O', memo = 'RESTORED', updated_at = now()
        WHERE biz_date = :h_bizdate AND status = 'X';
    if (sqlca.sqlcode < 0) { userlog("clqdb_restore_count FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return sqlca.sqlerrd[2];
}
