#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#include "tdsver.h"
#include "tds_sysdep_public.h"
Go to the source code of this file.
Compounds | |
| struct | _tds_compiletime_settings |
| A structure to hold all the compile-time settings. More... | |
| struct | TDS8_COLLATION |
| hold information for collate in TDS8 More... | |
| union | tds_align_struct |
| struct | tds_answer |
| struct | tds_blob_info |
| structure that hold information about blobs (like text or image). More... | |
| struct | tds_column_info |
| structure for storing data about regular and compute rows More... | |
| struct | tds_connect_info |
| struct | tds_context |
| struct | tds_dynamic |
| struct | tds_env_info |
| struct | tds_locale |
| struct | tds_login |
| struct | tds_msg_info |
| union | tds_option_arg |
| struct | tds_result_info |
| Hold information for any results. More... | |
| struct | tds_socket |
| struct | tdsdaterec |
| information on data, used by tds_datecrack More... | |
| struct | tdsdatetime |
| struct | tdsdatetime4 |
| union | tdsmoney |
| struct | tdsmoney4 |
| struct | tdsnumeric |
| struct | tdsoldmoney |
| struct | tdsunique |
| struct | tdsvarbinary |
| struct | tdsvarchar |
Defines | |
| #define | TDS_IS_SYBASE(x) (!(x->product_version & 0x80000000u)) |
| Check if product is Sybase (such as Adaptive Server Enterrprice). | |
| #define | TDS_IS_MSSQL(x) ((x->product_version & 0x80000000u)!=0) |
| Check if product is Microsft SQL Server. | |
| #define | TDS_MS_VER(maj, min, x) (0x80000000u|((maj)<<24)|((min)<<16)|(x)) |
| Calc a version number for mssql. | |
| #define | TDS_SYB_VER(maj, min, x) (((maj)<<24)|((min)<<16)|(x)<<8) |
| Calc a version number for Sybase. | |
Typedefs | |
| typedef _tds_compiletime_settings | TDS_COMPILETIME_SETTINGS |
| A structure to hold all the compile-time settings. | |
| typedef tdsdaterec | TDSDATEREC |
| information on data, used by tds_datecrack | |
| typedef tds_blob_info | TDSBLOBINFO |
| structure that hold information about blobs (like text or image). | |
| typedef tds_column_info | TDSCOLINFO |
| structure for storing data about regular and compute rows | |
| typedef tds_result_info | TDSRESULTINFO |
| Hold information for any results. | |
Enumerations | |
| enum | TDS_OPTION_CMD |
| options that can be sent with a TDS_OPTIONCMD token | |
Functions | |
| int | tds_put_string (TDSSOCKET *tds, const char *buf, int len) |
| Output a string to wire automatic translate string to unicode if needed. | |
| const TDS_COMPILETIME_SETTINGS * | tds_get_compiletime_settings (void) |
| Return a structure capturing the compile-time settings provided to the configure script. | |
| int | tds_read_conf_section (FILE *in, const char *section, TDSCONFPARSE tds_conf_parse, void *parse_param) |
| Read a section of configuration file (INI style file). | |
| int | tds_read_conf_file (TDSCONNECTINFO *connect_info, const char *server) |
| Read configuration info for given server return 0 on error. | |
| TDSCONNECTINFO * | tds_read_config_info (TDSSOCKET *tds, TDSLOGIN *login, TDSLOCALE *locale) |
| tds_read_config_info() will fill the tds connect_info structure based on configuration information gathered in the following order: 1) Program specified in TDSLOGIN structure 2) The environment variables TDSVER, TDSDUMP, TDSPORT, TDSQUERY, TDSHOST 3) A config file with the following search order: a) a readable file specified by environment variable FREETDSCONF b) a readable file in ~/.freetds.conf c) a readable file in $prefix/etc/freetds.conf 3) ~/.interfaces if exists 4) $SYBASE/interfaces if exists 5) TDS_DEF_* default values | |
| void | tds_fix_connect (TDSCONNECTINFO *connect_info) |
| Fix configuration after reading it. | |
| void | tds_config_verstr (const char *tdsver, TDSCONNECTINFO *connect_info) |
| Set TDS version from given string. | |
| void | tds_lookup_host (const char *servername, const char *portname, char *ip, char *port) |
| Given a servername and port name or number, lookup the hostname and service. | |
| int | tds_set_interfaces_file_loc (char *interfloc) |
| Set the full name of interface file. | |
| TDSLOCALE * | tds_get_locale (void) |
| Get locale information. | |
| unsigned char * | tds_alloc_row (TDSRESULTINFO *res_info) |
| Allocate space for row store return NULL on out of memory. | |
| char * | tds_alloc_get_string (TDSSOCKET *tds, int len) |
| Read a string from wire in a new allocated buffer. | |
| TDSCONNECTINFO * | tds_alloc_connect (TDSLOCALE *locale) |
| Allocate space for configure structure and initialize with default values. | |
| int | tds_connect (TDSSOCKET *tds, TDSCONNECTINFO *connect_info) |
| Do a connection to socket. | |
| int | tds_submit_query (TDSSOCKET *tds, const char *query, TDSPARAMINFO *params) |
| tds_submit_query() sends a language string to the database server for processing. | |
| int | tds_process_result_tokens (TDSSOCKET *tds, TDS_INT *result_type) |
| process TDS result-type message streams. | |
| int | tds_process_row_tokens (TDSSOCKET *tds, TDS_INT *rowtype, TDS_INT *computeid) |
| process TDS row-type message streams. | |
| int | tds_process_default_tokens (TDSSOCKET *tds, int marker) |
| tds_process_default_tokens() is a catch all function that is called to process tokens not known to other tds_process_* routines | |
| int | tds_process_trailing_tokens (TDSSOCKET *tds) |
| tds_process_trailing_tokens() is called to discard messages that may be left unprocessed at the end of a result "batch". | |
| TDS_INT | tds_process_end (TDSSOCKET *tds, int marker, int *flags) |
| tds_process_end() processes any of the DONE, DONEPROC, or DONEINPROC tokens. | |
| int | tds_client_msg (TDSCONTEXT *tds_ctx, TDSSOCKET *tds, int msgnum, int level, int state, int line, const char *message) |
| tds_client_msg() sends a message to the client application from the CLI or TDS layer. | |
| void | tds_set_null (unsigned char *current_row, int column) |
| set the null bit for the given column in the row buffer | |
| void | tds_clr_null (unsigned char *current_row, int column) |
| clear the null bit for the given column in the row buffer | |
| int | tds_get_null (unsigned char *current_row, int column) |
| Return the null bit for the given column in the row buffer. | |
| unsigned char * | tds7_crypt_pass (const unsigned char *clear_pass, int len, unsigned char *crypt_pass) |
| tds7_crypt_pass() -- 'encrypt' TDS 7.0 style passwords. | |
| char * | tds7_ascii2unicode (TDSSOCKET *tds, const char *in_string, char *out_string, int maxlen) |
| convert a ascii string to ucs2. | |
| int | tds7_unicode2ascii (TDSSOCKET *tds, const char *in_string, int in_len, char *out_string, int out_len) |
| convert from ucs2 string to ascii. | |
| char * | tds_get_homedir (void) |
| Get user home directory. | |
| unsigned char * | tds_alloc_param_row (TDSPARAMINFO *info, TDSCOLINFO *curparam) |
| Add another field to row. | |
| int | tds_submit_prepare (TDSSOCKET *tds, const char *query, const char *id, TDSDYNAMIC **dyn_out) |
| tds_submit_prepare() creates a temporary stored procedure in the server. | |
| int | tds_submit_execute (TDSSOCKET *tds, TDSDYNAMIC *dyn) |
| tds_submit_execute() sends a previously prepared dynamic statement to the server. | |
| int | tds_send_cancel (TDSSOCKET *tds) |
| tds_send_cancel() sends an empty packet (8 byte header only) tds_process_cancel should be called directly after this. | |
| const char * | tds_next_placeholders (const char *start) |
| Get position of next placeholders. | |
| int | tds_count_placeholders (const char *query) |
| Count the number of placeholders in query. | |
| int | tds_get_dynid (TDSSOCKET *tds, char **id) |
| Get an id for dynamic query based on TDS information. | |
| int | tds_submit_unprepare (TDSSOCKET *tds, TDSDYNAMIC *dyn) |
| Send a unprepare request for a prepared query. | |
| int | tds_submit_rpc (TDSSOCKET *tds, const char *rpc_name, TDSPARAMINFO *params) |
| tds_submit_rpc() call a RPC from server. | |
| int | tds_quote_id (TDSSOCKET *tds, char *buffer, const char *id) |
| Quote an id. | |
| int | tds_quote_string (TDSSOCKET *tds, char *buffer, const char *str, int len) |
| Quote a string. | |
| int | tds_process_cancel (TDSSOCKET *tds) |
| tds_process_cancel() processes the incoming token stream until it finds an end token (DONE, DONEPROC, DONEINPROC) with the cancel flag set. | |
| int | tds_get_token_size (int marker) |
| tds_get_token_size() returns the size of a fixed length token used by tds_process_cancel() to determine how to read past a token | |
| int | tds_process_login_tokens (TDSSOCKET *tds) |
| tds_process_login_tokens() is called after sending the login packet to the server. | |
| void | tds_set_column_type (TDSCOLINFO *curcol, int type) |
| Set type of column initializing all dependency. | |
| void | tds_add_row_column_size (TDSRESULTINFO *info, TDSCOLINFO *curcol) |
| Add a column size to result info row size and calc offset into row. | |
| int | tds_process_simple_query (TDSSOCKET *tds, TDS_INT *result_type) |
| Process results for simple query as "SET TEXTSIZE" or "USE dbname" If the statement returns results, beware they are discarded. | |
| TDS_INT | tds_datecrack (TDS_INT datetype, const void *di, TDSDATEREC *dr) |
| Convert from db date format to a structured date format. | |
| int | tds_flush_packet (TDSSOCKET *tds) |
| Flush packet to server. | |
| TDS_SMALLINT | tds_get_smallint (TDSSOCKET *tds) |
| Get an int16 from the server. | |
| TDS_INT | tds_get_int (TDSSOCKET *tds) |
| Get an int32 from the server. | |
| int | tds_get_string (TDSSOCKET *tds, int string_len, char *dest, int need) |
| Fetch a string from the wire. | |
| void * | tds_get_n (TDSSOCKET *tds, void *dest, int n) |
| Get N bytes from the buffer and return them in the already allocated space given to us. | |
| int | tds_get_size_by_type (int servertype) |
| Return the number of bytes needed by specified type. | |
| int | tds_read_packet (TDSSOCKET *tds) |
| Read in one 'packet' from the server. | |
| int | tds_version (TDSSOCKET *tds_socket, char *pversion_string) |
| Returns the version of the TDS protocol in effect for the link as a decimal integer. | |
| void | tds_answer_challenge (const char *passwd, const unsigned char *challenge, TDSANSWER *answer) |
| Crypt a given password using schema required for NTLMv1 authentication. | |
Variables | |
| 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 store the specified precision. | |
|
|
Value: (x==TDS_DONE_TOKEN || \
x==TDS_DONEPROC_TOKEN || \
x==TDS_DONEINPROC_TOKEN) |
|
|
Value: (x==SYBINT1 || \
x==SYBINT2 || \
x==SYBINT4 || \
x==SYBINT8 || \
x==SYBREAL || \
x==SYBFLT8 || \
x==SYBDATETIME || \
x==SYBDATETIME4 || \
x==SYBBIT || \
x==SYBMONEY || \
x==SYBMONEY4 || \
x==SYBUNIQUE) |
|
|
Value: (x==TDS_DONE_TOKEN || \
x==TDS_DONEPROC_TOKEN) |
|
|
Value: (x==TDS_INFO_TOKEN || \
x==TDS_ERROR_TOKEN || \
x==TDS_EED_TOKEN) |
|
|
Value: (x==SYBINTN || \
x==SYBFLTN || \
x==SYBDATETIMN || \
x==SYBVARCHAR || \
x==SYBVARBINARY || \
x==SYBMONEYN || \
x==SYBTEXT || \
x==SYBNTEXT || \
x==SYBBITN || \
x==SYBIMAGE) |
|
|
Value: (x==TDS_RESULT_TOKEN || \
x==TDS_ROWFMT2_TOKEN || \
x==TDS7_RESULT_TOKEN || \
x==TDS_COLFMT_TOKEN || \
x==TDS_COLNAME_TOKEN) |
|
|
Value: (((((unsigned short)value)<<8) & 0xFF00) | \ ((((unsigned short)value)>>8) & 0x00FF)) |
|
|
Value: (((((unsigned long)value)<<24) & 0xFF000000) | \ ((((unsigned long)value)<< 8) & 0x00FF0000) | \ ((((unsigned long)value)>> 8) & 0x0000FF00) | \ ((((unsigned long)value)>>24) & 0x000000FF)) |
|
|
Check if product is Microsft SQL Server. x should be a TDS_SOCKET*. |
|
|
Check if product is Sybase (such as Adaptive Server Enterrprice). x should be a TDS_SOCKET*. |
|
|
Calc a version number for mssql. Use with TDS_MS_VER(7,0,842). For test for a range of version you can use check like if (tds->product_version >= TDS_MS_VER(7,0,0) && tds->product_version < TDS_MS_VER(8,0,0)) |
|
|
A structure to hold all the compile-time settings. This structure is returned by tds_get_compiletime_settings |
|
|
structure that hold information about blobs (like text or image). current_row contain this structure. |
|
||||||||||||||||||||
|
convert a ascii string to ucs2. Note: output string is not terminated
|
|
||||||||||||||||
|
tds7_crypt_pass() -- 'encrypt' TDS 7.0 style passwords. the calling function is responsible for ensuring crypt_pass is at least 'len' characters |
|
||||||||||||||||||||||||
|
convert from ucs2 string to ascii.
|
|
||||||||||||
|
Add a column size to result info row size and calc offset into row.
|
|
|
Allocate space for configure structure and initialize with default values.
|
|
||||||||||||
|
Read a string from wire in a new allocated buffer.
|
|
||||||||||||
|
Add another field to row. Is assumed that last TDSCOLINFO contain information about this. Update also info structure.
|
|
||||||||||||||||
|
Crypt a given password using schema required for NTLMv1 authentication.
|
|
||||||||||||||||||||||||||||||||
|
tds_client_msg() sends a message to the client application from the CLI or TDS layer. A client message is one that is generated from with the library and not from the server. The message is sent to the CLI (the err_handler) so that it may forward it to the client application or discard it if no msg handler has been by the application. tds->parent contains a void pointer to the parent of the tds socket. This can be cast back into DBPROCESS or CS_CONNECTION by the CLI and used to determine the proper recipient function for this message. |
|
||||||||||||
|
Set TDS version from given string.
|
|
||||||||||||
|
Do a connection to socket.
|
|
||||||||||||||||
|
Convert from db date format to a structured date format.
|
|
|
Fix configuration after reading it. Currently this read some environment variables and replace some options. |
|
|
Flush packet to server.
|
|
||||||||||||
|
Get an id for dynamic query based on TDS information.
|
|
|
Get user home directory.
|
|
|
Get locale information.
|
|
||||||||||||||||
|
Get N bytes from the buffer and return them in the already allocated space given to us. We ASSUME that the person calling this function has done the bounds checking for us since they know how many bytes they want here. dest of NULL means we just want to eat the bytes. (tetherow@nol.org) |
|
||||||||||||||||||||
|
Fetch a string from the wire. Output string is NOT null terminated. If TDS version is 7 or 8 read unicode string and convert it.
|
|
||||||||||||||||||||
|
Given a servername and port name or number, lookup the hostname and service. The server ip will be stored in the string 'servername' in dotted-decimal notation. The service port number will be stored in string form in the 'port' parameter. If we can't determine both the IP address and port number then 'ip' and 'port' will be set to empty strings. |
|
|
Get position of next placeholders.
|
|
|
tds_process_cancel() processes the incoming token stream until it finds an end token (DONE, DONEPROC, DONEINPROC) with the cancel flag set. a that point the connetion should be ready to handle a new query. |
|
||||||||||||||||
|
tds_process_end() processes any of the DONE, DONEPROC, or DONEINPROC tokens.
|
|
|
tds_process_login_tokens() is called after sending the login packet to the server. It returns the success or failure of the login dependent on the protocol version. 4.2 sends an ACK token only when successful, TDS 5.0 sends it always with a success byte within |
|
||||||||||||
|
process TDS result-type message streams. tds_process_result_tokens() is called after submitting a query with tds_submit_query() and is responsible for calling the routines to populate tds->res_info if appropriate (some query have no result sets)
|
|
||||||||||||||||
|
process TDS row-type message streams. tds_process_row_tokens() is called once a result set has been obtained with tds_process_result_tokens(). It calls tds_process_row() to copy data into the row buffer.
|
|
||||||||||||
|
Process results for simple query as "SET TEXTSIZE" or "USE dbname" If the statement returns results, beware they are discarded. This function was written to avoid direct calls to tds_process_default_tokens (which caused problems such as ignoring query errors). Results are read until idle state or severe failure (do not stop for statement failure).
|
|
||||||||||||||||
|
Output a string to wire automatic translate string to unicode if needed.
|
|
||||||||||||||||
|
Quote an id.
|
|
||||||||||||||||||||
|
Quote a string.
|
|
||||||||||||
|
Read configuration info for given server return 0 on error.
|
|
||||||||||||||||||||
|
Read a section of configuration file (INI style file).
|
|
||||||||||||||||
|
tds_read_config_info() will fill the tds connect_info structure based on configuration information gathered in the following order: 1) Program specified in TDSLOGIN structure 2) The environment variables TDSVER, TDSDUMP, TDSPORT, TDSQUERY, TDSHOST 3) A config file with the following search order: a) a readable file specified by environment variable FREETDSCONF b) a readable file in ~/.freetds.conf c) a readable file in $prefix/etc/freetds.conf 3) ~/.interfaces if exists 4) $SYBASE/interfaces if exists 5) TDS_DEF_* default values .tdsrc and freetds.conf have been added to make the package easier to integration with various Linux and *BSD distributions. |
|
|
Read in one 'packet' from the server. This is a wrapped outer packet of the protocol (they bundle resulte packets into chunks and wrap them at what appears to be 512 bytes regardless of how that breaks internal packet up. (tetherow@nol.org)
|
|
||||||||||||
|
Set type of column initializing all dependency.
|
|
|
Set the full name of interface file.
|
|
||||||||||||
|
tds_submit_execute() sends a previously prepared dynamic statement to the server. Currently works with TDS 5.0 or TDS7+
|
|
||||||||||||||||||||
|
tds_submit_prepare() creates a temporary stored procedure in the server. Currently works with TDS 5.0 and TDS7+
|
|
||||||||||||||||
|
tds_submit_query() sends a language string to the database server for processing. TDS 4.2 is a plain text message with a packet type of 0x01, TDS 7.0 is a unicode string with packet type 0x01, and TDS 5.0 uses a TDS_LANGUAGE_TOKEN to encapsulate the query and a packet type of 0x0f.
|
|
||||||||||||||||
|
tds_submit_rpc() call a RPC from server. Output parameters will be stored in tds->param_info
|
|
||||||||||||
|
Send a unprepare request for a prepared query.
|
|
||||||||||||
|
Returns the version of the TDS protocol in effect for the link as a decimal integer. Typical returned values are 42, 50, 70, 80. Also fills pversion_string unless it is null. Typical pversion_string values are "4.2" and "7.0". |
1.2.18