home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer) / NeXT_Developer-3.3.iso / usr / sybase / include4_0 / sybdb.h next >
Encoding:
C/C++ Source or Header  |  1993-03-19  |  47.8 KB  |  1,556 lines

  1. /*
  2.  *    sybdb.h    62.2    4/11/90
  3.  *
  4.  *    Sybase DB-LIBRARY Version 4.0
  5.  *    Confidential Property of Sybase, Inc.
  6.  *    (c) Copyright Sybase, Inc. 1988, 1989
  7.  *    All rights reserved
  8.  *
  9.  *
  10.  * Use, duplication, or disclosure by the United States Government
  11.  * is subject to restrictions as set forth in subparagraph (c) (1) (ii)
  12.  * of the Rights in Technical Data and Computer Software clause
  13.  * at CFR 52.227-7013. Sybase, Inc. 6475 Christie Avenue, Emeryville,
  14.  * CA 94608.
  15.  *
  16.  */
  17.  
  18. /* temporarily undef ABS since there is one in sybdbtokens.h */
  19. #ifdef    ABS
  20. #undef    ABS
  21. #endif    /* ABS */
  22. #include    <sybdbtoken.h>
  23. #ifdef    ABS
  24. #undef    ABS
  25. #endif    /* ABS */
  26. #define    ABS(a)        ((a) > 0 ? (a) : -(a))
  27.  
  28. /*
  29. **  Status code for dbnextrow() and dbgetrow().
  30. **  Return of > 0 indicates ALTROW.
  31. **  FAIL is another possible return.
  32. */
  33. #define    MORE_ROWS    -1
  34. #define    NO_MORE_ROWS    -2
  35. #define    REG_ROW        MORE_ROWS
  36. #define    BUF_FULL    -3
  37.  
  38. /*
  39. **  Status code for dbresults(). Possible return values are
  40. **  SUCCEED, FAIL, and NO_MORE_RESULTS.
  41. */
  42. #define NO_MORE_RESULTS    2
  43.  
  44. /*
  45. **  Return code for message-handlers. Indicates whether or not the handler
  46. **  wants DB-LIBRARY to buffer the current Server message for later use
  47. **  by the program.
  48. */
  49. #define DBSAVE        1
  50. #define DBNOSAVE    0
  51.  
  52. #define DBNOERR        -1
  53.  
  54. /*
  55. ** Default size of row buffer.  This is what people get if they do
  56. ** a dbsetopt(dbproc, DBBUFFER, 0).
  57. */
  58. #define    DBBUFSIZE    1000
  59.  
  60. /* The size of a SYBTEXT timestamp, in bytes. This timestamp is not to be
  61.  * confused with a browse-mode timestamp.
  62.  */
  63. #define DBTXTSLEN    8
  64.  
  65. /* The size of a text-pointer, in bytes. */
  66. #if !VMS
  67. #define DBTXPLEN    ((DBTINYINT)16)
  68. #else
  69. #define DBTXPLEN    ((unsigned char)16)
  70. #endif
  71.  
  72. /*
  73. ** this is defined in the SQL Server server.h but it has alot of other 
  74. ** stuff that we don't want.
  75. */
  76. #define    MAXNAME    30
  77.  
  78. #include    <syblogin.h>
  79.  
  80. #define    DBMAXCHAR    256
  81. #define    DBMAXCOLNAME    30
  82. #define    DBMAXBYLIST    16
  83.  
  84. /* maximum printing lengths for fixed-length data */
  85. #define    PRINT4    11
  86. #define    PRINT2    6
  87. #define    PRINT1    3
  88. #define    PRFLT8    20
  89. #define    PRMONEY    24
  90. #define    PRBIT    1
  91. #define    PRDATETIME    20
  92. #define    PRLDATETIME    24    /* includes milliseconds */
  93.  
  94. /* SQL Server variable typedefs */
  95. typedef    unsigned short    DBUSMALLINT;    /* SQL Server 2 byte integer */
  96. typedef struct dbvarychar        /* Pascal-type string. */
  97. {
  98.     DBSMALLINT    len;        /* length of the character string */
  99.     DBCHAR        str[DBMAXCHAR];    /* string, with no NULL terminator */
  100. } DBVARYCHAR;
  101. typedef struct dbvarybin        /* Pascal-type binary array. */
  102. {
  103.     DBSMALLINT    len;        /* length of the binary array */
  104.     BYTE        array[DBMAXCHAR];/* the array itself. */
  105. } DBVARYBIN;
  106.  
  107. #define    TINYBIND    1
  108. #define    SMALLBIND    2
  109. #define    INTBIND        3
  110. #define    CHARBIND    4
  111. #define    TEXTBIND    5
  112. #define    BINARYBIND    6
  113. #define    ARRAYBIND    7
  114. #define    BITBIND        8
  115. #define    DATETIMEBIND    9
  116. #define    MONEYBIND    10
  117. #define    FLT8BIND    11
  118. #define    STRINGBIND    12
  119. #define    NTBSTRINGBIND    13
  120. #define VARYCHARBIND    14
  121. #define VARYBINBIND    15
  122. #if VOS
  123. #define    FIXEDBIND    16            /*kvk589*/
  124. #define PACKEDBIND    17            /*kvk589*/
  125. #define MAXBIND        PACKEDBIND        /*kvk589*/
  126. #else
  127. #define MAXBIND        VARYBINBIND
  128. #endif
  129.  
  130. /*
  131. ** From pss.h SQL Server structure.
  132. */
  133. /* Donepacket status bit defs go here */
  134. # define DONE_CONT    (DBUSMALLINT) 0x1    
  135. # define DONE_ERROR    (DBUSMALLINT) 0x2
  136. # define DONE_INXACT    (DBUSMALLINT) 0x4
  137. # define DONE_PROC    (DBUSMALLINT) 0x8
  138. # define DONE_COUNT    (DBUSMALLINT) 0x10
  139. # define DONE_ATTN    (DBUSMALLINT) 0x20
  140.  
  141. /*
  142. **    OFFSETS DEFINITIONS
  143. **
  144. **    These are a subset of the token values for offset information.
  145. **    These defines come from y.tab.h
  146. **
  147. */
  148. # define _ID 290
  149. # define _VARIABLE 291
  150. # define _STRING 292
  151. # define _BINARY 295
  152. # define _LABEL 296
  153. # define _INTEGER 293
  154. # define _REAL 294
  155. # define _MONEY 297
  156. # define _START 299
  157. # define _REQJOIN 280
  158. # define _LEQJOIN 281
  159. # define _MINKEYWORD 300
  160. # define _ADD 445
  161. # define _ALL 300
  162. # define _ALTER 444
  163. # define _AND 301
  164. # define _ANY 302
  165. # define _AS 305
  166. # define _ASC 306
  167. # define _AVG 307
  168. # define _BEGIN 385
  169. # define _BETWEEN 308
  170. # define _BREAK 408
  171. # define _BROWSE 309
  172. # define _BULK 430
  173. # define _BY 310
  174. # define _CHARINDEX 434
  175. # define _CHECKPOINT 400
  176. # define _CLUSTERED 311
  177. # define _COL_LENGTH 433
  178. # define _COL_NAME 332
  179. # define _COMMIT 458
  180. # define _COMPUTE 313
  181. # define _CONFIRM 314
  182. # define _CONTINUE 412
  183. # define _CONTROLROW 315
  184. # define _CONVERT 447
  185. # define _COUNT 316
  186. # define _CREATE 317
  187. # define _DATABASE 318
  188. # define _DATEADD 439
  189. # define _DATEDIFF 440
  190. # define _DATENAME 441
  191. # define _DATEPART 442
  192. # define _DBCC 399
  193. # define _DB_ID 428
  194. # define _DB_NAME 429
  195. # define _DEBUG 398
  196. # define _DECLARE 404
  197. # define _DEFAULT 402
  198. # define _DEFINE 319
  199. # define _DELETE 320
  200. # define _DESC 321
  201. # define _DISK 460
  202. # define _DISTINCT 322
  203. # define _DROP 323
  204. # define _DUMMY 324
  205. # define _DUMP 390
  206. # define _ELSE 406
  207. # define _END 386
  208. # define _ERRLVL 328
  209. # define _ERROREXIT 453
  210. # define _EXECUTE 330
  211. # define _EXISTS 331
  212. # define _EXIT 411
  213. # define _FILLFACTOR 333
  214. # define _FOR 419
  215. # define _FROM 335
  216. # define _GETDATE 443
  217. # define _GETDEFAULT 432
  218. # define _GOTO 409
  219. # define _GRANT 336
  220. # define _GROUP 337
  221. # define _HAVING 338
  222. # define _HOLDLOCK 413
  223. # define _HOST_ID 426
  224. # define _HOST_NAME 427
  225. # define _IF 405
  226. # define _IN 341
  227. # define _INDEX 342
  228. # define _INDEX_KEY 437
  229. # define _INSERT 343
  230. # define _INTO 344
  231. # define _IS 382
  232. # define _ISNULL 436
  233. # define _KILL 463
  234. # define _LIKE 438
  235. # define _LINENO 345
  236. # define _LOAD 391
  237. # define _LOG 393
  238. # define _MAX 346
  239. # define _MIN 347
  240. # define _NONCLUSTERED 349
  241. # define _NOT 350
  242. # define _NULL 351
  243. # define _OBJECT_ID 372
  244. # define _OBJECT_NAME 373
  245. # define _OFF 352
  246. # define _OFFSETS 353
  247. # define _ON 354
  248. # define _ONCE 355
  249. # define _OR 356
  250. # define _ORDER 357
  251. # define _OVER 359
  252. # define _PARAM 452
  253. # define _PERMANENT 361
  254. # define _PREPARE 455
  255. # define _PRINT 464
  256. # define _PROCEDURE 362
  257. # define _PROCESSEXIT 454
  258. # define _PUBLIC 421
  259. # define _RAISERROR 465
  260. # define _RECONFIGURE 461
  261. # define _RETURN 410
  262. # define _REVOKE 420
  263. # define _ROLLBACK 387
  264. # define _ROWCOUNT 466
  265. # define _RULE 401
  266. # define _SAVE 388
  267. # define _SELECT 365
  268. # define _SET 366
  269. # define _SETUSER 462
  270. # define _STATEMENT 459
  271. # define _STATISTICS 431
  272. # define _SUBSTRING 435
  273. # define _SUM 370
  274. # define _SUSER_ID 424
  275. # define _SUSER_NAME 425
  276. # define _TABLE 371
  277. # define _TAPE 395
  278. # define _TEMPORARY 374
  279. # define _TO 394
  280. # define _TRANSACTION 389
  281. # define _TRIGGER 418
  282. # define _TRUNCATE 392
  283. # define _UNIQUE 375
  284. # define _UPDATE 376
  285. # define _USE 377
  286. # define _USER_ID 422
  287. # define _USER_NAME 423
  288. # define _VALUES 378
  289. # define _VIEW 379
  290. # define _WAITFOR 450
  291. # define _WHERE 380
  292. # define _WHILE 407
  293. # define _WITH 381
  294. /* end y.tab.h */
  295.  
  296. /*
  297. ** HOSTSERVER.h - structures and defines for communicating with server
  298. **
  299. */
  300.  
  301. /*
  302. ** Data structure used by both send and recv
  303. */
  304. typedef struct servbuf
  305. {
  306.     BYTE    *serv_sbuf;    /* send: start of send buffer */
  307.     BYTE    *serv_snb;    /* send: next place in buffer */
  308.     int    serv_sleft;    /* send: room left in send buffer */
  309.     int    serv_sbsize;    /* send: buffer size */
  310.     int    serv_snum;    /* send # for network */
  311.     int    serv_sstat;    /* send: status bits */
  312.     BYTE    *serv_rbuf;    /* recv: start of recv buffer */
  313.     BYTE    *serv_rnb;    /* recv: next place in buffer */
  314.     int    serv_rleft;    /* recv: room left in recv buffer */
  315.     int    serv_rbsize;    /* recv: buffer size */
  316.     int    serv_rnum;    /* recv # for network */
  317.     int    serv_rstat;    /* recv: status bits */
  318.     int    serv_commtype;    /* communications type (tcp, etc.) */
  319.     RETCODE    (*serv_attn)(); /* network-dependent routine to send
  320.                  * an ATTN packet to the SQL Server.
  321.                  */
  322.     DBINT    (*serv_read)();    /* network-dependent routine to read
  323.                  * a byte stream from the SQL Server.
  324.                  */
  325.     RETCODE    (*serv_read_a)();/* async version of serv_read(). */
  326.     DBINT    (*serv_writ)();    /* network-dependent routine to write
  327.                  * a byte stream to the SQL Server.
  328.                  */
  329.     RETCODE    (*serv_clos)();    /* network-dependent routine to close
  330.                  * a connection to the SQL Server.
  331.                  */
  332. } SERVBUF;
  333.  
  334.  
  335. /*
  336. **  DBSTRING - This structure is just used for stringing text or parameters
  337. **    together.
  338. */
  339. struct dbstring
  340. {
  341.     BYTE     *strtext;    /* actual byte string */
  342.     DBINT    strtotlen;    /* allocated length of the byte string */
  343.     struct dbstring    *strnext;
  344. };
  345. typedef struct dbstring    DBSTRING;
  346.  
  347. /*
  348. **    DBROWDATA - This structure is used to hold the actual data that
  349. **    comes back for every column in every row. The DBPROCESS structure
  350. **    points to a linked-list of DBROW structures. Each DBROW strcture points
  351. **    to an array of DBROWDATA structures. Since every DBROWDATA structure
  352. **    contains pointers to separately allocated buffers, the members of
  353. **    each array are linked together in a singly-linked list, to facilitate
  354. **    the operation of simple row-freeing routines.
  355. */
  356. struct dbrowdata
  357. {
  358.     BYTE         *data;        /* actual data for this column in this
  359.                      * row
  360.                      */
  361.     DBINT        datlen;        /* length, in bytes, of this data */
  362.     DBBINARY    dattxptr[DBTXPLEN];/* This data's text-ptr, if it's of
  363.                      * type SYBTEXT.
  364.                      */
  365.     DBTINYINT    dattxplen;    /* Length, in bytes, of the text-ptr. */
  366.     DBBINARY    dattxts[DBTXTSLEN];/* The text-timestamp of this text
  367.                      * value.
  368.                      */
  369.     DBTINYINT    dattxtslen;    /* Length, in bytes, of the
  370.                      * text-timestamp.
  371.                      */
  372.     struct dbrowdata    *datnext;
  373. };
  374. typedef struct dbrowdata    DBROWDATA;
  375.  
  376. /*
  377. **  BINDREC - This is the structure used to store information about
  378. **    which columns should be bound to which programming variables
  379. */
  380. struct    bindrec
  381. {
  382.     BYTE        *bindvar;    /* ptr to program variable */
  383.     DBINT        bindlen;    /* length of program variable */
  384.     DBINT        (*bindproc)();    /* procedure to use for data copy. */
  385.     DBINT        *bindnullind;    /* IBM-type indicator variable. */
  386. };
  387. typedef struct bindrec    BINDREC;
  388.  
  389. /*
  390. ** NULLBIND - This structure is attached to the DBPROCESS and is used
  391. **    to determine what to bind when bind values are NULL.
  392. */
  393. struct    nullbind
  394. {
  395.     DBBIT        nullbit;
  396.     DBTINYINT    nulltiny;
  397.     DBSMALLINT    nullsmall;
  398.     DBINT        nullint;
  399.     DBCHAR        *nullchar;
  400.     DBINT        nulllchar;    /* length of char string */
  401.     DBBINARY    *nullbinary;
  402.     DBINT        nulllbinary;    /* length of binary string */
  403.     DBDATETIME    nulldatetime;
  404.     DBMONEY        nullmoney;
  405.     DBFLT8        nullflt8;
  406.     DBCHAR        *nullstring;
  407.     DBCHAR        *nullntbstring;
  408.     DBVARYCHAR    nullvarychar;
  409.     DBVARYBIN    nullvarybin;
  410. };
  411. typedef struct nullbind    NULLBIND;
  412.  
  413. /*
  414. **  DBCOLINFO - This structure contains the format information about a column.
  415. **    There is a linked list of DBCOLINFO structures in the DBPROCESS
  416. **    structure.  There is one DBCOLINFO structure for each column in the
  417. **    target list of the current command.  Format information for
  418. **    alternate rows, like compute, is kept in the DBALTHEAD and
  419. **    DBALTINFO structures.
  420. */
  421. struct dbcolinfo
  422. {
  423.     char    colname[DBMAXCOLNAME+1];/* column name */
  424.     BYTE    coltype;        /* column type */
  425.     DBINT    coludtype;        /* user-defined type */
  426.     DBINT    collen;            /* max length of column */
  427.     DBINT    colprlen;        /* max printing length of column */
  428.     char    *colcontrol;        /* control format, if any */
  429.     struct bindrec    colbind;    /* binding info, if any */
  430.     int    coltable;        /* for browse mode: which table
  431.                      * did this column come from?
  432.                      */
  433.     BYTE        colstatus;    /* for browse mode: what kind of column
  434.                      * is this?
  435.                      */
  436.     char    colorigname[DBMAXCOLNAME+1];/* for browse mode: what is the name
  437.                      * of the table column that provided
  438.                      * this select-list member?
  439.                      */
  440.     char    *coltxobjname;        /* the SQL Server always returns the
  441.                      * qualified object-name for TEXT
  442.                      * columns.
  443.                      */
  444.     struct dbcolinfo    *colnext;    /* next column */
  445. };
  446. typedef    struct dbcolinfo    DBCOLINFO;
  447.  
  448. /*
  449. **  DBTABNAME - This structure contains information about the tables which
  450. **    were used to produce the current set of results. The SQL Server only
  451. **    provides this info for queries that are executed in "browse mode".
  452. **
  453. **    There is a linked list of DBTABNAME structures in the DBPROCESS
  454. **    structure.  There is one DBTABNAME structure for each table used to
  455. **    produce the target list of the current command.
  456. **
  457. **    If this query was executed without "browse mode", then this list will
  458. **    have no members.
  459. */
  460. struct dbtabname
  461. {
  462.     char            tabname[MAXNAME+1];    /* column name */
  463.     struct dbtabname    *tabnext;        /* next column */
  464. };
  465. typedef    struct dbtabname    DBTABNAME;
  466.  
  467. /*
  468. **  DBRETVAL - This structure contains any data which was returned as a function
  469. **    value by the last command. Currently, "browse-mode" updates are the only
  470. **    commands which return function values.
  471. **
  472. **    There is a linked list of DBRETVAL structures in the DBPROCESS
  473. **    structure.  There is one DBRETVAL structure for each function value
  474. **    returned by the current command.
  475. **
  476. **    If this command returned no function value, this list will
  477. **    have no members.
  478. */
  479. struct dbretval
  480. {
  481.     char        retname[MAXNAME+1];    /* value name */
  482.     BYTE        retvalstat;        /* status byte */
  483.     DBINT        retusertype;        /* user type */
  484.     BYTE        rettype;        /* value type */
  485.     DBINT        retmaxlen;        /* max value length (ignored) */
  486.     DBINT        retlen;            /* value length */
  487.     BYTE        *retdata;        /* the return-value itself. */
  488.     struct dbretval    *retnext;        /* next return-value */
  489. };
  490. typedef    struct dbretval    DBRETVAL;
  491.  
  492. /*
  493. **  DBALTHEAD - This structure contains information for ALT rows.  ALT
  494. **    rows are COMPUTE results.  There is one DBALTHEAD for each COMPUTE
  495. **    statement.  All the COMPUTE operators in a particular COMPUTE statement
  496. **    must have the same bylist -- this is enforced by the SQL Server.
  497. **    Off of each DBALTHEAD is a linked list of DBALTINFO structures that
  498. **    describe the format for each particular COMPUTE operation in the
  499. **    COMPUTE.
  500. */
  501. struct    dbalthead
  502. {
  503.     DBUSMALLINT    althid;        /* id for this COMPUTE statement */
  504.     BYTE    althalts;    /* number of DBALTINFO structures in althlist */
  505.     BYTE    althsizeby;    /* number of elements in the bylist */
  506.     BYTE    althbylist[DBMAXBYLIST];    /* colids of bylist elements */
  507.     struct dbaltinfo    *althlist;    /* linked list of DBALTINFOs */
  508.     struct dbprlist        *althprlist;    /* order print list for aops */
  509.     struct dbalthead    *althnext;    /* next dbalthead */
  510. };
  511. typedef struct dbalthead    DBALTHEAD;
  512.  
  513. /*
  514. **  DBPRLIST - This structure is used to create an 'ordered' printing list
  515. **    for computes.  For example a compute might be:
  516. **        compute sum(col1), avg(col2), sum(col2), avg(col3), avg(col1)
  517. **    For printing, it would be nice to have a list that pointed to the
  518. **    right DBALTINFO structures like this:
  519. **        sum(col1)-->sum(col2)
  520. **          |
  521. **         \|/
  522. **        avg(col1)-->avg(col2)-->avg(col3)
  523. **    It is used by the praltrow function that dbprrow uses but the
  524. **    information could be used by any DBLIB client.
  525. */
  526. struct    dbprlist
  527. {
  528.     DBROWDATA    *prdata;    /* actual data for the compute */
  529.     struct dbaltinfo    *prtarget;    /* related ALTINFO struct */
  530.     struct dbprlist        *prright;    /* next aop in compute */
  531.     struct dbprlist        *prdown;    /* next compute in query */
  532. };
  533. typedef struct dbprlist    DBPRLIST;
  534.  
  535. /*
  536. **  DBALTINFO - This structure contains the format information about
  537. **    alternate rows.  Compute clauses produce alternate rows of data,
  538. **    interspersed with the regular data rows returned by the dataserver.
  539. **    There is a linked list of DBALTHEAD structures in the DBPROCESS
  540. **    structure.  There is one DBALTHEAD structure for each possible
  541. **    type of alternate row of the current command.  Format information for
  542. **    regular data rows is kept in the DBCOLINFO structure.
  543. */
  544. struct dbaltinfo
  545. {
  546.     char    *altname;    /* null terminated string to alt header */
  547.     BYTE    alttoken;    /* type of alternate information */
  548.     BYTE    altcolid;    /* which target list member referenced */
  549.     BYTE    alttype;    /* column type */
  550.     DBINT    altudtype;    /* user-defined type */
  551.     DBINT    altlen;        /* max length of column */
  552.     DBINT    altprlen;    /* printing length of data */
  553.     char    *altcontrol;        /* control format, if any */
  554.     struct dbprlist    *altprlist;    /* ptr to ordered printing list */
  555.     struct bindrec    altbind;    /* binding info, if any */
  556.     struct dbaltinfo    *altnext;    /* next column */
  557. };
  558. typedef    struct dbaltinfo    DBALTINFO;
  559.  
  560. /*
  561. **  DBROW - This structure is used to store the actual row and alternate row
  562. **    data returned by the dataserver.  The member of the DBPROCESS structure 
  563. **    called dbfirstdata stores the doubly-linked list of rows.  If buffering
  564. **    is off, only one row is stored.  The rows are stored in the order that
  565. **    they are received from the server.
  566. */
  567. struct dbrow
  568. {
  569.     DBINT        rowid;        /* this is the returned row number */
  570.     DBUSMALLINT    rowaltid;    /* for ALT rows, this is
  571.                      * DBALTINFO.altid
  572.                      */
  573.     DBROWDATA    *rowdata;    /* actual data */
  574.     BOOL        rowhasnull;    /* are there any NULLS in this row of
  575.                      * data?
  576.                      */
  577.     struct dbrow    *rowprev;    /* previous row if buffering on */
  578.     struct dbrow    *rownext;    /* next row if buffering on */
  579.     SECLAB         dbseclab;    /* security label */
  580.     unsigned long    dbcrc;        /* row crc (security only) */
  581. };
  582. typedef struct dbrow    DBROW;
  583.     
  584. /*
  585. **  DBINFO - This structure is used to store information and error messages
  586. **    returned by the dataserver.
  587. **
  588. **    NOTE - This structure is used by APT.
  589. **        Adding or deleting structure members should be done with
  590. **        care.
  591. */
  592. struct dbinfo
  593. {
  594.     DBINT        infonum;    /* error or info number */
  595.     DBTINYINT    infostate;    /* error state number */
  596.     DBTINYINT    infoclass;    /* info class or error severity */
  597.     char        *infotext;    /* null terminated message */
  598.     char        *infoservname;    /* null terminated Server-name */
  599.     char        *infoprocname;    /* null terminated procedure-name */
  600.     DBUSMALLINT    infolinenum;    /* stored-procedure line-number */
  601.     struct dbinfo    *infonext;
  602. };
  603. typedef struct dbinfo    DBINFO;
  604.  
  605. /*
  606. **  Options - both for the dataserver and DBLIB
  607. **    As additional options are added, they should be added here and in
  608. **    the Dboptdict array.
  609. */
  610.  
  611. /*
  612. ** dataserver options are defined in pss.h
  613. ** dataserver options and their index into the Dboptdict array
  614. ** Dboptdict is defined in options.c
  615. */
  616. #define DBPARSEONLY    0
  617. #define DBESTIMATE    1    
  618. #define DBSHOWPLAN    2
  619. #define DBNOEXEC    3
  620. #define DBARITHIGNORE    4
  621. #define DBNOCOUNT    5
  622. #define DBARITHABORT    6
  623. #define DBTEXTLIMIT    7
  624. #define DBBROWSE    8
  625. #define DBOFFSET    9
  626. #define DBSTAT        10
  627. #define DBERRLVL    11
  628. #define DBCONFIRM    12
  629. #define DBSTORPROCID    13
  630. #define DBBUFFER    14
  631. #define DBNOAUTOFREE    15
  632. #define DBROWCOUNT    16
  633. #define DBTEXTSIZE    17
  634.  
  635. #define    OFF        0
  636. #define    ON        1
  637.  
  638. /* RETCODES for option routines */
  639. #define    NOSUCHOPTION    2
  640.  
  641. /*
  642. **  DBOPTION - This structure is used to store the current dataserver and
  643. **    dblib options.
  644. */
  645. struct dboption
  646. {
  647.     char    *opttext;
  648.     DBSTRING    *optparam;    /* param to the option */
  649.     DBUSMALLINT    optstatus;    /* status of option */
  650.     BOOL    optactive;    /* is this structure active (being used?) */
  651.     struct dboption    *optnext;    /* for different versions of an option */
  652. };
  653. typedef struct dboption    DBOPTION;
  654.  
  655.  
  656. /*
  657. ** These are the offset types recognized by the SQL Server
  658. ** They are contained in the SQL Server header pss.h.  The _defines
  659. ** come from y.tab.h.
  660. */
  661. #define OFF_SELECT    (DBUSMALLINT) _SELECT
  662. #define OFF_EXEC    (DBUSMALLINT) _EXECUTE
  663. #define OFF_FROM    (DBUSMALLINT) _FROM
  664. #define OFF_ORDER    (DBUSMALLINT) _ORDER
  665. #define OFF_COMPUTE    (DBUSMALLINT) _COMPUTE
  666. #define OFF_TABLE    (DBUSMALLINT) _TABLE
  667. #define OFF_PROCEDURE    (DBUSMALLINT) _PROCEDURE
  668. #define OFF_STATEMENT    (DBUSMALLINT) _STATEMENT
  669. #define OFF_PARAM    (DBUSMALLINT) _PARAM
  670.  
  671. /*
  672. **  DBOFF - This structure is used to store text offset information.
  673. **    This information is used to send back to the dataserver new
  674. **    control formats.  
  675. */
  676. struct dboff
  677. {
  678.     DBUSMALLINT    offtype;    /* type of offset */
  679.     DBUSMALLINT    offset;        /* actual offset */
  680.     struct dboff    *offnext;
  681. };
  682. typedef struct dboff    DBOFF;
  683.  
  684. /*
  685. **  DBDONE - This structure is just the dataserver done packet.
  686. **    It has information about the completion of a command.
  687. */
  688. struct dbdone
  689. {
  690.     DBUSMALLINT    donestatus;    /* done status bits */
  691.     DBUSMALLINT    doneinfo;    /* command specific info */
  692.     DBINT        donecount;    /* done count -- rows for example */
  693. };
  694. typedef struct dbdone    DBDONE;
  695.  
  696. /* Status bits for DBPROCESS dbstatus */
  697. #define    READROW        (DBUSMALLINT) 0x2
  698. #define    INSPROC        (DBUSMALLINT) 0x4
  699. #define    EXECDONE    (DBUSMALLINT) 0x8
  700. #define    NEWDB        (DBUSMALLINT) 0x10
  701.  
  702. /* Possible flags for dbback_compatible(). Currently the only
  703. ** one is DBEXTRARESULTS.
  704. */
  705. #define DBEXTRARESULTS  (DBUSMALLINT) 0x1
  706.  
  707.  
  708. /* Bulk-copy information -- */
  709.  
  710. #define    PERIOD    '.'    /* the separator... */
  711.  
  712. #define    STATNULL    (BYTE) 0x08
  713. #define IN        (BYTE) 1 /* TEMPORARY - for backward compatibility. */
  714. #define    OUT        (BYTE) 2 /* TEMPORARY - for backward compatibility. */
  715. #define DB_IN        (BYTE) 1
  716. #define    DB_OUT        (BYTE) 2
  717. #define BCPNAMELEN    255
  718. #define DEFABORT    10        /* # of errors before we give up */
  719. #define    ERRFILE        "bcp.error"    /* default error file name */
  720.  
  721. /* BCP macros: */
  722. #define BCP_SETL(a,b)        dbsetlbool((a), (b), DBSETBCP)
  723.  
  724. /* The fields for calls to bcpcontrol. */
  725. #define    BCPMAXERRS    1
  726. #define    BCPFIRST    2
  727. #define    BCPLAST        3
  728. #define    BCPBATCH    4
  729. #define    BCPERRFILE    5    /* TEMPORARY - for backward compatibility. */
  730.  
  731. /* This macro is used by the Non-C interfaces to BCP-Library: */
  732. #define BCP_HOSTTYPE(a, b)    (((a)->db_bcpdesc->bd_hostdesc + (b - 1))->htype)
  733.  
  734. typedef    struct    bcpparsetable
  735. {
  736.     char    dbname[MAXNAME+1];
  737.     char    ownername[MAXNAME+1];
  738.     char    tabname[MAXNAME+1];
  739. } BCPPARSETABLE;
  740.  
  741. /*
  742. **  BCPCOLDESC
  743. **    This is the basic unit of information used for bulkcopy.
  744. **    All the bulkcopy routines that talk with the SQL Server
  745. **    routines pass an array of these.
  746. */
  747. typedef struct    bcpcoldesc
  748. {
  749.     BYTE    *cd_dvalue;        /* current value to be inserted */
  750.     BYTE    *cd_defvalue;        /* default value to be inserted */
  751.     DBINT    cd_dlen;        /* current length to be inserted */
  752.     DBINT    cd_deflen;        /* length of default to be inserted */
  753.     DBINT    cd_colen;        /* max length allowed in column */
  754.     short    cd_coloff;        /* column offset in row */
  755.     BYTE    cd_colid;        /* id of column */
  756.     BYTE    cd_type;        /* storage type of column */
  757.     BYTE    cd_status;        /* status bits */
  758.     BOOL    cd_nullok;        /* is a NULL ok here? */
  759.     char    cd_name[MAXNAME+1];    /* column name */
  760.     BOOL    cd_moretext;        /* Is this text to be sent via bcp__moretext? */
  761.     long    cd_textpos;        /* file-position of a long TEXT or IMAGE */
  762. } BCPCOLDESC;
  763.  
  764. /*
  765. **  BCPROWDESC
  766. **    This is the basic unit of information used for bulkcopy.
  767. **    All the bulkcopy routines that talk with the SQL Server
  768. **    routines pass it.
  769. */
  770. typedef struct bcprowdesc
  771. {
  772.     BCPCOLDESC    *rd_coldesc;    /* ptr to base address of COLDESC
  773.                      * array
  774.                      */
  775.     short        rd_colcount;    /* number of columns in COLDESC */
  776.     short        rd_minlen;    /* minimum length of a row */
  777.     short        rd_maxlen;    /* maximum length of a row */
  778. } BCPROWDESC;
  779.  
  780. /*
  781. ** BCPHOSTDESC
  782. **    This is the structure that has information about the type and
  783. **    format of the input or output data.  An array of these is used
  784. **    to read/write data to or from the host.
  785. */
  786. typedef struct    bcphostdesc
  787. {
  788.     BCPCOLDESC    *h_tabcol; /* which table column we are referring to */
  789.     int    h_tabcolnum;    /* which table column we are referring to */
  790.     DBINT    (*hconvert)();    /* conversion function, if applicable */
  791.     BYTE    htype;        /* host data type for this column */
  792.     DBINT    hcollen;    /* max length of hostfile column */
  793.     BYTE    *hdata;        /* host-format data for this column */
  794.     DBINT    hdatlen;    /* length of actual hostfile data */
  795.     int    hprefixlen;    /* length of length-prefix for this column */
  796.     BYTE    *hterm;        /* terminator for this column, if applicable */
  797.     int    htermlen;    /* length of terminator for this column */
  798.     BOOL    hmoretext;    /* Is this text to be sent via bcp__moretext? */
  799.     long    htextpos;    /* file-position of a long TEXT or IMAGE */
  800. } BCPHOSTDESC;
  801.  
  802. /* This structure contains information about any partially-sent TEXT or IMAGE
  803.  * values, which are still to be sent by bcp_moretext().
  804.  */
  805. typedef struct bcptextrec
  806. {
  807.     DBINT        len;
  808.     BYTE        *val;
  809.     BYTE        type;
  810.     DBSMALLINT    rowoffset;
  811.     BYTE        coloffset;
  812. } BCPTEXTREC;
  813.  
  814. /*
  815. **  BCPDESC
  816. **    This structure is used to pass the information contained in the
  817. **    Bulk Copy property sheet around (if in the form version), or 
  818. **    information typed in by the user (in dblib/stand alone version).
  819. **    In the form version, this information comes from the main form, while
  820. **    in the stand alone version this comes from the command line.
  821. */
  822. typedef struct    bcpdesc
  823. {
  824.     BCPROWDESC    *bd_rowdesc;        /* the associated rowdesc */
  825.     BCPHOSTDESC    *bd_hostdesc;        /* ptr to base address of
  826.                         ** BCPHOSTDESC array */
  827.     int        bd_hcolcount;        /* number of (cols) BCPHOSTDESC 
  828.                         ** structs */
  829.     BCPPARSETABLE    *bd_ptable;        /* ptr to tbl name components */
  830.     char        bd_table[(3 * MAXNAME) + 3]; /* full table name */
  831.     char        bd_filename[BCPNAMELEN+1];/* host filename */
  832.     BYTE        bd_direction;        /* in/out */
  833.     char        *bd_errfilename;    /* host err file name */
  834.     BYTE        *bd_errfile;        /* host err file pointer */
  835.     DBINT        bd_abort;        /* # of errors allowable */
  836.     DBINT        bd_firstrow;        /* begin copy at this row */
  837.     DBINT        bd_lastrow;        /* end copy at this row */
  838.     DBINT        bd_batch;        /* # of rows per batch */
  839.     int        bd_textcount;        /* # of text-columns in the
  840.                          * current row.
  841.                          */
  842.     int        bd_textcol;        /* # of the text-column now
  843.                          * being sent by bcp_moretext().
  844.                          * Starts at zero.
  845.                          */
  846.     DBINT        bd_textbytes;        /* # of bytes already sent of
  847.                          * the current bcp_moretext()
  848.                          * column.
  849.                          */
  850.     BCPTEXTREC    *bd_textarray;
  851. } BCPDESC;
  852.  
  853.  
  854. /*
  855. **  DBPROCESS - This is the basic DBLIB structure. It contains the command
  856. **    sent to the dataserver as well as the results of the command.
  857. **    It also includes any error or information messages, including the
  858. **    done packet, returned by the dataserver.  If buffering is turned on,
  859. **    this structure also stores the data rows.
  860. */
  861. struct    dbprocess
  862. {
  863.     struct servbuf    *dbfile;    /* dataserver connection */
  864.     DBUSMALLINT    dbstatus;    /* status field for dbprocess */
  865.     BYTE        dbtoken;    /* current dataserver token */
  866.     DBSTRING    *dbcmdbuf;    /* command buffer */
  867.     int        dbcurcmd;    /* number of the current cmd results */
  868.     DBINT        dbprocid;    /* procid, if any, of the current cmd */
  869.     DBCOLINFO    *dbcols;    /* linked list of column information */
  870.     DBALTHEAD    *dbalts;    /* linked list of alt column info */
  871.     DBROW        *dbfirstdata;    /* doubly linked list of returned row
  872.                      * data
  873.                      */
  874.     DBROW        *dbcurdata;    /* current row in dbfirstdata */
  875.     DBROW        *dblastdata;    /* last row in dbfirstdata, usually
  876.                      * dbcurdata
  877.                      */
  878.     DBOFF        *dboffsets;    /* list of offsets and controls in
  879.                      * dbcmdbuf
  880.                      */
  881.     int        dboffadjust;    /* adjustment factor for offsets */
  882.     DBSMALLINT    dbcuroffset;    /* active offset for results */
  883.     DBOPTION    *dbopts;
  884.     DBSTRING    *dboptcmd;    /* option string to send to server */
  885.     DBINFO        *dbmsgs;    /* linked list of info and error
  886.                      * messages
  887.                      */
  888.     DBINFO        *dbcurmsg;    /* last message read by dbgetmsg() */
  889.     DBDONE        dbdone;        /* done information */
  890.     char        dbcurdb[MAXNAME+1];    /* the name of the current
  891.                          * database
  892.                          */
  893.     int        (*(*dbbusy)())(); /* function to call when waiting on
  894.                        * dataserver
  895.                        */
  896.     void        (*dbidle)();    /* function to call when waiting on
  897.                      * dataserver
  898.                      */
  899.     int        (*dbchkintr)();    /* user's function to call to check for
  900.                      * queued interrupts
  901.                      */
  902.     int        (*dbhndlintr)();/* user's interrupt handler */
  903.     int        dbbufsize;    /* the size of the row buffer, if
  904.                      * enabled
  905.                      */
  906.     NULLBIND    dbnullbind;    /* what to bind for nulls */
  907.     int        dbsticky;    /* sticky flags like attn */
  908.     int        dbnumorders;    /* number of columns in the query's
  909.                      * "order by" clause.
  910.                      */
  911.     int        *dbordercols;    /* array of the column numbers found in
  912.                      * the query's "order by" clause.
  913.                      */
  914.     BOOL        dbavail;    /* is this dbproc available for general
  915.                      * use?
  916.                      */
  917.     int        dbftosnum;    /* this id is used when recording the
  918.                      * frontend-to-Server SQL traffic of
  919.                      * this DBPROCESS.
  920.                      */
  921.     BOOL        dbdead;        /* TRUE if this DBPROCESS has become
  922.                      * useless, usually due to a fatal
  923.                      * Server error, or a communications
  924.                      * failure.
  925.                      */
  926.     BOOL        dbenabled;    /* TRUE if this DBPROCESS is allowed to
  927.                      * be used in DB-LIBRARY functions. The
  928.                      * user may set this flag FALSE,
  929.                      * possibly within an error handler, if
  930.                      * execution of further commands would
  931.                      * just cause further errors.
  932.                      * DB-LIBRARY initially sets this flag
  933.                      * TRUE. The user may set and re-set
  934.                      * this flag at will.
  935.                      */
  936.     BOOL        dbsqlsent;    /* TRUE if the SQL in the command
  937.                      * buffer has already been sent to
  938.                      * the SQL Server.
  939.                      */
  940.     DBTABNAME    *dbtabnames;    /* linked-list of table-name
  941.                      * information used by "browse mode".
  942.                      */
  943.     DBINT        dbspid;        /* The Server process-id of this
  944.                      * DBPROCESS. It's returned in the
  945.                      * row-count field of the done-packet
  946.                      * which signifies a successful login.
  947.                      */
  948.     DBRETVAL    *dbretvals;    /* linked-list of function
  949.                      * return-values.
  950.                      */
  951.     BCPDESC        *db_bcpdesc;    /* A structure containing bulk-copy
  952.                      * information.
  953.                      */
  954.     BOOL        dbtransbegun;    /* Indicates that a text data transfer
  955.                      * is under way.
  956.                      */
  957.     DBINT        dbbytesleft;    /* This is a countdown variable, used
  958.                      * to track the number of bytes which
  959.                      * are still to be sent as part of
  960.                      * a dbwritetext() command.
  961.                      */
  962.     DBINT        dbretstat;    /* This is the return-status from
  963.                      * a stored procedure.
  964.                      */
  965.     BOOL        dbhasretstat;    /* Is the return-status valid? */
  966.     DBINT        dbtextlimit;    /* This is the longest text-column
  967.                      * that this dbproc will accept
  968.                      * from the Server. Any additional
  969.                      * bytes will be discarded.
  970.                      * If 0, then there's no limit.
  971.                      */
  972.     BYTE        *dbuserdata;    /* A pointer to any data that the
  973.                      * the user wishes to associate with
  974.                      * this DBPROCESS.
  975.                      */
  976.     DBINT        dbloginfailed;    /* The number of the Server message
  977.                      * which describes the reason for
  978.                      * this failed login.
  979.                      */
  980.     char        dblogin_node[MAXNAME + 1];
  981.                     /* The node that the Companion
  982.                      * Server's redirector has
  983.                      * recommended to us.
  984.                      */
  985.     int        dbcolcount;    /* The number of regular columns
  986.                      * in the current set of results.
  987.                      */
  988.  
  989.     DBBOOL        db_oldtds;    /* TRUE if the TDS version is older
  990.                      * than 4.0.
  991.                      */
  992.     int        db_tdsversion;    /* tds version for this dbproc. */
  993. #if VMS
  994.     int        db_event_mask;    /* a mask used to determine what
  995.                     ** event has happened in the front-
  996.                     ** end i/o routines.
  997.                     */
  998.     long        db_event_flag;    /* the number of the event flag used
  999.                     ** to check for timeout, interrupt 
  1000.                     ** (control_c) or i/o completion.
  1001.                     */
  1002.     short        db_io_channel;    /* channel assigned to sys$command
  1003.                     ** of the controlling process.
  1004.                     */
  1005.     short        r_iosb[4];    /* I/O status for read */
  1006.     short        w_iosb[4];    /* I/O status for write */                
  1007. #endif /* VMS */
  1008.  
  1009.     struct dbprocess    *dbnext;/* DBPROCESSes are kept track of
  1010.                      * in a big linked-list.
  1011.                      */
  1012. };
  1013. typedef struct dbprocess    DBPROCESS;
  1014.  
  1015. #define    DBTDS_2_0        1
  1016. #define    DBTDS_3_4        2
  1017. #define    DBTDS_4_0        3
  1018.  
  1019.  
  1020. /*
  1021. **  Various macros used to extract information from the DBPROCESS structure
  1022. */
  1023. #define    DBTDS(a)    ((a)->db_tdsversion)
  1024. #define    DBCURCMD(a)    ((a)->dbcurcmd)
  1025. #define    DBCURROW(a)    ((a)->dbcurdata == (DBROW *) NULL ? ((DBINT)0): (a)->dbcurdata->rowid)
  1026. #define    DBFIRSTROW(a)    ((a)->dbfirstdata == (DBROW *) NULL ? ((DBINT)0): (a)->dbfirstdata->rowid)
  1027. #define    DBLASTROW(a)    ((a)->dblastdata == (DBROW *) NULL ? ((DBINT)0): (a)->dblastdata->rowid)
  1028. #define    DBROWTYPE(a)    ((a)->dbcurdata == (DBROW *) NULL ? (DBINT)NO_MORE_ROWS: \
  1029.     ((a)->dbcurdata->rowaltid == 0 ? (DBINT)REG_ROW: (a)->dbcurdata->rowaltid))
  1030. #define    DBMORECMDS(a)    ((a)->dbdone.donestatus & DONE_CONT ? SUCCEED: FAIL)
  1031. #define    DONECONTINUE(a)    ((a)->dbdone.donestatus & DONE_CONT ? SUCCEED: FAIL)
  1032. #define    DBCOUNT(a)    ((a)->dbdone.donestatus & DONE_COUNT ? (a)->dbdone.donecount : ((DBINT)(-1)))
  1033. #define    DBCMDROW(x)    ((x)->dbcols == NULL ? FAIL: SUCCEED)
  1034. #define    DBROWS(x)    (((x)->dbstatus & READROW) ? SUCCEED: FAIL)
  1035. #define DBNUMORDERS(a)    ((a)->dbnumorders)
  1036. #define DBBUFFULL(a)    (DBLASTROW(a) - DBFIRSTROW(a) + 1 >= (a)->dbbufsize ? \
  1037.     TRUE : FALSE)
  1038. #define DBMOREROWS(a)    (((a)->dbtoken == SYBROW) || ((a)->dbtoken == SYBALTROW) ? \
  1039.     TRUE : FALSE)
  1040. #define DBISAVAIL(a)    (((a)->dbavail) ? TRUE : FALSE)
  1041. #define DBGETTIMEOUT(a)    (DbTimeout)
  1042. #define DBGETTIME()    (DbTimeout)
  1043. #define DBDEAD(a)    ((a)->dbdead)
  1044. #define DBIORDESC(a)    ((a)->dbfile->serv_rnum)
  1045. #define DBIOWDESC(a)    ((a)->dbfile->serv_snum)
  1046. #define DBRBUF(a)    (((a)->dbfile->serv_rleft || (!((a)->dbsticky & (DBUSMALLINT) 0x1))) ? ((DBBOOL)TRUE) : ((DBBOOL)FALSE))
  1047.  
  1048. #if (VMS)
  1049. #define DBZEROSPACE(dest, bytes)        db__bzero(dest, bytes)
  1050. #else
  1051. #define DBZEROSPACE(dest, bytes)        MEMZERO(dest, bytes)
  1052. #endif /* (VMS) */
  1053.  
  1054. /* These constants are used for RPC options. The first group are flags
  1055.  * in a 2-byte bitmask, so they'll be different on Suns and Vaxes. The second
  1056.  * group are flags in a 1-byte bitmask, so they should be machine-independent.
  1057.  */
  1058. #define DBRPCRECOMPILE    ((DBSMALLINT)1)
  1059.  
  1060. #define DBRPCRETURN    ((BYTE)1)
  1061.  
  1062. #if VMS
  1063. /* These constants are used for VMS network manipulation. */
  1064. #define    DB_IO_EVENT    1
  1065. #define    DB_INTERRUPT_EVENT 2
  1066. #define    DB_TIMER_EVENT    4
  1067. #endif /* VMS */
  1068.  
  1069. /*
  1070. ** Macros to set values in the LOGINREC structure.
  1071. */
  1072. #define    DBSETHOST    1
  1073. #define    DBSETUSER    2
  1074. #define    DBSETPWD    3
  1075. #define    DBSETHID    4
  1076. #define    DBSETAPP    5
  1077. #define    DBSETBCP    6
  1078. #define    DBSETLHOST(a,b)        dbsetlname((a), (b), DBSETHOST)
  1079. #define    DBSETLUSER(a,b)        dbsetlname((a), (b), DBSETUSER)
  1080. #define    DBSETLPWD(a,b)        dbsetlname((a), (b), DBSETPWD)
  1081. #define    DBSETLHID(a,b)        dbsetlname((a), (b), DBSETHID)
  1082. #define    DBSETLAPP(a,b)        dbsetlname((a), (b), DBSETAPP)
  1083. #define    DBSETLHIER(a,b)        ((a)->lseclab.slhier = ((b) << 8) | ((b) >> 8) )
  1084. #define    DBGETLHIER(a)  (((a)->lseclab.slhier << 8) | ((a)->lseclab.slhier >> 8))
  1085. #define    DBSETLROLE(a,b)        ((a)->lrole = b)
  1086. #define    DBGETLROLE(a)        ( (a)->lrole )
  1087. #define    DBSETLCOMP(a,b)        dbbmove((BYTE*)(b), \
  1088.                     (BYTE *) ((a)->lseclab.slcomp),\
  1089.                     (DBINT) 8)
  1090. #define    DBSETONECOMP(a,b)    (a)[ ((b)-1)/8 ] |= ( 0x80 >> (( (b)-1 ) % 8) )
  1091. #define    DBUNSETONECOMP(a,b)    (a)[ ((b)-1)/8 ] &= ~( 0x80 >> (( (b)-1 ) % 8) )
  1092. #define    DBGETONECOMP(a,b)    (a)[ ((b)-1)/8 ] & ( 0x80 >> (( (b)-1 ) % 8) )
  1093.  
  1094. extern BOOL    DbDebug;
  1095. extern int    DbTime;
  1096. extern BOOL    DbIntrFlag;    /* True if an interrupt was typed. */
  1097. extern char    DbSeparator;
  1098. extern int    DbHeader;
  1099. extern int    DbTimeout;    /* default timeout value for DBPROCESSes. */
  1100. extern DBUSMALLINT    Compatibility_Mask;
  1101.  
  1102. /* bcp functions */
  1103. extern BCPDESC    *bcpinit();
  1104. extern RETCODE    bcpcontrol();
  1105. extern RETCODE    bcpcolumn();
  1106. extern RETCODE    bcpformat();
  1107. extern RETCODE    bcpexec();
  1108. extern RETCODE    bcpbind();
  1109. extern RETCODE    bcpsendrow();
  1110. extern RETCODE    bcpabort();
  1111. extern RETCODE    bcpcollen();
  1112. extern DBINT    bcpdone();
  1113.  
  1114. /* DB-LIBRARY minor error numbers */
  1115. #define SYBESYNC    20001    /* Read attempted while out of synchronization
  1116.                  * with SQL Server.
  1117.                  */
  1118. #define SYBEFCON    20002    /* SQL Server connection failed. */
  1119. #define SYBETIME    20003    /* SQL Server connection timed out. */
  1120. #define SYBEREAD    20004    /* Read from SQL Server failed. */
  1121. #define SYBEBUFL    20005    /* DB-LIBRARY internal error - send buffer
  1122.                  * length corrupted.
  1123.                  */
  1124. #define SYBEWRIT    20006    /* Write to SQL Server failed. */
  1125. #define SYBEVMS        20007    /* Sendflush: VMS I/O error. */
  1126. #define SYBESOCK    20008    /* Unable to open socket */
  1127. #define SYBECONN    20009    /* Unable to connect socket -- SQL Server is
  1128.                  * unavailable or does not exist.
  1129.                  */
  1130. #define SYBEMEM        20010    /* Unable to allocate sufficient memory */
  1131. #define SYBEDBPS    20011    /* Maximum number of DBPROCESSes
  1132.                  * already allocated.
  1133.                  */
  1134. #define SYBEINTF    20012    /* Server name not found in interface file */
  1135. #define SYBEUHST    20013    /* Unknown host machine name */
  1136. #define SYBEPWD        20014    /* Incorrect password. */
  1137. #define    SYBEOPIN    20015    /* Could not open interface file. */
  1138. #define SYBEINLN    20016    /* Interface file: unexpected end-of-line. */
  1139. #define SYBESEOF    20017    /* Unexpected EOF from SQL Server. */
  1140. #define SYBESMSG    20018    /* General SQL Server error: Check messages
  1141.                  * from the SQL Server.
  1142.                  */
  1143. #define SYBERPND    20019    /* Attempt to initiate a new SQL Server
  1144.                  * operation with results pending.
  1145.                  */
  1146. #define SYBEBTOK    20020    /* Bad token from SQL Server: Data-stream
  1147.                  * processing out of sync.
  1148.                  */
  1149. #define SYBEITIM    20021    /* Illegal timeout value specified. */
  1150. #define SYBEOOB        20022    /* Error in sending out-of-band data to
  1151.                  * SQL Server.
  1152.                  */
  1153. #define SYBEBTYP    20023    /* Unknown bind type passed to DB-LIBRARY
  1154.                  * function.
  1155.                  */
  1156. #define    SYBEBNCR    20024    /* Attempt to bind user variable to a
  1157.                  * non-existent compute row.
  1158.                  */
  1159. #define SYBEIICL    20025    /* Illegal integer column length returned by
  1160.                  * SQL Server. Legal integer lengths are 1, 2,
  1161.                  * and 4 bytes.
  1162.                  */
  1163. #define SYBECNOR     20026    /* Column number out of range. */
  1164. #define SYBENPRM    20027    /* NULL parameter not allowed for this
  1165.                  * dboption.
  1166.                  */
  1167. #define SYBEUVDT     20028    /* Unknown variable-length datatype encountered.
  1168.                  */
  1169. #define SYBEUFDT     20029    /* Unknown fixed-length datatype encountered. */
  1170. #define SYBEWAID    20030    /* DB-LIBRARY internal error: ALTFMT following
  1171.                  * ALTNAME has wrong id.
  1172.                  */
  1173. #define SYBECDNS    20031    /* Datastream indicates that a compute column is
  1174.                  * derived from a non-existent select-list
  1175.                  * member.
  1176.                  */
  1177. #define SYBEABNC    20032    /* Attempt to bind to a non-existent column. */
  1178. #define SYBEABMT    20033    /* User attempted a dbbind() with mismatched
  1179.                  * column and variable types.
  1180.                  */
  1181. #define SYBEABNP    20034    /* Attempt to bind using NULL pointers. */
  1182. #define SYBEAAMT    20035    /* User attempted a dbaltbind() with mismatched
  1183.                  * column and variable types.
  1184.                  */
  1185. #define SYBENXID    20036    /* The Server did not grant us a
  1186.                  * distributed-transaction ID.
  1187.                  */
  1188. #define SYBERXID    20037    /* The Server did not recognize our
  1189.                  * distributed-transaction ID.
  1190.                  */
  1191. #define SYBEICN        20038    /* Invalid computeid or compute column number.
  1192.                  */
  1193. #define SYBENMOB    20039    /* No such member of 'order by' clause. */
  1194. #define SYBEAPUT    20040    /* Attempt to print unknown token. */
  1195. #define SYBEASNL    20041    /* Attempt to set fields in a null loginrec. */
  1196. #define SYBENTLL    20042    /* Name too long for loginrec field. */
  1197. #define SYBEASUL    20043    /* Attempt to set unknown loginrec field. */
  1198. #define SYBERDNR    20044    /* Attempt to retrieve data from a non-existent
  1199.                  * row.
  1200.                  */
  1201. #define SYBENSIP    20045    /* Negative starting index passed to dbstrcpy().
  1202.                  */
  1203. #define SYBEABNV    20046    /* Attempt to bind to a NULL program variable.
  1204.                  */
  1205. #define SYBEDDNE    20047    /* DBPROCESS is dead or not enabled. */
  1206. #define SYBECUFL    20048    /* Data-conversion resulted in underflow. */
  1207. #define SYBECOFL    20049    /* Data-conversion resulted in overflow. */
  1208. #define SYBECSYN    20050    /* Attempt to convert data stopped by syntax
  1209.                  * error in source field.
  1210.                  */
  1211. #define SYBECLPR    20051    /* Data-conversion resulted in loss of
  1212.                  * precision.
  1213.                  */
  1214. #define SYBECNOV    20052    /* Attempt to set variable to NULL resulted
  1215.                  * in overflow.
  1216.                  */
  1217. #define SYBERDCN    20053    /* Requested data-conversion does not exist. */
  1218. #define SYBESFOV    20054    /* dbsafestr() overflowed its destination
  1219.                  * buffer.
  1220.                  */
  1221. #define SYBEUNT        20055    /* Unknown network type found in
  1222.                  * interface file.
  1223.                  */
  1224. #define SYBECLOS    20056    /* Error in closing network connection. */
  1225. #define SYBEUAVE    20057    /* Unable to allocate VMS event flag. */
  1226. #define SYBEUSCT    20058    /* Unable to set communications timer. */
  1227. #define SYBEEQVA    20059    /* Error in queueing VMS AST routine. */
  1228. #define SYBEUDTY    20060    /* Unknown datatype encountered. */
  1229. #define SYBETSIT    20061    /* Attempt to call dbtsput() with an
  1230.                  * invalid timestamp.
  1231.                  */
  1232. #define SYBEAUTN    20062    /* Attempt to update the timestamp of a table
  1233.                  * which has no timestamp column.
  1234.                  */
  1235. #define SYBEBDIO    20063    /* Bad bulk-copy direction.  Must be either
  1236.                  * IN or OUT.
  1237.                  */
  1238. #define SYBEBCNT    20064    /* Attempt to use Bulk Copy with a non-existent
  1239.                  * Server table.
  1240.                  */
  1241. #define SYBEIFNB    20065    /* Illegal field number passed to bcp_control().
  1242.                  */
  1243. #define SYBETTS        20066    /* The table which bulk-copy is attempting to
  1244.                  * copy to a host-file is shorter than the
  1245.                  * number of rows which bulk-copy was instructed
  1246.                  * to skip.
  1247.                  */
  1248. #define SYBEKBCO    20067    /* 1000 rows successfully bulk-copied to
  1249.                  * host-file.
  1250.                  */
  1251. #define SYBEBBCI    20068    /* Batch successfully bulk-copied to SQL Server.
  1252.                  */
  1253. #define SYBEKBCI    20069    /* Bcp: 1000 rows sent to SQL Server. */
  1254. #define SYBEBCRE    20070    /* I/O error while reading bcp data-file. */
  1255. #define SYBETPTN    20071    /* Syntax error: only two periods are permitted
  1256.                  * in table names.
  1257.                  */
  1258. #define SYBEBCWE    20072    /* I/O error while writing bcp data-file. */
  1259. #define SYBEBCNN    20073    /* Attempt to bulk-copy a NULL value into
  1260.                  * Server column %d,  which does not accept
  1261.                  * NULL values.
  1262.                  */
  1263. #define SYBEBCOR    20074    /* Attempt to bulk-copy an oversized row to the
  1264.                  * SQL Server.
  1265.                  */
  1266. #define SYBEBCIS    20075    /* Attempt to bulk-copy an illegally-sized
  1267.                  * column value to the SQL Server.
  1268.                  */
  1269. #define SYBEBCPI    20076    /* bcp_init() must be called before any other
  1270.                  * bcp routines.
  1271.                  */
  1272. #define SYBEBCPN    20077    /* bcp_bind(), bcp_collen() and bcp_colptr()
  1273.                  * may be used only after bcp_init() has been
  1274.                  * called with the copy direction set to DB_IN.
  1275.                  */
  1276. #define SYBEBCPB    20078    /* bcp_bind() may NOT be used after bcp_init()
  1277.                  * has been passed a non-NULL input file name.
  1278.                  */
  1279. #define SYBEVDPT    20079    /* For bulk copy, all variable-length data
  1280.                  * must have either a length-prefix or a
  1281.                  * terminator specified.
  1282.                  */
  1283. #define SYBEBIVI    20080    /* bcp_columns() and bcp_colfmt() may be used
  1284.                  * only after bcp_init() has been passed a
  1285.                  * valid input file.
  1286.                  */
  1287. #define SYBEBCBC    20081    /* bcp_columns() must be called before
  1288.                  * bcp_colfmt().
  1289.                  */
  1290. #define SYBEBCFO    20082    /* Bcp host-files must contain at least one
  1291.                  * column.
  1292.                  */
  1293. #define SYBEBCVH    20083    /* bcp_exec() may be called only after
  1294.                  * bcp_init() has been passed a valid host file.
  1295.                  */
  1296. #define SYBEBCUO    20084    /* Bcp: Unable to open host data-file. */
  1297. #define SYBEBCUC    20085    /* Bcp: Unable to close host data-file. */
  1298. #define SYBEBUOE    20086    /* Bcp: Unable to open error-file. */
  1299. #define SYBEBUCE    20087    /* Bcp: Unable to close error-file. */
  1300. #define SYBEBWEF    20088    /* I/O error while writing bcp error-file. */
  1301. #define SYBEASTF    20089    /* VMS: Unable to setmode for control_c ast. */
  1302. #define    SYBEUACS    20090    /* VMS: Unable to assign channel to sys$command.
  1303.                  */
  1304. #define SYBEASEC    20091    /* Attempt to send an empty command buffer to
  1305.                  * the SQL Server.
  1306.                  */
  1307. #define SYBETMTD    20092    /* Attempt to send too much TEXT data via the
  1308.                  * dbmoretext() call.
  1309.                  */
  1310. #define SYBENTTN    20093    /* Attempt to use dbtxtsput() to put a new
  1311.                  * text-timestamp into a non-existent data row.
  1312.                  */
  1313. #define SYBEDNTI    20094    /* Attempt to use dbtxtsput() to put a new
  1314.                  * text-timestamp into a column whose datatype
  1315.                  * is neither SYBTEXT nor SYBIMAGE.
  1316.                  */
  1317. #define SYBEBTMT    20095    /* Attempt to send too much TEXT data via the
  1318.                  * bcp_moretext() call.
  1319.                  */
  1320. #define SYBEORPF    20096    /* Attempt to set remote password would
  1321.                  * overflow the login-record's remote-password
  1322.                  * field.
  1323.                  */
  1324. #define SYBEUVBF    20097    /* Attempt to read an unknown version of BCP
  1325.                  * format-file.
  1326.                  */
  1327. #define SYBEBUOF    20098    /* Bcp: Unable to open format-file. */
  1328. #define SYBEBUCF    20099    /* Bcp: Unable to close format-file. */
  1329. #define SYBEBRFF    20100    /* I/O error while reading bcp format-file. */
  1330. #define SYBEBWFF    20101    /* I/O error while writing bcp format-file. */
  1331. #define SYBEBUDF    20102    /* Bcp: Unrecognized datatype found in
  1332.                  * format-file.
  1333.                  */
  1334. #define SYBEBIHC    20103    /* Incorrect host-column number found in bcp
  1335.                  * format-file.
  1336.                  */
  1337. #define SYBEBEOF    20104    /* Unexpected EOF encountered in BCP data-file.
  1338.                  */
  1339. #define SYBEBCNL    20105    /* Negative length-prefix found in BCP
  1340.                  * data-file.
  1341.                  */
  1342. #define SYBEBCSI    20106    /* Host-file columns may be skipped only when
  1343.                  * copying INto the Server.
  1344.                  */
  1345. #define SYBEBCIT    20107    /* It's illegal to use BCP terminators with
  1346.                  * program variables other than
  1347.                  * SYBCHAR, SYBBINARY, SYBTEXT, or SYBIMAGE.
  1348.                  */
  1349. #define SYBEBCSA    20108    /* The BCP hostfile '%s' contains only %ld
  1350.                  * rows. Skipping all of these rows is not
  1351.                  * allowed.
  1352.                  */
  1353. #define SYBENULL    20109    /* NULL DBPROCESS pointer passed to DB-Library.
  1354.                  */
  1355. #define SYBEUNAM    20110    /* Unable to get current username from
  1356.                  * operating system.
  1357.                  */
  1358. #define SYBEBCRO    20111    /* The BCP hostfile '%s' contains only %ld
  1359.                  * rows. It was impossible to read the
  1360.                  * requested %ld rows.
  1361.                  */
  1362. #define SYBEMPLL    20112    /* Attempt to set maximum number of DBPROCESSes
  1363.                  * lower than 1.
  1364.                  */
  1365. #define SYBERPIL    20113    /* It is illegal to pass -1 to dbrpcparam()
  1366.                  * for the datalen of parameters which are of
  1367.                  * type SYBCHAR, SYBVARCHAR, SYBBINARY, or
  1368.                  * SYBVARBINARY.
  1369.                  */
  1370. #define SYBERPUL    20114    /* When passing a SYBINTN parameter via
  1371.                  * rpcparam(), it's necessary to specify the
  1372.                  * parameter's maximum or actual length, so
  1373.                  * that DB-Library can recognize it as a
  1374.                  * SYBINT1, SYBINT2, or SYBINT4.
  1375.                  */
  1376. #define SYBEUNOP    20115    /* Unknown option passed to dbsetopt(). */
  1377. #define SYBECRNC    20116    /* The current row is not a result of compute
  1378.                  * clause %d, so it is illegal to attempt to
  1379.                  * extract that data from this row.
  1380.                  */
  1381. #define    SYBERTCC    20117    /* dbreadtext() may not be used to receive
  1382.                  * the results of a query which contains a
  1383.                  * COMPUTE clause.
  1384.                  */
  1385. #define SYBERTSC    20118    /* dbreadtext() may only be used to receive
  1386.                  * the results of a query which contains a
  1387.                  * single result column.
  1388.                  */
  1389. #define SYBEUCRR    20119    /* Internal software error: Unknown
  1390.                  * connection result reported by                         * dbpasswd().
  1391.                  */
  1392. #define SYBERPNA    20120    /* The RPC facility is available only when
  1393.                  * using a SQL Server whose version number
  1394.                  * is 4.0 or greater.
  1395.                  */
  1396. #define SYBEOPNA    20121    /* The text/image facility is available only
  1397.                  * when using a SQL Server whose version number
  1398.                  * is 4.0 or greater.
  1399.                  */
  1400. #define SYBEFGTL    20122   /* Bcp: Row number for the first row to be 
  1401.                 ** copied cannot be greater than the row 
  1402.                 ** number for the last row to be copied.
  1403.                 */
  1404. #define SYBEACNV    20123    /* Attempt to do conversion with NULL 
  1405.                 ** destination variable.
  1406.                 */
  1407. #define SYBENTST        20124   /* The file being opened must be a stream_lf.
  1408.                 */
  1409.  
  1410. /* Forward declarations of DB-LIBRARY routines */
  1411.  
  1412. RETCODE        abort_xact();
  1413. void        close_commit();
  1414. RETCODE        commit_xact();
  1415.  
  1416. DBINT        bcp_batch();
  1417. RETCODE        bcp_bind();
  1418. RETCODE        bcp_colfmt();
  1419. RETCODE        bcp_collen();
  1420. RETCODE        bcp_colptr();
  1421. RETCODE        bcp_columns();
  1422. RETCODE        bcp_control();
  1423. DBINT        bcp_done();
  1424. RETCODE        bcp_exec();
  1425. RETCODE        bcp_init();
  1426. RETCODE        bcp_sendrow();
  1427.  
  1428. int        datetochar();
  1429. BYTE        *dbadata();
  1430. DBINT        dbadlen();
  1431. int        dballcols();
  1432. RETCODE        dbaltbind();
  1433. int        dbaltcolid();
  1434. DBINT        dbaltlen();
  1435. char        *dbaltname();
  1436. int        dbaltop();
  1437. int        dbalttype();
  1438. RETCODE        dbbind();
  1439. BYTE        *dbbylist();
  1440. RETCODE        dbcancel();
  1441. char        *dbchange();
  1442. void        dbclose();
  1443. void        dbclrbuf();
  1444. RETCODE        dbclropt();
  1445. RETCODE        dbcmd();
  1446. BOOL        dbcolbrowse();
  1447. DBINT        dbcollen();
  1448. char        *dbcolname();
  1449. char        *dbcolsource();
  1450. int        dbcoltype();
  1451. char        *dbcolufmt();
  1452. char        *dbcontrolcmd();
  1453. DBINT        dbconvert();
  1454. DBINT        (*dbcvtproc())();
  1455. BYTE        *dbdata();
  1456. DBINT        dbdatlen();
  1457. int        (*dberrhandle())();
  1458. int        dberrno();
  1459. char        *dberrstr();
  1460. void        dbexit();
  1461. RETCODE        dbfcmd();
  1462. void        dbfprhead();
  1463. void        dbfreebuf();
  1464. void        dbfreequal();
  1465. char        *dbgetchar();
  1466. char        *dbgetmsg();
  1467. int        dbgetoff();
  1468. STATUS        dbgetrow();
  1469. BYTE        *dbgetuserdata();
  1470. RETCODE        dbinit();
  1471. BOOL        dbisopt();
  1472. BYTE        *dbkeydata();
  1473. DBINT        dbkeydlen();
  1474. LOGINREC    *dblogin();
  1475. void        dbloginfree();
  1476. int        (*dbmsghandle())();
  1477. char        *dbname();
  1478. STATUS        dbnextrow();
  1479. int        dbnumalts();
  1480. int        dbnumcols();
  1481. int        dbnumcompute();
  1482. int        dbnumkeys();
  1483. int        dbnummsg();
  1484. int        dbnumrets();
  1485. DBPROCESS    *dbopen();
  1486. int        dbordercol();
  1487. char        *dboserrstr();
  1488. void        dbperror();
  1489. void        dbprhead();
  1490. RETCODE        dbprrow();
  1491. char        *dbprtype();
  1492. char        *dbqual();
  1493. DBINT        dbreadpage();
  1494. void        dbrecftos();
  1495. RETCODE        dbresults();
  1496. BYTE        *dbretdata();
  1497. DBINT        dbretlen();
  1498. char        *dbretname();
  1499. int        dbrettype();
  1500. RETCODE        dbsafestr();
  1501. char        *dbservermsg();
  1502. void        dbsetavail();
  1503. void        dbsetbusy();
  1504. void        dbsetidle();
  1505. void        dbsetinterrupt();
  1506. RETCODE        dbsetlogintime();
  1507. RETCODE        dbsetmaxprocs();
  1508. BOOL        dbsetmsg();
  1509. RETCODE        dbsetnull();
  1510. RETCODE        dbsetopt();
  1511. RETCODE        dbsettime();
  1512. RETCODE        dbsettimeout();
  1513. RETCODE        dbsetufmt();
  1514. void        dbsetuserdata();
  1515. RETCODE        dbsqlexec();
  1516. RETCODE        dbsqlok();
  1517. RETCODE        dbsqlsend();
  1518. RETCODE        dbstrcpy();
  1519. int        dbstrlen();
  1520. BOOL        dbtabbrowse();
  1521. int        dbtabcount();
  1522. char        *dbtabname();
  1523. char        *dbtabsource();
  1524. DBBINARY    *dbtimestamp();
  1525. int        dbtslen();
  1526. char        *dbtsname();
  1527. int        dbtsnewlen();
  1528. DBBINARY    *dbtsnewval();
  1529. RETCODE        dbtsput();
  1530. RETCODE        dbtxplen();
  1531. DBBINARY    *dbtxptr();
  1532. DBBINARY    *dbtxtimestamp();
  1533. DBBINARY    *dbtxtsnewval();
  1534. RETCODE        dbtxtsput();
  1535. RETCODE        dbuse();
  1536. BOOL        dbwillconvert();
  1537. RETCODE        dbwritepage();
  1538. RETCODE        dbwritetext();
  1539. char        *mnytochar();
  1540. DBPROCESS    *open_commit();
  1541. DBINT        start_xact();
  1542.  
  1543. /* VMS programs can use the AST facility to write asynchronous DB-LIBRARY
  1544.  * programs.
  1545.  */
  1546.  
  1547. #if VMS
  1548. extern RETCODE    dbcancel_a();
  1549. extern RETCODE    dbcanquery_a();
  1550. extern RETCODE    dbnextrow_a();
  1551. extern RETCODE    dbopen_a();
  1552. extern RETCODE    dbresults_a();
  1553. extern RETCODE    dbsqlexec_a();
  1554. extern RETCODE    dbsqlok_a();
  1555. #endif /* VMS */
  1556.