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

/* 지급 파일 총액 (단순 스칼라). */
long pydb_file_total(long file_id)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_file = file_id, h_v = 0;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT coalesce(total_amount,0) INTO :h_v FROM py_file WHERE file_id = :h_file;
    if (sqlca.sqlcode < 0) { userlog("pydb_file_total FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return h_v;
}

/* 지급 파일 상태 문자 회신. */
int pydb_file_status(long file_id, char *out)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_file = file_id;
    char h_status[8];
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT status INTO :h_status FROM py_file WHERE file_id = :h_file;
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) { userlog("pydb_file_status FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    out[0] = h_status[0];
    out[1] = 0;
    return 0;
}
