FreeTDS API: /home/jklowden/releases/freetds-0.91/include/tds.h Source File

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

- File List
- File Members

# /home/jklowden/releases/freetds-0.91/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) 2010, 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.352.2.4 2011/08/12 16:29:36 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 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
    00048 #pragma GCC visibility push(hidden)
    00049 #endif
    00050
    00051 #ifdef __cplusplus
    00052 extern "C"
    00053 {
    00054 #if 0
    00055 }
    00056 #endif
    00057 #endif
    00058
    00064 typedef struct tds_compiletime_settings
    00065 {
    00066         const char *freetds_version;    /* release version of FreeTDS */
    00067         const char *sysconfdir;         /* location of freetds.conf */
    00068         const char *last_update;        /* latest software_version date among the modules */
    00069         int msdblib;            /* for MS style dblib */
    00070         int sybase_compat;      /* enable increased Open Client binary compatibility */
    00071         int threadsafe;         /* compile for thread safety default=no */
    00072         int libiconv;           /* search for libiconv in DIR/include and DIR/lib */
    00073         const char *tdsver;     /* TDS protocol version (4.2/4.6/5.0/7.0/8.0) 5.0 */
    00074         int iodbc;              /* build odbc driver against iODBC in DIR */
    00075         int unixodbc;           /* build odbc driver against unixODBC in DIR */
    00076
    00077 } TDS_COMPILETIME_SETTINGS;
    00078
    00079 typedef struct tds_dstr {
    00080         char *dstr_s;
    00081         size_t dstr_size;
    00082 } DSTR;
    00083
    00099 /*
    00100  * All references to data that touch the wire should use the following typedefs.
    00101  *
    00102  * If you have problems on 64-bit machines and the code is
    00103  * using a native datatype, please change it to use
    00104  * these. (In the TDS layer only, the API layers have their
    00105  * own typedefs which equate to these).
    00106  */
    00107 typedef char TDS_CHAR;                                  /*  8-bit char     */
    00108 typedef unsigned char TDS_UCHAR;                        /*  8-bit uchar    */
    00109 typedef unsigned char TDS_TINYINT;                      /*  8-bit unsigned */
    00110 typedef tds_sysdep_int16_type TDS_SMALLINT;             /* 16-bit int      */
    00111 typedef unsigned tds_sysdep_int16_type TDS_USMALLINT;   /* 16-bit unsigned */
    00112 typedef tds_sysdep_int32_type TDS_INT;                  /* 32-bit int      */
    00113 typedef unsigned tds_sysdep_int32_type TDS_UINT;        /* 32-bit unsigned */
    00114 typedef tds_sysdep_real32_type TDS_REAL;                /* 32-bit real     */
    00115 typedef tds_sysdep_real64_type TDS_FLOAT;               /* 64-bit real     */
    00116 typedef tds_sysdep_int64_type TDS_INT8;                 /* 64-bit integer  */
    00117 typedef unsigned tds_sysdep_int64_type TDS_UINT8;       /* 64-bit unsigned */
    00118 typedef tds_sysdep_intptr_type TDS_INTPTR;
    00119
    00120 typedef struct tdsnumeric
    00121 {
    00122         unsigned char precision;
    00123         unsigned char scale;
    00124         unsigned char array[33];
    00125 } TDS_NUMERIC;
    00126
    00127 typedef struct tdsoldmoney
    00128 {
    00129         TDS_INT mnyhigh;
    00130         TDS_UINT mnylow;
    00131 } TDS_OLD_MONEY;
    00132
    00133 typedef union tdsmoney
    00134 {
    00135         TDS_OLD_MONEY tdsoldmoney;
    00136         TDS_INT8 mny;
    00137 } TDS_MONEY;
    00138
    00139 typedef struct tdsmoney4
    00140 {
    00141         TDS_INT mny4;
    00142 } TDS_MONEY4;
    00143
    00144 typedef struct tdsdatetime
    00145 {
    00146         TDS_INT dtdays;
    00147         TDS_INT dttime;
    00148 } TDS_DATETIME;
    00149
    00150 typedef struct tdsdatetime4
    00151 {
    00152         TDS_USMALLINT days;
    00153         TDS_USMALLINT minutes;
    00154 } TDS_DATETIME4;
    00155
    00156 typedef struct tdsvarbinary
    00157 {
    00158         TDS_SMALLINT len;
    00159         TDS_CHAR array[256];
    00160 } TDS_VARBINARY;
    00161 typedef struct tdsvarchar
    00162 {
    00163         TDS_SMALLINT len;
    00164         TDS_CHAR array[256];
    00165 } TDS_VARCHAR;
    00166
    00167 typedef struct tdsunique
    00168 {
    00169         TDS_UINT Data1;
    00170         TDS_USMALLINT Data2;
    00171         TDS_USMALLINT Data3;
    00172         TDS_UCHAR Data4[8];
    00173 } TDS_UNIQUE;
    00174
    00176 typedef struct tdsdaterec
    00177 {
    00178         TDS_INT year;
    00179         TDS_INT quarter;
    00180         TDS_INT month;
    00181         TDS_INT day;
    00182         TDS_INT dayofyear;
    00183         TDS_INT week;
    00184         TDS_INT weekday;
    00185         TDS_INT hour;
    00186         TDS_INT minute;
    00187         TDS_INT second;
    00188         TDS_INT millisecond;
    00189         TDS_INT tzone;
    00190 } TDSDATEREC;
    00191
    00197 extern const int tds_numeric_bytes_per_prec[];
    00198
    00199 #define TDS_SUCCEED          1
    00200 #define TDS_FAIL             0
    00201 #define TDS_NO_MORE_RESULTS  2
    00202 #define TDS_CANCELLED        3
    00203
    00204 #define TDS_INT_CONTINUE 1
    00205 #define TDS_INT_CANCEL 2
    00206 #define TDS_INT_TIMEOUT 3
    00207
    00208
    00209 #define TDS_NO_COUNT         -1
    00210
    00211 #define TDS_ROW_RESULT        4040
    00212 #define TDS_PARAM_RESULT      4042
    00213 #define TDS_STATUS_RESULT     4043
    00214 #define TDS_MSG_RESULT        4044
    00215 #define TDS_COMPUTE_RESULT    4045
    00216 #define TDS_CMD_DONE          4046
    00217 #define TDS_CMD_SUCCEED       4047
    00218 #define TDS_CMD_FAIL          4048
    00219 #define TDS_ROWFMT_RESULT     4049
    00220 #define TDS_COMPUTEFMT_RESULT 4050
    00221 #define TDS_DESCRIBE_RESULT   4051
    00222 #define TDS_DONE_RESULT       4052
    00223 #define TDS_DONEPROC_RESULT   4053
    00224 #define TDS_DONEINPROC_RESULT 4054
    00225 #define TDS_OTHERS_RESULT     4055
    00226
    00227 enum tds_token_results
    00228 {
    00229         TDS_TOKEN_RES_OTHERS,
    00230         TDS_TOKEN_RES_ROWFMT,
    00231         TDS_TOKEN_RES_COMPUTEFMT,
    00232         TDS_TOKEN_RES_PARAMFMT,
    00233         TDS_TOKEN_RES_DONE,
    00234         TDS_TOKEN_RES_ROW,
    00235         TDS_TOKEN_RES_COMPUTE,
    00236         TDS_TOKEN_RES_PROC,
    00237         TDS_TOKEN_RES_MSG
    00238 };
    00239
    00240 #define TDS_TOKEN_FLAG(flag) TDS_RETURN_##flag = (1 << (TDS_TOKEN_RES_##flag*2)), TDS_STOPAT_##flag = (2 << (TDS_TOKEN_RES_##flag*2))
    00241
    00242 enum tds_token_flags
    00243 {
    00244         TDS_HANDLE_ALL = 0,
    00245         TDS_TOKEN_FLAG(OTHERS),
    00246         TDS_TOKEN_FLAG(ROWFMT),
    00247         TDS_TOKEN_FLAG(COMPUTEFMT),
    00248         TDS_TOKEN_FLAG(PARAMFMT),
    00249         TDS_TOKEN_FLAG(DONE),
    00250         TDS_TOKEN_FLAG(ROW),
    00251         TDS_TOKEN_FLAG(COMPUTE),
    00252         TDS_TOKEN_FLAG(PROC),
    00253         TDS_TOKEN_FLAG(MSG),
    00254         TDS_TOKEN_RESULTS = TDS_RETURN_ROWFMT|TDS_RETURN_COMPUTEFMT|TDS_RETURN_DONE|TDS_STOPAT_ROW|TDS_STOPAT_COMPUTE|TDS_RETURN_PROC,
    00255         TDS_TOKEN_TRAILING = TDS_STOPAT_ROWFMT|TDS_STOPAT_COMPUTEFMT|TDS_STOPAT_ROW|TDS_STOPAT_COMPUTE|TDS_STOPAT_MSG|TDS_STOPAT_OTHERS
    00256 };
    00257
    00261 enum tds_end
    00262 {
    00263           TDS_DONE_FINAL        = 0x00
    00264         , TDS_DONE_MORE_RESULTS = 0x01
    00265         , TDS_DONE_ERROR        = 0x02
    00266         , TDS_DONE_INXACT       = 0x04
    00267         , TDS_DONE_PROC         = 0x08
    00268         , TDS_DONE_COUNT        = 0x10
    00269         , TDS_DONE_CANCELLED    = 0x20
    00270         , TDS_DONE_EVENT        = 0x40  /*   part of an event notification. */
    00271         , TDS_DONE_SRVERROR     = 0x100
    00273         /* after the above flags, a TDS_DONE packet has a field describing the state of the transaction */
    00274         , TDS_DONE_NO_TRAN      = 0     /* No transaction in effect */
    00275         , TDS_DONE_TRAN_SUCCEED = 1     /* Transaction completed successfully */
    00276         , TDS_DONE_TRAN_PROGRESS= 2     /* Transaction in progress */
    00277         , TDS_DONE_STMT_ABORT   = 3     /* A statement aborted */
    00278         , TDS_DONE_TRAN_ABORT   = 4     /* Transaction aborted */
    00279 };
    00280
    00281
    00282 /*
    00283  * TDSERRNO is emitted by libtds to the client library's error handler
    00284  * (which may in turn call the client's error handler).
    00285  * These match the db-lib msgno, because the same values have the same meaning
    00286  * in db-lib and ODBC.  ct-lib maps them to ct-lib numbers (todo).
    00287  */
    00288 typedef enum {  TDSEOK    = TDS_SUCCEED,
    00289                 TDSEVERDOWN    =  100,
    00290                 TDSEICONVIU    = 2400,
    00291                 TDSEICONVAVAIL = 2401,
    00292                 TDSEICONVO     = 2402,
    00293                 TDSEICONVI     = 2403,
    00294                 TDSEICONV2BIG  = 2404,
    00295                 TDSEPORTINSTANCE        = 2500,
    00296                 TDSESYNC = 20001,
    00297                 TDSEFCON = 20002,
    00298                 TDSETIME = 20003,
    00299                 TDSEREAD = 20004,
    00300                 TDSEWRIT = 20006,
    00301                 TDSESOCK = 20008,
    00302                 TDSECONN = 20009,
    00303                 TDSEMEM  = 20010,
    00304                 TDSEINTF = 20012,       /* Server name not found in interface file */
    00305                 TDSEUHST = 20013,       /* Unknown host machine name. */
    00306                 TDSEPWD  = 20014,
    00307                 TDSESEOF = 20017,
    00308                 TDSERPND = 20019,
    00309                 TDSEBTOK = 20020,
    00310                 TDSEOOB  = 20022,
    00311                 TDSECLOS = 20056,
    00312                 TDSEUSCT = 20058,
    00313                 TDSEUTDS = 20146,
    00314                 TDSEEUNR = 20185,
    00315                 TDSECAP  = 20203,
    00316                 TDSENEG  = 20210,
    00317                 TDSEUMSG = 20212,
    00318                 TDSECAPTYP  = 20213,
    00319                 TDSEBPROBADTYP = 20250,
    00320                 TDSECLOSEIN = 20292
    00321 } TDSERRNO;
    00322
    00323 #define TDS5_PARAMFMT2_TOKEN       32   /* 0x20 */
    00324 #define TDS_LANGUAGE_TOKEN         33   /* 0x21    TDS 5.0 only              */
    00325 #define TDS_ORDERBY2_TOKEN         34   /* 0x22 */
    00326 #define TDS_ROWFMT2_TOKEN          97   /* 0x61    TDS 5.0 only              */
    00327 #define TDS_LOGOUT_TOKEN          113   /* 0x71    TDS 5.0 only? ct_close()  */
    00328 #define TDS_RETURNSTATUS_TOKEN    121   /* 0x79                              */
    00329 #define TDS_PROCID_TOKEN          124   /* 0x7C    TDS 4.2 only - TDS_PROCID */
    00330 #define TDS7_RESULT_TOKEN         129   /* 0x81    TDS 7.0 only              */
    00331 #define TDS7_COMPUTE_RESULT_TOKEN 136   /* 0x88    TDS 7.0 only              */
    00332 #define TDS_COLNAME_TOKEN         160   /* 0xA0    TDS 4.2 only              */
    00333 #define TDS_COLFMT_TOKEN          161   /* 0xA1    TDS 4.2 only - TDS_COLFMT */
    00334 #define TDS_DYNAMIC2_TOKEN        163   /* 0xA3 */
    00335 #define TDS_TABNAME_TOKEN         164   /* 0xA4 */
    00336 #define TDS_COLINFO_TOKEN         165   /* 0xA5 */
    00337 #define TDS_OPTIONCMD_TOKEN       166   /* 0xA6 */
    00338 #define TDS_COMPUTE_NAMES_TOKEN   167   /* 0xA7 */
    00339 #define TDS_COMPUTE_RESULT_TOKEN  168   /* 0xA8 */
    00340 #define TDS_ORDERBY_TOKEN         169   /* 0xA9    TDS_ORDER                 */
    00341 #define TDS_ERROR_TOKEN           170   /* 0xAA                              */
    00342 #define TDS_INFO_TOKEN            171   /* 0xAB                              */
    00343 #define TDS_PARAM_TOKEN           172   /* 0xAC    RETURNVALUE?              */
    00344 #define TDS_LOGINACK_TOKEN        173   /* 0xAD                              */
    00345 #define TDS_CONTROL_TOKEN         174   /* 0xAE    TDS_CONTROL               */
    00346 #define TDS_ROW_TOKEN             209   /* 0xD1                              */
    00347 #define TDS_NBC_ROW_TOKEN         210   /* 0xD2    as of TDS 7.3.B           */ /* not implemented */
    00348 #define TDS_CMP_ROW_TOKEN         211   /* 0xD3                              */
    00349 #define TDS5_PARAMS_TOKEN         215   /* 0xD7    TDS 5.0 only              */
    00350 #define TDS_CAPABILITY_TOKEN      226   /* 0xE2                              */
    00351 #define TDS_ENVCHANGE_TOKEN       227   /* 0xE3                              */
    00352 #define TDS_EED_TOKEN             229   /* 0xE5                              */
    00353 #define TDS_DBRPC_TOKEN           230   /* 0xE6                              */
    00354 #define TDS5_DYNAMIC_TOKEN        231   /* 0xE7    TDS 5.0 only              */
    00355 #define TDS5_PARAMFMT_TOKEN       236   /* 0xEC    TDS 5.0 only              */
    00356 #define TDS_AUTH_TOKEN            237   /* 0xED    TDS 7.0 only              */
    00357 #define TDS_RESULT_TOKEN          238   /* 0xEE                              */
    00358 #define TDS_DONE_TOKEN            253   /* 0xFD    TDS_DONE                  */
    00359 #define TDS_DONEPROC_TOKEN        254   /* 0xFE    TDS_DONEPROC              */
    00360 #define TDS_DONEINPROC_TOKEN      255   /* 0xFF    TDS_DONEINPROC            */
    00361
    00362 /* CURSOR support: TDS 5.0 only*/
    00363 #define TDS_CURCLOSE_TOKEN        128  /* 0x80    TDS 5.0 only              */
    00364 #define TDS_CURDELETE_TOKEN       129  /* 0x81    TDS 5.0 only              */
    00365 #define TDS_CURFETCH_TOKEN        130  /* 0x82    TDS 5.0 only              */
    00366 #define TDS_CURINFO_TOKEN         131  /* 0x83    TDS 5.0 only              */
    00367 #define TDS_CUROPEN_TOKEN         132  /* 0x84    TDS 5.0 only              */
    00368 #define TDS_CURDECLARE_TOKEN      134  /* 0x86    TDS 5.0 only              */
    00369
    00370 enum {
    00371         TDS_CUR_ISTAT_UNUSED    = 0x00,
    00372         TDS_CUR_ISTAT_DECLARED  = 0x01,
    00373         TDS_CUR_ISTAT_OPEN      = 0x02,
    00374         TDS_CUR_ISTAT_CLOSED    = 0x04,
    00375         TDS_CUR_ISTAT_RDONLY    = 0x08,
    00376         TDS_CUR_ISTAT_UPDATABLE = 0x10,
    00377         TDS_CUR_ISTAT_ROWCNT    = 0x20,
    00378         TDS_CUR_ISTAT_DEALLOC   = 0x40
    00379 };
    00380
    00381 /* environment type field */
    00382 #define TDS_ENV_DATABASE        1
    00383 #define TDS_ENV_LANG            2
    00384 #define TDS_ENV_CHARSET         3
    00385 #define TDS_ENV_PACKSIZE        4
    00386 #define TDS_ENV_LCID            5
    00387 #define TDS_ENV_SQLCOLLATION    7
    00388 #define TDS_ENV_BEGINTRANS      8
    00389 #define TDS_ENV_COMMITTRANS     9
    00390 #define TDS_ENV_ROLLBACKTRANS   10
    00391
    00392 /* string types */
    00393 #define TDS_NULLTERM -9
    00394
    00395 /* Microsoft internal stored procedure id's */
    00396
    00397 #define TDS_SP_CURSOR           1
    00398 #define TDS_SP_CURSOROPEN       2
    00399 #define TDS_SP_CURSORPREPARE    3
    00400 #define TDS_SP_CURSOREXECUTE    4
    00401 #define TDS_SP_CURSORPREPEXEC   5
    00402 #define TDS_SP_CURSORUNPREPARE  6
    00403 #define TDS_SP_CURSORFETCH      7
    00404 #define TDS_SP_CURSOROPTION     8
    00405 #define TDS_SP_CURSORCLOSE      9
    00406 #define TDS_SP_EXECUTESQL      10
    00407 #define TDS_SP_PREPARE         11
    00408 #define TDS_SP_EXECUTE         12
    00409 #define TDS_SP_PREPEXEC        13
    00410 #define TDS_SP_PREPEXECRPC     14
    00411 #define TDS_SP_UNPREPARE       15
    00412 /*
    00413  * <rant> Sybase does an awful job of this stuff, non null ints of size 1 2
    00414  * and 4 have there own codes but nullable ints are lumped into INTN
    00415  * sheesh! </rant>
    00416  */
    00417 typedef enum
    00418 {
    00419         SYBCHAR = 47,           /* 0x2F */
    00420 #define SYBCHAR SYBCHAR
    00421         SYBVARCHAR = 39,        /* 0x27 */
    00422 #define SYBVARCHAR      SYBVARCHAR
    00423         SYBINTN = 38,           /* 0x26 */
    00424 #define SYBINTN SYBINTN
    00425         SYBINT1 = 48,           /* 0x30 */
    00426 #define SYBINT1 SYBINT1
    00427         SYBINT2 = 52,           /* 0x34 */
    00428 #define SYBINT2 SYBINT2
    00429         SYBINT4 = 56,           /* 0x38 */
    00430 #define SYBINT4 SYBINT4
    00431         SYBFLT8 = 62,           /* 0x3E */
    00432 #define SYBFLT8 SYBFLT8
    00433         SYBDATETIME = 61,       /* 0x3D */
    00434 #define SYBDATETIME     SYBDATETIME
    00435         SYBBIT = 50,            /* 0x32 */
    00436 #define SYBBIT  SYBBIT
    00437         SYBTEXT = 35,           /* 0x23 */
    00438 #define SYBTEXT SYBTEXT
    00439         SYBNTEXT = 99,          /* 0x63 */
    00440 #define SYBNTEXT        SYBNTEXT
    00441         SYBIMAGE = 34,          /* 0x22 */
    00442 #define SYBIMAGE        SYBIMAGE
    00443         SYBMONEY4 = 122,        /* 0x7A */
    00444 #define SYBMONEY4       SYBMONEY4
    00445         SYBMONEY = 60,          /* 0x3C */
    00446 #define SYBMONEY        SYBMONEY
    00447         SYBDATETIME4 = 58,      /* 0x3A */
    00448 #define SYBDATETIME4    SYBDATETIME4
    00449         SYBREAL = 59,           /* 0x3B */
    00450 #define SYBREAL SYBREAL
    00451         SYBBINARY = 45,         /* 0x2D */
    00452 #define SYBBINARY       SYBBINARY
    00453         SYBVOID = 31,           /* 0x1F */
    00454 #define SYBVOID SYBVOID
    00455         SYBVARBINARY = 37,      /* 0x25 */
    00456 #define SYBVARBINARY    SYBVARBINARY
    00457         SYBBITN = 104,          /* 0x68 */
    00458 #define SYBBITN SYBBITN
    00459         SYBNUMERIC = 108,       /* 0x6C */
    00460 #define SYBNUMERIC      SYBNUMERIC
    00461         SYBDECIMAL = 106,       /* 0x6A */
    00462 #define SYBDECIMAL      SYBDECIMAL
    00463         SYBFLTN = 109,          /* 0x6D */
    00464 #define SYBFLTN SYBFLTN
    00465         SYBMONEYN = 110,        /* 0x6E */
    00466 #define SYBMONEYN       SYBMONEYN
    00467         SYBDATETIMN = 111,      /* 0x6F */
    00468 #define SYBDATETIMN     SYBDATETIMN
    00469
    00470 /*
    00471  * MS only types
    00472  */
    00473         SYBNVARCHAR = 103,      /* 0x67 */
    00474 #define SYBNVARCHAR     SYBNVARCHAR
    00475         SYBINT8 = 127,          /* 0x7F */
    00476 #define SYBINT8 SYBINT8
    00477         XSYBCHAR = 175,         /* 0xAF */
    00478 #define XSYBCHAR        XSYBCHAR
    00479         XSYBVARCHAR = 167,      /* 0xA7 */
    00480 #define XSYBVARCHAR     XSYBVARCHAR
    00481         XSYBNVARCHAR = 231,     /* 0xE7 */
    00482 #define XSYBNVARCHAR    XSYBNVARCHAR
    00483         XSYBNCHAR = 239,        /* 0xEF */
    00484 #define XSYBNCHAR       XSYBNCHAR
    00485         XSYBVARBINARY = 165,    /* 0xA5 */
    00486 #define XSYBVARBINARY   XSYBVARBINARY
    00487         XSYBBINARY = 173,       /* 0xAD */
    00488 #define XSYBBINARY      XSYBBINARY
    00489         SYBUNIQUE = 36,         /* 0x24 */
    00490 #define SYBUNIQUE       SYBUNIQUE
    00491         SYBVARIANT = 98,        /* 0x62 */
    00492 #define SYBVARIANT      SYBVARIANT
    00493         SYBMSUDT = 240,         /* 0xF0 */
    00494 #define SYBMSUDT SYBMSUDT
    00495         SYBMSXML = 241,         /* 0xF1 */
    00496 #define SYBMSXML SYBMSXML
    00497
    00498 /*
    00499  * Sybase only types
    00500  */
    00501         SYBLONGBINARY = 225,    /* 0xE1 */
    00502 #define SYBLONGBINARY   SYBLONGBINARY
    00503         SYBUINT1 = 64,          /* 0x40 */
    00504 #define SYBUINT1        SYBUINT1
    00505         SYBUINT2 = 65,          /* 0x41 */
    00506 #define SYBUINT2        SYBUINT2
    00507         SYBUINT4 = 66,          /* 0x42 */
    00508 #define SYBUINT4        SYBUINT4
    00509         SYBUINT8 = 67,          /* 0x43 */
    00510 #define SYBUINT8        SYBUINT8
    00511         SYBBLOB = 36,           /* 0x24 */
    00512 #define SYBBLOB         SYBBLOB
    00513         SYBBOUNDARY = 104,      /* 0x68 */
    00514 #define SYBBOUNDARY     SYBBOUNDARY
    00515         SYBDATE = 49,           /* 0x31 */
    00516 #define SYBDATE         SYBDATE
    00517         SYBDATEN = 123,         /* 0x7B */
    00518 #define SYBDATEN        SYBDATEN
    00519         SYB5INT8 = 191,         /* 0xBF */
    00520 #define SYB5INT8                SYB5INT8
    00521         SYBINTERVAL = 46,       /* 0x2E */
    00522 #define SYBINTERVAL     SYBINTERVAL
    00523         SYBLONGCHAR = 175,      /* 0xAF */
    00524 #define SYBLONGCHAR     SYBLONGCHAR
    00525         SYBSENSITIVITY = 103,   /* 0x67 */
    00526 #define SYBSENSITIVITY  SYBSENSITIVITY
    00527         SYBSINT1 = 176,         /* 0xB0 */
    00528 #define SYBSINT1        SYBSINT1
    00529         SYBTIME = 51,           /* 0x33 */
    00530 #define SYBTIME         SYBTIME
    00531         SYBTIMEN = 147,         /* 0x93 */
    00532 #define SYBTIMEN        SYBTIMEN
    00533         SYBUINTN = 68,          /* 0x44 */
    00534 #define SYBUINTN        SYBUINTN
    00535         SYBUNITEXT = 174,       /* 0xAE */
    00536 #define SYBUNITEXT      SYBUNITEXT
    00537         SYBXML = 163,           /* 0xA3 */
    00538 #define SYBXML          SYBXML
    00539
    00540 } TDS_SERVER_TYPE;
    00541
    00542
    00543 typedef enum
    00544 {
    00545         USER_UNICHAR_TYPE = 34,         /* 0x22 */
    00546         USER_UNIVARCHAR_TYPE = 35       /* 0x23 */
    00547 } TDS_USER_TYPE;
    00548
    00549 #define SYBAOPCNT  0x4b
    00550 #define SYBAOPCNTU 0x4c
    00551 #define SYBAOPSUM  0x4d
    00552 #define SYBAOPSUMU 0x4e
    00553 #define SYBAOPAVG  0x4f
    00554 #define SYBAOPAVGU 0x50
    00555 #define SYBAOPMIN  0x51
    00556 #define SYBAOPMAX  0x52
    00557
    00558 /* mssql2k compute operator */
    00559 #define SYBAOPCNT_BIG           0x09
    00560 #define SYBAOPSTDEV             0x30
    00561 #define SYBAOPSTDEVP            0x31
    00562 #define SYBAOPVAR               0x32
    00563 #define SYBAOPVARP              0x33
    00564 #define SYBAOPCHECKSUM_AGG      0x72
    00565
    00566
    00570 typedef enum
    00571 {
    00572           TDS_OPT_SET = 1       /* Set an option. */
    00573         , TDS_OPT_DEFAULT = 2   /* Set option to its default value. */
    00574         , TDS_OPT_LIST = 3      /* Request current setting of a specific option. */
    00575         , TDS_OPT_INFO = 4      /* Report current setting of a specific option. */
    00576 } TDS_OPTION_CMD;
    00577
    00578 typedef enum
    00579 {
    00580           TDS_OPT_DATEFIRST = 1         /* 0x01 */
    00581         , TDS_OPT_TEXTSIZE = 2          /* 0x02 */
    00582         , TDS_OPT_STAT_TIME = 3         /* 0x03 */
    00583         , TDS_OPT_STAT_IO = 4           /* 0x04 */
    00584         , TDS_OPT_ROWCOUNT = 5          /* 0x05 */
    00585         , TDS_OPT_NATLANG = 6           /* 0x06 */
    00586         , TDS_OPT_DATEFORMAT = 7        /* 0x07 */
    00587         , TDS_OPT_ISOLATION = 8         /* 0x08 */
    00588         , TDS_OPT_AUTHON = 9            /* 0x09 */
    00589         , TDS_OPT_CHARSET = 10          /* 0x0a */
    00590         , TDS_OPT_SHOWPLAN = 13         /* 0x0d */
    00591         , TDS_OPT_NOEXEC = 14           /* 0x0e */
    00592         , TDS_OPT_ARITHIGNOREON = 15    /* 0x0f */
    00593         , TDS_OPT_ARITHABORTON = 17     /* 0x11 */
    00594         , TDS_OPT_PARSEONLY = 18        /* 0x12 */
    00595         , TDS_OPT_GETDATA = 20          /* 0x14 */
    00596         , TDS_OPT_NOCOUNT = 21          /* 0x15 */
    00597         , TDS_OPT_FORCEPLAN = 23        /* 0x17 */
    00598         , TDS_OPT_FORMATONLY = 24       /* 0x18 */
    00599         , TDS_OPT_CHAINXACTS = 25       /* 0x19 */
    00600         , TDS_OPT_CURCLOSEONXACT = 26   /* 0x1a */
    00601         , TDS_OPT_FIPSFLAG = 27         /* 0x1b */
    00602         , TDS_OPT_RESTREES = 28         /* 0x1c */
    00603         , TDS_OPT_IDENTITYON = 29       /* 0x1d */
    00604         , TDS_OPT_CURREAD = 30          /* 0x1e */
    00605         , TDS_OPT_CURWRITE = 31         /* 0x1f */
    00606         , TDS_OPT_IDENTITYOFF = 32      /* 0x20 */
    00607         , TDS_OPT_AUTHOFF = 33          /* 0x21 */
    00608         , TDS_OPT_ANSINULL = 34         /* 0x22 */
    00609         , TDS_OPT_QUOTED_IDENT = 35     /* 0x23 */
    00610         , TDS_OPT_ARITHIGNOREOFF = 36   /* 0x24 */
    00611         , TDS_OPT_ARITHABORTOFF = 37    /* 0x25 */
    00612         , TDS_OPT_TRUNCABORT = 38       /* 0x26 */
    00613 } TDS_OPTION;
    00614
    00615 typedef union tds_option_arg
    00616 {
    00617         TDS_TINYINT ti;
    00618         TDS_INT i;
    00619         TDS_CHAR *c;
    00620 } TDS_OPTION_ARG;
    00621
    00622 enum {
    00623         TDS_OPT_ARITHOVERFLOW = 0x01,
    00624         TDS_OPT_NUMERICTRUNC = 0x02
    00625 };
    00626
    00627 enum TDS_OPT_DATEFIRST_CHOICE
    00628 {
    00629         TDS_OPT_MONDAY = 1, TDS_OPT_TUESDAY = 2, TDS_OPT_WEDNESDAY = 3, TDS_OPT_THURSDAY = 4, TDS_OPT_FRIDAY = 5, TDS_OPT_SATURDAY =
    00630                 6, TDS_OPT_SUNDAY = 7
    00631 };
    00632
    00633 enum TDS_OPT_DATEFORMAT_CHOICE
    00634 {
    00635         TDS_OPT_FMTMDY = 1, TDS_OPT_FMTDMY = 2, TDS_OPT_FMTYMD = 3, TDS_OPT_FMTYDM = 4, TDS_OPT_FMTMYD = 5, TDS_OPT_FMTDYM = 6
    00636 };
    00637 enum TDS_OPT_ISOLATION_CHOICE
    00638 {
    00639         TDS_OPT_LEVEL1 = 1, TDS_OPT_LEVEL3 = 3
    00640 };
    00641
    00642 typedef enum tds_packet_type
    00643 {
    00644         TDS_QUERY = 1,
    00645         TDS_LOGIN = 2,
    00646         TDS_RPC = 3,
    00647         TDS_REPLY = 4,
    00648         TDS_CANCEL = 6,
    00649         TDS_BULK = 7,
    00650         TDS_NORMAL = 15,
    00651         TDS7_LOGIN = 16,
    00652         TDS7_AUTH = 17,
    00653         TDS8_PRELOGIN = 18
    00654 } TDS_PACKET_TYPE;
    00655
    00656 typedef enum tds_encryption_level {
    00657         TDS_ENCRYPTION_OFF, TDS_ENCRYPTION_REQUEST, TDS_ENCRYPTION_REQUIRE
    00658 } TDS_ENCRYPTION_LEVEL;
    00659
    00660 #define TDS_ZERO_FREE(x) do {free((x)); (x) = NULL;} while(0)
    00661 #define TDS_VECTOR_SIZE(x) (sizeof(x)/sizeof(x[0]))
    00662
    00663 #if defined(__GNUC__) && __GNUC__ >= 3
    00664 # define TDS_LIKELY(x)  __builtin_expect(!!(x), 1)
    00665 # define TDS_UNLIKELY(x)        __builtin_expect(!!(x), 0)
    00666 #else
    00667 # define TDS_LIKELY(x)  (x)
    00668 # define TDS_UNLIKELY(x)        (x)
    00669 #endif
    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 #define is_blob_col(x) ((x)->column_varint_size > 2)
    00747 /* large type means it has a two byte size field */
    00748 /* define is_large_type(x) (x>128) */
    00749 #define is_numeric_type(x) (x==SYBNUMERIC || x==SYBDECIMAL)
    00750 #define is_unicode_type(x) (x==XSYBNVARCHAR || x==XSYBNCHAR || x==SYBNTEXT || x==SYBMSXML)
    00751 #define is_collate_type(x) (x==XSYBVARCHAR || x==XSYBCHAR || x==SYBTEXT || x==XSYBNVARCHAR || x==XSYBNCHAR || x==SYBNTEXT)
    00752 #define is_ascii_type(x) ( x==XSYBCHAR || x==XSYBVARCHAR || x==SYBTEXT || x==SYBCHAR || x==SYBVARCHAR)
    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_DEFAULT_VERSION     0x402
    00769 #define TDS_DEF_PORT            1433
    00770 #elif TDS46
    00771 #define TDS_DEFAULT_VERSION     0x406
    00772 #define TDS_DEF_PORT            4000
    00773 #elif TDS70
    00774 #define TDS_DEFAULT_VERSION     0x700
    00775 #define TDS_DEF_PORT            1433
    00776 #elif TDS71
    00777 #define TDS_DEFAULT_VERSION     0x701
    00778 #define TDS_DEF_PORT            1433
    00779 #elif TDS72
    00780 #define TDS_DEFAULT_VERSION     0x702
    00781 #define TDS_DEF_PORT            1433
    00782 #else
    00783 #define TDS_DEFAULT_VERSION     0x500
    00784 #define TDS_DEF_PORT            4000
    00785 #endif
    00786
    00787 /* normalized strings from freetds.conf file */
    00788 #define TDS_STR_VERSION  "tds version"
    00789 #define TDS_STR_BLKSZ    "initial block size"
    00790 #define TDS_STR_SWAPDT   "swap broken dates"
    00791 #define TDS_STR_DUMPFILE "dump file"
    00792 #define TDS_STR_DEBUGLVL "debug level"
    00793 #define TDS_STR_DEBUGFLAGS "debug flags"
    00794 #define TDS_STR_TIMEOUT  "timeout"
    00795 #define TDS_STR_QUERY_TIMEOUT  "query timeout"
    00796 #define TDS_STR_CONNTIMEOUT "connect timeout"
    00797 #define TDS_STR_HOSTNAME "hostname"
    00798 #define TDS_STR_HOST     "host"
    00799 #define TDS_STR_PORT     "port"
    00800 #define TDS_STR_TEXTSZ   "text size"
    00801 /* for big endian hosts */
    00802 #define TDS_STR_EMUL_LE "emulate little endian"
    00803 #define TDS_STR_CHARSET "charset"
    00804 #define TDS_STR_CLCHARSET       "client charset"
    00805 #define TDS_STR_LANGUAGE        "language"
    00806 #define TDS_STR_APPENDMODE      "dump file append"
    00807 #define TDS_STR_DATEFMT "date format"
    00808 #define TDS_STR_INSTANCE "instance"
    00809 #define TDS_STR_ASA_DATABASE    "asa database"
    00810 #define TDS_STR_ENCRYPTION       "encryption"
    00811 #define TDS_STR_USENTLMV2       "use ntlmv2"
    00812 /* conf values */
    00813 #define TDS_STR_ENCRYPTION_OFF   "off"
    00814 #define TDS_STR_ENCRYPTION_REQUEST "request"
    00815 #define TDS_STR_ENCRYPTION_REQUIRE "require"
    00816 /* Defines to enable optional GSSAPI delegation */
    00817 #define TDS_GSSAPI_DELEGATION "enable gssapi delegation"
    00818 /* Kerberos realm name */
    00819 #define TDS_STR_REALM   "realm"
    00820
    00821
    00822 /* TODO do a better check for alignment than this */
    00823 typedef union
    00824 {
    00825         void *p;
    00826         int i;
    00827 } tds_align_struct;
    00828
    00829 #define TDS_ALIGN_SIZE sizeof(tds_align_struct)
    00830
    00831 #define TDS_MAX_LOGIN_STR_SZ 30
    00832 typedef struct tds_login
    00833 {
    00834         DSTR server_name;
    00835         int port;
    00836         TDS_USMALLINT tds_version;      /* TDS version */
    00837         int block_size;
    00838         DSTR language;                  /* e.g. us-english */
    00839         DSTR server_charset;            /* e.g. 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 encryption_level;
    00848
    00849         TDS_INT query_timeout;
    00850         unsigned char capabilities[TDS_MAX_CAPABILITY];
    00851         DSTR client_charset;
    00852         DSTR database;
    00853         unsigned int bulk_copy:1;
    00854         unsigned int suppress_language:1;
    00855 } TDSLOGIN;
    00856
    00857 typedef struct tds_connection
    00858 {
    00859         /* first part of structure is the same of login one */
    00860         DSTR server_name;
    00861         int port;
    00862         TDS_USMALLINT tds_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 server_realm_name;
    00870         DSTR app_name;
    00871         DSTR user_name;
    00872         DSTR password;
    00873         DSTR library;
    00874         TDS_TINYINT encryption_level;
    00875
    00876         TDS_INT query_timeout;
    00877         unsigned char capabilities[TDS_MAX_CAPABILITY];
    00878         unsigned char option_flag2;
    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         unsigned int broken_dates:1;
    00888         unsigned int emul_little_endian:1;
    00889         unsigned int bulk_copy:1;
    00890         unsigned int suppress_language:1;
    00891         unsigned int gssapi_use_delegation:1;
    00892         unsigned int use_ntlmv2:1;
    00893 } TDSCONNECTION;
    00894
    00895 typedef struct tds_locale
    00896 {
    00897         char *language;
    00898         char *server_charset;
    00899         char *date_fmt;
    00900 } TDSLOCALE;
    00901
    00906 typedef struct tds_blob
    00907 {
    00908         TDS_CHAR *textvalue;
    00909         TDS_CHAR textptr[16];
    00910         TDS_CHAR timestamp[8];
    00911 } TDSBLOB;
    00912
    00916 typedef struct tds_variant
    00917 {
    00918         /* this MUST have same position and place of textvalue in tds_blob */
    00919         TDS_CHAR *data;
    00920         TDS_INT size;
    00921         TDS_INT data_len;
    00922         TDS_UCHAR type;
    00923         TDS_UCHAR collation[5];
    00924 } TDSVARIANT;
    00925
    00929 typedef struct
    00930 {
    00931         TDS_USMALLINT locale_id;        /* master..syslanguages.lcid */
    00932         TDS_USMALLINT flags;
    00933         TDS_UCHAR charset_id;           /* or zero */
    00934 } TDS8_COLLATION;
    00935
    00936 /* SF stands for "sort flag" */
    00937 #define TDS_SF_BIN                   (TDS_USMALLINT) 0x100
    00938 #define TDS_SF_WIDTH_INSENSITIVE     (TDS_USMALLINT) 0x080
    00939 #define TDS_SF_KATATYPE_INSENSITIVE  (TDS_USMALLINT) 0x040
    00940 #define TDS_SF_ACCENT_SENSITIVE      (TDS_USMALLINT) 0x020
    00941 #define TDS_SF_CASE_INSENSITIVE      (TDS_USMALLINT) 0x010
    00942
    00943 /* UT stands for user type */
    00944 #define TDS_UT_TIMESTAMP             80
    00945
    00946
    00951 typedef struct tds_encoding
    00952 {
    00953         const char *name;
    00954         unsigned char min_bytes_per_char;
    00955         unsigned char max_bytes_per_char;
    00956         unsigned char canonic;
    00957 } TDS_ENCODING;
    00958
    00959 typedef struct tds_bcpcoldata
    00960 {
    00961         TDS_UCHAR *data;
    00962         TDS_INT    datalen;
    00963         TDS_INT    is_null;
    00964 } BCPCOLDATA;
    00965
    00966
    00967 enum
    00968 { TDS_SYSNAME_SIZE = 512 };
    00969
    00973 typedef struct tds_column
    00974 {
    00975         TDS_SMALLINT column_type;
    00980         TDS_INT column_usertype;
    00981         TDS_INT column_flags;
    00982
    00983         TDS_INT column_size;
    00985         TDS_TINYINT column_varint_size;
    00987         TDS_TINYINT column_prec;
    00988         TDS_TINYINT column_scale;
    00990         TDS_SMALLINT column_namelen;
    00991         TDS_SMALLINT table_namelen;
    00992         struct
    00993         {
    00994                 TDS_SMALLINT column_type;
    00995                 TDS_INT column_size;
    00996         } on_server;
    00997
    00998         TDSICONV *char_conv;
    01000         TDS_CHAR table_name[TDS_SYSNAME_SIZE];
    01001         TDS_CHAR column_name[TDS_SYSNAME_SIZE];
    01002         char * table_column_name;
    01003
    01004         unsigned char *column_data;
    01005         void (*column_data_free)(struct tds_column *column);
    01006         unsigned int column_nullable:1;
    01007         unsigned int column_writeable:1;
    01008         unsigned int column_identity:1;
    01009         unsigned int column_key:1;
    01010         unsigned int column_hidden:1;
    01011         unsigned int column_output:1;
    01012         unsigned int column_timestamp:1;
    01013         TDS_UCHAR column_collation[5];
    01014
    01015         /* additional fields flags for compute results */
    01016         TDS_TINYINT column_operator;
    01017         TDS_SMALLINT column_operand;
    01018
    01019         /* FIXME this is data related, not column */
    01021         TDS_INT column_cur_size;
    01022
    01023         /* related to binding or info stored by client libraries */
    01024         /* FIXME find a best place to store these data, some are unused */
    01025         TDS_SMALLINT column_bindtype;
    01026         TDS_SMALLINT column_bindfmt;
    01027         TDS_UINT column_bindlen;
    01028         TDS_SMALLINT *column_nullbind;
    01029         TDS_CHAR *column_varaddr;
    01030         TDS_INT *column_lenbind;
    01031         TDS_INT column_textpos;
    01032         TDS_INT column_text_sqlgetdatapos;
    01033         TDS_CHAR column_text_sqlputdatainfo;
    01034
    01035         BCPCOLDATA *bcp_column_data;
    01044         TDS_INT bcp_prefix_len;
    01045         TDS_INT bcp_term_len;
    01046         TDS_CHAR *bcp_terminator;
    01047 } TDSCOLUMN;
    01048
    01049
    01051 typedef struct tds_result_info
    01052 {
    01053         /* TODO those fields can became a struct */
    01054         TDS_SMALLINT num_cols;
    01055         TDSCOLUMN **columns;
    01056         TDS_INT row_size;
    01057         TDS_INT ref_count;
    01058         unsigned char *current_row;
    01059         void (*row_free)(struct tds_result_info* result, unsigned char *row);
    01060
    01061         TDS_SMALLINT rows_exist;
    01062         /* TODO remove ?? used only in dblib */
    01063         TDS_INT row_count;
    01064         /* TODO remove ?? used only in dblib */
    01065         TDS_TINYINT more_results;
    01066         TDS_SMALLINT computeid;
    01067         TDS_SMALLINT *bycolumns;
    01068         TDS_SMALLINT by_cols;
    01069 } TDSRESULTINFO;
    01070
    01072 typedef enum _TDS_STATE
    01073 {
    01074         TDS_IDLE,
    01075         TDS_QUERYING,
    01076         TDS_PENDING,
    01077         TDS_READING,
    01078         TDS_DEAD
    01079 } TDS_STATE;
    01080
    01081 #define TDS_DBG_LOGIN   __FILE__, ((__LINE__ << 4) | 11)
    01082 #define TDS_DBG_HEADER  __FILE__, ((__LINE__ << 4) | 10)
    01083 #define TDS_DBG_FUNC    __FILE__, ((__LINE__ << 4) |  7)
    01084 #define TDS_DBG_INFO2   __FILE__, ((__LINE__ << 4) |  6)
    01085 #define TDS_DBG_INFO1   __FILE__, ((__LINE__ << 4) |  5)
    01086 #define TDS_DBG_NETWORK __FILE__, ((__LINE__ << 4) |  4)
    01087 #define TDS_DBG_WARN    __FILE__, ((__LINE__ << 4) |  3)
    01088 #define TDS_DBG_ERROR   __FILE__, ((__LINE__ << 4) |  2)
    01089 #define TDS_DBG_SEVERE  __FILE__, ((__LINE__ << 4) |  1)
    01090
    01091 #define TDS_DBGFLAG_FUNC    0x80
    01092 #define TDS_DBGFLAG_INFO2   0x40
    01093 #define TDS_DBGFLAG_INFO1   0x20
    01094 #define TDS_DBGFLAG_NETWORK 0x10
    01095 #define TDS_DBGFLAG_WARN    0x08
    01096 #define TDS_DBGFLAG_ERROR   0x04
    01097 #define TDS_DBGFLAG_SEVERE  0x02
    01098 #define TDS_DBGFLAG_ALL     0xfff
    01099 #define TDS_DBGFLAG_LOGIN   0x0800
    01100 #define TDS_DBGFLAG_HEADER  0x0400
    01101 #define TDS_DBGFLAG_PID     0x1000
    01102 #define TDS_DBGFLAG_TIME    0x2000
    01103 #define TDS_DBGFLAG_SOURCE  0x4000
    01104 #define TDS_DBGFLAG_THREAD  0x8000
    01105
    01106 #if 0
    01107
    01112 enum TDS_DBG_LOG_STATE
    01113 {
    01114           TDS_DBG_LOGIN =  (1 << 0)
    01116         , TDS_DBG_API =    (1 << 1)
    01117         , TDS_DBG_ASYNC =  (1 << 2)
    01118         , TDS_DBG_DIAG =   (1 << 3)
    01119         , TDS_DBG_error =  (1 << 4)
    01120         /* TODO:  ^^^^^ make upper case when old #defines (above) are removed */
    01121         /* Log FreeTDS runtime/logic error occurs. */
    01122         , TDS_DBG_PACKET = (1 << 5)
    01123         , TDS_DBG_LIBTDS = (1 << 6)
    01124         , TDS_DBG_CONFIG = (1 << 7)
    01125         , TDS_DBG_DEFAULT = 0xFE
    01126 };
    01127 #endif
    01128
    01129 typedef struct tds_result_info TDSCOMPUTEINFO;
    01130
    01131 typedef TDSRESULTINFO TDSPARAMINFO;
    01132
    01133 typedef struct tds_message
    01134 {
    01135         TDS_CHAR *server;
    01136         TDS_CHAR *message;
    01137         TDS_CHAR *proc_name;
    01138         TDS_CHAR *sql_state;
    01139         TDS_UINT msgno;
    01140         TDS_INT line_number;
    01141         /* -1 .. 255 */
    01142         TDS_SMALLINT state;
    01143         TDS_TINYINT priv_msg_type;
    01144         TDS_TINYINT severity;
    01145         /* for library-generated errors */
    01146         int oserr;
    01147 } TDSMESSAGE;
    01148
    01149 typedef struct tds_upd_col
    01150 {
    01151         struct tds_upd_col *next;
    01152         TDS_INT colnamelength;
    01153         char * columnname;
    01154 } TDSUPDCOL;
    01155
    01156 typedef enum {
    01157           TDS_CURSOR_STATE_UNACTIONED = 0       /* initial value */
    01158         , TDS_CURSOR_STATE_REQUESTED = 1        /* called by ct_cursor */
    01159         , TDS_CURSOR_STATE_SENT = 2             /* sent to server */
    01160         , TDS_CURSOR_STATE_ACTIONED = 3         /* acknowledged by server */
    01161 } TDS_CURSOR_STATE;
    01162
    01163 typedef struct tds_cursor_status
    01164 {
    01165         TDS_CURSOR_STATE declare;
    01166         TDS_CURSOR_STATE cursor_row;
    01167         TDS_CURSOR_STATE open;
    01168         TDS_CURSOR_STATE fetch;
    01169         TDS_CURSOR_STATE close;
    01170         TDS_CURSOR_STATE dealloc;
    01171 } TDS_CURSOR_STATUS;
    01172
    01173 typedef enum tds_cursor_operation
    01174 {
    01175         TDS_CURSOR_POSITION = 0,
    01176         TDS_CURSOR_UPDATE = 1,
    01177         TDS_CURSOR_DELETE = 2,
    01178         TDS_CURSOR_INSERT = 4
    01179 } TDS_CURSOR_OPERATION;
    01180
    01181 typedef enum tds_cursor_fetch
    01182 {
    01183         TDS_CURSOR_FETCH_NEXT = 1,
    01184         TDS_CURSOR_FETCH_PREV,
    01185         TDS_CURSOR_FETCH_FIRST,
    01186         TDS_CURSOR_FETCH_LAST,
    01187         TDS_CURSOR_FETCH_ABSOLUTE,
    01188         TDS_CURSOR_FETCH_RELATIVE
    01189 } TDS_CURSOR_FETCH;
    01190
    01194 typedef struct tds_cursor
    01195 {
    01196         struct tds_cursor *next;
    01197         TDS_INT ref_count;
    01198         TDS_TINYINT cursor_name_len;
    01199         char *cursor_name;
    01200         TDS_INT cursor_id;
    01201         TDS_TINYINT options;
    01202         TDS_TINYINT hasargs;
    01203         TDS_USMALLINT query_len;
    01204         char *query;
    01205         /* TODO for updatable columns */
    01206         /* TDS_TINYINT number_upd_cols; */
    01207         /* TDSUPDCOL *cur_col_list; */
    01208         TDS_INT cursor_rows;
    01209         /* TDSPARAMINFO *params; */
    01210         TDS_CURSOR_STATUS status;
    01211         TDS_SMALLINT srv_status;
    01212         TDSRESULTINFO *res_info;
    01213         TDS_INT type, concurrency;
    01214 } TDSCURSOR;
    01215
    01219 typedef struct tds_env
    01220 {
    01221         int block_size;
    01222         char *language;
    01223         char *charset;
    01224         char *database;
    01225 } TDSENV;
    01226
    01230 typedef struct tds_dynamic
    01231 {
    01232         struct tds_dynamic *next;
    01238         char id[30];
    01239         /* int dyn_state; */ /* TODO use it */
    01241         TDS_INT num_id;
    01242         TDSPARAMINFO *res_info;
    01250         TDSPARAMINFO *params;
    01256         int emulated;
    01258         char *query;
    01259 } TDSDYNAMIC;
    01260
    01261 typedef enum {
    01262         TDS_MULTIPLE_QUERY,
    01263         TDS_MULTIPLE_EXECUTE,
    01264         TDS_MULTIPLE_RPC
    01265 } TDS_MULTIPLE_TYPE;
    01266
    01267 typedef struct tds_multiple
    01268 {
    01269         TDS_MULTIPLE_TYPE type;
    01270         unsigned int flags;
    01271 } TDSMULTIPLE;
    01272
    01273 /* forward declaration */
    01274 typedef struct tds_context TDSCONTEXT;
    01275 typedef int (*err_handler_t) (const TDSCONTEXT *, TDSSOCKET *, TDSMESSAGE *);
    01276
    01277 struct tds_context
    01278 {
    01279         TDSLOCALE *locale;
    01280         void *parent;
    01281         /* handlers */
    01282         int (*msg_handler) (const TDSCONTEXT *, TDSSOCKET *, TDSMESSAGE *);
    01283         int (*err_handler) (const TDSCONTEXT *, TDSSOCKET *, TDSMESSAGE *);
    01284         int (*int_handler) (void *);
    01285 };
    01286
    01287 enum TDS_ICONV_ENTRY
    01288 {
    01289           client2ucs2
    01290         , client2server_chardata
    01291         , iso2server_metadata
    01292         , initial_char_conv_count       /* keep last */
    01293 };
    01294
    01295 typedef struct tds_authentication
    01296 {
    01297         TDS_UCHAR *packet;
    01298         int packet_len;
    01299         int (*free)(TDSSOCKET * tds, struct tds_authentication * auth);
    01300         int (*handle_next)(TDSSOCKET * tds, struct tds_authentication * auth, size_t len);
    01301 } TDSAUTHENTICATION;
    01302
    01306 struct tds_socket
    01307 {
    01308         TDS_SYS_SOCKET s;
    01310         TDS_USMALLINT tds_version;
    01311         TDS_UINT product_version;
    01312         char *product_name;
    01313
    01314         unsigned char capabilities[TDS_MAX_CAPABILITY];
    01315         unsigned int broken_dates:1;
    01316         unsigned int emul_little_endian:1;
    01317         unsigned int use_iconv:1;
    01318         unsigned int tds71rev1:1;
    01319
    01320         unsigned char *in_buf;
    01321         unsigned char *out_buf;
    01322         unsigned int in_buf_max;
    01323         unsigned in_pos;
    01324         unsigned out_pos;
    01325         unsigned in_len;
    01327         unsigned char in_flag;
    01328         unsigned char out_flag;
    01329         void *parent;
    01330
    01336         TDSRESULTINFO *current_results;
    01337         TDSRESULTINFO *res_info;
    01338         TDS_INT num_comp_info;
    01339         TDSCOMPUTEINFO **comp_info;
    01340         TDSPARAMINFO *param_info;
    01341         TDSCURSOR *cur_cursor;
    01342         TDSCURSOR *cursors;
    01343         TDS_TINYINT has_status;
    01344         TDS_INT ret_status;
    01345         TDS_STATE state;
    01346
    01347         volatile
    01348         unsigned char in_cancel;
    01350         TDS_INT8 rows_affected;
    01351         TDS_INT query_timeout;
    01352         TDSENV env;
    01353
    01354         TDSDYNAMIC *cur_dyn;
    01355         TDSDYNAMIC *dyns;
    01357         const TDSCONTEXT *tds_ctx;
    01358         int char_conv_count;
    01359         TDSICONV **char_convs;
    01360
    01361         TDSCONNECTION *connection;
    01363         int spid;
    01364         TDS_UCHAR collation[5];
    01365         TDS_UCHAR tds9_transaction[8];
    01366         void (*env_chg_func) (TDSSOCKET * tds, int type, char *oldval, char *newval);
    01367         int internal_sp_called;
    01368
    01369         void *tls_session;
    01370         void *tls_credentials;
    01371         TDSAUTHENTICATION *authentication;
    01372         int option_value;
    01373 };
    01374
    01375 int tds_init_write_buf(TDSSOCKET * tds);
    01376 void tds_free_result_info(TDSRESULTINFO * info);
    01377 void tds_free_socket(TDSSOCKET * tds);
    01378 void tds_free_connection(TDSCONNECTION * connection);
    01379 void tds_free_all_results(TDSSOCKET * tds);
    01380 void tds_free_results(TDSRESULTINFO * res_info);
    01381 void tds_free_param_results(TDSPARAMINFO * param_info);
    01382 void tds_free_param_result(TDSPARAMINFO * param_info);
    01383 void tds_free_msg(TDSMESSAGE * message);
    01384 void tds_cursor_deallocated(TDSSOCKET *tds, TDSCURSOR *cursor);
    01385 void tds_release_cursor(TDSSOCKET *tds, TDSCURSOR *cursor);
    01386 void tds_free_bcp_column_data(BCPCOLDATA * coldata);
    01387
    01388 int tds_put_n(TDSSOCKET * tds, const void *buf, size_t n);
    01389 int tds_put_string(TDSSOCKET * tds, const char *buf, int len);
    01390 int tds_put_int(TDSSOCKET * tds, TDS_INT i);
    01391 int tds_put_int8(TDSSOCKET * tds, TDS_INT8 i);
    01392 int tds_put_smallint(TDSSOCKET * tds, TDS_SMALLINT si);
    01394 #define tds_put_tinyint(tds, ti) tds_put_byte(tds,ti)
    01395 int tds_put_byte(TDSSOCKET * tds, unsigned char c);
    01396 TDSRESULTINFO *tds_alloc_results(int num_cols);
    01397 TDSCOMPUTEINFO **tds_alloc_compute_results(TDSSOCKET * tds, int num_cols, int by_cols);
    01398 TDSCONTEXT *tds_alloc_context(void * parent);
    01399 void tds_free_context(TDSCONTEXT * locale);
    01400 TDSSOCKET *tds_alloc_socket(TDSCONTEXT * context, int bufsize);
    01401
    01402 /* config.c */
    01403 int tds_default_port(int major, int minor);
    01404 const TDS_COMPILETIME_SETTINGS *tds_get_compiletime_settings(void);
    01405 typedef void (*TDSCONFPARSE) (const char *option, const char *value, void *param);
    01406 int tds_read_conf_section(FILE * in, const char *section, TDSCONFPARSE tds_conf_parse, void *parse_param);
    01407 int tds_read_conf_file(TDSCONNECTION * connection, const char *server);
    01408 void tds_parse_conf_section(const char *option, const char *value, void *param);
    01409 TDSCONNECTION *tds_read_config_info(TDSSOCKET * tds, TDSLOGIN * login, TDSLOCALE * locale);
    01410 void tds_fix_connection(TDSCONNECTION * connection);
    01411 TDS_USMALLINT tds_config_verstr(const char *tdsver, TDSCONNECTION * connection);
    01412 int tds_lookup_host(const char *servername, char *ip);
    01413 int tds_set_interfaces_file_loc(const char *interfloc);
    01414 extern const char STD_DATETIME_FMT[];
    01415 int tds_config_boolean(const char *value);
    01416
    01417 TDSLOCALE *tds_get_locale(void);
    01418 int tds_alloc_row(TDSRESULTINFO * res_info);
    01419 int tds_alloc_compute_row(TDSCOMPUTEINFO * res_info);
    01420 BCPCOLDATA * tds_alloc_bcp_column_data(int column_size);
    01421 unsigned char *tds7_crypt_pass(const unsigned char *clear_pass, size_t len, unsigned char *crypt_pass);
    01422 TDSDYNAMIC *tds_lookup_dynamic(TDSSOCKET * tds, const char *id);
    01423 /*@observer@*/ const char *tds_prtype(int token);
    01424 int tds_get_varint_size(TDSSOCKET * tds, int datatype);
    01425 int tds_get_cardinal_type(int datatype, int usertype);
    01426
    01427
    01428
    01429 /* iconv.c */
    01430 void tds_iconv_open(TDSSOCKET * tds, const char *charset);
    01431 void tds_iconv_close(TDSSOCKET * tds);
    01432 void tds_srv_charset_changed(TDSSOCKET * tds, const char *charset);
    01433 void tds7_srv_charset_changed(TDSSOCKET * tds, int sql_collate, int lcid);
    01434 int tds_iconv_alloc(TDSSOCKET * tds);
    01435 void tds_iconv_free(TDSSOCKET * tds);
    01436 TDSICONV *tds_iconv_from_collate(TDSSOCKET * tds, TDS_UCHAR collate[5]);
    01437
    01438 /* threadsafe.c */
    01439 char *tds_timestamp_str(char *str, int maxlen);
    01440 struct tm *tds_localtime_r(const time_t *timep, struct tm *result);
    01441 struct hostent *tds_gethostbyname_r(const char *servername, struct hostent *result, char *buffer, int buflen, int *h_errnop);
    01442 struct hostent *tds_gethostbyaddr_r(const char *addr, int len, int type, struct hostent *result, char *buffer, int buflen,
    01443                                     int *h_errnop);
    01444 struct servent *tds_getservbyname_r(const char *name, const char *proto, struct servent *result, char *buffer, int buflen);
    01445 #ifdef INADDR_NONE
    01446 const char *tds_inet_ntoa_r(struct in_addr iaddr, char *ip, size_t len);
    01447 #endif
    01448 char *tds_get_homedir(void);
    01449
    01450 /* mem.c */
    01451 TDSPARAMINFO *tds_alloc_param_result(TDSPARAMINFO * old_param);
    01452 void tds_free_input_params(TDSDYNAMIC * dyn);
    01453 void tds_free_dynamic(TDSSOCKET * tds, TDSDYNAMIC * dyn);
    01454 TDSSOCKET *tds_realloc_socket(TDSSOCKET * tds, size_t bufsize);
    01455 char *tds_alloc_client_sqlstate(int msgno);
    01456 char *tds_alloc_lookup_sqlstate(TDSSOCKET * tds, int msgno);
    01457 TDSLOGIN *tds_alloc_login(void);
    01458 TDSDYNAMIC *tds_alloc_dynamic(TDSSOCKET * tds, const char *id);
    01459 void tds_free_login(TDSLOGIN * login);
    01460 TDSCONNECTION *tds_alloc_connection(TDSLOCALE * locale);
    01461 TDSLOCALE *tds_alloc_locale(void);
    01462 void *tds_alloc_param_data(TDSCOLUMN * curparam);
    01463 void tds_free_locale(TDSLOCALE * locale);
    01464 TDSCURSOR * tds_alloc_cursor(TDSSOCKET * tds, const char *name, TDS_INT namelen, const char *query, TDS_INT querylen);
    01465 void tds_free_row(TDSRESULTINFO * res_info, unsigned char *row);
    01466
    01467 /* login.c */
    01468 void tds_set_packet(TDSLOGIN * tds_login, int packet_size);
    01469 void tds_set_port(TDSLOGIN * tds_login, int port);
    01470 void tds_set_passwd(TDSLOGIN * tds_login, const char *password);
    01471 void tds_set_bulk(TDSLOGIN * tds_login, TDS_TINYINT enabled);
    01472 void tds_set_user(TDSLOGIN * tds_login, const char *username);
    01473 void tds_set_app(TDSLOGIN * tds_login, const char *application);
    01474 void tds_set_host(TDSLOGIN * tds_login, const char *hostname);
    01475 void tds_set_library(TDSLOGIN * tds_login, const char *library);
    01476 void tds_set_server(TDSLOGIN * tds_login, const char *server);
    01477 void tds_set_client_charset(TDSLOGIN * tds_login, const char *charset);
    01478 void tds_set_language(TDSLOGIN * tds_login, const char *language);
    01479 void tds_set_database_name(TDSLOGIN * tds_login, const char *dbname);
    01480 void tds_set_version(TDSLOGIN * tds_login, TDS_TINYINT major_ver, TDS_TINYINT minor_ver);
    01481 void tds_set_capabilities(TDSLOGIN * tds_login, unsigned char *capabilities, int size);
    01482 int tds_connect_and_login(TDSSOCKET * tds, TDSCONNECTION * connection);
    01483
    01484 /* query.c */
    01485 int tds_submit_query(TDSSOCKET * tds, const char *query);
    01486 int tds_submit_query_params(TDSSOCKET * tds, const char *query, TDSPARAMINFO * params);
    01487 int tds_submit_queryf(TDSSOCKET * tds, const char *queryf, ...);
    01488 int tds_submit_prepare(TDSSOCKET * tds, const char *query, const char *id, TDSDYNAMIC ** dyn_out, TDSPARAMINFO * params);
    01489 int tds_submit_execdirect(TDSSOCKET * tds, const char *query, TDSPARAMINFO * params);
    01490 int tds8_submit_prepexec(TDSSOCKET * tds, const char *query, const char *id, TDSDYNAMIC ** dyn_out, TDSPARAMINFO * params);
    01491 int tds_submit_execute(TDSSOCKET * tds, TDSDYNAMIC * dyn);
    01492 int tds_send_cancel(TDSSOCKET * tds);
    01493 const char *tds_next_placeholder(const char *start);
    01494 int tds_count_placeholders(const char *query);
    01495 int tds_needs_unprepare(TDSSOCKET * tds, TDSDYNAMIC * dyn);
    01496 int tds_submit_unprepare(TDSSOCKET * tds, TDSDYNAMIC * dyn);
    01497 int tds_submit_rpc(TDSSOCKET * tds, const char *rpc_name, TDSPARAMINFO * params);
    01498 int tds_submit_optioncmd(TDSSOCKET * tds, TDS_OPTION_CMD command, TDS_OPTION option, TDS_OPTION_ARG *param, TDS_INT param_size);
    01499 int tds_quote_id(TDSSOCKET * tds, char *buffer, const char *id, int idlen);
    01500 int tds_quote_string(TDSSOCKET * tds, char *buffer, const char *str, int len);
    01501 const char *tds_skip_quoted(const char *s);
    01502
    01503 int tds_cursor_declare(TDSSOCKET * tds, TDSCURSOR * cursor, TDSPARAMINFO *params, int *send);
    01504 int tds_cursor_setrows(TDSSOCKET * tds, TDSCURSOR * cursor, int *send);
    01505 int tds_cursor_open(TDSSOCKET * tds, TDSCURSOR * cursor, TDSPARAMINFO *params, int *send);
    01506 int tds_cursor_fetch(TDSSOCKET * tds, TDSCURSOR * cursor, TDS_CURSOR_FETCH fetch_type, TDS_INT i_row);
    01507 int tds_cursor_get_cursor_info(TDSSOCKET * tds, TDSCURSOR * cursor, TDS_UINT * row_number, TDS_UINT * row_count);
    01508 int tds_cursor_close(TDSSOCKET * tds, TDSCURSOR * cursor);
    01509 int tds_cursor_dealloc(TDSSOCKET * tds, TDSCURSOR * cursor);
    01510 int tds_cursor_update(TDSSOCKET * tds, TDSCURSOR * cursor, TDS_CURSOR_OPERATION op, TDS_INT i_row, TDSPARAMINFO * params);
    01511 int tds_cursor_setname(TDSSOCKET * tds, TDSCURSOR * cursor);
    01512
    01513 int tds_multiple_init(TDSSOCKET *tds, TDSMULTIPLE *multiple, TDS_MULTIPLE_TYPE type);
    01514 int tds_multiple_done(TDSSOCKET *tds, TDSMULTIPLE *multiple);
    01515 int tds_multiple_query(TDSSOCKET *tds, TDSMULTIPLE *multiple, const char *query, TDSPARAMINFO * params);
    01516 int tds_multiple_execute(TDSSOCKET *tds, TDSMULTIPLE *multiple, TDSDYNAMIC * dyn);
    01517
    01518 /* token.c */
    01519 int tds_process_cancel(TDSSOCKET * tds);
    01520 #ifdef WORDS_BIGENDIAN
    01521 void tds_swap_datatype(int coltype, unsigned char *buf);
    01522 #endif
    01523 void tds_swap_numeric(TDS_NUMERIC *num);
    01524 int tds_get_token_size(int marker);
    01525 int tds_process_login_tokens(TDSSOCKET * tds);
    01526 int tds_process_simple_query(TDSSOCKET * tds);
    01527 int tds5_send_optioncmd(TDSSOCKET * tds, TDS_OPTION_CMD tds_command, TDS_OPTION tds_option, TDS_OPTION_ARG * tds_argument,
    01528                         TDS_INT * tds_argsize);
    01529 int tds_process_tokens(TDSSOCKET * tds, /*@out@*/ TDS_INT * result_type, /*@out@*/ int *done_flags, unsigned flag);
    01530
    01531 /* data.c */
    01532 void tds_set_param_type(TDSSOCKET * tds, TDSCOLUMN * curcol, TDS_SERVER_TYPE type);
    01533 void tds_set_column_type(TDSSOCKET * tds, TDSCOLUMN * curcol, int type);
    01534 TDS_INT tds_data_get_info(TDSSOCKET *tds, TDSCOLUMN *col);
    01535
    01536
    01537 /* tds_convert.c */
    01538 TDS_INT tds_datecrack(TDS_INT datetype, const void *di, TDSDATEREC * dr);
    01539 int tds_get_conversion_type(int srctype, int colsize);
    01540 extern const char tds_hex_digits[];
    01541
    01542 /* write.c */
    01543 int tds_flush_packet(TDSSOCKET * tds);
    01544 int tds_put_buf(TDSSOCKET * tds, const unsigned char *buf, int dsize, int ssize);
    01545
    01546 /* read.c */
    01547 unsigned char tds_get_byte(TDSSOCKET * tds);
    01548 void tds_unget_byte(TDSSOCKET * tds);
    01549 unsigned char tds_peek(TDSSOCKET * tds);
    01550 TDS_SMALLINT tds_get_smallint(TDSSOCKET * tds);
    01551 TDS_INT tds_get_int(TDSSOCKET * tds);
    01552 TDS_INT8 tds_get_int8(TDSSOCKET * tds);
    01553 int tds_get_string(TDSSOCKET * tds, int string_len, char *dest, size_t dest_size);
    01554 int tds_get_char_data(TDSSOCKET * tds, char *dest, size_t wire_size, TDSCOLUMN * curcol);
    01555 void *tds_get_n(TDSSOCKET * tds, /*@out@*/ /*@null@*/ void *dest, int n);
    01556 int tds_get_size_by_type(int servertype);
    01557
    01558
    01559 /* util.c */
    01560 int tdserror (const TDSCONTEXT * tds_ctx, TDSSOCKET * tds, int msgno, int errnum);
    01561 TDS_STATE tds_set_state(TDSSOCKET * tds, TDS_STATE state);
    01562 void tds_set_parent(TDSSOCKET * tds, void *the_parent);
    01563 int tds_swap_bytes(unsigned char *buf, int bytes);
    01564 int tds_version(TDSSOCKET * tds_socket, char *pversion_string);
    01565 unsigned int tds_gettime_ms(void);
    01566
    01567 /* log.c */
    01568 void tdsdump_off(void);
    01569 void tdsdump_on(void);
    01570 int tdsdump_isopen(void);
    01571 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
    01572 #pragma GCC visibility pop
    01573 #endif
    01574 int tdsdump_open(const char *filename);
    01575 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
    01576 #pragma GCC visibility push(hidden)
    01577 #endif
    01578 void tdsdump_close(void);
    01579 void tdsdump_dump_buf(const char* file, unsigned int level_line, const char *msg, const void *buf, size_t length);
    01580 void tdsdump_col(const TDSCOLUMN *col);
    01581 #undef tdsdump_log
    01582 void tdsdump_log(const char* file, unsigned int level_line, const char *fmt, ...)
    01583 #if defined(__GNUC__) && __GNUC__ >= 2
    01584         __attribute__ ((__format__ (__printf__, 3, 4)))
    01585 #endif
    01586 ;
    01587 #define tdsdump_log if (TDS_UNLIKELY(tds_write_dump)) tdsdump_log
    01588
    01589 extern int tds_write_dump;
    01590 extern int tds_debug_flags;
    01591 extern int tds_g_append_mode;
    01592
    01593 /* net.c */
    01594 int tds_lastpacket(TDSSOCKET * tds);
    01595 TDSERRNO tds_open_socket(TDSSOCKET * tds, const char *ip_addr, unsigned int port, int timeout, int *p_oserr);
    01596 int tds_close_socket(TDSSOCKET * tds);
    01597 int tds_read_packet(TDSSOCKET * tds);
    01598 int tds_write_packet(TDSSOCKET * tds, unsigned char final);
    01599 int tds7_get_instance_ports(FILE *output, const char *ip_addr);
    01600 int tds7_get_instance_port(const char *ip_addr, const char *instance);
    01601 int tds_ssl_init(TDSSOCKET *tds);
    01602 void tds_ssl_deinit(TDSSOCKET *tds);
    01603 const char *tds_prwsaerror(int erc);
    01604
    01605
    01606
    01607 /* vstrbuild.c */
    01608 int tds_vstrbuild(char *buffer, int buflen, int *resultlen, char *text, int textlen, const char *formats, int formatlen,
    01609                   va_list ap);
    01610
    01611 /* numeric.c */
    01612 char *tds_money_to_string(const TDS_MONEY * money, char *s);
    01613 TDS_INT tds_numeric_to_string(const TDS_NUMERIC * numeric, char *s);
    01614 TDS_INT tds_numeric_change_prec_scale(TDS_NUMERIC * numeric, unsigned char new_prec, unsigned char new_scale);
    01615
    01616 /* getmac.c */
    01617 void tds_getmac(TDS_SYS_SOCKET s, unsigned char mac[6]);
    01618
    01619 #ifndef HAVE_SSPI
    01620 TDSAUTHENTICATION * tds_ntlm_get_auth(TDSSOCKET * tds);
    01621 TDSAUTHENTICATION * tds_gss_get_auth(TDSSOCKET * tds);
    01622 #else
    01623 TDSAUTHENTICATION * tds_sspi_get_auth(TDSSOCKET * tds);
    01624 #endif
    01625
    01626 /* bulk.c */
    01627
    01629 enum tds_bcp_directions
    01630 {
    01631         TDS_BCP_IN = 1,
    01632         TDS_BCP_OUT = 2,
    01633         TDS_BCP_QUERYOUT = 3
    01634 };
    01635
    01636 typedef struct tds_bcpinfo
    01637 {
    01638         const char *hint;
    01639         void *parent;
    01640         TDS_CHAR *tablename;
    01641         TDS_CHAR *insert_stmt;
    01642         TDS_INT direction;
    01643         TDS_INT identity_insert_on;
    01644         TDS_INT xfer_init;
    01645         TDS_INT var_cols;
    01646         TDS_INT bind_count;
    01647         TDSRESULTINFO *bindinfo;
    01648 } TDSBCPINFO;
    01649
    01650 int tds_bcp_init(TDSSOCKET *tds, TDSBCPINFO *bcpinfo);
    01651 typedef int  (*tds_bcp_get_col_data) (TDSBCPINFO *bulk, TDSCOLUMN *bcpcol, int offset);
    01652 typedef void (*tds_bcp_null_error)   (TDSBCPINFO *bulk, int index, int offset);
    01653 int tds_bcp_send_record(TDSSOCKET *tds, TDSBCPINFO *bcpinfo, tds_bcp_get_col_data get_col_data, tds_bcp_null_error null_error, int offset);
    01654 int tds_bcp_done(TDSSOCKET *tds, int *rows_copied);
    01655 int tds_bcp_start(TDSSOCKET *tds, TDSBCPINFO *bcpinfo);
    01656 int tds_bcp_start_copy_in(TDSSOCKET *tds, TDSBCPINFO *bcpinfo);
    01657
    01658 int tds_writetext_start(TDSSOCKET *tds, const char *objname, const char *textptr, const char *timestamp, int with_log, TDS_UINT size);
    01659 int tds_writetext_continue(TDSSOCKET *tds, const TDS_UCHAR *text, TDS_UINT size);
    01660 int tds_writetext_end(TDSSOCKET *tds);
    01661
    01662
    01663 #define IS_TDS42(x) (x->tds_version==0x402)
    01664 #define IS_TDS46(x) (x->tds_version==0x406)
    01665 #define IS_TDS50(x) (x->tds_version==0x500)
    01666 #define IS_TDS70(x) (x->tds_version==0x700)
    01667 #define IS_TDS71(x) (x->tds_version==0x701)
    01668 #define IS_TDS72(x) (x->tds_version==0x702)
    01669
    01670 #define IS_TDS7_PLUS(x) ((x)->tds_version>=0x700)
    01671 #define IS_TDS71_PLUS(x) ((x)->tds_version>=0x701)
    01672 #define IS_TDS72_PLUS(x) ((x)->tds_version>=0x702)
    01673
    01674 #define TDS_MAJOR(x) ((x)->tds_version >> 8)
    01675 #define TDS_MINOR(x) ((x)->tds_version & 0xff)
    01676
    01677 #define IS_TDSDEAD(x) (((x) == NULL) || TDS_IS_SOCKET_INVALID((x)->s))
    01678
    01680 #define TDS_IS_SYBASE(x) (!(x->product_version & 0x80000000u))
    01681
    01682 #define TDS_IS_MSSQL(x) ((x->product_version & 0x80000000u)!=0)
    01683
    01687 #define TDS_MS_VER(maj,min,x) (0x80000000u|((maj)<<24)|((min)<<16)|(x))
    01688
    01689 /* TODO test if not similar to ms one*/
    01691 #define TDS_SYB_VER(maj,min,x) (((maj)<<24)|((min)<<16)|(x)<<8)
    01692
    01693 #ifdef __cplusplus
    01694 #if 0
    01695 {
    01696 #endif
    01697 }
    01698 #endif
    01699
    01700 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
    01701 #pragma GCC visibility pop
    01702 #endif
    01703
    01704 #define TDS_PUT_INT(tds,v) tds_put_int((tds), ((TDS_INT)(v)))
    01705 #define TDS_PUT_SMALLINT(tds,v) tds_put_smallint((tds), ((TDS_SMALLINT)(v)))
    01706 #define TDS_PUT_BYTE(tds,v) tds_put_byte((tds), ((unsigned char)(v)))
    01707
    01708 #endif /* _tds_h_ */

All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines