Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit20d44ee

Browse files
committed
Another patch that was put into 2.x and not into 1.x
From Bruce...
1 parent2f9ee44 commit20d44ee

File tree

2 files changed

+43
-57
lines changed

2 files changed

+43
-57
lines changed

‎src/backend/commands/copy.c

Lines changed: 38 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.2.2.2 1996/08/26 06:53:03 scrappy Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.2.2.3 1996/10/28 22:09:30 scrappy Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -109,7 +109,7 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, char *filena
109109
if (!pipe) {
110110
fclose(fp);
111111
}elseif (!from&& !binary) {
112-
fputs(".\n",fp);
112+
fputs("\\.\n",fp);
113113
if (IsUnderPostmaster)fflush(Pfout);
114114
}
115115
}
@@ -176,6 +176,9 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
176176
CopyAttributeOut(fp,string,delim);
177177
pfree(string);
178178
}
179+
else
180+
fputs("\\N",fp);/* null indicator */
181+
179182
if (i==attr_count-1) {
180183
fputc('\n',fp);
181184
}else {
@@ -731,40 +734,21 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim)
731734
intdone=0;
732735
inti=0;
733736

734-
if (feof(fp)) {
735-
*isnull= (bool) false;
737+
if (feof(fp))
736738
return(NULL);
737-
}
738739

739740
while (!done) {
740741
c=getc(fp);
741742

742-
if (feof(fp)) {
743-
*isnull= (bool) false;
743+
if (feof(fp))
744744
return(NULL);
745-
}elseif (reading_from_input&&i==0&&c=='.') {
746-
attribute[0]=c;
747-
c=getc(fp);
748-
if (c=='\n') {
749-
*isnull= (bool) false;
750-
return(NULL);
751-
}elseif (inString(c,delim)) {
752-
attribute[1]=0;
753-
*isnull= (bool) false;
754-
return(&attribute[0]);
755-
}else {
756-
attribute[1]=c;
757-
i=2;
758-
}
759745
}elseif (c== '\\') {
760746
c=getc(fp);
761747
#ifdefESCAPE_PATCH
762748
#defineISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
763749
#defineVALUE(c) ((c) - '0')
764-
if (feof(fp)) {
765-
*isnull= (bool) false;
750+
if (feof(fp))
766751
return(NULL);
767-
}
768752
switch (c) {
769753
case'0':
770754
case'1':
@@ -783,21 +767,17 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim)
783767
if (ISOCTAL(c)) {
784768
val= (val<<3)+VALUE(c);
785769
}else {
786-
if (feof(fp)) {
787-
*isnull= (bool) false;
770+
if (feof(fp))
788771
return(NULL);
789-
}
790772
ungetc(c,fp);
791773
}
792774
}else {
793-
if (feof(fp)) {
794-
*isnull= (bool) false;
775+
if (feof(fp))
795776
return(NULL);
796-
}
797777
ungetc(c,fp);
798778
}
799779
c=val&0377;
800-
}
780+
}
801781
break;
802782
case'b':
803783
c='\b';
@@ -817,6 +797,16 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim)
817797
case'v':
818798
c='\v';
819799
break;
800+
case'N':
801+
attribute[0]='\0';/* just to be safe */
802+
*isnull= (bool) true;
803+
break;
804+
case'.':
805+
c=getc(fp);
806+
if (c!='\n')
807+
elog(WARN,"CopyReadAttribute - end of record marker corrupted");
808+
return(NULL);
809+
break;
820810
}
821811
#endif
822812
}elseif (inString(c,delim)||c== '\n') {
@@ -827,13 +817,7 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim)
827817
elog(WARN,"CopyReadAttribute - attribute length too long");
828818
}
829819
attribute[i]='\0';
830-
if (i==0) {
831-
*isnull= (bool) true;
832-
return(NULL);
833-
}else {
834-
*isnull= (bool) false;
835-
return(&attribute[0]);
836-
}
820+
return(&attribute[0]);
837821
}
838822

839823
#ifdefESCAPE_PATCH
@@ -845,26 +829,26 @@ CopyAttributeOut(FILE *fp, char *string, char *delim)
845829
intlen=strlen(string);
846830

847831
/* XXX - This is a kludge, we should check the data type */
848-
if (len&& (string[0]=='{')&& (string[len-1]=='}')) {
832+
if (len&& (string[0]=='{')&& (string[len-1]=='}'))
849833
is_array= true;
850-
}
851834

852835
for ( ;c=*string;string++) {
853-
if ((c==delim[0])|| (c=='\n')) {
836+
if (c==delim[0]||c=='\n'||
837+
(c=='\\'&& !is_array))
854838
fputc('\\',fp);
855-
}elseif ((c=='\\')&&is_array) {
856-
if (*(string+1)=='\\') {
857-
/* translate \\ to \\\\ */
858-
fputc('\\',fp);
859-
fputc('\\',fp);
860-
fputc('\\',fp);
861-
string++;
862-
}elseif (*(string+1)=='"') {
863-
/* translate \" to \\\" */
864-
fputc('\\',fp);
865-
fputc('\\',fp);
866-
}
867-
}
839+
else
840+
if (c=='\\'&&is_array)
841+
if (*(string+1)=='\\') {
842+
/* translate \\ to \\\\ */
843+
fputc('\\',fp);
844+
fputc('\\',fp);
845+
fputc('\\',fp);
846+
string++;
847+
}elseif (*(string+1)=='"') {
848+
/* translate \" to \\\" */
849+
fputc('\\',fp);
850+
fputc('\\',fp);
851+
}
868852
fputc(*string,fp);
869853
}
870854
}

‎src/bin/pg_dump/pg_dump.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
*
2222
* IDENTIFICATION
23-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.5.2.2 1996/10/02 21:39:29 scrappy Exp $
23+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.5.2.3 1996/10/28 22:09:39 scrappy Exp $
2424
*
2525
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2626
*
@@ -1405,7 +1405,9 @@ dumpClasses(TableInfo *tblinfo, int numTables, FILE *fout, char *onlytable, int
14051405
while (!copydone) {
14061406
ret=PQgetline(res->conn,copybuf,COPYBUFSIZ);
14071407

1408-
if (copybuf[0]=='.'&&copybuf[1]=='\0') {
1408+
if (copybuf[0]=='\\'&&
1409+
copybuf[1]=='.'&&
1410+
copybuf[2]=='\0') {
14091411
copydone= true;/* don't print this... */
14101412
}else {
14111413
fputs(copybuf,fout);
@@ -1421,7 +1423,7 @@ dumpClasses(TableInfo *tblinfo, int numTables, FILE *fout, char *onlytable, int
14211423
}
14221424
}
14231425
}
1424-
fprintf(fout,".\n");
1426+
fprintf(fout,"\\.\n");
14251427
PQclear(res);
14261428
PQendcopy(res->conn);
14271429
}else {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp