/*
 * vl_settle_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_settle_query_dbio.h"

long vldb_settle_net(long pid)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_pid = pid, h_net;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT coalesce(sum(net),0) INTO :h_net FROM settlement WHERE purchase_id = :h_pid;
    if (sqlca.sqlcode < 0) { userlog("vldb_settle_net FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_net;
}
