FreeTDS API
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tds.h
Go to the documentation of this file.
1 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Brian Bruns
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 
20 #ifndef _tds_h_
21 #define _tds_h_
22 
23 /* $Id: tds.h,v 1.284 2007/12/27 13:45:22 freddy77 Exp $ */
24 
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <time.h>
28 
29 /* forward declaration */
30 typedef struct tdsiconvinfo TDSICONV;
31 typedef struct tds_socket TDSSOCKET;
32 
33 #include "tdsver.h"
34 #include "tds_sysdep_public.h"
35 #ifdef _FREETDS_LIBRARY_SOURCE
36 #include "tds_sysdep_private.h"
37 #endif /* _FREETDS_LIBRARY_SOURCE */
38 
39 #ifdef __cplusplus
40 extern "C"
41 {
42 #if 0
43 }
44 #endif
45 #endif
46 
53 {
54  const char *freetds_version; /* release version of FreeTDS */
55  const char *sysconfdir; /* location of freetds.conf */
56  const char *last_update; /* latest software_version date among the modules */
57  int msdblib; /* for MS style dblib */
58  int sybase_compat; /* enable increased Open Client binary compatibility */
59  int threadsafe; /* compile for thread safety default=no */
60  int libiconv; /* search for libiconv in DIR/include and DIR/lib */
61  const char *tdsver; /* TDS protocol version (4.2/4.6/5.0/7.0/8.0) 5.0 */
62  int iodbc; /* build odbc driver against iODBC in DIR */
63  int unixodbc; /* build odbc driver against unixODBC in DIR */
64 
66 
67 struct DSTR_STRUCT {
68  char *dstr_s;
69  size_t dstr_size;
70 };
71 typedef struct DSTR_STRUCT DSTR;
72 
88 /*
89  * All references to data that touch the wire should use the following typedefs.
90  *
91  * If you have problems on 64-bit machines and the code is
92  * using a native datatype, please change it to use
93  * these. (In the TDS layer only, the API layers have their
94  * own typedefs which equate to these).
95  */
96 typedef char TDS_CHAR; /* 8-bit char */
97 typedef unsigned char TDS_UCHAR; /* 8-bit uchar */
98 typedef unsigned char TDS_TINYINT; /* 8-bit unsigned */
99 typedef tds_sysdep_int16_type TDS_SMALLINT; /* 16-bit int */
100 typedef unsigned tds_sysdep_int16_type TDS_USMALLINT; /* 16-bit unsigned */
101 typedef tds_sysdep_int32_type TDS_INT; /* 32-bit int */
102 typedef unsigned tds_sysdep_int32_type TDS_UINT; /* 32-bit unsigned */
103 typedef tds_sysdep_real32_type TDS_REAL; /* 32-bit real */
104 typedef tds_sysdep_real64_type TDS_FLOAT; /* 64-bit real */
105 typedef tds_sysdep_int64_type TDS_INT8; /* 64-bit integer */
106 typedef unsigned tds_sysdep_int64_type TDS_UINT8; /* 64-bit unsigned */
107 typedef tds_sysdep_intptr_type TDS_INTPTR;
108 
109 typedef struct tdsnumeric
110 {
111  unsigned char precision;
112  unsigned char scale;
113  unsigned char array[33];
114 } TDS_NUMERIC;
115 
116 typedef struct tdsoldmoney
117 {
118  TDS_INT mnyhigh;
119  TDS_UINT mnylow;
120 } TDS_OLD_MONEY;
121 
122 typedef union tdsmoney
123 {
125  TDS_INT8 mny;
126 } TDS_MONEY;
127 
128 typedef struct tdsmoney4
129 {
130  TDS_INT mny4;
131 } TDS_MONEY4;
132 
133 typedef struct tdsdatetime
134 {
135  TDS_INT dtdays;
136  TDS_INT dttime;
137 } TDS_DATETIME;
138 
139 typedef struct tdsdatetime4
140 {
141  TDS_USMALLINT days;
142  TDS_USMALLINT minutes;
143 } TDS_DATETIME4;
144 
145 typedef struct tdsvarbinary
146 {
147  TDS_SMALLINT len;
148  TDS_CHAR array[256];
149 } TDS_VARBINARY;
150 typedef struct tdsvarchar
151 {
152  TDS_INT len;
153  TDS_CHAR array[256];
154 } TDS_VARCHAR;
155 
156 typedef struct tdsunique
157 {
158  TDS_UINT Data1;
159  TDS_USMALLINT Data2;
160  TDS_USMALLINT Data3;
161  TDS_UCHAR Data4[8];
162 } TDS_UNIQUE;
163 
165 typedef struct tdsdaterec
166 {
167  TDS_INT year;
168  TDS_INT month;
169  TDS_INT day;
170  TDS_INT dayofyear;
171  TDS_INT weekday;
172  TDS_INT hour;
173  TDS_INT minute;
174  TDS_INT second;
175  TDS_INT millisecond;
176  TDS_INT tzone;
177 } TDSDATEREC;
178 
184 extern const int tds_numeric_bytes_per_prec[];
185 
186 #define TDS_SUCCEED 1
187 #define TDS_FAIL 0
188 #define TDS_NO_MORE_RESULTS 2
189 #define TDS_CANCELLED 3
190 
191 #define TDS_INT_CONTINUE 1
192 #define TDS_INT_CANCEL 2
193 #define TDS_INT_TIMEOUT 3
194 
195 
196 #define TDS_NO_COUNT -1
197 
198 #define TDS_ROW_RESULT 4040
199 #define TDS_PARAM_RESULT 4042
200 #define TDS_STATUS_RESULT 4043
201 #define TDS_MSG_RESULT 4044
202 #define TDS_COMPUTE_RESULT 4045
203 #define TDS_CMD_DONE 4046
204 #define TDS_CMD_SUCCEED 4047
205 #define TDS_CMD_FAIL 4048
206 #define TDS_ROWFMT_RESULT 4049
207 #define TDS_COMPUTEFMT_RESULT 4050
208 #define TDS_DESCRIBE_RESULT 4051
209 #define TDS_DONE_RESULT 4052
210 #define TDS_DONEPROC_RESULT 4053
211 #define TDS_DONEINPROC_RESULT 4054
212 #define TDS_OTHERS_RESULT 4055
213 
214 enum tds_token_results
215 {
216  TDS_TOKEN_RES_OTHERS,
217  TDS_TOKEN_RES_ROWFMT,
218  TDS_TOKEN_RES_COMPUTEFMT,
219  TDS_TOKEN_RES_PARAMFMT,
220  TDS_TOKEN_RES_DONE,
221  TDS_TOKEN_RES_ROW,
222  TDS_TOKEN_RES_COMPUTE,
223  TDS_TOKEN_RES_PROC,
224  TDS_TOKEN_RES_MSG
225 };
226 
227 #define TDS_TOKEN_FLAG(flag) TDS_RETURN_##flag = (1 << (TDS_TOKEN_RES_##flag*2)), TDS_STOPAT_##flag = (2 << (TDS_TOKEN_RES_##flag*2))
228 
229 enum tds_token_flags
230 {
231  TDS_HANDLE_ALL = 0,
232  TDS_TOKEN_FLAG(OTHERS),
233  TDS_TOKEN_FLAG(ROWFMT),
234  TDS_TOKEN_FLAG(COMPUTEFMT),
235  TDS_TOKEN_FLAG(PARAMFMT),
236  TDS_TOKEN_FLAG(DONE),
237  TDS_TOKEN_FLAG(ROW),
238  TDS_TOKEN_FLAG(COMPUTE),
239  TDS_TOKEN_FLAG(PROC),
240  TDS_TOKEN_FLAG(MSG),
241  TDS_TOKEN_RESULTS = TDS_RETURN_ROWFMT|TDS_RETURN_COMPUTEFMT|TDS_RETURN_DONE|TDS_STOPAT_ROW|TDS_STOPAT_COMPUTE|TDS_RETURN_PROC,
242  TDS_TOKEN_TRAILING = TDS_STOPAT_ROWFMT|TDS_STOPAT_COMPUTEFMT|TDS_STOPAT_ROW|TDS_STOPAT_COMPUTE|TDS_STOPAT_MSG|TDS_STOPAT_OTHERS
243 };
244 
249 {
252  , TDS_DONE_ERROR = 0x02
253  , TDS_DONE_INXACT = 0x04
254  , TDS_DONE_PROC = 0x08
255  , TDS_DONE_COUNT = 0x10
257  , TDS_DONE_EVENT = 0x40 /* part of an event notification. */
258  , TDS_DONE_SRVERROR = 0x100
260  /* after the above flags, a TDS_DONE packet has a field describing the state of the transaction */
261  , TDS_DONE_NO_TRAN = 0 /* No transaction in effect */
262  , TDS_DONE_TRAN_SUCCEED = 1 /* Transaction completed successfully */
263  , TDS_DONE_TRAN_PROGRESS= 2 /* Transaction in progress */
264  , TDS_DONE_STMT_ABORT = 3 /* A statement aborted */
265  , TDS_DONE_TRAN_ABORT = 4 /* Transaction aborted */
266 };
267 
268 
269 /*
270  * TDSERRNO is emitted by libtds to the client library's error handler
271  * (which may in turn call the client's error handler).
272  * These match the db-lib msgno, because the same values have the same meaning
273  * in db-lib and ODBC. ct-lib maps them to ct-lib numbers (todo).
274  */
275 typedef enum { TDSEICONVIU = 2400,
276  TDSEICONVAVAIL = 2401,
277  TDSEICONVO = 2402,
278  TDSEICONVI = 2403,
279  TDSEICONV2BIG = 2404,
280  TDSESYNC = 20001,
281  TDSEFCON = 20002,
282  TDSETIME = 20003,
283  TDSEREAD = 20004,
284  TDSEWRIT = 20006,
285  TDSESOCK = 20008,
286  TDSECONN = 20009,
287  TDSEPWD = 20014,
288  TDSESEOF = 20017,
289  TDSERPND = 20019,
290  TDSEBTOK = 20020,
291  TDSEOOB = 20022,
292  TDSECLOS = 20056,
293  TDSEUSCT = 20058,
294  TDSEUTDS = 20146,
295  TDSEEUNR = 20185,
296  TDSECAP = 20203,
297  TDSENEG = 20210,
298  TDSEUMSG = 20212,
299  TDSECAPTYP = 20213,
300  TDSECLOSEIN = 20292
301 } TDSERRNO;
302 
303 /*
304  * TDS_ERROR indicates a successful processing, but that a TDS_ERROR_TOKEN or TDS_EED_TOKEN error was encountered.
305  * TDS_FAIL indicates an unrecoverable failure.
306  */
307 #define TDS_ERROR 3
308 #define TDS_DONT_RETURN 42
309 
310 #define TDS5_PARAMFMT2_TOKEN 32 /* 0x20 */
311 #define TDS_LANGUAGE_TOKEN 33 /* 0x21 TDS 5.0 only */
312 #define TDS_ORDERBY2_TOKEN 34 /* 0x22 */
313 #define TDS_ROWFMT2_TOKEN 97 /* 0x61 TDS 5.0 only */
314 #define TDS_LOGOUT_TOKEN 113 /* 0x71 TDS 5.0 only? ct_close() */
315 #define TDS_RETURNSTATUS_TOKEN 121 /* 0x79 */
316 #define TDS_PROCID_TOKEN 124 /* 0x7C TDS 4.2 only - TDS_PROCID */
317 #define TDS7_RESULT_TOKEN 129 /* 0x81 TDS 7.0 only */
318 #define TDS7_COMPUTE_RESULT_TOKEN 136 /* 0x88 TDS 7.0 only */
319 #define TDS_COLNAME_TOKEN 160 /* 0xA0 TDS 4.2 only */
320 #define TDS_COLFMT_TOKEN 161 /* 0xA1 TDS 4.2 only - TDS_COLFMT */
321 #define TDS_DYNAMIC2_TOKEN 163 /* 0xA3 */
322 #define TDS_TABNAME_TOKEN 164 /* 0xA4 */
323 #define TDS_COLINFO_TOKEN 165 /* 0xA5 */
324 #define TDS_OPTIONCMD_TOKEN 166 /* 0xA6 */
325 #define TDS_COMPUTE_NAMES_TOKEN 167 /* 0xA7 */
326 #define TDS_COMPUTE_RESULT_TOKEN 168 /* 0xA8 */
327 #define TDS_ORDERBY_TOKEN 169 /* 0xA9 TDS_ORDER */
328 #define TDS_ERROR_TOKEN 170 /* 0xAA */
329 #define TDS_INFO_TOKEN 171 /* 0xAB */
330 #define TDS_PARAM_TOKEN 172 /* 0xAC RETURNVALUE? */
331 #define TDS_LOGINACK_TOKEN 173 /* 0xAD */
332 #define TDS_CONTROL_TOKEN 174 /* 0xAE TDS_CONTROL */
333 #define TDS_ROW_TOKEN 209 /* 0xD1 */
334 #define TDS_CMP_ROW_TOKEN 211 /* 0xD3 */
335 #define TDS5_PARAMS_TOKEN 215 /* 0xD7 TDS 5.0 only */
336 #define TDS_CAPABILITY_TOKEN 226 /* 0xE2 */
337 #define TDS_ENVCHANGE_TOKEN 227 /* 0xE3 */
338 #define TDS_EED_TOKEN 229 /* 0xE5 */
339 #define TDS_DBRPC_TOKEN 230 /* 0xE6 */
340 #define TDS5_DYNAMIC_TOKEN 231 /* 0xE7 TDS 5.0 only */
341 #define TDS5_PARAMFMT_TOKEN 236 /* 0xEC TDS 5.0 only */
342 #define TDS_AUTH_TOKEN 237 /* 0xED TDS 7.0 only */
343 #define TDS_RESULT_TOKEN 238 /* 0xEE */
344 #define TDS_DONE_TOKEN 253 /* 0xFD TDS_DONE */
345 #define TDS_DONEPROC_TOKEN 254 /* 0xFE TDS_DONEPROC */
346 #define TDS_DONEINPROC_TOKEN 255 /* 0xFF TDS_DONEINPROC */
347 
348 /* CURSOR support: TDS 5.0 only*/
349 #define TDS_CURCLOSE_TOKEN 128 /* 0x80 TDS 5.0 only */
350 #define TDS_CURDELETE_TOKEN 129 /* 0x81 TDS 5.0 only */
351 #define TDS_CURFETCH_TOKEN 130 /* 0x82 TDS 5.0 only */
352 #define TDS_CURINFO_TOKEN 131 /* 0x83 TDS 5.0 only */
353 #define TDS_CUROPEN_TOKEN 132 /* 0x84 TDS 5.0 only */
354 #define TDS_CURDECLARE_TOKEN 134 /* 0x86 TDS 5.0 only */
355 
356 enum {
357  TDS_CUR_ISTAT_UNUSED = 0x00,
358  TDS_CUR_ISTAT_DECLARED = 0x01,
359  TDS_CUR_ISTAT_OPEN = 0x02,
360  TDS_CUR_ISTAT_CLOSED = 0x04,
361  TDS_CUR_ISTAT_RDONLY = 0x08,
362  TDS_CUR_ISTAT_UPDATABLE = 0x10,
363  TDS_CUR_ISTAT_ROWCNT = 0x20,
364  TDS_CUR_ISTAT_DEALLOC = 0x40
365 };
366 
367 /*
368  * Cursor Declare, SetRows, Open and Close all return 0x83 token.
369  * But only SetRows includes the rowcount (4 byte) in the stream.
370  * So for Setrows we read the rowcount from the stream and not for others.
371  * These values are useful to determine when to read the rowcount from the packet
372  */
373 #define IS_DECLARE 100
374 #define IS_CURROW 200
375 #define IS_OPEN 300
376 #define IS_CLOSE 400
377 
378 /* states for tds_process_messages() */
379 #define PROCESS_ROWS 0
380 #define PROCESS_RESULTS 1
381 #define CANCEL_PROCESS 2
382 #define GOTO_1ST_ROW 3
383 #define LOGIN 4
384 
385 /* environment type field */
386 #define TDS_ENV_DATABASE 1
387 #define TDS_ENV_LANG 2
388 #define TDS_ENV_CHARSET 3
389 #define TDS_ENV_PACKSIZE 4
390 #define TDS_ENV_LCID 5
391 #define TDS_ENV_SQLCOLLATION 7
392 #define TDS_ENV_BEGINTRANS 8
393 #define TDS_ENV_COMMITTRANS 9
394 #define TDS_ENV_ROLLBACKTRANS 10
395 
396 /* string types */
397 #define TDS_NULLTERM -9
398 
399 /* Microsoft internal stored procedure id's */
400 
401 #define TDS_SP_CURSOR 1
402 #define TDS_SP_CURSOROPEN 2
403 #define TDS_SP_CURSORPREPARE 3
404 #define TDS_SP_CURSOREXECUTE 4
405 #define TDS_SP_CURSORPREPEXEC 5
406 #define TDS_SP_CURSORUNPREPARE 6
407 #define TDS_SP_CURSORFETCH 7
408 #define TDS_SP_CURSOROPTION 8
409 #define TDS_SP_CURSORCLOSE 9
410 #define TDS_SP_EXECUTESQL 10
411 #define TDS_SP_PREPARE 11
412 #define TDS_SP_EXECUTE 12
413 #define TDS_SP_PREPEXEC 13
414 #define TDS_SP_PREPEXECRPC 14
415 #define TDS_SP_UNPREPARE 15
416 /*
417  * <rant> Sybase does an awful job of this stuff, non null ints of size 1 2
418  * and 4 have there own codes but nullable ints are lumped into INTN
419  * sheesh! </rant>
420  */
421 typedef enum
422 {
423  SYBCHAR = 47, /* 0x2F */
424 #define SYBCHAR SYBCHAR
425  SYBVARCHAR = 39, /* 0x27 */
426 #define SYBVARCHAR SYBVARCHAR
427  SYBINTN = 38, /* 0x26 */
428 #define SYBINTN SYBINTN
429  SYBINT1 = 48, /* 0x30 */
430 #define SYBINT1 SYBINT1
431  SYBINT2 = 52, /* 0x34 */
432 #define SYBINT2 SYBINT2
433  SYBINT4 = 56, /* 0x38 */
434 #define SYBINT4 SYBINT4
435  SYBFLT8 = 62, /* 0x3E */
436 #define SYBFLT8 SYBFLT8
437  SYBDATETIME = 61, /* 0x3D */
438 #define SYBDATETIME SYBDATETIME
439  SYBBIT = 50, /* 0x32 */
440 #define SYBBIT SYBBIT
441  SYBTEXT = 35, /* 0x23 */
442 #define SYBTEXT SYBTEXT
443  SYBNTEXT = 99, /* 0x63 */
444 #define SYBNTEXT SYBNTEXT
445  SYBIMAGE = 34, /* 0x22 */
446 #define SYBIMAGE SYBIMAGE
447  SYBMONEY4 = 122, /* 0x7A */
448 #define SYBMONEY4 SYBMONEY4
449  SYBMONEY = 60, /* 0x3C */
450 #define SYBMONEY SYBMONEY
451  SYBDATETIME4 = 58, /* 0x3A */
452 #define SYBDATETIME4 SYBDATETIME4
453  SYBREAL = 59, /* 0x3B */
454 #define SYBREAL SYBREAL
455  SYBBINARY = 45, /* 0x2D */
456 #define SYBBINARY SYBBINARY
457  SYBVOID = 31, /* 0x1F */
458 #define SYBVOID SYBVOID
459  SYBVARBINARY = 37, /* 0x25 */
460 #define SYBVARBINARY SYBVARBINARY
461  SYBBITN = 104, /* 0x68 */
462 #define SYBBITN SYBBITN
463  SYBNUMERIC = 108, /* 0x6C */
464 #define SYBNUMERIC SYBNUMERIC
465  SYBDECIMAL = 106, /* 0x6A */
466 #define SYBDECIMAL SYBDECIMAL
467  SYBFLTN = 109, /* 0x6D */
468 #define SYBFLTN SYBFLTN
469  SYBMONEYN = 110, /* 0x6E */
470 #define SYBMONEYN SYBMONEYN
471  SYBDATETIMN = 111, /* 0x6F */
472 #define SYBDATETIMN SYBDATETIMN
473 
474 /*
475  * MS only types
476  */
477  SYBNVARCHAR = 103, /* 0x67 */
478 #define SYBNVARCHAR SYBNVARCHAR
479  SYBINT8 = 127, /* 0x7F */
480 #define SYBINT8 SYBINT8
481  XSYBCHAR = 175, /* 0xAF */
482 #define XSYBCHAR XSYBCHAR
483  XSYBVARCHAR = 167, /* 0xA7 */
484 #define XSYBVARCHAR XSYBVARCHAR
485  XSYBNVARCHAR = 231, /* 0xE7 */
486 #define XSYBNVARCHAR XSYBNVARCHAR
487  XSYBNCHAR = 239, /* 0xEF */
488 #define XSYBNCHAR XSYBNCHAR
489  XSYBVARBINARY = 165, /* 0xA5 */
490 #define XSYBVARBINARY XSYBVARBINARY
491  XSYBBINARY = 173, /* 0xAD */
492 #define XSYBBINARY XSYBBINARY
493  SYBUNIQUE = 36, /* 0x24 */
494 #define SYBUNIQUE SYBUNIQUE
495  SYBVARIANT = 98, /* 0x62 */
496 #define SYBVARIANT SYBVARIANT
497 
498 /*
499  * Sybase only types
500  */
501  SYBLONGBINARY = 225, /* 0xE1 */
502 #define SYBLONGBINARY SYBLONGBINARY
503  SYBUINT1 = 64, /* 0x40 */
504 #define SYBUINT1 SYBUINT1
505  SYBUINT2 = 65, /* 0x41 */
506 #define SYBUINT2 SYBUINT2
507  SYBUINT4 = 66, /* 0x42 */
508 #define SYBUINT4 SYBUINT4
509  SYBUINT8 = 67, /* 0x43 */
510 #define SYBUINT8 SYBUINT8
511  SYBBLOB = 36, /* 0x24 */
512 #define SYBBLOB SYBBLOB
513  SYBBOUNDARY = 104, /* 0x68 */
514 #define SYBBOUNDARY SYBBOUNDARY
515  SYBDATE = 49, /* 0x31 */
516 #define SYBDATE SYBDATE
517  SYBDATEN = 123, /* 0x7B */
518 #define SYBDATEN SYBDATEN
519  SYB5INT8 = 191, /* 0xBF */
520 #define SYB5INT8 SYB5INT8
521  SYBINTERVAL = 46, /* 0x2E */
522 #define SYBINTERVAL SYBINTERVAL
523  SYBLONGCHAR = 175, /* 0xAF */
524 #define SYBLONGCHAR SYBLONGCHAR
525  SYBSENSITIVITY = 103, /* 0x67 */
526 #define SYBSENSITIVITY SYBSENSITIVITY
527  SYBSINT1 = 176, /* 0xB0 */
528 #define SYBSINT1 SYBSINT1
529  SYBTIME = 51, /* 0x33 */
530 #define SYBTIME SYBTIME
531  SYBTIMEN = 147, /* 0x93 */
532 #define SYBTIMEN SYBTIMEN
533  SYBUINTN = 68, /* 0x44 */
534 #define SYBUINTN SYBUINTN
535  SYBUNITEXT = 174, /* 0xAE */
536 #define SYBUNITEXT SYBUNITEXT
537  SYBXML = 163, /* 0xA3 */
538 #define SYBXML SYBXML
539 
540 } TDS_SERVER_TYPE;
541 
542 
543 typedef enum
544 {
545  USER_UNICHAR_TYPE = 34, /* 0x22 */
546  USER_UNIVARCHAR_TYPE = 35 /* 0x23 */
547 } TDS_USER_TYPE;
548 
549 #define SYBAOPCNT 0x4b
550 #define SYBAOPCNTU 0x4c
551 #define SYBAOPSUM 0x4d
552 #define SYBAOPSUMU 0x4e
553 #define SYBAOPAVG 0x4f
554 #define SYBAOPAVGU 0x50
555 #define SYBAOPMIN 0x51
556 #define SYBAOPMAX 0x52
557 
558 /* mssql2k compute operator */
559 #define SYBAOPCNT_BIG 0x09
560 #define SYBAOPSTDEV 0x30
561 #define SYBAOPSTDEVP 0x31
562 #define SYBAOPVAR 0x32
563 #define SYBAOPVARP 0x33
564 #define SYBAOPCHECKSUM_AGG 0x72
565 
566 
570 typedef enum
571 {
572  TDS_OPT_SET = 1 /* Set an option. */
573  , TDS_OPT_DEFAULT = 2 /* Set option to its default value. */
574  , TDS_OPT_LIST = 3 /* Request current setting of a specific option. */
575  , TDS_OPT_INFO = 4 /* Report current setting of a specific option. */
577 
578 typedef enum
579 {
580  TDS_OPT_DATEFIRST = 1 /* 0x01 */
581  , TDS_OPT_TEXTSIZE = 2 /* 0x02 */
582  , TDS_OPT_STAT_TIME = 3 /* 0x03 */
583  , TDS_OPT_STAT_IO = 4 /* 0x04 */
584  , TDS_OPT_ROWCOUNT = 5 /* 0x05 */
585  , TDS_OPT_NATLANG = 6 /* 0x06 */
586  , TDS_OPT_DATEFORMAT = 7 /* 0x07 */
587  , TDS_OPT_ISOLATION = 8 /* 0x08 */
588  , TDS_OPT_AUTHON = 9 /* 0x09 */
589  , TDS_OPT_CHARSET = 10 /* 0x0a */
590  , TDS_OPT_SHOWPLAN = 13 /* 0x0d */
591  , TDS_OPT_NOEXEC = 14 /* 0x0e */
592  , TDS_OPT_ARITHIGNOREON = 15 /* 0x0f */
593  , TDS_OPT_ARITHABORTON = 17 /* 0x11 */
594  , TDS_OPT_PARSEONLY = 18 /* 0x12 */
595  , TDS_OPT_GETDATA = 20 /* 0x14 */
596  , TDS_OPT_NOCOUNT = 21 /* 0x15 */
597  , TDS_OPT_FORCEPLAN = 23 /* 0x17 */
598  , TDS_OPT_FORMATONLY = 24 /* 0x18 */
599  , TDS_OPT_CHAINXACTS = 25 /* 0x19 */
600  , TDS_OPT_CURCLOSEONXACT = 26 /* 0x1a */
601  , TDS_OPT_FIPSFLAG = 27 /* 0x1b */
602  , TDS_OPT_RESTREES = 28 /* 0x1c */
603  , TDS_OPT_IDENTITYON = 29 /* 0x1d */
604  , TDS_OPT_CURREAD = 30 /* 0x1e */
605  , TDS_OPT_CURWRITE = 31 /* 0x1f */
606  , TDS_OPT_IDENTITYOFF = 32 /* 0x20 */
607  , TDS_OPT_AUTHOFF = 33 /* 0x21 */
608  , TDS_OPT_ANSINULL = 34 /* 0x22 */
609  , TDS_OPT_QUOTED_IDENT = 35 /* 0x23 */
610  , TDS_OPT_ARITHIGNOREOFF = 36 /* 0x24 */
611  , TDS_OPT_ARITHABORTOFF = 37 /* 0x25 */
612  , TDS_OPT_TRUNCABORT = 38 /* 0x26 */
613 } TDS_OPTION;
614 
615 typedef union tds_option_arg
616 {
617  TDS_TINYINT ti;
618  TDS_INT i;
619  TDS_CHAR *c;
621 
622 enum {
623  TDS_OPT_ARITHOVERFLOW = 0x01,
624  TDS_OPT_NUMERICTRUNC = 0x02
625 };
626 
627 enum TDS_OPT_DATEFIRST_CHOICE
628 {
629  TDS_OPT_MONDAY = 1, TDS_OPT_TUESDAY = 2, TDS_OPT_WEDNESDAY = 3, TDS_OPT_THURSDAY = 4, TDS_OPT_FRIDAY = 5, TDS_OPT_SATURDAY =
630  6, TDS_OPT_SUNDAY = 7
631 };
632 
633 enum TDS_OPT_DATEFORMAT_CHOICE
634 {
635  TDS_OPT_FMTMDY = 1, TDS_OPT_FMTDMY = 2, TDS_OPT_FMTYMD = 3, TDS_OPT_FMTYDM = 4, TDS_OPT_FMTMYD = 5, TDS_OPT_FMTDYM = 6
636 };
637 enum TDS_OPT_ISOLATION_CHOICE
638 {
639  TDS_OPT_LEVEL1 = 1, TDS_OPT_LEVEL3 = 3
640 };
641 
642 typedef enum tds_packet_type
643 {
644  TDS_QUERY = 1,
645  TDS_LOGIN = 2,
646  TDS_RPC = 3,
647  TDS_REPLY = 4,
648  TDS_CANCEL = 6,
649  TDS_BULK = 7,
650  TDS_NORMAL = 15,
651  TDS7_LOGIN = 16,
652  TDS7_AUTH = 17,
653  TDS8_PRELOGIN = 18
654 } TDS_PACKET_TYPE;
655 
656 typedef enum tds_encryption_level {
657  TDS_ENCRYPTION_OFF, TDS_ENCRYPTION_REQUEST, TDS_ENCRYPTION_REQUIRE
658 } TDS_ENCRYPTION_LEVEL;
659 
660 #define TDS_ZERO_FREE(x) do {free((x)); (x) = NULL;} while(0)
661 #define TDS_VECTOR_SIZE(x) (sizeof(x)/sizeof(x[0]))
662 
663 /*
664  * TODO use system macros for optimization
665  * See mcrypt for reference and linux kernel source for optimization
666  * check if unaligned access and use fast write/read when implemented
667  */
668 #define TDS_BYTE_SWAP16(value) \
669  (((((unsigned short)value)<<8) & 0xFF00) | \
670  ((((unsigned short)value)>>8) & 0x00FF))
671 
672 #define TDS_BYTE_SWAP32(value) \
673  (((((unsigned long)value)<<24) & 0xFF000000) | \
674  ((((unsigned long)value)<< 8) & 0x00FF0000) | \
675  ((((unsigned long)value)>> 8) & 0x0000FF00) | \
676  ((((unsigned long)value)>>24) & 0x000000FF))
677 
678 #define is_end_token(x) (x==TDS_DONE_TOKEN || \
679  x==TDS_DONEPROC_TOKEN || \
680  x==TDS_DONEINPROC_TOKEN)
681 
682 #define is_hard_end_token(x) (x==TDS_DONE_TOKEN || \
683  x==TDS_DONEPROC_TOKEN)
684 
685 #define is_msg_token(x) (x==TDS_INFO_TOKEN || \
686  x==TDS_ERROR_TOKEN || \
687  x==TDS_EED_TOKEN)
688 
689 #define is_result_token(x) (x==TDS_RESULT_TOKEN || \
690  x==TDS_ROWFMT2_TOKEN || \
691  x==TDS7_RESULT_TOKEN || \
692  x==TDS_COLFMT_TOKEN || \
693  x==TDS_COLNAME_TOKEN || \
694  x==TDS_RETURNSTATUS_TOKEN)
695 
696 /* FIXME -- not a complete list */
697 #define is_fixed_type(x) (x==SYBINT1 || \
698  x==SYBINT2 || \
699  x==SYBINT4 || \
700  x==SYBINT8 || \
701  x==SYBREAL || \
702  x==SYBFLT8 || \
703  x==SYBDATETIME || \
704  x==SYBDATETIME4 || \
705  x==SYBBIT || \
706  x==SYBMONEY || \
707  x==SYBMONEY4 || \
708  x==SYBVOID || \
709  x==SYBUNIQUE)
710 #define is_nullable_type(x) ( \
711  x==SYBBITN || \
712  x==SYBINTN || \
713  x==SYBFLTN || \
714  x==SYBMONEYN || \
715  x==SYBDATETIMN || \
716  x==SYBVARCHAR || \
717  x==SYBBINARY || \
718  x==SYBVARBINARY || \
719  x==SYBTEXT || \
720  x==SYBNTEXT || \
721  x==SYBIMAGE)
722 
723 #define is_variable_type(x) ( \
724  (x)==SYBTEXT || \
725  (x)==SYBIMAGE || \
726  (x)==SYBNTEXT || \
727  (x)==SYBCHAR || \
728  (x)==SYBVARCHAR || \
729  (x)==SYBBINARY || \
730  (x)==SYBVARBINARY || \
731  (x)==SYBLONGBINARY || \
732  (x)==XSYBCHAR || \
733  (x)==XSYBVARCHAR || \
734  (x)==XSYBNVARCHAR || \
735  (x)==XSYBNCHAR)
736 
737 #define is_blob_type(x) (x==SYBTEXT || x==SYBIMAGE || x==SYBNTEXT)
738 /* large type means it has a two byte size field */
739 /* define is_large_type(x) (x>128) */
740 #define is_numeric_type(x) (x==SYBNUMERIC || x==SYBDECIMAL)
741 #define is_unicode_type(x) (x==XSYBNVARCHAR || x==XSYBNCHAR || x==SYBNTEXT)
742 #define is_collate_type(x) (x==XSYBVARCHAR || x==XSYBCHAR || x==SYBTEXT || x==XSYBNVARCHAR || x==XSYBNCHAR || x==SYBNTEXT)
743 #define is_ascii_type(x) ( x==XSYBCHAR || x==XSYBVARCHAR || x==SYBTEXT || x==SYBCHAR || x==SYBVARCHAR)
744 #define is_binary_type(x) (x==SYBLONGBINARY)
745 #define is_char_type(x) (is_unicode_type(x) || is_ascii_type(x))
746 #define is_similar_type(x, y) ((is_char_type(x) && is_char_type(y)) || ((is_unicode_type(x) && is_unicode_type(y))))
747 
748 
749 #define TDS_MAX_CAPABILITY 22
750 #define MAXPRECISION 80
751 #define TDS_MAX_CONN 4096
752 #define TDS_MAX_DYNID_LEN 30
753 
754 /* defaults to use if no others are found */
755 #define TDS_DEF_SERVER "SYBASE"
756 #define TDS_DEF_BLKSZ 512
757 #define TDS_DEF_CHARSET "iso_1"
758 #define TDS_DEF_LANG "us_english"
759 #if TDS42
760 #define TDS_DEF_MAJOR 4
761 #define TDS_DEF_MINOR 2
762 #define TDS_DEF_PORT 1433
763 #elif TDS46
764 #define TDS_DEF_MAJOR 4
765 #define TDS_DEF_MINOR 6
766 #define TDS_DEF_PORT 4000
767 #elif TDS70
768 #define TDS_DEF_MAJOR 7
769 #define TDS_DEF_MINOR 0
770 #define TDS_DEF_PORT 1433
771 #elif TDS80
772 #define TDS_DEF_MAJOR 8
773 #define TDS_DEF_MINOR 0
774 #define TDS_DEF_PORT 1433
775 #else
776 #define TDS_DEF_MAJOR 5
777 #define TDS_DEF_MINOR 0
778 #define TDS_DEF_PORT 4000
779 #endif
780 
781 /* normalized strings from freetds.conf file */
782 #define TDS_STR_VERSION "tds version"
783 #define TDS_STR_BLKSZ "initial block size"
784 #define TDS_STR_SWAPDT "swap broken dates"
785 #define TDS_STR_SWAPMNY "swap broken money"
786 #define TDS_STR_DUMPFILE "dump file"
787 #define TDS_STR_DEBUGLVL "debug level"
788 #define TDS_STR_DEBUGFLAGS "debug flags"
789 #define TDS_STR_TIMEOUT "timeout"
790 #define TDS_STR_QUERY_TIMEOUT "query timeout"
791 #define TDS_STR_CONNTIMEOUT "connect timeout"
792 #define TDS_STR_HOSTNAME "hostname"
793 #define TDS_STR_HOST "host"
794 #define TDS_STR_PORT "port"
795 #define TDS_STR_TEXTSZ "text size"
796 /* for big endian hosts */
797 #define TDS_STR_EMUL_LE "emulate little endian"
798 #define TDS_STR_CHARSET "charset"
799 #define TDS_STR_CLCHARSET "client charset"
800 #define TDS_STR_LANGUAGE "language"
801 #define TDS_STR_APPENDMODE "dump file append"
802 #define TDS_STR_DATEFMT "date format"
803 #define TDS_STR_INSTANCE "instance"
804 #define TDS_STR_ENCRYPTION "encryption"
805 /* conf values */
806 #define TDS_STR_ENCRYPTION_OFF "off"
807 #define TDS_STR_ENCRYPTION_REQUEST "request"
808 #define TDS_STR_ENCRYPTION_REQUIRE "require"
809 
810 
811 /* TODO do a better check for alignment than this */
812 typedef union
813 {
814  void *p;
815  int i;
817 
818 #define TDS_ALIGN_SIZE sizeof(tds_align_struct)
819 
820 #define TDS_MAX_LOGIN_STR_SZ 30
821 typedef struct tds_login
822 {
823  DSTR server_name;
824  DSTR server_addr;
825  int port;
826  TDS_TINYINT major_version; /* TDS version */
827  TDS_TINYINT minor_version; /* TDS version */
828  int block_size;
829  DSTR language; /* ie us-english */
830  DSTR server_charset; /* ie iso_1 */
831  TDS_INT connect_timeout;
832  DSTR client_host_name;
833  DSTR app_name;
834  DSTR user_name;
835  DSTR password;
836 
837  DSTR library; /* Ct-Library, DB-Library, TDS-Library or ODBC */
838  TDS_TINYINT bulk_copy;
839  TDS_TINYINT suppress_language;
840  TDS_TINYINT encryption_level;
841 
842  TDS_INT query_timeout;
843  unsigned char capabilities[TDS_MAX_CAPABILITY];
844  DSTR client_charset;
845 } TDSLOGIN;
846 
847 typedef struct tds_connection
848 {
849  /* first part of structure is the same of login one */
851  int port;
852  TDS_TINYINT major_version;
853  TDS_TINYINT minor_version;
854  int block_size;
855  DSTR language;
857  TDS_INT connect_timeout;
858  DSTR client_host_name;
859  DSTR server_host_name;
860  DSTR app_name;
863  DSTR library;
864  TDS_TINYINT bulk_copy;
865  TDS_TINYINT suppress_language;
866  TDS_TINYINT encryption_level;
867 
868  TDS_INT query_timeout;
869  unsigned char capabilities[TDS_MAX_CAPABILITY];
870  DSTR client_charset;
871 
873  DSTR instance_name;
874  DSTR database;
875  DSTR dump_file;
876  int debug_flags;
877  int text_size;
878  int broken_dates;
879  int broken_money;
880  int emul_little_endian;
881 } TDSCONNECTION;
882 
883 typedef struct tds_locale
884 {
885  char *language;
886  char *server_charset;
887  char *client_charset;
888  char *date_fmt;
889 } TDSLOCALE;
890 
895 typedef struct tds_blob
896 {
897  TDS_CHAR *textvalue;
898  TDS_CHAR textptr[16];
899  TDS_CHAR timestamp[8];
900 } TDSBLOB;
901 
905 typedef struct
906 {
907  TDS_USMALLINT locale_id; /* master..syslanguages.lcid */
908  TDS_USMALLINT flags;
909  TDS_UCHAR charset_id; /* or zero */
911 
912 /* SF stands for "sort flag" */
913 #define TDS_SF_BIN (TDS_USMALLINT) 0x100
914 #define TDS_SF_WIDTH_INSENSITIVE (TDS_USMALLINT) 0x080
915 #define TDS_SF_KATATYPE_INSENSITIVE (TDS_USMALLINT) 0x040
916 #define TDS_SF_ACCENT_SENSITIVE (TDS_USMALLINT) 0x020
917 #define TDS_SF_CASE_INSENSITIVE (TDS_USMALLINT) 0x010
918 
919 /* UT stands for user type */
920 #define TDS_UT_TIMESTAMP 80
921 
922 
927 typedef struct _tds_encoding
928 {
929  const char *name;
930  unsigned char min_bytes_per_char;
931  unsigned char max_bytes_per_char;
932 } TDS_ENCODING;
933 
934 typedef struct _tds_bcpcoldata
935 {
936  TDS_UCHAR *data;
937  TDS_INT datalen;
938  TDS_INT is_null;
939 } BCPCOLDATA;
940 
941 
942 enum
943 { TDS_SYSNAME_SIZE = 512 };
944 
948 typedef struct tds_column
949 {
950  TDS_SMALLINT column_type;
955  TDS_INT column_usertype;
956  TDS_INT column_flags;
957 
958  TDS_INT column_size;
960  TDS_TINYINT column_varint_size;
962  TDS_TINYINT column_prec;
963  TDS_TINYINT column_scale;
965  TDS_SMALLINT column_namelen;
966  TDS_SMALLINT table_namelen;
967  struct
968  {
969  TDS_SMALLINT column_type;
970  TDS_INT column_size;
971  } on_server;
972 
975  TDS_CHAR table_name[TDS_SYSNAME_SIZE];
976  TDS_CHAR column_name[TDS_SYSNAME_SIZE];
977  char * table_column_name;
978 
979  unsigned char *column_data;
980  void (*column_data_free)(struct tds_column *column);
981  unsigned int column_nullable:1;
982  unsigned int column_writeable:1;
983  unsigned int column_identity:1;
984  unsigned int column_key:1;
985  unsigned int column_hidden:1;
986  unsigned int column_output:1;
987  unsigned int column_timestamp:1;
988  TDS_UCHAR column_collation[5];
989 
990  /* additional fields flags for compute results */
991  TDS_TINYINT column_operator;
992  TDS_SMALLINT column_operand;
993 
994  /* FIXME this is data related, not column */
997 
998  /* related to binding or info stored by client libraries */
999  /* FIXME find a best place to store these data, some are unused */
1000  TDS_SMALLINT column_bindtype;
1001  TDS_SMALLINT column_bindfmt;
1002  TDS_UINT column_bindlen;
1003  TDS_SMALLINT *column_nullbind;
1004  TDS_CHAR *column_varaddr;
1005  TDS_INT *column_lenbind;
1006  TDS_INT column_textpos;
1007  TDS_INT column_text_sqlgetdatapos;
1008  TDS_CHAR column_text_sqlputdatainfo;
1009 
1010  BCPCOLDATA *bcp_column_data;
1020  TDS_INT bcp_term_len;
1021  TDS_CHAR *bcp_terminator;
1022 } TDSCOLUMN;
1023 
1024 
1026 typedef struct tds_result_info
1027 {
1028  /* TODO those fields can became a struct */
1029  TDS_SMALLINT num_cols;
1030  TDSCOLUMN **columns;
1031  TDS_INT row_size;
1032  TDS_INT ref_count;
1033  unsigned char *current_row;
1034  void (*row_free)(struct tds_result_info* result, unsigned char *row);
1035 
1036  TDS_SMALLINT rows_exist;
1037  /* TODO remove ?? used only in dblib */
1038  TDS_INT row_count;
1039  /* TODO remove ?? used only in dblib */
1040  TDS_TINYINT more_results;
1041  TDS_SMALLINT computeid;
1042  TDS_SMALLINT *bycolumns;
1043  TDS_SMALLINT by_cols;
1044 } TDSRESULTINFO;
1045 
1047 typedef enum _TDS_STATE
1048 {
1054 } TDS_STATE;
1055 
1056 #define TDS_DBG_FUNC __FILE__, ((__LINE__ << 4) | 7)
1057 #define TDS_DBG_INFO2 __FILE__, ((__LINE__ << 4) | 6)
1058 #define TDS_DBG_INFO1 __FILE__, ((__LINE__ << 4) | 5)
1059 #define TDS_DBG_NETWORK __FILE__, ((__LINE__ << 4) | 4)
1060 #define TDS_DBG_WARN __FILE__, ((__LINE__ << 4) | 3)
1061 #define TDS_DBG_ERROR __FILE__, ((__LINE__ << 4) | 2)
1062 #define TDS_DBG_SEVERE __FILE__, ((__LINE__ << 4) | 1)
1063 
1064 #define TDS_DBGFLAG_FUNC 0x80
1065 #define TDS_DBGFLAG_INFO2 0x40
1066 #define TDS_DBGFLAG_INFO1 0x20
1067 #define TDS_DBGFLAG_NETWORK 0x10
1068 #define TDS_DBGFLAG_WARN 0x08
1069 #define TDS_DBGFLAG_ERROR 0x04
1070 #define TDS_DBGFLAG_SEVERE 0x02
1071 #define TDS_DBGFLAG_ALLLVL 0xfff
1072 #define TDS_DBGFLAG_PID 0x1000
1073 #define TDS_DBGFLAG_TIME 0x2000
1074 #define TDS_DBGFLAG_SOURCE 0x4000
1075 #define TDS_DBGFLAG_THREAD 0x8000
1076 
1083 {
1084  TDS_DBG_LOGIN = (1 << 0)
1086  , TDS_DBG_API = (1 << 1)
1087  , TDS_DBG_ASYNC = (1 << 2)
1088  , TDS_DBG_DIAG = (1 << 3)
1089  , TDS_DBG_error = (1 << 4)
1090  /* TODO: ^^^^^ make upper case when old #defines (above) are removed */
1091  /* Log FreeTDS runtime/logic error occurs. */
1092  , TDS_DBG_PACKET = (1 << 5)
1093  , TDS_DBG_LIBTDS = (1 << 6)
1094  , TDS_DBG_CONFIG = (1 << 7)
1096 };
1097 
1098 typedef struct tds_result_info TDSCOMPUTEINFO;
1099 
1100 typedef TDSRESULTINFO TDSPARAMINFO;
1101 
1102 typedef struct tds_message
1103 {
1104  TDS_CHAR *server;
1105  TDS_CHAR *message;
1106  TDS_CHAR *proc_name;
1107  TDS_CHAR *sql_state;
1108  TDS_UINT msgno;
1109  TDS_INT line_number;
1110  /* -1 .. 255 */
1111  TDS_SMALLINT state;
1112  TDS_TINYINT priv_msg_type;
1113  TDS_TINYINT severity;
1114  /* for library-generated errors */
1115  int oserr;
1116 } TDSMESSAGE;
1117 
1118 typedef struct tds_upd_col
1119 {
1120  struct tds_upd_col *next;
1121  TDS_INT colnamelength;
1122  char * columnname;
1123 } TDSUPDCOL;
1124 
1125 typedef enum {
1126  TDS_CURSOR_STATE_UNACTIONED = 0 /* initial value */
1127  , TDS_CURSOR_STATE_REQUESTED = 1 /* called by ct_cursor */
1128  , TDS_CURSOR_STATE_SENT = 2 /* sent to server */
1129  , TDS_CURSOR_STATE_ACTIONED = 3 /* acknowledged by server */
1130 } TDS_CURSOR_STATE;
1131 
1132 typedef struct _tds_cursor_status
1133 {
1134  TDS_CURSOR_STATE declare;
1135  TDS_CURSOR_STATE cursor_row;
1136  TDS_CURSOR_STATE open;
1137  TDS_CURSOR_STATE fetch;
1138  TDS_CURSOR_STATE close;
1139  TDS_CURSOR_STATE dealloc;
1141 
1142 typedef enum _tds_cursor_operation
1143 {
1144  TDS_CURSOR_POSITION = 0,
1145  TDS_CURSOR_UPDATE = 1,
1146  TDS_CURSOR_DELETE = 2,
1147  TDS_CURSOR_INSERT = 4
1148 } TDS_CURSOR_OPERATION;
1149 
1150 typedef enum _tds_cursor_fetch
1151 {
1152  TDS_CURSOR_FETCH_NEXT = 1,
1153  TDS_CURSOR_FETCH_PREV,
1154  TDS_CURSOR_FETCH_FIRST,
1155  TDS_CURSOR_FETCH_LAST,
1156  TDS_CURSOR_FETCH_ABSOLUTE,
1157  TDS_CURSOR_FETCH_RELATIVE
1158 } TDS_CURSOR_FETCH;
1159 
1163 typedef struct _tds_cursor
1164 {
1165  struct _tds_cursor *next;
1166  TDS_INT ref_count;
1167  TDS_TINYINT cursor_name_len;
1168  char *cursor_name;
1169  TDS_INT cursor_id;
1170  TDS_TINYINT options;
1171  TDS_TINYINT hasargs;
1172  TDS_USMALLINT query_len;
1173  char *query;
1174  /* TODO for updatable columns */
1175  /* TDS_TINYINT number_upd_cols; */
1176  /* TDSUPDCOL *cur_col_list; */
1177  TDS_INT cursor_rows;
1178  /* TDSPARAMINFO *params; */
1180  TDS_SMALLINT srv_status;
1181  TDSRESULTINFO *res_info;
1182  TDS_INT type, concurrency;
1183 } TDSCURSOR;
1184 
1188 typedef struct tds_env
1189 {
1190  int block_size;
1191  char *language;
1192  char *charset;
1193  char *database;
1194 } TDSENV;
1195 
1199 typedef struct tds_dynamic
1200 {
1201  struct tds_dynamic *next;
1207  char id[30];
1208  int dyn_state;
1210  TDS_INT num_id;
1211  TDSPARAMINFO *res_info;
1219  TDSPARAMINFO *params;
1227  char *query;
1228 } TDSDYNAMIC;
1229 
1230 typedef enum {
1231  TDS_MULTIPLE_QUERY,
1232  TDS_MULTIPLE_EXECUTE,
1233  TDS_MULTIPLE_RPC
1234 } TDS_MULTIPLE_TYPE;
1235 
1236 typedef struct tds_multiple
1237 {
1238  TDS_MULTIPLE_TYPE type;
1239  unsigned int flags;
1240 } TDSMULTIPLE;
1241 
1242 /* forward declaration */
1243 typedef struct tds_context TDSCONTEXT;
1244 
1246 {
1247  TDSLOCALE *locale;
1248  void *parent;
1249  /* handlers */
1250  int (*msg_handler) (const TDSCONTEXT *, TDSSOCKET *, TDSMESSAGE *);
1251  int (*err_handler) (const TDSCONTEXT *, TDSSOCKET *, TDSMESSAGE *);
1252  int (*int_handler) (void *);
1253 };
1254 
1255 enum TDS_ICONV_ENTRY
1256 {
1257  client2ucs2
1258  , client2server_chardata
1259  , iso2server_metadata
1260  , initial_char_conv_count /* keep last */
1261 };
1262 
1264 {
1265  TDS_UCHAR *packet;
1266  int packet_len;
1267  int (*free)(TDSSOCKET * tds, struct tds_authentication * auth);
1268  int (*handle_next)(TDSSOCKET * tds, struct tds_authentication * auth, size_t len);
1269 };
1270 
1271 typedef struct tds_authentication TDSAUTHENTICATION;
1272 
1277 {
1278  /* fixed and connect time */
1280  TDS_SYS_SOCKET s;
1281  TDS_SMALLINT major_version;
1282  TDS_SMALLINT minor_version;
1285  char *product_name;
1286  unsigned char capabilities[TDS_MAX_CAPABILITY];
1287  unsigned char broken_dates;
1288  unsigned char option_flag2;
1289  /* in/out buffers */
1291  unsigned char *in_buf;
1293  unsigned char *out_buf;
1295  unsigned int in_buf_max;
1297  unsigned in_pos;
1299  unsigned out_pos;
1301  unsigned in_len;
1302  /* TODO remove blocksize from env and use out_len ?? */
1303 /* unsigned out_len; */
1305  unsigned char in_flag;
1307  unsigned char out_flag;
1309  unsigned char last_packet;
1310  void *parent;
1317  TDSRESULTINFO *res_info;
1318  TDS_INT num_comp_info;
1319  TDSCOMPUTEINFO **comp_info;
1320  TDSPARAMINFO *param_info;
1323  TDS_TINYINT has_status;
1324  TDS_INT ret_status;
1325  TDS_STATE state;
1327  volatile unsigned char in_cancel;
1329  TDS_INT8 rows_affected;
1330  /* timeout stuff from Jeff */
1331  TDS_INT query_timeout;
1332  TDSENV env;
1333 
1334  /* dynamic placeholder stuff */
1335  /*@dependent@*/ TDSDYNAMIC *cur_dyn;
1338  int emul_little_endian;
1339  char *date_fmt;
1340  const TDSCONTEXT *tds_ctx;
1341  int char_conv_count;
1342  TDSICONV **char_convs;
1343 
1346 
1347  int spid;
1348  TDS_UCHAR collation[5];
1349  TDS_UCHAR tds9_transaction[8];
1350  void (*env_chg_func) (TDSSOCKET * tds, int type, char *oldval, char *newval);
1351  int internal_sp_called;
1352 
1353  void *tls_session;
1354  void *tls_credentials;
1355  TDSAUTHENTICATION *authentication;
1356  int option_value;
1357 };
1358 
1359 int tds_init_write_buf(TDSSOCKET * tds);
1360 void tds_free_result_info(TDSRESULTINFO * info);
1361 void tds_free_socket(TDSSOCKET * tds);
1362 void tds_free_connection(TDSCONNECTION * connection);
1363 void tds_free_all_results(TDSSOCKET * tds);
1364 void tds_free_results(TDSRESULTINFO * res_info);
1365 void tds_free_param_results(TDSPARAMINFO * param_info);
1366 void tds_free_param_result(TDSPARAMINFO * param_info);
1367 void tds_free_msg(TDSMESSAGE * message);
1368 void tds_cursor_deallocated(TDSSOCKET *tds, TDSCURSOR *cursor);
1369 void tds_release_cursor(TDSSOCKET *tds, TDSCURSOR *cursor);
1370 void tds_free_bcp_column_data(BCPCOLDATA * coldata);
1371 
1372 int tds_put_n(TDSSOCKET * tds, const void *buf, int n);
1373 int tds_put_string(TDSSOCKET * tds, const char *buf, int len);
1374 int tds_put_int(TDSSOCKET * tds, TDS_INT i);
1375 int tds_put_int8(TDSSOCKET * tds, TDS_INT8 i);
1376 int tds_put_smallint(TDSSOCKET * tds, TDS_SMALLINT si);
1378 #define tds_put_tinyint(tds, ti) tds_put_byte(tds,ti)
1379 int tds_put_byte(TDSSOCKET * tds, unsigned char c);
1380 TDSRESULTINFO *tds_alloc_results(int num_cols);
1381 TDSCOMPUTEINFO **tds_alloc_compute_results(TDSSOCKET * tds, int num_cols, int by_cols);
1382 TDSCONTEXT *tds_alloc_context(void * parent);
1383 void tds_free_context(TDSCONTEXT * locale);
1384 TDSSOCKET *tds_alloc_socket(TDSCONTEXT * context, int bufsize);
1385 
1386 /* config.c */
1388 typedef void (*TDSCONFPARSE) (const char *option, const char *value, void *param);
1389 int tds_read_conf_section(FILE * in, const char *section, TDSCONFPARSE tds_conf_parse, void *parse_param);
1390 int tds_read_conf_file(TDSCONNECTION * connection, const char *server);
1392 void tds_fix_connection(TDSCONNECTION * connection);
1393 void tds_config_verstr(const char *tdsver, TDSCONNECTION * connection);
1394 void tds_lookup_host(const char *servername, char *ip);
1395 int tds_set_interfaces_file_loc(const char *interfloc);
1396 
1397 TDSLOCALE *tds_get_locale(void);
1398 int tds_alloc_row(TDSRESULTINFO * res_info);
1399 int tds_alloc_compute_row(TDSCOMPUTEINFO * res_info);
1400 BCPCOLDATA * tds_alloc_bcp_column_data(int column_size);
1401 unsigned char *tds7_crypt_pass(const unsigned char *clear_pass, int len, unsigned char *crypt_pass);
1402 TDSDYNAMIC *tds_lookup_dynamic(TDSSOCKET * tds, char *id);
1403 /*@observer@*/ const char *tds_prtype(int token);
1404 
1405 
1406 
1407 /* iconv.c */
1408 void tds_iconv_open(TDSSOCKET * tds, const char *charset);
1409 void tds_iconv_close(TDSSOCKET * tds);
1410 void tds_srv_charset_changed(TDSSOCKET * tds, const char *charset);
1411 void tds7_srv_charset_changed(TDSSOCKET * tds, int sql_collate, int lcid);
1412 int tds_iconv_alloc(TDSSOCKET * tds);
1413 void tds_iconv_free(TDSSOCKET * tds);
1414 TDSICONV *tds_iconv_from_collate(TDSSOCKET * tds, int sql_collate, int lcid);
1415 
1416 /* threadsafe.c */
1417 char *tds_timestamp_str(char *str, int maxlen);
1418 struct hostent *tds_gethostbyname_r(const char *servername, struct hostent *result, char *buffer, int buflen, int *h_errnop);
1419 struct hostent *tds_gethostbyaddr_r(const char *addr, int len, int type, struct hostent *result, char *buffer, int buflen,
1420  int *h_errnop);
1421 struct servent *tds_getservbyname_r(const char *name, const char *proto, struct servent *result, char *buffer, int buflen);
1422 #ifdef INADDR_NONE
1423 const char *tds_inet_ntoa_r(struct in_addr iaddr, char *ip, size_t len);
1424 #endif
1425 char *tds_get_homedir(void);
1426 
1427 /* mem.c */
1428 TDSPARAMINFO *tds_alloc_param_result(TDSPARAMINFO * old_param);
1429 void tds_free_input_params(TDSDYNAMIC * dyn);
1430 void tds_free_dynamic(TDSSOCKET * tds, TDSDYNAMIC * dyn);
1431 TDSSOCKET *tds_realloc_socket(TDSSOCKET * tds, int bufsize);
1432 char *tds_alloc_client_sqlstate(int msgno);
1433 char *tds_alloc_lookup_sqlstate(TDSSOCKET * tds, int msgno);
1434 TDSLOGIN *tds_alloc_login(void);
1435 TDSDYNAMIC *tds_alloc_dynamic(TDSSOCKET * tds, const char *id);
1436 void tds_free_login(TDSLOGIN * login);
1438 TDSLOCALE *tds_alloc_locale(void);
1439 void *tds_alloc_param_data(TDSCOLUMN * curparam);
1440 void tds_free_locale(TDSLOCALE * locale);
1441 TDSCURSOR * tds_alloc_cursor(TDSSOCKET * tds, const char *name, TDS_INT namelen, const char *query, TDS_INT querylen);
1442 void tds_free_row(TDSRESULTINFO * res_info, unsigned char *row);
1443 
1444 /* login.c */
1445 void tds_set_packet(TDSLOGIN * tds_login, int packet_size);
1446 void tds_set_port(TDSLOGIN * tds_login, int port);
1447 void tds_set_passwd(TDSLOGIN * tds_login, const char *password);
1448 void tds_set_bulk(TDSLOGIN * tds_login, TDS_TINYINT enabled);
1449 void tds_set_user(TDSLOGIN * tds_login, const char *username);
1450 void tds_set_app(TDSLOGIN * tds_login, const char *application);
1451 void tds_set_host(TDSLOGIN * tds_login, const char *hostname);
1452 void tds_set_server_addr(TDSLOGIN * tds_login, const char *server_addr);
1453 void tds_set_library(TDSLOGIN * tds_login, const char *library);
1454 void tds_set_server(TDSLOGIN * tds_login, const char *server);
1455 void tds_set_client_charset(TDSLOGIN * tds_login, const char *charset);
1456 void tds_set_language(TDSLOGIN * tds_login, const char *language);
1457 void tds_set_version(TDSLOGIN * tds_login, TDS_TINYINT major_ver, TDS_TINYINT minor_ver);
1458 void tds_set_capabilities(TDSLOGIN * tds_login, unsigned char *capabilities, int size);
1459 int tds_connect(TDSSOCKET * tds, TDSCONNECTION * connection);
1460 
1461 /* query.c */
1462 int tds_submit_query(TDSSOCKET * tds, const char *query);
1463 int tds_submit_query_params(TDSSOCKET * tds, const char *query, TDSPARAMINFO * params);
1464 int tds_submit_queryf(TDSSOCKET * tds, const char *queryf, ...);
1465 int tds_submit_prepare(TDSSOCKET * tds, const char *query, const char *id, TDSDYNAMIC ** dyn_out, TDSPARAMINFO * params);
1466 int tds_submit_execdirect(TDSSOCKET * tds, const char *query, TDSPARAMINFO * params);
1467 int tds_submit_execute(TDSSOCKET * tds, TDSDYNAMIC * dyn);
1468 int tds_send_cancel(TDSSOCKET * tds);
1469 const char *tds_next_placeholder(const char *start);
1470 int tds_count_placeholders(const char *query);
1471 int tds_get_dynid(TDSSOCKET * tds, char **id);
1472 int tds_submit_unprepare(TDSSOCKET * tds, TDSDYNAMIC * dyn);
1473 int tds_submit_rpc(TDSSOCKET * tds, const char *rpc_name, TDSPARAMINFO * params);
1474 int tds_submit_optioncmd(TDSSOCKET * tds, TDS_OPTION_CMD command, TDS_OPTION option, TDS_OPTION_ARG *param, TDS_INT param_size);
1475 int tds_quote_id(TDSSOCKET * tds, char *buffer, const char *id, int idlen);
1476 int tds_quote_string(TDSSOCKET * tds, char *buffer, const char *str, int len);
1477 const char *tds_skip_quoted(const char *s);
1478 
1479 int tds_cursor_declare(TDSSOCKET * tds, TDSCURSOR * cursor, TDSPARAMINFO *params, int *send);
1480 int tds_cursor_setrows(TDSSOCKET * tds, TDSCURSOR * cursor, int *send);
1481 int tds_cursor_open(TDSSOCKET * tds, TDSCURSOR * cursor, TDSPARAMINFO *params, int *send);
1482 int tds_cursor_fetch(TDSSOCKET * tds, TDSCURSOR * cursor, TDS_CURSOR_FETCH fetch_type, TDS_INT i_row);
1483 int tds_cursor_close(TDSSOCKET * tds, TDSCURSOR * cursor);
1484 int tds_cursor_dealloc(TDSSOCKET * tds, TDSCURSOR * cursor);
1485 int tds_cursor_update(TDSSOCKET * tds, TDSCURSOR * cursor, TDS_CURSOR_OPERATION op, TDS_INT i_row, TDSPARAMINFO * params);
1486 int tds_cursor_setname(TDSSOCKET * tds, TDSCURSOR * cursor);
1487 
1488 int tds_multiple_init(TDSSOCKET *tds, TDSMULTIPLE *multiple, TDS_MULTIPLE_TYPE type);
1489 int tds_multiple_done(TDSSOCKET *tds, TDSMULTIPLE *multiple);
1490 int tds_multiple_query(TDSSOCKET *tds, TDSMULTIPLE *multiple, const char *query, TDSPARAMINFO * params);
1491 int tds_multiple_execute(TDSSOCKET *tds, TDSMULTIPLE *multiple, TDSDYNAMIC * dyn);
1492 
1493 /* token.c */
1494 int tds_process_cancel(TDSSOCKET * tds);
1495 void tds_swap_datatype(int coltype, unsigned char *buf);
1496 void tds_swap_numeric(TDS_NUMERIC *num);
1497 int tds_get_token_size(int marker);
1500 int tds5_send_optioncmd(TDSSOCKET * tds, TDS_OPTION_CMD tds_command, TDS_OPTION tds_option, TDS_OPTION_ARG * tds_argument,
1501  TDS_INT * tds_argsize);
1502 int tds_process_tokens(TDSSOCKET * tds, /*@out@*/ TDS_INT * result_type, /*@out@*/ int *done_flags, unsigned flag);
1503 
1504 /* data.c */
1505 void tds_set_param_type(TDSSOCKET * tds, TDSCOLUMN * curcol, TDS_SERVER_TYPE type);
1506 void tds_set_column_type(TDSSOCKET * tds, TDSCOLUMN * curcol, int type);
1507 
1508 
1509 /* tds_convert.c */
1510 TDS_INT tds_datecrack(TDS_INT datetype, const void *di, TDSDATEREC * dr);
1511 int tds_get_conversion_type(int srctype, int colsize);
1512 extern const char tds_hex_digits[];
1513 
1514 /* write.c */
1515 int tds_flush_packet(TDSSOCKET * tds);
1516 int tds_put_buf(TDSSOCKET * tds, const unsigned char *buf, int dsize, int ssize);
1517 
1518 /* read.c */
1519 unsigned char tds_get_byte(TDSSOCKET * tds);
1520 void tds_unget_byte(TDSSOCKET * tds);
1521 unsigned char tds_peek(TDSSOCKET * tds);
1522 TDS_SMALLINT tds_get_smallint(TDSSOCKET * tds);
1523 TDS_INT tds_get_int(TDSSOCKET * tds);
1524 TDS_INT8 tds_get_int8(TDSSOCKET * tds);
1525 int tds_get_string(TDSSOCKET * tds, int string_len, char *dest, size_t dest_size);
1526 int tds_get_char_data(TDSSOCKET * tds, char *dest, size_t wire_size, TDSCOLUMN * curcol);
1527 void *tds_get_n(TDSSOCKET * tds, /*@out@*/ /*@null@*/ void *dest, int n);
1528 int tds_get_size_by_type(int servertype);
1529 
1530 
1531 /* util.c */
1532 int tdserror (const TDSCONTEXT * tds_ctx, TDSSOCKET * tds, int msgno, int errnum);
1534 void tds_set_parent(TDSSOCKET * tds, void *the_parent);
1535 void *tds_get_parent(TDSSOCKET * tds);
1536 int tds_swap_bytes(unsigned char *buf, int bytes);
1537 int tds_version(TDSSOCKET * tds_socket, char *pversion_string);
1538 void tdsdump_off(void);
1539 void tdsdump_on(void);
1540 int tdsdump_open(const char *filename);
1541 void tdsdump_close(void);
1542 void tdsdump_dump_buf(const char* file, unsigned int level_line, const char *msg, const void *buf, int length);
1543 void tdsdump_log(const char* file, unsigned int level_line, const char *fmt, ...)
1544 #if defined(__GNUC__) && __GNUC__ >= 2
1545  __attribute__ ((__format__ (__printf__, 3, 4)))
1546 #endif
1547 ;
1548 extern int tds_debug_flags;
1549 unsigned int tds_gettime_ms(void);
1550 
1551 /* net.c */
1552 int tds_open_socket(TDSSOCKET * tds, const char *ip_addr, unsigned int port, int timeout);
1553 int tds_close_socket(TDSSOCKET * tds);
1554 int tds_read_packet(TDSSOCKET * tds);
1555 int tds_write_packet(TDSSOCKET * tds, unsigned char final);
1556 int tds7_get_instance_port(const char *ip_addr, const char *instance);
1557 int tds_ssl_init(TDSSOCKET *tds);
1558 void tds_ssl_deinit(TDSSOCKET *tds);
1559 
1560 
1561 
1562 /* vstrbuild.c */
1563 int tds_vstrbuild(char *buffer, int buflen, int *resultlen, char *text, int textlen, const char *formats, int formatlen,
1564  va_list ap);
1565 
1566 /* numeric.c */
1567 char *tds_money_to_string(const TDS_MONEY * money, char *s);
1568 TDS_INT tds_numeric_to_string(const TDS_NUMERIC * numeric, char *s);
1569 TDS_INT tds_numeric_change_prec_scale(TDS_NUMERIC * numeric, unsigned char new_prec, unsigned char new_scale);
1570 
1571 /* getmac.c */
1572 void tds_getmac(int s, unsigned char mac[6]);
1573 
1575 TDSAUTHENTICATION * tds_gss_get_auth(TDSSOCKET * tds);
1576 
1577 #define IS_TDS42(x) (x->major_version==4 && x->minor_version==2)
1578 #define IS_TDS46(x) (x->major_version==4 && x->minor_version==6)
1579 #define IS_TDS50(x) (x->major_version==5 && x->minor_version==0)
1580 #define IS_TDS70(x) (x->major_version==7 && x->minor_version==0)
1581 #define IS_TDS80(x) (x->major_version==8 && x->minor_version==0)
1582 #define IS_TDS90(x) (x->major_version==9 && x->minor_version==0)
1583 
1584 #define IS_TDS7_PLUS(x) ((x)->major_version>=7)
1585 #define IS_TDS8_PLUS(x) ((x)->major_version>=8)
1586 
1587 #define IS_TDSDEAD(x) (((x) == NULL) || TDS_IS_SOCKET_INVALID((x)->s))
1588 
1590 #define TDS_IS_SYBASE(x) (!(x->product_version & 0x80000000u))
1591 
1592 #define TDS_IS_MSSQL(x) ((x->product_version & 0x80000000u)!=0)
1593 
1597 #define TDS_MS_VER(maj,min,x) (0x80000000u|((maj)<<24)|((min)<<16)|(x))
1598 
1599 /* TODO test if not similar to ms one*/
1601 #define TDS_SYB_VER(maj,min,x) (((maj)<<24)|((min)<<16)|(x)<<8)
1602 
1603 #ifdef __cplusplus
1604 #if 0
1605 {
1606 #endif
1607 }
1608 #endif
1609 
1610 #endif /* _tds_h_ */
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:144
Definition: tds.h:122
int tds_read_conf_file(TDSCONNECTION *connection, const char *server)
Read configuration info for given server return 0 on error.
Definition: config.c:294
Definition: tds.h:139
TDS_CURSOR_STATUS status
cursor parameter
Definition: tds.h:1179
Definition: tds.h:812
TDS_USMALLINT query_len
SQL query length.
Definition: tds.h:1172
int tds_get_conversion_type(int srctype, int colsize)
Return type suitable for conversions (convert all nullable types to fixed type)
Definition: convert.c:152
void tds_free_param_result(TDSPARAMINFO *param_info)
Delete latest parameter.
Definition: mem.c:222
int tds_count_placeholders(const char *query)
Count the number of placeholders in query.
Definition: query.c:498
cilent is waiting for data
Definition: tds.h:1051
TDSDYNAMIC * tds_alloc_dynamic(TDSSOCKET *tds, const char *id)
Allocate a dynamic statement.
Definition: mem.c:94
TDSDYNAMIC * dyns
list of dynamic allocate for this connection
Definition: tds.h:1336
acknowledging an attention command (usually a cancel)
Definition: tds.h:256
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:2802
TDS_SYS_SOCKET s
tcp socket, INVALID_SOCKET if not connected
Definition: tds.h:1280
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:188
Definition: tds.h:116
int emulated
this dynamic query cannot be prepared so libTDS have to construct a simple query. ...
Definition: tds.h:1225
void tds_set_column_type(TDSSOCKET *tds, TDSCOLUMN *curcol, int type)
Set type of column initializing all dependency.
Definition: data.c:51
TDS_INT month
month number (0-11)
Definition: tds.h:168
TDS_STATE tds_set_state(TDSSOCKET *tds, TDS_STATE state)
Set state of TDS connection, with logging and checking.
Definition: util.c:90
TDS_OPTION_CMD
options that can be sent with a TDS_OPTIONCMD token
Definition: tds.h:570
Current environment as reported by the server.
Definition: tds.h:1188
TDS_INT bcp_prefix_len
The length, in bytes, of any length prefix this column may have.
Definition: tds.h:1019
void tds_unget_byte(TDSSOCKET *tds)
Unget will always work as long as you don&#39;t call it twice in a row.
Definition: read.c:90
Definition: tds.h:150
struct tds_result_info TDSRESULTINFO
Hold information for any results.
char * tds_get_homedir(void)
Get user home directory.
Definition: threadsafe.c:513
void tdsdump_dump_buf(const char *file, unsigned int level_line, const char *msg, const void *buf, int length)
Dump the contents of data into the log file in a human readable format.
Definition: log.c:274
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:1930
struct _tds_encoding TDS_ENCODING
Information relevant to libiconv.
A structure to hold all the compile-time settings.
Definition: tds.h:52
TDS_TINYINT column_varint_size
size of length when reading from wire (0, 1, 2 or 4)
Definition: tds.h:960
client is sending request
Definition: tds.h:1050
unsigned out_pos
current position in out_buf
Definition: tds.h:1299
struct tds_blob TDSBLOB
Information about blobs (e.g.
TDSLOCALE * tds_get_locale(void)
Get locale information.
Definition: locale.c:54
TDS_INT8 rows_affected
rows updated/deleted/inserted/selected, TDS_NO_COUNT if not valid
Definition: tds.h:1329
TDS_INT day
day of month (1-31)
Definition: tds.h:169
_TDS_STATE
values for tds-&gt;state
Definition: tds.h:1047
TDSPARAMINFO * res_info
query results
Definition: tds.h:1211
TDS_INT dayofyear
day of year (1-366)
Definition: tds.h:170
TDS_TINYINT has_status
true is ret_status is valid
Definition: tds.h:1323
int tdsdump_open(const char *filename)
This creates and truncates a human readable dump file for the TDS traffic.
Definition: log.c:122
TDS_INT type
row fetched from this cursor
Definition: tds.h:1182
DSTR user_name
account for login
Definition: tds.h:861
TDSPARAMINFO * params
query parameters.
Definition: tds.h:1219
void tds_lookup_host(const char *servername, char *ip)
Given a servername lookup the hostname.
Definition: config.c:733
Definition: tdsiconv.h:132
int tds_connect(TDSSOCKET *tds, TDSCONNECTION *connection)
Do a connection to socket.
Definition: login.c:312
Information relevant to libiconv.
Definition: tds.h:927
unsigned char * tds7_crypt_pass(const unsigned char *clear_pass, int len, unsigned char *crypt_pass)
tds7_crypt_pass() – &#39;encrypt&#39; TDS 7.0 style passwords.
Definition: login.c:883
TDS_INT year
year
Definition: tds.h:167
Definition: tds.h:133
transaction in progress
Definition: tds.h:253
TDSAUTHENTICATION * tds_ntlm_get_auth(TDSSOCKET *tds)
Build a NTLMSPP packet to send to server.
Definition: challenge.c:366
Information about blobs (e.g.
Definition: tds.h:895
int tds_quote_id(TDSSOCKET *tds, char *buffer, const char *id, int idlen)
Quote an id.
Definition: query.c:1990
int tds_submit_execdirect(TDSSOCKET *tds, const char *query, TDSPARAMINFO *params)
Submit a prepared query with parameters.
Definition: query.c:1141
TDS_INT millisecond
0-999
Definition: tds.h:175
TDS_TINYINT options
read only|updatable
Definition: tds.h:1170
int tds_alloc_row(TDSRESULTINFO *res_info)
Allocate space for row store return NULL on out of memory.
Definition: mem.c:416
TDSPARAMINFO * tds_alloc_param_result(TDSPARAMINFO *old_param)
Adds a output parameter to TDSPARAMINFO.
Definition: mem.c:182
TDS_INT ref_count
reference counter so client can retain safely a pointer
Definition: tds.h:1166
const char * tds_skip_quoted(const char *s)
Skip quoting string (like &#39;sfsf&#39;, &quot;dflkdj&quot; or [dfkjd])
Definition: query.c:443
TDS_INT ret_status
return status from store procedure
Definition: tds.h:1324
more results follow
Definition: tds.h:251
all above except login packets
Definition: tds.h:1095
TDSICONV * tds_iconv_from_collate(TDSSOCKET *tds, int sql_collate, int lcid)
Get iconv information from a LCID (to support different column encoding under MSSQL2K) ...
Definition: iconv.c:1437
Definition: tds.h:1245
Definition: tds.h:1102
TDSCURSOR * cursors
linked list of cursors allocated for this connection
Definition: tds.h:1322
TDS_SMALLINT column_type
This type can be different from wire type because conversion (e.g.
Definition: tds.h:950
struct tds_dynamic TDSDYNAMIC
Holds information for a dynamic (also called prepared) query.
TDSCONNECTION * connection
config for login stuff.
Definition: tds.h:1345
int tds_process_tokens(TDSSOCKET *tds, TDS_INT *result_type, int *done_flags, unsigned flag)
process all streams.
Definition: token.c:473
const char * tds_next_placeholder(const char *start)
Get position of next placeholder.
Definition: query.c:463
TDS_UINT product_version
version of product (Sybase/MS and full version)
Definition: tds.h:1284
struct tds_dynamic * next
next in linked list, keep first
Definition: tds.h:1201
TDS_INT minute
0-59
Definition: tds.h:173
int tds_submit_rpc(TDSSOCKET *tds, const char *rpc_name, TDSPARAMINFO *params)
tds_submit_rpc() call a RPC from server.
Definition: query.c:1833
DSTR server_charset
charset of server
Definition: tds.h:856
void tds_fix_connection(TDSCONNECTION *connection)
Fix configuration after reading it.
Definition: config.c:237
TDS_SMALLINT column_namelen
length of column name
Definition: tds.h:965
Definition: tds.h:615
int tdserror(const TDSCONTEXT *tds_ctx, TDSSOCKET *tds, int msgno, int errnum)
Call the client library&#39;s error handler (for library-generated errors only)
Definition: util.c:322
for diagnosing login problems; otherwise the username/password information is suppressed.
Definition: tds.h:1084
Definition: tds.h:109
Log calls to client libraries.
Definition: tds.h:1086
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:2674
void tds_config_verstr(const char *tdsver, TDSCONNECTION *connection)
Set TDS version from given string.
Definition: config.c:668
int tds_read_packet(TDSSOCKET *tds)
Read in one &#39;packet&#39; from the server.
Definition: net.c:552
struct tdsdaterec TDSDATEREC
information on data, used by tds_datecrack
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:192
struct _tds_compiletime_settings TDS_COMPILETIME_SETTINGS
A structure to hold all the compile-time settings.
char * cursor_name
name of the cursor
Definition: tds.h:1168
Definition: tds.h:1263
void tds_set_server(TDSLOGIN *tds_login, const char *server)
Set the servername in a TDSLOGIN structure.
Definition: login.c:123
struct tds_column TDSCOLUMN
Metadata about columns in regular and compute rows.
unsigned int in_buf_max
allocated input buffer
Definition: tds.h:1295
final result set, command completed successfully.
Definition: tds.h:250
unsigned char last_packet
true if current input buffer is the last one
Definition: tds.h:1309
unsigned in_pos
current position in in_buf
Definition: tds.h:1297
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:997
Definition: tds.h:145
results are from a stored procedure
Definition: tds.h:254
void tds_free_input_params(TDSDYNAMIC *dyn)
Frees all allocated input parameters of a dynamic statement.
Definition: mem.c:126
Definition: tds.h:934
void tdsdump_on(void)
Turn logging back on.
Definition: log.c:105
Log client- and server-generated messages.
Definition: tds.h:1088
volatile unsigned char in_cancel
indicate we are waiting a cancel reply so discard tokens till acknowledge
Definition: tds.h:1327
Hold information for a server connection.
Definition: tds.h:1276
SQL server server error.
Definition: tds.h:258
Definition: tds.h:821
TDS_INT weekday
day of week (0-6, 0 = sunday)
Definition: tds.h:171
int port
port of database service
Definition: tds.h:851
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:1079
error occurred
Definition: tds.h:252
information on data, used by tds_datecrack
Definition: tds.h:165
TDS_INT hour
0-23
Definition: tds.h:172
Definition: tds.h:67
Definition: tds.h:1132
TDSDYNAMIC * cur_dyn
dynamic structure in use
Definition: tds.h:1335
int tds_process_login_tokens(TDSSOCKET *tds)
tds_process_login_tokens() is called after sending the login packet to the server.
Definition: token.c:300
DSTR ip_addr
ip of server
Definition: tds.h:872
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:279
TDS_TINYINT cursor_name_len
length of cursor name &gt; 0 and &lt;= 30
Definition: tds.h:1167
DSTR password
password of account login
Definition: tds.h:862
TDS_INT second
0-59
Definition: tds.h:174
unsigned char * out_buf
output buffer
Definition: tds.h:1293
void tds_free_dynamic(TDSSOCKET *tds, TDSDYNAMIC *dyn)
Frees dynamic statement and remove from TDS.
Definition: mem.c:144
int tds_put_string(TDSSOCKET *tds, const char *s, int len)
Output a string to wire automatic translate string to unicode if needed.
Definition: write.c:100
no connection
Definition: tds.h:1053
TDSCONNECTION * tds_alloc_connection(TDSLOCALE *locale)
Allocate space for configure structure and initialize with default values.
Definition: mem.c:722
Definition: tds.h:128
void tdsdump_close(void)
Close the TDS dump log file.
Definition: log.c:215
int tds_submit_execute(TDSSOCKET *tds, TDSDYNAMIC *dyn)
tds_submit_execute() sends a previously prepared dynamic statement to the server. ...
Definition: query.c:1623
TDS_INT tds_get_int(TDSSOCKET *tds)
Get an int32 from the server.
Definition: read.c:127
TDSRESULTINFO * current_results
info about current query.
Definition: tds.h:1316
struct _tds_cursor TDSCURSOR
Holds informations about a cursor.
client is reading data
Definition: tds.h:1052
int tds_read_conf_section(FILE *in, const char *section, TDSCONFPARSE tds_conf_parse, void *param)
Read a section of configuration file (INI style file)
Definition: config.c:388
TDSCURSOR * cur_cursor
cursor in use
Definition: tds.h:1321
Hold information for any results.
Definition: tds.h:1026
unsigned char * in_buf
input buffer
Definition: tds.h:1291
struct _tds_cursor * next
next in linked list, keep first
Definition: tds.h:1165
count field in packet is valid
Definition: tds.h:255
int tds_process_cancel(TDSSOCKET *tds)
Definition: token.c:2571
Definition: tds.h:847
int tds_submit_unprepare(TDSSOCKET *tds, TDSDYNAMIC *dyn)
Send a unprepare request for a prepared query.
Definition: query.c:1757
int tds_quote_string(TDSSOCKET *tds, char *buffer, const char *str, int len)
Quote a string.
Definition: query.c:2031
replaces TDSDUMPCONFIG
Definition: tds.h:1094
TDS_TINYINT column_scale
scale for decimal/numeric
Definition: tds.h:963
int tds_set_interfaces_file_loc(const char *interf)
Set the full name of interface file.
Definition: config.c:708
TDS_DBG_LOG_STATE
An attempt at better logging.
Definition: tds.h:1082
int tds_process_simple_query(TDSSOCKET *tds)
Process results for simple query as &quot;SET TEXTSIZE&quot; or &quot;USE dbname&quot; If the statement returns results...
Definition: token.c:794
int tds_iconv_alloc(TDSSOCKET *tds)
Allocate iconv stuff.
Definition: iconv.c:277
TDS_INT column_cur_size
size written in variable (ie: char, text, binary).
Definition: tds.h:996
TDS_TINYINT column_prec
precision for decimal/numeric
Definition: tds.h:962
TDS_INT column_size
maximun size of data.
Definition: tds.h:958
TDSDYNAMIC * tds_lookup_dynamic(TDSSOCKET *tds, char *id)
Find a dynamic given string id.
Definition: token.c:2604
struct tds_env TDSENV
Current environment as reported by the server.
Log calls to (and in) libtds.
Definition: tds.h:1093
TDS_INT cursor_id
cursor id returned by the server after cursor declare
Definition: tds.h:1169
unsigned char in_flag
input buffer type
Definition: tds.h:1305
TDS 8.0 collation informations.
Definition: tds.h:905
const TDSICONV * char_conv
refers to previously allocated iconv information
Definition: tds.h:973
unsigned in_len
input buffer length
Definition: tds.h:1301
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:2944
Definition: tds.h:156
TDS_INT num_id
numeric id for mssql7+
Definition: tds.h:1210
void tdsdump_log(const char *file, unsigned int level_line, const char *fmt,...)
This function write a message to the debug log.
Definition: log.c:371
Log hex dump of packets to/from the server.
Definition: tds.h:1092
unsigned char out_flag
output buffer type
Definition: tds.h:1307
tds_end
Flags returned in TDS_DONE token.
Definition: tds.h:248
int tds_get_dynid(TDSSOCKET *tds, char **id)
Get an id for dynamic query based on TDS information.
Definition: query.c:1721
int tds7_get_instance_port(const char *ip_addr, const char *instance)
Get port of given instance.
Definition: net.c:819
Metadata about columns in regular and compute rows.
Definition: tds.h:948
Definition: tds.h:883
int tds_get_string(TDSSOCKET *tds, int string_len, char *dest, size_t dest_size)
Fetch a string from the wire.
Definition: read.c:186
void * tds_alloc_param_data(TDSCOLUMN *curparam)
Allocate data for a parameter.
Definition: mem.c:267
void tds_set_param_type(TDSSOCKET *tds, TDSCOLUMN *curcol, TDS_SERVER_TYPE type)
Set type of column initializing all dependency.
Definition: data.c:72
TDS_SMALLINT tds_get_smallint(TDSSOCKET *tds)
Get an int16 from the server.
Definition: read.c:110
enum _TDS_STATE TDS_STATE
values for tds-&gt;state
Holds information for a dynamic (also called prepared) query.
Definition: tds.h:1199
char * query
SQL query.
Definition: tds.h:1173
int tds_get_char_data(TDSSOCKET *tds, char *row_buffer, size_t wire_size, TDSCOLUMN *curcol)
Fetch character data the wire.
Definition: read.c:229
TDS_TINYINT hasargs
cursor parameters exists ?
Definition: tds.h:1171
int tds_get_size_by_type(int servertype)
Return the number of bytes needed by specified type.
Definition: read.c:322
Log asynchronous function starts or completes.
Definition: tds.h:1087
void * tds_get_n(TDSSOCKET *tds, void *dest, int need)
Get N bytes from the buffer and return them in the already allocated space given to us...
Definition: read.c:290
Holds informations about a cursor.
Definition: tds.h:1163
TDS_INT cursor_rows
&lt; number of updatable columns
Definition: tds.h:1177
void tdsdump_off(void)
Temporarily turn off logging.
Definition: log.c:93
int tds_flush_packet(TDSSOCKET *tds)
Flush packet to server.
Definition: write.c:292
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
char * tds_timestamp_str(char *str, int maxlen)
Definition: threadsafe.c:90
Definition: tds.h:1118
DSTR server_name
server name (in freetds.conf)
Definition: tds.h:850
char * query
saved query, we need to know original query if prepare is impossible
Definition: tds.h:1227
no data expected
Definition: tds.h:1049
Definition: tds.h:1236