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

/* ACTIVE 계좌 잔액 총합 (무인자 집계). */
long pydb_account_active_balance(void)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_v = 0;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT coalesce(sum(balance),0) INTO :h_v FROM py_account WHERE status = 'ACTIVE';
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}

/* ACTIVE 계좌 수 (무인자 집계). */
long pydb_account_active_count(void)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_v = 0;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT count(*) INTO :h_v FROM py_account WHERE status = 'ACTIVE';
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}
