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