/*
 * au_fraud_query_dbio.pgc - au 모듈 DB 접근 함수 세트 (au_fraud_query_dbio), archived into libaudbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * Shape: min/max aggregate (카드별 부정거래 스코어 극값).
 */
#include <string.h>
#include <userlog.h>
#include "au_fraud_query_dbio.h"

/* 카드의 최대 부정거래 스코어. */
long audb_fraud_max_score(const char *card)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_card[24];
    long 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 coalesce(max(score),0) INTO :h_v FROM au_fraud_log WHERE card_no = :h_card;
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}

/* 카드의 최소 부정거래 스코어. */
long audb_fraud_min_score(const char *card)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_card[24];
    long 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 coalesce(min(score),0) INTO :h_v FROM au_fraud_log WHERE card_no = :h_card;
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}
