in results.c [4806:4925]
RETCODE spos_callback(RETCODE retcode, void *para)
{
CSTR func = "spos_callback";
RETCODE ret;
spos_cdata *s = (spos_cdata *) para;
QResultClass *res;
ARDFields *opts;
ConnectionClass *conn;
SQLULEN global_ridx;
SQLLEN kres_ridx, pos_ridx = 0;
ret = retcode;
MYLOG(MIN_LOG_LEVEL, "entering %d in\n", s->need_data_callback);
if (s->need_data_callback)
{
s->processed++;
if (SQL_ERROR != retcode)
{
s->nrow++;
s->idx++;
}
}
else
{
s->ridx = -1;
s->idx = s->nrow = s->processed = 0;
}
res = s->res;
opts = s->opts;
if (!res || !opts)
{
SC_set_error(s->stmt, STMT_SEQUENCE_ERROR, "Passed res or opts for spos_callback is NULL", func);
return SQL_ERROR;
}
s->need_data_callback = FALSE;
for (; SQL_ERROR != ret && s->nrow <= s->end_row; s->idx++)
{
global_ridx = RowIdx2GIdx(s->idx, s->stmt);
if (SQL_ADD != s->fOption)
{
if ((int) global_ridx >= QR_get_num_total_tuples(res))
break;
if (res->keyset)
{
kres_ridx = GIdx2KResIdx(global_ridx, s->stmt, res);
if (kres_ridx >= res->num_cached_keys)
break;
if (kres_ridx >= 0) /* the row may be deleted and not in the rowset */
{
if (0 == (res->keyset[kres_ridx].status & CURS_IN_ROWSET))
continue;
}
}
}
if (s->nrow < s->start_row)
{
s->nrow++;
continue;
}
s->ridx = s->nrow;
pos_ridx = s->idx;
if (0 != s->irow || !opts->row_operation_ptr || opts->row_operation_ptr[s->nrow] == SQL_ROW_PROCEED)
{
switch (s->fOption)
{
case SQL_UPDATE:
ret = SC_pos_update(s->stmt, s->nrow, global_ridx, NULL);
break;
case SQL_DELETE:
ret = SC_pos_delete(s->stmt, s->nrow, global_ridx, NULL);
break;
case SQL_ADD:
ret = SC_pos_add(s->stmt, s->nrow);
break;
case SQL_REFRESH:
ret = SC_pos_refresh(s->stmt, s->nrow, global_ridx);
break;
}
if (SQL_NEED_DATA == ret)
{
spos_cdata *cbdata = (spos_cdata *) malloc(sizeof(spos_cdata));
if (!cbdata)
{
SC_set_error(s->stmt, STMT_NO_MEMORY_ERROR, "Could not allocate memory for cbdata", func);
return SQL_ERROR;
}
memcpy(cbdata, s, sizeof(spos_cdata));
cbdata->need_data_callback = TRUE;
if (0 == enqueueNeedDataCallback(s->stmt, spos_callback, cbdata))
ret = SQL_ERROR;
return ret;
}
s->processed++;
}
if (SQL_ERROR != ret)
s->nrow++;
}
conn = SC_get_conn(s->stmt);
if (s->auto_commit_needed)
CC_set_autocommit(conn, TRUE);
if (s->irow > 0)
{
if (SQL_ADD != s->fOption && s->ridx >= 0) /* for SQLGetData */
{
s->stmt->currTuple = RowIdx2GIdx(pos_ridx, s->stmt);
QR_set_position(res, pos_ridx);
}
}
else if (SC_get_IRDF(s->stmt)->rowsFetched)
*(SC_get_IRDF(s->stmt)->rowsFetched) = s->processed;
res->recent_processed_row_count = s->stmt->diag_row_count = s->processed;
if (opts) /* logging */
{
MYLOG(DETAIL_LOG_LEVEL, "processed=" FORMAT_POSIROW " ret=%d rowset=" FORMAT_LEN, s->processed, ret, opts->size_of_rowset_odbc2);
MYPRINTF(DETAIL_LOG_LEVEL, "," FORMAT_LEN "\n", opts->size_of_rowset);
}
return ret;
}