buffering.h
typedef struct dblib_buffer_row {
TDSRESULTINFO *resinfo;
unsigned char *row_data;
DBINT row;
TDS_INT *sizes;
} DBLIB_BUFFER_ROW;
static void buffer_struct_print(const DBPROC_ROWBUF *buf);
static RETCODE buffer_save_row(DBPROCESS *dbproc);
static DBLIB_BUFFER_ROW* buffer_row_address(const DBPROC_ROWBUF * buf, int idx);
#if ENABLE_EXTRA_CHECKS
static void buffer_check_row_empty(DBLIB_BUFFER_ROW *row)
{
assert(row->resinfo == NULL);
assert(row->row_data == NULL);
assert(row->sizes == NULL);
assert(row->row == 0);
}
static void buffer_check(const DBPROC_ROWBUF *buf)
{
int i;
/* no buffering */
if (buf->capacity == 0 || buf->capacity == 1) {
assert(buf->head == 0);
assert(buf->tail == 0 || buf->tail == 1);
assert(buf->capacity == 1 || buf->rows == NULL);
return;
}
assert(buf->capacity > 0);
assert(buf->head >= 0);
assert(buf->tail >= 0);
assert(buf->head < buf->capacity);
assert(buf->tail <= buf->capacity);
/* check empty */
if (buf->tail == buf->capacity) {
assert(buf->head == 0);
for (i = 0; buf->rows && i < buf->capacity; ++i)
buffer_check_row_empty(&buf->rows[i]);
return;
}
if (buf->rows == NULL)
return;
/* check filled part */
i = buf->tail;
do {
assert(i >= 0 && i < buf->capacity);
assert(buf->rows[i].resinfo != NULL);
assert(buf->rows[i].row > 0);
assert(buf->rows[i].row <= buf->received);
++i;
if (i == buf->capacity)
i = 0;
} while (i != buf->head);
/* check empty part */
if (buf->head != buf->tail) {
i = buf->head;
do {
assert(i >= 0 && i < buf->capacity);
buffer_check_row_empty(&buf->rows[i]);
++i;
if (i == buf->capacity)
i = 0;
} while (i != buf->tail);
}
}
#define BUFFER_CHECK(buf) buffer_check(buf)
#else
#define BUFFER_CHECK(buf) do {} while(0)
#endif
static int
buffer_count(const DBPROC_ROWBUF *buf)
{
BUFFER_CHECK(buf);
return (buf->head > buf->tail) ?
buf->head - buf->tail : /* |...TddddH....| */
buf->capacity - (buf->tail - buf->head); /* |ddddH....Tddd| */
}
static int
buffer_is_full(const DBPROC_ROWBUF *buf)
{
BUFFER_CHECK(buf);
return buf->capacity == buffer_count(buf) && buf->capacity > 1;
}
#ifndef NDEBUG
static int
buffer_index_valid(const DBPROC_ROWBUF *buf, int idx)
{
BUFFER_CHECK(buf);
if (buf->tail <= buf->head)
if (buf->head <= idx && idx <= buf->tail)
return 1;
if (0 <= idx && idx <= buf->head)
return 1;
if (buf->tail <= idx && idx < buf->capacity)
return 1;
#if 0
printf("buffer_index_valid: idx = %d\n", idx);
buffer_struct_print(buf);
#endif
return 0;
}
#endif
static void
buffer_free_row(DBLIB_BUFFER_ROW *row)
{
if (row->sizes)
TDS_ZERO_FREE(row->sizes);
if (row->row_data) {
tds_free_row(row->resinfo, row->row_data);
row->row_data = NULL;
}
tds_free_results(row->resinfo);
row->resinfo = NULL;
row->row = 0;
}
/*
* Buffer is freed at slightly odd points, whenever
* capacity changes:
*
* 1. When setting capacity, to release prior buffer.
* 2. By dbresults. When called the second time, it has to
* release prior storage because the new resultset will have
* a different width.
* 3. By dbclose(), else open/close/open would leak.
*/
static void
buffer_free(DBPROC_ROWBUF *buf)
{
BUFFER_CHECK(buf);
if (buf->rows != NULL) {
int i;
for (i = 0; i < buf->capacity; ++i)
buffer_free_row(&buf->rows[i]);
TDS_ZERO_FREE(buf->rows);
}
BUFFER_CHECK(buf);
}
/*
* When no rows are currently buffered (and the buffer is allocated)
* set the indices to their initial positions.
*/
static void
buffer_reset(DBPROC_ROWBUF *buf)
{
buf->head = 0;
buf->current = buf->tail = buf->capacity;
BUFFER_CHECK(buf);
}
static int
buffer_idx_increment(const DBPROC_ROWBUF *buf, int idx)
{
if (++idx >= buf->capacity) {
idx = 0;
}
return idx;
}
static DBLIB_BUFFER_ROW*
buffer_row_address(const DBPROC_ROWBUF * buf, int idx)
{
BUFFER_CHECK(buf);
if (idx < 0 || idx >= buf->capacity) {
printf("idx is %d:\n", idx);
buffer_struct_print(buf);
return NULL;
}
return &(buf->rows[idx]);
}
static DBINT
buffer_idx2row(const DBPROC_ROWBUF *buf, int idx)
{
BUFFER_CHECK(buf);
return buffer_row_address(buf, idx)->row;
}
static int
buffer_row2idx(const DBPROC_ROWBUF *buf, int row_number)
{
int i = buf->tail;
#ifndef NDEBUG
int ii = 0;
#endif
BUFFER_CHECK(buf);
if (i == buf->capacity) {
assert (buf->head == 0);
return -1; /* no rows buffered */
}
/*
* March through the buffers from tail to head, stop if we find our row.
* A full queue is indicated by tail == head (which means we can't write).
*/
do {
if (buffer_idx2row(buf, i) == row_number)
return i;
assert(ii++ < buf->capacity); /* prevent infinite loop */
i = buffer_idx_increment(buf, i);
} while (i != buf->head);
return -1;
}
static void
buffer_delete_rows(DBPROC_ROWBUF * buf, int count)
{
int i;
BUFFER_CHECK(buf);
if (count < 0 || count > buffer_count(buf)) {
count = buffer_count(buf);
}
for (i=0; i < count; i++) {
if (buf->tail < buf->capacity)
buffer_free_row(&buf->rows[buf->tail]);
buf->tail = buffer_idx_increment(buf, buf->tail);
/*
* If deleting rows from the buffer catches the tail to the head,
* return to the initial position. Otherwise, it will look full.
*/
if (buf->tail == buf->head) {
buffer_reset(buf);
break;
}
}
#if 0
buffer_struct_print(buf);
#endif
BUFFER_CHECK(buf);
}
static void
buffer_transfer_bound_data(DBPROC_ROWBUF *buf, TDS_INT res_type, TDS_INT compute_id, DBPROCESS * dbproc, int idx)
{
int i;
BYTE *src;
const DBLIB_BUFFER_ROW *row;
tdsdump_log(TDS_DBG_FUNC, "buffer_transfer_bound_data(%p %d %d %p %d)\n", buf, res_type, compute_id, dbproc, idx);
BUFFER_CHECK(buf);
assert(buffer_index_valid(buf, idx));
row = buffer_row_address(buf, idx);
assert(row->resinfo);
for (i = 0; i < row->resinfo->num_cols; i++) {
TDS_SERVER_TYPE srctype;
DBINT srclen;
TDSCOLUMN *curcol = row->resinfo->columns[i];
if (row->sizes)
curcol->column_cur_size = row->sizes[i];
srclen = curcol->column_cur_size;
if (curcol->column_nullbind) {
if (srclen < 0) {
*(DBINT *)(curcol->column_nullbind) = -1;
} else {
*(DBINT *)(curcol->column_nullbind) = 0;
}
}
if (!curcol->column_varaddr)
continue;
if (srclen <= 0) {
if (srclen == 0 || !curcol->column_nullbind)
dbgetnull(dbproc, curcol->column_bindtype, curcol->column_bindlen,
(BYTE *) curcol->column_varaddr);
continue;
}
srctype = tds_get_conversion_type(curcol->column_type, curcol->column_size);
if (row->row_data)
src = &row->row_data[curcol->column_data - row->resinfo->current_row];
else
src = curcol->column_data;
if (is_blob_col(curcol))
src = (BYTE *) ((TDSBLOB *) src)->textvalue;
copy_data_to_host_var(dbproc, srctype, src, srclen,
(BYTE *) curcol->column_varaddr, curcol->column_bindlen,
curcol->column_bindtype, (DBINT*) curcol->column_nullbind);
}
/*
* This function always bumps current. Usually, it's called
* by dbnextrow(), so bumping current is a pretty obvious choice.
* It can also be called by dbgetrow(), but that function also
* causes the bump. If you call dbgetrow() for row N, a subsequent
* call to dbnextrow() yields N+1.
*/
buf->current = buffer_idx_increment(buf, buf->current);
} /* end buffer_transfer_bound_data() */
static void
buffer_struct_print(const DBPROC_ROWBUF *buf)
{
assert(buf);
printf("\t%d rows in buffer\n", buffer_count(buf));
printf("\thead = %d\t", buf->head);
printf("\ttail = %d\t", buf->tail);
printf("\tcurrent = %d\n", buf->current);
printf("\tcapacity = %d\t", buf->capacity);
printf("\thead row number = %d\n", buf->received);
}
/* * * Functions called only by public db-lib API take DBPROCESS* * */
static int
buffer_current_index(const DBPROCESS *dbproc)
{
const DBPROC_ROWBUF *buf = &dbproc->row_buf;
#if 0
buffer_struct_print(buf);
#endif
if (buf->capacity <= 1) /* no buffering */
return -1;
if (buf->current == buf->head || buf->current == buf->capacity)
return -1;
assert(buf->current >= 0);
assert(buf->current < buf->capacity);
if( buf->tail < buf->head) {
assert(buf->tail < buf->current);
assert(buf->current < buf->head);
} else {
if (buf->current > buf->head)
assert(buf->current > buf->tail);
}
return buf->current;
}
/*
* Normally called by dbsetopt() to prepare for buffering
* Called with nrows == 0 by dbopen to safely set buf->rows to NULL.
*/
static void
buffer_set_capacity(DBPROCESS *dbproc, int nrows)
{
DBPROC_ROWBUF *buf = &dbproc->row_buf;
buffer_free(buf);
memset(buf, 0, sizeof(DBPROC_ROWBUF));
if (0 == nrows) {
buf->capacity = 1;
BUFFER_CHECK(buf);
return;
}
assert(0 < nrows);
buf->capacity = nrows;
BUFFER_CHECK(buf);
}
/*
* Called only by dbresults(); capacity must be >= 1.
* Sybase's documents say dbresults() cannot return FAIL if the prior calls worked,
* which is a little strange, because (for FreeTDS, at least), dbresults
* is when we learn about the result set's width. Without that information, we
* can't allocate memory for the buffer. But if we *fail* to allocate memory,
* we're not to communicate it back to the caller?
*/
static void
buffer_alloc(DBPROCESS *dbproc)
{
DBPROC_ROWBUF *buf = &dbproc->row_buf;
/* Call this function only after setting capacity. */
assert(buf);
assert(buf->capacity > 0);
assert(buf->rows == NULL);
buf->rows = tds_new0(DBLIB_BUFFER_ROW, buf->capacity);
assert(buf->rows);
buffer_reset(buf);
buf->received = 0;
}
static int
buffer_add_row(DBPROCESS *dbproc, TDSRESULTINFO *resinfo)
{
DBPROC_ROWBUF *buf = &dbproc->row_buf;
DBLIB_BUFFER_ROW *row;
int i;
assert(buf->capacity >= 0);
if (buffer_is_full(buf))
return -1;
row = buffer_row_address(buf, buf->head);
/* bump the row number, write it, and move the data to head */
if (row->resinfo) {
tds_free_row(row->resinfo, row->row_data);
tds_free_results(row->resinfo);
}
row->row = ++buf->received;
++resinfo->ref_count;
row->resinfo = resinfo;
row->row_data = NULL;
if (row->sizes)
free(row->sizes);
row->sizes = tds_new0(TDS_INT, resinfo->num_cols);
for (i = 0; i < resinfo->num_cols; ++i)
row->sizes[i] = resinfo->columns[i]->column_cur_size;
/* initial condition is head == 0 and tail == capacity */
if (buf->tail == buf->capacity) {
/* bumping this tail will set it to zero */
assert(buf->head == 0);
buf->tail = 0;
}
/* update current, bump the head */
buf->current = buf->head;
buf->head = buffer_idx_increment(buf, buf->head);
return buf->current;
}
static RETCODE
buffer_save_row(DBPROCESS *dbproc)
{
DBPROC_ROWBUF *buf = &dbproc->row_buf;
DBLIB_BUFFER_ROW *row;
int idx = buf->head - 1;
if (buf->capacity <= 1)
return SUCCEED;
if (idx < 0)
idx = buf->capacity - 1;
if (idx >= 0 && idx < buf->capacity) {
row = &buf->rows[idx];
if (row->resinfo && !row->row_data) {
row->row_data = row->resinfo->current_row;
tds_alloc_row(row->resinfo);
}
}
return SUCCEED;
}
_cs_money
Definition: cstypes.h:129
tds_login::bulk_copy
unsigned int bulk_copy
if bulk copy should be enabled
Definition: tds.h:557
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_peek
unsigned char tds_peek(TDSSOCKET *tds)
Reads a byte from the TDS stream without removing it.
Definition: read.c:100
_cs_varchar
Definition: cstypes.h:84
sybdb.h
Primary include file for db-lib applications.
tds_variant
Store variant informations.
Definition: tds.h:605
BCP_HOSTCOLINFO
Definition: dblib.h:62
_cs_daterec
Definition: cstypes.h:159
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
tds_submit_unprepare
TDSRET tds_submit_unprepare(TDSSOCKET *tds, TDSDYNAMIC *dyn)
Send a unprepare request for a prepared query.
Definition: query.c:1797
tdsdaterec::month
TDS_INT month
month number (0-11)
Definition: tds.h:163
tdsdaterec::second
TDS_INT second
0-59
Definition: tds.h:169
tds_login::ip_addrs
struct addrinfo * ip_addrs
ip(s) of server
Definition: tds.h:547
_cs_context
Definition: ctlib.h:75
tds_login::server_name
DSTR server_name
server name (in freetds.conf)
Definition: tds.h:519
tds_bcp_start_copy_in
TDSRET tds_bcp_start_copy_in(TDSSOCKET *tds, TDSBCPINFO *bcpinfo)
Start bulk copy to server.
Definition: bulk.c:902
_cs_numeric
Definition: cstypes.h:69
dblib_buffer_row
Definition: buffering.h:1
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_submit_execute
TDSRET tds_submit_execute(TDSSOCKET *tds, TDSDYNAMIC *dyn)
Sends a previously prepared dynamic statement to the server.
Definition: query.c:1630
dbvarylen
DBINT dbvarylen(DBPROCESS *dbproc, int column)
Determine whether a column can vary in size.
Definition: dblib.c:3222
tds.h
Main include file for libtds.
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
_cs_datafmt
Definition: cstypes.h:114
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
tds_option_arg
Definition: tds.h:331
tdsoldmoney
Definition: proto.h:33
tds_submit_queryf
TDSRET tds_submit_queryf(TDSSOCKET *tds, const char *queryf,...)
Format and submit a query.
Definition: query.c:467
tds_blob
Information about blobs (e.g.
Definition: tds.h:594
tdsdaterec::year
TDS_INT year
year
Definition: tds.h:161
_cs_servermsg
Definition: cstypes.h:191
tds_socket::rows_affected
TDS_INT8 rows_affected
rows updated/deleted/inserted/selected, TDS_NO_COUNT if not valid
Definition: tds.h:1255
tds_bcp_done
TDSRET tds_bcp_done(TDSSOCKET *tds, int *rows_copied)
Tell we finished sending BCP data to server.
Definition: bulk.c:822
_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:2186
tds_cursor::cursor_rows
TDS_INT cursor_rows
< number of updatable columns
Definition: tds.h:952
tds_column::column_prec
TDS_TINYINT column_prec
precision for decimal/numeric
Definition: tds.h:704
tds_bcp_start
TDSRET tds_bcp_start(TDSSOCKET *tds, TDSBCPINFO *bcpinfo)
Start sending BCP data to server.
Definition: bulk.c:852
_cs_connection
Definition: ctlib.h:117
tdsdump_open
int tdsdump_open(const char *filename)
Create and truncate a human readable dump file for the TDS traffic.
Definition: log.c:112
tds_dstr_empty
#define tds_dstr_empty(s)
Make a string empty.
Definition: string.h:91
tds_result_info
Hold information for any results.
Definition: tds.h:770
TDS_DATETIMEALL
this structure is not directed connected to a TDS protocol but keeps any DATE/TIME information.
Definition: tds.h:147
_cs_objdata
Definition: cspublic.h:699
tds_cursor::cursor_id
TDS_INT cursor_id
cursor id returned by the server after cursor declare
Definition: tds.h:942
_cs_locale
Definition: ctlib.h:248
dbprtype
const char * dbprtype(int token)
Print a token value's name to a buffer.
Definition: dblib.c:6451
tds_connection::env
TDSENV env
environment is shared between all sessions
Definition: tds.h:1102
tds_socket
Information for a server connection.
Definition: tds.h:1164
tds_capability_type
Definition: tds.h:505
tds_alloc_param_result
TDSPARAMINFO * tds_alloc_param_result(TDSPARAMINFO *old_param)
Adds a output parameter to TDSPARAMINFO.
Definition: mem.c:284
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
bcp_options
RETCODE bcp_options(DBPROCESS *dbproc, int option, BYTE *value, int valuelen)
Set "hints" for uploading a file.
Definition: bcp.c:622
_bcp_get_term_var
static int _bcp_get_term_var(BYTE *pdata, 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:2298
_bcp_free_storage
static void _bcp_free_storage(DBPROCESS *dbproc)
Definition: bcp.c:2378
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_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:590
rtrim
static int rtrim(char *, int)
trim a string of trailing blanks
Definition: bcp.c:2324
tdsmoney4
Definition: proto.h:45
cs_diag_msg_client
Definition: ctlib.h:55
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
_bcp_exec_out
static RETCODE _bcp_exec_out(DBPROCESS *dbproc, DBINT *rows_copied)
Definition: bcp.c:872
is_datetime_type
#define is_datetime_type(x)
return true if type is a datetime (but not date or time)
Definition: tds.h:394
tds_willconvert
unsigned char tds_willconvert(int srctype, int desttype)
Test if a conversion is possible.
Definition: convert.c:3056
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
tds_login::server_spn
DSTR server_spn
server SPN (in freetds.conf)
Definition: tds.h:529
dbperror
int dbperror(DBPROCESS *dbproc, DBINT msgno, long errnum,...)
Call client-installed error handler.
Definition: dblib.c:8131
tds_prtype
const char * tds_prtype(int type)
Returns string representation of the given type.
Definition: token.c:3052
tds_context
Definition: tds.h:1030
tds_compiletime_settings
A structure to hold all the compile-time settings.
Definition: tds.h:83
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_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
tds_login::port
int port
port of database service
Definition: tds.h:520
tds_socket::cur_dyn
TDSDYNAMIC * cur_dyn
dynamic structure in use
Definition: tds.h:1257
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:2968
_cs_command
Definition: ctlib.h:212
tds_socket::current_results
TDSRESULTINFO * current_results
Current query information.
Definition: tds.h:1239
tds_login::server_charset
DSTR server_charset
charset of server e.g.
Definition: tds.h:524
tdsdatetime4
Definition: proto.h:56
tds_cursor::cursor_name
char * cursor_name
name of the cursor
Definition: tds.h:941
tds_dstr_isempty
static int tds_dstr_isempty(const DSTR *s)
test if string is empty
Definition: string.h:60
tds_set_interfaces_file_loc
TDSRET tds_set_interfaces_file_loc(const char *interf)
Set the full name of interface file.
Definition: config.c:965
bcp_batch
DBINT bcp_batch(DBPROCESS *dbproc)
Commit a set of rows to the table.
Definition: bcp.c:2011
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_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
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:1063
tds_cursor::query
char * query
SQL query.
Definition: tds.h:948
dblib_buffer_row::resinfo
TDSRESULTINFO * resinfo
pointer to result informations
Definition: buffering.h:3
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:354
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_dblib_dbprocess::msdblib
int msdblib
boolean use ms behaviour
Definition: dblib.h:154
tds_column::column_size
TDS_INT column_size
maximun size of data.
Definition: tds.h:695
_csremote_proc
Definition: ctlib.h:162
_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_close_socket
void tds_close_socket(TDSSOCKET *tds)
Close current socket.
Definition: net.c:548
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:125
_cs_money4
Definition: cstypes.h:135
tds_env::block_size
int block_size
packet size (512-65535)
Definition: tds.h:966
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_dynamic
Holds information for a dynamic (also called prepared) query.
Definition: tds.h:978
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
dbgetnull
RETCODE dbgetnull(DBPROCESS *dbproc, int bindtype, int varlen, BYTE *varaddr)
Definition: dblib.c:534
tds_dynamic::params
TDSPARAMINFO * params
query parameters.
Definition: tds.h:1008
tds_process_tokens
TDSRET tds_process_tokens(TDSSOCKET *tds, TDS_INT *result_type, int *done_flags, unsigned flag)
process all streams.
Definition: token.c:530
tdsdaterec::minute
TDS_INT minute
0-59
Definition: tds.h:168
tds_cursor::options
TDS_TINYINT options
read only|updatable TODO use it
Definition: tds.h:943
cs_diag_msg
Definition: ctlib.h:69
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_dstr_len
static size_t tds_dstr_len(const DSTR *s)
Returns the length of the string in bytes.
Definition: string.h:85
tds_column::column_scale
TDS_TINYINT column_scale
scale for decimal/numeric
Definition: tds.h:705
TDS_DONE_ERROR
@ TDS_DONE_ERROR
error occurred
Definition: tds.h:254
tdsdaterec::decimicrosecond
TDS_INT decimicrosecond
0-9999999
Definition: tds.h:170
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
Holds informations about a cursor.
Definition: tds.h:938
conv_result
Definition: convert.h:34
_cs_param
Definition: ctlib.h:138
tdsdaterec::day
TDS_INT day
day of month (1-31)
Definition: tds.h:164
DBPROC_ROWBUF
Definition: dblib.h:52
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
tds_message
Definition: tds.h:877
_cs_datetime4
Definition: cstypes.h:153
_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:2277
tds_bcpinfo
Definition: tds.h:1659
_bcp_exec_in
static RETCODE _bcp_exec_in(DBPROCESS *dbproc, DBINT *rows_copied)
Definition: bcp.c:1435
tds_login
Definition: tds.h:518
tds_dblib_dbprocess
Definition: dblib.h:123
_cs_context::query_timeout
int query_timeout
not used unless positive
Definition: ctlib.h:102
_bcp_read_hostfile
static STATUS _bcp_read_hostfile(DBPROCESS *dbproc, FILE *hostfile, int *row_error, bool skip)
Definition: bcp.c:1141
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
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:408
tds_dynamic::res_info
TDSPARAMINFO * res_info
query results
Definition: tds.h:1000
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:1171
dblib_buffer_row::row
DBINT row
row number
Definition: buffering.h:7
tds_column::column_cur_size
TDS_INT column_cur_size
size written in variable (ie: char, text, binary).
Definition: tds.h:737
tds_dstr
Structure to hold a string.
Definition: string.h:36
tds_column::char_conv
TDSICONV * char_conv
refers to previously allocated iconv information
Definition: tds.h:713
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:702
_cs_context::login_timeout
int login_timeout
not used unless positive
Definition: ctlib.h:101
tdsdatetime
Definition: proto.h:50
cs_diag_msg_svr
Definition: ctlib.h:61
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
tdsdaterec::weekday
TDS_INT weekday
day of week (0-6, 0 = sunday)
Definition: tds.h:166
tds_bcpcoldata
Definition: tds.h:629
_cs_iodesc
Definition: cstypes.h:97
tds_write_dump
int tds_write_dump
Tell if TDS debug logging is turned on or off.
Definition: log.c:58
bcp_readfmt
RETCODE bcp_readfmt(DBPROCESS *dbproc, const char filename[])
Read a format definition file.
Definition: bcp.c:1679
tdsdaterec
Used by tds_datecrack.
Definition: tds.h:160
BCP_HOSTFILEINFO
Definition: dblib.h:74
tds_writetext_end
TDSRET tds_writetext_end(TDSSOCKET *tds)
Finish sending writetext data.
Definition: bulk.c:1188
tdsnumeric
Definition: proto.h:26
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:1133
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_locale
Definition: tds.h:583
tds_socket::ret_status
TDS_INT ret_status
return status from store procedure
Definition: tds.h:1251
tds_login::password
DSTR password
password of account login
Definition: tds.h:536
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:3122
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_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:1341
tds7_get_instance_ports
int tds7_get_instance_ports(FILE *output, struct addrinfo *addr)
Get port of all instances.
Definition: net.c:1093
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:762
tds_release_dynamic
void tds_release_dynamic(TDSDYNAMIC **pdyn)
Frees dynamic statement.
Definition: mem.c:253
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:2080
_cs_objname
Definition: cspublic.h:685
tds_dstr_dup
DSTR * tds_dstr_dup(DSTR *s, const DSTR *src)
Duplicate a string from another dynamic string.
Definition: tdsstring.c:134
tds_bcp_init
TDSRET tds_bcp_init(TDSSOCKET *tds, TDSBCPINFO *bcpinfo)
Initialize BCP information.
Definition: bulk.c:82
TDS_PENDING
@ TDS_PENDING
cilent is waiting for data
Definition: tds.h:794
_cs_blkdesc
Definition: ctlib.h:239
bcp_control
RETCODE bcp_control(DBPROCESS *dbproc, int field, DBINT value)
Set BCP options for uploading a datafile.
Definition: bcp.c:544
tds_column
Metadata about columns in regular and compute rows.
Definition: tds.h:690
_hdbc
Definition: odbc.h:275
bcp_exec
RETCODE bcp_exec(DBPROCESS *dbproc, DBINT *rows_copied)
Write a datafile to a table.
Definition: bcp.c:1618
tdsdaterec::hour
TDS_INT hour
0-23
Definition: tds.h:167
dbtypeinfo
Definition: sybdb.h:336
TDS_DEAD
@ TDS_DEAD
no connection
Definition: tds.h:796
tds_flush_packet
TDSRET tds_flush_packet(TDSSOCKET *tds)
Flush packet to server.
Definition: write.c:224
dblib_buffer_row::row_data
unsigned char * row_data
row data, NULL for resinfo->current_row
Definition: buffering.h:5
tds_connection
Definition: tds.h:1092
bcp_done
DBINT bcp_done(DBPROCESS *dbproc)
Conclude the transfer of data from program variables.
Definition: bcp.c:2038
tds_process_cancel
TDSRET tds_process_cancel(TDSSOCKET *tds)
Definition: token.c:2550
tds_login::user_name
DSTR user_name
account for login
Definition: tds.h:535
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
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
tdsdaterec::dayofyear
TDS_INT dayofyear
day of year (1-366)
Definition: tds.h:165
tds_column::column_type
TDS_SERVER_TYPE column_type
This type can be different from wire type because conversion (e.g.
Definition: tds.h:697
_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
_cs_clientmsg
Definition: cstypes.h:177
tds_lookup_host
struct addrinfo * tds_lookup_host(const char *servername)
Get the IP address for a hostname.
Definition: config.c:991
_bcp_readfmt_colinfo
static int _bcp_readfmt_colinfo(DBPROCESS *dbproc, char *buf, BCP_HOSTCOLINFO *ci)
Definition: bcp.c:1776
_bcp_fgets
static char * _bcp_fgets(char *buffer, int size, FILE *f)
Definition: bcp.c:1653
bcp_sendrow
RETCODE bcp_sendrow(DBPROCESS *dbproc)
Write data in host variables to the table.
Definition: bcp.c:1382
_cs_datetime
Definition: cstypes.h:147
_bcp_free_columns
static void _bcp_free_columns(DBPROCESS *dbproc)
Definition: bcp.c:2352
tds_cursor::status
TDS_CURSOR_STATUS status
cursor parameter
Definition: tds.h:954
dblib_buffer_row::sizes
TDS_INT * sizes
save old sizes
Definition: buffering.h:9
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_param_data
void * tds_alloc_param_data(TDSCOLUMN *curparam)
Allocate data for a parameter.
Definition: mem.c:364
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:337
tdsdump_close
void tdsdump_close(void)
Close the TDS dump log file.
Definition: log.c:193
tds_cursor_dealloc
TDSRET tds_cursor_dealloc(TDSSOCKET *tds, TDSCURSOR *cursor)
Send a deallocation request to server.
Definition: query.c:3006
tds_dstr_copy
DSTR * tds_dstr_copy(DSTR *s, const char *src)
copy a string from another
Definition: tdsstring.c:122
_cs_dynamic
Definition: ctlib.h:176
LOGINREC
Definition: bsqlodbc.c:100