/*
 * mm_grade_count_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_grade_count_dbio.h"

long mmdb_grade_count(const char *grade)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_cnt; char h_grade[8];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_grade, grade, sizeof(h_grade)-1); h_grade[sizeof(h_grade)-1] = 0;
    EXEC SQL SELECT count(*) INTO :h_cnt FROM mm_merchant_ext
        WHERE grade = :h_grade AND status = 'ACTIVE';
    if (sqlca.sqlcode < 0) { userlog("mmdb_grade_count FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_cnt;
}
