testcase.pc
This is an example about how to use the DAO functions.
#include <ezpclib_commons.h>
#include <ezpclib_logging.h>
#include <ezpclib_db.h>
#define ARY_MAX 1211
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#ifndef DOXYGEN_SHOULD_SKIP_THIS
exec sql begin declare section;
#endif
#ifndef DOXYGEN_SHOULD_SKIP_THIS
exec sql include db001_employee.h;
#endif
#ifndef DOXYGEN_SHOULD_SKIP_THIS
exec sql end declare section;
#endif
static employee_t tmp;
static employeeA_t tmpA;
struct _employee_pkA {
int employee_id[ARY_MAX];
};
typedef struct _employee_pkA employee_pkA_t;
static employee_pkA_t tmpPK;
static int rows = -1;
static int db_sn = -1;
static int cnt = -1;
static int id = 0;
#endif
void init() {
char connstr[128];
rand_init();
read_key("testcase.properties", "conn.str", connstr);
log("connstr:%s\n", connstr);
db_sn = sql_open_conn("testdb", connstr);
}
void end() {
sql_close_all();
}
void howto_insert() {
tmp.employee_id = id;
rand_chars(tmp.first_name, 20);
rand_chars(tmp.last_name, 25);
rand_chars(tmp.email, 25);
rand_chars(tmp.phone_number, 20);
ora_sysdate(tmp.hire_date);
tmp.salary = rand_double();
tmp.commission_pct = 0.5;
employee_insLz(db_sn, &tmp);
employee_insLz(db_sn, NULL);
cnt = employee_qry_cnt(db_sn);
if (cnt == 1) {
logtestpass;
} else {
logtestfail;
}
}
void howto_update() {
rand_chars(tmp.first_name, 20);
rand_chars(tmp.last_name, 25);
rand_chars(tmp.email, 25);
rand_chars(tmp.phone_number, 20);
ora_sysdate(tmp.hire_date);
tmp.salary = rand_double();
tmp.commission_pct = 0.5;
employee_updLz(db_sn, &tmp);
employee_updLz(db_sn, NULL);
cnt = employee_qry_cnt(db_sn);
if (cnt == 1) {
logtestpass;
} else {
logtestfail;
}
}
void howto_delete() {
employee_delLz(db_sn, &tmp);
employee_delLz(db_sn, NULL);
cnt = employee_qry_cnt(db_sn);
if (cnt == 0) {
logtestpass;
} else {
logtestfail;
}
}
void howto_bulk_insert() {
for (int i=0 ; i<(ARY_MAX) ; i++) {
tmp.employee_id = ++id;
rand_chars(tmp.first_name, 20);
rand_chars(tmp.last_name, 25);
rand_chars(tmp.email, 25);
rand_chars(tmp.phone_number, 20);
ora_sysdate(tmp.hire_date);
tmp.salary = rand_double();
tmp.commission_pct = 0.5;
employee_insLz(db_sn, &tmp);
memcpy (&tmpPK.employee_id[i], &tmp.employee_id, sizeof(tmp.employee_id));
}
employee_insLz (db_sn, NULL);
cnt = employee_qry_cnt(db_sn);
if (cnt == ARY_MAX) {
logtestpass;
} else {
logtestfail;
}
}
void howto_bulk_update() {
for (int i=0 ; i<(ARY_MAX) ; i++) {
memcpy (&tmp.employee_id, &tmpPK.employee_id[i], sizeof(tmp.employee_id));
rand_chars(tmp.first_name, 20);
rand_chars(tmp.last_name, 25);
rand_chars(tmp.email, 25);
employee_updLz(db_sn, &tmp);
}
employee_updLz(db_sn, NULL);
cnt = employee_qry_cnt(db_sn);
if (cnt == ARY_MAX) {
logtestpass;
} else {
logtestfail;
}
}
void howto_bulk_delete() {
for (int i=0 ; i<(ARY_MAX) ; i++) {
memcpy (&tmp.employee_id, &tmpPK.employee_id[i], sizeof(tmp.employee_id));
employee_delLz(db_sn, &tmp);
}
employee_delLz(db_sn, NULL);
cnt = employee_qry_cnt(db_sn);
if (cnt == 0) {
logtestpass;
} else {
logtestfail;
}
}
void howto_logging_debug() {
int i = 99;
long l = 999999999;
double d = 909.0001;
char *s = "999,000.01";
logenter_d;
logdbg("this is a sample debug message. %d\n", 100);
qlogf_d(d);
qlogi_d(i);
qlogl_d(l);
qlogs_d(s);
logleave_d;
}
void howto_logging_production() {
int i = 88;
long l = 888888888;
double d = 808.0001;
char *s = "888,000.01";
logenter;
log("this is a sample log message. %d\n", 101);
qlogf(d);
qlogi(i);
qlogl(l);
qlogs(s);
logleave;
}
int main(int argc, char* argv[]) {
logenter;
init();
howto_insert();
howto_update();
howto_delete();
howto_bulk_insert();
howto_bulk_update();
howto_bulk_delete();
end();
howto_logging_debug();
howto_logging_production();
logleave;
}