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

/* 단일 지급건 조정 증감 누계 (payout_id 스칼라 키). */
long pydb_adjust_delta_sum(long payout_id)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_pay = payout_id, h_v = 0;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT coalesce(sum(delta),0) INTO :h_v FROM py_adjust WHERE payout_id = :h_pay;
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}

/* 당일 조정 건수. */
long pydb_adjust_count(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(*) INTO :h_v FROM py_adjust WHERE biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}
