/*
 * rc_nomatch_dbio.pgc - rc 모듈 DB 접근 함수 세트 (rc_nomatch_dbio), archived into librcdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 대사 로그가 없는 미대사 매입 건수 - NOT EXISTS 서브쿼리.
 */
#include <string.h>
#include <userlog.h>
#include "rc_nomatch_dbio.h"

long rcdb_purchase_no_matchlog(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(*) INTO :h_v FROM purchase p
        WHERE p.biz_date = :h_bizdate
          AND NOT EXISTS (SELECT 1 FROM rc_match_log m WHERE m.purchase_id = p.purchase_id);
    if (sqlca.sqlcode < 0) { userlog("rcdb_purchase_no_matchlog FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return h_v;
}
