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;
245 if (buf->tail == buf->capacity) {
246 assert (buf->head == 0);
254 for (ii=0, i = buf->tail; i != buf->head || ii == 0; ++ii, i = buffer_idx_increment(buf, i)) {
255 if( buffer_idx2row(buf, i) == row_number) {
259 assert(ii < buf->capacity);
275 if (count < 0 || count > buffer_count(buf)) {
276 count = buffer_count(buf);
279 for (i=0; i < count; i++) {
280 if (buf->tail < buf->capacity)
281 buffer_free_row(&buf->rows[buf->tail]);
282 buf->tail = buffer_idx_increment(buf, buf->tail);
287 if (buf->tail == buf->head) {
293 buffer_struct_print(buf);
299 buffer_transfer_bound_data(
DBPROC_ROWBUF *buf, TDS_INT res_type, TDS_INT compute_id,
DBPROCESS * dbproc,
int idx)
305 tdsdump_log(TDS_DBG_FUNC,
"buffer_transfer_bound_data(%p %d %d %p %d)\n", buf, res_type, compute_id, dbproc, idx);
307 assert(buffer_index_valid(buf, idx));
309 row = buffer_row_address(buf, idx);
312 for (i = 0; i < row->
resinfo->num_cols; i++) {
322 if (curcol->column_nullbind) {
324 *(DBINT *)(curcol->column_nullbind) = -1;
326 *(DBINT *)(curcol->column_nullbind) = 0;
329 if (!curcol->column_varaddr)
333 if (srclen == 0 || !curcol->column_nullbind)
334 dbgetnull(dbproc, curcol->column_bindtype, curcol->column_bindlen,
335 (BYTE *) curcol->column_varaddr);
344 src = curcol->column_data;
345 if (is_blob_col(curcol))
346 src = (BYTE *) ((
TDSBLOB *) src)->textvalue;
348 copy_data_to_host_var(dbproc, srctype, src, srclen,
349 (BYTE *) curcol->column_varaddr, curcol->column_bindlen,
350 curcol->column_bindtype, (DBINT*) curcol->column_nullbind);
360 buf->current = buffer_idx_increment(buf, buf->current);
369 printf(
"\t%d rows in buffer\n", buffer_count(buf));
371 printf(
"\thead = %d\t", buf->head);
372 printf(
"\ttail = %d\t", buf->tail);
373 printf(
"\tcurrent = %d\n", buf->current);
374 printf(
"\tcapacity = %d\t", buf->capacity);
375 printf(
"\thead row number = %d\n", buf->received);
397 buffer_current_index(
const DBPROCESS *dbproc)
401 buffer_struct_print(buf);
403 if (buf->capacity <= 1)
405 if (buf->current == buf->head || buf->current == buf->capacity)
408 assert(buf->current >= 0);
409 assert(buf->current < buf->capacity);
411 if( buf->tail < buf->head) {
412 assert(buf->tail < buf->current);
413 assert(buf->current < buf->head);
415 if (buf->current > buf->head)
416 assert(buf->current > buf->tail);
426 buffer_set_capacity(
DBPROCESS *dbproc,
int nrows)
442 buf->capacity = nrows;
462 assert(buf->capacity > 0);
463 assert(buf->rows == NULL);
485 assert(buf->capacity >= 0);
487 if (buffer_is_full(buf))
490 row = buffer_row_address(buf, buf->head);
495 tds_free_results(row->
resinfo);
497 row->
row = ++buf->received;
498 ++resinfo->ref_count;
503 row->
sizes = (TDS_INT *) calloc(resinfo->num_cols,
sizeof(TDS_INT));
504 for (i = 0; i < resinfo->num_cols; ++i)
508 if (buf->tail == buf->capacity) {
510 assert(buf->head == 0);
515 buf->current = buf->head;
516 buf->head = buffer_idx_increment(buf, buf->head);
526 int idx = buf->head - 1;
528 if (buf->capacity <= 1)
532 idx = buf->capacity - 1;
533 if (idx >= 0 && idx < buf->capacity) {
534 row = &buf->rows[idx];
TDS_TINYINT column_type
This type can be different from wire type because conversion (e.g.
Definition: tds.h:670
Hold information for any results.
Definition: tds.h:739
Information about blobs (e.g.
Definition: tds.h:586
void tdsdump_log(const char *file, unsigned int level_line, const char *fmt,...)
Write a message to the debug log.
Definition: log.c:353
TDSRESULTINFO * resinfo
pointer to result informations
Definition: buffering.h:3
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:709
TDS_INT * sizes
save old sizes
Definition: buffering.h:9
TDS_INT column_size
maximun size of data.
Definition: tds.h:668
Definition: buffering.h:1
TDSRET tds_alloc_row(TDSRESULTINFO *res_info)
Allocate space for row store return NULL on out of memory.
Definition: mem.c:516
DBINT row
row number
Definition: buffering.h:7
int tds_get_conversion_type(int srctype, int colsize)
Return type suitable for conversions (convert all nullable types to fixed type)
Definition: tds_types.h:123
Metadata about columns in regular and compute rows.
Definition: tds.h:662
RETCODE dbgetnull(DBPROCESS *dbproc, int bindtype, int varlen, BYTE *varaddr)
Definition: dblib.c:535