aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/copy.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2000-12-27 23:59:14 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2000-12-27 23:59:14 +0000
commit8609d4abf248f0eede4ed9505226da3f7e3e7c84 (patch)
tree39e5a813099835056d76dd385478069d01a8dcbf /src/backend/commands/copy.c
parent97799fc4757fd2699e0238254875994253659582 (diff)
downloadpostgresql-8609d4abf248f0eede4ed9505226da3f7e3e7c84.tar.gz
postgresql-8609d4abf248f0eede4ed9505226da3f7e3e7c84.zip
Fix portability problems recently exposed by regression tests on Alphas.
1. Distinguish cases where a Datum representing a tuple datatype is an OID from cases where it is a pointer to TupleTableSlot, and make sure we use the right typlen in each case. 2. Make fetchatt() and related code support 8-byte by-value datatypes on machines where Datum is 8 bytes. Centralize knowledge of the available by-value datatype sizes in two macros in tupmacs.h, so that this will be easier if we ever have to do it again.
Diffstat (limited to 'src/backend/commands/copy.c')
-rw-r--r--src/backend/commands/copy.c62
1 files changed, 7 insertions, 55 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 6cdba327295..f9507342d6d 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.125 2000/12/02 20:49:24 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.126 2000/12/27 23:59:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -49,7 +49,6 @@ static void CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim,
static void CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim, char *null_print);
static Oid GetInputFunction(Oid type);
static Oid GetTypeElement(Oid type);
-static bool IsTypeByVal(Oid type);
static void CopyReadNewline(FILE *fp, int *newline);
static char *CopyReadAttribute(FILE *fp, bool *isnull, char *delim, int *newline, char *null_print);
static void CopyAttributeOut(FILE *fp, char *string, char *delim);
@@ -586,7 +585,6 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp,
Oid in_func_oid;
Datum *values;
char *nulls;
- bool *byval;
bool isnull;
int done = 0;
char *string = NULL,
@@ -653,13 +651,9 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp,
values = (Datum *) palloc(attr_count * sizeof(Datum));
nulls = (char *) palloc(attr_count * sizeof(char));
- byval = (bool *) palloc(attr_count * sizeof(bool));
for (i = 0; i < attr_count; i++)
- {
nulls[i] = ' ';
- byval[i] = IsTypeByVal(attr[i]->atttypid);
- }
lineno = 0;
fe_eof = false;
@@ -742,36 +736,11 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp,
for (i = 0; i < attr_count; i++)
{
- if (byval[i] && nulls[i] != 'n')
- {
-
- switch (attr[i]->attlen)
- {
- case sizeof(char):
- values[i] = (Datum) *(unsigned char *) ptr;
- ptr += sizeof(char);
- break;
- case sizeof(short):
- ptr = (char *) SHORTALIGN(ptr);
- values[i] = (Datum) *(unsigned short *) ptr;
- ptr += sizeof(short);
- break;
- case sizeof(int32):
- ptr = (char *) INTALIGN(ptr);
- values[i] = (Datum) *(uint32 *) ptr;
- ptr += sizeof(int32);
- break;
- default:
- elog(ERROR, "COPY BINARY: impossible size");
- break;
- }
- }
- else if (nulls[i] != 'n')
- {
- ptr = (char *) att_align(ptr, attr[i]->attlen, attr[i]->attalign);
- values[i] = (Datum) ptr;
- ptr = att_addlength(ptr, attr[i]->attlen, ptr);
- }
+ if (nulls[i] == 'n')
+ continue;
+ ptr = (char *) att_align((long) ptr, attr[i]->attlen, attr[i]->attalign);
+ values[i] = fetchatt(attr[i], ptr);
+ ptr = att_addlength(ptr, attr[i]->attlen, ptr);
}
}
}
@@ -832,7 +801,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp,
for (i = 0; i < attr_count; i++)
{
- if (!byval[i] && nulls[i] != 'n')
+ if (!attr[i]->attbyval && nulls[i] != 'n')
{
if (!binary)
pfree((void *) values[i]);
@@ -855,7 +824,6 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp,
pfree(values);
pfree(nulls);
- pfree(byval);
if (!binary)
{
@@ -902,22 +870,6 @@ GetTypeElement(Oid type)
return result;
}
-static bool
-IsTypeByVal(Oid type)
-{
- HeapTuple typeTuple;
- bool result;
-
- typeTuple = SearchSysCache(TYPEOID,
- ObjectIdGetDatum(type),
- 0, 0, 0);
- if (!HeapTupleIsValid(typeTuple))
- elog(ERROR, "IsTypeByVal: Cache lookup of type %u failed", type);
- result = ((Form_pg_type) GETSTRUCT(typeTuple))->typbyval;
- ReleaseSysCache(typeTuple);
- return result;
-}
-
/*
* Reads input from fp until an end of line is seen.