/*
 * mg_channel_up_dbio.pgc - mg 모듈 DB 접근 함수 (mg_channel_up_dbio), archived into libmgdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 채널 UP 상태 여부.
 */
#include <string.h>
#include <userlog.h>
#include "mg_channel_up_dbio.h"

int mgdb_channel_is_up(const char *key)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_key[32], h_st[16];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_key, key, sizeof(h_key)-1); h_key[sizeof(h_key)-1] = 0;
    EXEC SQL SELECT status INTO :h_st FROM mg_channel WHERE channel = :h_key;
    if (sqlca.sqlcode == 100) return -1;
    if (sqlca.sqlcode < 0) return -1;
    if (strcmp(h_st, "UP") == 0) return 1;
    return 0;
}
