/*
 * cm_log_message_dbio.pgc - cm 모듈 DB 접근 함수 (cm_log_message_dbio), archived into libcmdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 로그 ID 메시지 조회.
 */
#include <string.h>
#include <userlog.h>
#include "cm_log_message_dbio.h"

int cmdb_log_message(long id, char *out)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_id = id;
    char h_s[64];
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT msg INTO :h_s FROM cm_log WHERE log_id = :h_id;
    if (sqlca.sqlcode == 100) { out[0] = 0; return -1; }
    if (sqlca.sqlcode < 0) { userlog("cmdb_log_message FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    strncpy(out, h_s, 63); out[63] = 0;
    return 0;
}
