/*
 * mg_queue_backlog_dbio.pgc - mg 모듈 DB 접근 함수 (mg_queue_backlog_dbio), archived into libmgdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 상태별 큐 적체 건수.
 */
#include <string.h>
#include <userlog.h>
#include "mg_queue_backlog_dbio.h"

long mgdb_queue_backlog(const char *status)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_st[16];
    long h_v = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_st, status, sizeof(h_st)-1); h_st[sizeof(h_st)-1] = 0;
    EXEC SQL SELECT count(*) INTO :h_v FROM mg_queue WHERE status = :h_st;
    if (sqlca.sqlcode < 0) { userlog("mgdb_queue_backlog FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return h_v;
}
