FreeTDS API: include/tds.h Source File

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

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

All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines