/*
 * mg_ackpurge_dbio.pgc - mg 모듈 DB 접근 함수 (mg_ackpurge_dbio), archived into libmgdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 기준일 이전 완료(D) 큐 삭제 후 삭제건수 반환 (DELETE 범위).
 */
#include <string.h>
#include <userlog.h>
#include "mg_ackpurge_dbio.h"

long mgdb_purge_acked(const char *cutoff)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_cut[16];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_cut, cutoff, sizeof(h_cut)-1); h_cut[sizeof(h_cut)-1] = 0;
    EXEC SQL DELETE FROM mg_queue
        WHERE biz_date < :h_cut AND status = 'D';
    if (sqlca.sqlcode < 0) { userlog("mgdb_purge_acked FAIL [%d]", sqlca.sqlcode); return -1; }
    return (long) sqlca.sqlerrd[2];
}
