/*
 * au_blacklist_query_dbio.pgc - au 모듈 DB 접근 함수 세트 (au_blacklist_query_dbio), archived into libaudbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * Shape: EXISTS predicate SELECT (블랙리스트 존재여부 0/1).
 */
#include <string.h>
#include <userlog.h>
#include "au_blacklist_query_dbio.h"

/* 카드가 블랙리스트에 존재하면 1, 없으면 0. */
long audb_blacklist_exists(const char *card)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_card[24];
    int h_v = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_card, card, sizeof(h_card)-1); h_card[sizeof(h_card)-1] = 0;
    EXEC SQL SELECT CASE WHEN EXISTS (SELECT 1 FROM au_blacklist WHERE card_no = :h_card)
                    THEN 1 ELSE 0 END INTO :h_v;
    if (sqlca.sqlcode < 0) { userlog("audb_blacklist_exists FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return (long)h_v;
}
