⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dependency.c

📁 PostgreSQL 8.1.4的源码 适用于Linux下的开源数据库系统
💻 C
📖 第 1 页 / 共 4 页
字号:
		case AttrDefaultRelationId:			Assert(object->objectSubId == 0);			return OCLASS_DEFAULT;		case LanguageRelationId:			Assert(object->objectSubId == 0);			return OCLASS_LANGUAGE;		case OperatorRelationId:			Assert(object->objectSubId == 0);			return OCLASS_OPERATOR;		case OperatorClassRelationId:			Assert(object->objectSubId == 0);			return OCLASS_OPCLASS;		case RewriteRelationId:			Assert(object->objectSubId == 0);			return OCLASS_REWRITE;		case TriggerRelationId:			Assert(object->objectSubId == 0);			return OCLASS_TRIGGER;		case NamespaceRelationId:			Assert(object->objectSubId == 0);			return OCLASS_SCHEMA;		case AuthIdRelationId:			Assert(object->objectSubId == 0);			return OCLASS_ROLE;		case DatabaseRelationId:			Assert(object->objectSubId == 0);			return OCLASS_DATABASE;		case TableSpaceRelationId:			Assert(object->objectSubId == 0);			return OCLASS_TBLSPACE;	}	/* shouldn't get here */	elog(ERROR, "unrecognized object class: %u", object->classId);	return OCLASS_CLASS;		/* keep compiler quiet */}/* * getObjectDescription: build an object description for messages * * The result is a palloc'd string. */char *getObjectDescription(const ObjectAddress *object){	StringInfoData buffer;	initStringInfo(&buffer);	switch (getObjectClass(object))	{		case OCLASS_CLASS:			getRelationDescription(&buffer, object->objectId);			if (object->objectSubId != 0)				appendStringInfo(&buffer, _(" column %s"),								 get_relid_attribute_name(object->objectId,													   object->objectSubId));			break;		case OCLASS_PROC:			appendStringInfo(&buffer, _("function %s"),							 format_procedure(object->objectId));			break;		case OCLASS_TYPE:			appendStringInfo(&buffer, _("type %s"),							 format_type_be(object->objectId));			break;		case OCLASS_CAST:			{				Relation	castDesc;				ScanKeyData skey[1];				SysScanDesc rcscan;				HeapTuple	tup;				Form_pg_cast castForm;				castDesc = heap_open(CastRelationId, AccessShareLock);				ScanKeyInit(&skey[0],							ObjectIdAttributeNumber,							BTEqualStrategyNumber, F_OIDEQ,							ObjectIdGetDatum(object->objectId));				rcscan = systable_beginscan(castDesc, CastOidIndexId, true,											SnapshotNow, 1, skey);				tup = systable_getnext(rcscan);				if (!HeapTupleIsValid(tup))					elog(ERROR, "could not find tuple for cast %u",						 object->objectId);				castForm = (Form_pg_cast) GETSTRUCT(tup);				appendStringInfo(&buffer, _("cast from %s to %s"),								 format_type_be(castForm->castsource),								 format_type_be(castForm->casttarget));				systable_endscan(rcscan);				heap_close(castDesc, AccessShareLock);				break;			}		case OCLASS_CONSTRAINT:			{				Relation	conDesc;				ScanKeyData skey[1];				SysScanDesc rcscan;				HeapTuple	tup;				Form_pg_constraint con;				conDesc = heap_open(ConstraintRelationId, AccessShareLock);				ScanKeyInit(&skey[0],							ObjectIdAttributeNumber,							BTEqualStrategyNumber, F_OIDEQ,							ObjectIdGetDatum(object->objectId));				rcscan = systable_beginscan(conDesc, ConstraintOidIndexId, true,											SnapshotNow, 1, skey);				tup = systable_getnext(rcscan);				if (!HeapTupleIsValid(tup))					elog(ERROR, "could not find tuple for constraint %u",						 object->objectId);				con = (Form_pg_constraint) GETSTRUCT(tup);				if (OidIsValid(con->conrelid))				{					appendStringInfo(&buffer, _("constraint %s on "),									 NameStr(con->conname));					getRelationDescription(&buffer, con->conrelid);				}				else				{					appendStringInfo(&buffer, _("constraint %s"),									 NameStr(con->conname));				}				systable_endscan(rcscan);				heap_close(conDesc, AccessShareLock);				break;			}		case OCLASS_CONVERSION:			{				HeapTuple	conTup;				conTup = SearchSysCache(CONOID,										ObjectIdGetDatum(object->objectId),										0, 0, 0);				if (!HeapTupleIsValid(conTup))					elog(ERROR, "cache lookup failed for conversion %u",						 object->objectId);				appendStringInfo(&buffer, _("conversion %s"),				 NameStr(((Form_pg_conversion) GETSTRUCT(conTup))->conname));				ReleaseSysCache(conTup);				break;			}		case OCLASS_DEFAULT:			{				Relation	attrdefDesc;				ScanKeyData skey[1];				SysScanDesc adscan;				HeapTuple	tup;				Form_pg_attrdef attrdef;				ObjectAddress colobject;				attrdefDesc = heap_open(AttrDefaultRelationId, AccessShareLock);				ScanKeyInit(&skey[0],							ObjectIdAttributeNumber,							BTEqualStrategyNumber, F_OIDEQ,							ObjectIdGetDatum(object->objectId));				adscan = systable_beginscan(attrdefDesc, AttrDefaultOidIndexId,											true, SnapshotNow, 1, skey);				tup = systable_getnext(adscan);				if (!HeapTupleIsValid(tup))					elog(ERROR, "could not find tuple for attrdef %u",						 object->objectId);				attrdef = (Form_pg_attrdef) GETSTRUCT(tup);				colobject.classId = RelationRelationId;				colobject.objectId = attrdef->adrelid;				colobject.objectSubId = attrdef->adnum;				appendStringInfo(&buffer, _("default for %s"),								 getObjectDescription(&colobject));				systable_endscan(adscan);				heap_close(attrdefDesc, AccessShareLock);				break;			}		case OCLASS_LANGUAGE:			{				HeapTuple	langTup;				langTup = SearchSysCache(LANGOID,										 ObjectIdGetDatum(object->objectId),										 0, 0, 0);				if (!HeapTupleIsValid(langTup))					elog(ERROR, "cache lookup failed for language %u",						 object->objectId);				appendStringInfo(&buffer, _("language %s"),				  NameStr(((Form_pg_language) GETSTRUCT(langTup))->lanname));				ReleaseSysCache(langTup);				break;			}		case OCLASS_OPERATOR:			appendStringInfo(&buffer, _("operator %s"),							 format_operator(object->objectId));			break;		case OCLASS_OPCLASS:			{				HeapTuple	opcTup;				Form_pg_opclass opcForm;				HeapTuple	amTup;				Form_pg_am	amForm;				char	   *nspname;				opcTup = SearchSysCache(CLAOID,										ObjectIdGetDatum(object->objectId),										0, 0, 0);				if (!HeapTupleIsValid(opcTup))					elog(ERROR, "cache lookup failed for opclass %u",						 object->objectId);				opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);				amTup = SearchSysCache(AMOID,									   ObjectIdGetDatum(opcForm->opcamid),									   0, 0, 0);				if (!HeapTupleIsValid(amTup))					elog(ERROR, "cache lookup failed for access method %u",						 opcForm->opcamid);				amForm = (Form_pg_am) GETSTRUCT(amTup);				/* Qualify the name if not visible in search path */				if (OpclassIsVisible(object->objectId))					nspname = NULL;				else					nspname = get_namespace_name(opcForm->opcnamespace);				appendStringInfo(&buffer, _("operator class %s for access method %s"),								 quote_qualified_identifier(nspname,												  NameStr(opcForm->opcname)),								 NameStr(amForm->amname));				ReleaseSysCache(amTup);				ReleaseSysCache(opcTup);				break;			}		case OCLASS_REWRITE:			{				Relation	ruleDesc;				ScanKeyData skey[1];				SysScanDesc rcscan;				HeapTuple	tup;				Form_pg_rewrite rule;				ruleDesc = heap_open(RewriteRelationId, AccessShareLock);				ScanKeyInit(&skey[0],							ObjectIdAttributeNumber,							BTEqualStrategyNumber, F_OIDEQ,							ObjectIdGetDatum(object->objectId));				rcscan = systable_beginscan(ruleDesc, RewriteOidIndexId, true,											SnapshotNow, 1, skey);				tup = systable_getnext(rcscan);				if (!HeapTupleIsValid(tup))					elog(ERROR, "could not find tuple for rule %u",						 object->objectId);				rule = (Form_pg_rewrite) GETSTRUCT(tup);				appendStringInfo(&buffer, _("rule %s on "),								 NameStr(rule->rulename));				getRelationDescription(&buffer, rule->ev_class);				systable_endscan(rcscan);				heap_close(ruleDesc, AccessShareLock);				break;			}		case OCLASS_TRIGGER:			{				Relation	trigDesc;				ScanKeyData skey[1];				SysScanDesc tgscan;				HeapTuple	tup;				Form_pg_trigger trig;				trigDesc = heap_open(TriggerRelationId, AccessShareLock);				ScanKeyInit(&skey[0],							ObjectIdAttributeNumber,							BTEqualStrategyNumber, F_OIDEQ,							ObjectIdGetDatum(object->objectId));				tgscan = systable_beginscan(trigDesc, TriggerOidIndexId, true,											SnapshotNow, 1, skey);				tup = systable_getnext(tgscan);				if (!HeapTupleIsValid(tup))					elog(ERROR, "could not find tuple for trigger %u",						 object->objectId);				trig = (Form_pg_trigger) GETSTRUCT(tup);				appendStringInfo(&buffer, _("trigger %s on "),								 NameStr(trig->tgname));				getRelationDescription(&buffer, trig->tgrelid);				systable_endscan(tgscan);				heap_close(trigDesc, AccessShareLock);				break;			}		case OCLASS_SCHEMA:			{				char	   *nspname;				nspname = get_namespace_name(object->objectId);				if (!nspname)					elog(ERROR, "cache lookup failed for namespace %u",						 object->objectId);				appendStringInfo(&buffer, _("schema %s"), nspname);				break;			}		case OCLASS_ROLE:			{				appendStringInfo(&buffer, _("role %s"),								 GetUserNameFromId(object->objectId));				break;			}		case OCLASS_DATABASE:			{				char	   *datname;				datname = get_database_name(object->objectId);				if (!datname)					elog(ERROR, "cache lookup failed for database %u",						 object->objectId);				appendStringInfo(&buffer, _("database %s"), datname);				break;			}		case OCLASS_TBLSPACE:			{				char	   *tblspace;				tblspace = get_tablespace_name(object->objectId);				if (!tblspace)					elog(ERROR, "cache lookup failed for tablespace %u",						 object->objectId);				appendStringInfo(&buffer, _("tablespace %s"), tblspace);				break;			}		default:			appendStringInfo(&buffer, "unrecognized object %u %u %d",							 object->classId,							 object->objectId,							 object->objectSubId);			break;	}	return buffer.data;}/* * subroutine for getObjectDescription: describe a relation */static voidgetRelationDescription(StringInfo buffer, Oid relid){	HeapTuple	relTup;	Form_pg_class relForm;	char	   *nspname;	char	   *relname;	relTup = SearchSysCache(RELOID,							ObjectIdGetDatum(relid),							0, 0, 0);	if (!HeapTupleIsValid(relTup))		elog(ERROR, "cache lookup failed for relation %u", relid);	relForm = (Form_pg_class) GETSTRUCT(relTup);	/* Qualify the name if not visible in search path */	if (RelationIsVisible(relid))		nspname = NULL;	else		nspname = get_namespace_name(relForm->relnamespace);	relname = quote_qualified_identifier(nspname, NameStr(relForm->relname));	switch (relForm->relkind)	{		case RELKIND_RELATION:			appendStringInfo(buffer, _("table %s"),							 relname);			break;		case RELKIND_INDEX:			appendStringInfo(buffer, _("index %s"),							 relname);			break;		case RELKIND_SPECIAL:			appendStringInfo(buffer, _("special system relation %s"),							 relname);			break;		case RELKIND_SEQUENCE:			appendStringInfo(buffer, _("sequence %s"),							 relname);			break;		case RELKIND_UNCATALOGED:			appendStringInfo(buffer, _("uncataloged table %s"),							 relname);			break;		case RELKIND_TOASTVALUE:			appendStringInfo(buffer, _("toast table %s"),							 relname);			break;		case RELKIND_VIEW:			appendStringInfo(buffer, _("view %s"),							 relname);			break;		case RELKIND_COMPOSITE_TYPE:			appendStringInfo(buffer, _("composite type %s"),							 relname);			break;		default:			/* shouldn't get here */			appendStringInfo(buffer, _("relation %s"),							 relname);			break;	}	ReleaseSysCache(relTup);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -