提交 c65ea0e0 编写于 作者: B Bruce Momjian

New pg_attribute.atttypmod for type-specific information like

varchar length.

Cleans up code so attlen is always length.

Removed varchar() hack added earlier.

Will fix bug in selecting varchar() fields, and varchar() can be
variable length.
上级 d7427e48
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.31 1998/01/07 21:00:45 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.32 1998/01/16 23:19:16 momjian Exp $
*
* NOTES
* some of the executor utility code such as "ExecTypeFromTL" should be
......@@ -301,11 +301,12 @@ TupleDescInitEntry(TupleDesc desc,
att->attdisbursion = 0; /* dummy value */
att->attcacheoff = -1;
att->atttypmod = 0;
att->attnum = attributeNumber;
att->attnelems = attdim;
att->attisset = attisset;
att->attnotnull = false;
att->atthasdef = false;
......@@ -512,17 +513,7 @@ BuildDescForRelation(List *schema, char *relname)
typename);
}
/*
* this is for char() and varchar(). When an entry is of type
* char() or varchar(), typlen is set to the appropriate length,
* which we'll use here instead. (The catalog lookup only returns
* the length of bpchar and varchar which is not what we want!) -
* ay 6/95
*/
if (entry->typename->typlen > 0)
{
desc->attrs[attnum - 1]->attlen = entry->typename->typlen;
}
desc->attrs[attnum - 1]->atttypmod = entry->typename->typmod;
/* This is for constraints */
if (entry->is_not_null)
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.12 1998/01/06 19:42:26 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.13 1998/01/16 23:19:23 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -190,16 +190,9 @@ fillatt(TupleDesc tupleDesc)
* and byval, since those were already set in
* TupleDescInitEntry. In fact, this seems redundant here,
* but who knows what I'll break if I take it out...
*
* same for char() and varchar() stuff. I share the same
* sentiments. This function is poorly written anyway. -ay
* 6/95
*/
if (!(*attributeP)->attisset &&
(*attributeP)->atttypid != BPCHAROID &&
(*attributeP)->atttypid != VARCHAROID)
if (!(*attributeP)->attisset)
{
typp = (TypeTupleForm) GETSTRUCT(tuple); /* XXX */
(*attributeP)->attlen = typp->typlen;
(*attributeP)->attbyval = typp->typbyval;
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.35 1998/01/15 19:42:27 pgsql Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.36 1998/01/16 23:19:27 momjian Exp $
*
*
* INTERFACE ROUTINES
......@@ -107,6 +107,7 @@ DefaultBuild(Relation heapRelation, Relation indexRelation,
* AttrNumber attnum;
* uint32 attnelems;
* int32 attcacheoff;
* int16 atttypmod;
* bool attbyval;
* bool attisset;
* char attalign;
......@@ -117,12 +118,12 @@ DefaultBuild(Relation heapRelation, Relation indexRelation,
* ----------------------------------------------------------------
*/
static FormData_pg_attribute sysatts[] = {
{0l, {"ctid"}, 27l, 0l, 6, -1, 0, -1, '\0', '\0', 'i', '\0', '\0'},
{0l, {"oid"}, 26l, 0l, 4, -2, 0, -1, '\001', '\0', 'i', '\0', '\0'},
{0l, {"xmin"}, 28l, 0l, 4, -3, 0, -1, '\0', '\0', 'i', '\0', '\0'},
{0l, {"cmin"}, 29l, 0l, 4, -4, 0, -1, '\001', '\0', 'i', '\0', '\0'},
{0l, {"xmax"}, 28l, 0l, 4, -5, 0, -1, '\0', '\0', 'i', '\0', '\0'},
{0l, {"cmax"}, 29l, 0l, 4, -6, 0, -1, '\001', '\0', 'i', '\0', '\0'},
{0l, {"ctid"}, 27l, 0l, 6, -1, 0, -1, 0, '\0', '\0', 'i', '\0', '\0'},
{0l, {"oid"}, 26l, 0l, 4, -2, 0, -1, 0, '\001', '\0', 'i', '\0', '\0'},
{0l, {"xmin"}, 28l, 0l, 4, -3, 0, -1, 0, '\0', '\0', 'i', '\0', '\0'},
{0l, {"cmin"}, 29l, 0l, 4, -4, 0, -1, 0, '\001', '\0', 'i', '\0', '\0'},
{0l, {"xmax"}, 28l, 0l, 4, -5, 0, -1, 0, '\0', '\0', 'i', '\0', '\0'},
{0l, {"cmax"}, 29l, 0l, 4, -6, 0, -1, 0, '\001', '\0', 'i', '\0', '\0'},
};
/* ----------------------------------------------------------------
......@@ -436,6 +437,7 @@ ConstructTupleDescriptor(Oid heapoid,
((AttributeTupleForm) to)->attnotnull = false;
((AttributeTupleForm) to)->atthasdef = false;
((AttributeTupleForm) to)->atttypmod = 0;
/*
* if the keytype is defined, we need to change the tuple form's
......@@ -454,11 +456,11 @@ ConstructTupleDescriptor(Oid heapoid,
((AttributeTupleForm) to)->atttypid = tup->t_oid;
((AttributeTupleForm) to)->attbyval =
((TypeTupleForm) ((char *) tup + tup->t_hoff))->typbyval;
if (IndexKeyType->typlen > 0)
((AttributeTupleForm) to)->attlen = IndexKeyType->typlen;
else
((AttributeTupleForm) to)->attlen =
((AttributeTupleForm) to)->attlen =
((TypeTupleForm) ((char *) tup + tup->t_hoff))->typlen;
((AttributeTupleForm) to)->atttypmod = IndexKeyType->typmod;
}
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.23 1998/01/05 16:38:44 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.24 1998/01/16 23:19:33 momjian Exp $
*
* NOTES
* The PortalExecutorHeapMemory crap needs to be eliminated
......@@ -482,11 +482,8 @@ PerformAddAttribute(char *relationName,
}
namestrcpy(&(attribute->attname), (char *) key[1].sk_argument);
attribute->atttypid = typeTuple->t_oid;
if (colDef->typename->typlen > 0)
attribute->attlen = colDef->typename->typlen;
else
/* bpchar, varchar, text */
attribute->attlen = form->typlen;
attribute->attlen = form->typlen;
attribute->atttypmod = colDef->typename->typmod;
attribute->attnum = i;
attribute->attbyval = form->typbyval;
attribute->attnelems = attnelems;
......
......@@ -6,7 +6,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.38 1998/01/15 19:42:36 pgsql Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.39 1998/01/16 23:19:40 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -574,7 +574,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
values[i] =
(Datum) (*fmgr_faddr(&in_functions[i])) (string,
elements[i],
attr[i]->attlen);
attr[i]->atttypmod);
/*
* Sanity check - by reference attributes cannot
......
......@@ -98,6 +98,7 @@ DefineSequence(CreateSeqStmt *seq)
typnam = makeNode(TypeName);
typnam->setof = FALSE;
typnam->arrayBounds = NULL;
typnam->typmod = 0;
coldef = makeNode(ColumnDef);
coldef->typename = typnam;
coldef->defval = NULL;
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execAmi.c,v 1.15 1998/01/16 05:03:45 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/execAmi.c,v 1.16 1998/01/16 23:19:47 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -42,7 +42,6 @@
#include "access/genam.h"
#include "access/heapam.h"
#include "catalog/heap.h"
#include "catalog/pg_type.h"
static Pointer
ExecBeginScan(Relation relation, int nkeys, ScanKey skeys,
......@@ -125,31 +124,6 @@ ExecOpenR(Oid relationOid, bool isindex)
if (relation == NULL)
elog(DEBUG, "ExecOpenR: relation == NULL, heap_open failed.");
{
int i;
Relation trel = palloc(sizeof(RelationData));
TupleDesc tdesc = palloc(sizeof(struct tupleDesc));
AttributeTupleForm *tatt =
palloc(sizeof(AttributeTupleForm*)*relation->rd_att->natts);
memcpy(trel, relation, sizeof(RelationData));
memcpy(tdesc, relation->rd_att, sizeof(struct tupleDesc));
trel->rd_att = tdesc;
tdesc->attrs = tatt;
for (i = 0; i < relation->rd_att->natts; i++)
{
if (relation->rd_att->attrs[i]->atttypid != VARCHAROID)
tdesc->attrs[i] = relation->rd_att->attrs[i];
else
{
tdesc->attrs[i] = palloc(sizeof(FormData_pg_attribute));
memcpy(tdesc->attrs[i], relation->rd_att->attrs[i],
sizeof(FormData_pg_attribute));
tdesc->attrs[i]->attlen = -1;
}
}
}
return relation;
}
......
......@@ -26,7 +26,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.38 1998/01/14 15:48:09 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.39 1998/01/16 23:19:49 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -563,13 +563,8 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
*/
tupdesc = CreateTupleDescCopy(tupType);
/* fixup to prevent zero-length columns in create */
setVarAttrLenForCreateTable(tupdesc, targetList, rangeTable);
intoRelationId = heap_create_with_catalog(intoName, tupdesc);
#ifdef NOT_USED /* it's copy ... */
resetVarAttrLenForCreateTable(tupdesc);
#endif
FreeTupleDesc(tupdesc);
/* ----------------
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.23 1998/01/07 21:02:50 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.24 1998/01/16 23:19:52 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -1177,76 +1177,3 @@ ExecInsertIndexTuples(TupleTableSlot *slot,
if (econtext != NULL)
pfree(econtext);
}
/* ----------------------------------------------------------------
* setVarAttrLenForCreateTable -
* called when we do a SELECT * INTO TABLE tab
* needed for attributes that have a defined length, like bpchar and
* varchar
* ----------------------------------------------------------------
*/
void
setVarAttrLenForCreateTable(TupleDesc tupType, List *targetList,
List *rangeTable)
{
List *tl;
TargetEntry *tle;
Node *expr;
int varno;
tl = targetList;
for (varno = 0; varno < tupType->natts; varno++)
{
tle = lfirst(tl);
if (tupType->attrs[varno]->atttypid == BPCHAROID ||
tupType->attrs[varno]->atttypid == VARCHAROID)
{
expr = tle->expr;
if (expr && IsA(expr, Var))
{
Var *var;
RangeTblEntry *rtentry;
Relation rd;
var = (Var *) expr;
rtentry = rt_fetch(var->varnoold, rangeTable);
rd = heap_open(rtentry->relid);
/* set length to that defined in relation */
tupType->attrs[varno]->attlen =
(*rd->rd_att->attrs[var->varoattno - 1]).attlen;
heap_close(rd);
}
else
elog(ERROR, "setVarAttrLenForCreateTable: can't get length for variable-length field");
}
tl = lnext(tl);
}
}
#ifdef NOT_USED /* look at execMain.c */
/* ----------------------------------------------------------------
* resetVarAttrLenForCreateTable -
* called when we do a SELECT * INTO TABLE tab
* needed for attributes that have a defined length, like bpchar and
* varchar
* resets length to -1 for those types
* ----------------------------------------------------------------
*/
void
resetVarAttrLenForCreateTable(TupleDesc tupType)
{
int varno;
for (varno = 0; varno < tupType->natts; varno++)
{
if (tupType->attrs[varno]->atttypid == BPCHAROID ||
tupType->attrs[varno]->atttypid == VARCHAROID)
/* set length to original -1 */
tupType->attrs[varno]->attlen = -1;
}
}
#endif
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.30 1998/01/15 18:59:20 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.31 1998/01/16 23:19:56 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -1480,8 +1480,8 @@ _copyTypeName(TypeName *from)
newnode->name = pstrdup(from->name);
newnode->timezone = from->timezone;
newnode->setof = from->setof;
newnode->typmod = from->typmod;
Node_Copy(from, newnode, arrayBounds);
newnode->typlen = from->typlen;
return newnode;
}
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.21 1998/01/15 18:59:26 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.22 1998/01/16 23:19:59 momjian Exp $
*
* NOTES
* Every (plan) node in POSTGRES has an associated "out" routine which
......@@ -137,11 +137,11 @@ _outTypeName(StringInfo str, TypeName *node)
appendStringInfo(str, (node->timezone ? "true" : "false"));
appendStringInfo(str, " :setof ");
appendStringInfo(str, (node->setof ? "true" : "false"));
appendStringInfo(str, " :typmod ");
sprintf(buf," %d ", node->typmod);
appendStringInfo(str, buf);
appendStringInfo(str, " :arrayBounds ");
_outNode(str, node->arrayBounds);
appendStringInfo(str, " :typlen ");
sprintf(buf," %d ", node->typlen);
appendStringInfo(str, buf);
}
static void
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.6 1997/11/25 22:00:06 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.7 1998/01/16 23:20:09 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -278,13 +278,9 @@ new_relation_targetlist(Oid relid, Index rt_index, NodeTag node_type)
*/
attisset = get_attisset( /* type_id, */ relid, attname);
if (attisset)
{
typlen = typeLen(typeidType(OIDOID));
}
else
{
typlen = get_typlen(atttype);
}
switch (node_type)
{
......
......@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.90 1998/01/11 20:01:59 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 1.91 1998/01/16 23:20:14 momjian Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
......@@ -2754,7 +2754,7 @@ Character: character '(' Iconst ')'
* between this and "text" is that we blank-pad and
* truncate where necessary
*/
$$->typlen = VARHDRSZ + $3;
$$->typmod = VARHDRSZ + $3;
}
| character
{
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.6 1998/01/05 03:32:27 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.7 1998/01/16 23:20:18 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -30,7 +30,7 @@
#include "parser/parse_target.h"
#include "utils/builtins.h"
static Node *parser_typecast(Value *expr, TypeName *typename, int typlen);
static Node *parser_typecast(Value *expr, TypeName *typename, int atttypmod);
/*
* transformExpr -
......@@ -403,7 +403,7 @@ handleNestedDots(ParseState *pstate, Attr *attr, int *curr_resno, int precedence
}
static Node *
parser_typecast(Value *expr, TypeName *typename, int typlen)
parser_typecast(Value *expr, TypeName *typename, int atttypmod)
{
/* check for passing non-ints */
Const *adt;
......@@ -492,7 +492,7 @@ parser_typecast(Value *expr, TypeName *typename, int typlen)
}
#endif
cp = stringTypeString(tp, const_string, typlen);
cp = stringTypeString(tp, const_string, atttypmod);
if (!typeByVal(tp))
{
......@@ -540,7 +540,7 @@ parser_typecast(Value *expr, TypeName *typename, int typlen)
}
Node *
parser_typecast2(Node *expr, Oid exprType, Type tp, int typlen)
parser_typecast2(Node *expr, Oid exprType, Type tp, int atttypmod)
{
/* check for passing non-ints */
Const *adt;
......@@ -627,8 +627,7 @@ parser_typecast2(Node *expr, Oid exprType, Type tp, int typlen)
return ((Node *) adt);
}
cp = stringTypeString(tp, const_string, typlen);
cp = stringTypeString(tp, const_string, atttypmod);
if (!typeByVal(tp))
{
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.6 1998/01/15 20:54:28 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.7 1998/01/16 23:20:20 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -401,9 +401,9 @@ unary_oper_get_candidates(char *op,
*candidates = NULL;
fmgr_info(NameEqualRegProcedure, (func_ptr *) &opKey[0].sk_func);
fmgr_info(NameEqualRegProcedure, (FmgrInfo *) &opKey[0].sk_func);
opKey[0].sk_argument = NameGetDatum(op);
fmgr_info(CharacterEqualRegProcedure, (func_ptr *) &opKey[1].sk_func);
fmgr_info(CharacterEqualRegProcedure, (FmgrInfo *) &opKey[1].sk_func);
opKey[1].sk_argument = CharGetDatum(rightleft);
/* currently, only "unknown" can be coerced */
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.5 1998/01/05 03:32:30 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.6 1998/01/16 23:20:21 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -430,10 +430,15 @@ checkTargetTypes(ParseState *pstate, char *target_colname,
elog(ERROR, "Type of %s does not match target column %s",
colname, target_colname);
if ((attrtype_id == BPCHAROID || attrtype_id == VARCHAROID) &&
rd->rd_att->attrs[resdomno_id - 1]->attlen !=
pstate->p_target_relation->rd_att->attrs[resdomno_target - 1]->attlen)
elog(ERROR, "Length of %s does not match length of target column %s",
if (attrtype_id == BPCHAROID &&
rd->rd_att->attrs[resdomno_id - 1]->atttypmod !=
pstate->p_target_relation->rd_att->attrs[resdomno_target - 1]->atttypmod)
elog(ERROR, "Length of %s is longer than length of target column %s",
colname, target_colname);
if (attrtype_id == VARCHAROID &&
rd->rd_att->attrs[resdomno_id - 1]->atttypmod >
pstate->p_target_relation->rd_att->attrs[resdomno_target - 1]->atttypmod)
elog(ERROR, "Length of %s is longer than length of target column %s",
colname, target_colname);
heap_close(rd);
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.5 1998/01/05 03:32:31 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.6 1998/01/16 23:20:22 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -326,7 +326,8 @@ make_targetlist_expr(ParseState *pstate,
Oid type_id,
attrtype;
int type_len,
attrlen;
attrlen,
attrtypmod;
int resdomno;
Relation rd;
bool attrisset;
......@@ -360,14 +361,8 @@ make_targetlist_expr(ParseState *pstate,
attrtype = attnumTypeId(rd, resdomno);
if ((arrayRef != NIL) && (lfirst(arrayRef) == NIL))
attrtype = GetArrayElementType(attrtype);
if (attrtype == BPCHAROID || attrtype == VARCHAROID)
{
attrlen = rd->rd_att->attrs[resdomno - 1]->attlen;
}
else
{
attrlen = typeLen(typeidType(attrtype));
}
attrlen = typeLen(typeidType(attrtype));
attrtypmod = rd->rd_att->attrs[resdomno - 1]->atttypmod;
#if 0
if (Input_is_string && Typecast_ok)
{
......@@ -438,13 +433,13 @@ make_targetlist_expr(ParseState *pstate,
expr = (Node *) parser_typecast2(expr,
type_id,
typeidType(typelem),
attrlen);
attrtypmod);
}
else
expr = (Node *) parser_typecast2(expr,
type_id,
typeidType(attrtype),
attrlen);
attrtypmod);
}
else
{
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.3 1998/01/05 03:32:33 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.4 1998/01/16 23:20:23 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -136,15 +136,14 @@ typeTypeFlag(Type t)
/* Given a type structure and a string, returns the internal form of
that string */
char *
stringTypeString(Type tp, char *string, int typlen)
stringTypeString(Type tp, char *string, int atttypmod)
{
Oid op;
Oid typelem;
op = ((TypeTupleForm) GETSTRUCT(tp))->typinput;
typelem = ((TypeTupleForm) GETSTRUCT(tp))->typelem; /* XXX - used for array_in */
/* typlen is for bpcharin() and varcharin() */
return ((char *) fmgr(op, string, typelem, typlen));
return ((char *) fmgr(op, string, typelem, atttypmod));
}
/* Given a type id, returns the out-conversion function of the type */
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.23 1998/01/08 06:18:18 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.24 1998/01/16 23:20:34 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -50,7 +50,7 @@
* because we pass typelem as the second argument for array_in.)
*/
char *
bpcharin(char *s, int dummy, int typlen)
bpcharin(char *s, int dummy, int atttypmod)
{
char *result,
*r;
......@@ -60,23 +60,23 @@ bpcharin(char *s, int dummy, int typlen)
if (s == NULL)
return ((char *) NULL);
if (typlen == -1)
if (atttypmod == -1)
{
/*
* this is here because some functions can't supply the typlen
* this is here because some functions can't supply the atttypmod
*/
len = strlen(s);
typlen = len + VARHDRSZ;
atttypmod = len + VARHDRSZ;
}
else
len = typlen - VARHDRSZ;
len = atttypmod - VARHDRSZ;
if (len > 4096)
elog(ERROR, "bpcharin: length of char() must be less than 4096");
result = (char *) palloc(typlen);
VARSIZE(result) = typlen;
result = (char *) palloc(atttypmod);
VARSIZE(result) = atttypmod;
r = VARDATA(result);
for (i = 0; i < len; i++, r++, s++)
{
......@@ -124,7 +124,7 @@ bpcharout(char *s)
* because we pass typelem as the second argument for array_in.)
*/
char *
varcharin(char *s, int dummy, int typlen)
varcharin(char *s, int dummy, int atttypmod)
{
char *result;
int len;
......@@ -133,8 +133,8 @@ varcharin(char *s, int dummy, int typlen)
return ((char *) NULL);
len = strlen(s) + VARHDRSZ;
if (typlen != -1 && len > typlen)
len = typlen; /* clip the string at max length */
if (atttypmod != -1 && len > atttypmod)
len = atttypmod; /* clip the string at max length */
if (len > 4096)
elog(ERROR, "varcharin: length of char() must be less than 4096");
......
......@@ -21,7 +21,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.59 1997/12/26 08:45:27 vadim Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.60 1998/01/16 23:20:39 momjian Exp $
*
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
*
......@@ -924,8 +924,8 @@ clearTableInfo(TableInfo *tblinfo, int numTables)
if (tblinfo[i].typnames[j])
free(tblinfo[i].typnames[j]);
}
if (tblinfo[i].attlen)
free((int *) tblinfo[i].attlen);
if (tblinfo[i].atttypmod)
free((int *) tblinfo[i].atttypmod);
if (tblinfo[i].inhAttrs)
free((int *) tblinfo[i].inhAttrs);
if (tblinfo[i].attnames)
......@@ -1613,7 +1613,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
char q[MAXQUERYLEN];
int i_attname;
int i_typname;
int i_attlen;
int i_atttypmod;
int i_attnotnull;
int i_atthasdef;
PGresult *res;
......@@ -1638,7 +1638,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
tblinfo[i].relname,
g_comment_end);
sprintf(q, "SELECT a.attnum, a.attname, t.typname, a.attlen, "
sprintf(q, "SELECT a.attnum, a.attname, t.typname, a.atttypmod, "
"a.attnotnull, a.atthasdef "
"from pg_attribute a, pg_type t "
"where a.attrelid = '%s'::oid and a.atttypid = t.oid "
......@@ -1656,14 +1656,14 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
i_attname = PQfnumber(res, "attname");
i_typname = PQfnumber(res, "typname");
i_attlen = PQfnumber(res, "attlen");
i_atttypmod = PQfnumber(res, "atttypmod");
i_attnotnull = PQfnumber(res, "attnotnull");
i_atthasdef = PQfnumber(res, "atthasdef");
tblinfo[i].numatts = ntups;
tblinfo[i].attnames = (char **) malloc(ntups * sizeof(char *));
tblinfo[i].typnames = (char **) malloc(ntups * sizeof(char *));
tblinfo[i].attlen = (int *) malloc(ntups * sizeof(int));
tblinfo[i].atttypmod = (int *) malloc(ntups * sizeof(int));
tblinfo[i].inhAttrs = (int *) malloc(ntups * sizeof(int));
tblinfo[i].notnull = (bool *) malloc(ntups * sizeof(bool));
tblinfo[i].adef_expr = (char **) malloc(ntups * sizeof(char *));
......@@ -1673,9 +1673,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
{
tblinfo[i].attnames[j] = strdup(PQgetvalue(res, j, i_attname));
tblinfo[i].typnames[j] = strdup(PQgetvalue(res, j, i_typname));
tblinfo[i].attlen[j] = atoi(PQgetvalue(res, j, i_attlen));
if (tblinfo[i].attlen[j] > 0)
tblinfo[i].attlen[j] = tblinfo[i].attlen[j] - VARHDRSZ;
tblinfo[i].atttypmod[j] = atoi(PQgetvalue(res, j, i_atttypmod));
tblinfo[i].inhAttrs[j] = 0; /* this flag is set in
* flagInhAttrs() */
tblinfo[i].notnull[j] = (PQgetvalue(res, j, i_attnotnull)[0] == 't') ? true : false;
......@@ -2321,11 +2319,9 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
(actual_atts > 0) ? ", " : "",
fmtId(tblinfo[i].attnames[j]));
/* stored length can be -1 (variable) */
if (tblinfo[i].attlen[j] > 0)
sprintf(q, "%s(%d)",
q,
tblinfo[i].attlen[j]);
sprintf(q, "%s(%d)",
q,
tblinfo[i].atttypmod[j]-VARHDRSZ);
actual_atts++;
}
else if (!strcmp(tblinfo[i].typnames[j], "varchar"))
......@@ -2336,11 +2332,9 @@ dumpTables(FILE *fout, TableInfo *tblinfo, int numTables,
fmtId(tblinfo[i].attnames[j]),
tblinfo[i].typnames[j]);
/* stored length can be -1 (variable) */
if (tblinfo[i].attlen[j] > 0)
sprintf(q, "%s(%d)",
q,
tblinfo[i].attlen[j]);
sprintf(q, "%s(%d)",
q,
tblinfo[i].atttypmod[j]-VARHDRSZ);
actual_atts++;
}
else
......
......@@ -5,7 +5,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: pg_dump.h,v 1.28 1997/12/04 01:31:28 scrappy Exp $
* $Id: pg_dump.h,v 1.29 1998/01/16 23:20:43 momjian Exp $
*
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
*
......@@ -86,7 +86,7 @@ typedef struct _tableInfo
* needed because the SQL tables will not
* have the same order of attributes as
* the POSTQUEL tables */
int *attlen; /* attribute lengths */
int *atttypmod; /* type-specific type modifier */
char *usename;
int ncheck; /* # of CHECK expressions */
char **check_expr; /* [CONSTRAINT name] CHECK expressions */
......
此差异已折叠。
......@@ -7,7 +7,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: pg_class.h,v 1.17 1997/12/04 00:27:50 scrappy Exp $
* $Id: pg_class.h,v 1.18 1998/01/16 23:20:52 momjian Exp $
*
* NOTES
* ``pg_relation'' is being replaced by ``pg_class''. currently
......@@ -119,11 +119,11 @@ typedef FormData_pg_class *Form_pg_class;
DATA(insert OID = 1247 ( pg_type 71 PGUID 0 0 0 f f r 16 0 0 f _null_ ));
DESCR("");
DATA(insert OID = 1249 ( pg_attribute 75 PGUID 0 0 0 f f r 16 0 0 f _null_ ));
DATA(insert OID = 1249 ( pg_attribute 75 PGUID 0 0 0 f f r 14 0 0 f _null_ ));
DESCR("");
DATA(insert OID = 1255 ( pg_proc 81 PGUID 0 0 0 f f r 16 0 0 f _null_ ));
DESCR("");
DATA(insert OID = 1259 ( pg_class 83 PGUID 0 0 0 f f r 18 0 0 f _null_ ));
DATA(insert OID = 1259 ( pg_class 83 PGUID 0 0 0 f f r 14 0 0 f _null_ ));
DESCR("");
DATA(insert OID = 1260 ( pg_user 86 PGUID 0 0 0 f t r 8 0 0 f _null_ ));
DESCR("");
......
......@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: parsenodes.h,v 1.44 1998/01/15 19:00:11 momjian Exp $
* $Id: parsenodes.h,v 1.45 1998/01/16 23:20:55 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -642,8 +642,8 @@ typedef struct TypeName
char *name; /* name of the type */
bool timezone; /* timezone specified? */
bool setof; /* is a set? */
int2 typmod; /* type modifier */
List *arrayBounds; /* array bounds */
int typlen; /* length for char() and varchar() */
} TypeName;
/*
......
......@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: parse_expr.h,v 1.4 1998/01/04 04:31:41 momjian Exp $
* $Id: parse_expr.h,v 1.5 1998/01/16 23:21:01 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -23,7 +23,7 @@ extern Node *transformIdent(ParseState *pstate, Node *expr, int precedence);
extern Oid exprType(Node *expr);
extern Node *handleNestedDots(ParseState *pstate, Attr *attr,
int *curr_resno, int precedence);
extern Node *parser_typecast2(Node *expr, Oid exprType, Type tp, int typlen);
extern Node *parser_typecast2(Node *expr, Oid exprType, Type tp, int attypmod);
#endif /* PARSE_EXPR_H */
......@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: parse_type.h,v 1.2 1997/11/26 01:14:14 momjian Exp $
* $Id: parse_type.h,v 1.3 1998/01/16 23:21:03 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -26,7 +26,7 @@ extern int16 typeLen(Type t);
extern bool typeByVal(Type t);
extern char *typeTypeName(Type t);
extern char typeTypeFlag(Type t);
extern char *stringTypeString(Type tp, char *string, int typlen);
extern char *stringTypeString(Type tp, char *string, int atttypmod);
extern Oid typeidRetoutfunc(Oid type_id);
extern Oid typeidTypeRelid(Oid type_id);
extern Oid typeTypeRelid(Type typ);
......
......@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: builtins.h,v 1.33 1998/01/01 05:42:40 thomas Exp $
* $Id: builtins.h,v 1.34 1998/01/16 23:21:07 momjian Exp $
*
* NOTES
* This should normally only be included by fmgr.h.
......@@ -445,7 +445,7 @@ DateTime *timestamp_datetime(time_t timestamp);
time_t datetime_timestamp(DateTime *datetime);
/* varchar.c */
extern char *bpcharin(char *s, int dummy, int typlen);
extern char *bpcharin(char *s, int dummy, int atttypmod);
extern char *bpcharout(char *s);
extern bool bpchareq(char *arg1, char *arg2);
extern bool bpcharne(char *arg1, char *arg2);
......@@ -457,7 +457,7 @@ extern int32 bpcharcmp(char *arg1, char *arg2);
extern int32 bpcharlen(char *arg);
extern uint32 hashbpchar(struct varlena * key);
extern char *varcharin(char *s, int dummy, int typlen);
extern char *varcharin(char *s, int dummy, int atttypmod);
extern char *varcharout(char *s);
extern bool varchareq(char *arg1, char *arg2);
extern bool varcharne(char *arg1, char *arg2);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册