\xDD patch for 7.5devel - Mailing list pgsql-hackers

From Jason Godden
Subject \xDD patch for 7.5devel
Date
Msg-id 200311052229.54012.jasongodden@optushome.com.au
Whole thread Raw
Responses Re: \xDD patch for 7.5devel
Re: \xDD patch for 7.5devel
List 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
simplestuff first).  I did notice that there may be a need to issue an error if an invalid octal or hex character is
foundfollowing 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':
 



pgsql-hackers by date:

Previous
From: Karel Zak
Date:
Subject: Re: UPPER()/LOWER() and UTF-8
Next
From: Andreas Pflug
Date:
Subject: Re: Open Sourcing pgManage