/*
 * ac_category_dbio.pgc - ac 모듈 DB 접근 함수 세트 (ac_category_dbio), archived into libacdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "ac_category_dbio.h"

/* 당일 사용된 업종/분류 가짓수 (distinct). */
long acdb_category_variety(const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16];
    long h_v = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL SELECT count(DISTINCT category) INTO :h_v FROM purchase WHERE biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) { userlog("acdb_category_variety FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_v;
}
