/*
 * py_payout_minmax_dbio.pgc - py 모듈 DB 접근 함수 세트 (py_payout_minmax_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_payout_minmax_dbio.h"

/* 당일 최대 지급액. */
long pydb_payout_peak_amount(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 coalesce(max(amount),0) INTO :h_v FROM py_payout WHERE biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}

/* 당일 최소 지급액. */
long pydb_payout_floor_amount(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 coalesce(min(amount),0) INTO :h_v FROM py_payout WHERE biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}
