/*
 * rc_typegrp_dbio.pgc - rc 모듈 DB 접근 함수 세트 (rc_typegrp_dbio), archived into librcdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 대사 유형별 GROUP BY 커서 순회 - 서로 다른 match_type 수 반환.
 */
#include <string.h>
#include <userlog.h>
#include "rc_typegrp_dbio.h"

long rcdb_match_type_kinds(const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16], h_type[24];
    long h_cnt, kinds = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL DECLARE tgc CURSOR FOR
        SELECT match_type, count(*) FROM rc_match_log
        WHERE biz_date = :h_bizdate GROUP BY match_type ORDER BY match_type;
    EXEC SQL OPEN tgc;
    if (sqlca.sqlcode < 0) return -1;
    for (;;) {
        EXEC SQL FETCH tgc INTO :h_type, :h_cnt;
        if (sqlca.sqlcode == 100) break;
        if (sqlca.sqlcode < 0) { EXEC SQL CLOSE tgc; return -1; }
        kinds++;
    }
    EXEC SQL CLOSE tgc;
    return kinds;
}
