/*
 * st_existsadj_dbio.pgc - st 모듈 DB 접근 함수 세트 (st_existsadj_dbio), archived into libstdbio.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 "st_existsadj_dbio.h"

int stdb_has_adjust(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 st_adjust WHERE purchase_id = :h_pid) THEN 1 ELSE 0 END INTO :h_v;
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}
