Main Page Modules Compound List File List Compound 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  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 static char rcsid_tds_h[] = "$Id: tds.h,v 1.167 2003/12/31 11:33:10 freddy77 Exp $";
    00024 static void *no_unused_tds_h_warn[] = { rcsid_tds_h, no_unused_tds_h_warn };
    00025
    00026 #include <stdio.h>
    00027 #include <stdarg.h>
    00028 #include <time.h>
    00029
    00030 /* forward declaration */
    00031 typedef struct tdsiconvinfo TDSICONVINFO;
    00032 typedef struct tds_socket TDSSOCKET;
    00033
    00034 #include "tdsver.h"
    00035 #include "tds_sysdep_public.h"
    00036 #ifdef _FREETDS_LIBRARY_SOURCE
    00037 #include "tds_sysdep_private.h"
    00038 #endif /* _FREETDS_LIBRARY_SOURCE */
    00039
    00040 #ifdef __cplusplus
    00041 extern "C"
    00042 {
    00043 #if 0
    00044 }
    00045 #endif
    00046 #endif
    00047
    00053 typedef struct _tds_compiletime_settings
    00054 {
    00055         const char *freetds_version;    /* release version of FreeTDS */
    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         /* keep always at last */
    00069         char dstr_s[1];
    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_INT 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
    00190 #define TDS_REG_ROW          -1
    00191 #define TDS_NO_MORE_ROWS     -2
    00192 #define TDS_COMP_ROW         -3
    00193 #define TDS_END_ROW          -4
    00194
    00195 #define TDS_INT_EXIT 0
    00196 #define TDS_INT_CONTINUE 1
    00197 #define TDS_INT_CANCEL 2
    00198 #define TDS_INT_TIMEOUT 3
    00199
    00200
    00201 #define TDS_NO_COUNT         -1
    00202
    00203 #define TDS_ROW_RESULT        4040
    00204 #define TDS_PARAM_RESULT      4042
    00205 #define TDS_STATUS_RESULT     4043
    00206 #define TDS_MSG_RESULT        4044
    00207 #define TDS_COMPUTE_RESULT    4045
    00208 #define TDS_CMD_DONE          4046
    00209 #define TDS_CMD_SUCCEED       4047
    00210 #define TDS_CMD_FAIL          4048
    00211 #define TDS_ROWFMT_RESULT     4049
    00212 #define TDS_COMPUTEFMT_RESULT 4050
    00213 #define TDS_DESCRIBE_RESULT   4051
    00214 #define TDS_DONE_RESULT       4052
    00215 #define TDS_DONEPROC_RESULT   4053
    00216 #define TDS_DONEINPROC_RESULT 4054
    00217
    00218 enum tds_end
    00219 {
    00220         TDS_DONE_FINAL = 0x00   /* final result set, command completed successfully. */
    00221                 , TDS_DONE_MORE_RESULTS = 0x01  /* more results follow */
    00222                 , TDS_DONE_ERROR = 0x02 /* error occurred */
    00223                 , TDS_DONE_INXACT = 0x04        /* transaction in progress */
    00224                 , TDS_DONE_PROC = 0x08  /* results are from a stored procedure */
    00225                 , TDS_DONE_COUNT = 0x10 /* count field in packet is valid */
    00226                 , TDS_DONE_CANCELLED = 0x20     /* acknowledging an attention command (usually a cancel) */
    00227                 , TDS_DONE_EVENT = 0x40 /* part of an event notification. */
    00228                 /* after the above flags, a TDS_DONE packet has a field describing the state of the transaction */
    00229                 , TDS_DONE_NO_TRAN = 0  /* No transaction in effect */
    00230                 , TDS_DONE_TRAN_SUCCEED = 1     /* Transaction completed successfully */
    00231                 , TDS_DONE_TRAN_PROGRESS = 2    /* Transaction in progress */
    00232                 , TDS_DONE_STMT_ABORT = 3       /* A statement aborted */
    00233                 , TDS_DONE_TRAN_ABORT = 4       /* Transaction aborted */
    00234 };
    00235
    00236 /*
    00237  * TDS_ERROR indicates a successful processing, but that a TDS_ERROR_TOKEN or TDS_EED_TOKEN error was encountered.
    00238  * TDS_FAIL indicates an unrecoverable failure.
    00239  */
    00240 #define TDS_ERROR            3
    00241 #define TDS_DONT_RETURN      42
    00242
    00243 #define TDS5_PARAMFMT2_TOKEN       32   /* 0x20 */
    00244 #define TDS_LANGUAGE_TOKEN         33   /* 0x21    TDS 5.0 only              */
    00245 #define TDS_ORDERBY2_TOKEN         34   /* 0x22 */
    00246 #define TDS_ROWFMT2_TOKEN          97   /* 0x61    TDS 5.0 only              */
    00247 #define TDS_LOGOUT_TOKEN          113   /* 0x71    TDS 5.0 only? ct_close()  */
    00248 #define TDS_RETURNSTATUS_TOKEN    121   /* 0x79                              */
    00249 #define TDS_PROCID_TOKEN          124   /* 0x7C    TDS 4.2 only - TDS_PROCID */
    00250 #define TDS7_RESULT_TOKEN         129   /* 0x81    TDS 7.0 only              */
    00251 #define TDS7_COMPUTE_RESULT_TOKEN 136   /* 0x88    TDS 7.0 only              */
    00252 #define TDS_COLNAME_TOKEN         160   /* 0xA0    TDS 4.2 only              */
    00253 #define TDS_COLFMT_TOKEN          161   /* 0xA1    TDS 4.2 only - TDS_COLFMT */
    00254 #define TDS_DYNAMIC2_TOKEN        163   /* 0xA3 */
    00255 #define TDS_TABNAME_TOKEN         164   /* 0xA4 */
    00256 #define TDS_COLINFO_TOKEN         165   /* 0xA5 */
    00257 #define TDS_OPTIONCMD_TOKEN       166   /* 0xA6 */
    00258 #define TDS_COMPUTE_NAMES_TOKEN   167   /* 0xA7 */
    00259 #define TDS_COMPUTE_RESULT_TOKEN  168   /* 0xA8 */
    00260 #define TDS_ORDERBY_TOKEN         169   /* 0xA9    TDS_ORDER                 */
    00261 #define TDS_ERROR_TOKEN           170   /* 0xAA                              */
    00262 #define TDS_INFO_TOKEN            171   /* 0xAB                              */
    00263 #define TDS_PARAM_TOKEN           172   /* 0xAC    RETURNVALUE?              */
    00264 #define TDS_LOGINACK_TOKEN        173   /* 0xAD                              */
    00265 #define TDS_CONTROL_TOKEN         174   /* 0xAE    TDS_CONTROL               */
    00266 #define TDS_ROW_TOKEN             209   /* 0xD1                              */
    00267 #define TDS_CMP_ROW_TOKEN         211   /* 0xD3                              */
    00268 #define TDS5_PARAMS_TOKEN         215   /* 0xD7    TDS 5.0 only              */
    00269 #define TDS_CAPABILITY_TOKEN      226   /* 0xE2                              */
    00270 #define TDS_ENVCHANGE_TOKEN       227   /* 0xE3                              */
    00271 #define TDS_EED_TOKEN             229   /* 0xE5                              */
    00272 #define TDS_DBRPC_TOKEN           230   /* 0xE6                              */
    00273 #define TDS5_DYNAMIC_TOKEN        231   /* 0xE7    TDS 5.0 only              */
    00274 #define TDS5_PARAMFMT_TOKEN       236   /* 0xEC    TDS 5.0 only              */
    00275 #define TDS_AUTH_TOKEN            237   /* 0xED                              */
    00276 #define TDS_RESULT_TOKEN          238   /* 0xEE                              */
    00277 #define TDS_DONE_TOKEN            253   /* 0xFD    TDS_DONE                  */
    00278 #define TDS_DONEPROC_TOKEN        254   /* 0xFE    TDS_DONEPROC              */
    00279 #define TDS_DONEINPROC_TOKEN      255   /* 0xFF    TDS_DONEINPROC            */
    00280
    00281 /* CURSOR support: TDS 5.0 only*/
    00282 #define TDS_CURCLOSE_TOKEN        128  /* 0x80    TDS 5.0 only              */
    00283 #define TDS_CURFETCH_TOKEN        130  /* 0x82    TDS 5.0 only              */
    00284 #define TDS_CURINFO_TOKEN         131  /* 0x83    TDS 5.0 only              */
    00285 #define TDS_CUROPEN_TOKEN         132  /* 0x84    TDS 5.0 only              */
    00286 #define TDS_CURDECLARE_TOKEN      134  /* 0x86    TDS 5.0 only              */
    00287
    00288 /*
    00289  * Cursor Declare, SetRows, Open and Close all return 0x83 token.
    00290  * But only SetRows includes the rowcount (4 byte) in the stream.
    00291  * So for Setrows we read the rowcount from the stream and not for others.
    00292  * These values are useful to determine when to read the rowcount from the packet
    00293  */
    00294 #define IS_DECLARE  100
    00295 #define IS_CURROW   200
    00296 #define IS_OPEN     300
    00297 #define IS_CLOSE    400
    00298
    00299 /* states for tds_process_messages() */
    00300 #define PROCESS_ROWS    0
    00301 #define PROCESS_RESULTS 1
    00302 #define CANCEL_PROCESS  2
    00303 #define GOTO_1ST_ROW    3
    00304 #define LOGIN           4
    00305
    00306 /* environment type field */
    00307 #define TDS_ENV_DATABASE        1
    00308 #define TDS_ENV_LANG            2
    00309 #define TDS_ENV_CHARSET         3
    00310 #define TDS_ENV_PACKSIZE        4
    00311 #define TDS_ENV_LCID            5
    00312 #define TDS_ENV_SQLCOLLATION    7
    00313
    00314 /* string types */
    00315 #define TDS_NULLTERM -9
    00316
    00317 /* Microsoft internal stored procedure id's */
    00318
    00319 #define TDS_SP_CURSOR           1
    00320 #define TDS_SP_CURSOROPEN       2
    00321 #define TDS_SP_CURSORPREPARE    3
    00322 #define TDS_SP_CURSOREXECUTE    4
    00323 #define TDS_SP_CURSORPREPEXEC   5
    00324 #define TDS_SP_CURSORUNPREPARE  6
    00325 #define TDS_SP_CURSORFETCH      7
    00326 #define TDS_SP_CURSOROPTION     8
    00327 #define TDS_SP_CURSORCLOSE      9
    00328 #define TDS_SP_EXECUTESQL      10
    00329 #define TDS_SP_PREPARE         11
    00330 #define TDS_SP_EXECUTE         12
    00331 #define TDS_SP_PREPEXEC        13
    00332 #define TDS_SP_PREPEXECRPC     14
    00333 #define TDS_SP_UNPREPARE       15
    00334 /*
    00335 <rant> Sybase does an awful job of this stuff, non null ints of size 1 2
    00336 and 4 have there own codes but nullable ints are lumped into INTN
    00337 sheesh! </rant>
    00338 */
    00339 typedef enum
    00340 {
    00341         SYBCHAR = 47,           /* 0x2F */
    00342 #define SYBCHAR SYBCHAR
    00343         SYBVARCHAR = 39,        /* 0x27 */
    00344 #define SYBVARCHAR      SYBVARCHAR
    00345         SYBINTN = 38,           /* 0x26 */
    00346 #define SYBINTN SYBINTN
    00347         SYBINT1 = 48,           /* 0x30 */
    00348 #define SYBINT1 SYBINT1
    00349         SYBINT2 = 52,           /* 0x34 */
    00350 #define SYBINT2 SYBINT2
    00351         SYBINT4 = 56,           /* 0x38 */
    00352 #define SYBINT4 SYBINT4
    00353         SYBINT8 = 127,          /* 0x7F */
    00354 #define SYBINT8 SYBINT8
    00355         SYBFLT8 = 62,           /* 0x3E */
    00356 #define SYBFLT8 SYBFLT8
    00357         SYBDATETIME = 61,       /* 0x3D */
    00358 #define SYBDATETIME     SYBDATETIME
    00359         SYBBIT = 50,            /* 0x32 */
    00360 #define SYBBIT  SYBBIT
    00361         SYBTEXT = 35,           /* 0x23 */
    00362 #define SYBTEXT SYBTEXT
    00363         SYBNTEXT = 99,          /* 0x63 */
    00364 #define SYBNTEXT        SYBNTEXT
    00365         SYBIMAGE = 34,          /* 0x22 */
    00366 #define SYBIMAGE        SYBIMAGE
    00367         SYBMONEY4 = 122,        /* 0x7A */
    00368 #define SYBMONEY4       SYBMONEY4
    00369         SYBMONEY = 60,          /* 0x3C */
    00370 #define SYBMONEY        SYBMONEY
    00371         SYBDATETIME4 = 58,      /* 0x3A */
    00372 #define SYBDATETIME4    SYBDATETIME4
    00373         SYBREAL = 59,           /* 0x3B */
    00374 #define SYBREAL SYBREAL
    00375         SYBBINARY = 45,         /* 0x2D */
    00376 #define SYBBINARY       SYBBINARY
    00377         SYBVOID = 31,           /* 0x1F */
    00378 #define SYBVOID SYBVOID
    00379         SYBVARBINARY = 37,      /* 0x25 */
    00380 #define SYBVARBINARY    SYBVARBINARY
    00381         SYBNVARCHAR = 103,      /* 0x67 */
    00382 #define SYBNVARCHAR     SYBNVARCHAR
    00383         SYBBITN = 104,          /* 0x68 */
    00384 #define SYBBITN SYBBITN
    00385         SYBNUMERIC = 108,       /* 0x6C */
    00386 #define SYBNUMERIC      SYBNUMERIC
    00387         SYBDECIMAL = 106,       /* 0x6A */
    00388 #define SYBDECIMAL      SYBDECIMAL
    00389         SYBFLTN = 109,          /* 0x6D */
    00390 #define SYBFLTN SYBFLTN
    00391         SYBMONEYN = 110,        /* 0x6E */
    00392 #define SYBMONEYN       SYBMONEYN
    00393         SYBDATETIMN = 111,      /* 0x6F */
    00394 #define SYBDATETIMN     SYBDATETIMN
    00395         XSYBCHAR = 175,         /* 0xAF */
    00396 #define XSYBCHAR        XSYBCHAR
    00397         XSYBVARCHAR = 167,      /* 0xA7 */
    00398 #define XSYBVARCHAR     XSYBVARCHAR
    00399         XSYBNVARCHAR = 231,     /* 0xE7 */
    00400 #define XSYBNVARCHAR    XSYBNVARCHAR
    00401         XSYBNCHAR = 239,        /* 0xEF */
    00402 #define XSYBNCHAR       XSYBNCHAR
    00403         XSYBVARBINARY = 165,    /* 0xA5 */
    00404 #define XSYBVARBINARY   XSYBVARBINARY
    00405         XSYBBINARY = 173,       /* 0xAD */
    00406 #define XSYBBINARY      XSYBBINARY
    00407         SYBLONGBINARY = 225,    /* 0xE1 */
    00408 #define SYBLONGBINARY   SYBLONGBINARY
    00409         SYBSINT1 = 64,          /* 0x40 */
    00410 #define SYBSINT1        SYBSINT1
    00411         SYBUINT2 = 65,          /* 0x41 */
    00412 #define SYBUINT2        SYBUINT2
    00413         SYBUINT4 = 66,          /* 0x42 */
    00414 #define SYBUINT4        SYBUINT4
    00415         SYBUINT8 = 67,          /* 0x43 */
    00416 #define SYBUINT8        SYBUINT8
    00417
    00418         SYBUNIQUE = 36,         /* 0x24 */
    00419 #define SYBUNIQUE       SYBUNIQUE
    00420         SYBVARIANT = 98         /* 0x62 */
    00421 #define SYBVARIANT      SYBVARIANT
    00422 } TDS_SERVER_TYPE;
    00423
    00424
    00425 typedef enum
    00426 {
    00427         USER_UNICHAR_TYPE = 34,         /* 0x22 */
    00428         USER_UNIVARCHAR_TYPE = 35       /* 0x23 */
    00429 } TDS_USER_TYPE;
    00430
    00431 #define SYBAOPCNT  0x4b
    00432 #define SYBAOPCNTU 0x4c
    00433 #define SYBAOPSUM  0x4d
    00434 #define SYBAOPSUMU 0x4e
    00435 #define SYBAOPAVG  0x4f
    00436 #define SYBAOPAVGU 0x50
    00437 #define SYBAOPMIN  0x51
    00438 #define SYBAOPMAX  0x52
    00439
    00440 /* mssql2k compute operator */
    00441 #define SYBAOPCNT_BIG           0x09
    00442 #define SYBAOPSTDEV             0x30
    00443 #define SYBAOPSTDEVP            0x31
    00444 #define SYBAOPVAR               0x32
    00445 #define SYBAOPVARP              0x33
    00446 #define SYBAOPCHECKSUM_AGG      0x72
    00447
    00448
    00452 typedef enum
    00453 {
    00454           TDS_OPT_SET = 1       /* Set an option. */
    00455         , TDS_OPT_DEFAULT = 2   /* Set option to its default value. */
    00456         , TDS_OPT_LIST = 3      /* Request current setting of a specific option. */
    00457         , TDS_OPT_INFO = 4      /* Report current setting of a specific option. */
    00458 } TDS_OPTION_CMD;
    00459
    00460 typedef enum
    00461 {
    00462           TDS_OPT_DATEFIRST = 1         /* 0x01 */
    00463         , TDS_OPT_TEXTSIZE = 2          /* 0x02 */
    00464         , TDS_OPT_STAT_TIME = 3         /* 0x03 */
    00465         , TDS_OPT_STAT_IO = 4           /* 0x04 */
    00466         , TDS_OPT_ROWCOUNT = 5          /* 0x05 */
    00467         , TDS_OPT_NATLANG = 6           /* 0x06 */
    00468         , TDS_OPT_DATEFORMAT = 7        /* 0x07 */
    00469         , TDS_OPT_ISOLATION = 8         /* 0x08 */
    00470         , TDS_OPT_AUTHON = 9            /* 0x09 */
    00471         , TDS_OPT_CHARSET = 10          /* 0x0a */
    00472         , TDS_OPT_SHOWPLAN = 13         /* 0x0d */
    00473         , TDS_OPT_NOEXEC = 14           /* 0x0e */
    00474         , TDS_OPT_ARITHIGNOREON = 15    /* 0x0f */
    00475         , TDS_OPT_ARITHABORTON = 17     /* 0x11 */
    00476         , TDS_OPT_PARSEONLY = 18        /* 0x12 */
    00477         , TDS_OPT_GETDATA = 20          /* 0x14 */
    00478         , TDS_OPT_NOCOUNT = 21          /* 0x15 */
    00479         , TDS_OPT_FORCEPLAN = 23        /* 0x17 */
    00480         , TDS_OPT_FORMATONLY = 24       /* 0x18 */
    00481         , TDS_OPT_CHAINXACTS = 25       /* 0x19 */
    00482         , TDS_OPT_CURCLOSEONXACT = 26   /* 0x1a */
    00483         , TDS_OPT_FIPSFLAG = 27         /* 0x1b */
    00484         , TDS_OPT_RESTREES = 28         /* 0x1c */
    00485         , TDS_OPT_IDENTITYON = 29       /* 0x1d */
    00486         , TDS_OPT_CURREAD = 30          /* 0x1e */
    00487         , TDS_OPT_CURWRITE = 31         /* 0x1f */
    00488         , TDS_OPT_IDENTITYOFF = 32      /* 0x20 */
    00489         , TDS_OPT_AUTHOFF = 33          /* 0x21 */
    00490         , TDS_OPT_ANSINULL = 34         /* 0x22 */
    00491         , TDS_OPT_QUOTED_IDENT = 35     /* 0x23 */
    00492         , TDS_OPT_ARITHIGNOREOFF = 36   /* 0x24 */
    00493         , TDS_OPT_ARITHABORTOFF = 37    /* 0x25 */
    00494         , TDS_OPT_TRUNCABORT = 38       /* 0x26 */
    00495 } TDS_OPTION;
    00496
    00497 typedef union tds_option_arg
    00498 {
    00499         TDS_TINYINT ti;
    00500         TDS_INT i;
    00501         TDS_CHAR *c;
    00502 } TDS_OPTION_ARG;
    00503
    00504 enum {
    00505         TDS_OPT_ARITHOVERFLOW = 0x01,
    00506         TDS_OPT_NUMERICTRUNC = 0x02
    00507 };
    00508
    00509 enum TDS_OPT_DATEFIRST_CHOICE
    00510 {
    00511         TDS_OPT_MONDAY = 1, TDS_OPT_TUESDAY = 2, TDS_OPT_WEDNESDAY = 3, TDS_OPT_THURSDAY = 4, TDS_OPT_FRIDAY = 5, TDS_OPT_SATURDAY =
    00512                 6, TDS_OPT_SUNDAY = 7
    00513 };
    00514
    00515 enum TDS_OPT_DATEFORMAT_CHOICE
    00516 {
    00517         TDS_OPT_FMTMDY = 1, TDS_OPT_FMTDMY = 2, TDS_OPT_FMTYMD = 3, TDS_OPT_FMTYDM = 4, TDS_OPT_FMTMYD = 5, TDS_OPT_FMTDYM = 6
    00518 };
    00519 enum TDS_OPT_ISOLATION_CHOICE
    00520 {
    00521         TDS_OPT_LEVEL1 = 1, TDS_OPT_LEVEL3 = 3
    00522 };
    00523
    00524 #define TDS_ZERO_FREE(x) {free((x)); (x) = NULL;}
    00525 #define TDS_VECTOR_SIZE(x) (sizeof(x)/sizeof(x[0]))
    00526
    00527 #define TDS_BYTE_SWAP16(value)                 \
    00528          (((((unsigned short)value)<<8) & 0xFF00)   | \
    00529           ((((unsigned short)value)>>8) & 0x00FF))
    00530
    00531 #define TDS_BYTE_SWAP32(value)                     \
    00532          (((((unsigned long)value)<<24) & 0xFF000000)  | \
    00533           ((((unsigned long)value)<< 8) & 0x00FF0000)  | \
    00534           ((((unsigned long)value)>> 8) & 0x0000FF00)  | \
    00535           ((((unsigned long)value)>>24) & 0x000000FF))
    00536
    00537 #define is_end_token(x) (x==TDS_DONE_TOKEN    || \
    00538                         x==TDS_DONEPROC_TOKEN    || \
    00539                         x==TDS_DONEINPROC_TOKEN)
    00540
    00541 #define is_hard_end_token(x) (x==TDS_DONE_TOKEN    || \
    00542                         x==TDS_DONEPROC_TOKEN)
    00543
    00544 #define is_msg_token(x) (x==TDS_INFO_TOKEN    || \
    00545                         x==TDS_ERROR_TOKEN    || \
    00546                         x==TDS_EED_TOKEN)
    00547
    00548 #define is_result_token(x) (x==TDS_RESULT_TOKEN    || \
    00549                         x==TDS_ROWFMT2_TOKEN || \
    00550                         x==TDS7_RESULT_TOKEN    || \
    00551                         x==TDS_COLFMT_TOKEN    || \
    00552                         x==TDS_COLNAME_TOKEN)
    00553
    00554 /* FIX ME -- not a complete list */
    00555 #define is_fixed_type(x) (x==SYBINT1    || \
    00556                         x==SYBINT2      || \
    00557                         x==SYBINT4      || \
    00558                         x==SYBINT8      || \
    00559                         x==SYBREAL       || \
    00560                         x==SYBFLT8      || \
    00561                         x==SYBDATETIME  || \
    00562                         x==SYBDATETIME4 || \
    00563                         x==SYBBIT       || \
    00564                         x==SYBMONEY     || \
    00565                         x==SYBMONEY4    || \
    00566                         x==SYBUNIQUE)
    00567 #define is_nullable_type(x) ( \
    00568                         x==SYBBITN      || \
    00569                      x==SYBINTN      || \
    00570                      x==SYBFLTN      || \
    00571                      x==SYBMONEYN    || \
    00572                      x==SYBDATETIMN  || \
    00573                      x==SYBCHAR      || \
    00574                      x==SYBVARCHAR   || \
    00575                      x==SYBBINARY    || \
    00576                      x==SYBVARBINARY || \
    00577                      x==SYBTEXT      || \
    00578                      x==SYBNTEXT     || \
    00579                      x==SYBIMAGE)
    00580
    00581 #define is_blob_type(x) (x==SYBTEXT || x==SYBIMAGE || x==SYBNTEXT)
    00582 /* large type means it has a two byte size field */
    00583 /* define is_large_type(x) (x>128) */
    00584 #define is_numeric_type(x) (x==SYBNUMERIC || x==SYBDECIMAL)
    00585 #define is_unicode_type(x) (x==XSYBNVARCHAR || x==XSYBNCHAR || x==SYBNTEXT)
    00586 #define is_collate_type(x) (x==XSYBVARCHAR || x==XSYBCHAR || x==SYBTEXT || x==XSYBNVARCHAR || x==XSYBNCHAR || x==SYBNTEXT)
    00587 #define is_ascii_type(x) ( x==XSYBCHAR || x==XSYBVARCHAR || x==SYBTEXT || x==SYBCHAR || x==SYBVARCHAR)
    00588 #define is_binary_type(x) (x==SYBLONGBINARY)
    00589 #define is_char_type(x) (is_unicode_type(x) || is_ascii_type(x))
    00590 #define is_similar_type(x, y) ((is_char_type(x) && is_char_type(y)) || ((is_unicode_type(x) && is_unicode_type(y))))
    00591
    00592
    00593 #define TDS_MAX_CAPABILITY      22
    00594 #define MAXPRECISION            80
    00595 #define TDS_MAX_CONN            4096
    00596 #define TDS_MAX_DYNID_LEN       30
    00597
    00598 /* defaults to use if no others are found */
    00599 #define TDS_DEF_SERVER          "SYBASE"
    00600 #define TDS_DEF_BLKSZ           512
    00601 #define TDS_DEF_CHARSET         "iso_1"
    00602 #define TDS_DEF_LANG            "us_english"
    00603 #if TDS42
    00604 #define TDS_DEF_MAJOR           4
    00605 #define TDS_DEF_MINOR           2
    00606 #define TDS_DEF_PORT            1433
    00607 #elif TDS46
    00608 #define TDS_DEF_MAJOR           4
    00609 #define TDS_DEF_MINOR           6
    00610 #define TDS_DEF_PORT            4000
    00611 #elif TDS70
    00612 #define TDS_DEF_MAJOR           7
    00613 #define TDS_DEF_MINOR           0
    00614 #define TDS_DEF_PORT            1433
    00615 #elif TDS80
    00616 #define TDS_DEF_MAJOR           8
    00617 #define TDS_DEF_MINOR           0
    00618 #define TDS_DEF_PORT            1433
    00619 #else
    00620 #define TDS_DEF_MAJOR           5
    00621 #define TDS_DEF_MINOR           0
    00622 #define TDS_DEF_PORT            4000
    00623 #endif
    00624
    00625 /* normalized strings from freetds.conf file */
    00626 #define TDS_STR_VERSION  "tds version"
    00627 #define TDS_STR_BLKSZ    "initial block size"
    00628 #define TDS_STR_SWAPDT   "swap broken dates"
    00629 #define TDS_STR_SWAPMNY  "swap broken money"
    00630 #define TDS_STR_TRYSVR   "try server login"
    00631 #define TDS_STR_TRYDOM   "try domain login"
    00632 #define TDS_STR_DOMAIN   "nt domain"
    00633 #define TDS_STR_XDOMAUTH "cross domain login"
    00634 #define TDS_STR_DUMPFILE "dump file"
    00635 #define TDS_STR_DEBUGLVL "debug level"
    00636 #define TDS_STR_TIMEOUT  "timeout"
    00637 #define TDS_STR_CONNTMOUT "connect timeout"
    00638 #define TDS_STR_HOSTNAME "hostname"
    00639 #define TDS_STR_HOST     "host"
    00640 #define TDS_STR_PORT     "port"
    00641 #define TDS_STR_TEXTSZ   "text size"
    00642 /* for big endian hosts */
    00643 #define TDS_STR_EMUL_LE "emulate little endian"
    00644 #define TDS_STR_CHARSET "charset"
    00645 #define TDS_STR_CLCHARSET       "client charset"
    00646 #define TDS_STR_LANGUAGE        "language"
    00647 #define TDS_STR_APPENDMODE      "dump file append"
    00648 #define TDS_STR_DATEFMT "date format"
    00649
    00650 /* TODO do a better check for alignment than this */
    00651 typedef union
    00652 {
    00653         void *p;
    00654         int i;
    00655 } tds_align_struct;
    00656
    00657 #define TDS_ALIGN_SIZE sizeof(tds_align_struct)
    00658
    00659 #define TDS_MAX_LOGIN_STR_SZ 30
    00660 typedef struct tds_login
    00661 {
    00662         DSTR server_name;
    00663         int port;
    00664         TDS_TINYINT major_version;      /* TDS version */
    00665         TDS_TINYINT minor_version;      /* TDS version */
    00666         int block_size;
    00667         DSTR language;          /* ie us-english */
    00668         DSTR server_charset;    /*  ie iso_1 */
    00669         TDS_INT connect_timeout;
    00670         DSTR host_name;
    00671         DSTR app_name;
    00672         DSTR user_name;
    00673         DSTR password;
    00674
    00675         DSTR library;   /* Ct-Library, DB-Library,  TDS-Library or ODBC */
    00676         TDS_TINYINT bulk_copy;
    00677         TDS_TINYINT suppress_language;
    00678         TDS_TINYINT encrypted;
    00679
    00680         TDS_INT query_timeout;
    00681         TDS_INT longquery_timeout;
    00682         void (*longquery_func) (void *param);
    00683         void *longquery_param;
    00684         unsigned char capabilities[TDS_MAX_CAPABILITY];
    00685         DSTR client_charset;
    00686 } TDSLOGIN;
    00687
    00688 typedef struct tds_connect_info
    00689 {
    00690         /* first part of structure is the same of login one */
    00691         DSTR server_name;
    00692         int port;
    00693         TDS_TINYINT major_version;
    00694         TDS_TINYINT minor_version;
    00695         int block_size;
    00696         DSTR language;
    00697         DSTR server_charset;
    00698         TDS_INT connect_timeout;
    00699         DSTR host_name;
    00700         DSTR app_name;
    00701         DSTR user_name;
    00702         DSTR password;
    00703         DSTR library;
    00704         TDS_TINYINT bulk_copy;
    00705         TDS_TINYINT suppress_language;
    00706         TDS_TINYINT encrypted;
    00707
    00708         TDS_INT query_timeout;
    00709         TDS_INT longquery_timeout;
    00710         void (*longquery_func) (void *param);
    00711         void *longquery_param;
    00712         unsigned char capabilities[TDS_MAX_CAPABILITY];
    00713         DSTR client_charset;
    00714
    00715         DSTR ip_addr;
    00716         DSTR database;
    00717         DSTR dump_file;
    00718         DSTR default_domain;
    00719         int timeout;
    00720         int debug_level;
    00721         int text_size;
    00722         int broken_dates;
    00723         int broken_money;
    00724         int try_server_login;
    00725         int try_domain_login;
    00726         int xdomain_auth;
    00727         int emul_little_endian;
    00728 } TDSCONNECTINFO;
    00729
    00730 typedef struct tds_locale
    00731 {
    00732         char *language;
    00733         char *char_set;
    00734         char *date_fmt;
    00735 } TDSLOCALE;
    00736
    00741 typedef struct tds_blob_info
    00742 {
    00743         TDS_CHAR *textvalue;
    00744         TDS_CHAR textptr[16];
    00745         TDS_CHAR timestamp[8];
    00746 } TDSBLOBINFO;
    00747
    00751 typedef struct
    00752 {
    00753         TDS_USMALLINT locale_id;        /* master..syslanguages.lcid */
    00754         TDS_USMALLINT flags;
    00755         TDS_UCHAR charset_id;           /* or zero */
    00756 } TDS8_COLLATION;
    00757
    00758 /* SF stands for "sort flag" */
    00759 #define TDS_SF_BIN                   (TDS_USMALLINT) 0x100
    00760 #define TDS_SF_WIDTH_INSENSITIVE     (TDS_USMALLINT) 0x080
    00761 #define TDS_SF_KATATYPE_INSENSITIVE  (TDS_USMALLINT) 0x040
    00762 #define TDS_SF_ACCENT_SENSITIVE      (TDS_USMALLINT) 0x020
    00763 #define TDS_SF_CASE_INSENSITIVE      (TDS_USMALLINT) 0x010
    00764
    00765
    00770 typedef struct _tds_encoding
    00771 {
    00772         const char *name;
    00773         unsigned char min_bytes_per_char;
    00774         unsigned char max_bytes_per_char;
    00775 } TDS_ENCODING;
    00776
    00777
    00778 enum
    00779 { TDS_SYSNAME_SIZE = 512 };
    00780
    00784 typedef struct tds_column_info
    00785 {
    00786         TDS_SMALLINT column_type;
    00791         TDS_INT column_usertype;
    00792         TDS_INT column_flags;
    00793
    00794         TDS_INT column_size;
    00796         TDS_TINYINT column_varint_size;
    00798         TDS_TINYINT column_prec;
    00799         TDS_TINYINT column_scale;
    00801         TDS_TINYINT column_namelen;
    00802         TDS_TINYINT table_namelen;
    00803         struct
    00804         {
    00805                 TDS_SMALLINT column_type;
    00806                 TDS_INT column_size;
    00807         } on_server;
    00808
    00809         const TDSICONVINFO *iconv_info;
    00811         TDS_CHAR table_name[TDS_SYSNAME_SIZE];
    00812         TDS_CHAR column_name[TDS_SYSNAME_SIZE];
    00813
    00814         TDS_INT column_offset;
    00815         unsigned int column_nullable:1;
    00816         unsigned int column_writeable:1;
    00817         unsigned int column_identity:1;
    00818         unsigned int column_key:1;
    00819         unsigned int column_hidden:1;
    00820         unsigned int column_output:1;
    00821         TDS_UCHAR column_collation[5];
    00822
    00823         /* additional fields flags for compute results */
    00824         TDS_TINYINT column_operator;
    00825         TDS_SMALLINT column_operand;
    00826
    00827         /* FIXME this is data related, not column */
    00829         TDS_INT column_cur_size;
    00830
    00831         /* related to binding or info stored by client libraries */
    00832         /* FIXME find a best place to store these data, some are unused */
    00833         TDS_SMALLINT column_bindtype;
    00834         TDS_SMALLINT column_bindfmt;
    00835         TDS_UINT column_bindlen;
    00836         TDS_CHAR *column_nullbind;
    00837         TDS_CHAR *column_varaddr;
    00838         TDS_CHAR *column_lenbind;
    00839         TDS_INT column_textpos;
    00840         TDS_INT column_text_sqlgetdatapos;
    00841 } TDSCOLINFO;
    00842
    00843 typedef struct
    00844 {
    00845         int tab_colnum;
    00846         char db_name[256];      /* column name */
    00847         TDS_SMALLINT db_minlen;
    00848         TDS_SMALLINT db_maxlen;
    00849         TDS_SMALLINT db_colcnt; /* I don't know what this does */
    00850         TDS_TINYINT db_type;
    00851         struct
    00852         {
    00853                 TDS_SMALLINT column_type;
    00854                 TDS_INT column_size;
    00855         } on_server;
    00856         const TDSICONVINFO *iconv_info;
    00857         TDS_SMALLINT db_usertype;
    00858         TDS_TINYINT db_varint_size;
    00859         TDS_INT db_length;      /* size of field according to database */
    00860         TDS_TINYINT db_nullable;
    00861         TDS_TINYINT db_status;
    00862         TDS_SMALLINT db_offset;
    00863         TDS_TINYINT db_default;
    00864         TDS_TINYINT db_prec;
    00865         TDS_TINYINT db_scale;
    00866         TDS_SMALLINT db_flags;
    00867         TDS_INT db_size;
    00868         char db_collate[5];
    00869         long data_size;
    00870         TDS_TINYINT *data;
    00871         int txptr_offset;
    00872 } BCP_COLINFO;
    00873
    00874
    00876 typedef struct tds_result_info
    00877 {
    00878         /* TODO those fields can became a struct */
    00879         TDS_SMALLINT num_cols;
    00880         TDSCOLINFO **columns;
    00881         TDS_INT row_size;
    00882         int null_info_size;
    00883         unsigned char *current_row;
    00884
    00885         TDS_SMALLINT rows_exist;
    00886         TDS_INT row_count;
    00887         TDS_SMALLINT computeid;
    00888         TDS_TINYINT more_results;
    00889         TDS_TINYINT *bycolumns;
    00890         TDS_SMALLINT by_cols;
    00891 } TDSRESULTINFO;
    00892
    00893 /* values for tds->state */
    00894 enum
    00895 {
    00896         TDS_QUERYING,
    00897         TDS_PENDING,
    00898         TDS_IDLE,
    00899         TDS_CANCELED,
    00900         TDS_DEAD
    00901 };
    00902
    00903 #define TDS_DBG_FUNC    7
    00904 #define TDS_DBG_INFO2   6
    00905 #define TDS_DBG_INFO1   5
    00906 #define TDS_DBG_NETWORK 4
    00907 #define TDS_DBG_WARN    3
    00908 #define TDS_DBG_ERROR   2
    00909 #define TDS_DBG_SEVERE  1
    00910
    00916 enum TDS_DBG_LOG_STATE
    00917 {
    00918           TDS_DBG_LOGIN = 1             /* for diagnosing login problems;
    00919                                            otherwise the username/password information is suppressed. */
    00920         , TDS_DBG_API =    (1 << 1)     /* Log calls to client libraries */
    00921         , TDS_DBG_ASYNC =  (1 << 2)     /* Log asynchronous function starts or completes. */
    00922         , TDS_DBG_DIAG =   (1 << 3)     /* Log client- and server-generated messages */
    00923         , TDS_DBG_error =  (1 << 4)
    00924         /* TODO:  ^^^^^ make upper case when old #defines (above) are removed */
    00925         /* Log FreeTDS runtime/logic error occurs. */
    00926         , TDS_DBG_PACKET = (1 << 5)     /* Log hex dump of packets to/from the server. */
    00927         , TDS_DBG_LIBTDS = (1 << 6)     /* Log calls to (and in) libtds */
    00928         , TDS_DBG_CONFIG = (1 << 7)     /* replaces TDSDUMPCONFIG */
    00929         , TDS_DBG_DEFAULT = 0xFE        /* all above except login packets */
    00930 };
    00931
    00932 typedef struct tds_result_info TDSCOMPUTEINFO;
    00933
    00934 typedef TDSRESULTINFO TDSPARAMINFO;
    00935
    00936 typedef struct tds_msg_info
    00937 {
    00938         TDS_SMALLINT priv_msg_type;
    00939         TDS_SMALLINT line_number;
    00940         TDS_UINT msg_number;
    00941         TDS_SMALLINT msg_state;
    00942         TDS_SMALLINT msg_level;
    00943         TDS_CHAR *server;
    00944         TDS_CHAR *message;
    00945         TDS_CHAR *proc_name;
    00946         TDS_CHAR *sql_state;
    00947 } TDSMSGINFO;
    00948
    00949 typedef struct tds_upd_col
    00950 {
    00951         struct tds_upd_col *next;
    00952         TDS_INT colnamelength;
    00953         char * columnname;
    00954 } TDSUPDCOL;
    00955
    00956 typedef enum {
    00957           TDS_CURSOR_STATE_UNACTIONED = 0
    00958         , TDS_CURSOR_STATE_REQUESTED = 1        /* called by ct_cursor */
    00959         , TDS_CURSOR_STATE_SENT = 2             /* sent to server and ack */
    00960 } TDS_CURSOR_STATE;
    00961
    00962 typedef struct _tds_cursor_status
    00963 {
    00964         TDS_CURSOR_STATE declare;
    00965         TDS_CURSOR_STATE cursor_row;
    00966         TDS_CURSOR_STATE open;
    00967         TDS_CURSOR_STATE fetch;
    00968         TDS_CURSOR_STATE close;
    00969         TDS_CURSOR_STATE dealloc;
    00970 } TDS_CURSOR_STATUS;
    00971
    00972 typedef struct _tds_cursor
    00973 {
    00974         TDS_INT length;                 /* total length of the remaining datastream */
    00975         TDS_TINYINT cursor_name_len;    /* length of cursor name > 0 and <= 30  */
    00976         char *cursor_name;              /* name of the cursor */
    00977         TDS_INT cursor_id;              /* cursor id returned by the server after cursor declare */
    00978         TDS_TINYINT options;            /* read only|updatable */
    00979         TDS_TINYINT hasargs;            /* cursor parameters exists ? */
    00980         TDS_USMALLINT query_len;        /* SQL query length */
    00981         char *query;                    /* SQL query */
    00982         /* TODO for updatable columns */
    00983         TDS_TINYINT number_upd_cols;    /* number of updatable columns */
    00984         TDS_INT cursor_rows;            /* number of cursor rows to fetch */
    00985         /*TODO when cursor has parameters*/
    00986         /*TDS_PARAM *param_list;         cursor parameter */
    00987         TDSUPDCOL *cur_col_list;        /* updatable column list */
    00988         TDS_CURSOR_STATUS status;
    00989 } TDS_CURSOR;
    00990
    00991 /*
    00992  * Current environment as reported by the server
    00993  */
    00994 typedef struct tds_env_info
    00995 {
    00996         int block_size;
    00997         char *language;
    00998         char *charset;
    00999         char *database;
    01000 } TDSENVINFO;
    01001
    01002 typedef struct tds_dynamic
    01003 {
    01004         char id[30];
    01005         int dyn_state;
    01007         TDS_INT num_id;
    01008         TDSPARAMINFO *res_info;
    01009         TDSPARAMINFO *params;
    01010         int emulated;
    01012         char *query;
    01013 } TDSDYNAMIC;
    01014
    01015 /* forward declaration */
    01016 typedef struct tds_context TDSCONTEXT;
    01017
    01018 struct tds_context
    01019 {
    01020         TDSLOCALE *locale;
    01021         void *parent;
    01022         /* handler */
    01023         int (*msg_handler) (TDSCONTEXT *, TDSSOCKET *, TDSMSGINFO *);
    01024         int (*err_handler) (TDSCONTEXT *, TDSSOCKET *, TDSMSGINFO *);
    01025 };
    01026
    01027 enum TDS_ICONV_INFO_ENTRY
    01028 {
    01029           client2ucs2
    01030         , client2server_chardata
    01031         , iso2server_metadata
    01032         , initial_iconv_info_count      /* keep last */
    01033 };
    01034
    01035 struct tds_socket
    01036 {
    01037         /* fixed and connect time */
    01038         TDS_SYS_SOCKET s;
    01039         TDS_SMALLINT major_version;
    01040         TDS_SMALLINT minor_version;
    01042         TDS_UINT product_version;
    01043         char *product_name;
    01044         unsigned char capabilities[TDS_MAX_CAPABILITY];
    01045         unsigned char broken_dates;
    01046         unsigned char option_flag2;
    01047         /* in/out buffers */
    01048         unsigned char *in_buf;
    01049         unsigned char *out_buf;
    01050         unsigned int in_buf_max;
    01051         unsigned in_pos;
    01052         unsigned out_pos;
    01053         unsigned in_len;
    01054         unsigned out_len;
    01055         unsigned char out_flag;
    01056         unsigned char last_packet;
    01057         void *parent;
    01058         /* info about current query.
    01059          * Contain information in process, even normal results and compute.
    01060          * This pointer shouldn't be freed.
    01061          */
    01062         TDSRESULTINFO *curr_resinfo;
    01063         TDSRESULTINFO *res_info;
    01064         TDS_INT num_comp_info;
    01065         TDSCOMPUTEINFO **comp_info;
    01066         TDSPARAMINFO *param_info;
    01067         TDS_CURSOR *cursor;
    01068         TDS_TINYINT has_status;
    01069         TDS_INT ret_status;
    01070         TDS_TINYINT state;
    01071         int rows_affected;
    01072         /* timeout stuff from Jeff */
    01073         TDS_INT timeout;
    01074         TDS_INT longquery_timeout;
    01075         void (*longquery_func) (void *param);
    01076         void *longquery_param;
    01077         time_t queryStarttime;
    01078         TDSENVINFO *env;
    01079         /* dynamic placeholder stuff */
    01080         int num_dyns;
    01081         TDSDYNAMIC *cur_dyn;
    01082         TDSDYNAMIC **dyns;
    01083         int emul_little_endian;
    01084         char *date_fmt;
    01085         TDSCONTEXT *tds_ctx;
    01086         int iconv_info_count;
    01087         TDSICONVINFO **iconv_info;
    01088
    01090         TDSCONNECTINFO *connect_info;
    01091         int spid;
    01092         TDS_UCHAR collation[5];
    01093         void (*env_chg_func) (TDSSOCKET * tds, int type, char *oldval, char *newval);
    01094         int (*chkintr) (TDSSOCKET * tds);
    01095         int (*hndlintr) (TDSSOCKET * tds);
    01096     int internal_sp_called;
    01097 };
    01098
    01099 void tds_set_longquery_handler(TDSLOGIN * tds_login, void (*longquery_func) (void *param), void *longquery_param);
    01100 void tds_set_timeouts(TDSLOGIN * tds_login, int connect_timeout, int query_timeout, int longquery_timeout);
    01101 int tds_init_write_buf(TDSSOCKET * tds);
    01102 void tds_free_result_info(TDSRESULTINFO * info);
    01103 void tds_free_socket(TDSSOCKET * tds);
    01104 void tds_free_connect(TDSCONNECTINFO * connect_info);
    01105 void tds_free_all_results(TDSSOCKET * tds);
    01106 void tds_free_results(TDSRESULTINFO * res_info);
    01107 void tds_free_param_results(TDSPARAMINFO * param_info);
    01108 void tds_free_msg(TDSMSGINFO * msg_info);
    01109 void tds_free_cursor(TDS_CURSOR *cursor);
    01110 int tds_put_n(TDSSOCKET * tds, const void *buf, int n);
    01111 int tds_put_string(TDSSOCKET * tds, const char *buf, int len);
    01112 int tds_put_int(TDSSOCKET * tds, TDS_INT i);
    01113 int tds_put_int8(TDSSOCKET * tds, TDS_INT8 i);
    01114 int tds_put_smallint(TDSSOCKET * tds, TDS_SMALLINT si);
    01115 int tds_put_tinyint(TDSSOCKET * tds, TDS_TINYINT ti);
    01116 int tds_put_byte(TDSSOCKET * tds, unsigned char c);
    01117 TDSRESULTINFO *tds_alloc_results(int num_cols);
    01118 TDSCOMPUTEINFO **tds_alloc_compute_results(TDS_INT * num_comp_results, TDSCOMPUTEINFO ** ci, int num_cols, int by_cols);
    01119 TDSCONTEXT *tds_alloc_context(void);
    01120 void tds_free_context(TDSCONTEXT * locale);
    01121 TDSSOCKET *tds_alloc_socket(TDSCONTEXT * context, int bufsize);
    01122
    01123 /* config.c */
    01124 const TDS_COMPILETIME_SETTINGS *tds_get_compiletime_settings(void);
    01125 typedef void (*TDSCONFPARSE) (const char *option, const char *value, void *param);
    01126 int tds_read_conf_section(FILE * in, const char *section, TDSCONFPARSE tds_conf_parse, void *parse_param);
    01127 int tds_read_conf_file(TDSCONNECTINFO * connect_info, const char *server);
    01128 TDSCONNECTINFO *tds_read_config_info(TDSSOCKET * tds, TDSLOGIN * login, TDSLOCALE * locale);
    01129 void tds_fix_connect(TDSCONNECTINFO * connect_info);
    01130 void tds_config_verstr(const char *tdsver, TDSCONNECTINFO * connect_info);
    01131 void tds_lookup_host(const char *servername, char *ip);
    01132 int tds_set_interfaces_file_loc(const char *interfloc);
    01133
    01134 TDSLOCALE *tds_get_locale(void);
    01135 unsigned char *tds_alloc_row(TDSRESULTINFO * res_info);
    01136 unsigned char *tds_alloc_compute_row(TDSCOMPUTEINFO * res_info);
    01137 int tds_alloc_get_string(TDSSOCKET * tds, char **string, int len);
    01138 void tds_set_null(unsigned char *current_row, int column);
    01139 void tds_clr_null(unsigned char *current_row, int column);
    01140 int tds_get_null(unsigned char *current_row, int column);
    01141 unsigned char *tds7_crypt_pass(const unsigned char *clear_pass, int len, unsigned char *crypt_pass);
    01142 TDSDYNAMIC *tds_lookup_dynamic(TDSSOCKET * tds, char *id);
    01143 const char *tds_prtype(int token);
    01144
    01145
    01146
    01147 /* iconv.c */
    01148 void tds_iconv_open(TDSSOCKET * tds, const char *charset);
    01149 void tds_iconv_close(TDSSOCKET * tds);
    01150 void tds_srv_charset_changed(TDSSOCKET * tds, const char *charset);
    01151 void tds7_srv_charset_changed(TDSSOCKET * tds, int lcid);
    01152 int tds_iconv_alloc(TDSSOCKET * tds);
    01153 void tds_iconv_free(TDSSOCKET * tds);
    01154 TDSICONVINFO *tds_iconv_from_lcid(TDSSOCKET * tds, int lcid);
    01155
    01156 /* threadsafe.c */
    01157 char *tds_timestamp_str(char *str, int maxlen);
    01158 struct hostent *tds_gethostbyname_r(const char *servername, struct hostent *result, char *buffer, int buflen, int *h_errnop);
    01159 struct hostent *tds_gethostbyaddr_r(const char *addr, int len, int type, struct hostent *result, char *buffer, int buflen,
    01160                                     int *h_errnop);
    01161 struct servent *tds_getservbyname_r(const char *name, const char *proto, struct servent *result, char *buffer, int buflen);
    01162 char *tds_get_homedir(void);
    01163
    01164 /* mem.c */
    01165 TDSPARAMINFO *tds_alloc_param_result(TDSPARAMINFO * old_param);
    01166 void tds_free_input_params(TDSDYNAMIC * dyn);
    01167 void tds_free_all_dynamic(TDSSOCKET * tds);
    01168 void tds_free_dynamic(TDSSOCKET * tds, TDSDYNAMIC * dyn);
    01169 TDSSOCKET *tds_realloc_socket(TDSSOCKET * tds, int bufsize);
    01170 void tds_free_compute_result(TDSCOMPUTEINFO * comp_info);
    01171 void tds_free_compute_results(TDSCOMPUTEINFO ** comp_info, TDS_INT num_comp);
    01172 unsigned char *tds_alloc_param_row(TDSPARAMINFO * info, TDSCOLINFO * curparam);
    01173 char *tds_alloc_client_sqlstate(int msgnum);
    01174 char *tds_alloc_lookup_sqlstate(TDSSOCKET * tds, int msgnum);
    01175 TDSLOGIN *tds_alloc_login(void);
    01176 TDSDYNAMIC *tds_alloc_dynamic(TDSSOCKET * tds, const char *id);
    01177 void tds_free_login(TDSLOGIN * login);
    01178 TDSCONNECTINFO *tds_alloc_connect(TDSLOCALE * locale);
    01179 TDSLOCALE *tds_alloc_locale(void);
    01180 void tds_free_locale(TDSLOCALE * locale);
    01181 TDS_CURSOR * tds_alloc_cursor(char *name, TDS_INT namelen, char *query, TDS_INT querylen);
    01182
    01183 /* login.c */
    01184 int tds7_send_auth(TDSSOCKET * tds, const unsigned char *challenge);
    01185 void tds_set_packet(TDSLOGIN * tds_login, int packet_size);
    01186 void tds_set_port(TDSLOGIN * tds_login, int port);
    01187 void tds_set_passwd(TDSLOGIN * tds_login, const char *password);
    01188 void tds_set_bulk(TDSLOGIN * tds_login, TDS_TINYINT enabled);
    01189 void tds_set_user(TDSLOGIN * tds_login, const char *username);
    01190 void tds_set_app(TDSLOGIN * tds_login, const char *application);
    01191 void tds_set_host(TDSLOGIN * tds_login, const char *hostname);
    01192 void tds_set_library(TDSLOGIN * tds_login, const char *library);
    01193 void tds_set_server(TDSLOGIN * tds_login, const char *server);
    01194 void tds_set_client_charset(TDSLOGIN * tds_login, const char *charset);
    01195 void tds_set_language(TDSLOGIN * tds_login, const char *language);
    01196 void tds_set_version(TDSLOGIN * tds_login, short major_ver, short minor_ver);
    01197 void tds_set_capabilities(TDSLOGIN * tds_login, unsigned char *capabilities, int size);
    01198 int tds_connect(TDSSOCKET * tds, TDSCONNECTINFO * connect_info);
    01199
    01200 /* query.c */
    01201 int tds_submit_query(TDSSOCKET * tds, const char *query);
    01202 int tds_submit_query_params(TDSSOCKET * tds, const char *query, TDSPARAMINFO * params);
    01203 int tds_submit_queryf(TDSSOCKET * tds, const char *queryf, ...);
    01204 int tds_submit_prepare(TDSSOCKET * tds, const char *query, const char *id, TDSDYNAMIC ** dyn_out, TDSPARAMINFO * params);
    01205 int tds_submit_execdirect(TDSSOCKET * tds, const char *query, TDSPARAMINFO * params);
    01206 int tds_submit_execute(TDSSOCKET * tds, TDSDYNAMIC * dyn);
    01207 int tds_send_cancel(TDSSOCKET * tds);
    01208 const char *tds_next_placeholders(const char *start);
    01209 int tds_count_placeholders(const char *query);
    01210 int tds_get_dynid(TDSSOCKET * tds, char **id);
    01211 int tds_submit_unprepare(TDSSOCKET * tds, TDSDYNAMIC * dyn);
    01212 int tds_submit_rpc(TDSSOCKET * tds, const char *rpc_name, TDSPARAMINFO * params);
    01213 int tds_quote_id(TDSSOCKET * tds, char *buffer, const char *id, int idlen);
    01214 int tds_quote_string(TDSSOCKET * tds, char *buffer, const char *str, int len);
    01215 const char *tds_skip_quoted(const char *s);
    01216 int tds_cursor_declare(TDSSOCKET * tds, int *send);
    01217 int tds_cursor_setrows(TDSSOCKET * tds, int *send);
    01218 int tds_cursor_open(TDSSOCKET * tds, int *send);
    01219 int tds_cursor_fetch(TDSSOCKET * tds);
    01220 int tds_cursor_close(TDSSOCKET * tds);
    01221 int tds_cursor_dealloc(TDSSOCKET * tds);
    01222
    01223 /* token.c */
    01224 int tds_process_cancel(TDSSOCKET * tds);
    01225 void tds_swap_datatype(int coltype, unsigned char *buf);
    01226 int tds_get_token_size(int marker);
    01227 int tds_process_login_tokens(TDSSOCKET * tds);
    01228 void tds_add_row_column_size(TDSRESULTINFO * info, TDSCOLINFO * curcol);
    01229 int tds_process_simple_query(TDSSOCKET * tds);
    01230 int tds5_send_optioncmd(TDSSOCKET * tds, TDS_OPTION_CMD tds_command, TDS_OPTION tds_option, TDS_OPTION_ARG * tds_argument,
    01231                         TDS_INT * tds_argsize);
    01232 int tds_process_result_tokens(TDSSOCKET * tds, TDS_INT * result_type, int *done_flags);
    01233 int tds_process_row_tokens(TDSSOCKET * tds, TDS_INT * rowtype, TDS_INT * computeid);
    01234 int tds_process_row_tokens_ct(TDSSOCKET * tds, TDS_INT * rowtype, TDS_INT *computeid);
    01235 int tds_process_trailing_tokens(TDSSOCKET * tds);
    01236 int tds_client_msg(TDSCONTEXT * tds_ctx, TDSSOCKET * tds, int msgnum, int level, int state, int line, const char *message);
    01237 int tds_do_until_done(TDSSOCKET * tds);
    01238
    01239 /* data.c */
    01240 void tds_set_param_type(TDSSOCKET * tds, TDSCOLINFO * curcol, TDS_SERVER_TYPE type);
    01241 void tds_set_column_type(TDSCOLINFO * curcol, int type);
    01242
    01243
    01244 /* tds_convert.c */
    01245 TDS_INT tds_datecrack(TDS_INT datetype, const void *di, TDSDATEREC * dr);
    01246 int tds_get_conversion_type(int srctype, int colsize);
    01247 extern const char tds_hex_digits[];
    01248
    01249 /* write.c */
    01250 int tds_put_bulk_data(TDSSOCKET * tds, const unsigned char *buf, TDS_INT bufsize);
    01251 int tds_flush_packet(TDSSOCKET * tds);
    01252 int tds_put_buf(TDSSOCKET * tds, const unsigned char *buf, int dsize, int ssize);
    01253 int tds7_put_bcpcol(TDSSOCKET * tds, const BCP_COLINFO * bcpcol);
    01254
    01255 /* read.c */
    01256 unsigned char tds_get_byte(TDSSOCKET * tds);
    01257 void tds_unget_byte(TDSSOCKET * tds);
    01258 unsigned char tds_peek(TDSSOCKET * tds);
    01259 TDS_SMALLINT tds_get_smallint(TDSSOCKET * tds);
    01260 TDS_INT tds_get_int(TDSSOCKET * tds);
    01261 int tds_get_string(TDSSOCKET * tds, int string_len, char *dest, size_t dest_size);
    01262 int tds_get_char_data(TDSSOCKET * tds, char *dest, size_t wire_size, TDSCOLINFO * curcol);
    01263 void *tds_get_n(TDSSOCKET * tds, void *dest, int n);
    01264 int tds_get_size_by_type(int servertype);
    01265 int tds_read_packet(TDSSOCKET * tds);
    01266
    01267 /* util.c */
    01268 void tds_set_parent(TDSSOCKET * tds, void *the_parent);
    01269 void *tds_get_parent(TDSSOCKET * tds);
    01270 void tds_ctx_set_parent(TDSCONTEXT * ctx, void *the_parent);
    01271 void *tds_ctx_get_parent(TDSCONTEXT * ctx);
    01272 int tds_swap_bytes(unsigned char *buf, int bytes);
    01273 int tds_version(TDSSOCKET * tds_socket, char *pversion_string);
    01274 void tdsdump_off(void);
    01275 void tdsdump_on(void);
    01276 int tdsdump_open(const char *filename);
    01277 int tdsdump_append(void);
    01278 void tdsdump_close(void);
    01279 void tdsdump_dump_buf(const void *buf, int length);
    01280 void tdsdump_log(int dbg_lvl, const char *fmt, ...);
    01281 int tds_close_socket(TDSSOCKET * tds);
    01282
    01283 /* vstrbuild.c */
    01284 int tds_vstrbuild(char *buffer, int buflen, int *resultlen, char *text, int textlen, const char *formats, int formatlen,
    01285                   va_list ap);
    01286
    01287 /* numeric.c */
    01288 char *tds_money_to_string(const TDS_MONEY * money, char *s);
    01289 char *tds_numeric_to_string(const TDS_NUMERIC * numeric, char *s);
    01290
    01291 /* getmac.c */
    01292 void tds_getmac(int s, unsigned char mac[6]);
    01293
    01294 typedef struct tds_answer
    01295 {
    01296         unsigned char lm_resp[24];
    01297         unsigned char nt_resp[24];
    01298 } TDSANSWER;
    01299 void tds_answer_challenge(const char *passwd, const unsigned char *challenge, TDSANSWER * answer);
    01300
    01301 #define IS_TDS42(x) (x->major_version==4 && x->minor_version==2)
    01302 #define IS_TDS46(x) (x->major_version==4 && x->minor_version==6)
    01303 #define IS_TDS50(x) (x->major_version==5 && x->minor_version==0)
    01304 #define IS_TDS70(x) (x->major_version==7 && x->minor_version==0)
    01305 #define IS_TDS80(x) (x->major_version==8 && x->minor_version==0)
    01306
    01307 #define IS_TDS7_PLUS(x) ( IS_TDS70(x) || IS_TDS80(x) )
    01308
    01309 #define IS_TDSDEAD(x) (((x) == NULL) || TDS_IS_SOCKET_INVALID((x)->s))
    01310
    01312 #define TDS_IS_SYBASE(x) (!(x->product_version & 0x80000000u))
    01313
    01314 #define TDS_IS_MSSQL(x) ((x->product_version & 0x80000000u)!=0)
    01315
    01319 #define TDS_MS_VER(maj,min,x) (0x80000000u|((maj)<<24)|((min)<<16)|(x))
    01320
    01321 /* TODO test if not similar to ms one*/
    01323 #define TDS_SYB_VER(maj,min,x) (((maj)<<24)|((min)<<16)|(x)<<8)
    01324
    01325 #ifdef __cplusplus
    01326 #if 0
    01327 {
    01328 #endif
    01329 }
    01330 #endif
    01331
    01332 #endif /* _tds_h_ */