/*
 * rc_excinsub_dbio.pgc - 미해결 예외 매입에 대한 대사 건수 (rc_excinsub_dbio), librcdbio.a.
 * ECPG; purchase_id IN (SELECT ... FROM rc_exception WHERE resolved=false) 형태의 IN 서브셀렉트.
 */
#include <string.h>
#include <userlog.h>
#include "rc_excinsub_dbio.h"

long rcdb_matches_in_open_exc(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 rc_match_log
        WHERE biz_date = :h_bizdate
          AND purchase_id IN (SELECT purchase_id FROM rc_exception WHERE resolved = false);
    if (sqlca.sqlcode < 0) { userlog("rcdb_matches_in_open_exc FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return h_v;
}
