Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ () — Sybase DB Library C 4.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

  1                       Version 4.0 -- 5/1/89             bcp_moretext
  ______________________________________________________________________

  NAME:  bcp_moretext

  FUNCTION:
       Send part of a text or image value to SQL Server.

  SYNTAX:
       RETCODE bcp_moretext(dbproc, size, text)

       DBPROCESS *dbproc;
       DBINT     size;
       BYTE      *text;








  bcp_moretext            Version 4.0 -- 5/1/89                        2
  ______________________________________________________________________

  COMMENTS:

       o This  routine  is  used  in  conjunction  with  bcp_bind()  and
         bcp_sendrow()  to  send  a  large  SYBTEXT or SYBIMAGE value to
         SQL Server in the form of a number of smaller chunks.  This  is
         particularly  useful  with operating systems unable to allocate
         extremely long data buffers.
       o If bcp_bind() is called with a type  parameter  of  SYBTEXT  or
         SYBIMAGE  and  a non-NULL varaddr parameter, bcp_sendrow() will
         send the entire text or image data value, just as it  does  for
         all  other  datatypes.   If,  however,  bcp_bind()  has  a NULL
         varaddr parameter, bcp_sendrow() will  return  control  to  the
         application immediately after all non-text or image columns are
         sent  to   SQL Server.    The   application   can   then   call
         bcp_moretext() repeatedly to send the text and image columns to
         SQL Server, a chunk at a time.



  3                       Version 4.0 -- 5/1/89             bcp_moretext
  ______________________________________________________________________

       o Here's an example that illustrates how  to  use  bcp_moretext()
         with bcp_bind() and bcp_sendrow():

            LOGINREC        *login;
            DBPROCESS       *dbproc;

            DBINT           id = 5;
            char            *part1 = "This text value isn't very long,";
            char            *part2 = " but it's broken up into three parts";
            char            *part3 = " anyhow.";

            /* Initialize DB-Library. */
            if (dbinit() == FAIL)
                exit(ERREXIT);

            /* Install error handler and message handler. */
            dberrhandle(err_handler);


  bcp_moretext            Version 4.0 -- 5/1/89                        4
  ______________________________________________________________________
            dbmsghandle(msg_handler);

            /* Open a DBPROCESS */
            login = dblogin();
            BCP_SETL(login, TRUE);
            dbproc = dbopen(login, NULL);

            /* Initialize bcp. */
            if (bcp_init(dbproc, "comdb..articles", (BYTE *)NULL, (BYTE *)NULL, DB_IN) == FAIL)
                exit(ERREXIT);

            /* Bind program variables to table columns. */
            if (bcp_bind(dbproc, (BYTE *)&id, 0, (DBINT)-1, (BYTE *)NULL, 0, SYBINT4, 1)
                == FAIL)
            {
                fprintf(stderr, "bcp_bind, column 1, failed.\n");
                exit(ERREXIT);



  5                       Version 4.0 -- 5/1/89             bcp_moretext
  ______________________________________________________________________
            }

            if (bcp_bind
                (dbproc, (BYTE *)NULL, 0, (DBINT) (strlen(part1) + strlen(part2) + strlen(part3)),
                 (BYTE *)NULL, 0, SYBTEXT, 2)
                 == FAIL)
            {
                fprintf(stderr, "bcp_bind, column 2, failed.\n");
                exit(ERREXIT);
            }

            /* Now send this row, with the text value broken into three chunks. */
            if (bcp_sendrow(dbproc) == FAIL)
                exit(ERREXIT);
            if (bcp_moretext(dbproc, (DBINT)strlen(part1), part1) == FAIL)
                exit(ERREXIT);
            if (bcp_moretext(dbproc, (DBINT)strlen(part2), part2) == FAIL)



  bcp_moretext            Version 4.0 -- 5/1/89                        6
  ______________________________________________________________________
                exit(ERREXIT);
            if (bcp_moretext(dbproc, (DBINT)strlen(part3), part3) == FAIL)
                exit(ERREXIT);

            /* We're all done. */
            bcp_done(dbproc);
            dbclose(dbproc);


       o If you use bcp_moretext() to send one text or image  column  in
         the  row, you must also use it to send all other text and image
         columns in the row.
       o If the row  contains  more  than  one  text  or  image  column,
         bcp_moretext()  will first send its data to the lowest-numbered
         (i.e., leftmost) text or image column,  followed  by  the  next
         lowest-numbered column, and so on.

       o An   application   will   normally   call   bcp_sendrow()   and


  7                       Version 4.0 -- 5/1/89             bcp_moretext
  ______________________________________________________________________
         bcp_moretext() within loops, in order to send a number of  rows
         of  data.  Here's an outline of how to do this for a table con-
         taining two text columns:

            while (there are still rows to send)
            {
                bcp_sendrow(...);

                for (all the data in the first text column)
                    bcp_moretext(...);

                for (all the data in the second text column)
                    bcp_moretext(...);
            }


       o For information on the bcp utility program, see its manual page
         in the Commands Reference.


  bcp_moretext            Version 4.0 -- 5/1/89                        8
  ______________________________________________________________________

  PARAMETERS:
       dbproc -  A pointer to the DBPROCESS structure that provides  the
           connection for a particular front-end/SQL Server process.  It
           contains all the information that DB-Library uses  to  manage
           communications and data between the front end and SQL Server.
       size -  The size of this particular part of  the  text  or  image
           value  being sent to SQL Server.  It is an error to send more
           text or image bytes to SQL Server than were specified in  the
           call to bcp_bind() or bcp_collen().
       text -  A pointer to the text or image portion to be written.

  RETURNS:
       SUCCEED or FAIL.

  SEE ALSO:
       bcp_bind, bcp_sendrow, dbmoretext, dbwritetext


Typewritten Software • bear@typewritten.org • Edmonds, WA 98026