* Get rows and convert it from oracle to db API representation */
| 363 | * Get rows and convert it from oracle to db API representation |
| 364 | */ |
| 365 | static int get_rows(ora_con_t* con, db_res_t* _r, OCIStmt* _c, dmap_t* _d) |
| 366 | { |
| 367 | ub4 rcnt; |
| 368 | sword status; |
| 369 | unsigned n = RES_COL_N(_r); |
| 370 | |
| 371 | memcpy(_d->len, _d->ilen, sizeof(_d->len[0]) * n); |
| 372 | |
| 373 | // timelimited operation |
| 374 | status = begin_timelimit(con, 0); |
| 375 | if (status != OCI_SUCCESS) goto ora_err; |
| 376 | do status = OCIStmtFetch2(_c, con->errhp, 1, OCI_FETCH_LAST, 0, |
| 377 | OCI_DEFAULT); |
| 378 | while (wait_timelimit(con, status)); |
| 379 | if (done_timelimit(con, status)) goto stop_load; |
| 380 | if (status != OCI_SUCCESS) { |
| 381 | if (status != OCI_NO_DATA) |
| 382 | goto ora_err; |
| 383 | |
| 384 | RES_ROW_N(_r) = 0; |
| 385 | RES_ROWS(_r) = NULL; |
| 386 | return 0; |
| 387 | } |
| 388 | |
| 389 | status = OCIAttrGet(_c, OCI_HTYPE_STMT, &rcnt, NULL, |
| 390 | OCI_ATTR_CURRENT_POSITION, con->errhp); |
| 391 | if (status != OCI_SUCCESS) goto ora_err; |
| 392 | if (!rcnt) { |
| 393 | LM_ERR("lastpos==0\n"); |
| 394 | goto stop_load; |
| 395 | } |
| 396 | |
| 397 | if (rcnt > 5) { |
| 398 | ub4 prefetch = rcnt/5; |
| 399 | status = OCIAttrSet(_c, OCI_HTYPE_STMT, &prefetch, 0, |
| 400 | OCI_ATTR_PREFETCH_ROWS, con->errhp); |
| 401 | if (status != OCI_SUCCESS) goto ora_err; |
| 402 | } |
| 403 | |
| 404 | RES_ROW_N(_r) = rcnt; |
| 405 | if (db_allocate_rows( _r, rcnt)!=0) { |
| 406 | LM_ERR("no private memory left\n"); |
| 407 | return -1; |
| 408 | } |
| 409 | |
| 410 | while ( 1 ) { |
| 411 | if (convert_row(_r, &RES_ROWS(_r)[--rcnt], _d) < 0) { |
| 412 | LM_ERR("error convert row\n"); |
| 413 | goto stop_load; |
| 414 | } |
| 415 | |
| 416 | if (!rcnt) |
| 417 | return 0; |
| 418 | |
| 419 | memcpy(_d->len, _d->ilen, sizeof(_d->len[0]) * n); |
| 420 | // timelimited operation |
| 421 | status = begin_timelimit(con, 0); |
| 422 | if (status != OCI_SUCCESS) goto ora_err; |
no test coverage detected