<!--
-$Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpgtcl.sgml,v 1.38 2003/09/29 18:18:35 momjian Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/Attic/libpgtcl.sgml,v 1.39 2003/10/31 00:18:55 tgl Exp $
 -->
 
 <chapter id="pgtcl">
     <term><parameter>conn</parameter></term>
     <listitem>
      <para>
-      The handle of a database connection in which to create the large
+      The handle of a connection to the database in which to create the large
       object.
      </para>
     </listitem>
 
     <listitem>
      <para>
-      The handle of a database connection in which the large object to
-      be opened exists.
+      The handle of a connection to the database in which the large object
+      exists.
      </para>
     </listitem>
    </varlistentry>
     <term><parameter>conn</parameter></term>
     <listitem>
      <para>
-      The handle of a database connection in which the large object
+      The handle of a connection to the database in which the large object
       exists.
      </para>
     </listitem>
     <term><parameter>conn</parameter></term>
     <listitem>
      <para>
-      The handle of a database connection in which the large object
+      The handle of a connection to the database in which the large object
       exists.
      </para>
     </listitem>
   <title>Return Value</title>
 
   <para>
-   None
+   The number of bytes actually read is returned; this could be less than
+   the number requested if the end of the large object is reached first.
+   In event of an error, the return value is negative.
   </para>
  </refsect1>
 </refentry>
     <term><parameter>conn</parameter></term>
     <listitem>
      <para>
-      The handle of a database connection in which the large object
+      The handle of a connection to the database in which the large object
       exists.
      </para>
     </listitem>
     <term><parameter>buf</parameter></term>
     <listitem>
      <para>
-      The string to write to the large object (not a variable name).
+      The string to write to the large object (not a variable name,
+      but the value itself).
      </para>
     </listitem>
    </varlistentry>
     <term><parameter>len</parameter></term>
     <listitem>
      <para>
-      The maximum number of bytes to write.
+      The maximum number of bytes to write.  The number written will
+      be the smaller of this value and the length of the string.
      </para>
     </listitem>
    </varlistentry>
   <title>Return Value</title>
 
   <para>
-   None
+   The number of bytes actually written is returned; this will ordinarily
+   be the same as the number requested.
+   In event of an error, the return value is negative.
   </para>
  </refsect1>
 </refentry>
     <term><parameter>conn</parameter></term>
     <listitem>
      <para>
-      The handle of a database connection in which the large object
+      The handle of a connection to the database in which the large object
       exists.
      </para>
     </listitem>
 
     <listitem>
      <para>
-      The handle of a database connection in which the large object
+      The handle of a connection to the database in which the large object
       exists.
      </para>
     </listitem>
     <term><parameter>conn</parameter></term>
     <listitem>
      <para>
-      The handle of a database connection in which the large object
+      The handle of a connection to the database in which the large object
       exists.
      </para>
     </listitem>
     <term><parameter>conn</parameter></term>
     <listitem>
      <para>
-      The handle of a database connection in which to create the large
+      The handle of a connection to the database in which to create the large
       object.
      </para>
     </listitem>
     <term><parameter>conn</parameter></term>
     <listitem>
      <para>
-      The handle of a database connection in which the large object
+      The handle of a connection to the database in which the large object
       exists.
      </para>
     </listitem>
 
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.73 2003/08/04 02:40:16 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.74 2003/10/31 00:18:55 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
    buf = ckalloc(len + 1);
 
    nbytes = lo_read(conn, fd, buf, len);
-   bufObj = Tcl_NewStringObj(buf, nbytes);
 
-   if (Tcl_ObjSetVar2(interp, bufVar, NULL, bufObj,
-                      TCL_LEAVE_ERR_MSG | TCL_PARSE_PART1) == NULL)
-       rc = TCL_ERROR;
-   else
+   if (nbytes >= 0)
+   {
+       bufObj = Tcl_NewByteArrayObj(buf, nbytes);
+
+       if (Tcl_ObjSetVar2(interp, bufVar, NULL, bufObj,
+                          TCL_LEAVE_ERR_MSG | TCL_PARSE_PART1) == NULL)
+           rc = TCL_ERROR;
+   }
+
+   if (rc == TCL_OK)
        Tcl_SetObjResult(interp, Tcl_NewIntObj(nbytes));
 
    ckfree(buf);
    return rc;
-
 }
 
 #else
 
    nbytes = lo_read(conn, fd, buf, len);
 
-   Tcl_SetVar(interp, bufVar, buf, TCL_LEAVE_ERR_MSG);
+   if (nbytes >= 0)
+       Tcl_SetVar(interp, bufVar, buf, TCL_LEAVE_ERR_MSG);
+
    sprintf(interp->result, "%d", nbytes);
    ckfree(buf);
    return TCL_OK;
    if (Tcl_GetIntFromObj(interp, objv[2], &fd) != TCL_OK)
        return TCL_ERROR;
 
-   buf = Tcl_GetStringFromObj(objv[3], &nbytes);
+   buf = Tcl_GetByteArrayFromObj(objv[3], &nbytes);
 
    if (Tcl_GetIntFromObj(interp, objv[4], &len) != TCL_OK)
        return TCL_ERROR;