home *** CD-ROM | disk | FTP | other *** search
- .Na "dbwritetext"
- .mc |
- .Aa
- .Fu
- Send a text or image value to \*S.
- .Ih "text value, updating"
- .Ih "image value, updating"
- .Sy
- .Sf "RETCODE dbwritetext(dbproc, objname, textptr, textptrlen,"
- .sp -1v
- .Sf " timestamp, log, size, text)"
- .Sp "DBPROCESS" "*dbproc"
- .Sp "char" "*objname"
- .Sp "DBBINARY" "*textptr"
- .Sp "DBTINYINT" "textptrlen"
- .Sp "DBBINARY" "*timestamp"
- .Sp "DBBOOL" "log"
- .Sp "DBINT" "size"
- .Sp "BYTE" "*text"
- .Co
- .Bl
- \f2dbwritetext()\f1 updates SYBTEXT and SYBIMAGE values.
- It allows the application to send long
- values to \*S without having to copy them into a
- \*N UPDATE statement.
- In addition, \f2dbwritetext()\f1 gives applications access
- to the text timestamp mechanism, which can be used to
- ensure that two competing application users do not inadvertently
- wipe out each other's modifications to the same value in the database.
- .Ih "text timestamp"
- .Ih "timestamp, text"
- .Bl
- \f2dbwritetext()\f1
- will succeed only if its \f2timestamp\f1 parameter, usually obtained when the column's
- value was originally retrieved, matches the text column's timestamp in the database.
- If a match does occur, \f2dbwritetext()\f1 will update the text column,
- and at the same time it will update the column's timestamp.
- This has the effect of governing updates by competing applications\(eman application's
- \f2dbwritetext()\f1 call will fail if a second application updated the text column between
- the time the first application retrieved the column and the time
- it made its \f2dbwritetext()\f1 call.
- .Bl
- \f2dbwritetext()\f1 is similar in function to the \*N WRITETEXT command.
- It is usually more efficient to call \f2dbwritetext()\f1 than to send
- a WRITETEXT command through the command buffer.
- In addition, \f2dbwritetext()\f1 can handle columns up to 2 gigabytes in length,
- while WRITETEXT data is limited to approximately 120K bytes.
- For more information on WRITETEXT, see the \f2Commands Reference\f1.
- .Bl
- \f2dbwritetext()\f1 can be invoked with or without logging,
- according to the value of the \f2log\f1 parameter.
- .sp 0.5v
- While logging aids media recovery, logging text data quickly
- increases the size of the transaction log.
- If you're logging \f2dbwritetext()\f1 operations, make sure that the transaction log
- resides on a separate database device.
- See the \f2System Administration Guide\f1
- and the CREATE DATABASE and \f2sp_logdevice\f1 manual pages in the
- \f2Commands Reference\f1 for details.
- .sp 0.5v
- To use \f2dbwritetext()\f1 with logging turned off,
- the database option \f2select into/bulkcopy\f1 must be set to ``true''.
- The following SQL command will do this:
- .SD
- .in +3n
- sp_dboption 'mydb', 'select into/bulkcopy', 'true'
- .in -3n
- .ED
- See the \f2Commands Reference\f1 for further details on \f2sp_dboption\f1.
- .Bl
- The application can send a text or image value to the \*S all at once or a
- chunk at a time.
- \f2dbwritetext()\f1 by itself handles sending an entire text or image value.
- The use of \f2dbwritetext()\f1 with \f2dbmoretext()\f1
- allows the application to send a
- large text or image value to \*S in the form
- of a number of smaller chunks.
- This is particularly useful with operating systems
- unable to allocate extremely long data buffers.
- .Bl
- To send an entire text or image value requires a
- non-NULL \f2text\f1 parameter.
- Then, \f2dbwritetext()\f1
- will execute the data transfer from start to finish, including
- any necessary calls to \f2dbsqlok()\f1 and \f2dbresults()\f1.
- Here's a code fragment that illustrates this use of \f2dbwritetext()\f1:
- .SD
- .ne 5
- .ta +4n +4n +4n +4n +4n +4n
- LOGINREC *login;
- DBPROCESS *q_dbproc;
- DBPROCESS *u_dbproc;
- DBCHAR abstract_var[512];
-
- /* Initialize DB-Library. */
- if (dbinit() == FAIL)
- exit(ERREXIT);
-
- /* Open separate DBPROCESSes for querying and updating.
- ** This is not strictly necessary in this example, which
- ** retrieves only one row. However, this approach becomes
- ** essential when performing updates on multiple rows of
- ** retrieved data.
- */
- login = dblogin();
- q_dbproc = dbopen(login, NULL);
- u_dbproc = dbopen(login, NULL);
-
- /* The database column "abstract" is a text column. Retrieve the
- ** value of one of its rows.
- */
- dbcmd(q_dbproc, "select abstract from articles where article_id = 10");
- dbsqlexec(q_dbproc);
- dbresults(q_dbproc);
- dbbind(q_dbproc, 1, STRINGBIND, (DBINT) 0, abstract_var);
-
- /* For simplicity, we'll assume that just one row is returned. */
- dbnextrow(q_dbproc);
-
- /* Here we can change the value of "abstract_var". For instance ... */
- strcpy(abstract_var, "A brand new value.");
-
- /* Update the text column. */
- dbwritetext
- (u_dbproc, "articles.abstract", dbtxptr(q_dbproc, 1), DBTXPLEN,
- dbtxtimestamp(q_dbproc, 1), TRUE, (DBINT)strlen(abstract_var),
- abstract_var);
-
- /* We're all done. */
- dbexit();
- .ED
- .Bl
- To send chunks of text or image, rather than the whole value at once, set
- the \f2text\f1 parameter to NULL.
- Then, \f2dbwritetext()\f1 will
- return control to the application immediately after notifying
- \*S that a text transfer is about to begin.
- The actual text will be sent to \*S with \f2dbmoretext()\f1, which can be called
- multiple times, once for each chunk.
- Here's a code fragment that illustrates the
- use of \f2dbwritetext()\f1 with \f2dbmoretext()\f1:
- .SD
- .ne 5
- .ta +4n +4n +4n +4n +4n +4n
- LOGINREC *login;
- DBPROCESS *q_dbproc;
- DBPROCESS *u_dbproc;
- DBCHAR part1[512];
- static DBCHAR part2[512] = " This adds another sentence to the text.";
-
- if (dbinit() == FAIL)
- exit(ERREXIT);
-
- login = dblogin();
- q_dbproc = dbopen(login, NULL);
- u_dbproc = dbopen(login, NULL);
-
- dbcmd(q_dbproc, "select abstract from articles where article_id = 10");
- dbsqlexec(q_dbproc);
- dbresults(q_dbproc);
- dbbind(q_dbproc, 1, STRINGBIND, (DBINT) 0, part1);
-
- /* For simplicity, we'll assume that just one row is returned. */
- dbnextrow(q_dbproc);
-
- /*
- ** Here we can change the value of part of the text column. In
- ** this example, we will merely add a sentence to the end of the
- ** existing text.
- */
-
- /* Update the text column. */
- dbwritetext
- (u_dbproc, "articles.abstract", dbtxptr(q_dbproc, 1), DBTXPLEN,
- dbtxtimestamp(q_dbproc, 1), TRUE, (DBINT)(strlen(part1) + strlen(part2)),
- NULL);
-
- dbsqlok(u_dbproc);
- dbresults(u_dbproc);
-
- /* Send the update value in chunks. */
- dbmoretext(u_dbproc, (DBINT)strlen(part1), part1);
- dbmoretext(u_dbproc, (DBINT)strlen(part2), part2);
-
- dbsqlok(u_dbproc);
- dbresults(u_dbproc);
-
- dbexit();
- .ED
- Note the required calls to \f2dbsqlok()\f1 and \f2dbresults()\f1 between
- the call to \f2dbwritetext()\f1 and the first call to
- \f2dbmoretext()\f1, and after the final call to \f2dbmoretext()\f1.
- .Bl
- When \f2dbwritetext()\f1 is used with \f2dbmoretext()\f1,
- it locks the specified database text column.
- The lock is not released until the final \f2dbmoretext()\f1 has sent its data.
- This ensures that a second application does not read or update the text
- column in the midst of the first application's update.
- .Bl
- You cannot use \f2dbwritetext()\f1 on text or image columns in views.
- .Bz
- .Pa
- .Pi dbproc
- A pointer to the DBPROCESS structure that provides the connection
- for a particular front-end/\*S process. It contains all the
- information that \*L uses to manage communications and data between the
- front end and \*S.
- .Pi objname
- The database table and column name of interest.
- The table and the column should be separated by a period (``.'').
- .Pi textptr
- A pointer to
- the text pointer of the text or image value to be modified.
- This can be obtained by calling \f2dbtxptr()\f1.
- The text pointer must be a valid one, as described on
- the \f2dbtxptr()\f1 manual page.
- .Pi textptrlen
- This parameter is included for future compatibility.
- For now, its value must be the defined constant DBTXPLEN.
- .Pi timestamp
- A pointer to the text timestamp of the text or image value to be modified.
- This can be obtained by calling \f2dbtxtimestamp()\f1 or \f2dbtxtsnewval()\f1.
- This value changes whenever the text or image value itself is changed.
- .Pi log
- A Boolean value, specifying whether this \f2dbwritetext()\f1 operation
- should be recorded in the transaction log.
- .Pi size
- The total size, in bytes, of the text or image value to be written.
- Since \f2dbwritetext()\f1 uses this parameter as its only guide
- to determining how many bytes to send,
- \f2size\f1 must not exceed the actual size of the value.
- .Pi text
- A pointer to the text or image to be written.
- If this pointer is NULL, \*L will expect the application to
- call \f2dbmoretext()\f1 one or more times, until all \f2size\f1
- bytes of data have been sent to \*S.
- .in -.375i
- .Re
- .br
- SUCCEED or FAIL.
- .sp 0.5v
- A common cause for failure is an invalid \f2timestamp\f1 parameter.
- This will occur if, between the time the application retrieves the
- text column and the time the application calls \f2dbwritetext()\f1 to update it,
- a second application intervenes with its own update.
- .Sa
- dbmoretext,
- dbtxptr,
- dbtxtimestamp,
- dbtxtsnewval,
- dbtxtsput
- .mc
-