Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

tds.h

Go to the documentation of this file.
00001 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
00002  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005  Brian Bruns
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  */
00019 
00020 #ifndef _tds_h_
00021 #define _tds_h_
00022 
00023 /* $Id: tds.h,v 1.284 2007/12/27 13:45:22 freddy77 Exp $ */
00024 
00025 #include <stdarg.h>
00026 #include <stdio.h>
00027 #include <time.h>
00028 
00029 /* forward declaration */
00030 typedef struct tdsiconvinfo TDSICONV;
00031 typedef struct tds_socket TDSSOCKET;
00032 
00033 #include "tdsver.h"
00034 #include "tds_sysdep_public.h"
00035 #ifdef _FREETDS_LIBRARY_SOURCE
00036 #include "tds_sysdep_private.h"
00037 #endif /* _FREETDS_LIBRARY_SOURCE */
00038 
00039 #ifdef __cplusplus
00040 extern "C"
00041 {
00042 #if 0
00043 }
00044 #endif
00045 #endif
00046 
00052 typedef struct _tds_compiletime_settings
00053 {
00054         const char *freetds_version;    /* release version of FreeTDS */
00055         const char *sysconfdir;         /* location of freetds.conf */
00056         const char *last_update;        /* latest software_version date among the modules */
00057         int msdblib;            /* for MS style dblib */
00058         int sybase_compat;      /* enable increased Open Client binary compatibility */
00059         int threadsafe;         /* compile for thread safety default=no */
00060         int libiconv;           /* search for libiconv in DIR/include and DIR/lib */
00061         const char *tdsver;     /* TDS protocol version (4.2/4.6/5.0/7.0/8.0) 5.0 */
00062         int iodbc;              /* build odbc driver against iODBC in DIR */
00063         int unixodbc;           /* build odbc driver against unixODBC in DIR */
00064 
00065 } TDS_COMPILETIME_SETTINGS;
00066 
00067 struct DSTR_STRUCT {
00068         char *dstr_s;
00069         size_t dstr_size;
00070 };
00071 typedef struct DSTR_STRUCT DSTR;
00072 
00088 /* 
00089  * All references to data that touch the wire should use the following typedefs.  
00090  *
00091  * If you have problems on 64-bit machines and the code is 
00092  * using a native datatype, please change it to use
00093  * these. (In the TDS layer only, the API layers have their
00094  * own typedefs which equate to these).
00095  */
00096 typedef char TDS_CHAR;                                  /*  8-bit char     */
00097 typedef unsigned char TDS_UCHAR;                        /*  8-bit uchar    */
00098 typedef unsigned char TDS_TINYINT;                      /*  8-bit unsigned */
00099 typedef tds_sysdep_int16_type TDS_SMALLINT;             /* 16-bit int      */
00100 typedef unsigned tds_sysdep_int16_type TDS_USMALLINT;   /* 16-bit unsigned */
00101 typedef tds_sysdep_int32_type TDS_INT;                  /* 32-bit int      */
00102 typedef unsigned tds_sysdep_int32_type TDS_UINT;        /* 32-bit unsigned */
00103 typedef tds_sysdep_real32_type TDS_REAL;                /* 32-bit real     */
00104 typedef tds_sysdep_real64_type TDS_FLOAT;               /* 64-bit real     */
00105 typedef tds_sysdep_int64_type TDS_INT8;                 /* 64-bit integer  */
00106 typedef unsigned tds_sysdep_int64_type TDS_UINT8;       /* 64-bit unsigned */
00107 typedef tds_sysdep_intptr_type TDS_INTPTR;
00108 
00109 typedef struct tdsnumeric
00110 {
00111         unsigned char precision;
00112         unsigned char scale;
00113         unsigned char array[33];
00114 } TDS_NUMERIC;
00115 
00116 typedef struct tdsoldmoney
00117 {
00118         TDS_INT mnyhigh;
00119         TDS_UINT mnylow;
00120 } TDS_OLD_MONEY;
00121 
00122 typedef union tdsmoney
00123 {
00124         TDS_OLD_MONEY tdsoldmoney;
00125         TDS_INT8 mny;
00126 } TDS_MONEY;
00127 
00128 typedef struct tdsmoney4
00129 {
00130         TDS_INT mny4;
00131 } TDS_MONEY4;
00132 
00133 typedef struct tdsdatetime
00134 {
00135         TDS_INT dtdays;
00136         TDS_INT dttime;
00137 } TDS_DATETIME;
00138 
00139 typedef struct tdsdatetime4
00140 {
00141         TDS_USMALLINT days;
00142         TDS_USMALLINT minutes;
00143 } TDS_DATETIME4;
00144 
00145 typedef struct tdsvarbinary
00146 {
00147         TDS_SMALLINT len;
00148         TDS_CHAR array[256];
00149 } TDS_VARBINARY;
00150 typedef struct tdsvarchar
00151 {
00152         TDS_INT len;
00153         TDS_CHAR array[256];
00154 } TDS_VARCHAR;
00155 
00156 typedef struct tdsunique
00157 {
00158         TDS_UINT Data1;
00159         TDS_USMALLINT Data2;
00160         TDS_USMALLINT Data3;
00161         TDS_UCHAR Data4[8];
00162 } TDS_UNIQUE;
00163 
00165 typedef struct tdsdaterec
00166 {
00167         TDS_INT year;          
00168         TDS_INT month;         
00169         TDS_INT day;           
00170         TDS_INT dayofyear;     
00171         TDS_INT weekday;       
00172         TDS_INT hour;          
00173         TDS_INT minute;        
00174         TDS_INT second;        
00175         TDS_INT millisecond;   
00176         TDS_INT tzone;
00177 } TDSDATEREC;
00178 
00184 extern const int tds_numeric_bytes_per_prec[];
00185 
00186 #define TDS_SUCCEED          1
00187 #define TDS_FAIL             0
00188 #define TDS_NO_MORE_RESULTS  2
00189 #define TDS_CANCELLED        3
00190 
00191 #define TDS_INT_CONTINUE 1
00192 #define TDS_INT_CANCEL 2
00193 #define TDS_INT_TIMEOUT 3
00194 
00195 
00196 #define TDS_NO_COUNT         -1
00197 
00198 #define TDS_ROW_RESULT        4040
00199 #define TDS_PARAM_RESULT      4042
00200 #define TDS_STATUS_RESULT     4043
00201 #define TDS_MSG_RESULT        4044
00202 #define TDS_COMPUTE_RESULT    4045
00203 #define TDS_CMD_DONE          4046
00204 #define TDS_CMD_SUCCEED       4047
00205 #define TDS_CMD_FAIL          4048
00206 #define TDS_ROWFMT_RESULT     4049
00207 #define TDS_COMPUTEFMT_RESULT 4050
00208 #define TDS_DESCRIBE_RESULT   4051
00209 #define TDS_DONE_RESULT       4052
00210 #define TDS_DONEPROC_RESULT   4053
00211 #define TDS_DONEINPROC_RESULT 4054
00212 #define TDS_OTHERS_RESULT     4055
00213 
00214 enum tds_token_results
00215 {
00216         TDS_TOKEN_RES_OTHERS,
00217         TDS_TOKEN_RES_ROWFMT,
00218         TDS_TOKEN_RES_COMPUTEFMT,
00219         TDS_TOKEN_RES_PARAMFMT,
00220         TDS_TOKEN_RES_DONE,
00221         TDS_TOKEN_RES_ROW,
00222         TDS_TOKEN_RES_COMPUTE,
00223         TDS_TOKEN_RES_PROC,
00224         TDS_TOKEN_RES_MSG
00225 };
00226 
00227 #define TDS_TOKEN_FLAG(flag) TDS_RETURN_##flag = (1 << (TDS_TOKEN_RES_##flag*2)), TDS_STOPAT_##flag = (2 << (TDS_TOKEN_RES_##flag*2))
00228 
00229 enum tds_token_flags
00230 {
00231         TDS_HANDLE_ALL = 0,
00232         TDS_TOKEN_FLAG(OTHERS),
00233         TDS_TOKEN_FLAG(ROWFMT),
00234         TDS_TOKEN_FLAG(COMPUTEFMT),
00235         TDS_TOKEN_FLAG(PARAMFMT),
00236         TDS_TOKEN_FLAG(DONE),
00237         TDS_TOKEN_FLAG(ROW),
00238         TDS_TOKEN_FLAG(COMPUTE),
00239         TDS_TOKEN_FLAG(PROC),
00240         TDS_TOKEN_FLAG(MSG),
00241         TDS_TOKEN_RESULTS = TDS_RETURN_ROWFMT|TDS_RETURN_COMPUTEFMT|TDS_RETURN_DONE|TDS_STOPAT_ROW|TDS_STOPAT_COMPUTE|TDS_RETURN_PROC,
00242         TDS_TOKEN_TRAILING = TDS_STOPAT_ROWFMT|TDS_STOPAT_COMPUTEFMT|TDS_STOPAT_ROW|TDS_STOPAT_COMPUTE|TDS_STOPAT_MSG|TDS_STOPAT_OTHERS
00243 };
00244 
00248 enum tds_end
00249 {
00250           TDS_DONE_FINAL        = 0x00  
00251         , TDS_DONE_MORE_RESULTS = 0x01  
00252         , TDS_DONE_ERROR        = 0x02  
00253         , TDS_DONE_INXACT       = 0x04  
00254         , TDS_DONE_PROC         = 0x08  
00255         , TDS_DONE_COUNT        = 0x10  
00256         , TDS_DONE_CANCELLED    = 0x20  
00257         , TDS_DONE_EVENT        = 0x40  /* part of an event notification. */
00258         , TDS_DONE_SRVERROR     = 0x100 
00260         /* after the above flags, a TDS_DONE packet has a field describing the state of the transaction */
00261         , TDS_DONE_NO_TRAN      = 0     /* No transaction in effect */
00262         , TDS_DONE_TRAN_SUCCEED = 1     /* Transaction completed successfully */
00263         , TDS_DONE_TRAN_PROGRESS= 2     /* Transaction in progress */
00264         , TDS_DONE_STMT_ABORT   = 3     /* A statement aborted */
00265         , TDS_DONE_TRAN_ABORT   = 4     /* Transaction aborted */
00266 };
00267 
00268 
00269 /*
00270  * TDSERRNO is emitted by libtds to the client library's error handler
00271  * (which may in turn call the client's error handler).
00272  * These match the db-lib msgno, because the same values have the same meaning
00273  * in db-lib and ODBC.  ct-lib maps them to ct-lib numbers (todo). 
00274  */
00275 typedef enum {  TDSEICONVIU    = 2400, 
00276                 TDSEICONVAVAIL = 2401, 
00277                 TDSEICONVO     = 2402, 
00278                 TDSEICONVI     = 2403, 
00279                 TDSEICONV2BIG  = 2404, 
00280                 TDSESYNC = 20001, 
00281                 TDSEFCON = 20002, 
00282                 TDSETIME = 20003, 
00283                 TDSEREAD = 20004, 
00284                 TDSEWRIT = 20006, 
00285                 TDSESOCK = 20008, 
00286                 TDSECONN = 20009, 
00287                 TDSEPWD  = 20014, 
00288                 TDSESEOF = 20017, 
00289                 TDSERPND = 20019, 
00290                 TDSEBTOK = 20020, 
00291                 TDSEOOB  = 20022, 
00292                 TDSECLOS = 20056,
00293                 TDSEUSCT = 20058, 
00294                 TDSEUTDS = 20146, 
00295                 TDSEEUNR = 20185, 
00296                 TDSECAP  = 20203, 
00297                 TDSENEG  = 20210, 
00298                 TDSEUMSG = 20212, 
00299                 TDSECAPTYP  = 20213, 
00300                 TDSECLOSEIN = 20292 
00301 } TDSERRNO;
00302 
00303 /*
00304  * TDS_ERROR indicates a successful processing, but that a TDS_ERROR_TOKEN or TDS_EED_TOKEN error was encountered.  
00305  * TDS_FAIL indicates an unrecoverable failure.
00306  */
00307 #define TDS_ERROR            3
00308 #define TDS_DONT_RETURN      42
00309 
00310 #define TDS5_PARAMFMT2_TOKEN       32   /* 0x20 */
00311 #define TDS_LANGUAGE_TOKEN         33   /* 0x21    TDS 5.0 only              */
00312 #define TDS_ORDERBY2_TOKEN         34   /* 0x22 */
00313 #define TDS_ROWFMT2_TOKEN          97   /* 0x61    TDS 5.0 only              */
00314 #define TDS_LOGOUT_TOKEN          113   /* 0x71    TDS 5.0 only? ct_close()  */
00315 #define TDS_RETURNSTATUS_TOKEN    121   /* 0x79                              */
00316 #define TDS_PROCID_TOKEN          124   /* 0x7C    TDS 4.2 only - TDS_PROCID */
00317 #define TDS7_RESULT_TOKEN         129   /* 0x81    TDS 7.0 only              */
00318 #define TDS7_COMPUTE_RESULT_TOKEN 136   /* 0x88    TDS 7.0 only              */
00319 #define TDS_COLNAME_TOKEN         160   /* 0xA0    TDS 4.2 only              */
00320 #define TDS_COLFMT_TOKEN          161   /* 0xA1    TDS 4.2 only - TDS_COLFMT */
00321 #define TDS_DYNAMIC2_TOKEN        163   /* 0xA3 */
00322 #define TDS_TABNAME_TOKEN         164   /* 0xA4 */
00323 #define TDS_COLINFO_TOKEN         165   /* 0xA5 */
00324 #define TDS_OPTIONCMD_TOKEN       166   /* 0xA6 */
00325 #define TDS_COMPUTE_NAMES_TOKEN   167   /* 0xA7 */
00326 #define TDS_COMPUTE_RESULT_TOKEN  168   /* 0xA8 */
00327 #define TDS_ORDERBY_TOKEN         169   /* 0xA9    TDS_ORDER                 */
00328 #define TDS_ERROR_TOKEN           170   /* 0xAA                              */
00329 #define TDS_INFO_TOKEN            171   /* 0xAB                              */
00330 #define TDS_PARAM_TOKEN           172   /* 0xAC    RETURNVALUE?              */
00331 #define TDS_LOGINACK_TOKEN        173   /* 0xAD                              */
00332 #define TDS_CONTROL_TOKEN         174   /* 0xAE    TDS_CONTROL               */
00333 #define TDS_ROW_TOKEN             209   /* 0xD1                              */
00334 #define TDS_CMP_ROW_TOKEN         211   /* 0xD3                              */
00335 #define TDS5_PARAMS_TOKEN         215   /* 0xD7    TDS 5.0 only              */
00336 #define TDS_CAPABILITY_TOKEN      226   /* 0xE2                              */
00337 #define TDS_ENVCHANGE_TOKEN       227   /* 0xE3                              */
00338 #define TDS_EED_TOKEN             229   /* 0xE5                              */
00339 #define TDS_DBRPC_TOKEN           230   /* 0xE6                              */
00340 #define TDS5_DYNAMIC_TOKEN        231   /* 0xE7    TDS 5.0 only              */
00341 #define TDS5_PARAMFMT_TOKEN       236   /* 0xEC    TDS 5.0 only              */
00342 #define TDS_AUTH_TOKEN            237   /* 0xED    TDS 7.0 only              */
00343 #define TDS_RESULT_TOKEN          238   /* 0xEE                              */
00344 #define TDS_DONE_TOKEN            253   /* 0xFD    TDS_DONE                  */
00345 #define TDS_DONEPROC_TOKEN        254   /* 0xFE    TDS_DONEPROC              */
00346 #define TDS_DONEINPROC_TOKEN      255   /* 0xFF    TDS_DONEINPROC            */
00347 
00348 /* CURSOR support: TDS 5.0 only*/
00349 #define TDS_CURCLOSE_TOKEN        128  /* 0x80    TDS 5.0 only              */
00350 #define TDS_CURDELETE_TOKEN       129  /* 0x81    TDS 5.0 only              */
00351 #define TDS_CURFETCH_TOKEN        130  /* 0x82    TDS 5.0 only              */
00352 #define TDS_CURINFO_TOKEN         131  /* 0x83    TDS 5.0 only              */
00353 #define TDS_CUROPEN_TOKEN         132  /* 0x84    TDS 5.0 only              */
00354 #define TDS_CURDECLARE_TOKEN      134  /* 0x86    TDS 5.0 only              */
00355 
00356 enum {
00357         TDS_CUR_ISTAT_UNUSED    = 0x00,
00358         TDS_CUR_ISTAT_DECLARED  = 0x01,
00359         TDS_CUR_ISTAT_OPEN      = 0x02,
00360         TDS_CUR_ISTAT_CLOSED    = 0x04,
00361         TDS_CUR_ISTAT_RDONLY    = 0x08,
00362         TDS_CUR_ISTAT_UPDATABLE = 0x10,
00363         TDS_CUR_ISTAT_ROWCNT    = 0x20,
00364         TDS_CUR_ISTAT_DEALLOC   = 0x40
00365 };
00366 
00367 /* 
00368  * Cursor Declare, SetRows, Open and Close all return 0x83 token. 
00369  * But only SetRows includes the rowcount (4 byte) in the stream. 
00370  * So for Setrows we read the rowcount from the stream and not for others. 
00371  * These values are useful to determine when to read the rowcount from the packet
00372  */
00373 #define IS_DECLARE  100
00374 #define IS_CURROW   200
00375 #define IS_OPEN     300
00376 #define IS_CLOSE    400
00377 
00378 /* states for tds_process_messages() */
00379 #define PROCESS_ROWS    0
00380 #define PROCESS_RESULTS 1
00381 #define CANCEL_PROCESS  2
00382 #define GOTO_1ST_ROW    3
00383 #define LOGIN           4
00384 
00385 /* environment type field */
00386 #define TDS_ENV_DATABASE        1
00387 #define TDS_ENV_LANG            2
00388 #define TDS_ENV_CHARSET         3
00389 #define TDS_ENV_PACKSIZE        4
00390 #define TDS_ENV_LCID            5
00391 #define TDS_ENV_SQLCOLLATION    7
00392 #define TDS_ENV_BEGINTRANS      8
00393 #define TDS_ENV_COMMITTRANS     9
00394 #define TDS_ENV_ROLLBACKTRANS   10
00395 
00396 /* string types */
00397 #define TDS_NULLTERM -9
00398 
00399 /* Microsoft internal stored procedure id's */
00400 
00401 #define TDS_SP_CURSOR           1
00402 #define TDS_SP_CURSOROPEN       2
00403 #define TDS_SP_CURSORPREPARE    3
00404 #define TDS_SP_CURSOREXECUTE    4
00405 #define TDS_SP_CURSORPREPEXEC   5
00406 #define TDS_SP_CURSORUNPREPARE  6
00407 #define TDS_SP_CURSORFETCH      7
00408 #define TDS_SP_CURSOROPTION     8
00409 #define TDS_SP_CURSORCLOSE      9
00410 #define TDS_SP_EXECUTESQL      10
00411 #define TDS_SP_PREPARE         11
00412 #define TDS_SP_EXECUTE         12
00413 #define TDS_SP_PREPEXEC        13
00414 #define TDS_SP_PREPEXECRPC     14
00415 #define TDS_SP_UNPREPARE       15
00416 /* 
00417  * <rant> Sybase does an awful job of this stuff, non null ints of size 1 2 
00418  * and 4 have there own codes but nullable ints are lumped into INTN
00419  * sheesh! </rant>
00420  */
00421 typedef enum
00422 {
00423         SYBCHAR = 47,           /* 0x2F */
00424 #define SYBCHAR SYBCHAR
00425         SYBVARCHAR = 39,        /* 0x27 */
00426 #define SYBVARCHAR      SYBVARCHAR
00427         SYBINTN = 38,           /* 0x26 */
00428 #define SYBINTN SYBINTN
00429         SYBINT1 = 48,           /* 0x30 */
00430 #define SYBINT1 SYBINT1
00431         SYBINT2 = 52,           /* 0x34 */
00432 #define SYBINT2 SYBINT2
00433         SYBINT4 = 56,           /* 0x38 */
00434 #define SYBINT4 SYBINT4
00435         SYBFLT8 = 62,           /* 0x3E */
00436 #define SYBFLT8 SYBFLT8
00437         SYBDATETIME = 61,       /* 0x3D */
00438 #define SYBDATETIME     SYBDATETIME
00439         SYBBIT = 50,            /* 0x32 */
00440 #define SYBBIT  SYBBIT
00441         SYBTEXT = 35,           /* 0x23 */
00442 #define SYBTEXT SYBTEXT
00443         SYBNTEXT = 99,          /* 0x63 */
00444 #define SYBNTEXT        SYBNTEXT
00445         SYBIMAGE = 34,          /* 0x22 */
00446 #define SYBIMAGE        SYBIMAGE
00447         SYBMONEY4 = 122,        /* 0x7A */
00448 #define SYBMONEY4       SYBMONEY4
00449         SYBMONEY = 60,          /* 0x3C */
00450 #define SYBMONEY        SYBMONEY
00451         SYBDATETIME4 = 58,      /* 0x3A */
00452 #define SYBDATETIME4    SYBDATETIME4
00453         SYBREAL = 59,           /* 0x3B */
00454 #define SYBREAL SYBREAL
00455         SYBBINARY = 45,         /* 0x2D */
00456 #define SYBBINARY       SYBBINARY
00457         SYBVOID = 31,           /* 0x1F */
00458 #define SYBVOID SYBVOID
00459         SYBVARBINARY = 37,      /* 0x25 */
00460 #define SYBVARBINARY    SYBVARBINARY
00461         SYBBITN = 104,          /* 0x68 */
00462 #define SYBBITN SYBBITN
00463         SYBNUMERIC = 108,       /* 0x6C */
00464 #define SYBNUMERIC      SYBNUMERIC
00465         SYBDECIMAL = 106,       /* 0x6A */
00466 #define SYBDECIMAL      SYBDECIMAL
00467         SYBFLTN = 109,          /* 0x6D */
00468 #define SYBFLTN SYBFLTN
00469         SYBMONEYN = 110,        /* 0x6E */
00470 #define SYBMONEYN       SYBMONEYN
00471         SYBDATETIMN = 111,      /* 0x6F */
00472 #define SYBDATETIMN     SYBDATETIMN
00473 
00474 /*
00475  * MS only types
00476  */
00477         SYBNVARCHAR = 103,      /* 0x67 */
00478 #define SYBNVARCHAR     SYBNVARCHAR
00479         SYBINT8 = 127,          /* 0x7F */
00480 #define SYBINT8 SYBINT8
00481         XSYBCHAR = 175,         /* 0xAF */
00482 #define XSYBCHAR        XSYBCHAR
00483         XSYBVARCHAR = 167,      /* 0xA7 */
00484 #define XSYBVARCHAR     XSYBVARCHAR
00485         XSYBNVARCHAR = 231,     /* 0xE7 */
00486 #define XSYBNVARCHAR    XSYBNVARCHAR
00487         XSYBNCHAR = 239,        /* 0xEF */
00488 #define XSYBNCHAR       XSYBNCHAR
00489         XSYBVARBINARY = 165,    /* 0xA5 */
00490 #define XSYBVARBINARY   XSYBVARBINARY
00491         XSYBBINARY = 173,       /* 0xAD */
00492 #define XSYBBINARY      XSYBBINARY
00493         SYBUNIQUE = 36,         /* 0x24 */
00494 #define SYBUNIQUE       SYBUNIQUE
00495         SYBVARIANT = 98,        /* 0x62 */
00496 #define SYBVARIANT      SYBVARIANT
00497 
00498 /*
00499  * Sybase only types
00500  */
00501         SYBLONGBINARY = 225,    /* 0xE1 */
00502 #define SYBLONGBINARY   SYBLONGBINARY
00503         SYBUINT1 = 64,          /* 0x40 */
00504 #define SYBUINT1        SYBUINT1
00505         SYBUINT2 = 65,          /* 0x41 */
00506 #define SYBUINT2        SYBUINT2
00507         SYBUINT4 = 66,          /* 0x42 */
00508 #define SYBUINT4        SYBUINT4
00509         SYBUINT8 = 67,          /* 0x43 */
00510 #define SYBUINT8        SYBUINT8
00511         SYBBLOB = 36,           /* 0x24 */
00512 #define SYBBLOB         SYBBLOB
00513         SYBBOUNDARY = 104,      /* 0x68 */
00514 #define SYBBOUNDARY     SYBBOUNDARY
00515         SYBDATE = 49,           /* 0x31 */
00516 #define SYBDATE         SYBDATE
00517         SYBDATEN = 123,         /* 0x7B */
00518 #define SYBDATEN        SYBDATEN
00519         SYB5INT8 = 191,         /* 0xBF */
00520 #define SYB5INT8                SYB5INT8
00521         SYBINTERVAL = 46,       /* 0x2E */
00522 #define SYBINTERVAL     SYBINTERVAL
00523         SYBLONGCHAR = 175,      /* 0xAF */
00524 #define SYBLONGCHAR     SYBLONGCHAR
00525         SYBSENSITIVITY = 103,   /* 0x67 */
00526 #define SYBSENSITIVITY  SYBSENSITIVITY
00527         SYBSINT1 = 176,         /* 0xB0 */
00528 #define SYBSINT1        SYBSINT1
00529         SYBTIME = 51,           /* 0x33 */
00530 #define SYBTIME         SYBTIME
00531         SYBTIMEN = 147,         /* 0x93 */
00532 #define SYBTIMEN        SYBTIMEN
00533         SYBUINTN = 68,          /* 0x44 */
00534 #define SYBUINTN        SYBUINTN
00535         SYBUNITEXT = 174,       /* 0xAE */
00536 #define SYBUNITEXT      SYBUNITEXT
00537         SYBXML = 163,           /* 0xA3 */
00538 #define SYBXML          SYBXML
00539 
00540 } TDS_SERVER_TYPE;
00541 
00542 
00543 typedef enum
00544 {
00545         USER_UNICHAR_TYPE = 34,         /* 0x22 */
00546         USER_UNIVARCHAR_TYPE = 35       /* 0x23 */
00547 } TDS_USER_TYPE;
00548 
00549 #define SYBAOPCNT  0x4b
00550 #define SYBAOPCNTU 0x4c
00551 #define SYBAOPSUM  0x4d
00552 #define SYBAOPSUMU 0x4e
00553 #define SYBAOPAVG  0x4f
00554 #define SYBAOPAVGU 0x50
00555 #define SYBAOPMIN  0x51
00556 #define SYBAOPMAX  0x52
00557 
00558 /* mssql2k compute operator */
00559 #define SYBAOPCNT_BIG           0x09
00560 #define SYBAOPSTDEV             0x30
00561 #define SYBAOPSTDEVP            0x31
00562 #define SYBAOPVAR               0x32
00563 #define SYBAOPVARP              0x33
00564 #define SYBAOPCHECKSUM_AGG      0x72
00565 
00566 
00570 typedef enum
00571 {
00572           TDS_OPT_SET = 1       /* Set an option. */
00573         , TDS_OPT_DEFAULT = 2   /* Set option to its default value. */
00574         , TDS_OPT_LIST = 3      /* Request current setting of a specific option. */
00575         , TDS_OPT_INFO = 4      /* Report current setting of a specific option. */
00576 } TDS_OPTION_CMD;
00577 
00578 typedef enum
00579 {
00580           TDS_OPT_DATEFIRST = 1         /* 0x01 */
00581         , TDS_OPT_TEXTSIZE = 2          /* 0x02 */
00582         , TDS_OPT_STAT_TIME = 3         /* 0x03 */
00583         , TDS_OPT_STAT_IO = 4           /* 0x04 */
00584         , TDS_OPT_ROWCOUNT = 5          /* 0x05 */
00585         , TDS_OPT_NATLANG = 6           /* 0x06 */
00586         , TDS_OPT_DATEFORMAT = 7        /* 0x07 */
00587         , TDS_OPT_ISOLATION = 8         /* 0x08 */
00588         , TDS_OPT_AUTHON = 9            /* 0x09 */
00589         , TDS_OPT_CHARSET = 10          /* 0x0a */
00590         , TDS_OPT_SHOWPLAN = 13         /* 0x0d */
00591         , TDS_OPT_NOEXEC = 14           /* 0x0e */
00592         , TDS_OPT_ARITHIGNOREON = 15    /* 0x0f */
00593         , TDS_OPT_ARITHABORTON = 17     /* 0x11 */
00594         , TDS_OPT_PARSEONLY = 18        /* 0x12 */
00595         , TDS_OPT_GETDATA = 20          /* 0x14 */
00596         , TDS_OPT_NOCOUNT = 21          /* 0x15 */
00597         , TDS_OPT_FORCEPLAN = 23        /* 0x17 */
00598         , TDS_OPT_FORMATONLY = 24       /* 0x18 */
00599         , TDS_OPT_CHAINXACTS = 25       /* 0x19 */
00600         , TDS_OPT_CURCLOSEONXACT = 26   /* 0x1a */
00601         , TDS_OPT_FIPSFLAG = 27         /* 0x1b */
00602         , TDS_OPT_RESTREES = 28         /* 0x1c */
00603         , TDS_OPT_IDENTITYON = 29       /* 0x1d */
00604         , TDS_OPT_CURREAD = 30          /* 0x1e */
00605         , TDS_OPT_CURWRITE = 31         /* 0x1f */
00606         , TDS_OPT_IDENTITYOFF = 32      /* 0x20 */
00607         , TDS_OPT_AUTHOFF = 33          /* 0x21 */
00608         , TDS_OPT_ANSINULL = 34         /* 0x22 */
00609         , TDS_OPT_QUOTED_IDENT = 35     /* 0x23 */
00610         , TDS_OPT_ARITHIGNOREOFF = 36   /* 0x24 */
00611         , TDS_OPT_ARITHABORTOFF = 37    /* 0x25 */
00612         , TDS_OPT_TRUNCABORT = 38       /* 0x26 */
00613 } TDS_OPTION;
00614 
00615 typedef union tds_option_arg
00616 {
00617         TDS_TINYINT ti;
00618         TDS_INT i;
00619         TDS_CHAR *c;
00620 } TDS_OPTION_ARG;
00621 
00622 enum {
00623         TDS_OPT_ARITHOVERFLOW = 0x01,
00624         TDS_OPT_NUMERICTRUNC = 0x02
00625 };
00626 
00627 enum TDS_OPT_DATEFIRST_CHOICE
00628 {
00629         TDS_OPT_MONDAY = 1, TDS_OPT_TUESDAY = 2, TDS_OPT_WEDNESDAY = 3, TDS_OPT_THURSDAY = 4, TDS_OPT_FRIDAY = 5, TDS_OPT_SATURDAY =
00630                 6, TDS_OPT_SUNDAY = 7
00631 };
00632 
00633 enum TDS_OPT_DATEFORMAT_CHOICE
00634 {
00635         TDS_OPT_FMTMDY = 1, TDS_OPT_FMTDMY = 2, TDS_OPT_FMTYMD = 3, TDS_OPT_FMTYDM = 4, TDS_OPT_FMTMYD = 5, TDS_OPT_FMTDYM = 6
00636 };
00637 enum TDS_OPT_ISOLATION_CHOICE
00638 {
00639         TDS_OPT_LEVEL1 = 1, TDS_OPT_LEVEL3 = 3
00640 };
00641 
00642 typedef enum tds_packet_type
00643 {
00644         TDS_QUERY = 1,
00645         TDS_LOGIN = 2,
00646         TDS_RPC = 3,
00647         TDS_REPLY = 4,
00648         TDS_CANCEL = 6,
00649         TDS_BULK = 7,
00650         TDS_NORMAL = 15,
00651         TDS7_LOGIN = 16,
00652         TDS7_AUTH = 17,
00653         TDS8_PRELOGIN = 18
00654 } TDS_PACKET_TYPE;
00655 
00656 typedef enum tds_encryption_level {
00657         TDS_ENCRYPTION_OFF, TDS_ENCRYPTION_REQUEST, TDS_ENCRYPTION_REQUIRE
00658 } TDS_ENCRYPTION_LEVEL;
00659 
00660 #define TDS_ZERO_FREE(x) do {free((x)); (x) = NULL;} while(0)
00661 #define TDS_VECTOR_SIZE(x) (sizeof(x)/sizeof(x[0]))
00662 
00663 /*
00664  * TODO use system macros for optimization
00665  * See mcrypt for reference and linux kernel source for optimization
00666  * check if unaligned access and use fast write/read when implemented
00667  */
00668 #define TDS_BYTE_SWAP16(value)                 \
00669          (((((unsigned short)value)<<8) & 0xFF00)   | \
00670           ((((unsigned short)value)>>8) & 0x00FF))
00671 
00672 #define TDS_BYTE_SWAP32(value)                     \
00673          (((((unsigned long)value)<<24) & 0xFF000000)  | \
00674           ((((unsigned long)value)<< 8) & 0x00FF0000)  | \
00675           ((((unsigned long)value)>> 8) & 0x0000FF00)  | \
00676           ((((unsigned long)value)>>24) & 0x000000FF))
00677 
00678 #define is_end_token(x) (x==TDS_DONE_TOKEN    || \
00679                         x==TDS_DONEPROC_TOKEN    || \
00680                         x==TDS_DONEINPROC_TOKEN)
00681 
00682 #define is_hard_end_token(x) (x==TDS_DONE_TOKEN    || \
00683                         x==TDS_DONEPROC_TOKEN)
00684 
00685 #define is_msg_token(x) (x==TDS_INFO_TOKEN    || \
00686                         x==TDS_ERROR_TOKEN    || \
00687                         x==TDS_EED_TOKEN)
00688 
00689 #define is_result_token(x) (x==TDS_RESULT_TOKEN || \
00690                         x==TDS_ROWFMT2_TOKEN    || \
00691                         x==TDS7_RESULT_TOKEN    || \
00692                         x==TDS_COLFMT_TOKEN     || \
00693                         x==TDS_COLNAME_TOKEN    || \
00694                         x==TDS_RETURNSTATUS_TOKEN)
00695 
00696 /* FIXME -- not a complete list */
00697 #define is_fixed_type(x) (x==SYBINT1    || \
00698                         x==SYBINT2      || \
00699                         x==SYBINT4      || \
00700                         x==SYBINT8      || \
00701                         x==SYBREAL      || \
00702                         x==SYBFLT8      || \
00703                         x==SYBDATETIME  || \
00704                         x==SYBDATETIME4 || \
00705                         x==SYBBIT       || \
00706                         x==SYBMONEY     || \
00707                         x==SYBMONEY4    || \
00708                         x==SYBVOID      || \
00709                         x==SYBUNIQUE)
00710 #define is_nullable_type(x) ( \
00711                         x==SYBBITN      || \
00712                      x==SYBINTN      || \
00713                      x==SYBFLTN      || \
00714                      x==SYBMONEYN    || \
00715                      x==SYBDATETIMN  || \
00716                      x==SYBVARCHAR   || \
00717                      x==SYBBINARY    || \
00718                      x==SYBVARBINARY || \
00719                      x==SYBTEXT      || \
00720                      x==SYBNTEXT     || \
00721                      x==SYBIMAGE)
00722 
00723 #define is_variable_type(x) ( \
00724         (x)==SYBTEXT    || \
00725         (x)==SYBIMAGE   || \
00726         (x)==SYBNTEXT   || \
00727         (x)==SYBCHAR    || \
00728         (x)==SYBVARCHAR || \
00729         (x)==SYBBINARY  || \
00730         (x)==SYBVARBINARY       || \
00731         (x)==SYBLONGBINARY      || \
00732         (x)==XSYBCHAR   || \
00733         (x)==XSYBVARCHAR        || \
00734         (x)==XSYBNVARCHAR       || \
00735         (x)==XSYBNCHAR)
00736 
00737 #define is_blob_type(x) (x==SYBTEXT || x==SYBIMAGE || x==SYBNTEXT)
00738 /* large type means it has a two byte size field */
00739 /* define is_large_type(x) (x>128) */
00740 #define is_numeric_type(x) (x==SYBNUMERIC || x==SYBDECIMAL)
00741 #define is_unicode_type(x) (x==XSYBNVARCHAR || x==XSYBNCHAR || x==SYBNTEXT)
00742 #define is_collate_type(x) (x==XSYBVARCHAR || x==XSYBCHAR || x==SYBTEXT || x==XSYBNVARCHAR || x==XSYBNCHAR || x==SYBNTEXT)
00743 #define is_ascii_type(x) ( x==XSYBCHAR || x==XSYBVARCHAR || x==SYBTEXT || x==SYBCHAR || x==SYBVARCHAR)
00744 #define is_binary_type(x) (x==SYBLONGBINARY)
00745 #define is_char_type(x) (is_unicode_type(x) || is_ascii_type(x))
00746 #define is_similar_type(x, y) ((is_char_type(x) && is_char_type(y)) || ((is_unicode_type(x) && is_unicode_type(y))))
00747 
00748 
00749 #define TDS_MAX_CAPABILITY      22
00750 #define MAXPRECISION            80
00751 #define TDS_MAX_CONN            4096
00752 #define TDS_MAX_DYNID_LEN       30
00753 
00754 /* defaults to use if no others are found */
00755 #define TDS_DEF_SERVER          "SYBASE"
00756 #define TDS_DEF_BLKSZ           512
00757 #define TDS_DEF_CHARSET         "iso_1"
00758 #define TDS_DEF_LANG            "us_english"
00759 #if TDS42
00760 #define TDS_DEF_MAJOR           4
00761 #define TDS_DEF_MINOR           2
00762 #define TDS_DEF_PORT            1433
00763 #elif TDS46
00764 #define TDS_DEF_MAJOR           4
00765 #define TDS_DEF_MINOR           6
00766 #define TDS_DEF_PORT            4000
00767 #elif TDS70
00768 #define TDS_DEF_MAJOR           7
00769 #define TDS_DEF_MINOR           0
00770 #define TDS_DEF_PORT            1433
00771 #elif TDS80
00772 #define TDS_DEF_MAJOR           8
00773 #define TDS_DEF_MINOR           0
00774 #define TDS_DEF_PORT            1433
00775 #else
00776 #define TDS_DEF_MAJOR           5
00777 #define TDS_DEF_MINOR           0
00778 #define TDS_DEF_PORT            4000
00779 #endif
00780 
00781 /* normalized strings from freetds.conf file */
00782 #define TDS_STR_VERSION  "tds version"
00783 #define TDS_STR_BLKSZ    "initial block size"
00784 #define TDS_STR_SWAPDT   "swap broken dates"
00785 #define TDS_STR_SWAPMNY  "swap broken money"
00786 #define TDS_STR_DUMPFILE "dump file"
00787 #define TDS_STR_DEBUGLVL "debug level"
00788 #define TDS_STR_DEBUGFLAGS "debug flags"
00789 #define TDS_STR_TIMEOUT  "timeout"
00790 #define TDS_STR_QUERY_TIMEOUT  "query timeout"
00791 #define TDS_STR_CONNTIMEOUT "connect timeout"
00792 #define TDS_STR_HOSTNAME "hostname"
00793 #define TDS_STR_HOST     "host"
00794 #define TDS_STR_PORT     "port"
00795 #define TDS_STR_TEXTSZ   "text size"
00796 /* for big endian hosts */
00797 #define TDS_STR_EMUL_LE "emulate little endian"
00798 #define TDS_STR_CHARSET "charset"
00799 #define TDS_STR_CLCHARSET       "client charset"
00800 #define TDS_STR_LANGUAGE        "language"
00801 #define TDS_STR_APPENDMODE      "dump file append"
00802 #define TDS_STR_DATEFMT "date format"
00803 #define TDS_STR_INSTANCE "instance"
00804 #define TDS_STR_ENCRYPTION       "encryption"
00805 /* conf values */
00806 #define TDS_STR_ENCRYPTION_OFF   "off"
00807 #define TDS_STR_ENCRYPTION_REQUEST "request"
00808 #define TDS_STR_ENCRYPTION_REQUIRE "require"
00809 
00810 
00811 /* TODO do a better check for alignment than this */
00812 typedef union
00813 {
00814         void *p;
00815         int i;
00816 } tds_align_struct;
00817 
00818 #define TDS_ALIGN_SIZE sizeof(tds_align_struct)
00819 
00820 #define TDS_MAX_LOGIN_STR_SZ 30
00821 typedef struct tds_login
00822 {
00823         DSTR server_name;
00824         DSTR server_addr;
00825         int port;
00826         TDS_TINYINT major_version;      /* TDS version */
00827         TDS_TINYINT minor_version;      /* TDS version */
00828         int block_size;
00829         DSTR language;          /* ie us-english */
00830         DSTR server_charset;    /*  ie iso_1 */
00831         TDS_INT connect_timeout;
00832         DSTR client_host_name;
00833         DSTR app_name;
00834         DSTR user_name;
00835         DSTR password;
00836         
00837         DSTR library;   /* Ct-Library, DB-Library,  TDS-Library or ODBC */
00838         TDS_TINYINT bulk_copy;
00839         TDS_TINYINT suppress_language;
00840         TDS_TINYINT encryption_level;
00841 
00842         TDS_INT query_timeout;
00843         unsigned char capabilities[TDS_MAX_CAPABILITY];
00844         DSTR client_charset;
00845 } TDSLOGIN;
00846 
00847 typedef struct tds_connection
00848 {
00849         /* first part of structure is the same of login one */
00850         DSTR server_name; 
00851         int port;          
00852         TDS_TINYINT major_version;
00853         TDS_TINYINT minor_version;
00854         int block_size;
00855         DSTR language;
00856         DSTR server_charset;    
00857         TDS_INT connect_timeout;
00858         DSTR client_host_name;
00859         DSTR server_host_name;
00860         DSTR app_name;
00861         DSTR user_name;     
00862         DSTR password;      
00863         DSTR library;
00864         TDS_TINYINT bulk_copy;
00865         TDS_TINYINT suppress_language;
00866         TDS_TINYINT encryption_level;
00867 
00868         TDS_INT query_timeout;
00869         unsigned char capabilities[TDS_MAX_CAPABILITY];
00870         DSTR client_charset;
00871 
00872         DSTR ip_addr;     
00873         DSTR instance_name;
00874         DSTR database;
00875         DSTR dump_file;
00876         int debug_flags;
00877         int text_size;
00878         int broken_dates;
00879         int broken_money;
00880         int emul_little_endian;
00881 } TDSCONNECTION;
00882 
00883 typedef struct tds_locale
00884 {
00885         char *language;
00886         char *server_charset;
00887         char *client_charset;
00888         char *date_fmt;
00889 } TDSLOCALE;
00890 
00895 typedef struct tds_blob
00896 {
00897         TDS_CHAR *textvalue;
00898         TDS_CHAR textptr[16];
00899         TDS_CHAR timestamp[8];
00900 } TDSBLOB;
00901 
00905 typedef struct
00906 {
00907         TDS_USMALLINT locale_id;        /* master..syslanguages.lcid */
00908         TDS_USMALLINT flags;
00909         TDS_UCHAR charset_id;           /* or zero */
00910 } TDS8_COLLATION;
00911 
00912 /* SF stands for "sort flag" */
00913 #define TDS_SF_BIN                   (TDS_USMALLINT) 0x100
00914 #define TDS_SF_WIDTH_INSENSITIVE     (TDS_USMALLINT) 0x080
00915 #define TDS_SF_KATATYPE_INSENSITIVE  (TDS_USMALLINT) 0x040
00916 #define TDS_SF_ACCENT_SENSITIVE      (TDS_USMALLINT) 0x020
00917 #define TDS_SF_CASE_INSENSITIVE      (TDS_USMALLINT) 0x010
00918 
00919 /* UT stands for user type */
00920 #define TDS_UT_TIMESTAMP             80
00921 
00922 
00927 typedef struct _tds_encoding
00928 {
00929         const char *name;
00930         unsigned char min_bytes_per_char;
00931         unsigned char max_bytes_per_char;
00932 } TDS_ENCODING;
00933 
00934 typedef struct _tds_bcpcoldata
00935 {
00936         TDS_UCHAR *data;
00937         TDS_INT    datalen;
00938         TDS_INT    is_null;
00939 } BCPCOLDATA;
00940 
00941 
00942 enum
00943 { TDS_SYSNAME_SIZE = 512 };
00944 
00948 typedef struct tds_column
00949 {
00950         TDS_SMALLINT column_type;       
00955         TDS_INT column_usertype;
00956         TDS_INT column_flags;
00957 
00958         TDS_INT column_size;            
00960         TDS_TINYINT column_varint_size; 
00962         TDS_TINYINT column_prec;        
00963         TDS_TINYINT column_scale;       
00965         TDS_SMALLINT column_namelen;    
00966         TDS_SMALLINT table_namelen;
00967         struct
00968         {
00969                 TDS_SMALLINT column_type;       
00970                 TDS_INT column_size;
00971         } on_server;
00972 
00973         const TDSICONV *char_conv;      
00975         TDS_CHAR table_name[TDS_SYSNAME_SIZE];
00976         TDS_CHAR column_name[TDS_SYSNAME_SIZE];
00977         char * table_column_name;
00978 
00979         unsigned char *column_data;
00980         void (*column_data_free)(struct tds_column *column);
00981         unsigned int column_nullable:1;
00982         unsigned int column_writeable:1;
00983         unsigned int column_identity:1;
00984         unsigned int column_key:1;
00985         unsigned int column_hidden:1;
00986         unsigned int column_output:1;
00987         unsigned int column_timestamp:1;
00988         TDS_UCHAR column_collation[5];
00989 
00990         /* additional fields flags for compute results */
00991         TDS_TINYINT column_operator;
00992         TDS_SMALLINT column_operand;
00993 
00994         /* FIXME this is data related, not column */
00996         TDS_INT column_cur_size;
00997 
00998         /* related to binding or info stored by client libraries */
00999         /* FIXME find a best place to store these data, some are unused */
01000         TDS_SMALLINT column_bindtype;
01001         TDS_SMALLINT column_bindfmt;
01002         TDS_UINT column_bindlen;
01003         TDS_SMALLINT *column_nullbind;
01004         TDS_CHAR *column_varaddr;
01005         TDS_INT *column_lenbind;
01006         TDS_INT column_textpos;
01007         TDS_INT column_text_sqlgetdatapos;
01008 
01009         BCPCOLDATA *bcp_column_data;
01018         TDS_INT bcp_prefix_len;
01019         TDS_INT bcp_term_len;
01020         TDS_CHAR *bcp_terminator;
01021 } TDSCOLUMN;
01022 
01023 
01025 typedef struct tds_result_info
01026 {
01027         /* TODO those fields can became a struct */
01028         TDS_SMALLINT num_cols;
01029         TDSCOLUMN **columns;
01030         TDS_INT row_size;
01031         TDS_INT ref_count;
01032         unsigned char *current_row;
01033         void (*row_free)(struct tds_result_info* result, unsigned char *row);
01034 
01035         TDS_SMALLINT rows_exist;
01036         /* TODO remove ?? used only in dblib */
01037         TDS_INT row_count;
01038         /* TODO remove ?? used only in dblib */
01039         TDS_TINYINT more_results;
01040         TDS_SMALLINT computeid;
01041         TDS_SMALLINT *bycolumns;
01042         TDS_SMALLINT by_cols;
01043 } TDSRESULTINFO;
01044 
01046 typedef enum _TDS_STATE
01047 {
01048         TDS_IDLE,       
01049         TDS_QUERYING,   
01050         TDS_PENDING,    
01051         TDS_READING,    
01052         TDS_DEAD        
01053 } TDS_STATE;
01054 
01055 #define TDS_DBG_FUNC    __FILE__, ((__LINE__ << 4) | 7)
01056 #define TDS_DBG_INFO2   __FILE__, ((__LINE__ << 4) | 6)
01057 #define TDS_DBG_INFO1   __FILE__, ((__LINE__ << 4) | 5)
01058 #define TDS_DBG_NETWORK __FILE__, ((__LINE__ << 4) | 4)
01059 #define TDS_DBG_WARN    __FILE__, ((__LINE__ << 4) | 3)
01060 #define TDS_DBG_ERROR   __FILE__, ((__LINE__ << 4) | 2)
01061 #define TDS_DBG_SEVERE  __FILE__, ((__LINE__ << 4) | 1)
01062 
01063 #define TDS_DBGFLAG_FUNC    0x80
01064 #define TDS_DBGFLAG_INFO2   0x40
01065 #define TDS_DBGFLAG_INFO1   0x20
01066 #define TDS_DBGFLAG_NETWORK 0x10
01067 #define TDS_DBGFLAG_WARN    0x08
01068 #define TDS_DBGFLAG_ERROR   0x04
01069 #define TDS_DBGFLAG_SEVERE  0x02
01070 #define TDS_DBGFLAG_ALLLVL  0xfff
01071 #define TDS_DBGFLAG_PID     0x1000
01072 #define TDS_DBGFLAG_TIME    0x2000
01073 #define TDS_DBGFLAG_SOURCE  0x4000
01074 #define TDS_DBGFLAG_THREAD  0x8000
01075 
01081 enum TDS_DBG_LOG_STATE
01082 {
01083           TDS_DBG_LOGIN =  (1 << 0)     
01085         , TDS_DBG_API =    (1 << 1)     
01086         , TDS_DBG_ASYNC =  (1 << 2)     
01087         , TDS_DBG_DIAG =   (1 << 3)     
01088         , TDS_DBG_error =  (1 << 4)
01089         /* TODO:  ^^^^^ make upper case when old #defines (above) are removed */
01090         /* Log FreeTDS runtime/logic error occurs. */
01091         , TDS_DBG_PACKET = (1 << 5)     
01092         , TDS_DBG_LIBTDS = (1 << 6)     
01093         , TDS_DBG_CONFIG = (1 << 7)     
01094         , TDS_DBG_DEFAULT = 0xFE        
01095 };
01096 
01097 typedef struct tds_result_info TDSCOMPUTEINFO;
01098 
01099 typedef TDSRESULTINFO TDSPARAMINFO;
01100 
01101 typedef struct tds_message
01102 {
01103         TDS_CHAR *server;
01104         TDS_CHAR *message;
01105         TDS_CHAR *proc_name;
01106         TDS_CHAR *sql_state;
01107         TDS_UINT msgno;
01108         TDS_INT line_number;
01109         /* -1 .. 255 */
01110         TDS_SMALLINT state;
01111         TDS_TINYINT priv_msg_type;
01112         TDS_TINYINT severity;
01113         /* for library-generated errors */
01114         int oserr;
01115 } TDSMESSAGE;
01116 
01117 typedef struct tds_upd_col
01118 {
01119         struct tds_upd_col *next;       
01120         TDS_INT colnamelength;
01121         char * columnname;
01122 } TDSUPDCOL;
01123 
01124 typedef enum {
01125           TDS_CURSOR_STATE_UNACTIONED = 0   /* initial value */
01126         , TDS_CURSOR_STATE_REQUESTED = 1        /* called by ct_cursor */ 
01127         , TDS_CURSOR_STATE_SENT = 2             /* sent to server */
01128         , TDS_CURSOR_STATE_ACTIONED = 3         /* acknowledged by server */
01129 } TDS_CURSOR_STATE;
01130 
01131 typedef struct _tds_cursor_status
01132 {
01133         TDS_CURSOR_STATE declare;
01134         TDS_CURSOR_STATE cursor_row;
01135         TDS_CURSOR_STATE open;
01136         TDS_CURSOR_STATE fetch;
01137         TDS_CURSOR_STATE close; 
01138         TDS_CURSOR_STATE dealloc;
01139 } TDS_CURSOR_STATUS;
01140 
01141 typedef enum _tds_cursor_operation
01142 {
01143         TDS_CURSOR_POSITION = 0,
01144         TDS_CURSOR_UPDATE = 1,
01145         TDS_CURSOR_DELETE = 2,
01146         TDS_CURSOR_INSERT = 4
01147 } TDS_CURSOR_OPERATION;
01148 
01149 typedef enum _tds_cursor_fetch
01150 {
01151         TDS_CURSOR_FETCH_NEXT = 1,
01152         TDS_CURSOR_FETCH_PREV,
01153         TDS_CURSOR_FETCH_FIRST,
01154         TDS_CURSOR_FETCH_LAST,
01155         TDS_CURSOR_FETCH_ABSOLUTE,
01156         TDS_CURSOR_FETCH_RELATIVE
01157 } TDS_CURSOR_FETCH;
01158 
01162 typedef struct _tds_cursor 
01163 {
01164         struct _tds_cursor *next;       
01165         TDS_INT ref_count;              
01166         TDS_TINYINT cursor_name_len;    
01167         char *cursor_name;              
01168         TDS_INT cursor_id;              
01169         TDS_TINYINT options;            
01170         TDS_TINYINT hasargs;            
01171         TDS_USMALLINT query_len;        
01172         char *query;                    
01173         /* TODO for updatable columns */
01174         /* TDS_TINYINT number_upd_cols; */      
01175         /* TDSUPDCOL *cur_col_list; */  
01176         TDS_INT cursor_rows;            
01177         /* TDSPARAMINFO *params; */     
01178         TDS_CURSOR_STATUS status;
01179         TDS_SMALLINT srv_status;
01180         TDSRESULTINFO *res_info;        
01181         TDS_INT type, concurrency;
01182 } TDSCURSOR;
01183 
01187 typedef struct tds_env
01188 {
01189         int block_size;
01190         char *language;
01191         char *charset;
01192         char *database;
01193 } TDSENV;
01194 
01198 typedef struct tds_dynamic
01199 {
01200         struct tds_dynamic *next;       
01206         char id[30];
01207         int dyn_state;
01209         TDS_INT num_id;
01210         TDSPARAMINFO *res_info; 
01218         TDSPARAMINFO *params;
01224         int emulated;
01226         char *query;
01227 } TDSDYNAMIC;
01228 
01229 typedef enum {
01230         TDS_MULTIPLE_QUERY,
01231         TDS_MULTIPLE_EXECUTE,
01232         TDS_MULTIPLE_RPC
01233 } TDS_MULTIPLE_TYPE;
01234 
01235 typedef struct tds_multiple
01236 {
01237         TDS_MULTIPLE_TYPE type;
01238         unsigned int flags;
01239 } TDSMULTIPLE;
01240 
01241 /* forward declaration */
01242 typedef struct tds_context TDSCONTEXT;
01243 
01244 struct tds_context
01245 {
01246         TDSLOCALE *locale;
01247         void *parent;
01248         /* handlers */
01249         int (*msg_handler) (const TDSCONTEXT *, TDSSOCKET *, TDSMESSAGE *);
01250         int (*err_handler) (const TDSCONTEXT *, TDSSOCKET *, TDSMESSAGE *);
01251         int (*int_handler) (void *);
01252 };
01253 
01254 enum TDS_ICONV_ENTRY
01255 { 
01256           client2ucs2
01257         , client2server_chardata
01258         , iso2server_metadata
01259         , initial_char_conv_count       /* keep last */
01260 };
01261 
01262 struct tds_authentication
01263 {
01264         TDS_UCHAR *packet;
01265         int packet_len;
01266         int (*free)(TDSSOCKET * tds, struct tds_authentication * auth);
01267         int (*handle_next)(TDSSOCKET * tds, struct tds_authentication * auth, size_t len);
01268 };
01269 
01270 typedef struct tds_authentication TDSAUTHENTICATION;
01271 
01275 struct tds_socket
01276 {
01277         /* fixed and connect time */
01279         TDS_SYS_SOCKET s;
01280         TDS_SMALLINT major_version;
01281         TDS_SMALLINT minor_version;
01283         TDS_UINT product_version;
01284         char *product_name;
01285         unsigned char capabilities[TDS_MAX_CAPABILITY];
01286         unsigned char broken_dates;
01287         unsigned char option_flag2;
01288         /* in/out buffers */
01290         unsigned char *in_buf;
01292         unsigned char *out_buf;
01294         unsigned int in_buf_max;
01296         unsigned in_pos;
01298         unsigned out_pos;
01300         unsigned in_len;
01301         /* TODO remove blocksize from env and use out_len ?? */
01302 /*      unsigned out_len; */
01304         unsigned char in_flag;
01306         unsigned char out_flag;
01308         unsigned char last_packet;
01309         void *parent;
01315         TDSRESULTINFO *current_results;
01316         TDSRESULTINFO *res_info;
01317         TDS_INT num_comp_info;
01318         TDSCOMPUTEINFO **comp_info;
01319         TDSPARAMINFO *param_info;
01320         TDSCURSOR *cur_cursor;  
01321         TDSCURSOR *cursors;     
01322         TDS_TINYINT has_status; 
01323         TDS_INT ret_status;     
01324         TDS_STATE state;
01326         volatile unsigned char in_cancel;
01328         TDS_INT8 rows_affected;
01329         /* timeout stuff from Jeff */
01330         TDS_INT query_timeout;
01331         TDSENV env;
01332 
01333         /* dynamic placeholder stuff */
01334         /*@dependent@*/ TDSDYNAMIC *cur_dyn;    
01335         TDSDYNAMIC *dyns;       
01337         int emul_little_endian;
01338         char *date_fmt;
01339         const TDSCONTEXT *tds_ctx;
01340         int char_conv_count;
01341         TDSICONV **char_convs;
01342 
01344         TDSCONNECTION *connection;
01345 
01346         int spid;
01347         TDS_UCHAR collation[5];
01348         TDS_UCHAR tds9_transaction[8];
01349         void (*env_chg_func) (TDSSOCKET * tds, int type, char *oldval, char *newval);
01350         int internal_sp_called;
01351 
01352         void *tls_session;
01353         void *tls_credentials;
01354         TDSAUTHENTICATION *authentication;
01355         int option_value;
01356 };
01357 
01358 int tds_init_write_buf(TDSSOCKET * tds);
01359 void tds_free_result_info(TDSRESULTINFO * info);
01360 void tds_free_socket(TDSSOCKET * tds);
01361 void tds_free_connection(TDSCONNECTION * connection);
01362 void tds_free_all_results(TDSSOCKET * tds);
01363 void tds_free_results(TDSRESULTINFO * res_info);
01364 void tds_free_param_results(TDSPARAMINFO * param_info);
01365 void tds_free_param_result(TDSPARAMINFO * param_info);
01366 void tds_free_msg(TDSMESSAGE * message);
01367 void tds_cursor_deallocated(TDSSOCKET *tds, TDSCURSOR *cursor);
01368 void tds_release_cursor(TDSSOCKET *tds, TDSCURSOR *cursor);
01369 void tds_free_bcp_column_data(BCPCOLDATA * coldata);
01370 
01371 int tds_put_n(TDSSOCKET * tds, const void *buf, int n);
01372 int tds_put_string(TDSSOCKET * tds, const char *buf, int len);
01373 int tds_put_int(TDSSOCKET * tds, TDS_INT i);
01374 int tds_put_int8(TDSSOCKET * tds, TDS_INT8 i);
01375 int tds_put_smallint(TDSSOCKET * tds, TDS_SMALLINT si);
01377 #define tds_put_tinyint(tds, ti) tds_put_byte(tds,ti)
01378 int tds_put_byte(TDSSOCKET * tds, unsigned char c);
01379 TDSRESULTINFO *tds_alloc_results(int num_cols);
01380 TDSCOMPUTEINFO **tds_alloc_compute_results(TDSSOCKET * tds, int num_cols, int by_cols);
01381 TDSCONTEXT *tds_alloc_context(void * parent);
01382 void tds_free_context(TDSCONTEXT * locale);
01383 TDSSOCKET *tds_alloc_socket(TDSCONTEXT * context, int bufsize);
01384 
01385 /* config.c */
01386 const TDS_COMPILETIME_SETTINGS *tds_get_compiletime_settings(void);
01387 typedef void (*TDSCONFPARSE) (const char *option, const char *value, void *param);
01388 int tds_read_conf_section(FILE * in, const char *section, TDSCONFPARSE tds_conf_parse, void *parse_param);
01389 int tds_read_conf_file(TDSCONNECTION * connection, const char *server);
01390 TDSCONNECTION *tds_read_config_info(TDSSOCKET * tds, TDSLOGIN * login, TDSLOCALE * locale);
01391 void tds_fix_connection(TDSCONNECTION * connection);
01392 void tds_config_verstr(const char *tdsver, TDSCONNECTION * connection);
01393 void tds_lookup_host(const char *servername, char *ip);
01394 int tds_set_interfaces_file_loc(const char *interfloc);
01395 
01396 TDSLOCALE *tds_get_locale(void);
01397 int tds_alloc_row(TDSRESULTINFO * res_info);
01398 int tds_alloc_compute_row(TDSCOMPUTEINFO * res_info);
01399 BCPCOLDATA * tds_alloc_bcp_column_data(int column_size);
01400 unsigned char *tds7_crypt_pass(const unsigned char *clear_pass, int len, unsigned char *crypt_pass);
01401 TDSDYNAMIC *tds_lookup_dynamic(TDSSOCKET * tds, char *id);
01402 /*@observer@*/ const char *tds_prtype(int token);
01403 
01404 
01405 
01406 /* iconv.c */
01407 void tds_iconv_open(TDSSOCKET * tds, const char *charset);
01408 void tds_iconv_close(TDSSOCKET * tds);
01409 void tds_srv_charset_changed(TDSSOCKET * tds, const char *charset);
01410 void tds7_srv_charset_changed(TDSSOCKET * tds, int sql_collate, int lcid);
01411 int tds_iconv_alloc(TDSSOCKET * tds);
01412 void tds_iconv_free(TDSSOCKET * tds);
01413 TDSICONV *tds_iconv_from_collate(TDSSOCKET * tds, int sql_collate, int lcid);
01414 
01415 /* threadsafe.c */
01416 char *tds_timestamp_str(char *str, int maxlen);
01417 struct hostent *tds_gethostbyname_r(const char *servername, struct hostent *result, char *buffer, int buflen, int *h_errnop);
01418 struct hostent *tds_gethostbyaddr_r(const char *addr, int len, int type, struct hostent *result, char *buffer, int buflen,
01419                                     int *h_errnop);
01420 struct servent *tds_getservbyname_r(const char *name, const char *proto, struct servent *result, char *buffer, int buflen);
01421 #ifdef INADDR_NONE
01422 const char *tds_inet_ntoa_r(struct in_addr iaddr, char *ip, size_t len);
01423 #endif
01424 char *tds_get_homedir(void);
01425 
01426 /* mem.c */
01427 TDSPARAMINFO *tds_alloc_param_result(TDSPARAMINFO * old_param);
01428 void tds_free_input_params(TDSDYNAMIC * dyn);
01429 void tds_free_dynamic(TDSSOCKET * tds, TDSDYNAMIC * dyn);
01430 TDSSOCKET *tds_realloc_socket(TDSSOCKET * tds, int bufsize);
01431 char *tds_alloc_client_sqlstate(int msgno);
01432 char *tds_alloc_lookup_sqlstate(TDSSOCKET * tds, int msgno);
01433 TDSLOGIN *tds_alloc_login(void);
01434 TDSDYNAMIC *tds_alloc_dynamic(TDSSOCKET * tds, const char *id);
01435 void tds_free_login(TDSLOGIN * login);
01436 TDSCONNECTION *tds_alloc_connection(TDSLOCALE * locale);
01437 TDSLOCALE *tds_alloc_locale(void);
01438 void *tds_alloc_param_data(TDSCOLUMN * curparam);
01439 void tds_free_locale(TDSLOCALE * locale);
01440 TDSCURSOR * tds_alloc_cursor(TDSSOCKET * tds, const char *name, TDS_INT namelen, const char *query, TDS_INT querylen);
01441 void tds_free_row(TDSRESULTINFO * res_info, unsigned char *row);
01442 
01443 /* login.c */
01444 void tds_set_packet(TDSLOGIN * tds_login, int packet_size);
01445 void tds_set_port(TDSLOGIN * tds_login, int port);
01446 void tds_set_passwd(TDSLOGIN * tds_login, const char *password);
01447 void tds_set_bulk(TDSLOGIN * tds_login, TDS_TINYINT enabled);
01448 void tds_set_user(TDSLOGIN * tds_login, const char *username);
01449 void tds_set_app(TDSLOGIN * tds_login, const char *application);
01450 void tds_set_host(TDSLOGIN * tds_login, const char *hostname);
01451 void tds_set_server_addr(TDSLOGIN * tds_login, const char *server_addr);
01452 void tds_set_library(TDSLOGIN * tds_login, const char *library);
01453 void tds_set_server(TDSLOGIN * tds_login, const char *server);
01454 void tds_set_client_charset(TDSLOGIN * tds_login, const char *charset);
01455 void tds_set_language(TDSLOGIN * tds_login, const char *language);
01456 void tds_set_version(TDSLOGIN * tds_login, TDS_TINYINT major_ver, TDS_TINYINT minor_ver);
01457 void tds_set_capabilities(TDSLOGIN * tds_login, unsigned char *capabilities, int size);
01458 int tds_connect(TDSSOCKET * tds, TDSCONNECTION * connection);
01459 
01460 /* query.c */
01461 int tds_submit_query(TDSSOCKET * tds, const char *query);
01462 int tds_submit_query_params(TDSSOCKET * tds, const char *query, TDSPARAMINFO * params);
01463 int tds_submit_queryf(TDSSOCKET * tds, const char *queryf, ...);
01464 int tds_submit_prepare(TDSSOCKET * tds, const char *query, const char *id, TDSDYNAMIC ** dyn_out, TDSPARAMINFO * params);
01465 int tds_submit_execdirect(TDSSOCKET * tds, const char *query, TDSPARAMINFO * params);
01466 int tds_submit_execute(TDSSOCKET * tds, TDSDYNAMIC * dyn);
01467 int tds_send_cancel(TDSSOCKET * tds);
01468 const char *tds_next_placeholder(const char *start);
01469 int tds_count_placeholders(const char *query);
01470 int tds_get_dynid(TDSSOCKET * tds, char **id);
01471 int tds_submit_unprepare(TDSSOCKET * tds, TDSDYNAMIC * dyn);
01472 int tds_submit_rpc(TDSSOCKET * tds, const char *rpc_name, TDSPARAMINFO * params);
01473 int tds_submit_optioncmd(TDSSOCKET * tds, TDS_OPTION_CMD command, TDS_OPTION option, TDS_OPTION_ARG *param, TDS_INT param_size);
01474 int tds_quote_id(TDSSOCKET * tds, char *buffer, const char *id, int idlen);
01475 int tds_quote_string(TDSSOCKET * tds, char *buffer, const char *str, int len);
01476 const char *tds_skip_quoted(const char *s);
01477 
01478 int tds_cursor_declare(TDSSOCKET * tds, TDSCURSOR * cursor, TDSPARAMINFO *params, int *send);
01479 int tds_cursor_setrows(TDSSOCKET * tds, TDSCURSOR * cursor, int *send);
01480 int tds_cursor_open(TDSSOCKET * tds, TDSCURSOR * cursor, TDSPARAMINFO *params, int *send);
01481 int tds_cursor_fetch(TDSSOCKET * tds, TDSCURSOR * cursor, TDS_CURSOR_FETCH fetch_type, TDS_INT i_row);
01482 int tds_cursor_close(TDSSOCKET * tds, TDSCURSOR * cursor);
01483 int tds_cursor_dealloc(TDSSOCKET * tds, TDSCURSOR * cursor);
01484 int tds_cursor_update(TDSSOCKET * tds, TDSCURSOR * cursor, TDS_CURSOR_OPERATION op, TDS_INT i_row, TDSPARAMINFO * params);
01485 int tds_cursor_setname(TDSSOCKET * tds, TDSCURSOR * cursor);
01486 
01487 int tds_multiple_init(TDSSOCKET *tds, TDSMULTIPLE *multiple, TDS_MULTIPLE_TYPE type);
01488 int tds_multiple_done(TDSSOCKET *tds, TDSMULTIPLE *multiple);
01489 int tds_multiple_query(TDSSOCKET *tds, TDSMULTIPLE *multiple, const char *query, TDSPARAMINFO * params);
01490 int tds_multiple_execute(TDSSOCKET *tds, TDSMULTIPLE *multiple, TDSDYNAMIC * dyn);
01491 
01492 /* token.c */
01493 int tds_process_cancel(TDSSOCKET * tds);
01494 void tds_swap_datatype(int coltype, unsigned char *buf);
01495 void tds_swap_numeric(TDS_NUMERIC *num);
01496 int tds_get_token_size(int marker);
01497 int tds_process_login_tokens(TDSSOCKET * tds);
01498 int tds_process_simple_query(TDSSOCKET * tds);
01499 int tds5_send_optioncmd(TDSSOCKET * tds, TDS_OPTION_CMD tds_command, TDS_OPTION tds_option, TDS_OPTION_ARG * tds_argument,
01500                         TDS_INT * tds_argsize);
01501 int tds_process_tokens(TDSSOCKET * tds, /*@out@*/ TDS_INT * result_type, /*@out@*/ int *done_flags, unsigned flag);
01502 
01503 /* data.c */
01504 void tds_set_param_type(TDSSOCKET * tds, TDSCOLUMN * curcol, TDS_SERVER_TYPE type);
01505 void tds_set_column_type(TDSSOCKET * tds, TDSCOLUMN * curcol, int type);
01506 
01507 
01508 /* tds_convert.c */
01509 TDS_INT tds_datecrack(TDS_INT datetype, const void *di, TDSDATEREC * dr);
01510 int tds_get_conversion_type(int srctype, int colsize);
01511 extern const char tds_hex_digits[];
01512 
01513 /* write.c */
01514 int tds_flush_packet(TDSSOCKET * tds);
01515 int tds_put_buf(TDSSOCKET * tds, const unsigned char *buf, int dsize, int ssize);
01516 
01517 /* read.c */
01518 unsigned char tds_get_byte(TDSSOCKET * tds);
01519 void tds_unget_byte(TDSSOCKET * tds);
01520 unsigned char tds_peek(TDSSOCKET * tds);
01521 TDS_SMALLINT tds_get_smallint(TDSSOCKET * tds);
01522 TDS_INT tds_get_int(TDSSOCKET * tds);
01523 TDS_INT8 tds_get_int8(TDSSOCKET * tds);
01524 int tds_get_string(TDSSOCKET * tds, int string_len, char *dest, size_t dest_size);
01525 int tds_get_char_data(TDSSOCKET * tds, char *dest, size_t wire_size, TDSCOLUMN * curcol);
01526 void *tds_get_n(TDSSOCKET * tds, /*@out@*/ /*@null@*/ void *dest, int n);
01527 int tds_get_size_by_type(int servertype);
01528 
01529 
01530 /* util.c */
01531 int tdserror (const TDSCONTEXT * tds_ctx, TDSSOCKET * tds, int msgno, int errnum);
01532 TDS_STATE tds_set_state(TDSSOCKET * tds, TDS_STATE state);
01533 void tds_set_parent(TDSSOCKET * tds, void *the_parent);
01534 void *tds_get_parent(TDSSOCKET * tds);
01535 int tds_swap_bytes(unsigned char *buf, int bytes);
01536 int tds_version(TDSSOCKET * tds_socket, char *pversion_string);
01537 void tdsdump_off(void);
01538 void tdsdump_on(void);
01539 int tdsdump_open(const char *filename);
01540 void tdsdump_close(void);
01541 void tdsdump_dump_buf(const char* file, unsigned int level_line, const char *msg, const void *buf, int length);
01542 void tdsdump_log(const char* file, unsigned int level_line, const char *fmt, ...) 
01543 #if defined(__GNUC__) && __GNUC__ >= 2
01544         __attribute__ ((__format__ (__printf__, 3, 4)))
01545 #endif
01546 ;
01547 extern int tds_debug_flags;
01548 unsigned int tds_gettime_ms(void);
01549 
01550 /* net.c */
01551 int tds_open_socket(TDSSOCKET * tds, const char *ip_addr, unsigned int port, int timeout);
01552 int tds_close_socket(TDSSOCKET * tds);
01553 int tds_read_packet(TDSSOCKET * tds);
01554 int tds_write_packet(TDSSOCKET * tds, unsigned char final);
01555 int tds7_get_instance_port(const char *ip_addr, const char *instance);
01556 int tds_ssl_init(TDSSOCKET *tds);
01557 void tds_ssl_deinit(TDSSOCKET *tds);
01558 
01559 
01560 
01561 /* vstrbuild.c */
01562 int tds_vstrbuild(char *buffer, int buflen, int *resultlen, char *text, int textlen, const char *formats, int formatlen,
01563                   va_list ap);
01564 
01565 /* numeric.c */
01566 char *tds_money_to_string(const TDS_MONEY * money, char *s);
01567 TDS_INT tds_numeric_to_string(const TDS_NUMERIC * numeric, char *s);
01568 TDS_INT tds_numeric_change_prec_scale(TDS_NUMERIC * numeric, unsigned char new_prec, unsigned char new_scale);
01569 
01570 /* getmac.c */
01571 void tds_getmac(int s, unsigned char mac[6]);
01572 
01573 TDSAUTHENTICATION * tds_ntlm_get_auth(TDSSOCKET * tds);
01574 TDSAUTHENTICATION * tds_gss_get_auth(TDSSOCKET * tds);
01575 
01576 #define IS_TDS42(x) (x->major_version==4 && x->minor_version==2)
01577 #define IS_TDS46(x) (x->major_version==4 && x->minor_version==6)
01578 #define IS_TDS50(x) (x->major_version==5 && x->minor_version==0)
01579 #define IS_TDS70(x) (x->major_version==7 && x->minor_version==0)
01580 #define IS_TDS80(x) (x->major_version==8 && x->minor_version==0)
01581 #define IS_TDS90(x) (x->major_version==9 && x->minor_version==0)
01582 
01583 #define IS_TDS7_PLUS(x) ((x)->major_version>=7)
01584 #define IS_TDS8_PLUS(x) ((x)->major_version>=8)
01585 
01586 #define IS_TDSDEAD(x) (((x) == NULL) || TDS_IS_SOCKET_INVALID((x)->s))
01587 
01589 #define TDS_IS_SYBASE(x) (!(x->product_version & 0x80000000u))
01590 
01591 #define TDS_IS_MSSQL(x) ((x->product_version & 0x80000000u)!=0)
01592 
01596 #define TDS_MS_VER(maj,min,x) (0x80000000u|((maj)<<24)|((min)<<16)|(x))
01597 
01598 /* TODO test if not similar to ms one*/
01600 #define TDS_SYB_VER(maj,min,x) (((maj)<<24)|((min)<<16)|(x)<<8)
01601 
01602 #ifdef __cplusplus
01603 #if 0
01604 {
01605 #endif
01606 }
01607 #endif
01608 
01609 #endif /* _tds_h_ */

Generated on Wed May 7 19:22:09 2008 for FreeTDS API by  doxygen 1.4.1