mirror of
https://github.com/postgres/postgres.git
synced 2025-04-25 21:42:33 +03:00
Add support for \x hex escapes in COPY.
Sergey Ten
This commit is contained in:
parent
b6e5c4ad0a
commit
202e6e73e6
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$PostgreSQL: pgsql/doc/src/sgml/ref/copy.sgml,v 1.65 2005/05/07 02:22:45 momjian Exp $
|
$PostgreSQL: pgsql/doc/src/sgml/ref/copy.sgml,v 1.66 2005/06/02 01:21:21 momjian Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -424,13 +424,18 @@ COPY <replaceable class="parameter">tablename</replaceable> [ ( <replaceable cla
|
|||||||
<entry>Backslash followed by one to three octal digits specifies
|
<entry>Backslash followed by one to three octal digits specifies
|
||||||
the character with that numeric code</entry>
|
the character with that numeric code</entry>
|
||||||
</row>
|
</row>
|
||||||
|
<row>
|
||||||
|
<entry><literal>\x</><replaceable>digits</></entry>
|
||||||
|
<entry>Backslash <literal>x</> followed by one or two hex digits specifies
|
||||||
|
the character with that numeric code</entry>
|
||||||
|
</row>
|
||||||
</tbody>
|
</tbody>
|
||||||
</tgroup>
|
</tgroup>
|
||||||
</informaltable>
|
</informaltable>
|
||||||
|
|
||||||
Presently, <command>COPY TO</command> will never emit an octal-digits
|
Presently, <command>COPY TO</command> will never emit an octal or
|
||||||
backslash sequence, but it does use the other sequences listed above
|
hex-digits backslash sequence, but it does use the other sequences
|
||||||
for those control characters.
|
listed above for those control characters.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.244 2005/05/07 02:22:46 momjian Exp $
|
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.245 2005/06/02 01:21:22 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -2274,6 +2274,18 @@ CopyReadLine(char * quote, char * escape)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return decimal value for a hexadecimal digit
|
||||||
|
*/
|
||||||
|
static
|
||||||
|
int GetDecimalFromHex(char hex)
|
||||||
|
{
|
||||||
|
if (isdigit(hex))
|
||||||
|
return hex - '0';
|
||||||
|
else
|
||||||
|
return tolower(hex) - 'a' + 10;
|
||||||
|
}
|
||||||
|
|
||||||
/*----------
|
/*----------
|
||||||
* Read the value of a single attribute, performing de-escaping as needed.
|
* Read the value of a single attribute, performing de-escaping as needed.
|
||||||
*
|
*
|
||||||
@ -2335,6 +2347,7 @@ CopyReadAttribute(const char *delim, const char *null_print,
|
|||||||
case '5':
|
case '5':
|
||||||
case '6':
|
case '6':
|
||||||
case '7':
|
case '7':
|
||||||
|
/* handle \013 */
|
||||||
{
|
{
|
||||||
int val;
|
int val;
|
||||||
|
|
||||||
@ -2360,6 +2373,30 @@ CopyReadAttribute(const char *delim, const char *null_print,
|
|||||||
c = val & 0377;
|
c = val & 0377;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'x':
|
||||||
|
/* Handle \x3F */
|
||||||
|
if (line_buf.cursor < line_buf.len)
|
||||||
|
{
|
||||||
|
char hexchar = line_buf.data[line_buf.cursor];
|
||||||
|
|
||||||
|
if (isxdigit(hexchar))
|
||||||
|
{
|
||||||
|
int val = GetDecimalFromHex(hexchar);
|
||||||
|
|
||||||
|
line_buf.cursor++;
|
||||||
|
if (line_buf.cursor < line_buf.len)
|
||||||
|
{
|
||||||
|
hexchar = line_buf.data[line_buf.cursor];
|
||||||
|
if (isxdigit(hexchar))
|
||||||
|
{
|
||||||
|
line_buf.cursor++;
|
||||||
|
val = (val << 4) + GetDecimalFromHex(hexchar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c = val & 0xff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
c = '\b';
|
c = '\b';
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user