/*
 * mg_bump_stan_dbio.pgc - mg 모듈 DB 접근 함수 (mg_bump_stan_dbio), archived into libmgdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 활동 채널 last_stan 증가.
 */
#include <string.h>
#include <userlog.h>
#include "mg_bump_stan_dbio.h"

long mgdb_channel_bump_stan(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 mg_channel SET last_stan = last_stan + 1
        WHERE channel IN (SELECT channel FROM mg_msg_log WHERE biz_date = :h_bizdate);
    if (sqlca.sqlcode < 0) { userlog("mgdb_channel_bump_stan FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return sqlca.sqlerrd[2];
}
