/*
 * mg_stanrange_dbio.pgc - mg 모듈 DB 접근 함수 (mg_stanrange_dbio), archived into libmgdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 당일 전문 추적번호(STAN) 최대-최소 범위 (min/max).
 */
#include <string.h>
#include <userlog.h>
#include "mg_stanrange_dbio.h"

long mgdb_stan_spread(const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16];
    long h_lo = 0, h_hi = 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(stan),0), coalesce(max(stan),0)
        INTO :h_lo, :h_hi FROM mg_msg_log WHERE biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) return -1;
    return h_hi - h_lo;
}
