#define SIZE_ARRAY 2000 #define SIZE_COL1 20 #define SIZE_COL2 30 #define NUM_COLS 2 #define ITERS 1000 int main(void) { OCI_Connection *cn; OCI_DirPath *dp; OCI_TypeInfo *tbl; dtext val1[SIZE_ARRAY][SIZE_COL1+1]; dtext val2[SIZE_ARRAY][SIZE_COL2+1]; unsigned int size1[SIZE_ARRAY]; unsigned int size2[SIZE_ARRAY]; int i, j, nb_rows = SIZE_ARRAY; int nb = 0; clock_t t_dp1, t_dp2, t_dp3, t_dp4, t_dp5, t_dp6, t_b1, t_b2, t_b3, t_b4; t_dp2 = t_dp4 = t_dp6 = t_b2 = t_b4 = 0; if (!OCI_Initialize(err_handler, NULL, OCI_ENV_DEFAULT)) return EXIT_FAILURE; /* build array test values */ for (i = 0; i < nb_rows; i++) { /* fill test values */ sprint_dt(val1[i], SIZE_COL1+1, "%04d", i+1); sprint_dt(val2[i], SIZE_COL2+1, "value %05d", i+1); size1[i] = (unsigned int) strlen(val1[i]); size2[i] = (unsigned int) strlen(val2[i]); } /* connect to server */ cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT); printf("\n*******TEST 1 (MODE DIRECT PATH) *******************\n"); tbl = OCI_TypeInfoGet(cn, "test_directpath", OCI_TIF_TABLE); dp = OCI_DirPathCreate(tbl, NULL, NUM_COLS, nb_rows); /* describe the target table */ OCI_DirPathSetColumn(dp, 1, "VAL_INT", SIZE_COL1, NULL); OCI_DirPathSetColumn(dp, 2, "VAL_STR", SIZE_COL2, NULL); /* prepare the load */ OCI_DirPathPrepare(dp); nb_rows = OCI_DirPathGetMaxRows(dp); for(j = 0; j < ITERS; j++) { t_dp1 = clock(); for (i = 0; i < nb_rows; i++) { OCI_DirPathSetEntry(dp, i+1, 1, val1[i], size1[i], TRUE); OCI_DirPathSetEntry(dp, i+1, 2, val2[i], size2[i], TRUE); } t_dp2 += (clock() - t_dp1); t_dp3 = clock(); /* load data to the server */ OCI_DirPathConvert(dp); OCI_DirPathLoad(dp); t_dp4 += (clock() - t_dp3); OCI_DirPathReset(dp); } t_dp5 = clock(); /* commits changes */ OCI_DirPathFinish(dp); t_dp6 += (clock() - t_dp5); printf("%d row(s) loaded\n", OCI_DirPathGetRowCount(dp)); /* free direct path object */ OCI_DirPathFree(dp); printf("\n*******TEST 2 (MODE BULK ARRAY) *******************\n"); st = OCI_StatementCreate(cn); /* binding */ OCI_Prepare(st, "insert into test_directpath(val_int, val_str) values(:1, :2)"); OCI_BindArraySetSize(st, SIZE_ARRAY); OCI_BindArrayOfStrings(st, ":1", (char*) val1, SIZE_COL1, 0); OCI_BindArrayOfStrings(st, ":2", (char*) val2, SIZE_COL2, 0); for(j = 0; j < ITERS; j++) { /* execute */ t_b1 = clock(); OCI_Execute(st); t_b2 += (clock() - t_b1); nb += OCI_GetAffectedRows(st); } t_b3 = clock(); OCI_Commit(cn); t_b4 += (clock() - t_b3); printf("%d row(s) loaded\n", nb); printf("\n****************** RESULTS ***********************\n"); printf("TOTAL TIME DIRECT PATH : %05d (set =%05d, load=%05d, commit=%05d)\n", t_dp2 + t_dp4 + t_dp6, t_dp2, t_dp4, t_dp6); printf("TOTAL TIME BULK ARRAY : %05d (exec=%05d, commit=%05d)\n", t_b2+t_b4, t_b2, t_b4); printf("\n******************** END ************************\n"); OCI_Cleanup(); return EXIT_SUCCESS; }