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

Commit4644fc8

Browse files
committed
Eliminate query length limitation imposed by pg_client_to_server
and pg_server_to_client. Eliminate copy.c's restriction on the lengthof a single attribute.
1 parentb65ab31 commit4644fc8

File tree

4 files changed

+137
-162
lines changed

4 files changed

+137
-162
lines changed

‎src/backend/commands/copy.c

Lines changed: 65 additions & 109 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.86 1999/07/22 02:40:06 tgl Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.87 1999/09/11 22:28:11 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -26,6 +26,7 @@
2626
#include"commands/copy.h"
2727
#include"commands/trigger.h"
2828
#include"executor/executor.h"
29+
#include"lib/stringinfo.h"
2930
#include"libpq/libpq.h"
3031
#include"miscadmin.h"
3132
#include"utils/acl.h"
@@ -51,14 +52,10 @@ static void GetIndexRelations(Oid main_relation_oid,
5152
int*n_indices,
5253
Relation**index_rels);
5354

54-
#ifdefCOPY_PATCH
5555
staticvoidCopyReadNewline(FILE*fp,int*newline);
5656
staticchar*CopyReadAttribute(FILE*fp,bool*isnull,char*delim,int*newline);
57-
#else
58-
staticchar*CopyReadAttribute(FILE*fp,bool*isnull,char*delim);
59-
#endif
6057

61-
staticvoidCopyAttributeOut(FILE*fp,char*string,char*delim,intis_array);
58+
staticvoidCopyAttributeOut(FILE*fp,char*string,char*delim);
6259
staticintCountTuples(Relationrelation);
6360

6461
/*
@@ -431,7 +428,7 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
431428
{
432429
string= (char*) (*fmgr_faddr(&out_functions[i]))
433430
(value,elements[i],typmod[i]);
434-
CopyAttributeOut(fp,string,delim,attr[i]->attnelems);
431+
CopyAttributeOut(fp,string,delim);
435432
pfree(string);
436433
}
437434
else
@@ -691,38 +688,31 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
691688
{
692689
if (!binary)
693690
{
694-
#ifdefCOPY_PATCH
695691
intnewline=0;
696692

697-
#endif
698693
lineno++;
699694
if (oids)
700695
{
701-
#ifdefCOPY_PATCH
702696
string=CopyReadAttribute(fp,&isnull,delim,&newline);
703-
#else
704-
string=CopyReadAttribute(fp,&isnull,delim);
705-
#endif
706697
if (string==NULL)
707698
done=1;
708699
else
709700
{
710701
loaded_oid=oidin(string);
711702
if (loaded_oid<BootstrapObjectIdData)
712703
elog(ERROR,"COPY TEXT: Invalid Oid. line: %d",lineno);
704+
pfree(string);
713705
}
714706
}
715707
for (i=0;i<attr_count&& !done;i++)
716708
{
717-
#ifdefCOPY_PATCH
718709
string=CopyReadAttribute(fp,&isnull,delim,&newline);
719-
#else
720-
string=CopyReadAttribute(fp,&isnull,delim);
721-
#endif
722710
if (isnull)
723711
{
724712
values[i]=PointerGetDatum(NULL);
725713
nulls[i]='n';
714+
if (string)
715+
pfree(string);
726716
}
727717
elseif (string==NULL)
728718
done=1;
@@ -739,12 +729,11 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
739729
if (!PointerIsValid(values[i])&&
740730
!(rel->rd_att->attrs[i]->attbyval))
741731
elog(ERROR,"copy from line %d: Bad file format",lineno);
732+
pfree(string);
742733
}
743734
}
744-
#ifdefCOPY_PATCH
745735
if (!done)
746736
CopyReadNewline(fp,&newline);
747-
#endif
748737
}
749738
else
750739
{/* binary */
@@ -812,11 +801,6 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
812801
if (done)
813802
continue;
814803

815-
/*
816-
* Does it have any sence ? - vadim 12/14/96
817-
*
818-
* tupDesc = CreateTupleDesc(attr_count, attr);
819-
*/
820804
tuple=heap_formtuple(tupDesc,values,nulls);
821805
if (oids)
822806
tuple->t_data->t_oid=loaded_oid;
@@ -1086,30 +1070,18 @@ GetIndexRelations(Oid main_relation_oid,
10861070
}
10871071
}
10881072

1089-
#defineEXT_ATTLEN(5 * BLCKSZ)
10901073

10911074
/*
1092-
returns 1is c is in s
1075+
returns 1if c is in s
10931076
*/
10941077
staticbool
10951078
inString(charc,char*s)
10961079
{
1097-
inti;
1098-
1099-
if (s)
1100-
{
1101-
i=0;
1102-
while (s[i]!='\0')
1103-
{
1104-
if (s[i]==c)
1105-
return1;
1106-
i++;
1107-
}
1108-
}
1080+
if (s&&c)
1081+
returnstrchr(s,c)!=NULL;
11091082
return0;
11101083
}
11111084

1112-
#ifdefCOPY_PATCH
11131085
/*
11141086
* Reads input from fp until an end of line is seen.
11151087
*/
@@ -1125,64 +1097,57 @@ CopyReadNewline(FILE *fp, int *newline)
11251097
*newline=0;
11261098
}
11271099

1128-
#endif
1129-
11301100
/*
1131-
* Reads input from fp until eof is seen. If we are reading from standard
1132-
* input, AND we see a dot on a line by itself (a dot followed immediately
1133-
* by a newline), we exit as if we saw eof. This is so that copy pipelines
1134-
* can be used as standard input.
1101+
* Read the value of a single attribute.
1102+
*
1103+
* Result is either a palloc'd string, or NULL (if EOF or a null attribute).
1104+
* *isnull is set true if a null attribute, else false.
1105+
*
1106+
* delim is the string of acceptable delimiter characters(s).
1107+
* *newline remembers whether we've seen a newline ending this tuple.
11351108
*/
11361109

11371110
staticchar*
1138-
#ifdefCOPY_PATCH
11391111
CopyReadAttribute(FILE*fp,bool*isnull,char*delim,int*newline)
1140-
#else
1141-
CopyReadAttribute(FILE*fp,bool*isnull,char*delim)
1142-
#endif
11431112
{
1144-
staticcharattribute[EXT_ATTLEN];
1113+
StringInfoDataattribute_buf;
11451114
charc;
1146-
intdone=0;
1147-
inti=0;
1148-
11491115
#ifdefMULTIBYTE
11501116
intmblen;
11511117
intencoding;
11521118
unsignedchars[2];
1119+
char*cvt;
11531120
intj;
11541121

1155-
#endif
1156-
1157-
#ifdefMULTIBYTE
11581122
encoding=pg_get_client_encoding();
11591123
s[1]=0;
11601124
#endif
11611125

1162-
#ifdefCOPY_PATCH
11631126
/* if last delimiter was a newline return a NULL attribute */
11641127
if (*newline)
11651128
{
11661129
*isnull= (bool) true;
11671130
returnNULL;
11681131
}
1169-
#endif
11701132

11711133
*isnull= (bool) false;/* set default */
1134+
1135+
initStringInfo(&attribute_buf);
1136+
11721137
if (CopyGetEof(fp))
1173-
returnNULL;
1138+
gotoendOfFile;
11741139

1175-
while (!done)
1140+
for (;;)
11761141
{
11771142
c=CopyGetChar(fp);
1178-
11791143
if (CopyGetEof(fp))
1180-
returnNULL;
1181-
elseif (c=='\\')
1144+
gotoendOfFile;
1145+
1146+
if (c=='\\')
11821147
{
11831148
c=CopyGetChar(fp);
11841149
if (CopyGetEof(fp))
1185-
returnNULL;
1150+
gotoendOfFile;
11861151
switch (c)
11871152
{
11881153
case'0':
@@ -1212,14 +1177,14 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim)
12121177
else
12131178
{
12141179
if (CopyGetEof(fp))
1215-
returnNULL;
1180+
gotoendOfFile;
12161181
CopyDonePeek(fp,c,0);/* Return to stream! */
12171182
}
12181183
}
12191184
else
12201185
{
12211186
if (CopyGetEof(fp))
1222-
returnNULL;
1187+
gotoendOfFile;
12231188
CopyDonePeek(fp,c,0);/* Return to stream! */
12241189
}
12251190
c=val&0377;
@@ -1244,66 +1209,70 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim)
12441209
c='\v';
12451210
break;
12461211
case'N':
1247-
attribute[0]='\0';/* just to be safe */
12481212
*isnull= (bool) true;
12491213
break;
12501214
case'.':
12511215
c=CopyGetChar(fp);
12521216
if (c!='\n')
12531217
elog(ERROR,"CopyReadAttribute - end of record marker corrupted. line: %d",lineno);
1254-
returnNULL;
1218+
gotoendOfFile;
12551219
break;
12561220
}
12571221
}
1258-
elseif (inString(c,delim)||c=='\n')
1222+
elseif (c=='\n'||inString(c,delim))
12591223
{
1260-
#ifdefCOPY_PATCH
12611224
if (c=='\n')
12621225
*newline=1;
1263-
#endif
1264-
done=1;
1226+
break;
12651227
}
1266-
if (!done)
1267-
attribute[i++]=c;
1228+
appendStringInfoChar(&attribute_buf,c);
12681229
#ifdefMULTIBYTE
1230+
/* get additional bytes of the char, if any */
12691231
s[0]=c;
12701232
mblen=pg_encoding_mblen(encoding,s);
1271-
mblen--;
1272-
for (j=0;j<mblen;j++)
1233+
for (j=1;j<mblen;j++)
12731234
{
12741235
c=CopyGetChar(fp);
12751236
if (CopyGetEof(fp))
1276-
returnNULL;
1277-
attribute[i++]=c;
1237+
gotoendOfFile;
1238+
appendStringInfoChar(&attribute_buf,c);
12781239
}
12791240
#endif
1280-
if (i==EXT_ATTLEN-1)
1281-
elog(ERROR,"CopyReadAttribute - attribute length too long. line: %d",lineno);
12821241
}
1283-
attribute[i]='\0';
1242+
12841243
#ifdefMULTIBYTE
1285-
return (pg_client_to_server((unsignedchar*)attribute,strlen(attribute)));
1286-
#else
1287-
return&attribute[0];
1244+
cvt= (char*)pg_client_to_server((unsignedchar*)attribute_buf.data,
1245+
attribute_buf.len);
1246+
if (cvt!=attribute_buf.data)
1247+
{
1248+
pfree(attribute_buf.data);
1249+
returncvt;
1250+
}
12881251
#endif
1252+
returnattribute_buf.data;
1253+
1254+
endOfFile:
1255+
pfree(attribute_buf.data);
1256+
returnNULL;
12891257
}
12901258

12911259
staticvoid
1292-
CopyAttributeOut(FILE*fp,char*server_string,char*delim,intis_array)
1260+
CopyAttributeOut(FILE*fp,char*server_string,char*delim)
12931261
{
12941262
char*string;
12951263
charc;
1296-
12971264
#ifdefMULTIBYTE
1298-
intmblen;
1265+
char*string_start;
12991266
intencoding;
1267+
intmblen;
13001268
inti;
1301-
13021269
#endif
13031270

13041271
#ifdefMULTIBYTE
1305-
string=pg_server_to_client(server_string,strlen(server_string));
13061272
encoding=pg_get_client_encoding();
1273+
string= (char*)pg_server_to_client((unsignedchar*)server_string,
1274+
strlen(server_string));
1275+
string_start=string;
13071276
#else
13081277
string=server_string;
13091278
#endif
@@ -1315,33 +1284,20 @@ CopyAttributeOut(FILE *fp, char *server_string, char *delim, int is_array)
13151284
for (; (c=*string)!='\0';string++)
13161285
#endif
13171286
{
1318-
if (c==delim[0]||c=='\n'||
1319-
(c=='\\'&& !is_array))
1287+
if (c==delim[0]||c=='\n'||c=='\\')
13201288
CopySendChar('\\',fp);
1321-
elseif (c=='\\'&&is_array)
1322-
{
1323-
if (*(string+1)=='\\')
1324-
{
1325-
/* translate \\ to \\\\ */
1326-
CopySendChar('\\',fp);
1327-
CopySendChar('\\',fp);
1328-
CopySendChar('\\',fp);
1329-
string++;
1330-
}
1331-
elseif (*(string+1)=='"')
1332-
{
1333-
/* translate \" to \\\" */
1334-
CopySendChar('\\',fp);
1335-
CopySendChar('\\',fp);
1336-
}
1337-
}
13381289
#ifdefMULTIBYTE
13391290
for (i=0;i<mblen;i++)
13401291
CopySendChar(*(string+i),fp);
13411292
#else
1342-
CopySendChar(*string,fp);
1293+
CopySendChar(c,fp);
13431294
#endif
13441295
}
1296+
1297+
#ifdefMULTIBYTE
1298+
if (string_start!=server_string)
1299+
pfree(string_start);/* pfree pg_server_to_client result */
1300+
#endif
13451301
}
13461302

13471303
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp