31 #include <netinet/in.h>
34 #include <arpa/inet.h>
42 #include "tds_sysdep_public.h"
43 #ifdef _FREETDS_LIBRARY_SOURCE
44 #include "tds_sysdep_private.h"
47 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
48 #pragma GCC visibility push(hidden)
66 const char *freetds_version;
67 const char *sysconfdir;
68 const char *last_update;
107 typedef char TDS_CHAR;
108 typedef unsigned char TDS_UCHAR;
109 typedef unsigned char TDS_TINYINT;
110 typedef tds_sysdep_int16_type TDS_SMALLINT;
111 typedef unsigned tds_sysdep_int16_type TDS_USMALLINT;
112 typedef tds_sysdep_int32_type TDS_INT;
113 typedef unsigned tds_sysdep_int32_type TDS_UINT;
114 typedef tds_sysdep_real32_type TDS_REAL;
115 typedef tds_sysdep_real64_type TDS_FLOAT;
116 typedef tds_sysdep_int64_type TDS_INT8;
117 typedef unsigned tds_sysdep_int64_type TDS_UINT8;
118 typedef tds_sysdep_intptr_type TDS_INTPTR;
122 unsigned char precision;
124 unsigned char array[33];
153 TDS_USMALLINT minutes;
199 #define TDS_SUCCEED 1
201 #define TDS_NO_MORE_RESULTS 2
202 #define TDS_CANCELLED 3
204 #define TDS_INT_CONTINUE 1
205 #define TDS_INT_CANCEL 2
206 #define TDS_INT_TIMEOUT 3
209 #define TDS_NO_COUNT -1
211 #define TDS_ROW_RESULT 4040
212 #define TDS_PARAM_RESULT 4042
213 #define TDS_STATUS_RESULT 4043
214 #define TDS_MSG_RESULT 4044
215 #define TDS_COMPUTE_RESULT 4045
216 #define TDS_CMD_DONE 4046
217 #define TDS_CMD_SUCCEED 4047
218 #define TDS_CMD_FAIL 4048
219 #define TDS_ROWFMT_RESULT 4049
220 #define TDS_COMPUTEFMT_RESULT 4050
221 #define TDS_DESCRIBE_RESULT 4051
222 #define TDS_DONE_RESULT 4052
223 #define TDS_DONEPROC_RESULT 4053
224 #define TDS_DONEINPROC_RESULT 4054
225 #define TDS_OTHERS_RESULT 4055
227 enum tds_token_results
229 TDS_TOKEN_RES_OTHERS,
230 TDS_TOKEN_RES_ROWFMT,
231 TDS_TOKEN_RES_COMPUTEFMT,
232 TDS_TOKEN_RES_PARAMFMT,
235 TDS_TOKEN_RES_COMPUTE,
240 #define TDS_TOKEN_FLAG(flag) TDS_RETURN_##flag = (1 << (TDS_TOKEN_RES_##flag*2)), TDS_STOPAT_##flag = (2 << (TDS_TOKEN_RES_##flag*2))
245 TDS_TOKEN_FLAG(OTHERS),
246 TDS_TOKEN_FLAG(ROWFMT),
247 TDS_TOKEN_FLAG(COMPUTEFMT),
248 TDS_TOKEN_FLAG(PARAMFMT),
249 TDS_TOKEN_FLAG(DONE),
251 TDS_TOKEN_FLAG(COMPUTE),
252 TDS_TOKEN_FLAG(PROC),
254 TDS_TOKEN_RESULTS = TDS_RETURN_ROWFMT|TDS_RETURN_COMPUTEFMT|TDS_RETURN_DONE|TDS_STOPAT_ROW|TDS_STOPAT_COMPUTE|TDS_RETURN_PROC,
255 TDS_TOKEN_TRAILING = TDS_STOPAT_ROWFMT|TDS_STOPAT_COMPUTEFMT|TDS_STOPAT_ROW|TDS_STOPAT_COMPUTE|TDS_STOPAT_MSG|TDS_STOPAT_OTHERS
270 , TDS_DONE_EVENT = 0x40
274 , TDS_DONE_NO_TRAN = 0
275 , TDS_DONE_TRAN_SUCCEED = 1
276 , TDS_DONE_TRAN_PROGRESS= 2
277 , TDS_DONE_STMT_ABORT = 3
278 , TDS_DONE_TRAN_ABORT = 4
288 typedef enum { TDSEOK = TDS_SUCCEED,
291 TDSEICONVAVAIL = 2401,
294 TDSEICONV2BIG = 2404,
295 TDSEPORTINSTANCE = 2500,
319 TDSEBPROBADTYP = 20250,
323 #define TDS5_PARAMFMT2_TOKEN 32
324 #define TDS_LANGUAGE_TOKEN 33
325 #define TDS_ORDERBY2_TOKEN 34
326 #define TDS_ROWFMT2_TOKEN 97
327 #define TDS_LOGOUT_TOKEN 113
328 #define TDS_RETURNSTATUS_TOKEN 121
329 #define TDS_PROCID_TOKEN 124
330 #define TDS7_RESULT_TOKEN 129
331 #define TDS7_COMPUTE_RESULT_TOKEN 136
332 #define TDS_COLNAME_TOKEN 160
333 #define TDS_COLFMT_TOKEN 161
334 #define TDS_DYNAMIC2_TOKEN 163
335 #define TDS_TABNAME_TOKEN 164
336 #define TDS_COLINFO_TOKEN 165
337 #define TDS_OPTIONCMD_TOKEN 166
338 #define TDS_COMPUTE_NAMES_TOKEN 167
339 #define TDS_COMPUTE_RESULT_TOKEN 168
340 #define TDS_ORDERBY_TOKEN 169
341 #define TDS_ERROR_TOKEN 170
342 #define TDS_INFO_TOKEN 171
343 #define TDS_PARAM_TOKEN 172
344 #define TDS_LOGINACK_TOKEN 173
345 #define TDS_CONTROL_TOKEN 174
346 #define TDS_ROW_TOKEN 209
347 #define TDS_NBC_ROW_TOKEN 210
348 #define TDS_CMP_ROW_TOKEN 211
349 #define TDS5_PARAMS_TOKEN 215
350 #define TDS_CAPABILITY_TOKEN 226
351 #define TDS_ENVCHANGE_TOKEN 227
352 #define TDS_EED_TOKEN 229
353 #define TDS_DBRPC_TOKEN 230
354 #define TDS5_DYNAMIC_TOKEN 231
355 #define TDS5_PARAMFMT_TOKEN 236
356 #define TDS_AUTH_TOKEN 237
357 #define TDS_RESULT_TOKEN 238
358 #define TDS_DONE_TOKEN 253
359 #define TDS_DONEPROC_TOKEN 254
360 #define TDS_DONEINPROC_TOKEN 255
363 #define TDS_CURCLOSE_TOKEN 128
364 #define TDS_CURDELETE_TOKEN 129
365 #define TDS_CURFETCH_TOKEN 130
366 #define TDS_CURINFO_TOKEN 131
367 #define TDS_CUROPEN_TOKEN 132
368 #define TDS_CURDECLARE_TOKEN 134
371 TDS_CUR_ISTAT_UNUSED = 0x00,
372 TDS_CUR_ISTAT_DECLARED = 0x01,
373 TDS_CUR_ISTAT_OPEN = 0x02,
374 TDS_CUR_ISTAT_CLOSED = 0x04,
375 TDS_CUR_ISTAT_RDONLY = 0x08,
376 TDS_CUR_ISTAT_UPDATABLE = 0x10,
377 TDS_CUR_ISTAT_ROWCNT = 0x20,
378 TDS_CUR_ISTAT_DEALLOC = 0x40
384 TDS_CUR_TYPE_KEYSET = 0x0001,
385 TDS_CUR_TYPE_DYNAMIC = 0x0002,
386 TDS_CUR_TYPE_FORWARD = 0x0004,
387 TDS_CUR_TYPE_STATIC = 0x0008,
388 TDS_CUR_TYPE_FASTFORWARDONLY = 0x0010,
389 TDS_CUR_TYPE_PARAMETERIZED = 0x1000,
390 TDS_CUR_TYPE_AUTO_FETCH = 0x2000
394 TDS_CUR_CONCUR_READ_ONLY = 1,
395 TDS_CUR_CONCUR_SCROLL_LOCKS = 2,
396 TDS_CUR_CONCUR_OPTIMISTIC = 4,
397 TDS_CUR_CONCUR_OPTIMISTIC_VALUES = 8
401 #define TDS_MAXNAME 30
402 #define TDS_PROGNLEN 10
406 #define TDS_ENV_DATABASE 1
407 #define TDS_ENV_LANG 2
408 #define TDS_ENV_CHARSET 3
409 #define TDS_ENV_PACKSIZE 4
410 #define TDS_ENV_LCID 5
411 #define TDS_ENV_SQLCOLLATION 7
412 #define TDS_ENV_BEGINTRANS 8
413 #define TDS_ENV_COMMITTRANS 9
414 #define TDS_ENV_ROLLBACKTRANS 10
417 #define TDS_NULLTERM -9
421 #define TDS_SP_CURSOR 1
422 #define TDS_SP_CURSOROPEN 2
423 #define TDS_SP_CURSORPREPARE 3
424 #define TDS_SP_CURSOREXECUTE 4
425 #define TDS_SP_CURSORPREPEXEC 5
426 #define TDS_SP_CURSORUNPREPARE 6
427 #define TDS_SP_CURSORFETCH 7
428 #define TDS_SP_CURSOROPTION 8
429 #define TDS_SP_CURSORCLOSE 9
430 #define TDS_SP_EXECUTESQL 10
431 #define TDS_SP_PREPARE 11
432 #define TDS_SP_EXECUTE 12
433 #define TDS_SP_PREPEXEC 13
434 #define TDS_SP_PREPEXECRPC 14
435 #define TDS_SP_UNPREPARE 15
444 #define SYBCHAR SYBCHAR
446 #define SYBVARCHAR SYBVARCHAR
448 #define SYBINTN SYBINTN
450 #define SYBINT1 SYBINT1
452 #define SYBINT2 SYBINT2
454 #define SYBINT4 SYBINT4
456 #define SYBFLT8 SYBFLT8
458 #define SYBDATETIME SYBDATETIME
460 #define SYBBIT SYBBIT
462 #define SYBTEXT SYBTEXT
464 #define SYBNTEXT SYBNTEXT
466 #define SYBIMAGE SYBIMAGE
468 #define SYBMONEY4 SYBMONEY4
470 #define SYBMONEY SYBMONEY
472 #define SYBDATETIME4 SYBDATETIME4
474 #define SYBREAL SYBREAL
476 #define SYBBINARY SYBBINARY
478 #define SYBVOID SYBVOID
480 #define SYBVARBINARY SYBVARBINARY
482 #define SYBBITN SYBBITN
484 #define SYBNUMERIC SYBNUMERIC
486 #define SYBDECIMAL SYBDECIMAL
488 #define SYBFLTN SYBFLTN
490 #define SYBMONEYN SYBMONEYN
492 #define SYBDATETIMN SYBDATETIMN
498 #define SYBNVARCHAR SYBNVARCHAR
500 #define SYBINT8 SYBINT8
502 #define XSYBCHAR XSYBCHAR
504 #define XSYBVARCHAR XSYBVARCHAR
506 #define XSYBNVARCHAR XSYBNVARCHAR
508 #define XSYBNCHAR XSYBNCHAR
510 #define XSYBVARBINARY XSYBVARBINARY
512 #define XSYBBINARY XSYBBINARY
514 #define SYBUNIQUE SYBUNIQUE
516 #define SYBVARIANT SYBVARIANT
518 #define SYBMSUDT SYBMSUDT
520 #define SYBMSXML SYBMSXML
526 #define SYBLONGBINARY SYBLONGBINARY
528 #define SYBUINT1 SYBUINT1
530 #define SYBUINT2 SYBUINT2
532 #define SYBUINT4 SYBUINT4
534 #define SYBUINT8 SYBUINT8
536 #define SYBBLOB SYBBLOB
538 #define SYBBOUNDARY SYBBOUNDARY
540 #define SYBDATE SYBDATE
542 #define SYBDATEN SYBDATEN
544 #define SYB5INT8 SYB5INT8
546 #define SYBINTERVAL SYBINTERVAL
548 #define SYBLONGCHAR SYBLONGCHAR
549 SYBSENSITIVITY = 103,
550 #define SYBSENSITIVITY SYBSENSITIVITY
552 #define SYBSINT1 SYBSINT1
554 #define SYBTIME SYBTIME
556 #define SYBTIMEN SYBTIMEN
558 #define SYBUINTN SYBUINTN
560 #define SYBUNITEXT SYBUNITEXT
562 #define SYBXML SYBXML
569 USER_UNICHAR_TYPE = 34,
570 USER_UNIVARCHAR_TYPE = 35
573 #define SYBAOPCNT 0x4b
574 #define SYBAOPCNTU 0x4c
575 #define SYBAOPSUM 0x4d
576 #define SYBAOPSUMU 0x4e
577 #define SYBAOPAVG 0x4f
578 #define SYBAOPAVGU 0x50
579 #define SYBAOPMIN 0x51
580 #define SYBAOPMAX 0x52
583 #define SYBAOPCNT_BIG 0x09
584 #define SYBAOPSTDEV 0x30
585 #define SYBAOPSTDEVP 0x31
586 #define SYBAOPVAR 0x32
587 #define SYBAOPVARP 0x33
588 #define SYBAOPCHECKSUM_AGG 0x72
597 , TDS_OPT_DEFAULT = 2
604 TDS_OPT_DATEFIRST = 1
605 , TDS_OPT_TEXTSIZE = 2
606 , TDS_OPT_STAT_TIME = 3
607 , TDS_OPT_STAT_IO = 4
608 , TDS_OPT_ROWCOUNT = 5
609 , TDS_OPT_NATLANG = 6
610 , TDS_OPT_DATEFORMAT = 7
611 , TDS_OPT_ISOLATION = 8
613 , TDS_OPT_CHARSET = 10
614 , TDS_OPT_SHOWPLAN = 13
615 , TDS_OPT_NOEXEC = 14
616 , TDS_OPT_ARITHIGNOREON = 15
617 , TDS_OPT_ARITHABORTON = 17
618 , TDS_OPT_PARSEONLY = 18
619 , TDS_OPT_GETDATA = 20
620 , TDS_OPT_NOCOUNT = 21
621 , TDS_OPT_FORCEPLAN = 23
622 , TDS_OPT_FORMATONLY = 24
623 , TDS_OPT_CHAINXACTS = 25
624 , TDS_OPT_CURCLOSEONXACT = 26
625 , TDS_OPT_FIPSFLAG = 27
626 , TDS_OPT_RESTREES = 28
627 , TDS_OPT_IDENTITYON = 29
628 , TDS_OPT_CURREAD = 30
629 , TDS_OPT_CURWRITE = 31
630 , TDS_OPT_IDENTITYOFF = 32
631 , TDS_OPT_AUTHOFF = 33
632 , TDS_OPT_ANSINULL = 34
633 , TDS_OPT_QUOTED_IDENT = 35
634 , TDS_OPT_ARITHIGNOREOFF = 36
635 , TDS_OPT_ARITHABORTOFF = 37
636 , TDS_OPT_TRUNCABORT = 38
647 TDS_OPT_ARITHOVERFLOW = 0x01,
648 TDS_OPT_NUMERICTRUNC = 0x02
651 enum TDS_OPT_DATEFIRST_CHOICE
653 TDS_OPT_MONDAY = 1, TDS_OPT_TUESDAY = 2, TDS_OPT_WEDNESDAY = 3, TDS_OPT_THURSDAY = 4, TDS_OPT_FRIDAY = 5, TDS_OPT_SATURDAY =
654 6, TDS_OPT_SUNDAY = 7
657 enum TDS_OPT_DATEFORMAT_CHOICE
659 TDS_OPT_FMTMDY = 1, TDS_OPT_FMTDMY = 2, TDS_OPT_FMTYMD = 3, TDS_OPT_FMTYDM = 4, TDS_OPT_FMTMYD = 5, TDS_OPT_FMTDYM = 6
661 enum TDS_OPT_ISOLATION_CHOICE
663 TDS_OPT_LEVEL1 = 1, TDS_OPT_LEVEL3 = 3
666 typedef enum tds_packet_type
680 typedef enum tds_encryption_level {
681 TDS_ENCRYPTION_OFF, TDS_ENCRYPTION_REQUEST, TDS_ENCRYPTION_REQUIRE
682 } TDS_ENCRYPTION_LEVEL;
684 #define TDS_ZERO_FREE(x) do {free((x)); (x) = NULL;} while(0)
685 #define TDS_VECTOR_SIZE(x) (sizeof(x)/sizeof(x[0]))
687 #if defined(__GNUC__) && __GNUC__ >= 3
688 # define TDS_LIKELY(x) __builtin_expect(!!(x), 1)
689 # define TDS_UNLIKELY(x) __builtin_expect(!!(x), 0)
691 # define TDS_LIKELY(x) (x)
692 # define TDS_UNLIKELY(x) (x)
700 #define TDS_BYTE_SWAP16(value) \
701 (((((unsigned short)value)<<8) & 0xFF00) | \
702 ((((unsigned short)value)>>8) & 0x00FF))
704 #define TDS_BYTE_SWAP32(value) \
705 (((((unsigned long)value)<<24) & 0xFF000000) | \
706 ((((unsigned long)value)<< 8) & 0x00FF0000) | \
707 ((((unsigned long)value)>> 8) & 0x0000FF00) | \
708 ((((unsigned long)value)>>24) & 0x000000FF))
710 #define is_end_token(x) (x==TDS_DONE_TOKEN || \
711 x==TDS_DONEPROC_TOKEN || \
712 x==TDS_DONEINPROC_TOKEN)
714 #define is_hard_end_token(x) (x==TDS_DONE_TOKEN || \
715 x==TDS_DONEPROC_TOKEN)
717 #define is_msg_token(x) (x==TDS_INFO_TOKEN || \
718 x==TDS_ERROR_TOKEN || \
721 #define is_result_token(x) (x==TDS_RESULT_TOKEN || \
722 x==TDS_ROWFMT2_TOKEN || \
723 x==TDS7_RESULT_TOKEN || \
724 x==TDS_COLFMT_TOKEN || \
725 x==TDS_COLNAME_TOKEN || \
726 x==TDS_RETURNSTATUS_TOKEN)
729 #define is_fixed_type(x) (x==SYBINT1 || \
742 #define is_nullable_type(x) ( \
754 #define is_variable_type(x) ( \
761 (x)==SYBVARBINARY || \
762 (x)==SYBLONGBINARY || \
764 (x)==XSYBVARCHAR || \
765 (x)==XSYBNVARCHAR || \
768 #define is_blob_type(x) (x==SYBTEXT || x==SYBIMAGE || x==SYBNTEXT)
769 #define is_blob_col(x) ((x)->column_varint_size > 2)
772 #define is_numeric_type(x) (x==SYBNUMERIC || x==SYBDECIMAL)
773 #define is_unicode_type(x) (x==XSYBNVARCHAR || x==XSYBNCHAR || x==SYBNTEXT || x==SYBMSXML)
774 #define is_collate_type(x) (x==XSYBVARCHAR || x==XSYBCHAR || x==SYBTEXT || x==XSYBNVARCHAR || x==XSYBNCHAR || x==SYBNTEXT)
775 #define is_ascii_type(x) ( x==XSYBCHAR || x==XSYBVARCHAR || x==SYBTEXT || x==SYBCHAR || x==SYBVARCHAR)
776 #define is_char_type(x) (is_unicode_type(x) || is_ascii_type(x))
777 #define is_similar_type(x, y) ((is_char_type(x) && is_char_type(y)) || ((is_unicode_type(x) && is_unicode_type(y))))
780 #define TDS_MAX_CAPABILITY 22
781 #define MAXPRECISION 77
782 #define TDS_MAX_CONN 4096
783 #define TDS_MAX_DYNID_LEN 30
786 #define TDS_DEF_SERVER "SYBASE"
787 #define TDS_DEF_BLKSZ 512
788 #define TDS_DEF_CHARSET "iso_1"
789 #define TDS_DEF_LANG "us_english"
791 #define TDS_DEFAULT_VERSION 0x402
792 #define TDS_DEF_PORT 1433
794 #define TDS_DEFAULT_VERSION 0x406
795 #define TDS_DEF_PORT 4000
797 #define TDS_DEFAULT_VERSION 0x700
798 #define TDS_DEF_PORT 1433
800 #define TDS_DEFAULT_VERSION 0x701
801 #define TDS_DEF_PORT 1433
803 #define TDS_DEFAULT_VERSION 0x702
804 #define TDS_DEF_PORT 1433
806 #define TDS_DEFAULT_VERSION 0x500
807 #define TDS_DEF_PORT 4000
811 #define TDS_STR_VERSION "tds version"
812 #define TDS_STR_BLKSZ "initial block size"
813 #define TDS_STR_SWAPDT "swap broken dates"
814 #define TDS_STR_DUMPFILE "dump file"
815 #define TDS_STR_DEBUGLVL "debug level"
816 #define TDS_STR_DEBUGFLAGS "debug flags"
817 #define TDS_STR_TIMEOUT "timeout"
818 #define TDS_STR_QUERY_TIMEOUT "query timeout"
819 #define TDS_STR_CONNTIMEOUT "connect timeout"
820 #define TDS_STR_HOSTNAME "hostname"
821 #define TDS_STR_HOST "host"
822 #define TDS_STR_PORT "port"
823 #define TDS_STR_TEXTSZ "text size"
825 #define TDS_STR_EMUL_LE "emulate little endian"
826 #define TDS_STR_CHARSET "charset"
827 #define TDS_STR_CLCHARSET "client charset"
828 #define TDS_STR_LANGUAGE "language"
829 #define TDS_STR_APPENDMODE "dump file append"
830 #define TDS_STR_DATEFMT "date format"
831 #define TDS_STR_INSTANCE "instance"
832 #define TDS_STR_ASA_DATABASE "asa database"
833 #define TDS_STR_ENCRYPTION "encryption"
834 #define TDS_STR_USENTLMV2 "use ntlmv2"
836 #define TDS_STR_ENCRYPTION_OFF "off"
837 #define TDS_STR_ENCRYPTION_REQUEST "request"
838 #define TDS_STR_ENCRYPTION_REQUIRE "require"
840 #define TDS_GSSAPI_DELEGATION "enable gssapi delegation"
842 #define TDS_STR_REALM "realm"
852 #define TDS_ALIGN_SIZE sizeof(tds_align_struct)
854 #define TDS_MAX_LOGIN_STR_SZ 128
859 TDS_USMALLINT tds_version;
863 TDS_INT connect_timeout;
864 DSTR client_host_name;
870 TDS_TINYINT encryption_level;
872 TDS_INT query_timeout;
873 unsigned char capabilities[TDS_MAX_CAPABILITY];
876 unsigned int bulk_copy:1;
877 unsigned int suppress_language:1;
885 TDS_USMALLINT tds_version;
889 TDS_INT connect_timeout;
890 DSTR client_host_name;
891 DSTR server_host_name;
897 TDS_TINYINT encryption_level;
899 TDS_INT query_timeout;
900 unsigned char capabilities[TDS_MAX_CAPABILITY];
901 unsigned char option_flag2;
910 unsigned int broken_dates:1;
911 unsigned int emul_little_endian:1;
912 unsigned int bulk_copy:1;
913 unsigned int suppress_language:1;
914 unsigned int gssapi_use_delegation:1;
915 unsigned int use_ntlmv2:1;
921 char *server_charset;
932 TDS_CHAR textptr[16];
933 TDS_CHAR timestamp[8];
946 TDS_UCHAR collation[5];
954 TDS_USMALLINT locale_id;
956 TDS_UCHAR charset_id;
960 #define TDS_SF_BIN (TDS_USMALLINT) 0x100
961 #define TDS_SF_WIDTH_INSENSITIVE (TDS_USMALLINT) 0x080
962 #define TDS_SF_KATATYPE_INSENSITIVE (TDS_USMALLINT) 0x040
963 #define TDS_SF_ACCENT_SENSITIVE (TDS_USMALLINT) 0x020
964 #define TDS_SF_CASE_INSENSITIVE (TDS_USMALLINT) 0x010
967 #define TDS_UT_TIMESTAMP 80
977 unsigned char min_bytes_per_char;
978 unsigned char max_bytes_per_char;
979 unsigned char canonic;
991 { TDS_SYSNAME_SIZE = 512 };
1003 TDS_INT column_usertype;
1004 TDS_INT column_flags;
1014 TDS_SMALLINT table_namelen;
1023 TDS_CHAR table_name[TDS_SYSNAME_SIZE];
1024 TDS_CHAR column_name[TDS_SYSNAME_SIZE];
1025 char * table_column_name;
1027 unsigned char *column_data;
1028 void (*column_data_free)(
struct tds_column *column);
1029 unsigned int column_nullable:1;
1030 unsigned int column_writeable:1;
1031 unsigned int column_identity:1;
1032 unsigned int column_key:1;
1033 unsigned int column_hidden:1;
1034 unsigned int column_output:1;
1035 unsigned int column_timestamp:1;
1036 TDS_UCHAR column_collation[5];
1039 TDS_TINYINT column_operator;
1040 TDS_SMALLINT column_operand;
1048 TDS_SMALLINT column_bindtype;
1049 TDS_SMALLINT column_bindfmt;
1050 TDS_UINT column_bindlen;
1051 TDS_SMALLINT *column_nullbind;
1052 TDS_CHAR *column_varaddr;
1053 TDS_INT *column_lenbind;
1054 TDS_INT column_textpos;
1055 TDS_INT column_text_sqlgetdatapos;
1056 TDS_CHAR column_text_sqlputdatainfo;
1068 TDS_INT bcp_term_len;
1069 TDS_CHAR *bcp_terminator;
1077 TDS_SMALLINT num_cols;
1081 unsigned char *current_row;
1084 TDS_SMALLINT rows_exist;
1088 TDS_TINYINT more_results;
1089 TDS_SMALLINT computeid;
1090 TDS_SMALLINT *bycolumns;
1091 TDS_SMALLINT by_cols;
1104 #define TDS_DBG_LOGIN __FILE__, ((__LINE__ << 4) | 11)
1105 #define TDS_DBG_HEADER __FILE__, ((__LINE__ << 4) | 10)
1106 #define TDS_DBG_FUNC __FILE__, ((__LINE__ << 4) | 7)
1107 #define TDS_DBG_INFO2 __FILE__, ((__LINE__ << 4) | 6)
1108 #define TDS_DBG_INFO1 __FILE__, ((__LINE__ << 4) | 5)
1109 #define TDS_DBG_NETWORK __FILE__, ((__LINE__ << 4) | 4)
1110 #define TDS_DBG_WARN __FILE__, ((__LINE__ << 4) | 3)
1111 #define TDS_DBG_ERROR __FILE__, ((__LINE__ << 4) | 2)
1112 #define TDS_DBG_SEVERE __FILE__, ((__LINE__ << 4) | 1)
1114 #define TDS_DBGFLAG_FUNC 0x80
1115 #define TDS_DBGFLAG_INFO2 0x40
1116 #define TDS_DBGFLAG_INFO1 0x20
1117 #define TDS_DBGFLAG_NETWORK 0x10
1118 #define TDS_DBGFLAG_WARN 0x08
1119 #define TDS_DBGFLAG_ERROR 0x04
1120 #define TDS_DBGFLAG_SEVERE 0x02
1121 #define TDS_DBGFLAG_ALL 0xfff
1122 #define TDS_DBGFLAG_LOGIN 0x0800
1123 #define TDS_DBGFLAG_HEADER 0x0400
1124 #define TDS_DBGFLAG_PID 0x1000
1125 #define TDS_DBGFLAG_TIME 0x2000
1126 #define TDS_DBGFLAG_SOURCE 0x4000
1127 #define TDS_DBGFLAG_THREAD 0x8000
1135 enum TDS_DBG_LOG_STATE
1137 TDS_DBG_LOGIN = (1 << 0)
1139 , TDS_DBG_API = (1 << 1)
1140 , TDS_DBG_ASYNC = (1 << 2)
1141 , TDS_DBG_DIAG = (1 << 3)
1142 , TDS_DBG_error = (1 << 4)
1145 , TDS_DBG_PACKET = (1 << 5)
1146 , TDS_DBG_LIBTDS = (1 << 6)
1147 , TDS_DBG_CONFIG = (1 << 7)
1148 , TDS_DBG_DEFAULT = 0xFE
1160 TDS_CHAR *proc_name;
1161 TDS_CHAR *sql_state;
1163 TDS_INT line_number;
1166 TDS_TINYINT priv_msg_type;
1167 TDS_TINYINT severity;
1175 TDS_INT colnamelength;
1180 TDS_CURSOR_STATE_UNACTIONED = 0
1181 , TDS_CURSOR_STATE_REQUESTED = 1
1182 , TDS_CURSOR_STATE_SENT = 2
1183 , TDS_CURSOR_STATE_ACTIONED = 3
1188 TDS_CURSOR_STATE declare;
1189 TDS_CURSOR_STATE cursor_row;
1190 TDS_CURSOR_STATE open;
1191 TDS_CURSOR_STATE fetch;
1192 TDS_CURSOR_STATE close;
1193 TDS_CURSOR_STATE dealloc;
1196 typedef enum tds_cursor_operation
1198 TDS_CURSOR_POSITION = 0,
1199 TDS_CURSOR_UPDATE = 1,
1200 TDS_CURSOR_DELETE = 2,
1201 TDS_CURSOR_INSERT = 4
1202 } TDS_CURSOR_OPERATION;
1204 typedef enum tds_cursor_fetch
1206 TDS_CURSOR_FETCH_NEXT = 1,
1207 TDS_CURSOR_FETCH_PREV,
1208 TDS_CURSOR_FETCH_FIRST,
1209 TDS_CURSOR_FETCH_LAST,
1210 TDS_CURSOR_FETCH_ABSOLUTE,
1211 TDS_CURSOR_FETCH_RELATIVE
1234 TDS_SMALLINT srv_status;
1286 TDS_MULTIPLE_EXECUTE,
1288 } TDS_MULTIPLE_TYPE;
1292 TDS_MULTIPLE_TYPE type;
1307 int (*int_handler) (
void *);
1310 enum TDS_ICONV_ENTRY
1313 , client2server_chardata
1314 , iso2server_metadata
1315 , initial_char_conv_count
1333 TDS_USMALLINT tds_version;
1337 unsigned char capabilities[TDS_MAX_CAPABILITY];
1338 unsigned int broken_dates:1;
1339 unsigned int emul_little_endian:1;
1340 unsigned int use_iconv:1;
1341 unsigned int tds71rev1:1;
1361 TDS_INT num_comp_info;
1374 TDS_INT query_timeout;
1381 int char_conv_count;
1387 TDS_UCHAR collation[5];
1388 TDS_UCHAR tds9_transaction[8];
1389 void (*env_chg_func) (
TDSSOCKET * tds,
int type,
char *oldval,
char *newval);
1390 int internal_sp_called;
1393 void *tls_credentials;
1398 int tds_init_write_buf(
TDSSOCKET * tds);
1402 void tds_free_all_results(
TDSSOCKET * tds);
1404 void tds_free_param_results(
TDSPARAMINFO * param_info);
1409 void tds_free_bcp_column_data(
BCPCOLDATA * coldata);
1411 int tds_put_n(
TDSSOCKET * tds,
const void *buf,
size_t n);
1413 int tds_put_int(
TDSSOCKET * tds, TDS_INT i);
1414 int tds_put_int8(
TDSSOCKET * tds, TDS_INT8 i);
1415 int tds_put_smallint(
TDSSOCKET * tds, TDS_SMALLINT si);
1417 #define tds_put_tinyint(tds, ti) tds_put_byte(tds,ti)
1418 int tds_put_byte(
TDSSOCKET * tds,
unsigned char c);
1421 TDSCONTEXT *tds_alloc_context(
void * parent);
1426 int tds_default_port(
int major,
int minor);
1428 typedef void (*TDSCONFPARSE) (
const char *option,
const char *value,
void *param);
1429 int tds_read_conf_section(FILE * in,
const char *section, TDSCONFPARSE tds_conf_parse,
void *parse_param);
1431 void tds_parse_conf_section(
const char *option,
const char *value,
void *param);
1437 extern const char STD_DATETIME_FMT[];
1438 int tds_config_boolean(
const char *value);
1443 BCPCOLDATA * tds_alloc_bcp_column_data(
int column_size);
1444 unsigned char *
tds7_crypt_pass(
const unsigned char *clear_pass,
size_t len,
unsigned char *crypt_pass);
1446 const char *tds_prtype(
int token);
1448 int tds_get_cardinal_type(
int datatype,
int usertype);
1453 void tds_iconv_open(
TDSSOCKET * tds,
const char *charset);
1455 void tds_srv_charset_changed(
TDSSOCKET * tds,
const char *charset);
1456 void tds7_srv_charset_changed(
TDSSOCKET * tds,
int sql_collate,
int lcid);
1463 struct tm *tds_localtime_r(
const time_t *timep,
struct tm *result);
1464 struct hostent *tds_gethostbyname_r(
const char *servername,
struct hostent *result,
char *buffer,
int buflen,
int *h_errnop);
1465 struct hostent *tds_gethostbyaddr_r(
const char *addr,
int len,
int type,
struct hostent *result,
char *buffer,
int buflen,
1467 struct servent *tds_getservbyname_r(
const char *name,
const char *proto,
struct servent *result,
char *buffer,
int buflen);
1469 const char *tds_inet_ntoa_r(
struct in_addr iaddr,
char *ip,
size_t len);
1478 char *tds_alloc_client_sqlstate(
int msgno);
1479 char *tds_alloc_lookup_sqlstate(
TDSSOCKET * tds,
int msgno);
1482 void tds_free_login(
TDSLOGIN * login);
1486 void tds_free_locale(
TDSLOCALE * locale);
1487 TDSCURSOR * tds_alloc_cursor(
TDSSOCKET * tds,
const char *name, TDS_INT namelen,
const char *query, TDS_INT querylen);
1488 void tds_free_row(
TDSRESULTINFO * res_info,
unsigned char *row);
1503 void tds_set_version(
TDSLOGIN *
tds_login, TDS_TINYINT major_ver, TDS_TINYINT minor_ver);
1504 void tds_set_capabilities(
TDSLOGIN *
tds_login,
unsigned char *capabilities,
int size);
1510 int tds_submit_queryf(
TDSSOCKET * tds,
const char *queryf, ...);
1524 const char *tds_skip_comment(
const char *s);
1530 int tds_cursor_fetch(
TDSSOCKET * tds,
TDSCURSOR * cursor, TDS_CURSOR_FETCH fetch_type, TDS_INT i_row);
1531 int tds_cursor_get_cursor_info(
TDSSOCKET * tds,
TDSCURSOR * cursor, TDS_UINT * row_number, TDS_UINT * row_count);
1544 #ifdef WORDS_BIGENDIAN
1545 void tds_swap_datatype(
int coltype,
unsigned char *buf);
1552 TDS_INT * tds_argsize);
1564 extern const char tds_hex_digits[];
1568 int tds_put_buf(
TDSSOCKET * tds,
const unsigned char *buf,
int dsize,
int ssize);
1571 unsigned char tds_get_byte(
TDSSOCKET * tds);
1573 unsigned char tds_peek(
TDSSOCKET * tds);
1586 void tds_set_parent(
TDSSOCKET * tds,
void *the_parent);
1587 int tds_swap_bytes(
unsigned char *buf,
int bytes);
1589 unsigned int tds_gettime_ms(
void);
1590 int tds_get_req_capability(
TDSSOCKET * tds,
int cap);
1595 int tdsdump_isopen(
void);
1596 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
1597 #pragma GCC visibility pop
1600 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
1601 #pragma GCC visibility push(hidden)
1604 void tdsdump_dump_buf(
const char* file,
unsigned int level_line,
const char *msg,
const void *buf,
size_t length);
1607 void tdsdump_log(
const char* file,
unsigned int level_line,
const char *fmt, ...)
1608 #if defined(__GNUC__) && __GNUC__ >= 2
1609 __attribute__ ((__format__ (__printf__, 3, 4)))
1612 #define tdsdump_log if (TDS_UNLIKELY(tds_write_dump)) tdsdump_log
1614 extern int tds_write_dump;
1615 extern int tds_debug_flags;
1616 extern int tds_g_append_mode;
1620 TDSERRNO tds_open_socket(
TDSSOCKET * tds,
const char *ip_addr,
unsigned int port,
int timeout,
int *p_oserr);
1623 int tds_write_packet(
TDSSOCKET * tds,
unsigned char final);
1628 const char *tds_prwsaerror(
int erc);
1633 int tds_vstrbuild(
char *buffer,
int buflen,
int *resultlen,
char *text,
int textlen,
const char *formats,
int formatlen,
1637 char *tds_money_to_string(
const TDS_MONEY * money,
char *s);
1638 TDS_INT tds_numeric_to_string(
const TDS_NUMERIC * numeric,
char *s);
1639 TDS_INT tds_numeric_change_prec_scale(
TDS_NUMERIC * numeric,
unsigned char new_prec,
unsigned char new_scale);
1642 void tds_getmac(TDS_SYS_SOCKET s,
unsigned char mac[6]);
1658 TDS_BCP_QUERYOUT = 3
1665 TDS_CHAR *tablename;
1666 TDS_CHAR *insert_stmt;
1668 TDS_INT identity_insert_on;
1677 typedef void (*tds_bcp_null_error) (
TDSBCPINFO *bulk,
int index,
int offset);
1679 int tds_bcp_done(
TDSSOCKET *tds,
int *rows_copied);
1683 int tds_writetext_start(
TDSSOCKET *tds,
const char *objname,
const char *textptr,
const char *timestamp,
int with_log, TDS_UINT size);
1684 int tds_writetext_continue(
TDSSOCKET *tds,
const TDS_UCHAR *text, TDS_UINT size);
1688 #define IS_TDS42(x) (x->tds_version==0x402)
1689 #define IS_TDS46(x) (x->tds_version==0x406)
1690 #define IS_TDS50(x) (x->tds_version==0x500)
1691 #define IS_TDS70(x) (x->tds_version==0x700)
1692 #define IS_TDS71(x) (x->tds_version==0x701)
1693 #define IS_TDS72(x) (x->tds_version==0x702)
1695 #define IS_TDS7_PLUS(x) ((x)->tds_version>=0x700)
1696 #define IS_TDS71_PLUS(x) ((x)->tds_version>=0x701)
1697 #define IS_TDS72_PLUS(x) ((x)->tds_version>=0x702)
1699 #define TDS_MAJOR(x) ((x)->tds_version >> 8)
1700 #define TDS_MINOR(x) ((x)->tds_version & 0xff)
1702 #define IS_TDSDEAD(x) (((x) == NULL) || TDS_IS_SOCKET_INVALID((x)->s))
1705 #define TDS_IS_SYBASE(x) (!(x->product_version & 0x80000000u))
1707 #define TDS_IS_MSSQL(x) ((x->product_version & 0x80000000u)!=0)
1712 #define TDS_MS_VER(maj,min,x) (0x80000000u|((maj)<<24)|((min)<<16)|(x))
1716 #define TDS_SYB_VER(maj,min,x) (((maj)<<24)|((min)<<16)|(x)<<8)
1725 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
1726 #pragma GCC visibility pop
1729 #define TDS_PUT_INT(tds,v) tds_put_int((tds), ((TDS_INT)(v)))
1730 #define TDS_PUT_SMALLINT(tds,v) tds_put_smallint((tds), ((TDS_SMALLINT)(v)))
1731 #define TDS_PUT_BYTE(tds,v) tds_put_byte((tds), ((unsigned char)(v)))
no connection
Definition: tds.h:1101
TDS_INT bcp_prefix_len
The length, in bytes, of any length prefix this column may have.
Definition: tds.h:1067
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:280
unsigned char out_flag
output buffer type
Definition: tds.h:1351
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)
Definition: config.c:473
Information for a server connection.
Definition: tds.h:1329
int tds_get_char_data(TDSSOCKET *tds, char *dest, size_t wire_size, TDSCOLUMN *curcol)
Fetch character data the wire.
Definition: read.c:225
TDS_SMALLINT column_type
This type can be different from wire type because conversion (e.g.
Definition: tds.h:998
struct tds_encoding TDS_ENCODING
Information relevant to libiconv.
TDSCONNECTION * connection
config for login stuff.
Definition: tds.h:1384
final result set, command completed successfully.
Definition: tds.h:263
A structure to hold all the compile-time settings.
Definition: tds.h:64
Information about blobs (e.g.
Definition: tds.h:929
Used by tds_datecrack.
Definition: tds.h:176
int tds_count_placeholders(const char *query)
Count the number of placeholders in query.
Definition: query.c:496
TDS_INT ref_count
reference counter so client can retain safely a pointer
Definition: tds.h:1220
TDSCURSOR * cursors
linked list of cursors allocated for this connection
Definition: tds.h:1365
TDS_INT week
1 - 54 (can be 54 in leap year)
Definition: tds.h:183
unsigned char * out_buf
output buffer
Definition: tds.h:1344
TDS_INT type
row fetched from this cursor
Definition: tds.h:1236
TDS_TINYINT cursor_name_len
length of cursor name > 0 and <= 30
Definition: tds.h:1221
Current environment as reported by the server.
Definition: tds.h:1242
TDS_CURSOR_STATUS status
cursor parameter
Definition: tds.h:1233
error occurred
Definition: tds.h:265
struct tds_dynamic TDSDYNAMIC
Holds information for a dynamic (also called prepared) query.
TDS_INT millisecond
0-999
Definition: tds.h:188
Holds information for a dynamic (also called prepared) query.
Definition: tds.h:1253
TDS_INT8 rows_affected
rows updated/deleted/inserted/selected, TDS_NO_COUNT if not valid
Definition: tds.h:1373
int tds_submit_execute(TDSSOCKET *tds, TDSDYNAMIC *dyn)
tds_submit_execute() sends a previously prepared dynamic statement to the server. ...
Definition: query.c:1815
char * dbname(DBPROCESS *dbproc)
Get name of current database.
Definition: dblib.c:6818
DSTR ip_addr
ip of server
Definition: tds.h:904
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:1171
TDS_INT tds_datecrack(TDS_INT datetype, const void *di, TDSDATEREC *dr)
Convert from db date format to a structured date format.
Definition: convert.c:2925
void tds_free_param_result(TDSPARAMINFO *param_info)
Delete latest parameter.
Definition: mem.c:274
int tds_submit_query(TDSSOCKET *tds, const char *query)
tds_submit_query() sends a language string to the database server for processing. ...
Definition: query.c:189
const char * tds_skip_quoted(const char *s)
Skip quoting string (like 'sfsf', "dflkdj" or [dfkjd])
Definition: query.c:441
volatile unsigned char in_cancel
indicate we are waiting a cancel reply; discard tokens till acknowledge
Definition: tds.h:1371
struct tds_blob TDSBLOB
Information about blobs (e.g.
TDS_OPTION_CMD
options that can be sent with a TDS_OPTIONCMD token
Definition: tds.h:594
struct tds_env TDSENV
Current environment as reported by the server.
DSTR server_name
server name (in freetds.conf)
Definition: tds.h:883
TDS_SMALLINT tds_get_smallint(TDSSOCKET *tds)
Get an int16 from the server.
Definition: read.c:106
int tds_alloc_row(TDSRESULTINFO *res_info)
Allocate space for row store return NULL on out of memory.
Definition: mem.c:468
TDS_INT quarter
quarter (0-3)
Definition: tds.h:179
Holds informations about a cursor.
Definition: tds.h:1217
TDSPARAMINFO * tds_alloc_param_result(TDSPARAMINFO *old_param)
Adds a output parameter to TDSPARAMINFO.
Definition: mem.c:234
void * tds_alloc_param_data(TDSCOLUMN *curparam)
Allocate data for a parameter.
Definition: mem.c:319
int tds_set_interfaces_file_loc(const char *interfloc)
Set the full name of interface file.
Definition: config.c:800
TDS_INT num_id
numeric id for mssql7+
Definition: tds.h:1264
void tdsdump_off(void)
Temporarily turn off logging.
Definition: log.c:93
TDS_SMALLINT column_namelen
length of column name
Definition: tds.h:1013
int tds8_submit_prepexec(TDSSOCKET *tds, const char *query, const char *id, TDSDYNAMIC **dyn_out, TDSPARAMINFO *params)
tds8_submit_prepexec() creates a temporary stored procedure in the server.
Definition: query.c:1292
int tds7_get_instance_port(const char *ip_addr, const char *instance)
Get port of given instance.
Definition: net.c:924
TDS_TINYINT hasargs
cursor parameters exists ?
Definition: tds.h:1225
int tds_put_string(TDSSOCKET *tds, const char *buf, int len)
Output a string to wire automatic translate string to unicode if needed.
Definition: write.c:98
TDS_SYS_SOCKET s
tcp socket, INVALID_SOCKET if not connected
Definition: tds.h:1331
int tds_get_conversion_type(int srctype, int colsize)
Return type suitable for conversions (convert all nullable types to fixed type)
Definition: tds_types.h:121
TDS_TINYINT column_varint_size
size of length when reading from wire (0, 1, 2 or 4)
Definition: tds.h:1008
client is reading data
Definition: tds.h:1100
int port
port of database service
Definition: tds.h:884
Hold information for any results.
Definition: tds.h:1074
count field in packet is valid
Definition: tds.h:268
TDS_INT day
day of month (1-31)
Definition: tds.h:181
int emulated
this dynamic query cannot be prepared so libTDS have to construct a simple query. ...
Definition: tds.h:1279
int tds_process_tokens(TDSSOCKET *tds, TDS_INT *result_type, int *done_flags, unsigned flag)
process all streams.
Definition: token.c:518
int tds_bcp_send_record(TDSSOCKET *tds, TDSBCPINFO *bcpinfo, tds_bcp_get_col_data get_col_data, tds_bcp_null_error null_error, int offset)
Definition: bulk.c:412
TDSRESULTINFO * current_results
Current query information.
Definition: tds.h:1359
struct tds_variant TDSVARIANT
Store variant informations.
int 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:2155
enum _TDS_STATE TDS_STATE
values for tds->state
TDS_INT cursor_id
cursor id returned by the server after cursor declare
Definition: tds.h:1223
struct tds_cursor TDSCURSOR
Holds informations about a cursor.
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 determi...
Definition: token.c:2919
unsigned in_pos
current position in in_buf
Definition: tds.h:1346
TDS_INT year
year
Definition: tds.h:178
int tds_submit_prepare(TDSSOCKET *tds, const char *query, const char *id, TDSDYNAMIC **dyn_out, TDSPARAMINFO *params)
tds_submit_prepare() creates a temporary stored procedure in the server.
Definition: query.c:1010
void tdsdump_on(void)
Turn logging back on.
Definition: log.c:105
int tds_flush_packet(TDSSOCKET *tds)
Flush packet to server.
Definition: write.c:295
char * query
saved query, we need to know original query if prepare is impossible
Definition: tds.h:1281
struct tdsdaterec TDSDATEREC
Used by tds_datecrack.
TDSLOCALE * tds_get_locale(void)
Get locale information.
Definition: locale.c:58
unsigned out_pos
current position in out_buf
Definition: tds.h:1347
TDS_TINYINT options
read only|updatable
Definition: tds.h:1224
int tds_read_conf_file(TDSCONNECTION *connection, const char *server)
Read configuration info for given server return 0 on error.
Definition: config.c:338
TDS_USMALLINT query_len
SQL query length.
Definition: tds.h:1226
void tdsdump_close(void)
Close the TDS dump log file.
Definition: log.c:221
Store variant informations.
Definition: tds.h:939
TDSICONV * tds_iconv_from_collate(TDSSOCKET *tds, TDS_UCHAR collate[5])
Get iconv information from a LCID (to support different column encoding under MSSQL2K) ...
Definition: iconv.c:1514
unsigned in_len
input buffer length
Definition: tds.h:1348
TDS_INT ret_status
return status from store procedure
Definition: tds.h:1367
char * query
SQL query.
Definition: tds.h:1227
void tdsdump_log(const char *file, unsigned int level_line, const char *fmt,...)
Write a message to the debug log.
Definition: log.c:377
TDS_INT cursor_rows
< number of updatable columns
Definition: tds.h:1231
TDSDYNAMIC * tds_lookup_dynamic(TDSSOCKET *tds, const char *id)
Find a dynamic given string id.
Definition: token.c:2751
void tdsdump_col(const TDSCOLUMN *col)
Write a column value to the debug log.
Definition: log.c:432
int tds7_get_instance_ports(FILE *output, const char *ip_addr)
Get port of all instances.
Definition: net.c:784
TDS_INT tds_get_int(TDSSOCKET *tds)
Get an int32 from the server.
Definition: read.c:123
TDS_INT dayofyear
day of year (1-366)
Definition: tds.h:182
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...
Definition: read.c:286
int tds_get_string(TDSSOCKET *tds, int string_len, char *dest, size_t dest_size)
Fetch a string from the wire.
Definition: read.c:182
int tds_process_cancel(TDSSOCKET *tds)
Definition: token.c:2718
TDS_STATE tds_set_state(TDSSOCKET *tds, TDS_STATE state)
Set state of TDS connection, with logging and checking.
Definition: util.c:84
unsigned char in_flag
input buffer type
Definition: tds.h:1350
void tds_unget_byte(TDSSOCKET *tds)
Unget will always work as long as you don't call it twice in a row.
Definition: read.c:86
no data expected
Definition: tds.h:1097
unsigned char * in_buf
input buffer
Definition: tds.h:1343
TDS_INT hour
0-23
Definition: tds.h:185
int tds_lookup_host(const char *servername, char *ip)
Get the IP address for a hostname.
Definition: config.c:826
int tds_submit_unprepare(TDSSOCKET *tds, TDSDYNAMIC *dyn)
Send a unprepare request for a prepared query.
Definition: query.c:1929
void tds_free_dynamic(TDSSOCKET *tds, TDSDYNAMIC *dyn)
Frees dynamic statement and remove from TDS.
Definition: mem.c:196
TDS_USMALLINT tds_config_verstr(const char *tdsver, TDSCONNECTION *connection)
Set TDS version from given string.
Definition: config.c:766
TDSPARAMINFO * res_info
query results
Definition: tds.h:1265
TDSICONV * char_conv
refers to previously allocated iconv information
Definition: tds.h:1021
TDS_TINYINT column_scale
scale for decimal/numeric
Definition: tds.h:1011
TDS_TINYINT has_status
true is ret_status is valid
Definition: tds.h:1366
acknowledging an attention command (usually a cancel)
Definition: tds.h:269
int tdsdump_open(const char *filename)
Create and truncate a human readable dump file for the TDS traffic.
Definition: log.c:128
TDSPARAMINFO * params
query parameters.
Definition: tds.h:1273
DSTR password
password of account login
Definition: tds.h:895
unsigned char * tds7_crypt_pass(const unsigned char *clear_pass, size_t len, unsigned char *crypt_pass)
tds7_crypt_pass() – 'encrypt' TDS 7.0 style passwords.
Definition: login.c:932
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:319
TDS_TINYINT column_prec
precision for decimal/numeric
Definition: tds.h:1010
TDS_INT column_size
maximun size of data.
Definition: tds.h:1006
DSTR user_name
account for login
Definition: tds.h:894
int tds_cursor_dealloc(TDSSOCKET *tds, TDSCURSOR *cursor)
Send a deallocation request to server libTDS care for all deallocation stuff (memory and server curso...
Definition: query.c:3016
cilent is waiting for data
Definition: tds.h:1099
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.
Definition: util.c:186
TDS_INT weekday
day of week (0-6, 0 = sunday)
Definition: tds.h:184
struct tds_result_info TDSRESULTINFO
Hold information for any results.
client is sending request
Definition: tds.h:1098
int 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:840
int tds_quote_id(TDSSOCKET *tds, char *buffer, const char *id, int idlen)
Quote an id.
Definition: query.c:2215
char * tds_timestamp_str(char *str, int maxlen)
Definition: threadsafe.c:114
tds_end
Flags returned in TDS_DONE token.
Definition: tds.h:261
TDS_INT second
0-59
Definition: tds.h:187
TDSDYNAMIC * tds_alloc_dynamic(TDSSOCKET *tds, const char *id)
Allocate a dynamic statement.
Definition: mem.c:136
void tds_fix_connection(TDSCONNECTION *connection)
Fix configuration after reading it.
Definition: config.c:277
char * cursor_name
name of the cursor
Definition: tds.h:1222
int tds_get_varint_size(TDSSOCKET *tds, int datatype)
tds_get_varint_size() returns the size of a variable length integer returned in a TDS 7...
Definition: tds_types.h:54
int tds_process_login_tokens(TDSSOCKET *tds)
tds_process_login_tokens() is called after sending the login packet to the server.
Definition: token.c:317
void tds_set_column_type(TDSSOCKET *tds, TDSCOLUMN *curcol, int type)
Set type of column initializing all dependency.
Definition: data.c:46
Definition: tdsiconv.h:100
transaction in progress
Definition: tds.h:266
void tds_set_server(TDSLOGIN *tds_login, const char *server)
Set the servername in a TDSLOGIN structure.
Definition: login.c:122
DSTR server_realm_name
server realm name (in freetds.conf)
Definition: tds.h:892
struct tds_column TDSCOLUMN
Metadata about columns in regular and compute rows.
int tds_quote_string(TDSSOCKET *tds, char *buffer, const char *str, int len)
Quote a string.
Definition: query.c:2260
int tds_submit_query_params(TDSSOCKET *tds, const char *query, TDSPARAMINFO *params)
tds_submit_query_params() sends a language string to the database server for processing.
Definition: query.c:277
int tds_submit_execdirect(TDSSOCKET *tds, const char *query, TDSPARAMINFO *params)
Submit a prepared query with parameters.
Definition: query.c:1153
TDSDYNAMIC * cur_dyn
dynamic structure in use
Definition: tds.h:1377
int tds_get_size_by_type(int servertype)
Return the number of bytes needed by specified type.
Definition: tds_types.h:10
TDSDYNAMIC * dyns
list of dynamic allocate for this connection
Definition: tds.h:1378
void tds_free_input_params(TDSDYNAMIC *dyn)
Frees all allocated input parameters of a dynamic statement.
Definition: mem.c:178
Metadata about columns in regular and compute rows.
Definition: tds.h:996
TDS_UINT product_version
version of product (Sybase/MS and full version)
Definition: tds.h:1334
const char * tds_next_placeholder(const char *start)
Get position of next placeholder.
Definition: query.c:461
more results follow
Definition: tds.h:264
_TDS_STATE
values for tds->state
Definition: tds.h:1095
int tds_submit_rpc(TDSSOCKET *tds, const char *rpc_name, TDSPARAMINFO *params)
tds_submit_rpc() call a RPC from server.
Definition: query.c:2054
struct tds_cursor * next
next in linked list, keep first
Definition: tds.h:1219
TDS_INT month
month number (0-11)
Definition: tds.h:180
void tds_set_param_type(TDSSOCKET *tds, TDSCOLUMN *curcol, TDS_SERVER_TYPE type)
Set type of column initializing all dependency.
Definition: data.c:67
TDSCURSOR * cur_cursor
cursor in use
Definition: tds.h:1364
TDSAUTHENTICATION * tds_ntlm_get_auth(TDSSOCKET *tds)
Build a NTLMSPP packet to send to server.
Definition: challenge.c:736
TDS_INT minute
0-59
Definition: tds.h:186
unsigned int in_buf_max
allocated input buffer
Definition: tds.h:1345
int tds_read_packet(TDSSOCKET *tds)
Read in one 'packet' from the server.
Definition: net.c:517
struct tds_compiletime_settings TDS_COMPILETIME_SETTINGS
A structure to hold all the compile-time settings.
SQL server server error.
Definition: tds.h:271
int tds_iconv_alloc(TDSSOCKET *tds)
Allocate iconv stuff.
Definition: iconv.c:269
char * tds_get_homedir(void)
Get user home directory.
Definition: threadsafe.c:523
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:60
TDSCONNECTION * tds_alloc_connection(TDSLOCALE *locale)
Allocate space for configure structure and initialize with default values.
Definition: mem.c:805
TDS 8.0 collation informations.
Definition: tds.h:952
Information relevant to libiconv.
Definition: tds.h:974
TDS_INT column_cur_size
size written in variable (ie: char, text, binary).
Definition: tds.h:1044
tds_bcp_directions
bcp direction
Definition: tds.h:1654
TDSCONNECTION * 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:157
DSTR server_charset
charset of server
Definition: tds.h:888
struct tds_dynamic * next
next in linked list, keep first
Definition: tds.h:1255
results are from a stored procedure
Definition: tds.h:267