/*
 * rc_existsexc_dbio.pgc - rc 모듈 DB 접근 함수 세트 (rc_existsexc_dbio), archived into librcdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 매입에 미해소 예외 존재 여부 - EXISTS boolean.
 */
#include <string.h>
#include <userlog.h>
#include "rc_existsexc_dbio.h"

int rcdb_has_open_exception(long pid)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_pid = pid;
    int h_v = 0;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT CASE WHEN EXISTS
        (SELECT 1 FROM rc_exception WHERE purchase_id = :h_pid AND resolved = false)
        THEN 1 ELSE 0 END;
    EXEC SQL SELECT CASE WHEN EXISTS
        (SELECT 1 FROM rc_exception WHERE purchase_id = :h_pid AND resolved = false)
        THEN 1 ELSE 0 END INTO :h_v;
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}
