/*
 * vl_errminmax_dbio.pgc - vl 모듈 DB 접근 함수 (vl_errminmax_dbio), archived into libvldbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 당일 검증 에러코드 최대-최소 스프레드 (min/max).
 */
#include <string.h>
#include <userlog.h>
#include "vl_errminmax_dbio.h"

long vldb_err_spread(const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16];
    long h_mn = 0, h_mx = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL SELECT coalesce(min(result_code),0), coalesce(max(result_code),0)
        INTO :h_mn, :h_mx FROM vl_check_log
        WHERE biz_date = :h_bizdate AND result_code > 0;
    if (sqlca.sqlcode < 0) return -1;
    return h_mx - h_mn;
}
