mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Add bytea datatype to ECPG.
So far ECPG programs had to treat binary data for bytea column as 'char' type. But this meant converting from/to escaped format with PQunescapeBytea/ PQescapeBytea() and therefore forcing users to add unnecessary code and cost for the conversion in runtime. By adding a dedicated datatype for bytea most of this special handling is no longer needed. Author: Matsumura-san ("Matsumura, Ryo" <matsumura.ryo@jp.fujitsu.com>) Discussion: https://postgr.es/m/flat/03040DFF97E6E54E88D3BFEE5F5480F737A141F9@G01JPEXMBYT04
This commit is contained in:
@ -917,7 +917,7 @@ do
|
||||
|
||||
<row>
|
||||
<entry><type>character(<replaceable>n</replaceable>)</type>, <type>varchar(<replaceable>n</replaceable>)</type>, <type>text</type></entry>
|
||||
<entry><type>char[<replaceable>n</replaceable>+1]</type>, <type>VARCHAR[<replaceable>n</replaceable>+1]</type><footnote><para>declared in <filename>ecpglib.h</filename></para></footnote></entry>
|
||||
<entry><type>char[<replaceable>n</replaceable>+1]</type>, <type>VARCHAR[<replaceable>n</replaceable>+1]</type></entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
@ -947,7 +947,7 @@ do
|
||||
|
||||
<row>
|
||||
<entry><type>bytea</type></entry>
|
||||
<entry><type>char *</type></entry>
|
||||
<entry><type>char *</type>, <type>bytea[<replaceable>n</replaceable>]</type></entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
@ -1204,6 +1204,36 @@ EXEC SQL END DECLARE SECTION;
|
||||
</programlisting>
|
||||
</para>
|
||||
</sect4>
|
||||
|
||||
<sect4>
|
||||
<title id="ecpg-type-bytea">bytea</title>
|
||||
|
||||
<para>
|
||||
The handling of the <type>bytea</type> type is also similar to
|
||||
the <type>VARCHAR</type>. The definition on an array of type
|
||||
<type>bytea</type> is converted into a named struct for every
|
||||
variable. A declaration like:
|
||||
<programlisting>
|
||||
bytea var[180];
|
||||
</programlisting>
|
||||
is converted into:
|
||||
<programlisting>
|
||||
struct bytea_var { int len; char arr[180]; } var;
|
||||
</programlisting>
|
||||
The member <structfield>arr</structfield> hosts binary format
|
||||
data. It also can handle even <literal>'\0'</literal> as part of
|
||||
data unlike <type>VARCHAR</type>.
|
||||
The data is converted from/to hex format and sent/received by
|
||||
ecpglib.
|
||||
</para>
|
||||
|
||||
<note>
|
||||
<para>
|
||||
<type>bytea</type> variable can be used only when
|
||||
<xref linkend="guc-bytea-output"/> is set to <literal>hex</literal>.
|
||||
</para>
|
||||
</note>
|
||||
</sect4>
|
||||
</sect3>
|
||||
|
||||
<sect3 id="ecpg-variables-nonprimitive-c">
|
||||
|
Reference in New Issue
Block a user