/*
 * lg_zero_bal_dbio.pgc - lg 모듈 DB 접근 함수 (lg_zero_bal_dbio), archived into liblgdbio.a.
 * 잔액 0 인 계정 수 (청산 계정).
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "lg_zero_bal_dbio.h"

/* 잔액이 정확히 0 인 계정 수. */
long lgqdb_zero_bal(const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16];
    long h_cnt = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL SELECT count(*) INTO :h_cnt FROM lg_account_bal
        WHERE biz_date = :h_bizdate AND balance = 0;
    if (sqlca.sqlcode < 0) { userlog("lgqdb_zero_bal FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_cnt;
}
