/*
 * mg_insert_mark_dbio.pgc - mg 모듈 DB 접근 함수 (mg_insert_mark_dbio), archived into libmgdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 마커 전문 채번 후 적재.
 */
#include <string.h>
#include <userlog.h>
#include "mg_insert_mark_dbio.h"

long mgdb_msg_insert_marker(const char *bizdate, long amount)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_id = 0, h_amt = amount;
    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 SELECT nextval('mg_msg_seq') INTO :h_id;
    if (sqlca.sqlcode < 0) return -1;
    EXEC SQL INSERT INTO mg_msg_log (msg_id, amount, biz_date)
        VALUES (:h_id, :h_amt, :h_bizdate);
    if (sqlca.sqlcode < 0) { userlog("mgdb_msg_insert_marker FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return h_id;
}
