/*
 * mg_qforup_dbio.pgc - mg 모듈 DB 접근 함수 (mg_qforup_dbio), archived into libmgdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * UP 상태 채널에 걸린 대기 큐 건수 (IN 서브셀렉트).
 */
#include <string.h>
#include <userlog.h>
#include "mg_qforup_dbio.h"

long mgdb_queue_for_up(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 mg_queue
        WHERE biz_date = :h_bizdate AND status = 'Q'
          AND channel IN (SELECT channel FROM mg_channel WHERE status = 'UP');
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}
