1 #define LIMIT_INDEXES_ADJUST 4
3 static const signed char limit_indexes[79]= {
85 static const TDS_WORD limits[]= {
size_t tds_quote_string(TDSSOCKET *tds, char *buffer, const char *str, int len)
Quote a string.
Definition: query.c:2241
TDSLOCALE * tds_get_locale(void)
Get locale information.
Definition: locale.c:50
Holds information for a dynamic (also called prepared) query.
Definition: tds.h:977
void tdsdump_off(TDSDUMP_OFF_ITEM *off_item)
Temporarily turn off logging for current thread.
Definition: log.c:81
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
bool bulk_query
true is query sent was a bulk query so we need to switch state to QUERYING
Definition: tds.h:1244
void tds_start_query(TDSSOCKET *tds, unsigned char packet_type)
Start query packet of a given type.
Definition: query.c:332
tds_func_put_data * put_data
Send column data to server.
Definition: tds.h:662
static void tds_dstr_init(DSTR *s)
init a string with empty
Definition: string.h:53
static void tds7_put_query_params(TDSSOCKET *tds, const char *query, size_t query_len)
Output params types and query (required by sp_prepare/sp_executesql/sp_prepexec)
Definition: query.c:1064
TDSRET tds_submit_unprepare(TDSSOCKET *tds, TDSDYNAMIC *dyn)
Send a unprepare request for a prepared query.
Definition: query.c:1797
static const char * tds_next_placeholder_ucs2le(const char *start, const char *end, int named)
Found the next placeholder (? or @param) in a string.
Definition: query.c:644
TDS_INT quarter
quarter (0-3)
Definition: tds.h:161
TDSPACKET * frozen_packets
list of packets frozen, points to first one.
Definition: tds.h:1203
char * charset
character set encoding
Definition: tds.h:968
Used by tds_datecrack.
Definition: tds.h:159
bool defer_close
true if dynamic was marker to be closed when connection is idle
Definition: tds.h:997
#define tds_dstr_empty(s)
Make a string empty.
Definition: string.h:91
char * left
buffer for store bytes readed that could be the terminator
Definition: bulk.c:1015
TDS_INT cursor_rows
< number of updatable columns
Definition: tds.h:951
TDSRET tds_deferred_cursor_dealloc(TDSCONNECTION *conn, TDSCURSOR *cursor)
Deallocate cursor on idle.
Definition: query.c:3057
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_STATE tds_set_state(TDSSOCKET *tds, TDS_STATE state)
Set state of TDS connection, with logging and checking.
Definition: util.c:58
int tm_min
minutes (0-59)
Definition: convert.c:60
static TDSRET tds_put_data_info(TDSSOCKET *tds, TDSCOLUMN *curcol, int flags)
Put data information to wire.
Definition: query.c:1533
TDS_CURSOR_STATUS status
cursor parameter
Definition: tds.h:953
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
int tds_iconv_alloc(TDSCONNECTION *conn)
Allocate iconv stuff.
Definition: iconv.c:307
char * buffer
write buffer.
Definition: stream.h:50
static const char * tds_dstr_cstr(const DSTR *s)
Returns a C version (NUL terminated string) of dstr.
Definition: string.h:78
FILE * f
file to read from
Definition: bulk.c:1007
int tm_ns
nanoseconds (0-999999999)
Definition: convert.c:62
TDSCURSOR * cursors
linked list of cursors allocated for this connection contains only cursors allocated on the server
Definition: tds.h:1107
bool has_status
true is ret_status is valid
Definition: tds.h:1245
@ TDS_DONE_COUNT
count field in packet is valid
Definition: tds.h:256
DSTR password
password of account login
Definition: tds.h:535
TDS_INT decimicrosecond
0-9999999
Definition: tds.h:169
const char * tds_prtype(int type)
Returns string representation of the given type.
Definition: token.c:3056
unsigned in_pos
current position in in_buf
Definition: tds.h:1192
TDS_INT date
date, 0 = 1900-01-01
Definition: tds.h:148
size_t tds_freeze_written(TDSFREEZE *freeze)
Compute how many bytes has been written from freeze.
Definition: packet.c:935
TDSICONV * tds_iconv_from_collate(TDSCONNECTION *conn, TDS_UCHAR collate[5])
Get iconv information from a LCID (to support different column encoding under MSSQL2K)
Definition: iconv.c:1245
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:2992
static void tds_swap_numeric(TDS_NUMERIC *num)
Converts numeric from Microsoft representation to internal one (Sybase).
Definition: data.c:1674
Main include file for libtds.
char * pb
buffer
Definition: bulk.c:61
static int tds_socket_read(TDSCONNECTION *conn, TDSSOCKET *tds, unsigned char *buf, int buflen)
Read from an OS socket @TODO remove tds, save error somewhere, report error in another way.
Definition: net.c:727
TDSENV env
environment is shared between all sessions
Definition: tds.h:1101
int(* read)(struct tds_input_stream *stream, void *ptr, size_t len)
read some data Return 0 if end of stream Return <0 if error (actually not defined)
Definition: stream.h:35
TDS_INT day
day of month (1-31)
Definition: tds.h:163
bool tds_read_conf_section(FILE *in, const char *section, TDSCONFPARSE tds_conf_parse, void *param)
Read a section of configuration file (INI style file)
Definition: config.c:503
static int tds_dstr_isempty(const DSTR *s)
test if string is empty
Definition: string.h:60
static TDSRET tds7_write_param_def_from_query(TDSSOCKET *tds, const char *converted_query, size_t converted_query_len, TDSPARAMINFO *params) TDS_WUR
Write string with parameters definition, useful for TDS7+.
Definition: query.c:903
static int tds_get_socket_error(TDS_SYS_SOCKET sock)
Returns error stored in the socket.
Definition: net.c:217
input stream to read data from a static buffer
Definition: stream.h:81
TDSRET tds_bcp_done(TDSSOCKET *tds, int *rows_copied)
Tell we finished sending BCP data to server.
Definition: bulk.c:836
TDSLOGIN * login
config for login stuff.
Definition: tds.h:1258
int tds7_get_instance_ports(FILE *output, struct addrinfo *addr)
Get port of all instances.
Definition: net.c:1093
TDSRET tds_generic_put(TDSSOCKET *tds, TDSCOLUMN *curcol, int bcp7)
Write data to wire.
Definition: data.c:919
unsigned char canonic
internal numeric index into array of all encodings
Definition: tds.h:624
Holds informations about a cursor.
Definition: tds.h:937
unsigned char * out_buf
Output buffer.
Definition: tds.h:1185
TDSINSTREAM stream
common fields, must be the first field
Definition: bulk.c:1005
int tds_socket_set_nonblocking(TDS_SYS_SOCKET sock)
Set socket to non-blocking.
Definition: net.c:168
TDSLOGIN * tds_init_login(TDSLOGIN *login, TDSLOCALE *locale)
Initialize login structure with locale information and other stuff for connection.
Definition: mem.c:800
TDSRET tds_freeze_abort(TDSFREEZE *freeze)
Discard all data written after the freeze.
Definition: packet.c:961
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
void tds_set_cur_dyn(TDSSOCKET *tds, TDSDYNAMIC *dyn)
Set current dynamic.
Definition: query.c:192
TDS_UINT product_version
version of product (Sybase/MS and full version)
Definition: tds.h:1093
int tds_socket_set_nosigpipe(TDS_SYS_SOCKET sock, int on)
Set socket to not throw SIGPIPE.
Definition: net.c:72
TDS_INT cursor_id
cursor id returned by the server after cursor declare
Definition: tds.h:941
TDSDYNAMIC * tds_alloc_dynamic(TDSCONNECTION *conn, const char *id)
Allocate a dynamic statement.
Definition: mem.c:160
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:1891
TDSRET tds_freeze_close_len(TDSFREEZE *freeze, int32_t size)
Stop keeping data for this specific freeze.
Definition: packet.c:1031
void tds_set_column_type(TDSCONNECTION *conn, TDSCOLUMN *curcol, TDS_SERVER_TYPE type)
Set type of column initializing all dependency.
Definition: data.c:224
static TDSRET tds7_send_execute(TDSSOCKET *tds, TDSDYNAMIC *dyn)
Send dynamic request on TDS 7+ to be executed.
Definition: query.c:1593
struct tds_blob TDSBLOB
Information about blobs (e.g.
TDS_INT weekday
day of week (0-6, 0 = sunday)
Definition: tds.h:165
TDS_INT8 rows_affected
rows updated/deleted/inserted/selected, TDS_NO_COUNT if not valid
Definition: tds.h:1254
TDSPACKET * send_packet
packet we are preparing to send
Definition: tds.h:1231
static TDSRET tds_start_query_head(TDSSOCKET *tds, unsigned char packet_type, TDSHEADERS *head)
Start query packet of a given type.
Definition: query.c:291
TDS_TINYINT column_prec
precision for decimal/numeric
Definition: tds.h:703
unsigned char * in_buf
Input buffer.
Definition: tds.h:1177
TDSCURSOR * cur_cursor
cursor in use
Definition: tds.h:1243
void tds_close_socket(TDSSOCKET *tds)
Close current socket.
Definition: net.c:548
static const char * parse_numeric(const char *buf, const char *pend, bool *p_negative, size_t *p_digits, size_t *p_decimals)
Parse a string for numbers.
Definition: convert.c:3435
const char * tds_skip_quoted(const char *s)
Skip quoting string (like 'sfsf', "dflkdj" or [dfkjd])
Definition: query.c:515
TDSDYNAMIC * dyns
list of dynamic allocated for this connection contains only dynamic allocated on the server
Definition: tds.h:1112
TDSRET tds_alloc_row(TDSRESULTINFO *res_info)
Allocate space for row store return NULL on out of memory.
Definition: mem.c:524
int tds_goodread(TDSSOCKET *tds, unsigned char *buf, int buflen)
Loops until we have received some characters return -1 on failure.
Definition: net.c:916
int tm_mon
month (0-11)
Definition: convert.c:57
unsigned data_len
data length, this does not account SMP header, only TDS part
Definition: tds.h:1071
static TDS_INT binary_to_result(int desttype, const void *data, size_t len, CONV_RESULT *cr)
Copy binary data to to result and return len or TDS_CONVERT_NOMEM.
Definition: convert.c:196
TDSRET tds_cursor_dealloc(TDSSOCKET *tds, TDSCURSOR *cursor)
Send a deallocation request to server.
Definition: query.c:3006
bool in_row
true if we are getting rows
Definition: tds.h:1246
TDSICONV * tds_iconv_get_info(TDSCONNECTION *conn, int canonic_client, int canonic_server)
Get a iconv info structure, allocate and initialize if needed.
Definition: iconv.c:758
DSTR server_realm_name
server realm name (in freetds.conf)
Definition: tds.h:527
Provide poll call where missing.
void tds_datain_stream_init(TDSDATAINSTREAM *stream, TDSSOCKET *tds, size_t wire_size)
Initialize a data input stream.
Definition: stream.c:204
static int tds_count_placeholders_ucs2le(const char *query, const char *query_end)
Count the number of placeholders ('?') in a query.
Definition: query.c:692
static char * tds_get_dynid(TDSCONNECTION *conn, char *id)
Get an id for dynamic query based on TDS information.
Definition: mem.c:94
Definition: challenge.c:564
TDS_TINYINT emulated
this dynamic query cannot be prepared so libTDS have to construct a simple query.
Definition: tds.h:993
input stream to read data from tds protocol
Definition: stream.h:63
TDSRET tds_generic_get(TDSSOCKET *tds, TDSCOLUMN *curcol)
Read a data from wire.
Definition: data.c:713
const char * tds_canonical_charset_name(const char *charset_name)
Determine canonical iconv character set name.
Definition: iconv.c:982
bool tds_set_server(TDSLOGIN *tds_login, const char *server) TDS_WUR
Set the servername in a TDSLOGIN structure.
Definition: login.c:129
TDSRET tds_process_simple_query(TDSSOCKET *tds)
Process results for simple query as "SET TEXTSIZE" or "USE dbname" If the statement returns results,...
Definition: token.c:881
static TDSRET tds_answer_challenge(TDSSOCKET *tds, TDSLOGIN *login, const unsigned char *challenge, uint32_t *flags, const unsigned char *names_blob, int names_blob_len, TDSANSWER *answer, unsigned char **ntlm_v2_response)
Crypt a given password using schema required for NTLMv1 or NTLM2 authentication.
Definition: challenge.c:291
static TDSRET tds_send_emulated_execute(TDSSOCKET *tds, const char *query, TDSPARAMINFO *params)
Emulate prepared execute traslating to a normal language.
Definition: query.c:3269
tds_func_put_info * put_info
Send metadata column information to server.
Definition: tds.h:652
TDSRET tds_submit_queryf(TDSSOCKET *tds, const char *queryf,...)
Format and submit a query.
Definition: query.c:467
int tds_get_varint_size(TDSCONNECTION *conn, int datatype)
tds_get_varint_size() returns the size of a variable length integer returned in a result string
Definition: tds_types.h:57
TDSPARAMINFO * params
query parameters.
Definition: tds.h:1007
static TDSRET tds_bcp_start_insert_stmt(TDSSOCKET *tds, TDSBCPINFO *bcpinfo)
Prepare the query to be sent to server to request BCP information.
Definition: bulk.c:266
DSTR * tds_dstr_dup(DSTR *s, const DSTR *src)
Duplicate a string from another dynamic string.
Definition: tdsstring.c:134
TDSRET tds_submit_begin_tran(TDSSOCKET *tds)
Send a rollback request.
Definition: query.c:3665
int(* write)(struct tds_output_stream *stream, size_t len)
write len bytes from buffer, return <0 if error or len
Definition: stream.h:41
Store variant informations.
Definition: tds.h:604
TDS_INT type
row fetched from this cursor
Definition: tds.h:956
TDS_INT dayofyear
day of year (1-366)
Definition: tds.h:164
TDSDYNAMIC * tds_lookup_dynamic(TDSCONNECTION *conn, const char *id)
Finds a dynamic given string id.
Definition: token.c:2587
TDS_SERVER_TYPE tds_get_null_type(TDS_SERVER_TYPE srctype)
Get same type but nullable.
Definition: convert.c:2926
size_t tds_quote_id_rpc(TDSSOCKET *tds, char *buffer, const char *id, int idlen)
Quote an id for a RPC call.
Definition: query.c:2216
static TDSRET tds4_send_emulated_rpc(TDSSOCKET *tds, const char *rpc_name, TDSPARAMINFO *params)
Send RPC as string query.
Definition: query.c:1873
define a stream of data used for input
Definition: stream.h:30
DSTR * tds_dstr_setlen(DSTR *s, size_t length)
limit length of string, MUST be <= current length
Definition: tdsstring.c:145
DSTR db_filename
database filename to attach (MSSQL)
Definition: tds.h:529
TDS 7.2 SMP packet header.
Definition: proto.h:361
static TDS_INT string_to_int8(const char *buf, const char *pend, TDS_INT8 *res)
convert a number in string to TDS_INT8
Definition: convert.c:3368
DSTR * tds_dstr_set(DSTR *s, char *src)
set a string from another buffer.
Definition: tdsstring.c:107
struct tds_pbcb TDSPBCB
Holds clause buffer.
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
char * query
SQL query.
Definition: tds.h:947
static void unix_to_nt_time(uint64_t *nt, struct timeval *tv)
put a 8 byte filetime from a time_t This takes GMT as input
Definition: challenge.c:586
Metadata about columns in regular and compute rows.
Definition: tds.h:689
static TDSRET tds7_bcp_send_colmetadata(TDSSOCKET *tds, TDSBCPINFO *bcpinfo)
Send BCP metadata to server.
Definition: bulk.c:736
struct tds_cursor * next
next in linked list, keep first
Definition: tds.h:938
TDSRET tds71_submit_prepexec(TDSSOCKET *tds, const char *query, const char *id, TDSDYNAMIC **dyn_out, TDSPARAMINFO *params)
Creates a temporary stored procedure in the server and execute it.
Definition: query.c:1401
TDS_INT ref_count
reference counter so client can retain safely a pointer
Definition: tds.h:939
size_t wire_size
bytes still to read
Definition: stream.h:65
static TDSRET tds5_put_params(TDSSOCKET *tds, TDSPARAMINFO *info, int flags) TDS_WUR
Send parameters to server.
Definition: query.c:1693
unsigned char tds_get_byte(TDSSOCKET *tds)
Return a single byte from the input buffer.
Definition: read.c:72
static int tds_socket_write(TDSCONNECTION *conn, TDSSOCKET *tds, const unsigned char *buf, int buflen)
Write to an OS socket.
Definition: net.c:762
static int tds5_bcp_add_fixed_columns(TDSBCPINFO *bcpinfo, tds_bcp_get_col_data get_col_data, tds_bcp_null_error null_error, int offset, unsigned char *rowbuffer, int start)
Add fixed size columns to the row.
Definition: bulk.c:507
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
DSTR * tds_dstr_get(TDSSOCKET *tds, DSTR *s, size_t len)
Reads a string from wire and put in a DSTR.
Definition: read.c:293
const char * tds_skip_comment(const char *s)
Skip a comment in a query.
Definition: query.c:490
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_SYS_SOCKET s
tcp socket, INVALID_SOCKET if not connected
Definition: tds.h:1096
int tm_sec
seconds (0-59)
Definition: convert.c:61
static TDSRET tds_put_param_as_string(TDSSOCKET *tds, TDSPARAMINFO *params, int n)
Send a parameter to server.
Definition: query.c:3189
const char * tds_next_placeholder(const char *start)
Get position of next placeholder.
Definition: query.c:535
unsigned char out_flag
output buffer type
Definition: tds.h:1196
int tds_goodwrite(TDSSOCKET *tds, const unsigned char *buffer, size_t buflen)
Definition: net.c:987
struct tds_dynamic * next
next in linked list, keep first
Definition: tds.h:978
volatile unsigned char in_cancel
indicate we are waiting a cancel reply; discard tokens till acknowledge; 1 mean we have to send cance...
Definition: tds.h:1248
static int string_to_numeric(const char *instr, const char *pend, CONV_RESULT *cr)
convert a number in string to a TDSNUMERIC
Definition: convert.c:2279
size_t tds_get_string(TDSSOCKET *tds, size_t string_len, char *dest, size_t dest_size)
Fetch a string from the wire.
Definition: read.c:166
TDSRET tds_datecrack(TDS_INT datetype, const void *di, TDSDATEREC *dr)
Convert from db date format to a structured date format.
Definition: convert.c:3172
bool defer_close
true if cursor was marker to be closed when connection is idle
Definition: tds.h:946
TDS_INT ref_count
reference counter so client can retain safely a pointer
Definition: tds.h:979
const char * terminator
terminator
Definition: bulk.c:1010
TDSRET tds_submit_query(TDSSOCKET *tds, const char *query)
Sends a language string to the database server for processing.
Definition: query.c:210
@ TDS_SENDING
client would send data
Definition: tds.h:792
Information about blobs (e.g.
Definition: tds.h:593
TDSRET tds_process_login_tokens(TDSSOCKET *tds)
tds_process_login_tokens() is called after sending the login packet to the server.
Definition: token.c:411
unsigned int bulk_copy
if bulk copy should be enabled
Definition: tds.h:556
static TDSRET tds_put_data(TDSSOCKET *tds, TDSCOLUMN *curcol)
Write data to wire.
Definition: query.c:279
DSTR new_password
new password to set (TDS 7.2+)
Definition: tds.h:536
TDSRET tds_dynamic_stream_init(TDSDYNAMICSTREAM *stream, void **ptr, size_t allocated)
Initialize a dynamic output stream.
Definition: stream.c:354
int tds_read_packet(TDSSOCKET *tds)
Read in one 'packet' from the server.
Definition: packet.c:527
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
output stream to write data to a dynamic buffer
Definition: stream.h:99
Structure to hold a string.
Definition: string.h:36
TDS_USMALLINT tds_version
TDS version.
Definition: tds.h:520
static char * tds5_fix_dot_query(const char *query, size_t *query_len, TDSPARAMINFO *params)
Substitute ?-style placeholders with named (@param) ones.
Definition: query.c:227
Hold information for any results.
Definition: tds.h:769
TDS_INT hour
0-23
Definition: tds.h:166
TDSPARAMINFO * tds_alloc_param_result(TDSPARAMINFO *old_param)
Adds a output parameter to TDSPARAMINFO.
Definition: mem.c:284
TDSDYNAMIC * cur_dyn
dynamic structure in use
Definition: tds.h:1256
static int stringz_to_numeric(const char *instr, CONV_RESULT *cr)
convert a zero terminated string to NUMERIC
Definition: convert.c:2273
static TDSRET tds7_build_bulk_insert_stmt(TDSSOCKET *tds, TDSPBCB *clause, TDSCOLUMN *bcpcol, int first)
Help to build query to be sent to server.
Definition: bulk.c:219
static void tds_bcp_row_free(TDSRESULTINFO *result, unsigned char *row)
Free row data allocated in the result set.
Definition: bulk.c:904
TDSRESULTINFO * current_results
Current query information.
Definition: tds.h:1238
struct addrinfo * ip_addrs
ip(s) of server
Definition: tds.h:546
char * cursor_name
name of the cursor
Definition: tds.h:940
const char * tds_convert_string(TDSSOCKET *tds, TDSICONV *char_conv, const char *s, int len, size_t *out_len)
Convert a string in an allocated buffer.
Definition: query.c:126
TDS_INT month
month number (0-11)
Definition: tds.h:162
@ TDS_WRITING
client is writing data
Definition: tds.h:791
TDS_INT second
0-59
Definition: tds.h:168
void * tds_alloc_param_data(TDSCOLUMN *curparam)
Allocate data for a parameter.
Definition: mem.c:364
static bool tds_cursor_check_allocated(TDSCONNECTION *conn, TDSCURSOR *cursor)
Check if a cursor is allocated into the server.
Definition: query.c:2991
int tds_select(TDSSOCKET *tds, unsigned tds_sel, int timeout_seconds)
Select on a socket until it's available or the timeout expires.
Definition: net.c:612
#define TDS_PUT_N_AS_UCS2(tds, s)
Utility to convert a constant ascii string to ucs2 and send to server.
Definition: query.c:110
unsigned int from_malloc
true is buffer came from malloc
Definition: bulk.c:65
int tds_get_size_by_type(TDS_SERVER_TYPE servertype)
Return the number of bytes needed by specified type.
Definition: tds_types.h:9
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
static TDS_INT string_to_uint8(const char *buf, const char *pend, TDS_UINT8 *res)
convert a number in string to TDS_UINT8
Definition: convert.c:3397
TDSRET tds_submit_execute(TDSSOCKET *tds, TDSDYNAMIC *dyn)
Sends a previously prepared dynamic statement to the server.
Definition: query.c:1630
void tds_free_input_params(TDSDYNAMIC *dyn)
Frees all allocated input parameters of a dynamic statement.
Definition: mem.c:206
DSTR server_name
server name (in freetds.conf)
Definition: tds.h:518
unsigned in_len
input buffer length
Definition: tds.h:1194
unsigned out_pos
current position in out_buf
Definition: tds.h:1193
static TDSRET tds7_write_param_def_from_params(TDSSOCKET *tds, const char *query, size_t query_len, TDSPARAMINFO *params) TDS_WUR
Write string with parameters definition, useful for TDS7+.
Definition: query.c:964
TDS_INT column_size
maximun size of data.
Definition: tds.h:694
TDSAUTHENTICATION * tds_ntlm_get_auth(TDSSOCKET *tds)
Build a NTLMSPP packet to send to server.
Definition: challenge.c:721
DSTR * tds_dstr_alloc(DSTR *s, size_t length)
allocate space for length char
Definition: tdsstring.c:165
TDSRET tds_submit_execdirect(TDSSOCKET *tds, const char *query, TDSPARAMINFO *params, TDSHEADERS *head)
Submit a prepared query with parameters.
Definition: query.c:1256
TDS_INT ret_status
return status from store procedure
Definition: tds.h:1250
static TDS_INT parse_int8(const char *buf, const char *pend, TDS_UINT8 *res, bool *p_negative)
convert a number in string to TDS_INT8
Definition: convert.c:3338
TDSRET tds_copy_stream(TDSINSTREAM *istream, TDSOUTSTREAM *ostream)
Reads and writes from a stream to another.
Definition: stream.c:163
#define tds_put_tinyint(tds, ti)
Output a tinyint value.
Definition: tds.h:1469
TDS_INT timezone
-840 - 840 minutes from UTC
Definition: tds.h:170
TDSRET tds_convert_stream(TDSSOCKET *tds, TDSICONV *char_conv, TDS_ICONV_DIRECTION direction, TDSINSTREAM *istream, TDSOUTSTREAM *ostream)
Reads and writes from a stream converting characters.
Definition: stream.c:71
static int tds5_bcp_add_variable_columns(TDSBCPINFO *bcpinfo, tds_bcp_get_col_data get_col_data, tds_bcp_null_error null_error, int offset, TDS_UCHAR *rowbuffer, int start, int *pncols)
Add variable size columns to the row.
Definition: bulk.c:594
TDS_INT column_cur_size
size written in variable (ie: char, text, binary).
Definition: tds.h:736
char * query
saved query, we need to know original query if prepare is impossible
Definition: tds.h:1009
TDSICONV * char_conv
refers to previously allocated iconv information
Definition: tds.h:712
TDS_TINYINT column_varint_size
size of length when reading from wire (0, 1, 2 or 4)
Definition: tds.h:701
unsigned int cb
buffer length
Definition: bulk.c:63
int tds_needs_unprepare(TDSCONNECTION *conn, TDSDYNAMIC *dyn)
Check if dynamic request must be unprepared.
Definition: query.c:1752
TDSRET tds_submit_rollback(TDSSOCKET *tds, int cont)
Send a rollback request.
Definition: query.c:3693
input stream to read a file
Definition: bulk.c:1003
void tds_staticin_stream_init(TDSSTATICINSTREAM *stream, const void *ptr, size_t len)
Initialize an input stream for read from a static allocated buffer.
Definition: stream.c:286
int tdsdump_open(const char *filename)
Create and truncate a human readable dump file for the TDS traffic.
Definition: log.c:131
size_t tds_fix_column_size(TDSSOCKET *tds, TDSCOLUMN *curcol)
Get column size for wire.
Definition: query.c:1491
#define TDS_IS_MSSQL(x)
Check if product is Microsft SQL Server.
Definition: tds.h:1722
static TDS_INT string_to_result(int desttype, const char *s, CONV_RESULT *cr)
Copy a terminated string to result and return len or TDS_CONVERT_NOMEM.
Definition: convert.c:178
TDSRET tds_get_char_data(TDSSOCKET *tds, char *row_buffer, size_t wire_size, TDSCOLUMN *curcol)
Fetch character data the wire.
Definition: read.c:195
void tds_dstr_free(DSTR *s)
free string
Definition: tdsstring.c:62
TDS_INT year
year
Definition: tds.h:160
TDSRET tds_bcp_init(TDSSOCKET *tds, TDSBCPINFO *bcpinfo)
Initialize BCP information.
Definition: bulk.c:84
DSTR * tds_dstr_copy(DSTR *s, const char *src)
copy a string from another
Definition: tdsstring.c:122
int tds_put_string(TDSSOCKET *tds, const char *s, int len)
Output a string to wire automatic translate string to unicode if needed.
Definition: write.c:97
int tdserror(const TDSCONTEXT *tds_ctx, TDSSOCKET *tds, int msgno, int errnum)
Call the client library's error handler (for library-generated errors only)
Definition: util.c:321
int tm_year
year (0=1900)
Definition: convert.c:56
size_t tds_quote_id(TDSSOCKET *tds, char *buffer, const char *id, int idlen)
Quote an id.
Definition: query.c:2171
int port
port of database service
Definition: tds.h:519
void * tds_realloc(void **pp, size_t new_size)
Reallocate a pointer and update it if success.
Definition: mem.c:1876
void tdsdump_dump_buf(const char *file, unsigned int level_line, const char *msg, const void *buf, size_t length)
Dump the contents of data into the log file in a human readable format.
Definition: log.c:293
TDS_TINYINT column_scale
scale for decimal/numeric
Definition: tds.h:704
TDSPARAMINFO * res_info
query results
Definition: tds.h:999
DSTR user_name
account for login
Definition: tds.h:534
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
no connection
Definition: tds.h:795
static int tds_file_stream_read(TDSINSTREAM *stream, void *ptr, size_t len)
Reads a chunk of data from file stream checking for terminator.
Definition: bulk.c:1047
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_SMALLINT offset
time offset
Definition: tds.h:149
void tds_release_dynamic(TDSDYNAMIC **pdyn)
Frees dynamic statement.
Definition: mem.c:253
char * database
database name
Definition: tds.h:970
DSTR crlfile
certificate revocation file
Definition: tds.h:531
TDS_UINT8 time
time, 7 digit precision
Definition: tds.h:147
static size_t tds_quote(TDSSOCKET *tds, char *buffer, char quoting, const char *id, size_t len)
Quote a string properly.
Definition: query.c:2128
Definition: challenge.c:72
TDSRET tds_writetext_end(TDSSOCKET *tds)
Finish sending writetext data.
Definition: bulk.c:1202
char id[30]
id of dynamic.
Definition: tds.h:987
static void tds_set_cur_cursor(TDSSOCKET *tds, TDSCURSOR *cursor)
Set current cursor.
Definition: query.c:2253
this structure is not directed connected to a TDS protocol but keeps any DATE/TIME information.
Definition: tds.h:146
TDSRET tds_bcp_start(TDSSOCKET *tds, TDSBCPINFO *bcpinfo)
Start sending BCP data to server.
Definition: bulk.c:866
unsigned int pending_close
true is connection has pending closing (cursors or dynamic)
Definition: tds.h:1123
bool tds_get_n(TDSSOCKET *tds, void *dest, size_t need)
Get N bytes from the buffer and return them in the already allocated space given to us.
Definition: read.c:230
int tm_mday
month day (1-31)
Definition: convert.c:58
static const char * tds_skip_quoted_ucs2le(const char *s, const char *end)
Return pointer to end of a quoted string.
Definition: query.c:618
Holds clause buffer.
Definition: bulk.c:59
struct tds_file_stream TDSFILESTREAM
input stream to read a file
@ TDS_IDLE
no data expected
Definition: tds.h:790
static size_t tds_dstr_len(const DSTR *s)
Returns the length of the string in bytes.
Definition: string.h:85
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
Information for a server connection.
Definition: tds.h:1163
#define DSTR_INITIALIZER
Initializer, used to initialize string like in the following example.
Definition: string.h:49
int tds_count_placeholders(const char *query)
Count the number of placeholders ('?') in a query.
Definition: query.c:571
unsigned char in_flag
input buffer type
Definition: tds.h:1195
DSTR server_spn
server SPN (in freetds.conf)
Definition: tds.h:528
void tdsdump_on(TDSDUMP_OFF_ITEM *off_item)
Turn logging back on for current thread.
Definition: log.c:101
static TDSERRNO tds_setup_socket(TDS_SYS_SOCKET *p_sock, struct addrinfo *addr, unsigned int port, int *p_oserr)
Setup the socket and attempt a connection.
Definition: net.c:249
TDS_INT minute
0-59
Definition: tds.h:167
int tds7_get_instance_port(struct addrinfo *addr, const char *instance)
Get port of given instance.
Definition: net.c:1229
static TDSRET tds_query_flush_packet(TDSSOCKET *tds)
Flush query packet.
Definition: query.c:178
#define TDS_SYB_VER(maj, min, x)
Calc a version number for Sybase.
Definition: tds.h:1731
TDSRET tds_submit_rpc(TDSSOCKET *tds, const char *rpc_name, TDSPARAMINFO *params, TDSHEADERS *head)
Calls a RPC from server.
Definition: query.c:1929
unsigned int out_buf_max
Maximum size of packet pointed by out_buf.
Definition: tds.h:1191
@ TDS_DONE_ERROR
error occurred
Definition: tds.h:253
TDSRET tds_flush_packet(TDSSOCKET *tds)
Flush packet to server.
Definition: write.c:224
TDSRET tds_get_column_declaration(TDSSOCKET *tds, TDSCOLUMN *curcol, char *out)
Return declaration for column (like "varchar(20)").
Definition: query.c:718
define a stream of data used for output
Definition: stream.h:39
TDSRET tds_freeze_close(TDSFREEZE *freeze)
Stop keeping data for this specific freeze.
Definition: packet.c:996
TDSRET tds_process_tokens(TDSSOCKET *tds, TDS_INT *result_type, int *done_flags, unsigned flag)
process all streams.
Definition: token.c:531
TDS_INT num_id
numeric id for mssql7+
Definition: tds.h:981
DSTR server_charset
charset of server e.g.
Definition: tds.h:523
TDSRET tds_submit_commit(TDSSOCKET *tds, int cont)
Send a commit request.
Definition: query.c:3724
void tds_freeze(TDSSOCKET *tds, TDSFREEZE *freeze, unsigned size_len)
Stop writing to server and cache every packet not sending them to server.
Definition: packet.c:907
Definition: challenge.c:65
@ TDS_PENDING
cilent is waiting for data
Definition: tds.h:793
int block_size
packet size (512-65535)
Definition: tds.h:965
TDS_SERVER_TYPE column_type
This type can be different from wire type because conversion (e.g.
Definition: tds.h:696
int tds_write_dump
Tell if TDS debug logging is turned on or off.
Definition: log.c:58
static int store_monthname(const char *, struct tds_time *)
Test if a string is a month name and store correct month number.
Definition: convert.c:2719
TDS_UINT tds_get_uint(TDSSOCKET *tds)
Get an int32 from the server.
Definition: read.c:127
TDS_USMALLINT tds_get_usmallint(TDSSOCKET *tds)
Get an int16 from the server.
Definition: read.c:113
TDSRET tds_deferred_unprepare(TDSCONNECTION *conn, TDSDYNAMIC *dyn)
Unprepare dynamic on idle.
Definition: query.c:1774
static TDSCOMPUTEINFO * tds_alloc_compute_result(TDS_USMALLINT num_cols, TDS_USMALLINT by_cols)
Allocate memory for storing compute info return NULL on out of memory.
Definition: mem.c:395
size_t size
size of data inside buffer
Definition: stream.h:106
size_t term_len
terminator length in bytes
Definition: bulk.c:1012
TDSRET tds_bcp_start_copy_in(TDSSOCKET *tds, TDSBCPINFO *bcpinfo)
Start bulk copy to server.
Definition: bulk.c:916
static const char * tds_skip_comment_ucs2le(const char *s, const char *end)
Skip a comment in a query.
Definition: query.c:589
DSTR cafile
certificate authorities file
Definition: tds.h:530
void tdsdump_close(void)
Close the TDS dump log file.
Definition: log.c:212
static TDS_INT string_to_int(const char *buf, const char *pend, TDS_INT *res)
convert a number in string to TDS_INT
Definition: convert.c:3299
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
TDSRET tds_generic_put_info(TDSSOCKET *tds, TDSCOLUMN *col)
Put data information to wire.
Definition: data.c:875
void tds_detach_results(TDSRESULTINFO *info)
Detach result info from it current socket.
Definition: mem.c:488
TDS_INT tds_numeric_to_string(const TDS_NUMERIC *numeric, char *s)
Definition: numeric.c:95
unsigned char tds_willconvert(int srctype, int desttype)
Test if a conversion is possible.
Definition: convert.c:3106
static char * tds_dstr_buf(DSTR *s)
Returns a buffer to edit the string.
Definition: string.h:71
void tds_free_param_result(TDSPARAMINFO *param_info)
Delete latest parameter.
Definition: mem.c:320
static void tds_quote_and_put(TDSSOCKET *tds, const char *s, const char *end)
Send a string to server while quoting it.
Definition: query.c:3079
void tds_dstr_zero(DSTR *s)
clear all string filling with zeroes (mainly for security reason)
Definition: tdsstring.c:55
void tdsdump_log(const char *file, unsigned int level_line, const char *fmt,...)
Write a message to the debug log.
Definition: log.c:396
void tdsdump_col(const TDSCOLUMN *col)
Write a column value to the debug log.
Definition: log.c:455
static size_t tds_ascii_to_ucs2(char *buffer, const char *buf)
Accept an ASCII string, convert it to UCS2-LE The input is NUL-terminated, but the output does not co...
Definition: query.c:91
int tm_hour
hours (0-23)
Definition: convert.c:59