FreeTDS API: src/dblib/buffering.h Source File

FreeTDS API

buffering.h
1 typedef struct dblib_buffer_row {
3 TDSRESULTINFO *resinfo;
5 unsigned char *row_data;
7 DBINT row;
9 TDS_INT *sizes;
10 } DBLIB_BUFFER_ROW;
11
12 static void buffer_struct_print(const DBPROC_ROWBUF *buf);
13 static RETCODE buffer_save_row(DBPROCESS *dbproc);
14 static DBLIB_BUFFER_ROW* buffer_row_address(const DBPROC_ROWBUF * buf, int idx);
15
16 #if ENABLE_EXTRA_CHECKS
17 static void buffer_check_row_empty(DBLIB_BUFFER_ROW *row)
18 {
19 assert(row->resinfo == NULL);
20 assert(row->row_data == NULL);
21 assert(row->sizes == NULL);
22 assert(row->row == 0);
23 }
24
25 static void buffer_check(const DBPROC_ROWBUF *buf)
26 {
27 int i;
28
29 /* no buffering */
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);
34 return;
35 }
36
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);
42
43 /* check empty */
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]);
48 return;
49 }
50
51 if (buf->rows == NULL)
52 return;
53
54 /* check filled part */
55 i = buf->tail;
56 do {
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);
61 ++i;
62 if (i == buf->capacity)
63 i = 0;
64 } while (i != buf->head);
65
66 /* check empty part */
67 if (buf->head != buf->tail) {
68 i = buf->head;
69 do {
70 assert(i >= 0 && i < buf->capacity);
71 buffer_check_row_empty(&buf->rows[i]);
72 ++i;
73 if (i == buf->capacity)
74 i = 0;
75 } while (i != buf->tail);
76 }
77 }
78 #define BUFFER_CHECK(buf) buffer_check(buf)
79 #else
80 #define BUFFER_CHECK(buf) do {} while(0)
81 #endif
82
111 static int
112 buffer_count(const DBPROC_ROWBUF *buf)
113 {
114 BUFFER_CHECK(buf);
115 return (buf->head > buf->tail) ?
116 buf->head - buf->tail : /* |...TddddH....| */
117 buf->capacity - (buf->tail - buf->head); /* |ddddH....Tddd| */
118 }
119
123 static int
124 buffer_is_full(const DBPROC_ROWBUF *buf)
125 {
126 BUFFER_CHECK(buf);
127 return buf->capacity == buffer_count(buf) && buf->capacity > 1;
128 }
129
130 #ifndef NDEBUG
131 static int
132 buffer_index_valid(const DBPROC_ROWBUF *buf, int idx)
133 {
134 BUFFER_CHECK(buf);
135 if (buf->tail <= buf->head)
136 if (buf->head <= idx && idx <= buf->tail)
137 return 1;
138
139 if (0 <= idx && idx <= buf->head)
140 return 1;
141
142 if (buf->tail <= idx && idx < buf->capacity)
143 return 1;
144 #if 0
145 printf("buffer_index_valid: idx = %d\n", idx);
146 buffer_struct_print(buf);
147 #endif
148 return 0;
149 }
150 #endif
151
152 static void
153 buffer_free_row(DBLIB_BUFFER_ROW *row)
154 {
155 if (row->sizes)
156 TDS_ZERO_FREE(row->sizes);
157 if (row->row_data) {
158 tds_free_row(row->resinfo, row->row_data);
159 row->row_data = NULL;
160 }
161 tds_free_results(row->resinfo);
162 row->resinfo = NULL;
163 row->row = 0;
164 }
165
166 /*
167 * Buffer is freed at slightly odd points, whenever
168 * capacity changes:
169 *
170 * 1. When setting capacity, to release prior buffer.
171 * 2. By dbresults. When called the second time, it has to
172 * release prior storage because the new resultset will have
173 * a different width.
174 * 3. By dbclose(), else open/close/open would leak.
175 */
176 static void
177 buffer_free(DBPROC_ROWBUF *buf)
178 {
179 BUFFER_CHECK(buf);
180 if (buf->rows != NULL) {
181 int i;
182 for (i = 0; i < buf->capacity; ++i)
183 buffer_free_row(&buf->rows[i]);
184 TDS_ZERO_FREE(buf->rows);
185 }
186 BUFFER_CHECK(buf);
187 }
188
189 /*
190 * When no rows are currently buffered (and the buffer is allocated)
191 * set the indices to their initial positions.
192 */
193 static void
194 buffer_reset(DBPROC_ROWBUF *buf)
195 {
196 buf->head = 0;
197 buf->current = buf->tail = buf->capacity;
198 BUFFER_CHECK(buf);
199 }
200
201 static int
202 buffer_idx_increment(const DBPROC_ROWBUF *buf, int idx)
203 {
204 if (++idx >= buf->capacity) {
205 idx = 0;
206 }
207 return idx;
208 }
209
214 static DBLIB_BUFFER_ROW*
215 buffer_row_address(const DBPROC_ROWBUF * buf, int idx)
216 {
217 BUFFER_CHECK(buf);
218 if (idx < 0 || idx >= buf->capacity) {
219 printf("idx is %d:\n", idx);
220 buffer_struct_print(buf);
221 return NULL;
222 }
223
224 return &(buf->rows[idx]);
225 }
226
230 static DBINT
231 buffer_idx2row(const DBPROC_ROWBUF *buf, int idx)
232 {
233 BUFFER_CHECK(buf);
234 return buffer_row_address(buf, idx)->row;
235 }
236
240 static int
241 buffer_row2idx(const DBPROC_ROWBUF *buf, int row_number)
242 {
243 int i = buf->tail;
244 #ifndef NDEBUG
245 int ii = 0;
246 #endif
247
248 BUFFER_CHECK(buf);
249 if (i == buf->capacity) {
250 assert (buf->head == 0);
251 return -1; /* no rows buffered */
252 }
253
254 /*
255 * March through the buffers from tail to head, stop if we find our row.
256 * A full queue is indicated by tail == head (which means we can't write).
257 */
258 do {
259 if (buffer_idx2row(buf, i) == row_number)
260 return i;
261
262 assert(ii++ < buf->capacity); /* prevent infinite loop */
263
264 i = buffer_idx_increment(buf, i);
265 } while (i != buf->head);
266
267 return -1;
268 }
269
274 static void
275 buffer_delete_rows(DBPROC_ROWBUF * buf, int count)
276 {
277 int i;
278
279 BUFFER_CHECK(buf);
280 if (count < 0 || count > buffer_count(buf)) {
281 count = buffer_count(buf);
282 }
283
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);
288 /*
289 * If deleting rows from the buffer catches the tail to the head,
290 * return to the initial position. Otherwise, it will look full.
291 */
292 if (buf->tail == buf->head) {
293 buffer_reset(buf);
294 break;
295 }
296 }
297 #if 0
298 buffer_struct_print(buf);
299 #endif
300 BUFFER_CHECK(buf);
301 }
302
306 static void
307 buffer_transfer_bound_data(DBPROC_ROWBUF *buf, TDS_INT res_type, TDS_INT compute_id, DBPROCESS * dbproc, int idx)
308 {
309 int i;
310 BYTE *src;
311 const DBLIB_BUFFER_ROW *row;
312
313 tdsdump_log(TDS_DBG_FUNC, "buffer_transfer_bound_data(%p %d %d %p %d)\n", buf, res_type, compute_id, dbproc, idx);
314 BUFFER_CHECK(buf);
315 assert(buffer_index_valid(buf, idx));
316
317 row = buffer_row_address(buf, idx);
318 assert(row->resinfo);
319
320 for (i = 0; i < row->resinfo->num_cols; i++) {
321 TDS_SERVER_TYPE srctype;
322 DBINT srclen;
323 TDSCOLUMN *curcol = row->resinfo->columns[i];
324
325 if (row->sizes)
326 curcol->column_cur_size = row->sizes[i];
327
328 srclen = curcol->column_cur_size;
329
330 if (curcol->column_nullbind) {
331 if (srclen < 0) {
332 *(DBINT *)(curcol->column_nullbind) = -1;
333 } else {
334 *(DBINT *)(curcol->column_nullbind) = 0;
335 }
336 }
337 if (!curcol->column_varaddr)
338 continue;
339
340 if (srclen <= 0) {
341 if (srclen == 0 || !curcol->column_nullbind)
342 dbgetnull(dbproc, curcol->column_bindtype, curcol->column_bindlen,
343 (BYTE *) curcol->column_varaddr);
344 continue;
345 }
346
347 srctype = tds_get_conversion_type(curcol->column_type, curcol->column_size);
348
349 if (row->row_data)
350 src = &row->row_data[curcol->column_data - row->resinfo->current_row];
351 else
352 src = curcol->column_data;
353 if (is_blob_col(curcol))
354 src = (BYTE *) ((TDSBLOB *) src)->textvalue;
355
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);
359 }
360
361 /*
362 * This function always bumps current. Usually, it's called
363 * by dbnextrow(), so bumping current is a pretty obvious choice.
364 * It can also be called by dbgetrow(), but that function also
365 * causes the bump. If you call dbgetrow() for row N, a subsequent
366 * call to dbnextrow() yields N+1.
367 */
368 buf->current = buffer_idx_increment(buf, buf->current);
369
370 } /* end buffer_transfer_bound_data() */
371
372 static void
373 buffer_struct_print(const DBPROC_ROWBUF *buf)
374 {
375 assert(buf);
376
377 printf("\t%d rows in buffer\n", buffer_count(buf));
378
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);
384 }
385
386 /* * * Functions called only by public db-lib API take DBPROCESS* * */
387
404 static int
405 buffer_current_index(const DBPROCESS *dbproc)
406 {
407 const DBPROC_ROWBUF *buf = &dbproc->row_buf;
408 #if 0
409 buffer_struct_print(buf);
410 #endif
411 if (buf->capacity <= 1) /* no buffering */
412 return -1;
413 if (buf->current == buf->head || buf->current == buf->capacity)
414 return -1;
415
416 assert(buf->current >= 0);
417 assert(buf->current < buf->capacity);
418
419 if( buf->tail < buf->head) {
420 assert(buf->tail < buf->current);
421 assert(buf->current < buf->head);
422 } else {
423 if (buf->current > buf->head)
424 assert(buf->current > buf->tail);
425 }
426 return buf->current;
427 }
428
429 /*
430 * Normally called by dbsetopt() to prepare for buffering
431 * Called with nrows == 0 by dbopen to safely set buf->rows to NULL.
432 */
433 static void
434 buffer_set_capacity(DBPROCESS *dbproc, int nrows)
435 {
436 DBPROC_ROWBUF *buf = &dbproc->row_buf;
437
438 buffer_free(buf);
439
440 memset(buf, 0, sizeof(DBPROC_ROWBUF));
441
442 if (0 == nrows) {
443 buf->capacity = 1;
444 BUFFER_CHECK(buf);
445 return;
446 }
447
448 assert(0 < nrows);
449
450 buf->capacity = nrows;
451 BUFFER_CHECK(buf);
452 }
453
454 /*
455 * Called only by dbresults(); capacity must be >= 1.
456 * Sybase's documents say dbresults() cannot return FAIL if the prior calls worked,
457 * which is a little strange, because (for FreeTDS, at least), dbresults
458 * is when we learn about the result set's width. Without that information, we
459 * can't allocate memory for the buffer. But if we *fail* to allocate memory,
460 * we're not to communicate it back to the caller?
461 */
462 static void
463 buffer_alloc(DBPROCESS *dbproc)
464 {
465 DBPROC_ROWBUF *buf = &dbproc->row_buf;
466
467 /* Call this function only after setting capacity. */
468
469 assert(buf);
470 assert(buf->capacity > 0);
471 assert(buf->rows == NULL);
472
473 buf->rows = tds_new0(DBLIB_BUFFER_ROW, buf->capacity);
474
475 assert(buf->rows);
476
477 buffer_reset(buf);
478
479 buf->received = 0;
480 }
481
486 static int
487 buffer_add_row(DBPROCESS *dbproc, TDSRESULTINFO *resinfo)
488 {
489 DBPROC_ROWBUF *buf = &dbproc->row_buf;
490 DBLIB_BUFFER_ROW *row;
491 int i;
492
493 assert(buf->capacity >= 0);
494
495 if (buffer_is_full(buf))
496 return -1;
497
498 row = buffer_row_address(buf, buf->head);
499
500 /* bump the row number, write it, and move the data to head */
501 if (row->resinfo) {
502 tds_free_row(row->resinfo, row->row_data);
503 tds_free_results(row->resinfo);
504 }
505 row->row = ++buf->received;
506 ++resinfo->ref_count;
507 row->resinfo = resinfo;
508 row->row_data = NULL;
509 if (row->sizes)
510 free(row->sizes);
511 row->sizes = tds_new0(TDS_INT, resinfo->num_cols);
512 for (i = 0; i < resinfo->num_cols; ++i)
513 row->sizes[i] = resinfo->columns[i]->column_cur_size;
514
515 /* initial condition is head == 0 and tail == capacity */
516 if (buf->tail == buf->capacity) {
517 /* bumping this tail will set it to zero */
518 assert(buf->head == 0);
519 buf->tail = 0;
520 }
521
522 /* update current, bump the head */
523 buf->current = buf->head;
524 buf->head = buffer_idx_increment(buf, buf->head);
525
526 return buf->current;
527 }
528
532 static RETCODE
533 buffer_save_row(DBPROCESS *dbproc)
534 {
535 DBPROC_ROWBUF *buf = &dbproc->row_buf;
536 DBLIB_BUFFER_ROW *row;
537 int idx = buf->head - 1;
538
539 if (buf->capacity <= 1)
540 return SUCCEED;
541
542 if (idx < 0)
543 idx = buf->capacity - 1;
544 if (idx >= 0 && idx < buf->capacity) {
545 row = &buf->rows[idx];
546
547 if (row->resinfo && !row->row_data) {
548 row->row_data = row->resinfo->current_row;
549 tds_alloc_row(row->resinfo);
550 }
551 }
552
553 return SUCCEED;
554 }
555
rtrim
static int rtrim(char *, int)
trim a string of trailing blanks
Definition: bcp.c:2323
tds_dynamic
Holds information for a dynamic (also called prepared) query.
Definition: tds.h:977
tds_numeric_bytes_per_prec
const int tds_numeric_bytes_per_prec[]
The following little table is indexed by precision and will tell us the number of bytes required to s...
Definition: numeric.c:41
_cs_objname
Definition: cspublic.h:685
_cs_blkdesc
Definition: ctlib.h:239
bcp_readfmt
RETCODE bcp_readfmt(DBPROCESS *dbproc, const char filename[])
Read a format definition file.
Definition: bcp.c:1678
_bcp_exec_in
static RETCODE _bcp_exec_in(DBPROCESS *dbproc, DBINT *rows_copied)
Definition: bcp.c:1434
tds_submit_unprepare
TDSRET tds_submit_unprepare(TDSSOCKET *tds, TDSDYNAMIC *dyn)
Send a unprepare request for a prepared query.
Definition: query.c:1797
_hdbc
Definition: odbc.h:275
tdsdaterec
Used by tds_datecrack.
Definition: tds.h:159
_cs_command
Definition: ctlib.h:212
tds_dstr_empty
#define tds_dstr_empty(s)
Make a string empty.
Definition: string.h:91
tds_cursor::cursor_rows
TDS_INT cursor_rows
< number of updatable columns
Definition: tds.h:951
tds_set_param_type
void tds_set_param_type(TDSCONNECTION *conn, TDSCOLUMN *curcol, TDS_SERVER_TYPE type)
Set type of column initializing all dependency.
Definition: data.c:246
tds_set_state
TDS_STATE tds_set_state(TDSSOCKET *tds, TDS_STATE state)
Set state of TDS connection, with logging and checking.
Definition: util.c:58
tds_cursor::status
TDS_CURSOR_STATUS status
cursor parameter
Definition: tds.h:953
tds_submit_query_params
TDSRET tds_submit_query_params(TDSSOCKET *tds, const char *query, TDSPARAMINFO *params, TDSHEADERS *head)
Sends a language string to the database server for processing.
Definition: query.c:350
tds_dstr_cstr
static const char * tds_dstr_cstr(const DSTR *s)
Returns a C version (NUL terminated string) of dstr.
Definition: string.h:78
tds_login::password
DSTR password
password of account login
Definition: tds.h:535
tdsdaterec::decimicrosecond
TDS_INT decimicrosecond
0-9999999
Definition: tds.h:169
tds_locale
Definition: tds.h:582
tds_prtype
const char * tds_prtype(int type)
Returns string representation of the given type.
Definition: token.c:3056
tds_strftime
size_t tds_strftime(char *buf, size_t maxsize, const char *format, const TDSDATEREC *dr, int prec)
format a date string according to an "extended" strftime(3) formatting definition.
Definition: convert.c:2979
tds.h
Main include file for libtds.
_bcp_free_storage
static void _bcp_free_storage(DBPROCESS *dbproc)
Definition: bcp.c:2377
_bcp_get_col_data
static TDSRET _bcp_get_col_data(TDSBCPINFO *bcpinfo, TDSCOLUMN *bindcol, int offset)
For a bcp in from program variables, get the data from the host variable.
Definition: bcp.c:2185
tds_connection::env
TDSENV env
environment is shared between all sessions
Definition: tds.h:1101
tdsdaterec::day
TDS_INT day
day of month (1-31)
Definition: tds.h:163
is_datetime_type
#define is_datetime_type(x)
return true if type is a datetime (but not date or time)
Definition: tds.h:393
tds_dstr_isempty
static int tds_dstr_isempty(const DSTR *s)
test if string is empty
Definition: string.h:60
tds_bcp_done
TDSRET tds_bcp_done(TDSSOCKET *tds, int *rows_copied)
Tell we finished sending BCP data to server.
Definition: bulk.c:836
bcp_init
RETCODE bcp_init(DBPROCESS *dbproc, const char *tblname, const char *hfile, const char *errfile, int direction)
Prepare for bulk copy operation on a table.
Definition: bcp.c:167
tds7_get_instance_ports
int tds7_get_instance_ports(FILE *output, struct addrinfo *addr)
Get port of all instances.
Definition: net.c:1093
tds_lookup_host
struct addrinfo * tds_lookup_host(const char *servername)
Get the IP address for a hostname.
Definition: config.c:987
_bcp_convert_out
static int _bcp_convert_out(DBPROCESS *dbproc, TDSCOLUMN *curcol, BCP_HOSTCOLINFO *hostcol, TDS_UCHAR **p_data, const char *bcpdatefmt)
Convert column for output (usually to a file) Conversion is slightly different from input as:
Definition: bcp.c:725
dblib_buffer_row::row_data
unsigned char * row_data
row data, NULL for resinfo->current_row
Definition: buffering.h:5
tds_cursor
Holds informations about a cursor.
Definition: tds.h:937
tds_get_conversion_type
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
_cs_dynamic
Definition: ctlib.h:176
LOGINREC
Definition: bsqlodbc.c:100
tds_cursor::cursor_id
TDS_INT cursor_id
cursor id returned by the server after cursor declare
Definition: tds.h:941
_cs_context::login_timeout
int login_timeout
not used unless positive
Definition: ctlib.h:101
tds_convert
TDS_INT tds_convert(const TDSCONTEXT *tds_ctx, int srctype, const void *src, TDS_UINT srclen, int desttype, CONV_RESULT *cr)
tds_convert convert a type to another.
Definition: convert.c:1878
tds_set_column_type
void tds_set_column_type(TDSCONNECTION *conn, TDSCOLUMN *curcol, TDS_SERVER_TYPE type)
Set type of column initializing all dependency.
Definition: data.c:224
tdsdaterec::weekday
TDS_INT weekday
day of week (0-6, 0 = sunday)
Definition: tds.h:165
tds_socket::rows_affected
TDS_INT8 rows_affected
rows updated/deleted/inserted/selected, TDS_NO_COUNT if not valid
Definition: tds.h:1254
tds_column::column_prec
TDS_TINYINT column_prec
precision for decimal/numeric
Definition: tds.h:703
tds_close_socket
void tds_close_socket(TDSSOCKET *tds)
Close current socket.
Definition: net.c:548
_bcp_read_hostfile
static STATUS _bcp_read_hostfile(DBPROCESS *dbproc, FILE *hostfile, int *row_error, bool skip)
Definition: bcp.c:1141
conv_result
Definition: convert.h:34
bcp_getl
DBBOOL bcp_getl(LOGINREC *login)
See if BCP_SETL() was used to set the LOGINREC for BCP work.
Definition: bcp.c:707
tds_alloc_row
TDSRET tds_alloc_row(TDSRESULTINFO *res_info)
Allocate space for row store return NULL on out of memory.
Definition: mem.c:524
_cs_param
Definition: ctlib.h:138
tds_read_config_info
TDSLOGIN * tds_read_config_info(TDSSOCKET *tds, TDSLOGIN *login, TDSLOCALE *locale)
tds_read_config_info() will fill the tds connection structure based on configuration information gath...
Definition: config.c:138
tds_set_interfaces_file_loc
TDSRET tds_set_interfaces_file_loc(const char *interf)
Set the full name of interface file.
Definition: config.c:961
tds_cursor_dealloc
TDSRET tds_cursor_dealloc(TDSSOCKET *tds, TDSCURSOR *cursor)
Send a deallocation request to server.
Definition: query.c:3006
bcp_collen
RETCODE bcp_collen(DBPROCESS *dbproc, DBINT varlen, int table_column)
Set the length of a host variable to be written to a table.
Definition: bcp.c:267
_cs_context
Definition: ctlib.h:75
_cs_money
Definition: cstypes.h:129
tds_process_cancel
TDSRET tds_process_cancel(TDSSOCKET *tds)
Definition: token.c:2554
tds_set_server
bool tds_set_server(TDSLOGIN *tds_login, const char *server) TDS_WUR
Set the servername in a TDSLOGIN structure.
Definition: login.c:129
_cs_context::query_timeout
int query_timeout
not used unless positive
Definition: ctlib.h:102
bcp_bind
RETCODE bcp_bind(DBPROCESS *dbproc, BYTE *varaddr, int prefixlen, DBINT varlen, BYTE *terminator, int termlen, int db_vartype, int table_column)
Bind a program host variable to a database column.
Definition: bcp.c:2079
tds_dstr_copyn
DSTR * tds_dstr_copyn(DSTR *s, const char *src, size_t length)
Set string to a given buffer of characters.
Definition: tdsstring.c:77
bcp_columns
RETCODE bcp_columns(DBPROCESS *dbproc, int host_colcount)
Indicate how many columns are to be found in the datafile.
Definition: bcp.c:301
tds_submit_queryf
TDSRET tds_submit_queryf(TDSSOCKET *tds, const char *queryf,...)
Format and submit a query.
Definition: query.c:467
tds_dynamic::params
TDSPARAMINFO * params
query parameters.
Definition: tds.h:1007
tds_dstr_dup
DSTR * tds_dstr_dup(DSTR *s, const DSTR *src)
Duplicate a string from another dynamic string.
Definition: tdsstring.c:134
tdsdatetime
Definition: proto.h:50
cs_diag_msg_svr
Definition: ctlib.h:61
tds_peek
unsigned char tds_peek(TDSSOCKET *tds)
Reads a byte from the TDS stream without removing it.
Definition: read.c:100
bcp_control
RETCODE bcp_control(DBPROCESS *dbproc, int field, DBINT value)
Set BCP options for uploading a datafile.
Definition: bcp.c:544
bcp_colfmt
RETCODE bcp_colfmt(DBPROCESS *dbproc, int host_colnum, int host_type, int host_prefixlen, DBINT host_collen, const BYTE *host_term, int host_termlen, int table_colnum)
Specify the format of a datafile prior to writing to a table.
Definition: bcp.c:377
tds_variant
Store variant informations.
Definition: tds.h:604
tdsdaterec::dayofyear
TDS_INT dayofyear
day of year (1-366)
Definition: tds.h:164
_cs_servermsg
Definition: cstypes.h:191
dbvarylen
DBINT dbvarylen(DBPROCESS *dbproc, int column)
Determine whether a column can vary in size.
Definition: dblib.c:3218
tds_message
Definition: tds.h:876
_cs_numeric
Definition: cstypes.h:69
dblib_buffer_row
Definition: buffering.h:1
_cs_connection
Definition: ctlib.h:117
tds_send_cancel
TDSRET tds_send_cancel(TDSSOCKET *tds)
tds_send_cancel() sends an empty packet (8 byte header only) tds_process_cancel should be called dire...
Definition: query.c:2026
tds_cursor::query
char * query
SQL query.
Definition: tds.h:947
tds_column
Metadata about columns in regular and compute rows.
Definition: tds.h:689
_bcp_readfmt_colinfo
static int _bcp_readfmt_colinfo(DBPROCESS *dbproc, char *buf, BCP_HOSTCOLINFO *ci)
Definition: bcp.c:1775
tds_cursor::options
TDS_TINYINT options
read only|updatable TODO use it
Definition: tds.h:942
tds_connection
Definition: tds.h:1091
tds_submit_optioncmd
TDSRET tds_submit_optioncmd(TDSSOCKET *tds, TDS_OPTION_CMD command, TDS_OPTION option, TDS_OPTION_ARG *param, TDS_INT param_size)
Send option commands to server.
Definition: query.c:3389
tds_writetext_continue
TDSRET tds_writetext_continue(TDSSOCKET *tds, const TDS_UCHAR *text, TDS_UINT size)
Send some data in the writetext request started by tds_writetext_start.
Definition: bulk.c:1185
tds_bcpcoldata
Definition: tds.h:628
tdsmoney4
Definition: proto.h:45
_bcp_exec_out
static RETCODE _bcp_exec_out(DBPROCESS *dbproc, DBINT *rows_copied)
Definition: bcp.c:872
tds_datecrack
TDSRET tds_datecrack(TDS_INT datetype, const void *di, TDSDATEREC *dr)
Convert from db date format to a structured date format.
Definition: convert.c:3159
tds_submit_query
TDSRET tds_submit_query(TDSSOCKET *tds, const char *query)
Sends a language string to the database server for processing.
Definition: query.c:210
tds_blob
Information about blobs (e.g.
Definition: tds.h:593
tds_login::bulk_copy
unsigned int bulk_copy
if bulk copy should be enabled
Definition: tds.h:556
dbprtype
const char * dbprtype(int token)
Print a token value's name to a buffer.
Definition: dblib.c:6447
tds_writetext_start
TDSRET tds_writetext_start(TDSSOCKET *tds, const char *objname, const char *textptr, const char *timestamp, int with_log, TDS_UINT size)
Start writing writetext request.
Definition: bulk.c:1147
tds_dstr
Structure to hold a string.
Definition: string.h:36
tds_result_info
Hold information for any results.
Definition: tds.h:769
tdsdaterec::hour
TDS_INT hour
0-23
Definition: tds.h:166
tds_alloc_param_result
TDSPARAMINFO * tds_alloc_param_result(TDSPARAMINFO *old_param)
Adds a output parameter to TDSPARAMINFO.
Definition: mem.c:284
tds_socket::cur_dyn
TDSDYNAMIC * cur_dyn
dynamic structure in use
Definition: tds.h:1256
_bcp_free_columns
static void _bcp_free_columns(DBPROCESS *dbproc)
Definition: bcp.c:2351
dbgetnull
RETCODE dbgetnull(DBPROCESS *dbproc, int bindtype, int varlen, BYTE *varaddr)
Definition: dblib.c:529
tds_socket::current_results
TDSRESULTINFO * current_results
Current query information.
Definition: tds.h:1238
tds_login::ip_addrs
struct addrinfo * ip_addrs
ip(s) of server
Definition: tds.h:546
tds_cursor::cursor_name
char * cursor_name
name of the cursor
Definition: tds.h:940
tdsdaterec::month
TDS_INT month
month number (0-11)
Definition: tds.h:162
tdsdaterec::second
TDS_INT second
0-59
Definition: tds.h:168
_bcp_convert_in
static TDSRET _bcp_convert_in(DBPROCESS *dbproc, TDS_SERVER_TYPE srctype, const TDS_CHAR *src, TDS_UINT srclen, TDS_SERVER_TYPE desttype, BCPCOLDATA *coldata)
Convert column for input to a table.
Definition: bcp.c:1054
tds_alloc_param_data
void * tds_alloc_param_data(TDSCOLUMN *curparam)
Allocate data for a parameter.
Definition: mem.c:364
_cs_datetime
Definition: cstypes.h:147
bcp_done
DBINT bcp_done(DBPROCESS *dbproc)
Conclude the transfer of data from program variables.
Definition: bcp.c:2037
tds_get_size_by_type
int tds_get_size_by_type(TDS_SERVER_TYPE servertype)
Return the number of bytes needed by specified type.
Definition: tds_types.h:9
tds_bcp_fread
TDSRET tds_bcp_fread(TDSSOCKET *tds, TDSICONV *char_conv, FILE *stream, const char *terminator, size_t term_len, char **outbuf, size_t *outbytes)
Read a data file, passing the data through iconv().
Definition: bulk.c:1077
tds_submit_execute
TDSRET tds_submit_execute(TDSSOCKET *tds, TDSDYNAMIC *dyn)
Sends a previously prepared dynamic statement to the server.
Definition: query.c:1630
_bcp_get_term_var
static int _bcp_get_term_var(const BYTE *pdata, const BYTE *term, int term_len)
Get the data for bcp-in from program variables, where the program data have been identified as charac...
Definition: bcp.c:2297
tds_free_input_params
void tds_free_input_params(TDSDYNAMIC *dyn)
Frees all allocated input parameters of a dynamic statement.
Definition: mem.c:206
tds_login::server_name
DSTR server_name
server name (in freetds.conf)
Definition: tds.h:518
tds_column::column_size
TDS_INT column_size
maximun size of data.
Definition: tds.h:694
dblib_buffer_row::sizes
TDS_INT * sizes
save old sizes
Definition: buffering.h:9
tds_socket::ret_status
TDS_INT ret_status
return status from store procedure
Definition: tds.h:1250
tds_column::column_cur_size
TDS_INT column_cur_size
size written in variable (ie: char, text, binary).
Definition: tds.h:736
tds_column::char_conv
TDSICONV * char_conv
refers to previously allocated iconv information
Definition: tds.h:712
tds_column::column_varint_size
TDS_TINYINT column_varint_size
size of length when reading from wire (0, 1, 2 or 4)
Definition: tds.h:701
bcp_colptr
RETCODE bcp_colptr(DBPROCESS *dbproc, BYTE *colptr, int table_column)
Override bcp_bind() by pointing to a different host variable.
Definition: bcp.c:671
_cs_varchar
Definition: cstypes.h:84
sybdb.h
Primary include file for db-lib applications.
tdsdump_open
int tdsdump_open(const char *filename)
Create and truncate a human readable dump file for the TDS traffic.
Definition: log.c:131
BCP_HOSTCOLINFO
Definition: dblib.h:62
_bcp_no_get_col_data
static TDSRET _bcp_no_get_col_data(TDSBCPINFO *bcpinfo, TDSCOLUMN *bindcol, int offset)
Function to read data from file.
Definition: bcp.c:2276
_cs_daterec
Definition: cstypes.h:159
bcp_options
RETCODE bcp_options(DBPROCESS *dbproc, int option, BYTE *value, int valuelen)
Set "hints" for uploading a file.
Definition: bcp.c:622
dblib_buffer_row::resinfo
TDSRESULTINFO * resinfo
pointer to result informations
Definition: buffering.h:3
tdsdaterec::year
TDS_INT year
year
Definition: tds.h:160
tds_bcp_init
TDSRET tds_bcp_init(TDSSOCKET *tds, TDSBCPINFO *bcpinfo)
Initialize BCP information.
Definition: bulk.c:84
tds_dstr_copy
DSTR * tds_dstr_copy(DSTR *s, const char *src)
copy a string from another
Definition: tdsstring.c:122
bcp_colfmt_ps
RETCODE bcp_colfmt_ps(DBPROCESS *dbproc, int host_colnum, int host_type, int host_prefixlen, DBINT host_collen, BYTE *host_term, int host_termlen, int table_colnum, DBTYPEINFO *typeinfo)
Specify the format of a host file for bulk copy purposes, with precision and scale support for numeri...
Definition: bcp.c:509
tds_login::port
int port
port of database service
Definition: tds.h:519
_cs_money4
Definition: cstypes.h:135
tds_column::column_scale
TDS_TINYINT column_scale
scale for decimal/numeric
Definition: tds.h:704
_bcp_fgets
static char * _bcp_fgets(char *buffer, int size, FILE *f)
Definition: bcp.c:1652
tds_dynamic::res_info
TDSPARAMINFO * res_info
query results
Definition: tds.h:999
cs_diag_msg_client
Definition: ctlib.h:55
tds_login::user_name
DSTR user_name
account for login
Definition: tds.h:534
tds_iconv
size_t tds_iconv(TDSSOCKET *tds, TDSICONV *conv, TDS_ICONV_DIRECTION io, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
Wrapper around iconv(3).
Definition: iconv.c:592
TDS_DEAD
@ TDS_DEAD
no connection
Definition: tds.h:795
tds_strndup
char * tds_strndup(const void *s, TDS_INTPTR len)
Copy a string of length len to a new allocated buffer This function does not read more than len bytes...
Definition: util.c:406
tds_release_dynamic
void tds_release_dynamic(TDSDYNAMIC **pdyn)
Frees dynamic statement.
Definition: mem.c:253
_csremote_proc
Definition: ctlib.h:162
_cs_datafmt
Definition: cstypes.h:114
tds_writetext_end
TDSRET tds_writetext_end(TDSSOCKET *tds)
Finish sending writetext data.
Definition: bulk.c:1202
TDS_DATETIMEALL
this structure is not directed connected to a TDS protocol but keeps any DATE/TIME information.
Definition: tds.h:146
tds_bcp_start
TDSRET tds_bcp_start(TDSSOCKET *tds, TDSBCPINFO *bcpinfo)
Start sending BCP data to server.
Definition: bulk.c:866
tdsoldmoney
Definition: proto.h:33
tds_bcpinfo
Definition: tds.h:1661
bcp_sendrow
RETCODE bcp_sendrow(DBPROCESS *dbproc)
Write data in host variables to the table.
Definition: bcp.c:1381
DBPROC_ROWBUF
Definition: dblib.h:52
bcp_exec
RETCODE bcp_exec(DBPROCESS *dbproc, DBINT *rows_copied)
Write a datafile to a table.
Definition: bcp.c:1617
_cs_datetime4
Definition: cstypes.h:153
tds_dstr_len
static size_t tds_dstr_len(const DSTR *s)
Returns the length of the string in bytes.
Definition: string.h:85
tds_bcp_send_record
TDSRET tds_bcp_send_record(TDSSOCKET *tds, TDSBCPINFO *bcpinfo, tds_bcp_get_col_data get_col_data, tds_bcp_null_error null_error, int offset)
Send one row of data to server.
Definition: bulk.c:468
dblib_buffer_row::row
DBINT row
row number
Definition: buffering.h:7
tds_socket
Information for a server connection.
Definition: tds.h:1163
tds_capability_type
Definition: tds.h:504
tds_dblib_dbprocess
Definition: dblib.h:123
tds_column::bcp_prefix_len
TDS_INT bcp_prefix_len
The length, in bytes, of any length prefix this column may have.
Definition: tds.h:761
tds_login::server_spn
DSTR server_spn
server SPN (in freetds.conf)
Definition: tds.h:528
tdsdatetime4
Definition: proto.h:56
tdsdaterec::minute
TDS_INT minute
0-59
Definition: tds.h:167
tds7_get_instance_port
int tds7_get_instance_port(struct addrinfo *addr, const char *instance)
Get port of given instance.
Definition: net.c:1229
tds_submit_rpc
TDSRET tds_submit_rpc(TDSSOCKET *tds, const char *rpc_name, TDSPARAMINFO *params, TDSHEADERS *head)
Calls a RPC from server.
Definition: query.c:1929
cs_diag_msg
Definition: ctlib.h:69
TDS_DONE_ERROR
@ TDS_DONE_ERROR
error occurred
Definition: tds.h:253
_cs_objdata
Definition: cspublic.h:699
tds_dblib_dbprocess::msdblib
int msdblib
boolean use ms behaviour
Definition: dblib.h:154
tds_flush_packet
TDSRET tds_flush_packet(TDSSOCKET *tds)
Flush packet to server.
Definition: write.c:224
_cs_locale
Definition: ctlib.h:248
tds_process_tokens
TDSRET tds_process_tokens(TDSSOCKET *tds, TDS_INT *result_type, int *done_flags, unsigned flag)
process all streams.
Definition: token.c:531
dbtypeinfo
Definition: sybdb.h:336
tds_login::server_charset
DSTR server_charset
charset of server e.g.
Definition: tds.h:523
tds_option_arg
Definition: tds.h:330
bcp_batch
DBINT bcp_batch(DBPROCESS *dbproc)
Commit a set of rows to the table.
Definition: bcp.c:2010
_cs_iodesc
Definition: cstypes.h:97
TDS_PENDING
@ TDS_PENDING
cilent is waiting for data
Definition: tds.h:793
tds_env::block_size
int block_size
packet size (512-65535)
Definition: tds.h:965
tds_column::column_type
TDS_SERVER_TYPE column_type
This type can be different from wire type because conversion (e.g.
Definition: tds.h:696
tds_write_dump
int tds_write_dump
Tell if TDS debug logging is turned on or off.
Definition: log.c:58
tds_context
Definition: tds.h:1029
tds_compiletime_settings
A structure to hold all the compile-time settings.
Definition: tds.h:82
BCP_HOSTFILEINFO
Definition: dblib.h:74
tdsnumeric
Definition: proto.h:26
tds_login
Definition: tds.h:517
tds_bcp_start_copy_in
TDSRET tds_bcp_start_copy_in(TDSSOCKET *tds, TDSBCPINFO *bcpinfo)
Start bulk copy to server.
Definition: bulk.c:916
tds_get_compiletime_settings
const TDS_COMPILETIME_SETTINGS * tds_get_compiletime_settings(void)
Return a structure capturing the compile-time settings provided to the configure script.
Definition: config.c:1337
_cs_clientmsg
Definition: cstypes.h:177
tdsdump_close
void tdsdump_close(void)
Close the TDS dump log file.
Definition: log.c:212
tds_submit_prepare
TDSRET tds_submit_prepare(TDSSOCKET *tds, const char *query, const char *id, TDSDYNAMIC **dyn_out, TDSPARAMINFO *params)
Creates a temporary stored procedure in the server.
Definition: query.c:1124
dbperror
int dbperror(DBPROCESS *dbproc, DBINT msgno, long errnum,...)
Call client-installed error handler.
Definition: dblib.c:8127
tds_willconvert
unsigned char tds_willconvert(int srctype, int desttype)
Test if a conversion is possible.
Definition: convert.c:3093
tdsdump_log
void tdsdump_log(const char *file, unsigned int level_line, const char *fmt,...)
Write a message to the debug log.
Definition: log.c:396