From fa5400c0a40eab95499da5a54d8a526593a1f243 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sat, 22 Jan 2000 14:20:56 +0000 Subject: [PATCH] added ALTER TABLE DROP COLUMN, early version --- src/backend/access/heap/heapam.c | 4 +- src/backend/catalog/catalog.c | 4 +- src/backend/catalog/heap.c | 6 +- src/backend/catalog/pg_type.c | 4 +- src/backend/commands/command.c | 227 +++++++++++++++++++++++++++-- src/backend/commands/rename.c | 4 +- src/backend/parser/gram.y | 6 +- src/backend/utils/adt/name.c | 24 +-- src/backend/utils/cache/relcache.c | 18 +-- src/backend/utils/cache/temprel.c | 10 +- src/bin/psql/command.c | 3 +- src/include/access/heapam.h | 4 +- src/include/catalog/heap.h | 6 +- src/include/catalog/pg_type.h | 4 +- src/include/commands/rename.h | 6 +- src/include/utils/builtins.h | 22 +-- src/include/utils/rel.h | 4 +- src/include/utils/relcache.h | 4 +- src/include/utils/temprel.h | 8 +- 19 files changed, 286 insertions(+), 82 deletions(-) diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 4b7c409622..6383a49dac 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.63 2000/01/10 06:30:50 inoue Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.64 2000/01/22 14:20:43 petere Exp $ * * * INTERFACE ROUTINES @@ -562,7 +562,7 @@ heap_open(Oid relationId, LOCKMODE lockmode) * ---------------- */ Relation -heap_openr(char *relationName, LOCKMODE lockmode) +heap_openr(const char *relationName, LOCKMODE lockmode) { Relation r; diff --git a/src/backend/catalog/catalog.c b/src/backend/catalog/catalog.c index 20256babde..d4d167739a 100644 --- a/src/backend/catalog/catalog.c +++ b/src/backend/catalog/catalog.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.28 2000/01/16 20:04:54 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.29 2000/01/22 14:20:44 petere Exp $ * *------------------------------------------------------------------------- */ @@ -38,7 +38,7 @@ relpath(const char *relname) snprintf(path, bufsize, "%s/%s", DataDir, relname); return path; } - return relname; + return pstrdup(relname); } /* diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index d61df6561b..dc578bd8c2 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.117 2000/01/17 23:57:43 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.118 2000/01/22 14:20:44 petere Exp $ * * * INTERFACE ROUTINES @@ -480,7 +480,7 @@ CheckAttributeNames(TupleDesc tupdesc) * -------------------------------- */ Oid -RelnameFindRelid(char *relname) +RelnameFindRelid(const char *relname) { HeapTuple tuple; Oid relid; @@ -1441,7 +1441,7 @@ DeleteTypeTuple(Relation rel) * -------------------------------- */ void -heap_drop_with_catalog(char *relname) +heap_drop_with_catalog(const char *relname) { Relation rel; Oid rid; diff --git a/src/backend/catalog/pg_type.c b/src/backend/catalog/pg_type.c index 3de8020595..2be9fd6836 100644 --- a/src/backend/catalog/pg_type.c +++ b/src/backend/catalog/pg_type.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.47 2000/01/17 23:57:43 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.48 2000/01/22 14:20:44 petere Exp $ * *------------------------------------------------------------------------- */ @@ -525,7 +525,7 @@ TypeCreate(char *typeName, * ---------------------------------------------------------------- */ void -TypeRename(char *oldTypeName, char *newTypeName) +TypeRename(const char *oldTypeName, const char *newTypeName) { Relation pg_type_desc; Relation idescs[Num_pg_type_indices]; diff --git a/src/backend/commands/command.c b/src/backend/commands/command.c index 93322d7a7f..5c29dd692a 100644 --- a/src/backend/commands/command.c +++ b/src/backend/commands/command.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.63 2000/01/16 20:04:55 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.64 2000/01/22 14:20:45 petere Exp $ * * NOTES * The PortalExecutorHeapMemory crap needs to be eliminated @@ -30,6 +30,7 @@ #include "catalog/pg_attrdef.h" #include "catalog/pg_type.h" #include "commands/command.h" +#include "commands/rename.h" #include "executor/execdefs.h" #include "executor/executor.h" #include "catalog/heap.h" @@ -299,7 +300,7 @@ AlterTableAddColumn(const char *relationName, Relation idescs[Num_pg_attr_indices]; Relation ridescs[Num_pg_class_indices]; bool hasindex; - List *rawDefaults = NIL; +// List *rawDefaults = NIL; /* * permissions checking. this would normally be done in utility.c, @@ -319,7 +320,7 @@ AlterTableAddColumn(const char *relationName, * Grab an exclusive lock on the target table, which we will NOT release * until end of transaction. */ - rel = heap_openr((char *)relationName, AccessExclusiveLock); + rel = heap_openr(relationName, AccessExclusiveLock); myrelid = RelationGetRelid(rel); heap_close(rel, NoLock); /* close rel but keep lock! */ @@ -519,8 +520,7 @@ AlterTableAlterColumn(const char *relationName, elog(ERROR, "ALTER TABLE: permission denied"); #endif - /* XXX should heap_openr take const char * ? */ - rel = heap_openr((char *)relationName, AccessExclusiveLock); + rel = heap_openr(relationName, AccessExclusiveLock); myrelid = RelationGetRelid(rel); heap_close(rel, NoLock); @@ -626,7 +626,7 @@ AlterTableAlterColumn(const char *relationName, /* keep the system catalog indices current */ CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, irelations); CatalogIndexInsert(irelations, Num_pg_attr_indices, attr_rel, newtuple); - CatalogCloseIndices(Num_pg_class_indices, irelations); + CatalogCloseIndices(Num_pg_attrdef_indices, irelations); /* get rid of actual default definition */ drop_default(myrelid, attnum); @@ -672,31 +672,234 @@ drop_default(Oid relid, int16 attnum) /* * ALTER TABLE DROP COLUMN + * + * Strategy: + * - permission/sanity checks + * - create a new table _ATDC with all attributes minus the desired one + * - copy over all the data + * - make the column defaults point to the new table + * - kill the old table + * - rename the intermediate table back */ void AlterTableDropColumn(const char *relationName, bool inh, const char *colName, int behavior) { - elog(NOTICE, "ALTER TABLE / DROP COLUMN is not implemented"); + Relation oldrel, newrel, defrel; + HeapTuple tuple; + TupleDesc olddesc, newdesc, defdsc; + int16 dropattnum, oldnumatts; + Oid oldrel_oid, newrel_oid; + char tmpname[NAMEDATALEN]; + int16 i; + HeapScanDesc scan; + ScanKeyData scankey; + + if (!allowSystemTableMods && IsSystemRelationName(relationName)) + elog(ERROR, "ALTER TABLE: relation \"%s\" is a system catalog", + relationName); +#ifndef NO_SECURITY + if (!pg_ownercheck(UserName, relationName, RELNAME)) + elog(ERROR, "ALTER TABLE: permission denied"); +#endif + + oldrel = heap_openr(relationName, AccessExclusiveLock); + if (oldrel->rd_rel->relkind != RELKIND_RELATION) + { + heap_close(oldrel, AccessExclusiveLock); + elog(ERROR, "ALTER TABLE: relation %s is not a table", relationName); + } + + oldrel_oid = ObjectIdGetDatum(RelationGetRelid(oldrel)); + oldnumatts = RelationGetNumberOfAttributes(oldrel); + + if (oldnumatts==1) + { + heap_close(oldrel, AccessExclusiveLock); + elog(ERROR, "ALTER TABLE: relation %s only has one column", relationName); + } + +/* What to do here? */ +/* + if (length(find_all_inheritors(RelationGetRelid(oldrel)))>0) + elog(ERROR, "ALTER TABLE: cannot drop a column on table that is inherited from"); +*/ + /* + * get the number of the attribute + */ + tuple = SearchSysCacheTuple(ATTNAME, oldrel_oid, NameGetDatum(namein(colName)), 0, 0); + if (!HeapTupleIsValid(tuple)) + { + heap_close(oldrel, AccessExclusiveLock); + elog(ERROR, "ALTER TABLE: relation \"%s\" has no column \"%s\"", + relationName, colName); + } + + dropattnum = ((Form_pg_attribute) GETSTRUCT(tuple))->attnum; + + if (snprintf(tmpname, NAMEDATALEN, "_ATDC%s", relationName)==-1) + { + heap_close(oldrel, AccessExclusiveLock); + elog(ERROR, "AlterTableDropColumn: relation name too long"); + } + + /* + * Build descriptor for new relation + */ + olddesc = RelationGetDescr(oldrel); + + newdesc = CreateTemplateTupleDesc(oldnumatts-1); + for(i = 1; i < dropattnum; i++) + { + Form_pg_attribute att = olddesc->attrs[i-1]; + TupleDescInitEntry(newdesc, i, nameout(&(att->attname)), + att->atttypid, att->atttypmod, + att->attnelems, att->attisset); + /* the above function doesn't take care of these two */ + newdesc->attrs[i-1]->attnotnull = att->attnotnull; + newdesc->attrs[i-1]->atthasdef = att->atthasdef; + } + + for(i = dropattnum; i <= oldnumatts-1; i++) + { + Form_pg_attribute att = olddesc->attrs[i]; + TupleDescInitEntry(newdesc, i, nameout(&(att->attname)), + att->atttypid, att->atttypmod, + att->attnelems, att->attisset); + /* the above function doesn't take care of these two */ + newdesc->attrs[i-1]->attnotnull = att->attnotnull; + newdesc->attrs[i-1]->atthasdef = att->atthasdef; + } + + /* Create the new table */ + newrel_oid = heap_create_with_catalog(tmpname, newdesc, RELKIND_RELATION, false); + if (newrel_oid == InvalidOid) + { + heap_close(oldrel, AccessExclusiveLock); + elog(ERROR, "ALTER TABLE: something went wrong"); + } + + /* Make the new table visible */ + CommandCounterIncrement(); + + /* + * Copy over the data + */ + newrel = heap_open(newrel_oid, AccessExclusiveLock); + + scan = heap_beginscan(oldrel, false, SnapshotNow, 0, NULL); + while (HeapTupleIsValid(tuple = heap_getnext(scan, 0))) + { + bool isnull; + Datum *new_record; + bool *new_record_nulls; + HeapTuple new_tuple; + + new_record = palloc((oldnumatts-1) * sizeof(*new_record)); + new_record_nulls = palloc((oldnumatts-1) * sizeof(*new_record_nulls)); + + for(i = 1; i < dropattnum; i++) + { + new_record[i-1] = heap_getattr(tuple, i, olddesc, &isnull); + new_record_nulls[i-1] = isnull ? 'n' : ' '; + } + for(i = dropattnum+1; i <= oldnumatts; i++) + { + new_record[i-2] = heap_getattr(tuple, i, olddesc, &isnull); + new_record_nulls[i-2] = isnull ? 'n' : ' '; + } + + new_tuple = heap_formtuple(newdesc, new_record, new_record_nulls); + Assert(new_tuple); + + if (heap_insert(newrel, new_tuple) == InvalidOid) + elog(ERROR, "AlterTableDropColumn: heap_insert failed"); + + pfree(new_record); + pfree(new_record_nulls); + } + heap_endscan(scan); + + heap_close(newrel, NoLock); + heap_close(oldrel, NoLock); + + /* + * Move defaults over to the new table + */ + defrel = heap_openr(AttrDefaultRelationName, AccessExclusiveLock); + defdsc = RelationGetDescr(defrel); + + /* look for all entries referencing the old table */ + ScanKeyEntryInitialize(&scankey, 0x0, Anum_pg_attrdef_adrelid, F_OIDEQ, + ObjectIdGetDatum(oldrel_oid)); + scan = heap_beginscan(defrel, false, SnapshotNow, 1, &scankey); + while(HeapTupleIsValid(tuple = heap_getnext(scan, false))) + { + HeapTuple newtuple; + int2 attrnum; + Relation irelations[Num_pg_attrdef_indices]; + + attrnum = ((Form_pg_attrdef) GETSTRUCT(tuple))->adnum; + + /* remove the entry about the dropped column */ + if (attrnum == dropattnum) + { + heap_delete(defrel, &tuple->t_self, NULL); + continue; + } + + newtuple = heap_copytuple(tuple); + + if (attrnum > dropattnum) + ((Form_pg_attrdef) GETSTRUCT(newtuple))->adnum--; + + /* make it point to the new table */ + ((Form_pg_attrdef) GETSTRUCT(newtuple))->adrelid = newrel_oid; + heap_update(defrel, &tuple->t_self, newtuple, NULL); + + /* keep the system catalog indices current */ + CatalogOpenIndices(Num_pg_attrdef_indices, Name_pg_attrdef_indices, irelations); + CatalogIndexInsert(irelations, Num_pg_attrdef_indices, defrel, newtuple); + CatalogCloseIndices(Num_pg_attrdef_indices, irelations); + } + heap_endscan(scan); + heap_close(defrel, NoLock); + + CommandCounterIncrement(); + + /* make the old table disappear */ + heap_drop_with_catalog(relationName); + CommandCounterIncrement(); + + /* set back original name */ + TypeRename(tmpname, relationName); + renamerel(tmpname, relationName); } +/* + * ALTER TABLE ADD CONSTRAINT + */ void AlterTableAddConstraint(const char *relationName, bool inh, Node *newConstraint) { - elog(NOTICE, "ALTER TABLE / ADD CONSTRAINT is not implemented"); + elog(ERROR, "ALTER TABLE / ADD CONSTRAINT is not implemented"); } -void AlterTableDropConstraint(const char *relationName, - bool inh, const char *constrName, - int behavior) +/* + * ALTER TABLE DROP CONSTRAINT + */ +void +AlterTableDropConstraint(const char *relationName, + bool inh, const char *constrName, + int behavior) { - elog(NOTICE, "ALTER TABLE / DROP CONSTRAINT is not implemented"); + elog(ERROR, "ALTER TABLE / DROP CONSTRAINT is not implemented"); } diff --git a/src/backend/commands/rename.c b/src/backend/commands/rename.c index 8a94597770..b6bd229a56 100644 --- a/src/backend/commands/rename.c +++ b/src/backend/commands/rename.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.39 1999/12/16 22:19:42 wieck Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.40 2000/01/22 14:20:45 petere Exp $ * *------------------------------------------------------------------------- */ @@ -172,7 +172,7 @@ renameatt(char *relname, * renamerel - change the name of a relation */ void -renamerel(char *oldrelname, char *newrelname) +renamerel(const char *oldrelname, const char *newrelname) { int i; Relation targetrelation; diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index ca22fc095f..3a673bc74b 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.132 2000/01/20 02:24:50 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.133 2000/01/22 14:20:46 petere Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT @@ -830,14 +830,14 @@ AlterTableStmt: $$ = (Node *)n; } /* ALTER TABLE DROP [COLUMN] {RESTRICT|CASCADE} */ - | ALTER TABLE relation_name opt_inh_star DROP opt_column ColId drop_behavior + | ALTER TABLE relation_name opt_inh_star DROP opt_column ColId /* drop_behavior */ { AlterTableStmt *n = makeNode(AlterTableStmt); n->subtype = 'D'; n->relname = $3; n->inh = $4; n->name = $7; - n->behavior = $8; + /* n->behavior = $8; */ $$ = (Node *)n; } /* ALTER TABLE ADD CONSTRAINT ... */ diff --git a/src/backend/utils/adt/name.c b/src/backend/utils/adt/name.c index 479d9e2539..da47dd1b34 100644 --- a/src/backend/utils/adt/name.c +++ b/src/backend/utils/adt/name.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.25 1999/11/25 19:15:20 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.26 2000/01/22 14:20:49 petere Exp $ * *------------------------------------------------------------------------- */ @@ -31,7 +31,7 @@ * Now, always NULL terminated */ NameData * -namein(char *s) +namein(const char *s) { NameData *result; int len; @@ -54,7 +54,7 @@ namein(char *s) * nameout - converts internal reprsentation to "..." */ char * -nameout(NameData *s) +nameout(const NameData *s) { if (s == NULL) return "-"; @@ -82,7 +82,7 @@ nameout(NameData *s) * */ bool -nameeq(NameData *arg1, NameData *arg2) +nameeq(const NameData *arg1, const NameData *arg2) { if (!arg1 || !arg2) return 0; @@ -91,7 +91,7 @@ nameeq(NameData *arg1, NameData *arg2) } bool -namene(NameData *arg1, NameData *arg2) +namene(const NameData *arg1, const NameData *arg2) { if (arg1 == NULL || arg2 == NULL) return (bool) 0; @@ -99,7 +99,7 @@ namene(NameData *arg1, NameData *arg2) } bool -namelt(NameData *arg1, NameData *arg2) +namelt(const NameData *arg1, const NameData *arg2) { if (arg1 == NULL || arg2 == NULL) return (bool) 0; @@ -107,7 +107,7 @@ namelt(NameData *arg1, NameData *arg2) } bool -namele(NameData *arg1, NameData *arg2) +namele(const NameData *arg1, const NameData *arg2) { if (arg1 == NULL || arg2 == NULL) return (bool) 0; @@ -115,7 +115,7 @@ namele(NameData *arg1, NameData *arg2) } bool -namegt(NameData *arg1, NameData *arg2) +namegt(const NameData *arg1, const NameData *arg2) { if (arg1 == NULL || arg2 == NULL) return (bool) 0; @@ -124,7 +124,7 @@ namegt(NameData *arg1, NameData *arg2) } bool -namege(NameData *arg1, NameData *arg2) +namege(const NameData *arg1, const NameData *arg2) { if (arg1 == NULL || arg2 == NULL) return (bool) 0; @@ -163,7 +163,7 @@ namecmp(Name n1, Name n2) #endif int -namestrcpy(Name name, char *str) +namestrcpy(Name name, const char *str) { if (!name || !str) return -1; @@ -173,7 +173,7 @@ namestrcpy(Name name, char *str) #ifdef NOT_USED int -namestrcat(Name name, char *str) +namestrcat(Name name, const char *str) { int i; char *p, @@ -195,7 +195,7 @@ namestrcat(Name name, char *str) #endif int -namestrcmp(Name name, char *str) +namestrcmp(Name name, const char *str) { if (!name && !str) return 0; diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index ed11b77325..a6b0f6ca9b 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.85 2000/01/15 02:59:39 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.86 2000/01/22 14:20:50 petere Exp $ * *------------------------------------------------------------------------- */ @@ -62,7 +62,7 @@ static void RelationClearRelation(Relation relation, bool rebuildIt); static void RelationFlushRelation(Relation *relationPtr, bool onlyFlushReferenceCountZero); -static Relation RelationNameCacheGetRelation(char *relationName); +static Relation RelationNameCacheGetRelation(const char *relationName); static void RelationCacheAbortWalker(Relation *relationPtr, int dummy); static void init_irels(void); @@ -1067,7 +1067,7 @@ RelationIdCacheGetRelation(Oid relationId) * -------------------------------- */ static Relation -RelationNameCacheGetRelation(char *relationName) +RelationNameCacheGetRelation(const char *relationName) { Relation rd; NameData name; @@ -1144,7 +1144,7 @@ RelationIdGetRelation(Oid relationId) * -------------------------------- */ Relation -RelationNameGetRelation(char *relationName) +RelationNameGetRelation(const char *relationName) { char *temprelname; Relation rd; @@ -1180,7 +1180,7 @@ RelationNameGetRelation(char *relationName) * ---------------- */ buildinfo.infotype = INFO_RELNAME; - buildinfo.i.info_name = relationName; + buildinfo.i.info_name = (char *)relationName; rd = RelationBuildDesc(buildinfo, NULL); return rd; @@ -1727,7 +1727,7 @@ AttrDefaultFetch(Relation relation) if (adform->adnum != attrdef[i].adnum) continue; if (attrdef[i].adbin != NULL) - elog(ERROR, "AttrDefaultFetch: second record found for attr %s in rel %s", + elog(NOTICE, "AttrDefaultFetch: second record found for attr %s in rel %s", NameStr(relation->rd_att->attrs[adform->adnum - 1]->attname), RelationGetRelationName(relation)); @@ -1735,7 +1735,7 @@ AttrDefaultFetch(Relation relation) Anum_pg_attrdef_adbin, adrel->rd_att, &isnull); if (isnull) - elog(ERROR, "AttrDefaultFetch: adbin IS NULL for attr %s in rel %s", + elog(NOTICE, "AttrDefaultFetch: adbin IS NULL for attr %s in rel %s", NameStr(relation->rd_att->attrs[adform->adnum - 1]->attname), RelationGetRelationName(relation)); attrdef[i].adbin = textout(val); @@ -1744,13 +1744,13 @@ AttrDefaultFetch(Relation relation) ReleaseBuffer(buffer); if (i >= ndef) - elog(ERROR, "AttrDefaultFetch: unexpected record found for attr %d in rel %s", + elog(NOTICE, "AttrDefaultFetch: unexpected record found for attr %d in rel %s", adform->adnum, RelationGetRelationName(relation)); } if (found < ndef) - elog(ERROR, "AttrDefaultFetch: %d record not found for rel %s", + elog(NOTICE, "AttrDefaultFetch: %d record not found for rel %s", ndef - found, RelationGetRelationName(relation)); index_endscan(sd); diff --git a/src/backend/utils/cache/temprel.c b/src/backend/utils/cache/temprel.c index 23ac1aadbc..88894a806e 100644 --- a/src/backend/utils/cache/temprel.c +++ b/src/backend/utils/cache/temprel.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.18 1999/12/10 03:56:00 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.19 2000/01/22 14:20:50 petere Exp $ * *------------------------------------------------------------------------- */ @@ -49,7 +49,7 @@ typedef struct TempTable void -create_temp_relation(char *relname, HeapTuple pg_class_tuple) +create_temp_relation(const char *relname, HeapTuple pg_class_tuple) { MemoryContext oldcxt; TempTable *temp_rel; @@ -202,7 +202,7 @@ invalidate_temp_relations(void) } char * -get_temp_rel_by_username(char *user_relname) +get_temp_rel_by_username(const char *user_relname) { List *l; @@ -217,7 +217,7 @@ get_temp_rel_by_username(char *user_relname) } char * -get_temp_rel_by_physicalname(char *relname) +get_temp_rel_by_physicalname(const char *relname) { List *l; @@ -229,5 +229,5 @@ get_temp_rel_by_physicalname(char *relname) return temp_rel->user_relname; } /* needed for bootstrapping temp tables */ - return relname; + return pstrdup(relname); } diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 93be3d946c..333da8cbc9 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Team * - * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.13 2000/01/18 23:30:22 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.14 2000/01/22 14:20:51 petere Exp $ */ #include #include "command.h" @@ -1217,6 +1217,7 @@ process_file(char *filename) pset.inputfile = filename; result = MainLoop(fd); fclose(fd); + pset.inputfile = NULL; return (result == EXIT_SUCCESS); } diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h index 39da155329..ad522297fd 100644 --- a/src/include/access/heapam.h +++ b/src/include/access/heapam.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: heapam.h,v 1.49 1999/12/16 22:19:58 wieck Exp $ + * $Id: heapam.h,v 1.50 2000/01/22 14:20:52 petere Exp $ * *------------------------------------------------------------------------- */ @@ -248,7 +248,7 @@ extern HeapAccessStatistics heap_access_stats; /* in stats.c */ /* heapam.c */ extern Relation heap_open(Oid relationId, LOCKMODE lockmode); -extern Relation heap_openr(char *relationName, LOCKMODE lockmode); +extern Relation heap_openr(const char *relationName, LOCKMODE lockmode); extern void heap_close(Relation relation, LOCKMODE lockmode); extern HeapScanDesc heap_beginscan(Relation relation, int atend, Snapshot snapshot, unsigned nkeys, ScanKey key); diff --git a/src/include/catalog/heap.h b/src/include/catalog/heap.h index 4370247a6b..5e8fd47ba3 100644 --- a/src/include/catalog/heap.h +++ b/src/include/catalog/heap.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: heap.h,v 1.26 1999/12/10 03:56:05 momjian Exp $ + * $Id: heap.h,v 1.27 2000/01/22 14:20:53 petere Exp $ * *------------------------------------------------------------------------- */ @@ -21,7 +21,7 @@ typedef struct RawColumnDefault Node *raw_default; /* default value (untransformed parse tree) */ } RawColumnDefault; -extern Oid RelnameFindRelid(char *relname); +extern Oid RelnameFindRelid(const char *relname); extern Relation heap_create(char *relname, TupleDesc att, bool isnoname, bool istemp, bool storage_create); extern bool heap_storage_create(Relation rel); @@ -29,7 +29,7 @@ extern bool heap_storage_create(Relation rel); extern Oid heap_create_with_catalog(char *relname, TupleDesc tupdesc, char relkind, bool istemp); -extern void heap_drop_with_catalog(char *relname); +extern void heap_drop_with_catalog(const char *relname); extern void heap_truncate(char *relname); extern void heap_drop(Relation rel); diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h index a41e577e03..0927b00757 100644 --- a/src/include/catalog/pg_type.h +++ b/src/include/catalog/pg_type.h @@ -7,7 +7,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: pg_type.h,v 1.77 2000/01/17 01:29:07 tgl Exp $ + * $Id: pg_type.h,v 1.78 2000/01/22 14:20:53 petere Exp $ * * NOTES * the genbki.sh script reads this file and generates .bki @@ -410,7 +410,7 @@ extern Oid TypeCreate(char *typeName, char *elementTypeName, char *defaultTypeValue, bool passedByValue, char alignment); -extern void TypeRename(char *oldTypeName, char *newTypeName); +extern void TypeRename(const char *oldTypeName, const char *newTypeName); extern char *makeArrayTypeName(char *typeName); diff --git a/src/include/commands/rename.h b/src/include/commands/rename.h index cf9bd41a7f..4b28bee8bd 100644 --- a/src/include/commands/rename.h +++ b/src/include/commands/rename.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: rename.h,v 1.6 1999/02/13 23:21:19 momjian Exp $ + * $Id: rename.h,v 1.7 2000/01/22 14:20:54 petere Exp $ * *------------------------------------------------------------------------- */ @@ -18,7 +18,7 @@ extern void renameatt(char *relname, char *newattname, char *userName, int recurse); -extern void renamerel(char *oldrelname, - char *newrelname); +extern void renamerel(const char *oldrelname, + const char *newrelname); #endif /* RENAME_H */ diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h index 2e8b9771a9..1be8ee5495 100644 --- a/src/include/utils/builtins.h +++ b/src/include/utils/builtins.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: builtins.h,v 1.95 2000/01/10 16:13:22 momjian Exp $ + * $Id: builtins.h,v 1.96 2000/01/22 14:20:55 petere Exp $ * * NOTES * This should normally only be included by fmgr.h. @@ -136,17 +136,17 @@ extern int32 int4larger(int32 arg1, int32 arg2); extern int32 int4smaller(int32 arg1, int32 arg2); /* name.c */ -extern NameData *namein(char *s); -extern char *nameout(NameData *s); -extern bool nameeq(NameData *arg1, NameData *arg2); -extern bool namene(NameData *arg1, NameData *arg2); -extern bool namelt(NameData *arg1, NameData *arg2); -extern bool namele(NameData *arg1, NameData *arg2); -extern bool namegt(NameData *arg1, NameData *arg2); -extern bool namege(NameData *arg1, NameData *arg2); +extern NameData *namein(const char *s); +extern char *nameout(const NameData *s); +extern bool nameeq(const NameData *arg1, const NameData *arg2); +extern bool namene(const NameData *arg1, const NameData *arg2); +extern bool namelt(const NameData *arg1, const NameData *arg2); +extern bool namele(const NameData *arg1, const NameData *arg2); +extern bool namegt(const NameData *arg1, const NameData *arg2); +extern bool namege(const NameData *arg1, const NameData *arg2); extern int namecpy(Name n1, Name n2); -extern int namestrcpy(Name name, char *str); -extern int namestrcmp(Name name, char *str); +extern int namestrcpy(Name name, const char *str); +extern int namestrcmp(Name name, const char *str); /* numutils.c */ /* XXX hack. HP-UX has a ltoa (with different arguments) already. */ diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 84bbe0950e..0b7c04ea14 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: rel.h,v 1.31 2000/01/10 17:14:44 momjian Exp $ + * $Id: rel.h,v 1.32 2000/01/22 14:20:56 petere Exp $ * *------------------------------------------------------------------------- */ @@ -176,7 +176,7 @@ typedef Relation *RelationPtr; * Returns a Relation Name */ /* added to prevent circular dependency. bjm 1999/11/15 */ -char *get_temp_rel_by_physicalname(char *relname); +char *get_temp_rel_by_physicalname(const char *relname); #define RelationGetRelationName(relation) \ (\ (strncmp(RelationGetPhysicalRelationName(relation), \ diff --git a/src/include/utils/relcache.h b/src/include/utils/relcache.h index 2aeec820df..f3330a0270 100644 --- a/src/include/utils/relcache.h +++ b/src/include/utils/relcache.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: relcache.h,v 1.16 1999/11/21 01:58:20 tgl Exp $ + * $Id: relcache.h,v 1.17 2000/01/22 14:20:56 petere Exp $ * *------------------------------------------------------------------------- */ @@ -20,7 +20,7 @@ */ extern Relation RelationIdCacheGetRelation(Oid relationId); extern Relation RelationIdGetRelation(Oid relationId); -extern Relation RelationNameGetRelation(char *relationName); +extern Relation RelationNameGetRelation(const char *relationName); extern void RelationClose(Relation relation); extern void RelationForgetRelation(Oid rid); diff --git a/src/include/utils/temprel.h b/src/include/utils/temprel.h index 39e5157bd4..960c8b97ee 100644 --- a/src/include/utils/temprel.h +++ b/src/include/utils/temprel.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: temprel.h,v 1.6 1999/11/16 04:14:03 momjian Exp $ + * $Id: temprel.h,v 1.7 2000/01/22 14:20:56 petere Exp $ * *------------------------------------------------------------------------- */ @@ -15,11 +15,11 @@ #include "access/htup.h" -void create_temp_relation(char *relname, HeapTuple pg_class_tuple); +void create_temp_relation(const char *relname, HeapTuple pg_class_tuple); void remove_all_temp_relations(void); void invalidate_temp_relations(void); void remove_temp_relation(Oid relid); -char *get_temp_rel_by_username(char *user_relname); -char *get_temp_rel_by_physicalname(char *relname); +char *get_temp_rel_by_username(const char *user_relname); +char *get_temp_rel_by_physicalname(const char *relname); #endif /* TEMPREL_H */