/*
 * mg_route_exists_dbio.pgc - mg 모듈 DB 접근 함수 (mg_route_exists_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_route_exists_dbio.h"

int mgdb_route_channel_exists(const char *key)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_key[64];
    long h_v = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_key, key, sizeof(h_key)-1); h_key[sizeof(h_key)-1] = 0;
    EXEC SQL SELECT count(*) INTO :h_v FROM mg_route WHERE channel = :h_key;
    if (sqlca.sqlcode < 0) return -1;
    return h_v > 0 ? 1 : 0;
}
