/*
 * cm_log_archive_dbio.pgc - cm 모듈 DB 접근 함수 (cm_log_archive_dbio), archived into libcmdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 정보 로그 보관(A) 전이.
 */
#include <string.h>
#include <userlog.h>
#include "cm_log_archive_dbio.h"

long cmdb_log_archive(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 cm_log SET log_level = 'A', updated_at = now()
        WHERE biz_date = :h_bizdate AND log_level = 'I';
    if (sqlca.sqlcode < 0) { userlog("cmdb_log_archive FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return sqlca.sqlerrd[2];
}
