aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc G. Fournier <scrappy@hub.org>1998-06-19 11:40:46 +0000
committerMarc G. Fournier <scrappy@hub.org>1998-06-19 11:40:46 +0000
commit5fdefbc7ef5884d19573e758c1a7c9200a42022a (patch)
tree841379a2213643a34dceb432de158d779da27ff3
parent7a7770e682e11ef61cf51246930ba79dfb5014eb (diff)
downloadpostgresql-5fdefbc7ef5884d19573e758c1a7c9200a42022a.tar.gz
postgresql-5fdefbc7ef5884d19573e758c1a7c9200a42022a.zip
From: t-ishii@sra.co.jp
As mentioned around line 1153 in backend/commands/copy.c, the method of array checking is not perfect. test=> create table t1 (i text); test=> insert into t1 values('{\\.}'); INSERT 2645600 1 test=> select * from t1; i ----- {\\.} (2 rows) test=> copy t1 to '/tmp/aaa'; test=> copy t1 from '/tmp/aaa'; ERROR: CopyReadAttribute - end of record marker corrupted Copy cannot read data produced by itself!
-rw-r--r--src/backend/commands/copy.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index dc6de2bb776..86ae89f0e70 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -6,7 +6,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.46 1998/06/15 19:28:13 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.47 1998/06/19 11:40:46 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -61,7 +61,7 @@ static char *CopyReadAttribute(FILE *fp, bool *isnull, char *delim, int *newline
static char *CopyReadAttribute(FILE *fp, bool *isnull, char *delim);
#endif
-static void CopyAttributeOut(FILE *fp, char *string, char *delim);
+static void CopyAttributeOut(FILE *fp, char *string, char *delim, int is_array);
static int CountTuples(Relation relation);
extern FILE *Pfout,
@@ -277,7 +277,7 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
{
string = (char *) (*fmgr_faddr(&out_functions[i]))
(value, elements[i], typmod[i]);
- CopyAttributeOut(fp, string, delim);
+ CopyAttributeOut(fp, string, delim, attr[i]->attnelems);
pfree(string);
}
else
@@ -554,7 +554,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
{
loaded_oid = oidin(string);
if (loaded_oid < BootstrapObjectIdData)
- elog(ERROR, "COPY TEXT: Invalid Oid");
+ elog(ERROR, "COPY TEXT: Invalid Oid. line: %d", lineno);
}
}
for (i = 0; i < attr_count && !done; i++)
@@ -603,7 +603,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
{
fread(&loaded_oid, sizeof(int32), 1, fp);
if (loaded_oid < BootstrapObjectIdData)
- elog(ERROR, "COPY BINARY: Invalid Oid");
+ elog(ERROR, "COPY BINARY: Invalid Oid line: %d", lineno);
}
fread(&null_ct, sizeof(int32), 1, fp);
if (null_ct > 0)
@@ -642,7 +642,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
ptr += sizeof(int32);
break;
default:
- elog(ERROR, "COPY BINARY: impossible size!");
+ elog(ERROR, "COPY BINARY: impossible size! line: %d", lineno);
break;
}
}
@@ -1099,7 +1099,7 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim)
case '.':
c = getc(fp);
if (c != '\n')
- elog(ERROR, "CopyReadAttribute - end of record marker corrupted");
+ elog(ERROR, "CopyReadAttribute - end of record marker corrupted. line: %d", lineno);
return (NULL);
break;
}
@@ -1115,22 +1115,16 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim)
if (!done)
attribute[i++] = c;
if (i == EXT_ATTLEN - 1)
- elog(ERROR, "CopyReadAttribute - attribute length too long");
+ elog(ERROR, "CopyReadAttribute - attribute length too long. line: %d", lineno);
}
attribute[i] = '\0';
return (&attribute[0]);
}
static void
-CopyAttributeOut(FILE *fp, char *string, char *delim)
+CopyAttributeOut(FILE *fp, char *string, char *delim, int is_array)
{
char c;
- int is_array = false;
- int len = strlen(string);
-
- /* XXX - This is a kludge, we should check the data type */
- if (len && (string[0] == '{') && (string[len - 1] == '}'))
- is_array = true;
for (; (c = *string) != '\0'; string++)
{