/*
 * mm_code_query_dbio.pgc - 공통코드 명칭 조회 (libmmdbio.a).
 * ECPG functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "mm_code_query_dbio.h"

int mmdb_code_name(const char *grp, const char *code, char *name_out)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_grp[32], h_code[32], h_name[64];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_grp, grp, sizeof(h_grp)-1); h_grp[sizeof(h_grp)-1] = 0;
    strncpy(h_code, code, sizeof(h_code)-1); h_code[sizeof(h_code)-1] = 0;
    EXEC SQL SELECT code_name INTO :h_name FROM mm_code
        WHERE code_group = :h_grp AND code = :h_code;
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) { userlog("mmdb_code_name FAIL [%d]", sqlca.sqlcode); return -1; }
    strncpy(name_out, h_name, 63); name_out[63] = 0;
    return 0;
}
