/*
 * au_cancel_query_dbio.pgc - au 모듈 DB 접근 함수 세트 (au_cancel_query_dbio), archived into libaudbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * Shape: aggregate sum keyed by FK (한 승인의 누적 취소액).
 */
#include <string.h>
#include <userlog.h>
#include "au_cancel_query_dbio.h"

/* 한 승인건에 대한 누적 취소 금액. */
long audb_cancel_amount_by_auth(long auth_id)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_auth, h_v = 0;
    EXEC SQL END DECLARE SECTION;
    h_auth = auth_id;
    EXEC SQL SELECT coalesce(sum(amount),0) INTO :h_v FROM au_cancel WHERE auth_id = :h_auth;
    if (sqlca.sqlcode < 0) { userlog("audb_cancel_amount_by_auth FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return h_v;
}
