/*
 * mg_queue_stale_dbio.pgc - mg 모듈 DB 접근 함수 (mg_queue_stale_dbio), archived into libmgdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 대기(Q) 오래된 큐 실패(F) 전이.
 */
#include <string.h>
#include <userlog.h>
#include "mg_queue_stale_dbio.h"

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