/*
 * ac_approval_query_dbio.pgc - ac 모듈 DB 접근 함수 세트 (ac_approval_query_dbio), archived into libacdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "ac_approval_query_dbio.h"

long acdb_approval_count_all(long pid)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_pid, h_v = 0;
    EXEC SQL END DECLARE SECTION;
    h_pid = pid;
    EXEC SQL SELECT count(*) INTO :h_v FROM approval WHERE purchase_id = :h_pid;
    if (sqlca.sqlcode < 0) { userlog("acdb_approval_count_all FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return h_v;
}

long acdb_approval_ok_count(long pid)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_pid, h_v = 0;
    EXEC SQL END DECLARE SECTION;
    h_pid = pid;
    EXEC SQL SELECT count(*) INTO :h_v FROM approval WHERE purchase_id = :h_pid AND approved = true;
    if (sqlca.sqlcode < 0) { userlog("acdb_approval_ok_count FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return h_v;
}
