/*
 * au_card_velocity_dbio.pgc - au 모듈 DB 접근 함수 세트 (au_card_velocity_dbio), archived into libaudbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * Shape: subquery WHERE col IN (SELECT ...) (블랙리스트 카드의 당일 승인 건수).
 */
#include <string.h>
#include <userlog.h>
#include "au_card_velocity_dbio.h"

/* 블랙리스트에 등재된 카드가 당일 발생시킨 승인 건수. */
long audb_blacklisted_auth_count(const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[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;
    EXEC SQL SELECT count(*) INTO :h_v FROM au_authorization
        WHERE biz_date = :h_bizdate
          AND card_no IN (SELECT card_no FROM au_blacklist);
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}
