13 static int 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; 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)
302 int srctype, desttype;
306 tdsdump_log(TDS_DBG_FUNC,
"buffer_transfer_bound_data(%p %d %d %p %d)\n", buf, res_type, compute_id, dbproc, idx);
308 assert(buffer_index_valid(buf, idx));
310 row = buffer_row_address(buf, idx);
313 for (i = 0; i < row->
resinfo->num_cols; i++) {
320 if (curcol->column_nullbind) {
322 *(DBINT *)(curcol->column_nullbind) = -1;
324 *(DBINT *)(curcol->column_nullbind) = 0;
327 if (!curcol->column_varaddr)
333 src = curcol->column_data;
335 if (is_blob_col(curcol))
336 src = (BYTE *) ((
TDSBLOB *) src)->textvalue;
337 desttype = _db_get_server_type(curcol->column_bindtype);
341 if (srclen == 0 || !curcol->column_nullbind)
342 dbgetnull(dbproc, curcol->column_bindtype, curcol->column_bindlen,
343 (BYTE *) curcol->column_varaddr);
345 copy_data_to_host_var(dbproc, srctype, src, srclen, desttype,
346 (BYTE *) curcol->column_varaddr, curcol->column_bindlen,
347 curcol->column_bindtype, (DBINT*) curcol->column_nullbind);
358 buf->current = buffer_idx_increment(buf, buf->current);
367 printf(
"\t%d rows in buffer\n", buffer_count(buf));
369 printf(
"\thead = %d\t", buf->head);
370 printf(
"\ttail = %d\t", buf->tail);
371 printf(
"\tcurrent = %d\n", buf->current);
372 printf(
"\tcapacity = %d\t", buf->capacity);
373 printf(
"\thead row number = %d\n", buf->received);
395 buffer_current_index(
const DBPROCESS *dbproc)
399 buffer_struct_print(buf);
401 if (buf->capacity <= 1)
403 if (buf->current == buf->head || buf->current == buf->capacity)
406 assert(buf->current >= 0);
407 assert(buf->current < buf->capacity);
409 if( buf->tail < buf->head) {
410 assert(buf->tail < buf->current);
411 assert(buf->current < buf->head);
413 if (buf->current > buf->head)
414 assert(buf->current > buf->tail);
424 buffer_set_capacity(
DBPROCESS *dbproc,
int nrows)
440 buf->capacity = nrows;
460 assert(buf->capacity > 0);
461 assert(buf->rows == NULL);
483 assert(buf->capacity >= 0);
485 if (buffer_is_full(buf))
488 row = buffer_row_address(buf, buf->head);
493 tds_free_results(row->
resinfo);
495 row->
row = ++buf->received;
496 ++resinfo->ref_count;
501 row->
sizes = (TDS_INT *) calloc(resinfo->num_cols,
sizeof(TDS_INT));
502 for (i = 0; i < resinfo->num_cols; ++i)
506 if (buf->tail == buf->capacity) {
508 assert(buf->head == 0);
513 buf->current = buf->head;
514 buf->head = buffer_idx_increment(buf, buf->head);
524 int idx = buf->head - 1;
526 if (buf->capacity <= 1)
530 idx = buf->capacity - 1;
531 if (idx >= 0 && idx < buf->capacity) {
532 row = &buf->rows[idx];