# 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.3 2008/11/05 14:56:12 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_ENCRYPTION       "encryption"
    00809 /* conf values */
    00810 #define TDS_STR_ENCRYPTION_OFF   "off"
    00811 #define TDS_STR_ENCRYPTION_REQUEST "request"
    00812 #define TDS_STR_ENCRYPTION_REQUIRE "require"
    00813
    00814
    00815 /* TODO do a better check for alignment than this */
    00816 typedef union
    00817 {
    00818         void *p;
    00819         int i;
    00820 } tds_align_struct;
    00821
    00822 #define TDS_ALIGN_SIZE sizeof(tds_align_struct)
    00823
    00824 #define TDS_MAX_LOGIN_STR_SZ 30
    00825 typedef struct tds_login
    00826 {
    00827         DSTR server_name;
    00828         DSTR server_addr;
    00829         int port;
    00830         TDS_TINYINT major_version;      /* TDS version */
    00831         TDS_TINYINT minor_version;      /* TDS version */
    00832         int block_size;
    00833         DSTR language;          /* ie us-english */
    00834         DSTR server_charset;    /*  ie iso_1 */
    00835         TDS_INT connect_timeout;
    00836         DSTR client_host_name;
    00837         DSTR app_name;
    00838         DSTR user_name;
    00839         DSTR password;
    00840
    00841         DSTR library;   /* Ct-Library, DB-Library,  TDS-Library or ODBC */
    00842         TDS_TINYINT bulk_copy;
    00843         TDS_TINYINT suppress_language;
    00844         TDS_TINYINT encryption_level;
    00845
    00846         TDS_INT query_timeout;
    00847         unsigned char capabilities[TDS_MAX_CAPABILITY];
    00848         DSTR client_charset;
    00849 } TDSLOGIN;
    00850
    00851 typedef struct tds_connection
    00852 {
    00853         /* first part of structure is the same of login one */
    00854         DSTR server_name;
    00855         int port;
    00856         TDS_TINYINT major_version;
    00857         TDS_TINYINT minor_version;
    00858         int block_size;
    00859         DSTR language;
    00860         DSTR server_charset;
    00861         TDS_INT connect_timeout;
    00862         DSTR client_host_name;
    00863         DSTR server_host_name;
    00864         DSTR app_name;
    00865         DSTR user_name;
    00866         DSTR password;
    00867         DSTR library;
    00868         TDS_TINYINT bulk_copy;
    00869         TDS_TINYINT suppress_language;
    00870         TDS_TINYINT encryption_level;
    00871
    00872         TDS_INT query_timeout;
    00873         unsigned char capabilities[TDS_MAX_CAPABILITY];
    00874         DSTR client_charset;
    00875
    00876         DSTR ip_addr;
    00877         DSTR instance_name;
    00878         DSTR database;
    00879         DSTR dump_file;
    00880         int debug_flags;
    00881         int text_size;
    00882         int broken_dates;
    00883         int broken_money;
    00884         int emul_little_endian;
    00885 } TDSCONNECTION;
    00886
    00887 typedef struct tds_locale
    00888 {
    00889         char *language;
    00890         char *server_charset;
    00891         char *client_charset;
    00892         char *date_fmt;
    00893 } TDSLOCALE;
    00894
    00899 typedef struct tds_blob
    00900 {
    00901         TDS_CHAR *textvalue;
    00902         TDS_CHAR textptr[16];
    00903         TDS_CHAR timestamp[8];
    00904 } TDSBLOB;
    00905
    00909 typedef struct
    00910 {
    00911         TDS_USMALLINT locale_id;        /* master..syslanguages.lcid */
    00912         TDS_USMALLINT flags;
    00913         TDS_UCHAR charset_id;           /* or zero */
    00914 } TDS8_COLLATION;
    00915
    00916 /* SF stands for "sort flag" */
    00917 #define TDS_SF_BIN                   (TDS_USMALLINT) 0x100
    00918 #define TDS_SF_WIDTH_INSENSITIVE     (TDS_USMALLINT) 0x080
    00919 #define TDS_SF_KATATYPE_INSENSITIVE  (TDS_USMALLINT) 0x040
    00920 #define TDS_SF_ACCENT_SENSITIVE      (TDS_USMALLINT) 0x020
    00921 #define TDS_SF_CASE_INSENSITIVE      (TDS_USMALLINT) 0x010
    00922
    00923 /* UT stands for user type */
    00924 #define TDS_UT_TIMESTAMP             80
    00925
    00926
    00931 typedef struct _tds_encoding
    00932 {
    00933         const char *name;
    00934         unsigned char min_bytes_per_char;
    00935         unsigned char max_bytes_per_char;
    00936 } TDS_ENCODING;
    00937
    00938 typedef struct _tds_bcpcoldata
    00939 {
    00940         TDS_UCHAR *data;
    00941         TDS_INT    datalen;
    00942         TDS_INT    is_null;
    00943 } BCPCOLDATA;
    00944
    00945
    00946 enum
    00947 { TDS_SYSNAME_SIZE = 512 };
    00948
    00952 typedef struct tds_column
    00953 {
    00954         TDS_SMALLINT column_type;
    00959         TDS_INT column_usertype;
    00960         TDS_INT column_flags;
    00961
    00962         TDS_INT column_size;
    00964         TDS_TINYINT column_varint_size;
    00966         TDS_TINYINT column_prec;
    00967         TDS_TINYINT column_scale;
    00969         TDS_SMALLINT column_namelen;
    00970         TDS_SMALLINT table_namelen;
    00971         struct
    00972         {
    00973                 TDS_SMALLINT column_type;
    00974                 TDS_INT column_size;
    00975         } on_server;
    00976
    00977         const TDSICONV *char_conv;
    00979         TDS_CHAR table_name[TDS_SYSNAME_SIZE];
    00980         TDS_CHAR column_name[TDS_SYSNAME_SIZE];
    00981         char * table_column_name;
    00982
    00983         unsigned char *column_data;
    00984         void (*column_data_free)(struct tds_column *column);
    00985         unsigned int column_nullable:1;
    00986         unsigned int column_writeable:1;
    00987         unsigned int column_identity:1;
    00988         unsigned int column_key:1;
    00989         unsigned int column_hidden:1;
    00990         unsigned int column_output:1;
    00991         unsigned int column_timestamp:1;
    00992         TDS_UCHAR column_collation[5];
    00993
    00994         /* additional fields flags for compute results */
    00995         TDS_TINYINT column_operator;
    00996         TDS_SMALLINT column_operand;
    00997
    00998         /* FIXME this is data related, not column */
    01000         TDS_INT column_cur_size;
    01001
    01002         /* related to binding or info stored by client libraries */
    01003         /* FIXME find a best place to store these data, some are unused */
    01004         TDS_SMALLINT column_bindtype;
    01005         TDS_SMALLINT column_bindfmt;
    01006         TDS_UINT column_bindlen;
    01007         TDS_SMALLINT *column_nullbind;
    01008         TDS_CHAR *column_varaddr;
    01009         TDS_INT *column_lenbind;
    01010         TDS_INT column_textpos;
    01011         TDS_INT column_text_sqlgetdatapos;
    01012
    01013         BCPCOLDATA *bcp_column_data;
    01022         TDS_INT bcp_prefix_len;
    01023         TDS_INT bcp_term_len;
    01024         TDS_CHAR *bcp_terminator;
    01025 } TDSCOLUMN;
    01026
    01027
    01029 typedef struct tds_result_info
    01030 {
    01031         /* TODO those fields can became a struct */
    01032         TDS_SMALLINT num_cols;
    01033         TDSCOLUMN **columns;
    01034         TDS_INT row_size;
    01035         TDS_INT ref_count;
    01036         unsigned char *current_row;
    01037         void (*row_free)(struct tds_result_info* result, unsigned char *row);
    01038
    01039         TDS_SMALLINT rows_exist;
    01040         /* TODO remove ?? used only in dblib */
    01041         TDS_INT row_count;
    01042         /* TODO remove ?? used only in dblib */
    01043         TDS_TINYINT more_results;
    01044         TDS_SMALLINT computeid;
    01045         TDS_SMALLINT *bycolumns;
    01046         TDS_SMALLINT by_cols;
    01047 } TDSRESULTINFO;
    01048
    01050 typedef enum _TDS_STATE
    01051 {
    01052         TDS_IDLE,
    01053         TDS_QUERYING,
    01054         TDS_PENDING,
    01055         TDS_READING,
    01056         TDS_DEAD
    01057 } TDS_STATE;
    01058
    01059 #define TDS_DBG_FUNC    __FILE__, ((__LINE__ << 4) | 7)
    01060 #define TDS_DBG_INFO2   __FILE__, ((__LINE__ << 4) | 6)
    01061 #define TDS_DBG_INFO1   __FILE__, ((__LINE__ << 4) | 5)
    01062 #define TDS_DBG_NETWORK __FILE__, ((__LINE__ << 4) | 4)
    01063 #define TDS_DBG_WARN    __FILE__, ((__LINE__ << 4) | 3)
    01064 #define TDS_DBG_ERROR   __FILE__, ((__LINE__ << 4) | 2)
    01065 #define TDS_DBG_SEVERE  __FILE__, ((__LINE__ << 4) | 1)
    01066
    01067 #define TDS_DBGFLAG_FUNC    0x80
    01068 #define TDS_DBGFLAG_INFO2   0x40
    01069 #define TDS_DBGFLAG_INFO1   0x20
    01070 #define TDS_DBGFLAG_NETWORK 0x10
    01071 #define TDS_DBGFLAG_WARN    0x08
    01072 #define TDS_DBGFLAG_ERROR   0x04
    01073 #define TDS_DBGFLAG_SEVERE  0x02
    01074 #define TDS_DBGFLAG_ALLLVL  0xfff
    01075 #define TDS_DBGFLAG_PID     0x1000
    01076 #define TDS_DBGFLAG_TIME    0x2000
    01077 #define TDS_DBGFLAG_SOURCE  0x4000
    01078 #define TDS_DBGFLAG_THREAD  0x8000
    01079
    01085 enum TDS_DBG_LOG_STATE
    01086 {
    01087           TDS_DBG_LOGIN =  (1 << 0)
    01089         , TDS_DBG_API =    (1 << 1)
    01090         , TDS_DBG_ASYNC =  (1 << 2)
    01091         , TDS_DBG_DIAG =   (1 << 3)
    01092         , TDS_DBG_error =  (1 << 4)
    01093         /* TODO:  ^^^^^ make upper case when old #defines (above) are removed */
    01094         /* Log FreeTDS runtime/logic error occurs. */
    01095         , TDS_DBG_PACKET = (1 << 5)
    01096         , TDS_DBG_LIBTDS = (1 << 6)
    01097         , TDS_DBG_CONFIG = (1 << 7)
    01098         , TDS_DBG_DEFAULT = 0xFE
    01099 };
    01100
    01101 typedef struct tds_result_info TDSCOMPUTEINFO;
    01102
    01103 typedef TDSRESULTINFO TDSPARAMINFO;
    01104
    01105 typedef struct tds_message
    01106 {
    01107         TDS_CHAR *server;
    01108         TDS_CHAR *message;
    01109         TDS_CHAR *proc_name;
    01110         TDS_CHAR *sql_state;
    01111         TDS_UINT msgno;
    01112         TDS_INT line_number;
    01113         /* -1 .. 255 */
    01114         TDS_SMALLINT state;
    01115         TDS_TINYINT priv_msg_type;
    01116         TDS_TINYINT severity;
    01117         /* for library-generated errors */
    01118         int oserr;
    01119 } TDSMESSAGE;
    01120
    01121 typedef struct tds_upd_col
    01122 {
    01123         struct tds_upd_col *next;
    01124         TDS_INT colnamelength;
    01125         char * columnname;
    01126 } TDSUPDCOL;
    01127
    01128 typedef enum {
    01129           TDS_CURSOR_STATE_UNACTIONED = 0   /* initial value */
    01130         , TDS_CURSOR_STATE_REQUESTED = 1        /* called by ct_cursor */
    01131         , TDS_CURSOR_STATE_SENT = 2             /* sent to server */
    01132         , TDS_CURSOR_STATE_ACTIONED = 3         /* acknowledged by server */
    01133 } TDS_CURSOR_STATE;
    01134
    01135 typedef struct _tds_cursor_status
    01136 {
    01137         TDS_CURSOR_STATE declare;
    01138         TDS_CURSOR_STATE cursor_row;
    01139         TDS_CURSOR_STATE open;
    01140         TDS_CURSOR_STATE fetch;
    01141         TDS_CURSOR_STATE close;
    01142         TDS_CURSOR_STATE dealloc;
    01143 } TDS_CURSOR_STATUS;
    01144
    01145 typedef enum _tds_cursor_operation
    01146 {
    01147         TDS_CURSOR_POSITION = 0,
    01148         TDS_CURSOR_UPDATE = 1,
    01149         TDS_CURSOR_DELETE = 2,
    01150         TDS_CURSOR_INSERT = 4
    01151 } TDS_CURSOR_OPERATION;
    01152
    01153 typedef enum _tds_cursor_fetch
    01154 {
    01155         TDS_CURSOR_FETCH_NEXT = 1,
    01156         TDS_CURSOR_FETCH_PREV,
    01157         TDS_CURSOR_FETCH_FIRST,
    01158         TDS_CURSOR_FETCH_LAST,
    01159         TDS_CURSOR_FETCH_ABSOLUTE,
    01160         TDS_CURSOR_FETCH_RELATIVE
    01161 } TDS_CURSOR_FETCH;
    01162
    01166 typedef struct _tds_cursor
    01167 {
    01168         struct _tds_cursor *next;
    01169         TDS_INT ref_count;
    01170         TDS_TINYINT cursor_name_len;
    01171         char *cursor_name;
    01172         TDS_INT cursor_id;
    01173         TDS_TINYINT options;
    01174         TDS_TINYINT hasargs;
    01175         TDS_USMALLINT query_len;
    01176         char *query;
    01177         /* TODO for updatable columns */
    01178         /* TDS_TINYINT number_upd_cols; */
    01179         /* TDSUPDCOL *cur_col_list; */
    01180         TDS_INT cursor_rows;
    01181         /* TDSPARAMINFO *params; */
    01182         TDS_CURSOR_STATUS status;
    01183         TDS_SMALLINT srv_status;
    01184         TDSRESULTINFO *res_info;
    01185         TDS_INT type, concurrency;
    01186 } TDSCURSOR;
    01187
    01191 typedef struct tds_env
    01192 {
    01193         int block_size;
    01194         char *language;
    01195         char *charset;
    01196         char *database;
    01197 } TDSENV;
    01198
    01202 typedef struct tds_dynamic
    01203 {
    01204         struct tds_dynamic *next;
    01210         char id[30];
    01211         int dyn_state;
    01213         TDS_INT num_id;
    01214         TDSPARAMINFO *res_info;
    01222         TDSPARAMINFO *params;
    01228         int emulated;
    01230         char *query;
    01231 } TDSDYNAMIC;
    01232
    01233 typedef enum {
    01234         TDS_MULTIPLE_QUERY,
    01235         TDS_MULTIPLE_EXECUTE,
    01236         TDS_MULTIPLE_RPC
    01237 } TDS_MULTIPLE_TYPE;
    01238
    01239 typedef struct tds_multiple
    01240 {
    01241         TDS_MULTIPLE_TYPE type;
    01242         unsigned int flags;
    01243 } TDSMULTIPLE;
    01244
    01245 /* forward declaration */
    01246 typedef struct tds_context TDSCONTEXT;
    01247
    01248 struct tds_context
    01249 {
    01250         TDSLOCALE *locale;
    01251         void *parent;
    01252         /* handlers */
    01253         int (*msg_handler) (const TDSCONTEXT *, TDSSOCKET *, TDSMESSAGE *);
    01254         int (*err_handler) (const TDSCONTEXT *, TDSSOCKET *, TDSMESSAGE *);
    01255         int (*int_handler) (void *);
    01256 };
    01257
    01258 enum TDS_ICONV_ENTRY
    01259 {
    01260           client2ucs2
    01261         , client2server_chardata
    01262         , iso2server_metadata
    01263         , initial_char_conv_count       /* keep last */
    01264 };
    01265
    01266 struct tds_authentication
    01267 {
    01268         TDS_UCHAR *packet;
    01269         int packet_len;
    01270         int (*free)(TDSSOCKET * tds, struct tds_authentication * auth);
    01271         int (*handle_next)(TDSSOCKET * tds, struct tds_authentication * auth, size_t len);
    01272 };
    01273
    01274 typedef struct tds_authentication TDSAUTHENTICATION;
    01275
    01279 struct tds_socket
    01280 {
    01281         /* fixed and connect time */
    01283         TDS_SYS_SOCKET s;
    01284         TDS_SMALLINT major_version;
    01285         TDS_SMALLINT minor_version;
    01287         TDS_UINT product_version;
    01288         char *product_name;
    01289         unsigned char capabilities[TDS_MAX_CAPABILITY];
    01290         unsigned char broken_dates;
    01291         unsigned char option_flag2;
    01292         /* in/out buffers */
    01294         unsigned char *in_buf;
    01296         unsigned char *out_buf;
    01298         unsigned int in_buf_max;
    01300         unsigned in_pos;
    01302         unsigned out_pos;
    01304         unsigned in_len;
    01305         /* TODO remove blocksize from env and use out_len ?? */
    01306 /*      unsigned out_len; */
    01308         unsigned char in_flag;
    01310         unsigned char out_flag;
    01312         unsigned char last_packet;
    01313         void *parent;
    01319         TDSRESULTINFO *current_results;
    01320         TDSRESULTINFO *res_info;
    01321         TDS_INT num_comp_info;
    01322         TDSCOMPUTEINFO **comp_info;
    01323         TDSPARAMINFO *param_info;
    01324         TDSCURSOR *cur_cursor;
    01325         TDSCURSOR *cursors;
    01326         TDS_TINYINT has_status;
    01327         TDS_INT ret_status;
    01328         TDS_STATE state;
    01330         volatile unsigned char in_cancel;
    01332         TDS_INT8 rows_affected;
    01333         /* timeout stuff from Jeff */
    01334         TDS_INT query_timeout;
    01335         TDSENV env;
    01336
    01337         /* dynamic placeholder stuff */
    01338         /*@dependent@*/ TDSDYNAMIC *cur_dyn;
    01339         TDSDYNAMIC *dyns;
    01341         int emul_little_endian;
    01342         char *date_fmt;
    01343         const TDSCONTEXT *tds_ctx;
    01344         int char_conv_count;
    01345         TDSICONV **char_convs;
    01346
    01348         TDSCONNECTION *connection;
    01349
    01350         int spid;
    01351         TDS_UCHAR collation[5];
    01352         TDS_UCHAR tds9_transaction[8];
    01353         void (*env_chg_func) (TDSSOCKET * tds, int type, char *oldval, char *newval);
    01354         int internal_sp_called;
    01355
    01356         void *tls_session;
    01357         void *tls_credentials;
    01358         TDSAUTHENTICATION *authentication;
    01359         int option_value;
    01360 };
    01361
    01362 int tds_init_write_buf(TDSSOCKET * tds);
    01363 void tds_free_result_info(TDSRESULTINFO * info);
    01364 void tds_free_socket(TDSSOCKET * tds);
    01365 void tds_free_connection(TDSCONNECTION * connection);
    01366 void tds_free_all_results(TDSSOCKET * tds);
    01367 void tds_free_results(TDSRESULTINFO * res_info);
    01368 void tds_free_param_results(TDSPARAMINFO * param_info);
    01369 void tds_free_param_result(TDSPARAMINFO * param_info);
    01370 void tds_free_msg(TDSMESSAGE * message);
    01371 void tds_cursor_deallocated(TDSSOCKET *tds, TDSCURSOR *cursor);
    01372 void tds_release_cursor(TDSSOCKET *tds, TDSCURSOR *cursor);
    01373 void tds_free_bcp_column_data(BCPCOLDATA * coldata);
    01374
    01375 int tds_put_n(TDSSOCKET * tds, const void *buf, int n);
    01376 int tds_put_string(TDSSOCKET * tds, const char *buf, int len);
    01377 int tds_put_int(TDSSOCKET * tds, TDS_INT i);
    01378 int tds_put_int8(TDSSOCKET * tds, TDS_INT8 i);
    01379 int tds_put_smallint(TDSSOCKET * tds, TDS_SMALLINT si);
    01381 #define tds_put_tinyint(tds, ti) tds_put_byte(tds,ti)
    01382 int tds_put_byte(TDSSOCKET * tds, unsigned char c);
    01383 TDSRESULTINFO *tds_alloc_results(int num_cols);
    01384 TDSCOMPUTEINFO **tds_alloc_compute_results(TDSSOCKET * tds, int num_cols, int by_cols);
    01385 TDSCONTEXT *tds_alloc_context(void * parent);
    01386 void tds_free_context(TDSCONTEXT * locale);
    01387 TDSSOCKET *tds_alloc_socket(TDSCONTEXT * context, int bufsize);
    01388
    01389 /* config.c */
    01390 const TDS_COMPILETIME_SETTINGS *tds_get_compiletime_settings(void);
    01391 typedef void (*TDSCONFPARSE) (const char *option, const char *value, void *param);
    01392 int tds_read_conf_section(FILE * in, const char *section, TDSCONFPARSE tds_conf_parse, void *parse_param);
    01393 int tds_read_conf_file(TDSCONNECTION * connection, const char *server);
    01394 TDSCONNECTION *tds_read_config_info(TDSSOCKET * tds, TDSLOGIN * login, TDSLOCALE * locale);
    01395 void tds_fix_connection(TDSCONNECTION * connection);
    01396 void tds_config_verstr(const char *tdsver, TDSCONNECTION * connection);
    01397 void tds_lookup_host(const char *servername, char *ip);
    01398 int tds_set_interfaces_file_loc(const char *interfloc);
    01399
    01400 TDSLOCALE *tds_get_locale(void);
    01401 int tds_alloc_row(TDSRESULTINFO * res_info);
    01402 int tds_alloc_compute_row(TDSCOMPUTEINFO * res_info);
    01403 BCPCOLDATA * tds_alloc_bcp_column_data(int column_size);
    01404 unsigned char *tds7_crypt_pass(const unsigned char *clear_pass, int len, unsigned char *crypt_pass);
    01405 TDSDYNAMIC *tds_lookup_dynamic(TDSSOCKET * tds, const char *id);
    01406 /*@observer@*/ const char *tds_prtype(int token);
    01407
    01408
    01409
    01410 /* iconv.c */
    01411 void tds_iconv_open(TDSSOCKET * tds, const char *charset);
    01412 void tds_iconv_close(TDSSOCKET * tds);
    01413 void tds_srv_charset_changed(TDSSOCKET * tds, const char *charset);
    01414 void tds7_srv_charset_changed(TDSSOCKET * tds, int sql_collate, int lcid);
    01415 int tds_iconv_alloc(TDSSOCKET * tds);
    01416 void tds_iconv_free(TDSSOCKET * tds);
    01417 TDSICONV *tds_iconv_from_collate(TDSSOCKET * tds, int sql_collate, int lcid);
    01418
    01419 /* threadsafe.c */
    01420 char *tds_timestamp_str(char *str, int maxlen);
    01421 struct hostent *tds_gethostbyname_r(const char *servername, struct hostent *result, char *buffer, int buflen, int *h_errnop);
    01422 struct hostent *tds_gethostbyaddr_r(const char *addr, int len, int type, struct hostent *result, char *buffer, int buflen,
    01423                                     int *h_errnop);
    01424 struct servent *tds_getservbyname_r(const char *name, const char *proto, struct servent *result, char *buffer, int buflen);
    01425 #ifdef INADDR_NONE
    01426 const char *tds_inet_ntoa_r(struct in_addr iaddr, char *ip, size_t len);
    01427 #endif
    01428 char *tds_get_homedir(void);
    01429
    01430 /* mem.c */
    01431 TDSPARAMINFO *tds_alloc_param_result(TDSPARAMINFO * old_param);
    01432 void tds_free_input_params(TDSDYNAMIC * dyn);
    01433 void tds_free_dynamic(TDSSOCKET * tds, TDSDYNAMIC * dyn);
    01434 TDSSOCKET *tds_realloc_socket(TDSSOCKET * tds, int bufsize);
    01435 char *tds_alloc_client_sqlstate(int msgno);
    01436 char *tds_alloc_lookup_sqlstate(TDSSOCKET * tds, int msgno);
    01437 TDSLOGIN *tds_alloc_login(void);
    01438 TDSDYNAMIC *tds_alloc_dynamic(TDSSOCKET * tds, const char *id);
    01439 void tds_free_login(TDSLOGIN * login);
    01440 TDSCONNECTION *tds_alloc_connection(TDSLOCALE * locale);
    01441 TDSLOCALE *tds_alloc_locale(void);
    01442 void *tds_alloc_param_data(TDSCOLUMN * curparam);
    01443 void tds_free_locale(TDSLOCALE * locale);
    01444 TDSCURSOR * tds_alloc_cursor(TDSSOCKET * tds, const char *name, TDS_INT namelen, const char *query, TDS_INT querylen);
    01445 void tds_free_row(TDSRESULTINFO * res_info, unsigned char *row);
    01446
    01447 /* login.c */
    01448 void tds_set_packet(TDSLOGIN * tds_login, int packet_size);
    01449 void tds_set_port(TDSLOGIN * tds_login, int port);
    01450 void tds_set_passwd(TDSLOGIN * tds_login, const char *password);
    01451 void tds_set_bulk(TDSLOGIN * tds_login, TDS_TINYINT enabled);
    01452 void tds_set_user(TDSLOGIN * tds_login, const char *username);
    01453 void tds_set_app(TDSLOGIN * tds_login, const char *application);
    01454 void tds_set_host(TDSLOGIN * tds_login, const char *hostname);
    01455 void tds_set_server_addr(TDSLOGIN * tds_login, const char *server_addr);
    01456 void tds_set_library(TDSLOGIN * tds_login, const char *library);
    01457 void tds_set_server(TDSLOGIN * tds_login, const char *server);
    01458 void tds_set_client_charset(TDSLOGIN * tds_login, const char *charset);
    01459 void tds_set_language(TDSLOGIN * tds_login, const char *language);
    01460 void tds_set_version(TDSLOGIN * tds_login, TDS_TINYINT major_ver, TDS_TINYINT minor_ver);
    01461 void tds_set_capabilities(TDSLOGIN * tds_login, unsigned char *capabilities, int size);
    01462 int tds_connect(TDSSOCKET * tds, TDSCONNECTION * connection);
    01463
    01464 /* query.c */
    01465 int tds_submit_query(TDSSOCKET * tds, const char *query);
    01466 int tds_submit_query_params(TDSSOCKET * tds, const char *query, TDSPARAMINFO * params);
    01467 int tds_submit_queryf(TDSSOCKET * tds, const char *queryf, ...);
    01468 int tds_submit_prepare(TDSSOCKET * tds, const char *query, const char *id, TDSDYNAMIC ** dyn_out, TDSPARAMINFO * params);
    01469 int tds_submit_execdirect(TDSSOCKET * tds, const char *query, TDSPARAMINFO * params);
    01470 int tds_submit_execute(TDSSOCKET * tds, TDSDYNAMIC * dyn);
    01471 int tds_send_cancel(TDSSOCKET * tds);
    01472 const char *tds_next_placeholder(const char *start);
    01473 int tds_count_placeholders(const char *query);
    01474 int tds_submit_unprepare(TDSSOCKET * tds, TDSDYNAMIC * dyn);
    01475 int tds_submit_rpc(TDSSOCKET * tds, const char *rpc_name, TDSPARAMINFO * params);
    01476 int tds_submit_optioncmd(TDSSOCKET * tds, TDS_OPTION_CMD command, TDS_OPTION option, TDS_OPTION_ARG *param, TDS_INT param_size);
    01477 int tds_quote_id(TDSSOCKET * tds, char *buffer, const char *id, int idlen);
    01478 int tds_quote_string(TDSSOCKET * tds, char *buffer, const char *str, int len);
    01479 const char *tds_skip_quoted(const char *s);
    01480
    01481 int tds_cursor_declare(TDSSOCKET * tds, TDSCURSOR * cursor, TDSPARAMINFO *params, int *send);
    01482 int tds_cursor_setrows(TDSSOCKET * tds, TDSCURSOR * cursor, int *send);
    01483 int tds_cursor_open(TDSSOCKET * tds, TDSCURSOR * cursor, TDSPARAMINFO *params, int *send);
    01484 int tds_cursor_fetch(TDSSOCKET * tds, TDSCURSOR * cursor, TDS_CURSOR_FETCH fetch_type, TDS_INT i_row);
    01485 int tds_cursor_close(TDSSOCKET * tds, TDSCURSOR * cursor);
    01486 int tds_cursor_dealloc(TDSSOCKET * tds, TDSCURSOR * cursor);
    01487 int tds_cursor_update(TDSSOCKET * tds, TDSCURSOR * cursor, TDS_CURSOR_OPERATION op, TDS_INT i_row, TDSPARAMINFO * params);
    01488 int tds_cursor_setname(TDSSOCKET * tds, TDSCURSOR * cursor);
    01489
    01490 int tds_multiple_init(TDSSOCKET *tds, TDSMULTIPLE *multiple, TDS_MULTIPLE_TYPE type);
    01491 int tds_multiple_done(TDSSOCKET *tds, TDSMULTIPLE *multiple);
    01492 int tds_multiple_query(TDSSOCKET *tds, TDSMULTIPLE *multiple, const char *query, TDSPARAMINFO * params);
    01493 int tds_multiple_execute(TDSSOCKET *tds, TDSMULTIPLE *multiple, TDSDYNAMIC * dyn);
    01494
    01495 /* token.c */
    01496 int tds_process_cancel(TDSSOCKET * tds);
    01497 void tds_swap_datatype(int coltype, unsigned char *buf);
    01498 void tds_swap_numeric(TDS_NUMERIC *num);
    01499 int tds_get_token_size(int marker);
    01500 int tds_process_login_tokens(TDSSOCKET * tds);
    01501 int tds_process_simple_query(TDSSOCKET * tds);
    01502 int tds5_send_optioncmd(TDSSOCKET * tds, TDS_OPTION_CMD tds_command, TDS_OPTION tds_option, TDS_OPTION_ARG * tds_argument,
    01503                         TDS_INT * tds_argsize);
    01504 int tds_process_tokens(TDSSOCKET * tds, /*@out@*/ TDS_INT * result_type, /*@out@*/ int *done_flags, unsigned flag);
    01505
    01506 /* data.c */
    01507 void tds_set_param_type(TDSSOCKET * tds, TDSCOLUMN * curcol, TDS_SERVER_TYPE type);
    01508 void tds_set_column_type(TDSSOCKET * tds, TDSCOLUMN * curcol, int type);
    01509
    01510
    01511 /* tds_convert.c */
    01512 TDS_INT tds_datecrack(TDS_INT datetype, const void *di, TDSDATEREC * dr);
    01513 int tds_get_conversion_type(int srctype, int colsize);
    01514 extern const char tds_hex_digits[];
    01515
    01516 /* write.c */
    01517 int tds_flush_packet(TDSSOCKET * tds);
    01518 int tds_put_buf(TDSSOCKET * tds, const unsigned char *buf, int dsize, int ssize);
    01519
    01520 /* read.c */
    01521 unsigned char tds_get_byte(TDSSOCKET * tds);
    01522 void tds_unget_byte(TDSSOCKET * tds);
    01523 unsigned char tds_peek(TDSSOCKET * tds);
    01524 TDS_SMALLINT tds_get_smallint(TDSSOCKET * tds);
    01525 TDS_INT tds_get_int(TDSSOCKET * tds);
    01526 TDS_INT8 tds_get_int8(TDSSOCKET * tds);
    01527 int tds_get_string(TDSSOCKET * tds, int string_len, char *dest, size_t dest_size);
    01528 int tds_get_char_data(TDSSOCKET * tds, char *dest, size_t wire_size, TDSCOLUMN * curcol);
    01529 void *tds_get_n(TDSSOCKET * tds, /*@out@*/ /*@null@*/ void *dest, int n);
    01530 int tds_get_size_by_type(int servertype);
    01531
    01532
    01533 /* util.c */
    01534 int tdserror (const TDSCONTEXT * tds_ctx, TDSSOCKET * tds, int msgno, int errnum);
    01535 TDS_STATE tds_set_state(TDSSOCKET * tds, TDS_STATE state);
    01536 void tds_set_parent(TDSSOCKET * tds, void *the_parent);
    01537 void *tds_get_parent(TDSSOCKET * tds);
    01538 int tds_swap_bytes(unsigned char *buf, int bytes);
    01539 int tds_version(TDSSOCKET * tds_socket, char *pversion_string);
    01540 void tdsdump_off(void);
    01541 void tdsdump_on(void);
    01542 int tdsdump_open(const char *filename);
    01543 void tdsdump_close(void);
    01544 void tdsdump_dump_buf(const char* file, unsigned int level_line, const char *msg, const void *buf, int length);
    01545 void tdsdump_log(const char* file, unsigned int level_line, const char *fmt, ...)
    01546 #if defined(__GNUC__) && __GNUC__ >= 2
    01547         __attribute__ ((__format__ (__printf__, 3, 4)))
    01548 #endif
    01549 ;
    01550 extern int tds_debug_flags;
    01551 unsigned int tds_gettime_ms(void);
    01552
    01553 /* net.c */
    01554 int tds_open_socket(TDSSOCKET * tds, const char *ip_addr, unsigned int port, int timeout);
    01555 int tds_close_socket(TDSSOCKET * tds);
    01556 int tds_read_packet(TDSSOCKET * tds);
    01557 int tds_write_packet(TDSSOCKET * tds, unsigned char final);
    01558 int tds7_get_instance_port(const char *ip_addr, const char *instance);
    01559 int tds_ssl_init(TDSSOCKET *tds);
    01560 void tds_ssl_deinit(TDSSOCKET *tds);
    01561
    01562
    01563
    01564 /* vstrbuild.c */
    01565 int tds_vstrbuild(char *buffer, int buflen, int *resultlen, char *text, int textlen, const char *formats, int formatlen,
    01566                   va_list ap);
    01567
    01568 /* numeric.c */
    01569 char *tds_money_to_string(const TDS_MONEY * money, char *s);
    01570 TDS_INT tds_numeric_to_string(const TDS_NUMERIC * numeric, char *s);
    01571 TDS_INT tds_numeric_change_prec_scale(TDS_NUMERIC * numeric, unsigned char new_prec, unsigned char new_scale);
    01572
    01573 /* getmac.c */
    01574 void tds_getmac(int s, unsigned char mac[6]);
    01575
    01576 TDSAUTHENTICATION * tds_ntlm_get_auth(TDSSOCKET * tds);
    01577 TDSAUTHENTICATION * tds_gss_get_auth(TDSSOCKET * tds);
    01578
    01579 #define IS_TDS42(x) (x->major_version==4 && x->minor_version==2)
    01580 #define IS_TDS46(x) (x->major_version==4 && x->minor_version==6)
    01581 #define IS_TDS50(x) (x->major_version==5 && x->minor_version==0)
    01582 #define IS_TDS70(x) (x->major_version==7 && x->minor_version==0)
    01583 #define IS_TDS80(x) (x->major_version==8 && x->minor_version==0)
    01584 #define IS_TDS90(x) (x->major_version==9 && x->minor_version==0)
    01585
    01586 #define IS_TDS7_PLUS(x) ((x)->major_version>=7)
    01587 #define IS_TDS8_PLUS(x) ((x)->major_version>=8)
    01588
    01589 #define IS_TDSDEAD(x) (((x) == NULL) || TDS_IS_SOCKET_INVALID((x)->s))
    01590
    01592 #define TDS_IS_SYBASE(x) (!(x->product_version & 0x80000000u))
    01593
    01594 #define TDS_IS_MSSQL(x) ((x->product_version & 0x80000000u)!=0)
    01595
    01599 #define TDS_MS_VER(maj,min,x) (0x80000000u|((maj)<<24)|((min)<<16)|(x))
    01600
    01601 /* TODO test if not similar to ms one*/
    01603 #define TDS_SYB_VER(maj,min,x) (((maj)<<24)|((min)<<16)|(x)<<8)
    01604
    01605 #ifdef __cplusplus
    01606 #if 0
    01607 {
    01608 #endif
    01609 }
    01610 #endif
    01611
    01612 #endif /* _tds_h_ */