/*
 * cl_archive_mark_dbio.pgc - cl 모듈 DB 접근 함수 (cl_archive_mark_dbio), archived into libcldbio.a.
 * 완료/승인 마감 아카이브 표시 (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_archive_mark_dbio.h"

/* before 이전 완료(C)/승인(A) 마감을 ARCHIVED 로 표시, 표시 건수 반환. */
long clqdb_archive_mark(const char *before)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_before[16];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_before, before, sizeof(h_before)-1); h_before[sizeof(h_before)-1] = 0;
    EXEC SQL UPDATE cl_close_log SET memo = 'ARCHIVED', updated_at = now()
        WHERE biz_date < :h_before AND status IN ('C','A','L') AND memo <> 'ARCHIVED';
    if (sqlca.sqlcode < 0) { userlog("clqdb_archive_mark FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return sqlca.sqlerrd[2];
}
