FreeTDS API

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;
36 } TDS_OLD_MONEY;
37
38 typedef union tdsmoney
39 {
40 TDS_OLD_MONEY tdsoldmoney;
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;
59 } TDS_DATETIME4;
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 #define TDS_ENV_ROUTING 20
137
138 /* Microsoft internal stored procedure id's */
139 #define TDS_SP_CURSOR 1
140 #define TDS_SP_CURSOROPEN 2
141 #define TDS_SP_CURSORPREPARE 3
142 #define TDS_SP_CURSOREXECUTE 4
143 #define TDS_SP_CURSORPREPEXEC 5
144 #define TDS_SP_CURSORUNPREPARE 6
145 #define TDS_SP_CURSORFETCH 7
146 #define TDS_SP_CURSOROPTION 8
147 #define TDS_SP_CURSORCLOSE 9
148 #define TDS_SP_EXECUTESQL 10
149 #define TDS_SP_PREPARE 11
150 #define TDS_SP_EXECUTE 12
151 #define TDS_SP_PREPEXEC 13
152 #define TDS_SP_PREPEXECRPC 14
153 #define TDS_SP_UNPREPARE 15
154
155 /*
156 * <rant> Sybase does an awful job of this stuff, non null ints of size 1 2
157 * and 4 have there own codes but nullable ints are lumped into INTN
158 * sheesh! </rant>
159 */
160 typedef enum
161 {
162 SYBCHAR = 47, /* 0x2F */
163 SYBVARCHAR = 39, /* 0x27 */
164 SYBINTN = 38, /* 0x26 */
165 SYBINT1 = 48, /* 0x30 */
166 SYBINT2 = 52, /* 0x34 */
167 SYBINT4 = 56, /* 0x38 */
168 SYBFLT8 = 62, /* 0x3E */
169 SYBDATETIME = 61, /* 0x3D */
170 SYBBIT = 50, /* 0x32 */
171 SYBTEXT = 35, /* 0x23 */
172 SYBNTEXT = 99, /* 0x63 */
173 SYBIMAGE = 34, /* 0x22 */
174 SYBMONEY4 = 122, /* 0x7A */
175 SYBMONEY = 60, /* 0x3C */
176 SYBDATETIME4 = 58, /* 0x3A */
177 SYBREAL = 59, /* 0x3B */
178 SYBBINARY = 45, /* 0x2D */
179 SYBVOID = 31, /* 0x1F */
180 SYBVARBINARY = 37, /* 0x25 */
181 SYBBITN = 104, /* 0x68 */
182 SYBNUMERIC = 108, /* 0x6C */
183 SYBDECIMAL = 106, /* 0x6A */
184 SYBFLTN = 109, /* 0x6D */
185 SYBMONEYN = 110, /* 0x6E */
186 SYBDATETIMN = 111, /* 0x6F */
187
188 /*
189 * MS only types
190 */
191 SYBNVARCHAR = 103, /* 0x67 */
192 SYBINT8 = 127, /* 0x7F */
193 XSYBCHAR = 175, /* 0xAF */
194 XSYBVARCHAR = 167, /* 0xA7 */
195 XSYBNVARCHAR = 231, /* 0xE7 */
196 XSYBNCHAR = 239, /* 0xEF */
197 XSYBVARBINARY = 165, /* 0xA5 */
198 XSYBBINARY = 173, /* 0xAD */
199 SYBUNIQUE = 36, /* 0x24 */
200 SYBVARIANT = 98, /* 0x62 */
201 SYBMSUDT = 240, /* 0xF0 */
202 SYBMSXML = 241, /* 0xF1 */
203 SYBMSDATE = 40, /* 0x28 */
204 SYBMSTIME = 41, /* 0x29 */
205 SYBMSDATETIME2 = 42, /* 0x2a */
206 SYBMSDATETIMEOFFSET = 43,/* 0x2b */
207
208 /*
209 * Sybase only types
210 */
211 SYBLONGBINARY = 225, /* 0xE1 */
212 SYBUINT1 = 64, /* 0x40 */
213 SYBUINT2 = 65, /* 0x41 */
214 SYBUINT4 = 66, /* 0x42 */
215 SYBUINT8 = 67, /* 0x43 */
216 SYBBLOB = 36, /* 0x24 */
217 SYBBOUNDARY = 104, /* 0x68 */
218 SYBDATE = 49, /* 0x31 */
219 SYBDATEN = 123, /* 0x7B */
220 SYB5INT8 = 191, /* 0xBF */
221 SYBINTERVAL = 46, /* 0x2E */
222 SYBLONGCHAR = 175, /* 0xAF */
223 SYBSENSITIVITY = 103, /* 0x67 */
224 SYBSINT1 = 176, /* 0xB0 */
225 SYBTIME = 51, /* 0x33 */
226 SYBTIMEN = 147, /* 0x93 */
227 SYBUINTN = 68, /* 0x44 */
228 SYBUNITEXT = 174, /* 0xAE */
229 SYBXML = 163, /* 0xA3 */
230 SYB5BIGDATETIME = 187, /* 0xBB */
231 SYB5BIGTIME = 188, /* 0xBC */
232
233 } TDS_SERVER_TYPE;
234
235 typedef enum
236 {
237 USER_UNICHAR_TYPE = 34, /* 0x22 */
238 USER_UNIVARCHAR_TYPE = 35 /* 0x23 */
239 } TDS_USER_TYPE;
240
241 /* compute operator */
242 #define SYBAOPCNT 75 /* 0x4B */
243 #define SYBAOPCNTU 76 /* 0x4C, obsolete */
244 #define SYBAOPSUM 77 /* 0x4D */
245 #define SYBAOPSUMU 78 /* 0x4E, obsolete */
246 #define SYBAOPAVG 79 /* 0x4F */
247 #define SYBAOPAVGU 80 /* 0x50, obsolete */
248 #define SYBAOPMIN 81 /* 0x51 */
249 #define SYBAOPMAX 82 /* 0x52 */
250
251 /* mssql2k compute operator */
252 #define SYBAOPCNT_BIG 9 /* 0x09 */
253 #define SYBAOPSTDEV 48 /* 0x30 */
254 #define SYBAOPSTDEVP 49 /* 0x31 */
255 #define SYBAOPVAR 50 /* 0x32 */
256 #define SYBAOPVARP 51 /* 0x33 */
257 #define SYBAOPCHECKSUM_AGG 114 /* 0x72 */
258
262 typedef enum
263 {
264 TDS_OPT_SET = 1
265 , TDS_OPT_DEFAULT = 2
266 , TDS_OPT_LIST = 3
267 , TDS_OPT_INFO = 4
268 } TDS_OPTION_CMD;
269
270 typedef enum
271 {
272 TDS_OPT_DATEFIRST = 1 /* 0x01 */
273 , TDS_OPT_TEXTSIZE = 2 /* 0x02 */
274 , TDS_OPT_STAT_TIME = 3 /* 0x03 */
275 , TDS_OPT_STAT_IO = 4 /* 0x04 */
276 , TDS_OPT_ROWCOUNT = 5 /* 0x05 */
277 , TDS_OPT_NATLANG = 6 /* 0x06 */
278 , TDS_OPT_DATEFORMAT = 7 /* 0x07 */
279 , TDS_OPT_ISOLATION = 8 /* 0x08 */
280 , TDS_OPT_AUTHON = 9 /* 0x09 */
281 , TDS_OPT_CHARSET = 10 /* 0x0a */
282 , TDS_OPT_SHOWPLAN = 13 /* 0x0d */
283 , TDS_OPT_NOEXEC = 14 /* 0x0e */
284 , TDS_OPT_ARITHIGNOREON = 15 /* 0x0f */
285 , TDS_OPT_ARITHABORTON = 17 /* 0x11 */
286 , TDS_OPT_PARSEONLY = 18 /* 0x12 */
287 , TDS_OPT_GETDATA = 20 /* 0x14 */
288 , TDS_OPT_NOCOUNT = 21 /* 0x15 */
289 , TDS_OPT_FORCEPLAN = 23 /* 0x17 */
290 , TDS_OPT_FORMATONLY = 24 /* 0x18 */
291 , TDS_OPT_CHAINXACTS = 25 /* 0x19 */
292 , TDS_OPT_CURCLOSEONXACT = 26 /* 0x1a */
293 , TDS_OPT_FIPSFLAG = 27 /* 0x1b */
294 , TDS_OPT_RESTREES = 28 /* 0x1c */
295 , TDS_OPT_IDENTITYON = 29 /* 0x1d */
296 , TDS_OPT_CURREAD = 30 /* 0x1e */
297 , TDS_OPT_CURWRITE = 31 /* 0x1f */
298 , TDS_OPT_IDENTITYOFF = 32 /* 0x20 */
299 , TDS_OPT_AUTHOFF = 33 /* 0x21 */
300 , TDS_OPT_ANSINULL = 34 /* 0x22 */
301 , TDS_OPT_QUOTED_IDENT = 35 /* 0x23 */
302 , TDS_OPT_ARITHIGNOREOFF = 36 /* 0x24 */
303 , TDS_OPT_ARITHABORTOFF = 37 /* 0x25 */
304 , TDS_OPT_TRUNCABORT = 38 /* 0x26 */
305 } TDS_OPTION;
306
307 enum {
308 TDS_OPT_ARITHOVERFLOW = 0x01,
309 TDS_OPT_NUMERICTRUNC = 0x02
310 };
311
312 enum TDS_OPT_DATEFIRST_CHOICE
313 {
314 TDS_OPT_MONDAY = 1, TDS_OPT_TUESDAY = 2, TDS_OPT_WEDNESDAY = 3, TDS_OPT_THURSDAY = 4, TDS_OPT_FRIDAY = 5, TDS_OPT_SATURDAY =
315 6, TDS_OPT_SUNDAY = 7
316 };
317
318 enum TDS_OPT_DATEFORMAT_CHOICE
319 {
320 TDS_OPT_FMTMDY = 1, TDS_OPT_FMTDMY = 2, TDS_OPT_FMTYMD = 3, TDS_OPT_FMTYDM = 4, TDS_OPT_FMTMYD = 5, TDS_OPT_FMTDYM = 6
321 };
322 enum TDS_OPT_ISOLATION_CHOICE
323 {
324 TDS_OPT_LEVEL0 = 0,
325 TDS_OPT_LEVEL1 = 1,
326 TDS_OPT_LEVEL2 = 2,
327 TDS_OPT_LEVEL3 = 3
328 };
329
330
331 typedef enum tds_packet_type
332 {
333 TDS_QUERY = 1,
334 TDS_LOGIN = 2,
335 TDS_RPC = 3,
336 TDS_REPLY = 4,
337 TDS_CANCEL = 6,
338 TDS_BULK = 7,
339 TDS7_TRANS = 14, /* transaction management */
340 TDS_NORMAL = 15,
341 TDS7_LOGIN = 16,
342 TDS7_AUTH = 17,
343 TDS71_PRELOGIN = 18,
344 TDS72_SMP = 0x53
345 } TDS_PACKET_TYPE;
346
350 typedef struct
351 {
352 TDS_USMALLINT locale_id; /* master..syslanguages.lcid */
353 TDS_USMALLINT flags;
354 TDS_UCHAR charset_id; /* or zero */
355 } TDS71_COLLATION;
356
360 typedef struct
361 {
362 TDS_UCHAR signature; /* TDS72_SMP */
363 TDS_UCHAR type;
364 TDS_USMALLINT sid;
365 TDS_UINT size;
366 TDS_UINT seq;
367 TDS_UINT wnd;
368 } TDS72_SMP_HEADER;
369
370 enum {
371 TDS_SMP_SYN = 1,
372 TDS_SMP_ACK = 2,
373 TDS_SMP_FIN = 4,
374 TDS_SMP_DATA = 8,
375 };
376
377 /* SF stands for "sort flag" */
378 #define TDS_SF_BIN (TDS_USMALLINT) 0x100
379 #define TDS_SF_WIDTH_INSENSITIVE (TDS_USMALLINT) 0x080
380 #define TDS_SF_KATATYPE_INSENSITIVE (TDS_USMALLINT) 0x040
381 #define TDS_SF_ACCENT_SENSITIVE (TDS_USMALLINT) 0x020
382 #define TDS_SF_CASE_INSENSITIVE (TDS_USMALLINT) 0x010
383
384 /* UT stands for user type */
385 #define TDS_UT_TIMESTAMP 80
386
387
388 /* mssql login options flags */
389 enum option_flag1_values {
390 TDS_BYTE_ORDER_X86 = 0,
391 TDS_CHARSET_ASCII = 0,
392 TDS_DUMPLOAD_ON = 0,
393 TDS_FLOAT_IEEE_754 = 0,
394 TDS_INIT_DB_WARN = 0,
395 TDS_SET_LANG_OFF = 0,
396 TDS_USE_DB_SILENT = 0,
397 TDS_BYTE_ORDER_68000 = 0x01,
398 TDS_CHARSET_EBDDIC = 0x02,
399 TDS_FLOAT_VAX = 0x04,
400 TDS_FLOAT_ND5000 = 0x08,
401 TDS_DUMPLOAD_OFF = 0x10, /* prevent BCP */
402 TDS_USE_DB_NOTIFY = 0x20,
403 TDS_INIT_DB_FATAL = 0x40,
404 TDS_SET_LANG_ON = 0x80
405 };
406
407 enum option_flag2_values {
408 TDS_INIT_LANG_WARN = 0,
409 TDS_INTEGRATED_SECURTY_OFF = 0,
410 TDS_ODBC_OFF = 0,
411 TDS_USER_NORMAL = 0, /* SQL Server login */
412 TDS_INIT_LANG_REQUIRED = 0x01,
413 TDS_ODBC_ON = 0x02,
414 TDS_TRANSACTION_BOUNDARY71 = 0x04, /* removed in TDS 7.2 */
415 TDS_CACHE_CONNECT71 = 0x08, /* removed in TDS 7.2 */
416 TDS_USER_SERVER = 0x10, /* reserved */
417 TDS_USER_REMUSER = 0x20, /* DQ login */
418 TDS_USER_SQLREPL = 0x40, /* replication login */
419 TDS_INTEGRATED_SECURITY_ON = 0x80
420 };
421
422 enum option_flag3_values {
423 TDS_RESTRICTED_COLLATION = 0,
424 TDS_CHANGE_PASSWORD = 0x01, /* TDS 7.2 */
425 TDS_SEND_YUKON_BINARY_XML = 0x02, /* TDS 7.2 */
426 TDS_REQUEST_USER_INSTANCE = 0x04, /* TDS 7.2 */
427 TDS_UNKNOWN_COLLATION_HANDLING = 0x08, /* TDS 7.3 */
428 TDS_EXTENSION = 0x10, /* TDS 7.4 */
429 };
430
431 enum type_flags {
432 TDS_OLEDB_ON = 0x10,
433 TDS_READONLY_INTENT = 0x20,
434 };
435
436 /* Sybase dynamic types */
437 enum dynamic_types {
438 TDS_DYN_PREPARE = 0x01,
439 TDS_DYN_EXEC = 0x02,
440 TDS_DYN_DEALLOC = 0x04,
441 TDS_DYN_EXEC_IMMED = 0x08,
442 TDS_DYN_PROCNAME = 0x10,
443 TDS_DYN_ACK = 0x20,
444 TDS_DYN_DESCIN = 0x40,
445 TDS_DYN_DESCOUT = 0x80,
446 };
447
448 /* http://jtds.sourceforge.net/apiCursors.html */
449 /* Cursor scroll option, must be one of 0x01 - 0x10, OR'd with other bits */
450 enum {
451 TDS_CUR_TYPE_KEYSET = 0x0001, /* default */
452 TDS_CUR_TYPE_DYNAMIC = 0x0002,
453 TDS_CUR_TYPE_FORWARD = 0x0004,
454 TDS_CUR_TYPE_STATIC = 0x0008,
455 TDS_CUR_TYPE_FASTFORWARDONLY = 0x0010,
456 TDS_CUR_TYPE_PARAMETERIZED = 0x1000,
457 TDS_CUR_TYPE_AUTO_FETCH = 0x2000
458 };
459
460 enum {
461 TDS_CUR_CONCUR_READ_ONLY = 1,
462 TDS_CUR_CONCUR_SCROLL_LOCKS = 2,
463 TDS_CUR_CONCUR_OPTIMISTIC = 4, /* default */
464 TDS_CUR_CONCUR_OPTIMISTIC_VALUES = 8
465 };
466
467 /* TDS 4/5 login*/
468 #define TDS_MAXNAME 30 /* maximum login name lenghts */
469 #define TDS_PROGNLEN 10 /* maximum program lenght */
470 #define TDS_PKTLEN 6 /* maximum packet lenght in login */
471
472 /* TDS 5 login security flags */
473 enum {
474 TDS5_SEC_LOG_ENCRYPT = 1,
475 TDS5_SEC_LOG_CHALLENGE = 2,
476 TDS5_SEC_LOG_LABELS = 4,
477 TDS5_SEC_LOG_APPDEFINED = 8,
478 TDS5_SEC_LOG_SECSESS = 16,
479 TDS5_SEC_LOG_ENCRYPT2 = 32,
480 TDS5_SEC_LOG_NONCE = 128
481 };
tdsdatetime
Definition: proto.h:49
tdsoldmoney
Definition: proto.h:32
tdsunique
Definition: proto.h:61
tdsmoney4
Definition: proto.h:44
tdsnumeric
Definition: proto.h:25
TDS72_SMP_HEADER
TDS 7.2 SMP packet header.
Definition: proto.h:360
tdsdatetime4
Definition: proto.h:55
tdsmoney
Definition: proto.h:38
TDS71_COLLATION
TDS 7.1 collation informations.
Definition: proto.h:350