FreeTDS API: include/freetds/proto.h Source File

FreeTDS API

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

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