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

Commit07c8d9f

Browse files
committed
COPY_PATCH...
Submitted by: Massimo Dal Zotto <dz@cs.unitn.it>
1 parentdc97a7b commit07c8d9f

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

‎src/backend/commands/copy.c

Lines changed: 76 additions & 1 deletion
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.18 1996/12/14 04:58:20 vadim Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.19 1996/12/19 04:58:24 scrappy Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -49,12 +49,21 @@ static Oid IsTypeByVal(Oid type);
4949
staticvoidGetIndexRelations(Oidmain_relation_oid,
5050
int*n_indices,
5151
Relation**index_rels);
52+
#ifdefCOPY_PATCH
53+
staticvoidCopyReadNewline(FILE*fp,int*newline);
54+
staticchar*CopyReadAttribute(FILE*fp,bool*isnull,char*delim,int*newline);
55+
#else
5256
staticchar*CopyReadAttribute(FILE*fp,bool*isnull,char*delim);
57+
#endif
5358
staticvoidCopyAttributeOut(FILE*fp,char*string,char*delim);
5459
staticintCountTuples(Relationrelation);
5560

5661
externFILE*Pfout,*Pfin;
5762

63+
#ifdefCOPY_DEBUG
64+
staticintlineno;
65+
#endif
66+
5867
/*
5968
* DoCopy executes a the SQL COPY statement.
6069
*/
@@ -433,10 +442,24 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
433442
byval[i]= (bool)IsTypeByVal(attr[i]->atttypid);
434443
}
435444

445+
#ifdefCOPY_DEBUG
446+
lineno=0;
447+
#endif
436448
while (!done) {
437449
if (!binary) {
450+
#ifdefCOPY_PATCH
451+
intnewline=0;
452+
#endif
453+
#ifdefCOPY_DEBUG
454+
lineno++;
455+
elog(DEBUG,"line %d",lineno);
456+
#endif
438457
if (oids) {
458+
#ifdefCOPY_PATCH
459+
string=CopyReadAttribute(fp,&isnull,delim,&newline);
460+
#else
439461
string=CopyReadAttribute(fp,&isnull,delim);
462+
#endif
440463
if (string==NULL)
441464
done=1;
442465
else {
@@ -446,7 +469,11 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
446469
}
447470
}
448471
for (i=0;i<attr_count&& !done;i++) {
472+
#ifdefCOPY_PATCH
473+
string=CopyReadAttribute(fp,&isnull,delim,&newline);
474+
#else
449475
string=CopyReadAttribute(fp,&isnull,delim);
476+
#endif
450477
if (isnull) {
451478
values[i]=PointerGetDatum(NULL);
452479
nulls[i]='n';
@@ -463,10 +490,20 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
463490
*/
464491
if (!PointerIsValid(values[i])&&
465492
!(rel->rd_att->attrs[i]->attbyval)) {
493+
#ifdefCOPY_DEBUG
494+
elog(WARN,
495+
"copy from: line %d - Bad file format",lineno);
496+
#else
466497
elog(WARN,"copy from: Bad file format");
498+
#endif
467499
}
468500
}
469501
}
502+
#ifdefCOPY_PATCH
503+
if (!done) {
504+
CopyReadNewline(fp,&newline);
505+
}
506+
#endif
470507
}else {/* binary */
471508
fread(&len,sizeof(int32),1,fp);
472509
if (feof(fp)) {
@@ -773,6 +810,27 @@ inString(char c, char* s)
773810
return0;
774811
}
775812

813+
#ifdefCOPY_PATCH
814+
/*
815+
* Reads input from fp until an end of line is seen.
816+
*/
817+
818+
void
819+
CopyReadNewline(FILE*fp,int*newline)
820+
{
821+
if (!*newline) {
822+
#ifdefCOPY_DEBUG
823+
elog(NOTICE,"CopyReadNewline: line %d - extra fields ignored",
824+
lineno);
825+
#else
826+
elog(NOTICE,"CopyReadNewline: line - extra fields ignored");
827+
#endif
828+
while (!feof(fp)&& (getc(fp)!='\n'));
829+
}
830+
*newline=0;
831+
}
832+
#endif
833+
776834
/*
777835
* Reads input from fp until eof is seen. If we are reading from standard
778836
* input, AND we see a dot on a line by itself (a dot followed immediately
@@ -781,13 +839,25 @@ inString(char c, char* s)
781839
*/
782840

783841
staticchar*
842+
#ifdefCOPY_PATCH
843+
CopyReadAttribute(FILE*fp,bool*isnull,char*delim,int*newline)
844+
#else
784845
CopyReadAttribute(FILE*fp,bool*isnull,char*delim)
846+
#endif
785847
{
786848
staticcharattribute[EXT_ATTLEN];
787849
charc;
788850
intdone=0;
789851
inti=0;
790852

853+
#ifdefCOPY_PATCH
854+
/* if last delimiter was a newline return a NULL attribute */
855+
if (*newline) {
856+
*isnull= (bool) true;
857+
return(NULL);
858+
}
859+
#endif
860+
791861
*isnull= (bool) false;/* set default */
792862
if (feof(fp))
793863
return(NULL);
@@ -861,6 +931,11 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim)
861931
break;
862932
}
863933
}elseif (inString(c,delim)||c=='\n') {
934+
#ifdefCOPY_PATCH
935+
if (c=='\n') {
936+
*newline=1;
937+
}
938+
#endif
864939
done=1;
865940
}
866941
if (!done)attribute[i++]=c;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp