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

- File List
- File Members

# include/tds.h

Go to the documentation of this file.

    00001 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
    00002  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005  Brian Bruns
    00003  * Copyright (C) 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 /* http://jtds.sourceforge.net/apiCursors.html */
    00382 /* Cursor scroll option, must be one of 0x01 - 0x10, OR'd with other bits */
    00383 enum {
    00384         TDS_CUR_TYPE_KEYSET          = 0x0001, /* default */
    00385         TDS_CUR_TYPE_DYNAMIC         = 0x0002,
    00386         TDS_CUR_TYPE_FORWARD         = 0x0004,
    00387         TDS_CUR_TYPE_STATIC          = 0x0008,
    00388         TDS_CUR_TYPE_FASTFORWARDONLY = 0x0010,
    00389         TDS_CUR_TYPE_PARAMETERIZED   = 0x1000,
    00390         TDS_CUR_TYPE_AUTO_FETCH      = 0x2000
    00391 };
    00392
    00393 enum {
    00394         TDS_CUR_CONCUR_READ_ONLY         = 1,
    00395         TDS_CUR_CONCUR_SCROLL_LOCKS      = 2,
    00396         TDS_CUR_CONCUR_OPTIMISTIC        = 4, /* default */
    00397         TDS_CUR_CONCUR_OPTIMISTIC_VALUES = 8
    00398 };
    00399
    00400 /* TDS 4/5 login*/
    00401 #define TDS_MAXNAME 30  /* maximum login name lenghts */
    00402 #define TDS_PROGNLEN 10 /* maximum program lenght */
    00403 #define TDS_PKTLEN 6    /* maximum packet lenght in login */
    00404
    00405 /* environment type field */
    00406 #define TDS_ENV_DATABASE        1
    00407 #define TDS_ENV_LANG            2
    00408 #define TDS_ENV_CHARSET         3
    00409 #define TDS_ENV_PACKSIZE        4
    00410 #define TDS_ENV_LCID            5
    00411 #define TDS_ENV_SQLCOLLATION    7
    00412 #define TDS_ENV_BEGINTRANS      8
    00413 #define TDS_ENV_COMMITTRANS     9
    00414 #define TDS_ENV_ROLLBACKTRANS   10
    00415
    00416 /* string types */
    00417 #define TDS_NULLTERM -9
    00418
    00419 /* Microsoft internal stored procedure id's */
    00420
    00421 #define TDS_SP_CURSOR           1
    00422 #define TDS_SP_CURSOROPEN       2
    00423 #define TDS_SP_CURSORPREPARE    3
    00424 #define TDS_SP_CURSOREXECUTE    4
    00425 #define TDS_SP_CURSORPREPEXEC   5
    00426 #define TDS_SP_CURSORUNPREPARE  6
    00427 #define TDS_SP_CURSORFETCH      7
    00428 #define TDS_SP_CURSOROPTION     8
    00429 #define TDS_SP_CURSORCLOSE      9
    00430 #define TDS_SP_EXECUTESQL      10
    00431 #define TDS_SP_PREPARE         11
    00432 #define TDS_SP_EXECUTE         12
    00433 #define TDS_SP_PREPEXEC        13
    00434 #define TDS_SP_PREPEXECRPC     14
    00435 #define TDS_SP_UNPREPARE       15
    00436 /*
    00437  * <rant> Sybase does an awful job of this stuff, non null ints of size 1 2
    00438  * and 4 have there own codes but nullable ints are lumped into INTN
    00439  * sheesh! </rant>
    00440  */
    00441 typedef enum
    00442 {
    00443         SYBCHAR = 47,           /* 0x2F */
    00444 #define SYBCHAR SYBCHAR
    00445         SYBVARCHAR = 39,        /* 0x27 */
    00446 #define SYBVARCHAR      SYBVARCHAR
    00447         SYBINTN = 38,           /* 0x26 */
    00448 #define SYBINTN SYBINTN
    00449         SYBINT1 = 48,           /* 0x30 */
    00450 #define SYBINT1 SYBINT1
    00451         SYBINT2 = 52,           /* 0x34 */
    00452 #define SYBINT2 SYBINT2
    00453         SYBINT4 = 56,           /* 0x38 */
    00454 #define SYBINT4 SYBINT4
    00455         SYBFLT8 = 62,           /* 0x3E */
    00456 #define SYBFLT8 SYBFLT8
    00457         SYBDATETIME = 61,       /* 0x3D */
    00458 #define SYBDATETIME     SYBDATETIME
    00459         SYBBIT = 50,            /* 0x32 */
    00460 #define SYBBIT  SYBBIT
    00461         SYBTEXT = 35,           /* 0x23 */
    00462 #define SYBTEXT SYBTEXT
    00463         SYBNTEXT = 99,          /* 0x63 */
    00464 #define SYBNTEXT        SYBNTEXT
    00465         SYBIMAGE = 34,          /* 0x22 */
    00466 #define SYBIMAGE        SYBIMAGE
    00467         SYBMONEY4 = 122,        /* 0x7A */
    00468 #define SYBMONEY4       SYBMONEY4
    00469         SYBMONEY = 60,          /* 0x3C */
    00470 #define SYBMONEY        SYBMONEY
    00471         SYBDATETIME4 = 58,      /* 0x3A */
    00472 #define SYBDATETIME4    SYBDATETIME4
    00473         SYBREAL = 59,           /* 0x3B */
    00474 #define SYBREAL SYBREAL
    00475         SYBBINARY = 45,         /* 0x2D */
    00476 #define SYBBINARY       SYBBINARY
    00477         SYBVOID = 31,           /* 0x1F */
    00478 #define SYBVOID SYBVOID
    00479         SYBVARBINARY = 37,      /* 0x25 */
    00480 #define SYBVARBINARY    SYBVARBINARY
    00481         SYBBITN = 104,          /* 0x68 */
    00482 #define SYBBITN SYBBITN
    00483         SYBNUMERIC = 108,       /* 0x6C */
    00484 #define SYBNUMERIC      SYBNUMERIC
    00485         SYBDECIMAL = 106,       /* 0x6A */
    00486 #define SYBDECIMAL      SYBDECIMAL
    00487         SYBFLTN = 109,          /* 0x6D */
    00488 #define SYBFLTN SYBFLTN
    00489         SYBMONEYN = 110,        /* 0x6E */
    00490 #define SYBMONEYN       SYBMONEYN
    00491         SYBDATETIMN = 111,      /* 0x6F */
    00492 #define SYBDATETIMN     SYBDATETIMN
    00493
    00494 /*
    00495  * MS only types
    00496  */
    00497         SYBNVARCHAR = 103,      /* 0x67 */
    00498 #define SYBNVARCHAR     SYBNVARCHAR
    00499         SYBINT8 = 127,          /* 0x7F */
    00500 #define SYBINT8 SYBINT8
    00501         XSYBCHAR = 175,         /* 0xAF */
    00502 #define XSYBCHAR        XSYBCHAR
    00503         XSYBVARCHAR = 167,      /* 0xA7 */
    00504 #define XSYBVARCHAR     XSYBVARCHAR
    00505         XSYBNVARCHAR = 231,     /* 0xE7 */
    00506 #define XSYBNVARCHAR    XSYBNVARCHAR
    00507         XSYBNCHAR = 239,        /* 0xEF */
    00508 #define XSYBNCHAR       XSYBNCHAR
    00509         XSYBVARBINARY = 165,    /* 0xA5 */
    00510 #define XSYBVARBINARY   XSYBVARBINARY
    00511         XSYBBINARY = 173,       /* 0xAD */
    00512 #define XSYBBINARY      XSYBBINARY
    00513         SYBUNIQUE = 36,         /* 0x24 */
    00514 #define SYBUNIQUE       SYBUNIQUE
    00515         SYBVARIANT = 98,        /* 0x62 */
    00516 #define SYBVARIANT      SYBVARIANT
    00517         SYBMSUDT = 240,         /* 0xF0 */
    00518 #define SYBMSUDT SYBMSUDT
    00519         SYBMSXML = 241,         /* 0xF1 */
    00520 #define SYBMSXML SYBMSXML
    00521
    00522 /*
    00523  * Sybase only types
    00524  */
    00525         SYBLONGBINARY = 225,    /* 0xE1 */
    00526 #define SYBLONGBINARY   SYBLONGBINARY
    00527         SYBUINT1 = 64,          /* 0x40 */
    00528 #define SYBUINT1        SYBUINT1
    00529         SYBUINT2 = 65,          /* 0x41 */
    00530 #define SYBUINT2        SYBUINT2
    00531         SYBUINT4 = 66,          /* 0x42 */
    00532 #define SYBUINT4        SYBUINT4
    00533         SYBUINT8 = 67,          /* 0x43 */
    00534 #define SYBUINT8        SYBUINT8
    00535         SYBBLOB = 36,           /* 0x24 */
    00536 #define SYBBLOB         SYBBLOB
    00537         SYBBOUNDARY = 104,      /* 0x68 */
    00538 #define SYBBOUNDARY     SYBBOUNDARY
    00539         SYBDATE = 49,           /* 0x31 */
    00540 #define SYBDATE         SYBDATE
    00541         SYBDATEN = 123,         /* 0x7B */
    00542 #define SYBDATEN        SYBDATEN
    00543         SYB5INT8 = 191,         /* 0xBF */
    00544 #define SYB5INT8                SYB5INT8
    00545         SYBINTERVAL = 46,       /* 0x2E */
    00546 #define SYBINTERVAL     SYBINTERVAL
    00547         SYBLONGCHAR = 175,      /* 0xAF */
    00548 #define SYBLONGCHAR     SYBLONGCHAR
    00549         SYBSENSITIVITY = 103,   /* 0x67 */
    00550 #define SYBSENSITIVITY  SYBSENSITIVITY
    00551         SYBSINT1 = 176,         /* 0xB0 */
    00552 #define SYBSINT1        SYBSINT1
    00553         SYBTIME = 51,           /* 0x33 */
    00554 #define SYBTIME         SYBTIME
    00555         SYBTIMEN = 147,         /* 0x93 */
    00556 #define SYBTIMEN        SYBTIMEN
    00557         SYBUINTN = 68,          /* 0x44 */
    00558 #define SYBUINTN        SYBUINTN
    00559         SYBUNITEXT = 174,       /* 0xAE */
    00560 #define SYBUNITEXT      SYBUNITEXT
    00561         SYBXML = 163,           /* 0xA3 */
    00562 #define SYBXML          SYBXML
    00563
    00564 } TDS_SERVER_TYPE;
    00565
    00566
    00567 typedef enum
    00568 {
    00569         USER_UNICHAR_TYPE = 34,         /* 0x22 */
    00570         USER_UNIVARCHAR_TYPE = 35       /* 0x23 */
    00571 } TDS_USER_TYPE;
    00572
    00573 #define SYBAOPCNT  0x4b
    00574 #define SYBAOPCNTU 0x4c
    00575 #define SYBAOPSUM  0x4d
    00576 #define SYBAOPSUMU 0x4e
    00577 #define SYBAOPAVG  0x4f
    00578 #define SYBAOPAVGU 0x50
    00579 #define SYBAOPMIN  0x51
    00580 #define SYBAOPMAX  0x52
    00581
    00582 /* mssql2k compute operator */
    00583 #define SYBAOPCNT_BIG           0x09
    00584 #define SYBAOPSTDEV             0x30
    00585 #define SYBAOPSTDEVP            0x31
    00586 #define SYBAOPVAR               0x32
    00587 #define SYBAOPVARP              0x33
    00588 #define SYBAOPCHECKSUM_AGG      0x72
    00589
    00590
    00594 typedef enum
    00595 {
    00596           TDS_OPT_SET = 1       /* Set an option. */
    00597         , TDS_OPT_DEFAULT = 2   /* Set option to its default value. */
    00598         , TDS_OPT_LIST = 3      /* Request current setting of a specific option. */
    00599         , TDS_OPT_INFO = 4      /* Report current setting of a specific option. */
    00600 } TDS_OPTION_CMD;
    00601
    00602 typedef enum
    00603 {
    00604           TDS_OPT_DATEFIRST = 1         /* 0x01 */
    00605         , TDS_OPT_TEXTSIZE = 2          /* 0x02 */
    00606         , TDS_OPT_STAT_TIME = 3         /* 0x03 */
    00607         , TDS_OPT_STAT_IO = 4           /* 0x04 */
    00608         , TDS_OPT_ROWCOUNT = 5          /* 0x05 */
    00609         , TDS_OPT_NATLANG = 6           /* 0x06 */
    00610         , TDS_OPT_DATEFORMAT = 7        /* 0x07 */
    00611         , TDS_OPT_ISOLATION = 8         /* 0x08 */
    00612         , TDS_OPT_AUTHON = 9            /* 0x09 */
    00613         , TDS_OPT_CHARSET = 10          /* 0x0a */
    00614         , TDS_OPT_SHOWPLAN = 13         /* 0x0d */
    00615         , TDS_OPT_NOEXEC = 14           /* 0x0e */
    00616         , TDS_OPT_ARITHIGNOREON = 15    /* 0x0f */
    00617         , TDS_OPT_ARITHABORTON = 17     /* 0x11 */
    00618         , TDS_OPT_PARSEONLY = 18        /* 0x12 */
    00619         , TDS_OPT_GETDATA = 20          /* 0x14 */
    00620         , TDS_OPT_NOCOUNT = 21          /* 0x15 */
    00621         , TDS_OPT_FORCEPLAN = 23        /* 0x17 */
    00622         , TDS_OPT_FORMATONLY = 24       /* 0x18 */
    00623         , TDS_OPT_CHAINXACTS = 25       /* 0x19 */
    00624         , TDS_OPT_CURCLOSEONXACT = 26   /* 0x1a */
    00625         , TDS_OPT_FIPSFLAG = 27         /* 0x1b */
    00626         , TDS_OPT_RESTREES = 28         /* 0x1c */
    00627         , TDS_OPT_IDENTITYON = 29       /* 0x1d */
    00628         , TDS_OPT_CURREAD = 30          /* 0x1e */
    00629         , TDS_OPT_CURWRITE = 31         /* 0x1f */
    00630         , TDS_OPT_IDENTITYOFF = 32      /* 0x20 */
    00631         , TDS_OPT_AUTHOFF = 33          /* 0x21 */
    00632         , TDS_OPT_ANSINULL = 34         /* 0x22 */
    00633         , TDS_OPT_QUOTED_IDENT = 35     /* 0x23 */
    00634         , TDS_OPT_ARITHIGNOREOFF = 36   /* 0x24 */
    00635         , TDS_OPT_ARITHABORTOFF = 37    /* 0x25 */
    00636         , TDS_OPT_TRUNCABORT = 38       /* 0x26 */
    00637 } TDS_OPTION;
    00638
    00639 typedef union tds_option_arg
    00640 {
    00641         TDS_TINYINT ti;
    00642         TDS_INT i;
    00643         TDS_CHAR *c;
    00644 } TDS_OPTION_ARG;
    00645
    00646 enum {
    00647         TDS_OPT_ARITHOVERFLOW = 0x01,
    00648         TDS_OPT_NUMERICTRUNC = 0x02
    00649 };
    00650
    00651 enum TDS_OPT_DATEFIRST_CHOICE
    00652 {
    00653         TDS_OPT_MONDAY = 1, TDS_OPT_TUESDAY = 2, TDS_OPT_WEDNESDAY = 3, TDS_OPT_THURSDAY = 4, TDS_OPT_FRIDAY = 5, TDS_OPT_SATURDAY =
    00654                 6, TDS_OPT_SUNDAY = 7
    00655 };
    00656
    00657 enum TDS_OPT_DATEFORMAT_CHOICE
    00658 {
    00659         TDS_OPT_FMTMDY = 1, TDS_OPT_FMTDMY = 2, TDS_OPT_FMTYMD = 3, TDS_OPT_FMTYDM = 4, TDS_OPT_FMTMYD = 5, TDS_OPT_FMTDYM = 6
    00660 };
    00661 enum TDS_OPT_ISOLATION_CHOICE
    00662 {
    00663         TDS_OPT_LEVEL1 = 1, TDS_OPT_LEVEL3 = 3
    00664 };
    00665
    00666 typedef enum tds_packet_type
    00667 {
    00668         TDS_QUERY = 1,
    00669         TDS_LOGIN = 2,
    00670         TDS_RPC = 3,
    00671         TDS_REPLY = 4,
    00672         TDS_CANCEL = 6,
    00673         TDS_BULK = 7,
    00674         TDS_NORMAL = 15,
    00675         TDS7_LOGIN = 16,
    00676         TDS7_AUTH = 17,
    00677         TDS8_PRELOGIN = 18
    00678 } TDS_PACKET_TYPE;
    00679
    00680 typedef enum tds_encryption_level {
    00681         TDS_ENCRYPTION_OFF, TDS_ENCRYPTION_REQUEST, TDS_ENCRYPTION_REQUIRE
    00682 } TDS_ENCRYPTION_LEVEL;
    00683
    00684 #define TDS_ZERO_FREE(x) do {free((x)); (x) = NULL;} while(0)
    00685 #define TDS_VECTOR_SIZE(x) (sizeof(x)/sizeof(x[0]))
    00686
    00687 #if defined(__GNUC__) && __GNUC__ >= 3
    00688 # define TDS_LIKELY(x)  __builtin_expect(!!(x), 1)
    00689 # define TDS_UNLIKELY(x)        __builtin_expect(!!(x), 0)
    00690 #else
    00691 # define TDS_LIKELY(x)  (x)
    00692 # define TDS_UNLIKELY(x)        (x)
    00693 #endif
    00694
    00695 /*
    00696  * TODO use system macros for optimization
    00697  * See mcrypt for reference and linux kernel source for optimization
    00698  * check if unaligned access and use fast write/read when implemented
    00699  */
    00700 #define TDS_BYTE_SWAP16(value)                 \
    00701          (((((unsigned short)value)<<8) & 0xFF00)   | \
    00702           ((((unsigned short)value)>>8) & 0x00FF))
    00703
    00704 #define TDS_BYTE_SWAP32(value)                     \
    00705          (((((unsigned long)value)<<24) & 0xFF000000)  | \
    00706           ((((unsigned long)value)<< 8) & 0x00FF0000)  | \
    00707           ((((unsigned long)value)>> 8) & 0x0000FF00)  | \
    00708           ((((unsigned long)value)>>24) & 0x000000FF))
    00709
    00710 #define is_end_token(x) (x==TDS_DONE_TOKEN    || \
    00711                         x==TDS_DONEPROC_TOKEN    || \
    00712                         x==TDS_DONEINPROC_TOKEN)
    00713
    00714 #define is_hard_end_token(x) (x==TDS_DONE_TOKEN    || \
    00715                         x==TDS_DONEPROC_TOKEN)
    00716
    00717 #define is_msg_token(x) (x==TDS_INFO_TOKEN    || \
    00718                         x==TDS_ERROR_TOKEN    || \
    00719                         x==TDS_EED_TOKEN)
    00720
    00721 #define is_result_token(x) (x==TDS_RESULT_TOKEN || \
    00722                         x==TDS_ROWFMT2_TOKEN    || \
    00723                         x==TDS7_RESULT_TOKEN    || \
    00724                         x==TDS_COLFMT_TOKEN     || \
    00725                         x==TDS_COLNAME_TOKEN    || \
    00726                         x==TDS_RETURNSTATUS_TOKEN)
    00727
    00728 /* FIXME -- not a complete list */
    00729 #define is_fixed_type(x) (x==SYBINT1    || \
    00730                         x==SYBINT2      || \
    00731                         x==SYBINT4      || \
    00732                         x==SYBINT8      || \
    00733                         x==SYBREAL      || \
    00734                         x==SYBFLT8      || \
    00735                         x==SYBDATETIME  || \
    00736                         x==SYBDATETIME4 || \
    00737                         x==SYBBIT       || \
    00738                         x==SYBMONEY     || \
    00739                         x==SYBMONEY4    || \
    00740                         x==SYBVOID      || \
    00741                         x==SYBUNIQUE)
    00742 #define is_nullable_type(x) ( \
    00743                      x==SYBBITN      || \
    00744                      x==SYBINTN      || \
    00745                      x==SYBFLTN      || \
    00746                      x==SYBMONEYN    || \
    00747                      x==SYBDATETIMN  || \
    00748                      x==SYBVARCHAR   || \
    00749                      x==SYBVARBINARY || \
    00750                      x==SYBTEXT      || \
    00751                      x==SYBNTEXT     || \
    00752                      x==SYBIMAGE)
    00753
    00754 #define is_variable_type(x) ( \
    00755         (x)==SYBTEXT    || \
    00756         (x)==SYBIMAGE   || \
    00757         (x)==SYBNTEXT   || \
    00758         (x)==SYBCHAR    || \
    00759         (x)==SYBVARCHAR || \
    00760         (x)==SYBBINARY  || \
    00761         (x)==SYBVARBINARY       || \
    00762         (x)==SYBLONGBINARY      || \
    00763         (x)==XSYBCHAR   || \
    00764         (x)==XSYBVARCHAR        || \
    00765         (x)==XSYBNVARCHAR       || \
    00766         (x)==XSYBNCHAR)
    00767
    00768 #define is_blob_type(x) (x==SYBTEXT || x==SYBIMAGE || x==SYBNTEXT)
    00769 #define is_blob_col(x) ((x)->column_varint_size > 2)
    00770 /* large type means it has a two byte size field */
    00771 /* define is_large_type(x) (x>128) */
    00772 #define is_numeric_type(x) (x==SYBNUMERIC || x==SYBDECIMAL)
    00773 #define is_unicode_type(x) (x==XSYBNVARCHAR || x==XSYBNCHAR || x==SYBNTEXT || x==SYBMSXML)
    00774 #define is_collate_type(x) (x==XSYBVARCHAR || x==XSYBCHAR || x==SYBTEXT || x==XSYBNVARCHAR || x==XSYBNCHAR || x==SYBNTEXT)
    00775 #define is_ascii_type(x) ( x==XSYBCHAR || x==XSYBVARCHAR || x==SYBTEXT || x==SYBCHAR || x==SYBVARCHAR)
    00776 #define is_char_type(x) (is_unicode_type(x) || is_ascii_type(x))
    00777 #define is_similar_type(x, y) ((is_char_type(x) && is_char_type(y)) || ((is_unicode_type(x) && is_unicode_type(y))))
    00778
    00779
    00780 #define TDS_MAX_CAPABILITY      22
    00781 #define MAXPRECISION            77
    00782 #define TDS_MAX_CONN            4096
    00783 #define TDS_MAX_DYNID_LEN       30
    00784
    00785 /* defaults to use if no others are found */
    00786 #define TDS_DEF_SERVER          "SYBASE"
    00787 #define TDS_DEF_BLKSZ           512
    00788 #define TDS_DEF_CHARSET         "iso_1"
    00789 #define TDS_DEF_LANG            "us_english"
    00790 #if TDS42
    00791 #define TDS_DEFAULT_VERSION     0x402
    00792 #define TDS_DEF_PORT            1433
    00793 #elif TDS46
    00794 #define TDS_DEFAULT_VERSION     0x406
    00795 #define TDS_DEF_PORT            4000
    00796 #elif TDS70
    00797 #define TDS_DEFAULT_VERSION     0x700
    00798 #define TDS_DEF_PORT            1433
    00799 #elif TDS71
    00800 #define TDS_DEFAULT_VERSION     0x701
    00801 #define TDS_DEF_PORT            1433
    00802 #elif TDS72
    00803 #define TDS_DEFAULT_VERSION     0x702
    00804 #define TDS_DEF_PORT            1433
    00805 #else
    00806 #define TDS_DEFAULT_VERSION     0x500
    00807 #define TDS_DEF_PORT            4000
    00808 #endif
    00809
    00810 /* normalized strings from freetds.conf file */
    00811 #define TDS_STR_VERSION  "tds version"
    00812 #define TDS_STR_BLKSZ    "initial block size"
    00813 #define TDS_STR_SWAPDT   "swap broken dates"
    00814 #define TDS_STR_DUMPFILE "dump file"
    00815 #define TDS_STR_DEBUGLVL "debug level"
    00816 #define TDS_STR_DEBUGFLAGS "debug flags"
    00817 #define TDS_STR_TIMEOUT  "timeout"
    00818 #define TDS_STR_QUERY_TIMEOUT  "query timeout"
    00819 #define TDS_STR_CONNTIMEOUT "connect timeout"
    00820 #define TDS_STR_HOSTNAME "hostname"
    00821 #define TDS_STR_HOST     "host"
    00822 #define TDS_STR_PORT     "port"
    00823 #define TDS_STR_TEXTSZ   "text size"
    00824 /* for big endian hosts */
    00825 #define TDS_STR_EMUL_LE "emulate little endian"
    00826 #define TDS_STR_CHARSET "charset"
    00827 #define TDS_STR_CLCHARSET       "client charset"
    00828 #define TDS_STR_LANGUAGE        "language"
    00829 #define TDS_STR_APPENDMODE      "dump file append"
    00830 #define TDS_STR_DATEFMT "date format"
    00831 #define TDS_STR_INSTANCE "instance"
    00832 #define TDS_STR_ASA_DATABASE    "asa database"
    00833 #define TDS_STR_ENCRYPTION       "encryption"
    00834 #define TDS_STR_USENTLMV2       "use ntlmv2"
    00835 /* conf values */
    00836 #define TDS_STR_ENCRYPTION_OFF   "off"
    00837 #define TDS_STR_ENCRYPTION_REQUEST "request"
    00838 #define TDS_STR_ENCRYPTION_REQUIRE "require"
    00839 /* Defines to enable optional GSSAPI delegation */
    00840 #define TDS_GSSAPI_DELEGATION "enable gssapi delegation"
    00841 /* Kerberos realm name */
    00842 #define TDS_STR_REALM   "realm"
    00843
    00844
    00845 /* TODO do a better check for alignment than this */
    00846 typedef union
    00847 {
    00848         void *p;
    00849         int i;
    00850 } tds_align_struct;
    00851
    00852 #define TDS_ALIGN_SIZE sizeof(tds_align_struct)
    00853
    00854 #define TDS_MAX_LOGIN_STR_SZ 128
    00855 typedef struct tds_login
    00856 {
    00857         DSTR server_name;
    00858         int port;
    00859         TDS_USMALLINT tds_version;      /* TDS version */
    00860         int block_size;
    00861         DSTR language;                  /* e.g. us-english */
    00862         DSTR server_charset;            /* e.g. iso_1 */
    00863         TDS_INT connect_timeout;
    00864         DSTR client_host_name;
    00865         DSTR app_name;
    00866         DSTR user_name;
    00867         DSTR password;
    00868
    00869         DSTR library;   /* Ct-Library, DB-Library,  TDS-Library or ODBC */
    00870         TDS_TINYINT encryption_level;
    00871
    00872         TDS_INT query_timeout;
    00873         unsigned char capabilities[TDS_MAX_CAPABILITY];
    00874         DSTR client_charset;
    00875         DSTR database;
    00876         unsigned int bulk_copy:1;
    00877         unsigned int suppress_language:1;
    00878 } TDSLOGIN;
    00879
    00880 typedef struct tds_connection
    00881 {
    00882         /* first part of structure is the same of login one */
    00883         DSTR server_name;
    00884         int port;
    00885         TDS_USMALLINT tds_version;
    00886         int block_size;
    00887         DSTR language;
    00888         DSTR server_charset;
    00889         TDS_INT connect_timeout;
    00890         DSTR client_host_name;
    00891         DSTR server_host_name;
    00892         DSTR server_realm_name;
    00893         DSTR app_name;
    00894         DSTR user_name;
    00895         DSTR password;
    00896         DSTR library;
    00897         TDS_TINYINT encryption_level;
    00898
    00899         TDS_INT query_timeout;
    00900         unsigned char capabilities[TDS_MAX_CAPABILITY];
    00901         unsigned char option_flag2;
    00902         DSTR client_charset;
    00903
    00904         DSTR ip_addr;
    00905         DSTR instance_name;
    00906         DSTR database;
    00907         DSTR dump_file;
    00908         int debug_flags;
    00909         int text_size;
    00910         unsigned int broken_dates:1;
    00911         unsigned int emul_little_endian:1;
    00912         unsigned int bulk_copy:1;
    00913         unsigned int suppress_language:1;
    00914         unsigned int gssapi_use_delegation:1;
    00915         unsigned int use_ntlmv2:1;
    00916 } TDSCONNECTION;
    00917
    00918 typedef struct tds_locale
    00919 {
    00920         char *language;
    00921         char *server_charset;
    00922         char *date_fmt;
    00923 } TDSLOCALE;
    00924
    00929 typedef struct tds_blob
    00930 {
    00931         TDS_CHAR *textvalue;
    00932         TDS_CHAR textptr[16];
    00933         TDS_CHAR timestamp[8];
    00934 } TDSBLOB;
    00935
    00939 typedef struct tds_variant
    00940 {
    00941         /* this MUST have same position and place of textvalue in tds_blob */
    00942         TDS_CHAR *data;
    00943         TDS_INT size;
    00944         TDS_INT data_len;
    00945         TDS_UCHAR type;
    00946         TDS_UCHAR collation[5];
    00947 } TDSVARIANT;
    00948
    00952 typedef struct
    00953 {
    00954         TDS_USMALLINT locale_id;        /* master..syslanguages.lcid */
    00955         TDS_USMALLINT flags;
    00956         TDS_UCHAR charset_id;           /* or zero */
    00957 } TDS8_COLLATION;
    00958
    00959 /* SF stands for "sort flag" */
    00960 #define TDS_SF_BIN                   (TDS_USMALLINT) 0x100
    00961 #define TDS_SF_WIDTH_INSENSITIVE     (TDS_USMALLINT) 0x080
    00962 #define TDS_SF_KATATYPE_INSENSITIVE  (TDS_USMALLINT) 0x040
    00963 #define TDS_SF_ACCENT_SENSITIVE      (TDS_USMALLINT) 0x020
    00964 #define TDS_SF_CASE_INSENSITIVE      (TDS_USMALLINT) 0x010
    00965
    00966 /* UT stands for user type */
    00967 #define TDS_UT_TIMESTAMP             80
    00968
    00969
    00974 typedef struct tds_encoding
    00975 {
    00976         const char *name;
    00977         unsigned char min_bytes_per_char;
    00978         unsigned char max_bytes_per_char;
    00979         unsigned char canonic;
    00980 } TDS_ENCODING;
    00981
    00982 typedef struct tds_bcpcoldata
    00983 {
    00984         TDS_UCHAR *data;
    00985         TDS_INT    datalen;
    00986         TDS_INT    is_null;
    00987 } BCPCOLDATA;
    00988
    00989
    00990 enum
    00991 { TDS_SYSNAME_SIZE = 512 };
    00992
    00996 typedef struct tds_column
    00997 {
    00998         TDS_SMALLINT column_type;
    01003         TDS_INT column_usertype;
    01004         TDS_INT column_flags;
    01005
    01006         TDS_INT column_size;
    01008         TDS_TINYINT column_varint_size;
    01010         TDS_TINYINT column_prec;
    01011         TDS_TINYINT column_scale;
    01013         TDS_SMALLINT column_namelen;
    01014         TDS_SMALLINT table_namelen;
    01015         struct
    01016         {
    01017                 TDS_SMALLINT column_type;
    01018                 TDS_INT column_size;
    01019         } on_server;
    01020
    01021         TDSICONV *char_conv;
    01023         TDS_CHAR table_name[TDS_SYSNAME_SIZE];
    01024         TDS_CHAR column_name[TDS_SYSNAME_SIZE];
    01025         char * table_column_name;
    01026
    01027         unsigned char *column_data;
    01028         void (*column_data_free)(struct tds_column *column);
    01029         unsigned int column_nullable:1;
    01030         unsigned int column_writeable:1;
    01031         unsigned int column_identity:1;
    01032         unsigned int column_key:1;
    01033         unsigned int column_hidden:1;
    01034         unsigned int column_output:1;
    01035         unsigned int column_timestamp:1;
    01036         TDS_UCHAR column_collation[5];
    01037
    01038         /* additional fields flags for compute results */
    01039         TDS_TINYINT column_operator;
    01040         TDS_SMALLINT column_operand;
    01041
    01042         /* FIXME this is data related, not column */
    01044         TDS_INT column_cur_size;
    01045
    01046         /* related to binding or info stored by client libraries */
    01047         /* FIXME find a best place to store these data, some are unused */
    01048         TDS_SMALLINT column_bindtype;
    01049         TDS_SMALLINT column_bindfmt;
    01050         TDS_UINT column_bindlen;
    01051         TDS_SMALLINT *column_nullbind;
    01052         TDS_CHAR *column_varaddr;
    01053         TDS_INT *column_lenbind;
    01054         TDS_INT column_textpos;
    01055         TDS_INT column_text_sqlgetdatapos;
    01056         TDS_CHAR column_text_sqlputdatainfo;
    01057
    01058         BCPCOLDATA *bcp_column_data;
    01067         TDS_INT bcp_prefix_len;
    01068         TDS_INT bcp_term_len;
    01069         TDS_CHAR *bcp_terminator;
    01070 } TDSCOLUMN;
    01071
    01072
    01074 typedef struct tds_result_info
    01075 {
    01076         /* TODO those fields can became a struct */
    01077         TDS_SMALLINT num_cols;
    01078         TDSCOLUMN **columns;
    01079         TDS_INT row_size;
    01080         TDS_INT ref_count;
    01081         unsigned char *current_row;
    01082         void (*row_free)(struct tds_result_info* result, unsigned char *row);
    01083
    01084         TDS_SMALLINT rows_exist;
    01085         /* TODO remove ?? used only in dblib */
    01086         TDS_INT row_count;
    01087         /* TODO remove ?? used only in dblib */
    01088         TDS_TINYINT more_results;
    01089         TDS_SMALLINT computeid;
    01090         TDS_SMALLINT *bycolumns;
    01091         TDS_SMALLINT by_cols;
    01092 } TDSRESULTINFO;
    01093
    01095 typedef enum _TDS_STATE
    01096 {
    01097         TDS_IDLE,
    01098         TDS_QUERYING,
    01099         TDS_PENDING,
    01100         TDS_READING,
    01101         TDS_DEAD
    01102 } TDS_STATE;
    01103
    01104 #define TDS_DBG_LOGIN   __FILE__, ((__LINE__ << 4) | 11)
    01105 #define TDS_DBG_HEADER  __FILE__, ((__LINE__ << 4) | 10)
    01106 #define TDS_DBG_FUNC    __FILE__, ((__LINE__ << 4) |  7)
    01107 #define TDS_DBG_INFO2   __FILE__, ((__LINE__ << 4) |  6)
    01108 #define TDS_DBG_INFO1   __FILE__, ((__LINE__ << 4) |  5)
    01109 #define TDS_DBG_NETWORK __FILE__, ((__LINE__ << 4) |  4)
    01110 #define TDS_DBG_WARN    __FILE__, ((__LINE__ << 4) |  3)
    01111 #define TDS_DBG_ERROR   __FILE__, ((__LINE__ << 4) |  2)
    01112 #define TDS_DBG_SEVERE  __FILE__, ((__LINE__ << 4) |  1)
    01113
    01114 #define TDS_DBGFLAG_FUNC    0x80
    01115 #define TDS_DBGFLAG_INFO2   0x40
    01116 #define TDS_DBGFLAG_INFO1   0x20
    01117 #define TDS_DBGFLAG_NETWORK 0x10
    01118 #define TDS_DBGFLAG_WARN    0x08
    01119 #define TDS_DBGFLAG_ERROR   0x04
    01120 #define TDS_DBGFLAG_SEVERE  0x02
    01121 #define TDS_DBGFLAG_ALL     0xfff
    01122 #define TDS_DBGFLAG_LOGIN   0x0800
    01123 #define TDS_DBGFLAG_HEADER  0x0400
    01124 #define TDS_DBGFLAG_PID     0x1000
    01125 #define TDS_DBGFLAG_TIME    0x2000
    01126 #define TDS_DBGFLAG_SOURCE  0x4000
    01127 #define TDS_DBGFLAG_THREAD  0x8000
    01128
    01129 #if 0
    01130
    01135 enum TDS_DBG_LOG_STATE
    01136 {
    01137           TDS_DBG_LOGIN =  (1 << 0)
    01139         , TDS_DBG_API =    (1 << 1)
    01140         , TDS_DBG_ASYNC =  (1 << 2)
    01141         , TDS_DBG_DIAG =   (1 << 3)
    01142         , TDS_DBG_error =  (1 << 4)
    01143         /* TODO:  ^^^^^ make upper case when old #defines (above) are removed */
    01144         /* Log FreeTDS runtime/logic error occurs. */
    01145         , TDS_DBG_PACKET = (1 << 5)
    01146         , TDS_DBG_LIBTDS = (1 << 6)
    01147         , TDS_DBG_CONFIG = (1 << 7)
    01148         , TDS_DBG_DEFAULT = 0xFE
    01149 };
    01150 #endif
    01151
    01152 typedef struct tds_result_info TDSCOMPUTEINFO;
    01153
    01154 typedef TDSRESULTINFO TDSPARAMINFO;
    01155
    01156 typedef struct tds_message
    01157 {
    01158         TDS_CHAR *server;
    01159         TDS_CHAR *message;
    01160         TDS_CHAR *proc_name;
    01161         TDS_CHAR *sql_state;
    01162         TDS_UINT msgno;
    01163         TDS_INT line_number;
    01164         /* -1 .. 255 */
    01165         TDS_SMALLINT state;
    01166         TDS_TINYINT priv_msg_type;
    01167         TDS_TINYINT severity;
    01168         /* for library-generated errors */
    01169         int oserr;
    01170 } TDSMESSAGE;
    01171
    01172 typedef struct tds_upd_col
    01173 {
    01174         struct tds_upd_col *next;
    01175         TDS_INT colnamelength;
    01176         char * columnname;
    01177 } TDSUPDCOL;
    01178
    01179 typedef enum {
    01180           TDS_CURSOR_STATE_UNACTIONED = 0       /* initial value */
    01181         , TDS_CURSOR_STATE_REQUESTED = 1        /* called by ct_cursor */
    01182         , TDS_CURSOR_STATE_SENT = 2             /* sent to server */
    01183         , TDS_CURSOR_STATE_ACTIONED = 3         /* acknowledged by server */
    01184 } TDS_CURSOR_STATE;
    01185
    01186 typedef struct tds_cursor_status
    01187 {
    01188         TDS_CURSOR_STATE declare;
    01189         TDS_CURSOR_STATE cursor_row;
    01190         TDS_CURSOR_STATE open;
    01191         TDS_CURSOR_STATE fetch;
    01192         TDS_CURSOR_STATE close;
    01193         TDS_CURSOR_STATE dealloc;
    01194 } TDS_CURSOR_STATUS;
    01195
    01196 typedef enum tds_cursor_operation
    01197 {
    01198         TDS_CURSOR_POSITION = 0,
    01199         TDS_CURSOR_UPDATE = 1,
    01200         TDS_CURSOR_DELETE = 2,
    01201         TDS_CURSOR_INSERT = 4
    01202 } TDS_CURSOR_OPERATION;
    01203
    01204 typedef enum tds_cursor_fetch
    01205 {
    01206         TDS_CURSOR_FETCH_NEXT = 1,
    01207         TDS_CURSOR_FETCH_PREV,
    01208         TDS_CURSOR_FETCH_FIRST,
    01209         TDS_CURSOR_FETCH_LAST,
    01210         TDS_CURSOR_FETCH_ABSOLUTE,
    01211         TDS_CURSOR_FETCH_RELATIVE
    01212 } TDS_CURSOR_FETCH;
    01213
    01217 typedef struct tds_cursor
    01218 {
    01219         struct tds_cursor *next;
    01220         TDS_INT ref_count;
    01221         TDS_TINYINT cursor_name_len;
    01222         char *cursor_name;
    01223         TDS_INT cursor_id;
    01224         TDS_TINYINT options;
    01225         TDS_TINYINT hasargs;
    01226         TDS_USMALLINT query_len;
    01227         char *query;
    01228         /* TODO for updatable columns */
    01229         /* TDS_TINYINT number_upd_cols; */
    01230         /* TDSUPDCOL *cur_col_list; */
    01231         TDS_INT cursor_rows;
    01232         /* TDSPARAMINFO *params; */
    01233         TDS_CURSOR_STATUS status;
    01234         TDS_SMALLINT srv_status;
    01235         TDSRESULTINFO *res_info;
    01236         TDS_INT type, concurrency;
    01237 } TDSCURSOR;
    01238
    01242 typedef struct tds_env
    01243 {
    01244         int block_size;
    01245         char *language;
    01246         char *charset;
    01247         char *database;
    01248 } TDSENV;
    01249
    01253 typedef struct tds_dynamic
    01254 {
    01255         struct tds_dynamic *next;
    01261         char id[30];
    01262         /* int dyn_state; */ /* TODO use it */
    01264         TDS_INT num_id;
    01265         TDSPARAMINFO *res_info;
    01273         TDSPARAMINFO *params;
    01279         int emulated;
    01281         char *query;
    01282 } TDSDYNAMIC;
    01283
    01284 typedef enum {
    01285         TDS_MULTIPLE_QUERY,
    01286         TDS_MULTIPLE_EXECUTE,
    01287         TDS_MULTIPLE_RPC
    01288 } TDS_MULTIPLE_TYPE;
    01289
    01290 typedef struct tds_multiple
    01291 {
    01292         TDS_MULTIPLE_TYPE type;
    01293         unsigned int flags;
    01294 } TDSMULTIPLE;
    01295
    01296 /* forward declaration */
    01297 typedef struct tds_context TDSCONTEXT;
    01298 typedef int (*err_handler_t) (const TDSCONTEXT *, TDSSOCKET *, TDSMESSAGE *);
    01299
    01300 struct tds_context
    01301 {
    01302         TDSLOCALE *locale;
    01303         void *parent;
    01304         /* handlers */
    01305         int (*msg_handler) (const TDSCONTEXT *, TDSSOCKET *, TDSMESSAGE *);
    01306         int (*err_handler) (const TDSCONTEXT *, TDSSOCKET *, TDSMESSAGE *);
    01307         int (*int_handler) (void *);
    01308 };
    01309
    01310 enum TDS_ICONV_ENTRY
    01311 {
    01312           client2ucs2
    01313         , client2server_chardata
    01314         , iso2server_metadata
    01315         , initial_char_conv_count       /* keep last */
    01316 };
    01317
    01318 typedef struct tds_authentication
    01319 {
    01320         TDS_UCHAR *packet;
    01321         int packet_len;
    01322         int (*free)(TDSSOCKET * tds, struct tds_authentication * auth);
    01323         int (*handle_next)(TDSSOCKET * tds, struct tds_authentication * auth, size_t len);
    01324 } TDSAUTHENTICATION;
    01325
    01329 struct tds_socket
    01330 {
    01331         TDS_SYS_SOCKET s;
    01333         TDS_USMALLINT tds_version;
    01334         TDS_UINT product_version;
    01335         char *product_name;
    01336
    01337         unsigned char capabilities[TDS_MAX_CAPABILITY];
    01338         unsigned int broken_dates:1;
    01339         unsigned int emul_little_endian:1;
    01340         unsigned int use_iconv:1;
    01341         unsigned int tds71rev1:1;
    01342
    01343         unsigned char *in_buf;
    01344         unsigned char *out_buf;
    01345         unsigned int in_buf_max;
    01346         unsigned in_pos;
    01347         unsigned out_pos;
    01348         unsigned in_len;
    01350         unsigned char in_flag;
    01351         unsigned char out_flag;
    01352         void *parent;
    01353
    01359         TDSRESULTINFO *current_results;
    01360         TDSRESULTINFO *res_info;
    01361         TDS_INT num_comp_info;
    01362         TDSCOMPUTEINFO **comp_info;
    01363         TDSPARAMINFO *param_info;
    01364         TDSCURSOR *cur_cursor;
    01365         TDSCURSOR *cursors;
    01366         TDS_TINYINT has_status;
    01367         TDS_INT ret_status;
    01368         TDS_STATE state;
    01369
    01370         volatile
    01371         unsigned char in_cancel;
    01373         TDS_INT8 rows_affected;
    01374         TDS_INT query_timeout;
    01375         TDSENV env;
    01376
    01377         TDSDYNAMIC *cur_dyn;
    01378         TDSDYNAMIC *dyns;
    01380         const TDSCONTEXT *tds_ctx;
    01381         int char_conv_count;
    01382         TDSICONV **char_convs;
    01383
    01384         TDSCONNECTION *connection;
    01386         int spid;
    01387         TDS_UCHAR collation[5];
    01388         TDS_UCHAR tds9_transaction[8];
    01389         void (*env_chg_func) (TDSSOCKET * tds, int type, char *oldval, char *newval);
    01390         int internal_sp_called;
    01391
    01392         void *tls_session;
    01393         void *tls_credentials;
    01394         TDSAUTHENTICATION *authentication;
    01395         int option_value;
    01396 };
    01397
    01398 int tds_init_write_buf(TDSSOCKET * tds);
    01399 void tds_free_result_info(TDSRESULTINFO * info);
    01400 void tds_free_socket(TDSSOCKET * tds);
    01401 void tds_free_connection(TDSCONNECTION * connection);
    01402 void tds_free_all_results(TDSSOCKET * tds);
    01403 void tds_free_results(TDSRESULTINFO * res_info);
    01404 void tds_free_param_results(TDSPARAMINFO * param_info);
    01405 void tds_free_param_result(TDSPARAMINFO * param_info);
    01406 void tds_free_msg(TDSMESSAGE * message);
    01407 void tds_cursor_deallocated(TDSSOCKET *tds, TDSCURSOR *cursor);
    01408 void tds_release_cursor(TDSSOCKET *tds, TDSCURSOR *cursor);
    01409 void tds_free_bcp_column_data(BCPCOLDATA * coldata);
    01410
    01411 int tds_put_n(TDSSOCKET * tds, const void *buf, size_t n);
    01412 int tds_put_string(TDSSOCKET * tds, const char *buf, int len);
    01413 int tds_put_int(TDSSOCKET * tds, TDS_INT i);
    01414 int tds_put_int8(TDSSOCKET * tds, TDS_INT8 i);
    01415 int tds_put_smallint(TDSSOCKET * tds, TDS_SMALLINT si);
    01417 #define tds_put_tinyint(tds, ti) tds_put_byte(tds,ti)
    01418 int tds_put_byte(TDSSOCKET * tds, unsigned char c);
    01419 TDSRESULTINFO *tds_alloc_results(int num_cols);
    01420 TDSCOMPUTEINFO **tds_alloc_compute_results(TDSSOCKET * tds, int num_cols, int by_cols);
    01421 TDSCONTEXT *tds_alloc_context(void * parent);
    01422 void tds_free_context(TDSCONTEXT * locale);
    01423 TDSSOCKET *tds_alloc_socket(TDSCONTEXT * context, int bufsize);
    01424
    01425 /* config.c */
    01426 int tds_default_port(int major, int minor);
    01427 const TDS_COMPILETIME_SETTINGS *tds_get_compiletime_settings(void);
    01428 typedef void (*TDSCONFPARSE) (const char *option, const char *value, void *param);
    01429 int tds_read_conf_section(FILE * in, const char *section, TDSCONFPARSE tds_conf_parse, void *parse_param);
    01430 int tds_read_conf_file(TDSCONNECTION * connection, const char *server);
    01431 void tds_parse_conf_section(const char *option, const char *value, void *param);
    01432 TDSCONNECTION *tds_read_config_info(TDSSOCKET * tds, TDSLOGIN * login, TDSLOCALE * locale);
    01433 void tds_fix_connection(TDSCONNECTION * connection);
    01434 TDS_USMALLINT tds_config_verstr(const char *tdsver, TDSCONNECTION * connection);
    01435 int tds_lookup_host(const char *servername, char *ip);
    01436 int tds_set_interfaces_file_loc(const char *interfloc);
    01437 extern const char STD_DATETIME_FMT[];
    01438 int tds_config_boolean(const char *value);
    01439
    01440 TDSLOCALE *tds_get_locale(void);
    01441 int tds_alloc_row(TDSRESULTINFO * res_info);
    01442 int tds_alloc_compute_row(TDSCOMPUTEINFO * res_info);
    01443 BCPCOLDATA * tds_alloc_bcp_column_data(int column_size);
    01444 unsigned char *tds7_crypt_pass(const unsigned char *clear_pass, size_t len, unsigned char *crypt_pass);
    01445 TDSDYNAMIC *tds_lookup_dynamic(TDSSOCKET * tds, const char *id);
    01446 /*@observer@*/ const char *tds_prtype(int token);
    01447 int tds_get_varint_size(TDSSOCKET * tds, int datatype);
    01448 int tds_get_cardinal_type(int datatype, int usertype);
    01449
    01450
    01451
    01452 /* iconv.c */
    01453 void tds_iconv_open(TDSSOCKET * tds, const char *charset);
    01454 void tds_iconv_close(TDSSOCKET * tds);
    01455 void tds_srv_charset_changed(TDSSOCKET * tds, const char *charset);
    01456 void tds7_srv_charset_changed(TDSSOCKET * tds, int sql_collate, int lcid);
    01457 int tds_iconv_alloc(TDSSOCKET * tds);
    01458 void tds_iconv_free(TDSSOCKET * tds);
    01459 TDSICONV *tds_iconv_from_collate(TDSSOCKET * tds, TDS_UCHAR collate[5]);
    01460
    01461 /* threadsafe.c */
    01462 char *tds_timestamp_str(char *str, int maxlen);
    01463 struct tm *tds_localtime_r(const time_t *timep, struct tm *result);
    01464 struct hostent *tds_gethostbyname_r(const char *servername, struct hostent *result, char *buffer, int buflen, int *h_errnop);
    01465 struct hostent *tds_gethostbyaddr_r(const char *addr, int len, int type, struct hostent *result, char *buffer, int buflen,
    01466                                     int *h_errnop);
    01467 struct servent *tds_getservbyname_r(const char *name, const char *proto, struct servent *result, char *buffer, int buflen);
    01468 #ifdef INADDR_NONE
    01469 const char *tds_inet_ntoa_r(struct in_addr iaddr, char *ip, size_t len);
    01470 #endif
    01471 char *tds_get_homedir(void);
    01472
    01473 /* mem.c */
    01474 TDSPARAMINFO *tds_alloc_param_result(TDSPARAMINFO * old_param);
    01475 void tds_free_input_params(TDSDYNAMIC * dyn);
    01476 void tds_free_dynamic(TDSSOCKET * tds, TDSDYNAMIC * dyn);
    01477 TDSSOCKET *tds_realloc_socket(TDSSOCKET * tds, size_t bufsize);
    01478 char *tds_alloc_client_sqlstate(int msgno);
    01479 char *tds_alloc_lookup_sqlstate(TDSSOCKET * tds, int msgno);
    01480 TDSLOGIN *tds_alloc_login(void);
    01481 TDSDYNAMIC *tds_alloc_dynamic(TDSSOCKET * tds, const char *id);
    01482 void tds_free_login(TDSLOGIN * login);
    01483 TDSCONNECTION *tds_alloc_connection(TDSLOCALE * locale);
    01484 TDSLOCALE *tds_alloc_locale(void);
    01485 void *tds_alloc_param_data(TDSCOLUMN * curparam);
    01486 void tds_free_locale(TDSLOCALE * locale);
    01487 TDSCURSOR * tds_alloc_cursor(TDSSOCKET * tds, const char *name, TDS_INT namelen, const char *query, TDS_INT querylen);
    01488 void tds_free_row(TDSRESULTINFO * res_info, unsigned char *row);
    01489
    01490 /* login.c */
    01491 void tds_set_packet(TDSLOGIN * tds_login, int packet_size);
    01492 void tds_set_port(TDSLOGIN * tds_login, int port);
    01493 void tds_set_passwd(TDSLOGIN * tds_login, const char *password);
    01494 void tds_set_bulk(TDSLOGIN * tds_login, TDS_TINYINT enabled);
    01495 void tds_set_user(TDSLOGIN * tds_login, const char *username);
    01496 void tds_set_app(TDSLOGIN * tds_login, const char *application);
    01497 void tds_set_host(TDSLOGIN * tds_login, const char *hostname);
    01498 void tds_set_library(TDSLOGIN * tds_login, const char *library);
    01499 void tds_set_server(TDSLOGIN * tds_login, const char *server);
    01500 void tds_set_client_charset(TDSLOGIN * tds_login, const char *charset);
    01501 void tds_set_language(TDSLOGIN * tds_login, const char *language);
    01502 void tds_set_database_name(TDSLOGIN * tds_login, const char *dbname);
    01503 void tds_set_version(TDSLOGIN * tds_login, TDS_TINYINT major_ver, TDS_TINYINT minor_ver);
    01504 void tds_set_capabilities(TDSLOGIN * tds_login, unsigned char *capabilities, int size);
    01505 int tds_connect_and_login(TDSSOCKET * tds, TDSCONNECTION * connection);
    01506
    01507 /* query.c */
    01508 int tds_submit_query(TDSSOCKET * tds, const char *query);
    01509 int tds_submit_query_params(TDSSOCKET * tds, const char *query, TDSPARAMINFO * params);
    01510 int tds_submit_queryf(TDSSOCKET * tds, const char *queryf, ...);
    01511 int tds_submit_prepare(TDSSOCKET * tds, const char *query, const char *id, TDSDYNAMIC ** dyn_out, TDSPARAMINFO * params);
    01512 int tds_submit_execdirect(TDSSOCKET * tds, const char *query, TDSPARAMINFO * params);
    01513 int tds8_submit_prepexec(TDSSOCKET * tds, const char *query, const char *id, TDSDYNAMIC ** dyn_out, TDSPARAMINFO * params);
    01514 int tds_submit_execute(TDSSOCKET * tds, TDSDYNAMIC * dyn);
    01515 int tds_send_cancel(TDSSOCKET * tds);
    01516 const char *tds_next_placeholder(const char *start);
    01517 int tds_count_placeholders(const char *query);
    01518 int tds_needs_unprepare(TDSSOCKET * tds, TDSDYNAMIC * dyn);
    01519 int tds_submit_unprepare(TDSSOCKET * tds, TDSDYNAMIC * dyn);
    01520 int tds_submit_rpc(TDSSOCKET * tds, const char *rpc_name, TDSPARAMINFO * params);
    01521 int tds_submit_optioncmd(TDSSOCKET * tds, TDS_OPTION_CMD command, TDS_OPTION option, TDS_OPTION_ARG *param, TDS_INT param_size);
    01522 int tds_quote_id(TDSSOCKET * tds, char *buffer, const char *id, int idlen);
    01523 int tds_quote_string(TDSSOCKET * tds, char *buffer, const char *str, int len);
    01524 const char *tds_skip_quoted(const char *s);
    01525
    01526 int tds_cursor_declare(TDSSOCKET * tds, TDSCURSOR * cursor, TDSPARAMINFO *params, int *send);
    01527 int tds_cursor_setrows(TDSSOCKET * tds, TDSCURSOR * cursor, int *send);
    01528 int tds_cursor_open(TDSSOCKET * tds, TDSCURSOR * cursor, TDSPARAMINFO *params, int *send);
    01529 int tds_cursor_fetch(TDSSOCKET * tds, TDSCURSOR * cursor, TDS_CURSOR_FETCH fetch_type, TDS_INT i_row);
    01530 int tds_cursor_get_cursor_info(TDSSOCKET * tds, TDSCURSOR * cursor, TDS_UINT * row_number, TDS_UINT * row_count);
    01531 int tds_cursor_close(TDSSOCKET * tds, TDSCURSOR * cursor);
    01532 int tds_cursor_dealloc(TDSSOCKET * tds, TDSCURSOR * cursor);
    01533 int tds_cursor_update(TDSSOCKET * tds, TDSCURSOR * cursor, TDS_CURSOR_OPERATION op, TDS_INT i_row, TDSPARAMINFO * params);
    01534 int tds_cursor_setname(TDSSOCKET * tds, TDSCURSOR * cursor);
    01535
    01536 int tds_multiple_init(TDSSOCKET *tds, TDSMULTIPLE *multiple, TDS_MULTIPLE_TYPE type);
    01537 int tds_multiple_done(TDSSOCKET *tds, TDSMULTIPLE *multiple);
    01538 int tds_multiple_query(TDSSOCKET *tds, TDSMULTIPLE *multiple, const char *query, TDSPARAMINFO * params);
    01539 int tds_multiple_execute(TDSSOCKET *tds, TDSMULTIPLE *multiple, TDSDYNAMIC * dyn);
    01540
    01541 /* token.c */
    01542 int tds_process_cancel(TDSSOCKET * tds);
    01543 #ifdef WORDS_BIGENDIAN
    01544 void tds_swap_datatype(int coltype, unsigned char *buf);
    01545 #endif
    01546 void tds_swap_numeric(TDS_NUMERIC *num);
    01547 int tds_get_token_size(int marker);
    01548 int tds_process_login_tokens(TDSSOCKET * tds);
    01549 int tds_process_simple_query(TDSSOCKET * tds);
    01550 int tds5_send_optioncmd(TDSSOCKET * tds, TDS_OPTION_CMD tds_command, TDS_OPTION tds_option, TDS_OPTION_ARG * tds_argument,
    01551                         TDS_INT * tds_argsize);
    01552 int tds_process_tokens(TDSSOCKET * tds, /*@out@*/ TDS_INT * result_type, /*@out@*/ int *done_flags, unsigned flag);
    01553
    01554 /* data.c */
    01555 void tds_set_param_type(TDSSOCKET * tds, TDSCOLUMN * curcol, TDS_SERVER_TYPE type);
    01556 void tds_set_column_type(TDSSOCKET * tds, TDSCOLUMN * curcol, int type);
    01557 TDS_INT tds_data_get_info(TDSSOCKET *tds, TDSCOLUMN *col);
    01558
    01559
    01560 /* tds_convert.c */
    01561 TDS_INT tds_datecrack(TDS_INT datetype, const void *di, TDSDATEREC * dr);
    01562 int tds_get_conversion_type(int srctype, int colsize);
    01563 extern const char tds_hex_digits[];
    01564
    01565 /* write.c */
    01566 int tds_flush_packet(TDSSOCKET * tds);
    01567 int tds_put_buf(TDSSOCKET * tds, const unsigned char *buf, int dsize, int ssize);
    01568
    01569 /* read.c */
    01570 unsigned char tds_get_byte(TDSSOCKET * tds);
    01571 void tds_unget_byte(TDSSOCKET * tds);
    01572 unsigned char tds_peek(TDSSOCKET * tds);
    01573 TDS_SMALLINT tds_get_smallint(TDSSOCKET * tds);
    01574 TDS_INT tds_get_int(TDSSOCKET * tds);
    01575 TDS_INT8 tds_get_int8(TDSSOCKET * tds);
    01576 int tds_get_string(TDSSOCKET * tds, int string_len, char *dest, size_t dest_size);
    01577 int tds_get_char_data(TDSSOCKET * tds, char *dest, size_t wire_size, TDSCOLUMN * curcol);
    01578 void *tds_get_n(TDSSOCKET * tds, /*@out@*/ /*@null@*/ void *dest, int n);
    01579 int tds_get_size_by_type(int servertype);
    01580
    01581
    01582 /* util.c */
    01583 int tdserror (const TDSCONTEXT * tds_ctx, TDSSOCKET * tds, int msgno, int errnum);
    01584 TDS_STATE tds_set_state(TDSSOCKET * tds, TDS_STATE state);
    01585 void tds_set_parent(TDSSOCKET * tds, void *the_parent);
    01586 int tds_swap_bytes(unsigned char *buf, int bytes);
    01587 int tds_version(TDSSOCKET * tds_socket, char *pversion_string);
    01588 unsigned int tds_gettime_ms(void);
    01589 int tds_get_req_capability(TDSSOCKET * tds, int cap);
    01590
    01591 /* log.c */
    01592 void tdsdump_off(void);
    01593 void tdsdump_on(void);
    01594 int tdsdump_isopen(void);
    01595 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
    01596 #pragma GCC visibility pop
    01597 #endif
    01598 int tdsdump_open(const char *filename);
    01599 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
    01600 #pragma GCC visibility push(hidden)
    01601 #endif
    01602 void tdsdump_close(void);
    01603 void tdsdump_dump_buf(const char* file, unsigned int level_line, const char *msg, const void *buf, size_t length);
    01604 void tdsdump_col(const TDSCOLUMN *col);
    01605 #undef tdsdump_log
    01606 void tdsdump_log(const char* file, unsigned int level_line, const char *fmt, ...)
    01607 #if defined(__GNUC__) && __GNUC__ >= 2
    01608         __attribute__ ((__format__ (__printf__, 3, 4)))
    01609 #endif
    01610 ;
    01611 #define tdsdump_log if (TDS_UNLIKELY(tds_write_dump)) tdsdump_log
    01612
    01613 extern int tds_write_dump;
    01614 extern int tds_debug_flags;
    01615 extern int tds_g_append_mode;
    01616
    01617 /* net.c */
    01618 int tds_lastpacket(TDSSOCKET * tds);
    01619 TDSERRNO tds_open_socket(TDSSOCKET * tds, const char *ip_addr, unsigned int port, int timeout, int *p_oserr);
    01620 int tds_close_socket(TDSSOCKET * tds);
    01621 int tds_read_packet(TDSSOCKET * tds);
    01622 int tds_write_packet(TDSSOCKET * tds, unsigned char final);
    01623 int tds7_get_instance_ports(FILE *output, const char *ip_addr);
    01624 int tds7_get_instance_port(const char *ip_addr, const char *instance);
    01625 int tds_ssl_init(TDSSOCKET *tds);
    01626 void tds_ssl_deinit(TDSSOCKET *tds);
    01627 const char *tds_prwsaerror(int erc);
    01628
    01629
    01630
    01631 /* vstrbuild.c */
    01632 int tds_vstrbuild(char *buffer, int buflen, int *resultlen, char *text, int textlen, const char *formats, int formatlen,
    01633                   va_list ap);
    01634
    01635 /* numeric.c */
    01636 char *tds_money_to_string(const TDS_MONEY * money, char *s);
    01637 TDS_INT tds_numeric_to_string(const TDS_NUMERIC * numeric, char *s);
    01638 TDS_INT tds_numeric_change_prec_scale(TDS_NUMERIC * numeric, unsigned char new_prec, unsigned char new_scale);
    01639
    01640 /* getmac.c */
    01641 void tds_getmac(TDS_SYS_SOCKET s, unsigned char mac[6]);
    01642
    01643 #ifndef HAVE_SSPI
    01644 TDSAUTHENTICATION * tds_ntlm_get_auth(TDSSOCKET * tds);
    01645 TDSAUTHENTICATION * tds_gss_get_auth(TDSSOCKET * tds);
    01646 #else
    01647 TDSAUTHENTICATION * tds_sspi_get_auth(TDSSOCKET * tds);
    01648 #endif
    01649
    01650 /* bulk.c */
    01651
    01653 enum tds_bcp_directions
    01654 {
    01655         TDS_BCP_IN = 1,
    01656         TDS_BCP_OUT = 2,
    01657         TDS_BCP_QUERYOUT = 3
    01658 };
    01659
    01660 typedef struct tds_bcpinfo
    01661 {
    01662         const char *hint;
    01663         void *parent;
    01664         TDS_CHAR *tablename;
    01665         TDS_CHAR *insert_stmt;
    01666         TDS_INT direction;
    01667         TDS_INT identity_insert_on;
    01668         TDS_INT xfer_init;
    01669         TDS_INT var_cols;
    01670         TDS_INT bind_count;
    01671         TDSRESULTINFO *bindinfo;
    01672 } TDSBCPINFO;
    01673
    01674 int tds_bcp_init(TDSSOCKET *tds, TDSBCPINFO *bcpinfo);
    01675 typedef int  (*tds_bcp_get_col_data) (TDSBCPINFO *bulk, TDSCOLUMN *bcpcol, int offset);
    01676 typedef void (*tds_bcp_null_error)   (TDSBCPINFO *bulk, int index, int offset);
    01677 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);
    01678 int tds_bcp_done(TDSSOCKET *tds, int *rows_copied);
    01679 int tds_bcp_start(TDSSOCKET *tds, TDSBCPINFO *bcpinfo);
    01680 int tds_bcp_start_copy_in(TDSSOCKET *tds, TDSBCPINFO *bcpinfo);
    01681
    01682 int tds_writetext_start(TDSSOCKET *tds, const char *objname, const char *textptr, const char *timestamp, int with_log, TDS_UINT size);
    01683 int tds_writetext_continue(TDSSOCKET *tds, const TDS_UCHAR *text, TDS_UINT size);
    01684 int tds_writetext_end(TDSSOCKET *tds);
    01685
    01686
    01687 #define IS_TDS42(x) (x->tds_version==0x402)
    01688 #define IS_TDS46(x) (x->tds_version==0x406)
    01689 #define IS_TDS50(x) (x->tds_version==0x500)
    01690 #define IS_TDS70(x) (x->tds_version==0x700)
    01691 #define IS_TDS71(x) (x->tds_version==0x701)
    01692 #define IS_TDS72(x) (x->tds_version==0x702)
    01693
    01694 #define IS_TDS7_PLUS(x) ((x)->tds_version>=0x700)
    01695 #define IS_TDS71_PLUS(x) ((x)->tds_version>=0x701)
    01696 #define IS_TDS72_PLUS(x) ((x)->tds_version>=0x702)
    01697
    01698 #define TDS_MAJOR(x) ((x)->tds_version >> 8)
    01699 #define TDS_MINOR(x) ((x)->tds_version & 0xff)
    01700
    01701 #define IS_TDSDEAD(x) (((x) == NULL) || TDS_IS_SOCKET_INVALID((x)->s))
    01702
    01704 #define TDS_IS_SYBASE(x) (!(x->product_version & 0x80000000u))
    01705
    01706 #define TDS_IS_MSSQL(x) ((x->product_version & 0x80000000u)!=0)
    01707
    01711 #define TDS_MS_VER(maj,min,x) (0x80000000u|((maj)<<24)|((min)<<16)|(x))
    01712
    01713 /* TODO test if not similar to ms one*/
    01715 #define TDS_SYB_VER(maj,min,x) (((maj)<<24)|((min)<<16)|(x)<<8)
    01716
    01717 #ifdef __cplusplus
    01718 #if 0
    01719 {
    01720 #endif
    01721 }
    01722 #endif
    01723
    01724 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
    01725 #pragma GCC visibility pop
    01726 #endif
    01727
    01728 #define TDS_PUT_INT(tds,v) tds_put_int((tds), ((TDS_INT)(v)))
    01729 #define TDS_PUT_SMALLINT(tds,v) tds_put_smallint((tds), ((TDS_SMALLINT)(v)))
    01730 #define TDS_PUT_BYTE(tds,v) tds_put_byte((tds), ((unsigned char)(v)))
    01731
    01732 #endif /* _tds_h_ */

All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines