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

/* 당일 조정 사유 가짓수 (count DISTINCT reason). */
long pydb_adjust_reason_variety(const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16];
    long h_v = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL SELECT count(DISTINCT reason) INTO :h_v FROM py_adjust WHERE biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) { userlog("pydb_adjust_reason_variety FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return h_v;
}
