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