13 static int buffer_save_row(
DBPROCESS *dbproc);
48 return (buf->head > buf->tail) ?
49 buf->head - buf->tail :
50 buf->capacity - (buf->tail - buf->head);
59 return buf->capacity == buffer_count(buf) && buf->capacity > 1;
66 if (buf->tail <= buf->head)
67 if (buf->head <= idx && idx <= buf->tail)
70 if (0 <= idx && idx <= buf->head)
73 if (buf->tail <= idx && idx < buf->capacity)
76 printf(
"buffer_index_valid: idx = %d\n", idx);
77 buffer_struct_print(buf);
87 TDS_ZERO_FREE(row->
sizes);
109 if (buf->rows != NULL) {
111 for (i = 0; i < buf->capacity; ++i)
112 buffer_free_row(&buf->rows[i]);
113 TDS_ZERO_FREE(buf->rows);
125 buf->current = buf->tail = buf->capacity;
131 if (++idx >= buf->capacity) {
144 if (!(idx >= 0 && idx < buf->capacity)) {
145 printf(
"idx is %d:\n", idx);
146 buffer_struct_print(buf);
148 assert(idx < buf->capacity);
151 return &(buf->rows[idx]);
160 return buffer_row_address(buf, idx)->
row;
171 if (buf->tail == buf->capacity) {
172 assert (buf->head == 0);
180 for (ii=0, i = buf->tail; i != buf->head || ii == 0; i = buffer_idx_increment(buf, i)) {
181 if( buffer_idx2row(buf, i) == row_number) {
185 assert(ii++ < buf->capacity);
201 if (count < 0 || count > buffer_count(buf)) {
202 count = buffer_count(buf);
205 for (i=0; i < count; i++) {
206 if (buf->tail < buf->capacity)
207 buffer_free_row(&buf->rows[i]);
208 buf->tail = buffer_idx_increment(buf, buf->tail);
213 if (buf->tail == buf->head) {
219 buffer_struct_print(buf);
224 buffer_transfer_bound_data(
DBPROC_ROWBUF *buf, TDS_INT res_type, TDS_INT compute_id,
DBPROCESS * dbproc,
int idx)
227 int srctype, desttype;
231 tdsdump_log(TDS_DBG_FUNC,
"buffer_transfer_bound_data(%p %d %d %p %d)\n", buf, res_type, compute_id, dbproc, idx);
232 assert(buffer_index_valid(buf, idx));
234 row = buffer_row_address(buf, idx);
237 for (i = 0; i < row->
resinfo->num_cols; i++) {
244 if (curcol->column_nullbind) {
246 *(DBINT *)(curcol->column_nullbind) = -1;
248 *(DBINT *)(curcol->column_nullbind) = 0;
251 if (!curcol->column_varaddr)
257 src = curcol->column_data;
260 src = (BYTE *) ((
TDSBLOB *) src)->textvalue;
262 desttype = _db_get_server_type(curcol->column_bindtype);
266 if (srclen == 0 || !curcol->column_nullbind)
267 dbgetnull(dbproc, curcol->column_bindtype, curcol->column_bindlen,
268 (BYTE *) curcol->column_varaddr);
270 copy_data_to_host_var(dbproc, srctype, src, srclen, desttype,
271 (BYTE *) curcol->column_varaddr, curcol->column_bindlen,
272 curcol->column_bindtype, curcol->column_nullbind);
283 buf->current = buffer_idx_increment(buf, buf->current);
292 printf(
"\t%d rows in buffer\n", buffer_count(buf));
294 printf(
"\thead = %d\t", buf->head);
295 printf(
"\ttail = %d\t", buf->tail);
296 printf(
"\tcurrent = %d\n", buf->current);
297 printf(
"\tcapacity = %d\t", buf->capacity);
298 printf(
"\thead row number = %d\n", buf->received);
320 buffer_current_index(
const DBPROCESS *dbproc)
324 buffer_struct_print(buf);
326 if (buf->capacity <= 1)
328 if (buf->current == buf->head || buf->current == buf->capacity)
331 assert(buf->current >= 0);
332 assert(buf->current < buf->capacity);
334 if( buf->tail < buf->head) {
335 assert(buf->tail < buf->current);
336 assert(buf->current < buf->head);
338 if (buf->current > buf->head)
339 assert(buf->current > buf->tail);
349 buffer_set_capacity(
DBPROCESS *dbproc,
int nrows)
364 buf->capacity = nrows;
383 assert(buf->capacity > 0);
384 assert(buf->rows == NULL);
406 assert(buf->capacity >= 0);
408 if (buffer_is_full(buf))
412 if (buf->tail == buf->capacity) {
414 assert(buf->head == 0);
415 buf->tail = buffer_idx_increment(buf, buf->tail);
418 row = buffer_row_address(buf, buf->head);
423 tds_free_results(row->
resinfo);
425 row->
row = ++buf->received;
426 ++resinfo->ref_count;
431 row->
sizes = (TDS_INT *) calloc(resinfo->num_cols,
sizeof(TDS_INT));
432 for (i = 0; i < resinfo->num_cols; ++i)
436 buf->current = buf->head;
437 buf->head = buffer_idx_increment(buf, buf->head);
447 int idx = buf->head - 1;
449 if (buf->capacity <= 1)
453 idx = buf->capacity - 1;
454 if (idx >= 0 && idx < buf->capacity) {
455 row = &buf->rows[idx];
TDS_INT * sizes
save old sizes
Definition: buffering.h:9
int tds_get_conversion_type(int srctype, int colsize)
Return type suitable for conversions (convert all nullable types to fixed type)
Definition: convert.c:152
unsigned char * row_data
row data, NULL for resinfo->current_row
Definition: buffering.h:5
TDSRESULTINFO * resinfo
pointer to result informations
Definition: buffering.h:3
Information about blobs (e.g.
Definition: tds.h:895
Definition: buffering.h:1
int tds_alloc_row(TDSRESULTINFO *res_info)
Allocate space for row store return NULL on out of memory.
Definition: mem.c:416
TDS_SMALLINT column_type
This type can be different from wire type because conversion (e.g.
Definition: tds.h:950
static RETCODE dbgetnull(DBPROCESS *dbproc, int bindtype, int varlen, BYTE *varaddr)
Definition: dblib.c:528
Hold information for any results.
Definition: tds.h:1026
DBINT row
row number
Definition: buffering.h:7
TDS_INT column_cur_size
size written in variable (ie: char, text, binary).
Definition: tds.h:996
TDS_INT column_size
maximun size of data.
Definition: tds.h:958
void tdsdump_log(const char *file, unsigned int level_line, const char *fmt,...)
This function write a message to the debug log.
Definition: log.c:371
Metadata about columns in regular and compute rows.
Definition: tds.h:948