13static RETCODE buffer_save_row(
DBPROCESS *dbproc);
 
   16#if ENABLE_EXTRA_CHECKS 
   21    assert(row->
sizes == NULL);
 
   22    assert(row->
row == 0);
 
   30    if (buf->capacity == 0 || buf->capacity == 1) {
 
   31        assert(buf->head == 0);
 
   32        assert(buf->tail == 0 || buf->tail == 1);
 
   33        assert(buf->capacity == 1 || buf->rows == NULL);
 
   37    assert(buf->capacity > 0);
 
   38    assert(buf->head >= 0);
 
   39    assert(buf->tail >= 0);
 
   40    assert(buf->head < buf->capacity);
 
   41    assert(buf->tail <= buf->capacity);
 
   44    if (buf->tail == buf->capacity) {
 
   45        assert(buf->head == 0);
 
   46        for (i = 0; buf->rows && i < buf->capacity; ++i)
 
   47            buffer_check_row_empty(&buf->rows[i]);
 
   51    if (buf->rows == NULL)
 
   57        assert(i >= 0 && i < buf->capacity);
 
   58        assert(buf->rows[i].
resinfo != NULL);
 
   59        assert(buf->rows[i].
row > 0);
 
   60        assert(buf->rows[i].
row <= buf->received);
 
   62        if (i == buf->capacity)
 
   64    } 
while (i != buf->head);
 
   67    if (buf->head != buf->tail) {
 
   70            assert(i >= 0 && i < buf->capacity);
 
   71            buffer_check_row_empty(&buf->rows[i]);
 
   73            if (i == buf->capacity)
 
   75        } 
while (i != buf->tail);
 
   78#define BUFFER_CHECK(buf) buffer_check(buf) 
   80#define BUFFER_CHECK(buf) do {} while(0) 
  115    return (buf->head > buf->tail) ?
 
  116        buf->head - buf->tail :             
 
  117        buf->capacity - (buf->tail - buf->head);    
 
  127    return buf->capacity == buffer_count(buf) && buf->capacity > 1;
 
  135    if (buf->tail <= buf->head)
 
  136        if (buf->head <= idx && idx <= buf->tail)
 
  139    if (0 <= idx && idx <= buf->head)
 
  142    if (buf->tail <= idx && idx < buf->capacity)
 
  145    printf(
"buffer_index_valid: idx = %d\n", idx);
 
  146    buffer_struct_print(buf);
 
  156        TDS_ZERO_FREE(row->
sizes);
 
  161    tds_free_results(row->
resinfo);
 
  180    if (buf->rows != NULL) {
 
  182        for (i = 0; i < buf->capacity; ++i)
 
  183            buffer_free_row(&buf->rows[i]);
 
  184        TDS_ZERO_FREE(buf->rows);
 
  197    buf->current = buf->tail = buf->capacity;
 
  204    if (++idx >= buf->capacity) { 
 
  218    if (idx < 0 || idx >= buf->capacity) {
 
  219        printf(
"idx is %d:\n", idx);
 
  220        buffer_struct_print(buf);
 
  224    return &(buf->rows[idx]);
 
  234    return buffer_row_address(buf, idx)->
row;
 
  249    if (i == buf->capacity) {
 
  250        assert (buf->head == 0);
 
  259        if (buffer_idx2row(buf, i) == row_number)
 
  262        assert(ii++ < buf->capacity); 
 
  264        i = buffer_idx_increment(buf, i);
 
  265    } 
while (i != buf->head);
 
  280    if (count < 0 || count > buffer_count(buf)) {
 
  281        count = buffer_count(buf);
 
  284    for (i=0; i < count; i++) {
 
  285        if (buf->tail < buf->capacity)
 
  286            buffer_free_row(&buf->rows[buf->tail]);
 
  287        buf->tail = buffer_idx_increment(buf, buf->tail);
 
  292        if (buf->tail == buf->head) {
 
  298    buffer_struct_print(buf);
 
  307buffer_transfer_bound_data(
DBPROC_ROWBUF *buf, TDS_INT res_type, TDS_INT compute_id, 
DBPROCESS * dbproc, 
int idx)
 
  313    tdsdump_log(TDS_DBG_FUNC, 
"buffer_transfer_bound_data(%p %d %d %p %d)\n", buf, res_type, compute_id, dbproc, idx);
 
  315    assert(buffer_index_valid(buf, idx));
 
  317    row = buffer_row_address(buf, idx);
 
  320    for (i = 0; i < row->
resinfo->num_cols; i++) {
 
  321        TDS_SERVER_TYPE srctype;
 
  330        if (curcol->column_nullbind) {
 
  332                *(DBINT *)(curcol->column_nullbind) = -1;
 
  334                *(DBINT *)(curcol->column_nullbind) = 0;
 
  337        if (!curcol->column_varaddr)
 
  341            if (srclen == 0 || !curcol->column_nullbind)
 
  342                dbgetnull(dbproc, curcol->column_bindtype, curcol->column_bindlen,
 
  343                        (BYTE *) curcol->column_varaddr);
 
  352            src = curcol->column_data;
 
  353        if (is_blob_col(curcol))
 
  354            src = (BYTE *) ((
TDSBLOB *) src)->textvalue;
 
  356        copy_data_to_host_var(dbproc, srctype, src, srclen,
 
  357                    (BYTE *) curcol->column_varaddr,  curcol->column_bindlen,
 
  358                         curcol->column_bindtype, (DBINT*) curcol->column_nullbind);
 
  368    buf->current = buffer_idx_increment(buf, buf->current);
 
  377    printf(
"\t%d rows in buffer\n",     buffer_count(buf));
 
  379    printf(
"\thead = %d\t",         buf->head);
 
  380    printf(
"\ttail = %d\t",         buf->tail);
 
  381    printf(
"\tcurrent = %d\n",      buf->current);
 
  382    printf(
"\tcapacity = %d\t",         buf->capacity);
 
  383    printf(
"\thead row number = %d\n",  buf->received);
 
  405buffer_current_index(
const DBPROCESS *dbproc)
 
  409    buffer_struct_print(buf);
 
  411    if (buf->capacity <= 1) 
 
  413    if (buf->current == buf->head || buf->current == buf->capacity)
 
  416    assert(buf->current >= 0);
 
  417    assert(buf->current < buf->capacity);
 
  419    if( buf->tail < buf->head) {
 
  420        assert(buf->tail < buf->current);
 
  421        assert(buf->current < buf->head);
 
  423        if (buf->current > buf->head)
 
  424                assert(buf->current > buf->tail);
 
  434buffer_set_capacity(
DBPROCESS *dbproc, 
int nrows)
 
  450    buf->capacity = nrows;
 
  470    assert(buf->capacity > 0);
 
  471    assert(buf->rows == NULL);
 
  493    assert(buf->capacity >= 0);
 
  495    if (buffer_is_full(buf))
 
  498    row = buffer_row_address(buf, buf->head);
 
  503        tds_free_results(row->
resinfo);
 
  505    row->
row = ++buf->received;
 
  506    ++resinfo->ref_count;
 
  511    row->
sizes = tds_new0(TDS_INT, resinfo->num_cols);
 
  512    for (i = 0; i < resinfo->num_cols; ++i)
 
  516    if (buf->tail == buf->capacity) {
 
  518        assert(buf->head == 0);
 
  523    buf->current = buf->head;
 
  524    buf->head = buffer_idx_increment(buf, buf->head);
 
  537    int idx = buf->head - 1;
 
  539    if (buf->capacity <= 1)
 
  543        idx = buf->capacity - 1;
 
  544    if (idx >= 0 && idx < buf->capacity) {
 
  545        row = &buf->rows[idx];
 
RETCODE dbgetnull(DBPROCESS *dbproc, int bindtype, int varlen, BYTE *varaddr)
Definition dblib.c:529
TDSRET tds_alloc_row(TDSRESULTINFO *res_info)
Allocate space for row store return NULL on out of memory.
Definition mem.c:533
DBINT row
row number
Definition buffering.h:7
unsigned char * row_data
row data, NULL for resinfo->current_row
Definition buffering.h:5
TDS_INT * sizes
save old sizes
Definition buffering.h:9
TDSRESULTINFO * resinfo
pointer to result informations
Definition buffering.h:3
Information about blobs (e.g.
Definition tds.h:597
Metadata about columns in regular and compute rows.
Definition tds.h:693
TDS_INT column_size
maximun size of data.
Definition tds.h:698
TDS_SERVER_TYPE column_type
This type can be different from wire type because conversion (e.g.
Definition tds.h:700
TDS_INT column_cur_size
size written in variable (ie: char, text, binary).
Definition tds.h:740
Hold information for any results.
Definition tds.h:773