/*
 * lg_line_delrange_dbio.pgc - lg 모듈 DB 접근 함수 (lg_line_delrange_dbio), archived into liblgdbio.a.
 * 기준일 이전의 마감(closed) 분개 라인을 범위 삭제한다.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "lg_line_delrange_dbio.h"

/* DELETE 범위: before 이전 closed 라인 삭제, 삭제 건수 반환. */
long lgqdb_purge_closed_lines(const char *before)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_before[16];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_before, before, sizeof(h_before)-1); h_before[sizeof(h_before)-1] = 0;
    EXEC SQL DELETE FROM lg_ledger_line
        WHERE status = 'closed' AND biz_date < :h_before;
    if (sqlca.sqlcode < 0) { userlog("lgqdb_purge_closed_lines FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return sqlca.sqlerrd[2];
}
