/*
 * au_summary_query_dbio.pgc - au 모듈 DB 접근 함수 세트 (au_summary_query_dbio), archived into libaudbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * Shape: two-key scalar SELECT (가맹점/일자 승인집계 단건).
 */
#include <string.h>
#include <userlog.h>
#include "au_summary_query_dbio.h"

/* 가맹점 당일 승인건수(au_summary.approve_count). */
long audb_summary_approve_count(const char *merch, const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_merch[64], h_bizdate[16];
    long h_v = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_merch, merch, sizeof(h_merch)-1); h_merch[sizeof(h_merch)-1] = 0;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL SELECT coalesce(approve_count,0) INTO :h_v FROM au_summary
        WHERE merchant_id = :h_merch AND biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) { userlog("audb_summary_approve_count FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return h_v;
}
