/*
 * mm_hist_purge_dbio.pgc - mm 모듈 DB 접근 함수 (mm_hist_purge_dbio), archived into libmmdbio.a.
 * 수수료율 이력 범위 삭제 후 삭제건수 반환 (DELETE range).
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "mm_hist_purge_dbio.h"

/* eff_date 이전 수수료율 이력 삭제, 삭제 행수 반환. */
long mmdb_hist_purge(const char *cutoff)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_cutoff[16];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_cutoff, cutoff, sizeof(h_cutoff)-1); h_cutoff[sizeof(h_cutoff)-1] = 0;
    EXEC SQL DELETE FROM mm_fee_rate_hist WHERE eff_date < :h_cutoff;
    if (sqlca.sqlcode < 0) { userlog("mmdb_hist_purge FAIL [%d]", sqlca.sqlcode); return -1; }
    return (long) sqlca.sqlerrd[2];
}
