home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft_Programmers_Library.7z / MPL / net / sqlpgmr.txt < prev   
Encoding:
Text File  |  2013-11-08  |  428.4 KB  |  15,236 lines

  1.  Microsoft(R) SQL Server - Programmer's Reference - for C
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  ────────────────────────────────────────────────────────────────────────────
  10.  Microsoft(R) SQL Server - Programmer's Reference - for C
  11.  
  12.  The SYBASE(R) SQL Server database for PC networks
  13.  VERSION 1.1
  14.  ────────────────────────────────────────────────────────────────────────────
  15.  
  16.  
  17.  for the MS(R) OS/2 Operating System
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  Microsoft Corporation
  27.  
  28.  Information in this document is subject to change without notice and does
  29.  not represent a commitment on the part of Microsoft Corporation. The
  30.  software described in this document is furnished under a license agreement
  31.  or nondisclosure agreement. The software may be used or copied only in
  32.  accordance with the terms of the agreement. It is against the law to copy
  33.  the software on any medium except as specifically allowed in the license or
  34.  nondisclosure agreement. No part of this manual may be reproduced or
  35.  transmitted in any form or by any means, electronic or mechanical, including
  36.  photocopying and recording, for any purpose without the express written
  37.  permission of Microsoft Corporation.
  38.  (C) 1990 Microsoft Corporation and SYBASE, Inc. All rights reserved.
  39.  
  40.  
  41.  Printed in the USA.
  42.  
  43.  
  44.  Microsoft, MS, MS-DOS, and the Microsoft logo are registered
  45.  trademarks of Microsoft Corporation. Windows is a trademark of Microsoft
  46.  Corporation.
  47.  
  48.  IBM is a registered trademark of International Business
  49.  Machines Corporation.
  50.  
  51.  SYBASE is a registered trademark of SYBASE, Inc.
  52.  TRANSACT-SQL and DB-LIBRARY are trademarks of SYBASE, Inc.
  53.  
  54.  Document Number: SY10232-0290
  55.   OEM-D/0788-1Z
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  Table of Contents
  63.  ────────────────────────────────────────────────────────────────────────────
  64.  
  65.  
  66.  
  67.  Before You Begin
  68.       Manual Overview
  69.       How to Use This Guide
  70.       Notational Conventions
  71.       Finding Further Information
  72.  
  73.  Chapter 1  Overview of DB-LIBRARY
  74.  
  75.       Introduction
  76.              TRANSACT-SQL
  77.              Applications for DB-LIBRARY
  78.              Comparing the Library Approach to Embedded SQL
  79.       Communicating with SQL Server
  80.       DB-LIBRARY Programming
  81.              DB-LIBRARY Datatypes
  82.       Finding SQL Servers on the Network
  83.       DB-LIBRARY Functions and Macros
  84.              Initialization
  85.              Command Processing
  86.              Results Processing
  87.              Error and Message Handling
  88.              Information Retrieval
  89.              Browse Mode
  90.              Text and Image Handling
  91.              Datatype Conversion
  92.              Cleanup
  93.              Miscellaneous Functions
  94.              Bulk Copy Special Library
  95.              Two-Phase Commit Service Special Library
  96.  
  97.  Chapter 2  Functions and Macros
  98.  
  99.       Introduction
  100.              dbadata
  101.              dbadlen
  102.              dbaltbind
  103.              dbaltcolid
  104.              dbaltlen
  105.              dbaltop
  106.              dbalttype
  107.              dbbind
  108.              dbbylist
  109.              dbcancel
  110.              dbcanquery
  111.              dbchange
  112.              dbclose
  113.              dbclrbuf
  114.              dbclropt
  115.              dbcmd
  116.              DBCMDROW
  117.              dbcolbrowse
  118.              dbcollen
  119.              dbcolname
  120.              dbcolsource
  121.              dbcoltype
  122.              dbconvert
  123.              DBCOUNT
  124.              DBCURCMD
  125.              DBCURROW
  126.              dbdata
  127.              dbdataready
  128.              dbdatlen
  129.              DBDEAD
  130.              dberrhandle
  131.              dbexit
  132.              dbfcmd
  133.              DBFIRSTROW
  134.              dbfreebuf
  135.              dbfreelogin
  136.              dbfreequal
  137.              dbgetchar
  138.              dbgetmaxprocs
  139.              dbgetoff
  140.              dbgetrow
  141.              DBGETTIME
  142.              DBISAVAIL
  143.              dbinit
  144.              dbisopt
  145.              DBLASTROW
  146.              DBLOCKLIB (Windows only)
  147.              dblogin
  148.              DBMORECMDS
  149.              dbmoretext
  150.              dbmsghandle
  151.              dbname
  152.              dbnextrow
  153.              dbnumalts
  154.              dbnumcols
  155.              dbnumcompute
  156.              DBNUMORDERS
  157.              dbopen
  158.              dbordercol
  159.              dbprhead
  160.              dbprrow
  161.              dbprtype
  162.              dbqual
  163.              DBRBUF
  164.              dbreadpage
  165.              dbresults
  166.              DBROWS
  167.              DBROWTYPE
  168.              dbsetavail
  169.              DBSETLAPP
  170.              DBSETLHOST
  171.              dbsetlogintime
  172.              DBSETLPWD
  173.              DBSETLUSER
  174.              dbsetmaxprocs
  175.              dbsetnull
  176.              dbsetopt
  177.              dbsettime
  178.              dbsqlexec
  179.              dbsqlok
  180.              dbsqlsend
  181.              dbstrcpy
  182.              dbstrlen
  183.              dbtabbrowse
  184.              dbtabcount
  185.              dbtabname
  186.              dbtabsource
  187.              dbtsnewlen
  188.              dbtsnewval
  189.              dbtsput
  190.              dbtxptr
  191.              dbtxtimestamp
  192.              dbtxtsnewval
  193.              dbtxtsput
  194.              DBUNLOCKLIB (Windows only)
  195.              dbuse
  196.              dbwillconvert
  197.              dbwinexit (Windows only)
  198.              dbwritepage
  199.              dbwritetext
  200.  
  201.  Chapter 3  Example Programs
  202.  
  203.       Introduction
  204.       Examples
  205.              Sending Queries in a Command Batch
  206.              Working with Data Files
  207.              Binding Aggregate and Compute Results
  208.              Using Row Buffering
  209.              Converting Data with dbconvert
  210.              Querying and Updating the Database
  211.              Using Browse-Mode Functions
  212.  
  213.  Chapter 4  Bulk Copy Special Library
  214.  
  215.       Introduction
  216.              bcp_batch
  217.              bcp_bind
  218.              bcp_colfmt
  219.              bcp_collen
  220.              bcp_colptr
  221.              bcp_columns
  222.              bcp_control
  223.              bcp_done
  224.              bcp_exec
  225.              bcp_init
  226.              bcp_moretext
  227.              bcp_sendrow
  228.              BCP_SETL
  229.  
  230.  Chapter 5  Two-Phase Commit Special Library
  231.  
  232.       Programming Distributed Transactions
  233.              The Commit Service and the Application Program
  234.              The Probe Process
  235.       The Two-Phase Commit Functions
  236.              Specifying the Commit Server
  237.              Two-Phase Commit Example Program
  238.              abort_xact
  239.              build_xact_string
  240.              close_commit
  241.              commit_xact
  242.              open_commit
  243.              remove_xact
  244.              scan_xact
  245.              start_xact
  246.              stat_xact
  247.  
  248.  Appendix A  Functions and Macros
  249.  
  250.       DB-LIBRARY Functions and Macros
  251.       Bulk Copy Functions
  252.       Two-Phase Commit Functions
  253.  
  254.  Appendix B  DB-LIBRARY Options
  255.  
  256.       Introduction
  257.       Options
  258.  
  259.  Appendix C  DB-LIBRARY Datatypes
  260.  
  261.       Introduction
  262.       Datatypes
  263.              SQL Type Definitions
  264.  
  265.  Appendix D  Error Messages
  266.  
  267.       Introduction
  268.       Errors
  269.       Error Severity Levels
  270.  
  271.  Appendix E  Building Applications
  272.  
  273.       Building MS-DOS Applications
  274.              Terminate and Stay Resident Utility
  275.              Libraries
  276.              Include Files
  277.              Required System Libraries
  278.              Compiling and Linking Considerations
  279.              Increasing the Number of SQL Server Connections
  280.              Sample Program
  281.       Building MS OS/2 Applications
  282.              Libraries
  283.              Include Files
  284.              Special Considerations
  285.              Compiling and Linking Considerations
  286.              Sample Programs
  287.       Building an Application for Windows
  288.              Libraries
  289.              Include Files
  290.              Special Windows DB-LIBRARY Functions
  291.              Special Considerations for Windows DB-LIBRARY Applications
  292.              Increasing the Number of Allowable Open Files
  293.              Sample Program
  294.  
  295.  Appendix F  Finding SQL Servers on the Network
  296.  
  297.  
  298.  Appendix G  Relative Sizes of Library Routines
  299.  
  300.       Static Link Library Memory Costs
  301.       DB-LIBRARY Core Routines
  302.       Relative Memory Sizes
  303.              Setting Up the LOGINREC
  304.              Establishing an SQL Server Connection
  305.              Setting the Current Database
  306.              Building a Command Batch
  307.              Accessing a Command Batch
  308.              Executing a Command Batch
  309.              Setting and Clearing Command Options
  310.              Setting Up the Results
  311.              Getting Result Data
  312.              Accessing Result Rows
  313.              Canceling Results
  314.              Setting Response Time for Results
  315.              Error and Message Handling
  316.              Regular Result Column Information
  317.              Compute Result Column Information
  318.              Row Buffer Information
  319.              Command State Information
  320.              Miscellaneous Information
  321.              Browse Mode
  322.              Text and Image Handling
  323.              Datatype Conversion
  324.              Cleanup
  325.              Miscellaneous Functions
  326.              Bulk Copy
  327.              Two-Phase Commit
  328.       Modularity
  329.  
  330.  Index
  331.  
  332.  
  333.  
  334.  
  335.  Before You Begin
  336.  ────────────────────────────────────────────────────────────────────────────
  337.  
  338.  
  339.  Manual Overview
  340.  
  341.  This manual describes DB-LIBRARY(tm), a set of C routines and macros that
  342.  allows your application to interact with SQL Server. The manual is written
  343.  for programmers who are developing SQL Server applications.
  344.  
  345.  Before using this manual, you should be familiar with TRANSACT-SQL(tm),
  346.  which is described in SQL Server Learning TRANSACT-SQL and in the SQL Server
  347.  Language Reference.
  348.  
  349.  
  350.  How to Use This Guide
  351.  
  352.  The following topics are covered in this manual:
  353.  
  354.  ────────────────────────────────────────────────────────────────────────────
  355.  Chapter 1
  356.    A summary of all DB-LIBRARY functions and macros grouped by category
  357.  
  358.  Chapter 2
  359.    DB-LIBRARY functions and macros
  360.  
  361.  Chapter 3
  362.    Sample programs
  363.  
  364.  Chapter 4
  365.    Bulk copy functions
  366.  
  367.  Chapter 5
  368.    Two-phase commit service functions
  369.  
  370.  Appendix A
  371.    An alphabetical listing of functions and macros
  372.  
  373.  Appendix B
  374.    DB-LIBRARY options
  375.  
  376.  Appendix C
  377.    DB-LIBRARY datatypes and definitions
  378.  
  379.  Appendix D
  380.    DB-LIBRARY errors and error severity levels
  381.  
  382.  Appendix E
  383.    Building applications
  384.  
  385.  Appendix F
  386.    Finding SQL Servers on the network
  387.  
  388.  Appendix G
  389.    Relative sizes of DB-LIBRARY routines
  390.  
  391.  ────────────────────────────────────────────────────────────────────────────
  392.  Notational Conventions
  393.  
  394.  Throughout this manual, the following conventions are used to distinguish
  395.  elements of text:
  396.  
  397. ╓┌─────────────────────────────────┌─────────────────────────────────────────
  398.  Convention                        Purpose
  399.  ────────────────────────────────────────────────────────────────────────────
  400.  UPPERCASE                         Represents statement and clause names,
  401.  Convention                        Purpose
  402.  ────────────────────────────────────────────────────────────────────────────
  403.  UPPERCASE                         Represents statement and clause names,
  404.                                    functions, macros, and any other portions
  405.                                    of syntax that must appear exactly as
  406.                                    shown.
  407.  
  408.  SMALL CAPS                        Represent key names such as CTRL.
  409.  
  410.  bold                              Represents stored procedures, system
  411.                                    procedures, triggers, defaults, rules,
  412.                                    utility programs, and commands.
  413.  
  414.  italic                            Represents database names, table names,
  415.                                    view names, column names, datatypes, index
  416.                                    names, pathnames, filenames, and variables
  417.                                    that appear in text.
  418.  
  419.  monospace                         Represents examples, screen output,
  420.                                    program code, and error messages.
  421.  
  422.  Convention                        Purpose
  423.  ────────────────────────────────────────────────────────────────────────────
  424. 
  425.  [brackets]                        Enclose optional items. Type only the
  426.                                    information within the brackets, not the
  427.                                    brackets themselves.
  428.  
  429.  {braces}                          Enclose required items. Type only the
  430.                                    information within the braces, not the
  431.                                    braces themselves.
  432.  
  433.  | (vertical bar)                  Separates items inside a set of braces or
  434.                                    brackets. The vertical bar means you must
  435.                                    choose one and only one item.
  436.  
  437.  ... (ellipsis)                    Means that you can repeat the previous
  438.                                    item as many times as you like.
  439.  
  440.  <execute>                         Executes one or more SQL statements. (In
  441.                                    the SQL Server Administration facility,
  442.                                    SQL statements are executed by pressing
  443.  Convention                        Purpose
  444.  ────────────────────────────────────────────────────────────────────────────
  445.                                   SQL statements are executed by pressing
  446.                                    the CONTROL+E keys. In the isql program,
  447.                                    SQL statements are executed with the go
  448.                                    command.)
  449.  
  450.  ────────────────────────────────────────────────────────────────────────────
  451.  
  452.  
  453.  
  454.  
  455.  Finding Further Information
  456.  
  457.  The following manuals describe SQL Server and are included in the standard
  458.  documentation set:
  459.  
  460.  ────────────────────────────────────────────────────────────────────────────
  461.  SQL Server Installation Guide
  462.    A guide to installing and setting up SQL Server
  463.  
  464.  SQL Server Learning TRANSACT-SQL
  465.    A guide to learning and using TRANSACT-SQL
  466.  
  467.  SQL Server System Administrator's Guide
  468.    A guide to managing SQL Server and to using the SQL Server Administration
  469.    Facility (SAF) for database queries
  470.  
  471.  SQL Server Language Reference
  472.    A reference to the syntax of all TRANSACT-SQL statements, commands,
  473.    procedures, and utilities
  474.  
  475.  SQL Server Quick Reference
  476.    A quick reference guide to TRANSACT-SQL
  477.  
  478.  ────────────────────────────────────────────────────────────────────────────
  479.  
  480.  
  481.  
  482.  
  483.  Chapter 1  Overview of DB-LIBRARY
  484.  ────────────────────────────────────────────────────────────────────────────
  485.  
  486.  
  487.  Introduction
  488.  
  489.  DB-LIBRARY is a set of C functions and macros that allows your application
  490.  to interact with SQL Server. It includes functions that send TRANSACT-SQL
  491.  statements to SQL Server and functions that process the results of those
  492.  statements. Other functions handle errors, perform data conversion, and
  493.  provide a variety of information about the interaction with SQL Server.
  494.  
  495.  
  496.  TRANSACT-SQL
  497.  
  498.  TRANSACT-SQL is the enhanced SQL Server version of the Structured Query
  499.  Language (SQL) database language. The application uses TRANSACT-SQL to
  500.  communicate with SQL Server. TRANSACT-SQL provides statements for creating
  501.  and manipulating database objects, as well as for inserting, updating, and
  502.  selecting data. The TRANSACT-SQL enhancements include data integrity
  503.  features and stored procedures. Stored procedures allow much of an
  504.  application's processing logic to be shifted from the front-end application
  505.  to SQL Server. They can contain most TRANSACT-SQL statements, including
  506.  TRANSACT-SQL control-of-flow statements. Furthermore, stored procedures are
  507.  precompiled, so the statements don't have to be parsed each time the
  508.  procedure is executed.
  509.  
  510.  
  511.  Applications for DB-LIBRARY
  512.  
  513.  DB-LIBRARY enables the database to become an integral part of an
  514.  application. TRANSACT-SQL statements can be incorporated into the
  515.  application, allowing the application to retrieve and update values from a
  516.  database. Through DB-LIBRARY, values from the database can be placed in
  517.  program variables for manipulation by the application. Conversely, values in
  518.  program variables can be inserted into the database.
  519.  
  520.  Although DB-LIBRARY contains a large number of functions, giving the
  521.  application much control over its interaction with SQL Server, most
  522.  applications require only a few of the functions. The actual process of
  523.  connecting with SQL Server, sending TRANSACT-SQL statements to SQL Server,
  524.  and processing the resulting data is simple and straightforward.
  525.  
  526.  
  527.  Comparing the Library Approach to Embedded SQL
  528.  
  529.  The DB-LIBRARY approach is distinctly different from the "embedded SQL" type
  530.  of language interface that some other database management systems provide.
  531.  In contrast to an embedded SQL interface, the DB-LIBRARY interface does not
  532.  require a language precompiler. Avoiding preprocessing in this way makes
  533.  applications involving a database more straightforward to write and to
  534.  debug. The DB-LIBRARY functions are C functions and are not preprocessed
  535.  into some intermediate form.
  536.  
  537.  
  538.  Communicating with SQL Server
  539.  
  540.  DB-LIBRARY functions communicate with SQL Server through the DBPROCESS
  541.  structure. The dbopen function allocates and initializes a DBPROCESS when it
  542.  logs on to SQL Server. The DBPROCESS serves as the connection between the
  543.  application and SQL Server. Most DB-LIBRARY functions require a DBPROCESS as
  544.  the first parameter. An application may have more than one DBPROCESS if, for
  545.  instance, it needs to perform updates to a database while it is still
  546.  processing the results of a previous query. Each DBPROCESS is completely
  547.  independent of any other DBPROCESS.
  548.  
  549.  The DBPROCESS structure points to a command buffer that contains
  550.  TRANSACT-SQL statements for transmission to SQL Server. It also points to
  551.  result rows returned from SQL Server─either single or multiple rows or a
  552.  buffer of rows if buffering has been specified.
  553.  
  554.  The DBPROCESS also contains information on various aspects of SQL Server
  555.  interaction. Many of the DB-LIBRARY functions extract information from the
  556.  DBPROCESS. Applications access and manipulate components of the DBPROCESS
  557.  structure only through DB-LIBRARY functions, not directly.
  558.  
  559.  One other structure of importance is the LOGINREC. This is the login record
  560.  that contains information the dbopen function uses to log on to SQL Server.
  561.  It contains typical login information, such as the username and the
  562.  password. This information can be specified through DB-LIBRARY functions.
  563.  
  564.  ────────────────────────────────────────────────────────────────────────────
  565.  NOTE
  566.  
  567.  Under Microsoft(R) Operating System/2 (MS(R) OS/2), each DB process is a
  568.  separate execution thread. This thread is spawned when the connection to SQL
  569.  Server is established and terminated when the connection is closed.
  570.  ────────────────────────────────────────────────────────────────────────────
  571.  
  572.  
  573.  DB-LIBRARY Programming
  574.  
  575.  Programming with DB-LIBRARY typically involves a few basic steps:
  576.  
  577.  
  578.    1.  Logging on to SQL Server.
  579.  
  580.    2.  Placing TRANSACT-SQL statements into a buffer and sending them to SQL
  581.        Server.
  582.  
  583.    3.  Processing the results, if any, returned from SQL Server, one
  584.        statement at a time and one row at a time. The results can be placed
  585.        in program variables, where the application can manipulate them.
  586.  
  587.    4.  Handling DB-LIBRARY errors and SQL Server messages.
  588.  
  589.    5.  Closing the connection with SQL Server.
  590.  
  591.  
  592.  The following example shows the basic framework of many DB-LIBRARY
  593.  applications. The program opens a connection to SQL Server, sends a
  594.  TRANSACT-SQL SELECT statement to SQL Server, and processes the set of rows
  595.  resulting from the SELECT. For brevity's sake, this program does not include
  596.  the error or message handling functions; those functions are illustrated in
  597.  the examples in Chapter 3, "Example Programs." For information about
  598.  defining the target operating system prior to compiling your application,
  599.  see Appendix E, "Building Applications."
  600.  
  601.    #include <sqlfront.h>
  602.     #include <sqldb.h>
  603.  
  604.     /* Forward declarations of the error handler and message handler. */
  605.     int err_handler();
  606.     int msg_handler();
  607.  
  608.     main()
  609.     {
  610.      DBPROCESS *dbproc; /* The connection with SQL Server. */
  611.      LOGINREC *login; /* The login information. */
  612.      DBCHAR name[40];
  613.      DBCHAR city[20];
  614.  
  615.      /*
  616.      ** Install user-supplied error- and message-handling functions.
  617.      ** The code for these is omitted from this example for conciseness.
  618.      */
  619.      dberrhandle(err_handler);
  620.      dbmsghandle(msg_handler);
  621.  
  622.      /* Get a LOGINREC. */
  623.      login = dblogin();
  624.      DBSETLUSER(login, "user");
  625.      DBSETLPWD(login, "my_passwd");
  626.      DBSETLAPP(login, "example");
  627.  
  628.      /* Get a DBPROCESS structure for communication with SQL Server. */
  629.      dbproc = dbopen(login, "my_server");
  630.  
  631.      /*
  632.      ** Retrieve some columns from the "authors" table in the
  633.      ** "pubs" database.
  634.      */
  635.  
  636.      /* First, put the command into the command buffer. */
  637.      dbcmd(dbproc, "select au_lname, city from pubs..authors");
  638.      dbcmd(dbproc, " where state = 'CA' ");
  639.  
  640.      /* Send the command to SQL Server and start execution. */
  641.      dbsqlexec(dbproc);
  642.  
  643.      /* Process the command. */
  644.      if (dbresults(dbproc) == SUCCEED)
  645.      {
  646.       /* Bind results to program variables. */
  647.       dbbind(dbproc, 1, STRINGBIND, (DBINT) 0, name);
  648.       dbbind(dbproc, 2, STRINGBIND, (DBINT) 0, city);
  649.  
  650.       /* Retrieve and print the result rows. */
  651.       while (dbnextrow(dbproc) != NO_MORE_ROWS)
  652.       {
  653.        printf ("%s: %s\n", name, city);
  654.       }
  655.      }
  656.  
  657.      /* Close the connection to SQL Server. */
  658.      dbexit();
  659.     }
  660.  
  661.  The example illustrates features common to most DB-LIBRARY applications.
  662.  These features are
  663.  
  664.  header files
  665.    Two header files, sqlfront.h and sqldb.h, are required in all source files
  666.    that contain calls to DB-LIBRARY functions. The sqlfront.h file must
  667.    appear first in the file. It defines symbolic constants, such as function
  668.    return values, described in Chapter 2, "Functions and Macros," and the
  669.    exit values STDEXIT and ERREXIT. These exit values can be used as the
  670.    parameter for the C standard library function EXIT. Since they are defined
  671.    appropriately for the operating system running the program, their use
  672.    provides a system-independent approach to exiting the program. The
  673.    sqlfront.h file also includes typedefs for datatypes that can be used in
  674.    program variable declarations. These datatypes are described in Appendix
  675.    C, "DB-LIBRARY Datatypes."
  676.  
  677.    The sqldb.h file contains additional definitions and typedefs, most of
  678.    which are meant to be used only by the DB-LIBRARY functions. They should
  679.    not be directly accessed by the program. To ensure compatibility with
  680.    future releases of DB-LIBRARY, use the contents of sqldb.h only as
  681.    documented in this manual.
  682.  
  683.  dberrhandle and dbmsghandle
  684.    The first of these DB-LIBRARY functions, dberrhandle, installs a
  685.    user-supplied error-handling function, which is called automatically
  686.    whenever the application encounters a DB-LIBRARY error. Similarly,
  687.    dbmsghandle installs a message-handling function, which is called in
  688.    response to informational or error messages returned from SQL Server. The
  689.    error- and message-handling functions are user-supplied. Sample handlers
  690.    have not been supplied with the example provided at the beginning of this
  691.    section but are included at the end of each example program in Chapter 3,
  692.    "Example Programs."
  693.  
  694.  dblogin
  695.    This function supplies a LOGINREC structure, which DB-LIBRARY uses to log
  696.    in to SQL Server. Two macros set certain components of the LOGINREC.
  697.    DBSETLPWD sets the password that DB-LIBRARY uses when logging in.
  698.    DBSETLAPP sets the name of the application, which appears in SQL Server's
  699.    sysprocess table. Functions are available for setting other aspects of the
  700.    LOGINREC. The LOGINREC contains default values for each of the values they
  701.    set.
  702.  
  703.  dbopen
  704.    This function opens a connection between the application and SQL Server.
  705.    It uses the LOGINREC supplied by dblogin to log in to the server. It
  706.    returns a DBPROCESS structure, which serves as the conduit for information
  707.    between the application and the server. After this function has been
  708.    called, the application is connected with SQL Server and can send
  709.    TRANSACT-SQL statements to SQL Server and process results.
  710.  
  711.  dbcmd
  712.    This function fills the command buffer with TRANSACT-SQL statements, which
  713.    can then be sent to SQL Server. Each succeeding call to dbcmd adds the
  714.    supplied text to the end of any text already in the buffer. It is the
  715.    programmer's responsibility to supply necessary blanks between words, such
  716.    as the blank at the beginning of the text in the second dbcmd call in the
  717.    example. Multiple statements can be included in the buffer. This example
  718.    only shows how to send and process a single statement, but DB-LIBRARY
  719.    allows an application to send multiple statements to SQL Server and
  720.    process each statement's set of results separately.
  721.  
  722.  dbsqlexec
  723.    This function executes the command buffer; that is, it sends the contents
  724.    of the buffer to SQL Server, which parses and executes the commands.
  725.  
  726.  dbresults
  727.    This function gets the results of the current TRANSACT-SQL statement ready
  728.    for processing. In this example, the buffer contains only a single
  729.    statement, so dbresults is called only once. If the buffer contained
  730.    multiple statements, the program would need to call dbresults once for
  731.    each statement in the buffer.
  732.  
  733.  dbbind
  734.    This function binds result columns to program variables. In the example,
  735.    the first call to dbbind binds the first result column to the name
  736.    variable. In other words, when the program reads a result row by calling
  737.    dbnextrow, the contents of the first column in the result row is placed in
  738.    the name variable. The datatype of the binding is "STRINGBIND", one of
  739.    several binding types available for character data. The second call binds
  740.    the second result column to the city variable.
  741.  
  742.  dbnextrow
  743.    This function reads a row and places the results in the program variables
  744.    specified by the earlier dbbind calls. Each successive call to dbnextrow
  745.    reads another result row until the last row has been read and NO_MORE_ROWS
  746.    is returned. Processing of the results must take place inside the
  747.    dbnextrow loop because each call to dbnextrow overwrites the previous
  748.    values in the program variables. Even if you know that the query returns
  749.    only one row, you still must call dbnextrow twice: once to get the result
  750.    row and once to get the NO_MORE_ROWS indication.
  751.  
  752.  dbexit
  753.    This function closes all SQL Server connections and frees all DBPROCESS
  754.    structures created as a result of your program. It is usually the last
  755.    DB-LIBRARY function in the program.
  756.  
  757.  Although DB-LIBRARY contains a great number of functions, much can be
  758.  accomplished with just the functions shown in this example.
  759.  
  760.  
  761.  DB-LIBRARY Datatypes
  762.  
  763.  DB-LIBRARY defines datatypes for SQL Server data. These datatypes begin with
  764.  "SQL" (for example, SQLINT4, SQLCHAR, SQLMONEY). DB-LIBRARY also provides
  765.  typedefs for use in program variable declarations. These typedefs begin with
  766.  the prefix "DB" (for example, DBINT, DBCHAR, DBMONEY, and so on). By using
  767.  them, you ensure that your program variables will be compatible with SQL
  768.  Server datatypes. For a list of SQL Server datatypes and the DB-LIBRARY
  769.  program variable types, see Appendix C, "DB-LIBRARY Datatypes."
  770.  
  771.  The dbconvert function provides a way to convert data from one SQL Server
  772.  datatype to another. It supports conversion between most datatypes. Since
  773.  the SQL Server datatypes correspond directly to the DB-LIBRARY datatypes,
  774.  you can use dbconvert widely within your application. The functions that
  775.  bind SQL Server result columns to program variables─dbbind and
  776.  dbaltbind─also provide type conversion.
  777.  
  778.  
  779.  Finding SQL Servers on the Network
  780.  
  781.  Information on all SQL Servers is contained in the workstation's LAN Manager
  782.  table, which is updated whenever an SQL Server is added or deleted from the
  783.  network. For information on locating an SQL Server on the network from an
  784.  application program, see Appendix F, "Finding SQL Servers on the Network."
  785.  
  786.  
  787.  DB-LIBRARY Functions and Macros
  788.  
  789.  DB-LIBRARY functions and macros handle a large variety of tasks. These tasks
  790.  are divided into a number of categories:
  791.  
  792.  
  793.    ■   Initialization
  794.  
  795.    ■   Command processing
  796.  
  797.    ■   Results processing
  798.  
  799.    ■   Error and message handling
  800.  
  801.    ■   Information retrieval
  802.  
  803.    ■   Browse mode
  804.  
  805.    ■   Text and image handling
  806.  
  807.    ■   Datatype conversion
  808.  
  809.    ■   Cleanup
  810.  
  811.    ■   Miscellaneous
  812.  
  813.  
  814.  Chapter 2, "Functions and Macros" describes the functions and macros in
  815.  individual reference pages. They all begin with the prefix "db". Functions
  816.  are spelled with lowercase letters. Macros are spelled with uppercase
  817.  letters. Macros are provided for compatibility with other SYBASE(R)
  818.  platforms only. All macros map directly to functions in this release.
  819.  
  820.  In addition, DB-LIBRARY includes two special libraries:
  821.  
  822.  
  823.    ■   Bulk Copy
  824.  
  825.    ■   Two-Phase Commit Service
  826.  
  827.  
  828.  Chapter 4, "Bulk Copy Special Library," and Chapter 5, "Two-Phase Commit
  829.  Special Library," describe the functions in these libraries. The bulk copy
  830.  functions begin with the prefix "bcp_". The two-phase commit service
  831.  functions have no standard prefix.
  832.  
  833.  
  834.  Initialization
  835.  
  836.  The functions in this section set up and define the connection between the
  837.  application program and SQL Server. They handle such tasks as allocating and
  838.  defining a LOGINREC structure, opening a connection to SQL Server, and
  839.  allocating a DBPROCESS structure. Only a few of the functions are absolutely
  840.  necessary in every DB-LIBRARY program; in particular, an application
  841.  requires dblogin and dbopen. The following sections specify the
  842.  initialization functions. The sections are in the approximate order in which
  843.  a program is likely to call them.
  844.  
  845.  
  846.  Setting Up the LOGINREC
  847.  
  848.  These functions and macros allocate and define the LOGINREC structure, which
  849.  can then be used to open a connection to SQL Server:
  850.  
  851.  ────────────────────────────────────────────────────────────────────────────
  852.  dbfreelogin
  853.    Frees a LOGINREC.
  854.  
  855.  dblogin
  856.    Allocates a LOGINREC for subsequent use by dbopen.
  857.  
  858.  DBSETLAPP
  859.    Sets the application name in the LOGINREC.
  860.  
  861.  DBSETLHOST
  862.    Sets the workstation name in the LOGINREC.
  863.  
  864.  DBSETLPWD
  865.    Sets the SQL Server password in the LOGINREC.
  866.  
  867.  DBSETLUSER
  868.    Sets the SQL Server username in the LOGINREC.
  869.  
  870.  ────────────────────────────────────────────────────────────────────────────
  871.  Establishing an SQL Server Connection
  872.  
  873.  These functions connect the application to a particular SQL Server:
  874.  
  875.  ────────────────────────────────────────────────────────────────────────────
  876.  dbopen
  877.    Sets up communication with the network, logs in to SQL Server using the
  878.    LOGINREC, initializes any options specified in the LOGINREC, and allocates
  879.    a DBPROCESS. An application can open multiple connections to SQL Server,
  880.    each with its own DBPROCESS.
  881.  
  882.  dbsetlogintime
  883.    Sets the number of seconds DB-LIBRARY waits for SQL Server to respond to a
  884.    request by dbopen for a DBPROCESS connection.
  885.  
  886.  ────────────────────────────────────────────────────────────────────────────
  887.  Setting the Current Database
  888.  
  889.  Once the application has been connected to an SQL Server, the database
  890.  context can be changed.
  891.  
  892.  ────────────────────────────────────────────────────────────────────────────
  893.  dbuse
  894.    Sets the current database. This function is equivalent to the TRANSACT-SQL
  895.    USE statement and can be called repeatedly in an application.
  896.  
  897.  ────────────────────────────────────────────────────────────────────────────
  898.  Command Processing
  899.  
  900.  The application communicates with SQL Server through TRANSACT-SQL
  901.  statements. It enters the statements into a command buffer, which the
  902.  DBPROCESS points to. The application can place multiple statements in the
  903.  command buffer; the set of statements in the buffer is known as the command
  904.  batch. The application then sends the command batch to SQL Server, which
  905.  executes the statements in the order entered in the buffer.
  906.  
  907.  
  908.  Building the Command Batch
  909.  
  910.  These functions add statements to the buffer or clear the buffer:
  911.  
  912.  ────────────────────────────────────────────────────────────────────────────
  913.  dbcmd
  914.    Adds text to the command buffer. It may be called repeatedly to add
  915.    multiple statements or parts of statements. The text added with each
  916.    successive call is concatenated to the previous text.
  917.  
  918.  dbfcmd
  919.    Adds text to the command buffer using sprintf-type formatting. This
  920.    function is the same as dbcmd except that it allows parameters to be
  921.    substituted into the text.
  922.  
  923.  dbfreebuf
  924.    Clears the command buffer. The command buffer is automatically cleared
  925.    before a batch of statements is entered. To clear it at other times or
  926.    when the DBNOAUTOFREE option has been set, use dbfreebuf.
  927.  
  928.  ────────────────────────────────────────────────────────────────────────────
  929.  Accessing the Command Batch
  930.  
  931.  These functions can be used to examine and copy parts of the command buffer:
  932.  
  933.  
  934.  ────────────────────────────────────────────────────────────────────────────
  935.  dbgetchar
  936.    Returns a pointer to a particular character in the command buffer.
  937.  
  938.  dbstrcpy
  939.    Copies a portion of the command buffer to a program variable. This
  940.    function is particularly valuable for debugging because it can tell you
  941.    exactly what was sent to SQL Server.
  942.  
  943.  dbstrlen
  944.    Returns the length of the contents of the command buffer.
  945.  
  946.  ────────────────────────────────────────────────────────────────────────────
  947.  Executing the Command Batch
  948.  
  949.  Once TRANSACT-SQL statements have been entered in the buffer, they can be
  950.  sent to SQL Server for execution.
  951.  
  952.  ────────────────────────────────────────────────────────────────────────────
  953.  dbdataready
  954.    Determines whether database command processing has completed.
  955.  
  956.  dbsqlexec
  957.    Sends the contents of the command buffer to SQL Server for execution. Once
  958.    dbsqlexec has returned SUCCEED, dbresults must be called to process the
  959.    results. Calling dbsqlexec is equivalent to calling dbsqlsend followed by
  960.    dbsqlok.
  961.  
  962.  dbsqlok
  963.    Verifies the accuracy of a command batch sent to SQL Server. This function
  964.    must be called after a successful return from dbsqlsend. Once dbsqlok has
  965.    returned SUCCEED, dbresults must be called to process the results.
  966.  
  967.  dbsqlsend
  968.    Sends the contents of the command buffer to SQL Server for execution.
  969.    Unlike dbsqlexec, this function does not wait for a response from SQL
  970.    Server. When dbsqlsend has returned SUCCEED, dbsqlok must be called to
  971.    verify the accuracy of the command batch.
  972.  
  973.  ────────────────────────────────────────────────────────────────────────────
  974.  Setting and Clearing Command Options
  975.  
  976.  The application can set a number of SQL Server and DB-LIBRARY command
  977.  options. Among them are DBPARSEONLY, which causes SQL Server to parse but
  978.  not execute the command batch, and DBBUFFER, which provides buffering of
  979.  result rows. For a list of all available options, see Appendix B,
  980.  "DB-LIBRARY Options."
  981.  
  982.  ────────────────────────────────────────────────────────────────────────────
  983.  dbclropt
  984.    Clears an option.
  985.  
  986.  dbisopt
  987.    Determines whether a particular option is set.
  988.  
  989.  dbsetopt
  990.    Sets an option.
  991.  
  992.  ────────────────────────────────────────────────────────────────────────────
  993.  Results Processing
  994.  
  995.  Once a command batch has been executed in SQL Server, indicated by dbsqlexec
  996.  or dbsqlok returning SUCCEED, the application must process any results. The
  997.  SELECT statement and EXECUTE statements that contain SELECT statements both
  998.  return result rows. INSERT statements and most other TRANSACT-SQL statements
  999.  also return data needed by the DB-LIBRARY.
  1000.  
  1001.  There are two types of result rows: regular rows and compute rows. Regular
  1002.  rows are generated from columns in a SELECT statement's select list; compute
  1003.  rows are generated from columns in a SELECT statement's COMPUTE clause.
  1004.  Since these two types of rows contain very different data, the application
  1005.  must process them separately.
  1006.  
  1007.  The result for each statement in a batch is returned to the application
  1008.  separately. Within each statement's set of results, the result rows are
  1009.  processed one at a time.
  1010.  
  1011.  
  1012.  Setting Up the Results
  1013.  
  1014.  The results for each statement in the batch must be set up separately with
  1015.  dbresults.
  1016.  
  1017.  ────────────────────────────────────────────────────────────────────────────
  1018.  dbresults
  1019.    Sets up the results of the next statement in the batch. This function must
  1020.    be called once for each statement in the batch, whether or not the
  1021.    statement returns rows.
  1022.  
  1023.    The dbresults function must be called after dbsqlexec or dbsqlok has
  1024.    returned SUCCEED, but before calls to dbbind or dbnextrow.
  1025.  
  1026.  ────────────────────────────────────────────────────────────────────────────
  1027.  Getting Result Data
  1028.  
  1029.  The simplest way to get result data is to bind result columns to program
  1030.  variables by using dbbind and dbaltbind. Then, when a result row is accessed
  1031.  (see the following section, "Accessing Result Rows"), DB-LIBRARY
  1032.  automatically places copies of the columns' data into the program variables
  1033.  to which they are bound.
  1034.  
  1035.  You can also access a result column's data directly with dbdata and dbadata,
  1036.  which return pointers to the data. These functions are frequently used in
  1037.  conjunction with dbdatlen and dbadlen, which return the length of the data
  1038.  and are described later. The dbdata and dbadata functions have the advantage
  1039.  of providing access to the actual data, not a copy of the data.
  1040.  
  1041.  Binding of columns to variables must take place after the call to dbresults
  1042.  but before the first call to dbnextrow. No such preliminary step is needed
  1043.  when results will be directly accessed with dbdata or dbadata.
  1044.  
  1045.  ────────────────────────────────────────────────────────────────────────────
  1046.  dbadata
  1047.    Returns a pointer to the data for a compute row result column.
  1048.  
  1049.  dbaltbind
  1050.    Binds a compute row result column to a program variable.
  1051.  
  1052.  dbbind
  1053.    Binds a regular row result column to a program variable.
  1054.  
  1055.  dbdata
  1056.    Returns a pointer to the data for a regular row result column.
  1057.  
  1058.  ────────────────────────────────────────────────────────────────────────────
  1059.  Accessing Result Rows
  1060.  
  1061.  Once dbresults has returned SUCCEED and any binding of columns to variables
  1062.  has been specified, the application is ready to process the results. The
  1063.  first step is to make the result rows available to the application. The
  1064.  dbnextrow function accomplishes this. Each call to dbnextrow reads the next
  1065.  row returned from SQL Server. The row is read directly from the network.
  1066.  
  1067.  Once a row has been read in by dbnextrow, the application can perform any
  1068.  processing desired on the data in the row. If the result columns have been
  1069.  bound to program variables, the data in the row will have been automatically
  1070.  copied into the variables. Alternatively, the data is accessible through
  1071.  dbdata or dbadata.
  1072.  
  1073.  Rows read in by dbnextrow can be automatically saved in a row buffer, if
  1074.  desired. This is accomplished by setting the DBBUFFER option. Without row
  1075.  buffering, each row must be processed as it is read in by dbnextrow because
  1076.  the next call to dbnextrow will overwrite the previously read row. If row
  1077.  buffering has been turned on, the rows are added to a row buffer as they are
  1078.  read in by dbnextrow. Row buffering allows the application to skip around in
  1079.  the buffer and return to previously read rows.
  1080.  
  1081.  After all result rows have been returned, the final call to dbnextrow
  1082.  returns the NO_MORE_ROWS indication. You must continue calling dbnextrow
  1083.  until it returns NO_MORE_ROWS, even if you know that the query produces only
  1084.  one result row.
  1085.  
  1086.  Functions are also available that print result rows in a default format.
  1087.  Because the format is predetermined, these functions are of limited
  1088.  usefulness and are appropriate primarily for debugging. (These are not
  1089.  available under Microsoft Windows(tm).)
  1090.  
  1091.  DB-LIBRARY processes results one statement at a time. When all the results
  1092.  for one statement have been read, dbresults must be called again to set up
  1093.  the results for the next statement in the command buffer.
  1094.  
  1095.  ────────────────────────────────────────────────────────────────────────────
  1096.  dbclrbuf
  1097.    Drops rows from the row buffer.
  1098.  
  1099.  dbgetrow
  1100.    Reads the specified row in the row buffer. This function provides the
  1101.    application with access to buffered rows that have been previously read by
  1102.    dbnextrow.
  1103.  
  1104.  dbnextrow
  1105.    Reads in the next row. The return value from dbnextrow tells the
  1106.    application whether the row is a regular row or a compute row, whether the
  1107.    buffer is full, and whether the last result row has been read.
  1108.  
  1109.  dbprhead
  1110.    Prints default column headings for result rows. This function is used in
  1111.    conjunction with dbprrow.
  1112.  
  1113.  dbprrow
  1114.    Prints all the result rows in a default format. When this function is
  1115.    used, the program does not need to bind results or call dbnextrow.
  1116.  
  1117.  ────────────────────────────────────────────────────────────────────────────
  1118.  Canceling Results
  1119.  
  1120.  The results of either an entire command batch or a single query can be
  1121.  canceled.
  1122.  
  1123.  ────────────────────────────────────────────────────────────────────────────
  1124.  dbcancel
  1125.    Cancels results from the current command batch. This function cancels all
  1126.    the statements in the current batch.
  1127.  
  1128.  dbcanquery
  1129.    Cancels any rows pending from the most recently executed query.
  1130.  
  1131.  ────────────────────────────────────────────────────────────────────────────
  1132.  Setting Response Time for Results
  1133.  
  1134.  The application can set a limit on SQL Server response time.
  1135.  
  1136.  ────────────────────────────────────────────────────────────────────────────
  1137.  DBGETTIME
  1138.    Gets the number of seconds that DB-LIBRARY will wait for an SQL Server
  1139.    response.
  1140.  
  1141.  dbsettime
  1142.    Sets the number of seconds that DB-LIBRARY will wait for an SQL Server
  1143.    response.
  1144.  
  1145.  ────────────────────────────────────────────────────────────────────────────
  1146.  Error and Message Handling
  1147.  
  1148.  DB-LIBRARY applications deal with two types of errors and messages: those
  1149.  from SQL Server (known as messages) and those generated by DB-LIBRARY
  1150.  functions (known as errors). SQL Server can return both informational and
  1151.  error messages to the application. In addition, DB-LIBRARY has its own set
  1152.  of possible warnings and errors. For a list of DB-LIBRARY errors, see
  1153.  Appendix D, "Error Messages."
  1154.  
  1155.  DB-LIBRARY provides an easy way to centralize error and message handling.
  1156.  Using dbmsghandle and dberrhandle, you can install your own message- and
  1157.  error-handling functions. When a message or error occurs, DB-LIBRARY
  1158.  automatically calls the appropriate user-supplied function, providing
  1159.  information to that function on the nature of the message or error. The
  1160.  error- and message-handling logic can thus be assigned to two functions in
  1161.  your application.
  1162.  
  1163.  ────────────────────────────────────────────────────────────────────────────
  1164.  DBDEAD
  1165.    Determines whether a particular DBPROCESS is dead. When a DBPROCESS is
  1166.    dead, the current DB-LIBRARY function fails, causing the error handler to
  1167.    be called.
  1168.  
  1169.  dberrhandle
  1170.    Installs a user function to handle DB-LIBRARY error messages.
  1171.  
  1172.  dbmsghandle
  1173.    Installs a user function to handle SQL Server informational and error
  1174.    messages.
  1175.  
  1176.  ────────────────────────────────────────────────────────────────────────────
  1177.  Information Retrieval
  1178.  
  1179.  Information covering several areas, including regular result columns,
  1180.  compute result columns, row buffers, and the command state, can be retrieved
  1181.  from the DBPROCESS structure. As mentioned earlier, regular result columns
  1182.  correspond to columns in the SELECT statement's select list, and compute
  1183.  result columns correspond to columns in the SELECT statement's optional
  1184.  COMPUTE clause.
  1185.  
  1186.  
  1187.  Regular Result Column Information
  1188.  
  1189.  These functions can be called after dbsqlexec or dbsqlok returns SUCCEED:
  1190.  
  1191.  ────────────────────────────────────────────────────────────────────────────
  1192.  dbcollen
  1193.    Returns the maximum length for a regular column's data.
  1194.  
  1195.  dbcolname
  1196.    Returns the name of a regular result column.
  1197.  
  1198.  dbcoltype
  1199.    Returns the SQL Server datatype for a regular result column.
  1200.  
  1201.  dbdatlen
  1202.    Returns the actual length of a regular column's data. This function is
  1203.    often used in conjunction with dbdata. The value returned by dbdatlen may
  1204.    be different for each regular row read by dbnextrow.
  1205.  
  1206.  dbnumcols
  1207.    Determines the number of columns in the current set of results.
  1208.  
  1209.  ────────────────────────────────────────────────────────────────────────────
  1210.  Compute Result Column Information
  1211.  
  1212.  These functions can be called after dbsqlexec or dbsqlok returns SUCCEED:
  1213.  
  1214.  ────────────────────────────────────────────────────────────────────────────
  1215.  dbadlen
  1216.    Returns the actual length of a compute column's data. This function is
  1217.    often used in conjunction with dbadata. The value returned by dbadlen may
  1218.    be different for each compute row read by dbnextrow.
  1219.  
  1220.  dbaltcolid
  1221.    Returns the column ID for a compute column.
  1222.  
  1223.  dbaltlen
  1224.    Returns the maximum length for a compute column's data.
  1225.  
  1226.  dbaltop
  1227.    Returns the type of aggregate operator for a compute column.
  1228.  
  1229.  dbalttype
  1230.    Returns the datatype for a compute column.
  1231.  
  1232.  dbbylist
  1233.    Returns the bylist for a compute row.
  1234.  
  1235.  dbnumalts
  1236.    Returns the number of columns in a compute row.
  1237.  
  1238.  dbnumcompute
  1239.    Returns the number of COMPUTE clauses in the current set of results.
  1240.  
  1241.  ────────────────────────────────────────────────────────────────────────────
  1242.  Row Buffer Information
  1243.  
  1244.  These macros return information that can be useful when manipulating result
  1245.  rows in buffers:
  1246.  
  1247.  ────────────────────────────────────────────────────────────────────────────
  1248.  DBFIRSTROW
  1249.    Returns the number of the first row in the buffer.
  1250.  
  1251.  DBLASTROW
  1252.    Returns the number of the last row in the buffer.
  1253.  
  1254.  ────────────────────────────────────────────────────────────────────────────
  1255.  Command State Information
  1256.  
  1257.  These functions and macros return information about the current state of the
  1258.  command batch. Several of them return information about the "current"
  1259.  statement─that is, the statement currently being processed by dbresults.
  1260.  
  1261.  ────────────────────────────────────────────────────────────────────────────
  1262.  DBCMDROW
  1263.    Indicates whether the current statement is one that can return rows (that
  1264.    is, a SELECT or a stored procedure containing a SELECT).
  1265.  
  1266.  DBCOUNT
  1267.    Returns the number of rows affected by a statement.
  1268.  
  1269.  DBCURCMD
  1270.    Returns the number of the current statement in a batch.
  1271.  
  1272.  dbgetoff
  1273.    Checks for the existence of specified TRANSACT-SQL constructs in the
  1274.    command buffer. This function is used with the DBOFFSET option.
  1275.  
  1276.  DBMORECMDS
  1277.    Indicates whether there are more statements in the batch.
  1278.  
  1279.  DBNUMORDERS
  1280.    Returns the number of columns specified in a SELECT statement's ORDER BY
  1281.    clause.
  1282.  
  1283.  dbordercol
  1284.    Returns the ID of a column appearing in a SELECT statement's ORDER BY
  1285.    clause.
  1286.  
  1287.  DBROWS
  1288.    Indicates whether the current statement actually did return rows.
  1289.  
  1290.  ────────────────────────────────────────────────────────────────────────────
  1291.  Miscellaneous Information
  1292.  
  1293.  The application can extract a variety of other information from the
  1294.  DBPROCESS structure.
  1295.  
  1296.  ────────────────────────────────────────────────────────────────────────────
  1297.  dbchange
  1298.    Indicates whether a command batch has changed the current database.
  1299.  
  1300.  DBCURROW
  1301.    Returns the number of the row currently being read.
  1302.  
  1303.  dbgetmaxprocs
  1304.    Indicates the current maximum number of simultaneously open DBPROCESS
  1305.    structures.
  1306.  
  1307.  DBISAVAIL
  1308.    Indicates whether a DBPROCESS is available for general use.
  1309.  
  1310.  dbname
  1311.    Returns the name of the current database.
  1312.  
  1313.  DBROWTYPE
  1314.    Indicates whether the current result row is a regular row or a compute
  1315.    row.
  1316.  
  1317.  ────────────────────────────────────────────────────────────────────────────
  1318.  Browse Mode
  1319.  
  1320.  Browse mode allows browsing through database rows and updating of their
  1321.  values a row at a time. From the standpoint of the program, the process
  1322.  involves several steps because each row must be transferred from the
  1323.  database into program variables before it can be browsed and updated.
  1324.  
  1325.  Since a row being browsed is not the actual row residing in the database,
  1326.  but a copy residing in program variables, the program must be able to ensure
  1327.  that changes to the variables' values can be used reliably to update the
  1328.  original database row. In particular, in multiuser situations, the program
  1329.  needs to ensure that updates made to the database by one user do not
  1330.  incorrectly overwrite updates recently made by another user. This becomes an
  1331.  issue because the application typically selects a number of rows from the
  1332.  database at once, but the application's users browse and update the database
  1333.  one row at a time. A timestamp column in database tables that can be browsed
  1334.  provides the information necessary to regulate this type of multiuser
  1335.  updating.
  1336.  
  1337.  Browse mode functions also allow an application to handle ad hoc queries.
  1338.  Several of them return information that an application can use to examine
  1339.  the structure of a complicated ad hoc query to update the underlying
  1340.  database tables.
  1341.  
  1342.  Conceptually, browse mode involves three steps:
  1343.  
  1344.  
  1345.    1.  Select result rows containing columns derived from one or more
  1346.        database tables.
  1347.  
  1348.    2.  Where appropriate, change values in columns of the result rows (not
  1349.        the actual database rows) one row at a time.
  1350.  
  1351.    3.  Update the original database tables, one row at a time, using the new
  1352.        values in the result rows.
  1353.  
  1354.  
  1355.  These steps are implemented in a program as follows:
  1356.  
  1357.  
  1358.    1.  Execute a SELECT statement, generating result rows containing result
  1359.        columns. The SELECT statement must include the FOR BROWSE option.
  1360.  
  1361.    2.  Copy the result column values into program variables, one row at a
  1362.        time.
  1363.  
  1364.    3.  If appropriate, change the variables' values (possibly in response to
  1365.        user input).
  1366.  
  1367.    4.  If appropriate, execute an UPDATE statement that updates the database
  1368.        row corresponding to the current result row. To handle multiuser
  1369.        updates, the WHERE clause of the UPDATE statement must reference the
  1370.        timestamp column. Such a WHERE clause can be obtained with the dbqual
  1371.        function.
  1372.  
  1373.    5.  Repeat the second, third, and fourth steps for each result row.
  1374.  
  1375.  
  1376.  To use browse mode, the following conditions must be true:
  1377.  
  1378.  
  1379.    ■   The SELECT statement must end with the keywords FOR BROWSE.
  1380.  
  1381.    ■   The table(s) to be updated must have a unique index and a timestamp
  1382.        column.
  1383.  
  1384.    ■   The result columns to be used in the updates must be derived from
  1385.        tables the can be browsed and cannot be the result of SQL expressions,
  1386.        such as "max(colname)". In other words, there must be a valid
  1387.        correspondence between the result column and the database column to be
  1388.        updated.
  1389.  
  1390.  
  1391.  In addition, browse mode usually requires two DBPROCESS structures: one for
  1392.  selecting the data and another for performing updates based on the selected
  1393.  data.
  1394.  
  1395.  For examples of browse-mode programming, see Chapter 3, "Example Programs."
  1396.  
  1397.  
  1398.  The browse-mode functions are as follows:
  1399.  
  1400.  ────────────────────────────────────────────────────────────────────────────
  1401.  dbcolbrowse
  1402.    Indicates whether the source of a result column can be updated through
  1403.    browse mode.
  1404.  
  1405.  dbcolsource
  1406.    Returns a pointer to the name of the database column from which the
  1407.    specified result column was derived.
  1408.  
  1409.  dbfreequal
  1410.    Frees memory allocated by the dbqual function.
  1411.  
  1412.  dbqual
  1413.    Returns a pointer to a WHERE clause suitable for use in updating the
  1414.    current row in a table that can be browsed.
  1415.  
  1416.  dbtabbrowse
  1417.    Indicates whether a particular table can be updated through browse mode.
  1418.  
  1419.  dbtabcount
  1420.    Returns the number of tables involved in the current SELECT statement.
  1421.  
  1422.  dbtabname
  1423.    Returns the name of a table based on its number.
  1424.  
  1425.  dbtabsource
  1426.    Returns the name and number of the table from which a particular result
  1427.    column was derived.
  1428.  
  1429.  dbtsnewlen
  1430.    Returns the length of the new value of the timestamp column after a
  1431.    browse-mode update.
  1432.  
  1433.  dbtsnewval
  1434.    Returns the new value of the timestamp column after a browse mode update.
  1435.  
  1436.  dbtsput
  1437.    Puts the new value of the timestamp column into the given table's current
  1438.    row in the DBPROCESS.
  1439.  
  1440.  ────────────────────────────────────────────────────────────────────────────
  1441.  Text and Image Handling
  1442.  
  1443.  Since text and image values can be quite large, several functions are
  1444.  available to facilitate the process of updating text and image columns in
  1445.  database tables:
  1446.  
  1447.  ────────────────────────────────────────────────────────────────────────────
  1448.  dbmoretext
  1449.    Sends part of a text or image value to SQL Server.
  1450.  
  1451.  dbtxptr
  1452.    Returns the text pointer for a column in the current results row.
  1453.  
  1454.  dbtxtimestamp
  1455.    Returns the value of the text timestamp for a column in the current
  1456.    results row.
  1457.  
  1458.  dbtxtsnewval
  1459.    Returns the new value of a text timestamp after a call to dbwritetext.
  1460.  
  1461.  dbtxtsput
  1462.    Puts the new value of a text timestamp into the specified column of the
  1463.    current row in the DBPROCESS.
  1464.  
  1465.  dbwritetext
  1466.    Sends a text or image value to SQL Server.
  1467.  
  1468.  ────────────────────────────────────────────────────────────────────────────
  1469.  Datatype Conversion
  1470.  
  1471.  DB-LIBRARY supports conversions between most SQL Server datatypes. For
  1472.  information on SQL Server datatypes, see Appendix C, "DB-LIBRARY Datatypes."
  1473.  
  1474.  
  1475.  ────────────────────────────────────────────────────────────────────────────
  1476.  dbconvert
  1477.    Converts data from one SQL Server datatype to another.
  1478.  
  1479.  dbwillconvert
  1480.    Indicates whether a specified datatype conversion is supported.
  1481.  
  1482.  ────────────────────────────────────────────────────────────────────────────
  1483.  Cleanup
  1484.  
  1485.  These functions break the connection between the application and SQL Server:
  1486.  
  1487.  
  1488.  ────────────────────────────────────────────────────────────────────────────
  1489.  dbclose
  1490.    Closes and frees a single DBPROCESS structure.
  1491.  
  1492.  dbexit
  1493.    Closes and frees all DBPROCESS structures.
  1494.  
  1495.  ────────────────────────────────────────────────────────────────────────────
  1496.  Miscellaneous Functions
  1497.  
  1498.  These functions and macros provide the application with various
  1499.  capabilities:
  1500.  
  1501.  ────────────────────────────────────────────────────────────────────────────
  1502.  DBLOCKLIB
  1503.    Locks DB-LIBRARY segments (for Windows only).
  1504.  
  1505.  dbprtype
  1506.    Converts an SQL Server token value into a readable string. Token values
  1507.    are returned by various functions such as dbcoltype and dbaltop.
  1508.  
  1509.  dbreadpage
  1510.    Reads in a page of binary data from SQL Server.
  1511.  
  1512.  dbsetavail
  1513.    Marks a DBPROCESS as being available for general use.
  1514.  
  1515.  dbsetmaxprocs
  1516.    Sets the maximum number of simultaneously open DBPROCESS structures.
  1517.  
  1518.  dbsetnull
  1519.    Defines substitution values to be used when binding null values.
  1520.  
  1521.  DBUNLOCKLIB
  1522.    Unlocks DB-LIBRARY segments (for Windows only).
  1523.  
  1524.  dbwritepage
  1525.    Writes a page of binary data to SQL Server.
  1526.  
  1527.  ────────────────────────────────────────────────────────────────────────────
  1528.  Bulk Copy Special Library
  1529.  
  1530.  The functions and macro in this library allow an application to bulk copy
  1531.  data in and out of SQL Server. They provide a facility for high-speed
  1532.  loading of data into SQL Server from either files or program variables. They
  1533.  also allow you to copy data out of SQL Server into files using a predefined
  1534.  format. The bulk copy functions are similar in function to the bcp program,
  1535.  described in the SQL Server System Administrator's Guide.
  1536.  
  1537.  ────────────────────────────────────────────────────────────────────────────
  1538.  bcp_batch
  1539.    Saves any preceding rows in SQL Server.
  1540.  
  1541.  bcp_bind
  1542.    Binds data from a program variable to an SQL Server table.
  1543.  
  1544.  bcp_colfmt
  1545.    Specifies the format of an operating system file for bulk copy purposes.
  1546.  
  1547.  bcp_collen
  1548.    Sets the program variable data length for the current copy in.
  1549.  
  1550.  bcp_colptr
  1551.    Sets the program variable data address for the current copy in.
  1552.  
  1553.  bcp_columns
  1554.    Sets the total number of columns found in the operating system file.
  1555.  
  1556.  bcp_control
  1557.    Changes various control parameter default settings.
  1558.  
  1559.  bcp_done
  1560.    Ends a bulk copy from program variables into SQL Server.
  1561.  
  1562.  bcp_exec
  1563.    Executes a bulk copy of data between a database table and an operating
  1564.    system file.
  1565.  
  1566.  bcp_init
  1567.    Initializes bulk copy.
  1568.  
  1569.  bcp_moretext
  1570.    Sends part of a text or image value to SQL Server.
  1571.  
  1572.  bcp_sendrow
  1573.    Sends a row of data from program variables to SQL Server.
  1574.  
  1575.  BCP_SETL
  1576.    Sets the LOGINREC for bulk copy operations.
  1577.  
  1578.  ────────────────────────────────────────────────────────────────────────────
  1579.  Two-Phase Commit Service Special Library
  1580.  
  1581.  The functions in this library allow an application to coordinate updates
  1582.  among two or more SQL Servers:
  1583.  
  1584.  ────────────────────────────────────────────────────────────────────────────
  1585.  abort_xact
  1586.    Marks a distributed transaction as being aborted.
  1587.  
  1588.  build_xact_string
  1589.    Builds a name for a distributed transaction.
  1590.  
  1591.  close_commit
  1592.    Ends a connection with the commit service.
  1593.  
  1594.  commit_xact
  1595.    Marks a distributed transaction as being committed.
  1596.  
  1597.  open_commit
  1598.    Establishes a connection with the commit service.
  1599.  
  1600.  remove_xact
  1601.    Decrements the count of sites still active in the distributed transaction.
  1602.  
  1603.  
  1604.  scan_xact
  1605.    Prints commit service record for distributed transactions.
  1606.  
  1607.  start_xact
  1608.    Starts a distributed transaction using the commit service.
  1609.  
  1610.  stat_xact
  1611.    Returns the current status of a distributed transaction.
  1612.  
  1613.  ────────────────────────────────────────────────────────────────────────────
  1614.  
  1615.  
  1616.  
  1617.  
  1618.  Chapter 2  Functions and Macros
  1619.  ────────────────────────────────────────────────────────────────────────────
  1620.  
  1621.  
  1622.  Introduction
  1623.  
  1624.  This chapter contains syntax and usage information about each function and
  1625.  macro contained in DB-LIBRARY. Functions and macros are arranged in
  1626.  alphabetical order.
  1627.  
  1628.  
  1629.  
  1630.  dbadata
  1631.  ────────────────────────────────────────────────────────────────────────────
  1632.  
  1633.  Function
  1634.  
  1635.  Returns a pointer to the data for a compute column.
  1636.  
  1637.  
  1638.  Syntax
  1639.  
  1640.    BYTE *dbadata(dbproc, computeid, column)
  1641.  
  1642.     DBPROCESS *dbproc;
  1643.     int   computeid;
  1644.     int   column;
  1645.  
  1646.  
  1647.  Comments
  1648.  
  1649.  After each call to dbnextrow that returns a value, you can use dbadata to
  1650.  obtain a pointer to the data for a particular column in a compute. The data
  1651.  is not null-terminated. You can use dbadlen to get the length of the data.
  1652.  
  1653.  When a column of integer data is summed or averaged, SQL Server always
  1654.  returns a 4-byte integer, regardless of the size of the column. Therefore,
  1655.  be sure that the variable that is to contain the result from such a compute
  1656.  is declared as DBINT.
  1657.  
  1658.  The following program fragment illustrates the use of dbadata:
  1659.  
  1660.    DBPROCESS *dbproc;
  1661.     int   rowinfo;
  1662.     DBINT  sum;
  1663.  
  1664.     /* First, put the commands into the command buffer. */
  1665.     dbcmd(dbproc, "select db_name(dbid), dbid, size from sysusages");
  1666.     dbcmd(dbproc, " order by dbid");
  1667.     dbcmd(dbproc, " compute sum(size) by dbid");
  1668.     /* Send the commands to SQL Server and start execution. */
  1669.     dbsqlexec(dbproc);
  1670.     /* Process the command. */
  1671.     dbresults(dbproc);
  1672.     /* Examine the results of the COMPUTE clause. */
  1673.     while((rowinfo = dbnextrow(dbproc)) != NO_MORE_ROWS)
  1674.     {
  1675.      if (rowinfo == REG_ROW)
  1676.       printf("regular row returned.\n");
  1677.      else
  1678.      {
  1679.       /* This row is the result of a COMPUTE clause,
  1680.        * and "rowinfo" is the computeid of this COMPUTE
  1681.        * clause.
  1682.        */
  1683.       sum = *(DBINT *)(dbadata(dbproc, rowinfo, 1));
  1684.       printf("sum = %ld\n", sum);
  1685.      }
  1686.     }
  1687.  
  1688.  The dbaltbind function automatically binds data to your program variables.
  1689.  It is somewhat easier to use than dbadata and dbadlen but is less efficient
  1690.  since it copies the data into your variable.
  1691.  
  1692.  
  1693.  Parameters
  1694.  
  1695.  dbproc
  1696.    The DBPROCESS structure that is the handle for a particular
  1697.    workstation/SQL Server process. It contains all the information that
  1698.    DB-LIBRARY uses to manage communications and data between the workstation
  1699.    and SQL Server.
  1700.  
  1701.  computeid
  1702.    The ID that identifies the compute. A SELECT statement can have multiple
  1703.    COMPUTE clauses, each of which can have a different number of aggregate
  1704.    operators and aggregate targets. The computeid is returned by dbnextrow or
  1705.    dbgetrow.
  1706.  
  1707.  column
  1708.    The number of the column. The first column returned is number 1. Note that
  1709.    the order in which compute columns are returned is determined by the order
  1710.    of the corresponding columns in the select list, not by the order in which
  1711.    the compute columns were originally specified. For example, in the
  1712.    following query the result of "sum(price)" is referenced by giving column
  1713.    a value of 1, not 2:
  1714.  
  1715.        select price, advance from titles
  1716.         compute sum(advance), sum(price)
  1717.  
  1718.    The relative order of compute columns in the select list, rather than
  1719.    their absolute position, determines the value of column. For instance,
  1720.    given the following variation of the previous SELECT, the column for
  1721.    "sum(price)" still has a value of 1 and not 2 because the "title_id"
  1722.    column in the select list is not a compute column and therefore is ignored
  1723.    when determining the compute column's number:
  1724.  
  1725.        select title_id, price, advance from titles
  1726.         compute sum(advance), sum(price)
  1727.  
  1728.  
  1729.  Returns
  1730.  
  1731.  A BYTE pointer to the data for a particular column in a compute. A BYTE
  1732.  pointer to NULL is returned if there is no such column or compute or if the
  1733.  data has a null value. The data space pointed to is allocated and freed by
  1734.  DB-LIBRARY. You should be careful not to overwrite the space.
  1735.  
  1736.  
  1737.  See Also
  1738.  
  1739.  dbadlen, dbaltbind, dbaltlen, dbalttype, dbgetrow, dbnextrow, dbnumalts
  1740.  
  1741.  
  1742.  dbadlen
  1743.  ────────────────────────────────────────────────────────────────────────────
  1744.  
  1745.  Function
  1746.  
  1747.  Returns the actual length of the data for a compute column.
  1748.  
  1749.  
  1750.  Syntax
  1751.  
  1752.    DBINT dbadlen(dbproc, computeid, column)
  1753.  
  1754.     DBPROCESS *dbproc;
  1755.     int   computeid;
  1756.     int   column;
  1757.  
  1758.  
  1759.  Comments
  1760.  
  1761.  This function returns the length of the data for a particular column in a
  1762.  COMPUTE clause. You can get a pointer to the actual data using dbadata.
  1763.  
  1764.  The following program fragment illustrates the use of dbadlen:
  1765.  
  1766.    DBPROCESS *dbproc;
  1767.     char  biggest_name[MAXNAME+1];
  1768.     DBINT  namelen;
  1769.     STATUS  rowinfo;
  1770.  
  1771.     /* Put the command into the command buffer. */
  1772.     dbcmd(dbproc, "select name from sysobjects");
  1773.     dbcmd(dbproc, " order by name");
  1774.     dbcmd(dbproc, " compute max(name)");
  1775.  
  1776.     /* Send the command to SQL Server and start execution. */
  1777.     dbsqlexec(dbproc);
  1778.  
  1779.     /* Process the command. */
  1780.     dbresults(dbproc);
  1781.  
  1782.     /* Examine each row returned by the command. */
  1783.     while ((rowinfo = dbnextrow(dbproc)) != NO_MORE_ROWS)
  1784.     {
  1785.      if (rowinfo == REG_ROW)
  1786.       printf("regular row returned.\n");
  1787.      else
  1788.      {
  1789.       /* This row is the result of a COMPUTE clause,
  1790.        * and "rowinfo" is the computeid of this COMPUTE
  1791.        * clause.
  1792.        */
  1793.  
  1794.  
  1795.    namelen = dbadlen(dbproc, rowinfo, 1);
  1796.       strncpy(biggest_name,(char *)dbadata(dbproc, rowinfo, 1),
  1797.        (int)namelen);
  1798.  
  1799.       /* Data pointed to by dbadata() is not null-terminated. */
  1800.       biggest_name[namelen] = '\0';
  1801.  
  1802.       printf("biggest name = %s\n", biggest_name);
  1803.      }
  1804.     }
  1805.  
  1806.  
  1807.  Parameters
  1808.  
  1809.  dbproc
  1810.    The DBPROCESS structure that is the handle for a particular
  1811.    workstation/SQL Server process. It contains all the information that
  1812.    DB-LIBRARY uses to manage communications and data between the workstation
  1813.    and SQL Server.
  1814.  
  1815.  computeid
  1816.    The ID that identifies the compute. A SELECT statement can have multiple
  1817.    COMPUTE clauses, each of which can have a different number of aggregate
  1818.    operators and aggregate targets. The computeid is returned by dbnextrow or
  1819.    dbgetrow.
  1820.  
  1821.  column
  1822.    The number of the column. The first column is number 1.
  1823.  
  1824.  
  1825.  Returns
  1826.  
  1827.  The length, in bytes, of the data for a particular column in a particular
  1828.  COMPUTE clause. If there is no such column or COMPUTE clause, -1 is
  1829.  returned. If the data has a null value, 0 is returned.
  1830.  
  1831.  
  1832.  See Also
  1833.  
  1834.  dbadata, dbaltlen, dbalttype, dbgetrow, dbnextrow, dbnumalts
  1835.  
  1836.  
  1837.  dbaltbind
  1838.  ────────────────────────────────────────────────────────────────────────────
  1839.  
  1840.  Function
  1841.  
  1842.  Binds a compute result column to a program variable.
  1843.  
  1844.  
  1845.  Syntax
  1846.  
  1847.    RETCODE dbaltbind(dbproc, computeid, column, vartype, varlen, varaddr)
  1848.  
  1849.     DBPROCESS *dbproc;
  1850.     int   computeid;
  1851.     int   column;
  1852.     int   vartype;
  1853.     DBINT  varlen;
  1854.     BYTE  *varaddr;
  1855.  
  1856.  
  1857.  Comments
  1858.  
  1859.  This function directs DB-LIBRARY to copy compute column data returned by SQL
  1860.  Server into a program variable. (A compute column results from the COMPUTE
  1861.  clause of a TRANSACT-SQL SELECT statement.) When each new row containing
  1862.  compute data is read by dbnextrow or dbgetrow, the data from the designated
  1863.  column in that compute row is copied into the program variable with the
  1864.  address varaddr. There must be a separate dbaltbind call for each compute
  1865.  column that is to be copied. It is not necessary to bind every compute
  1866.  column to a program variable.
  1867.  
  1868.  SQL Server can return two types of rows: regular rows containing data from
  1869.  columns designated by a SELECT statement's select list, and compute rows
  1870.  resulting from the COMPUTE clause. The dbaltbind function binds data from
  1871.  compute rows. Use dbbind for binding data from regular rows.
  1872.  
  1873.  The calls to dbaltbind must be made after a call to dbresults and before the
  1874.  first call to dbnextrow.
  1875.  
  1876.  The typical sequence of calls is
  1877.  
  1878.    DBCHAR name[20];
  1879.     DBINT namecount;
  1880.  
  1881.     /* Read the query into the command buffer. */
  1882.     dbcmd(dbproc, "select name from employee compute count(name)");
  1883.     /* Send the query to SQL Server. */
  1884.     dbsqlexec(dbproc);
  1885.     /* Get ready to process the results of the query. */
  1886.     dbresults(dbproc);
  1887.     /* Bind the regular row data - name. */
  1888.     dbbind(dbproc, 1, STRINGBIND, (DBINT) 0, name);
  1889.     /* Bind the compute column data - count of name. */
  1890.     dbaltbind(dbproc, 1, 1, INTBIND, (DBINT) 0, (BYTE *) &namecount);
  1891.  
  1892.  
  1893.  
  1894.    /* Now process each row. */
  1895.     while (dbnextrow(dbproc) != NO_MORE_ROWS)
  1896.     {
  1897.      /*C-code to print or process row data*/
  1898.     }
  1899.  
  1900.  There is some overhead incurred by using dbaltbind because it always copies
  1901.  the row data into the designated program variable. To avoid this copying,
  1902.  the returned data can be more directly accessed using the dbadlen and
  1903.  dbadata functions.
  1904.  
  1905.  Since null values can be returned from SQL Server, there is a set of default
  1906.  values, one for each datatype, that will be substituted when binding null
  1907.  values. You can explicitly set your own values to be substituted for the
  1908.  default null values with the dbsetnull function. (For a list of the default
  1909.  substitution values, see "dbsetnull.")
  1910.  
  1911.  
  1912.  Parameters
  1913.  
  1914.  dbproc
  1915.    The DBPROCESS structure that is the handle for a particular
  1916.    workstation/SQL Server process. It contains all the information that
  1917.    DB-LIBRARY uses to manage communications and data between the workstation
  1918.    and SQL Server.
  1919.  
  1920.  computeid
  1921.    The ID of the COMPUTE clause to which the dbaltbind function refers. Since
  1922.    a SELECT statement can have more than one COMPUTE clause, the computeid is
  1923.    necessary to distinguish between them. The computeid of the first COMPUTE
  1924.    clause of a SELECT statement is 1.
  1925.  
  1926.  column
  1927.    The column number of the row data that is to be copied to a program
  1928.    variable. The first column is column number 1. Note that the order in
  1929.    which compute columns are returned is determined by the order of the
  1930.    corresponding columns in the select list, not by the order in which the
  1931.    compute columns were originally specified. For example, in the following
  1932.    query, the result of "sum(price)" is referenced by giving column a value
  1933.    of 1, not 2:
  1934.  
  1935.        select price, advance from titles
  1936.         compute sum(advance), sum(price)
  1937.  
  1938.    The relative order of compute columns in the select list, rather than
  1939.    their absolute position, determines the value of column. For instance,
  1940.    given the following variation of the previous SELECT, the column for
  1941.    "sum(price)" still has a value of 1 and not 2 because the "title_id"
  1942.    column in the select list is not a compute column and therefore is ignored
  1943.    when determining the compute column's number:
  1944.  
  1945.        select title_id, price, advance from titles
  1946.         compute sum(advance), sum(price)
  1947.  
  1948.  vartype
  1949.    A description of the binding's datatype. As shown in the following table,
  1950.    it corresponds to the datatype of the program variable that receives the
  1951.    copy of the data from the DBPROCESS.
  1952.  
  1953.    The dbaltbind function supports a wide range of type conversions, so this
  1954.    type can be different from the type returned by the SQL query. For
  1955.    instance, an SQLMONEY result can be bound to a DBFLT8 program variable,
  1956.    using FLT8BIND, and the appropriate data conversion will happen
  1957.    automatically.
  1958.  
  1959.    For a list of the data conversions provided by DB-LIBRARY, see
  1960.    "dbwillconvert." For a list of the typedefs used by DB-LIBRARY, see
  1961.    Appendix C, "DB-LIBRARY Datatypes." The following table lists legal
  1962.    vartypes recognized by dbaltbind and the program variable and SQL Server
  1963.    types that each one refers to.
  1964.  
  1965. ╓┌──────────────┌──────────────────────┌─────────────────────────────────────╖
  1966.  Vartype        Program Variable Type  SQL Server Type
  1967.  ────────────────────────────────────────────────────────────────────────────
  1968.  CHARBIND       DBCHAR                 SQLCHAR
  1969.  
  1970.  STRINGBIND     DBCHAR                 SQLCHAR
  1971.  
  1972.  NTBSTRINGBIND  DBCHAR                 SQLCHAR
  1973.  
  1974.  VARYCHARBIND   DBVARYCHAR             SQLCHAR
  1975.  
  1976.  Vartype        Program Variable Type  SQL Server Type
  1977.  ────────────────────────────────────────────────────────────────────────────
  1978. 
  1979.  BINARYBIND     DBBINARY               SQLBINARY
  1980.  
  1981.  VARYBINBIND    DBVARYBIN              SQLBINARY
  1982.  
  1983.  TINYBIND       DBTINYINT              SQLINT1
  1984.  
  1985.  SMALLBIND      DBSMALLINT             SQLINT2
  1986.  
  1987.  INTBIND        DBINT                  SQLINT4
  1988.  
  1989.  FLT8BIND       DBFLT8                 SQLFLT8
  1990.  
  1991.  BITBIND        DBBIT                  SQLBIT
  1992.  
  1993.  DATETIMEBIND   DBDATETIME             SQLDATETIME
  1994.  
  1995.  MONEYBIND      DBMONEY                SQLMONEY
  1996.  
  1997.  Vartype        Program Variable Type  SQL Server Type
  1998.  ────────────────────────────────────────────────────────────────────────────
  1999. 
  2000.  ────────────────────────────────────────────────────────────────────────────
  2001.  
  2002.  
  2003.  
  2004.    Since SQLTEXT and SQLIMAGE data are never returned through a compute row,
  2005.    those datatypes are not included in the preceding table. Note that the SQL
  2006.    Server type is listed merely for your information. The vartype you specify
  2007.    does not necessarily have to correspond to a particular SQL Server type
  2008.    because, as mentioned earlier, dbaltbind converts SQL Server data into the
  2009.    specified vartype.
  2010.  
  2011.  The following table shows that four representations for character data are
  2012.  available. They differ according to whether the data is padded with blanks
  2013.  or is null-terminated:
  2014.  
  2015. ╓┌──────────────┌─────────────┌────────┌─────────────────────────────────────╖
  2016.  Vartype        Program Type  Padding  Terminator
  2017.  ────────────────────────────────────────────────────────────────────────────
  2018.  Vartype        Program Type  Padding  Terminator
  2019.  ────────────────────────────────────────────────────────────────────────────
  2020.  CHARBIND       DBCHAR        blanks   none
  2021.  
  2022.  STRINGBIND     DBCHAR        blanks   \0
  2023.  
  2024.  NTBSTRINGBIND  DBCHAR        none     \0
  2025.  
  2026.  VARYCHARBIND   DBVARYCHAR    none     none
  2027.  
  2028.  ────────────────────────────────────────────────────────────────────────────
  2029.  
  2030.  
  2031.  
  2032.    Note that "\0" is the null terminator character. Similarly, binary data
  2033.    can be stored in two different ways:
  2034.  
  2035. ╓┌────────────┌─────────────┌────────────────────────────────────────────────╖
  2036.  Vartype      Program Type  Padding
  2037.  ────────────────────────────────────────────────────────────────────────────
  2038.  BINARYBIND   DBBINARY      nulls
  2039.  Vartype      Program Type  Padding
  2040.  ────────────────────────────────────────────────────────────────────────────
  2041.  BINARYBIND   DBBINARY      nulls
  2042.  
  2043.  VARYBINBIND  DBVARBINARY   none
  2044.  
  2045.  ────────────────────────────────────────────────────────────────────────────
  2046.  
  2047.  
  2048.  
  2049.    When a column of integer data is summed or averaged, SQL Server always
  2050.    returns a 4-byte integer, regardless of the size of the column. Therefore,
  2051.    be sure that the variable that is to contain the result from such a
  2052.    compute is declared as DBINT and that the vartype of the binding is
  2053.    INTBIND.
  2054.  
  2055.  varlen
  2056.    The length of the program variable in bytes. For fixed-length vartypes,
  2057.    such as MONEYBIND or FLT8BIND, this length is ignored. For character and
  2058.    binary types, varlen must describe the total length of the available
  2059.    destination buffer space, including any space that can be required for
  2060.    special terminating bytes, such as a null terminator. If varlen is 0, the
  2061.    total number of bytes available is copied into the program variable. (For
  2062.    char and binary SQL Server data, the total number of bytes available is
  2063.    equal to the defined length of the database column, including any blank
  2064.    padding. For varchar and varbinary data, the total number of bytes
  2065.    available is equal to the actual data contained in the column.) Therefore,
  2066.    if you are sure that your program variable is large enough to handle the
  2067.    results, you can just set the varlen to 0. The varlen is ignored for
  2068.    VARYCHARBIND and VARYBINBIND data.
  2069.  
  2070.  varaddr
  2071.    The address of the program variable to which the data is copied.
  2072.  
  2073.  
  2074.  Returns
  2075.  
  2076.  SUCCEED or FAIL. The dbaltbind function returns FAIL if the column number
  2077.  given isn't valid, if the vartype isn't compatible with the SQL Server type
  2078.  being returned, or if varaddr is NULL.
  2079.  
  2080.  
  2081.  See Also
  2082.  
  2083.  dbadata, dbadlen, dbbind, dbconvert, dbgetrow, dbnextrow, dbresults,
  2084.  dbsetnull, dbwillconvert, Appendix C
  2085.  
  2086.  
  2087.  dbaltcolid
  2088.  ────────────────────────────────────────────────────────────────────────────
  2089.  
  2090.  Function
  2091.  
  2092.  Returns the operand column ID for a compute column.
  2093.  
  2094.  
  2095.  Syntax
  2096.  
  2097.    int dbaltcolid(dbproc, computeid, column)
  2098.  
  2099.     DBPROCESS *dbproc;
  2100.     int   computeid;
  2101.     int   column;
  2102.  
  2103.  
  2104.  Comments
  2105.  
  2106.  This function returns the ID of the column to which the aggregate operator
  2107.  applies for a particular column in a compute. For example, the function
  2108.  dbaltcolid(dbproc, 1, 1) returns 2, since the COMPUTE COUNT clause in the
  2109.  following example refers to the second column in the select list:
  2110.  
  2111.    select dept, name from employee
  2112.     order by dept, name
  2113.     compute count(name) by dept
  2114.  
  2115.  
  2116.  Parameters
  2117.  
  2118.  dbproc
  2119.    The DBPROCESS structure that is the handle for a particular
  2120.    workstation/SQL Server process. It contains all the information that
  2121.    DB-LIBRARY uses to manage communications and data between the workstation
  2122.    and SQL Server.
  2123.  
  2124.  computeid
  2125.    The ID that identifies the compute. A SELECT statement can have multiple
  2126.    COMPUTE clauses, each of which can have a different number of aggregate
  2127.    operators and aggregate targets. The computeid is returned by dbnextrow or
  2128.    dbgetrow.
  2129.  
  2130.  column
  2131.    The number of the compute column. The first column is number 1.
  2132.  
  2133.  
  2134.  Returns
  2135.  
  2136.  The column ID that the aggregate in the compute applies to. The first column
  2137.  is number 1. If either the computeid or the column are invalid, then -1 is
  2138.  returned.
  2139.  
  2140.  
  2141.  See Also
  2142.  
  2143.  dbadata, dbadlen, dbaltlen, dbgetrow, dbnextrow, dbnumalts, dbprtype
  2144.  
  2145.  
  2146.  dbaltlen
  2147.  ────────────────────────────────────────────────────────────────────────────
  2148.  
  2149.  Function
  2150.  
  2151.  Returns the maximum length of the data for a compute column.
  2152.  
  2153.  
  2154.  Syntax
  2155.  
  2156.    DBINT dbaltlen(dbproc, computeid, column)
  2157.  
  2158.     DBPROCESS *dbproc;
  2159.     int   computeid;
  2160.     int   column;
  2161.  
  2162.  
  2163.  Comments
  2164.  
  2165.  This function returns the maximum length, in bytes, for a particular column
  2166.  in a compute row. In the case of variable length data, this is not
  2167.  necessarily the actual length of the data, but rather the maximum length.
  2168.  For the actual data length, use dbadlen. In the following example,
  2169.  dbaltlen(dbproc, 1, 1) returns 4 because counts are of SQLINT4 type, which
  2170.  is 4 bytes long:
  2171.  
  2172.    select dept, name from employee
  2173.     order by dept, name
  2174.     compute count(name) by dept
  2175.  
  2176.  
  2177.  Parameters
  2178.  
  2179.  dbproc
  2180.    The DBPROCESS structure that is the handle for a particular
  2181.    workstation/SQL Server process. It contains all the information that
  2182.    DB-LIBRARY uses to manage communications and data between the workstation
  2183.    and SQL Server.
  2184.  
  2185.  computeid
  2186.    The ID that identifies the compute. A SELECT statement can have multiple
  2187.    COMPUTE clauses, each of which can have a different number of aggregate
  2188.    operators and aggregate targets. The computeid is returned by dbnextrow or
  2189.    dbgetrow.
  2190.  
  2191.  column
  2192.    The number of the column. The first column is number 1.
  2193.  
  2194.  
  2195.  Returns
  2196.  
  2197.  The maximum number of bytes the data for a particular column in a compute
  2198.  can be. If there is no such column or compute, -1 is returned.
  2199.  
  2200.  
  2201.  See Also
  2202.  
  2203.  dbadata, dbadlen, dbalttype, dbgetrow, dbnextrow, dbnumalts
  2204.  
  2205.  
  2206.  dbaltop
  2207.  ────────────────────────────────────────────────────────────────────────────
  2208.  
  2209.  Function
  2210.  
  2211.  Returns the type of aggregate function for a compute column.
  2212.  
  2213.  
  2214.  Syntax
  2215.  
  2216.    int dbaltop(dbproc, computeid, column)
  2217.  
  2218.     DBPROCESS *dbproc;
  2219.     int   computeid;
  2220.     int   column;
  2221.  
  2222.  
  2223.  Comments
  2224.  
  2225.  This function returns the type of aggregate function for a particular column
  2226.  in a compute. In the following example, dbaltop(dbproc, 1, 1) returns the
  2227.  type for count since the first aggregate operator in the first COMPUTE
  2228.  clause is COUNT:
  2229.  
  2230.    select dept, name from employee
  2231.     order by dept, name
  2232.     compute count(name) by dept
  2233.  
  2234.  You can convert the type to a readable string using dbprtype.
  2235.  
  2236.  
  2237.  Parameters
  2238.  
  2239.  dbproc
  2240.    The DBPROCESS structure that is the handle for a particular
  2241.    workstation/SQL Server process. It contains all the information that
  2242.    DB-LIBRARY uses to manage communications and data between the workstation
  2243.    and SQL Server.
  2244.  
  2245.  computeid
  2246.    The ID that identifies the compute. A SELECT statement can have multiple
  2247.    COMPUTE clauses, each of which can have a different number of aggregate
  2248.    operators and aggregate targets. The computeid is returned by dbnextrow or
  2249.    dbgetrow.
  2250.  
  2251.  column
  2252.    The number of the column. The first column is number 1.
  2253.  
  2254.  
  2255.  Returns
  2256.  
  2257.  The type of aggregate operator for the particular column in the compute. The
  2258.  types are defined as follows:
  2259.  
  2260. ╓┌─────────────────────────────────┌─────────────────────────────────────────╖
  2261.  Type                              Aggregate Operator
  2262.  ────────────────────────────────────────────────────────────────────────────
  2263.  SQLAOPSUM                         sum
  2264.  
  2265.  SQLAOPAVG                         avg
  2266.  
  2267.  SQLAOPCNT                         count
  2268.  
  2269.  SQLAOPMIN                         min
  2270.  Type                              Aggregate Operator
  2271.  ────────────────────────────────────────────────────────────────────────────
  2272. SQLAOPMIN                         min
  2273.  
  2274.  SQLAOPMAX                         max
  2275.  
  2276.  ────────────────────────────────────────────────────────────────────────────
  2277.  
  2278.  
  2279.  
  2280.  If the computeid or column are not valid, -1 is returned.
  2281.  
  2282.  
  2283.  See Also
  2284.  
  2285.  dbadata, dbadlen, dbaltlen, dbgetrow, dbnextrow, dbnumalts, dbprtype
  2286.  
  2287.  
  2288.  dbalttype
  2289.  ────────────────────────────────────────────────────────────────────────────
  2290.  
  2291.  Function
  2292.  
  2293.  Returns the datatype for a compute column.
  2294.  
  2295.  
  2296.  Syntax
  2297.  
  2298.    int dbalttype(dbproc, computeid, column)
  2299.  
  2300.     DBPROCESS *dbproc;
  2301.     int   computeid;
  2302.     int   column;
  2303.  
  2304.  
  2305.  Comments
  2306.  
  2307.  This function returns the type of the data for a particular column in a
  2308.  compute. In the following example, dbalttype(dbproc, 1, 1) returns the type
  2309.  for SQLINT4 since counts are of SQLINT4 type.
  2310.  
  2311.    select dept, name from employee
  2312.     order by dept, name
  2313.     compute count(name) by dept
  2314.  
  2315.  You can convert the type to a readable string using dbprtype.
  2316.  
  2317.  
  2318.  Parameters
  2319.  
  2320.  dbproc
  2321.    The DBPROCESS structure that is the handle for a particular
  2322.    workstation/SQL Server process. It contains all the information that
  2323.    DB-LIBRARY uses to manage communications and data between the workstation
  2324.    and SQL Server.
  2325.  
  2326.  computeid
  2327.    The ID that identifies the compute. A SELECT statement can have multiple
  2328.    COMPUTE clauses, each of which can have a different number of aggregate
  2329.    operators and aggregate targets. The computeid is returned by dbnextrow or
  2330.    dbgetrow.
  2331.  
  2332.  column
  2333.    The number of the column. The first column is number 1.
  2334.  
  2335.  
  2336.  Returns
  2337.  
  2338.  The type of the data for the particular column in the compute.
  2339.  
  2340. ╓┌─────────────────────────────────┌─────────────────────────────────────────
  2341.  Column                            Return
  2342.  ────────────────────────────────────────────────────────────────────────────
  2343.  SQLVARCHAR                        SQLCHAR
  2344.  
  2345.  SQLVARBINARY                      SQLBINARY
  2346.  
  2347.  SQLDATETIME                       SQLDATETIME
  2348.  
  2349.  SQLMONEY                          SQLMONEY
  2350.  
  2351.  SQLFLT8                           SQLFLT8
  2352.  
  2353.  SQLCHAR                           SQLCHAR
  2354.  Column                            Return
  2355.  ────────────────────────────────────────────────────────────────────────────
  2356. SQLCHAR                           SQLCHAR
  2357.  
  2358.  SQLBINARY                         SQLBINARY
  2359.  
  2360.  SQLINTn                           SQLINT1, SQLINT2, or SQLINT4 depending on
  2361.                                    the actual type of the SQLINTn
  2362.  
  2363.  -1                                If either the computeid or the column are
  2364.                                    invalid
  2365.  
  2366.  
  2367.  
  2368.  
  2369.  See Also
  2370.  
  2371.  dbadata, dbadlen, dbaltlen, dbgetrow, dbnextrow, dbnumalts, dbprtype,
  2372.  Appendix C
  2373.  
  2374.  
  2375.  dbbind
  2376.  ────────────────────────────────────────────────────────────────────────────
  2377.  
  2378.  Function
  2379.  
  2380.  Binds a regular result column to a program variable.
  2381.  
  2382.  
  2383.  Syntax
  2384.  
  2385.    RETCODE dbbind(dbproc, column, vartype, varlen, varaddr)
  2386.  
  2387.     DBPROCESS *dbproc;
  2388.     int   column;
  2389.     int   vartype;
  2390.     DBINT  varlen;
  2391.     BYTE  *varaddr;
  2392.  
  2393.  
  2394.  Comments
  2395.  
  2396.  Data comes back from SQL Server one row at a time. This function directs
  2397.  DB-LIBRARY to copy the data for a regular column (designated in a SELECT
  2398.  statement's select list) into a program variable. When each new row
  2399.  containing regular (not compute) data is read using dbnextrow or dbgetrow,
  2400.  the data from the designated column in that row is copied into the program
  2401.  variable with the address varaddr. There must be a separate dbbind call for
  2402.  each regular column that is to be copied. It is not necessary to bind every
  2403.  column to a program variable. A result column can be bound to only one
  2404.  program variable.
  2405.  
  2406.  The SQL Server can return two types of rows: regular rows and compute rows
  2407.  resulting from the COMPUTE clause of a SELECT statement. The dbbind function
  2408.  binds data from regular rows. Use dbaltbind for binding data from compute
  2409.  rows.
  2410.  
  2411.  The calls to dbbind must be made after a call to dbresults and before the
  2412.  first call to dbnextrow.
  2413.  
  2414.  The typical sequence of calls is
  2415.  
  2416.    DBINT xvariable;
  2417.     DBCHAR yvariable[10];
  2418.  
  2419.     /* Read the query into the command buffer. */
  2420.     dbcmd(dbproc, "select x = 100, y = 'hello'");
  2421.     /* Send the query to SQL Server. */
  2422.     dbsqlexec(dbproc);
  2423.     /* Get ready to process the results of the query. */
  2424.     dbresults(dbproc);
  2425.     /* Bind column data to program variables. */
  2426.     dbbind(dbproc, 1, INTBIND, (DBINT) 0, (BYTE *) &xvariable);
  2427.     dbbind(dbproc, 2, STRINGBIND, (DBINT) 0, yvariable);
  2428.  
  2429.     /* Now process each row. */
  2430.     while (dbnextrow(dbproc) != NO_MORE_ROWS)
  2431.     {
  2432.      /* C-code to print or process row data*/
  2433.     }
  2434.  
  2435.  There is some overhead incurred by using dbbind since it copies the row data
  2436.  into the designated program variable. To avoid this copying, the returned
  2437.  data can be more directly accessed using the dbdatlen and dbdata functions.
  2438.  
  2439.  
  2440.  Since null values can be returned from SQL Server, there is a set of default
  2441.  values, one for each datatype, that will be substituted when binding null
  2442.  values. You can explicitly set your own values to be substituted for the
  2443.  default null value with the dbsetnull function. (See "dbsetnull" for a list
  2444.  of the default substitution values.)
  2445.  
  2446.  
  2447.  Parameters
  2448.  
  2449.  dbproc
  2450.    The DBPROCESS structure that is the handle for a particular
  2451.    workstation/SQL Server process. It contains all the information that
  2452.    DB-LIBRARY uses to manage communications and data between the workstation
  2453.    and SQL Server.
  2454.  
  2455.  column
  2456.    The column number of the row data that is to be copied to a program
  2457.    variable. The first column is number 1.
  2458.  
  2459.  vartype
  2460.    A description of the binding's datatype. As shown in the following table,
  2461.    it corresponds to the datatype of the program variable that receives the
  2462.    copy of the data from the DBPROCESS. The dbbind function supports a wide
  2463.    range of type conversions, so this type can be different from the type
  2464.    returned by the SQL query. For instance, an SQLMONEY result can be bound
  2465.    to a DBFLT8 program variable, using FLT8BIND, and the appropriate data
  2466.    conversion happens automatically. For a list of the data conversions
  2467.    provided by DB-LIBRARY, see "dbwillconvert." For a list of the typedefs
  2468.    used by DB-LIBRARY, see Appendix C, "DB-LIBRARY Datatypes."
  2469.  
  2470.    The following table lists legal vartypes recognized by dbbind and the
  2471.    program variable and SQL Server types that each one refers to:
  2472.  
  2473. ╓┌──────────────┌──────────────────────┌─────────────────────────────────────╖
  2474.  Vartype        Program Variable Type  SQL Server Type
  2475.  ────────────────────────────────────────────────────────────────────────────
  2476.  CHARBIND       DBCHAR                 SQLCHAR or SQLTEXT
  2477.  
  2478.  STRINGBIND     DBCHAR                 SQLCHAR or SQLTEXT
  2479.  
  2480.  Vartype        Program Variable Type  SQL Server Type
  2481.  ────────────────────────────────────────────────────────────────────────────
  2482. 
  2483.  NTBSTRINGBIND  DBCHAR                 SQLCHAR or SQLTEXT
  2484.  
  2485.  VARYCHARBIND   DBVARYCHAR             SQLCHAR or SQLTEXT
  2486.  
  2487.  BINARYBIND     DBBINARY               SQLBINARY or SQLIMAGE
  2488.  
  2489.  VARYBINBIND    DBVARYBIN              SQLBINARY or SQLIMAGE
  2490.  
  2491.  TINYBIND       DBTINYINT              SQLINT1
  2492.  
  2493.  SMALLBIND      DBSMALLINT             SQLINT2
  2494.  
  2495.  INTBIND        DBINT                  SQLINT4
  2496.  
  2497.  FLT8BIND       DBFLT8                 SQLFLT8
  2498.  
  2499.  BITBIND        DBBIT                  SQLBIT
  2500.  
  2501.  Vartype        Program Variable Type  SQL Server Type
  2502.  ────────────────────────────────────────────────────────────────────────────
  2503. 
  2504.  DATETIMEBIND   DBDATETIME             SQLDATETIME
  2505.  
  2506.  MONEYBIND      DBMONEY                SQLMONEY
  2507.  
  2508.  ────────────────────────────────────────────────────────────────────────────
  2509.  
  2510.  
  2511.  
  2512.    Note that the SQL Server type in the preceding table is listed merely for
  2513.    your information. The vartype you specify does not necessarily have to
  2514.    correspond to a particular SQL Server type because as mentioned earlier,
  2515.    dbbind converts SQL Server data into the specified vartype.
  2516.  
  2517.    The following table shows that four representations for character and text
  2518.    data are available. They differ according to whether the data is
  2519.    blank-padded or null-terminated:
  2520.  
  2521. ╓┌──────────────┌─────────────┌────────┌─────────────────────────────────────╖
  2522.  Vartype        Program Type  Padding  Terminator
  2523.  ────────────────────────────────────────────────────────────────────────────
  2524.  CHARBIND       DBCHAR        blanks   none
  2525.  
  2526.  STRINGBIND     DBCHAR        blanks   \0
  2527.  
  2528.  NTBSTRINGBIND  DBCHAR        none     \0
  2529.  
  2530.  VARYCHARBIND   DBVARYCHAR    none     none
  2531.  
  2532.  ────────────────────────────────────────────────────────────────────────────
  2533.  
  2534.  
  2535.  
  2536.    Note that "\0" is the null terminator character. Similarly, binary and
  2537.    image data can be stored in two different ways:
  2538.  
  2539. ╓┌────────────┌─────────────┌────────────────────────────────────────────────╖
  2540.  Vartype      Program Type  Padding
  2541.  ────────────────────────────────────────────────────────────────────────────
  2542.  BINARYBIND   DBBINARY      nulls
  2543.  Vartype      Program Type  Padding
  2544.  ────────────────────────────────────────────────────────────────────────────
  2545.  BINARYBIND   DBBINARY      nulls
  2546.  
  2547.  VARYBINBIND  DBVARBINARY   none
  2548.  
  2549.  ────────────────────────────────────────────────────────────────────────────
  2550.  
  2551.  
  2552.  
  2553.  varlen
  2554.    The length of the program variable in bytes. For fixed-length vartypes,
  2555.    such as MONEYBIND or FLT8BIND, this length is ignored. For character,
  2556.    text, binary, and image types, varlen must describe the total length of
  2557.    the available destination buffer space, including any space that can be
  2558.    required for special terminating bytes, such as a null terminator. If
  2559.    varlen is 0, the number of bytes available is copied into the program
  2560.    variable. (For char and binary SQL Server data, the number of bytes
  2561.    available is equal to the defined length of the database column, including
  2562.    any blank padding. For varchar, varbinary, text, and image data, the
  2563.    number of bytes available is equal to the actual data contained in the
  2564.    column.) Therefore, if you are sure that your program variable is large
  2565.    enough to handle the results, you can set varlen to 0.
  2566.  
  2567.    In some cases, DB-LIBRARY issues a message indicating that data conversion
  2568.    resulted in an overflow. This is usually caused by a varlen specification
  2569.    being too small for the data being received from SQL Server. For example,
  2570.    if varlen is set to 5, vartype is set to VARYCHARBIND, and the SQL Server
  2571.    column being bound is of type VARCHAR with a length of 20. When the bind
  2572.    occurs (using dbnextrow), the overflow message is issued. Note however
  2573.    that 5 bytes of data will be bound. Other types of binds can also cause
  2574.    the overflow message to be issued. For information on datatype
  2575.    conversions, see "dbconvert."
  2576.  
  2577.  varaddr
  2578.    The address of the program variable to which the data is copied. Calling
  2579.    dbbind with a NULL varaddr parameter breaks a previously set binding.
  2580.  
  2581.  
  2582.  Returns
  2583.  
  2584.  SUCCEED or FAIL. The dbbind function returns FAIL if the column number given
  2585.  isn't valid, if the vartype isn't compatible with the SQL Server type being
  2586.  returned, or if varaddr is NULL.
  2587.  
  2588.  
  2589.  See Also
  2590.  
  2591.  dbaltbind, dbconvert, dbdata, dbdatlen, dbgetrow, dbnextrow, dbresults,
  2592.  dbsetnull, dbwillconvert, Appendix C
  2593.  
  2594.  
  2595.  dbbylist
  2596.  ────────────────────────────────────────────────────────────────────────────
  2597.  
  2598.  Function
  2599.  
  2600.  Returns the bylist for a compute row.
  2601.  
  2602.  
  2603.  Syntax
  2604.  
  2605.    BYTE *dbbylist(dbproc, computeid, size)
  2606.  
  2607.     DBPROCESS *dbproc;
  2608.     int   computeid;
  2609.     int   *size;
  2610.  
  2611.  
  2612.  Comments
  2613.  
  2614.  The dbbylist function returns the bylist for a compute row. (A SELECT
  2615.  statement's COMPUTE clause can contain the keyword BY, followed by a list of
  2616.  columns. This list, known as the bylist, divides the results into subgroups
  2617.  based on changing values in the specified columns. The COMPUTE clause's row
  2618.  aggregate is applied to each subgroup, generating a compute row for each
  2619.  subgroup.)
  2620.  
  2621.  This function should be called after dbresults has returned SUCCEED.
  2622.  
  2623.  Assume the following command has been executed:
  2624.  
  2625.    select dept, name, year, sales from employee
  2626.     order by dept, name, year
  2627.     compute count(name) by dept,name
  2628.  
  2629.  The call dbbylist(dbproc, 1, &size) sets size to 2 because there are two
  2630.  items in the bylist. It returns a pointer to an array of two BYTES, which
  2631.  contain the values 1 and 2, indicating that the bylist is composed of
  2632.  columns 1 and 2 from the select list.
  2633.  
  2634.  
  2635.  Parameters
  2636.  
  2637.  dbproc
  2638.    The DBPROCESS structure that is the handle for a particular
  2639.    workstation/SQL Server process. It contains all the information that
  2640.    DB-LIBRARY uses to manage communications and data between the workstation
  2641.    and SQL Server.
  2642.  
  2643.  computeid
  2644.    The ID that identifies the compute. A SELECT statement can have multiple
  2645.    COMPUTE clauses, each of which can have a different number of aggregate
  2646.    operators and targets. The computeid is returned by dbnextrow or dbgetrow.
  2647.  
  2648.  size
  2649.    A pointer to an integer, which dbbylist sets to the number of elements in
  2650.    the bylist.
  2651.  
  2652.  
  2653.  Returns
  2654.  
  2655.  A pointer to an array of BYTES containing the numbers of the columns that
  2656.  compose the bylist for the specified compute. The names of the columns are
  2657.  available by calling dbcolname. If the computeid is out of range, NULL is
  2658.  returned. The size of the array is returned in the size parameter. A size of
  2659.  0 indicates that either there is no bylist for this particular compute or
  2660.  the computeid is out of range.
  2661.  
  2662.  
  2663.  See Also
  2664.  
  2665.  dbadata, dbadlen, dbaltlen, dbalttype, dbcolname, dbgetrow, dbnextrow,
  2666.  dbresults
  2667.  
  2668.  
  2669.  dbcancel
  2670.  ────────────────────────────────────────────────────────────────────────────
  2671.  
  2672.  Function
  2673.  
  2674.  Cancels the current command batch.
  2675.  
  2676.  
  2677.  Syntax
  2678.  
  2679.    RETCODE dbcancel(dbproc)
  2680.  
  2681.     DBPROCESS *dbproc;
  2682.  
  2683.  
  2684.  Comments
  2685.  
  2686.  This function can be called after calling dbsqlexec, dbsqlsend, dbsqlok,
  2687.  dbresults, or dbnextrow to cancel execution of the current command batch on
  2688.  SQL Server and flush any pending results. When called, SQL Server is
  2689.  interrupted and ceases the execution of the command batch associated with
  2690.  the dbproc. Any pending results are read and discarded. Note that dbcancel
  2691.  cancels all the commands in the current command batch. It cannot be used to
  2692.  cancel only the current command in a multiple-command batch.
  2693.  
  2694.  
  2695.  Parameters
  2696.  
  2697.  dbproc
  2698.    The DBPROCESS structure that is the handle for a particular
  2699.    workstation/SQL Server process. It contains all the information that
  2700.    DB-LIBRARY uses to manage communications and data between the workstation
  2701.    and SQL Server.
  2702.  
  2703.  
  2704.  Returns
  2705.  
  2706.  SUCCEED or FAIL.
  2707.  
  2708.  
  2709.  See Also
  2710.  
  2711.  dbnextrow, dbresults, dbsetinterrupt, dbsqlexec, dbsqlok, dbsqlsend
  2712.  
  2713.  
  2714.  dbcanquery
  2715.  ────────────────────────────────────────────────────────────────────────────
  2716.  
  2717.  Function
  2718.  
  2719.  Cancels any rows pending from the most recently executed query.
  2720.  
  2721.  
  2722.  Syntax
  2723.  
  2724.    RETCODE dbcanquery(dbproc)
  2725.  
  2726.     DBPROCESS *dbproc;
  2727.  
  2728.  
  2729.  Comments
  2730.  
  2731.  This function is an efficient way to throw away any unread rows that result
  2732.  from the most recently executed SQL query. Calling dbcanquery is similar to
  2733.  calling dbnextrow until it returns NO_MORE_ROWS, except for the following
  2734.  difference: data that was bound when the application called dbcanquery will
  2735.  continue to be bound when the function returns.
  2736.  
  2737.  If you want to ignore all of the results from all of the commands in the
  2738.  current command batch, you should call dbcancel.
  2739.  
  2740.  
  2741.  Parameters
  2742.  
  2743.  dbproc
  2744.    The DBPROCESS structure that is the handle for a particular
  2745.    workstation/SQL Server process. It contains all the information that
  2746.    DB-LIBRARY uses to manage communications and data between the workstation
  2747.    and SQL Server.
  2748.  
  2749.  
  2750.  Returns
  2751.  
  2752.  SUCCEED or FAIL.
  2753.  
  2754.  
  2755.  See Also
  2756.  
  2757.  dbcancel, dbnextrow, dbresults, dbsetinterrupt, dbsqlexec
  2758.  
  2759.  
  2760.  dbchange
  2761.  ────────────────────────────────────────────────────────────────────────────
  2762.  
  2763.  Function
  2764.  
  2765.  Determines whether a command batch has changed the current database.
  2766.  
  2767.  
  2768.  Syntax
  2769.  
  2770.    char *dbchange(dbproc)
  2771.  
  2772.     DBPROCESS *dbproc;
  2773.  
  2774.  
  2775.  Comments
  2776.  
  2777.  The dbchange function informs the program of a change in the current
  2778.  database by catching any instance of the TRANSACT-SQL USE statement.
  2779.  
  2780.  Database changes made by a USE statement do not take effect until the end of
  2781.  the batch. The dbchange function is therefore useful only in determining
  2782.  whether the current command batch has changed the database for subsequent
  2783.  command batches.
  2784.  
  2785.  The internal DBPROCESS flag that dbchange monitors to determine whether the
  2786.  database has changed is cleared when the program executes a new command
  2787.  batch by calling either dbsqlexec or dbsqlsend. Therefore, the simplest way
  2788.  to keep track of database changes is to call dbchange when dbresults returns
  2789.  NO_MORE_RESULTS at the end of each command batch.
  2790.  
  2791.  Alternatively, you can always get the name of the current database by
  2792.  calling dbname.
  2793.  
  2794.  
  2795.  Parameters
  2796.  
  2797.  dbproc
  2798.    The DBPROCESS structure that is the handle for a particular
  2799.    workstation/SQL Server process. It contains all the information that
  2800.    DB-LIBRARY uses to manage communications and data between the workstation
  2801.    and SQL Server.
  2802.  
  2803.  
  2804.  Returns
  2805.  
  2806.  A pointer to the null-terminated name of the new database, if any. If the
  2807.  database has not changed, NULL is returned.
  2808.  
  2809.  
  2810.  See Also
  2811.  
  2812.  dbname, dbresults, dbsqlexec, dbsqlsend
  2813.  
  2814.  
  2815.  dbclose
  2816.  ────────────────────────────────────────────────────────────────────────────
  2817.  
  2818.  Function
  2819.  
  2820.  Closes and frees a single DBPROCESS structure.
  2821.  
  2822.  
  2823.  Syntax
  2824.  
  2825.    void dbclose(dbproc)
  2826.  
  2827.     DBPROCESS *dbproc;
  2828.  
  2829.  
  2830.  Comments
  2831.  
  2832.  The dbclose function is the inverse of dbopen. It cleans up any activity
  2833.  associated with one DBPROCESS structure and frees the memory. It also closes
  2834.  the corresponding network connection.
  2835.  
  2836.  Use dbexit to close every open DBPROCESS structure.
  2837.  
  2838.  Calling dbclose with a parameter not returned by dbopen causes an error.
  2839.  
  2840.  
  2841.  Parameters
  2842.  
  2843.  dbproc
  2844.    The DBPROCESS structure that is the handle for a particular
  2845.    workstation/SQL Server process. It contains all the information that
  2846.    DB-LIBRARY uses to manage communications and data between the workstation
  2847.    and SQL Server.
  2848.  
  2849.  
  2850.  Returns
  2851.  
  2852.  None.
  2853.  
  2854.  
  2855.  See Also
  2856.  
  2857.  dbexit, dbopen
  2858.  
  2859.  
  2860.  dbclrbuf
  2861.  ────────────────────────────────────────────────────────────────────────────
  2862.  
  2863.  Function
  2864.  
  2865.  Drops rows from the row buffer.
  2866.  
  2867.  
  2868.  Syntax
  2869.  
  2870.    void dbclrbuf(dbproc, n)
  2871.  
  2872.     DBPROCESS *dbproc;
  2873.     DBINT n;
  2874.  
  2875.  
  2876.  Comments
  2877.  
  2878.  DB-LIBRARY provides a service that allows rows to be buffered as they are
  2879.  returned from SQL Server. You can turn row buffering on by calling
  2880.  dbsetopt(dbproc, DBBUFFER, "n"), where n is the number of rows you would
  2881.  like DB-LIBRARY to buffer. If buffering is on, you can then randomly refer
  2882.  to rows that have been read from SQL Server using dbgetrow.
  2883.  
  2884.  The row buffer can become full if SQL Server has returned more than the n
  2885.  rows that you said you wanted buffered. The row buffer is full when
  2886.  dbnextrow returns BUF_FULL. When this happens, dbnextrow is refusing to read
  2887.  in the next row from SQL Server. Once the row buffer is full, dbnextrow will
  2888.  continue to return BUF_FULL until at least one row is freed by calling
  2889.  dbclrbuf. The dbclrbuf function always frees the oldest row in the buffer
  2890.  first.
  2891.  
  2892.  
  2893.  Parameters
  2894.  
  2895.  dbproc
  2896.    The DBPROCESS structure that is the handle for a particular
  2897.    workstation/SQL Server process. It contains all the information that
  2898.    DB-LIBRARY uses to manage communications and data between the workstation
  2899.    and SQL Server.
  2900.  
  2901.  n
  2902.    The number of rows you want cleared from the row buffer. If n is equal to
  2903.    or greater than the number of rows in the buffer, all but the newest row
  2904.    will be removed. If n is less than 1, the call is ignored.
  2905.  
  2906.  
  2907.  Returns
  2908.  
  2909.  None.
  2910.  
  2911.  
  2912.  See Also
  2913.  
  2914.  dbgetrow, dbnextrow, dbsetopt, Appendix B
  2915.  
  2916.  
  2917.  dbclropt
  2918.  ────────────────────────────────────────────────────────────────────────────
  2919.  
  2920.  Function
  2921.  
  2922.  Clears an option set by dbsetopt.
  2923.  
  2924.  
  2925.  Syntax
  2926.  
  2927.    RETCODE dbclropt(dbproc, option, param)
  2928.  
  2929.     DBPROCESS *dbproc;
  2930.     int   option;
  2931.     char  *param;
  2932.  
  2933.  
  2934.  Comments
  2935.  
  2936.  This function clears SQL Server and DB-LIBRARY options that have been set
  2937.  with dbsetopt. Although SQL Server options can be set and cleared directly
  2938.  through SQL, the application should use dbsetopt and dbclropt to set and
  2939.  clear options. This provides a uniform interface for setting both SQL Server
  2940.  and DB-LIBRARY options. It also allows the application to use the dbisopt
  2941.  function to check the status of an option.
  2942.  
  2943.  This function does not immediately clear the options specified. With the
  2944.  exception of DBBUFFER and DBNOAUTOFREE, they are not cleared until the
  2945.  command buffer is sent to SQL Server (by invoking the dbsqlexec function).
  2946.  An additional result is returned, using the dbresults function. (For
  2947.  information on results returned, see "dbresult.")
  2948.  
  2949.  For a complete list of options, see Appendix B, "DB-LIBRARY Options."
  2950.  
  2951.  
  2952.  Parameters
  2953.  
  2954.  dbproc
  2955.    The DBPROCESS structure that is the handle for a particular
  2956.    workstation/SQL Server process. It contains all the information that
  2957.    DB-LIBRARY uses to manage communications and data between the workstation
  2958.    and SQL Server. If dbproc is NULL, the option is cleared for all active
  2959.    DBPROCESS structures.
  2960.  
  2961.  option
  2962.    The option that is to be turned off.
  2963.  
  2964.  param
  2965.    Certain options take parameters. The DBOFFSET option, for example, takes
  2966.    as a parameter the SQL construct for which offsets are to be returned. For
  2967.    a list of options that take parameters, see Appendix B, "DB-LIBRARY
  2968.    Options." If an option does not take a parameter, param must be NULL. If
  2969.    the option you are clearing takes a parameter but there can be only one
  2970.    instance of the option, dbclropt ignores the param parameter. For example,
  2971.    dbclropt ignores the value of param when clearing the DBBUFFER option
  2972.    because row buffering can have only one setting at a time. On the other
  2973.    hand, the DBOFFSET option can have several settings, each with a different
  2974.    parameter. It can have been set twice─to look for offsets to SELECT
  2975.    statements and offsets to ORDER BY clauses. In that case, dbclropt needs
  2976.    the param parameter to determine whether to clear the SELECT offset or the
  2977.    ORDER BY offset. The only other option for which dbclropt requires a param
  2978.    is DBSTAT.
  2979.  
  2980.    Note that the command string generated by this function is not immediately
  2981.    sent to SQL Server. Instead, it is buffered within DB-LIBRARY and sent the
  2982.    next time dbsqlexec is invoked; therefore, any options requested by this
  2983.    function do not go into effect until then. Also, the results of the
  2984.    command generated by this function are not returned until the command is
  2985.    transferred to SQL Server. Therefore, the application should be expecting
  2986.    the results returned from the command string generated by this function.
  2987.    If an invalid parameter is specified, this is not known until the command
  2988.    is sent to SQL Server and the results for that command are returned using
  2989.    dbresult.
  2990.  
  2991.  
  2992.  Returns
  2993.  
  2994.  SUCCEED or FAIL.
  2995.  
  2996.  
  2997.  See Also
  2998.  
  2999.  dbisopt, dbresults, dbsetopt, dbsqlexec, Appendix B
  3000.  
  3001.  
  3002.  dbcmd
  3003.  ────────────────────────────────────────────────────────────────────────────
  3004.  
  3005.  Function
  3006.  
  3007.  Adds text to the DBPROCESS command buffer.
  3008.  
  3009.  
  3010.  Syntax
  3011.  
  3012.    RETCODE dbcmd(dbproc, cmdstring)
  3013.  
  3014.     DBPROCESS *dbproc;
  3015.     char  *cmdstring;
  3016.  
  3017.  
  3018.  Comments
  3019.  
  3020.  This function adds text to the command buffer in the DBPROCESS structure. It
  3021.  adds to the existing command buffer; it doesn't delete or overwrite the
  3022.  current contents except after the buffer has been sent to SQL Server. (See
  3023.  the following comment.) The user can call dbcmd repeatedly. Note that
  3024.  sequential calls are concatenated together; it is the application's
  3025.  responsibility to ensure that any necessary blanks appear between the end of
  3026.  one line and the beginning of the next.
  3027.  
  3028.  After a call to dbsqlexec or dbsqlsend, the first call to either dbcmd or
  3029.  dbfcmd automatically clears the command buffer before the new text is
  3030.  entered. If this situation is undesirable, set the DBNOAUTOFREE option. When
  3031.  DBNOAUTOFREE is set, the command buffer is cleared only by an explicit call
  3032.  to dbfreebuf.
  3033.  
  3034.  The following example shows how to use dbcmd to build up a multiple-line SQL
  3035.  statement:
  3036.  
  3037.    DBPROCESS *dbproc;
  3038.  
  3039.     dbcmd(dbproc, "Select name from sysobjects");
  3040.     dbcmd(dbproc, " where id < 5");
  3041.     dbcmd(dbproc, " and type='S'");
  3042.  
  3043.  The dbfcmd function is a related function. Unlike dbcmd, dbfcmd takes
  3044.  additional parameters and interprets the cmdstring as a format string that
  3045.  is passed to sprintf along with any additional parameters.
  3046.  
  3047.  
  3048.  Parameters
  3049.  
  3050.  dbproc
  3051.    The DBPROCESS structure that is the handle for a particular
  3052.    workstation/SQL Server process. It contains all the information that
  3053.    DB-LIBRARY uses to manage communications and data between the workstation
  3054.    and SQL Server.
  3055.  
  3056.  cmdstring
  3057.    A null-terminated character string that is to be copied into the command
  3058.    buffer.
  3059.  
  3060.  
  3061.  Returns
  3062.  
  3063.  SUCCEED or FAIL.
  3064.  
  3065.  
  3066.  See Also
  3067.  
  3068.  dbfcmd, dbfreebuf, dbsqlexec, dbsqlsend, Appendix B
  3069.  
  3070.  
  3071.  DBCMDROW
  3072.  ────────────────────────────────────────────────────────────────────────────
  3073.  
  3074.  Function
  3075.  
  3076.  Determines whether the current command can return rows.
  3077.  
  3078.  
  3079.  Syntax
  3080.  
  3081.    RETCODE DBCMDROW(dbproc)
  3082.  
  3083.     DBPROCESS *dbproc;
  3084.  
  3085.  
  3086.  Comments
  3087.  
  3088.  This macro determines whether the current command is one that can return
  3089.  rows, that is, a TRANSACT-SQL SELECT statement or an EXECUTE on a stored
  3090.  procedure containing a SELECT. It should be called after dbresults returns
  3091.  SUCCEED.
  3092.  
  3093.  Even if this macro returns SUCCEED, the statement will not return any rows
  3094.  if none have qualified. To determine whether any rows are actually being
  3095.  returned, use the DBROWS macro.
  3096.  
  3097.  
  3098.  Parameters
  3099.  
  3100.  dbproc
  3101.    The DBPROCESS structure that is the handle for a particular
  3102.    workstation/SQL Server process. It contains all the information that
  3103.    DB-LIBRARY uses to manage communications and data between the workstation
  3104.    and SQL Server.
  3105.  
  3106.  
  3107.  Returns
  3108.  
  3109.  SUCCEED or FAIL to indicate whether this statement can return rows.
  3110.  
  3111.  
  3112.  See Also
  3113.  
  3114.  dbnextrow, dbresults, DBROWS, DBROWTYPE
  3115.  
  3116.  
  3117.  dbcolbrowse
  3118.  ────────────────────────────────────────────────────────────────────────────
  3119.  
  3120.  Function
  3121.  
  3122.  Determines whether the source of a result column can be updated with the
  3123.  DB-LIBRARY browse-mode facilities.
  3124.  
  3125.  
  3126.  Syntax
  3127.  
  3128.    DBBOOL dbcolbrowse(dbproc, colnum)
  3129.  
  3130.     DBPROCESS *dbproc;
  3131.     int   colnum;
  3132.  
  3133.  
  3134.  Comments
  3135.  
  3136.  The dbcolbrowse function is one of the DB-LIBRARY browse-mode functions. For
  3137.  a detailed discussion of browse mode, see Chapter 1, "Overview of
  3138.  DB-LIBRARY."
  3139.  
  3140.  The dbcolbrowse function provides a way to determine whether the database
  3141.  column that's the source of a result column in a select list can be updated
  3142.  with the DB-LIBRARY browse-mode facilities. This function is useful in
  3143.  examining ad hoc queries. If the query has been hardcoded into the program,
  3144.  dbcolbrowse is unnecessary.
  3145.  
  3146.  Only a column derived from a table that has a unique index and a timestamp
  3147.  column can be updated. It cannot be the result of a TRANSACT-SQL expression.
  3148.  For example, in the following select list, result columns 1 and 2 (title and
  3149.  category) can be updated, but column 3 (wholesale) cannot because it is the
  3150.  result of an expression:
  3151.  
  3152.    select title, category=type, wholesale=(price * 0.6)
  3153.     from inventory for browse
  3154.  
  3155.  The dbcolbrowse function can be called any time after dbresults.
  3156.  
  3157.  To determine the name of the source column given the name of the result
  3158.  column, use dbcolsource.
  3159.  
  3160.  
  3161.  Parameters
  3162.  
  3163.  dbproc
  3164.    The DBPROCESS structure that is the handle for a particular
  3165.    workstation/SQL Server process. It contains all the information that
  3166.    DB-LIBRARY uses to manage communications and data between the workstation
  3167.    and SQL Server.
  3168.  
  3169.  colnum
  3170.    The number of the result column. Column numbers start at 1.
  3171.  
  3172.  
  3173.  Returns
  3174.  
  3175.  TRUE or FALSE.
  3176.  
  3177.  
  3178.  See Also
  3179.  
  3180.  dbcolsource, dbqual, dbresults, dbtabbrowse, dbtabcount, dbtabname,
  3181.  dbtabsource, dbtsnewlen, dbtsnewval, dbtsput
  3182.  
  3183.  
  3184.  dbcollen
  3185.  ────────────────────────────────────────────────────────────────────────────
  3186.  
  3187.  Function
  3188.  
  3189.  Returns the maximum length, in bytes, of the data for a column.
  3190.  
  3191.  
  3192.  Syntax
  3193.  
  3194.    DBINT dbcollen(dbproc, column)
  3195.  
  3196.     DBPROCESS *dbproc;
  3197.     int   column;
  3198.  
  3199.  
  3200.  Comments
  3201.  
  3202.  This function returns the maximum length, in bytes, of the data for a
  3203.  particular column. In the case of variable length data, this is not
  3204.  necessarily the actual length of the data, but rather the maximum length
  3205.  that the data can be. For the actual data length, use dbdatlen.
  3206.  
  3207.  The following program fragment uses dbcollen:
  3208.  
  3209.    DBPROCESS *dbproc;
  3210.     int   colnum;
  3211.     DBINT  column_length;
  3212.  
  3213.     /* Put the command into the command buffer. */
  3214.     dbcmd(dbproc, "select name, id, type from sysobjects");
  3215.  
  3216.     /* Send the command to SQL Server and begin execution. */
  3217.     dbsqlexec(dbproc);
  3218.  
  3219.     /* Process the command results. */
  3220.     dbresults(dbproc);
  3221.  
  3222.     /* Examine the column lengths. */
  3223.     for (colnum = 1; colnum < 4; colnum++)
  3224.     {
  3225.      column_length = dbcollen(dbproc, colnum);
  3226.      printf("column %d, length is %ld.\n", colnum, column_length);
  3227.     }
  3228.  
  3229.  
  3230.  Parameters
  3231.  
  3232.  dbproc
  3233.    The DBPROCESS structure that is the handle for a particular
  3234.    workstation/SQL Server process. It contains all the information that
  3235.    DB-LIBRARY uses to manage communications and data between the workstation
  3236.    and SQL Server.
  3237.  
  3238.  column
  3239.    The number of the column. The first column is number 1.
  3240.  
  3241.  
  3242.  Returns
  3243.  
  3244.  The maximum length of the data for the particular column. If the column
  3245.  number is not in range, -1 is returned.
  3246.  
  3247.  
  3248.  See Also
  3249.  
  3250.  dbcoltype, dbcolname, dbdata, dbdatlen, dbnumcols
  3251.  
  3252.  
  3253.  dbcolname
  3254.  ────────────────────────────────────────────────────────────────────────────
  3255.  
  3256.  Function
  3257.  
  3258.  Returns the name of a particular result column.
  3259.  
  3260.  
  3261.  Syntax
  3262.  
  3263.    char *dbcolname(dbproc, column)
  3264.  
  3265.     DBPROCESS *dbproc;
  3266.     int   column;
  3267.  
  3268.  
  3269.  Comments
  3270.  
  3271.  This function returns a pointer to the null-terminated name of a particular
  3272.  column.
  3273.  
  3274.  The following program fragment uses dbcolname:
  3275.  
  3276.    DBPROCESS *dbproc;
  3277.  
  3278.     /* Put the command into the command buffer. */
  3279.     dbcmd(dbproc, "select name, id, type from sysobjects");
  3280.  
  3281.     /* Send the command to SQL Server and begin execution. */
  3282.     dbsqlexec(dbproc);
  3283.  
  3284.     /* Process the command results. */
  3285.     dbresults(dbproc);
  3286.  
  3287.     /* Examine the column names. */
  3288.     printf("first column name is %s\n", dbcolname(dbproc, 1));
  3289.     printf("second column name is %s\n", dbcolname(dbproc, 2));
  3290.     printf("third column name is %s\n", dbcolname(dbproc, 3));
  3291.  
  3292.  
  3293.  Parameters
  3294.  
  3295.  dbproc
  3296.    The DBPROCESS structure that is the handle for a particular
  3297.    workstation/SQL Server process. It contains all the information that
  3298.    DB-LIBRARY uses to manage communications and data between the workstation
  3299.    and SQL Server.
  3300.  
  3301.  column
  3302.    The number of the column. The first column is number 1.
  3303.  
  3304.  
  3305.  Returns
  3306.  
  3307.  A char pointer to the null-terminated name of the particular column. If the
  3308.  column number is not in range, NULL is returned.
  3309.  
  3310.  
  3311.  See Also
  3312.  
  3313.  dbcollen, dbcoltype, dbdata, dbdatlen, dbnumcols
  3314.  
  3315.  
  3316.  dbcolsource
  3317.  ────────────────────────────────────────────────────────────────────────────
  3318.  
  3319.  Function
  3320.  
  3321.  Returns a pointer to the name of the database column from which the
  3322.  specified result column was derived.
  3323.  
  3324.  
  3325.  Syntax
  3326.  
  3327.    char *dbcolsource(dbproc, colnum)
  3328.  
  3329.     DBPROCESS *dbproc;
  3330.     int   colnum;
  3331.  
  3332.  
  3333.  Comments
  3334.  
  3335.  The dbcolsource function is one of the DB-LIBRARY browse-mode functions. For
  3336.  a detailed discussion of browse mode, see Chapter 1, "Overview of
  3337.  DB-LIBRARY."
  3338.  
  3339.  The dbcolsource function provides an application with information it needs
  3340.  to update a database column, based on an ad hoc query. SELECT statements can
  3341.  optionally specify header names for result columns:
  3342.  
  3343.    select author = au_lname from authors
  3344.  
  3345.  When updating a table, you must use the database column name, not the header
  3346.  name (in this example, au_lname, not author). You can use the dbcolsource
  3347.  function to get the underlying database column name:
  3348.  
  3349.    dbcolsource(dbproc, 1)
  3350.  
  3351.  This call returns a pointer to the string au_lname.
  3352.  
  3353.  The dbcolsource function is useful for ad hoc queries. If the query has been
  3354.  hardcoded into the program, this function is unnecessary.
  3355.  
  3356.  The dbcolsource function can be called any time after dbresults.
  3357.  
  3358.  
  3359.  Parameters
  3360.  
  3361.  dbproc
  3362.    The DBPROCESS structure that is the handle for a particular
  3363.    workstation/SQL Server process. It contains all the information that
  3364.    DB-LIBRARY uses to manage communications and data between the workstation
  3365.    and SQL Server.
  3366.  
  3367.  colnum
  3368.    The number of the result column. Column numbers start at 1.
  3369.  
  3370.  
  3371.  Returns
  3372.  
  3373.  A pointer to a null-terminated column name. This pointer will be NULL if the
  3374.  column number is out of range or if the column is the result of a
  3375.  TRANSACT-SQL expression, such as "max(colname)".
  3376.  
  3377.  
  3378.  See Also
  3379.  
  3380.  dbcolbrowse, dbqual, dbresults, dbtabbrowse, dbtabcount, dbtabname,
  3381.  dbtabsource, dbtsnewlen, dbtsnewval, dbtsput
  3382.  
  3383.  
  3384.  dbcoltype
  3385.  ────────────────────────────────────────────────────────────────────────────
  3386.  
  3387.  Function
  3388.  
  3389.  Returns the datatype for a column.
  3390.  
  3391.  
  3392.  Syntax
  3393.  
  3394.    int dbcoltype(dbproc, column)
  3395.  
  3396.     DBPROCESS *dbproc;
  3397.     int   column;
  3398.  
  3399.  
  3400.  Comments
  3401.  
  3402.  This function returns the type of the data for a particular column. For a
  3403.  list of SQL Server types, see Appendix C, "DB-LIBRARY Datatypes."
  3404.  
  3405.  The dbcoltype function returns an integer value for the type. Use dbprtype
  3406.  to convert the type value into a readable string.
  3407.  
  3408.  The following program fragment uses dbcoltype:
  3409.  
  3410.    DBPROCESS *dbproc;
  3411.     int   colnum;
  3412.     int   coltype;
  3413.  
  3414.     /* Put the command into the command buffer. */
  3415.     dbcmd(dbproc, "select name, id, type from sysobjects");
  3416.  
  3417.     /* Send the command to SQL Server and begin execution. */
  3418.     dbsqlexec(dbproc);
  3419.  
  3420.     /* Process the command results. */
  3421.     dbresults(dbproc);
  3422.  
  3423.     /* Examine the column types. */
  3424.     for (colnum = 1; colnum < 4; colnum++)
  3425.     {
  3426.      coltype = dbcoltype(dbproc, colnum);
  3427.      printf("column %d, type is %s.\n", colnum, dbprtype(coltype));
  3428.     }
  3429.  
  3430.  
  3431.  Parameters
  3432.  
  3433.  dbproc
  3434.    The DBPROCESS structure that is the handle for a particular
  3435.    workstation/SQL Server process. It contains all the information that
  3436.    DB-LIBRARY uses to manage communications and data between the workstation
  3437.    and SQL Server.
  3438.  
  3439.  column
  3440.    The number of the column. The first column is number 1.
  3441.  
  3442.  
  3443.  Returns
  3444.  
  3445.  A value for the datatype for the particular column. If the column is not in
  3446.  range, -1 is returned.
  3447.  
  3448. ╓┌─────────────────────────────────┌─────────────────────────────────────────
  3449.  Column                            Return
  3450.  ────────────────────────────────────────────────────────────────────────────
  3451.  SQLVARCHAR                        SQLCHAR
  3452.  
  3453.  SQLVARBINARY                      SQLBINARY
  3454.  
  3455.  SQLDATETIME                       SQLDATETIME
  3456.  
  3457.  SQLMONEY                          SQLMONEY
  3458.  
  3459.  SQLFLT8                           SQLFLT8
  3460.  
  3461.  SQLCHAR                           SQLCHAR
  3462.  
  3463.  SQLBINARY                         SQLBINARY
  3464.  
  3465.  SQLTEXT                           SQLTEXT
  3466.  
  3467.  Column                            Return
  3468.  ────────────────────────────────────────────────────────────────────────────
  3469. 
  3470.  SQLIMAGE                          SQLIMAGE
  3471.  
  3472.  SQLINTn                           SQLINT1, SQLINT2, or SQLINT4, depending on
  3473.                                    the actual type of the SQLINTn
  3474.  
  3475.  
  3476.  
  3477.  
  3478.  See Also
  3479.  
  3480.  dbcollen, dbcolname, dbdata, dbdatlen, dbnumcols, dbprtype, Appendix C,
  3481.  "DB-LIBRARY Datatypes"
  3482.  
  3483.  
  3484.  dbconvert
  3485.  ────────────────────────────────────────────────────────────────────────────
  3486.  
  3487.  Function
  3488.  
  3489.  Converts data from one datatype to another.
  3490.  
  3491.  
  3492.  Syntax
  3493.  
  3494.    int dbconvert(dbproc, srctype, src, srclen, desttype, dest, destlen)
  3495.  
  3496.     DBPROCESS *dbproc;
  3497.     int   srctype;
  3498.     BYTE  *src;
  3499.     DBINT  srclen;
  3500.     int   desttype;
  3501.     BYTE  *dest;
  3502.     DBINT  destlen;
  3503.  
  3504.  
  3505.  Comments
  3506.  
  3507.  This function allows the program to convert data from one representation to
  3508.  another. To determine whether a particular conversion is permitted, the
  3509.  program can call dbwillconvert before attempting a conversion.
  3510.  
  3511.  The dbconvert function can convert data stored in any of the SQL Server
  3512.  datatypes (although not all conversions are legal.) The following table
  3513.  shows the program variable type you must provide to receive the results from
  3514.  dbconvert for each SQL Server datatype.
  3515.  
  3516. ╓┌─────────────────────────────────┌─────────────────────────────────────────╖
  3517.  SQL Server Type                   Program Variable Type
  3518.  ────────────────────────────────────────────────────────────────────────────
  3519.  SQLCHAR                           DBCHAR
  3520.  
  3521.  SQLTEXT                           DBCHAR
  3522.  
  3523.  SQLBINARY                         DBBINARY
  3524.  
  3525.  SQLIMAGE                          DBBINARY
  3526.  
  3527.  SQLINT1                           DBTINYINT
  3528.  
  3529.  SQLINT2                           DBSMALLINT
  3530.  SQL Server Type                   Program Variable Type
  3531.  ────────────────────────────────────────────────────────────────────────────
  3532. SQLINT2                           DBSMALLINT
  3533.  
  3534.  SQLINT4                           DBINT
  3535.  
  3536.  SQLFLT8                           DBFLT8
  3537.  
  3538.  SQLBIT                            DBBIT
  3539.  
  3540.  SQLMONEY                          DBMONEY
  3541.  
  3542.  SQLDATETIME                       DBDATETIME
  3543.  
  3544.  
  3545.  
  3546.  The following table lists the datatype conversions that dbconvert supports.
  3547.  The source datatypes are listed down the leftmost column, and the
  3548.  destination datatypes are listed along the top row of the table. (For
  3549.  brevity, the prefix "SQL" has been eliminated from each datatype.) T (TRUE)
  3550.  indicates that the conversion is supported; F (FALSE) indicates that the
  3551.  conversion is not supported.
  3552.  
  3553. ╓┌─────────┌───────┌───────┌───────┌───────┌───────┌───────┌───────┌───────┌─
  3554.  ────────────────────────────────────────────────────────────────────────────
  3555.  To:       char    text    binary  image   int1    int2    int4    flt8    bit
  3556.  
  3557.  From:
  3558.  
  3559.  char      T       T       T       T       T       T       T       T       T
  3560.  
  3561.  text      T       T       T       T       T       T       T       T       T
  3562.  
  3563.  binary    T       T       T       T       T       T       T       T       T
  3564.  
  3565.  image     T       T       T       T       T       T       T       T       T
  3566.  
  3567.  int1      T       T       T       T       T       T       T       T       T
  3568.  
  3569.  int2      T       T       T       T       T       T       T       T       T
  3570.  
  3571.  int4      T       T       T       T       T       T       T       T       T
  3572.  ────────────────────────────────────────────────────────────────────────────
  3573. int4      T       T       T       T       T       T       T       T       T
  3574.  
  3575.  flt8      T       T       T       T       T       T       T       T       T
  3576.  
  3577.  bit       T       T       T       T       T       T       T       T       T
  3578.  
  3579.  money     T       T       T       T       T       T       T       T       T
  3580.  
  3581.  datetime  T       T       T       T       F       F       F       F       F
  3582.  
  3583.  ────────────────────────────────────────────────────────────────────────────
  3584.  
  3585.  
  3586.  
  3587.  A conversion to or from the datatypes SQLBINARY and SQLIMAGE is a straight
  3588.  bit-copy except when the conversion involves SQLCHAR or SQLTEXT. When
  3589.  converting SQLCHAR or SQLTEXT data to SQLBINARY or SQLIMAGE, dbconvert
  3590.  interprets the SQLCHAR or SQLTEXT string as hexadecimal, whether or not the
  3591.  string contains a leading "0x". When converting SQLBINARY or SQLIMAGE data
  3592.  to SQLCHAR or SQLTEXT, dbconvert creates a hexadecimal string without a
  3593.  leading "0x".
  3594.  
  3595.  Converting an SQLMONEY, SQLCHAR, or SQLTEXT value to SQLFLT8 can result in
  3596.  some loss of precision. Converting an SQLFLT8 value to SQLCHAR or SQLTEXT
  3597.  can also result in some loss of precision.
  3598.  
  3599.  Converting an SQLFLT8 value to SQLMONEY can result in overflow because the
  3600.  maximum value for SQLMONEY is $922,337,203,685,477.58.
  3601.  
  3602.  If overflow occurs when converting integer or float data to SQLCHAR or
  3603.  SQLTEXT, the first character of the resulting value will contain an asterisk
  3604.  ("*") to indicate the error.
  3605.  
  3606.  The following example illustrates how to convert SQL Server data obtained
  3607.  with dbdata:
  3608.  
  3609.    DBCHAR title[81];
  3610.     DBCHAR price[9];
  3611.  
  3612.     /* Read the query into the command buffer. */
  3613.     dbcmd(dbproc, "select title, price, royalty from pubs..titles");
  3614.     /* Send the query to SQL Server. */
  3615.     dbsqlexec(dbproc);
  3616.  
  3617.     /* Get ready to process the results of the query. */
  3618.     dbresults(dbproc);
  3619.  
  3620.     /* Process each row. */
  3621.     while (dbnextrow(dbproc) != NO_MORE_ROWS)
  3622.     {
  3623.      /* The first dbconvert() adds a null terminator to the string. */
  3624.      dbconvert(dbproc, SQLCHAR, (dbdata(dbproc,1)), (dbdatlen(dbproc,1)),
  3625.      SQLCHAR, title, (DBINT)-1);
  3626.      /* The second dbconvert() converts money to string. */
  3627.      dbconvert(dbproc, SQLMONEY, (dbdata(dbproc,2)), (DBINT)-1, SQLCHAR,
  3628.       price, (DBINT)-1);
  3629.  
  3630.      if (dbdatlen(dbproc,3) != 0)
  3631.       printf ("%s\n $%s %ld\n", title, price,
  3632.        *((DBINT *)dbdata(dbproc,3)));
  3633.     }
  3634.  
  3635.  If you're binding data to variables rather than accessing the data directly,
  3636.  you can use dbbind to perform the conversions rather than dbconvert.
  3637.  
  3638.  Example 5 in Chapter 3, "Example Programs," illustrates several more types
  3639.  of conversions using dbconvert.
  3640.  
  3641.  
  3642.  Parameters
  3643.  
  3644.  dbproc
  3645.    The DBPROCESS structure that is the handle for a particular
  3646.    workstation/SQL Server process. It contains all the information that
  3647.    DB-LIBRARY uses to manage communications and data between the workstation
  3648.    and SQL Server. In dbconvert, the DBPROCESS is used only to supply any
  3649.    custom null values that the program specified through dbsetnull. If dbproc
  3650.    is NULL, dbconvert uses the default values for null value data
  3651.    conversions.
  3652.  
  3653.  srctype
  3654.    The datatype of the data to be converted. This parameter can be any of the
  3655.    SQL Server datatypes. You can use dbcoltype to get the SQL Server datatype
  3656.    for a particular column.
  3657.  
  3658.  src
  3659.    A pointer to the data to be converted. If this pointer is NULL, dbconvert
  3660.    will place an appropriate null value in the destination variable. You can
  3661.    use dbdata to get the SQL Server data.
  3662.  
  3663.  srclen
  3664.    The length, in bytes, of the data to be converted. If the srclen is 0, the
  3665.    source data is assumed to be null, and dbconvert places an appropriate
  3666.    null value in the destination variable. Otherwise, this length is ignored
  3667.    for all datatypes except char, text, binary, and image. For SQLCHAR data,
  3668.    a length of -1 indicates that the string is null-terminated.
  3669.  
  3670.  desttype
  3671.    The datatype that the source data is to be converted into. This parameter
  3672.    can be any of the SQL Server datatypes.
  3673.  
  3674.  dest
  3675.    A pointer to the destination variable that will receive the converted
  3676.    data. If this pointer is NULL, dbconvert will call the user-supplied error
  3677.    handler (if any) and return -1.
  3678.  
  3679.  destlen
  3680.    The length, in bytes, of the destination variable. The destlen is ignored
  3681.    for fixed-length datatypes. For an SQLCHAR destination, the value of
  3682.    destlen must be the total length of the destination buffer space. A length
  3683.    of -1 for an SQLCHAR or SQLBINARY destination means that there is
  3684.    sufficient space available. Note that for an SQLCHAR destination, a length
  3685.    of -1 causes the character string to be given a terminating null.  You can
  3686.    use dbdatlen to get the length of SQL Server data.
  3687.  
  3688.  
  3689.  Returns
  3690.  
  3691.  The length of the converted data, in bytes, if the datatype conversion
  3692.  succeeds. If the conversion fails, -1 is returned. If dbconvert fails, it
  3693.  first calls a user-supplied error handler (if any). This routine may fail
  3694.  for one of these reasons:
  3695.  
  3696.  
  3697.    ■   The requested conversion was unavailable.
  3698.  
  3699.    ■   The conversion resulted in truncation, overflow, or loss of precision
  3700.        in the destination variable.
  3701.  
  3702.    ■   A syntax error occurred in converting a character string to some
  3703.        numeric type.
  3704.  
  3705.  
  3706.  
  3707.  See Also
  3708.  
  3709.  dbaltbind, dbbind, dbcoltype, dbdata, dbdatlen, dberrhandle, dbsetnull,
  3710.  dbwillconvert, Appendix C, Appendix D
  3711.  
  3712.  
  3713.  DBCOUNT
  3714.  ────────────────────────────────────────────────────────────────────────────
  3715.  
  3716.  Function
  3717.  
  3718.  Returns the number of rows affected by a TRANSACT-SQL statement.
  3719.  
  3720.  
  3721.  Syntax
  3722.  
  3723.    DBINT DBCOUNT(dbproc)
  3724.  
  3725.     DBPROCESS *dbproc;
  3726.  
  3727.  
  3728.  Comments
  3729.  
  3730.  Once the results of a statement have been processed, you can call DBCOUNT to
  3731.  find out how many rows were affected by the statement. For example, if a
  3732.  SELECT statement was sent to SQL Server and you have read all the rows by
  3733.  calling dbnextrow until it returned NO_MORE_ROWS, you can call this macro to
  3734.  find out how many rows were retrieved.
  3735.  
  3736.  If the current statement doesn't immediately return rows (for example, a
  3737.  DELETE), you can call DBCOUNT after dbresults.
  3738.  
  3739.  
  3740.  Parameters
  3741.  
  3742.  dbproc
  3743.    The DBPROCESS structure that is the handle for a particular
  3744.    workstation/SQL Server process. It contains all the information that
  3745.    DB-LIBRARY uses to manage communications and data between the workstation
  3746.    and SQL Server.
  3747.  
  3748.  
  3749.  Returns
  3750.  
  3751.  The number of rows affected.
  3752.  
  3753.  
  3754.  See Also
  3755.  
  3756.  dbnextrow, dbresults
  3757.  
  3758.  
  3759.  DBCURCMD
  3760.  ────────────────────────────────────────────────────────────────────────────
  3761.  
  3762.  Function
  3763.  
  3764.  Returns the number of the current command.
  3765.  
  3766.  
  3767.  Syntax
  3768.  
  3769.    int DBCURCMD(dbproc)
  3770.  
  3771.     DBPROCESS *dbproc;
  3772.  
  3773.  
  3774.  Comments
  3775.  
  3776.  This macro returns the number of the command whose results are currently
  3777.  being processed.
  3778.  
  3779.  The first command in a batch is number 1. The command number is incremented
  3780.  every time dbresults returns SUCCEED or FAIL. (Unsuccessful commands are
  3781.  counted.) The command number is reset by each call to dbsqlexec or
  3782.  dbsqlsend.
  3783.  
  3784.  
  3785.  Parameters
  3786.  
  3787.  dbproc
  3788.    The DBPROCESS structure that is the handle for a particular
  3789.    workstation/SQL Server process. It contains all the information that
  3790.    DB-LIBRARY uses to manage communications and data between the workstation
  3791.    and SQL Server.
  3792.  
  3793.  
  3794.  Returns
  3795.  
  3796.  The number of the current command. The first command in a batch is number 1.
  3797.  
  3798.  
  3799.  
  3800.  See Also
  3801.  
  3802.  DBCMDROW, DBMORECMDS, DBROWS, dbsqlexec, dbsqlsend
  3803.  
  3804.  
  3805.  DBCURROW
  3806.  ────────────────────────────────────────────────────────────────────────────
  3807.  
  3808.  Function
  3809.  
  3810.  Returns the number of the row currently being read.
  3811.  
  3812.  
  3813.  Syntax
  3814.  
  3815.    DBINT DBCURROW(dbproc)
  3816.  
  3817.     DBPROCESS *dbproc;
  3818.  
  3819.  
  3820.  Comments
  3821.  
  3822.  This macro returns the number of the current row being read. The first row
  3823.  returned from SQL Server is number 1. The row number is changed every time
  3824.  dbnextrow or dbgetrow returns SUCCEED.
  3825.  
  3826.  The row number is reset to 0 by each new call to dbresults.
  3827.  
  3828.  
  3829.  Parameters
  3830.  
  3831.  dbproc
  3832.    The DBPROCESS structure that is the handle for a particular
  3833.    workstation/SQL Server process. It contains all the information that
  3834.    DB-LIBRARY uses to manage communications and data between the workstation
  3835.    and SQL Server.
  3836.  
  3837.  
  3838.  Returns
  3839.  
  3840.  The number of the current row. The first row returned from SQL Server is
  3841.  number 1.
  3842.  
  3843.  
  3844.  See Also
  3845.  
  3846.  dbclrbuf, DBFIRSTROW, dbgetrow, DBLASTROW, dbnextrow, dbresults, dbsetopt,
  3847.  Appendix B
  3848.  
  3849.  
  3850.  dbdata
  3851.  ────────────────────────────────────────────────────────────────────────────
  3852.  
  3853.  Function
  3854.  
  3855.  Returns a pointer to the data for a result column.
  3856.  
  3857.  
  3858.  Syntax
  3859.  
  3860.    BYTE *dbdata(dbproc, column)
  3861.  
  3862.     DBPROCESS *dbproc;
  3863.     int   column;
  3864.  
  3865.  
  3866.  Comments
  3867.  
  3868.  This function returns a pointer to the data for a particular column. The
  3869.  data is not null-terminated. You can use dbdatlen to get the length of the
  3870.  data.
  3871.  
  3872.  The dbbind function automatically binds data to your program variables. It
  3873.  is sometimes easier to use than dbdata, but it makes a copy of the data.
  3874.  
  3875.  The following program fragment uses dbdata:
  3876.  
  3877.    DBPROCESS *dbproc;
  3878.     DBINT  row_number = 0;
  3879.     DBINT  object_id;
  3880.  
  3881.     /* Put the command into the command buffer. */
  3882.     dbcmd(dbproc, "select id from sysobjects");
  3883.  
  3884.     /* Send the command to SQL Server and begin execution. */
  3885.     dbsqlexec(dbproc);
  3886.  
  3887.     /* Process the command results. */
  3888.     dbresults(dbproc);
  3889.  
  3890.     /* Examine the data in each row. */
  3891.     while (dbnextrow(dbproc) != NO_MORE_ROWS)
  3892.     {
  3893.      row_number++;
  3894.      object_id = *((DBINT *)dbdata(dbproc, 1));
  3895.      printf("row %ld, object id is %ld.\n", row_number, object_id);
  3896.     }
  3897.  
  3898.  
  3899.  Parameters
  3900.  
  3901.  dbproc
  3902.    The DBPROCESS structure that is the handle for a particular
  3903.    workstation/SQL Server process. It contains all the information that
  3904.    DB-LIBRARY uses to manage communications and data between the workstation
  3905.    and SQL Server.
  3906.  
  3907.  column
  3908.    The number of the column. The first column is number 1.
  3909.  
  3910.  
  3911.  Returns
  3912.  
  3913.  A BYTE pointer to the data for the column. A NULL BYTE pointer is returned
  3914.  if there is no such column or if the data has a null value. To make sure
  3915.  that the data is really a null value, check for a return of 0 from dbdatlen.
  3916.  
  3917.  
  3918.  
  3919.  See Also
  3920.  
  3921.  dbbind, dbcollen, dbcolname, dbcoltype, dbdatlen, dbnumcols
  3922.  
  3923.  
  3924.  dbdataready
  3925.  ────────────────────────────────────────────────────────────────────────────
  3926.  
  3927.  Function
  3928.  
  3929.  Determines whether database command processing has completed.
  3930.  
  3931.  
  3932.  Syntax
  3933.  
  3934.    BOOL dbdataready(dbproc)
  3935.  
  3936.     DBPROCESS *dbproc;
  3937.  
  3938.  
  3939.  Comments
  3940.  
  3941.  This function allows an application to continue processing while SQL Server
  3942.  is actually performing the database operation.
  3943.  
  3944.  The dbdataready function is ordinarily used after a call to dbsqlsend and
  3945.  before a call to dbsqlok. After dbsqlsend, SQL Server begins executing the
  3946.  commands in the command buffer. When dbsqlok is called, DB-LIBRARY waits for
  3947.  SQL Server processing to be completed before returning control to the
  3948.  application program.
  3949.  
  3950.  The dbdataready function provides a way to determine when command processing
  3951.  has been completed. It should be called repeatedly until it returns a
  3952.  nonzero value. At that point, the application can call dbsqlok.
  3953.  
  3954.  ────────────────────────────────────────────────────────────────────────────
  3955.  NOTE
  3956.  
  3957.  It is possible for dbdataready to return FALSE forever if another process
  3958.  has a conflicting lock or if the connection is broken. It is the
  3959.  responsibility of the calling program to provide a time-out mechanism.
  3960.  ────────────────────────────────────────────────────────────────────────────
  3961.  
  3962.  
  3963.  Parameters
  3964.  
  3965.  dbproc
  3966.    The DBPROCESS structure that is the handle for a particular
  3967.    workstation/SQL Server process. It contains all the information that
  3968.    DB-LIBRARY uses to manage communications and data between the workstation
  3969.    and SQL Server.
  3970.  
  3971.  
  3972.  Returns
  3973.  
  3974.  TRUE if data is available to be read; FALSE otherwise.
  3975.  
  3976.  
  3977.  See Also
  3978.  
  3979.  dbresults, dbsqlok, dbsqlsend
  3980.  
  3981.  
  3982.  dbdatlen
  3983.  ────────────────────────────────────────────────────────────────────────────
  3984.  
  3985.  Function
  3986.  
  3987.  Returns the actual length, in bytes, of the data for a column.
  3988.  
  3989.  
  3990.  Syntax
  3991.  
  3992.    DBINT dbdatlen(dbproc, column)
  3993.  
  3994.     DBPROCESS *dbproc;
  3995.     int   column;
  3996.  
  3997.  
  3998.  Comments
  3999.  
  4000.  This function returns the actual length, in bytes, of the data for a
  4001.  particular column. The maximum possible length for the data can be
  4002.  determined with the dbcollen function. The data itself is available by
  4003.  calling dbdata. The following program fragment uses dbdatlen:
  4004.  
  4005.    DBPROCESS *dbproc;
  4006.     DBINT  row_number = 0;
  4007.     DBINT  data_length;
  4008.  
  4009.     /* Put the command into the command buffer. */
  4010.     dbcmd(dbproc, "select name from sysobjects");
  4011.  
  4012.     /* Send the command to SQL Server and begin execution. */
  4013.     dbsqlexec(dbproc);
  4014.  
  4015.     /* Process the command results. */
  4016.     dbresults(dbproc);
  4017.  
  4018.     /* Examine the data lengths of each row. */
  4019.     while (dbnextrow(dbproc) != NO_MORE_ROWS)
  4020.     {
  4021.      row_number++;
  4022.      data_length = dbdatlen(dbproc, 1);
  4023.      printf("row %ld, data length is %ld.\n", row_number, data_length);
  4024.     }
  4025.  
  4026.  
  4027.  Parameters
  4028.  
  4029.  dbproc
  4030.    The DBPROCESS structure that is the handle for a particular
  4031.    workstation/SQL Server process. It contains all the information that
  4032.    DB-LIBRARY uses to manage communications and data between the workstation
  4033.    and SQL Server.
  4034.  
  4035.  column
  4036.    The number of the column. The first column is number 1.
  4037.  
  4038.  
  4039.  Returns
  4040.  
  4041.  The actual length of the data for the particular column. If the data has a
  4042.  null value, 0 is returned. If the column number is not in range, -1 is
  4043.  returned.
  4044.  
  4045.  
  4046.  See Also
  4047.  
  4048.  dbcollen, dbcolname, dbcoltype, dbdata, dbnumcols
  4049.  
  4050.  
  4051.  DBDEAD
  4052.  ────────────────────────────────────────────────────────────────────────────
  4053.  
  4054.  Function
  4055.  
  4056.  Determines whether a particular DBPROCESS is dead.
  4057.  
  4058.  
  4059.  Syntax
  4060.  
  4061.    DBBOOL DBDEAD(dbproc)
  4062.  
  4063.     DBPROCESS *dbproc;
  4064.  
  4065.  
  4066.  Comments
  4067.  
  4068.  This macro indicates whether the specified DBPROCESS is dead. It is
  4069.  particularly useful in user-supplied error handlers.
  4070.  
  4071.  If a DBPROCESS is dead, then almost every DB-LIBRARY function that receives
  4072.  it as a parameter immediately fails, calling the user-supplied error
  4073.  handler.
  4074.  
  4075.  
  4076.  Parameters
  4077.  
  4078.  dbproc
  4079.    The DBPROCESS structure that is the handle for a particular
  4080.    workstation/SQL Server process. It contains all the information that
  4081.    DB-LIBRARY uses to manage communications and data between the workstation
  4082.    and SQL Server.
  4083.  
  4084.  
  4085.  Returns
  4086.  
  4087.  TRUE or FALSE.
  4088.  
  4089.  
  4090.  See Also
  4091.  
  4092.  dberrhandle, Appendix D
  4093.  
  4094.  
  4095.  dberrhandle
  4096.  ────────────────────────────────────────────────────────────────────────────
  4097.  
  4098.  Function
  4099.  
  4100.  Supplies a user function to handle DB-LIBRARY errors.
  4101.  
  4102.  
  4103.  Syntax
  4104.  
  4105.    int (*dberrhandle(handler)) ()
  4106.  
  4107.     int (*handler) ();
  4108.  
  4109.  
  4110.  Comments
  4111.  
  4112.  This function installs an error-handling function that you supply. When a
  4113.  DB-LIBRARY error occurs, DB-LIBRARY immediately calls this error handler.
  4114.  You must install an error handler to handle DB-LIBRARY errors properly.
  4115.  
  4116.  Since the error handler is a call-back function, special consideration is
  4117.  required when compiling these functions under Windows or MS OS/2. For more
  4118.  information, see Appendix E, "Building Applications." The user-supplied
  4119.  error handler completely determines the response of DB-LIBRARY to any error
  4120.  that occurs. It must tell DB-LIBRARY whether to
  4121.  
  4122.  
  4123.    ■   Abort the program
  4124.  
  4125.    ■   Return an error code
  4126.  
  4127.    ■   Keep trying (in the case of a timeout error)
  4128.  
  4129.  
  4130.  If the user does not supply an error handler (or passes a NULL pointer to
  4131.  dberrhandle), DB-LIBRARY exhibits its default error-handling behavior: It
  4132.  returns FAIL from the DB-LIBRARY function that caused the error; program
  4133.  execution continues.
  4134.  
  4135.  
  4136.  Parameters
  4137.  
  4138.  handler
  4139.    A pointer to the user function that is called whenever DB-LIBRARY
  4140.    determines that an error has occurred. DB-LIBRARY calls this function with
  4141.    six parameters:
  4142.  
  4143.      dbproc
  4144.        The affected DBPROCESS. If there is no DBPROCESS associated with this
  4145.        error, this parameter is NULL.
  4146.  
  4147.      severity
  4148.        The severity of the error (datatype int). Error severities are defined
  4149.        in sqlfront.h.
  4150.  
  4151.      dberr
  4152.        The identifying number of the error (datatype int). Error numbers are
  4153.        defined in sqlfront.h.
  4154.  
  4155.      oserr
  4156.        The operating-system-specific error number that describes the cause of
  4157.        the error (datatype int). If there is no relevant operating system
  4158.        error, the value of this parameter is DBNOERR.
  4159.  
  4160.      dberrstr
  4161.        A printable description of dberr (datatype char *).
  4162.  
  4163.      oserrstr
  4164.        A printable description of oserr (datatype char *).
  4165.  
  4166.  The error handler must return one of the following three values, directing
  4167.  DB-LIBRARY to perform particular actions:
  4168.  
  4169. ╓┌─────────────────────────────────┌─────────────────────────────────────────
  4170.  Action                            Value
  4171.  ────────────────────────────────────────────────────────────────────────────
  4172.  INT_EXIT                          Prints an error message and aborts the
  4173.                                    program. DB-LIBRARY also returns an error
  4174.                                    to the operating system. Under Windows,
  4175.                                    this value is considered an error and is
  4176.                                    treated as an INT_CANCEL.
  4177.  
  4178.  INT_CANCEL                        Returns FAIL from the DB-LIBRARY function
  4179.                                    that caused the error.
  4180.  
  4181.  Action                            Value
  4182.  ────────────────────────────────────────────────────────────────────────────
  4183. 
  4184.  INT_CONTINUE                      Continues to wait for one additional
  4185.                                    timeout period. At the end of that period,
  4186.                                    calls the error handler again. This return
  4187.                                    value is meaningful only for timeout
  4188.                                    errors (SQLETIME). In any other case, this
  4189.                                    value is considered an error and is
  4190.                                    treated as an INT_CANCEL.
  4191.  
  4192.  ────────────────────────────────────────────────────────────────────────────
  4193.  
  4194.  
  4195.  
  4196.  If the error handler returns any value besides these three, the program
  4197.  continues. The following example shows a typical error-handling function:
  4198.  
  4199.    #include <sqlfront.h>
  4200.     #include <sqldb.h>
  4201.  
  4202.     int err_handler(dbproc, severity, dberr, oserr, dberrstr, oserrstr)
  4203.     DBPROCESS *dbproc;
  4204.     int   severity;
  4205.     int   dberr;
  4206.     int   oserr;
  4207.     char  *dberrstr;
  4208.     char  *oserrstr;
  4209.  
  4210.    {
  4211.      if ((dbproc == NULL) || (DBDEAD(dbproc)))
  4212.       return(INT_EXIT);
  4213.      else
  4214.      {
  4215.       printf("DB-LIBRARY error:\n\t%s\n", dberrstr);
  4216.  
  4217.       if (oserr != DBNOERR)
  4218.        printf("Operating-system error:\n\t%s\n", oserrstr);
  4219.  
  4220.       return(INT_CANCEL);
  4221.      }
  4222.     }
  4223.  
  4224.  ────────────────────────────────────────────────────────────────────────────
  4225.  NOTE
  4226.  
  4227.  Do not call any DB-LIBRARY functions from within the error handler, as this
  4228.  may result in infinite recursive calls to the error handler. You may,
  4229.  however, call DB-LIBRARY macros; they have been coded to avoid recursion.
  4230.  ────────────────────────────────────────────────────────────────────────────
  4231.  
  4232.  
  4233.  Returns
  4234.  
  4235.  A pointer to the previously installed error handler. This can be NULL.
  4236.  
  4237.  
  4238.  See Also
  4239.  
  4240.  dbmsghandle, Appendix D
  4241.  
  4242.  
  4243.  dbexit
  4244.  ────────────────────────────────────────────────────────────────────────────
  4245.  
  4246.  Function
  4247.  
  4248.  Closes and frees all DBPROCESS structures created as a result of your
  4249.  program.
  4250.  
  4251.  
  4252.  Syntax
  4253.  
  4254.    void dbexit(void)
  4255.  
  4256.  
  4257.  Comments
  4258.  
  4259.  The dbexit function calls dbclose repeatedly for all allocated DBPROCESS
  4260.  structures. The dbclose function cleans up any activity associated with a
  4261.  DBPROCESS structure and frees the space.
  4262.  
  4263.  You can use dbclose directly to close just a single DBPROCESS structure.
  4264.  
  4265.  
  4266.  Returns
  4267.  
  4268.  None.
  4269.  
  4270.  
  4271.  See Also
  4272.  
  4273.  dbclose, dbopen
  4274.  
  4275.  
  4276.  dbfcmd
  4277.  ────────────────────────────────────────────────────────────────────────────
  4278.  
  4279.  Function
  4280.  
  4281.  Adds text to the DBPROCESS command buffer using C run-time library
  4282.  sprintf-type formatting.
  4283.  
  4284.  
  4285.  Syntax
  4286.  
  4287.    RETCODE dbfcmd(dbproc, cmdstring, params...)
  4288.  
  4289.     DBPROCESS *dbproc;
  4290.     char  *cmdstring;
  4291.     long  params...;
  4292.  
  4293.  
  4294.  Comments
  4295.  
  4296.  This function adds text to the command buffer in the DBPROCESS structure.
  4297.  The dbfcmd function works just like the C language Standard I/O library
  4298.  sprintf function.
  4299.  
  4300.  To include a percent character (%) in the command string, you must encode it
  4301.  as two percent characters (%%). This is because dbfcmd calls sprintf, which
  4302.  treats the % character as a format specification. In addition, don't use
  4303.  variables containing strings with apostrophes or single quotation marks. If
  4304.  you don't need any of the formatting capability of sprintf, you can use
  4305.  dbcmd.
  4306.  
  4307.  The dbfcmd function manages the space allocation for the command buffer. It
  4308.  adds to the existing command buffer; it doesn't delete or overwrite the
  4309.  current contents except after the buffer has been sent to SQL Server. (See
  4310.  the following comment.) The user can call dbfcmd repeatedly. Note that
  4311.  sequential calls are concatenated together: it is the program's
  4312.  responsibility to ensure that any necessary blanks appear between the end of
  4313.  one line and the beginning of the next.
  4314.  
  4315.  After a call to dbsqlexec or dbsqlsend, the first call to either dbcmd or
  4316.  dbfcmd automatically clears the command buffer before the new text is
  4317.  entered. If this situation is undesirable, set the DBNOAUTOFREE option. When
  4318.  DBNOAUTOFREE is set, the command buffer is cleared only by a call to
  4319.  dbfreebuf.
  4320.  
  4321.  The following program fragment uses dbfcmd to build up a multiple-line SQL
  4322.  command:
  4323.  
  4324.    char  *column_name;
  4325.     DBPROCESS *dbproc;
  4326.     int   low_id;
  4327.     char  *object_type;
  4328.     char  *tablename;
  4329.  
  4330.     dbfcmd(dbproc, "Select %s from %s", column_name, tablename);
  4331.     dbfcmd(dbproc, " where id > %d", low_id);
  4332.     dbfcmd(dbproc, " and type='%s'", object_type);
  4333.  
  4334.  Do not pass dbfcmd null pointers contained in variables.
  4335.  
  4336.  
  4337.  Parameters
  4338.  
  4339.  dbproc
  4340.    The DBPROCESS structure that is the handle for a particular
  4341.    workstation/SQL Server process. It contains all the information that
  4342.    DB-LIBRARY uses to manage communications and data between the workstation
  4343.    and SQL Server.
  4344.  
  4345.  cmdstring
  4346.    A format string of the form used by the sprintf function.
  4347.  
  4348.  params...
  4349.    Optional parameters to dbfcmd. The number of parameters required depends
  4350.    on the number indicated in the cmdstring parameter. The parameters are
  4351.    passed directly to the sprintf function.
  4352.  
  4353.  
  4354.  Returns
  4355.  
  4356.  SUCCEED or FAIL.
  4357.  
  4358.  
  4359.  Limitations
  4360.  
  4361.  This function allocates its working buffer dynamically. The size it picks to
  4362.  allocate space is the maximum of a defined constant (1024) and the string
  4363.  length of cmdstring * 2. If the arguments are very big in comparison to the
  4364.  size of cmdstring, it may not be possible to allocate enough space.
  4365.  
  4366.  
  4367.  See Also
  4368.  
  4369.  dbcmd, dbfreebuf, Appendix B
  4370.  
  4371.  
  4372.  DBFIRSTROW
  4373.  ────────────────────────────────────────────────────────────────────────────
  4374.  
  4375.  Function
  4376.  
  4377.  Returns the number of the first row in the row buffer.
  4378.  
  4379.  
  4380.  Syntax
  4381.  
  4382.    DBINT DBFIRSTROW(dbproc)
  4383.  
  4384.     DBPROCESS *dbproc;
  4385.  
  4386.  
  4387.  Comments
  4388.  
  4389.  This macro returns the number of the first row in the row buffer. If you
  4390.  aren't buffering rows, DBFIRSTROW, DBCURROW, and DBLASTROW always have the
  4391.  same value: the current row number in the current batch. If you enable
  4392.  buffering by setting the DBBUFFER option, DBFIRSTROW returns the number of
  4393.  the row that is the first row in the row buffer.
  4394.  
  4395.  Note that the first row returned from SQL Server (whose value is 1) is not
  4396.  necessarily the first row sitting in the row buffer. The rows in the row
  4397.  buffer are dependent on manipulation by the application program.
  4398.  
  4399.  
  4400.  Parameters
  4401.  
  4402.  dbproc
  4403.    The DBPROCESS structure that is the handle for a particular
  4404.    workstation/SQL Server process. It contains all the information that
  4405.    DB-LIBRARY uses to manage communications and data between the workstation
  4406.    and SQL Server.
  4407.  
  4408.  
  4409.  Returns
  4410.  
  4411.  The number of the first row in the row buffer. The first row returned from
  4412.  SQL Server is number 1.
  4413.  
  4414.  
  4415.  See Also
  4416.  
  4417.  dbclrbuf, DBCURROW, dbgetrow, DBLASTROW, dbnextrow, dbsetopt, Appendix B
  4418.  
  4419.  
  4420.  dbfreebuf
  4421.  ────────────────────────────────────────────────────────────────────────────
  4422.  
  4423.  Function
  4424.  
  4425.  Sets the command buffer in a DBPROCESS structure to NULL.
  4426.  
  4427.  
  4428.  Syntax
  4429.  
  4430.    void dbfreebuf(dbproc)
  4431.  
  4432.     DBPROCESS *dbproc;
  4433.  
  4434.  
  4435.  Comments
  4436.  
  4437.  This function frees any space allocated to the command buffer of the
  4438.  DBPROCESS structure. The command buffer is then set to NULL. Commands for
  4439.  SQL Server are added to the command buffer with the dbcmd or dbfcmd
  4440.  function.
  4441.  
  4442.  After a call to dbsqlexec or dbsqlsend, the first call to either dbcmd or
  4443.  dbfcmd automatically calls dbfreebuf to clear the command buffer before the
  4444.  new text is entered. If this situation is undesirable, set the DBNOAUTOFREE
  4445.  option. When DBNOAUTOFREE is set, the command buffer is cleared only by a
  4446.  call to dbfreebuf.
  4447.  
  4448.  The contents of the command buffer can be accessed through the dbgetchar,
  4449.  dbstrlen, and dbstrcpy functions.
  4450.  
  4451.  
  4452.  Parameters
  4453.  
  4454.  dbproc
  4455.    The DBPROCESS structure that is the handle for a particular
  4456.    workstation/SQL Server process. It contains all the information that
  4457.    DB-LIBRARY uses to manage communications and data between the workstation
  4458.    and SQL Server.
  4459.  
  4460.  
  4461.  Returns
  4462.  
  4463.  None.
  4464.  
  4465.  
  4466.  See Also
  4467.  
  4468.  dbcmd, dbfcmd, dbgetchar, dbsqlexec, dbsqlsend, dbstrcpy, dbstrlen, Appendix
  4469.  B
  4470.  
  4471.  
  4472.  dbfreelogin
  4473.  ────────────────────────────────────────────────────────────────────────────
  4474.  
  4475.  Function
  4476.  
  4477.  Frees a login record.
  4478.  
  4479.  
  4480.  Syntax
  4481.  
  4482.    void dbfreelogin(login)
  4483.  
  4484.     LOGINREC *login;
  4485.  
  4486.  
  4487.  Comments
  4488.  
  4489.  This function frees up the memory allocated by the dblogin function. It can
  4490.  be called immediately after a call to dbopen; however, you can use the same
  4491.  login record for multiple calls to dbopen. Call dbfreelogin when you are
  4492.  completely finished with the login record.
  4493.  
  4494.  The following program fragment uses dbfreelogin:
  4495.  
  4496.    DBPROCESS *dbproc;
  4497.     LOGINREC *loginrec;
  4498.  
  4499.     loginrec = dblogin();
  4500.     DBSETLUSER(login, "user");
  4501.     DBSETLPWD(loginrec, "my_password");
  4502.     DBSETLAPP(loginrec, "my_program");
  4503.     dbproc = dbopen(loginrec, "my_server");
  4504.     dbfreelogin (loginrec);
  4505.  
  4506.  
  4507.  Parameters
  4508.  
  4509.  login
  4510.    The pointer to a LOGINREC structure returned from the dblogin function.
  4511.  
  4512.  
  4513.  Returns
  4514.  
  4515.  None.
  4516.  
  4517.  
  4518.  See Also
  4519.  
  4520.  dblogin, dbopen
  4521.  
  4522.  
  4523.  dbfreequal
  4524.  ────────────────────────────────────────────────────────────────────────────
  4525.  
  4526.  Function
  4527.  
  4528.  Frees memory allocated by the dbqual function.
  4529.  
  4530.  
  4531.  Syntax
  4532.  
  4533.    void dbfreequal(ptr)
  4534.  
  4535.     char *ptr;
  4536.  
  4537.  
  4538.  Comments
  4539.  
  4540.  Whenever a successful call to dbqual has been issued, a buffer is
  4541.  dynamically allocated by dbqual. The buffer remains allocated to the
  4542.  application. When the application is finished using the buffer, it should be
  4543.  freed by invoking the dbfreequal function.
  4544.  
  4545.  
  4546.  Parameters
  4547.  
  4548.  ptr
  4549.    A pointer to the memory allocated by the dbqual function.
  4550.  
  4551.  
  4552.  Returns
  4553.  
  4554.  None.
  4555.  
  4556.  
  4557.  See Also
  4558.  
  4559.  dbqual
  4560.  
  4561.  
  4562.  dbgetchar
  4563.  ────────────────────────────────────────────────────────────────────────────
  4564.  
  4565.  Function
  4566.  
  4567.  Returns a pointer to a character in the command buffer.
  4568.  
  4569.  
  4570.  Syntax
  4571.  
  4572.    char *dbgetchar(dbproc, n)
  4573.  
  4574.     DBPROCESS *dbproc;
  4575.     int   n;
  4576.  
  4577.  
  4578.  Comments
  4579.  
  4580.  The dbgetchar function can be used to find a particular character in the
  4581.  command buffer. It returns a pointer to the nth character in the command
  4582.  buffer.
  4583.  
  4584.  Internally, the command buffer is a linked list of non-null-terminated text
  4585.  strings. Parts of the command buffer can be located and copied using the
  4586.  dbgetchar, dbstrcpy, and dbstrlen functions.
  4587.  
  4588.  Since the command buffer is not just one large text string, but rather a
  4589.  linked list of text strings, you must use dbgetchar to index through the
  4590.  buffer. If you just get a pointer using dbgetchar and then increment it
  4591.  yourself, it will probably fall off the end of a string (and cause a
  4592.  segmentation fault under MS OS/2).
  4593.  
  4594.  
  4595.  Parameters
  4596.  
  4597.  dbproc
  4598.    The DBPROCESS structure that is the handle for a particular
  4599.    workstation/SQL Server process. It contains all the information that
  4600.    DB-LIBRARY uses to manage communications and data between the workstation
  4601.    and SQL Server.
  4602.  
  4603.  n
  4604.    The character to find in the command buffer. The first character is the
  4605.    0th character.
  4606.  
  4607.  
  4608.  Returns
  4609.  
  4610.  A pointer to the nth character in the command buffer. If n is not in range,
  4611.  NULL is returned.
  4612.  
  4613.  
  4614.  See Also
  4615.  
  4616.  dbcmd, dbfcmd, dbfreebuf, dbstrcpy, dbstrlen
  4617.  
  4618.  
  4619.  dbgetmaxprocs
  4620.  ────────────────────────────────────────────────────────────────────────────
  4621.  
  4622.  Function
  4623.  
  4624.  Determines the current maximum number of simultaneously open DBPROCESS
  4625.  structures.
  4626.  
  4627.  
  4628.  Syntax
  4629.  
  4630.    int dbgetmaxprocs()
  4631.  
  4632.  
  4633.  Comments
  4634.  
  4635.  A DB-LIBRARY program has a maximum number of simultaneously open DBPROCESS
  4636.  structures. By default, this number is 25. The application program can
  4637.  change this limit by calling dbsetmaxprocs.
  4638.  
  4639.  
  4640.  Returns
  4641.  
  4642.  An integer representing the current limit on the number of simultaneously
  4643.  open DBPROCESS structures.
  4644.  
  4645.  
  4646.  See Also
  4647.  
  4648.  dbopen, dbsetmaxprocs
  4649.  
  4650.  
  4651.  dbgetoff
  4652.  ────────────────────────────────────────────────────────────────────────────
  4653.  
  4654.  Function
  4655.  
  4656.  Checks for the existence of TRANSACT-SQL statements in the command buffer.
  4657.  
  4658.  
  4659.  Syntax
  4660.  
  4661.    int dbgetoff(dbproc, offtype, startfrom)
  4662.  
  4663.     DBPROCESS  *dbproc;
  4664.     DBUSMALLINT  offtype;
  4665.     int    startfrom;
  4666.  
  4667.  
  4668.  Comments
  4669.  
  4670.  If the DBOFFSET option has been set (see Appendix B, "DB-LIBRARY Options"),
  4671.  this function can check for the location of certain TRANSACT-SQL statements
  4672.  in the command buffer. As a simple example, assume that the program doesn't
  4673.  know the contents of the command buffer but needs to know where the SQL
  4674.  keyword SELECT appears:
  4675.  
  4676.    int  select_offset[10];
  4677.     int  last_offset;
  4678.     int  i;
  4679.  
  4680.     /* Set the offset option. */
  4681.     dbsetopt(dbproc, DBOFFSET, "select");
  4682.  
  4683.     /* Assume the command buffer contains the following SELECTs: */
  4684.     dbcmd(dbproc, "select x = 100 select y = 5");
  4685.  
  4686.     /* Send the query to SQL Server. */
  4687.     dbsqlexec(dbproc);
  4688.  
  4689.     /* Get all the offsets to the SELECT keyword. */
  4690.     for (i = 0, last_offset = 0; last_offset != -1; i++)
  4691.      if ((last_offset = dbgetoff(dbproc, OFF_SELECT, last_offset))!= -1)
  4692.       select_offset[i] = last_offset++;
  4693.  
  4694.  In this example, select_offset[0] = 0 and select_offset[1] = 15.
  4695.  
  4696.  
  4697.  Parameters
  4698.  
  4699.  dbproc
  4700.    The DBPROCESS structure that is the handle for a particular
  4701.    workstation/SQL Server process. It contains all the information that
  4702.    DB-LIBRARY uses to manage communications and data between the workstation
  4703.    and SQL Server.
  4704.  
  4705.  offtype
  4706.    The type of offset you want to find. The types (defined in the header file
  4707.    sqlfront.h) are:
  4708.  
  4709.    OFF_SELECT OFF_FROM OFF_ORDER OFF_COMPUTE OFF_TABLE OFF_PROCEDURE
  4710.    OFF_STATEMENT OFF_PARAM OFF_EXEC
  4711.  
  4712.    For details, see Appendix B, "DB-LIBRARY Options."
  4713.  
  4714.  startfrom
  4715.    The point in the buffer from which to start looking. The command buffer
  4716.    begins at 0.
  4717.  
  4718.  
  4719.  Returns
  4720.  
  4721.  The character offset into the command buffer for the specified offset. If
  4722.  the offset is not found, -1 is returned.
  4723.  
  4724.  
  4725.  See Also
  4726.  
  4727.  dbcmd, dbgetchar, dbsetopt, dbstrcpy, dbstrlen, Appendix B
  4728.  
  4729.  
  4730.  dbgetrow
  4731.  ────────────────────────────────────────────────────────────────────────────
  4732.  
  4733.  Function
  4734.  
  4735.  Reads the specified row in the row buffer.
  4736.  
  4737.  
  4738.  Syntax
  4739.  
  4740.    STATUS dbgetrow(dbproc, row)
  4741.  
  4742.     DBPROCESS *dbproc;
  4743.     DBINT  row;
  4744.  
  4745.  
  4746.  Comments
  4747.  
  4748.  The dbgetrow function sets the current row to a specific row and reads it.
  4749.  This function only works if the DBBUFFER option is on. Any specified binding
  4750.  of row data to program variables takes effect.
  4751.  
  4752.  When buffering is not turned on, normally each row is processed, in turn, by
  4753.  repeatedly calling dbnextrow until it returns NO_MORE_ROWS. When buffering
  4754.  is turned on, dbgetrow allows the user to jump to any row that has already
  4755.  been read using dbnextrow and is still in the row buffer. Calls to dbnextrow
  4756.  after a dbgetrow call return rows in order, following the row read by
  4757.  dbgetrow.
  4758.  
  4759.  
  4760.  Parameters
  4761.  
  4762.  dbproc
  4763.    The DBPROCESS structure that is the handle for a particular
  4764.    workstation/SQL Server process. It contains all the information that
  4765.    DB-LIBRARY uses to manage communications and data between the workstation
  4766.    and SQL Server.
  4767.  
  4768.  row
  4769.    The number of the row to read. The first row returned from SQL Server is
  4770.    number 1.
  4771.  
  4772.  
  4773.  Returns
  4774.  
  4775.  One of four different types of values:
  4776.  
  4777.  
  4778.    ■   If the current row is a regular row, REG_ROW is returned.
  4779.  
  4780.    ■   If the current row is a compute row, the computeid of the row is
  4781.        returned. (See "dbaltbind" for information on the computeid.)
  4782.  
  4783.    ■   If the row is not in the row buffer, NO_MORE_ROWS is returned.
  4784.  
  4785.    ■   If the function was unsuccessful, FAIL is returned.
  4786.  
  4787.  
  4788.  
  4789.  See Also
  4790.  
  4791.  dbaltbind, dbbind, dbclrbuf, dbnextrow, Appendix B
  4792.  
  4793.  
  4794.  DBGETTIME
  4795.  ────────────────────────────────────────────────────────────────────────────
  4796.  
  4797.  Function
  4798.  
  4799.  Returns the number of seconds that DB-LIBRARY will wait for an SQL Server
  4800.  response to a TRANSACT-SQL statement.
  4801.  
  4802.  
  4803.  Syntax
  4804.  
  4805.    int DBGETTIME()
  4806.  
  4807.  
  4808.  Comments
  4809.  
  4810.  This macro returns the length of time in seconds that DB-LIBRARY will wait
  4811.  for an SQL Server response during calls to dbsqlexec, dbsqlok, dbresults,
  4812.  and dbnextrow. The default timeout value is 0, which represents an infinite
  4813.  timeout period.
  4814.  
  4815.  The program can call dbsettime to change the timeout value.
  4816.  
  4817.  
  4818.  Returns
  4819.  
  4820.  The timeout value─the number of seconds that DB-LIBRARY waits for an SQL
  4821.  Server response before timing out. A timeout value of 0 represents an
  4822.  infinite timeout period.
  4823.  
  4824.  
  4825.  See Also
  4826.  
  4827.  dbnextrow, dbresults, dbsettime, dbsqlexec, dbsqlok
  4828.  
  4829.  
  4830.  DBISAVAIL
  4831.  ────────────────────────────────────────────────────────────────────────────
  4832.  
  4833.  Function
  4834.  
  4835.  Determines whether a DBPROCESS is available for general use.
  4836.  
  4837.  
  4838.  Syntax
  4839.  
  4840.    DBBOOL DBISAVAIL(dbproc)
  4841.  
  4842.     DBPROCESS *dbproc;
  4843.  
  4844.  
  4845.  Comments
  4846.  
  4847.  This macro indicates whether the specified DBPROCESS is available for
  4848.  general use. When a DBPROCESS is first opened, it is marked as being
  4849.  available until some use is made of it. Many DB-LIBRARY functions
  4850.  automatically set the DBPROCESS to "not available," but only dbsetavail
  4851.  resets it to "available." This facility is useful when several parts of a
  4852.  program are attempting to share a single DBPROCESS.
  4853.  
  4854.  
  4855.  Parameters
  4856.  
  4857.  dbproc
  4858.    The DBPROCESS structure that is the handle for a particular
  4859.    workstation/SQL Server process. It contains all the information that
  4860.    DB-LIBRARY uses to manage communications and data between the workstation
  4861.    and SQL Server.
  4862.  
  4863.  
  4864.  Returns
  4865.  
  4866.  TRUE if the DBPROCESS is available for general use; FALSE otherwise.
  4867.  
  4868.  
  4869.  See Also
  4870.  
  4871.  dbsetavail
  4872.  
  4873.  
  4874.  dbinit
  4875.  ────────────────────────────────────────────────────────────────────────────
  4876.  
  4877.  Function
  4878.  
  4879.  Initializes DB-LIBRARY.
  4880.  
  4881.  
  4882.  Syntax
  4883.  
  4884.    CHAR *dbinit(void)
  4885.  
  4886.  
  4887.  Comments
  4888.  
  4889.  This function behaves differently under each supported operating system.
  4890.  Under Windows, you must call dbinit before calling any other DB-LIBRARY
  4891.  functions.
  4892.  
  4893.  
  4894.    ■   Under MS OS/2, dbinit returns a pointer to the version string. Calling
  4895.        dbinit is optional.
  4896.  
  4897.    ■   Under Windows, dbinit causes DB-LIBRARY to "register" the calling
  4898.        application to prevent conflicts with other applications calling
  4899.        DB-LIBRARY concurrently. (See dbwinexit.) You must call dbinit under
  4900.        Windows.
  4901.  
  4902.    ■   Under MS-DOS(R), dbinit tests for the presence of the DB-LIBRARY
  4903.        communications TSR (Terminate-Stay-Resident) utility. If the function
  4904.        returns a NULL pointer (memory model dependent pointer type), the TSR
  4905.        is not loaded. A call to dbopen also checks for the presence of the
  4906.        TSR and returns a null DBPROCESS pointer if it is not loaded.
  4907.  
  4908.  
  4909.  
  4910.  Parameters
  4911.  
  4912.  None.
  4913.  
  4914.  
  4915.  Returns
  4916.  
  4917.  If initialization is successful, the function returns a pointer to a string
  4918.  containing the version number of the library. Otherwise, dbinit returns
  4919.  NULL.
  4920.  
  4921.  
  4922.  See Also
  4923.  
  4924.  dbopen, dbwinexit
  4925.  
  4926.  
  4927.  dbisopt
  4928.  ────────────────────────────────────────────────────────────────────────────
  4929.  
  4930.  Function
  4931.  
  4932.  Checks the status of an SQL Server or DB-LIBRARY option.
  4933.  
  4934.  
  4935.  Syntax
  4936.  
  4937.    DBBOOL dbisopt(dbproc, option, param)
  4938.  
  4939.     DBPROCESS *dbproc;
  4940.     int   option;
  4941.     char  *param;
  4942.  
  4943.  
  4944.  Comments
  4945.  
  4946.  This function checks the status of SQL Server and DB-LIBRARY options.
  4947.  Although SQL Server options can be set and cleared directly through SQL, the
  4948.  application should use dbsetopt and dbclropt to set and clear options. This
  4949.  provides a uniform interface for setting both SQL Server and DB-LIBRARY
  4950.  options. It also allows the application to use the dbisopt function to check
  4951.  the status of an option.
  4952.  
  4953.  For a list of each option and its default status, see Appendix B,
  4954.  "DB-LIBRARY Options."
  4955.  
  4956.  
  4957.  Parameters
  4958.  
  4959.  dbproc
  4960.    The DBPROCESS structure that is the handle for a particular
  4961.    workstation/SQL Server process. It contains all the information that
  4962.    DB-LIBRARY uses to manage communications and data between the workstation
  4963.    and SQL Server. Unlike the functions dbsetopt and dbclropt, dbproc cannot
  4964.    be NULL here.
  4965.  
  4966.  option
  4967.    The option to be checked.
  4968.  
  4969.  param
  4970.    Certain options take parameters. The DBOFFSET option, for example, takes
  4971.    as a parameter the SQL construct for which offsets are to be returned.
  4972.    Appendix B, "DB-LIBRARY Options," lists those options that take
  4973.    parameters. If an option does not take a parameter, param must be NULL. If
  4974.    the option you are checking takes a parameter but there can be only one
  4975.    instance of the option, dbisopt ignores the param parameter. For example,
  4976.    dbisopt ignores the value of param when checking the DBBUFFER option
  4977.    because row buffering can have only one setting at a time. On the other
  4978.    hand, the DBOFFSET option can have several settings, each with a different
  4979.    parameter. It can have been set twice─to look for offsets to SELECT
  4980.    statements and offsets to ORDER BY clauses. In that case, dbisopt needs
  4981.    the param parameter to determine whether to check the SELECT offset or the
  4982.    ORDER BY offset. The only other option for which dbisopt requires a param
  4983.    is DBSTAT.
  4984.  
  4985.  
  4986.  Returns
  4987.  
  4988.  TRUE or FALSE.
  4989.  
  4990.  
  4991.  See Also
  4992.  
  4993.  dbclropt, dbsetopt, Appendix B
  4994.  
  4995.  
  4996.  DBLASTROW
  4997.  ────────────────────────────────────────────────────────────────────────────
  4998.  
  4999.  Function
  5000.  
  5001.  Returns the number of the last row in the row buffer.
  5002.  
  5003.  
  5004.  Syntax
  5005.  
  5006.    DBINT DBLASTROW(dbproc)
  5007.  
  5008.     DBPROCESS *dbproc;
  5009.  
  5010.  
  5011.  Comments
  5012.  
  5013.  This macro returns the number of the last row in the row buffer. The first
  5014.  row returned from SQL Server is number 1. If you aren't buffering rows,
  5015.  DBFIRSTROW, DBCURROW, and DBLASTROW always have the same value. If you have
  5016.  enabled buffering by setting the DBBUFFER option, DBLASTROW returns the
  5017.  number of the row that is the last row in the row buffer, which may not be
  5018.  the last row available from the server.
  5019.  
  5020.  
  5021.  Parameters
  5022.  
  5023.  dbproc
  5024.    The DBPROCESS structure that is the handle for a particular
  5025.    workstation/SQL Server process. It contains all the information that
  5026.    DB-LIBRARY uses to manage communications and data between the workstation
  5027.    and SQL Server.
  5028.  
  5029.  
  5030.  Returns
  5031.  
  5032.  The number of the last row in the row buffer. The first row returned from
  5033.  SQL Server is number 1.
  5034.  
  5035.  
  5036.  See Also
  5037.  
  5038.  dbclrbuf, DBCURROW, DBFIRSTROW, dbgetrow, dbnextrow, dbsetopt, Appendix B
  5039.  
  5040.  
  5041.  DBLOCKLIB (Windows only)
  5042.  ────────────────────────────────────────────────────────────────────────────
  5043.  
  5044.  Function
  5045.  
  5046.  Locks DB-LIBRARY segments.
  5047.  
  5048.  
  5049.  Syntax
  5050.  
  5051.    DBLOCKLIB()
  5052.  
  5053.  
  5054.  Comments
  5055.  
  5056.  This macro applies only to Microsoft Windows application programs. It is not
  5057.  available in the MS-DOS or MS OS/2 DB-LIBRARY.
  5058.  
  5059.  This macro is necessary because segments in Windows libraries move around.
  5060.  If an application (or DB-LIBRARY function) is relying on a far pointer for
  5061.  later use, the segments must remain stable. For example, if a far pointer
  5062.  value is retrieved from the dbname function, DB-LIBRARY must remain locked
  5063.  until the pointer value is no longer used by the application.
  5064.  
  5065.  The DBLOCKLIB macro locks the DB-LIBRARY segments. It should be called prior
  5066.  to calling any DB-LIBRARY functions. The DBUNLOCKLIB macro should be called
  5067.  after returning from a DB-LIBRARY function and only after the application
  5068.  uses any pointer information returned from a function call. The DBLOCKLIB
  5069.  macro can be called once, then many DB-LIBRARY functions can be called, and
  5070.  then the DB-LIBRARY segments can be unlocked with the DBUNLOCKLIB macro.
  5071.  
  5072.  Note that DB-LIBRARY can be unlocked after a call to dbopen or dblogin
  5073.  because the value returned from dbopen or dblogin is a near pointer only
  5074.  used within DB-LIBRARY.
  5075.  
  5076.  The following program fragment calls DBLOCKLIB:
  5077.  
  5078.    DBPROCESS *dbproc;
  5079.     LOGINREC *login;
  5080.     char far *name;
  5081.  
  5082.     DBLOCKLIB();
  5083.     login = dblogin();
  5084.     DBSETLUSER(login, "user");
  5085.     DBSETLPWD(login, "my_password");
  5086.     DBSETLAPP(login, "my program");
  5087.     dbproc = dbopen(login, "my_server");
  5088.     DBUNLOCKLIB();
  5089.      .
  5090.      .
  5091.      .
  5092.  
  5093.    DBLOCKLIB();
  5094.     name = dbname(dbproc);
  5095.     /* use name */
  5096.      .
  5097.      .
  5098.      .
  5099.     /* name no longer required */
  5100.      .
  5101.      .
  5102.      .
  5103.     DBUNLOCKLIB();
  5104.      .
  5105.      .
  5106.      .
  5107.  
  5108.  
  5109.  Parameters
  5110.  
  5111.  None.
  5112.  
  5113.  
  5114.  Returns
  5115.  
  5116.  None.
  5117.  
  5118.  
  5119.  See Also
  5120.  
  5121.  dblogin, dbname, dbopen, DBUNLOCKLIB
  5122.  
  5123.  
  5124.  dblogin
  5125.  ────────────────────────────────────────────────────────────────────────────
  5126.  
  5127.  Function
  5128.  
  5129.  Allocates a login record for use in dbopen.
  5130.  
  5131.  
  5132.  Syntax
  5133.  
  5134.    LOGINREC *dblogin()
  5135.  
  5136.  
  5137.  Comments
  5138.  
  5139.  This function allocates a LOGINREC structure for use with dbopen.
  5140.  
  5141.  There are various functions available to supply components of the LOGINREC.
  5142.  The program can supply the workstation name, user name, user password, and
  5143.  application name. It is generally only necessary for the program to supply
  5144.  the user password (and even this can be eliminated if the password is a null
  5145.  value). All components in the LOGINREC are initially set to NULL.
  5146.  
  5147.  
  5148.  Returns
  5149.  
  5150.  A pointer to a LOGINREC structure. NULL is returned if the structure could
  5151.  not be allocated.
  5152.  
  5153.  
  5154.  See Also
  5155.  
  5156.  dbfreelogin, dbopen, DBSETLAPP, DBSETLHOST, DBSETLPWD, DBSETLUSER
  5157.  
  5158.  
  5159.  
  5160.  
  5161.  
  5162.  DBMORECMDS
  5163.  ────────────────────────────────────────────────────────────────────────────
  5164.  
  5165.  Function
  5166.  
  5167.  Indicates whether there are more commands to be processed.
  5168.  
  5169.  
  5170.  Syntax
  5171.  
  5172.    RETCODE DBMORECMDS(dbproc)
  5173.  
  5174.     DBPROCESS *dbproc;
  5175.  
  5176.  
  5177.  Comments
  5178.  
  5179.  This macro determines whether there are more results to process. It should
  5180.  be called after dbnextrow returns NO_MORE_ROWS. If you know that the current
  5181.  command is returning no rows, you can call DBMORECMDS after dbresults
  5182.  returns.
  5183.  
  5184.  You can get the same information by calling dbresults until it returns
  5185.  NO_MORE_RESULTS.
  5186.  
  5187.  
  5188.  Parameters
  5189.  
  5190.  dbproc
  5191.    The DBPROCESS structure that is the handle for a particular
  5192.    workstation/SQL Server process. It contains all the information that
  5193.    DB-LIBRARY uses to manage communications and data between the workstation
  5194.    and SQL Server.
  5195.  
  5196.  
  5197.  Returns
  5198.  
  5199.  SUCCEED or FAIL to indicate whether there are more results in the command
  5200.  batch.
  5201.  
  5202.  
  5203.  See Also
  5204.  
  5205.  DBCMDROW, dbnextrow, dbresults, DBROWS, DBROWTYPE
  5206.  
  5207.  
  5208.  dbmoretext
  5209.  ────────────────────────────────────────────────────────────────────────────
  5210.  
  5211.  Function
  5212.  
  5213.  Sends part of a text or image value to SQL Server.
  5214.  
  5215.  
  5216.  Syntax
  5217.  
  5218.    RETCODE dbmoretext(dbproc, size, text)
  5219.  
  5220.     DBPROCESS *dbproc;
  5221.     DBINT  size;
  5222.     BYTE  *text;
  5223.  
  5224.  
  5225.  Comments
  5226.  
  5227.  This function is used in conjunction with dbwritetext to send a large
  5228.  SQLTEXT or SQLIMAGE value to SQL Server in the form of a number of smaller
  5229.  chunks. This is particularly useful with operating systems unable to
  5230.  allocate extremely long data buffers. A text/image fragment cannot be longer
  5231.  than 64K bytes. DB-LIBRARY does not support huge pointers, only near (for
  5232.  medium model MS-DOS) and far (for large model MS-DOS, Windows, and MS OS/2.)
  5233.  
  5234.  
  5235.  The dbmoretext and dbwritetext functions are used in updates only to replace
  5236.  the TRANSACT-SQL UPDATE statement.
  5237.  
  5238.  See "dbwritetext" for an example of dbmoretext.
  5239.  
  5240.  
  5241.  Parameters
  5242.  
  5243.  dbproc
  5244.    The DBPROCESS structure that is the handle for a particular
  5245.    workstation/SQL Server process. It contains all the information that
  5246.    DB-LIBRARY uses to manage communications and data between the workstation
  5247.    and SQL Server.
  5248.  
  5249.  size
  5250.    The size, in bytes, of this particular part of the text or image value
  5251.    being sent to SQL Server. It is an error to send more text or image bytes
  5252.    to SQL Server than were specified in the call to dbwritetext.
  5253.  
  5254.  text
  5255.    A pointer to the text or image portion to be written.
  5256.  
  5257.  
  5258.  Returns
  5259.  
  5260.  SUCCEED or FAIL.
  5261.  
  5262.  
  5263.  See Also
  5264.  
  5265.  dbtxptr, dbtxtimestamp, dbwritetext
  5266.  
  5267.  
  5268.  dbmsghandle
  5269.  ────────────────────────────────────────────────────────────────────────────
  5270.  
  5271.  Function
  5272.  
  5273.  Supplies a user function to handle SQL Server messages.
  5274.  
  5275.  
  5276.  Syntax
  5277.  
  5278.    int  (*dbmsghandle(handler))()
  5279.  
  5280.     int  (*handler)();
  5281.  
  5282.  
  5283.  Comments
  5284.  
  5285.  This function installs a message-handling function that you supply. When
  5286.  DB-LIBRARY receives an SQL Server error or informational message, it
  5287.  immediately calls this message handler. You must install a message handler
  5288.  to handle SQL Server messages properly. Since the message handler is a
  5289.  call-back function, special considerations are required when compiling these
  5290.  functions under Windows or MS OS/2. For more information, see Appendix E,
  5291.  "Building Applications."
  5292.  
  5293.  The message-handling function should not call any DB-LIBRARY functions.
  5294.  Since calls to DB-LIBRARY functions can themselves generate messages, calls
  5295.  from within a message handler could result in infinite recursion. If your
  5296.  message handler must call a DB-LIBRARY function, it should set the
  5297.  message-handler to a null value, and then restore it when it exits. The
  5298.  following code fragment illustrates this technique:
  5299.  
  5300.    int msg_handler (dbproc, . . .
  5301.     {
  5302.     /* Set the message handler to NULL to prevent infinite recursion. */
  5303.     dbmsghandle(NULL);
  5304.     /* Call other DB_LIBRARY functions as necessary. */
  5305.       .
  5306.       .
  5307.       .
  5308.     /* Reset the message handler to this function. */
  5309.     dbmsghandle(msg_handler);
  5310.     return(. . .
  5311.     }
  5312.  
  5313.  
  5314.  Parameters
  5315.  
  5316.  handler
  5317.    A pointer to the user function that is called whenever DB-LIBRARY receives
  5318.    an error or informational message from SQL Server. DB-LIBRARY calls this
  5319.    function with five parameters:
  5320.  
  5321.      dbproc
  5322.        The affected DBPROCESS.
  5323.  
  5324.      msgno
  5325.        The current message's number (datatype DBINT). These numbers are
  5326.        documented in the SQL Server System Administrator's Guide.
  5327.  
  5328.      msgstate
  5329.        The current message's error state number (datatype int). These numbers
  5330.        provide information about the context of the error.
  5331.  
  5332.      severity
  5333.        The current message's information class or error severity (datatype
  5334.        int). These numbers are documented in the SQL Server System
  5335.        Administrator's Guide.
  5336.  
  5337.      msgtext
  5338.        The null-terminated text of the current message (datatype char *).
  5339.  
  5340.  
  5341.  
  5342.    The message handler must return a value of 0 to DB-LIBRARY.
  5343.  
  5344.    The following example shows a typical message-handling function:
  5345.  
  5346.        #include <sqlfront.h>
  5347.         #include <sqldb.h>
  5348.  
  5349.         int   msg_handler(dbproc, msgno, msgstate, severity, msgtext)
  5350.         DBPROCESS *dbproc;
  5351.         DBINT  msgno;
  5352.         DBSMALLINT msgstate;
  5353.         DBSMALLINT severity;
  5354.         char  *msgtext;
  5355.         {
  5356.          printf("SQL Server message %ld, state %d, "
  5357.           "severity %d:\n\t%s\n", msgno, msgstate, severity, msgtext);
  5358.          return(0);
  5359.         }
  5360.  
  5361.  
  5362.  Returns
  5363.  
  5364.  A pointer to the previously installed message handler. This can be NULL.
  5365.  
  5366.  
  5367.  See Also
  5368.  
  5369.  dberrhandle
  5370.  
  5371.  
  5372.  dbname
  5373.  ────────────────────────────────────────────────────────────────────────────
  5374.  
  5375.  Function
  5376.  
  5377.  Returns the name of the current database.
  5378.  
  5379.  
  5380.  Syntax
  5381.  
  5382.    char *dbname(dbproc)
  5383.  
  5384.     DBPROCESS *dbproc;
  5385.  
  5386.  
  5387.  Comments
  5388.  
  5389.  If you need to keep track of when the database changes, use dbchange.
  5390.  
  5391.  
  5392.  Parameters
  5393.  
  5394.  dbproc
  5395.    The DBPROCESS structure that is the handle for a particular
  5396.    workstation/SQL Server process. It contains all the information that
  5397.    DB-LIBRARY uses to manage communications and data between the workstation
  5398.    and SQL Server.
  5399.  
  5400.  
  5401.  Returns
  5402.  
  5403.  A pointer to the null-terminated name of the current database.
  5404.  
  5405.  
  5406.  See Also
  5407.  
  5408.  dbchange
  5409.  
  5410.  
  5411.  dbnextrow
  5412.  ────────────────────────────────────────────────────────────────────────────
  5413.  
  5414.  Function
  5415.  
  5416.  Reads in the next row.
  5417.  
  5418.  
  5419.  Syntax
  5420.  
  5421.    STATUS dbnextrow(dbproc)
  5422.  
  5423.     DBPROCESS *dbproc;
  5424.  
  5425.  
  5426.  Comments
  5427.  
  5428.  The dbnextrow function causes the next data row to be made available through
  5429.  the dbproc. If the DBBUFFER option is turned on and rows have been read out
  5430.  of order by calling dbgetrow, the next data row is read from the linked list
  5431.  of buffered rows. Any specified binding of row data to program variables
  5432.  takes effect.
  5433.  
  5434.  The dbresults function must be called and must have returned SUCCEED before
  5435.  you make any calls to dbnextrow.
  5436.  
  5437.  To determine whether a particular statement is one that returns rows and
  5438.  needs results processing with dbnextrow, call DBROWS after dbresults.
  5439.  
  5440.  Normally, each row is processed in turn by repeatedly calling dbnextrow. If
  5441.  row buffering is enabled and the row buffer has been cleared by the dbclrbuf
  5442.  function, the discarded rows are no longer available (even if dbgetrow tries
  5443.  to position to a discarded row). When row buffering is disabled, the last
  5444.  row is cleared when dbnextrow returns no more rows.
  5445.  
  5446.  The typical sequence of calls is
  5447.  
  5448.    DBINT xvariable;
  5449.     DBCHAR yvariable[10];
  5450.  
  5451.     /* Read the query into the command buffer. */
  5452.     dbcmd(dbproc, "select x = 100, y = 'hello'");
  5453.  
  5454.     /* Send the query to SQL Server. */
  5455.     dbsqlexec(dbproc);
  5456.  
  5457.     /* Get ready to process the results of the query. */
  5458.     dbresults(dbproc);
  5459.  
  5460.     /* Bind column data to program variables. */
  5461.     dbbind(dbproc, 1, INTBIND, (DBINT) 0, (BYTE *)&xvariable);
  5462.     dbbind(dbproc, 2, STRINGBIND, (DBINT) 0, yvariable);
  5463.  
  5464.     /* Now process each row. */
  5465.     while (dbnextrow(dbproc) != NO_MORE_ROWS)
  5466.     {
  5467.     /* C-code to print or process row data */
  5468.     }
  5469.  
  5470.  Note that if you are not using row buffering, you must continue calling
  5471.  dbnextrow until it returns NO_MORE_ROWS. This is true even if you are sure
  5472.  that your query only generates one results row. The while loop in the
  5473.  preceding example illustrates the correct way to use dbnextrow.
  5474.  
  5475.  The SQL Server can return two types of rows:
  5476.  
  5477.  
  5478.    ■   Regular rows containing data from columns designated by a SELECT
  5479.        statement's select list.
  5480.  
  5481.    ■   Compute rows resulting from the COMPUTE clause.
  5482.  
  5483.  
  5484.  To facilitate the processing of data rows from SQL Server, dbnextrow returns
  5485.  different values according to the type of row. For details, see "Returns."
  5486.  
  5487.  If you want data returned from SQL Server to be displayed on the default
  5488.  output device, use dbprrow instead of dbnextrow (except under Windows.)
  5489.  
  5490.  
  5491.  Parameters
  5492.  
  5493.  dbproc
  5494.    The DBPROCESS structure that is the handle for a particular
  5495.    workstation/SQL Server process. It contains all the information that
  5496.    DB-LIBRARY uses to manage communications and data between the workstation
  5497.    and SQL Server.
  5498.  
  5499.  
  5500.  Returns
  5501.  
  5502.  One of five different types of values:
  5503.  
  5504.  
  5505.    ■   If a regular row is read, REG_ROW is returned.
  5506.  
  5507.    ■   If a compute row is read, the computeid of the row is returned. (For
  5508.        information on the computeid, see "dbaltbind.")
  5509.  
  5510.    ■   If there are no more rows to be read or the statement didn't return
  5511.        any rows, NO_MORE_ROWS is returned.
  5512.  
  5513.    ■   If buffering is turned on and reading the next row would cause the
  5514.        buffer to be exceeded, BUF_FULL is returned. In this case, no row will
  5515.        have been read. To read any more rows, at least one row must first be
  5516.        cleared from the top of the row buffer. You can clear the row buffer
  5517.        by calling dbclrbuf.
  5518.  
  5519.    ■   If the function was unsuccessful, FAIL is returned.
  5520.  
  5521.  
  5522.  
  5523.  See Also
  5524.  
  5525.  dbaltbind, dbbind, dbclrbuf, dbgetrow, dbprrow, dbresults, Appendix B
  5526.  
  5527.  
  5528.  dbnumalts
  5529.  ────────────────────────────────────────────────────────────────────────────
  5530.  
  5531.  Function
  5532.  
  5533.  Returns the number of columns in a compute row.
  5534.  
  5535.  
  5536.  Syntax
  5537.  
  5538.    int dbnumalts(dbproc, computeid)
  5539.  
  5540.     DBPROCESS *dbproc;
  5541.     int   computeid;
  5542.  
  5543.  
  5544.  Comments
  5545.  
  5546.  The dbnumalts function returns the number of columns in a compute row. This
  5547.  function should be called after dbresults has returned SUCCEED. In this
  5548.  example, dbnumalts(dbproc, 1) returns 3:
  5549.  
  5550.    select dept, year, sales from employee
  5551.     order by dept, year
  5552.     compute avg(sales), min(sales), max(sales) by dept
  5553.  
  5554.  
  5555.  Parameters
  5556.  
  5557.  dbproc
  5558.    The DBPROCESS structure that is the handle for a particular
  5559.    workstation/SQL Server process. It contains all the information that
  5560.    DB-LIBRARY uses to manage communications and data between the workstation
  5561.    and SQL Server.
  5562.  
  5563.  computeid
  5564.    The ID that identifies the compute. A SELECT statement can have multiple
  5565.    COMPUTE clauses, each of which can have a different number of aggregate
  5566.    operators and aggregate targets. The computeid is returned by dbnextrow or
  5567.    dbgetrow.
  5568.  
  5569.  
  5570.  Returns
  5571.  
  5572.  The number of columns for the particular computeid. If computeid is invalid,
  5573.  -1 is returned.
  5574.  
  5575.  
  5576.  See Also
  5577.  
  5578.  dbadata, dbadlen, dbaltlen, dbalttype, dbgetrow, dbnextrow, dbresults
  5579.  
  5580.  
  5581.  dbnumcols
  5582.  ────────────────────────────────────────────────────────────────────────────
  5583.  
  5584.  Function
  5585.  
  5586.  Determines the number of columns for the current set of results.
  5587.  
  5588.  
  5589.  Syntax
  5590.  
  5591.    int dbnumcols(dbproc)
  5592.  
  5593.     DBPROCESS *dbproc;
  5594.  
  5595.  
  5596.  Comments
  5597.  
  5598.  The following program fragment illustrates the use of dbnumcols:
  5599.  
  5600.    int   column_count;
  5601.     DBPROCESS *dbproc;
  5602.  
  5603.     /* put the commands into the command buffer */
  5604.     dbcmd(dbproc, "select name, id, type from sysobjects");
  5605.     dbcmd(dbproc, " select name from sysobjects");
  5606.  
  5607.     /* send the commands to SQL Server and start execution */
  5608.     dbsqlexec(dbproc);
  5609.  
  5610.     /* process each command until there are no more */
  5611.     while (dbresults(dbproc) != NO_MORE_RESULTS)
  5612.     {
  5613.      column_count = dbnumcols(dbproc);
  5614.      printf("%d columns in this SQL Server result.\n", column_count);
  5615.      while (dbnextrow(dbproc) != NO_MORE_ROWS)
  5616.       printf("row received.\n");
  5617.     }
  5618.  
  5619.  
  5620.  Parameters
  5621.  
  5622.  dbproc
  5623.    The DBPROCESS structure that is the handle for a particular
  5624.    workstation/SQL Server process. It contains all the information that
  5625.    DB-LIBRARY uses to manage communications and data between the workstation
  5626.    and SQL Server.
  5627.  
  5628.  
  5629.  Returns
  5630.  
  5631.  The number of columns in the current set of results. If there are no
  5632.  columns, 0 is returned.
  5633.  
  5634.  
  5635.  See Also
  5636.  
  5637.  dbcollen, dbcolname
  5638.  
  5639.  
  5640.  dbnumcompute
  5641.  ────────────────────────────────────────────────────────────────────────────
  5642.  
  5643.  Function
  5644.  
  5645.  Returns the number of COMPUTE clauses in the current set of results.
  5646.  
  5647.  
  5648.  Syntax
  5649.  
  5650.    int dbnumcompute(dbproc)
  5651.  
  5652.     DBPROCESS *dbproc;
  5653.  
  5654.  
  5655.  Comments
  5656.  
  5657.  This function should be called after dbresults has returned SUCCEED. In this
  5658.  example, dbnumcompute(dbproc) returns 2 since there are two COMPUTE clauses
  5659.  in the SELECT statement:
  5660.  
  5661.    select dept, name from employee
  5662.     order by dept, name
  5663.     compute count(name) by dept
  5664.     compute count(name)
  5665.  
  5666.  
  5667.  Parameters
  5668.  
  5669.  dbproc
  5670.    The DBPROCESS structure that is the handle for a particular
  5671.    workstation/SQL Server process. It contains all the information that
  5672.    DB-LIBRARY uses to manage communications and data between the workstation
  5673.    and SQL Server.
  5674.  
  5675.  
  5676.  Returns
  5677.  
  5678.  The number of COMPUTE clauses in the current set of results.
  5679.  
  5680.  
  5681.  See Also
  5682.  
  5683.  dbnumalts, dbresults
  5684.  
  5685.  
  5686.  DBNUMORDERS
  5687.  ────────────────────────────────────────────────────────────────────────────
  5688.  
  5689.  Function
  5690.  
  5691.  Returns the number of columns specified in a TRANSACT-SQL SELECT statement's
  5692.  ORDER BY clause.
  5693.  
  5694.  
  5695.  Syntax
  5696.  
  5697.    int DBNUMORDERS(dbproc)
  5698.  
  5699.     DBPROCESS *dbproc;
  5700.  
  5701.  
  5702.  Comments
  5703.  
  5704.  Once a SELECT statement has been executed and dbresults is called, you can
  5705.  call DBNUMORDERS to find out how many columns were specified in the current
  5706.  statement's ORDER BY clause.
  5707.  
  5708.  
  5709.  Parameters
  5710.  
  5711.  dbproc
  5712.    The DBPROCESS structure that is the handle for a particular
  5713.    workstation/SQL Server process. It contains all the information that
  5714.    DB-LIBRARY uses to manage communications and data between the workstation
  5715.    and SQL Server.
  5716.  
  5717.  
  5718.  Returns
  5719.  
  5720.  The number of ORDER BY columns.
  5721.  
  5722.  
  5723.  See Also
  5724.  
  5725.  dbordercol dbresults
  5726.  
  5727.  
  5728.  dbopen
  5729.  ────────────────────────────────────────────────────────────────────────────
  5730.  
  5731.  Function
  5732.  
  5733.  Allocates and initializes a DBPROCESS structure.
  5734.  
  5735.  
  5736.  Syntax
  5737.  
  5738.    DBPROCESS *dbopen(login, servername)
  5739.  
  5740.     LOGINREC *login;
  5741.     char  *servername;
  5742.  
  5743.  
  5744.  Comments
  5745.  
  5746.  The DBPROCESS structure is the basic data structure that DB-LIBRARY uses to
  5747.  communicate with SQL Server. The program needs a DBPROCESS structure to talk
  5748.  to SQL Server. It is the first parameter in almost every DB-LIBRARY call.
  5749.  Besides allocating the DBPROCESS structure, this function sets up
  5750.  communication with the network, logs in to SQL Server, and initializes any
  5751.  default options. The following program fragment uses dbopen:
  5752.  
  5753.    DBPROCESS *dbproc;
  5754.     LOGINREC *loginrec;
  5755.  
  5756.     loginrec = dblogin();
  5757.     DBSETLUSER(loginrec, "user");
  5758.     DBSETLPWD(loginrec, "my_password");
  5759.     DBSETLAPP(loginrec, "my_program");
  5760.     dbproc = dbopen(loginrec, "my_server");
  5761.  
  5762.  
  5763.  Parameters
  5764.  
  5765.  login
  5766.    A pointer to a LOGINREC structure. This pointer is passed as a parameter
  5767.    to dbopen. You can get one by calling dblogin.
  5768.  
  5769.  servername
  5770.    The name of the SQL server that you want to connect to. If this is a null
  5771.    string,  dbopen uses a local SQL server if one is available.
  5772.  
  5773.  
  5774.  Returns
  5775.  
  5776.  A DBPROCESS pointer if everything is correct. Ordinarily, NULL is returned
  5777.  if a DBPROCESS structure couldn't be created or initialized, or if your
  5778.  login to SQL Server failed. When NULL is returned, the user-supplied error
  5779.  handler is called to indicate the error.
  5780.  
  5781.  ────────────────────────────────────────────────────────────────────────────
  5782.  NOTE
  5783.  
  5784.  If there's an unexpected communications failure during the SQL Server login
  5785.  process and an error handler has not been installed, the function returns
  5786.  NULL.
  5787.  ────────────────────────────────────────────────────────────────────────────
  5788.  
  5789.  
  5790.  Errors
  5791.  
  5792.  The dbopen function returns NULL if any of the following are true:
  5793.  
  5794. ╓┌─────────────────────────────────┌─────────────────────────────────────────
  5795.  Error Code                        Description
  5796.  ────────────────────────────────────────────────────────────────────────────
  5797.  SQLEMEM                           Unable to allocate sufficient memory.
  5798.  Error Code                        Description
  5799.  ────────────────────────────────────────────────────────────────────────────
  5800.  SQLEMEM                           Unable to allocate sufficient memory.
  5801.  
  5802.  SQLEDBPS                          Maximum number of DBPROCESS structures
  5803.                                    already allocated.
  5804.  
  5805.  SQLESOCK                          Unable to establish communication with SQL
  5806.                                    Server.
  5807.  
  5808.  SQLEUHST                          Unknown workstation name.
  5809.  
  5810.  SQLECONN                          Unable to connect: SQL Server is
  5811.                                    unavailable or does not exist.
  5812.  
  5813.  SQLEPWD                           Login incorrect.
  5814.  
  5815.  
  5816.  
  5817.  
  5818.  See Also
  5819.  
  5820.  dbclose, dbexit, dblogin
  5821.  
  5822.  
  5823.  dbordercol
  5824.  ────────────────────────────────────────────────────────────────────────────
  5825.  
  5826.  Function
  5827.  
  5828.  Returns the ID of a column appearing in the most recently executed query's
  5829.  ORDER BY clause.
  5830.  
  5831.  
  5832.  Syntax
  5833.  
  5834.    int dbordercol(dbproc, order)
  5835.  
  5836.     DBPROCESS *dbproc;
  5837.     int   order;
  5838.  
  5839.  
  5840.  Comments
  5841.  
  5842.  This function returns the ID of the column that appears in a specified
  5843.  location within the ORDER BY clause of a TRANSACT-SQL SELECT statement. In
  5844.  this example, dbordercol(dbproc, 1) returns 3 since the first column named
  5845.  in the ORDER BY clause refers to the third column in the SELECT clause:
  5846.  
  5847.    select dept, name, salary from employee
  5848.     order by salary, name
  5849.  
  5850.  
  5851.  Parameters
  5852.  
  5853.  dbproc
  5854.    The DBPROCESS structure that is the handle for a particular
  5855.    workstation/SQL Server process. It contains all the information that
  5856.    DB-LIBRARY uses to manage communications and data between the workstation
  5857.    and SQL Server.
  5858.  
  5859.  order
  5860.    The ID that identifies the particular ORDER BY column. The first column
  5861.    named within the ORDER BY clause is number 1.
  5862.  
  5863.  
  5864.  Returns
  5865.  
  5866.  The column ID (based on the column's position in the select list) for the
  5867.  column in the specified place in the ORDER BY clause. If the order is
  5868.  invalid, then -1 is returned.
  5869.  
  5870.  
  5871.  See Also
  5872.  
  5873.  DBNUMORDERS
  5874.  
  5875.  
  5876.  dbprhead
  5877.  ────────────────────────────────────────────────────────────────────────────
  5878.  
  5879.  Function
  5880.  
  5881.  Prints the column headings for rows returned from SQL Server.
  5882.  
  5883.  
  5884.  Syntax
  5885.  
  5886.    void dbprhead(dbproc)
  5887.  
  5888.     DBPROCESS *dbproc;
  5889.  
  5890.  
  5891.  Comments
  5892.  
  5893.  This function displays the column headings for a set of query results on the
  5894.  default output device in a format similar to that used by isql.exe. The
  5895.  format is compatible with the format used by dbprrow. The output width is
  5896.  set at 80 columns.
  5897.  
  5898.  The dbprhead function can be called after dbresults has succeeded.
  5899.  
  5900.  This function is useful for debugging.
  5901.  
  5902.  This function is not supported in the Windows environment.
  5903.  
  5904.  
  5905.  Parameters
  5906.  
  5907.  dbproc
  5908.    The DBPROCESS structure that is the handle for a particular
  5909.    workstation/SQL Server process. It contains all the information that
  5910.    DB-LIBRARY uses to manage communications and data between the workstation
  5911.    and SQL Server.
  5912.  
  5913.  
  5914.  Returns
  5915.  
  5916.  None.
  5917.  
  5918.  
  5919.  See Also
  5920.  
  5921.  dbbind, dbnextrow, dbprrow, dbresults
  5922.  
  5923.  
  5924.  dbprrow
  5925.  ────────────────────────────────────────────────────────────────────────────
  5926.  
  5927.  Function
  5928.  
  5929.  Prints all rows returned from SQL Server.
  5930.  
  5931.  
  5932.  Syntax
  5933.  
  5934.    RETCODE dbprrow(dbproc)
  5935.  
  5936.     DBPROCESS *dbproc;
  5937.  
  5938.  
  5939.  Comments
  5940.  
  5941.  This function displays the rows for a set of query results on the default
  5942.  output device in a format similar to that used by isql.exe. This function
  5943.  reads and prints all the rows. It saves the trouble of allocating program
  5944.  variables to store the data and calling dbbind, but the format is
  5945.  predetermined.
  5946.  
  5947.  This function can be called after dbresults has succeeded.
  5948.  
  5949.  When using this function, it is not necessary to call dbnextrow to loop
  5950.  through the rows.
  5951.  
  5952.  The dbprrow function is useful for debugging. The output line width is set
  5953.  at 80 columns.
  5954.  
  5955.  This function is not supported in the Windows environment.
  5956.  
  5957.  
  5958.  Parameters
  5959.  
  5960.  dbproc
  5961.    The DBPROCESS structure that is the handle for a particular
  5962.    workstation/SQL Server process. It contains all the information that
  5963.    DB-LIBRARY uses to manage communications and data between the workstation
  5964.    and SQL Server.
  5965.  
  5966.  
  5967.  Returns
  5968.  
  5969.  SUCCEED or FAIL.
  5970.  
  5971.  
  5972.  See Also
  5973.  
  5974.  dbbind, dbnextrow, dbprhead, dbresults
  5975.  
  5976.  
  5977.  dbprtype
  5978.  ────────────────────────────────────────────────────────────────────────────
  5979.  
  5980.  Function
  5981.  
  5982.  Converts an SQL Server token value to a readable string.
  5983.  
  5984.  
  5985.  Syntax
  5986.  
  5987.    char *dbprtype(token)
  5988.  
  5989.     int  token;
  5990.  
  5991.  
  5992.  Comments
  5993.  
  5994.  Functions like dbcoltype and dbalttype return SQL Server token values. If
  5995.  you want to print out what the token value means, dbprtype will provide the
  5996.  string.
  5997.  
  5998.  The following token values are used by dbprtype:
  5999.  
  6000. ╓┌─────────────────────────────────┌─────────────────────────────────────────╖
  6001.  Token Value                       Datatype
  6002.  ────────────────────────────────────────────────────────────────────────────
  6003.  SQLINT1                           tinyint
  6004.  
  6005.  SQLINT2                           smallint
  6006.  
  6007.  SQLINT4                           int
  6008.  Token Value                       Datatype
  6009.  ────────────────────────────────────────────────────────────────────────────
  6010. SQLINT4                           int
  6011.  
  6012.  SQLMONEY                          money
  6013.  
  6014.  SLQFLT8                           float
  6015.  
  6016.  SQLDATETIME                       datetime
  6017.  
  6018.  SQLBIT                            bit
  6019.  
  6020.  SQLCHAR                           char
  6021.  
  6022.  SQLVARCHAR                        varchar
  6023.  
  6024.  SQLTEXT                           text
  6025.  
  6026.  SQLBINARY                         binary
  6027.  
  6028.  SQLVARBINARY                      varbinary
  6029.  Token Value                       Datatype
  6030.  ────────────────────────────────────────────────────────────────────────────
  6031. SQLVARBINARY                      varbinary
  6032.  
  6033.  SQLIMAGE                          image
  6034.  
  6035.  SQLINTN                           integer-null
  6036.  
  6037.  SQLDATETIMN                       datetime-null
  6038.  
  6039.  SQLMONEYN                         money-null
  6040.  
  6041.  SQLFLTN                           float-null
  6042.  
  6043.  SQLAOPSUM                         sum
  6044.  
  6045.  SQLAOPAVG                         avg
  6046.  
  6047.  SQLAOPCNT                         count
  6048.  
  6049.  SQLAOPMIN                         min
  6050.  Token Value                       Datatype
  6051.  ────────────────────────────────────────────────────────────────────────────
  6052. SQLAOPMIN                         min
  6053.  
  6054.  SQLAOPMAX                         max
  6055.  
  6056.  ────────────────────────────────────────────────────────────────────────────
  6057.  
  6058.  
  6059.  
  6060.  
  6061.  Parameters
  6062.  
  6063.  token
  6064.    The SQL Server token value.
  6065.  
  6066.  
  6067.  Returns
  6068.  
  6069.  A pointer to a null-terminated string that is the readable translation of
  6070.  the SQL Server token value. The pointer points to space that is never
  6071.  overwritten, so it is safe to call this function more than once in the same
  6072.  statement. If the token is unknown, the function returns a pointer to an
  6073.  empty string. The strings correspond to SQL Server datatype names.
  6074.  
  6075.  
  6076.  See Also
  6077.  
  6078.  dbaltop, dbalttype, dbcoltype, Appendix C, SQL Server Language Reference
  6079.  
  6080.  
  6081.  dbqual
  6082.  ────────────────────────────────────────────────────────────────────────────
  6083.  
  6084.  Function
  6085.  
  6086.  Returns a pointer to a WHERE clause suitable for use in updating the current
  6087.  row in a table that can be browsed.
  6088.  
  6089.  
  6090.  Syntax
  6091.  
  6092.    char *dbqual(dbproc, tabnum, tabname)
  6093.  
  6094.     DBPROCESS *dbproc;
  6095.     int   tabnum;
  6096.     char  *tabname;
  6097.  
  6098.  
  6099.  Comments
  6100.  
  6101.  The dbqual function is one of the DB-LIBRARY browse-mode functions. For a
  6102.  detailed discussion of browse mode, see Chapter 1, "Overview of DB-LIBRARY."
  6103.  
  6104.  
  6105.  The dbqual function provides a WHERE clause that the application can use to
  6106.  update a single row in a browsable table. Columns from this row must have
  6107.  been previously retrieved into the application through a browse-mode SELECT
  6108.  query.
  6109.  
  6110.  The WHERE clause produced by dbqual begins with the keyword WHERE and
  6111.  contains references to the row's unique index and timestamp column. The
  6112.  application appends the WHERE clause to an UPDATE or DELETE statement; it
  6113.  does not need to examine it or manipulate it in any way.
  6114.  
  6115.  The timestamp column indicates the time that the particular row was last
  6116.  updated. An update on a browsable table fails if the timestamp column in the
  6117.  dbqual-generated WHERE clause is different from the timestamp column in the
  6118.  table. Such a condition, which provokes SQL Server error message 532,
  6119.  indicates that another user updated the row between the time this
  6120.  application selected it for browsing and the time it tried to update it. The
  6121.  application itself must provide the logic for handling the update failure.
  6122.  The following program fragment illustrates one approach:
  6123.  
  6124.    /* This code fragment illustrates a technique for handling the case where
  6125.     ** a browse-mode update fails because the row has already been updated
  6126.     ** by another user. In this example, we simply retrieve the entire row
  6127.     ** again, allow the user to examine and modify it, and try the update
  6128.     ** again.
  6129.     **
  6130.     ** Note that "q_dbproc" is the DBPROCESS used to query the database, and
  6131.     ** "u_dbproc" is the DBPROCESS used to update the database.
  6132.     */
  6133.  
  6134.     /* First, find out which employee record the user wants to update. */
  6135.     employee_id = which_employee();
  6136.  
  6137.    while (1)
  6138.     {
  6139.      /* Retrieve that employee record from the database. We'll
  6140.      ** assume that "empid" is a unique index, so this query will
  6141.      ** return only one row.
  6142.      */
  6143.      dbfcmd
  6144.      (q_dbproc,
  6145.      "select * from employees where empid = %d for browse",
  6146.      employee_id);
  6147.      dbsqlexec(q_dbproc);
  6148.      dbresults(q_dbproc);
  6149.      dbnextrow(q_dbproc);
  6150.  
  6151.      /* Now, let the user examine or edit the employee's
  6152.      ** data, first placing the data into the program variables.
  6153.      */
  6154.      extract_employee_data(q_dbproc, employee_struct);
  6155.      examine_and_edit(employee_struct, &edit_flag);
  6156.  
  6157.      if (edit_flag == FALSE)
  6158.      {
  6159.       /* The user didn't edit this record,
  6160.       ** so we're done.
  6161.       */
  6162.       break;
  6163.      }
  6164.      else
  6165.      {
  6166.       /* The user edited this record, so we'll use the edited
  6167.       ** data to update the corresponding row in the database.
  6168.       */
  6169.       qualptr = dbqual(q_dbproc, -1, "employees");
  6170.       dbcmd(u_dbproc, "update employees");
  6171.       dbfcmd
  6172.       (u_dbproc,
  6173.       " set address = '%s', salary = %d %s",
  6174.       employee_struct->address, employee_struct->salary,
  6175.       qualptr);
  6176.       dbfreequal(qualptr);
  6177.       if ((dbsqlexec(u_dbproc) == FAIL)
  6178.       || (dbresults(u_dbproc) == FAIL))
  6179.  
  6180.  
  6181.       {
  6182.        /* Our update failed. In a real program, it
  6183.        ** would be necessary to examine the messages
  6184.        ** returned from the SQL Server to determine
  6185.        ** why it failed. In this example, we'll
  6186.        ** assume that the update failed because
  6187.        ** someone else has already updated this
  6188.        ** row, thereby changing the timestamp.
  6189.        **
  6190.        ** To cope with this situation, we'll just
  6191.        ** repeat the loop, retrieving the changed
  6192.        ** row for our user to examine and edit.
  6193.        ** This will give our user the opportunity
  6194.        ** to decide whether to overwrite the change
  6195.        ** made by the other user.
  6196.        */
  6197.        continue;
  6198.       }
  6199.       else
  6200.       {
  6201.        /* The update succeeded, so we're done. */
  6202.        break;
  6203.       }
  6204.      }
  6205.     }
  6206.  
  6207.  The dbqual function can only construct WHERE clauses for tables that can be
  6208.  browsed. You can use dbtabbrowse to determine whether a table can be
  6209.  browsed.
  6210.  
  6211.  The dbqual function is usually called after dbnextrow.
  6212.  
  6213.  
  6214.  Parameters
  6215.  
  6216.  dbproc
  6217.    The DBPROCESS structure that is the handle for a particular
  6218.    workstation/SQL Server process. It contains all the information that
  6219.    DB-LIBRARY uses to manage communications and data between the workstation
  6220.    and SQL Server.
  6221.  
  6222.  tabnum
  6223.    The number of the table, as specified in the SELECT statement's FROM
  6224.    clause. Table numbers start at 1. If tabnum is -1, the tabname parameter
  6225.    is used to identify the table.
  6226.  
  6227.  tabname
  6228.    A pointer to the null-terminated name of a table specified in the SELECT
  6229.    statement's FROM clause. If tabname is NULL, the tabnum parameter is used
  6230.    to identify the table.
  6231.  
  6232.  
  6233.  Returns
  6234.  
  6235.  A pointer to a null-terminated WHERE clause for the current row in the
  6236.  specified table. This buffer is dynamically allocated, and the application
  6237.  must free it by calling dbfreequal. If dbqual is asked to construct a WHERE
  6238.  clause for a table that cannot be browsed, it will return a NULL pointer.
  6239.  For details, see "dbtabbrowse."
  6240.  
  6241.  
  6242.  See Also
  6243.  
  6244.  dbcolbrowse, dbcolsource, dbfreequal, dbnextrow, dbqual, dbtabbrowse,
  6245.  dbtabcount, dbtabname, dbtabsource, dbtsnewlen, dbtsnewval, dbtsput
  6246.  
  6247.  
  6248.  DBRBUF
  6249.  ────────────────────────────────────────────────────────────────────────────
  6250.  
  6251.  Function
  6252.  
  6253.  Determines whether database command processing has completed.
  6254.  
  6255.  
  6256.  Syntax
  6257.  
  6258.    BOOL DBRBUF(dbproc)
  6259.  
  6260.     DBPROCESS *dbproc;
  6261.  
  6262.  
  6263.  Comments
  6264.  
  6265.  This macro allows an application to continue processing while SQL Server is
  6266.  actually performing the database operation.
  6267.  
  6268.  The DBRBUF macro is ordinarily used after a call to dbsqlsend and before a
  6269.  call to dbsqlok. After dbsqlsend, SQL Server begins executing the commands
  6270.  in the command buffer. When dbsqlok is called, DB-LIBRARY waits for SQL
  6271.  Server processing to be completed before returning control to the
  6272.  application program.
  6273.  
  6274.  The DBRBUF macro provides a method for determining when command processing
  6275.  has completed. It should be called repeatedly until it returns a nonzero
  6276.  value. At that point, dbsqlok can be called.
  6277.  
  6278.  ────────────────────────────────────────────────────────────────────────────
  6279.  NOTE
  6280.  
  6281.  The DBRBUF macro is provided for compatibility with other SYBASE platforms.
  6282.  It has been replaced by the dbdataready function. DBRBUF now maps directly
  6283.  to a call to dbdataready.
  6284.  ────────────────────────────────────────────────────────────────────────────
  6285.  
  6286.  
  6287.  Parameters
  6288.  
  6289.  dbproc
  6290.    The DBPROCESS structure that is the handle for a particular
  6291.    workstation/SQL Server process. It contains all the information that
  6292.    DB-LIBRARY uses to manage communications and data between the workstation
  6293.    and SQL Server.
  6294.  
  6295.  
  6296.  Returns
  6297.  
  6298.  TRUE if data is available; FALSE otherwise.
  6299.  
  6300.  
  6301.  See Also
  6302.  
  6303.  dbdataready, dbresults, dbsqlok, dbsqlsend
  6304.  
  6305.  
  6306.  dbreadpage
  6307.  ────────────────────────────────────────────────────────────────────────────
  6308.  
  6309.  Function
  6310.  
  6311.  Reads in a page of binary data from SQL Server.
  6312.  
  6313.  
  6314.  Syntax
  6315.  
  6316.    DBINT dbreadpage(dbproc, dbname, pageno, buf)
  6317.  
  6318.     DBPROCESS *dbproc;
  6319.     char  *dbname;
  6320.     DBINT  pageno;
  6321.     BYTE  buf[];
  6322.  
  6323.  
  6324.  Comments
  6325.  
  6326.  This function is primarily useful for examining and repairing damaged
  6327.  database pages. After calling dbreadpage, the DBPROCESS can contain some
  6328.  error or informational messages from SQL Server. These messages can be
  6329.  accessed through a user-supplied message handler.
  6330.  
  6331.  
  6332.  Parameters
  6333.  
  6334.  dbproc
  6335.    The DBPROCESS structure that is the handle for a particular
  6336.    workstation/SQL Server process. It contains all the information that
  6337.    DB-LIBRARY uses to manage communications and data between the workstation
  6338.    and SQL Server.
  6339.  
  6340.  dbname
  6341.    The name of the database.
  6342.  
  6343.  pageno
  6344.    The number of the database page to be read.
  6345.  
  6346.  buf
  6347.    A pointer to a buffer to hold the received page data. SQL Server pages are
  6348.    currently 2048 bytes long.
  6349.  
  6350.  
  6351.  Returns
  6352.  
  6353.  The number of bytes read from SQL Server. If the operation was unsuccessful,
  6354.  dbreadpage returns -1.
  6355.  
  6356.  
  6357.  Limitations
  6358.  
  6359.  Alters the contents of the DBPROCESS command buffer.
  6360.  
  6361.  
  6362.  See Also
  6363.  
  6364.  dbmsghandle, dbwritepage
  6365.  
  6366.  
  6367.  dbresults
  6368.  ────────────────────────────────────────────────────────────────────────────
  6369.  
  6370.  Function
  6371.  
  6372.  Sets up the results of the next query.
  6373.  
  6374.  
  6375.  Syntax
  6376.  
  6377.    RETCODE dbresults(dbproc)
  6378.  
  6379.     DBPROCESS *dbproc;
  6380.  
  6381.  
  6382.  Comments
  6383.  
  6384.  This function sets up the next statement in the command batch for
  6385.  processing. It is called after dbsqlexec or dbsqlok returns SUCCEED. It is
  6386.  guaranteed that dbresults will return SUCCEED or NO_MORE_RESULTS on the
  6387.  first call if dbsqlexec or dbsqlok has returned SUCCEED, unless a network
  6388.  error or out-of-memory error has occurred. The user typically processes
  6389.  rows, if any, using dbnextrow, once dbresults returns SUCCEED.
  6390.  
  6391.  The dbresults function must be called for each statement in the command
  6392.  batch, whether or not the statement returns any rows. If the application
  6393.  code doesn't know how many statements are in the batch, dbresults can be
  6394.  called until it returns NO_MORE_RESULTS. The dbresults function must also
  6395.  ordinarily be called once for any stored procedure in the command batch.
  6396.  However, if the stored procedure contains more than one SQL SELECT
  6397.  statement, then dbresults must be called once for each SELECT. The easiest
  6398.  way to do this is to continue to call dbresults until it returns
  6399.  NO_MORE_RESULTS.
  6400.  
  6401.  To determine whether a particular statement is one that returns rows and
  6402.  needs results processing with dbnextrow, call DBROWS.
  6403.  
  6404.  The typical sequence of calls for using dbresults with dbsqlexec is
  6405.  
  6406.    DBINT xvariable;
  6407.     DBCHAR yvariable[10];
  6408.  
  6409.     /* Read the query into the command buffer. */
  6410.     dbcmd(dbproc, "select x = 100, y = 'hello'");
  6411.  
  6412.     /* Send the query to SQL Server. */
  6413.     dbsqlexec(dbproc);
  6414.     /* Get ready to process the results of the query. */
  6415.     dbresults(dbproc);
  6416.     /* Bind column data to program variables. */
  6417.     dbbind(dbproc, 1, INTBIND, (DBINT) 0, (BYTE *) &xvariable);
  6418.     dbbind(dbproc, 2, STRINGBIND, (DBINT) 0, yvariable);
  6419.     /* Now process each row. */
  6420.     while (dbnextrow(dbproc) != NO_MORE_ROWS)
  6421.     {
  6422.      /* C-code to print or process row data */
  6423.     }
  6424.  
  6425.  
  6426.  Parameters
  6427.  
  6428.  dbproc
  6429.    The DBPROCESS structure that is the handle for a particular
  6430.    workstation/SQL Server process. It contains all the information that
  6431.    DB-LIBRARY uses to manage communications and data between the workstation
  6432.    and SQL Server.
  6433.  
  6434.  
  6435.  Returns
  6436.  
  6437.  SUCCEED, FAIL, or NO_MORE_RESULTS. The most common reason for failing is a
  6438.  NULL or dead dbproc. NO_MORE_RESULTS is returned if there are no more
  6439.  results to be processed.
  6440.  
  6441.  
  6442.  See Also
  6443.  
  6444.  dbbind, dbnextrow, DBROWS, dbsqlexec, dbsqlok
  6445.  
  6446.  
  6447.  DBROWS
  6448.  ────────────────────────────────────────────────────────────────────────────
  6449.  
  6450.  Function
  6451.  
  6452.  Indicates whether the current statement returned rows.
  6453.  
  6454.  
  6455.  Syntax
  6456.  
  6457.    RETCODE DBROWS(dbproc)
  6458.  
  6459.     DBPROCESS *dbproc;
  6460.  
  6461.  
  6462.  Comments
  6463.  
  6464.  This macro should be called after dbresults returns SUCCEED. Note that
  6465.  DBROWS should be called before dbnextrow; otherwise, DBROWS returns an
  6466.  incorrect value. You can use the DBCMDROW macro to determine whether the
  6467.  current statement is one that can return rows (that is, a TRANSACT-SQL
  6468.  SELECT statement or an EXECUTE on a stored procedure containing a SELECT).
  6469.  
  6470.  
  6471.  Parameters
  6472.  
  6473.  dbproc
  6474.    The DBPROCESS structure that is the handle for a particular
  6475.    workstation/SQL Server process. It contains all the information that
  6476.    DB-LIBRARY uses to manage communications and data between the workstation
  6477.    and SQL Server.
  6478.  
  6479.  
  6480.  Returns
  6481.  
  6482.  SUCCEED or FAIL, indicating whether the current statement will return rows.
  6483.  
  6484.  
  6485.  
  6486.  See Also
  6487.  
  6488.  DBCMDROW, dbnextrow, dbresults, DBROWTYPE
  6489.  
  6490.  
  6491.  DBROWTYPE
  6492.  ────────────────────────────────────────────────────────────────────────────
  6493.  
  6494.  Function
  6495.  
  6496.  Returns the type of the current row.
  6497.  
  6498.  
  6499.  Syntax
  6500.  
  6501.    STATUS DBROWTYPE(dbproc)
  6502.  
  6503.     DBPROCESS *dbproc;
  6504.  
  6505.  
  6506.  Comments
  6507.  
  6508.  This macro tells you the type (regular or compute) of the current row.
  6509.  Usually you already know this since dbnextrow returns the row type.
  6510.  
  6511.  
  6512.  Parameters
  6513.  
  6514.  dbproc
  6515.    The DBPROCESS structure that is the handle for a particular
  6516.    workstation/SQL Server process. It contains all the information that
  6517.    DB-LIBRARY uses to manage communications and data between the workstation
  6518.    and SQL Server.
  6519.  
  6520.  
  6521.  Returns
  6522.  
  6523.  One of four different types of values:
  6524.  
  6525.  
  6526.    ■   If the current row is a regular row, REG_ROW is returned.
  6527.  
  6528.    ■   If the current row is a compute row, the computeid of the row is
  6529.        returned. (For information on the computeid, see "dbaltbind.")
  6530.  
  6531.    ■   If no rows have been read, NO_MORE_ROWS is returned.
  6532.  
  6533.    ■   If the macro was unsuccessful, FAIL is returned.
  6534.  
  6535.  
  6536.  
  6537.  See Also
  6538.  
  6539.  dbaltbind, dbnextrow
  6540.  
  6541.  
  6542.  dbsetavail
  6543.  ────────────────────────────────────────────────────────────────────────────
  6544.  
  6545.  Function
  6546.  
  6547.  Marks a DBPROCESS as being available for general use.
  6548.  
  6549.  
  6550.  Syntax
  6551.  
  6552.    void dbsetavail(dbproc)
  6553.  
  6554.     DBPROCESS *dbproc;
  6555.  
  6556.  
  6557.  Comments
  6558.  
  6559.  Any subsequent call to DBISAVAIL returns TRUE until some use is made of the
  6560.  DBPROCESS. Many DB-LIBRARY functions automatically set the DBPROCESS to "not
  6561.  available." This is useful when many different parts of a program are
  6562.  attempting to share a single DBPROCESS.
  6563.  
  6564.  
  6565.  Parameters
  6566.  
  6567.  dbproc
  6568.    The DBPROCESS structure that is the handle for a particular
  6569.    workstation/SQL Server process. It contains all the information that
  6570.    DB-LIBRARY uses to manage communications and data between the workstation
  6571.    and SQL Server.
  6572.  
  6573.  
  6574.  Returns
  6575.  
  6576.  None.
  6577.  
  6578.  
  6579.  See Also
  6580.  
  6581.  DBISAVAIL
  6582.  
  6583.  
  6584.  DBSETLAPP
  6585.  ────────────────────────────────────────────────────────────────────────────
  6586.  
  6587.  Function
  6588.  
  6589.  Sets the application name in the LOGINREC structure.
  6590.  
  6591.  
  6592.  Syntax
  6593.  
  6594.    RETCODE DBSETLAPP(loginrec, application)
  6595.  
  6596.     LOGINREC *loginrec;
  6597.     char  *application;
  6598.  
  6599.  
  6600.  Comments
  6601.  
  6602.  This macro sets the application field in the LOGINREC structure. For it to
  6603.  have any effect, it must be called before dbopen. This macro is optional. If
  6604.  not called, the application name is set to NULL.
  6605.  
  6606.  SQL Server uses the application name in its sysprocesses table to help
  6607.  identify your process. If you set the application name, you will see it if
  6608.  you query the sysprocesses table in the master database.
  6609.  
  6610.  
  6611.  Parameters
  6612.  
  6613.  loginrec
  6614.    A pointer to a LOGINREC structure, which will be passed as a parameter to
  6615.    dbopen. You can get one by calling dblogin.
  6616.  
  6617.  application
  6618.    The application name that will be sent to SQL Server. It must be a
  6619.    null-terminated character string. The maximum length of the string is 30
  6620.    characters, not including the null-terminating character.
  6621.  
  6622.  
  6623.  Returns
  6624.  
  6625.  SUCCEED or FAIL.
  6626.  
  6627.  
  6628.  See Also
  6629.  
  6630.  dblogin, dbopen, DBSETLHOST, DBSETLPWD, DBSETLUSER
  6631.  
  6632.  
  6633.  DBSETLHOST
  6634.  ────────────────────────────────────────────────────────────────────────────
  6635.  
  6636.  Function
  6637.  
  6638.  Sets the workstation name in the LOGINREC structure.
  6639.  
  6640.  
  6641.  Syntax
  6642.  
  6643.    RETCODE DBSETLHOST(loginrec, workstation)
  6644.  
  6645.     LOGINREC *loginrec;
  6646.     char  *workstation;
  6647.  
  6648.  
  6649.  Comments
  6650.  
  6651.  This macro sets the workstation name in the LOGINREC structure. For it to
  6652.  have any effect, it must be called before dbopen.
  6653.  
  6654.  The workstation name shows up in the sysprocesses table in the master
  6655.  database, or if you issue an sp_who command.
  6656.  
  6657.  It is not necessary to call this macro. If it is not called, DB-LIBRARY sets
  6658.  the workstation name to NULL.
  6659.  
  6660.  
  6661.  Parameters
  6662.  
  6663.  loginrec
  6664.    A pointer to a LOGINREC structure, which is passed as a parameter to
  6665.    dbopen. You can get one by calling dblogin.
  6666.  
  6667.  workstation
  6668.    The workstation name that will be sent to SQL Server. It must be a
  6669.    null-terminated character string. The maximum length of the string is 30
  6670.    characters, not including the null-terminating character.
  6671.  
  6672.  
  6673.  Returns
  6674.  
  6675.  SUCCEED or FAIL.
  6676.  
  6677.  
  6678.  See Also
  6679.  
  6680.  dblogin, dbopen, DBSETLAPP, DBSETLPWD, DBSETLUSER
  6681.  
  6682.  
  6683.  dbsetlogintime
  6684.  ────────────────────────────────────────────────────────────────────────────
  6685.  
  6686.  Function
  6687.  
  6688.  Sets the number of seconds that DB-LIBRARY waits for an SQL Server response
  6689.  to a request for a DBPROCESS connection.
  6690.  
  6691.  
  6692.  Syntax
  6693.  
  6694.    RETCODE dbsetlogintime(seconds)
  6695.  
  6696.     int  seconds;
  6697.  
  6698.  
  6699.  Comments
  6700.  
  6701.  This function sets the length of time in seconds that DB-LIBRARY will wait
  6702.  for a login response after calling dbopen. The default timeout value is 60
  6703.  seconds.
  6704.  
  6705.  
  6706.  Parameters
  6707.  
  6708.  seconds
  6709.    The timeout value─the number of seconds that DB-LIBRARY waits for a login
  6710.    response before timing out. A timeout value of 0 represents an infinite
  6711.    timeout period.
  6712.  
  6713.  
  6714.  Returns
  6715.  
  6716.  SUCCEED or FAIL.
  6717.  
  6718.  
  6719.  See Also
  6720.  
  6721.  dberrhandle, dbopen, dbsettime
  6722.  
  6723.  
  6724.  DBSETLPWD
  6725.  ────────────────────────────────────────────────────────────────────────────
  6726.  
  6727.  Function
  6728.  
  6729.  Sets the user SQL Server password in the LOGINREC structure.
  6730.  
  6731.  
  6732.  Syntax
  6733.  
  6734.    RETCODE  DBSETLPWD(loginrec, password)
  6735.  
  6736.     LOGINREC *loginrec;
  6737.     char  *password;
  6738.  
  6739.  
  6740.  Comments
  6741.  
  6742.  For this macro to have any effect, it must be called before dbopen.
  6743.  
  6744.  You do not need to call this macro if the password is a null value.
  6745.  
  6746.  
  6747.  Parameters
  6748.  
  6749.  loginrec
  6750.    A pointer to a LOGINREC structure, which is passed as a parameter to
  6751.    dbopen. You can get one by calling dblogin.
  6752.  
  6753.  password
  6754.    The SQL Server password that is sent to SQL Server. It must be a
  6755.    null-terminated character string. The maximum length of the string is 30
  6756.    characters, not including the null-terminating character.
  6757.  
  6758.  
  6759.  Returns
  6760.  
  6761.  SUCCEED or FAIL.
  6762.  
  6763.  
  6764.  See Also
  6765.  
  6766.  dblogin, dbopen, DBSETLAPP, DBSETLHOST, DBSETLUSER
  6767.  
  6768.  
  6769.  DBSETLUSER
  6770.  ────────────────────────────────────────────────────────────────────────────
  6771.  
  6772.  Function
  6773.  
  6774.  Sets the username in the LOGINREC structure.
  6775.  
  6776.  
  6777.  Syntax
  6778.  
  6779.    RETCODE DBSETLUSER(loginrec, username)
  6780.  
  6781.     LOGINREC *loginrec;
  6782.     char  *username;
  6783.  
  6784.  
  6785.  Comments
  6786.  
  6787.  For this macro to have any effect, it must be called before dbopen.
  6788.  
  6789.  
  6790.  Parameters
  6791.  
  6792.  loginrec
  6793.    A pointer to a LOGINREC structure, which is passed as a parameter to
  6794.    dbopen. You can get one by calling dblogin.
  6795.  
  6796.  username
  6797.    The username that is sent to SQL Server. It must be a null-terminated
  6798.    character string. The maximum length of the string is 30 characters, not
  6799.    including the null-terminating character. SQL Server uses it to determine
  6800.    who is attempting the connection. The SQL Server usernames are defined in
  6801.    the syslogins table in the master database.
  6802.  
  6803.  
  6804.  Returns
  6805.  
  6806.  SUCCEED or FAIL.
  6807.  
  6808.  
  6809.  See Also
  6810.  
  6811.  dblogin, dbopen, DBSETLAPP, DBSETLHOST, DBSETLPWD
  6812.  
  6813.  
  6814.  dbsetmaxprocs
  6815.  ────────────────────────────────────────────────────────────────────────────
  6816.  
  6817.  Function
  6818.  
  6819.  Sets the maximum number of simultaneously open DBPROCESS structures.
  6820.  
  6821.  
  6822.  Syntax
  6823.  
  6824.    RETCODE dbsetmaxprocs(maxprocs)
  6825.  
  6826.     int  maxprocs;
  6827.  
  6828.  
  6829.  Comments
  6830.  
  6831.  A DB-LIBRARY program has a maximum number of simultaneously open DBPROCESS
  6832.  structures. By default, this number is 25. The program can change this limit
  6833.  by calling dbsetmaxprocs.
  6834.  
  6835.  The program can find out what the current limit is by calling dbgetmaxprocs.
  6836.  
  6837.  
  6838.  
  6839.  Parameters
  6840.  
  6841.  maxprocs
  6842.    The new limit on simultaneously open DBPROCESS structures for this
  6843.    particular program.
  6844.  
  6845.  
  6846.  Returns
  6847.  
  6848.  SUCCEED if the function call is successful, or else FAIL (that is, maxprocs
  6849.  
  6850.  
  6851.  See Also
  6852.  
  6853.  dbgetmaxprocs, dbopen
  6854.  
  6855.  
  6856.  dbsetnull
  6857.  ────────────────────────────────────────────────────────────────────────────
  6858.  
  6859.  Function
  6860.  
  6861.  Defines substitution values to be used when binding null values.
  6862.  
  6863.  
  6864.  Syntax
  6865.  
  6866.    RETCODE dbsetnull(dbproc, bindtype, bindlen, bindval)
  6867.  
  6868.     DBPROCESS *dbproc;
  6869.     int   bindtype;
  6870.     int   bindlen;
  6871.     BYTE  *bindval;
  6872.  
  6873.  
  6874.  Comments
  6875.  
  6876.  The dbbind and dbaltbind functions are used to bind returned SQL Server
  6877.  column values to your program variables. Since a null value can be returned,
  6878.  there is a mechanism for defining what values should be substituted for the
  6879.  null value when doing automatic copying of column data to program variables.
  6880.  Associated with each DBPROCESS is a list of substitute values for each of
  6881.  the binding types. The default substitution values are as follows:
  6882.  
  6883. ╓┌─────────────────────────────────┌─────────────────────────────────────────
  6884.  Binding Type                      Default Substitution Value
  6885.  ────────────────────────────────────────────────────────────────────────────
  6886.  TINYBIND                          0
  6887.  
  6888.  SMALLBIND                         0
  6889.  
  6890.  Binding Type                      Default Substitution Value
  6891.  ────────────────────────────────────────────────────────────────────────────
  6892. 
  6893.  INTBIND                           0
  6894.  
  6895.  BITBIND                           0
  6896.  
  6897.  CHARBIND                          Empty string (padded with blanks)
  6898.  
  6899.  STRINGBIND                        Empty string (padded with blanks,
  6900.                                    null-terminated)
  6901.  
  6902.  NTBSTRINGBIND                     Empty string (null-terminated)
  6903.  
  6904.  VARYCHARBIND                      Empty string
  6905.  
  6906.  BINARYBIND                        Empty array (padded with zeros)
  6907.  
  6908.  VARYBINBIND                       Empty array
  6909.  
  6910.  DATETIMEBIND                      8 bytes of zeros
  6911.  Binding Type                      Default Substitution Value
  6912.  ────────────────────────────────────────────────────────────────────────────
  6913. DATETIMEBIND                      8 bytes of zeros
  6914.  
  6915.  MONEYBIND                         $0.00
  6916.  
  6917.  FLT8BIND                          0.0
  6918.  
  6919.  ────────────────────────────────────────────────────────────────────────────
  6920.  
  6921.  
  6922.  
  6923.  You can provide your own null substitution values by calling dbsetnull. Any
  6924.  time you call dbsetnull to change a particular null substitution value, the
  6925.  new value remains in force for that DBPROCESS until you change it with
  6926.  another call to dbsetnull.
  6927.  
  6928.  The dbconvert function also uses the current null substitution values when
  6929.  it needs to set a destination variable to null.
  6930.  
  6931.  
  6932.  Parameters
  6933.  
  6934.  dbproc
  6935.    The DBPROCESS structure that is the handle for a particular
  6936.    workstation/SQL Server process. It contains all the information that
  6937.    DB-LIBRARY uses to manage communications and data between the workstation
  6938.    and SQL Server.
  6939.  
  6940.  bindtype
  6941.    The type of variable binding to which the substitute value will apply.
  6942.    (See "dbbind" for more information about the different bindtypes.)
  6943.  
  6944.  bindlen
  6945.    The length, in bytes, of the substitute value you are supplying. It is
  6946.    ignored in all cases except CHARBIND and BINARYBIND. All the other types
  6947.    are either fixed-length or have a special terminator or embedded byte
  6948.    count that provides the length of the data.
  6949.  
  6950.  bindval
  6951.    A generic BYTE pointer to the value you want to use as a null value
  6952.    substitution. The dbsetnull function always makes a copy of this data, so
  6953.    you can free this pointer any time after this call.
  6954.  
  6955.  
  6956.  Returns
  6957.  
  6958.  SUCCEED or FAIL. The dbsetnull function fails if you give it a null bindval
  6959.  or if the length is smaller than 1 when CHARBIND and BINARYBIND types are
  6960.  used.
  6961.  
  6962.  
  6963.  See Also
  6964.  
  6965.  dbaltbind, dbbind, dbconvert, Appendix C
  6966.  
  6967.  
  6968.  dbsetopt
  6969.  ────────────────────────────────────────────────────────────────────────────
  6970.  
  6971.  Function
  6972.  
  6973.  Sets an SQL Server or DB-LIBRARY option.
  6974.  
  6975.  
  6976.  Syntax
  6977.  
  6978.    RETCODE dbsetopt(dbproc, option, param)
  6979.  
  6980.     DBPROCESS *dbproc;
  6981.     int   option;
  6982.     char  *param;
  6983.  
  6984.  
  6985.  Comments
  6986.  
  6987.  Although SQL Server options can be set and cleared directly through SQL, the
  6988.  application should use dbsetopt and dbclropt to set and clear options. This
  6989.  provides a uniform interface for setting both SQL Server and DB-LIBRARY
  6990.  options. It also allows the application to use the dbisopt function to check
  6991.  the status of an option.
  6992.  
  6993.  This function does not immediately set the options specified. They are not
  6994.  set until the command buffer is sent to SQL Server (by invoking the
  6995.  dbsqlexec function). An additional result for each option set is returned
  6996.  through the dbresults function. (See "dbresults" for information on results
  6997.  returned.)
  6998.  
  6999.  Note that the command string generated by this function is not immediately
  7000.  sent to SQL Server. Instead, it is buffered within DB-LIBRARY and sent the
  7001.  next time dbsqlexec is invoked; therefore, any options requested by this
  7002.  function do not go into effect until then. Also, the results of the command
  7003.  generated by this function are not returned until the command is transferred
  7004.  to SQL Server. Therefore, the application should be expecting the results
  7005.  returned from the command string generated by this function. If an invalid
  7006.  parameter is specified, this is not known until the command is sent to SQL
  7007.  Server and the results for that command are returned through dbresult.
  7008.  DB-LIBRARY does not detect these types of errors.
  7009.  
  7010.  For a list of each option and its default status, see Appendix B,
  7011.  "DB-LIBRARY Options."
  7012.  
  7013.  
  7014.  Parameters
  7015.  
  7016.  dbproc
  7017.    The DBPROCESS structure that is the handle for a particular
  7018.    workstation/SQL Server process. It contains all the information that
  7019.    DB-LIBRARY uses to manage communications and data between the workstation
  7020.    and SQL Server. If dbproc is NULL, the option will be set for all active
  7021.    DBPROCESS structures.
  7022.  
  7023.  option
  7024.    The option that is to be set.
  7025.  
  7026.  param
  7027.    Certain options take parameters. For example, the DBOFFSET option takes as
  7028.    its parameter the construct for which offsets are to be returned:
  7029.  
  7030.        dbsetopt(dbproc, DBOFFSET, "compute")
  7031.  
  7032.    The DBBUFFER option takes as its parameter the number of rows to be
  7033.    buffered. A parameter of -1 selects the default (currently 100 rows). The
  7034.    syntax is:
  7035.  
  7036.        dbsetopt(dbproc, DBBUFFER, "500")
  7037.  
  7038.  ────────────────────────────────────────────────────────────────────────────
  7039.  NOTE
  7040.  
  7041.  The param variable must always be a character string enclosed in quotes,
  7042.  even in the case of a numeric value, as in the DBBUFFER example.
  7043.  ────────────────────────────────────────────────────────────────────────────
  7044.  
  7045.    If the option takes no parameters, param must be NULL.
  7046.  
  7047.  
  7048.  Returns
  7049.  
  7050.  SUCCEED or FAIL.
  7051.  
  7052.  
  7053.  See Also
  7054.  
  7055.  dbclropt, dbisopt, dbresults, dbsqlexec, Appendix B
  7056.  
  7057.  
  7058.  dbsettime
  7059.  ────────────────────────────────────────────────────────────────────────────
  7060.  
  7061.  Function
  7062.  
  7063.  Sets the number of seconds that DB-LIBRARY will wait for an SQL Server
  7064.  response to a TRANSACT-SQL statement.
  7065.  
  7066.  
  7067.  Syntax
  7068.  
  7069.    RETCODE dbsettime(seconds)
  7070.  
  7071.     int  seconds;
  7072.  
  7073.  
  7074.  Comments
  7075.  
  7076.  This function sets the length of time, in seconds, that DB-LIBRARY will wait
  7077.  for an SQL Server response during calls to dbsqlexec, dbsqlok, dbresults,
  7078.  and dbnextrow. The default timeout value is 0, which represents an infinite
  7079.  timeout period.
  7080.  
  7081.  The dbsettime function can be called at any time during the
  7082.  application─before or after a call to dbopen. It takes effect immediately
  7083.  upon being called.
  7084.  
  7085.  To set a timeout value for calls to dbopen, use dbsetlogintime.
  7086.  
  7087.  Note that if an application sends a command to SQL Server using dbsqlexec,
  7088.  control is not returned to the calling application until SQL Server
  7089.  completes the processing of the command. If the application program needs to
  7090.  continue execution while SQL Server is processing the command, it should
  7091.  send the command with dbsqlsend, continue its processing, and then, when it
  7092.  is ready to retrieve the results, call dbsqlok.
  7093.  
  7094.  The program can call DBGETTIME to learn the current timeout value.
  7095.  
  7096.  
  7097.  Parameters
  7098.  
  7099.  seconds
  7100.    The timeout value─the number of seconds that DB-LIBRARY waits for an SQL
  7101.    Server response before timing out. A timeout value of 0 represents an
  7102.    infinite timeout period.
  7103.  
  7104.  
  7105.  Returns
  7106.  
  7107.  SUCCEED or FAIL.
  7108.  
  7109.  
  7110.  See Also
  7111.  
  7112.  dberrhandle, DBGETTIME, dbnextrow, dbresults, dbsetlogintime, dbsqlexec,
  7113.  dbsqlok, dbsqlsend
  7114.  
  7115.  
  7116.  dbsqlexec
  7117.  ────────────────────────────────────────────────────────────────────────────
  7118.  
  7119.  Function
  7120.  
  7121.  Sends a command batch to SQL Server.
  7122.  
  7123.  
  7124.  Syntax
  7125.  
  7126.    RETCODE dbsqlexec(dbproc)
  7127.  
  7128.     DBPROCESS *dbproc;
  7129.  
  7130.  
  7131.  Comments
  7132.  
  7133.  This function sends SQL statements, stored in the command buffer of the
  7134.  DBPROCESS, to SQL Server. Statements can be added to the DBPROCESS structure
  7135.  by calling dbcmd or dbfcmd.
  7136.  
  7137.  Once dbsqlexec has returned SUCCEED, dbresults must be called to process the
  7138.  results.
  7139.  
  7140.  The typical sequence of calls is
  7141.  
  7142.    DBINT xvariable;
  7143.     DBCHAR yvariable[10];
  7144.  
  7145.     /* Place the query into the command buffer */
  7146.     dbcmd(dbproc, "select x = 100, y = 'hello'");
  7147.  
  7148.     /* send the command buffer to SQL Server */
  7149.     dbsqlexec(dbproc);
  7150.  
  7151.     /* get ready to process the results of the query */
  7152.     dbresults(dbproc);
  7153.  
  7154.     /* bind column data to program variables */
  7155.     dbbind(dbproc, 1, INTBIND, (DBINT) 0, (BYTE *) &xvariable);
  7156.     dbbind(dbproc, 2, STRINGBIND, (DBINT) 0, yvariable);
  7157.  
  7158.     /* now process each row */
  7159.     while (dbnextrow(dbproc) != NO_MORE_ROWS)
  7160.     {
  7161.      /* C-code to print or process row data */
  7162.     }
  7163.  
  7164.  The dbsqlexec function is equivalent to dbsqlsend followed by dbsqlok.
  7165.  
  7166.  
  7167.  Parameters
  7168.  
  7169.  dbproc
  7170.    The DBPROCESS structure that is the handle for a particular
  7171.    workstation/SQL Server process. It contains all the information that
  7172.    DB-LIBRARY uses to manage communications and data between the workstation
  7173.    and SQL Server.
  7174.  
  7175.  
  7176.  Returns
  7177.  
  7178.  SUCCEED or FAIL. The most common reason for failing is a TRANSACT-SQL syntax
  7179.  error or SQL Server permission violation. Other reasons include incorrect
  7180.  column or table names. The dbsqlexec function also fails if previous results
  7181.  were not processed, or if no statement was specified.
  7182.  
  7183.  Note that if a series of commands is sent to SQL Server and if one or more
  7184.  of the commands contains syntax errors, SQL Server processes none of the
  7185.  commands, and dbsqlexec returns FAIL.
  7186.  
  7187.  
  7188.  See Also
  7189.  
  7190.  dbcmd, dbfcmd, dbnextrow, dbresults, dbsettime, dbsqlok, dbsqlsend
  7191.  
  7192.  
  7193.  dbsqlok
  7194.  ────────────────────────────────────────────────────────────────────────────
  7195.  
  7196.  Function
  7197.  
  7198.  Verifies the correctness of a command batch.
  7199.  
  7200.  
  7201.  Syntax
  7202.  
  7203.    RETCODE dbsqlok(dbproc)
  7204.  
  7205.     DBPROCESS *dbproc;
  7206.  
  7207.  
  7208.  Comments
  7209.  
  7210.  This function must be called after dbsqlsend returns SUCCEED. If dbsqlok
  7211.  returns SUCCEED, then dbresults can be called to process the results.
  7212.  
  7213.  The dbsqlok function is also useful in text update operations. When chunks
  7214.  of text are sent to SQL Server using dbwritetext and dbmoretext, dbsqlok
  7215.  must be called before the first call to dbmoretext and after the last call
  7216.  to dbmoretext. For an example of its use in this context, see "dbwritetext."
  7217.  
  7218.  
  7219.  
  7220.  Parameters
  7221.  
  7222.  dbproc
  7223.    The DBPROCESS structure that is the handle for a particular
  7224.    workstation/SQL Server process. It contains all the information that
  7225.    DB-LIBRARY uses to manage communications and data between the workstation
  7226.    and SQL Server.
  7227.  
  7228.  
  7229.  Returns
  7230.  
  7231.  SUCCEED or FAIL. The most common reason for failing is an SQL syntax error.
  7232.  
  7233.  
  7234.  
  7235.  See Also
  7236.  
  7237.  dbcmd, dbfcmd, dbmoretext, dbnextrow, dbresults, dbsettime, dbsqlexec,
  7238.  dbsqlsend, dbwritetext
  7239.  
  7240.  
  7241.  dbsqlsend
  7242.  ────────────────────────────────────────────────────────────────────────────
  7243.  
  7244.  Function
  7245.  
  7246.  Sends a command batch to SQL Server and does not wait for a response.
  7247.  
  7248.  
  7249.  Syntax
  7250.  
  7251.    RETCODE dbsqlsend(dbproc)
  7252.  
  7253.     DBPROCESS *dbproc;
  7254.  
  7255.  
  7256.  Comments
  7257.  
  7258.  This function sends SQL statements, stored in the command buffer of the
  7259.  DBPROCESS, to SQL Server. Statements can be added to the command buffer by
  7260.  calling dbcmd or dbfcmd.
  7261.  
  7262.  Once dbsqlsend returns SUCCEED, dbsqlok must be called to verify the
  7263.  accuracy of the command batch. Then dbresults can be called to process the
  7264.  results.
  7265.  
  7266.  
  7267.  Parameters
  7268.  
  7269.  dbproc
  7270.    The DBPROCESS structure that is the handle for a particular
  7271.    workstation/SQL Server process. It contains all the information that
  7272.    DB-LIBRARY uses to manage communications and data between the workstation
  7273.    and SQL Server.
  7274.  
  7275.  
  7276.  Returns
  7277.  
  7278.  SUCCEED or FAIL.
  7279.  
  7280.  
  7281.  See Also
  7282.  
  7283.  dbcmd, dbfcmd, dbnextrow, dbresults, dbsettime, dbsqlexec, dbsqlok
  7284.  
  7285.  
  7286.  dbstrcpy
  7287.  ────────────────────────────────────────────────────────────────────────────
  7288.  
  7289.  Function
  7290.  
  7291.  Copies a portion of the command buffer in the DBPROCESS structure to a
  7292.  specified memory location.
  7293.  
  7294.  
  7295.  Syntax
  7296.  
  7297.    RETCODE dbstrcpy(dbproc, start, numbytes, dest)
  7298.  
  7299.     DBPROCESS *dbproc;
  7300.     int   start;
  7301.     int   numbytes;
  7302.     char  *dest;
  7303.  
  7304.  
  7305.  Comments
  7306.  
  7307.  The copy is null-terminated. The dbstrcpy function assumes that the
  7308.  destination string is large enough to receive the source string. If not, a
  7309.  segmentation fault is likely.
  7310.  
  7311.  Internally, the command buffer is a linked list of nonterminated text
  7312.  strings. Parts of the command buffer can be located and copied using the
  7313.  dbgetchar, dbstrcpy, and dbstrlen functions.
  7314.  
  7315.  
  7316.  Parameters
  7317.  
  7318.  dbproc
  7319.    The DBPROCESS structure that is the handle for a particular
  7320.    workstation/SQL Server process. It contains all the information that
  7321.    DB-LIBRARY uses to manage communications and data between the workstation
  7322.    and SQL Server.
  7323.  
  7324.  start
  7325.    The character position in the command buffer to start copying from. The
  7326.    first character position is the 0th character. If start is greater than
  7327.    the length of the command buffer, a null terminator is inserted at
  7328.    dest[0].
  7329.  
  7330.  numbytes
  7331.    The number of characters to copy. If numbytes is less than 0, dbstrcpy
  7332.    copies the entire command buffer. It is legal to copy 0 bytes. In this
  7333.    case, a null terminator is inserted at dest[0]. If numbytes are not
  7334.    available to copy, dbstrcpy copies the number of bytes available and
  7335.    returns SUCCEED.
  7336.  
  7337.  dest
  7338.    A pointer to the memory location to copy the source string into.
  7339.  
  7340.  
  7341.  Returns
  7342.  
  7343.  SUCCEED or FAIL. FAIL is returned if start is negative.
  7344.  
  7345.  
  7346.  See Also
  7347.  
  7348.  dbcmd, dbfcmd, dbfreebuf, dbgetchar, dbstrlen
  7349.  
  7350.  
  7351.  dbstrlen
  7352.  ────────────────────────────────────────────────────────────────────────────
  7353.  
  7354.  Function
  7355.  
  7356.  Returns the length, in characters, of the command buffer.
  7357.  
  7358.  
  7359.  Syntax
  7360.  
  7361.    int dbstrlen(dbproc)
  7362.  
  7363.     DBPROCESS *dbproc;
  7364.  
  7365.  
  7366.  Comments
  7367.  
  7368.  Internally, the command buffer is a linked list of nonterminated text
  7369.  strings. Parts of the command buffer can be located and copied using the
  7370.  dbgetchar, dbstrcpy, and dbstrlen functions.
  7371.  
  7372.  
  7373.  Parameters
  7374.  
  7375.  dbproc
  7376.    The DBPROCESS structure that is the handle for a particular
  7377.    workstation/SQL Server process. It contains all the information that
  7378.    DB-LIBRARY uses to manage communications and data between the workstation
  7379.    and SQL Server.
  7380.  
  7381.  
  7382.  Returns
  7383.  
  7384.  The length, in characters, of the command buffer.
  7385.  
  7386.  
  7387.  See Also
  7388.  
  7389.  dbcmd, dbfcmd, dbfreebuf, dbgetchar, dbstrcpy
  7390.  
  7391.  
  7392.  dbtabbrowse
  7393.  ────────────────────────────────────────────────────────────────────────────
  7394.  
  7395.  Function
  7396.  
  7397.  Determines whether the specified table can be updated with the DB-LIBRARY
  7398.  browse-mode facilities.
  7399.  
  7400.  
  7401.  Syntax
  7402.  
  7403.    DBBOOL dbtabbrowse(dbproc, tabnum)
  7404.  
  7405.     DBPROCESS *dbproc;
  7406.     int   tabnum;
  7407.  
  7408.  
  7409.  Comments
  7410.  
  7411.  The dbtabbrowse function is one of the DB-LIBRARY browse-mode functions. See
  7412.  Chapter 1, "Overview of DB-LIBRARY," for a detailed discussion of browse
  7413.  mode.
  7414.  
  7415.  The dbtabbrowse function provides a way to identify tables that can be
  7416.  browsed. It is useful when examining ad hoc queries prior to performing
  7417.  browse-mode updates based on them. If the query has been hardcoded into the
  7418.  program, this function is unnecessary.
  7419.  
  7420.  For a table to be browsed it must have a unique index and a timestamp
  7421.  column.
  7422.  
  7423.  The dbtabbrowse function can be called any time after dbresults.
  7424.  
  7425.  
  7426.  Parameters
  7427.  
  7428.  dbproc
  7429.    The DBPROCESS structure that is the handle for a particular
  7430.    workstation/SQL Server process. It contains all the information that
  7431.    DB-LIBRARY uses to manage communications and data between the workstation
  7432.    and SQL Server.
  7433.  
  7434.  tabnum
  7435.    The number of the table, as specified in the SELECT statement's FROM
  7436.    clause. Table numbers start at 1.
  7437.  
  7438.  
  7439.  Returns
  7440.  
  7441.  TRUE or FALSE. If you drop the unique index of a table while browsing,
  7442.  dbtabbrowse continues to return TRUE.
  7443.  
  7444.  
  7445.  See Also
  7446.  
  7447.  dbcolbrowse, dbcolsource, dbqual, dbresults, dbtabcount, dbtabname,
  7448.  dbtabsource, dbtsnewlen, dbtsnewval, dbtsput
  7449.  
  7450.  
  7451.  dbtabcount
  7452.  ────────────────────────────────────────────────────────────────────────────
  7453.  
  7454.  Function
  7455.  
  7456.  Returns the number of tables involved in the current SELECT statement.
  7457.  
  7458.  
  7459.  Syntax
  7460.  
  7461.    int dbtabcount(dbproc)
  7462.  
  7463.     DBPROCESS *dbproc;
  7464.  
  7465.  
  7466.  Comments
  7467.  
  7468.  The dbtabcount function is one of the DB-LIBRARY browse-mode functions. See
  7469.  Chapter 1, "Overview of DB-LIBRARY," for a detailed discussion of browse
  7470.  mode.
  7471.  
  7472.  A SELECT statement can generate a set of result rows whose columns are
  7473.  derived from several database tables. To perform browse-mode updates of
  7474.  columns in a statement's select list, the application must know how many
  7475.  tables were involved in the query, because each table requires a separate
  7476.  UPDATE statement. The dbtabcount function can provide this information for
  7477.  ad hoc queries. If the query has been hardcoded into the program, this
  7478.  function is unnecessary.
  7479.  
  7480.  The count returned by this function includes any SQL Server "work tables"
  7481.  used in processing the query. The SQL Server sometimes creates temporary,
  7482.  internal work tables to process a query. It deletes these work tables by the
  7483.  time it finishes processing the statement. Work tables cannot be updated and
  7484.  are not available to the application. Therefore, before using a table
  7485.  number, the application must make sure that it does not belong to a work
  7486.  table. The dbtabname function can be used to determine whether a particular
  7487.  table number refers to a work table.
  7488.  
  7489.  The dbtabcount function can be called any time after dbresults.
  7490.  
  7491.  
  7492.  Parameters
  7493.  
  7494.  dbproc
  7495.    The DBPROCESS structure that is the handle for a particular
  7496.    workstation/SQL Server process. It contains all the information that
  7497.    DB-LIBRARY uses to manage communications and data between the workstation
  7498.    and SQL Server.
  7499.  
  7500.  
  7501.  Returns
  7502.  
  7503.  The number of tables, including SQL Server work tables, involved in the
  7504.  current set of row results. A value of -1 is returned if an invalid dbproc
  7505.  value is sent to dbtabcount.
  7506.  
  7507.  
  7508.  See Also
  7509.  
  7510.  dbcolbrowse, dbcolsource, dbqual, dbresults, dbtabbrowse, dbtabname,
  7511.  dbtabsource, dbtsnewlen, dbtsnewval, dbtsput
  7512.  
  7513.  
  7514.  dbtabname
  7515.  ────────────────────────────────────────────────────────────────────────────
  7516.  
  7517.  Function
  7518.  
  7519.  Returns the name of a table based on its number.
  7520.  
  7521.  
  7522.  Syntax
  7523.  
  7524.    char *dbtabname(dbproc, tabnum)
  7525.  
  7526.     DBPROCESS *dbproc;
  7527.     int   tabnum;
  7528.  
  7529.  
  7530.  Comments
  7531.  
  7532.  The dbtabname function is one of the DB-LIBRARY browse-mode functions. See
  7533.  Chapter 1, "Overview of DB-LIBRARY," for a detailed discussion of browse
  7534.  mode.
  7535.  
  7536.  A SELECT statement can generate a set of result rows whose columns are
  7537.  derived from several database tables. The database tables are specified by
  7538.  the FROM clause. The dbtabname function provides a way for an application to
  7539.  determine the name of each table involved in an ad hoc query. If the query
  7540.  has been hardcoded into the program, this function is unnecessary.
  7541.  
  7542.  The dbtabname function can be called any time after dbresults.
  7543.  
  7544.  
  7545.  Parameters
  7546.  
  7547.  dbproc
  7548.    The DBPROCESS structure that is the handle for a particular
  7549.    workstation/SQL Server process. It contains all the information that
  7550.    DB-LIBRARY uses to manage communications and data between the workstation
  7551.    and SQL Server.
  7552.  
  7553.  tabnum
  7554.    The number of the table. Table numbers start with 1. Use dbtabcount to
  7555.    find out the total number of tables involved in a particular statement.
  7556.  
  7557.  
  7558.  Returns
  7559.  
  7560.  A pointer to the null-terminated name of the specified table. This pointer
  7561.  is NULL if the table number is out of range or if the specified table is an
  7562.  SQL Server work table. See "dbtabcount" for a description of work tables.
  7563.  
  7564.  
  7565.  See Also
  7566.  
  7567.  dbcolbrowse, dbcolsource, dbqual, dbresults, dbtabbrowse, dbtabcount,
  7568.  dbtabsource, dbtsnewlen, dbtsnewval, dbtsput
  7569.  
  7570.  
  7571.  dbtabsource
  7572.  ────────────────────────────────────────────────────────────────────────────
  7573.  
  7574.  Function
  7575.  
  7576.  Returns the name and number of the table from which a particular result
  7577.  column was derived.
  7578.  
  7579.  
  7580.  Syntax
  7581.  
  7582.    char *dbtabsource(dbproc, colnum, tabnum)
  7583.  
  7584.     DBPROCESS *dbproc;
  7585.     int   colnum;
  7586.     int   *tabnum;
  7587.  
  7588.  
  7589.  Comments
  7590.  
  7591.  The dbtabsource function is one of the DB-LIBRARY browse-mode functions. See
  7592.  Chapter 1, "Overview of DB-LIBRARY," for a detailed discussion of browse
  7593.  mode.
  7594.  
  7595.  The dbtabsource function allows an application to determine which tables
  7596.  provided the columns in the current set of result rows. This information is
  7597.  valuable when using dbqual to construct WHERE clauses for UPDATE and DELETE
  7598.  statements based on ad hoc queries. If the query has been hardcoded into the
  7599.  program, this function is unnecessary.
  7600.  
  7601.  The dbtabsource function can be called any time after dbresults.
  7602.  
  7603.  
  7604.  Parameters
  7605.  
  7606.  dbproc
  7607.    The DBPROCESS structure that is the handle for a particular
  7608.    workstation/SQL Server process. It contains all the information that
  7609.    DB-LIBRARY uses to manage communications and data between the workstation
  7610.    and SQL Server.
  7611.  
  7612.  colnum
  7613.    The number of the result column. Column numbers start at 1.
  7614.  
  7615.  tabnum
  7616.    A pointer to an integer, which is filled in with the table's number. Many
  7617.    DB-LIBRARY functions that deal with browse mode accept either a table name
  7618.    or a table number. If dbtabsource returns NULL (see "Returns"), tabnum
  7619.    will be set to -1.
  7620.  
  7621.  
  7622.  Returns
  7623.  
  7624.  A pointer to the name of the table from which this result column was
  7625.  derived. A NULL return value can mean one of the following:
  7626.  
  7627.  
  7628.    ■   The DBPROCESS is dead or not enabled. This is an error that will cause
  7629.        an application's error handler to be invoked.
  7630.  
  7631.    ■   The column number is out of range.
  7632.  
  7633.    ■   The column is the result of an expression, such as "max(colname)".
  7634.  
  7635.  
  7636.  
  7637.  See Also
  7638.  
  7639.  dbcolbrowse, dbcolsource, dbqual, dbresults, dbtabbrowse, dbtabcount,
  7640.  dbtabname, dbtsnewlen, dbtsnewval, dbtsput
  7641.  
  7642.  
  7643.  dbtsnewlen
  7644.  ────────────────────────────────────────────────────────────────────────────
  7645.  
  7646.  Function
  7647.  
  7648.  Returns the length of the new value of the timestamp column after a
  7649.  browse-mode update.
  7650.  
  7651.  
  7652.  Syntax
  7653.  
  7654.    int dbtsnewlen(dbproc)
  7655.  
  7656.     DBPROCESS *dbproc;
  7657.  
  7658.  
  7659.  Comments
  7660.  
  7661.  The dbtsnewlen function is one of the DB-LIBRARY browse-mode functions. See
  7662.  Chapter 1, "Overview of DB-LIBRARY," for a detailed discussion of browse
  7663.  mode.
  7664.  
  7665.  The dbtsnewlen function provides information about the timestamp column. The
  7666.  WHERE clause returned by dbqual contains a call to the TSEQUAL built-in
  7667.  function. When such a WHERE clause is used in an UPDATE statement, the
  7668.  TSEQUAL function places a new value in the updated row's timestamp column
  7669.  and returns the new timestamp value to the application (if the update is
  7670.  successful). The dbtsnewlen function allows the application to save the
  7671.  length of the new timestamp value, possibly for use with dbtsput.
  7672.  
  7673.  
  7674.  Parameters
  7675.  
  7676.  dbproc
  7677.    The DBPROCESS structure that is the handle for a particular
  7678.    workstation/SQL Server process. It contains all the information that
  7679.    DB-LIBRARY uses to manage communications and data between the workstation
  7680.    and SQL Server.
  7681.  
  7682.  
  7683.  Returns
  7684.  
  7685.  The length, in bytes, of the updated row's new timestamp value. If no
  7686.  timestamp was returned to the application (because the update was
  7687.  unsuccessful or because the UPDATE statement did not contain the TSEQUAL
  7688.  built-in function), the function returns -1.
  7689.  
  7690.  
  7691.  See Also
  7692.  
  7693.  dbcolbrowse, dbcolsource, dbqual, dbtabbrowse, dbtabcount, dbtabname,
  7694.  dbtabsource, dbtsnewval, dbtsput
  7695.  
  7696.  
  7697.  dbtsnewval
  7698.  ────────────────────────────────────────────────────────────────────────────
  7699.  
  7700.  Function
  7701.  
  7702.  Returns the new value of the timestamp column after a browse-mode update.
  7703.  
  7704.  
  7705.  Syntax
  7706.  
  7707.    DBBINARY *dbtsnewval(dbproc)
  7708.  
  7709.     DBPROCESS *dbproc;
  7710.  
  7711.  
  7712.  Comments
  7713.  
  7714.  The dbtsnewval function is one of the DB-LIBRARY browse-mode functions. See
  7715.  Chapter 1, "Overview of DB-LIBRARY," for a detailed discussion of browse
  7716.  mode.
  7717.  
  7718.  The dbtsnewval function provides information about the timestamp column. The
  7719.  WHERE clause returned by dbqual contains a call to the TSEQUAL built-in
  7720.  function. When such a WHERE clause is used in an UPDATE statement, the
  7721.  TSEQUAL function places a new value in the updated row's timestamp column
  7722.  and returns the new timestamp value to the application (if the update is
  7723.  successful). This function allows the application to save the new timestamp
  7724.  value, possibly for use with dbtsput.
  7725.  
  7726.  
  7727.  Parameters
  7728.  
  7729.  dbproc
  7730.    The DBPROCESS structure that is the handle for a particular
  7731.    workstation/SQL Server process. It contains all the information that
  7732.    DB-LIBRARY uses to manage communications and data between the workstation
  7733.    and SQL Server.
  7734.  
  7735.  
  7736.  Returns
  7737.  
  7738.  A pointer to the updated row's new timestamp value. If no timestamp was
  7739.  returned to the application (possibly because the update was unsuccessful or
  7740.  because the UPDATE statement did not contain the TSEQUAL built-in function),
  7741.  the pointer is NULL.
  7742.  
  7743.  
  7744.  See Also
  7745.  
  7746.  dbcolbrowse, dbcolsource, dbqual, dbtabbrowse, dbtabcount, dbtabname,
  7747.  dbtabsource, dbtsnewlen, dbtsput
  7748.  
  7749.  
  7750.  dbtsput
  7751.  ────────────────────────────────────────────────────────────────────────────
  7752.  
  7753.  Function
  7754.  
  7755.  Puts the new value of the timestamp column into the given table's current
  7756.  row in the DBPROCESS.
  7757.  
  7758.  
  7759.  Syntax
  7760.  
  7761.    RETCODE dbtsput(dbproc, newts, newtslen, tabnum, tabname)
  7762.  
  7763.     DBPROCESS *dbproc;
  7764.     DBBINARY *newts;
  7765.     int   newtslen;
  7766.     int   tabnum;
  7767.     char  *tabname;
  7768.  
  7769.  
  7770.  Comments
  7771.  
  7772.  The dbtsput function is one of the DB-LIBRARY browse-mode functions. See
  7773.  Chapter 1, "Overview of DB-LIBRARY," for a detailed discussion of browse
  7774.  mode.
  7775.  
  7776.  The dbtsput function manipulates the timestamp column. The WHERE clause
  7777.  returned by dbqual contains a call to the TSEQUAL built-in function. When
  7778.  such a WHERE clause is used in an UPDATE statement, the TSEQUAL function
  7779.  places a new value in the updated row's timestamp column and returns the new
  7780.  timestamp value to the application (if the update is successful). If the
  7781.  same row is updated a second time, the UPDATE statement's WHERE clause must
  7782.  use the latest timestamp value. This function updates the timestamp in the
  7783.  DBPROCESS for the row currently being browsed. Then, if the application
  7784.  needs to update the row a second time, it can call dbqual to formulate a new
  7785.  WHERE clause that uses the new timestamp.
  7786.  
  7787.  
  7788.  Parameters
  7789.  
  7790.  dbproc
  7791.    The DBPROCESS structure that is the handle for a particular
  7792.    workstation/SQL Server process. It contains all the information that
  7793.    DB-LIBRARY uses to manage communications and data between the workstation
  7794.    and SQL Server. This must be the DBPROCESS used to perform the original
  7795.    SELECT query.
  7796.  
  7797.  newts
  7798.    A pointer to the new timestamp value. It is returned by dbtsnewval.
  7799.  
  7800.  newtslen
  7801.    The length of the new timestamp value. It is returned by dbtsnewlen.
  7802.  
  7803.  tabnum
  7804.    The number of the updated table. Table numbers start at 1. The tabnum must
  7805.    refer to a table that can be browsed. Use dbtabbrowse to determine whether
  7806.    it can be browsed. If this value is -1, the tabname parameter will be used
  7807.    to identify the table.
  7808.  
  7809.  tabname
  7810.    A pointer to a null-terminated table name. The tabname must refer to a
  7811.    table that can be browsed. Set this pointer to NULL if the tabnum
  7812.    parameter is used to identify the table.
  7813.  
  7814.  
  7815.  Returns
  7816.  
  7817.  SUCCEED or FAIL. The following situations cause this function to return
  7818.  FAIL:
  7819.  
  7820.  
  7821.    ■   The application tries to update the timestamp of a nonexistent row.
  7822.  
  7823.    ■   The application tries to update the timestamp, using NULL as the new
  7824.        timestamp value (newts).
  7825.  
  7826.    ■   The specified table cannot be browsed.
  7827.  
  7828.  
  7829.  
  7830.  See Also
  7831.  
  7832.  dbcolbrowse, dbcolsource, dbqual, dbtabbrowse, dbtabcount, dbtabname,
  7833.  dbtabsource, dbtsnewlen, dbtsnewval
  7834.  
  7835.  
  7836.  dbtxptr
  7837.  ────────────────────────────────────────────────────────────────────────────
  7838.  
  7839.  Function
  7840.  
  7841.  Returns the value of the text pointer for a column in the current row.
  7842.  
  7843.  
  7844.  Syntax
  7845.  
  7846.    DBBINARY *dbtxptr(dbproc, column)
  7847.  
  7848.     DBPROCESS *dbproc;
  7849.     int   column;
  7850.  
  7851.  
  7852.  Comments
  7853.  
  7854.  Every database column of type SQLTEXT or SQLIMAGE has an associated text
  7855.  pointer, which uniquely identifies the text or image value. This text
  7856.  pointer is useful in conjunction with the dbwritetext function.
  7857.  
  7858.  Text pointers are of fixed length and can be NULL in the case of a null text
  7859.  or image value.
  7860.  
  7861.  
  7862.  Parameters
  7863.  
  7864.  dbproc
  7865.    The DBPROCESS structure that is the handle for a particular
  7866.    workstation/SQL Server process. It contains all the information that
  7867.    DB-LIBRARY uses to manage communications and data between the workstation
  7868.    and SQL Server.
  7869.  
  7870.  column
  7871.    The number of the column. The first column in a table is number 1.
  7872.  
  7873.  
  7874.  Returns
  7875.  
  7876.  A DBBINARY pointer to the text pointer for the column. This pointer can be
  7877.  NULL.
  7878.  
  7879.  
  7880.  See Also
  7881.  
  7882.  dbtxtimestamp, dbwritetext
  7883.  
  7884.  
  7885.  dbtxtimestamp
  7886.  ────────────────────────────────────────────────────────────────────────────
  7887.  
  7888.  Function
  7889.  
  7890.  Returns the value of the text timestamp for a column in the current row.
  7891.  
  7892.  
  7893.  Syntax
  7894.  
  7895.    DBBINARY *dbtxtimestamp(dbproc, column)
  7896.  
  7897.     DBPROCESS *dbproc;
  7898.     int   column;
  7899.  
  7900.  
  7901.  Comments
  7902.  
  7903.  Every database column of type SQLTEXT or SQLIMAGE has an associated text
  7904.  timestamp, which marks the time of the column's last modification. The text
  7905.  timestamp is useful in conjunction with the dbwritetext function to ensure
  7906.  that two competing users do not inadvertently overwrite each other's
  7907.  modifications to the same value in the database. It is returned to the
  7908.  DBPROCESS when a TRANSACT-SQL SELECT is performed on an SQLTEXT or SQLIMAGE
  7909.  column.
  7910.  
  7911.  The length of a non-NULL text timestamp is always DBTXTSLEN (currently
  7912.  defined as eight bytes).
  7913.  
  7914.  
  7915.  Parameters
  7916.  
  7917.  dbproc
  7918.    The DBPROCESS structure that is the handle for a particular
  7919.    workstation/SQL Server process. It contains all the information that
  7920.    DB-LIBRARY uses to manage communications and data between the workstation
  7921.    and SQL Server.
  7922.  
  7923.  column
  7924.    The number of the column. The first column in a table is number 1.
  7925.  
  7926.  
  7927.  Returns
  7928.  
  7929.  A DBBINARY pointer to the text timestamp for the column. This pointer can be
  7930.  NULL.
  7931.  
  7932.  
  7933.  See Also
  7934.  
  7935.  dbtxptr, dbwritetext
  7936.  
  7937.  
  7938.  dbtxtsnewval
  7939.  ────────────────────────────────────────────────────────────────────────────
  7940.  
  7941.  Function
  7942.  
  7943.  Returns the new value of a text timestamp after a call to dbwritetext.
  7944.  
  7945.  
  7946.  Syntax
  7947.  
  7948.    DBBINARY *dbtxtsnewval(dbproc)
  7949.  
  7950.     DBPROCESS *dbproc;
  7951.  
  7952.  
  7953.  Comments
  7954.  
  7955.  Every database column of type SQLTEXT or SQLIMAGE has an associated text
  7956.  timestamp, which is updated whenever the column's value is changed. The text
  7957.  timestamp is useful in conjunction with the dbwritetext function to ensure
  7958.  that two competing users do not inadvertently overwrite each other's
  7959.  modifications to the same value in the database. It is returned to the
  7960.  DBPROCESS when a TRANSACT-SQL SELECT is performed on an SQLTEXT or SQLIMAGE
  7961.  column and can be examined by calling dbtxtimestamp.
  7962.  
  7963.  After each successful dbwritetext operation (which can include a number of
  7964.  calls to dbmoretext), SQL Server sends the updated text timestamp value back
  7965.  to DB-LIBRARY. The dbtxtsnewval function provides a way for the application
  7966.  to get this new timestamp value. The application can then use dbtxtsput to
  7967.  put the new timestamp value in the DBPROCESS for future access through
  7968.  dbtxtimestamp.
  7969.  
  7970.  The application can use dbtxtsnewval in two ways. First, the return from
  7971.  dbtxtsnewval can be used as the timestamp parameter of a dbwritetext call.
  7972.  Second, dbtxtsnewval and dbtxtsput can be used together to put the new
  7973.  timestamp value into the DBPROCESS row buffer for future access using
  7974.  dbtxtimestamp. This is particularly useful when the application is buffering
  7975.  result rows and does not need the new timestamp immediately.
  7976.  
  7977.  
  7978.  Parameters
  7979.  
  7980.  dbproc
  7981.    The DBPROCESS structure that is the handle for a particular
  7982.    workstation/SQL Server process. It contains all the information that
  7983.    DB-LIBRARY uses to manage communications and data between the workstation
  7984.    and SQL Server.
  7985.  
  7986.  
  7987.  Returns
  7988.  
  7989.  A pointer to the new text timestamp value for the SQLTEXT or SQLIMAGE value
  7990.  modified by a dbwritetext operation. This pointer can be NULL.
  7991.  
  7992.  
  7993.  See Also
  7994.  
  7995.  dbmoretext, dbtxtimestamp, dbtxtsput, dbwritetext
  7996.  
  7997.  
  7998.  dbtxtsput
  7999.  ────────────────────────────────────────────────────────────────────────────
  8000.  
  8001.  Function
  8002.  
  8003.  Puts the new value of a text timestamp into the specified column of the
  8004.  current row in the DBPROCESS.
  8005.  
  8006.  
  8007.  Syntax
  8008.  
  8009.    RETCODE dbtxtsput(dbproc, newtxts, colnum)
  8010.  
  8011.     DBPROCESS *dbproc;
  8012.     DBBINARY *newtxts;
  8013.     int   colnum;
  8014.  
  8015.  
  8016.  Comments
  8017.  
  8018.  Every database column of type SQLTEXT or SQLIMAGE has an associated text
  8019.  timestamp, which is updated whenever the column's value is changed. The text
  8020.  timestamp is useful in conjunction with the dbwritetext function to ensure
  8021.  that two competing users do not inadvertently overwrite each other's
  8022.  modifications to the same value in the database. It is returned to the
  8023.  DBPROCESS when a TRANSACT-SQL SELECT is performed on an SQLTEXT or SQLIMAGE
  8024.  column and can be examined by calling dbtxtimestamp.
  8025.  
  8026.  After each successful dbwritetext operation (which can include a number of
  8027.  calls to dbmoretext), SQL Server will send the updated text timestamp value
  8028.  back to DB-LIBRARY. The dbtxtsnewval function allows the application to get
  8029.  this new timestamp value. The application can then use dbtxtsput to put the
  8030.  new timestamp value in the DBPROCESS row buffer for future access through
  8031.  dbtxtimestamp. This is particularly useful when the application is buffering
  8032.  result rows and does not need the new timestamp immediately.
  8033.  
  8034.  
  8035.  Parameters
  8036.  
  8037.  dbproc
  8038.    The DBPROCESS structure that is the handle for a particular
  8039.    workstation/SQL Server process. It contains all the information that
  8040.    DB-LIBRARY uses to manage communications and data between the workstation
  8041.    and SQL Server.
  8042.  
  8043.  newtxts
  8044.    A pointer to the new text timestamp value. It is returned by dbtxtsnewval.
  8045.  
  8046.  colnum
  8047.    The number of the column associated with this text timestamp. Column
  8048.    numbers start at 1.
  8049.  
  8050.  
  8051.  Returns
  8052.  
  8053.  SUCCEED or FAIL.
  8054.  
  8055.  
  8056.  See Also
  8057.  
  8058.  dbmoretext, dbtxtimestamp, dbtxtsnewval, dbwritetext
  8059.  
  8060.  
  8061.  DBUNLOCKLIB (Windows only)
  8062.  ────────────────────────────────────────────────────────────────────────────
  8063.  
  8064.  Function
  8065.  
  8066.  Unlocks DB-LIBRARY segments.
  8067.  
  8068.  
  8069.  Syntax
  8070.  
  8071.    DBUNLOCKLIB()
  8072.  
  8073.  
  8074.  Comments
  8075.  
  8076.  This macro applies only to Windows application programs. It is not available
  8077.  in the MS-DOS or MS OS/2 DB-LIBRARY.
  8078.  
  8079.  This macro is the counterpart of the DBLOCKLIB macro.
  8080.  
  8081.  This macro is necessary because segments in Windows libraries move around.
  8082.  If an application (or DB-LIBRARY function) is relying on a far pointer for
  8083.  later use, the segments must remain stable. For example, if a far pointer
  8084.  value is retrieved from the dbname function, DB-LIBRARY must remain locked
  8085.  until the pointer value is no longer used by the application.
  8086.  
  8087.  The DBLOCKLIB macro locks the DB-LIBRARY segments. It should be called prior
  8088.  to calling any DB-LIBRARY functions. The DBUNLOCKLIB macro should be called
  8089.  after returning from a DB-LIBRARY function and only after the application
  8090.  uses any pointer information returned from a function call. The DBLOCKLIB
  8091.  macro can be called once, then many DB-LIBRARY functions can be called, and
  8092.  then the DB-LIBRARY segments can be unlocked with the DBUNLOCKLIB macro.
  8093.  
  8094.  Note that DB-LIBRARY can be unlocked after a call to dbopen because the
  8095.  value returned from dbopen is a near pointer used only within DB-LIBRARY.
  8096.  
  8097.  Here's a program fragment that calls DBLOCKLIB:
  8098.  
  8099.    DBPROCESS *dbproc;
  8100.     LOGINREC *login;
  8101.     char far *name;
  8102.  
  8103.     DBLOCKLIB();
  8104.     login = dblogin();
  8105.     DBSETLUSER(login, "user");
  8106.     DBSETLPWD(login, "my_password");
  8107.     DBSETLAPP(login, "my program");
  8108.     dbproc = dbopen(login, "my_server");
  8109.     DBUNLOCKLIB();
  8110.      .
  8111.      .
  8112.      .
  8113.     DBLOCKLIB();
  8114.     name = dbname(dbproc);
  8115.     /* use name */
  8116.      .
  8117.      .
  8118.      .
  8119.     /* name no longer required */
  8120.      .
  8121.      .
  8122.      .
  8123.     DBUNLOCKLIB();
  8124.      .
  8125.      .
  8126.      .
  8127.  
  8128.  
  8129.  Parameters
  8130.  
  8131.  None.
  8132.  
  8133.  
  8134.  Returns
  8135.  
  8136.  None.
  8137.  
  8138.  
  8139.  See Also
  8140.  
  8141.  DBLOCKLIB, dbname, dbopen
  8142.  
  8143.  
  8144.  dbuse
  8145.  ────────────────────────────────────────────────────────────────────────────
  8146.  
  8147.  Function
  8148.  
  8149.  Uses a particular database.
  8150.  
  8151.  
  8152.  Syntax
  8153.  
  8154.    RETCODE dbuse(dbproc, dbname)
  8155.  
  8156.     DBPROCESS *dbproc;
  8157.     char  *dbname;
  8158.  
  8159.  
  8160.  Comments
  8161.  
  8162.  This function executes a TRANSACT-SQL USE statement for the specified
  8163.  database for a particular DBPROCESS. It sets up the statement and calls
  8164.  dbsqlexec and dbresults.
  8165.  
  8166.  If the USE statement fails because the requested database has not yet
  8167.  completed a recovery process, dbuse continues to send USE statements at one
  8168.  second intervals until it either succeeds or encounters some other error.
  8169.  
  8170.  The function uses the dbproc provided by the caller and its command buffer.
  8171.  Any existing statements in the buffer are lost, and the command buffer is
  8172.  cleared by dbuse when it is finished.
  8173.  
  8174.  
  8175.  Parameters
  8176.  
  8177.  dbproc
  8178.    The DBPROCESS structure that is the handle for a particular
  8179.    workstation/SQL Server process. It contains all the information that
  8180.    DB-LIBRARY uses to manage communications and data between the workstation
  8181.    and SQL Server.
  8182.  
  8183.  dbname
  8184.    A character pointer to a null-terminated string to be used as the database
  8185.    name.
  8186.  
  8187.  
  8188.  Returns
  8189.  
  8190.  SUCCEED or FAIL.
  8191.  
  8192.  
  8193.  See Also
  8194.  
  8195.  dbresults, dbsqlexec
  8196.  
  8197.  
  8198.  dbwillconvert
  8199.  ────────────────────────────────────────────────────────────────────────────
  8200.  
  8201.  Function
  8202.  
  8203.  Determines whether a specific datatype conversion is available within
  8204.  DB-LIBRARY.
  8205.  
  8206.  
  8207.  Syntax
  8208.  
  8209.    DBBOOL dbwillconvert(srctype, desttype)
  8210.  
  8211.     int  srctype;
  8212.     int  desttype;
  8213.  
  8214.  
  8215.  Comments
  8216.  
  8217.  When dbconvert is asked to perform a conversion that it doesn't support, it
  8218.  calls a user-supplied error handler (if any) and returns -1.
  8219.  
  8220.  The dbconvert function can convert data stored in any of the SQL Server
  8221.  datatypes (not all conversions are allowable):
  8222.  
  8223. ╓┌─────────────────────────────────┌─────────────────────────────────────────╖
  8224.  SQL Server Datatype               Program Variable Type
  8225.  ────────────────────────────────────────────────────────────────────────────
  8226.  SQLCHAR                           DBCHAR
  8227.  
  8228.  SQLTEXT                           DBCHAR
  8229.  
  8230.  SQLBINARY                         DBBINARY
  8231.  
  8232.  SQLIMAGE                          DBBINARY
  8233.  
  8234.  SQL Server Datatype               Program Variable Type
  8235.  ────────────────────────────────────────────────────────────────────────────
  8236. 
  8237.  SQLINT1                           DBTINYINT
  8238.  
  8239.  SQLINT2                           DBSMALLINT
  8240.  
  8241.  SQLINT4                           DBINT
  8242.  
  8243.  SQLFLT8                           DBFLT8
  8244.  
  8245.  SQLBIT                            DBBIT
  8246.  
  8247.  SQLMONEY                          DBMONEY
  8248.  
  8249.  SQLDATETIME                       DBDATETIME
  8250.  
  8251.  ────────────────────────────────────────────────────────────────────────────
  8252.  
  8253.  
  8254.  
  8255.  The following table lists the datatype conversions that dbconvert supports.
  8256.  The source datatypes are listed down the leftmost column and the destination
  8257.  datatypes are listed along the top row of the table. (For brevity, the
  8258.  prefix "SQL" has been eliminated from each datatype.)
  8259.  
  8260. ╓┌─────────┌───────┌───────┌───────┌───────┌───────┌───────┌───────┌───────┌─
  8261.  ────────────────────────────────────────────────────────────────────────────
  8262.  TO:       char    text    binary  image   int1    int2    int4    flt8    bit
  8263.  
  8264.  FROM:
  8265.  
  8266.  char      T       T       T       T       T       T       T       T       T
  8267.  
  8268.  text      T       T       T       T       T       T       T       T       T
  8269.  
  8270.  binary    T       T       T       T       T       T       T       T       T
  8271.  
  8272.  image     T       T       T       T       T       T       T       T       T
  8273.  
  8274.  int1      T       T       T       T       T       T       T       T       T
  8275.  
  8276.  ────────────────────────────────────────────────────────────────────────────
  8277. 
  8278.  int2      T       T       T       T       T       T       T       T       T
  8279.  
  8280.  int4      T       T       T       T       T       T       T       T       T
  8281.  
  8282.  flt8      T       T       T       T       T       T       T       T       T
  8283.  
  8284.  bit       T       T       T       T       T       T       T       T       T
  8285.  
  8286.  money     T       T       T       T       T       T       T       T       T
  8287.  
  8288.  datetime  T       T       T       T       F       F       F       F       F
  8289.  
  8290.  ────────────────────────────────────────────────────────────────────────────
  8291.  
  8292.  
  8293.  
  8294.  See "dbconvert" for more information on datatype conversions.
  8295.  
  8296.  
  8297.  Parameters
  8298.  
  8299.  srctype
  8300.    The datatype of the data which is to be converted. This parameter can be
  8301.    any of the SQL Server datatypes.
  8302.  
  8303.  desttype
  8304.    The datatype that the source data is to be converted into. This parameter
  8305.    can be any of the SQL Server datatypes.
  8306.  
  8307.  
  8308.  Returns
  8309.  
  8310.  TRUE if the datatype conversion is supported; FALSE if the conversion is not
  8311.  supported.
  8312.  
  8313.  
  8314.  See Also
  8315.  
  8316.  dbaltbind, dbbind, dbconvert, Appendix C
  8317.  
  8318.  
  8319.  dbwinexit (Windows only)
  8320.  ────────────────────────────────────────────────────────────────────────────
  8321.  
  8322.  Function
  8323.  
  8324.  Under Windows, informs DB-LIBRARY that the application is about to exit.
  8325.  
  8326.  
  8327.  Syntax
  8328.  
  8329.    void dbwinexit()
  8330.  
  8331.  
  8332.  Comments
  8333.  
  8334.  This function informs DB-LIBRARY that the Windows application calling it is
  8335.  about to exit. When running under Windows, DB-LIBRARY maintains information
  8336.  about each application that has referenced it. DB-LIBRARY creates the
  8337.  information when a library application calls dbinit; it does this in order
  8338.  to prevent conflicts between applications that utilize DB-LIBRARY
  8339.  concurrently. In order for DB-LIBRARY to release this information, the
  8340.  application must call dbwinexit just before it exits. You should put the
  8341.  call to dbwinexit within the message handling code for the WM_DESTROY
  8342.  message. For example:
  8343.  
  8344.    case WM_DESTROY:
  8345.      dbwinexit();
  8346.      break;
  8347.  
  8348.  This call releases the memory DB-LIBRARY allocated to keep track of this
  8349.  application and makes that memory available to other applications. It is not
  8350.  necessary to call DBLOCKLIB before calling dbwinexit.
  8351.  
  8352.  ────────────────────────────────────────────────────────────────────────────
  8353.  NOTE
  8354.  
  8355.  Once your application has called dbwinexit, it cannot call any other
  8356.  DB-LIBRARY function except DBUNLOCKLIB. If you have called dbwinexit and
  8357.  then need to issue one or more DB-LIBRARY calls, you must again call dbinit
  8358.  to re-register your application.
  8359.  ────────────────────────────────────────────────────────────────────────────
  8360.  
  8361.  
  8362.  Parameters
  8363.  
  8364.  None.
  8365.  
  8366.  
  8367.  Returns
  8368.  
  8369.  None.
  8370.  
  8371.  
  8372.  See Also
  8373.  
  8374.  dbinit, DBUNLOCKLIB
  8375.  
  8376.  
  8377.  dbwritepage
  8378.  ────────────────────────────────────────────────────────────────────────────
  8379.  
  8380.  Function
  8381.  
  8382.  Writes a page of binary data to SQL Server.
  8383.  
  8384.  
  8385.  Syntax
  8386.  
  8387.    RETCODE dbwritepage(dbproc, dbname, pageno, size, buf)
  8388.  
  8389.     DBPROCESS *dbproc;
  8390.     char  *dbname;
  8391.     DBINT  pageno;
  8392.     DBINT  size;
  8393.     BYTE  buf[];
  8394.  
  8395.  
  8396.  Comments
  8397.  
  8398.  The dbwritepage function writes a page of binary data to SQL Server. This
  8399.  function is primarily useful for examining and repairing damaged database
  8400.  pages. After calling dbwritepage, the DBPROCESS may contain some error or
  8401.  informational messages from SQL Server. These messages can be accessed
  8402.  through a user-supplied message handler.
  8403.  
  8404.  
  8405.  Parameters
  8406.  
  8407.  dbproc
  8408.    The DBPROCESS structure that is the handle for a particular
  8409.    workstation/SQL Server process. It contains all the information that
  8410.    DB-LIBRARY uses to manage communications and data between the workstation
  8411.    and SQL Server.
  8412.  
  8413.  dbname
  8414.    The name of the database.
  8415.  
  8416.  pageno
  8417.    The number of the database page to be written.
  8418.  
  8419.  size
  8420.    The number of bytes to be written to SQL Server. Currently, SQL Server
  8421.    database pages are 2048 bytes long.
  8422.  
  8423.  buf
  8424.    A pointer to a buffer that holds the data to be written.
  8425.  
  8426.  
  8427.  Returns
  8428.  
  8429.  SUCCEED or FAIL.
  8430.  
  8431.  
  8432.  See Also
  8433.  
  8434.  dbmsghandle, dbreadpage
  8435.  
  8436.  
  8437.  dbwritetext
  8438.  ────────────────────────────────────────────────────────────────────────────
  8439.  
  8440.  Function
  8441.  
  8442.  Sends a text or image value to SQL Server.
  8443.  
  8444.  
  8445.  Syntax
  8446.  
  8447.    RETCODE dbwritetext(dbproc, objname, textptr, textptrlen,
  8448.      timestamp, log, size, text)
  8449.  
  8450.     DBPROCESS *dbproc;
  8451.     char  *objname;
  8452.     DBBINARY *textptr;
  8453.     DBTINYINT textptrlen;
  8454.     DBBINARY *timestamp;
  8455.     DBBOOL  log;
  8456.     DBINT  size;
  8457.     BYTE  *text;
  8458.  
  8459.  
  8460.  Comments
  8461.  
  8462.  This function is used to update text and image values, allowing the
  8463.  application to send long values to SQL Server without having to copy them
  8464.  into a TRANSACT-SQL UPDATE statement. In addition, this function gives
  8465.  applications access to the text timestamp mechanism, which can be used to
  8466.  ensure that two competing users do not inadvertently overwrite each other's
  8467.  modifications to the same value in the database.
  8468.  
  8469.  The dbwritetext function succeeds only if its timestamp parameter, usually
  8470.  obtained when the column's value was originally retrieved, matches the text
  8471.  column's timestamp in the database. If a match does occur, dbwritetext
  8472.  updates the text column, and at the same time updates the column's
  8473.  timestamp. This has the effect of governing updates by competing
  8474.  applications─an application's dbwritetext call fails if a second application
  8475.  updated the text column between the time the first application retrieved the
  8476.  column and the time it made its dbwritetext call.
  8477.  
  8478.  The dbwritetext function is similar to the TRANSACT-SQL WRITETEXT statement.
  8479.  It is usually more efficient to call dbwritetext than to send a WRITETEXT
  8480.  statement through the command buffer. For information on WRITETEXT, see the
  8481.  SQL Server Language Reference.
  8482.  
  8483.  The dbwritetext function can be invoked with or without logging, according
  8484.  to the value of the log parameter. To use dbwritetext with logging turned
  8485.  off, the database option select into/bulkcopy must be set to true, as shown
  8486.  in the following:
  8487.  
  8488.    sp_dboption 'mbdb', 'select into/bulk', 'true'
  8489.  
  8490.  This function, in conjunction with the dbmoretext function, also allows the
  8491.  application to send a large text or image value to SQL Server in the form of
  8492.  a number of smaller chunks. This is particularly useful with operating
  8493.  systems unable to allocate extremely long data buffers. No single block of
  8494.  text can be longer than 64K bytes; DB-LIBRARY does not support huge
  8495.  pointers.
  8496.  
  8497.  If the text parameter is a non-null value, dbwritetext executes the data
  8498.  transfer from start to finish, including any necessary calls to dbsqlok and
  8499.  dbresults. Here's a code fragment that illustrates this simple use of
  8500.  dbwritetext:
  8501.  
  8502.    LOGINREC *login;
  8503.     DBPROCESS *q_dbproc;
  8504.     DBPROCESS *u_dbproc;
  8505.     DBCHAR abstract_var[512];
  8506.  
  8507.     /* Open separate DBPROCESSes for querying and updating.
  8508.     ** This is not strictly necessary in this example, which
  8509.     ** retrieves only one row. However, this approach becomes
  8510.     ** essential when performing updates on multiple rows of
  8511.     ** retrieved data.
  8512.     */
  8513.  
  8514.     login = dblogin();
  8515.     DBSETLUSER(login, "user");
  8516.     DBSETLPWD(login, "my_passwd");
  8517.     DBSETLAPP(login, "example1");
  8518.     q_dbproc = dbopen(login, "my_server");
  8519.     u_dbproc = dbopen(login, "my_server");
  8520.  
  8521.     /* The database column "abstract" is a text column. Retrieve the
  8522.     ** value of one of its rows.
  8523.     */
  8524.     dbcmd(q_dbproc, "select abstract from articles where article_id = 10");
  8525.     dbsqlexec(q_dbproc);
  8526.     dbresults(q_dbproc);
  8527.     dbbind(q_dbproc, 1, STRINGBIND, (DBINT)0, abstract_var);
  8528.  
  8529.     /* For simplicity, we'll assume that just one row is returned. */
  8530.     dbnextrow(q_dbproc);
  8531.  
  8532.     /* Here we can change the value of "abstract_var". For instance ... */
  8533.     strcpy(abstract_var, "A brand new value.");
  8534.  
  8535.     /* Update the text column. */
  8536.     dbwritetext
  8537.      (u_dbproc, "articles.abstract", dbtxptr(q_dbproc, 1), DBTXPLEN,
  8538.      dbtxtimestamp(q_dbproc, 1), TRUE, (DBINT)strlen(abstract_var),
  8539.      abstract_var);
  8540.  
  8541.     /* We're all done. */
  8542.     dbexit();
  8543.  
  8544.  To send chunks of text or image, rather than the whole value at once, set
  8545.  the text parameter to NULL. Then, dbwritetext will return control to the
  8546.  application immediately after notifying SQL Server that a text transfer is
  8547.  about to begin. The actual text is sent to SQL Server with dbmoretext, which
  8548.  can be called multiple times, once for each chunk. Here's a code fragment
  8549.  that illustrates the use of dbwritetext with dbmoretext:
  8550.  
  8551.    LOGINREC *login;
  8552.     DBPROCESS *q_dbproc;
  8553.     DBPROCESS *u_dbproc;
  8554.     DBCHAR part1[512];
  8555.     static DBCHAR part2[512] = " This adds another sentence to the text.";
  8556.  
  8557.     login = dblogin();
  8558.     DBSETLUSER(login, "user");
  8559.     DBSETLPWD(login, "my_passwd");
  8560.     DBSETLAPP(login, "example2");
  8561.     q_dbproc = dbopen(login, "my_server");
  8562.     u_dbproc = dbopen(login, "my_server");
  8563.  
  8564.     dbcmd(q_dbproc, "select abstract from articles where article_id = 10");
  8565.     dbsqlexec(q_dbproc);
  8566.     dbresults(q_dbproc);
  8567.     dbbind(q_dbproc, 1, STRINGBIND, (DBINT)0, part1);
  8568.  
  8569.     /* For simplicity, we'll assume that just one row is returned. */
  8570.     dbnextrow(q_dbproc);
  8571.  
  8572.     /*
  8573.     ** Here we can change the value of the part of the text column. In
  8574.     ** this example, we will merely add a sentence to the end of the
  8575.     ** existing text.
  8576.     */
  8577.  
  8578.     /* Update the text column. */
  8579.     dbwritetext(u_dbproc, "articles.abstract", dbtxptr(q_dbproc, 1),
  8580.  DBTXPLEN,
  8581.     dbtxtimestamp(q_dbproc, 1), TRUE, (DBINT)(strlen(part1) + strlen(part2)),
  8582.  NULL);
  8583.  
  8584.     dbsqlok(u_dbproc);
  8585.     dbresults(u_dbproc);
  8586.  
  8587.     /* Send the update value in chunks. */
  8588.     dbmoretext(u_dbproc, (DBINT)strlen(part1), part1);
  8589.     dbmoretext(u_dbproc, (DBINT)strlen(part2), part2);
  8590.  
  8591.     dbsqlok(u_dbproc);
  8592.     dbresults(u_dbproc);
  8593.  
  8594.     dbexit();
  8595.  
  8596.  ────────────────────────────────────────────────────────────────────────────
  8597.  NOTE
  8598.  
  8599.  Notice the required calls to dbsqlok and dbresults, between the call to
  8600.  dbwritetext and the first call to dbmoretext and after the final call to
  8601.  dbmoretext.
  8602.  ────────────────────────────────────────────────────────────────────────────
  8603.  
  8604.  When dbwritetext is used with dbmoretext, it locks the specified database
  8605.  text column. The lock is not released until the final dbmoretext has sent
  8606.  its data. This ensures that a second application does not read or update the
  8607.  text column in the midst of the first application's update.
  8608.  
  8609.  
  8610.  Parameters
  8611.  
  8612.  dbproc
  8613.    The DBPROCESS structure that is the handle for a particular
  8614.    workstation/SQL Server process. It contains all the information that
  8615.    DB-LIBRARY uses to manage communications and data between the workstation
  8616.    and SQL Server.
  8617.  
  8618.  objname
  8619.    The database table and column name. The table and the column should be
  8620.    separated by a period.
  8621.  
  8622.  textptr
  8623.    The text pointer of the text or image value to be modified. This can be
  8624.    obtained by calling dbtxptr.
  8625.  
  8626.  textptrlen
  8627.    This parameter is included for future compatibility. For now, its value
  8628.    must be the defined constant DBTXPLEN.
  8629.  
  8630.  timestamp
  8631.    The text timestamp of the text or image value to be modified. This can be
  8632.    obtained by calling dbtxtimestamp. This value changes whenever the text or
  8633.    image value itself is changed.
  8634.  
  8635.  log
  8636.    A boolean value, specifying whether this dbwritetext operation should be
  8637.    recorded in the transaction log.
  8638.  
  8639.  size
  8640.    The total size, in bytes, of the text or image value to be written.
  8641.  
  8642.  text
  8643.    A pointer to the text or image to be written. If this pointer is NULL,
  8644.    DB-LIBRARY expects the application to call dbmoretext one or more times
  8645.    until all size bytes of data have been sent to SQL Server. No single data
  8646.    block can be larger than 64K bytes. DB-LIBRARY does not support huge
  8647.    pointers.
  8648.  
  8649.  
  8650.  Returns
  8651.  
  8652.  SUCCEED or FAIL.
  8653.  
  8654.  
  8655.  See Also
  8656.  
  8657.  dbmoretext, dbresults, dbsqlok, dbtxptr, dbtxtimestamp, dbtxtsnewval,
  8658.  dbtxtsput
  8659.  
  8660.  
  8661.  
  8662.  
  8663.  
  8664.  
  8665.  Chapter 3  Example Programs
  8666.  ────────────────────────────────────────────────────────────────────────────
  8667.  
  8668.  
  8669.  Introduction
  8670.  
  8671.  The examples in this chapter illustrate typical uses for DB-LIBRARY
  8672.  functions in C programs. Note the following:
  8673.  
  8674.  
  8675.    ■   The header files sqlfront.h and sqldb.h are required and must be
  8676.        included in that order.
  8677.  
  8678.    ■   Before any calls to SQL Server are made, the application must connect
  8679.        to SQL Server with a call to dbopen, which returns a pointer to the
  8680.        DBPROCESS structure.
  8681.  
  8682.    ■   Normally, the first part of the program sends a set of SQL statements
  8683.        to SQL Server to retrieve some data. Then the information statements
  8684.        returned from SQL Server are bound or copied to program variables.
  8685.  
  8686.    ■   After all processing is complete, the application must call dbclose or
  8687.        dbexit to close the connection to SQL Server and free the DBPROCESS
  8688.        structures.
  8689.  
  8690.  
  8691.  The DB-LIBRARY sample code and a small data file are supplied with your
  8692.  DB-LIBRARY release in the sql\dblib\samples directory. You can copy the
  8693.  sample files into one of your directories to run them. Your system should
  8694.  have access to an SQL Server that includes the pubs sample database. See
  8695.  your System Administrator for instructions on creating the sample database
  8696.  if you do not have access to it.
  8697.  
  8698.  When you type these examples, replace the string "user" with your username,
  8699.  "my_password" with your SQL Server password, and the string "my_server" with
  8700.  the name of your server. Example 2 expects a file named datafile (supplied)
  8701.  and assumes that you have CREATE DATABASE permission on your server as well
  8702.  as enough space to create a small database.
  8703.  
  8704.  For information on compiling and linking the example programs, see Appendix
  8705.  E, "Building Applications." Note that the examples in this chapter apply
  8706.  only to the MS-DOS and MS OS/2 environments and will not work properly in
  8707.  the Windows environment. See Appendix E, "Building Applications," for
  8708.  information on building DB-LIBRARY Windows applications.
  8709.  
  8710.  
  8711.  Examples
  8712.  
  8713.  
  8714.  Sending Queries in a Command Batch
  8715.  
  8716.    /*
  8717.    ** This example illustrates how to send two queries to
  8718.    ** SQL Server in a command batch. It binds each set
  8719.    ** of results and prints the rows.
  8720.    */
  8721.  
  8722.    #define DBMSOS2
  8723.    #include <stdio.h>
  8724.    #include <sqlfront.h>
  8725.    #include <sqldb.h>
  8726.  
  8727.    #define DATELEN 26
  8728.    #define TYPELEN 2
  8729.    #define STDEXIT 0
  8730.  
  8731.    /* Forward declarations of the error handler and message handler.
  8732.    */
  8733.    int err_handler();
  8734.    int msg_handler();
  8735.  
  8736.    main(argc, argv)
  8737.    int argc;
  8738.    char *argv[];
  8739.    {
  8740.     DBPROCESS *dbproc; /* Our connection with SQL Server. */
  8741.     LOGINREC *login; /* Our login information. */
  8742.  
  8743.     /* These are the variables used to store the returning data. */
  8744.  
  8745.     DBCHAR crdate[DATELEN+1];
  8746.     DBINT id;
  8747.     DBCHAR name[MAXNAME+1]; /* MAXNAME is defined in
  8748.     * "sqldb.h" as the maximum
  8749.     * length for names of database
  8750.     * objects, such as tables,
  8751.     * columns, and procedures.
  8752.     */
  8753.     DBCHAR type[TYPELEN+1];
  8754.     RETCODE result_code;
  8755.  
  8756.    /* Install the user-supplied error-handling and message-handling
  8757.     * functions. They are defined at the bottom of this source file.
  8758.     */
  8759.     dberrhandle(err_handler);
  8760.     dbmsghandle(msg_handler);
  8761.  
  8762.     /*
  8763.     ** Get a LOGINREC structure and fill it with the necessary
  8764.     ** login information.
  8765.     */
  8766.  
  8767.     login = dblogin();
  8768.     DBSETLUSER(login, "user");
  8769.     DBSETLPWD(login, "my_passwd");
  8770.     DBSETLAPP(login, "example1");
  8771.  
  8772.     /*
  8773.     ** Get a DBPROCESS structure for communicating with SQL Server.
  8774.     */
  8775.  
  8776.     dbproc = dbopen(login, "my_server");
  8777.  
  8778.     /*
  8779.     ** We are going to retrieve some information from a table
  8780.     ** named "sysobjects", regarding names of system tables and
  8781.     ** stored procedures.
  8782.     ** We will submit two queries. The first finds all the rows
  8783.     ** that describe system tables. The second finds all the rows
  8784.     ** that describe stored procedures. The program will only look
  8785.     ** at the first 10 rows that describe stored procedures.
  8786.     */
  8787.  
  8788.     /* First, put the commands into the command buffer. */
  8789.  
  8790.     dbcmd(dbproc, "select name, type, id, crdate from sysobjects");
  8791.     dbcmd(dbproc, " where type = 'S' ");
  8792.     dbcmd(dbproc, "select name, type, id, crdate from sysobjects");
  8793.     dbcmd(dbproc, " where type = 'P' ");
  8794.  
  8795.     /*
  8796.     ** SQL Server processes the command batch in the following
  8797.     ** order:
  8798.     **
  8799.     ** 1) It checks for syntax errors (i.e., "use database pubs"
  8800.     **  is syntactically incorrect; it should be "use pubs").
  8801.     ** 2) The second check is a semantic check (i.e., "select * from
  8802.     **  titels" is incorrect because the spelling should be
  8803.     **  "titles".)
  8804.     ** 3) The third check occurs in the actual execution phase. This
  8805.     ** check involves issues like permissions or memory problems.
  8806.     **
  8807.     ** In the execution phase, dbsqlexec() and dbresults() can return
  8808.     ** the value "SUCCEED", which means there are more commands in the
  8809.     ** batch to process and that command was successful. A value
  8810.     ** of "FAIL" means that the query failed but there may be more
  8811.     ** commands in the batch to process. A value of "NO_MORE_RESULTS"
  8812.     ** means that there are no more commands in the batch to process.
  8813.     ** Therefore, the programmer must check the return values after
  8814.     ** dbsqlexec() and dbresults(), as illustrated below.
  8815.     **
  8816.     */
  8817.  
  8818.     /* Send the commands to SQL Server and start execution. */
  8819.     dbsqlexec(dbproc);
  8820.  
  8821.     /* Process each command until there are no more. */
  8822.  
  8823.     while ((result_code = dbresults(dbproc)) != NO_MORE_RESULTS)
  8824.     {
  8825.      if (result_code == SUCCEED)
  8826.      {
  8827.       /* Bind program variables. */
  8828.  
  8829.       dbbind(dbproc, 1, NTBSTRINGBIND, (DBINT) 0, name);
  8830.       dbbind(dbproc, 2, NTBSTRINGBIND, (DBINT) 0, type);
  8831.       dbbind(dbproc, 3, INTBIND, (DBINT) 0, (BYTE *) &id);
  8832.       dbbind(dbproc, 4, NTBSTRINGBIND, (DBINT) 0, crdate);
  8833.  
  8834.       /* Print appropriate header for the type of
  8835.       * data coming back.
  8836.       */
  8837.  
  8838.       printf("\n %s Objects: \n\n",
  8839.       DBCURCMD(dbproc) == 1 ? "System Table": "Procedure");
  8840.  
  8841.       /* Now print the rows. */
  8842.  
  8843.       while (dbnextrow(dbproc) != NO_MORE_ROWS)
  8844.       {
  8845.        /*
  8846.        ** If this is the 2nd command and
  8847.        ** 10th row, flush the rest of the
  8848.        ** rows for that command.
  8849.        */
  8850.  
  8851.    if ((DBCURCMD(dbproc) == 2)
  8852.        && (DBCURROW(dbproc)  10))
  8853.                continue;
  8854.  
  8855.        printf
  8856.        ("%s %s %ld %s\n", name, type, id, crdate);
  8857.       }
  8858.      }
  8859.     }
  8860.  
  8861.  
  8862.     /* Close our connection and exit the program. */
  8863.  
  8864.     dbexit();
  8865.     exit(STDEXIT);
  8866.    }
  8867.  
  8868.    int err_handler(dbproc, severity, dberr, oserr, dberrstr, oserrstr)
  8869.    DBPROCESS *dbproc;
  8870.    int severity;
  8871.    int dberr;
  8872.    int oserr;
  8873.    char *dberrstr;
  8874.    char *oserrstr;
  8875.    {
  8876.     if ((dbproc == NULL) || (DBDEAD(dbproc)))
  8877.      return(INT_EXIT);
  8878.     else
  8879.     {
  8880.      printf("DB-LIBRARY error:\n\t%s\n", dberrstr);
  8881.  
  8882.     if (oserr != DBNOERR)
  8883.      printf("Operating-system error:\n\t%s\n", oserrstr);
  8884.  
  8885.     return(INT_CANCEL);
  8886.     }
  8887.    }
  8888.  
  8889.    int msg_handler(dbproc, msgno, msgstate, severity, msgtext)
  8890.    DBPROCESS *dbproc;
  8891.    DBINT msgno;
  8892.    int msgstate;
  8893.    int severity;
  8894.    char *msgtext;
  8895.  
  8896.    {
  8897.     printf
  8898.     ("SQL Server message %ld, state %d, severity %d:\n\t%s\n",
  8899.     msgno, msgstate, severity, msgtext);
  8900.     return(0);
  8901.    }
  8902.  
  8903.  
  8904.  Working with Data Files
  8905.  
  8906.    /*
  8907.    ** This example opens a data file, inserts data from the file
  8908.    ** into a newly created table containing several of the
  8909.    ** SQL Server datatypes, and binds and prints the results.
  8910.    ** You must have a file named datafile and CREATE DATABASE
  8911.    ** permission in your login database. Also you must have enough room
  8912.    ** in your default device to create a new database (minimum 2Mb).
  8913.    */
  8914.  
  8915.    #define DBMSOS2
  8916.    #include <stdio.h>
  8917.    #include <sqlfront.h>
  8918.    #include <sqldb.h>
  8919.  
  8920.    #define STDEXIT 0
  8921.    #define BUFLEN 2048
  8922.    #define HEXLEN 510
  8923.    #define PLEN 25
  8924.  
  8925.    /* Forward declarations of the error-handling and message-handling
  8926.  functions.
  8927.    */
  8928.    int err_handler();
  8929.    int msg_handler();
  8930.  
  8931.    main(argc,argv)
  8932.    int argc;
  8933.    char *argv[];
  8934.    {
  8935.  
  8936.     LOGINREC *login;
  8937.     DBPROCESS *dbproc;
  8938.     RETCODE return_code;
  8939.  
  8940.     DBTINYINT age;
  8941.     DBSMALLINT userid;
  8942.     DBINT royalty;
  8943.     DBCHAR name[PLEN+1];
  8944.     DBBINARY title_id[PLEN+1];
  8945.     DBBIT us_citizen;
  8946.     DBFLT8 account;
  8947.     DBCHAR title[PLEN+1]; /* string */
  8948.     DBCHAR manager[PLEN+1]; /* ntbstring */
  8949.     DBCHAR id_buffer[HEXLEN+1];
  8950.  
  8951.     static char cmdbuf[BUFLEN];
  8952.     FILE *infile;
  8953.  
  8954.     /* Install the user-supplied error-handling and message-handling
  8955.     * functions. They are defined at the bottom of this source file.
  8956.     */
  8957.     dberrhandle(err_handler);
  8958.     dbmsghandle(msg_handler);
  8959.  
  8960.     /* Allocate and initialize the LOGINREC structure to be used
  8961.     * to open a connection to SQL Server.
  8962.     */
  8963.  
  8964.     login = dblogin();
  8965.     DBSETLUSER(login, "user");
  8966.     DBSETLPWD(login, "my_passwd");
  8967.     DBSETLAPP(login, "example2");
  8968.  
  8969.     dbproc = dbopen(login, "my_server");
  8970.     printf("Creating the 'test' database.\n");
  8971.     dbcmd(dbproc,"create database test ");
  8972.     dbsqlexec(dbproc);
  8973.     dbresults(dbproc);
  8974.     dbuse(dbproc,"test");
  8975.     printf("Creating the 'alltypes' table.\n");
  8976.  
  8977.     /* Create a table that contains several SQL Server datatypes. */
  8978.     dbcmd(dbproc,"create table alltypes ");
  8979.     dbcmd(dbproc,"(age tinyint,");
  8980.     dbcmd(dbproc,"userid smallint,");
  8981.     dbcmd(dbproc,"royalty int,");
  8982.     dbcmd(dbproc,"name char(25),");
  8983.     dbcmd(dbproc,"title_id varbinary(20),");
  8984.     dbcmd(dbproc,"us_citizen bit,");
  8985.     dbcmd(dbproc,"account float,");
  8986.     dbcmd(dbproc,"title varchar(20),");
  8987.     dbcmd(dbproc,"manager char(25))");
  8988.     dbsqlexec(dbproc);
  8989.     dbresults(dbproc);
  8990.  
  8991.     /* Insert rows of data into the newly created table "alltypes".
  8992.     * We will read in the contents of the file and form an
  8993.     * INSERT statement.
  8994.     */
  8995.  
  8996.     if ((infile=fopen("datafile","r")) == NULL)
  8997.     {
  8998.      printf("Unable to open file 'datafile'.\n");
  8999.      exit(STDEXIT);
  9000.     }
  9001.  
  9002.     printf("Inserting rows into the 'alltypes' table.\n");
  9003.  
  9004.     while ((fgets(cmdbuf,BUFLEN,infile)) != NULL)
  9005.     {
  9006.      dbfcmd(dbproc,"insert into alltypes \n");
  9007.      dbfcmd(dbproc,"values(%s) \n",cmdbuf);
  9008.     }
  9009.     dbsqlexec(dbproc);
  9010.  
  9011.     /* Process the results of each of the INSERT statements. */
  9012.     while ((return_code = dbresults(dbproc)) != NO_MORE_RESULTS)
  9013.     {
  9014.      if (return_code == FAIL)
  9015.       printf("One of the insert statements failed.\n");
  9016.     }
  9017.     printf("Selecting rows from the 'alltypes' table:\n");
  9018.     dbcmd(dbproc,"select * from alltypes");
  9019.     dbsqlexec(dbproc);
  9020.  
  9021.     while ((return_code = dbresults(dbproc)) != NO_MORE_RESULTS)
  9022.     {
  9023.      if (return_code == SUCCEED)
  9024.      {
  9025.       dbbind(dbproc,1,TINYBIND, (DBINT) 0,(BYTE *) &age);
  9026.       dbbind(dbproc,2,SMALLBIND, (DBINT) 0,(BYTE *) &userid);
  9027.       dbbind(dbproc,3,INTBIND, (DBINT) 0,(BYTE *) &royalty);
  9028.       dbbind(dbproc,4,CHARBIND, (DBINT) 0,name);
  9029.       dbbind(dbproc,5,BINARYBIND, (DBINT) 0,title_id);
  9030.       dbbind(dbproc,6,BITBIND, (DBINT) 0,(BYTE *) &us_citizen);
  9031.       dbbind(dbproc,7,FLT8BIND, (DBINT) 0,(BYTE *) &account);
  9032.       dbbind(dbproc,8,STRINGBIND, (DBINT) 0,title);
  9033.       dbbind(dbproc,9,NTBSTRINGBIND, (DBINT) 0,manager);
  9034.  
  9035.  
  9036.    /*
  9037.       ** Initialize null terminator in "name" array,
  9038.       ** since CHARBIND does not add one.
  9039.       */
  9040.       name[PLEN] = '\0';
  9041.  
  9042.       while (dbnextrow(dbproc) != NO_MORE_ROWS)
  9043.       {
  9044.        dbconvert
  9045.        (dbproc, SQLBINARY, title_id,
  9046.        dbdatlen(dbproc, 5), SQLCHAR, id_buffer, (DBINT)-1);
  9047.        printf
  9048.        ("%d %d %ld %s 0x%s\n",
  9049.        age, userid, royalty, name, id_buffer);
  9050.        printf
  9051.        ("%d %8.2f %s %s\n",
  9052.        us_citizen, account, title, manager);
  9053.       }
  9054.      }
  9055.     }
  9056.     dbexit();
  9057.     exit(STDEXIT);
  9058.    }
  9059.  
  9060.    int err_handler(dbproc, severity, dberr, oserr, dberrstr, oserrstr)
  9061.    DBPROCESS *dbproc;
  9062.    int severity;
  9063.    int dberr;
  9064.    int oserr;
  9065.    char *dberrstr;
  9066.    char *oserrstr;
  9067.    {
  9068.     if ((dbproc == NULL) || (DBDEAD(dbproc)))
  9069.      return(INT_EXIT);
  9070.     else
  9071.     {
  9072.      printf("DB-LIBRARY error:\n\t%s\n", dberrstr);
  9073.  
  9074.      if (oserr != DBNOERR)
  9075.      printf("Operating-system error:\n\t%s\n", oserrstr);
  9076.  
  9077.      return(INT_CANCEL);
  9078.     }
  9079.    }
  9080.  
  9081.    int msg_handler(dbproc, msgno, msgstate, severity, msgtext)
  9082.    DBPROCESS *dbproc;
  9083.    DBINT msgno;
  9084.    int msgstate;
  9085.    int severity;
  9086.    char *msgtext;
  9087.    {
  9088.     printf
  9089.     ("SQL Server message %ld, state %d, severity %d:\n\t%s\n",
  9090.     msgno, msgstate, severity, msgtext);
  9091.     return(0);
  9092.    }
  9093.  
  9094.  
  9095.  Binding Aggregate and Compute Results
  9096.  
  9097.    /*
  9098.    ** This example selects some information from the "pubs" database.
  9099.    ** It illustrates binding of both aggregate and compute results.
  9100.    **
  9101.    ** Note that this example only work if the "pubs" database exists
  9102.    ** on your SQL Server.
  9103.    */
  9104.  
  9105.    #define DBMSOS2
  9106.    #include <stdio.h>
  9107.    #include <sqlfront.h>
  9108.    #include <sqldb.h>
  9109.  
  9110.    #define STDEXIT 0
  9111.    #define PLEN 4
  9112.    #define DATEPRINT 26
  9113.    #define MONEYPRINT 12
  9114.  
  9115.    /* Forward declarations of the error handler and message handler.
  9116.    */
  9117.    int err_handler();
  9118.    int msg_handler();
  9119.  
  9120.    main(argc,argv)
  9121.    int argc;
  9122.    char *argv[];
  9123.    {
  9124.     LOGINREC *login;
  9125.     DBPROCESS *dbproc;
  9126.  
  9127.     /* Declare the datatypes for the columns in the table "titles". */
  9128.     DBINT pcount;
  9129.     DBINT sales;
  9130.     DBINT salesavg;
  9131.     DBINT sumsale;
  9132.     DBCHAR date[DATEPRINT+1];
  9133.     DBCHAR price[MONEYPRINT+1];
  9134.     DBCHAR priceavg[MONEYPRINT+1];
  9135.     DBCHAR pubid[PLEN+1];
  9136.     RETCODE result_code; /* to hold the results of dbresults() */
  9137.     STATUS row_code; /* to hold the results of dbnextrow() */
  9138.     /* Install the user-supplied error-handling and message-handling
  9139.     * functions. They are defined at the bottom of this source file.
  9140.     */
  9141.     dberrhandle(err_handler);
  9142.     dbmsghandle(msg_handler);
  9143.  
  9144.     /* Set up the login information. */
  9145.  
  9146.     login = dblogin();
  9147.     DBSETLUSER(login, "user");
  9148.     DBSETLPWD(login, "my_passwd");
  9149.     DBSETLAPP(login, "example3");
  9150.     dbproc = dbopen(login, "my_server");
  9151.  
  9152.     /* Send a "use database" command. */
  9153.     dbuse(dbproc,"pubs");
  9154.  
  9155.     /* Put the SQL statement into the command buffer. */
  9156.     dbcmd(dbproc, "select pub_id, pubdate, price, avg(price), ytd_sales,");
  9157.     dbcmd(dbproc, " avg(ytd_sales), sum(ytd_sales) from titles");
  9158.     dbcmd(dbproc, " group by pub_id");
  9159.     dbcmd(dbproc, " order by pub_id");
  9160.     dbcmd(dbproc, " compute count(pub_id) by pub_id");
  9161.  
  9162.     /* Send the command buffer to SQL Server for execution. */
  9163.     dbsqlexec(dbproc);
  9164.  
  9165.     /*
  9166.     ** Using the aggregates "sum" and "avg" with the COMPUTE clause
  9167.     ** necessitates special handling when binding the results. Since each
  9168.     ** aggregate creates a new column, this is accounted for in the bind.
  9169.     ** Notice that avg(price) is the fourth column in the select list
  9170.     ** and is also specified as the fourth column in the dbbind() function.
  9171.     **
  9172.  
  9173.     ** The COMPUTE clause creates a compute row, which requires a
  9174.     ** special bind function called dbaltbind().
  9175.     */
  9176.  
  9177.     while ((result_code = dbresults(dbproc)) != NO_MORE_RESULTS)
  9178.     {
  9179.      if (result_code == SUCCEED)
  9180.      {
  9181.       dbbind(dbproc,1,NTBSTRINGBIND, (DBINT) 0,pubid);
  9182.       dbbind(dbproc,2,NTBSTRINGBIND, (DBINT) 0,date);
  9183.       dbbind(dbproc,3,NTBSTRINGBIND, (DBINT) 0,price);
  9184.       dbbind(dbproc,4,NTBSTRINGBIND, (DBINT) 0,priceavg);
  9185.       dbbind(dbproc,5,INTBIND, (DBINT) 0, (BYTE *) &sales);
  9186.       dbbind(dbproc,6,INTBIND, (DBINT) 0, (BYTE *) &salesavg);
  9187.       dbbind(dbproc,7,INTBIND, (DBINT) 0, (BYTE *) &sumsale);
  9188.  
  9189.       /* dbaltbind() binds compute columns. */
  9190.       dbaltbind(dbproc,1,1,INTBIND,(DBINT) 0,(BYTE *)&pcount);
  9191.  
  9192.       printf("\nAccounts:\n");
  9193.       printf("---------\n\n");
  9194.       printf
  9195.       ("%-5s %-19s %-6s %-10s %-5s %-10s %-10s\n\n",
  9196.       "pubid", "date", "price", "avg(price)",
  9197.       "sales", "avg(sales)", "sum(sales)");
  9198.  
  9199.       /*
  9200.       ** Print out each result row, using different statements
  9201.       ** depending on whether the row is a regular row or a
  9202.       ** compute row.
  9203.       */
  9204.  
  9205.       while ((row_code = dbnextrow(dbproc)) != NO_MORE_ROWS)
  9206.       {
  9207.        if (row_code == REG_ROW)
  9208.        {
  9209.         printf("%5s %19s %6s %10s %5ld %10ld %10ld\n",
  9210.          pubid, date, price, priceavg, sales,
  9211.          salesavg, sumsale);
  9212.        }
  9213.        else
  9214.         printf("title count: %ld\n\n",pcount);
  9215.       }
  9216.      }
  9217.     }
  9218.  
  9219.     dbexit();
  9220.     exit(STDEXIT);
  9221.    }
  9222.  
  9223.    int err_handler(dbproc, severity, dberr, oserr, dberrstr, oserrstr)
  9224.    DBPROCESS *dbproc;
  9225.    int severity;
  9226.    int dberr;
  9227.    int oserr;
  9228.    char *dberrstr;
  9229.    char *oserrstr;
  9230.    {
  9231.     if ((dbproc == NULL) || (DBDEAD(dbproc)))
  9232.      return(INT_EXIT);
  9233.     else
  9234.     {
  9235.      printf("DB-LIBRARY error:\n\t%s\n", dberrstr);
  9236.  
  9237.      if (oserr != DBNOERR)
  9238.       printf("Operating-system error:\n\t%s\n", oserrstr);
  9239.  
  9240.      return(INT_CANCEL);
  9241.     }
  9242.    }
  9243.  
  9244.    int msg_handler(dbproc, msgno, msgstate, severity, msgtext)
  9245.    DBPROCESS *dbproc;
  9246.    DBINT msgno;
  9247.    int msgstate;
  9248.    int severity;
  9249.    char *msgtext;
  9250.    {
  9251.     printf
  9252.     ("SQL Server message %ld, state %d, severity %d:\n\t%s\n",
  9253.     msgno, msgstate, severity, msgtext);
  9254.     return(0);
  9255.    }
  9256.  
  9257.  
  9258.  Using Row Buffering
  9259.  
  9260.    /*
  9261.    ** This example accesses the data within each row without using dbbind()
  9262.    ** and illustrates the use of row buffering.
  9263.    **
  9264.    ** It runs a query, saves all of the returned rows (up to a maximum
  9265.    ** of 100) using DB-LIBRARY row buffering, and allows the user to
  9266.    ** examine data rows at random.
  9267.    */
  9268.  
  9269.    #define DBMSOS2
  9270.    #include <stdio.h>
  9271.    #include <sqlfront.h>
  9272.    #include <sqldb.h>
  9273.  
  9274.    extern char *malloc();
  9275.  
  9276.    DBPROCESS *dbproc; /* Our connection with SQL Server. */
  9277.    LOGINREC *login; /* Our login information. */
  9278.  
  9279.    #define STDEXIT 0
  9280.    #define TYPELEN 2
  9281.    #define DATELEN 25
  9282.  
  9283.    /* Forward declarations of the error handler and message handler.
  9284.    */
  9285.    int err_handler();
  9286.    int msg_handler();
  9287.  
  9288.    main(argc, argv)
  9289.    int argc;
  9290.    char *argv[];
  9291.    {
  9292.     /* Here are the variables which will be used to store the
  9293.     * data being examined.
  9294.     */
  9295.     DBCHAR name[MAXNAME+1]; /* MAXNAME is defined in
  9296.     * "sqldb.h" as the maximum
  9297.     * length for names of database
  9298.     * objects, such as tables,
  9299.     * columns, and procedures.
  9300.     */
  9301.     DBCHAR type[TYPELEN+1];
  9302.     DBINT id;
  9303.  
  9304.     DBCHAR datebuf[64];
  9305.     DBINT len;
  9306.     char numstring[32];
  9307.     int quitflag = 0;
  9308.     RETCODE row_code;
  9309.     DBINT rownum;
  9310.  
  9311.     /* Install the user-supplied error-handling and message-handling
  9312.     * functions. They are defined at the bottom of this source file.
  9313.     */
  9314.     dberrhandle(err_handler);
  9315.     dbmsghandle(msg_handler);
  9316.  
  9317.     /*
  9318.     ** Get a LOGINREC structure and fill it with the necessary
  9319.     ** login information.
  9320.     */
  9321.  
  9322.     login = dblogin();
  9323.     DBSETLUSER (login, "user");
  9324.     DBSETLPWD(login, "my_passwd");
  9325.     DBSETLAPP(login, "example4");
  9326.  
  9327.     dbproc = dbopen(login, "my_server");
  9328.     dbcmd(dbproc, "select name, type, id, crdate from sysobjects");
  9329.     dbcmd(dbproc, " where type = 'S'");
  9330.  
  9331.     /*
  9332.     ** Set row buffering to 100 rows, via dbsetopt().
  9333.     ** Note that this parameter must be passed as an ASCII string.
  9334.     */
  9335.  
  9336.     dbsetopt(dbproc, DBBUFFER, "100");
  9337.     dbsqlexec(dbproc);
  9338.     if (dbresults(dbproc) == SUCCEED)
  9339.     {
  9340.      /* Read all of the rows into DB-LIBRARY's buffer */
  9341.      while ((row_code = dbnextrow(dbproc)) != NO_MORE_ROWS)
  9342.      {
  9343.       /* If DB-LIBRARY's row buffer is full, throw
  9344.        * away the oldest row to allow the newest
  9345.        * row to be read in.
  9346.        */
  9347.       if (row_code == BUF_FULL)
  9348.        dbclrbuf(dbproc, (DBINT) 1);
  9349.      }
  9350.  
  9351.      /* Print out the column headers. */
  9352.  
  9353.      printf
  9354.       (" %-20s %10s %25s %15s \n",
  9355.       " NAME ",
  9356.       "TYPE",
  9357.       " DATE ",
  9358.       "ID");
  9359.      printf
  9360.       (" %20s %10s %25s %15s \n",
  9361.       "--------------------",
  9362.       "----",
  9363.       "----------------------",
  9364.       "----");
  9365.      /* Let the user view any row in the table. */
  9366.  
  9367.      printf("Type the number of the row you want to see.\n");
  9368.      printf("The first row is number 1.\n");
  9369.      printf("Asking for row 0 will terminate the program.\n");
  9370.  
  9371.      while (quitflag == 0)
  9372.      {
  9373.       printf("Row number: ");
  9374.       gets(numstring);
  9375.       rownum = atoi(numstring);
  9376.      if (rownum == 0)
  9377.       quitflag = 1;
  9378.      else
  9379.      {
  9380.       /* Print out the requested row. */
  9381.       if (dbgetrow(dbproc, rownum) == NO_MORE_ROWS)
  9382.        printf
  9383.        ("That row is not in the table.\n");
  9384.       else
  9385.       {
  9386.        /* Copy variable-length character data
  9387.        * (colname).
  9388.        */
  9389.  
  9390.        strncpy
  9391.        (name, (DBCHAR *)dbdata(dbproc, 1),
  9392.        (len = dbdatlen(dbproc, 1)));
  9393.  
  9394.        /* String needs terminating null. */
  9395.  
  9396.        name[len] = '\0';
  9397.  
  9398.        /* Copy fixed-length character data. */
  9399.  
  9400.        strncpy
  9401.        (type, (DBCHAR *)dbdata(dbproc, 2),
  9402.        (len = dbdatlen(dbproc, 2)));
  9403.        type[len] = '\0';
  9404.  
  9405.        /* Copy integer data. */
  9406.        id = *((DBINT *)dbdata(dbproc, 3));
  9407.  
  9408.        /* Convert datetime data to a printable
  9409.        * string.
  9410.        */
  9411.  
  9412.    dbconvert(dbproc, SQLDATETIME, (dbdata(dbproc, 4)),
  9413.        (DBINT)-1, SQLCHAR, datebuf, (DBINT)-1);
  9414.        printf
  9415.        ("%20s %10s %25s %15ld \n",
  9416.        name, type, datebuf, id);
  9417.        }
  9418.       }
  9419.      }
  9420.     }
  9421.  
  9422.     dbexit();
  9423.     exit(STDEXIT);
  9424.    }
  9425.  
  9426.    int err_handler(dbproc, severity, dberr, oserr, dberrstr, oserrstr)
  9427.    DBPROCESS *dbproc;
  9428.    int severity;
  9429.    int dberr;
  9430.    int oserr;
  9431.    char *dberrstr;
  9432.    char *oserrstr;
  9433.    {
  9434.     if ((dbproc == NULL) || (DBDEAD(dbproc)))
  9435.      return(INT_EXIT);
  9436.     else
  9437.      {
  9438.      printf("DB-LIBRARY error:\n\t%s\n", dberrstr);
  9439.      if (oserr != DBNOERR)
  9440.       printf("Operating-system error:\n\t%s\n", oserrstr);
  9441.      return(INT_CANCEL);
  9442.     }
  9443.    }
  9444.  
  9445.    int msg_handler(dbproc, msgno, msgstate, severity, msgtext)
  9446.    DBPROCESS *dbproc;
  9447.    DBINT msgno;
  9448.    int msgstate;
  9449.    int severity;
  9450.    char *msgtext;
  9451.    {
  9452.     printf
  9453.     ("SQL Server message %ld, state %d, severity %d:\n\t%s\n",
  9454.     msgno, msgstate, severity, msgtext);
  9455.     return(0);
  9456.    }
  9457.  
  9458.  
  9459.  Converting Data with dbconvert
  9460.  
  9461.    /*
  9462.    ** This example illustrates dbconvert. It converts a
  9463.    ** number of constants to strings, a number of strings
  9464.    ** to numerical or binary quantities, and a number of
  9465.    ** numerical quantities to other numerical types.
  9466.    **
  9467.    */
  9468.  
  9469.    #define DBMSOS2
  9470.    #include <stdio.h>
  9471.    #include <sqlfront.h>
  9472.    #include <sqldb.h>
  9473.  
  9474.    #define STDEXIT 0
  9475.    #define ARRAY_LEN 20
  9476.  
  9477.    /* Forward declarations of the error handler and message handler.
  9478.    */
  9479.    int err_handler();
  9480.    int msg_handler();
  9481.  
  9482.    main(argc, argv)
  9483.    int argc;
  9484.    char *argv[];
  9485.    {
  9486.     /* These variables hold the results of data conversions. */
  9487.     static DBBINARY my_binary_array[ARRAY_LEN]
  9488.     = {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0};
  9489.     DBFLT8 my_flt8;
  9490.     DBINT my_int4;
  9491.     DBMONEY my_money;
  9492.     DBCHAR my_string[ARRAY_LEN];
  9493.  
  9494.     /* Install the user-supplied error-handling and message-handling
  9495.     * functions. They are defined at the bottom of this source file.
  9496.     */
  9497.     dberrhandle(err_handler);
  9498.     dbmsghandle(msg_handler);
  9499.  
  9500.     /* Convert numerical and binary constants to strings. */
  9501.  
  9502.    dbconvert
  9503.     ((DBPROCESS *)NULL, SQLBINARY, my_binary_array, (DBINT)8,
  9504.                SQLCHAR, my_string,(DBINT)-1);
  9505.     printf("Binary constant 0x123456789abcdef0 converted to string");
  9506.     printf("\"%s\".\n\n", my_string);
  9507.  
  9508.     my_flt8 = 55.555;
  9509.     dbconvert
  9510.     ((DBPROCESS *)NULL, SQLFLT8, (BYTE *) &my_flt8,
  9511.                (DBINT)-1, SQLCHAR, my_string, (DBINT)-1);
  9512.     printf
  9513.     ("Floating-pt constant 55.555 converted to string \"%s\".\n\n",
  9514.     my_string);
  9515.  
  9516.     /* Convert string constants to numerical and binary quantities. */
  9517.  
  9518.     dbconvert
  9519.     ((DBPROCESS *)NULL, SQLCHAR, "123", (DBINT)-1, SQLINT4, (BYTE *)
  9520.      &my_int4, (DBINT)-1);
  9521.     printf
  9522.     ("String constant \"123\" converted to 4-byte integer %ld.\n\n",
  9523.     my_int4);
  9524.  
  9525.     dbconvert
  9526.     ((DBPROCESS *)NULL,
  9527.     SQLCHAR, "0xfedc", (DBINT)-1, SQLBINARY, my_binary_array,
  9528.                (DBINT)ARRAY_LEN);
  9529.     printf("String constant \"0xfedc\" converted to binary sequence ");
  9530.     printf("%x.\n\n", *((int *)my_binary_array));
  9531.  
  9532.     dbconvert
  9533.     ((DBPROCESS *)NULL, SQLCHAR, "123.456", (DBINT)-1, SQLFLT8,
  9534.        (BYTE *) &my_flt8, (DBINT)-1);
  9535.     printf("String constant \"123.456\" converted to ");
  9536.     printf("floating-pt number %f.\n\n", my_flt8);
  9537.  
  9538.     /* Convert numerical types to other numerical types. */
  9539.  
  9540.     my_flt8 = 98.76;
  9541.     dbconvert
  9542.        ((DBPROCESS *)NULL, SQLFLT8, (BYTE *) &my_flt8, (DBINT)-1, SQLMONEY,
  9543.      (BYTE *) &my_money, (DBINT)-1);
  9544.     dbconvert
  9545.        ((DBPROCESS *)NULL, SQLMONEY, (BYTE *) &my_money, (DBINT)-1, SQLCHAR,
  9546.            my_string, (DBINT)-1);
  9547.     printf
  9548.     ("floating-pt number %f converted to money value %s.\n\n",
  9549.     my_flt8, my_string);
  9550.  
  9551.     dbconvert
  9552.        ((DBPROCESS *)NULL, SQLMONEY, (BYTE *) &my_money, (DBINT)-1, SQLFLT8,
  9553.            (BYTE *) &my_flt8, (DBINT)-1);
  9554.     printf
  9555.     ("money value %s converted to floating-pt value %f.\n\n",
  9556.     my_string, my_flt8);
  9557.    }
  9558.  
  9559.    int err_handler(dbproc, severity, dberr, oserr, dberrstr, oserrstr)
  9560.    DBPROCESS *dbproc;
  9561.    int severity;
  9562.    int dberr;
  9563.    int oserr;
  9564.    char *dberrstr;
  9565.    char *oserrstr;
  9566.    {
  9567.     if ((dbproc == NULL) || (DBDEAD(dbproc)))
  9568.      return(INT_EXIT);
  9569.     else
  9570.     {
  9571.      printf("DB-LIBRARY error:\n\t%s\n", dberrstr);
  9572.      if (oserr != DBNOERR)
  9573.       printf("Operating-system error:\n\t%s\n", oserrstr);
  9574.      return(INT_CANCEL);
  9575.     }
  9576.    }
  9577.  
  9578.    int msg_handler(dbproc, msgno, msgstate, severity, msgtext)
  9579.    DBPROCESS *dbproc;
  9580.    DBINT msgno;
  9581.    int msgstate;
  9582.    int severity;
  9583.    char *msgtext;
  9584.    {
  9585.     printf
  9586.     ("SQL Server message %ld, state %d, severity %d:\n\t%s\n",
  9587.     msgno, msgstate, severity, msgtext);
  9588.     return(0);
  9589.    }
  9590.  
  9591.  
  9592.  Querying and Updating the Database
  9593.  
  9594.    /*
  9595.    ** This example illustrates opening a data file, inserting data
  9596.    ** from the file into a newly created table containing several
  9597.    ** SQL Server datatypes, and updating the table using browse mode
  9598.    ** techniques.
  9599.    */
  9600.  
  9601.    #define DBMSOS2
  9602.    #include <stdio.h>
  9603.    #include <sqlfront.h>
  9604.    #include <sqldb.h>
  9605.  
  9606.    #define STDEXIT 0
  9607.    #define BUFLEN 2048
  9608.  
  9609.    /* Forward declarations of the error-handling and message-handing
  9610.    functions. */
  9611.    int err_handler();
  9612.    int msg_handler();
  9613.  
  9614.    main()
  9615.    {
  9616.     LOGINREC *login;
  9617.     DBPROCESS *q_dbproc; /* This DBPROCESS is used to
  9618.     * query the database.
  9619.     */
  9620.     DBPROCESS *u_dbproc; /* This DBPROCESS is used to
  9621.     * simultaneously update the database.
  9622.     */
  9623.     char *qualptr; /* This points to the WHERE clause
  9624.     * appropriate for updating q_dbproc's current data row.
  9625.     */
  9626.     RETCODE return_code;
  9627.     DBTINYINT age;
  9628.     static char cmdbuf[BUFLEN];
  9629.     FILE *infile;
  9630.  
  9631.     /* Install the user-supplied error-handling and message-handling
  9632.     * functions. They are defined at the bottom of this source file.
  9633.     */
  9634.     dberrhandle(err_handler);
  9635.     dbmsghandle(msg_handler);
  9636.  
  9637.    /* Allocate and initialize the LOGINREC structure to be used
  9638.     * to open a connection to SQL Server.
  9639.     */
  9640.     login = dblogin();
  9641.  
  9642.     DBSETLUSER(login, "user");
  9643.     DBSETLPWD(login, "my_passwd");
  9644.     DBSETLAPP(login, "example6");
  9645.  
  9646.     q_dbproc = dbopen(login, "my_server");
  9647.     u_dbproc = dbopen(login, "my_server");
  9648.  
  9649.     printf("Creating the 'alltypes' table.\n");
  9650.  
  9651.     /* Create a table that contains several SQL Server datatypes. */
  9652.     dbcmd(q_dbproc,"create table alltypes ");
  9653.     dbcmd(q_dbproc,"(age tinyint,");
  9654.     dbcmd(q_dbproc,"userid smallint,");
  9655.     dbcmd(q_dbproc,"royalty int,");
  9656.     dbcmd(q_dbproc,"name char(25),");
  9657.     dbcmd(q_dbproc,"title_id varbinary(20),");
  9658.     dbcmd(q_dbproc,"us_citizen bit,");
  9659.     dbcmd(q_dbproc,"account float,");
  9660.     dbcmd(q_dbproc,"title varchar(20),");
  9661.     dbcmd(q_dbproc,"manager char(25),");
  9662.     dbcmd(q_dbproc,"timestamp)");
  9663.  
  9664.     dbcmd(q_dbproc, "create unique index index1 on alltypes(userid)");
  9665.  
  9666.     dbsqlexec(q_dbproc);
  9667.     while (dbresults(q_dbproc) != NO_MORE_RESULTS)
  9668.     continue;
  9669.  
  9670.     /* Insert rows of data into the newly created table "alltypes".
  9671.     * We will read in the contents of the file and form an
  9672.     * INSERT statement.
  9673.     */
  9674.  
  9675.     if ((infile=fopen("datafile","r")) == NULL)
  9676.     {
  9677.      printf("Unable to open file 'datafile'.\n");
  9678.      exit(STDEXIT);
  9679.     }
  9680.  
  9681.     printf("Inserting rows into the 'alltypes' table...\n");
  9682.  
  9683.    while ((fgets(cmdbuf,BUFLEN,infile)) != NULL)
  9684.     {
  9685.      dbfcmd(q_dbproc,"insert into alltypes \n");
  9686.      dbfcmd(q_dbproc,"values(%s, null) \n",cmdbuf);
  9687.     }
  9688.     dbsqlexec(q_dbproc);
  9689.  
  9690.     /* Process the results of each of the INSERT statements. */
  9691.  
  9692.     while ((return_code = dbresults(q_dbproc)) != NO_MORE_RESULTS)
  9693.     {
  9694.      if (return_code == FAIL)
  9695.       printf("One of the insert statements failed.\n");
  9696.     }
  9697.  
  9698.     /* Using DB-LIBRARY's browse mode facilities, we'll increment
  9699.     * the age of every person in the table.
  9700.     */
  9701.  
  9702.     printf("Updating rows in the 'alltypes' table...\n");
  9703.  
  9704.     dbcmd(q_dbproc,"select * from alltypes for browse");
  9705.     dbsqlexec(q_dbproc);
  9706.  
  9707.     while ((return_code = dbresults(q_dbproc)) != NO_MORE_RESULTS)
  9708.     {
  9709.      if (return_code == SUCCEED)
  9710.      {
  9711.       while (dbnextrow(q_dbproc) != NO_MORE_ROWS)
  9712.       {
  9713.        age = *((DBTINYINT *)(dbdata(q_dbproc, 1)));
  9714.        qualptr = dbqual(q_dbproc, -1, "alltypes");
  9715.        dbcmd(u_dbproc, "update alltypes");
  9716.        dbfcmd
  9717.        (u_dbproc, " set age = %d %s", age+1, qualptr);
  9718.        dbsqlexec(u_dbproc);
  9719.        dbresults(u_dbproc);
  9720.        dbfreequal(qualptr);
  9721.       }
  9722.      }
  9723.     }
  9724.  
  9725.     /* Now, we'll look at the updated contents of the table to
  9726.     * verify that the ages were properly incremented.
  9727.     */
  9728.  
  9729.    printf("Selecting rows from the 'alltypes' table:\n");
  9730.     dbcmd(q_dbproc, "select * from alltypes");
  9731.     dbsqlexec(q_dbproc);
  9732.     dbresults(q_dbproc);
  9733.     dbprrow(q_dbproc);
  9734.  
  9735.    dbexit();
  9736.     exit(STDEXIT);
  9737.    }
  9738.  
  9739.    int err_handler(dbproc, severity, dberr, oserr, dberrstr, oserrstr)
  9740.    DBPROCESS *dbproc;
  9741.    int severity;
  9742.    int dberr;
  9743.    int oserr;
  9744.    char *dberrstr;
  9745.    char *oserrstr;
  9746.    {
  9747.     if ((dbproc == NULL) || (DBDEAD(dbproc)))
  9748.      return(INT_EXIT);
  9749.     else
  9750.     {
  9751.      printf("DB-LIBRARY error:\n\t%s\n", dberrstr);
  9752.  
  9753.      if (oserr != DBNOERR)
  9754.       printf("Operating-system error:\n\t%s\n", oserrstr);
  9755.      return(INT_CANCEL);
  9756.     }
  9757.    }
  9758.  
  9759.    int msg_handler(dbproc, msgno, msgstate, severity, msgtext)
  9760.    DBPROCESS *dbproc;
  9761.    DBINT msgno;
  9762.    int msgstate;
  9763.    int severity;
  9764.    char *msgtext;
  9765.    {
  9766.     printf
  9767.     ("SQL Server message %ld, state %d, severity %d:\n\t%s\n",
  9768.     msgno, msgstate, severity, msgtext);
  9769.     return(0);
  9770.    }
  9771.  
  9772.  
  9773.  Using Browse-Mode Functions
  9774.  
  9775.    /*
  9776.    ** This example illustrates the use of browse mode functions to
  9777.    ** determine the source of result columns from ad hoc queries.
  9778.    */
  9779.  
  9780.    #define DBMSOS2
  9781.    #include <stdio.h>
  9782.    #include <sqlfront.h>
  9783.    #include <sqldb.h>
  9784.  
  9785.    #define STDEXIT 0
  9786.    void examine_results();
  9787.    void send_command();
  9788.  
  9789.    /* Forward declarations of the error-handling and message-handling
  9790.    functions. */
  9791.    int err_handler();
  9792.    int msg_handler();
  9793.  
  9794.    main()
  9795.    {
  9796.     LOGINREC *login;
  9797.     DBPROCESS *dbproc;
  9798.  
  9799.     int command_count = 0;
  9800.     RETCODE retcode;
  9801.  
  9802.     /* Install the user-supplied error-handling and message-handling
  9803.     * functions. They are defined at the bottom of this source file.
  9804.     */
  9805.     dberrhandle(err_handler);
  9806.     dbmsghandle(msg_handler);
  9807.  
  9808.     /* Allocate and initialize the LOGINREC structure to be used
  9809.     * to open a connection to SQL Server.
  9810.     */
  9811.  
  9812.     login = dblogin();
  9813.     DBSETLUSER(login, "user");
  9814.     DBSETLPWD(login, "my_passwd");
  9815.     DBSETLAPP(login, "example7");
  9816.  
  9817.     dbproc = dbopen(login, "my_server");
  9818.  
  9819.    /* Allow the user to type in a series of queries. This program
  9820.     * is terminated by the word "quit" appearing at the
  9821.     * beginning of the line.
  9822.     */
  9823.     while (1)
  9824.     {
  9825.      /* Send a user-generated query to SQL Server. */
  9826.      send_command(dbproc);
  9827.  
  9828.      /* Now, examine the results of any queries the user has
  9829.      * typed in.
  9830.      */
  9831.  
  9832.      command_count = 1;
  9833.      while ((retcode = dbresults(dbproc)) != NO_MORE_RESULTS)
  9834.      {
  9835.       command_count++ ;
  9836.       if (retcode == FAIL)
  9837.        printf("Command %d failed.\n", command_count);
  9838.       else
  9839.       {
  9840.        if (!(DBCMDROW(dbproc)))
  9841.         printf
  9842.        ("Command %d returned no rows.\n",
  9843.        command_count);
  9844.        else
  9845.        {
  9846.        /* This is a command that can return
  9847.        * rows. Let's take a closer look at it.
  9848.        */
  9849.        printf("Command %d:\n", command_count);
  9850.        examine_results(dbproc);
  9851.  
  9852.        /* Throw away all data rows. */
  9853.        dbcanquery(dbproc);
  9854.        }
  9855.       }
  9856.      }
  9857.     }
  9858.    }
  9859.  
  9860.  
  9861.    void examine_results(dbproc)
  9862.    DBPROCESS *dbproc;
  9863.    {
  9864.     int colcount;
  9865.     int colnum;
  9866.     char fullsource[128];
  9867.     char *sourcecolname;
  9868.     int tabcount;
  9869.     char *tabname;
  9870.     int tabnum;
  9871.  
  9872.     /* Determine which tables were used to generate the query results.*/
  9873.  
  9874.     tabcount = dbtabcount(dbproc);
  9875.     printf
  9876.     ("The following tables were used to generate these query results:\n");
  9877.  
  9878.     for (tabnum = 1; tabnum <= tabcount; tabnum++)
  9879.     {
  9880.     if ((tabname = dbtabname(dbproc, tabnum)) != NULL)
  9881.      printf
  9882.      ("\t%s (%s)\n", tabname,
  9883.      (dbtabbrowse(dbproc, tabnum)
  9884.      ? "browsable" : "not browsable"));
  9885.     }
  9886.  
  9887.     /* Determine which tables were used to generate each result column.*/
  9888.  
  9889.     colcount = dbnumcols(dbproc);
  9890.     printf("Here are the columns of the target list and their sources:\n");
  9891.  
  9892.     printf
  9893.     ("\t%-20s %-30s %s\n\n",
  9894.     "Result column:", "Source:", "Browsable?");
  9895.     for (colnum = 1; colnum  colcount; colnum++)
  9896.     {
  9897.     tabname = dbtabsource(dbproc, colnum, NULL);
  9898.     sourcecolname = dbcolsource(dbproc, colnum);
  9899.  
  9900.     if (tabname == NULL)
  9901.      strcpy(fullsource, "(result of expression)");
  9902.     else
  9903.      sprintf(fullsource, "%s.%s", tabname, sourcecolname);
  9904.  
  9905.    printf
  9906.     ("\t%-20s %-30s %s\n",
  9907.     dbcolname(dbproc, colnum),
  9908.     fullsource,
  9909.     (dbcolbrowse(dbproc, colnum) ? "yes" : "no"));
  9910.     }
  9911.    }
  9912.  
  9913.  
  9914.    void send_command(dbproc)
  9915.    DBPROCESS *dbproc;
  9916.    {
  9917.  
  9918.     static char cmdbuf[2048];
  9919.  
  9920.     /* Allow the user to type in an ad hoc query. This query
  9921.     * is terminated by the word "go" appearing at the
  9922.     * beginning of the line.
  9923.     *
  9924.     * If the user types the word "quit" at the beginning of a line,
  9925.     * we'll quit the program.
  9926.     */
  9927.     printf("Enter SQL query:\n");
  9928.     while (1)
  9929.     {
  9930.      printf(" ");
  9931.      gets(cmdbuf);
  9932.  
  9933.      if (strcmp(cmdbuf, "go") == 0)
  9934.      {
  9935.       dbsqlexec(dbproc);
  9936.       break;
  9937.      }
  9938.      else if (strcmp(cmdbuf, "quit") == 0)
  9939.      {
  9940.       exit(STDEXIT);
  9941.      }
  9942.      else
  9943.      {
  9944.       /* Keep reading SQL commands. */
  9945.       dbcmd(dbproc, cmdbuf);
  9946.      }
  9947.     }
  9948.    }
  9949.  
  9950.    int err_handler(dbproc, severity, dberr, oserr, dberrstr, oserrstr)
  9951.    DBPROCESS *dbproc;
  9952.    int severity;
  9953.    int dberr;
  9954.    int oserr;
  9955.    char *dberrstr;
  9956.    char *oserrstr;
  9957.    {
  9958.     if ((dbproc == NULL) || (DBDEAD(dbproc)))
  9959.      return(INT_EXIT);
  9960.     else
  9961.     {
  9962.      printf("DB-LIBRARY error:\n\t%s\n", dberrstr);
  9963.  
  9964.      if (oserr != DBNOERR)
  9965.       printf("Operating-system error:\n\t%s\n", oserrstr);
  9966.  
  9967.      return(INT_CANCEL);
  9968.     }
  9969.    }
  9970.  
  9971.    int msg_handler(dbproc, msgno, msgstate, severity, msgtext)
  9972.    DBPROCESS *dbproc;
  9973.    DBINT msgno;
  9974.    int msgstate;
  9975.    int severity;
  9976.    char *msgtext;
  9977.    {
  9978.     printf
  9979.     ("SQL Server message %ld, state %d, severity %d:\n\t%s\n",
  9980.     msgno, msgstate, severity, msgtext);
  9981.     return(0);
  9982.    }
  9983.  
  9984.  
  9985.  
  9986.  
  9987.  
  9988.  
  9989.  
  9990.  
  9991.  Chapter 4  Bulk Copy Special Library
  9992.  ────────────────────────────────────────────────────────────────────────────
  9993.  
  9994.  
  9995.  Introduction
  9996.  
  9997.  This chapter contains syntax and usage information about the functions
  9998.  contained in the Bulk Copy Special Library. The information is arranged in
  9999.  alphabetical order by function name.
  10000.  
  10001.  For more information about the bcp utility, see the SQL Server System
  10002.  Administrator's Guide.
  10003.  
  10004.  
  10005.  
  10006.  
  10007.  
  10008.  bcp_batch
  10009.  ────────────────────────────────────────────────────────────────────────────
  10010.  
  10011.  
  10012.  Function
  10013.  
  10014.  Saves any preceding rows in SQL Server.
  10015.  
  10016.  
  10017.  Syntax
  10018.  
  10019.    DBINT bcp_batch(dbproc)
  10020.  
  10021.     DBPROCESS *dbproc;
  10022.  
  10023.  
  10024.  Comments
  10025.  
  10026.  When an application uses bcp_bind and bcp_sendrow to bulk copy rows from
  10027.  program variables to SQL Server tables, the rows are permanently saved in
  10028.  SQL Server only when the program calls bcp_batch or bcp_done.
  10029.  
  10030.  You can call bcp_batch once every n rows or when there is a lull between
  10031.  periods of incoming data (as in a telemetry application). Of course, you can
  10032.  choose some other criteria, or can decide not to call bcp_batch at all. If
  10033.  bcp_batch is not called, the rows are permanently saved in SQL Server when
  10034.  bcp_done is called.
  10035.  
  10036.  
  10037.  Parameters
  10038.  
  10039.  dbproc
  10040.    The DBPROCESS structure that is the handle for a particular
  10041.    workstation/SQL Server process. It contains all the information that
  10042.    DB-LIBRARY uses to manage communications and data between the workstation
  10043.    and SQL Server.
  10044.  
  10045.  
  10046.  Returns
  10047.  
  10048.  The number of rows saved since the last call to bcp_batch, or -1 in case of
  10049.  error.
  10050.  
  10051.  
  10052.  See Also
  10053.  
  10054.  bcp_bind, bcp_done, bcp_sendrow
  10055.  
  10056.  
  10057.  bcp_bind
  10058.  ────────────────────────────────────────────────────────────────────────────
  10059.  
  10060.  
  10061.  Function
  10062.  
  10063.  Binds data from a program variable to an SQL Server table.
  10064.  
  10065.  
  10066.  Syntax
  10067.  
  10068.    RETCODE bcp_bind (dbproc, varaddr, prefixlen, varlen,
  10069.      terminator, termlen, type, table_column)
  10070.  
  10071.     DBPROCESS  *dbproc;
  10072.     BYTE   *varaddr;
  10073.     int    prefixlen;
  10074.     DBINT   varlen;
  10075.     BYTE   *terminator;
  10076.     int    termlen;
  10077.     int    type;
  10078.     int    table_column;
  10079.  
  10080.  
  10081.  Comments
  10082.  
  10083.  There can be times when you want to copy data directly from a program
  10084.  variable into a table in SQL Server without having to first place the data
  10085.  in an operating system file or use the SQL INSERT statement. The bcp_bind
  10086.  function is a fast and efficient way to do this.
  10087.  
  10088.  You must call bcp_init before calling this or any other bulk copy functions.
  10089.  
  10090.  
  10091.  There must be a separate bcp_bind call for every column in the SQL Server
  10092.  table into which you want to copy. After the necessary bcp_bind calls have
  10093.  been made, you then call bcp_sendrow to send a row of data from your program
  10094.  variables to SQL Server. The table to be copied into is set by calling
  10095.  bcp_init.
  10096.  
  10097.  Whenever you want SQL Server to checkpoint the rows already received, call
  10098.  bcp_batch. For example, you can call bcp_batch once for every 1000 rows
  10099.  inserted or at any other interval.
  10100.  
  10101.  When there are no more rows to be inserted, call bcp_done. Failure to do so
  10102.  results in an error.
  10103.  
  10104.  When using bcp_bind, the operating system filename parameter, hfile, used in
  10105.  the call to bcp_init, must be set to NULL, and the direction parameter,
  10106.  direction, must be set to DB_IN.
  10107.  
  10108.  Control parameter settings, specified with bcp_control, have no effect on
  10109.  bcp_bind row transfers.
  10110.  
  10111.  It is an error to call bcp_columns when using bcp_bind.
  10112.  
  10113.  The following program fragment illustrates bcp_bind:
  10114.  
  10115.    LOGINREC *login;
  10116.     DBPROCESS *dbproc;
  10117.     char  co_name[MAXNAME];
  10118.     DBINT  co_id;
  10119.     DBINT  rows_sent;
  10120.     DBBOOL  more_data;
  10121.     char  *terminator = "\t\t";
  10122.  
  10123.     /* Install error-handler and message-handler. */
  10124.     dberrhandle(err_handler);
  10125.     dbmsghandle(msg_handler);
  10126.  
  10127.     /* Open a DBPROCESS. */
  10128.     login = dblogin();
  10129.     DBSETLUSER(login, "user");
  10130.     DBSETLPWD(login, "my_passwd");
  10131.     DBSETLAPP(login, "example");
  10132.     BCP_SETL(login, TRUE);
  10133.     dbproc = dbopen(login, "my_server");
  10134.  
  10135.     /* Initialize bcp. */
  10136.     if (bcp_init(dbproc, "comdb..accounts_info", (BYTE *)NULL,
  10137.      (BYTE *)NULL, DB_IN) == FAIL)
  10138.      exit(ERREXIT);
  10139.  
  10140.     /* Bind program variables to table columns. */
  10141.     if (bcp_bind(dbproc, (BYTE *)&co_id, 0, (DBINT)-1, (BYTE *)NULL, 0, 0, 1)
  10142.  == FAIL)
  10143.     {
  10144.      fprintf(stderr, "bcp_bind, column 1, failed.\n");
  10145.      exit(ERREXIT);
  10146.     }
  10147.  
  10148.     if (bcp_bind
  10149.      (dbproc, co_name, 0, (DBINT)-1, terminator, strlen(terminator), 0, 2)
  10150.       == FAIL)
  10151.     {
  10152.      fprintf(stderr, "bcp_bind, column 2, failed.\n");
  10153.      exit(ERREXIT);
  10154.     }
  10155.  
  10156.     while (TRUE)
  10157.     {
  10158.      /* Process/retrieve program data. */
  10159.      more_data = getdata(&co_id, co_name);
  10160.  
  10161.      if (more_data == FALSE)
  10162.       break;
  10163.  
  10164.    /* Send the data. */
  10165.      if (bcp_sendrow(dbproc) == FAIL)
  10166.       exit(ERREXIT);
  10167.     }
  10168.  
  10169.     /* Terminate the bulk copy operation. */
  10170.     if ((rows_sent = bcp_done(dbproc)) == -1)
  10171.      printf("Bulk-copy unsuccessful.\n");
  10172.     else
  10173.      printf("%ld rows copied.\n", rows_sent);
  10174.  
  10175.  
  10176.  Parameters
  10177.  
  10178.  dbproc
  10179.    The DBPROCESS structure that is the handle for a particular
  10180.    workstation/SQL Server process. It contains all the information that
  10181.    DB-LIBRARY uses to manage communications and data between the workstation
  10182.    and SQL Server.
  10183.  
  10184.  varaddr
  10185.    The address of the program variable from which the data is copied. If type
  10186.    is SQLTEXT or SQLIMAGE, varaddr can be NULL. A NULL varaddr indicates that
  10187.    text and image values will be sent to SQL Server in chunks by
  10188.    bcp_moretext, rather than all at once by bcp_sendrow.
  10189.  
  10190.  prefixlen
  10191.    The length, in bytes, of any length prefix this column can have; valid
  10192.    length prefixes are 0, 1, 2, or 4 bytes. For example, strings in some
  10193.    non-C programming languages are made up of a 1-byte length prefix,
  10194.    followed by the string data itself. If the data does not have a length
  10195.    prefix, set prefixlen to 0.
  10196.  
  10197.  varlen
  10198.    The length of the data in the program variable, not including the length
  10199.    of any length prefix and/or terminator. Setting varlen to 0 signifies that
  10200.    the data is NULL. Setting varlen to -1 indicates that the system should
  10201.    ignore this parameter. For fixed-length datatypes, such as integers, the
  10202.    datatype itself indicates to the system the length of the data. Therefore,
  10203.    for fixed-length datatypes, varlen must always be -1 except when the data
  10204.    is NULL, in which case varlen must be 0. For character, text, binary, and
  10205.    image data, varlen can be -1, 0, or some positive value. If varlen is -1,
  10206.    the system uses either a length prefix or a terminator sequence to
  10207.    determine the length. (If both are supplied, the system uses the one that
  10208.    results in the shortest amount of data being copied.) If varlen is -1 and
  10209.    neither a prefix length nor a terminator sequence is specified, the system
  10210.    returns an error message. If varlen is 0, the system assumes the data is
  10211.    NULL. If varlen is some positive value, the system uses varlen as the data
  10212.    length. However, if, in addition to a positive varlen, a prefix length
  10213.    and/or terminator sequence is provided, the system determines the data
  10214.    length by using the method that results in the shortest amount of data
  10215.    being copied.
  10216.  
  10217.  terminator
  10218.    A pointer to the byte pattern, if any, that marks the end of this program
  10219.    variable. For example, C strings usually have a 1-byte terminator whose
  10220.    value is 0. If there is no terminator for the variable, set terminator to
  10221.    NULL. If you want to designate the C null terminator as the program
  10222.    variable terminator, the simplest way is to use an empty string (" ") as
  10223.    terminator and set termlen to 1, since the null terminator constitutes a
  10224.    single byte. For instance, the second bcp_bind call in the previous
  10225.    example uses two tabs as the program variable terminator. It could be
  10226.    rewritten to use a C null terminator instead, as follows:
  10227.  
  10228.    (bcp_bind (dbproc, co_name, 0, -1, "", 1, 0, 2)
  10229.  
  10230.  termlen
  10231.    The length of this program variable's terminator, if any. If there is no
  10232.    terminator for the variable, set termlen to 0.
  10233.  
  10234.  type
  10235.    The datatype of your program variable. The data in the program variable is
  10236.    automatically converted to the type of the database column. If this
  10237.    parameter is 0, no conversion is performed. See "dbconvert" for a list of
  10238.    supported conversions. See Appendix C, "DB-LIBRARY Datatypes," for the
  10239.    list of valid SQL Server datatypes.
  10240.  
  10241.  table_column
  10242.    The column in the database table to which the data is copied. Column
  10243.    numbers start at 1.
  10244.  
  10245.  
  10246.  Returns
  10247.  
  10248.  SUCCEED or FAIL.
  10249.  
  10250.  
  10251.  See Also
  10252.  
  10253.  bcp_batch, bcp_colfmt, bcp_collen, bcp_colptr, bcp_columns, bcp_control,
  10254.  bcp_done, bcp_exec, bcp_init, bcp_moretext, bcp_sendrow, dbconvert, Appendix
  10255.  C
  10256.  
  10257.  
  10258.  bcp_colfmt
  10259.  ────────────────────────────────────────────────────────────────────────────
  10260.  
  10261.  
  10262.  Function
  10263.  
  10264.  Specifies the format of an operating system file for bulk copy.
  10265.  
  10266.  
  10267.  Syntax
  10268.  
  10269.    RETCODE bcp_colfmt (dbproc, file_column, file_type,
  10270.      file_prefixlen, file_collen, file_term,
  10271.      file_termlen, table_column)
  10272.  
  10273.     DBPROCESS *dbproc;
  10274.     int   file_column;
  10275.     BYTE  file_type;
  10276.     int   file_prefixlen;
  10277.     DBINT  file_collen;
  10278.     BYTE  *file_term;
  10279.     int   file_termlen;
  10280.     int   table_column;
  10281.  
  10282.  
  10283.  Comments
  10284.  
  10285.  The bcp_colfmt function allows you to specify the operating system file
  10286.  format for bulk copies. For bulk copy, a format contains the following
  10287.  parts:
  10288.  
  10289.  
  10290.    ■   A mapping from operating system file columns to database columns.
  10291.  
  10292.    ■   The datatype of each operating system file column.
  10293.  
  10294.    ■   The length of the optional length prefix of each column.
  10295.  
  10296.    ■   The maximum length of the operating system file column's data.
  10297.  
  10298.    ■   The optional terminating byte sequence for each column.
  10299.  
  10300.    ■   The length of this optional terminating byte sequence.
  10301.  
  10302.  
  10303.  Each call to bcp_colfmt specifies the format for one operating system file
  10304.  column. For example, if you have a table with five columns and want to
  10305.  change the default settings for three of those columns, you should first
  10306.  call bcp_columns(5), and then call bcp_colfmt five times, with three of
  10307.  those calls setting your custom format. The remaining two calls should have
  10308.  their file_type set to 0 and their file_prefixlen, file_collen, and
  10309.  file_termlen parameters set to -1. The result of this would be to copy all
  10310.  five columns─three with your customized format and two with the default
  10311.  format.
  10312.  
  10313.  The bcp_columns function must be called before any calls to bcp_colfmt.
  10314.  
  10315.  You must call bcp_colfmt for every column in the operating system file,
  10316.  regardless of whether some of those columns use the default format or are
  10317.  skipped.
  10318.  
  10319.  To skip a column, set the table_column parameter to 0.
  10320.  
  10321.  
  10322.  Parameters
  10323.  
  10324.  dbproc
  10325.    The DBPROCESS structure that is the handle for a particular
  10326.    workstation/SQL Server process. It contains all the information that
  10327.    DB-LIBRARY uses to manage communications and data between the workstation
  10328.    and SQL Server.
  10329.  
  10330.  file_column
  10331.    The column in the operating system file whose format is being specified.
  10332.    The first column is number 1.
  10333.  
  10334.  file_type
  10335.    The datatype of this column in the operating system file. If it is
  10336.    different from the datatype of the corresponding column in the database
  10337.    table (table_column), the conversion is performed automatically. See
  10338.    "dbconvert" for a table of allowable data conversions. If you want to
  10339.    specify the same datatype as in the corresponding column of the database
  10340.    table (table_column), this parameter should be set to 0.
  10341.  
  10342.  file_prefixlen
  10343.    The length of the length prefix for this column in the operating system
  10344.    file. Legal prefix lengths are 1, 2, and 4 bytes. To avoid using a length
  10345.    prefix, this parameter should be set to 0. To let bcp decide whether to
  10346.    use a length prefix, this parameter should be set to -1. In such a case,
  10347.    bcp uses a length prefix (of whatever length is necessary) if the database
  10348.    column length is variable.
  10349.  
  10350.    If more than one means of specifying an operating system file column
  10351.    length is used (such as a length prefix and a maximum column length, or a
  10352.    length prefix and a terminator sequence), bcp looks at all of them and
  10353.    uses the one that results in the shortest amount of data being copied.
  10354.  
  10355.    One valuable use for length prefixes is to simplify the specifying of null
  10356.    data values in an operating system file. For instance, assume you have a
  10357.    1-byte length prefix for a 4-byte integer column. Ordinarily, the length
  10358.    prefix contains a value of 4 to indicate that a 4-byte value follows.
  10359.    However, if the value of the column is NULL, the length prefix can be set
  10360.    to 0 to indicate that 0 bytes follow for the column.
  10361.  
  10362.  file_collen
  10363.    The maximum length of this column's data in the operating system file, not
  10364.    including the length of any length prefix and/or terminator. Setting
  10365.    file_collen to 0 signifies that the data is NULL. Setting file_collen to
  10366.    -1 indicates that the system should ignore this parameter (that is, there
  10367.    is no default maximum length).
  10368.  
  10369.    For fixed-length datatypes, such as integers, the length of the data is
  10370.    constant, except for the special case of null values. Therefore, for
  10371.    fixed-length datatypes, file_collen must always be -1, except when the
  10372.    data is NULL, in which case file_collen must be 0. For character, text,
  10373.    binary, and image data, file_collen can be -1, 0, or some positive value.
  10374.    If file_collen is -1, the system uses either a length prefix or a
  10375.    terminator sequence to determine the length of the data. (If both are
  10376.    supplied, the system uses the one that results in the shortest amount of
  10377.    data being copied.) If file_collen is -1 and neither a prefix length nor a
  10378.    terminator sequence is specified, the system returns an error message. If
  10379.    file_collen is 0, the system assumes the data is NULL. If file_collen is
  10380.    some positive value, the system uses file_collen as the maximum data
  10381.    length. However, if, in addition to a positive file_collen, a prefix
  10382.    length and/or terminator sequence is provided, the system determines the
  10383.    data length by using the method that results in the shortest amount of
  10384.    data being copied.
  10385.  
  10386.  file_term
  10387.    The terminator sequence to be used for this column. This parameter is
  10388.    mainly useful for character, text, binary, and image datatypes because all
  10389.    other types are of fixed length. To avoid using a terminator, set this
  10390.    parameter to NULL. To set the terminator to NULL, set file_term to "\0".
  10391.    To make the tab character the terminator, set file_term to "\t". To make
  10392.    the newline character the terminator, set file_term to "\n".
  10393.  
  10394.    If more than one means of specifying an operating system file column
  10395.    length is used (such as a terminator and a length prefix, or a terminator
  10396.    and a maximum column length), bcp looks at all of them and uses the one
  10397.    that results in the shortest amount of data being copied.
  10398.  
  10399.  file_termlen
  10400.    The length, in bytes, of the terminator sequence to be used for this
  10401.    column. To avoid using a terminator, set this value to -1.
  10402.  
  10403.  table_column
  10404.    The corresponding column in the database table. If this value is 0, this
  10405.    column will not be copied. The first column is column 1.
  10406.  
  10407.  
  10408.  Returns
  10409.  
  10410.  SUCCEED or FAIL.
  10411.  
  10412.  
  10413.  See Also
  10414.  
  10415.  bcp_batch, bcp_bind, bcp_collen, bcp_colptr, bcp_columns, bcp_control,
  10416.  bcp_done, bcp_exec, bcp_init, bcp_sendrow, dbconvert
  10417.  
  10418.  
  10419.  bcp_collen
  10420.  ────────────────────────────────────────────────────────────────────────────
  10421.  
  10422.  
  10423.  Function
  10424.  
  10425.  Sets the program variable data length for the current copy IN.
  10426.  
  10427.  
  10428.  Syntax
  10429.  
  10430.    RETCODE bcp_collen(dbproc, varlen, table_column)
  10431.  
  10432.     DBPROCESS *dbproc;
  10433.     DBINT  varlen;
  10434.     int   table_column;
  10435.  
  10436.  
  10437.  Comments
  10438.  
  10439.  The bcp_collen function allows you to change the program variable data
  10440.  length for a particular column while running a copy IN through calls to
  10441.  bcp_bind.
  10442.  
  10443.  Initially, the program variable data length is determined when bcp_bind is
  10444.  called. If the program variable data length changes between calls to
  10445.  bcp_sendrow and no length prefix or terminator is being used, you can call
  10446.  bcp_collen to reset the length. The next call to bcp_sendrow uses the length
  10447.  you just set.
  10448.  
  10449.  There must be a separate bcp_collen call for every column in the table whose
  10450.  data length you want to modify.
  10451.  
  10452.  
  10453.  Parameters
  10454.  
  10455.  dbproc
  10456.    The DBPROCESS structure that is the handle for a particular
  10457.    workstation/SQL Server process. It contains all the information that
  10458.    DB-LIBRARY uses to manage communications and data between the workstation
  10459.    and SQL Server.
  10460.  
  10461.  varlen
  10462.    The length of the program variable, which does not include the length of
  10463.    the length prefix or terminator. Setting varlen to 0 signifies that the
  10464.    data is NULL. Setting it to -1 signifies that the data is variable length
  10465.    and that the length is determined by the length prefix or terminator. If
  10466.    both a length prefix and a terminator exist, bcp uses the one that results
  10467.    in the shortest amount of data being copied.
  10468.  
  10469.  table_column
  10470.    The column in the SQL Server table to which the data is copied. Column
  10471.    numbers start at 1.
  10472.  
  10473.  
  10474.  Returns
  10475.  
  10476.  SUCCEED or FAIL.
  10477.  
  10478.  
  10479.  See Also
  10480.  
  10481.  bcp_bind, bcp_colptr, bcp_sendrow
  10482.  
  10483.  
  10484.  bcp_colptr
  10485.  ────────────────────────────────────────────────────────────────────────────
  10486.  
  10487.  
  10488.  Function
  10489.  
  10490.  Sets the program variable data address for the current copy IN.
  10491.  
  10492.  
  10493.  Syntax
  10494.  
  10495.    RETCODE bcp_colptr(dbproc, colptr, table_column)
  10496.  
  10497.     DBPROCESS *dbproc;
  10498.     BYTE  *colptr;
  10499.     int   table_column;
  10500.  
  10501.  
  10502.  Comments
  10503.  
  10504.  The bcp_colptr function allows you to change the program variable data
  10505.  address for a particular column while running a copy IN through calls to
  10506.  bcp_bind.
  10507.  
  10508.  Initially, the program variable data address is determined when bcp_bind is
  10509.  called. If the program variable data address changes between calls to
  10510.  bcp_sendrow, you can call bcp_colptr to reset the address of the data. The
  10511.  next call to bcp_sendrow uses the data at the address you just set.
  10512.  
  10513.  There must be a separate bcp_colptr call for every column in the table whose
  10514.  data address you want to modify.
  10515.  
  10516.  
  10517.  Parameters
  10518.  
  10519.  dbproc
  10520.    The DBPROCESS structure that is the handle for a particular
  10521.    workstation/SQL Server process. It contains all the information that
  10522.    DB-LIBRARY uses to manage communications and data between the workstation
  10523.    and SQL Server.
  10524.  
  10525.  colptr
  10526.    The address of the program variable.
  10527.  
  10528.  table_column
  10529.    The column in the SQL Server table to which the data is copied. Column
  10530.    numbers start at 1.
  10531.  
  10532.  
  10533.  Returns
  10534.  
  10535.  SUCCEED or FAIL.
  10536.  
  10537.  
  10538.  See Also
  10539.  
  10540.  bcp_bind, bcp_collen, bcp_sendrow
  10541.  
  10542.  
  10543.  bcp_columns
  10544.  ────────────────────────────────────────────────────────────────────────────
  10545.  
  10546.  
  10547.  Function
  10548.  
  10549.  Sets the total number of columns found in the operating system file for use
  10550.  with bulk copy.
  10551.  
  10552.  
  10553.  Syntax
  10554.  
  10555.    RETCODE bcp_columns(dbproc, file_colcount)
  10556.  
  10557.     DBPROCESS *dbproc;
  10558.     int   file_colcount;
  10559.  
  10560.  
  10561.  Comments
  10562.  
  10563.  This function can be called only after bcp_init has been called with a valid
  10564.  filename.
  10565.  
  10566.  You should call this function only if you intend to use an operating system
  10567.  file format that differs from the default. See "bcp_init" for a description
  10568.  of the default operating system file format.
  10569.  
  10570.  After calling bcp_columns, you must call bcp_colfmt file_colcount times
  10571.  because you are defining a completely custom file format.
  10572.  
  10573.  
  10574.  Parameters
  10575.  
  10576.  dbproc
  10577.    The DBPROCESS structure that is the handle for a particular
  10578.    workstation/SQL Server process. It contains all the information that
  10579.    DB-LIBRARY uses to manage communications and data between the workstation
  10580.    and SQL Server.
  10581.  
  10582.  file_colcount
  10583.    The total number of columns in the operating system file. Even if you are
  10584.    preparing to bulk copy data from the operating system file to an SQL
  10585.    Server table and do not intend to copy all columns in the operating system
  10586.    file, you must still set file_colcount to the total number of operating
  10587.    system file columns.
  10588.  
  10589.  
  10590.  Returns
  10591.  
  10592.  SUCCEED or FAIL.
  10593.  
  10594.  
  10595.  See Also
  10596.  
  10597.  bcp_colfmt, bcp_init
  10598.  
  10599.  
  10600.  bcp_control
  10601.  ────────────────────────────────────────────────────────────────────────────
  10602.  
  10603.  
  10604.  Function
  10605.  
  10606.  Changes various control parameter default settings.
  10607.  
  10608.  
  10609.  Syntax
  10610.  
  10611.    RETCODE bcp_control(dbproc, field, value)
  10612.  
  10613.     DBPROCESS *dbproc;
  10614.     int   field;
  10615.     DBINT  value;
  10616.  
  10617.  
  10618.  Comments
  10619.  
  10620.  This function sets various control parameters for bulk copy operations,
  10621.  including the number of errors allowed before aborting a bulk copy, the
  10622.  numbers of the first and last rows to copy, and the batch size.
  10623.  
  10624.  These control parameters are only meaningful when copying between an
  10625.  operating system file and an SQL Server table. Control parameter settings
  10626.  have no effect on bcp_bind row transfers.
  10627.  
  10628.  The following program fragment illustrates bcp_control:
  10629.  
  10630.    LOGINREC *login;
  10631.     DBPROCESS *dbproc;
  10632.     DBINT  rowsread;
  10633.  
  10634.     /* Install error-handler and message-handler. */
  10635.     dberrhandle(err_handler);
  10636.     dbmsghandle(msg_handler);
  10637.  
  10638.     /* Open a DBPROCESS. */
  10639.     login = dblogin();
  10640.     BCP_SETL(login, TRUE);
  10641.     DBSETLUSER(login, "user");
  10642.     DBSETLPWD(login, "my_passwd");
  10643.     DBSETLAPP(login, "example");
  10644.     dbproc = dbopen(login, "my_server");
  10645.     /* Initialize bcp. */
  10646.     if (bcp_init(dbproc, "comdb..address", "address.add", "addr.err",
  10647.      DB_IN) == FAIL)
  10648.      exit(ERREXIT);
  10649.     /* Set the number of rows per batch. */
  10650.     if (bcp_control(dbproc, BCPBATCH, (DBINT) 1000) == FAIL)
  10651.     {
  10652.      printf("bcp_control failed to set batching behavior.\n");
  10653.      exit(ERREXIT);
  10654.     }
  10655.  
  10656.     /* Set file column count. */
  10657.     if (bcp_columns(dbproc, 1) == FAIL)
  10658.     {
  10659.      printf("bcp_columns failed.\n");
  10660.      exit(ERREXIT);
  10661.     }
  10662.     /* Set the file format. */
  10663.     if (bcp_colfmt(dbproc, 1, 0, 0, (DBINT)-1, "\n", 1, 1) == FAIL)
  10664.     {
  10665.      printf("bcp_colformat failed.\n");
  10666.      exit(ERREXIT);
  10667.     }
  10668.     /* Now, execute the bulk copy. */
  10669.     if (bcp_exec(dbproc, &rowsread) == FAIL)
  10670.     {
  10671.      printf("Incomplete bulk copy. Only %ld row%c copied.\n",
  10672.       rowsread, (rowsread == 1) ? ' ': 's');
  10673.      exit(ERREXIT);
  10674.     }
  10675.  
  10676.  
  10677.  Parameters
  10678.  
  10679.  dbproc
  10680.    The DBPROCESS structure that is the handle for a particular
  10681.    workstation/SQL Server process. It contains all the information that
  10682.    DB-LIBRARY uses to manage communications and data between the workstation
  10683.    and SQL Server.
  10684.  
  10685.  field
  10686.    One of the following:
  10687.  
  10688.      BCPMAXERRS
  10689.        The number of errors allowed before giving up. The default is 10.
  10690.        Providing a value less than 1 to this field resets it to its default
  10691.        value.
  10692.  
  10693.      BCPFIRST
  10694.        The first row to copy. The default is 1. Providing a value less than 1
  10695.        to this field resets it to its default value.
  10696.  
  10697.      BCPLAST
  10698.        The last row to copy. The default is to copy all rows. Providing a
  10699.        value less than 1 to this field resets it to its default value.
  10700.  
  10701.      BCPBATCH
  10702.        The number of rows per batch. The default is 0. Providing a value less
  10703.        than 1 to this field resets it to its default value.
  10704.  
  10705.  value
  10706.    The value for the specified field.
  10707.  
  10708.  
  10709.  Returns
  10710.  
  10711.  SUCCEED or FAIL.
  10712.  
  10713.  
  10714.  See Also
  10715.  
  10716.  bcp_batch, bcp_bind, bcp_colfmt, bcp_collen, bcp_colptr, bcp_columns,
  10717.  bcp_done, bcp_exec, bcp_init
  10718.  
  10719.  
  10720.  bcp_done
  10721.  ────────────────────────────────────────────────────────────────────────────
  10722.  
  10723.  
  10724.  Function
  10725.  
  10726.  Ends a bulk copy from program variables into SQL Server.
  10727.  
  10728.  
  10729.  Syntax
  10730.  
  10731.    DBINT bcp_done(dbproc)
  10732.  
  10733.     DBPROCESS *dbproc;
  10734.  
  10735.  
  10736.  Comments
  10737.  
  10738.  The bcp_done function ends a bulk copy performed with bcp_bind and
  10739.  bcp_sendrow. It should be called after the last call to bcp_sendrow or
  10740.  bcp_moretext. Failure to call bcp_done after you have completed copying in
  10741.  all your data results in unpredictable errors.
  10742.  
  10743.  
  10744.  Parameters
  10745.  
  10746.  dbproc
  10747.    The DBPROCESS structure that is the handle for a particular
  10748.    workstation/SQL Server process. It contains all the information that
  10749.    DB-LIBRARY uses to manage communications and data between the workstation
  10750.    and SQL Server.
  10751.  
  10752.  
  10753.  Returns
  10754.  
  10755.  The number of rows permanently saved since the last call to bcp_batch, or -1
  10756.  in case of error.
  10757.  
  10758.  
  10759.  See Also
  10760.  
  10761.  bcp_batch, bcp_bind, bcp_moretext, bcp_sendrow
  10762.  
  10763.  
  10764.  bcp_exec
  10765.  ────────────────────────────────────────────────────────────────────────────
  10766.  
  10767.  
  10768.  Function
  10769.  
  10770.  Executes a bulk copy of data between a database table and an operating
  10771.  system file.
  10772.  
  10773.  
  10774.  Syntax
  10775.  
  10776.    RETCODE bcp_exec(dbproc, rows_copied)
  10777.  
  10778.     DBPROCESS *dbproc;
  10779.     DBINT  *rows_copied;
  10780.  
  10781.  
  10782.  Comments
  10783.  
  10784.  This function copies data from an operating system file to a database table
  10785.  or vice versa, depending on the value of the direction parameter in
  10786.  bcp_init.
  10787.  
  10788.  Before calling this function you must call bcp_init with a valid operating
  10789.  system filename. Failure to do so results in an error.
  10790.  
  10791.  The following program fragment illustrates bcp_exec:
  10792.  
  10793.    LOGINREC *login;
  10794.     DBPROCESS *dbproc;
  10795.     DBINT  rowsread;
  10796.  
  10797.     /* Install error-handler and message-handler. */
  10798.     dberrhandle(err_handler);
  10799.     dbmsghandle(msg_handler);
  10800.  
  10801.     /* Open a DBPROCESS. */
  10802.     login = dblogin();
  10803.     DBSETLUSER(login, "user");
  10804.     DBSETLPWD(login, "my_passwd");
  10805.     DBSETLAPP(login, "example");
  10806.     BCP_SETL(login, TRUE);
  10807.     dbproc = dbopen(login, "my_server");
  10808.  
  10809.     /* Initialize bcp. */
  10810.     if (bcp_init(dbproc, "pubs..authors", "authors.sav",
  10811.      (BYTE *)NULL, DB_OUT) == FAIL)
  10812.      exit(ERREXIT);
  10813.  
  10814.     /* Now, execute the bulk copy. */
  10815.     if (bcp_exec(dbproc, &rowsread) == FAIL)
  10816.      printf("Incomplete bulk copy. Only %ld row%s copied.\n",
  10817.       rowsread, (rowsread == 1) ? "": "s");
  10818.  
  10819.  
  10820.  Parameters
  10821.  
  10822.  dbproc
  10823.    The DBPROCESS structure that is the handle for a particular
  10824.    workstation/SQL Server process. It contains all the information that
  10825.    DB-LIBRARY uses to manage communications and data between the workstation
  10826.    and SQL Server.
  10827.  
  10828.  rows_copied
  10829.    A pointer to a DBINT. The bcp_exec function fills this DBINT with the
  10830.    number of rows successfully copied. If set to NULL, this parameter is not
  10831.    filled in by bcp_exec.
  10832.  
  10833.  
  10834.  Returns
  10835.  
  10836.  SUCCEED or FAIL. The bcp_exec function returns SUCCEED if all rows are
  10837.  copied. If a partial or complete failure occurs, bcp_exec returns FAIL.
  10838.  Check the rows_copied parameter for the number of rows successfully copied.
  10839.  
  10840.  
  10841.  
  10842.  See Also
  10843.  
  10844.  bcp_batch, bcp_bind, bcp_colfmt, bcp_collen, bcp_colptr, bcp_columns,
  10845.  bcp_control, bcp_done, bcp_init, bcp_sendrow
  10846.  
  10847.  
  10848.  bcp_init
  10849.  ────────────────────────────────────────────────────────────────────────────
  10850.  
  10851.  
  10852.  Function
  10853.  
  10854.  Initializes bulk copy.
  10855.  
  10856.  
  10857.  Syntax
  10858.  
  10859.    RETCODE bcp_init(dbproc, tblname, hfile, errfile, direction)
  10860.  
  10861.     DBPROCESS *dbproc;
  10862.     char  *tblname;
  10863.     char  *hfile;
  10864.     char  *errfile;
  10865.     int   direction;
  10866.  
  10867.  
  10868.  Comments
  10869.  
  10870.  The bcp_init function performs the necessary initializations for a bulk copy
  10871.  of data between the workstation and SQL Server. It sets the default
  10872.  operating system file data formats and examines the structure of the
  10873.  database table.
  10874.  
  10875.  If an operating system file is being used (see the description of the hfile
  10876.  parameter), the default data formats are as follows:
  10877.  
  10878.  
  10879.    ■   The order, type, length, and number of the columns in the operating
  10880.        system file are assumed to be identical to the order, type, and number
  10881.        of the columns in the database table.
  10882.  
  10883.    ■   If a given database column's data is fixed length, then the operating
  10884.        system file's data column will also be fixed length. If a given
  10885.        database column's data is variable length or can contain NULL values,
  10886.        the operating system file's data column is prefixed by a 4-byte length
  10887.        value for SQLTEXT and SQLIMAGE datatypes and a 1-byte length value for
  10888.        all other types.
  10889.  
  10890.    ■   There are no terminators of any kind between operating system file
  10891.        columns.
  10892.  
  10893.  
  10894.  Any of these defaults can be overridden by calling bcp_columns and
  10895.  bcp_colfmt.
  10896.  
  10897.  To use the bulk copy functions to copy data to a database table, you must do
  10898.  the following:
  10899.  
  10900.  
  10901.    ■   Call BCP_SETL to make the DBPROCESS structure usable for bulk copy
  10902.        purposes:
  10903.  
  10904.        login = dblogin();
  10905.        BCP_SETL(login, TRUE);
  10906.  
  10907.  
  10908.    ■   If the table has no indexes, set the database option select
  10909.        into/bulkcopy to "true":
  10910.  
  10911.        sp_dboption 'mydb', 'select into/bulkcopy', 'true'
  10912.  
  10913.  
  10914.  
  10915.  If no operating system file is being used, it's necessary to call bcp_bind
  10916.  to specify the format and location in memory of each column's data value.
  10917.  
  10918.  The bcp_init function must be called before any other bulk copy functions.
  10919.  Failure to do so results in an error.
  10920.  
  10921.  
  10922.  Parameters
  10923.  
  10924.  dbproc
  10925.    The DBPROCESS structure that is the handle for a particular
  10926.    workstation/SQL Server process. It contains all the information that
  10927.    DB-LIBRARY uses to manage communications and data between the workstation
  10928.    and SQL Server.
  10929.  
  10930.  tblname
  10931.    The name of the database table to be copied in or out. This name can also
  10932.    include the database name or the Database Owner name. For example,
  10933.    "pubs.gracie.titles", "pubs..titles", "gracie.titles", and "titles" are
  10934.    all legal table names.
  10935.  
  10936.  hfile
  10937.    The name of the operating system file to be copied in or out. If no
  10938.    operating system file is involved (the situation when data is being copied
  10939.    directly from variables), hfile should be NULL.
  10940.  
  10941.  errfile
  10942.    The name of the error file to be used. This error file will be filled with
  10943.    progress messages, error messages, and copies of any rows that, for any
  10944.    reason, could not be copied from an operating system file to an SQL Server
  10945.    table. If NULL is passed as errfile, no error file is used.
  10946.  
  10947.  direction
  10948.    The direction of the copy. It must be one of two values: DB_IN or DB_OUT.
  10949.    DB_IN indicates a copy from the operating system file into the database
  10950.    table, while DB_OUT indicates a copy from the database table into the
  10951.    operating system file. It is illegal to request a bulk copy from the
  10952.    database table (DB_OUT) without supplying an operating system filename.
  10953.  
  10954.  
  10955.  Returns
  10956.  
  10957.  SUCCEED or FAIL.
  10958.  
  10959.  
  10960.  See Also
  10961.  
  10962.  bcp_batch, bcp_bind, bcp_colfmt, bcp_collen, bcp_colptr, bcp_columns,
  10963.  bcp_control, bcp_done, bcp_exec, bcp_sendrow
  10964.  
  10965.  
  10966.  bcp_moretext
  10967.  ────────────────────────────────────────────────────────────────────────────
  10968.  
  10969.  
  10970.  Function
  10971.  
  10972.  Sends part of a text or image value to SQL Server.
  10973.  
  10974.  
  10975.  Syntax
  10976.  
  10977.    RETCODE bcp_moretext(dbproc, size, text)
  10978.  
  10979.     DBPROCESS *dbproc;
  10980.     DBINT  size;
  10981.     BYTE  *text;
  10982.  
  10983.  
  10984.  Comments
  10985.  
  10986.  This function is used in conjunction with bcp_bind and bcp_sendrow to send a
  10987.  large SQLTEXT or SQLIMAGE value to SQL Server in the form of a number of
  10988.  smaller chunks. This is particularly useful with operating systems unable to
  10989.  allocate extremely long data buffers.
  10990.  
  10991.  If bcp_bind is called with a type parameter of SQLTEXT or SQLIMAGE and a
  10992.  non-NULL varaddr parameter, bcp_sendrow sends the entire text or image data
  10993.  value, just as it does for all other datatypes. If, however, bcp_bind has a
  10994.  NULL varaddr parameter, bcp_sendrow returns control to the application
  10995.  immediately after all nontext or image columns are sent to SQL Server. The
  10996.  application can then call bcp_moretext repeatedly to send the text and image
  10997.  columns to SQL Server, a chunk at a time.
  10998.  
  10999.  Here's an example that illustrates how to use bcp_moretext with bcp_bind and
  11000.  bcp_sendrow:
  11001.  
  11002.    LOGINREC *login;
  11003.     DBPROCESS *dbproc;
  11004.  
  11005.     DBINT id = 5;
  11006.     char *part1 = "This text value isn't very long,";
  11007.     char *part2 = " but it's broken up into three parts";
  11008.     char *part3 = " anyhow.";
  11009.  
  11010.     /* Install error handler and message handler. */
  11011.     dberrhandle(err_handler);
  11012.     dbmsghandle(msg_handler);
  11013.  
  11014.     /* Open a DBPROCESS */
  11015.     login = dblogin();
  11016.     BCP_SETL(login, TRUE);
  11017.     DBSETLUSER(login, "user");
  11018.     DBSETLPWD(login, "my_passwd");
  11019.     DBSETLAPP(login, "example");
  11020.     dbproc = dbopen(login, "my_server");
  11021.  
  11022.    /* Initialize bcp. */
  11023.     if (bcp_init(dbproc, "comdb..articles", (BYTE *)NULL,
  11024.      (BYTE *)NULL, DB_IN) == FAIL)
  11025.      exit(ERREXIT);
  11026.  
  11027.     /* Bind program variables to table columns. */
  11028.     if (bcp_bind(dbproc, (BYTE *)&id, 0, (DBINT)-1, (BYTE *)NULL, 0, SQLINT4,
  11029.  1)
  11030.      == FAIL)
  11031.     {
  11032.      fprintf(stderr, "bcp_bind, column 1, failed.\n");
  11033.      exit(ERREXIT);
  11034.     }
  11035.  
  11036.     if (bcp_bind
  11037.      (dbproc, (BYTE *)NULL, 0, (DBINT)(strlen(part1) +
  11038.      strlen(part2) + strlen(part3)), (BYTE *)NULL, 0,
  11039.      SQLTEXT, 2) == FAIL)
  11040.     {
  11041.      fprintf(stderr, "bcp_bind, column 2, failed.\n");
  11042.      exit(ERREXIT);
  11043.     }
  11044.  
  11045.     /* Now send this row, with the text value broken into three chunks. */
  11046.     if (bcp_sendrow(dbproc) == FAIL)
  11047.      exit(ERREXIT);
  11048.     if (bcp_moretext(dbproc, (DBINT)strlen(part1), part1) == FAIL)
  11049.      exit(ERREXIT);
  11050.     if (bcp_moretext(dbproc, (DBINT)strlen(part2), part2) == FAIL)
  11051.      exit(ERREXIT);
  11052.     if (bcp_moretext(dbproc, (DBINT)strlen(part3), part3) == FAIL)
  11053.      exit(ERREXIT);
  11054.  
  11055.     /* We're all done. */
  11056.     bcp_done(dbproc);
  11057.     dbclose(dbproc);
  11058.  
  11059.  If you use bcp_moretext to send one text or image column in the row, you
  11060.  must also use it to send all other text and image columns in the row.
  11061.  
  11062.  If the row contains more than one text or image column, bcp_moretext first
  11063.  sends its data to the lowest numbered (that is, leftmost) text or image
  11064.  column, followed by the next lowest numbered column, and so on.
  11065.  
  11066.  An application normally calls bcp_sendrow and bcp_moretext within loops to
  11067.  send a number of rows of data. Here's an outline of how to do this for a
  11068.  table containing two text columns:
  11069.  
  11070.    while (there are still rows to send)
  11071.     {
  11072.      bcp_sendrow(...);
  11073.  
  11074.     for (all the data in the first text column)
  11075.      bcp_moretext(...);
  11076.  
  11077.     for (all the data in the second text column)
  11078.      bcp_moretext(...);
  11079.     }
  11080.  
  11081.  
  11082.  Parameters
  11083.  
  11084.  dbproc
  11085.    The DBPROCESS structure that is the handle for a particular
  11086.    workstation/SQL Server process. It contains all the information that
  11087.    DB-LIBRARY uses to manage communications and data between the workstation
  11088.    and SQL Server.
  11089.  
  11090.  size
  11091.    The size of this particular part of the text or image value being sent to
  11092.    SQL Server. It is an error to send more text or image bytes to SQL Server
  11093.    than were specified in the call to bcp_bind or bcp_collen.
  11094.  
  11095.  text
  11096.    A pointer to the text or image portion to be written.
  11097.  
  11098.  
  11099.  Returns
  11100.  
  11101.  SUCCEED or FAIL.
  11102.  
  11103.  
  11104.  See Also
  11105.  
  11106.  bcp_bind, bcp_collen, bcp_sendrow, dbwritetext
  11107.  
  11108.  
  11109.  bcp_sendrow
  11110.  ────────────────────────────────────────────────────────────────────────────
  11111.  
  11112.  
  11113.  Function
  11114.  
  11115.  Sends a row of data from program variables to SQL Server.
  11116.  
  11117.  
  11118.  Syntax
  11119.  
  11120.    RETCODE bcp_sendrow(dbproc)
  11121.  
  11122.     DBPROCESS *dbproc;
  11123.  
  11124.  
  11125.  Comments
  11126.  
  11127.  The bcp_sendrow function builds a row from program variables and sends it to
  11128.  SQL Server.
  11129.  
  11130.  Before calling bcp_sendrow, you must make calls to bcp_bind to specify the
  11131.  program variables to be used.
  11132.  
  11133.  If bcp_bind is called with a type parameter of SQLTEXT or SQLIMAGE and a
  11134.  non-NULL varaddr parameter, bcp_sendrow sends the entire text or image data
  11135.  value, just as it does for all other datatypes. If, however, bcp_bind has a
  11136.  NULL varaddr parameter, bcp_sendrow returns control to the application
  11137.  immediately after all nontext or image columns are sent to SQL Server. The
  11138.  application can then call bcp_moretext repeatedly to send the text and image
  11139.  columns to SQL Server, a chunk at a time. For an example, see
  11140.  "bcp_moretext."
  11141.  
  11142.  After the last call to bcp_sendrow, you must call bcp_done to ensure proper
  11143.  internal cleanup.
  11144.  
  11145.  When bcp_sendrow is used to bulk copy rows from program variables into SQL
  11146.  Server tables, rows are permanently saved in SQL Server only when the user
  11147.  calls bcp_batch or bcp_done. The user can choose to call bcp_batch once
  11148.  every n rows or when there is a lull between periods of incoming data (as in
  11149.  a telemetry application). Of course, the user can choose some other criteria
  11150.  or decide not to call bcp_batch at all. If bcp_batch is never called, the
  11151.  rows are permanently saved in SQL Server when bcp_done is called.
  11152.  
  11153.  
  11154.  Parameters
  11155.  
  11156.  dbproc
  11157.    The DBPROCESS structure that is the handle for a particular
  11158.    workstation/SQL Server process. It contains all the information that
  11159.    DB-LIBRARY uses to manage communications and data between the workstation
  11160.    and SQL Server.
  11161.  
  11162.  
  11163.  Returns
  11164.  
  11165.  SUCCEED or FAIL.
  11166.  
  11167.  
  11168.  See Also
  11169.  
  11170.  bcp, bcp_batch, bcp_bind, bcp_colfmt, bcp_collen, bcp_colptr, bcp_columns,
  11171.  bcp_control, bcp_done, bcp_exec, bcp_init, bcp_moretext
  11172.  
  11173.  
  11174.  BCP_SETL
  11175.  ────────────────────────────────────────────────────────────────────────────
  11176.  
  11177.  
  11178.  Function
  11179.  
  11180.  Sets the LOGINREC for bulk copy operations.
  11181.  
  11182.  
  11183.  Syntax
  11184.  
  11185.    RETCODE BCP_SETL(loginrec, enable)
  11186.  
  11187.     LOGINREC *loginrec;
  11188.     DBBOOL  enable;
  11189.  
  11190.  
  11191.  Comments
  11192.  
  11193.  This macro sets a field in the LOGINREC structure that tells SQL Server that
  11194.  the DBPROCESS connection can be used for bulk copy operations. For it to
  11195.  have any effect, it must be called before dbopen, the function that actually
  11196.  allocates the DBPROCESS structure.
  11197.  
  11198.  Applications that allow users to make ad hoc queries may want to avoid
  11199.  calling this macro (or call it with the enable parameter set to FALSE) to
  11200.  keep users from initiating a bulk copy sequence with SQL statements. Once a
  11201.  bulk copy sequence has begun, it cannot be stopped with an ordinary SQL
  11202.  statement.
  11203.  
  11204.  
  11205.  Parameters
  11206.  
  11207.  loginrec
  11208.    A pointer to a LOGINREC structure, which is passed as a parameter to
  11209.    dbopen. You can get one by calling dblogin.
  11210.  
  11211.  enable
  11212.    A boolean value (TRUE or FALSE) that specifies whether or not to enable
  11213.    bulk copy operations for the resulting DBPROCESS. By default, DBPROCESS
  11214.    structures are not enabled for bulk copy operations.
  11215.  
  11216.  
  11217.  Returns
  11218.  
  11219.  SUCCEED or FAIL.
  11220.  
  11221.  
  11222.  See Also
  11223.  
  11224.  bcp_init, dblogin, dbopen, DBSETLAPP, DBSETLHOST, DBSETLPWD, DBSETLUSER
  11225.  
  11226.  
  11227.  
  11228.  
  11229.  
  11230.  
  11231.  
  11232.  
  11233.  Chapter 5  Two-Phase Commit Special Library
  11234.  ────────────────────────────────────────────────────────────────────────────
  11235.  
  11236.  
  11237.  Programming Distributed Transactions
  11238.  
  11239.  The two-phase commit service allows an application to coordinate updates
  11240.  among multiple SQL Servers. This initial implementation of distributed
  11241.  transactions treats separate transactions (which may be on separate SQL
  11242.  Servers) as if they were a single transaction. The service uses one SQL
  11243.  Server, the "commit server," as a record keeper that helps the application
  11244.  determine whether to commit or to roll back transactions in case of failure.
  11245.  Thus, the two-phase commit guarantees that either all the databases on the
  11246.  participating servers are updated or that none of them are.
  11247.  
  11248.  A distributed transaction is performed by submitting TRANSACT-SQL statements
  11249.  to SQL Servers through DB-LIBRARY functions and macros. An application
  11250.  program opens a session with each server, executes the update commands, and
  11251.  then prepares to commit the transaction. Through DB-LIBRARY, the application
  11252.  executes the following to each participating server:
  11253.  
  11254.  
  11255.    ■   A BEGIN TRANSACTION statement with identifying information on the
  11256.        application, the transaction, and the commit server.
  11257.  
  11258.    ■   The TRANSACT-SQL update statements.
  11259.  
  11260.    ■   A PREPARE TRANSACTION statement that indicates that the updates have
  11261.        been performed and that the server is prepared to commit. This
  11262.        statement cannot be used outside of the context of DB-LIBRARY.
  11263.  
  11264.  
  11265.  After the updates have been performed on all servers participating in the
  11266.  distributed transaction, the two-phase commit begins. In the first phase,
  11267.  all servers agree that they are ready to commit. In the second phase, they
  11268.  all commit─a COMMIT TRANSACTION is executed to all servers. The application
  11269.  then tells the commit service that the transaction is complete, and the
  11270.  connections are closed.
  11271.  
  11272.  If an error occurs between phase one and two, all servers coordinate with
  11273.  the commit service to see if the transaction should be committed or aborted.
  11274.  
  11275.  
  11276.  
  11277.  The Commit Service and the Application Program
  11278.  
  11279.  The role of the commit service is to be a single place of record that helps
  11280.  the application decide whether the transaction should be committed or
  11281.  aborted.
  11282.  
  11283.  If all SQL Servers are prepared to commit, the application notifies the
  11284.  commit service to mark the transaction as committed. Once this happens, the
  11285.  transaction is committed despite any failures that might subsequently
  11286.  happen.
  11287.  
  11288.  If any SQL Server or the application program fails before the PREPARE
  11289.  TRANSACTION statement, the SQL Server rolls back the transaction. If any SQL
  11290.  Server or the application program fails after the PREPARE but before the
  11291.  COMMIT, SQL Server communicates with the server functioning as the commit
  11292.  service and asks it whether to roll back or commit.
  11293.  
  11294.  The role of the application program is to deliver the TRANSACT-SQL
  11295.  statements to the SQL Servers in the proper order, using the proper
  11296.  DB-LIBRARY functions and macros. The role of the commit service is to
  11297.  provide a single place where the commit/rollback status is maintained. The
  11298.  SQL Servers communicate with the commit service only if a failure happens
  11299.  during the two-phase commit.
  11300.  
  11301.  The commit service needs its own DBPROCESS, separate from the DBPROCESS
  11302.  structures used for the distributed transaction, to perform its
  11303.  record-keeping. Note, however, that the server handling the commit service
  11304.  can also be one of the servers participating in the transaction, as long as
  11305.  the commit service has its own DBPROCESS. In fact, all the servers involved
  11306.  in the transaction can be one and the same.
  11307.  
  11308.  
  11309.  The Probe Process
  11310.  
  11311.  If any server must recover the transaction, it initiates a process, probe,
  11312.  that determines the last known status of the transaction. After it returns
  11313.  the status of that transaction to the commit service, the probe process
  11314.  dies. The probe process makes use of the same status-checking function,
  11315.  stat_xact, that the commit service uses to check on the progress of a
  11316.  distributed transaction.
  11317.  
  11318.  
  11319.  The Two-Phase Commit Functions
  11320.  
  11321.  The functions that make up the two-phase commit service are as follows:
  11322.  
  11323.  open_commit
  11324.    Opens a connection with the commit service. The function is given the
  11325.    login ID of the user initiating the session and the name of the commit
  11326.    service. It returns a pointer to a DBPROCESS structure used in subsequent
  11327.    commit service calls.
  11328.  
  11329.  start_xact
  11330.    Records the start of a distributed transaction and stores initial
  11331.    information about the transaction (DBPROCESS ID, application name,
  11332.    transaction name, and number of sites participating) in a lookup table on
  11333.    the commit server. It returns the commid identifying number for the
  11334.    transaction.
  11335.  
  11336.  build_xact_string
  11337.    Builds a name string for use by each participating SQL Server for its
  11338.    BEGIN TRANSACTION and PREPARE TRANSACTION statements. This string encodes
  11339.    the application's transaction name, the commit service name, and the
  11340.    commid.
  11341.  
  11342.  commit_xact
  11343.    Tells the commit service to commit the transaction.
  11344.  
  11345.  abort_xact
  11346.    Tells the commit service to abort the transaction.
  11347.  
  11348.  remove_xact
  11349.    Decreases the number of servers still participating in the transaction.
  11350.  
  11351.  close_commit
  11352.    Closes the connection with the commit service.
  11353.  
  11354.  Two additional functions are used for ongoing status reports:
  11355.  
  11356.  scan_xact
  11357.    Returns the status of a single transaction or all distributed
  11358.    transactions.
  11359.  
  11360.  stat_xact
  11361.    Returns the completion status of a distributed transaction.
  11362.  
  11363.  During the course of a session, the diagnostic functions, scan_xact and
  11364.  stat_xact, are used to check that the commit service carried out the
  11365.  request.
  11366.  
  11367.  The scan_xact function uses the commit service lookup table, spt_committab,
  11368.  which holds the values of the following:
  11369.  
  11370.  
  11371.    ■   Transaction ID
  11372.  
  11373.    ■   Time the transaction started
  11374.  
  11375.    ■   Last time the row was updated
  11376.  
  11377.    ■   Number of servers initially involved in the transaction
  11378.  
  11379.    ■   Number of servers that still have not completed
  11380.  
  11381.    ■   Status ("a"-abort, "c"-commit, "b"-begin)
  11382.  
  11383.    ■   Application name
  11384.  
  11385.    ■   Transaction name
  11386.  
  11387.  
  11388.  The two-phase commit functions call internal stored procedures (for example,
  11389.  sp_start_xact) that are created in each server's master database. The
  11390.  instos2.sql script creates the commit service lookup table and stored
  11391.  procedures in each server's master database for use whenever that server
  11392.  becomes a commit server.
  11393.  
  11394.  
  11395.  Specifying the Commit Server
  11396.  
  11397.  The name of the commit server is used as a parameter in a call to the
  11398.  open_commit function. The commit server name must be the same on all
  11399.  machines participating in the transaction.
  11400.  
  11401.  
  11402.  Two-Phase Commit Example Program
  11403.  
  11404.  The example program illustrates the two-phase commit service. An online
  11405.  version of the example source code, twophase.c, is included in the
  11406.  DB-LIBRARY sample code directory. This directory is described in Chapter 3,
  11407.  "Example Programs."
  11408.  
  11409.  To compile and link the example, follow the instructions given in Chapter 3,
  11410.  "Example Programs," for compiling and linking programs under your operating
  11411.  system. This example assumes that you have two servers running, "sql_svr1"
  11412.  and "sql_svr2". If you don't have a second server available, contact your
  11413.  System Administrator. If your servers are named differently, you will need
  11414.  to replace "sql_svr1" and "sql_svr2" in the source code with the actual
  11415.  names of your servers.
  11416.  
  11417.    /* Demo of Two-Phase Commit Service
  11418.     **
  11419.     ** This example uses the two-phase commit service
  11420.     ** to perform a simultaneous update on two servers.
  11421.     ** In this example, one of the servers participating
  11422.     ** in the distributed transaction also functions as
  11423.     ** the commit service.
  11424.     **
  11425.     ** In this particular example, the same update is
  11426.     ** performed on both servers. You can, however, use
  11427.     ** the commit server to perform completely different
  11428.     ** updates on each server.
  11429.     **
  11430.     */
  11431.  
  11432.     #include <stdio.h>
  11433.     #include <sqlfront.h>
  11434.     #include <sqldb.h>
  11435.  
  11436.     char cmdbuf[256];
  11437.     char xact_string[128];
  11438.  
  11439.     /* Forward declarations of the error handler and message handler. */
  11440.     int err_handler();
  11441.     int msg_handler();
  11442.  
  11443.     main(argv,argc)
  11444.     int argc;
  11445.     char *argv[];
  11446.     {
  11447.  
  11448.      DBPROCESS *dbproc_server1;
  11449.      DBPROCESS *dbproc_server2;
  11450.      DBPROCESS *dbproc_commit;
  11451.      LOGINREC *login;
  11452.      DBINT commid;
  11453.  
  11454.      RETCODE ret_server1;
  11455.      RETCODE ret_server2;
  11456.  
  11457.      dberrhandle(err_handler);
  11458.      dbmsghandle(msg_handler);
  11459.  
  11460.      printf("Demo of Two Phase Commit\n");
  11461.  
  11462.      /* Open connections with the servers and the commit service. */
  11463.      login = dblogin();
  11464.      DBSETLUSER(login, "user");
  11465.      DBSETLPWD(login, "my_passwd");
  11466.      DBSETLAPP(login, "example");
  11467.      dbproc_server1 = dbopen (login, "sql_svr1");
  11468.      dbproc_server2 = dbopen (login, "sql_svr2");
  11469.      dbproc_commit = open_commit (login, "sql_svr1");
  11470.  
  11471.      if (dbproc_server1 == NULL ||
  11472.       dbproc_server2 == NULL ||
  11473.       dbproc_commit == NULL)
  11474.      {
  11475.       printf (" Connections failed!\n");
  11476.       exit (ERREXIT);
  11477.      }
  11478.  
  11479.      /* Use the "pubs" database. */
  11480.      dbuse(dbproc_server1, "pubs");
  11481.      dbuse(dbproc_server2, "pubs");
  11482.  
  11483.      /* Start the distributed transaction on the commit service. */
  11484.      commid = start_xact(dbproc_commit, "demo", "test", 2);
  11485.  
  11486.      /* Build the transaction name. */
  11487.      build_xact_string ("test", "SERVICE", commid, xact_string);
  11488.  
  11489.      /* Build the first command buffer. */
  11490.      sprintf(cmdbuf, "BEGIN TRANSACTION %s", xact_string);
  11491.  
  11492.      /* Begin the transactions on the different servers. */
  11493.      dbcmd(dbproc_server1, cmdbuf);
  11494.      dbsqlexec(dbproc_server1);
  11495.      dbcmd(dbproc_server2, cmdbuf);
  11496.      dbsqlexec(dbproc_server2);
  11497.  
  11498.      /* Do various updates. */
  11499.      sprintf(cmdbuf, " update titles set price = $1.50 where");
  11500.      strcat(cmdbuf, " title_id = 'BU1032'");
  11501.      dbcmd(dbproc_server1, cmdbuf);
  11502.      ret_server1 = dbsqlexec(dbproc_server1);
  11503.      dbcmd(dbproc_server2, cmdbuf);
  11504.      ret_server2 =dbsqlexec(dbproc_server2);
  11505.      if (ret_server1 == FAIL || ret_server2 == FAIL)
  11506.      {
  11507.       /* Some part of the transaction failed. */
  11508.       printf(" Transaction aborted -- dbsqlexec failed\n");
  11509.       abortall(dbproc_server1, dbproc_server2, dbproc_commit, commid);
  11510.      }
  11511.  
  11512.      /* Find out if all servers can commit the transaction. */
  11513.      sprintf(cmdbuf, "PREPARE TRANSACTION");
  11514.      dbcmd(dbproc_server1, cmdbuf);
  11515.      dbcmd(dbproc_server2, cmdbuf);
  11516.      ret_server1 = dbsqlexec(dbproc_server1);
  11517.      ret_server2 = dbsqlexec(dbproc_server2);
  11518.      if (ret_server1 == FAIL || ret_server2 == FAIL)
  11519.      {
  11520.       /* One or both of the servers failed to prepare. */
  11521.       printf(" Transaction aborted -- PREPARE failed\n");
  11522.       abortall(dbproc_server1, dbproc_server2, dbproc_commit, commid);
  11523.      }
  11524.  
  11525.      /* Commit the transaction. */
  11526.      if (commit_xact(dbproc_commit, commid) == FAIL)
  11527.      {
  11528.       /* The commit server failed to record the commit. */
  11529.       printf( " Transaction aborted -- commit_xact failed\n");
  11530.       abortall(dbproc_server1, dbproc_server2, dbproc_commit, commid);
  11531.       exit(ERREXIT);
  11532.      }
  11533.  
  11534.      /* The transaction has successfully committed. Inform the servers. */
  11535.      sprintf(cmdbuf, "COMMIT TRANSACTION");
  11536.      dbcmd(dbproc_server1, cmdbuf);
  11537.      if (dbsqlexec(dbproc_server1) != FAIL)
  11538.       remove_xact(dbproc_commit, commid, 1);
  11539.      dbcmd(dbproc_server2, cmdbuf);
  11540.      if (dbsqlexec(dbproc_server2) != FAIL)
  11541.       remove_xact(dbproc_commit, commid, 1);
  11542.  
  11543.      /* Close the connection to the commit server. */
  11544.      close_commit(dbproc_commit);
  11545.  
  11546.      printf( "We made it!\n");
  11547.      dbexit();
  11548.      exit(STDEXIT);
  11549.     }
  11550.  
  11551.     /* Function to abort the distributed transaction. */
  11552.  
  11553.     abortall( dbproc_server1, dbproc_server2, dbproc_commit, commid )
  11554.     DBPROCESS *dbproc_server1;
  11555.     DBPROCESS *dbproc_server2;
  11556.     DBPROCESS *dbproc_commit;
  11557.     DBINT commid;
  11558.     {
  11559.      /* Some part of the transaction failed. */
  11560.  
  11561.      /* Inform the commit server of the failure. */
  11562.      abort_xact(dbproc_commit, commid);
  11563.  
  11564.      /* Roll back the transactions on the different servers. */
  11565.      sprintf(cmdbuf, "ROLLBACK TRANSACTION");
  11566.      dbcmd(dbproc_server1, cmdbuf);
  11567.      if (dbsqlexec(dbproc_server1) != FAIL)
  11568.       remove_xact(dbproc_commit, commid, 1);
  11569.      dbcmd(dbproc_server2, cmdbuf);
  11570.      if (dbsqlexec(dbproc_server2) != FAIL)
  11571.       remove_xact(dbproc_commit, commid, 1);
  11572.  
  11573.      dbexit();
  11574.      exit(ERREXIT);
  11575.     }
  11576.     /* Message and error-handling functions. */
  11577.     int msg_handler(dbproc,msgno,msgstate, severity, msgtext)
  11578.     DBPROCESS *dbproc;
  11579.     DBINT msgno;
  11580.     int msgstate;
  11581.     int severity;
  11582.     char *msgtext;
  11583.     {
  11584.      /* Msg 5701 is just a USE DATABASE message, so skip it. */
  11585.      if (msgno == 5701)
  11586.       return (0);
  11587.      /* Print any severity 0 message as is, without extra stuff. */
  11588.      if (severity == 0)
  11589.      {
  11590.       printf ("%s\n",msgtext);
  11591.       return (0);
  11592.      }
  11593.  
  11594.      printf("SQL Server message %ld, severity %d:\n\t%s\n",
  11595.       msgno, severity, msgtext);
  11596.  
  11597.      if (severity >= 16)
  11598.      {
  11599.       printf("Program Terminated! Fatal SQL Server error.\n");
  11600.       exit(ERREXIT);
  11601.      }
  11602.      return (0);
  11603.     }
  11604.  
  11605.     int err_handler(dbproc, severity, dberr, oserr, dberrstr, oserrstr)
  11606.     DBPROCESS *dbproc;
  11607.     int severity;
  11608.     int dberr;
  11609.     int oserr;
  11610.     char *dberrstr;
  11611.     char *oserrstr;
  11612.     {
  11613.      if ((dbproc == NULL) || (DBDEAD(dbproc)))
  11614.       return (INT_EXIT);
  11615.      else
  11616.      {
  11617.       printf ("DB-LIBRARY error: \n\t%s\n", dberrstr);
  11618.  
  11619.       if (oserr != DBNOERR)
  11620.        printf ("Operating system error:\n\t%s\n", oserrstr);
  11621.      }
  11622.      return (INT_CANCEL);
  11623.     }
  11624.  
  11625.  
  11626.  
  11627.  
  11628.  
  11629.  abort_xact
  11630.  ────────────────────────────────────────────────────────────────────────────
  11631.  
  11632.  
  11633.  Function
  11634.  
  11635.  Marks a distributed transaction as being aborted.
  11636.  
  11637.  
  11638.  Syntax
  11639.  
  11640.    RETCODE abort_xact(connect, commid)
  11641.  
  11642.     DBPROCESS *connect;
  11643.     DBINT  commid;
  11644.  
  11645.  
  11646.  Comments
  11647.  
  11648.  This function informs the commit service that the status of a distributed
  11649.  transaction should be changed from "begin" to "abort."
  11650.  
  11651.  
  11652.  Parameters
  11653.  
  11654.  connect
  11655.    The DBPROCESS used to communicate with the commit service.
  11656.  
  11657.  commid
  11658.    The number used by the commit service to identify the transaction.
  11659.  
  11660.  
  11661.  Returns
  11662.  
  11663.  SUCCEED or FAIL.
  11664.  
  11665.  
  11666.  See Also
  11667.  
  11668.  commit_xact, remove_xact, scan_xact, start_xact, stat_xact
  11669.  
  11670.  
  11671.  build_xact_string
  11672.  ────────────────────────────────────────────────────────────────────────────
  11673.  
  11674.  
  11675.  Function
  11676.  
  11677.  Builds a name for a distributed transaction.
  11678.  
  11679.  
  11680.  Syntax
  11681.  
  11682.    void build_xact_string(xact_name, service_name, commid, result)
  11683.  
  11684.     char *xact_name;
  11685.     char *service_name;
  11686.     DBINT commid;
  11687.     char *result;
  11688.  
  11689.  
  11690.  Comments
  11691.  
  11692.  This function builds a name string for use in the BEGIN TRANSACTION and
  11693.  PREPARE TRANSACTION of the SQL Server transaction. If SQL Server has to
  11694.  recover the transaction, it uses information encoded in the name to
  11695.  determine which commit service to contact and which transaction in that
  11696.  service to inquire about. The application should execute a TRANSACT-SQL
  11697.  BEGIN TRANSACTION statement using the string built by build_xact_string.
  11698.  
  11699.  
  11700.  Parameters
  11701.  
  11702.  xact_name
  11703.    The application or user name for the transaction. This name is encoded in
  11704.    the name string but is not used by the commit service or SQL Server. It
  11705.    serves to identify the transaction for debugging purposes.
  11706.  
  11707.  service_name
  11708.    The name SQL Server will use to contact the commit service, should it be
  11709.    necessary to recover the transaction. If service_name is NULL, the name
  11710.    DSCOMMIT is used.
  11711.  
  11712.  commid
  11713.    The number used by the commit service to identify the transaction. The
  11714.    commid is the number returned by the call to start_xact.
  11715.  
  11716.  result
  11717.    The address of the buffer where the string should be built. The space must
  11718.    be allocated by the caller.
  11719.  
  11720.  
  11721.  Returns
  11722.  
  11723.  None.
  11724.  
  11725.  
  11726.  See Also
  11727.  
  11728.  commit_xact, start_xact
  11729.  
  11730.  
  11731.  close_commit
  11732.  ────────────────────────────────────────────────────────────────────────────
  11733.  
  11734.  
  11735.  Function
  11736.  
  11737.  Ends a connection with the commit service.
  11738.  
  11739.  
  11740.  Syntax
  11741.  
  11742.    void close_commit(connect)
  11743.  
  11744.     DBPROCESS *connect;
  11745.  
  11746.  
  11747.  Comments
  11748.  
  11749.  This function calls dbclose to end a connection with the commit service.
  11750.  When the application is through with the commit service, a call to
  11751.  close_commit should be made to free resources.
  11752.  
  11753.  
  11754.  Parameters
  11755.  
  11756.  connect
  11757.    The pointer to the DBPROCESS structure that was originally returned by
  11758.    open_commit.
  11759.  
  11760.  
  11761.  Returns
  11762.  
  11763.  None.
  11764.  
  11765.  
  11766.  See Also
  11767.  
  11768.  dbclose, open_commit
  11769.  
  11770.  
  11771.  commit_xact
  11772.  ────────────────────────────────────────────────────────────────────────────
  11773.  
  11774.  
  11775.  Function
  11776.  
  11777.  Marks a distributed transaction as being committed.
  11778.  
  11779.  
  11780.  Syntax
  11781.  
  11782.    RETCODE commit_xact(connect, commid)
  11783.  
  11784.     DBPROCESS *connect;
  11785.     DBINT  commid;
  11786.  
  11787.  
  11788.  Comments
  11789.  
  11790.  This function informs the commit service that the status of a distributed
  11791.  transaction should be changed from "begin" to "commit."
  11792.  
  11793.  
  11794.  Parameters
  11795.  
  11796.  connect
  11797.    The DBPROCESS used to communicate with the commit service.
  11798.  
  11799.  commid
  11800.    The number used by the commit service to identify the transaction.
  11801.  
  11802.  
  11803.  Returns
  11804.  
  11805.  SUCCEED or FAIL.
  11806.  
  11807.  
  11808.  See Also
  11809.  
  11810.  abort_xact, remove_xact, scan_xact, start_xact, stat_xact
  11811.  
  11812.  
  11813.  open_commit
  11814.  ────────────────────────────────────────────────────────────────────────────
  11815.  
  11816.  
  11817.  Function
  11818.  
  11819.  Establishes a connection with the commit service.
  11820.  
  11821.  
  11822.  Syntax
  11823.  
  11824.    DBPROCESS *open_commit(login, servername)
  11825.  
  11826.     LOGINREC *login;
  11827.     char  *servername;
  11828.  
  11829.  
  11830.  Comments
  11831.  
  11832.  This function calls dbopen to establish a connection with the commit
  11833.  service. A call to open_commit must precede any calls to other commit
  11834.  service functions, such as start_xact, commit_xact, abort_xact, remove_xact,
  11835.  and scan_xact. A session with the commit service is closed by calling
  11836.  close_commit.
  11837.  
  11838.  
  11839.  Parameters
  11840.  
  11841.  login
  11842.    A LOGINREC containing information about the user initiating the session,
  11843.    such as login name, password, or options desired. The LOGINREC must have
  11844.    been obtained from a prior call to the DB-LIBRARY function dblogin. The
  11845.    caller may want to initialize fields in the LOGINREC. See "dblogin" for
  11846.    more details.
  11847.  
  11848.  servername
  11849.    The name of the commit service, for example, "my_server".
  11850.  
  11851.  
  11852.  Returns
  11853.  
  11854.  A pointer to a DBPROCESS structure used in subsequent commit service calls
  11855.  or other DB-LIBRARY calls, or NULL if the open failed.
  11856.  
  11857.  
  11858.  See Also
  11859.  
  11860.  abort_xact, close_commit, commit_xact, dblogin, dbopen, remove_xact,
  11861.  scan_xact, start_xact
  11862.  
  11863.  
  11864.  remove_xact
  11865.  ────────────────────────────────────────────────────────────────────────────
  11866.  
  11867.  
  11868.  Function
  11869.  
  11870.  Decrements the count of sites still active in the distributed transaction.
  11871.  
  11872.  
  11873.  Syntax
  11874.  
  11875.    RETCODE remove_xact(connect, commid, n)
  11876.  
  11877.     DBPROCESS *connect;
  11878.     DBINT  commid;
  11879.     int   n;
  11880.  
  11881.  
  11882.  Comments
  11883.  
  11884.  The commit service keeps a count of the number of sites participating in a
  11885.  distributed transaction. This function informs the commit service that one
  11886.  or more sites has done a local commit or abort on the transaction and hence
  11887.  is no longer participating. The commit service removes the sites from the
  11888.  transaction by decrementing the count of sites. The transaction record is
  11889.  deleted entirely if the count drops to zero.
  11890.  
  11891.  
  11892.  Parameters
  11893.  
  11894.  connect
  11895.    The DBPROCESS used to communicate with the commit service.
  11896.  
  11897.  commid
  11898.    The number used by the commit service to identify the transaction.
  11899.  
  11900.  n
  11901.    The number of sites to remove from the transaction.
  11902.  
  11903.  
  11904.  Returns
  11905.  
  11906.  SUCCEED or FAIL.
  11907.  
  11908.  
  11909.  See Also
  11910.  
  11911.  abort_xact, commit_xact, scan_xact, start_xact, stat_xact
  11912.  
  11913.  
  11914.  scan_xact
  11915.  ────────────────────────────────────────────────────────────────────────────
  11916.  
  11917.  
  11918.  Function
  11919.  
  11920.  Prints the commit service record for distributed transactions.
  11921.  
  11922.  
  11923.  Syntax
  11924.  
  11925.    RETCODE scan_xact(connect, commid)
  11926.  
  11927.     DBPROCESS *connect;
  11928.     DBINT  commid;
  11929.  
  11930.  
  11931.  Comments
  11932.  
  11933.  This function displays the commit service record for a specific distributed
  11934.  transaction or for all distributed transactions known to the commit service
  11935.  or the default output device.
  11936.  
  11937.  This function is not supported under Microsoft Windows.
  11938.  
  11939.  
  11940.  Parameters
  11941.  
  11942.  connect
  11943.    The DBPROCESS used to communicate with the commit service.
  11944.  
  11945.  commid
  11946.    The number used by the commit service to identify the transaction. If
  11947.    commid is -1, all commit service records are displayed.
  11948.  
  11949.  
  11950.  Returns
  11951.  
  11952.  SUCCEED or FAIL.
  11953.  
  11954.  
  11955.  See Also
  11956.  
  11957.  abort_xact, commit_xact, remove_xact, start_xact, stat_xact
  11958.  
  11959.  
  11960.  start_xact
  11961.  ────────────────────────────────────────────────────────────────────────────
  11962.  
  11963.  
  11964.  Function
  11965.  
  11966.  Starts a distributed transaction using the commit service.
  11967.  
  11968.  
  11969.  Syntax
  11970.  
  11971.    DBINT start_xact(connect, application_name, xact_name, site_count)
  11972.  
  11973.     DBPROCESS *connect;
  11974.     char  *application_name;
  11975.     char  *xact_name;
  11976.     int   site_count;
  11977.  
  11978.  
  11979.  Comments
  11980.  
  11981.  This function records the start of a distributed transaction with the commit
  11982.  service. A record is placed in the commit service containing the commid,
  11983.  which is a number that the caller subsequently uses to identify the
  11984.  transaction to the commit service.
  11985.  
  11986.  
  11987.  Parameters
  11988.  
  11989.  connect
  11990.    The DBPROCESS used to communicate with the commit service.
  11991.  
  11992.  application_name
  11993.    The name of the application. This name can be anything the application
  11994.    chooses. It appears in the table maintained by the commit service but is
  11995.    not used by the commit service or the SQL Server recovery system.
  11996.  
  11997.  xact_name
  11998.    The name of the transaction. This name appears in the table maintained by
  11999.    the commit service and must be supplied as part of the transaction name
  12000.    string built by build_xact_string. The name cannot contain a period (.) or
  12001.    a colon (:).
  12002.  
  12003.  site_count
  12004.    The number of sites participating in the transaction.
  12005.  
  12006.  
  12007.  Returns
  12008.  
  12009.  An integer called commid. This number is used to identify the transaction in
  12010.  subsequent calls to the commit service. In case of error, this function
  12011.  returns 0.
  12012.  
  12013.  
  12014.  See Also
  12015.  
  12016.  abort_xact, build_xact_string, commit_xact, remove_xact, scan_xact,
  12017.  stat_xact
  12018.  
  12019.  
  12020.  stat_xact
  12021.  ────────────────────────────────────────────────────────────────────────────
  12022.  
  12023.  
  12024.  Function
  12025.  
  12026.  Returns the current status of a distributed transaction.
  12027.  
  12028.  
  12029.  Syntax
  12030.  
  12031.    int stat_xact(connect, commid)
  12032.  
  12033.     DBPROCESS *connect;
  12034.     DBINT  commid;
  12035.  
  12036.  
  12037.  Comments
  12038.  
  12039.  This function returns the transaction status for the specified distributed
  12040.  transaction.
  12041.  
  12042.  
  12043.  Parameters
  12044.  
  12045.  connect
  12046.    The DBPROCESS used to communicate with the commit service.
  12047.  
  12048.  commid
  12049.    The number used by the commit service to identify the transaction. If
  12050.    commid is -1, all commit service records are displayed.
  12051.  
  12052.  
  12053.  Returns
  12054.  
  12055.  A character code: "a" (abort), "b" (begin), "c" (commit), "u" (unknown), or
  12056.  -1 (request failed).
  12057.  
  12058.  
  12059.  See Also
  12060.  
  12061.  abort_xact, commit_xact, remove_xact, scan_xact, start_xact
  12062.  
  12063.  
  12064.  
  12065.  
  12066.  
  12067.  
  12068.  Appendix A  Functions and Macros
  12069.  ────────────────────────────────────────────────────────────────────────────
  12070.  
  12071.  
  12072.  DB-LIBRARY Functions and Macros
  12073.  
  12074.  ────────────────────────────────────────────────────────────────────────────
  12075.  dbadata
  12076.    Returns a pointer to the data for a compute column.
  12077.  
  12078.  dbadlen
  12079.    Returns the actual length of the data for a compute column.
  12080.  
  12081.  dbaltbind
  12082.    Binds a compute result column to a program variable.
  12083.  
  12084.  dbaltcolid
  12085.    Returns the operand column ID for a compute column.
  12086.  
  12087.  dbaltlen
  12088.    Returns the maximum length of the data for a compute column.
  12089.  
  12090.  dbaltop
  12091.    Returns the type of aggregate operator for a compute column.
  12092.  
  12093.  dbalttype
  12094.    Returns the datatype for a compute column.
  12095.  
  12096.  dbbind
  12097.    Binds a regular result column to a program variable.
  12098.  
  12099.  dbbylist
  12100.    Returns the bylist for a compute row.
  12101.  
  12102.  dbcancel
  12103.    Cancels the current command batch.
  12104.  
  12105.  dbcanquery
  12106.    Cancels any rows pending from the most recently executed query.
  12107.  
  12108.  dbchange
  12109.    Determines whether a command batch has changed the current database.
  12110.  
  12111.  dbclose
  12112.    Closes and frees a single DBPROCESS structure.
  12113.  
  12114.  dbclrbuf
  12115.    Drops rows from the row buffer.
  12116.  
  12117.  dbclropt
  12118.    Clears an option set by dbsetopt.
  12119.  
  12120.  dbcmd
  12121.    Adds text to the DBPROCESS command buffer.
  12122.  
  12123.  DBCMDROW
  12124.    Determines whether the current command can return rows.
  12125.  
  12126.  dbcolbrowse
  12127.    Determines whether the source of a result column can be updated with the
  12128.    DB-LIBRARY browse-mode facilities.
  12129.  
  12130.  dbcollen
  12131.    Returns the maximum length, in bytes, of the data for a column.
  12132.  
  12133.  dbcolname
  12134.    Returns the name of a particular result column.
  12135.  
  12136.  dbcolsource
  12137.    Returns a pointer to the name of the database column from which the
  12138.    specified result column was derived.
  12139.  
  12140.  dbcoltype
  12141.    Returns the datatype for a column.
  12142.  
  12143.  dbconvert
  12144.    Converts data from one datatype to another.
  12145.  
  12146.  DBCOUNT
  12147.    Returns the number of rows affected by a TRANSACT-SQL statement.
  12148.  
  12149.  DBCURCMD
  12150.    Returns the number of the current command.
  12151.  
  12152.  DBCURROW
  12153.    Returns the number of the row currently being read.
  12154.  
  12155.  dbdata
  12156.    Returns a pointer to the data for a result column.
  12157.  
  12158.  dbdataready
  12159.    Determines whether database command processing has completed.
  12160.  
  12161.  dbdatlen
  12162.    Returns the actual length, in bytes, of the data for a column.
  12163.  
  12164.  DBDEAD
  12165.    Determines whether a particular DBPROCESS is dead.
  12166.  
  12167.  dberrhandle
  12168.    Supplies a user function to handle DB-LIBRARY errors.
  12169.  
  12170.  dbexit
  12171.    Closes and frees all DBPROCESS structures created as a result of your
  12172.    program.
  12173.  
  12174.  dbfcmd
  12175.    Adds text to the DBPROCESS command buffer using C run-time library
  12176.    sprintf-type formatting.
  12177.  
  12178.  DBFIRSTROW
  12179.    Returns the number of the first row in the row buffer.
  12180.  
  12181.  dbfreebuf
  12182.    Sets the command buffer in a DBPROCESS structure to NULL.
  12183.  
  12184.  dbfreelogin
  12185.    Frees a login record.
  12186.  
  12187.  dbfreequal
  12188.    Frees memory allocated by the dbqual function.
  12189.  
  12190.  dbgetchar
  12191.    Returns a pointer to a character in the command buffer.
  12192.  
  12193.  dbgetmaxprocs
  12194.    Determines the current maximum number of simultaneously open DBPROCESS
  12195.    structures.
  12196.  
  12197.  dbgetoff
  12198.    Checks for the existence of TRANSACT-SQL constructs in the command buffer.
  12199.  
  12200.  dbgetrow
  12201.    Reads the specified row in the row buffer.
  12202.  
  12203.  DBGETTIME
  12204.    Returns the number of seconds that DB-LIBRARY will wait for an SQL Server
  12205.    response to a TRANSACT-SQL statement.
  12206.  
  12207.  dbinit
  12208.    Initializes the DB-LIBRARY application under Windows.
  12209.  
  12210.  DBISAVAIL
  12211.    Determines whether a DBPROCESS is available for general use.
  12212.  
  12213.  dbisopt
  12214.    Checks the status of an SQL Server or DB-LIBRARY option.
  12215.  
  12216.  DBLASTROW
  12217.    Returns the number of the last row in the row buffer.
  12218.  
  12219.  DBLOCKLIB
  12220.    Locks DB-LIBRARY segments under Windows.
  12221.  
  12222.  dblogin
  12223.    Allocates a login record for use in dbopen.
  12224.  
  12225.  DBMORECMDS
  12226.    Indicates whether there are more commands to be processed.
  12227.  
  12228.  dbmoretext
  12229.    Sends part of a text or image value to SQL Server.
  12230.  
  12231.  dbmsghandle
  12232.    Supplies a user function to handle SQL Server messages.
  12233.  
  12234.  dbname
  12235.    Returns the name of the current database.
  12236.  
  12237.  dbnextrow
  12238.    Reads in the next row.
  12239.  
  12240.  dbnumalts
  12241.    Returns the number of columns in a particular compute row.
  12242.  
  12243.  dbnumcols
  12244.    Determines the number of columns for the current set of results.
  12245.  
  12246.  dbnumcompute
  12247.    Returns the number of COMPUTE clauses in the current set of results.
  12248.  
  12249.  DBNUMORDERS
  12250.    Returns the number of columns specified in a TRANSACT-SQL SELECT
  12251.    statement's ORDER BY clause.
  12252.  
  12253.  dbopen
  12254.    Allocates and initializes a DBPROCESS structure.
  12255.  
  12256.  dbordercol
  12257.    Returns the ID of a column appearing in the most recently executed query's
  12258.    ORDER BY clause.
  12259.  
  12260.  dbprhead
  12261.    Prints the column headings for rows returned from SQL Server.
  12262.  
  12263.  dbprrow
  12264.    Prints all rows returned from SQL Server.
  12265.  
  12266.  dbprtype
  12267.    Converts an SQL Server type token to a readable string.
  12268.  
  12269.  dbqual
  12270.    Returns a pointer to a WHERE clause suitable for use in updating the
  12271.    current row in a table that can be browsed.
  12272.  
  12273.  DBRBUF
  12274.    Determines whether database command processing has completed.
  12275.  
  12276.  dbreadpage
  12277.    Reads in a page of binary data from SQL Server.
  12278.  
  12279.  dbresults
  12280.    Sets up the results of the next query.
  12281.  
  12282.  DBROWS
  12283.    Indicates whether the current statement actually returned rows.
  12284.  
  12285.  DBROWTYPE
  12286.    Returns the type of the current row.
  12287.  
  12288.  dbsetavail
  12289.    Marks a DBPROCESS as being available for general use.
  12290.  
  12291.  DBSETLAPP
  12292.    Sets the application name in the LOGINREC structure.
  12293.  
  12294.  DBSETLHOST
  12295.    Sets the workstation name in the LOGINREC structure.
  12296.  
  12297.  dbsetlogintime
  12298.    Sets the number of seconds that DB-LIBRARY waits for an SQL Server
  12299.    response to a request for a DBPROCESS connection.
  12300.  
  12301.  DBSETLPWD
  12302.    Sets the user SQL Server password in the LOGINREC structure.
  12303.  
  12304.  DBSETLUSER
  12305.    Sets the username in the LOGINREC structure.
  12306.  
  12307.  dbsetmaxprocs
  12308.    Sets the maximum number of simultaneously open DBPROCESS structures.
  12309.  
  12310.  dbsetnull
  12311.    Defines substitution values to be used when binding null values.
  12312.  
  12313.  dbsetopt
  12314.    Sets an SQL Server or DB-LIBRARY option.
  12315.  
  12316.  dbsettime
  12317.    Sets the number of seconds that DB-LIBRARY will wait for an SQL Server
  12318.    response to a TRANSACT-SQL statement.
  12319.  
  12320.  dbsqlexec
  12321.    Sends a command batch to SQL Server.
  12322.  
  12323.  dbsqlok
  12324.    Verifies the correctness of a command batch.
  12325.  
  12326.  dbsqlsend
  12327.    Sends a command batch to SQL Server and does not wait for a response.
  12328.  
  12329.  dbstrcpy
  12330.    Copies a portion of the command buffer.
  12331.  
  12332.  dbstrlen
  12333.    Returns the length, in characters, of the command buffer.
  12334.  
  12335.  dbtabbrowse
  12336.    Determines whether the specified table can be updated with the DB-LIBRARY
  12337.    browse-mode facilities.
  12338.  
  12339.  dbtabcount
  12340.    Returns the number of tables involved in the current SELECT statement.
  12341.  
  12342.  dbtabname
  12343.    Returns the name of a table based on its number.
  12344.  
  12345.  dbtabsource
  12346.    Returns the name and number of the table from which a particular result
  12347.    column was derived.
  12348.  
  12349.  dbtsnewlen
  12350.    Returns the length of the new value of the timestamp column after a
  12351.    browse-mode update.
  12352.  
  12353.  dbtsnewval
  12354.    Returns the new value of the timestamp column after a browse mode update.
  12355.  
  12356.  dbtsput
  12357.    Puts the new value of the timestamp column into the given table's current
  12358.    row in the DBPROCESS.
  12359.  
  12360.  dbtxptr
  12361.    Returns the value of the text pointer for a column in the current row.
  12362.  
  12363.  dbtxtimestamp
  12364.    Returns the value of the text timestamp for a column in the current row.
  12365.  
  12366.  dbtxtsnewval
  12367.    Returns the new value of a text timestamp after a call to dbwritetext.
  12368.  
  12369.  dbtxtsput
  12370.    Puts the new value of a text timestamp into the specified column of the
  12371.    current row in the DBPROCESS.
  12372.  
  12373.  DBUNLOCKLIB
  12374.    Unlocks DB-LIBRARY segments under Windows.
  12375.  
  12376.  dbuse
  12377.    Uses a particular database.
  12378.  
  12379.  dbwillconvert
  12380.    Determines whether a specific data conversion is available within
  12381.    DB-LIBRARY.
  12382.  
  12383.  dbwinexit
  12384.    De-registers an application from the DB-LIBRARY in the Windows
  12385.    environment.
  12386.  
  12387.  dbwritepage
  12388.    Writes a page of binary data to SQL Server.
  12389.  
  12390.  dbwritetext
  12391.    Sends a text or image value to SQL Server.
  12392.  
  12393.  ────────────────────────────────────────────────────────────────────────────
  12394.  Bulk Copy Functions
  12395.  
  12396.  ────────────────────────────────────────────────────────────────────────────
  12397.  bcp_batch
  12398.    Saves any preceding rows in SQL Server.
  12399.  
  12400.  bcp_bind
  12401.    Binds data from a program variable to an SQL Server table.
  12402.  
  12403.  bcp_colfmt
  12404.    Specifies the format of an operating system file for bulk copy purposes.
  12405.  
  12406.  bcp_collen
  12407.    Sets the program variable data length for the current copy IN.
  12408.  
  12409.  bcp_colptr
  12410.    Sets the program variable data address for the current copy IN.
  12411.  
  12412.  bcp_columns
  12413.    Sets the total number of columns found in the operating system file.
  12414.  
  12415.  bcp_control
  12416.    Changes various control parameter default settings.
  12417.  
  12418.  bcp_done
  12419.    Ends a bulk copy from program variables into SQL Server.
  12420.  
  12421.  bcp_exec
  12422.    Executes a bulk copy of data between a database table and an operating
  12423.    system file.
  12424.  
  12425.  bcp_init
  12426.    Initializes bulk copy.
  12427.  
  12428.  bcp_moretext
  12429.    Sends part of a text or image value to SQL Server.
  12430.  
  12431.  bcp_sendrow
  12432.    Sends a row of data from program variables to SQL Server.
  12433.  
  12434.  BCP_SETL
  12435.    Sets the LOGINREC for bulk copy operations.
  12436.  
  12437.  ────────────────────────────────────────────────────────────────────────────
  12438.  Two-Phase Commit Functions
  12439.  
  12440.  ────────────────────────────────────────────────────────────────────────────
  12441.  abort_xact
  12442.    Marks a distributed transaction as being aborted.
  12443.  
  12444.  build_xact_string
  12445.    Builds a name for a distributed transaction.
  12446.  
  12447.  close_commit
  12448.    Ends a connection with the commit service.
  12449.  
  12450.  commit_xact
  12451.    Marks a distributed transaction as being committed.
  12452.  
  12453.  open_commit
  12454.    Establishes a connection with the commit service.
  12455.  
  12456.  remove_xact
  12457.    Decrements the count of sites still active in the distributed transaction.
  12458.  
  12459.  scan_xact
  12460.    Prints the commit service record for distributed transactions.
  12461.  
  12462.  start_xact
  12463.    Starts a distributed transaction using the commit service.
  12464.  
  12465.  stat_xact
  12466.    Returns the current status of a distributed transaction.
  12467.  
  12468.  ────────────────────────────────────────────────────────────────────────────
  12469.  
  12470.  
  12471.  
  12472.  
  12473.  Appendix B  DB-LIBRARY Options
  12474.  ────────────────────────────────────────────────────────────────────────────
  12475.  
  12476.  
  12477.  Introduction
  12478.  
  12479.  This appendix describes the DB-LIBRARY options. To use these options, you
  12480.  must include the sqlfront.h and sqldb.h header files in your program.
  12481.  
  12482.  
  12483.  Options
  12484.  
  12485.  The following options are available (all options are off by default):
  12486.  
  12487.  ────────────────────────────────────────────────────────────────────────────
  12488.  DBARITHABORT
  12489.    When an arithmetic exception occurs during execution, aborts the query.
  12490.  
  12491.  DBARITHIGNORE
  12492.    When an arithmetic exception occurs during query execution, substitutes
  12493.    null values for selected or updated values. No warning message is
  12494.    returned. If neither DBARITHABORT nor DBARITHIGNORE is set, SQL Server
  12495.    substitutes null values and prints a warning message after the query has
  12496.    been executed.
  12497.  
  12498.  DBBUFFER
  12499.    Buffers result rows. It is required if the dbgetrow function is used. This
  12500.    option is handled locally by DB-LIBRARY and is not an SQL Server option.
  12501.    When the option is set, you supply a parameter for the number of rows you
  12502.    want buffered. If you use a value less than 0 as the number of rows to
  12503.    buffer, the buffer will be set to the default size (currently 100).
  12504.    Buffering of only one row is not allowed. (See "dbnextrow," "dbgetrow,"
  12505.    and "dbclrbuf" for more information about buffered rows.)
  12506.  
  12507.  DBNOAUTOFREE
  12508.    Causes the command buffer to be cleared only by a call to dbfreebuf. When
  12509.    DBNOAUTOFREE is not set, after a call to dbsqlexec or dbsqlsend, the first
  12510.    call to either dbcmd or dbfcmd automatically clears the command buffer
  12511.    before the new text is entered. This is not an SQL Server option.
  12512.  
  12513.  DBNOCOUNT
  12514.    Stops sending back information about the number of rows affected by each
  12515.    SQL statement. The application can otherwise obtain this information by
  12516.    calling DBCOUNT.
  12517.  
  12518.  DBNOEXEC
  12519.    Processes the query through the compile step but does not execute it. This
  12520.    could be used in conjunction with DBSHOWPLAN.
  12521.  
  12522.  DBOFFSET
  12523.    Indicates where SQL Server should return offsets to certain constructs in
  12524.    the query. This option takes a parameter that specifies the particular
  12525.    construct. The valid parameters for this option are SELECT, FROM, TABLE,
  12526.    ORDER, COMPUTE, STATEMENT, PROCEDURE, EXECUTE, and PARAM. (Note that PARAM
  12527.    refers to parameters of stored procedures.) Calls to functions such as
  12528.    dbsetopt can specify these option parameters in either lowercase or
  12529.    uppercase. For the internal types that correspond to the offsets, see
  12530.    "dbgetoff." Offsets are returned only if the batch contains no syntax
  12531.    errors.
  12532.  
  12533.  DBPARSEONLY
  12534.    Checks the syntax of the query and returns error messages to the
  12535.    workstation. Offsets are returned if the DBOFFSET option is set and there
  12536.    are no errors.
  12537.  
  12538.  DBROWCOUNT
  12539.    Specifies a maximum number of regular rows to be returned on SELECT
  12540.    statements. It does not limit the number of compute rows returned.
  12541.    DBROWCOUNT works somewhat differently from most options. It is always on,
  12542.    never off. Setting DBROWCOUNT to 0 sets it back to the default, returning
  12543.    all the rows generated by a SELECT statement. Therefore, the way to turn
  12544.    DBROWCOUNT off is to turn it on with a count of 0.
  12545.  
  12546.  DBSHOWPLAN
  12547.    Generates a description of the processing plan after compilation and
  12548.    continues executing the query.
  12549.  
  12550.  DBSTAT
  12551.    Determines when performance statistics (CPU time, elapsed time, I/O, and
  12552.    so on) will be returned to the workstation after each query. This option
  12553.    takes a parameter with two possible values: IO (for statistics about SQL
  12554.    Server internal I/O) and TIME (for information about SQL Server's parsing,
  12555.    compilation, and execution times). DB-LIBRARY receives these statistics in
  12556.    the form of informational messages, and application programs can access
  12557.    them through the user-supplied message handler.
  12558.  
  12559.  DBSTORPROCID
  12560.    Sends the stored procedure ID to the workstation before sending rows
  12561.    generated by the stored procedure.
  12562.  
  12563.  DBTEXTLIMIT
  12564.    Causes DB-LIBRARY to limit the size of returned text or image values. When
  12565.    setting this option, you supply a parameter that is the length, in bytes,
  12566.    of the longest text or image value that your program can handle.
  12567.    DB-LIBRARY reads but ignores any part of a text or image value that goes
  12568.    over this limit. In the case of huge text values, it may take some time
  12569.    for the entire text value to be returned over the network. To keep SQL
  12570.    Server from sending this extra text in the first place, use the DBTEXTSIZE
  12571.    option instead.
  12572.  
  12573.  DBTEXTSIZE
  12574.    Limits the size of returned text or image values. When setting this
  12575.    option, you supply a parameter that is the length, in bytes, of the
  12576.    longest text or image value that SQL Server should return. Note that in
  12577.    programs that allow users to make ad hoc queries, the user can override
  12578.    this option with the SET TEXTSIZE statement. To set a text limit that the
  12579.    user cannot override, use the DBTEXTLIMIT option instead.
  12580.  
  12581.  ────────────────────────────────────────────────────────────────────────────
  12582.  As mentioned in the preceding descriptions, certain options take parameters:
  12583.  
  12584.  
  12585.  ────────────────────────────────────────────────────────────────────────────
  12586.  DBBUFFER
  12587.    0 to 32,767
  12588.  
  12589.  DBOFFSET
  12590.    SELECT, FROM, TABLE, ORDER, COMPUTE, STATEMENT, PROCEDURE, EXECUTE, or
  12591.    PARAM
  12592.  
  12593.  DBROWCOUNT
  12594.    0 to 2,147,483,647
  12595.  
  12596.  DBSTAT
  12597.    IO or TIME
  12598.  
  12599.  DBTEXTLIMIT
  12600.    0 to 2,147,483,647
  12601.  
  12602.  DBTEXTSIZE
  12603.    0 to 2,147,483,647
  12604.  
  12605.  ────────────────────────────────────────────────────────────────────────────
  12606.  The dbsetopt function requires that an option parameter be specified when
  12607.  setting any option from the preceding list. The dbclropt and dbisopt
  12608.  functions require that the parameter be specified only for DBOFFSET and
  12609.  DBSTAT. This is because DBOFFSET and DBSTAT are the only options that can
  12610.  have multiple settings at a time; thus, they require further definition
  12611.  before being cleared or checked. Note that parameters specified in calls to
  12612.  dbsetopt, dbclropt, and dbisopt are always passed as character strings and
  12613.  must be surrounded by quotation marks, even if they are numeric values. See
  12614.  "dbsetopt" for more information.
  12615.  
  12616.  
  12617.  
  12618.  
  12619.  
  12620.  
  12621.  Appendix C  DB-LIBRARY Datatypes
  12622.  ────────────────────────────────────────────────────────────────────────────
  12623.  
  12624.  
  12625.  Introduction
  12626.  
  12627.  This appendix contains a list of SQL Server datatypes. To use these
  12628.  datatypes, include the sqlfront.h and sqldb.h header files in your program.
  12629.  For a detailed description of SQL Server datatypes, refer to the SQL Server
  12630.  Language Reference.
  12631.  
  12632.  
  12633.  Datatypes
  12634.  
  12635.  The following list describes the SQL Server datatypes. The dbconvert and
  12636.  dbwillconvert functions use these types. In addition, the dbcoltype function
  12637.  returns one of these types.
  12638.  
  12639. ╓┌─────────────────────────────────┌─────────────────────────────────────────╖
  12640.  Datatype                          Description
  12641.  ────────────────────────────────────────────────────────────────────────────
  12642.  SQLBINARY                         binary type
  12643.  
  12644.  Datatype                          Description
  12645.  ────────────────────────────────────────────────────────────────────────────
  12646. 
  12647.  SQLBIT                            bit type
  12648.  
  12649.  SQLCHAR                           char type
  12650.  
  12651.  SQLDATETIME                       datetime type
  12652.  
  12653.  SQLFLT8                           8-byte float type
  12654.  
  12655.  SQLIMAGE                          image type
  12656.  
  12657.  SQLINT1                           1-byte integer
  12658.  
  12659.  SQLINT2                           2-byte integer
  12660.  
  12661.  SQLINT4                           4-byte integer
  12662.  
  12663.  SQLMONEY                          money type
  12664.  
  12665.  Datatype                          Description
  12666.  ────────────────────────────────────────────────────────────────────────────
  12667. 
  12668.  SQLTEXT                           text type
  12669.  
  12670.  
  12671.  
  12672.  
  12673.  SQL Type Definitions
  12674.  
  12675.  The following type definitions are used by DB-LIBRARY functions. The
  12676.  DB-LIBRARY user will find it convenient to use these when defining C program
  12677.  variables, particularly those used in dbbind, dbaltbind, and dbconvert.
  12678.  
  12679.  
  12680.    typedef char   DBCHAR;  /* char and text type */
  12681.     typedef unsigned char DBBINARY; /* binary and image type */
  12682.     typedef unsigned char DBTINYINT; /* 1-byte integer */
  12683.     typedef short   DBSMALLINT; /* 2-byte integer */
  12684.     typedef unsigned short DBUSMALLINT;/* unsigned 2-byte integer */
  12685.     typedef long   DBINT;  /* 4-byte integer */
  12686.     typedef double   DBFLT8;  /* 8-byte float type */
  12687.     typedef unsigned char DBBIT;  /* bit type */
  12688.     typedef int    RETCODE; /* SUCCEED or FAIL */
  12689.     typedef int    STATUS;  /* OK or condition code */
  12690.     typedef unsigned char DBBOOL;  /* TRUE or FALSE */
  12691.     typedef unsigned char BYTE;  /* A single byte */
  12692.  
  12693.     typedef struct money /* money type */
  12694.     {
  12695.      long mnyhigh;
  12696.      long mnylow;
  12697.     } DBMONEY;
  12698.  
  12699.     typedef struct datetime /* datetime type */
  12700.     {
  12701.      long dtdays;  /* number of days since 1/1/1900 */
  12702.      unsigned long dttime; /* 300ths of a second since midnight */
  12703.     } DBDATETIME;
  12704.  
  12705.     typedef struct dbvarychar /* Pascal-type string. */
  12706.     {
  12707.      DBSMALLINT len;  /* character count */
  12708.      DBCHAR str[DBMAXCHAR]; /* non-terminated string */
  12709.     } DBVARYCHAR;
  12710.  
  12711.     typedef struct dbvarybin /* Pascal-type binary array. */
  12712.     {
  12713.      DBSMALLINT len;  /* byte count */
  12714.      BYTE array[DBMAXCHAR]; /* non-terminated array */
  12715.     } DBVARYBIN;
  12716.  
  12717.     typedef DBSMALLINT DBINDICATOR; /* Used by DB-LIBRARY
  12718.      for indicator variables. */
  12719.  
  12720.  
  12721.  
  12722.  
  12723.  
  12724.  
  12725.  Appendix D  Error Messages
  12726.  ────────────────────────────────────────────────────────────────────────────
  12727.  
  12728.  
  12729.  Introduction
  12730.  
  12731.  This appendix contains the complete range of possible DB-LIBRARY errors and
  12732.  error severity levels. The errors are listed alphabetically, and the error
  12733.  severity levels are listed by increasing severity.
  12734.  
  12735.  These values are passed to the currently installed, user-supplied error
  12736.  handler. For information on creating an error handler function for your
  12737.  application, see "dberrhandle" in Chapter 2, "Functions and Macros."
  12738.  
  12739.  To access these error definitions, include the sqlfront.h and sqldb.h header
  12740.  files in your program.
  12741.  
  12742.  
  12743.  Errors
  12744.  
  12745.  These error values are defined in the header file sqlfront.h.
  12746.  
  12747.  ────────────────────────────────────────────────────────────────────────────
  12748.  SQLEAAMT
  12749.    User attempted a dbaltbind with mismatched column and variable types.
  12750.  
  12751.  
  12752.  
  12753.  SQLEABMT
  12754.    User attempted a dbbind with mismatched column and variable types.
  12755.  
  12756.  
  12757.  
  12758.  SQLEABNC
  12759.    Attempt to bind to a non-existent column.
  12760.  
  12761.  
  12762.  
  12763.  SQLEABNP
  12764.    Attempt to bind using NULL pointers.
  12765.  
  12766.  
  12767.  
  12768.  SQLEASEC
  12769.    Attempt to send an empty command buffer to the SQL Server.
  12770.  
  12771.  
  12772.  
  12773.  SQLEASNL
  12774.    Attempt to set fields in a null loginrec.
  12775.  
  12776.  
  12777.  
  12778.  SQLEASUL
  12779.    Attempt to set unknown loginrec field.
  12780.  
  12781.  
  12782.  
  12783.  SQLEAUTN
  12784.    Attempt to update the timestamp of a table which has no timestamp column.
  12785.  
  12786.  
  12787.  
  12788.  SQLEBBCI
  12789.    Batch successfully bulk-copied to SQL Server.
  12790.  
  12791.  
  12792.  
  12793.  SQLEBCBC
  12794.    bcp_columns() must be called before bcp_colfmt().
  12795.  
  12796.  
  12797.  
  12798.  SQLEBCFO
  12799.    Bcp host-files must contain at least one column.
  12800.  
  12801.  
  12802.  
  12803.  SQLEBCNN
  12804.    Attempt to bulk-copy a NULL value into a Server column which does not
  12805.    accept NULL values.
  12806.  
  12807.  
  12808.  
  12809.  SQLEBCNT
  12810.    Attempt to use Bulk Copy with a non-existent Server table.
  12811.  
  12812.  
  12813.  
  12814.  SQLEBCOR
  12815.    Attempt to bulk-copy an oversized row to the SQL Server.
  12816.  
  12817.  
  12818.  
  12819.  SQLEBCPB
  12820.    bcp_bind() may NOT be used after bcp_init() has been passed a non-NULL
  12821.    input file name.
  12822.  
  12823.  
  12824.  
  12825.  SQLEBCPI
  12826.    bcp_init() must be called before any other bcp routines.
  12827.  
  12828.  
  12829.  
  12830.  SQLEBCPN
  12831.    bcp_bind(), bcp_collen() and bcp_colptr() may be used only after
  12832.    bcp_init() has been called with the copy direction set to DB_IN.
  12833.  
  12834.  
  12835.  
  12836.  SQLEBCSI
  12837.    Host-file columns may be skipped only when copying INto the Server.
  12838.  
  12839.  
  12840.  
  12841.  SQLEBCUO
  12842.    Bcp: Unable to open host data-file.
  12843.  
  12844.  
  12845.  
  12846.  SQLEBCVH
  12847.    bcp_exec() may be called only after bcp_init() has been passed a valid
  12848.    host file.
  12849.  
  12850.  
  12851.  
  12852.  SQLEBCWE
  12853.    I/O error while writing bcp data-file.
  12854.  
  12855.  
  12856.  
  12857.  SQLEBDIO
  12858.    Bad bulk-copy direction. Must be either IN or OUT.
  12859.  
  12860.  
  12861.  
  12862.  SQLEBEOF
  12863.    Unexpected EOF encountered in BCP data-file.
  12864.  
  12865.  
  12866.  
  12867.  SQLEBIVI
  12868.    bcp_columns() and bcp_colfmt() may be used only after bcp_init() has been
  12869.    passed a valid input file.
  12870.  
  12871.  
  12872.  
  12873.  SQLEBNCR
  12874.    Attempt to bind user variable to a non-existent compute row.
  12875.  
  12876.  
  12877.  
  12878.  SQLEBRFF
  12879.    I/O error while reading bcp format-file.
  12880.  
  12881.  
  12882.  
  12883.  SQLEBSKERR
  12884.    Cannot seek in data file.
  12885.  
  12886.  
  12887.  
  12888.  SQLEBTMT
  12889.    Attempt to send too much TEXT data via the bcp_moretext() call.
  12890.  
  12891.  
  12892.  
  12893.  SQLEBTOK
  12894.    Bad token from SQL Server: Datastream processing out of sync.
  12895.  
  12896.  
  12897.  
  12898.  SQLEBTYP
  12899.    Unknown bind type passed to DB-LIBRARY function.
  12900.  
  12901.  
  12902.  
  12903.  SQLEBUOE
  12904.    Bcp: Unable to open error-file.
  12905.  
  12906.  
  12907.  
  12908.  SQLEBWEF
  12909.    I/O error while writing bcp error-file.
  12910.  
  12911.  
  12912.  
  12913.  SQLECLOS
  12914.    Error in closing network connection.
  12915.  
  12916.  
  12917.  
  12918.  SQLECNOR
  12919.    Column number out of range.
  12920.  
  12921.  
  12922.  
  12923.  SQLECNULL
  12924.    NULL destination variable not allowed.
  12925.  
  12926.  
  12927.  
  12928.  SQLECOFL
  12929.    Data-conversion resulted in overflow.
  12930.  
  12931.  
  12932.  
  12933.  SQLECONN
  12934.    Unable to connect: SQL Server is unavailable or does not exist.
  12935.  
  12936.  
  12937.  
  12938.  SQLECSYN
  12939.    Attempt to convert data stopped by syntax error in source field.
  12940.  
  12941.  
  12942.  
  12943.  SQLEDBOP
  12944.    Invalid or out of range dbn option parameter.
  12945.  
  12946.  
  12947.  
  12948.  SQLEDBPS
  12949.    Maximum number of DBPROCESSes already allocated.
  12950.  
  12951.  
  12952.  
  12953.  SQLEDDNE
  12954.    DBPROCESS is dead or not enabled.
  12955.  
  12956.  
  12957.  
  12958.  SQLEDNTI
  12959.    Attempt to use dbtxtsput to put a new text-timestamp into a column whose
  12960.    datatype is neither SQLTEXT nor SQLIMAGE.
  12961.  
  12962.  
  12963.  
  12964.  SQLEICN
  12965.    Invalid computeid or compute column number.
  12966.  
  12967.  
  12968.  
  12969.  SQLEIFNB
  12970.    Illegal field number passed to bcp_control().
  12971.  
  12972.  
  12973.  
  12974.  SQLEIICL
  12975.    Illegal integer column length returned by SQL Server. Legal integer
  12976.    lengths are 1, 2, and 4 bytes.
  12977.  
  12978.  
  12979.  
  12980.  SQLEIOPT
  12981.    Attempt to use invalid DBOPTION.
  12982.  
  12983.  
  12984.  
  12985.  SQLEITIM
  12986.    Illegal timeout value specified.
  12987.  
  12988.  
  12989.  
  12990.  SQLEKBCI
  12991.    1000 rows sent to SQL Server.
  12992.  
  12993.  
  12994.  
  12995.  SQLEKBCO
  12996.    1000 rows successfully bulk-copied to host-file.
  12997.  
  12998.  
  12999.  
  13000.  SQLEMEM
  13001.    Unable to allocate sufficient memory.
  13002.  
  13003.  
  13004.  
  13005.  SQLEMODE
  13006.    Network connection not in correct mode - invalid SQL Server connection.
  13007.  
  13008.  
  13009.  
  13010.  SQLENLOG
  13011.    NULL loginrec pointer encountered.
  13012.  
  13013.  
  13014.  
  13015.  SQLENONET
  13016.    DB-LIBRARY network communications layer not loaded.
  13017.  
  13018.  
  13019.  
  13020.  SQLENPRM
  13021.    NULL parameter not allowed for this dboption.
  13022.  
  13023.  
  13024.  
  13025.  SQLENSIP
  13026.    Negative starting index passed to dbstrcpy.
  13027.  
  13028.  
  13029.  
  13030.  SQLENTLL
  13031.    Name too long for loginrec field.
  13032.  
  13033.  
  13034.  
  13035.  SQLENTXT
  13036.    Attempt to get text point / timestamp from a non-text column.
  13037.  
  13038.  
  13039.  
  13040.  SQLENULL
  13041.    NULL DBPROCESS pointer encountered.
  13042.  
  13043.  
  13044.  
  13045.  SQLENXID
  13046.    The Server did not grant us a distributed-transaction ID.
  13047.  
  13048.  
  13049.  
  13050.  SQLEOOB
  13051.    Error in sending out-of-band data to SQL Server.
  13052.  
  13053.  
  13054.  
  13055.  SQLEPARM
  13056.    Invalid parameter in DB-LIBRARY function reference.
  13057.  
  13058.  
  13059.  
  13060.  SQLEPNUL
  13061.    NULL program pointer encountered.
  13062.  
  13063.  
  13064.  
  13065.  SQLEPWD
  13066.    Login incorrect.
  13067.  
  13068.  
  13069.  
  13070.  SQLERDCN
  13071.    Requested data-conversion does not exist.
  13072.  
  13073.  
  13074.  
  13075.  SQLEREAD
  13076.    Read from SQL Server failed.
  13077.  
  13078.  
  13079.  
  13080.  SQLERPND
  13081.    Attempt to initiate a new SQL Server operation with results pending.
  13082.  
  13083.  
  13084.  
  13085.  SQLESEOF
  13086.    Unexpected EOF from SQL Server.
  13087.  
  13088.  
  13089.  
  13090.  SQLESMSG
  13091.    General SQL Server error: Check messages from the SQL Server.
  13092.  
  13093.  
  13094.  
  13095.  SQLETIME
  13096.    SQL Server connection timed out.
  13097.  
  13098.  
  13099.  
  13100.  SQLETMTD
  13101.    Attempt to send too much TEXT data via the dbmoretext call.
  13102.  
  13103.  
  13104.  
  13105.  SQLETSIT
  13106.    Attempt to call dbtsput with an invalid timestamp.
  13107.  
  13108.  
  13109.  
  13110.  SQLEUDTY
  13111.    Unknown datatype encountered.
  13112.  
  13113.  
  13114.  
  13115.  SQLEVDPT
  13116.    For bulk copy, all variable-length data must have either a length-prefix
  13117.    or a terminator specified.
  13118.  
  13119.  
  13120.  
  13121.  SQLEWRIT
  13122.    Write to SQL Server failed. This error number is unused.
  13123.  
  13124.  
  13125.  
  13126.  SQLNULLO
  13127.    Attempt to login with null loginrec.
  13128.  
  13129.  
  13130.  ────────────────────────────────────────────────────────────────────────────
  13131.  
  13132.  
  13133.  Error Severity Levels
  13134.  
  13135.  The following error severity levels are defined in the sqlfront.h header
  13136.  file. Your program must include sqlfront.h if it refers to these severity
  13137.  levels.
  13138.  
  13139.  ────────────────────────────────────────────────────────────────────────────
  13140.  EXINFO
  13141.    Informational, non-error.
  13142.  
  13143.  
  13144.  
  13145.  EXUSER
  13146.    User error.
  13147.  
  13148.  
  13149.  
  13150.  EXNONFATAL
  13151.    Non-fatal error.
  13152.  
  13153.  
  13154.  
  13155.  EXCONVERSION
  13156.    Error in DB-LIBRARY data conversion.
  13157.  
  13158.  
  13159.  
  13160.  EXSERVER
  13161.    Server returned an error flag.
  13162.  
  13163.  
  13164.  
  13165.  EXTIME
  13166.    Exceeded timeout period while waiting for a response from the Server - the
  13167.    DBPROCESS is still alive.
  13168.  
  13169.  
  13170.  
  13171.  EXPROGRAM
  13172.    Coding error in user program.
  13173.  
  13174.  
  13175.  
  13176.  EXRESOURCE
  13177.    Running out of resources - the DBPROCESS may be dead.
  13178.  
  13179.  
  13180.  
  13181.  EXCOMM
  13182.    Failure in communication with Server - the DBPROCESS is dead.
  13183.  
  13184.  
  13185.  
  13186.  EXFATAL
  13187.    Fatal error - the DBPROCESS is dead.
  13188.  
  13189.  
  13190.  
  13191.  EXCONSISTENCY
  13192.    Internal software error - notify customer support.
  13193.  
  13194.  
  13195.  
  13196.  ────────────────────────────────────────────────────────────────────────────
  13197.  
  13198.  
  13199.  
  13200.  
  13201.  
  13202.  
  13203.  Appendix E  Building Applications
  13204.  ────────────────────────────────────────────────────────────────────────────
  13205.  
  13206.  
  13207.  Building MS-DOS Applications
  13208.  
  13209.  This section describes how to build DB-LIBRARY applications to run in the
  13210.  MS-DOS environment.
  13211.  
  13212.  
  13213.  Terminate and Stay Resident Utility
  13214.  
  13215.  The DB-LIBRARY modules use a terminate and stay resident utility (TSR) for
  13216.  all network communications; the TSR is called dbnmpipe.exe. Normally, you
  13217.  will execute the TSR from your autoexec.bat file whenever you boot your
  13218.  system. If this is the case, make sure that you load the network before
  13219.  running the TSR.
  13220.  
  13221.  You can also load and execute the TSR just before you run your SQL Server
  13222.  application. In that case, simply type the name of the TSR on the command
  13223.  line, exactly as you would any other program:
  13224.  
  13225.    dbnmpipe
  13226.  
  13227.  If the directory in which the TSR resides is not named in your PATH
  13228.  variable, you must type in the exact path to the TSR.
  13229.  
  13230.  Whether you load the TSR through autoexec.bat or from the command line, you
  13231.  can unload it and recover the memory that it uses with the enddblib.exe
  13232.  program. The following example illustrates this:
  13233.  
  13234.    enddblib
  13235.  
  13236.  This program checks to make sure that the TSR is loaded and then unloads it.
  13237.  If dbnmpipe was not the last TSR loaded, it is dangerous to unload it. In
  13238.  this case, enddblib will prompt you if you want to remove it anyway. Do it
  13239.  at your own risk. You can supress prompting and force enddblib to unload the
  13240.  TSR by using the /q (quiet) command line switch as follows:
  13241.  
  13242.    enddblib /q
  13243.  
  13244.  Again, it is dangerous to unload a TSR if it was not the last one loaded.
  13245.  
  13246.  
  13247.  Libraries
  13248.  
  13249.  Two memory models are supported: the "medium" and "large" models. The
  13250.  following table shows the libraries for each model.
  13251.  
  13252. ╓┌─────────────────────────────────┌─────────────────────────────────────────╖
  13253.  Memory Model                      Library File
  13254.  ────────────────────────────────────────────────────────────────────────────
  13255.  Large                             rldblib.lib
  13256.  
  13257.  Medium                            rmdblib.lib
  13258.  
  13259.  ────────────────────────────────────────────────────────────────────────────
  13260.  
  13261.  
  13262.  
  13263.  At program link time, the LIB environment variable must be set to point to
  13264.  the directory in which the library files reside.
  13265.  
  13266.  
  13267.  Include Files
  13268.  
  13269.  The following DB-LIBRARY include files are provided:
  13270.  
  13271. ╓┌─────────────────────────────────┌─────────────────────────────────────────
  13272.  Include File                      Contents
  13273.  ────────────────────────────────────────────────────────────────────────────
  13274.  Include File                      Contents
  13275.  ────────────────────────────────────────────────────────────────────────────
  13276.  sqlfront.h                        Error codes and severity levels;
  13277.                                    miscellaneous definitions and typedefs
  13278.  
  13279.  sqldb.h                           Function prototypes for all DB-LIBRARY
  13280.                                    functions
  13281.  
  13282.  ────────────────────────────────────────────────────────────────────────────
  13283.  
  13284.  
  13285.  
  13286.  At compile time, you can set the INCLUDE environment variable to point to
  13287.  the directory in which the include files reside. Alternatively, you can use
  13288.  the /I compile line switch to point to the include file directory.
  13289.  
  13290.  Since your application must always include the sqldb.h file, you need not
  13291.  define the DB-LIBRARY functions you use. These functions and their proper
  13292.  declarations are already defined in the include file.
  13293.  
  13294.  You must define the application program's target operating system before
  13295.  your program includes the DB-LIBRARY header files. Use the following
  13296.  statements at the beginning of all SQL Server applications that will run
  13297.  under MS-DOS:
  13298.  
  13299.    #define  DBMSDOS
  13300.     #include <sqlfront.h>
  13301.     #include <sqldb.h>
  13302.  
  13303.  
  13304.  Required System Libraries
  13305.  
  13306.  DB-LIBRARY does not require any special system libraries, except for the
  13307.  standard C run-time libraries; the TSR handles all network communication for
  13308.  the application. If your program needs any special libraries, including any
  13309.  that provide direct access to the LAN Manager, you must load them yourself
  13310.  in the normal manner.
  13311.  
  13312.  
  13313.  Compiling and Linking Considerations
  13314.  
  13315.  The following command illustrates a typical compilation with automatic
  13316.  linkage:
  13317.  
  13318.    cl /Lr /AL foo.c rldblib.lib
  13319.  
  13320.  The name foo.c is the name of your application. The large model (/AL) and
  13321.  real mode (/Lr) were used. Notice that the large model library, rldblib.lib,
  13322.  is specified.
  13323.  
  13324.  
  13325.  Increasing the Number of SQL Server Connections
  13326.  
  13327.  The C 5.10 run-time functions have a limitation of 20 open file handles at
  13328.  any one time. Because of this, a workstation can establish a maximum of 15
  13329.  SQL Server connections at any one time. A new module is provided that allows
  13330.  applications running on a workstation to have up to 45 connections to an SQL
  13331.  Server. The module is crt0dat.obj and is designed to be used in the MS-DOS
  13332.  environment (versions 3.3 or later). If your application needs to establish
  13333.  more than 15 connections to SQL Servers, perform the following steps:
  13334.  
  13335.  
  13336.    1.  Explicitly link the crt0dat.obj module with your application:
  13337.  
  13338.        cl /Lr /AL foo.c crt0dat.obj RLDBLIB.LIB /link /NOE
  13339.  
  13340.  
  13341.    2.  This example assumes that the crt0dat.obj object module resides within
  13342.        the current directory. Note the additional option "/link /NOE"
  13343.        appended to the end of the compilation command line. This option is
  13344.        passed to the linker, instructing it not to search its extended
  13345.        dictionary. It is required because of the redefinition of symbols
  13346.        contained within the crt0dat.obj module.
  13347.  
  13348.    3.  Change or add the "FILES=" statement in the config.sys file to
  13349.        "FILES=50" and reboot the system.
  13350.  
  13351.  
  13352.  Most applications need only one connection to SQL Server. Applications using
  13353.  BROWSE mode require two connections. If you need more than two connections,
  13354.  reexamine your design to see if it can be improved.
  13355.  
  13356.  If the limit of 50 isn't satisfactory, refer to the readme.doc file supplied
  13357.  with the C 5.10 package. It explains how to create your own crt0dat.obj file
  13358.  with whatever limit you need.
  13359.  
  13360.  
  13361.  Sample Program
  13362.  
  13363.  The sqltestr.c sample program is included. This program establishes a
  13364.  connection with an SQL Server and then performs a simple query. It assumes
  13365.  that an SQL Server is attached to the network and has the pubs database
  13366.  installed. For example, if your SQL Server is named sql_svr, enter the name
  13367.  sql_svr in response to the "Enter LAN Manager Network Computer name of SQL
  13368.  SERVER:" prompt. Next, enter "Dull" to the "Enter author's last name to
  13369.  retrieve:" prompt. You will see information displayed that is associated
  13370.  with the name entered.
  13371.  
  13372.  A make file that builds the sample program is included. Be sure that your
  13373.  LIB and INCLUDE environment variables are set properly, and then enter the
  13374.  following command:
  13375.  
  13376.    make sqltestr
  13377.  
  13378.  
  13379.  Building MS OS/2 Applications
  13380.  
  13381.  This section describes how to build DB-LIBRARY applications to run in the MS
  13382.  OS/2 environment.
  13383.  
  13384.  
  13385.  Libraries
  13386.  
  13387.  The DB-LIBRARY functions are stored in a dynamic link library, pdblib.dll;
  13388.  the named pipe functions are stored in dbnmpp.dll. The LIBPATH command found
  13389.  in your config.sys file has to be modified to point to the directory in
  13390.  which pdblib.dll and dbnmpp.dll reside. Another file called pdblib.lib
  13391.  contains the "import" definitions that will be used by your application. The
  13392.  LIB environment variable also must be set to point to the directory in which
  13393.  pdblib.lib resides.
  13394.  
  13395.  
  13396.  Include Files
  13397.  
  13398.  The following DB-LIBRARY include files are provided:
  13399.  
  13400. ╓┌─────────────────────────────────┌─────────────────────────────────────────
  13401.  Include File                      Contents
  13402.  ────────────────────────────────────────────────────────────────────────────
  13403.  sqlfront.h                        Error codes and severity levels;
  13404.                                    miscellaneous definitions and typedefs
  13405.  
  13406.  sqldb.h                           Function prototypes for all DB-LIBRARY
  13407.                                    functions
  13408.  
  13409.  ────────────────────────────────────────────────────────────────────────────
  13410.  
  13411.  
  13412.  
  13413.  You can set the INCLUDE environment variable to point to the directory in
  13414.  which the include files reside. Alternatively, you can use the /I compile
  13415.  line switch to point to the include file directory.
  13416.  
  13417.  Since your application must always include the sqldb.h file, you need not
  13418.  define the DB-LIBRARY functions you use. These functions and their proper
  13419.  declarations are already defined in the include file.
  13420.  
  13421.  You must define the application program's target operating system before
  13422.  your program includes the DB-LIBRARY header files. Use the following
  13423.  statements at the beginning of all SQL Server applications that will run
  13424.  under MS OS/2:
  13425.  
  13426.    #define  DBMSOS2
  13427.     #include <sqlfront.h>
  13428.     #include <sqldb.h>
  13429.  
  13430.  
  13431.  Special Considerations
  13432.  
  13433.  If your application is sending or receiving pointer information to and from
  13434.  DB-LIBRARY, the pointers must be defined as "far pointers." Normally the
  13435.  only time that this is a concern is when you are compiling your application
  13436.  with the small (/AS) or medium (/AM) compiler options set. For example, the
  13437.  following code declarations:
  13438.  
  13439.    .
  13440.     .
  13441.     .
  13442.     main()
  13443.     {
  13444.      DBPROCESS *dbproc;
  13445.      LOGINREC *login;
  13446.      .
  13447.      .
  13448.      .
  13449.  
  13450.  must be changed to:
  13451.  
  13452.    .
  13453.     .
  13454.     .
  13455.     main()
  13456.     {
  13457.      DBPROCESS far *dbproc;
  13458.      LOGINREC far *login;
  13459.      .
  13460.      .
  13461.      .
  13462.  
  13463.  
  13464.  Compiling and Linking Considerations
  13465.  
  13466.  The following command illustrates a typical compilation with automatic
  13467.  linkage:
  13468.  
  13469.    cl /Lp /AL /Au /Gs foo.c pdblib.lib
  13470.  
  13471.  The name foo.c is the name of the application. The large model (/AL) and
  13472.  protected mode (/Lp) options were used. The pdblib.lib file contains all of
  13473.  the DB-LIBRARY import definitions.
  13474.  
  13475.  Note that the /Au and /Gs options are specified. These options are required
  13476.  to force the DS register to be loaded with the proper data segment and to
  13477.  disable stack checking when a user-supplied function is invoked by
  13478.  DB-LIBRARY. For example, if a user function is supplied through the
  13479.  dbmsghandle function, then the message-handling function will require the
  13480.  /Au and /Gs options during compilation.
  13481.  
  13482.  
  13483.  Sample Programs
  13484.  
  13485.  The sqltestp.c sample program is included. This program simply establishes a
  13486.  connection with an SQL Server and then allows a simple query to be
  13487.  performed. It is assumed that an SQL Server is attached to the network and
  13488.  has the pubs database installed. For example, if your SQL Server is named
  13489.  sql_svr, enter the name sql_svr in response to the "Enter LAN Manager
  13490.  Network Computer name of SQL SERVER:" prompt. Next, enter "Dull" to the
  13491.  "Enter author's last name to retrieve:" prompt. You will see information
  13492.  displayed that is associated with the name entered.
  13493.  
  13494.  A make file that builds the sample program is included. Make sure that your
  13495.  LIB and INCLUDE environment variables are properly set, and then enter the
  13496.  following command:
  13497.  
  13498.    make sqltestp
  13499.  
  13500.  A Presentation Manager sample program is also included in the file sqlpm.c
  13501.  
  13502.  A make file that builds the sample program is included. Make sure that your
  13503.  LIB and INCLUDE environment variables are properly set, and then enter the
  13504.  following command:
  13505.  
  13506.    make sqlpm
  13507.  
  13508.  
  13509.  Building an Application for Windows
  13510.  
  13511.  This section describes how to build DB-LIBRARY applications to run in the
  13512.  Windows environment.
  13513.  
  13514.  
  13515.  Libraries
  13516.  
  13517.  The DB-LIBRARY functions for Windows are stored in two dynamic link
  13518.  libraries, wdblib.exe for Windows 2.1 and w3dblib.exe for Windows 3.0. In
  13519.  addition, the named pipe interface is stored in dbnmp3.dll for Windows 3.0.
  13520.  The PATH environment variable should be set to point to the directory in
  13521.  which the libraries reside. Two other files, called wdblib.lib for Windows
  13522.  2.1 and w3dblib.lib for Windows 3.0, contain the "import" definitions that
  13523.  will be used by your application. The LIB environment variable must be set
  13524.  to point to the directory in which wdblib.lib and w3dblib.lib reside.
  13525.  
  13526.  
  13527.  Include Files
  13528.  
  13529.  The following DB-LIBRARY include files are provided:
  13530.  
  13531. ╓┌─────────────────────────────────┌─────────────────────────────────────────
  13532.  Include File                      Contents
  13533.  ────────────────────────────────────────────────────────────────────────────
  13534.  sqlfront.h                        Error codes and severity levels;
  13535.                                    miscellaneous definitions and typedefs
  13536.  
  13537.  sqldb.h                           Function prototypes for all DB-LIBRARY
  13538.                                    functions
  13539.  
  13540.  ────────────────────────────────────────────────────────────────────────────
  13541.  
  13542.  
  13543.  
  13544.  You can set the INCLUDE environment variable to point to the directory in
  13545.  which the include files reside. Alternatively, you can use the /I compile
  13546.  line switch to point to the include file directory.
  13547.  
  13548.  Since your application must always include the sqldb.h file, you need not
  13549.  define the DB-LIBRARY functions you use. These functions and their proper
  13550.  declarations are already defined in the include file.
  13551.  
  13552.  You must define the application program's target operating system before
  13553.  your program includes the DB-LIBRARY header files. Use the following
  13554.  statements at the beginning of all SQL Server applications that will run
  13555.  under Windows:
  13556.  
  13557.    #define  DBMSWIN
  13558.     #include <sqlfront.h>
  13559.     #include <sqldb.h>
  13560.  
  13561.  
  13562.  Special Windows DB-LIBRARY Functions
  13563.  
  13564.  The DB-LIBRARY macros DBLOCKLIB and DBUNLOCKLIB have been added to the
  13565.  Windows version of DB-LIBRARY. These two macros are necessary because
  13566.  segments in Windows libraries move around. If an application (or DB-LIBRARY
  13567.  function) is relying on a far pointer for later use, the segments must not
  13568.  move.
  13569.  
  13570.  Your Windows-based application must call dbinit before calling any other
  13571.  DB-LIBRARY function. In addition, the dbwinexit function has also been added
  13572.  to the Windows version of DB-LIBRARY. Your application must call this
  13573.  function immediately before exiting, to de-register as a Windows
  13574.  application.
  13575.  
  13576.  
  13577.  Special Considerations for Windows DB-LIBRARY Applications
  13578.  
  13579.  Error handling and message handling for DB-LIBRARY under Windows is
  13580.  installed differently than for MS-DOS or MS OS/2. Because the error and
  13581.  message handlers are callback functions and Windows dynamic link libraries
  13582.  may be moving around in memory between calls to the dynamic link library,
  13583.  the error handler and message handler must be installed exported callback
  13584.  functions. When Windows executes a callback function, the data segment
  13585.  register is not set to the application's data segment, even though the error
  13586.  handler is part of the application. Making the error handler and message
  13587.  handler functions into procedure instances and exporting them in the .def
  13588.  file causes Windows to set up the DS register correctly so that your
  13589.  handlers can correctly access the application's data.
  13590.  
  13591.  To create an error handler or message handler, you first must make the
  13592.  function into a procedure instance. To do so, you must call
  13593.  MakeProcInstance, in your initialization code or in the application message
  13594.  loop. The following example illustrates the call in the application's
  13595.  message loop:
  13596.  
  13597.    long FAR PASCAL MySqlWndProc(hWnd, message, wParam, lParam)
  13598.     HWND hWnd;    /* window handle   */
  13599.     unsigned message;  /* type of message   */
  13600.     WORD wParam;   /* additional information */
  13601.     LONG lParam;   /* additional information */
  13602.     {
  13603.       .
  13604.       .
  13605.       .
  13606.  
  13607.      static FARPROC lpMyMessageHandler; /* pointer to message handler */
  13608.      static FARPROC lpMyErrorHandler; /* pointer to error handler */
  13609.      int cdecl FAR MyMessageHandler(DBPROCESS *,DBINT, DBSMALLINT,
  13610.       DBSMALLINT, LPSTR);
  13611.      int cdecl FAR MyErrorHandler(DBPROCESS *, int, int, int, LPSTR, LPSTR);
  13612.  
  13613.      switch (message) {
  13614.       .
  13615.       .
  13616.       .
  13617.  
  13618.      case WM_CREATE: /* message: window being created */
  13619.          /* Make the message and error handler instances. */
  13620.       lpMyMessageHandler =
  13621.       MakeProcInstance((FARPROC)MyMessageHandler, hInst);
  13622.       lpMyErrorHandler =
  13623.       MakeProcInstance((FARPROC)MyErrorHandler, hInst);
  13624.  
  13625.       /* Install the instances into dblib. */
  13626.       dbmsghandle(lpMyMessageHandler);
  13627.       dberrhandle(lpMyErrorHandler);
  13628.       .
  13629.       .
  13630.       .
  13631.  
  13632.  Making the FARPROC variables static allows you to free them during
  13633.  WM_DESTROY message processing:
  13634.  
  13635.    .
  13636.      .
  13637.      .
  13638.     case WM_DESTROY: /* message: window being destroyed */
  13639.      FreeProcInstance(lpMyMessageHandler); /* release handlers */
  13640.      FreeProcInstance(lpMyErrorHandler);
  13641.      PostQuitMessage(0);
  13642.      dbwinexit();   break;
  13643.      .
  13644.      .
  13645.      .
  13646.  
  13647.  Note that callback functions in Windows are normally declared FAR PASCAL,
  13648.  but not with these two callback functions for DB-LIBRARY. DB-LIBRARY expects
  13649.  all function calls to be cdecl FAR: consequently, your handlers must also be
  13650.  cdecl FAR, as shown in the following example:
  13651.  
  13652.    int FAR cdecl MyErrorHandler(dbproc, severity, errno,
  13653.      oserr, dberrstr, oserrstr);
  13654.  
  13655.  Because this function declaration type is contrary to the FARPROC
  13656.  declaration type in MakeProcInstance, you must cast the function name, when
  13657.  passed as a parameter to MakeProcInstance, as FARPROC; otherwise the
  13658.  compiler generates an error message.
  13659.  
  13660.  Also, you must pass the FARPROC pointers returned from MakeProcInstance to
  13661.  dberrhandle and dbmsghandle to properly install the handlers. Passing the
  13662.  addresses of the handler functions instead of the procedure instances will
  13663.  cause unpredictable results.
  13664.  
  13665.  Finally, you must export the functions so that Windows will correctly fix up
  13666.  the segment references. In your .def file, add the following lines to the
  13667.  EXPORTS section:
  13668.  
  13669.    _MyMessageHandler @x ; message handler
  13670.     _MyErrorHandler @y ; error handler
  13671.  
  13672.  Note that the function names begin with an underscore, this is because with
  13673.  the cdecl, the compiler automatically adds the underscore to the function
  13674.  name. The "@x" and "@y" are replaced with "@numbers" for the number of your
  13675.  exported functions. See the sample Windows application for examples of
  13676.  installing error and message handlers.
  13677.  
  13678.  
  13679.  Increasing the Number of Allowable Open Files
  13680.  
  13681.  The C 5.10 run-time functions have a limitation of 20 open file handles at
  13682.  any one time. Five files are already opened by the system and are
  13683.  unavailable. Therefore, a maximum of 15 SQL Server connections can be
  13684.  established from a workstation at any one time. A startup module is provided
  13685.  that allows applications running on a workstation to have up to 45
  13686.  user-opened files and connections to an SQL Server (providing there is
  13687.  enough memory available within the dynamic link library's data segment).
  13688.  
  13689.  The crt0dat.obj module is designed for the MS-DOS environment (versions 3.3
  13690.  or later) running Windows versions 2.1 or later. If your application needs
  13691.  to open more than 15 files or connections to SQL Servers, perform the
  13692.  following steps:
  13693.  
  13694.  
  13695.    1.  Explicitly link the crt0dat.obj module with your application using the
  13696.        /NOE switch with the linker invocation command.
  13697.  
  13698.    2.  Change or add the "FILES=" statement in the config.sys file to
  13699.        "FILES=50" and reboot the system.
  13700.  
  13701.  
  13702.  If the limit of 50 isn't satisfactory, refer to the readme.doc file supplied
  13703.  with the C 5.10 package. It explains how to create your own crt0dat.obj file
  13704.  with whatever limit you need. The application determines the allowable
  13705.  number of open handles; however, this number also depends on the memory
  13706.  available within the dynamic link library's data segment. By using the
  13707.  supplied crt0dat.obj module, you can increase the number of files or
  13708.  connections that your application can open.
  13709.  
  13710.  
  13711.  Sample Program
  13712.  
  13713.  The sqltestw.c sample program is included. This program simply establishes a
  13714.  connection with an SQL Server and then performs a simple query. It is
  13715.  assumed that an SQL Server is attached to the network and has the pubs
  13716.  database installed.
  13717.  
  13718.  A make file that builds the sample program is included. Make sure that your
  13719.  LIB and INCLUDE environment variables are properly set, and then enter the
  13720.  following command:
  13721.  
  13722.    make sqltestw
  13723.  
  13724.  
  13725.  
  13726.  
  13727.  
  13728.  
  13729.  Appendix F  Finding SQL Servers on the Network
  13730.  ────────────────────────────────────────────────────────────────────────────
  13731.  
  13732.  This appendix describes how to locate an SQL Server on the network from an
  13733.  application program.
  13734.  
  13735.  Information on all SQL Servers is contained in the workstation's LAN Manager
  13736.  table, which is updated whenever an SQL Server is added or deleted from the
  13737.  network. To gain access to the information in this table, call
  13738.  NetServerEnum, a LAN Manager Applications Program Interface (API) function.
  13739.  (See the Microsoft LAN Manager Programmer's Reference for information on
  13740.  this function.) NetServerEnum should be called with a level 1 or level 2
  13741.  request. If the call is successful, it returns a value of 0. Then the
  13742.  program checks the sv_type variable to determine if the SV_TYPE_SQLSERVER
  13743.  bit is set. If the bit is set, the server is an SQL Server.
  13744.  
  13745.  The following example prints out all SQL Servers found on the network:
  13746.  
  13747.    #include <stdio.h> /* usually located in ..\c\include */
  13748.     #include <netcons.h> /* usually located in ..\lanman\netsrc\h */
  13749.     #include <server.h> /* usually located in ..\lanman\netsrc\h */
  13750.  
  13751.     /*
  13752.      Define server_info_1 buffer area. It is defined
  13753.      here to avoid requiring an excess amount of stack area.
  13754.     */
  13755.     struct server_info_1 svr[100];
  13756.  
  13757.     main ()
  13758.     {
  13759.      int i; /* use as loop counter */
  13760.      int ret; /* return variable for NetServerEnum */
  13761.      unsigned short entriesread; /* entries read by NetServerEnum */
  13762.      unsigned short totalentries; /* total number of entries available */
  13763.  
  13764.      /*
  13765.      Now make an API call to NetServerEnum. The following LAN Manager
  13766.      libraries are required.
  13767.  
  13768.      - NETAPI.LIB (usually found in ..\lanman\netsrc\lib)
  13769.      - NETOEM.LIB (usually found in ..\lanman\netsrc\lib)
  13770.  
  13771.      The "svr" buffer must be large enough
  13772.      to hold all entries. In this example, it is set to
  13773.      hold 100 entries. Note that a "level 1"
  13774.      call (the second parameter) is made to retrieve the
  13775.      information needed.
  13776.      */
  13777.      ret = NetServerEnum (NULL, 1, (char *)svr, sizeof (svr),
  13778.      &entriesread, &totalentries);
  13779.      if (!ret) /* if successful call to NetServerEnum */
  13780.      {
  13781.      printf ("\nThe folowing SQL Servers were found on ");
  13782.      printf ("the network:\n");
  13783.      printf (" Server Name Server Comment\n");
  13784.      printf (" ------------------------------------\n");
  13785.  
  13786.      for (i=0; i < entriesread; i++)
  13787.      /*
  13788.      Look for all entries with the SV_TYPE_SQLSERVER
  13789.      bit set
  13790.      */
  13791.      if (svr[i].sv1_type & SV_TYPE_SQLSERVER)
  13792.       printf (" %-20s %s\n", svr[i].sv1_name,svr[i].sv1_comment);
  13793.      }
  13794.      else
  13795.      {
  13796.       printf ("Error in call to NetSeverEnum, ");
  13797.       printf ("error value = %d\n", ret);
  13798.      }
  13799.     }
  13800.  
  13801.  
  13802.  
  13803.  
  13804.  
  13805.  
  13806.  Appendix G  Relative Sizes of Library Routines
  13807.  ────────────────────────────────────────────────────────────────────────────
  13808.  
  13809.  This appendix documents the relative sizes of the DB-LIBRARY routines.
  13810.  
  13811.  Size estimates for DB-LIBRARY are for the static link MS-DOS libraries only.
  13812.  The dynamic link libraries for MS OS/2 and Windows require no program
  13813.  memory; however, they do consume system memory. Under MS OS/2 this is not
  13814.  usually a problem; under Windows, memory constraints can result in a segment
  13815.  load failure if multiple data locks are present and memory is highly
  13816.  fragmented when you attempt to load a code segment. The dynamic nature of
  13817.  memory swapping precludes accurate estimates of memory requirements for a
  13818.  given DB-LIBRARY function under Windows, but the static link library memory
  13819.  cost estimates may be used as a rough guideline.
  13820.  
  13821.  
  13822.  Static Link Library Memory Costs
  13823.  
  13824.  A number of functions in DB-LIBRARY are considered to be "core" functions.
  13825.  These functions are used by almost every application that communicates with
  13826.  the SQL Server. Core functions are grouped together in the object modules of
  13827.  DB-LIBRARY. In addition, a number of support routines are loaded with an
  13828.  application during linking with these core routines. However, once an
  13829.  application references a single core routine, it incurs little or no
  13830.  additional cost when it references other core routines.
  13831.  
  13832.  Many of the non-core routines may reference core routines. In this case, the
  13833.  core routines will be loaded during link time, making these non-core
  13834.  routines costly. Since the core routines are almost always loaded, the
  13835.  estimates for non-core routines assume that the core routines have already
  13836.  been loaded.
  13837.  
  13838.  
  13839.  DB-LIBRARY Core Routines
  13840.  
  13841.  The following DB-LIBRARY functions comprise the core routines
  13842.  
  13843.  
  13844.    ■   dbclose
  13845.  
  13846.    ■   dbcmd
  13847.  
  13848.    ■   dbdataready
  13849.  
  13850.    ■   dberrhandle
  13851.  
  13852.    ■   dbexit
  13853.  
  13854.    ■   dbfreelogin
  13855.  
  13856.    ■   dbinit
  13857.  
  13858.    ■   dblogin
  13859.  
  13860.    ■   dbmsghandle
  13861.  
  13862.    ■   dbnextrow
  13863.  
  13864.    ■   dbopen
  13865.  
  13866.    ■   dbresults
  13867.  
  13868.    ■   dbsetlogintime
  13869.  
  13870.    ■   dbsettime
  13871.  
  13872.    ■   dbsqlexec
  13873.  
  13874.    ■   dbsqlok
  13875.  
  13876.    ■   dbsqlsend
  13877.  
  13878.  
  13879.  
  13880.  Relative Memory Sizes
  13881.  
  13882.  Core functions contribute about 1/2 to 3/5 of the library code and data
  13883.  size. (Note that this is not the physical size of the libraries; typically,
  13884.  a library's physical size is up to 30% larger than its memory resident code
  13885.  and data size.)
  13886.  
  13887.  In the tables that follow, relative memory sizes are rated on a scale of 1
  13888.  to 10, with 1 being the smallest module and 10 being the largest. These
  13889.  estimates include the necessary C run-time support routines.
  13890.  
  13891.  
  13892.  Setting Up the LOGINREC
  13893.  
  13894.  Function                          Relative Size
  13895.  ────────────────────────────────────────────────────────────────────────────
  13896.  dbfreelogin                       Core
  13897.  
  13898.  dblogin                           Core
  13899.  
  13900.  DBSETLAPP                         4
  13901.  
  13902.  DBSETLHOST                        4
  13903.  
  13904.  DBSETLPWD                         4
  13905.  
  13906.  DBSETLUSER                        4
  13907.  
  13908.  
  13909.  Establishing an SQL Server Connection
  13910.  
  13911.  Function                          Relative Size
  13912.  ────────────────────────────────────────────────────────────────────────────
  13913.  dbopen                            Core
  13914.  
  13915.  dbsetllogintime                   Core
  13916.  
  13917.  
  13918.  Setting the Current Database
  13919.  
  13920.  Function                          Relative Size
  13921.  ────────────────────────────────────────────────────────────────────────────
  13922.  dbuse                             2
  13923.  
  13924.  
  13925.  Building a Command Batch
  13926.  
  13927.  Function                          Relative Size
  13928.  ────────────────────────────────────────────────────────────────────────────
  13929.  dbcmd                             Core
  13930.  
  13931.  dbfcmd                            10
  13932.  
  13933.  dbfreebuf                         4
  13934.  
  13935.  
  13936.  Accessing a Command Batch
  13937.  
  13938.  Function                          Relative Size
  13939.  ────────────────────────────────────────────────────────────────────────────
  13940.  dbgetchar                         3
  13941.  
  13942.  dbstrcpy                          3
  13943.  
  13944.  dbstrlen                          3
  13945.  
  13946.  
  13947.  Executing a Command Batch
  13948.  
  13949.  Function                          Relative Size
  13950.  ────────────────────────────────────────────────────────────────────────────
  13951.  DBRBUF                            Core
  13952.  
  13953.  dbsqlexec                         Core
  13954.  
  13955.  dbsqlok                           Core
  13956.  
  13957.  dbsqlsend                         Core
  13958.  
  13959.  
  13960.  Setting and Clearing Command Options
  13961.  
  13962.  Function                          Relative Size
  13963.  ────────────────────────────────────────────────────────────────────────────
  13964.  dbclropt                          4
  13965.  
  13966.  dbisopt                           4
  13967.  
  13968.  dbsetopt                          4
  13969.  
  13970.  
  13971.  Setting Up the Results
  13972.  
  13973.  Function                          Relative Size
  13974.  ────────────────────────────────────────────────────────────────────────────
  13975.  dbresults                         Core
  13976.  
  13977.  
  13978.  Getting Result Data
  13979.  
  13980.  Function                          Relative Size
  13981.  ────────────────────────────────────────────────────────────────────────────
  13982.  dbadata                           4
  13983.  
  13984.  dbaltbind                         10
  13985.  
  13986.  dbbind                            10
  13987.  
  13988.  dbdata                            4
  13989.  
  13990.  
  13991.  Accessing Result Rows
  13992.  
  13993.  Function                          Relative Size
  13994.  ────────────────────────────────────────────────────────────────────────────
  13995.  dbclrbuf                          1
  13996.  
  13997.  dbgetrow                          1
  13998.  
  13999.  dbnextrow                         Core
  14000.  
  14001.  dbprhead                          6
  14002.  
  14003.  dbprrow                           6
  14004.  
  14005.  
  14006.  Canceling Results
  14007.  
  14008.  Function                          Relative Size
  14009.  ────────────────────────────────────────────────────────────────────────────
  14010.  dbcancel                          3
  14011.  
  14012.  dbcanquery                        3
  14013.  
  14014.  
  14015.  Setting Response Time for Results
  14016.  
  14017.  Function                          Relative Size
  14018.  ────────────────────────────────────────────────────────────────────────────
  14019.  DBGETTIME                         3
  14020.  
  14021.  dbsettime                         Core
  14022.  
  14023.  
  14024.  Error and Message Handling
  14025.  
  14026.  Function                          Relative Size
  14027.  ────────────────────────────────────────────────────────────────────────────
  14028.  DBDEAD                            3
  14029.  
  14030.  dberrhandle                       Core
  14031.  
  14032.  dbmsghandle                       Core
  14033.  
  14034.  
  14035.  Regular Result Column Information
  14036.  
  14037.  Function                          Relative Size
  14038.  ────────────────────────────────────────────────────────────────────────────
  14039.  dbcollen                          4
  14040.  
  14041.  dbcolname                         4
  14042.  
  14043.  dbcoltype                         4
  14044.  
  14045.  dbdatlen                          4
  14046.  
  14047.  dbnumcols                         4
  14048.  
  14049.  
  14050.  Compute Result Column Information
  14051.  
  14052.  Function                          Relative Size
  14053.  ────────────────────────────────────────────────────────────────────────────
  14054.  dbadlen                           5
  14055.  
  14056.  dbaltcolid                        5
  14057.  
  14058.  dbaltlen                          5
  14059.  
  14060.  dbaltop                           5
  14061.  
  14062.  dbalttype                         5
  14063.  
  14064.  dbbylist                          5
  14065.  
  14066.  dbnumalts                         5
  14067.  
  14068.  dbnumcompute                      5
  14069.  
  14070.  
  14071.  Row Buffer Information
  14072.  
  14073.  Function                          Relative Size
  14074.  ────────────────────────────────────────────────────────────────────────────
  14075.  DBFIRSTROW                        3
  14076.  
  14077.  DBLASTROW                         3
  14078.  
  14079.  
  14080.  Command State Information
  14081.  
  14082.  Function                          Relative Size
  14083.  ────────────────────────────────────────────────────────────────────────────
  14084.  DBCMDROW                          3
  14085.  
  14086.  DBCOUNT                           3
  14087.  
  14088.  DBCURCMD                          3
  14089.  
  14090.  dbgetoff                          1
  14091.  
  14092.  DBMORECMDS                        3
  14093.  
  14094.  DBNUMORDERS                       3
  14095.  
  14096.  dbordercol                        4
  14097.  
  14098.  DBROWS                            3
  14099.  
  14100.  
  14101.  Miscellaneous Information
  14102.  
  14103.  Function                          Relative Size
  14104.  ────────────────────────────────────────────────────────────────────────────
  14105.  dbchange                          3
  14106.  
  14107.  DBCURROW                          3
  14108.  
  14109.  dbgetmaxprocs                     3
  14110.  
  14111.  DBISAVAIL                         3
  14112.  
  14113.  dbname                            3
  14114.  
  14115.  DBROWTYPE                         3
  14116.  
  14117.  
  14118.  Browse Mode
  14119.  
  14120.  Function                          Relative Size
  14121.  ────────────────────────────────────────────────────────────────────────────
  14122.  dbcolbrowse                       8
  14123.  
  14124.  dbcolsource                       8
  14125.  
  14126.  dbqual                            8
  14127.  
  14128.  dbtabbrowse                       8
  14129.  
  14130.  dbtabcount                        8
  14131.  
  14132.  dbtabname                         8
  14133.  
  14134.  dbtabsource                       8
  14135.  
  14136.  dbtsnewlen                        8
  14137.  
  14138.  dbtsnewval                        8
  14139.  
  14140.  dbtsput                           8
  14141.  
  14142.  
  14143.  Text and Image Handling
  14144.  
  14145.  Function                          Relative Size
  14146.  ────────────────────────────────────────────────────────────────────────────
  14147.  dbmoretext                        7
  14148.  
  14149.  dbtsptr                           7
  14150.  
  14151.  dbtxtimestamp                     7
  14152.  
  14153.  dbtxtsnewval                      7
  14154.  
  14155.  dbtxtsput                         7
  14156.  
  14157.  dbwritetext                       7
  14158.  
  14159.  
  14160.  Datatype Conversion
  14161.  
  14162.  Function                          Relative Size
  14163.  ────────────────────────────────────────────────────────────────────────────
  14164.  dbwillconvert                     10
  14165.  
  14166.  dbconvert                         10
  14167.  
  14168.  
  14169.  Cleanup
  14170.  
  14171.  Function                          Relative Size
  14172.  ────────────────────────────────────────────────────────────────────────────
  14173.  dbclose                           Core
  14174.  
  14175.  dbexit                            Core
  14176.  
  14177.  
  14178.  Miscellaneous Functions
  14179.  
  14180.  Function                          Relative Size
  14181.  ────────────────────────────────────────────────────────────────────────────
  14182.  dbprtype                          1
  14183.  
  14184.  dbreadpage                        2
  14185.  
  14186.  dbsetavail3
  14187.  
  14188.  dbsetmaxprocs                     3
  14189.  
  14190.  dbsetnull                         3
  14191.  
  14192.  dbwritepage                       2
  14193.  
  14194.  
  14195.  Bulk Copy
  14196.  
  14197.  Function                          Relative Size
  14198.  ────────────────────────────────────────────────────────────────────────────
  14199.  bcp_batch                         10
  14200.  
  14201.  bcp_bind                          10
  14202.  
  14203.  bcp_colfmt                        10
  14204.  
  14205.  bcp_collen                        10
  14206.  
  14207.  bcp_colptr                        10
  14208.  
  14209.  bcp_columns                       10
  14210.  
  14211.  bcp_control                       10
  14212.  
  14213.  bcp_done                          10
  14214.  
  14215.  bcp_exec                          10
  14216.  
  14217.  bcp_init                          10
  14218.  
  14219.  bcp_moretext                      10
  14220.  
  14221.  bcp_sendrow                       10
  14222.  
  14223.  BCP_SETL                          10
  14224.  
  14225.  
  14226.  Two-Phase Commit
  14227.  
  14228.  Function                          Relative Size
  14229.  ────────────────────────────────────────────────────────────────────────────
  14230.  abort_xact                        6
  14231.  
  14232.  build_xact_string                 6
  14233.  
  14234.  close_commit                      6
  14235.  
  14236.  commit_xact                       6
  14237.  
  14238.  open_commit                       6
  14239.  
  14240.  remove_xact                       6
  14241.  
  14242.  scan_xact                         6
  14243.  
  14244.  start_xact                        6
  14245.  
  14246.  stat_xact                         6
  14247.  
  14248.  
  14249.  Modularity
  14250.  
  14251.  DB-LIBRARY static link libraries contain a number of object modules. Each
  14252.  module may have one or more DB-LIBRARY APIs or support routines within it.
  14253.  Whenever an application references any of the APIs contained within a
  14254.  module, the entire module and all of the APIs that it contains will be
  14255.  linked with the application. If an application calls any one of the APIs in
  14256.  a module, it can call any of the other APIs in that same module without
  14257.  incurring additional memory overhead.
  14258.  
  14259.  
  14260.    ■   Core Routines
  14261.  
  14262.        ■   dbdataready, dberrhandle, dbmsghandle, dblogin, dbfreelogin,
  14263.            dbresults, dbnextrow, dbclose, dbopen, dbcmd, dbsqlexec, dbsqlok,
  14264.            dbsqlsend, dbsettime, dbsetlogintime, dbexit, dbinit
  14265.  
  14266.  
  14267.    ■   Other standard routines
  14268.  
  14269.        ■   dbfcmd
  14270.  
  14271.        ■   dbsetopt, dbisopt, dbclropt, dbfreebuf
  14272.  
  14273.        ■   dbstrlen, dbstrcpy, dbgetchar
  14274.  
  14275.        ■   dbcanquery, dbcancel
  14276.  
  14277.        ■   dbgetrow, dbclrbuf
  14278.  
  14279.        ■   dbconvert, dbwillconvert
  14280.  
  14281.        ■   dbcollen, dbcolname, dbcoltype, dbdata, dbdatlen, dbnumcols,
  14282.            dbordercol
  14283.  
  14284.        ■   dbcolbrowse, dbtabname, dbcolsource, dbtabbrowse, dbtabsource,
  14285.            dbtabcount, dbtsnewval, dbtsnewlen, dbtsput, dbqual, dbfreequal
  14286.  
  14287.        ■   dbprhead, dbprrow
  14288.  
  14289.        ■   dbtxptr, dbtxtimestamp, dbtxtsnewval, dbtxtsput, dbwritetext,
  14290.            dbmoretext
  14291.  
  14292.        ■   dbuse
  14293.  
  14294.        ■   dbbind─uses dbconvert
  14295.  
  14296.        ■   dbsetnull
  14297.  
  14298.        ■   dbaltbind─uses dbconvert
  14299.  
  14300.        ■   dbaltlen, dbalttype, dbadata, dbadlen, dbnumalts, dbaltcolid,
  14301.            dbbylist, dbaltop, dbnumcompute
  14302.  
  14303.        ■   dbgetoff
  14304.  
  14305.        ■   dbprtype
  14306.  
  14307.        ■   dbsetmaxprocs, dbgetmaxprocs, dbchange, dbname, dbsetavail
  14308.  
  14309.        ■   dbreadpage, dbwritepage
  14310.  
  14311.  
  14312.  
  14313.  
  14314.  
  14315.  
  14316.  INDEX
  14317.  ──────────────────────────────────────────────────────────────────────────
  14318.  
  14319.  
  14320.  
  14321.  
  14322.      A
  14323.  abort_xact
  14324.  Ad hoc query, process
  14325.  Aggregate function
  14326.  Application
  14327.    build
  14328.    DB-LIBRARY
  14329.  
  14330.      B
  14331.  Batch command
  14332.  bcp_batch
  14333.  bcp_bind
  14334.  bcp_colfmt
  14335.  bcp_collen
  14336.  bcp_colptr
  14337.  bcp_columns
  14338.  bcp_control
  14339.  bcp_done
  14340.  bcp_exec
  14341.  bcp_init
  14342.  bcp_moretext
  14343.  bcp_sendrow
  14344.  BCP_SETL
  14345.  Binary data
  14346.    read
  14347.    write
  14348.  Bind aggregate and compute results program example
  14349.  Browse mode functions
  14350.    program example
  14351.  Browse mode
  14352.    steps
  14353.    update column
  14354.    WHERE clause
  14355.  Buffer
  14356.    clear row
  14357.    command
  14358.    message
  14359.    row information
  14360.    row
  14361.    row, number of first
  14362.  build_xact_string
  14363.  Bulk copy functions
  14364.    bcp_batch
  14365.    bcp_bind
  14366.    bcp_colfmt
  14367.    bcp_collen
  14368.    bcp_colptr
  14369.    bcp_columns
  14370.    bcp_control
  14371.    bcp_done
  14372.    bcp_exec
  14373.    bcp_init
  14374.    bcp_moretext
  14375.    bcp_sendrow
  14376.  Bulk copy macro
  14377.    BCP_SETL
  14378.  Bulk Copy special library
  14379.  Bulk copy
  14380.    data format
  14381.    end from program variable
  14382.    execute
  14383.    initialize
  14384.    special library
  14385.  Bylist, compute row
  14386.  
  14387.      C
  14388.  C functions and macros
  14389.  Cancel
  14390.    command batch
  14391.    result row
  14392.  Cleanup functions
  14393.  close_commit
  14394.  Column
  14395.    bind to program variable
  14396.    datatype
  14397.    get data
  14398.    in ORDER BY clause
  14399.    length for data in
  14400.    length of data
  14401.    number in compute row
  14402.    number in results row
  14403.    ORDER BY clause
  14404.    print headings
  14405.    updatable using browse mode
  14406.    update
  14407.  Command batch
  14408.    access
  14409.    build
  14410.    cancel
  14411.    determine changes to database
  14412.    execute
  14413.    program example
  14414.    set up next statement
  14415.    verify
  14416.  Command buffer
  14417.    add text
  14418.    character in
  14419.    check for TRANSACT-SQL statements
  14420.    clear
  14421.    copy portion
  14422.    length
  14423.  Command processing functions
  14424.  Command state information functions
  14425.  Command
  14426.    complete process
  14427.    current number
  14428.    determine whether returns rows
  14429.    more to process
  14430.    option
  14431.  Commit server
  14432.    specify
  14433.  Commit service
  14434.    end connection
  14435.    establish connection
  14436.    lookup table
  14437.  commit_xact
  14438.  COMPUTE clause, number
  14439.  Compute column
  14440.    aggregate function
  14441.    bind to program variable
  14442.    datatype
  14443.    length of data
  14444.    maximum data length
  14445.    operand column ID
  14446.    pointer
  14447.  Compute row
  14448.    bylist
  14449.    determine
  14450.    number of columns
  14451.  Connections, number of SQL Server
  14452.  Constant, symbolic
  14453.  Control parameter, set
  14454.  Convert data
  14455.    program example
  14456.  core functions
  14457.    dbclose
  14458.    dbcmd
  14459.    dberrhandle
  14460.    dbexit
  14461.    dbfreelogin
  14462.    dbinit
  14463.    dblogin
  14464.    dbmsghandle
  14465.    dbnextrow
  14466.    dbopen
  14467.    dbresults
  14468.    dbsetlogintime
  14469.    dbsettime
  14470.    dbsqlexec
  14471.    dbsqlok
  14472.    dbsqlsend
  14473.    Sizes
  14474.  
  14475.      D
  14476.  Data files
  14477.    program example
  14478.  Data
  14479.    bind
  14480.    high-speed load
  14481.    length in column
  14482.    length in compute column
  14483.    maximum length
  14484.    result
  14485.  Database
  14486.    current name
  14487.    determine whether command batch has changed
  14488.    query and update program example
  14489.    set
  14490.  Datatype
  14491.    column
  14492.    compute column
  14493.    conversion function
  14494.    convert
  14495.  Datatypes, DB-LIBRARY
  14496.    DBBINARY
  14497.    DBBIT
  14498.    DBBOOL
  14499.    DBCHAR
  14500.    DBDATETIME
  14501.    DBFLT8
  14502.    DBINT
  14503.    DBMONEY
  14504.    DBSMALLINT
  14505.    DBTINYINT
  14506.    DBUSMALLINT
  14507.    DBVARYBIN
  14508.    DBVARYCHAR
  14509.    RETCODE
  14510.    STATUS
  14511.  Datatypes, SQL Server
  14512.    SQLBINARY
  14513.    SQLBIT
  14514.    SQLCHAR
  14515.    SQLDATETIME
  14516.    SQLFLT8
  14517.    SQLIMAGE
  14518.    SQLINT1
  14519.    SQLINT2
  14520.    SQLINT4
  14521.    SQLMONEY
  14522.    SQLTEXT
  14523.  DB-LIBRARY options
  14524.    DBARITHABORT
  14525.    DBARITHIGNORE
  14526.    DBBUFFER
  14527.    DBNOAUTOFREE
  14528.    DBNOCOUNT
  14529.    DBNOEXEC
  14530.    DBOFFSET
  14531.    DBPARSEONLY
  14532.    DBROWCOUNT
  14533.    DBSHOWPLAN
  14534.    DBSTAT
  14535.    DBSTORPROCID
  14536.    DBTEXTLIMIT
  14537.    DBTEXTSIZE
  14538.  DB-LIBRARY
  14539.    application
  14540.    datatypes. See Datatypes, DB-LIBRARY
  14541.    error severity
  14542.    error
  14543.    function categories
  14544.    lock segment
  14545.    option
  14546.    overview
  14547.    program framework
  14548.    program with
  14549.    unlock
  14550.    Windows functions
  14551.  dbadata
  14552.  dbadlen
  14553.  dbaltbind
  14554.    vartype
  14555.  dbaltcolid
  14556.  dbaltlen
  14557.  dbaltop
  14558.  dbalttype
  14559.  DBARITHABORT option
  14560.  DBARITHIGNORE option
  14561.  dbbind
  14562.  DBBUFFER option
  14563.  dbbylist
  14564.  dbcancel
  14565.  dbcanquery
  14566.  dbchange
  14567.  dbclose
  14568.  dbclrbuf
  14569.  dbclropt
  14570.  dbcmd
  14571.  DBCMDROW
  14572.  dbcolbrowse
  14573.  dbcollen
  14574.  dbcolname
  14575.  dbcolsource
  14576.  dbcoltype
  14577.  dbconvert
  14578.    program example
  14579.  DBCOUNT
  14580.  DBCURCMD
  14581.  DBCURROW
  14582.  dbdata
  14583.  dbdatarady
  14584.  dbdataready
  14585.  dbdatlen
  14586.  DBDEAD
  14587.  dberrhandle
  14588.  dbexit
  14589.  dbfcmd
  14590.  DBFIRSTROW
  14591.  dbfreebuf
  14592.  dbfreelogin
  14593.  dbfreequal
  14594.  dbgetchar
  14595.  dbgetmaxprocs
  14596.  dbgetoff
  14597.  dbgetrow
  14598.  DBGETTIME
  14599.  dbinit
  14600.  DBISAVAIL
  14601.  DBISAVIAL
  14602.  dbisopt
  14603.  DBLASTROW
  14604.  DBLOCKLIB (Windows only)
  14605.  DBLOCKLIB
  14606.  dblogin
  14607.  DBMORECMDS
  14608.  dbmoretext
  14609.  dbmsghandle
  14610.  dbname
  14611.  dbnextrow
  14612.  DBNOAUTOFREE option
  14613.  DBNOCOUNT option
  14614.  DBNOEXEC option
  14615.  dbnumalts
  14616.  dbnumcols
  14617.  dbnumcompute
  14618.  DBNUMORDERS
  14619.  DBOFFSET option
  14620.  dbopen
  14621.  dbordercol
  14622.  DBPARSEONLY option
  14623.  dbprhead
  14624.  DBPROCESS
  14625.    allocate structure
  14626.    close structure
  14627.    close
  14628.    dead
  14629.    determine if available
  14630.    determine maximum structures
  14631.    mark
  14632.    set maximum structures
  14633.    structure
  14634.  dbprrow
  14635.  dbprtype
  14636.  dbqual
  14637.  DBRBUF
  14638.  dbreadpage
  14639.  dbresults
  14640.  DBROWCOUNT option
  14641.  DBROWS
  14642.  DBROWTYPE
  14643.  dbrwitepage
  14644.  dbsetavail
  14645.  DBSETLAPP
  14646.  DBSETLHOST
  14647.  dbsetlogintime
  14648.  DBSETLPWD
  14649.  DBSETLUSER
  14650.  dbsetmaxprocs
  14651.  dbsetnull
  14652.  dbsetopt
  14653.  dbsettime
  14654.  DBSHOWPLAN option
  14655.  dbsqlexec
  14656.  dbsqlok
  14657.  dbsqlsend
  14658.  DBSTAT option
  14659.  DBSTORPROCID option
  14660.  dbstrcpy
  14661.  dbstrlen
  14662.  dbtabbrowse
  14663.  dbtabcount
  14664.  dbtabname
  14665.  dbtabsource
  14666.  DBTEXTLIMIT option
  14667.  DBTEXTSIZE option
  14668.  dbtsnewlen
  14669.  dbtsnewval
  14670.  dbtsput
  14671.  dbtxptr
  14672.  dbtxtimestamp
  14673.  dbtxtsnewval
  14674.  dbtxtsput function
  14675.  dbtxtsput
  14676.  DBUNLOCKLIB (Windows only)
  14677.  DBUNLOCKLIB
  14678.  dbuse
  14679.  dbwillconvert
  14680.  dbwinexit
  14681.  dbwritepage
  14682.  dbwritetext
  14683.  Debug
  14684.  Dynamic link library
  14685.  Dynamic Link Library
  14686.    size of
  14687.  
  14688.      E
  14689.  Environment
  14690.    MS OS/2
  14691.    MS-DOS
  14692.  ERREXIT exit value
  14693.  Error handling functions
  14694.  Error severity
  14695.    DB-LIBRARY
  14696.  Error
  14697.    DB-LIBRARY
  14698.    handling
  14699.    install handler
  14700.    SQL Server
  14701.  Example programs
  14702.  Exit value
  14703.  
  14704.      F
  14705.  File
  14706.    header
  14707.    include
  14708.  Functions
  14709.    abort_xact
  14710.    alphabetical list
  14711.    bcp_batch
  14712.    bcp_bind
  14713.    bcp_colfmt
  14714.    bcp_collen
  14715.    bcp_colptr
  14716.    bcp_columns
  14717.    bcp_control
  14718.    bcp_done
  14719.    bcp_exec
  14720.    bcp_init
  14721.    bcp_moretext
  14722.    bcp_sendrow
  14723.    browse mode program example
  14724.    browse mode
  14725.    build_xact_string
  14726.    C
  14727.    categories
  14728.    cleanup
  14729.    close_commit
  14730.    command processing
  14731.    command state information
  14732.    commit_xact
  14733.    datatype conversion
  14734.    dbadata
  14735.    dbadlen
  14736.    dbaltbind
  14737.    dbaltcolid
  14738.    dbaltlen
  14739.    dbaltop
  14740.    dbalttype
  14741.    dbbind
  14742.    dbbylist
  14743.    dbcancel
  14744.    dbcanquery
  14745.    dbchange
  14746.    dbclose
  14747.    dbclrbuf
  14748.    dbclropt
  14749.    dbcmd
  14750.    dbcolbrowse
  14751.    dbcollen
  14752.    dbcolname
  14753.    dbcolsource
  14754.    dbcoltype
  14755.    dbconvert
  14756.    dbdata
  14757.    dbdatarady
  14758.    dbdataready
  14759.    dbdatlen
  14760.    dberrhandle
  14761.    dbexit
  14762.    dbfcmd
  14763.    dbfreebuf
  14764.    dbfreelogin
  14765.    dbfreequal
  14766.    dbgetchar
  14767.    dbgetmaxprocs
  14768.    dbgetoff
  14769.    dbgetrow
  14770.    dbinit
  14771.    dbisopt
  14772.    dblogin
  14773.    dbmoretext
  14774.    dbmsghandle
  14775.    dbname
  14776.    dbnextrow
  14777.    dbnumalts
  14778.    dbnumcols
  14779.    dbnumcompute
  14780.    dbopen
  14781.    dbordercol
  14782.    dbprhead
  14783.    dbprrow
  14784.    dbprtype
  14785.    dbqual
  14786.    dbreadpage
  14787.    dbresults
  14788.    dbsetavail
  14789.    dbsetlogintime
  14790.    dbsetmaxprocs
  14791.    dbsetnull
  14792.    dbsetopt
  14793.    dbsettime
  14794.    dbsqlexec
  14795.    dbsqlok
  14796.    dbsqlsend
  14797.    dbstrcpy
  14798.    dbstrlen
  14799.    dbtabbrowse
  14800.    dbtabcount
  14801.    dbtabname
  14802.    dbtabsource
  14803.    dbtsnewlen
  14804.    dbtsnewval
  14805.    dbtsput
  14806.    dbtxptr
  14807.    dbtxtimestamp
  14808.    dbtxtsnewval
  14809.    dbtxtsput
  14810.    dbuse
  14811.    dbwillconvert
  14812.    dbwinexit
  14813.    dbwritepage
  14814.    dbwritetext
  14815.    error-handling
  14816.    information retrieval
  14817.    initialization
  14818.    message-handling
  14819.    miscellaneous information
  14820.    miscellaneous
  14821.    open_commit
  14822.    remove_xact
  14823.    results processing
  14824.    scan_xact
  14825.    start_xact
  14826.    stat_xact
  14827.    text- and image-handling
  14828.    TSEQUAL built-in
  14829.  
  14830.      I
  14831.  Image
  14832.    handling functions
  14833.    limit value size
  14834.    send value to SQL Server
  14835.    update value
  14836.  Include files
  14837.    Microsoft Windows applications
  14838.    MS OS/2 applications
  14839.    MS-DOS applications
  14840.  Information retrieval functions
  14841.  Initialization functions
  14842.  
  14843.      L
  14844.  LAN Manager
  14845.  Library
  14846.    bulk copy
  14847.    Microsoft Windows application
  14848.    MS OS/2 application
  14849.    MS-DOS required
  14850.    two-phase commit service
  14851.  Lock, DB-LIBRARY segment
  14852.  Log in to SQL Server
  14853.  LOGINREC
  14854.    allocate
  14855.    free
  14856.    set application name
  14857.    set for bulk copy
  14858.    set password
  14859.    set up
  14860.    set username in
  14861.    set workstation name in
  14862.    structure
  14863.  
  14864.      M
  14865.  Macros
  14866.    alphabetical list
  14867.    BCP_SETL
  14868.    C
  14869.    DBCMDROW
  14870.    DBCOUNT
  14871.    DBCURCMD
  14872.    DBCURROW
  14873.    DBDEAD
  14874.    DBFIRSTROW
  14875.    DBGETTIME
  14876.    DBISAVAIL
  14877.    DBLASTROW
  14878.    DBLOCKLIB
  14879.    DBMORECMDS
  14880.    DBNUMORDERS
  14881.    DBRBUF
  14882.    DBROWS
  14883.    DBROWTYPE
  14884.    DBSETLAPP
  14885.    DBSETLHOST
  14886.    DBSETLPWD
  14887.    DBSETLUSER
  14888.    DBUNLOCKLIB
  14889.  memory constraints
  14890.    Microsoft Windows
  14891.  Message
  14892.    buffer
  14893.    handling functions
  14894.    handling
  14895.    install handler
  14896.    SQL Server
  14897.  Microsoft Windows
  14898.    include files
  14899.  Miscellaneous information functions
  14900.  MS OS/2
  14901.    include files
  14902.  MS-DOS
  14903.    include files
  14904.    increasing SQL Server connections
  14905.    library
  14906.    required system library
  14907.    sample program
  14908.  
  14909.      N
  14910.  Name
  14911.    database
  14912.    result column
  14913.    set application
  14914.    set workstation
  14915.  Network
  14916.    close connection
  14917.    find SQL Server on
  14918.  Notational conventions
  14919.  Null value
  14920.    bind
  14921.    define substitution value
  14922.  
  14923.      O
  14924.  Offsets, types of
  14925.  open_commit
  14926.  Operand column ID
  14927.  Operating system file
  14928.    set columns
  14929.    specify format
  14930.  Option
  14931.    check status
  14932.    clear
  14933.    command
  14934.    DB-LIBRARY
  14935.    set
  14936.  ORDER BY clause
  14937.    columns in
  14938.    number of columns in
  14939.  OS/2
  14940.    dynamic-link library
  14941.    sample program
  14942.  
  14943.      P
  14944.  Password, set
  14945.  Pointer
  14946.    data for compute column
  14947.    text
  14948.  Print
  14949.    column headings
  14950.    row
  14951.  Probe process
  14952.  Program example
  14953.    binding aggregate and compute results
  14954.    converting data with dbconvert
  14955.    querying and updating the database
  14956.    sending queries in a command batch
  14957.    two-phase commit service
  14958.    using browse mode functions
  14959.    using row buffering
  14960.    working with data files
  14961.  Program variable
  14962.    bind compute result column to
  14963.    bind result column
  14964.    dbaltbind
  14965.    send row to SQL Server
  14966.    set data address
  14967.    set data length
  14968.  Program
  14969.    examples
  14970.    with DB-LIBRARY
  14971.  
  14972.      Q
  14973.  Query database
  14974.    program example
  14975.  Query
  14976.    ad hoc
  14977.    example in command batch
  14978.  
  14979.      R
  14980.  Record, login
  14981.  Relative size
  14982.    abort_xact
  14983.    bcp_batch
  14984.    bcp_bind
  14985.    bcp_colfmt
  14986.    bcp_collen
  14987.    bcp_colptr
  14988.    bcp_columns
  14989.    bcp_control
  14990.    bcp_done
  14991.    bcp_exec
  14992.    bcp_init
  14993.    bcp_moretext
  14994.    bcp_sendrow
  14995.    BCP_SETL
  14996.    build_xact
  14997.    close_commit
  14998.    commit_xact
  14999.    dbadata
  15000.    dbadlen
  15001.    dbaltbind
  15002.    dbaltcolid
  15003.    dbaltlen
  15004.    dbaltop
  15005.    dbalttype
  15006.    dbbind
  15007.    dbbylist
  15008.    dbcancel
  15009.    dbcanquery
  15010.    dbchange
  15011.    dbclose
  15012.    dbclrbuf
  15013.    dbclropt
  15014.    dbcmd
  15015.    DBCMDROW
  15016.    dbcolbrowse
  15017.    dbcollen
  15018.    dbcolname
  15019.    dbcolsource
  15020.    dbcoltype
  15021.    dbconvert
  15022.    DBCOUNT
  15023.    DBCURCMD
  15024.    DBCURROW
  15025.    dbdata
  15026.    dbdataready
  15027.    dbdatlen
  15028.    dberrhandle
  15029.    dbexit
  15030.    dbfcmd
  15031.    DBFIRSTROW
  15032.    dbfreebuf
  15033.    dbfreelogin
  15034.    dbgetchar
  15035.    dbgetmaxprocs
  15036.    dbgetoff
  15037.    dbgetrow
  15038.    DBGETTIME
  15039.    DBISAVAIL
  15040.    dbisopt
  15041.    DBLASTROW
  15042.    dblogin
  15043.    DBMORECMDS
  15044.    dbmoretext
  15045.    dbmsghandle
  15046.    dbname
  15047.    dbnextrow
  15048.    dbnumalts
  15049.    dbnumcols
  15050.    dbnumcompute
  15051.    DBNUMORDERS
  15052.    dbopen
  15053.    dbordercol
  15054.    dbprhead
  15055.    dbprrow
  15056.    dbprtype
  15057.    dbqual
  15058.    DBREAD
  15059.    dbreadpage
  15060.    dbresults
  15061.    DBROWS
  15062.    DBROWTYPE
  15063.    dbsetavail
  15064.    DBSETLAPP
  15065.    DBSETLHOST
  15066.    dbsetlogintime
  15067.    DBSETLPWD
  15068.    DBSETLUSER
  15069.    dbsetmaxprocs
  15070.    dbsetopt
  15071.    dbsettime
  15072.    dbsetull
  15073.    dbsqlexec
  15074.    dbsqlok
  15075.    dbsqlsend
  15076.    dbstrcpy
  15077.    dbstrlen
  15078.    dbtabbrowse
  15079.    dbtabcount
  15080.    dbtabname
  15081.    dbtabsource
  15082.    dbtsnewlen
  15083.    dbtsnewval
  15084.    dbtsptr
  15085.    dbtsput
  15086.    dbtxtsnewval
  15087.    dbtxtsput
  15088.    dbtxttimestamp
  15089.    dbuse
  15090.    dbwillconvert
  15091.    dbwritepage
  15092.    dbwritetext
  15093.    library routines
  15094.    open_commit
  15095.    remove_xact
  15096.    scan_xact
  15097.    start_xact
  15098.    stat_xact
  15099.  remove_xact
  15100.  Result
  15101.    access data directly
  15102.    access row
  15103.    bind data to variable
  15104.    cancel row
  15105.    cancel
  15106.    column name
  15107.    data
  15108.    database column name
  15109.    more to process
  15110.    number of columns
  15111.    read row
  15112.    row
  15113.    set up
  15114.    stored procedure
  15115.  Results processing functions
  15116.  Row buffer
  15117.    clear
  15118.    information
  15119.    last row number
  15120.    number of first row
  15121.    program example
  15122.    read
  15123.  Row
  15124.    compute
  15125.    current number
  15126.    determine if statement returns
  15127.    determine type
  15128.    determine
  15129.    number affected by statement
  15130.    print column headings
  15131.    print
  15132.    read data
  15133.    read
  15134.    regular
  15135.    result
  15136.    save
  15137.    set maximum number
  15138.    type
  15139.  
  15140.      S
  15141.  Sample program
  15142.    Microsoft Windows
  15143.    MS OS/2
  15144.    MS-DOS
  15145.  scan_xact
  15146.  Sizes
  15147.    core functions
  15148.    Dynamic link libraries
  15149.    Relative
  15150.  SQL Server response
  15151.    time DB-LIBRARY will wait for
  15152.  SQL Server
  15153.    communicate with
  15154.    datatypes. See Datatypes, SQL Server
  15155.    error
  15156.    establish connection
  15157.    find on network
  15158.    increase number of connections
  15159.    log in
  15160.    message
  15161.  sqltestp.c sample program
  15162.  sqltestr.c sample program
  15163.  sqltestw.c sample program
  15164.  start_xact
  15165.  Statement, process
  15166.  Statements
  15167.    check command buffer for
  15168.  stat_xact
  15169.  STDEXIT exit value
  15170.  Symbolic constant
  15171.  
  15172.      T
  15173.  Table
  15174.    browsable
  15175.    name
  15176.    number
  15177.    work
  15178.  Text
  15179.    handling functions
  15180.    limit value size
  15181.    pointer value
  15182.    pointer
  15183.    put timestamp value in DBPROCESS
  15184.    send value to SQL Server
  15185.    timestamp
  15186.    update value
  15187.  Time
  15188.    response to connection request
  15189.    SQL Server response
  15190.  Timestamp
  15191.    column length
  15192.    column value
  15193.    put column value in DBPROCESS
  15194.    put text value in DBPROCESS
  15195.    text
  15196.  Token value, convert to string
  15197.  TRANSACT-SQL
  15198.  Transaction, distributed
  15199.    build name
  15200.    decrement active sites
  15201.    mark as aborted
  15202.    mark as committed
  15203.    print record
  15204.    start
  15205.    status
  15206.  TSEQUAL built-in function
  15207.  Two-phase commit functions
  15208.    abort_xact
  15209.    build_xact_string
  15210.    close_commit
  15211.    commit_xact
  15212.    open_commit
  15213.    remove_xact
  15214.    scan_xact
  15215.    start_xact
  15216.    stat_xact
  15217.  Two-phase commit service special library
  15218.  
  15219.      U
  15220.  Username
  15221.    set
  15222.  
  15223.      W
  15224.  WHERE clause
  15225.    update browsable table
  15226.  Windows
  15227.    application
  15228.    Dynamic link library
  15229.    memory constraints
  15230.    sample program
  15231.    special DB-LIBRARY functions
  15232.  Work table
  15233.  
  15234.  
  15235.  
  15236.