13 static RETCODE buffer_save_row(
DBPROCESS *dbproc);
    16 #if ENABLE_EXTRA_CHECKS    22     if (buf->capacity == 0 || buf->capacity == 1) {
    23         assert(buf->head == 0);
    24         assert(buf->tail == 0 || buf->tail == 1);
    25         assert(buf->capacity == 1 || buf->rows == NULL);
    29     assert(buf->capacity > 0);
    30     assert(buf->head >= 0);
    31     assert(buf->tail >= 0);
    32     assert(buf->head < buf->capacity);
    33     assert(buf->tail <= buf->capacity);
    36     if (buf->tail == buf->capacity) {
    37         assert(buf->head == 0);
    38         for (i = 0; buf->rows && i < buf->capacity; ++i) {
    39             assert(buf->rows[i].
resinfo == NULL);
    40             assert(buf->rows[i].
row_data == NULL);
    41             assert(buf->rows[i].
sizes == NULL);
    42             assert(buf->rows[i].
row == 0);
    47     if (buf->rows == NULL)
    53         assert(i >= 0 && i < buf->capacity);
    54         assert(buf->rows[i].
resinfo != NULL);
    55         assert(buf->rows[i].
row > 0);
    56         assert(buf->rows[i].
row <= buf->received);
    58         if (i == buf->capacity)
    60     } 
while (i != buf->head);
    63     if (buf->head != buf->tail) {
    66             assert(i >= 0 && i < buf->capacity);
    67             assert(buf->rows[i].
resinfo == NULL);
    68             assert(buf->rows[i].
row_data == NULL);
    69             assert(buf->rows[i].
sizes == NULL);
    70             assert(buf->rows[i].
row == 0);
    72             if (i == buf->capacity)
    74         } 
while (i != buf->tail);
    77 #define BUFFER_CHECK(buf) buffer_check(buf)    79 #define BUFFER_CHECK(buf) do {} while(0)   114     return (buf->head > buf->tail) ?
   115         buf->head - buf->tail :             
   116         buf->capacity - (buf->tail - buf->head);    
   126     return buf->capacity == buffer_count(buf) && buf->capacity > 1;
   134     if (buf->tail <= buf->head)
   135         if (buf->head <= idx && idx <= buf->tail)
   138     if (0 <= idx && idx <= buf->head)
   141     if (buf->tail <= idx && idx < buf->capacity)
   144     printf(
"buffer_index_valid: idx = %d\n", idx);
   145     buffer_struct_print(buf);
   155         TDS_ZERO_FREE(row->
sizes);
   160     tds_free_results(row->
resinfo);
   179     if (buf->rows != NULL) {
   181         for (i = 0; i < buf->capacity; ++i)
   182             buffer_free_row(&buf->rows[i]);
   183         TDS_ZERO_FREE(buf->rows);
   196     buf->current = buf->tail = buf->capacity;
   203     if (++idx >= buf->capacity) { 
   217     if (idx < 0 || idx >= buf->capacity) {
   218         printf(
"idx is %d:\n", idx);
   219         buffer_struct_print(buf);
   223     return &(buf->rows[idx]);
   233     return buffer_row_address(buf, idx)->
row;
   248     if (i == buf->capacity) {
   249         assert (buf->head == 0);
   258         if (buffer_idx2row(buf, i) == row_number)
   261         assert(ii++ < buf->capacity); 
   263         i = buffer_idx_increment(buf, i);
   264     } 
while (i != buf->head);
   279     if (count < 0 || count > buffer_count(buf)) {
   280         count = buffer_count(buf);
   283     for (i=0; i < count; i++) {
   284         if (buf->tail < buf->capacity)
   285             buffer_free_row(&buf->rows[buf->tail]);
   286         buf->tail = buffer_idx_increment(buf, buf->tail);
   291         if (buf->tail == buf->head) {
   297     buffer_struct_print(buf);
   303 buffer_transfer_bound_data(
DBPROC_ROWBUF *buf, TDS_INT res_type, TDS_INT compute_id, 
DBPROCESS * dbproc, 
int idx)
   309     tdsdump_log(TDS_DBG_FUNC, 
"buffer_transfer_bound_data(%p %d %d %p %d)\n", buf, res_type, compute_id, dbproc, idx);
   311     assert(buffer_index_valid(buf, idx));
   313     row = buffer_row_address(buf, idx);
   316     for (i = 0; i < row->
resinfo->num_cols; i++) {
   317         TDS_SERVER_TYPE srctype;
   326         if (curcol->column_nullbind) {
   328                 *(DBINT *)(curcol->column_nullbind) = -1;
   330                 *(DBINT *)(curcol->column_nullbind) = 0;
   333         if (!curcol->column_varaddr)
   337             if (srclen == 0 || !curcol->column_nullbind)
   338                 dbgetnull(dbproc, curcol->column_bindtype, curcol->column_bindlen,
   339                         (BYTE *) curcol->column_varaddr);
   348             src = curcol->column_data;
   349         if (is_blob_col(curcol))
   350             src = (BYTE *) ((
TDSBLOB *) src)->textvalue;
   352         copy_data_to_host_var(dbproc, srctype, src, srclen,
   353                     (BYTE *) curcol->column_varaddr,  curcol->column_bindlen,
   354                          curcol->column_bindtype, (DBINT*) curcol->column_nullbind);
   364     buf->current = buffer_idx_increment(buf, buf->current);
   373     printf(
"\t%d rows in buffer\n",     buffer_count(buf));
   375     printf(
"\thead = %d\t",         buf->head);
   376     printf(
"\ttail = %d\t",         buf->tail);
   377     printf(
"\tcurrent = %d\n",      buf->current);
   378     printf(
"\tcapacity = %d\t",         buf->capacity);
   379     printf(
"\thead row number = %d\n",  buf->received);
   401 buffer_current_index(
const DBPROCESS *dbproc)
   405     buffer_struct_print(buf);
   407     if (buf->capacity <= 1) 
   409     if (buf->current == buf->head || buf->current == buf->capacity)
   412     assert(buf->current >= 0);
   413     assert(buf->current < buf->capacity);
   415     if( buf->tail < buf->head) {
   416         assert(buf->tail < buf->current);
   417         assert(buf->current < buf->head);
   419         if (buf->current > buf->head)
   420                 assert(buf->current > buf->tail);
   430 buffer_set_capacity(
DBPROCESS *dbproc, 
int nrows)
   446     buf->capacity = nrows;
   466     assert(buf->capacity > 0);
   467     assert(buf->rows == NULL);
   489     assert(buf->capacity >= 0);
   491     if (buffer_is_full(buf))
   494     row = buffer_row_address(buf, buf->head);
   499         tds_free_results(row->
resinfo);
   501     row->
row = ++buf->received;
   502     ++resinfo->ref_count;
   507     row->
sizes = tds_new0(TDS_INT, resinfo->num_cols);
   508     for (i = 0; i < resinfo->num_cols; ++i)
   512     if (buf->tail == buf->capacity) {
   514         assert(buf->head == 0);
   519     buf->current = buf->head;
   520     buf->head = buffer_idx_increment(buf, buf->head);
   530     int idx = buf->head - 1;
   532     if (buf->capacity <= 1)
   536         idx = buf->capacity - 1;
   537     if (idx >= 0 && idx < buf->capacity) {
   538         row = &buf->rows[idx];
 TDS_INT column_size
maximun size of data. 
Definition: tds.h:732
RETCODE dbgetnull(DBPROCESS *dbproc, int bindtype, int varlen, BYTE *varaddr)
Definition: dblib.c:540
TDS_SERVER_TYPE column_type
This type can be different from wire type because conversion (e.g. 
Definition: tds.h:734
Hold information for any results. 
Definition: tds.h:803
TDS_INT * sizes
save old sizes 
Definition: buffering.h:9
Definition: buffering.h:1
TDSRESULTINFO * resinfo
pointer to result informations 
Definition: buffering.h:3
void tdsdump_log(const char *file, unsigned int level_line, const char *fmt,...)
Write a message to the debug log. 
Definition: log.c:353
DBINT row
row number 
Definition: buffering.h:7
Information about blobs (e.g. 
Definition: tds.h:623
TDSRET tds_alloc_row(TDSRESULTINFO *res_info)
Allocate space for row store return NULL on out of memory. 
Definition: mem.c:521
Metadata about columns in regular and compute rows. 
Definition: tds.h:726
unsigned char * row_data
row data, NULL for resinfo->current_row 
Definition: buffering.h:5
TDS_INT column_cur_size
size written in variable (ie: char, text, binary). 
Definition: tds.h:773
TDS_SERVER_TYPE tds_get_conversion_type(TDS_SERVER_TYPE srctype, int colsize)
Return type suitable for conversions (convert all nullable types to fixed type) 
Definition: tds_types.h:125