@ -6,7 +6,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $ Header : / cvsroot / pgsql / src / backend / commands / copy . c , v 1.2 1996 / 07 / 23 02 : 23 : 15 scrappy Exp $
* $ Header : / cvsroot / pgsql / src / backend / commands / copy . c , v 1.3 1996 / 08 / 14 05 : 33 : 04 scrappy Exp $
*
*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
*/
@ -107,7 +107,7 @@ DoCopy(char *relname, bool binary, bool from, bool pipe, char *filename,
if ( ! pipe ) {
if ( ! pipe ) {
fclose ( fp ) ;
fclose ( fp ) ;
} else if ( ! from & & ! binary ) {
} else if ( ! from & & ! binary ) {
fputs ( " . \n " , fp ) ;
fputs ( " \\ . \n " , fp ) ;
if ( IsUnderPostmaster ) fflush ( Pfout ) ;
if ( IsUnderPostmaster ) fflush ( Pfout ) ;
}
}
}
}
@ -169,6 +169,9 @@ CopyTo(Relation rel, bool binary, FILE *fp, char *delim)
CopyAttributeOut ( fp , string , delim ) ;
CopyAttributeOut ( fp , string , delim ) ;
pfree ( string ) ;
pfree ( string ) ;
}
}
else
fputs ( " \\ N " , fp ) ; /* null indicator */
if ( i = = attr_count - 1 ) {
if ( i = = attr_count - 1 ) {
fputc ( ' \n ' , fp ) ;
fputc ( ' \n ' , fp ) ;
} else {
} else {
@ -703,40 +706,22 @@ CopyReadAttribute(int attno, FILE *fp, bool *isnull, char *delim)
int done = 0 ;
int done = 0 ;
int i = 0 ;
int i = 0 ;
if ( feof ( fp ) ) {
* isnull = ( bool ) false ; /* set default */
* isnull = ( bool ) false ;
if ( feof ( fp ) )
return ( NULL ) ;
return ( NULL ) ;
}
while ( ! done ) {
while ( ! done ) {
c = getc ( fp ) ;
c = getc ( fp ) ;
if ( feof ( fp ) ) {
if ( feof ( fp ) )
* isnull = ( bool ) false ;
return ( NULL ) ;
} else if ( reading_from_input & & attno = = 0 & & i = = 0 & & c = = ' . ' ) {
attribute [ 0 ] = c ;
c = getc ( fp ) ;
if ( c = = ' \n ' ) {
* isnull = ( bool ) false ;
return ( NULL ) ;
return ( NULL ) ;
} else if ( inString ( c , delim ) ) {
else if ( c = = ' \\ ' ) {
attribute [ 1 ] = 0 ;
* isnull = ( bool ) false ;
return ( & attribute [ 0 ] ) ;
} else {
attribute [ 1 ] = c ;
i = 2 ;
}
} else if ( c = = ' \\ ' ) {
c = getc ( fp ) ;
c = getc ( fp ) ;
# ifdef ESCAPE_PATCH
# ifdef ESCAPE_PATCH
# define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
# define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
# define VALUE(c) ((c) - '0')
# define VALUE(c) ((c) - '0')
if ( feof ( fp ) ) {
if ( feof ( fp ) )
* isnull = ( bool ) false ;
return ( NULL ) ;
return ( NULL ) ;
}
switch ( c ) {
switch ( c ) {
case ' 0 ' :
case ' 0 ' :
case ' 1 ' :
case ' 1 ' :
@ -755,17 +740,13 @@ CopyReadAttribute(int attno, FILE *fp, bool *isnull, char *delim)
if ( ISOCTAL ( c ) ) {
if ( ISOCTAL ( c ) ) {
val = ( val < < 3 ) + VALUE ( c ) ;
val = ( val < < 3 ) + VALUE ( c ) ;
} else {
} else {
if ( feof ( fp ) ) {
if ( feof ( fp ) )
* isnull = ( bool ) false ;
return ( NULL ) ;
return ( NULL ) ;
}
ungetc ( c , fp ) ;
ungetc ( c , fp ) ;
}
}
} else {
} else {
if ( feof ( fp ) ) {
if ( feof ( fp ) )
* isnull = ( bool ) false ;
return ( NULL ) ;
return ( NULL ) ;
}
ungetc ( c , fp ) ;
ungetc ( c , fp ) ;
}
}
c = val & 0377 ;
c = val & 0377 ;
@ -789,6 +770,16 @@ CopyReadAttribute(int attno, FILE *fp, bool *isnull, char *delim)
case ' v ' :
case ' v ' :
c = ' \v ' ;
c = ' \v ' ;
break ;
break ;
case ' N ' :
attribute [ 0 ] = ' \0 ' ; /* just to be safe */
* isnull = ( bool ) true ;
break ;
case ' . ' :
c = getc ( fp ) ;
if ( c ! = ' \n ' )
elog ( WARN , " CopyReadAttribute - end of record marker corrupted " ) ;
return ( NULL ) ;
break ;
}
}
# endif
# endif
} else if ( inString ( c , delim ) | | c = = ' \n ' ) {
} else if ( inString ( c , delim ) | | c = = ' \n ' ) {
@ -799,14 +790,8 @@ CopyReadAttribute(int attno, FILE *fp, bool *isnull, char *delim)
elog ( WARN , " CopyReadAttribute - attribute length too long " ) ;
elog ( WARN , " CopyReadAttribute - attribute length too long " ) ;
}
}
attribute [ i ] = ' \0 ' ;
attribute [ i ] = ' \0 ' ;
if ( i = = 0 ) {
* isnull = ( bool ) true ;
return ( NULL ) ;
} else {
* isnull = ( bool ) false ;
return ( & attribute [ 0 ] ) ;
return ( & attribute [ 0 ] ) ;
}
}
}
# ifdef ESCAPE_PATCH
# ifdef ESCAPE_PATCH
static void
static void
@ -817,14 +802,15 @@ CopyAttributeOut(FILE *fp, char *string, char *delim)
int len = strlen ( string ) ;
int len = strlen ( string ) ;
/* XXX - This is a kludge, we should check the data type */
/* XXX - This is a kludge, we should check the data type */
if ( len & & ( string [ 0 ] = = ' { ' ) & & ( string [ len - 1 ] = = ' } ' ) ) {
if ( len & & ( string [ 0 ] = = ' { ' ) & & ( string [ len - 1 ] = = ' } ' ) )
is_array = true ;
is_array = true ;
}
for ( ; c = * string ; string + + ) {
for ( ; c = * string ; string + + ) {
if ( ( c = = delim [ 0 ] ) | | ( c = = ' \n ' ) ) {
if ( c = = delim [ 0 ] | | c = = ' \n ' | |
( c = = ' \\ ' & & ! is_array ) )
fputc ( ' \\ ' , fp ) ;
fputc ( ' \\ ' , fp ) ;
} else if ( ( c = = ' \\ ' ) & & is_array ) {
else
if ( c = = ' \\ ' & & is_array )
if ( * ( string + 1 ) = = ' \\ ' ) {
if ( * ( string + 1 ) = = ' \\ ' ) {
/* translate \\ to \\\\ */
/* translate \\ to \\\\ */
fputc ( ' \\ ' , fp ) ;
fputc ( ' \\ ' , fp ) ;
@ -836,7 +822,6 @@ CopyAttributeOut(FILE *fp, char *string, char *delim)
fputc ( ' \\ ' , fp ) ;
fputc ( ' \\ ' , fp ) ;
fputc ( ' \\ ' , fp ) ;
fputc ( ' \\ ' , fp ) ;
}
}
}
fputc ( * string , fp ) ;
fputc ( * string , fp ) ;
}
}
}
}