/*
 * AUTH_HISTORY.pgc - au 모듈 서비스 AUTH_HISTORY (one service = one file).
 * 카드 승인 이력 건수 조회.
 * Moved verbatim from the former inline au_svr.pgc; runs on the caller's XA
 * branch (no EXEC SQL CONNECT). Advertised by au_svr at tpsvrinit.
 */
#include "AUTH_HISTORY.h"

void AUTH_HISTORY(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char card[24];
    EXEC SQL BEGIN DECLARE SECTION;
    long h_cnt;
    char h_card[24];
    EXEC SQL END DECLARE SECTION;
    gets_(b, T_KEY1, card, sizeof(card));
    strncpy(h_card, card, sizeof(h_card)-1); h_card[sizeof(h_card)-1] = 0;
    EXEC SQL SELECT count(*) INTO :h_cnt FROM au_authorization WHERE card_no = :h_card;
    if (sqlca.sqlcode < 0) FAIL(b);
    setl(b, T_COUNT, h_cnt);
    OK(b);
}
