1. Why i do
this:
I try to migrate a database with
a 200 tables from Sybase SQL Anywhere to PostgreSQL,
but SQL Anywhere escapes special
characters like a HEX values ( like \x0D \x2C ..... ).
PostgreSQL COPY FROM recognize
only OCT values ( lie \001 ... )
2. How-to it' easy :)))
2.1 - Open
$UrSourceDir/src/backend/commands/copy.c
2.2 - Add #include
<ctype.h> in te begining
2.3 find
function
static char
*
CopyReadAttribute(FILE *fp, bool *isnull, char *delim, int *newline, char
*null_print)
/*----------------*/
/*-------- Add this code before it --------*/
static int
HEXVALUE( int
c )
{
if (isdigit(c))
{
c -= '0';
}
else
{
if (islower(c))
c=
c-'a'+10;
else
c=
c-'A'+10;
}
return(c);
}
2.4 in body of CopyReadAttribute
find this
code and modify it like this
if (c == '\\')
{
c =
CopyGetChar(fp);
if (c ==
EOF)
goto
endOfFile;
switch
(c)
{
/*------ Here is my additional code ------*/
case 'x':
case 'X':
{
int val;
CopyDonePeek(fp, c, true /*pick up*/); /* Get x always
*/
c = CopyPeekChar(fp); /* Get next */
if (isxdigit(c))
{
val = HEXVALUE(c);
c = CopyPeekChar(fp);
if (isxdigit(c))
{
val = (val << 4)
+ HEXVALUE(c);
CopyDonePeek(fp, c,
true /*pick up*/);
}
else
{
if (c == EOF)
goto
endOfFile;
CopyDonePeek(fp, c,
false /*put back*/);
}
}
else
{
if (c == EOF)
goto
endOfFile;
CopyDonePeek(fp, c, false /*put
back*/);
}
c = val;
}
break;
/*------ End of my additional code ------*/
case
'0':
case
'1':
case
'2':
case
'3':
case
'4':
case
'5':
case
'6':
case
'7':
{
int val;
val = OCTVALUE(c);
2.4 he he now make , make install
....
3. An idea to developers : maybe u include this
addition to COPY in future releases
10x
P.S. Excuse me for my English ( i'm better in C
:)
|
- Re: [HACKERS] "COPY FROM" recognize \xDD sequence ... Igor Georgiev
- Re: [HACKERS] "COPY FROM" recognize \xDD sequ... Bruce Momjian
- Re: [HACKERS] "COPY FROM" recognize \xDD ... Tom Lane
- Re: [HACKERS] "COPY FROM" recognize \... Bruce Momjian
- Re: [HACKERS] "COPY FROM" recognize \... Gavin Sherry
- Re: [HACKERS] "COPY FROM" recogni... Bruce Momjian