고도화: 전 모듈 dbio 25→40 · batch 17→22 세분화 (+432본, 전부 고유)
- 11개 모듈 각 dbio +15(→40), batch +5(→22) 새 고유 ECPG 프로그램 + 카피북 헤더 (window/HAVING/JOIN/FILTER/NOT EXISTS/upsert/correlated/INSERT..SELECT 등 구조 다양) - 전 코퍼스 .pgc 1004/1004 정규화-고유 (dup 그룹 0) - 통합 검증: 12서버 runok, 333 서비스, 242 배치 바이너리, 매입체인 XA 커밋, prepared_xacts=0 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
05ad8a3064
commit
fc16ea64c8
422 changed files with 8717 additions and 0 deletions
50
app/src/cl/batch/cl_gap_batch.pgc
Normal file
50
app/src/cl/batch/cl_gap_batch.pgc
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* cl_gap_batch.pgc - cl 일마감 저장건수 vs 실매입 대사 배치 (커서 + XA).
|
||||
*
|
||||
* period_key 프리픽스의 DAILY 마감을 커서로 훑어, 각 마감의 저장 txn_count 와
|
||||
* 실제 purchase 건수를 비교하여 불일치 마감 수를 집계한다. 전 구간 ONE global XA.
|
||||
* host 변수는 전용 카피북 cl_gap_cpy.h 를 EXEC SQL INCLUDE 로 가져온다.
|
||||
* Usage: cl_gap_batch [YYYY-MM]
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <atmi.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *prefix = (argc > 1) ? argv[1] : "2026-07";
|
||||
long checked = 0, mismatch = 0;
|
||||
|
||||
EXEC SQL INCLUDE cl_gap_cpy;
|
||||
|
||||
strncpy(g_prefix, prefix, sizeof(g_prefix)-1); g_prefix[sizeof(g_prefix)-1] = 0;
|
||||
|
||||
if (tpinit(NULL) < 0) { fprintf(stderr, "tpinit FAIL: %s\n", tpstrerror(tperrno)); return 1; }
|
||||
if (tpopen() < 0) { fprintf(stderr, "tpopen FAIL: %s\n", tpstrerror(tperrno)); return 1; }
|
||||
if (tpbegin(60, 0) < 0) { fprintf(stderr, "tpbegin FAIL: %s\n", tpstrerror(tperrno)); return 1; }
|
||||
|
||||
EXEC SQL DECLARE cgap CURSOR FOR
|
||||
SELECT close_id, to_char(biz_date,'YYYY-MM-DD'), txn_count FROM cl_close_log
|
||||
WHERE close_type = 'DAILY' AND period_key LIKE :g_prefix || '%' AND status <> 'X'
|
||||
ORDER BY biz_date;
|
||||
EXEC SQL OPEN cgap;
|
||||
if (sqlca.sqlcode < 0) { fprintf(stderr, "OPEN FAIL [%d] %s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); tpabort(0); return 1; }
|
||||
|
||||
for (;;) {
|
||||
EXEC SQL FETCH cgap INTO :g_cid, :g_bizdate, :g_stored;
|
||||
if (sqlca.sqlcode == 100) break;
|
||||
if (sqlca.sqlcode < 0) { fprintf(stderr, "FETCH FAIL [%d] %s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); EXEC SQL CLOSE cgap; tpabort(0); return 1; }
|
||||
EXEC SQL SELECT count(*) INTO :g_actual FROM purchase WHERE biz_date = :g_bizdate;
|
||||
if (sqlca.sqlcode < 0) { EXEC SQL CLOSE cgap; tpabort(0); return 1; }
|
||||
checked++;
|
||||
if (g_stored != g_actual) mismatch++;
|
||||
}
|
||||
EXEC SQL CLOSE cgap;
|
||||
|
||||
if (tpcommit(0) < 0) { fprintf(stderr, "tpcommit FAIL: %s\n", tpstrerror(tperrno)); tpabort(0); return 1; }
|
||||
printf(">>> cl_gap_batch COMMIT: prefix=%s 검증=%ld 불일치=%ld\n", prefix, checked, mismatch);
|
||||
|
||||
tpclose(); tpterm();
|
||||
return 0;
|
||||
}
|
||||
8
app/src/cl/batch/cl_gap_cpy.h
Normal file
8
app/src/cl/batch/cl_gap_cpy.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
/* cl_gap_cpy.h - cl_gap_batch 전용 카피북 (host 변수 선언, EXEC SQL INCLUDE 대상). */
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
char g_prefix[16];
|
||||
char g_bizdate[16];
|
||||
long g_cid;
|
||||
long g_stored;
|
||||
long g_actual;
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
35
app/src/cl/batch/cl_purgeold_batch.pgc
Normal file
35
app/src/cl/batch/cl_purgeold_batch.pgc
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* cl_purgeold_batch.pgc - cl 오래된 마감 스냅샷 정리 배치 (DELETE range + XA).
|
||||
*
|
||||
* cutoff 이전(biz_date < cutoff) 마감 스냅샷을 한 문장으로 삭제하고 삭제행수를
|
||||
* sqlca.sqlerrd[2] 로 확인한다. ONE global XA transaction 하에서 수행.
|
||||
* host 변수는 전용 카피북 cl_purgeold_cpy.h 를 EXEC SQL INCLUDE.
|
||||
* Usage: cl_purgeold_batch [YYYY-MM-DD]
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <atmi.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *cutoff = (argc > 1) ? argv[1] : "2026-01-01";
|
||||
|
||||
EXEC SQL INCLUDE cl_purgeold_cpy;
|
||||
|
||||
strncpy(p_cutoff, cutoff, sizeof(p_cutoff)-1); p_cutoff[sizeof(p_cutoff)-1] = 0;
|
||||
|
||||
if (tpinit(NULL) < 0) { fprintf(stderr, "tpinit FAIL: %s\n", tpstrerror(tperrno)); return 1; }
|
||||
if (tpopen() < 0) { fprintf(stderr, "tpopen FAIL: %s\n", tpstrerror(tperrno)); return 1; }
|
||||
if (tpbegin(60, 0) < 0) { fprintf(stderr, "tpbegin FAIL: %s\n", tpstrerror(tperrno)); return 1; }
|
||||
|
||||
EXEC SQL DELETE FROM cl_snapshot WHERE biz_date < :p_cutoff;
|
||||
if (sqlca.sqlcode < 0) { fprintf(stderr, "DELETE FAIL [%d] %s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); tpabort(0); return 1; }
|
||||
p_deleted = (long) sqlca.sqlerrd[2];
|
||||
|
||||
if (tpcommit(0) < 0) { fprintf(stderr, "tpcommit FAIL: %s\n", tpstrerror(tperrno)); tpabort(0); return 1; }
|
||||
printf(">>> cl_purgeold_batch COMMIT: cutoff=%s 삭제=%ld건\n", cutoff, p_deleted);
|
||||
|
||||
tpclose(); tpterm();
|
||||
return 0;
|
||||
}
|
||||
5
app/src/cl/batch/cl_purgeold_cpy.h
Normal file
5
app/src/cl/batch/cl_purgeold_cpy.h
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
/* cl_purgeold_cpy.h - cl_purgeold_batch 전용 카피북 (host 변수 선언). */
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
char p_cutoff[16];
|
||||
long p_deleted;
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
47
app/src/cl/batch/cl_relock_batch.pgc
Normal file
47
app/src/cl/batch/cl_relock_batch.pgc
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* cl_relock_batch.pgc - cl 완료 기간 일괄 잠금 배치 (커서 + upsert + XA).
|
||||
*
|
||||
* status='C' 로 마감된 고유 period_key 를 커서로 훑어 cl_period_lock 에
|
||||
* upsert(ON CONFLICT) 하여 기간을 잠근다. 전 구간 ONE global XA transaction.
|
||||
* host 변수는 전용 카피북 cl_relock_cpy.h 를 EXEC SQL INCLUDE.
|
||||
* Usage: cl_relock_batch
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <atmi.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
long locked = 0;
|
||||
(void) argc; (void) argv;
|
||||
|
||||
EXEC SQL INCLUDE cl_relock_cpy;
|
||||
|
||||
if (tpinit(NULL) < 0) { fprintf(stderr, "tpinit FAIL: %s\n", tpstrerror(tperrno)); return 1; }
|
||||
if (tpopen() < 0) { fprintf(stderr, "tpopen FAIL: %s\n", tpstrerror(tperrno)); return 1; }
|
||||
if (tpbegin(60, 0) < 0) { fprintf(stderr, "tpbegin FAIL: %s\n", tpstrerror(tperrno)); return 1; }
|
||||
|
||||
EXEC SQL DECLARE crel CURSOR FOR
|
||||
SELECT DISTINCT period_key FROM cl_close_log WHERE status = 'C'
|
||||
ORDER BY period_key;
|
||||
EXEC SQL OPEN crel;
|
||||
if (sqlca.sqlcode < 0) { fprintf(stderr, "OPEN FAIL [%d] %s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); tpabort(0); return 1; }
|
||||
|
||||
for (;;) {
|
||||
EXEC SQL FETCH crel INTO :r_period;
|
||||
if (sqlca.sqlcode == 100) break;
|
||||
if (sqlca.sqlcode < 0) { fprintf(stderr, "FETCH FAIL [%d] %s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); EXEC SQL CLOSE crel; tpabort(0); return 1; }
|
||||
EXEC SQL INSERT INTO cl_period_lock (period_key, locked) VALUES (:r_period, true)
|
||||
ON CONFLICT (period_key) DO UPDATE SET locked = true, locked_at = now();
|
||||
if (sqlca.sqlcode < 0) { fprintf(stderr, "UPSERT FAIL [%d] %s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); EXEC SQL CLOSE crel; tpabort(0); return 1; }
|
||||
locked++;
|
||||
}
|
||||
EXEC SQL CLOSE crel;
|
||||
|
||||
if (tpcommit(0) < 0) { fprintf(stderr, "tpcommit FAIL: %s\n", tpstrerror(tperrno)); tpabort(0); return 1; }
|
||||
printf(">>> cl_relock_batch COMMIT: 잠금기간=%ld\n", locked);
|
||||
|
||||
tpclose(); tpterm();
|
||||
return 0;
|
||||
}
|
||||
4
app/src/cl/batch/cl_relock_cpy.h
Normal file
4
app/src/cl/batch/cl_relock_cpy.h
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
/* cl_relock_cpy.h - cl_relock_batch 전용 카피북 (host 변수 선언). */
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
char r_period[16];
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
51
app/src/cl/batch/cl_reweigh_batch.pgc
Normal file
51
app/src/cl/batch/cl_reweigh_batch.pgc
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* cl_reweigh_batch.pgc - cl 마감 총액 스냅샷 재계산 배치 (커서 + UPDATE + XA).
|
||||
*
|
||||
* period_key 프리픽스 마감을 커서로 훑어, 각 마감의 스냅샷 net 합을 다시 계산하여
|
||||
* cl_close_log.total_amount 를 갱신한다. 전 구간 ONE global XA transaction.
|
||||
* host 변수는 전용 카피북 cl_reweigh_cpy.h 를 EXEC SQL INCLUDE.
|
||||
* Usage: cl_reweigh_batch [YYYY-MM]
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <atmi.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *prefix = (argc > 1) ? argv[1] : "2026-07";
|
||||
long updated = 0;
|
||||
|
||||
EXEC SQL INCLUDE cl_reweigh_cpy;
|
||||
|
||||
strncpy(w_prefix, prefix, sizeof(w_prefix)-1); w_prefix[sizeof(w_prefix)-1] = 0;
|
||||
|
||||
if (tpinit(NULL) < 0) { fprintf(stderr, "tpinit FAIL: %s\n", tpstrerror(tperrno)); return 1; }
|
||||
if (tpopen() < 0) { fprintf(stderr, "tpopen FAIL: %s\n", tpstrerror(tperrno)); return 1; }
|
||||
if (tpbegin(60, 0) < 0) { fprintf(stderr, "tpbegin FAIL: %s\n", tpstrerror(tperrno)); return 1; }
|
||||
|
||||
EXEC SQL DECLARE crw CURSOR FOR
|
||||
SELECT close_id FROM cl_close_log
|
||||
WHERE period_key LIKE :w_prefix || '%' AND status <> 'X'
|
||||
ORDER BY close_id;
|
||||
EXEC SQL OPEN crw;
|
||||
if (sqlca.sqlcode < 0) { fprintf(stderr, "OPEN FAIL [%d] %s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); tpabort(0); return 1; }
|
||||
|
||||
for (;;) {
|
||||
EXEC SQL FETCH crw INTO :w_cid;
|
||||
if (sqlca.sqlcode == 100) break;
|
||||
if (sqlca.sqlcode < 0) { fprintf(stderr, "FETCH FAIL [%d] %s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); EXEC SQL CLOSE crw; tpabort(0); return 1; }
|
||||
EXEC SQL SELECT coalesce(sum(net_amount),0) INTO :w_sum FROM cl_snapshot WHERE close_id = :w_cid;
|
||||
if (sqlca.sqlcode < 0) { EXEC SQL CLOSE crw; tpabort(0); return 1; }
|
||||
EXEC SQL UPDATE cl_close_log SET total_amount = :w_sum, updated_at = now() WHERE close_id = :w_cid;
|
||||
if (sqlca.sqlcode < 0) { fprintf(stderr, "UPDATE FAIL [%d] %s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); EXEC SQL CLOSE crw; tpabort(0); return 1; }
|
||||
updated++;
|
||||
}
|
||||
EXEC SQL CLOSE crw;
|
||||
|
||||
if (tpcommit(0) < 0) { fprintf(stderr, "tpcommit FAIL: %s\n", tpstrerror(tperrno)); tpabort(0); return 1; }
|
||||
printf(">>> cl_reweigh_batch COMMIT: prefix=%s 재계산=%ld건\n", prefix, updated);
|
||||
|
||||
tpclose(); tpterm();
|
||||
return 0;
|
||||
}
|
||||
6
app/src/cl/batch/cl_reweigh_cpy.h
Normal file
6
app/src/cl/batch/cl_reweigh_cpy.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
/* cl_reweigh_cpy.h - cl_reweigh_batch 전용 카피북 (host 변수 선언). */
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
char w_prefix[16];
|
||||
long w_cid;
|
||||
long w_sum;
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
39
app/src/cl/batch/cl_tierstat_batch.pgc
Normal file
39
app/src/cl/batch/cl_tierstat_batch.pgc
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* cl_tierstat_batch.pgc - cl 마감 총액 구간 분포 배치 (CASE 집계 + XA).
|
||||
*
|
||||
* period_key 프리픽스 마감을 총액 소/중/대 구간으로 CASE 분류하여 각 구간 건수를
|
||||
* 한 행으로 집계해 보고한다. ONE global XA transaction (read-committed).
|
||||
* host 변수는 전용 카피북 cl_tierstat_cpy.h 를 EXEC SQL INCLUDE.
|
||||
* Usage: cl_tierstat_batch [YYYY-MM]
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <atmi.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *prefix = (argc > 1) ? argv[1] : "2026-07";
|
||||
|
||||
EXEC SQL INCLUDE cl_tierstat_cpy;
|
||||
|
||||
strncpy(t_prefix, prefix, sizeof(t_prefix)-1); t_prefix[sizeof(t_prefix)-1] = 0;
|
||||
|
||||
if (tpinit(NULL) < 0) { fprintf(stderr, "tpinit FAIL: %s\n", tpstrerror(tperrno)); return 1; }
|
||||
if (tpopen() < 0) { fprintf(stderr, "tpopen FAIL: %s\n", tpstrerror(tperrno)); return 1; }
|
||||
if (tpbegin(60, 0) < 0) { fprintf(stderr, "tpbegin FAIL: %s\n", tpstrerror(tperrno)); return 1; }
|
||||
|
||||
EXEC SQL SELECT
|
||||
coalesce(sum(CASE WHEN total_amount < 1000000 THEN 1 ELSE 0 END),0),
|
||||
coalesce(sum(CASE WHEN total_amount >= 1000000 AND total_amount < 100000000 THEN 1 ELSE 0 END),0),
|
||||
coalesce(sum(CASE WHEN total_amount >= 100000000 THEN 1 ELSE 0 END),0)
|
||||
INTO :t_lo, :t_mid, :t_hi FROM cl_close_log
|
||||
WHERE period_key LIKE :t_prefix || '%' AND status <> 'X';
|
||||
if (sqlca.sqlcode < 0) { fprintf(stderr, "AGG FAIL [%d] %s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); tpabort(0); return 1; }
|
||||
|
||||
if (tpcommit(0) < 0) { fprintf(stderr, "tpcommit FAIL: %s\n", tpstrerror(tperrno)); tpabort(0); return 1; }
|
||||
printf(">>> cl_tierstat_batch COMMIT: prefix=%s 소=%ld 중=%ld 대=%ld\n", prefix, t_lo, t_mid, t_hi);
|
||||
|
||||
tpclose(); tpterm();
|
||||
return 0;
|
||||
}
|
||||
7
app/src/cl/batch/cl_tierstat_cpy.h
Normal file
7
app/src/cl/batch/cl_tierstat_cpy.h
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
/* cl_tierstat_cpy.h - cl_tierstat_batch 전용 카피북 (host 변수 선언). */
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
char t_prefix[16];
|
||||
long t_lo;
|
||||
long t_mid;
|
||||
long t_hi;
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
9
app/src/cl/dbio/cl_corr_sub_dbio.h
Normal file
9
app/src/cl/dbio/cl_corr_sub_dbio.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* cl_corr_sub_dbio.h - cl 모듈 DB 접근 계층 copybook (cl_corr_sub_dbio, part of libcldbio.a).
|
||||
* 마감별 스냅샷 수 상관 서브쿼리 순회 최대치 (correlated subquery + cursor).
|
||||
* Return convention: >=0 ok, -1 = SQL error.
|
||||
*/
|
||||
#ifndef CL_CORR_SUB_DBIO_H
|
||||
#define CL_CORR_SUB_DBIO_H
|
||||
long clqdb_corr_max_snap(const char *ctype);
|
||||
#endif /* CL_CORR_SUB_DBIO_H */
|
||||
34
app/src/cl/dbio/cl_corr_sub_dbio.pgc
Normal file
34
app/src/cl/dbio/cl_corr_sub_dbio.pgc
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* cl_corr_sub_dbio.pgc - cl 모듈 DB 접근 함수 (cl_corr_sub_dbio), archived into libcldbio.a.
|
||||
* 마감별 스냅샷 수 상관 서브쿼리 순회 최대치 (correlated subquery + cursor).
|
||||
* ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <userlog.h>
|
||||
#include "cl_corr_sub_dbio.h"
|
||||
|
||||
/* 각 마감의 스냅샷 수를 상관 서브쿼리로 뽑아 커서로 훑어 최대값 반환. */
|
||||
long clqdb_corr_max_snap(const char *ctype)
|
||||
{
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
char h_type[16];
|
||||
long h_cid, h_snaps;
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
long peak = 0;
|
||||
strncpy(h_type, ctype, sizeof(h_type)-1); h_type[sizeof(h_type)-1] = 0;
|
||||
EXEC SQL DECLARE ccs CURSOR FOR
|
||||
SELECT c.close_id,
|
||||
(SELECT count(*) FROM cl_snapshot s WHERE s.close_id = c.close_id)
|
||||
FROM cl_close_log c WHERE c.close_type = :h_type AND c.status <> 'X'
|
||||
ORDER BY c.close_id;
|
||||
EXEC SQL OPEN ccs;
|
||||
if (sqlca.sqlcode < 0) return -1;
|
||||
for (;;) {
|
||||
EXEC SQL FETCH ccs INTO :h_cid, :h_snaps;
|
||||
if (sqlca.sqlcode == 100) break;
|
||||
if (sqlca.sqlcode < 0) { EXEC SQL CLOSE ccs; return -1; }
|
||||
if (h_snaps > peak) peak = h_snaps;
|
||||
}
|
||||
EXEC SQL CLOSE ccs;
|
||||
return peak;
|
||||
}
|
||||
9
app/src/cl/dbio/cl_lock_upsert_dbio.h
Normal file
9
app/src/cl/dbio/cl_lock_upsert_dbio.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* cl_lock_upsert_dbio.h - cl 모듈 DB 접근 계층 copybook (cl_lock_upsert_dbio, part of libcldbio.a).
|
||||
* 기간잠금 upsert (ON CONFLICT).
|
||||
* Return convention: >=0 ok, -1 = SQL error.
|
||||
*/
|
||||
#ifndef CL_LOCK_UPSERT_DBIO_H
|
||||
#define CL_LOCK_UPSERT_DBIO_H
|
||||
int cldb_lock_upsert(const char *period, int locked);
|
||||
#endif /* CL_LOCK_UPSERT_DBIO_H */
|
||||
24
app/src/cl/dbio/cl_lock_upsert_dbio.pgc
Normal file
24
app/src/cl/dbio/cl_lock_upsert_dbio.pgc
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* cl_lock_upsert_dbio.pgc - cl 모듈 DB 접근 함수 (cl_lock_upsert_dbio), archived into libcldbio.a.
|
||||
* 기간잠금 upsert (ON CONFLICT).
|
||||
* ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <userlog.h>
|
||||
#include "cl_lock_upsert_dbio.h"
|
||||
|
||||
/* cl_period_lock 에 잠금 여부를 upsert. */
|
||||
int cldb_lock_upsert(const char *period, int locked)
|
||||
{
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
char h_period[16];
|
||||
int h_locked = locked;
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
strncpy(h_period, period, sizeof(h_period)-1); h_period[sizeof(h_period)-1] = 0;
|
||||
EXEC SQL INSERT INTO cl_period_lock (period_key, locked)
|
||||
VALUES (:h_period, :h_locked)
|
||||
ON CONFLICT (period_key) DO UPDATE
|
||||
SET locked = EXCLUDED.locked, locked_at = now();
|
||||
if (sqlca.sqlcode < 0) { userlog("cldb_lock_upsert FAIL [%d]", sqlca.sqlcode); return -1; }
|
||||
return 0;
|
||||
}
|
||||
9
app/src/cl/dbio/cl_minmax_dbio.h
Normal file
9
app/src/cl/dbio/cl_minmax_dbio.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* cl_minmax_dbio.h - cl 모듈 DB 접근 계층 copybook (cl_minmax_dbio, part of libcldbio.a).
|
||||
* 기간 프리픽스 마감 총액 최소/최대 (min/max).
|
||||
* Return convention: >=0 ok, -1 = SQL error.
|
||||
*/
|
||||
#ifndef CL_MINMAX_DBIO_H
|
||||
#define CL_MINMAX_DBIO_H
|
||||
int clqdb_minmax(const char *prefix, long *lo, long *hi);
|
||||
#endif /* CL_MINMAX_DBIO_H */
|
||||
24
app/src/cl/dbio/cl_minmax_dbio.pgc
Normal file
24
app/src/cl/dbio/cl_minmax_dbio.pgc
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* cl_minmax_dbio.pgc - cl 모듈 DB 접근 함수 (cl_minmax_dbio), archived into libcldbio.a.
|
||||
* 기간 프리픽스 마감 총액 최소/최대 (min/max).
|
||||
* ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <userlog.h>
|
||||
#include "cl_minmax_dbio.h"
|
||||
|
||||
/* period_key 프리픽스 마감의 total_amount 최소/최대를 반환. */
|
||||
int clqdb_minmax(const char *prefix, long *lo, long *hi)
|
||||
{
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
char h_prefix[16];
|
||||
long h_lo = 0, h_hi = 0;
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
strncpy(h_prefix, prefix, sizeof(h_prefix)-1); h_prefix[sizeof(h_prefix)-1] = 0;
|
||||
EXEC SQL SELECT coalesce(min(total_amount),0), coalesce(max(total_amount),0)
|
||||
INTO :h_lo, :h_hi FROM cl_close_log
|
||||
WHERE period_key LIKE :h_prefix || '%' AND status <> 'X';
|
||||
if (sqlca.sqlcode < 0) return -1;
|
||||
*lo = h_lo; *hi = h_hi;
|
||||
return 0;
|
||||
}
|
||||
9
app/src/cl/dbio/cl_snap_distinct_dbio.h
Normal file
9
app/src/cl/dbio/cl_snap_distinct_dbio.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* cl_snap_distinct_dbio.h - cl 모듈 DB 접근 계층 copybook (cl_snap_distinct_dbio, part of libcldbio.a).
|
||||
* 마감 스냅샷 고유 가맹점 수 (count DISTINCT).
|
||||
* Return convention: >=0 ok, -1 = SQL error.
|
||||
*/
|
||||
#ifndef CL_SNAP_DISTINCT_DBIO_H
|
||||
#define CL_SNAP_DISTINCT_DBIO_H
|
||||
long clqdb_snap_distinct(long cid);
|
||||
#endif /* CL_SNAP_DISTINCT_DBIO_H */
|
||||
20
app/src/cl/dbio/cl_snap_distinct_dbio.pgc
Normal file
20
app/src/cl/dbio/cl_snap_distinct_dbio.pgc
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* cl_snap_distinct_dbio.pgc - cl 모듈 DB 접근 함수 (cl_snap_distinct_dbio), archived into libcldbio.a.
|
||||
* 마감 스냅샷 고유 가맹점 수 (count DISTINCT).
|
||||
* ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <userlog.h>
|
||||
#include "cl_snap_distinct_dbio.h"
|
||||
|
||||
/* close_id 스냅샷의 고유 가맹점 수. */
|
||||
long clqdb_snap_distinct(long cid)
|
||||
{
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
long h_cid = cid, h_v = 0;
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
EXEC SQL SELECT count(DISTINCT merchant_id) INTO :h_v FROM cl_snapshot
|
||||
WHERE close_id = :h_cid;
|
||||
if (sqlca.sqlcode < 0) return -1;
|
||||
return h_v;
|
||||
}
|
||||
9
app/src/cl/dbio/cl_snap_in_dbio.h
Normal file
9
app/src/cl/dbio/cl_snap_in_dbio.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* cl_snap_in_dbio.h - cl 모듈 DB 접근 계층 copybook (cl_snap_in_dbio, part of libcldbio.a).
|
||||
* 특정 마감유형에 속한 스냅샷 net 합 (IN 서브셀렉트).
|
||||
* Return convention: >=0 ok, -1 = SQL error.
|
||||
*/
|
||||
#ifndef CL_SNAP_IN_DBIO_H
|
||||
#define CL_SNAP_IN_DBIO_H
|
||||
long clqdb_snap_in_net(const char *ctype);
|
||||
#endif /* CL_SNAP_IN_DBIO_H */
|
||||
23
app/src/cl/dbio/cl_snap_in_dbio.pgc
Normal file
23
app/src/cl/dbio/cl_snap_in_dbio.pgc
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* cl_snap_in_dbio.pgc - cl 모듈 DB 접근 함수 (cl_snap_in_dbio), archived into libcldbio.a.
|
||||
* 특정 마감유형에 속한 스냅샷 net 합 (IN 서브셀렉트).
|
||||
* ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <userlog.h>
|
||||
#include "cl_snap_in_dbio.h"
|
||||
|
||||
/* close_type 에 해당하는 close_id 집합(IN)의 스냅샷 net 합계. */
|
||||
long clqdb_snap_in_net(const char *ctype)
|
||||
{
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
char h_type[16];
|
||||
long h_v = 0;
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
strncpy(h_type, ctype, sizeof(h_type)-1); h_type[sizeof(h_type)-1] = 0;
|
||||
EXEC SQL SELECT coalesce(sum(net_amount),0) INTO :h_v FROM cl_snapshot
|
||||
WHERE close_id IN (SELECT close_id FROM cl_close_log
|
||||
WHERE close_type = :h_type AND status <> 'X');
|
||||
if (sqlca.sqlcode < 0) return -1;
|
||||
return h_v;
|
||||
}
|
||||
9
app/src/cl/dbio/cl_snap_insert_sel_dbio.h
Normal file
9
app/src/cl/dbio/cl_snap_insert_sel_dbio.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* cl_snap_insert_sel_dbio.h - cl 모듈 DB 접근 계층 copybook (cl_snap_insert_sel_dbio, part of libcldbio.a).
|
||||
* merchant_summary 로부터 스냅샷 일괄 적재 (INSERT..SELECT).
|
||||
* Return convention: >=0 ok(적재건수), -1 = SQL error.
|
||||
*/
|
||||
#ifndef CL_SNAP_INSERT_SEL_DBIO_H
|
||||
#define CL_SNAP_INSERT_SEL_DBIO_H
|
||||
long cldb_snap_insert_sel(long cid, long sid_base, const char *period, const char *bizdate);
|
||||
#endif /* CL_SNAP_INSERT_SEL_DBIO_H */
|
||||
28
app/src/cl/dbio/cl_snap_insert_sel_dbio.pgc
Normal file
28
app/src/cl/dbio/cl_snap_insert_sel_dbio.pgc
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* cl_snap_insert_sel_dbio.pgc - cl 모듈 DB 접근 함수 (cl_snap_insert_sel_dbio), archived into libcldbio.a.
|
||||
* merchant_summary 로부터 스냅샷 일괄 적재 (INSERT..SELECT).
|
||||
* ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <userlog.h>
|
||||
#include "cl_snap_insert_sel_dbio.h"
|
||||
|
||||
/* 당일 merchant_summary 를 스냅샷으로 한 문장에 적재, 적재건수 반환. */
|
||||
long cldb_snap_insert_sel(long cid, long sid_base, const char *period, const char *bizdate)
|
||||
{
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
long h_cid = cid, h_base = sid_base;
|
||||
char h_period[16], h_bizdate[16];
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
strncpy(h_period, period, sizeof(h_period)-1); h_period[sizeof(h_period)-1] = 0;
|
||||
strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
|
||||
EXEC SQL INSERT INTO cl_snapshot
|
||||
(snapshot_id, close_id, period_key, biz_date, merchant_id,
|
||||
gross_amount, fee_amount, net_amount, txn_count)
|
||||
SELECT :h_base + row_number() OVER (ORDER BY merchant_id),
|
||||
:h_cid, :h_period, :h_bizdate, merchant_id,
|
||||
gross_amount, fee_amount, net_amount, txn_count
|
||||
FROM merchant_summary WHERE biz_date = :h_bizdate;
|
||||
if (sqlca.sqlcode < 0) { userlog("cldb_snap_insert_sel FAIL [%d]", sqlca.sqlcode); return -1; }
|
||||
return (long) sqlca.sqlerrd[2];
|
||||
}
|
||||
9
app/src/cl/dbio/cl_snap_join_dbio.h
Normal file
9
app/src/cl/dbio/cl_snap_join_dbio.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* cl_snap_join_dbio.h - cl 모듈 DB 접근 계층 copybook (cl_snap_join_dbio, part of libcldbio.a).
|
||||
* 완료 마감(JOIN)에 속한 가맹점 gross 합계.
|
||||
* Return convention: >=0 ok, -1 = SQL error.
|
||||
*/
|
||||
#ifndef CL_SNAP_JOIN_DBIO_H
|
||||
#define CL_SNAP_JOIN_DBIO_H
|
||||
long clqdb_snap_join_gross(const char *merch);
|
||||
#endif /* CL_SNAP_JOIN_DBIO_H */
|
||||
23
app/src/cl/dbio/cl_snap_join_dbio.pgc
Normal file
23
app/src/cl/dbio/cl_snap_join_dbio.pgc
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* cl_snap_join_dbio.pgc - cl 모듈 DB 접근 함수 (cl_snap_join_dbio), archived into libcldbio.a.
|
||||
* 완료 마감(JOIN)에 속한 가맹점 gross 합계.
|
||||
* ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <userlog.h>
|
||||
#include "cl_snap_join_dbio.h"
|
||||
|
||||
/* cl_snapshot 을 cl_close_log 와 조인해 status='C' 마감의 가맹점 gross 합. */
|
||||
long clqdb_snap_join_gross(const char *merch)
|
||||
{
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
char h_merch[64];
|
||||
long h_v = 0;
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
strncpy(h_merch, merch, sizeof(h_merch)-1); h_merch[sizeof(h_merch)-1] = 0;
|
||||
EXEC SQL SELECT coalesce(sum(s.gross_amount),0) INTO :h_v
|
||||
FROM cl_snapshot s JOIN cl_close_log c ON s.close_id = c.close_id
|
||||
WHERE c.status = 'C' AND s.merchant_id = :h_merch;
|
||||
if (sqlca.sqlcode < 0) { userlog("clqdb_snap_join_gross FAIL [%d]", sqlca.sqlcode); return -1; }
|
||||
return h_v;
|
||||
}
|
||||
9
app/src/cl/dbio/cl_snap_purge_dbio.h
Normal file
9
app/src/cl/dbio/cl_snap_purge_dbio.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* cl_snap_purge_dbio.h - cl 모듈 DB 접근 계층 copybook (cl_snap_purge_dbio, part of libcldbio.a).
|
||||
* 마감 스냅샷 범위 삭제 후 삭제건수 반환 (DELETE range).
|
||||
* Return convention: >=0 ok(삭제건수), -1 = SQL error.
|
||||
*/
|
||||
#ifndef CL_SNAP_PURGE_DBIO_H
|
||||
#define CL_SNAP_PURGE_DBIO_H
|
||||
long cldb_snap_purge(const char *bizdate);
|
||||
#endif /* CL_SNAP_PURGE_DBIO_H */
|
||||
20
app/src/cl/dbio/cl_snap_purge_dbio.pgc
Normal file
20
app/src/cl/dbio/cl_snap_purge_dbio.pgc
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* cl_snap_purge_dbio.pgc - cl 모듈 DB 접근 함수 (cl_snap_purge_dbio), archived into libcldbio.a.
|
||||
* 마감 스냅샷 범위 삭제 후 삭제건수 반환 (DELETE range).
|
||||
* ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <userlog.h>
|
||||
#include "cl_snap_purge_dbio.h"
|
||||
|
||||
/* biz_date 이하 스냅샷 삭제, 삭제 행수 반환. */
|
||||
long cldb_snap_purge(const char *bizdate)
|
||||
{
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
char h_bizdate[16];
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
|
||||
EXEC SQL DELETE FROM cl_snapshot WHERE biz_date <= :h_bizdate;
|
||||
if (sqlca.sqlcode < 0) { userlog("cldb_snap_purge FAIL [%d]", sqlca.sqlcode); return -1; }
|
||||
return (long) sqlca.sqlerrd[2];
|
||||
}
|
||||
9
app/src/cl/dbio/cl_snap_rank_dbio.h
Normal file
9
app/src/cl/dbio/cl_snap_rank_dbio.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* cl_snap_rank_dbio.h - cl 모듈 DB 접근 계층 copybook (cl_snap_rank_dbio, part of libcldbio.a).
|
||||
* 마감 스냅샷 gross 순위 n번째 가맹점 (window ROW_NUMBER).
|
||||
* Return convention: >=0 ok, -1 = SQL error.
|
||||
*/
|
||||
#ifndef CL_SNAP_RANK_DBIO_H
|
||||
#define CL_SNAP_RANK_DBIO_H
|
||||
int clqdb_snap_rank(long cid, long rank, char *merch_out);
|
||||
#endif /* CL_SNAP_RANK_DBIO_H */
|
||||
25
app/src/cl/dbio/cl_snap_rank_dbio.pgc
Normal file
25
app/src/cl/dbio/cl_snap_rank_dbio.pgc
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* cl_snap_rank_dbio.pgc - cl 모듈 DB 접근 함수 (cl_snap_rank_dbio), archived into libcldbio.a.
|
||||
* 마감 스냅샷 gross 순위 n번째 가맹점 (window ROW_NUMBER).
|
||||
* ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <userlog.h>
|
||||
#include "cl_snap_rank_dbio.h"
|
||||
|
||||
/* close_id 스냅샷에서 gross 내림차순 rank 번째 가맹점 반환. */
|
||||
int clqdb_snap_rank(long cid, long rank, char *merch_out)
|
||||
{
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
long h_cid = cid, h_rank = rank;
|
||||
char h_merch[64];
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
EXEC SQL SELECT merchant_id INTO :h_merch FROM (
|
||||
SELECT merchant_id, row_number() OVER (ORDER BY gross_amount DESC) AS rn
|
||||
FROM cl_snapshot WHERE close_id = :h_cid) t
|
||||
WHERE t.rn = :h_rank;
|
||||
if (sqlca.sqlcode == 100) { merch_out[0] = 0; return 0; }
|
||||
if (sqlca.sqlcode < 0) return -1;
|
||||
strcpy(merch_out, h_merch);
|
||||
return 0;
|
||||
}
|
||||
9
app/src/cl/dbio/cl_status_filter_dbio.h
Normal file
9
app/src/cl/dbio/cl_status_filter_dbio.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* cl_status_filter_dbio.h - cl 모듈 DB 접근 계층 copybook (cl_status_filter_dbio, part of libcldbio.a).
|
||||
* 마감 상태별 건수 한 행 분리집계 (FILTER).
|
||||
* Return convention: >=0 ok, -1 = SQL error.
|
||||
*/
|
||||
#ifndef CL_STATUS_FILTER_DBIO_H
|
||||
#define CL_STATUS_FILTER_DBIO_H
|
||||
int clqdb_status_filter(const char *prefix, long *opn, long *closed, long *locked);
|
||||
#endif /* CL_STATUS_FILTER_DBIO_H */
|
||||
27
app/src/cl/dbio/cl_status_filter_dbio.pgc
Normal file
27
app/src/cl/dbio/cl_status_filter_dbio.pgc
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* cl_status_filter_dbio.pgc - cl 모듈 DB 접근 함수 (cl_status_filter_dbio), archived into libcldbio.a.
|
||||
* 마감 상태별 건수 한 행 분리집계 (FILTER).
|
||||
* ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <userlog.h>
|
||||
#include "cl_status_filter_dbio.h"
|
||||
|
||||
/* 개시(O)/완료(C)/잠금(L) 건수를 FILTER 로 한 번에 반환. */
|
||||
int clqdb_status_filter(const char *prefix, long *opn, long *closed, long *locked)
|
||||
{
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
char h_prefix[16];
|
||||
long h_o = 0, h_c = 0, h_l = 0;
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
strncpy(h_prefix, prefix, sizeof(h_prefix)-1); h_prefix[sizeof(h_prefix)-1] = 0;
|
||||
EXEC SQL SELECT
|
||||
count(*) FILTER (WHERE status = 'O'),
|
||||
count(*) FILTER (WHERE status = 'C'),
|
||||
count(*) FILTER (WHERE status = 'L')
|
||||
INTO :h_o, :h_c, :h_l FROM cl_close_log
|
||||
WHERE period_key LIKE :h_prefix || '%';
|
||||
if (sqlca.sqlcode < 0) return -1;
|
||||
*opn = h_o; *closed = h_c; *locked = h_l;
|
||||
return 0;
|
||||
}
|
||||
9
app/src/cl/dbio/cl_streak_cursor_dbio.h
Normal file
9
app/src/cl/dbio/cl_streak_cursor_dbio.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* cl_streak_cursor_dbio.h - cl 모듈 DB 접근 계층 copybook (cl_streak_cursor_dbio, part of libcldbio.a).
|
||||
* 일마감 연속 완료 최장 구간 (cursor + 상태 누적).
|
||||
* Return convention: >=0 ok, -1 = SQL error.
|
||||
*/
|
||||
#ifndef CL_STREAK_CURSOR_DBIO_H
|
||||
#define CL_STREAK_CURSOR_DBIO_H
|
||||
long clqdb_close_streak(const char *prefix);
|
||||
#endif /* CL_STREAK_CURSOR_DBIO_H */
|
||||
33
app/src/cl/dbio/cl_streak_cursor_dbio.pgc
Normal file
33
app/src/cl/dbio/cl_streak_cursor_dbio.pgc
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* cl_streak_cursor_dbio.pgc - cl 모듈 DB 접근 함수 (cl_streak_cursor_dbio), archived into libcldbio.a.
|
||||
* 일마감 연속 완료 최장 구간 (cursor + 상태 누적).
|
||||
* ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <userlog.h>
|
||||
#include "cl_streak_cursor_dbio.h"
|
||||
|
||||
/* 날짜순 DAILY 마감을 훑어 status='C' 연속 최장 구간 길이 반환. */
|
||||
long clqdb_close_streak(const char *prefix)
|
||||
{
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
char h_prefix[16], h_status[4];
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
long cur = 0, best = 0;
|
||||
strncpy(h_prefix, prefix, sizeof(h_prefix)-1); h_prefix[sizeof(h_prefix)-1] = 0;
|
||||
EXEC SQL DECLARE csk CURSOR FOR
|
||||
SELECT status FROM cl_close_log
|
||||
WHERE close_type = 'DAILY' AND period_key LIKE :h_prefix || '%'
|
||||
ORDER BY biz_date;
|
||||
EXEC SQL OPEN csk;
|
||||
if (sqlca.sqlcode < 0) return -1;
|
||||
for (;;) {
|
||||
EXEC SQL FETCH csk INTO :h_status;
|
||||
if (sqlca.sqlcode == 100) break;
|
||||
if (sqlca.sqlcode < 0) { EXEC SQL CLOSE csk; return -1; }
|
||||
if (h_status[0] == 'C') { cur++; if (cur > best) best = cur; }
|
||||
else cur = 0;
|
||||
}
|
||||
EXEC SQL CLOSE csk;
|
||||
return best;
|
||||
}
|
||||
9
app/src/cl/dbio/cl_tier_case_dbio.h
Normal file
9
app/src/cl/dbio/cl_tier_case_dbio.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* cl_tier_case_dbio.h - cl 모듈 DB 접근 계층 copybook (cl_tier_case_dbio, part of libcldbio.a).
|
||||
* 마감 총액 구간별 건수 (CASE 집계).
|
||||
* Return convention: >=0 ok, -1 = SQL error.
|
||||
*/
|
||||
#ifndef CL_TIER_CASE_DBIO_H
|
||||
#define CL_TIER_CASE_DBIO_H
|
||||
int clqdb_tier_case(long small, long large, long *lo, long *mid, long *hi);
|
||||
#endif /* CL_TIER_CASE_DBIO_H */
|
||||
24
app/src/cl/dbio/cl_tier_case_dbio.pgc
Normal file
24
app/src/cl/dbio/cl_tier_case_dbio.pgc
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* cl_tier_case_dbio.pgc - cl 모듈 DB 접근 함수 (cl_tier_case_dbio), archived into libcldbio.a.
|
||||
* 마감 총액 구간별 건수 (CASE 집계).
|
||||
* ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <userlog.h>
|
||||
#include "cl_tier_case_dbio.h"
|
||||
|
||||
/* total_amount 을 소/중/대 구간으로 CASE 분류해 각 건수 반환. */
|
||||
int clqdb_tier_case(long small, long large, long *lo, long *mid, long *hi)
|
||||
{
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
long h_small = small, h_large = large, h_lo = 0, h_mid = 0, h_hi = 0;
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
EXEC SQL SELECT
|
||||
coalesce(sum(CASE WHEN total_amount < :h_small THEN 1 ELSE 0 END),0),
|
||||
coalesce(sum(CASE WHEN total_amount >= :h_small AND total_amount < :h_large THEN 1 ELSE 0 END),0),
|
||||
coalesce(sum(CASE WHEN total_amount >= :h_large THEN 1 ELSE 0 END),0)
|
||||
INTO :h_lo, :h_mid, :h_hi FROM cl_close_log WHERE status <> 'X';
|
||||
if (sqlca.sqlcode < 0) return -1;
|
||||
*lo = h_lo; *mid = h_mid; *hi = h_hi;
|
||||
return 0;
|
||||
}
|
||||
9
app/src/cl/dbio/cl_type_having_dbio.h
Normal file
9
app/src/cl/dbio/cl_type_having_dbio.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* cl_type_having_dbio.h - cl 모듈 DB 접근 계층 copybook (cl_type_having_dbio, part of libcldbio.a).
|
||||
* 마감유형별 건수 임계 초과 유형 수 (GROUP BY ... HAVING).
|
||||
* Return convention: >=0 ok, -1 = SQL error.
|
||||
*/
|
||||
#ifndef CL_TYPE_HAVING_DBIO_H
|
||||
#define CL_TYPE_HAVING_DBIO_H
|
||||
long clqdb_type_having(long min_cnt);
|
||||
#endif /* CL_TYPE_HAVING_DBIO_H */
|
||||
32
app/src/cl/dbio/cl_type_having_dbio.pgc
Normal file
32
app/src/cl/dbio/cl_type_having_dbio.pgc
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* cl_type_having_dbio.pgc - cl 모듈 DB 접근 함수 (cl_type_having_dbio), archived into libcldbio.a.
|
||||
* 마감유형별 건수 임계 초과 유형 수 (GROUP BY ... HAVING 커서).
|
||||
* ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <userlog.h>
|
||||
#include "cl_type_having_dbio.h"
|
||||
|
||||
/* close_type 별 마감 건수가 min_cnt 이상인 유형 개수. */
|
||||
long clqdb_type_having(long min_cnt)
|
||||
{
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
long h_min = min_cnt, h_cnt;
|
||||
char h_type[16];
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
long types = 0;
|
||||
EXEC SQL DECLARE cth CURSOR FOR
|
||||
SELECT close_type, count(*) FROM cl_close_log
|
||||
WHERE status <> 'X' GROUP BY close_type HAVING count(*) >= :h_min
|
||||
ORDER BY close_type;
|
||||
EXEC SQL OPEN cth;
|
||||
if (sqlca.sqlcode < 0) return -1;
|
||||
for (;;) {
|
||||
EXEC SQL FETCH cth INTO :h_type, :h_cnt;
|
||||
if (sqlca.sqlcode == 100) break;
|
||||
if (sqlca.sqlcode < 0) { EXEC SQL CLOSE cth; return -1; }
|
||||
types++;
|
||||
}
|
||||
EXEC SQL CLOSE cth;
|
||||
return types;
|
||||
}
|
||||
9
app/src/cl/dbio/cl_unlocked_dbio.h
Normal file
9
app/src/cl/dbio/cl_unlocked_dbio.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* cl_unlocked_dbio.h - cl 모듈 DB 접근 계층 copybook (cl_unlocked_dbio, part of libcldbio.a).
|
||||
* 완료됐지만 기간잠금이 없는 마감 기간 수 (NOT EXISTS).
|
||||
* Return convention: >=0 ok, -1 = SQL error.
|
||||
*/
|
||||
#ifndef CL_UNLOCKED_DBIO_H
|
||||
#define CL_UNLOCKED_DBIO_H
|
||||
long clqdb_unlocked(void);
|
||||
#endif /* CL_UNLOCKED_DBIO_H */
|
||||
22
app/src/cl/dbio/cl_unlocked_dbio.pgc
Normal file
22
app/src/cl/dbio/cl_unlocked_dbio.pgc
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* cl_unlocked_dbio.pgc - cl 모듈 DB 접근 함수 (cl_unlocked_dbio), archived into libcldbio.a.
|
||||
* 완료됐지만 기간잠금이 없는 마감 기간 수 (NOT EXISTS).
|
||||
* ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <userlog.h>
|
||||
#include "cl_unlocked_dbio.h"
|
||||
|
||||
/* status='C' 마감 중 cl_period_lock 에 잠금이 없는 기간 수. */
|
||||
long clqdb_unlocked(void)
|
||||
{
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
long h_v = 0;
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
EXEC SQL SELECT count(DISTINCT c.period_key) INTO :h_v FROM cl_close_log c
|
||||
WHERE c.status = 'C'
|
||||
AND NOT EXISTS (SELECT 1 FROM cl_period_lock l
|
||||
WHERE l.period_key = c.period_key AND l.locked);
|
||||
if (sqlca.sqlcode < 0) return -1;
|
||||
return h_v;
|
||||
}
|
||||
9
app/src/cl/dbio/cl_wavg_dbio.h
Normal file
9
app/src/cl/dbio/cl_wavg_dbio.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* cl_wavg_dbio.h - cl 모듈 DB 접근 계층 copybook (cl_wavg_dbio, part of libcldbio.a).
|
||||
* 건수 가중 평균 gross (weighted average).
|
||||
* Return convention: >=0 ok, -1 = SQL error.
|
||||
*/
|
||||
#ifndef CL_WAVG_DBIO_H
|
||||
#define CL_WAVG_DBIO_H
|
||||
long clqdb_wavg_gross(long cid);
|
||||
#endif /* CL_WAVG_DBIO_H */
|
||||
21
app/src/cl/dbio/cl_wavg_dbio.pgc
Normal file
21
app/src/cl/dbio/cl_wavg_dbio.pgc
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* cl_wavg_dbio.pgc - cl 모듈 DB 접근 함수 (cl_wavg_dbio), archived into libcldbio.a.
|
||||
* 건수 가중 평균 gross (weighted average).
|
||||
* ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <userlog.h>
|
||||
#include "cl_wavg_dbio.h"
|
||||
|
||||
/* 스냅샷 gross 를 txn_count 로 가중한 평균 = sum(gross*cnt)/sum(cnt). */
|
||||
long clqdb_wavg_gross(long cid)
|
||||
{
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
long h_cid = cid, h_num = 0, h_den = 0;
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
EXEC SQL SELECT coalesce(sum(gross_amount * txn_count),0), coalesce(sum(txn_count),0)
|
||||
INTO :h_num, :h_den FROM cl_snapshot WHERE close_id = :h_cid;
|
||||
if (sqlca.sqlcode < 0) return -1;
|
||||
if (h_den <= 0) return 0;
|
||||
return h_num / h_den;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue