Commit ede9b68e authored by Tom Lane's avatar Tom Lane

Use Tcl ByteArray objects to avoid unwanted character set translation

in libpgtcl's lo_read/lo_write commands.  Also, deal correctly with
failure return from lo_read().  ljb and Tom Lane.
parent e84487f6
<!-- <!--
$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"> <chapter id="pgtcl">
...@@ -1217,7 +1217,7 @@ pg_lo_creat <parameter>conn</parameter> <parameter>mode</parameter> ...@@ -1217,7 +1217,7 @@ pg_lo_creat <parameter>conn</parameter> <parameter>mode</parameter>
<term><parameter>conn</parameter></term> <term><parameter>conn</parameter></term>
<listitem> <listitem>
<para> <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. object.
</para> </para>
</listitem> </listitem>
...@@ -1284,8 +1284,8 @@ pg_lo_open <parameter>conn</parameter> <parameter>loid</parameter> <parameter>mo ...@@ -1284,8 +1284,8 @@ pg_lo_open <parameter>conn</parameter> <parameter>loid</parameter> <parameter>mo
<listitem> <listitem>
<para> <para>
The handle of a database connection in which the large object to The handle of a connection to the database in which the large object
be opened exists. exists.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1354,7 +1354,7 @@ pg_lo_close <parameter>conn</parameter> <parameter>descriptor</parameter> ...@@ -1354,7 +1354,7 @@ pg_lo_close <parameter>conn</parameter> <parameter>descriptor</parameter>
<term><parameter>conn</parameter></term> <term><parameter>conn</parameter></term>
<listitem> <listitem>
<para> <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. exists.
</para> </para>
</listitem> </listitem>
...@@ -1417,7 +1417,7 @@ pg_lo_read <parameter>conn</parameter> <parameter>descriptor</parameter> <parame ...@@ -1417,7 +1417,7 @@ pg_lo_read <parameter>conn</parameter> <parameter>descriptor</parameter> <parame
<term><parameter>conn</parameter></term> <term><parameter>conn</parameter></term>
<listitem> <listitem>
<para> <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. exists.
</para> </para>
</listitem> </listitem>
...@@ -1458,7 +1458,9 @@ pg_lo_read <parameter>conn</parameter> <parameter>descriptor</parameter> <parame ...@@ -1458,7 +1458,9 @@ pg_lo_read <parameter>conn</parameter> <parameter>descriptor</parameter> <parame
<title>Return Value</title> <title>Return Value</title>
<para> <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> </para>
</refsect1> </refsect1>
</refentry> </refentry>
...@@ -1499,7 +1501,7 @@ pg_lo_write <parameter>conn</parameter> <parameter>descriptor</parameter> <param ...@@ -1499,7 +1501,7 @@ pg_lo_write <parameter>conn</parameter> <parameter>descriptor</parameter> <param
<term><parameter>conn</parameter></term> <term><parameter>conn</parameter></term>
<listitem> <listitem>
<para> <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. exists.
</para> </para>
</listitem> </listitem>
...@@ -1519,7 +1521,8 @@ pg_lo_write <parameter>conn</parameter> <parameter>descriptor</parameter> <param ...@@ -1519,7 +1521,8 @@ pg_lo_write <parameter>conn</parameter> <parameter>descriptor</parameter> <param
<term><parameter>buf</parameter></term> <term><parameter>buf</parameter></term>
<listitem> <listitem>
<para> <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> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1528,7 +1531,8 @@ pg_lo_write <parameter>conn</parameter> <parameter>descriptor</parameter> <param ...@@ -1528,7 +1531,8 @@ pg_lo_write <parameter>conn</parameter> <parameter>descriptor</parameter> <param
<term><parameter>len</parameter></term> <term><parameter>len</parameter></term>
<listitem> <listitem>
<para> <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> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1539,7 +1543,9 @@ pg_lo_write <parameter>conn</parameter> <parameter>descriptor</parameter> <param ...@@ -1539,7 +1543,9 @@ pg_lo_write <parameter>conn</parameter> <parameter>descriptor</parameter> <param
<title>Return Value</title> <title>Return Value</title>
<para> <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> </para>
</refsect1> </refsect1>
</refentry> </refentry>
...@@ -1580,7 +1586,7 @@ pg_lo_lseek <parameter>conn</parameter> <parameter>descriptor</parameter> <param ...@@ -1580,7 +1586,7 @@ pg_lo_lseek <parameter>conn</parameter> <parameter>descriptor</parameter> <param
<term><parameter>conn</parameter></term> <term><parameter>conn</parameter></term>
<listitem> <listitem>
<para> <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. exists.
</para> </para>
</listitem> </listitem>
...@@ -1664,7 +1670,7 @@ pg_lo_tell <parameter>conn</parameter> <parameter>descriptor</parameter> ...@@ -1664,7 +1670,7 @@ pg_lo_tell <parameter>conn</parameter> <parameter>descriptor</parameter>
<listitem> <listitem>
<para> <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. exists.
</para> </para>
</listitem> </listitem>
...@@ -1727,7 +1733,7 @@ pg_lo_unlink <parameter>conn</parameter> <parameter>loid</parameter> ...@@ -1727,7 +1733,7 @@ pg_lo_unlink <parameter>conn</parameter> <parameter>loid</parameter>
<term><parameter>conn</parameter></term> <term><parameter>conn</parameter></term>
<listitem> <listitem>
<para> <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. exists.
</para> </para>
</listitem> </listitem>
...@@ -1788,7 +1794,7 @@ pg_lo_import <parameter>conn</parameter> <parameter>filename</parameter> ...@@ -1788,7 +1794,7 @@ pg_lo_import <parameter>conn</parameter> <parameter>filename</parameter>
<term><parameter>conn</parameter></term> <term><parameter>conn</parameter></term>
<listitem> <listitem>
<para> <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. object.
</para> </para>
</listitem> </listitem>
...@@ -1858,7 +1864,7 @@ pg_lo_export <parameter>conn</parameter> <parameter>loid</parameter> <parameter> ...@@ -1858,7 +1864,7 @@ pg_lo_export <parameter>conn</parameter> <parameter>loid</parameter> <parameter>
<term><parameter>conn</parameter></term> <term><parameter>conn</parameter></term>
<listitem> <listitem>
<para> <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. exists.
</para> </para>
</listitem> </listitem>
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1215,17 +1215,21 @@ Pg_lo_read(ClientData cData, Tcl_Interp *interp, int objc, ...@@ -1215,17 +1215,21 @@ Pg_lo_read(ClientData cData, Tcl_Interp *interp, int objc,
buf = ckalloc(len + 1); buf = ckalloc(len + 1);
nbytes = lo_read(conn, fd, buf, len); nbytes = lo_read(conn, fd, buf, len);
bufObj = Tcl_NewStringObj(buf, nbytes);
if (nbytes >= 0)
{
bufObj = Tcl_NewByteArrayObj(buf, nbytes);
if (Tcl_ObjSetVar2(interp, bufVar, NULL, bufObj, if (Tcl_ObjSetVar2(interp, bufVar, NULL, bufObj,
TCL_LEAVE_ERR_MSG | TCL_PARSE_PART1) == NULL) TCL_LEAVE_ERR_MSG | TCL_PARSE_PART1) == NULL)
rc = TCL_ERROR; rc = TCL_ERROR;
else }
if (rc == TCL_OK)
Tcl_SetObjResult(interp, Tcl_NewIntObj(nbytes)); Tcl_SetObjResult(interp, Tcl_NewIntObj(nbytes));
ckfree(buf); ckfree(buf);
return rc; return rc;
} }
#else #else
...@@ -1265,7 +1269,9 @@ Pg_lo_read(ClientData cData, Tcl_Interp *interp, int argc, CONST84 char *argv[]) ...@@ -1265,7 +1269,9 @@ Pg_lo_read(ClientData cData, Tcl_Interp *interp, int argc, CONST84 char *argv[])
nbytes = lo_read(conn, fd, buf, len); nbytes = lo_read(conn, fd, buf, len);
if (nbytes >= 0)
Tcl_SetVar(interp, bufVar, buf, TCL_LEAVE_ERR_MSG); Tcl_SetVar(interp, bufVar, buf, TCL_LEAVE_ERR_MSG);
sprintf(interp->result, "%d", nbytes); sprintf(interp->result, "%d", nbytes);
ckfree(buf); ckfree(buf);
return TCL_OK; return TCL_OK;
...@@ -1307,7 +1313,7 @@ Pg_lo_write(ClientData cData, Tcl_Interp *interp, int objc, ...@@ -1307,7 +1313,7 @@ Pg_lo_write(ClientData cData, Tcl_Interp *interp, int objc,
if (Tcl_GetIntFromObj(interp, objv[2], &fd) != TCL_OK) if (Tcl_GetIntFromObj(interp, objv[2], &fd) != TCL_OK)
return TCL_ERROR; return TCL_ERROR;
buf = Tcl_GetStringFromObj(objv[3], &nbytes); buf = Tcl_GetByteArrayFromObj(objv[3], &nbytes);
if (Tcl_GetIntFromObj(interp, objv[4], &len) != TCL_OK) if (Tcl_GetIntFromObj(interp, objv[4], &len) != TCL_OK)
return TCL_ERROR; return TCL_ERROR;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment