/*
 * au_preauth_query_dbio.pgc - au 모듈 DB 접근 함수 세트 (au_preauth_query_dbio), archived into libaudbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * Shape: multi-column SELECT INTO out-params (예비승인 상세).
 */
#include <string.h>
#include <userlog.h>
#include "au_preauth_query_dbio.h"

/* 예비승인의 금액/상태를 한 번에 조회하여 out 파라미터로 반환. */
int audb_preauth_detail(long preauth_id, long *amount_out, char *status_out)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_pre = preauth_id, h_amt = 0;
    char h_status[8];
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT coalesce(amount,0), status INTO :h_amt, :h_status
        FROM au_preauth WHERE preauth_id = :h_pre;
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) {
        userlog("audb_preauth_detail FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
        return -1;
    }
    *amount_out = h_amt;
    status_out[0] = h_status[0];
    status_out[1] = 0;
    return 0;
}
