/*
 * st_purgecancel_dbio.pgc - st 모듈 DB 접근 함수 세트 (st_purgecancel_dbio), archived into libstdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 취소 지급 레코드 정리 - DELETE 후 삭제 행수 반환.
 */
#include <string.h>
#include <userlog.h>
#include "st_purgecancel_dbio.h"

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