/* $Id$ [$Rev$] $Author$ $Date$ $URL$ This file is part of "Easy Pro*C Lib". "Easy Pro*c Lib" is copyright (c) 2009 by F.C. Huang - all rights reserved "Easy Pro*c Lib" is available under the MIT License. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #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 /* DOXYGEN_SHOULD_SKIP_THIS */ #ifndef DOXYGEN_SHOULD_SKIP_THIS exec sql include db001_employee.h; #endif /* DOXYGEN_SHOULD_SKIP_THIS */ #ifndef DOXYGEN_SHOULD_SKIP_THIS exec sql end declare section; #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 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 /* DOXYGEN_SHOULD_SKIP_THIS */ 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; }