/*
 * vl_fee_query_dbio.pgc - 매입 수수료/금액/가맹점 조회 (libvldbio.a).
 * ECPG functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "vl_fee_query_dbio.h"

int vldb_purchase_fee(long pid, long *amt_out, long *fee_out, char *merch_out)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_pid = pid, h_amt, h_fee; char h_merch[64];
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT amount, fee, merchant_id INTO :h_amt, :h_fee, :h_merch
        FROM purchase WHERE purchase_id = :h_pid;
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) { userlog("vldb_purchase_fee FAIL [%d]", sqlca.sqlcode); return -1; }
    *amt_out = h_amt; *fee_out = h_fee;
    strncpy(merch_out, h_merch, 63); merch_out[63] = 0;
    return 0;
}
