66 *
77 *
88 * IDENTIFICATION
9- * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.1.1.1 1996/07/09 06:21:19 scrappy Exp $
9+ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.2 1996/07/23 02:23:15 scrappy Exp $
1010 *
1111 *-------------------------------------------------------------------------
1212 */
@@ -650,6 +650,10 @@ GetIndexRelations(Oid main_relation_oid,
650650heap_endscan (scandesc );
651651heap_close (pg_index_rel );
652652
653+ /* We cannot trust to relhasindex of the main_relation now, so... */
654+ if (* n_indices == 0 )
655+ return ;
656+
653657* index_rels = (Relation * )palloc (* n_indices * sizeof (Relation ));
654658
655659for (i = 0 ,scan = head ;i < * n_indices ;i ++ ,scan = scan -> next ) {
@@ -726,6 +730,67 @@ CopyReadAttribute(int attno, FILE *fp, bool *isnull, char *delim)
726730 }
727731}else if (c == '\\' ) {
728732c = getc (fp );
733+ #ifdef ESCAPE_PATCH
734+ #define ISOCTAL (c ) (((c) >= '0') && ((c) <= '7'))
735+ #define VALUE (c ) ((c) - '0')
736+ if (feof (fp )) {
737+ * isnull = (bool ) false;
738+ return (NULL );
739+ }
740+ switch (c ) {
741+ case '0' :
742+ case '1' :
743+ case '2' :
744+ case '3' :
745+ case '4' :
746+ case '5' :
747+ case '6' :
748+ case '7' : {
749+ int val ;
750+ val = VALUE (c );
751+ c = getc (fp );
752+ if (ISOCTAL (c )) {
753+ val = (val <<3 )+ VALUE (c );
754+ c = getc (fp );
755+ if (ISOCTAL (c )) {
756+ val = (val <<3 )+ VALUE (c );
757+ }else {
758+ if (feof (fp )) {
759+ * isnull = (bool ) false;
760+ return (NULL );
761+ }
762+ ungetc (c ,fp );
763+ }
764+ }else {
765+ if (feof (fp )) {
766+ * isnull = (bool ) false;
767+ return (NULL );
768+ }
769+ ungetc (c ,fp );
770+ }
771+ c = val & 0377 ;
772+ }
773+ break ;
774+ case 'b' :
775+ c = '\b' ;
776+ break ;
777+ case 'f' :
778+ c = '\f' ;
779+ break ;
780+ case 'n' :
781+ c = '\n' ;
782+ break ;
783+ case 'r' :
784+ c = '\r' ;
785+ break ;
786+ case 't' :
787+ c = '\t' ;
788+ break ;
789+ case 'v' :
790+ c = '\v' ;
791+ break ;
792+ }
793+ #endif
729794}else if (inString (c ,delim )|| c == '\n' ) {
730795done = 1 ;
731796}
@@ -743,6 +808,39 @@ CopyReadAttribute(int attno, FILE *fp, bool *isnull, char *delim)
743808 }
744809}
745810
811+ #ifdef ESCAPE_PATCH
812+ static void
813+ CopyAttributeOut (FILE * fp ,char * string ,char * delim )
814+ {
815+ char c ;
816+ int is_array = false;
817+ int len = strlen (string );
818+
819+ /* XXX - This is a kludge, we should check the data type */
820+ if (len && (string [0 ]== '{' )&& (string [len - 1 ]== '}' )) {
821+ is_array = true;
822+ }
823+
824+ for ( ;c = * string ;string ++ ) {
825+ if ((c == delim [0 ])|| (c == '\n' )) {
826+ fputc ('\\' ,fp );
827+ }else if ((c == '\\' )&& is_array ) {
828+ if (* (string + 1 )== '\\' ) {
829+ /* translate \\ to \\\\ */
830+ fputc ('\\' ,fp );
831+ fputc ('\\' ,fp );
832+ fputc ('\\' ,fp );
833+ string ++ ;
834+ }else if (* (string + 1 )== '"' ) {
835+ /* translate \" to \\\" */
836+ fputc ('\\' ,fp );
837+ fputc ('\\' ,fp );
838+ }
839+ }
840+ fputc (* string ,fp );
841+ }
842+ }
843+ #else
746844static void
747845CopyAttributeOut (FILE * fp ,char * string ,char * delim )
748846{
@@ -756,6 +854,7 @@ CopyAttributeOut(FILE *fp, char *string, char *delim)
756854fputc (string [i ],fp );
757855 }
758856}
857+ #endif
759858
760859/*
761860 * Returns the number of tuples in a relation. Unfortunately, currently