/*
 * vl_purchase_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_purchase_dbio.h"

int vldb_purchase_exists(long pid)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_pid = pid, h_cnt;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT count(*) INTO :h_cnt FROM purchase WHERE purchase_id = :h_pid;
    if (sqlca.sqlcode < 0) { userlog("vldb_purchase_exists FAIL [%d]", sqlca.sqlcode); return -1; }
    return (h_cnt > 0) ? 1 : 0;
}

long vldb_purchase_amount(long pid)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_pid = pid, h_amt;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT amount INTO :h_amt FROM purchase WHERE purchase_id = :h_pid;
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) { userlog("vldb_purchase_amount FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_amt;
}
