/*
 * au_fraud_purge_dbio.pgc - au 모듈 DB 접근 함수 세트 (au_fraud_purge_dbio), archived into libaudbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * Shape: DELETE 복합조건 구간 삭제 - 기준일 이전 저점수 부정로그 정리.
 */
#include <string.h>
#include <userlog.h>
#include "au_fraud_purge_dbio.h"

/* cutoff 이전이면서 점수가 min_score 미만인 부정로그를 삭제하고 삭제 건수를 반환. */
long audb_fraud_purge_lowscore(const char *cutoff, long min_score)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_cut[16];
    long h_min = min_score, deleted = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_cut, cutoff, sizeof(h_cut)-1); h_cut[sizeof(h_cut)-1] = 0;
    EXEC SQL DELETE FROM au_fraud_log WHERE biz_date < :h_cut AND score < :h_min;
    if (sqlca.sqlcode < 0) {
        userlog("audb_fraud_purge_lowscore FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
        return -1;
    }
    deleted = sqlca.sqlerrd[2];
    return deleted;
}
