Commit 8c3b52e7 authored by Tom Lane's avatar Tom Lane

Allow COPY WITH OIDS to system OID values --- rely on unique indexes to

prevent duplicate OIDs from being added.  Clean up redundant error
messages.
parent a6acf1a0
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.104 2000/04/12 17:14:58 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.105 2000/04/16 04:27:52 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -118,7 +118,7 @@ CopySendData(void *databuf, int datasize, FILE *fp) ...@@ -118,7 +118,7 @@ CopySendData(void *databuf, int datasize, FILE *fp)
{ {
fwrite(databuf, datasize, 1, fp); fwrite(databuf, datasize, 1, fp);
if (ferror(fp)) if (ferror(fp))
elog(ERROR, "CopySendData: %s", strerror(errno)); elog(ERROR, "CopySendData: %m");
} }
} }
...@@ -350,18 +350,19 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, ...@@ -350,18 +350,19 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
{ {
mode_t oumask; /* Pre-existing umask value */ mode_t oumask; /* Pre-existing umask value */
oumask = umask((mode_t) 022);
if (*filename != '/') if (*filename != '/')
elog(ERROR, "Relative path not allowed for server side" elog(ERROR, "Relative path not allowed for server side"
" COPY command."); " COPY command.");
oumask = umask((mode_t) 022);
#ifndef __CYGWIN32__ #ifndef __CYGWIN32__
fp = AllocateFile(filename, "w"); fp = AllocateFile(filename, "w");
#else #else
fp = AllocateFile(filename, "wb"); fp = AllocateFile(filename, "wb");
#endif #endif
umask(oumask); umask(oumask);
if (fp == NULL) if (fp == NULL)
elog(ERROR, "COPY command, running in backend with " elog(ERROR, "COPY command, running in backend with "
"effective uid %d, could not open file '%s' for " "effective uid %d, could not open file '%s' for "
...@@ -626,7 +627,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null ...@@ -626,7 +627,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null
int n_indices; int n_indices;
InsertIndexResult indexRes; InsertIndexResult indexRes;
TupleDesc tupDesc; TupleDesc tupDesc;
Oid loaded_oid; Oid loaded_oid = InvalidOid;
bool skip_tuple = false; bool skip_tuple = false;
tupDesc = RelationGetDescr(rel); tupDesc = RelationGetDescr(rel);
...@@ -775,11 +776,12 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null ...@@ -775,11 +776,12 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null
CancelQuery(); CancelQuery();
} }
lineno++;
if (!binary) if (!binary)
{ {
int newline = 0; int newline = 0;
lineno++;
if (oids) if (oids)
{ {
string = CopyReadAttribute(fp, &isnull, delim, &newline, null_print); string = CopyReadAttribute(fp, &isnull, delim, &newline, null_print);
...@@ -788,8 +790,8 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null ...@@ -788,8 +790,8 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null
else else
{ {
loaded_oid = oidin(string); loaded_oid = oidin(string);
if (loaded_oid < BootstrapObjectIdData) if (loaded_oid == InvalidOid)
elog(ERROR, "COPY TEXT: Invalid Oid. line: %d", lineno); elog(ERROR, "COPY TEXT: Invalid Oid");
} }
} }
for (i = 0; i < attr_count && !done; i++) for (i = 0; i < attr_count && !done; i++)
...@@ -822,7 +824,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null ...@@ -822,7 +824,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null
*/ */
if (!PointerIsValid(values[i]) && if (!PointerIsValid(values[i]) &&
!(rel->rd_att->attrs[i]->attbyval)) !(rel->rd_att->attrs[i]->attbyval))
elog(ERROR, "copy from line %d: Bad file format", lineno); elog(ERROR, "COPY: Bad file format");
} }
} }
if (!done) if (!done)
...@@ -838,8 +840,8 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null ...@@ -838,8 +840,8 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null
if (oids) if (oids)
{ {
CopyGetData(&loaded_oid, sizeof(int32), fp); CopyGetData(&loaded_oid, sizeof(int32), fp);
if (loaded_oid < BootstrapObjectIdData) if (loaded_oid == InvalidOid)
elog(ERROR, "COPY BINARY: Invalid Oid line: %d", lineno); elog(ERROR, "COPY BINARY: Invalid Oid");
} }
CopyGetData(&null_ct, sizeof(int32), fp); CopyGetData(&null_ct, sizeof(int32), fp);
if (null_ct > 0) if (null_ct > 0)
...@@ -878,7 +880,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null ...@@ -878,7 +880,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null
ptr += sizeof(int32); ptr += sizeof(int32);
break; break;
default: default:
elog(ERROR, "COPY BINARY: impossible size! line: %d", lineno); elog(ERROR, "COPY BINARY: impossible size");
break; break;
} }
} }
...@@ -1044,7 +1046,7 @@ GetTypeElement(Oid type) ...@@ -1044,7 +1046,7 @@ GetTypeElement(Oid type)
if (HeapTupleIsValid(typeTuple)) if (HeapTupleIsValid(typeTuple))
return (int) ((Form_pg_type) GETSTRUCT(typeTuple))->typelem; return (int) ((Form_pg_type) GETSTRUCT(typeTuple))->typelem;
elog(ERROR, "GetOutputFunction: Cache lookup of type %d failed", type); elog(ERROR, "GetOutputFunction: Cache lookup of type %u failed", type);
return InvalidOid; return InvalidOid;
} }
...@@ -1172,7 +1174,7 @@ CopyReadNewline(FILE *fp, int *newline) ...@@ -1172,7 +1174,7 @@ CopyReadNewline(FILE *fp, int *newline)
{ {
if (!*newline) if (!*newline)
{ {
elog(NOTICE, "CopyReadNewline: line %d - extra fields ignored", lineno); elog(NOTICE, "CopyReadNewline: extra fields ignored");
while (!CopyGetEof(fp) && (CopyGetChar(fp) != '\n')); while (!CopyGetEof(fp) && (CopyGetChar(fp) != '\n'));
} }
*newline = 0; *newline = 0;
...@@ -1307,7 +1309,7 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim, int *newline, char *null_ ...@@ -1307,7 +1309,7 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim, int *newline, char *null_
case '.': case '.':
c = CopyGetChar(fp); c = CopyGetChar(fp);
if (c != '\n') if (c != '\n')
elog(ERROR, "CopyReadAttribute - end of record marker corrupted. line: %d", lineno); elog(ERROR, "CopyReadAttribute: end of record marker corrupted");
goto endOfFile; goto endOfFile;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment