/*
 * py_payout_delrange_dbio.pgc - py 모듈 DB 접근 함수 세트 (py_payout_delrange_dbio), archived into libpydbio.a.
 * 기간 범위의 취소(C) 지급건을 정리 삭제한다.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "py_payout_delrange_dbio.h"

/* DELETE 범위: [from,to] 기간의 취소 지급건 삭제, 삭제 건수 반환. */
long pydb_payout_purge_cancelled(const char *from_date, const char *to_date)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_from[16], h_to[16];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_from, from_date, sizeof(h_from)-1); h_from[sizeof(h_from)-1] = 0;
    strncpy(h_to, to_date, sizeof(h_to)-1); h_to[sizeof(h_to)-1] = 0;
    EXEC SQL DELETE FROM py_payout
        WHERE status = 'C' AND biz_date >= :h_from AND biz_date <= :h_to;
    if (sqlca.sqlcode < 0) { userlog("pydb_payout_purge_cancelled FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return sqlca.sqlerrd[2];
}
