/*
 * rc_matchsum_dbio.pgc - rc 모듈 DB 접근 함수 세트 (rc_matchsum_dbio), archived into librcdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 대사 로그 금액 상태별 단순 합계.
 */
#include <string.h>
#include <userlog.h>
#include "rc_matchsum_dbio.h"

long rcdb_match_amount_sum(const char *bizdate, const char *status)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16], h_status[16];
    long h_v = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    strncpy(h_status, status, sizeof(h_status)-1); h_status[sizeof(h_status)-1] = 0;
    EXEC SQL SELECT coalesce(sum(amount),0) INTO :h_v FROM rc_match_log
        WHERE biz_date = :h_bizdate AND status = :h_status;
    if (sqlca.sqlcode < 0) { userlog("rcdb_match_amount_sum FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return h_v;
}
