/*
 * cl_close_total_dbio.pgc - cl 모듈 DB 접근 함수 (cl_close_total_dbio), archived into libcldbio.a.
 * 마감 헤더 총액/건수 조회.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "cl_close_total_dbio.h"

/* 마감 헤더의 저장된 txn_count/total_amount. */
int clqdb_close_total(long cid, long *cnt, long *amt)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_cid = cid, h_cnt, h_amt;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT txn_count, total_amount INTO :h_cnt, :h_amt
        FROM cl_close_log WHERE close_id = :h_cid;
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) { userlog("clqdb_close_total miss [%d]", sqlca.sqlcode); return -1; }
    *cnt = h_cnt; *amt = h_amt;
    return 0;
}
