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

All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines