FreeTDS API
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
proto.h
1 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Brian Bruns
3  * Copyright (C) 2010, 2011 Frediano Ziglio
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 
21 /*
22  * This file contains defines and structures strictly related to TDS protocol
23  */
24 
25 typedef struct tdsnumeric
26 {
27  unsigned char precision;
28  unsigned char scale;
29  unsigned char array[33];
30 } TDS_NUMERIC;
31 
32 typedef struct tdsoldmoney
33 {
34  TDS_INT mnyhigh;
35  TDS_UINT mnylow;
37 
38 typedef union tdsmoney
39 {
41  TDS_INT8 mny;
42 } TDS_MONEY;
43 
44 typedef struct tdsmoney4
45 {
46  TDS_INT mny4;
47 } TDS_MONEY4;
48 
49 typedef struct tdsdatetime
50 {
51  TDS_INT dtdays;
52  TDS_INT dttime;
53 } TDS_DATETIME;
54 
55 typedef struct tdsdatetime4
56 {
57  TDS_USMALLINT days;
58  TDS_USMALLINT minutes;
60 
61 typedef struct tdsunique
62 {
63  TDS_UINT Data1;
64  TDS_USMALLINT Data2;
65  TDS_USMALLINT Data3;
66  TDS_UCHAR Data4[8];
67 } TDS_UNIQUE;
68 
69 typedef TDS_INT TDS_DATE;
70 typedef TDS_INT TDS_TIME;
71 
72 typedef TDS_UINT8 TDS_BIGTIME;
73 typedef TDS_UINT8 TDS_BIGDATETIME;
74 
75 #define TDS5_PARAMFMT2_TOKEN 32 /* 0x20 */
76 #define TDS_LANGUAGE_TOKEN 33 /* 0x21 TDS 5.0 only */
77 #define TDS_ORDERBY2_TOKEN 34 /* 0x22 */
78 #define TDS_ROWFMT2_TOKEN 97 /* 0x61 TDS 5.0 only */
79 #define TDS_MSG_TOKEN 101 /* 0x65 TDS 5.0 only */
80 #define TDS_LOGOUT_TOKEN 113 /* 0x71 TDS 5.0 only? ct_close() */
81 #define TDS_RETURNSTATUS_TOKEN 121 /* 0x79 */
82 #define TDS_PROCID_TOKEN 124 /* 0x7C TDS 4.2 only - TDS_PROCID */
83 #define TDS7_RESULT_TOKEN 129 /* 0x81 TDS 7.0 only */
84 #define TDS7_COMPUTE_RESULT_TOKEN 136 /* 0x88 TDS 7.0 only */
85 #define TDS_COLNAME_TOKEN 160 /* 0xA0 TDS 4.2 only */
86 #define TDS_COLFMT_TOKEN 161 /* 0xA1 TDS 4.2 only - TDS_COLFMT */
87 #define TDS_DYNAMIC2_TOKEN 163 /* 0xA3 */
88 #define TDS_TABNAME_TOKEN 164 /* 0xA4 */
89 #define TDS_COLINFO_TOKEN 165 /* 0xA5 */
90 #define TDS_OPTIONCMD_TOKEN 166 /* 0xA6 */
91 #define TDS_COMPUTE_NAMES_TOKEN 167 /* 0xA7 */
92 #define TDS_COMPUTE_RESULT_TOKEN 168 /* 0xA8 */
93 #define TDS_ORDERBY_TOKEN 169 /* 0xA9 TDS_ORDER */
94 #define TDS_ERROR_TOKEN 170 /* 0xAA */
95 #define TDS_INFO_TOKEN 171 /* 0xAB */
96 #define TDS_PARAM_TOKEN 172 /* 0xAC RETURNVALUE? */
97 #define TDS_LOGINACK_TOKEN 173 /* 0xAD */
98 #define TDS_CONTROL_FEATUREEXTACK_TOKEN \
99  174 /* 0xAE TDS_CONTROL/TDS_FEATUREEXTACK */
100 #define TDS_ROW_TOKEN 209 /* 0xD1 */
101 #define TDS_NBC_ROW_TOKEN 210 /* 0xD2 as of TDS 7.3.B */
102 #define TDS_CMP_ROW_TOKEN 211 /* 0xD3 */
103 #define TDS5_PARAMS_TOKEN 215 /* 0xD7 TDS 5.0 only */
104 #define TDS_CAPABILITY_TOKEN 226 /* 0xE2 */
105 #define TDS_ENVCHANGE_TOKEN 227 /* 0xE3 */
106 #define TDS_SESSIONSTATE_TOKEN 228 /* 0xE4 TDS 7.4 */
107 #define TDS_EED_TOKEN 229 /* 0xE5 */
108 #define TDS_DBRPC_TOKEN 230 /* 0xE6 TDS 5.0 only */
109 #define TDS5_DYNAMIC_TOKEN 231 /* 0xE7 TDS 5.0 only */
110 #define TDS5_PARAMFMT_TOKEN 236 /* 0xEC TDS 5.0 only */
111 #define TDS_AUTH_TOKEN 237 /* 0xED TDS 7.0 only */
112 #define TDS_RESULT_TOKEN 238 /* 0xEE */
113 #define TDS_DONE_TOKEN 253 /* 0xFD TDS_DONE */
114 #define TDS_DONEPROC_TOKEN 254 /* 0xFE TDS_DONEPROC */
115 #define TDS_DONEINPROC_TOKEN 255 /* 0xFF TDS_DONEINPROC */
116 
117 /* CURSOR support: TDS 5.0 only*/
118 #define TDS_CURCLOSE_TOKEN 128 /* 0x80 TDS 5.0 only */
119 #define TDS_CURDELETE_TOKEN 129 /* 0x81 TDS 5.0 only */
120 #define TDS_CURFETCH_TOKEN 130 /* 0x82 TDS 5.0 only */
121 #define TDS_CURINFO_TOKEN 131 /* 0x83 TDS 5.0 only */
122 #define TDS_CUROPEN_TOKEN 132 /* 0x84 TDS 5.0 only */
123 #define TDS_CURDECLARE_TOKEN 134 /* 0x86 TDS 5.0 only */
124 
125 
126 /* environment type field */
127 #define TDS_ENV_DATABASE 1
128 #define TDS_ENV_LANG 2
129 #define TDS_ENV_CHARSET 3
130 #define TDS_ENV_PACKSIZE 4
131 #define TDS_ENV_LCID 5
132 #define TDS_ENV_SQLCOLLATION 7
133 #define TDS_ENV_BEGINTRANS 8
134 #define TDS_ENV_COMMITTRANS 9
135 #define TDS_ENV_ROLLBACKTRANS 10
136 
137 /* Microsoft internal stored procedure id's */
138 #define TDS_SP_CURSOR 1
139 #define TDS_SP_CURSOROPEN 2
140 #define TDS_SP_CURSORPREPARE 3
141 #define TDS_SP_CURSOREXECUTE 4
142 #define TDS_SP_CURSORPREPEXEC 5
143 #define TDS_SP_CURSORUNPREPARE 6
144 #define TDS_SP_CURSORFETCH 7
145 #define TDS_SP_CURSOROPTION 8
146 #define TDS_SP_CURSORCLOSE 9
147 #define TDS_SP_EXECUTESQL 10
148 #define TDS_SP_PREPARE 11
149 #define TDS_SP_EXECUTE 12
150 #define TDS_SP_PREPEXEC 13
151 #define TDS_SP_PREPEXECRPC 14
152 #define TDS_SP_UNPREPARE 15
153 
154 /*
155  * <rant> Sybase does an awful job of this stuff, non null ints of size 1 2
156  * and 4 have there own codes but nullable ints are lumped into INTN
157  * sheesh! </rant>
158  */
159 typedef enum
160 {
161  SYBCHAR = 47, /* 0x2F */
162  SYBVARCHAR = 39, /* 0x27 */
163  SYBINTN = 38, /* 0x26 */
164  SYBINT1 = 48, /* 0x30 */
165  SYBINT2 = 52, /* 0x34 */
166  SYBINT4 = 56, /* 0x38 */
167  SYBFLT8 = 62, /* 0x3E */
168  SYBDATETIME = 61, /* 0x3D */
169  SYBBIT = 50, /* 0x32 */
170  SYBTEXT = 35, /* 0x23 */
171  SYBNTEXT = 99, /* 0x63 */
172  SYBIMAGE = 34, /* 0x22 */
173  SYBMONEY4 = 122, /* 0x7A */
174  SYBMONEY = 60, /* 0x3C */
175  SYBDATETIME4 = 58, /* 0x3A */
176  SYBREAL = 59, /* 0x3B */
177  SYBBINARY = 45, /* 0x2D */
178  SYBVOID = 31, /* 0x1F */
179  SYBVARBINARY = 37, /* 0x25 */
180  SYBBITN = 104, /* 0x68 */
181  SYBNUMERIC = 108, /* 0x6C */
182  SYBDECIMAL = 106, /* 0x6A */
183  SYBFLTN = 109, /* 0x6D */
184  SYBMONEYN = 110, /* 0x6E */
185  SYBDATETIMN = 111, /* 0x6F */
186 
187 /*
188  * MS only types
189  */
190  SYBNVARCHAR = 103, /* 0x67 */
191  SYBINT8 = 127, /* 0x7F */
192  XSYBCHAR = 175, /* 0xAF */
193  XSYBVARCHAR = 167, /* 0xA7 */
194  XSYBNVARCHAR = 231, /* 0xE7 */
195  XSYBNCHAR = 239, /* 0xEF */
196  XSYBVARBINARY = 165, /* 0xA5 */
197  XSYBBINARY = 173, /* 0xAD */
198  SYBUNIQUE = 36, /* 0x24 */
199  SYBVARIANT = 98, /* 0x62 */
200  SYBMSUDT = 240, /* 0xF0 */
201  SYBMSXML = 241, /* 0xF1 */
202  SYBMSDATE = 40, /* 0x28 */
203  SYBMSTIME = 41, /* 0x29 */
204  SYBMSDATETIME2 = 42, /* 0x2a */
205  SYBMSDATETIMEOFFSET = 43,/* 0x2b */
206 
207 /*
208  * Sybase only types
209  */
210  SYBLONGBINARY = 225, /* 0xE1 */
211  SYBUINT1 = 64, /* 0x40 */
212  SYBUINT2 = 65, /* 0x41 */
213  SYBUINT4 = 66, /* 0x42 */
214  SYBUINT8 = 67, /* 0x43 */
215  SYBBLOB = 36, /* 0x24 */
216  SYBBOUNDARY = 104, /* 0x68 */
217  SYBDATE = 49, /* 0x31 */
218  SYBDATEN = 123, /* 0x7B */
219  SYB5INT8 = 191, /* 0xBF */
220  SYBINTERVAL = 46, /* 0x2E */
221  SYBLONGCHAR = 175, /* 0xAF */
222  SYBSENSITIVITY = 103, /* 0x67 */
223  SYBSINT1 = 176, /* 0xB0 */
224  SYBTIME = 51, /* 0x33 */
225  SYBTIMEN = 147, /* 0x93 */
226  SYBUINTN = 68, /* 0x44 */
227  SYBUNITEXT = 174, /* 0xAE */
228  SYBXML = 163, /* 0xA3 */
229  SYB5BIGDATETIME = 187, /* 0xBB */
230  SYB5BIGTIME = 188, /* 0xBC */
231 
232 } TDS_SERVER_TYPE;
233 
234 typedef enum
235 {
236  USER_UNICHAR_TYPE = 34, /* 0x22 */
237  USER_UNIVARCHAR_TYPE = 35 /* 0x23 */
238 } TDS_USER_TYPE;
239 
240 /* compute operator */
241 #define SYBAOPCNT 75 /* 0x4B */
242 #define SYBAOPCNTU 76 /* 0x4C, obsolete */
243 #define SYBAOPSUM 77 /* 0x4D */
244 #define SYBAOPSUMU 78 /* 0x4E, obsolete */
245 #define SYBAOPAVG 79 /* 0x4F */
246 #define SYBAOPAVGU 80 /* 0x50, obsolete */
247 #define SYBAOPMIN 81 /* 0x51 */
248 #define SYBAOPMAX 82 /* 0x52 */
249 
250 /* mssql2k compute operator */
251 #define SYBAOPCNT_BIG 9 /* 0x09 */
252 #define SYBAOPSTDEV 48 /* 0x30 */
253 #define SYBAOPSTDEVP 49 /* 0x31 */
254 #define SYBAOPVAR 50 /* 0x32 */
255 #define SYBAOPVARP 51 /* 0x33 */
256 #define SYBAOPCHECKSUM_AGG 114 /* 0x72 */
257 
261 typedef enum
262 {
263  TDS_OPT_SET = 1
264  , TDS_OPT_DEFAULT = 2
265  , TDS_OPT_LIST = 3
266  , TDS_OPT_INFO = 4
267 } TDS_OPTION_CMD;
268 
269 typedef enum
270 {
271  TDS_OPT_DATEFIRST = 1 /* 0x01 */
272  , TDS_OPT_TEXTSIZE = 2 /* 0x02 */
273  , TDS_OPT_STAT_TIME = 3 /* 0x03 */
274  , TDS_OPT_STAT_IO = 4 /* 0x04 */
275  , TDS_OPT_ROWCOUNT = 5 /* 0x05 */
276  , TDS_OPT_NATLANG = 6 /* 0x06 */
277  , TDS_OPT_DATEFORMAT = 7 /* 0x07 */
278  , TDS_OPT_ISOLATION = 8 /* 0x08 */
279  , TDS_OPT_AUTHON = 9 /* 0x09 */
280  , TDS_OPT_CHARSET = 10 /* 0x0a */
281  , TDS_OPT_SHOWPLAN = 13 /* 0x0d */
282  , TDS_OPT_NOEXEC = 14 /* 0x0e */
283  , TDS_OPT_ARITHIGNOREON = 15 /* 0x0f */
284  , TDS_OPT_ARITHABORTON = 17 /* 0x11 */
285  , TDS_OPT_PARSEONLY = 18 /* 0x12 */
286  , TDS_OPT_GETDATA = 20 /* 0x14 */
287  , TDS_OPT_NOCOUNT = 21 /* 0x15 */
288  , TDS_OPT_FORCEPLAN = 23 /* 0x17 */
289  , TDS_OPT_FORMATONLY = 24 /* 0x18 */
290  , TDS_OPT_CHAINXACTS = 25 /* 0x19 */
291  , TDS_OPT_CURCLOSEONXACT = 26 /* 0x1a */
292  , TDS_OPT_FIPSFLAG = 27 /* 0x1b */
293  , TDS_OPT_RESTREES = 28 /* 0x1c */
294  , TDS_OPT_IDENTITYON = 29 /* 0x1d */
295  , TDS_OPT_CURREAD = 30 /* 0x1e */
296  , TDS_OPT_CURWRITE = 31 /* 0x1f */
297  , TDS_OPT_IDENTITYOFF = 32 /* 0x20 */
298  , TDS_OPT_AUTHOFF = 33 /* 0x21 */
299  , TDS_OPT_ANSINULL = 34 /* 0x22 */
300  , TDS_OPT_QUOTED_IDENT = 35 /* 0x23 */
301  , TDS_OPT_ARITHIGNOREOFF = 36 /* 0x24 */
302  , TDS_OPT_ARITHABORTOFF = 37 /* 0x25 */
303  , TDS_OPT_TRUNCABORT = 38 /* 0x26 */
304 } TDS_OPTION;
305 
306 enum {
307  TDS_OPT_ARITHOVERFLOW = 0x01,
308  TDS_OPT_NUMERICTRUNC = 0x02
309 };
310 
311 enum TDS_OPT_DATEFIRST_CHOICE
312 {
313  TDS_OPT_MONDAY = 1, TDS_OPT_TUESDAY = 2, TDS_OPT_WEDNESDAY = 3, TDS_OPT_THURSDAY = 4, TDS_OPT_FRIDAY = 5, TDS_OPT_SATURDAY =
314  6, TDS_OPT_SUNDAY = 7
315 };
316 
317 enum TDS_OPT_DATEFORMAT_CHOICE
318 {
319  TDS_OPT_FMTMDY = 1, TDS_OPT_FMTDMY = 2, TDS_OPT_FMTYMD = 3, TDS_OPT_FMTYDM = 4, TDS_OPT_FMTMYD = 5, TDS_OPT_FMTDYM = 6
320 };
321 enum TDS_OPT_ISOLATION_CHOICE
322 {
323  TDS_OPT_LEVEL0 = 0,
324  TDS_OPT_LEVEL1 = 1,
325  TDS_OPT_LEVEL2 = 2,
326  TDS_OPT_LEVEL3 = 3
327 };
328 
329 
330 typedef enum tds_packet_type
331 {
332  TDS_QUERY = 1,
333  TDS_LOGIN = 2,
334  TDS_RPC = 3,
335  TDS_REPLY = 4,
336  TDS_CANCEL = 6,
337  TDS_BULK = 7,
338  TDS7_TRANS = 14, /* transaction management */
339  TDS_NORMAL = 15,
340  TDS7_LOGIN = 16,
341  TDS7_AUTH = 17,
342  TDS71_PRELOGIN = 18,
343  TDS72_SMP = 0x53
344 } TDS_PACKET_TYPE;
345 
349 typedef struct
350 {
351  TDS_USMALLINT locale_id; /* master..syslanguages.lcid */
352  TDS_USMALLINT flags;
353  TDS_UCHAR charset_id; /* or zero */
355 
359 typedef struct
360 {
361  TDS_UCHAR signature; /* TDS72_SMP */
362  TDS_UCHAR type;
363  TDS_USMALLINT sid;
364  TDS_UINT size;
365  TDS_UINT seq;
366  TDS_UINT wnd;
368 
369 enum {
370  TDS_SMP_SYN = 1,
371  TDS_SMP_ACK = 2,
372  TDS_SMP_FIN = 4,
373  TDS_SMP_DATA = 8,
374 };
375 
376 /* SF stands for "sort flag" */
377 #define TDS_SF_BIN (TDS_USMALLINT) 0x100
378 #define TDS_SF_WIDTH_INSENSITIVE (TDS_USMALLINT) 0x080
379 #define TDS_SF_KATATYPE_INSENSITIVE (TDS_USMALLINT) 0x040
380 #define TDS_SF_ACCENT_SENSITIVE (TDS_USMALLINT) 0x020
381 #define TDS_SF_CASE_INSENSITIVE (TDS_USMALLINT) 0x010
382 
383 /* UT stands for user type */
384 #define TDS_UT_TIMESTAMP 80
385 
386 
387 /* mssql login options flags */
388 enum option_flag1_values {
389  TDS_BYTE_ORDER_X86 = 0,
390  TDS_CHARSET_ASCII = 0,
391  TDS_DUMPLOAD_ON = 0,
392  TDS_FLOAT_IEEE_754 = 0,
393  TDS_INIT_DB_WARN = 0,
394  TDS_SET_LANG_OFF = 0,
395  TDS_USE_DB_SILENT = 0,
396  TDS_BYTE_ORDER_68000 = 0x01,
397  TDS_CHARSET_EBDDIC = 0x02,
398  TDS_FLOAT_VAX = 0x04,
399  TDS_FLOAT_ND5000 = 0x08,
400  TDS_DUMPLOAD_OFF = 0x10, /* prevent BCP */
401  TDS_USE_DB_NOTIFY = 0x20,
402  TDS_INIT_DB_FATAL = 0x40,
403  TDS_SET_LANG_ON = 0x80
404 };
405 
406 enum option_flag2_values {
407  TDS_INIT_LANG_WARN = 0,
408  TDS_INTEGRATED_SECURTY_OFF = 0,
409  TDS_ODBC_OFF = 0,
410  TDS_USER_NORMAL = 0, /* SQL Server login */
411  TDS_INIT_LANG_REQUIRED = 0x01,
412  TDS_ODBC_ON = 0x02,
413  TDS_TRANSACTION_BOUNDARY71 = 0x04, /* removed in TDS 7.2 */
414  TDS_CACHE_CONNECT71 = 0x08, /* removed in TDS 7.2 */
415  TDS_USER_SERVER = 0x10, /* reserved */
416  TDS_USER_REMUSER = 0x20, /* DQ login */
417  TDS_USER_SQLREPL = 0x40, /* replication login */
418  TDS_INTEGRATED_SECURITY_ON = 0x80
419 };
420 
421 enum option_flag3_values {
422  TDS_RESTRICTED_COLLATION = 0,
423  TDS_CHANGE_PASSWORD = 0x01, /* TDS 7.2 */
424  TDS_SEND_YUKON_BINARY_XML = 0x02, /* TDS 7.2 */
425  TDS_REQUEST_USER_INSTANCE = 0x04, /* TDS 7.2 */
426  TDS_UNKNOWN_COLLATION_HANDLING = 0x08, /* TDS 7.3 */
427  TDS_EXTENSION = 0x10, /* TDS 7.4 */
428 };
429 
430 enum type_flags {
431  TDS_OLEDB_ON = 0x10,
432  TDS_READONLY_INTENT = 0x20,
433 };
434 
435 /* Sybase dynamic types */
436 enum dynamic_types {
437  TDS_DYN_PREPARE = 0x01,
438  TDS_DYN_EXEC = 0x02,
439  TDS_DYN_DEALLOC = 0x04,
440  TDS_DYN_EXEC_IMMED = 0x08,
441  TDS_DYN_PROCNAME = 0x10,
442  TDS_DYN_ACK = 0x20,
443  TDS_DYN_DESCIN = 0x40,
444  TDS_DYN_DESCOUT = 0x80,
445 };
446 
447 /* http://jtds.sourceforge.net/apiCursors.html */
448 /* Cursor scroll option, must be one of 0x01 - 0x10, OR'd with other bits */
449 enum {
450  TDS_CUR_TYPE_KEYSET = 0x0001, /* default */
451  TDS_CUR_TYPE_DYNAMIC = 0x0002,
452  TDS_CUR_TYPE_FORWARD = 0x0004,
453  TDS_CUR_TYPE_STATIC = 0x0008,
454  TDS_CUR_TYPE_FASTFORWARDONLY = 0x0010,
455  TDS_CUR_TYPE_PARAMETERIZED = 0x1000,
456  TDS_CUR_TYPE_AUTO_FETCH = 0x2000
457 };
458 
459 enum {
460  TDS_CUR_CONCUR_READ_ONLY = 1,
461  TDS_CUR_CONCUR_SCROLL_LOCKS = 2,
462  TDS_CUR_CONCUR_OPTIMISTIC = 4, /* default */
463  TDS_CUR_CONCUR_OPTIMISTIC_VALUES = 8
464 };
465 
466 /* TDS 4/5 login*/
467 #define TDS_MAXNAME 30 /* maximum login name lenghts */
468 #define TDS_PROGNLEN 10 /* maximum program lenght */
469 #define TDS_PKTLEN 6 /* maximum packet lenght in login */
470 
471 /* TDS 5 login security flags */
472 enum {
473  TDS5_SEC_LOG_ENCRYPT = 1,
474  TDS5_SEC_LOG_CHALLENGE = 2,
475  TDS5_SEC_LOG_LABELS = 4,
476  TDS5_SEC_LOG_APPDEFINED = 8,
477  TDS5_SEC_LOG_SECSESS = 16,
478  TDS5_SEC_LOG_ENCRYPT2 = 32,
479  TDS5_SEC_LOG_NONCE = 128
480 };
TDS 7.2 SMP packet header.
Definition: proto.h:359
Definition: proto.h:49
Definition: proto.h:44
Definition: proto.h:61
TDS 7.1 collation informations.
Definition: proto.h:349
Definition: proto.h:38
Definition: proto.h:32
Definition: proto.h:55
Definition: proto.h:25