/*
 * cl_snap_purge_dbio.pgc - cl 모듈 DB 접근 함수 (cl_snap_purge_dbio), archived into libcldbio.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 "cl_snap_purge_dbio.h"

/* biz_date 이하 스냅샷 삭제, 삭제 행수 반환. */
long cldb_snap_purge(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 DELETE FROM cl_snapshot WHERE biz_date <= :h_bizdate;
    if (sqlca.sqlcode < 0) { userlog("cldb_snap_purge FAIL [%d]", sqlca.sqlcode); return -1; }
    return (long) sqlca.sqlerrd[2];
}
