\xDD patch for 7.5devel

From: Jason Godden <jasongodden(at)optushome(dot)com(dot)au>
To: pgsql-hackers(at)postgresql(dot)org
Subject: \xDD patch for 7.5devel
Date: 2003-11-05 11:29:53
Message-ID: 200311052229.54012.jasongodden@optushome.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all,

This is my first patch for PostgreSQL against the 7.5devel cvs (please advise if this is the wrong place to post patches). This patch simply enables the \xDD (or \XDD) hexadecimal import in the copy command (im starting with the simple stuff first). I did notice that there may be a need to issue an error if an invalid octal or hex character is found following a \ or \x. No errors are currently flagged by the octal (or this hex) import.

Rgds,

Jason

cvs server: Diffing .
Index: copy.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/commands/copy.c,v
retrieving revision 1.213
diff -u -r1.213 copy.c
--- copy.c 6 Oct 2003 02:38:53 -0000 1.213
+++ copy.c 5 Nov 2003 11:19:33 -0000
@@ -48,9 +48,10 @@
#include "utils/lsyscache.h"
#include "utils/syscache.h"

-
#define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
#define OCTVALUE(c) ((c) - '0')
+#define ISHEX(c) ((((c)>='0') && ((c)<='9')) || (((c)>='A') && ((c)<='F')) || (((c)>='a') && ((c)<='f')))
+#define HEXVALUE(c) (((c)>='a') ? ((c)-87) : (((c)>='A') ? ((c)-55) : ((c)-'0')))

/*
* Represents the different source/dest cases we need to worry about at
@@ -1947,6 +1948,33 @@
c = line_buf.data[line_buf.cursor++];
switch (c)
{
+ case 'x':
+ case 'X':
+ {
+ if (line_buf.cursor < line_buf.len)
+ {
+ int hexval = 0;
+
+ c = line_buf.data[line_buf.cursor];
+ if (ISHEX(c))
+ {
+ line_buf.cursor++;
+ hexval = HEXVALUE(c);
+ if (line_buf.cursor < line_buf.len)
+ {
+ c = line_buf.data[line_buf.cursor];
+ line_buf.cursor++;
+ if (ISHEX(c))
+ {
+ line_buf.cursor++;
+ hexval = (hexval << 4) + HEXVALUE(c);
+ }
+ }
+ }
+ c = hexval;
+ }
+ }
+ break;
case '0':
case '1':
case '2':

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andreas Pflug 2003-11-05 11:30:14 Re: Open Sourcing pgManage
Previous Message Alexey Mahotkin 2003-11-05 09:41:33 Re: UPPER()/LOWER() and UTF-8