您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ GETSTRUCT函数代码示例

51自学网 2021-06-01 20:50:50
  C++
这篇教程C++ GETSTRUCT函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中GETSTRUCT函数的典型用法代码示例。如果您正苦于以下问题:C++ GETSTRUCT函数的具体用法?C++ GETSTRUCT怎么用?C++ GETSTRUCT使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了GETSTRUCT函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: PersistentBuild_FindGpRelationNodeIndex

static voidPersistentBuild_FindGpRelationNodeIndex(	Oid				database,	Oid				defaultTablespace,	RelFileNode		*relFileNode){	Relation	pg_class_rel;	HeapScanDesc scan;	HeapTuple	tuple;	bool found;	/*	 * Iterate through all the relations of the database and find gp_relation_node_index.	 */	pg_class_rel = 			DirectOpen_PgClassOpen(							defaultTablespace, 							database);	scan = heap_beginscan(pg_class_rel, SnapshotNow, 0, NULL);	found = false;	while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)	{		Oid 			relationOid;		Form_pg_class	form_pg_class;		Oid 			reltablespace;		relationOid = HeapTupleGetOid(tuple);		if (relationOid != GpRelfileNodeOidIndexId)		{			continue;		}		form_pg_class = (Form_pg_class) GETSTRUCT(tuple);		reltablespace = form_pg_class->reltablespace;		if (reltablespace == 0)		{			reltablespace = defaultTablespace;		}		relFileNode->spcNode = reltablespace;		relFileNode->dbNode = database;		relFileNode->relNode= form_pg_class->relfilenode;		found = true;		break;	}	heap_endscan(scan);	DirectOpen_PgClassClose(pg_class_rel);	if (!found)	{		elog(ERROR, "pg_class entry for gp_relation_node_index not found");	}}
开发者ID:PivotalBigData,项目名称:incubator-hawq,代码行数:64,


示例2: Type_fromOid

Type Type_fromOid(Oid typeId, jobject typeMap){	CacheEntry   ce;	HeapTuple    typeTup;	Form_pg_type typeStruct;	Type         type = Type_fromOidCache(typeId);	if(type != 0)		return type;	typeTup    = PgObject_getValidTuple(TYPEOID, typeId, "type");	typeStruct = (Form_pg_type)GETSTRUCT(typeTup);	if(typeStruct->typelem != 0 && typeStruct->typlen == -1)	{		type = Type_getArrayType(Type_fromOid(typeStruct->typelem, typeMap), typeId);		goto finally;	}	/* For some reason, the anyarray is *not* an array with anyelement as the	 * element type. We'd like to see it that way though.	 */	if(typeId == ANYARRAYOID)	{		type = Type_getArrayType(Type_fromOid(ANYELEMENTOID, typeMap), typeId);		goto finally;	}	if(typeStruct->typbasetype != 0)	{		/* Domain type, recurse using the base type (which in turn may		 * also be a domain)		 */		type = Type_fromOid(typeStruct->typbasetype, typeMap);		goto finally;	}	if(typeMap != 0)	{		jobject joid      = Oid_create(typeId);		jclass  typeClass = (jclass)JNI_callObjectMethod(typeMap, s_Map_get, joid);		JNI_deleteLocalRef(joid);		if(typeClass != 0)		{			TupleDesc tupleDesc = lookup_rowtype_tupdesc_noerror(typeId, -1, true);			type = (Type)UDT_registerUDT(typeClass, typeId, typeStruct, tupleDesc, false);			JNI_deleteLocalRef(typeClass);			goto finally;		}	}	/* Composite and record types will not have a TypeObtainer registered	 */	if(typeStruct->typtype == 'c' || (typeStruct->typtype == 'p' && typeId == RECORDOID))	{		type = Composite_obtain(typeId);		goto finally;	}	ce = (CacheEntry)HashMap_getByOid(s_obtainerByOid, typeId);	if(ce == 0)		/*		 * Default to String and standard textin/textout coersion.		 */		type = String_obtain(typeId);	else	{		type = ce->type;		if(type == 0)			type = ce->obtainer(typeId);	}finally:	ReleaseSysCache(typeTup);	Type_cacheByOid(typeId, type);	return type;}
开发者ID:addisonhuddy,项目名称:gpdb,代码行数:78,


示例3: LookupExtProtocolFunction

/* * Finds an external protocol by passed in protocol name. * Errors if no such protocol exist, or if no function to * execute this protocol exists (for read or write separately). *  * Returns the protocol function to use. */OidLookupExtProtocolFunction(const char *prot_name, 						  ExtPtcFuncType prot_type,						  bool error){	Relation	rel;	Oid			funcOid = InvalidOid;	ScanKeyData skey;	SysScanDesc scan;	HeapTuple	tup;	Form_pg_extprotocol extprot;	rel = heap_open(ExtprotocolRelationId, AccessShareLock);	/*	 * Check the pg_extprotocol relation to be certain the protocol	 * is there.	 */	ScanKeyInit(&skey,				Anum_pg_extprotocol_ptcname,				BTEqualStrategyNumber, F_NAMEEQ,				CStringGetDatum(prot_name));	scan = systable_beginscan(rel, ExtprotocolPtcnameIndexId, true,							  SnapshotNow, 1, &skey);	tup = systable_getnext(scan);	if (!HeapTupleIsValid(tup))		ereport(ERROR,				(errcode(ERRCODE_UNDEFINED_OBJECT),				 errmsg("protocol /"%s/" does not exist",						prot_name)));	extprot = (Form_pg_extprotocol) GETSTRUCT(tup);	switch (prot_type)	{		case EXTPTC_FUNC_READER:			funcOid = extprot->ptcreadfn;			break;		case EXTPTC_FUNC_WRITER:			funcOid = extprot->ptcwritefn;			break;		case EXTPTC_FUNC_VALIDATOR:			funcOid = extprot->ptcvalidatorfn;			break;		default:			elog(ERROR, "internal error in pg_extprotocol:func_type_to_attnum");			break;	}	systable_endscan(scan);	heap_close(rel, AccessShareLock);	if (!OidIsValid(funcOid) && error)		ereport(ERROR,				(errcode(ERRCODE_UNDEFINED_OBJECT),				 errmsg("protocol '%s' has no %s function defined",						 prot_name, func_type_to_name(prot_type))));	return funcOid;}
开发者ID:PengJi,项目名称:gpdb-comments,代码行数:68,


示例4: sepgsql_relation_post_create

/* * sepgsql_relation_post_create * * The post creation hook of relation/attribute */voidsepgsql_relation_post_create(Oid relOid){	Relation	rel;	ScanKeyData skey;	SysScanDesc sscan;	HeapTuple	tuple;	Form_pg_class classForm;	ObjectAddress object;	uint16		tclass;	const char *tclass_text;	char	   *scontext;		/* subject */	char	   *tcontext;		/* schema */	char	   *rcontext;		/* relation */	char	   *ccontext;		/* column */	char		audit_name[2 * NAMEDATALEN + 20];	/*	 * Fetch catalog record of the new relation. Because pg_class entry is not	 * visible right now, we need to scan the catalog using SnapshotSelf.	 */	rel = heap_open(RelationRelationId, AccessShareLock);	ScanKeyInit(&skey,				ObjectIdAttributeNumber,				BTEqualStrategyNumber, F_OIDEQ,				ObjectIdGetDatum(relOid));	sscan = systable_beginscan(rel, ClassOidIndexId, true,							   SnapshotSelf, 1, &skey);	tuple = systable_getnext(sscan);	if (!HeapTupleIsValid(tuple))		elog(ERROR, "catalog lookup failed for relation %u", relOid);	classForm = (Form_pg_class) GETSTRUCT(tuple);	switch (classForm->relkind)	{		case RELKIND_RELATION:			tclass = SEPG_CLASS_DB_TABLE;			tclass_text = "table";			break;		case RELKIND_SEQUENCE:			tclass = SEPG_CLASS_DB_SEQUENCE;			tclass_text = "sequence";			break;		case RELKIND_VIEW:			tclass = SEPG_CLASS_DB_VIEW;			tclass_text = "view";			break;		default:			goto out;	}	/*	 * check db_schema:{add_name} permission of the namespace	 */	object.classId = NamespaceRelationId;	object.objectId = classForm->relnamespace;	object.objectSubId = 0;	sepgsql_avc_check_perms(&object,							SEPG_CLASS_DB_SCHEMA,							SEPG_DB_SCHEMA__ADD_NAME,							getObjectDescription(&object),							true);	/*	 * Compute a default security label when we create a new relation object	 * under the specified namespace.	 */	scontext = sepgsql_get_client_label();	tcontext = sepgsql_get_label(NamespaceRelationId,								 classForm->relnamespace, 0);	rcontext = sepgsql_compute_create(scontext, tcontext, tclass);	/*	 * check db_xxx:{create} permission	 */	snprintf(audit_name, sizeof(audit_name), "%s %s",			 tclass_text, NameStr(classForm->relname));	sepgsql_avc_check_perms_label(rcontext,								  tclass,								  SEPG_DB_DATABASE__CREATE,								  audit_name,								  true);	/*	 * Assign the default security label on the new relation	 */	object.classId = RelationRelationId;	object.objectId = relOid;	object.objectSubId = 0;	SetSecurityLabel(&object, SEPGSQL_LABEL_TAG, rcontext);//.........这里部分代码省略.........
开发者ID:ASchurman,项目名称:BufStrat,代码行数:101,


示例5: sepgsql_attribute_post_create

/* * sepgsql_attribute_post_create * * This routine assigns a default security label on a newly defined * column, using ALTER TABLE ... ADD COLUMN. * Note that this routine is not invoked in the case of CREATE TABLE, * although it also defines columns in addition to table. */voidsepgsql_attribute_post_create(Oid relOid, AttrNumber attnum){	Relation	rel;	ScanKeyData skey[2];	SysScanDesc sscan;	HeapTuple	tuple;	char	   *scontext;	char	   *tcontext;	char	   *ncontext;	char		audit_name[2 * NAMEDATALEN + 20];	ObjectAddress object;	Form_pg_attribute attForm;	/*	 * Only attributes within regular relation have individual security	 * labels.	 */	if (get_rel_relkind(relOid) != RELKIND_RELATION)		return;	/*	 * Compute a default security label of the new column underlying the	 * specified relation, and check permission to create it.	 */	rel = heap_open(AttributeRelationId, AccessShareLock);	ScanKeyInit(&skey[0],				Anum_pg_attribute_attrelid,				BTEqualStrategyNumber, F_OIDEQ,				ObjectIdGetDatum(relOid));	ScanKeyInit(&skey[1],				Anum_pg_attribute_attnum,				BTEqualStrategyNumber, F_INT2EQ,				Int16GetDatum(attnum));	sscan = systable_beginscan(rel, AttributeRelidNumIndexId, true,							   SnapshotSelf, 2, &skey[0]);	tuple = systable_getnext(sscan);	if (!HeapTupleIsValid(tuple))		elog(ERROR, "catalog lookup failed for column %d of relation %u",			 attnum, relOid);	attForm = (Form_pg_attribute) GETSTRUCT(tuple);	scontext = sepgsql_get_client_label();	tcontext = sepgsql_get_label(RelationRelationId, relOid, 0);	ncontext = sepgsql_compute_create(scontext, tcontext,									  SEPG_CLASS_DB_COLUMN);	/*	 * check db_column:{create} permission	 */	snprintf(audit_name, sizeof(audit_name), "table %s column %s",			 get_rel_name(relOid), NameStr(attForm->attname));	sepgsql_avc_check_perms_label(ncontext,								  SEPG_CLASS_DB_COLUMN,								  SEPG_DB_COLUMN__CREATE,								  audit_name,								  true);	/*	 * Assign the default security label on a new procedure	 */	object.classId = RelationRelationId;	object.objectId = relOid;	object.objectSubId = attnum;	SetSecurityLabel(&object, SEPGSQL_LABEL_TAG, ncontext);	systable_endscan(sscan);	heap_close(rel, AccessShareLock);	pfree(tcontext);	pfree(ncontext);}
开发者ID:ASchurman,项目名称:BufStrat,代码行数:84,


示例6: RemoveRewriteRule

/* * RemoveRewriteRule * * Delete a rule given its name. */voidRemoveRewriteRule(Oid owningRel, const char *ruleName, DropBehavior behavior,				  bool missing_ok){	HeapTuple	tuple;	Oid			eventRelationOid;	ObjectAddress object;	cqContext	*pcqCtx;	/*	 * Find the tuple for the target rule.	 */	pcqCtx = caql_beginscan(			NULL,			cql("SELECT * FROM pg_rewrite "				" WHERE ev_class = :1 "				" AND rulename = :2 "				" FOR UPDATE ",				ObjectIdGetDatum(owningRel),				CStringGetDatum((char *) ruleName)));	tuple = caql_getnext(pcqCtx);	/*	 * complain if no rule with such name exists	 */	if (!HeapTupleIsValid(tuple))	{		if (!missing_ok)			ereport(ERROR,					(errcode(ERRCODE_UNDEFINED_OBJECT),					 errmsg("rule /"%s/" for relation /"%s/" does not exist",							ruleName, get_rel_name(owningRel))));		else			ereport(NOTICE,					(errmsg("rule /"%s/" for relation /"%s/" does not exist, skipping",							ruleName, get_rel_name(owningRel))));		caql_endscan(pcqCtx);		return;	}	/*	 * Verify user has appropriate permissions.	 */	eventRelationOid = ((Form_pg_rewrite) GETSTRUCT(tuple))->ev_class;	Assert(eventRelationOid == owningRel);	if (!pg_class_ownercheck(eventRelationOid, GetUserId()))		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,					   get_rel_name(eventRelationOid));	/*	 * Do the deletion	 */	object.classId = RewriteRelationId;	object.objectId = HeapTupleGetOid(tuple);	object.objectSubId = 0;	caql_endscan(pcqCtx);	performDeletion(&object, behavior);}
开发者ID:ricky-wu,项目名称:gpdb,代码行数:67,


示例7: lookup_ts_parser_cache

/* * Fetch parser cache entry */TSParserCacheEntry *lookup_ts_parser_cache(Oid prsId){	TSParserCacheEntry *entry;	if (TSParserCacheHash == NULL)	{		/* First time through: initialize the hash table */		HASHCTL		ctl;		MemSet(&ctl, 0, sizeof(ctl));		ctl.keysize = sizeof(Oid);		ctl.entrysize = sizeof(TSParserCacheEntry);		TSParserCacheHash = hash_create("Tsearch parser cache", 4,										&ctl, HASH_ELEM | HASH_BLOBS);		/* Flush cache on pg_ts_parser changes */		CacheRegisterSyscacheCallback(TSPARSEROID, InvalidateTSCacheCallBack,									  PointerGetDatum(TSParserCacheHash));		/* Also make sure CacheMemoryContext exists */		if (!CacheMemoryContext)			CreateCacheMemoryContext();	}	/* Check single-entry cache */	if (lastUsedParser && lastUsedParser->prsId == prsId &&		lastUsedParser->isvalid)		return lastUsedParser;	/* Try to look up an existing entry */	entry = (TSParserCacheEntry *) hash_search(TSParserCacheHash,											   (void *) &prsId,											   HASH_FIND, NULL);	if (entry == NULL || !entry->isvalid)	{		/*		 * If we didn't find one, we want to make one. But first look up the		 * object to be sure the OID is real.		 */		HeapTuple	tp;		Form_pg_ts_parser prs;		tp = SearchSysCache1(TSPARSEROID, ObjectIdGetDatum(prsId));		if (!HeapTupleIsValid(tp))			elog(ERROR, "cache lookup failed for text search parser %u",				 prsId);		prs = (Form_pg_ts_parser) GETSTRUCT(tp);		/*		 * Sanity checks		 */		if (!OidIsValid(prs->prsstart))			elog(ERROR, "text search parser %u has no prsstart method", prsId);		if (!OidIsValid(prs->prstoken))			elog(ERROR, "text search parser %u has no prstoken method", prsId);		if (!OidIsValid(prs->prsend))			elog(ERROR, "text search parser %u has no prsend method", prsId);		if (entry == NULL)		{			bool		found;			/* Now make the cache entry */			entry = (TSParserCacheEntry *)				hash_search(TSParserCacheHash,							(void *) &prsId,							HASH_ENTER, &found);			Assert(!found);		/* it wasn't there a moment ago */		}		MemSet(entry, 0, sizeof(TSParserCacheEntry));		entry->prsId = prsId;		entry->startOid = prs->prsstart;		entry->tokenOid = prs->prstoken;		entry->endOid = prs->prsend;		entry->headlineOid = prs->prsheadline;		entry->lextypeOid = prs->prslextype;		ReleaseSysCache(tp);		fmgr_info_cxt(entry->startOid, &entry->prsstart, CacheMemoryContext);		fmgr_info_cxt(entry->tokenOid, &entry->prstoken, CacheMemoryContext);		fmgr_info_cxt(entry->endOid, &entry->prsend, CacheMemoryContext);		if (OidIsValid(entry->headlineOid))			fmgr_info_cxt(entry->headlineOid, &entry->prsheadline,						  CacheMemoryContext);		entry->isvalid = true;	}	lastUsedParser = entry;	return entry;}
开发者ID:0x0FFF,项目名称:postgres,代码行数:97,


示例8: CheckMyDatabase

/* * CheckMyDatabase -- fetch information from the pg_database entry for our DB */static voidCheckMyDatabase(const char *name, bool am_superuser){	HeapTuple	tup;	Form_pg_database dbform;	/* Fetch our pg_database row normally, via syscache */	tup = SearchSysCache(DATABASEOID,						 ObjectIdGetDatum(MyDatabaseId),						 0, 0, 0);	if (!HeapTupleIsValid(tup))		elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);	dbform = (Form_pg_database) GETSTRUCT(tup);	/* This recheck is strictly paranoia */	if (strcmp(name, NameStr(dbform->datname)) != 0)		ereport(FATAL,				(errcode(ERRCODE_UNDEFINED_DATABASE),				 errmsg("database /"%s/" has disappeared from pg_database",						name),				 errdetail("Database OID %u now seems to belong to /"%s/".",						   MyDatabaseId, NameStr(dbform->datname))));	/*	 * Check permissions to connect to the database.	 *	 * These checks are not enforced when in standalone mode, so that there is	 * a way to recover from disabling all access to all databases, for	 * example "UPDATE pg_database SET datallowconn = false;".	 *	 * We do not enforce them for the autovacuum worker processes either.	 */	if (IsUnderPostmaster && !IsAutoVacuumWorkerProcess())	{		/*		 * Check that the database is currently allowing connections.		 */		if (!dbform->datallowconn)			ereport(FATAL,					(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),			 errmsg("database /"%s/" is not currently accepting connections",					name)));		/*		 * Check privilege to connect to the database.	(The am_superuser test		 * is redundant, but since we have the flag, might as well check it		 * and save a few cycles.)		 */		if (!am_superuser &&			pg_database_aclcheck(MyDatabaseId, GetUserId(),								 ACL_CONNECT) != ACLCHECK_OK)			ereport(FATAL,					(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),					 errmsg("permission denied for database /"%s/"", name),					 errdetail("User does not have CONNECT privilege.")));		/*		 * Check connection limit for this database.		 *		 * There is a race condition here --- we create our PGPROC before		 * checking for other PGPROCs.	If two backends did this at about the		 * same time, they might both think they were over the limit, while		 * ideally one should succeed and one fail.  Getting that to work		 * exactly seems more trouble than it is worth, however; instead we		 * just document that the connection limit is approximate.		 */		if (dbform->datconnlimit >= 0 &&			!am_superuser &&			CountDBBackends(MyDatabaseId) > dbform->datconnlimit)			ereport(FATAL,					(errcode(ERRCODE_TOO_MANY_CONNECTIONS),					 errmsg("too many connections for database /"%s/"",							name)));	}	/*	 * OK, we're golden.  Next to-do item is to save the encoding info out of	 * the pg_database tuple.	 */	SetDatabaseEncoding(dbform->encoding);	/* Record it as a GUC internal option, too */	SetConfigOption("server_encoding", GetDatabaseEncodingName(),					PGC_INTERNAL, PGC_S_OVERRIDE);	/* If we have no other source of client_encoding, use server encoding */	SetConfigOption("client_encoding", GetDatabaseEncodingName(),					PGC_BACKEND, PGC_S_DEFAULT);	/* Use the right encoding in translated messages */#ifdef ENABLE_NLS	pg_bind_textdomain_codeset(textdomain(NULL));#endif	/*	 * Lastly, set up any database-specific configuration variables.	 */	if (IsUnderPostmaster)	{//.........这里部分代码省略.........
开发者ID:a320321wb,项目名称:gpdb,代码行数:101,


示例9: InitPostgres

//.........这里部分代码省略.........		InitializeClientEncoding();		/* report this backend in the PgBackendStatus array */		pgstat_bestart();		/* close the transaction we started above */		CommitTransactionCommand();		return;	}	/*	 * Set up the global variables holding database id and path.  But note we	 * won't actually try to touch the database just yet.	 *	 * We take a shortcut in the bootstrap case, otherwise we have to look up	 * the db name in pg_database.	 */	if (bootstrap)	{		MyDatabaseId = TemplateDbOid;		MyDatabaseTableSpace = DEFAULTTABLESPACE_OID;	}	else if (in_dbname != NULL)	{		HeapTuple	tuple;		Form_pg_database dbform;		tuple = GetDatabaseTuple(in_dbname);		if (!HeapTupleIsValid(tuple))			ereport(FATAL,					(errcode(ERRCODE_UNDEFINED_DATABASE),					 errmsg("database /"%s/" does not exist", in_dbname)));		dbform = (Form_pg_database) GETSTRUCT(tuple);		MyDatabaseId = HeapTupleGetOid(tuple);		MyDatabaseTableSpace = dbform->dattablespace;		/* take database name from the caller, just for paranoia */		strlcpy(dbname, in_dbname, sizeof(dbname));		pfree(tuple);	}	else	{		/* caller specified database by OID */		HeapTuple	tuple;		Form_pg_database dbform;		tuple = GetDatabaseTupleByOid(dboid);		if (!HeapTupleIsValid(tuple))			ereport(FATAL,					(errcode(ERRCODE_UNDEFINED_DATABASE),					 errmsg("database %u does not exist", dboid)));		dbform = (Form_pg_database) GETSTRUCT(tuple);		MyDatabaseId = HeapTupleGetOid(tuple);		MyDatabaseTableSpace = dbform->dattablespace;		Assert(MyDatabaseId == dboid);		strlcpy(dbname, NameStr(dbform->datname), sizeof(dbname));		/* pass the database name back to the caller */		if (out_dbname)			strcpy(out_dbname, dbname);		pfree(tuple);	}	/* Now we can mark our PGPROC entry with the database ID */	/* (We assume this is an atomic store so no lock is needed) */	MyProc->databaseId = MyDatabaseId;
开发者ID:a320321wb,项目名称:gpdb,代码行数:66,


示例10: CheckMyDatabase

/* * CheckMyDatabase -- fetch information from the pg_database entry for our DB */static voidCheckMyDatabase(const char *name, bool am_superuser, bool override_allow_connections){	HeapTuple	tup;	Form_pg_database dbform;	char	   *collate;	char	   *ctype;	/* Fetch our pg_database row normally, via syscache */	tup = SearchSysCache1(DATABASEOID, ObjectIdGetDatum(MyDatabaseId));	if (!HeapTupleIsValid(tup))		elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);	dbform = (Form_pg_database) GETSTRUCT(tup);	/* This recheck is strictly paranoia */	if (strcmp(name, NameStr(dbform->datname)) != 0)		ereport(FATAL,				(errcode(ERRCODE_UNDEFINED_DATABASE),				 errmsg("database /"%s/" has disappeared from pg_database",						name),				 errdetail("Database OID %u now seems to belong to /"%s/".",						   MyDatabaseId, NameStr(dbform->datname))));	/*	 * Check permissions to connect to the database.	 *	 * These checks are not enforced when in standalone mode, so that there is	 * a way to recover from disabling all access to all databases, for	 * example "UPDATE pg_database SET datallowconn = false;".	 *	 * We do not enforce them for autovacuum worker processes either.	 */	if (IsUnderPostmaster && !IsAutoVacuumWorkerProcess())	{		/*		 * Check that the database is currently allowing connections.		 */		if (!dbform->datallowconn && !override_allow_connections)			ereport(FATAL,					(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),					 errmsg("database /"%s/" is not currently accepting connections",							name)));		/*		 * Check privilege to connect to the database.  (The am_superuser test		 * is redundant, but since we have the flag, might as well check it		 * and save a few cycles.)		 */		if (!am_superuser &&			pg_database_aclcheck(MyDatabaseId, GetUserId(),								 ACL_CONNECT) != ACLCHECK_OK)			ereport(FATAL,					(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),					 errmsg("permission denied for database /"%s/"", name),					 errdetail("User does not have CONNECT privilege.")));		/*		 * Check connection limit for this database.		 *		 * There is a race condition here --- we create our PGPROC before		 * checking for other PGPROCs.  If two backends did this at about the		 * same time, they might both think they were over the limit, while		 * ideally one should succeed and one fail.  Getting that to work		 * exactly seems more trouble than it is worth, however; instead we		 * just document that the connection limit is approximate.		 */		if (dbform->datconnlimit >= 0 &&			!am_superuser &&			CountDBConnections(MyDatabaseId) > dbform->datconnlimit)			ereport(FATAL,					(errcode(ERRCODE_TOO_MANY_CONNECTIONS),					 errmsg("too many connections for database /"%s/"",							name)));	}	/*	 * OK, we're golden.  Next to-do item is to save the encoding info out of	 * the pg_database tuple.	 */	SetDatabaseEncoding(dbform->encoding);	/* Record it as a GUC internal option, too */	SetConfigOption("server_encoding", GetDatabaseEncodingName(),					PGC_INTERNAL, PGC_S_OVERRIDE);	/* If we have no other source of client_encoding, use server encoding */	SetConfigOption("client_encoding", GetDatabaseEncodingName(),					PGC_BACKEND, PGC_S_DYNAMIC_DEFAULT);	/* assign locale variables */	collate = NameStr(dbform->datcollate);	ctype = NameStr(dbform->datctype);	if (pg_perm_setlocale(LC_COLLATE, collate) == NULL)		ereport(FATAL,				(errmsg("database locale is incompatible with operating system"),				 errdetail("The database was initialized with LC_COLLATE /"%s/", "						   " which is not recognized by setlocale().", collate),				 errhint("Recreate the database with another locale or install the missing locale.")));//.........这里部分代码省略.........
开发者ID:MasahikoSawada,项目名称:postgresql,代码行数:101,


示例11: InitPostgres

//.........这里部分代码省略.........		InitializeClientEncoding();		/* report this backend in the PgBackendStatus array */		pgstat_bestart();		/* close the transaction we started above */		CommitTransactionCommand();		return;	}	/*	 * Set up the global variables holding database id and default tablespace.	 * But note we won't actually try to touch the database just yet.	 *	 * We take a shortcut in the bootstrap case, otherwise we have to look up	 * the db's entry in pg_database.	 */	if (bootstrap)	{		MyDatabaseId = TemplateDbOid;		MyDatabaseTableSpace = DEFAULTTABLESPACE_OID;	}	else if (in_dbname != NULL)	{		HeapTuple	tuple;		Form_pg_database dbform;		tuple = GetDatabaseTuple(in_dbname);		if (!HeapTupleIsValid(tuple))			ereport(FATAL,					(errcode(ERRCODE_UNDEFINED_DATABASE),					 errmsg("database /"%s/" does not exist", in_dbname)));		dbform = (Form_pg_database) GETSTRUCT(tuple);		MyDatabaseId = dbform->oid;		MyDatabaseTableSpace = dbform->dattablespace;		/* take database name from the caller, just for paranoia */		strlcpy(dbname, in_dbname, sizeof(dbname));	}	else if (OidIsValid(dboid))	{		/* caller specified database by OID */		HeapTuple	tuple;		Form_pg_database dbform;		tuple = GetDatabaseTupleByOid(dboid);		if (!HeapTupleIsValid(tuple))			ereport(FATAL,					(errcode(ERRCODE_UNDEFINED_DATABASE),					 errmsg("database %u does not exist", dboid)));		dbform = (Form_pg_database) GETSTRUCT(tuple);		MyDatabaseId = dbform->oid;		MyDatabaseTableSpace = dbform->dattablespace;		Assert(MyDatabaseId == dboid);		strlcpy(dbname, NameStr(dbform->datname), sizeof(dbname));		/* pass the database name back to the caller */		if (out_dbname)			strcpy(out_dbname, dbname);	}	else	{		/*		 * If this is a background worker not bound to any particular		 * database, we're done now.  Everything that follows only makes sense		 * if we are bound to a specific database.  We do need to close the		 * transaction we started before returning.
开发者ID:MasahikoSawada,项目名称:postgresql,代码行数:67,


示例12: func_new_from_oid

static PyObjfunc_new_from_oid(PyTypeObject *subtype, Oid fn_oid, PyObj fn_oid_int, PyObj fn_oid_str){	volatile HeapTuple ht = NULL;	volatile PyObj rob = NULL;	Assert(OidIsValid(fn_oid));	Assert(fn_oid_int != NULL);	Assert(fn_oid_str != NULL);	rob = subtype->tp_alloc(subtype, 0);	if (rob == NULL)		return(NULL);	PyPgFunction_SetOid(rob, fn_oid);	PyPgFunction_SetStateful(rob, false);	Py_INCREF(fn_oid_int);	Py_INCREF(fn_oid_str);	PyPgFunction_SetPyLongOid(rob, fn_oid_int);	PyPgFunction_SetPyUnicodeOid(rob, fn_oid_str);	/*	 * Collect the Function information from the system cache	 */	PG_TRY();	{		Form_pg_proc ps;		Form_pg_namespace ns;		FmgrInfo flinfo;		text *prosrc;		Datum prosrc_datum;		bool isnull = true;		const char *filename = NULL, *nspname, *q_nspname;		TupleDesc argdesc = NULL, result_desc = NULL;		Oid prorettype = InvalidOid;		PyObj id_str_ob = NULL, nspname_str_ob = NULL;		PyObj filename_str_ob = NULL, q_nspname_str_ob = NULL;		PyObj output = NULL, src = NULL;		PyObj input;		ht = SearchSysCache(PROCOID, fn_oid, 0, 0, 0);		if (!HeapTupleIsValid(ht))		{			ereport(ERROR,(				errcode(ERRCODE_UNDEFINED_FUNCTION),				errmsg("failed to find function at oid %d", fn_oid)			));		}		PyPgFunction_SetXMin(rob, HeapTupleHeaderGetXmin(ht->t_data));		PyPgFunction_SetItemPointer(rob, &(ht->t_self));		ps = (Form_pg_proc) GETSTRUCT(ht);		PyPgFunction_SetNamespace(rob, ps->pronamespace);		PyPgFunction_SetLanguage(rob, ps->prolang);		PyPgFunction_SetReturnsSet(rob, ps->proretset);		PyPgFunction_SetVolatile(rob, ps->provolatile);		prorettype = ps->prorettype;		prosrc_datum = SysCacheGetAttr(			PROCOID, ht, Anum_pg_proc_prosrc, &isnull);		if (!isnull)		{			prosrc = DatumGetTextPCopy(prosrc_datum);			src = PyUnicode_FromTEXT(prosrc);			PyPgFunction_SetSource(rob, src);			pfree(prosrc);			prosrc = NULL;		}		else		{			src = Py_None;			Py_INCREF(src);			PyPgFunction_SetSource(rob, src);		}		if (src == NULL)			PyErr_RelayException();		/*		 * Get the function's address.		 */		fmgr_info(fn_oid, &flinfo);		PyPgFunction_SetPGFunction(rob, flinfo.fn_addr);		/*		 * Build function parameters TupleDesc		 */		if (ps->pronargs > 0)		{			argdesc = TupleDesc_From_pg_proc_arginfo(ht);			input = PyPgTupleDesc_FromCopy(argdesc);			if (input == NULL)				PyErr_RelayException();			PyPgFunction_SetInput(rob, input);			FreeTupleDesc(argdesc);		}		else//.........这里部分代码省略.........
开发者ID:fdr,项目名称:pg-python,代码行数:101,


示例13: sepgsql_relation_post_create

/* * sepgsql_relation_post_create * * The post creation hook of relation/attribute */voidsepgsql_relation_post_create(Oid relOid){	Relation	rel;	ScanKeyData skey;	SysScanDesc sscan;	HeapTuple	tuple;	Form_pg_class classForm;	ObjectAddress object;	uint16		tclass;	char	   *scontext;		/* subject */	char	   *tcontext;		/* schema */	char	   *rcontext;		/* relation */	char	   *ccontext;		/* column */	/*	 * Fetch catalog record of the new relation. Because pg_class entry is not	 * visible right now, we need to scan the catalog using SnapshotSelf.	 */	rel = heap_open(RelationRelationId, AccessShareLock);	ScanKeyInit(&skey,				ObjectIdAttributeNumber,				BTEqualStrategyNumber, F_OIDEQ,				ObjectIdGetDatum(relOid));	sscan = systable_beginscan(rel, ClassOidIndexId, true,							   SnapshotSelf, 1, &skey);	tuple = systable_getnext(sscan);	if (!HeapTupleIsValid(tuple))		elog(ERROR, "catalog lookup failed for relation %u", relOid);	classForm = (Form_pg_class) GETSTRUCT(tuple);	if (classForm->relkind == RELKIND_RELATION)		tclass = SEPG_CLASS_DB_TABLE;	else if (classForm->relkind == RELKIND_SEQUENCE)		tclass = SEPG_CLASS_DB_SEQUENCE;	else if (classForm->relkind == RELKIND_VIEW)		tclass = SEPG_CLASS_DB_VIEW;	else		goto out;				/* No need to assign individual labels */	/*	 * Compute a default security label when we create a new relation object	 * under the specified namespace.	 */	scontext = sepgsql_get_client_label();	tcontext = sepgsql_get_label(NamespaceRelationId,								 classForm->relnamespace, 0);	rcontext = sepgsql_compute_create(scontext, tcontext, tclass);	/*	 * Assign the default security label on the new relation	 */	object.classId = RelationRelationId;	object.objectId = relOid;	object.objectSubId = 0;	SetSecurityLabel(&object, SEPGSQL_LABEL_TAG, rcontext);	/*	 * We also assigns a default security label on columns of the new regular	 * tables.	 */	if (classForm->relkind == RELKIND_RELATION)	{		AttrNumber	index;		ccontext = sepgsql_compute_create(scontext, rcontext,										  SEPG_CLASS_DB_COLUMN);		for (index = FirstLowInvalidHeapAttributeNumber + 1;			 index <= classForm->relnatts;			 index++)		{			if (index == InvalidAttrNumber)				continue;			if (index == ObjectIdAttributeNumber && !classForm->relhasoids)				continue;			object.classId = RelationRelationId;			object.objectId = relOid;			object.objectSubId = index;			SetSecurityLabel(&object, SEPGSQL_LABEL_TAG, ccontext);		}		pfree(ccontext);	}	pfree(rcontext);out:	systable_endscan(sscan);	heap_close(rel, AccessShareLock);}
开发者ID:GisKook,项目名称:Gis,代码行数:98,


示例14: PersistentBuild_TruncateAllGpRelationNode

static int64PersistentBuild_TruncateAllGpRelationNode(void){	Relation pg_database;	HeapScanDesc scan;	HeapTuple tuple;	int64 count;	pg_database = heap_open(						DatabaseRelationId,						AccessShareLock);	/*	 * Truncate gp_relation_node and its index in each database.	 */	scan = heap_beginscan(pg_database, SnapshotNow, 0, NULL);	count = 0;	while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)	{		Form_pg_database form_pg_database =						(Form_pg_database)GETSTRUCT(tuple);		Oid dbOid;		Oid dattablespace;		RelFileNode relFileNode;		SMgrRelation smgrRelation;		Page btree_metapage;				dbOid = HeapTupleGetOid(tuple);		dattablespace = form_pg_database->dattablespace;		if (dbOid == HcatalogDbOid)			continue;		if (Debug_persistent_print)			elog(Persistent_DebugPrintLevel(), 				 "PersistentBuild_TruncateAllGpRelationNode: dbOid %u, '%s'",				 dbOid,				 form_pg_database->datname.data);		if (Debug_persistent_print)			elog(Persistent_DebugPrintLevel(), 				 "Truncating gp_relation_node %u/%u/%u in database oid %u ('%s')",				 relFileNode.spcNode,				 relFileNode.dbNode,				 relFileNode.relNode,				 dbOid,				 form_pg_database->datname.data);		relFileNode.spcNode = dattablespace;		relFileNode.dbNode = dbOid;		relFileNode.relNode = GpRelfileNodeRelationId;		/*		 * Truncate WITHOUT generating an XLOG record (i.e. pretend it is a temp relation).		 */		PersistentBuild_NonTransactionTruncate(&relFileNode);		count++;		/*		 * And, the index.  Unfortunately, the relfilenode OID can change due to a		 * REINDEX {TABLE|INDEX} command.		 */		PersistentBuild_FindGpRelationNodeIndex(											dbOid,											dattablespace,											&relFileNode);		if (Debug_persistent_print)			elog(Persistent_DebugPrintLevel(), 				 "Truncating gp_relation_node_index %u/%u/%u in database oid %u ('%s').  relfilenode different %s, tablespace different %s",				 relFileNode.spcNode,				 relFileNode.dbNode,				 relFileNode.relNode,				 dbOid,				 form_pg_database->datname.data,				 ((relFileNode.relNode != GpRelfileNodeOidIndexId) ? "true" : "false"),				 ((relFileNode.spcNode != dattablespace) ? "true" : "false"));		PersistentBuild_NonTransactionTruncate(&relFileNode);		// The BTree needs an empty meta-data block.		smgrRelation = smgropen(relFileNode);		btree_metapage = (Page)palloc(BLCKSZ);		_bt_initmetapage(btree_metapage, P_NONE, 0);		smgrwrite(			smgrRelation, 			/* blockNum */ 0, 			(char*)btree_metapage,			/* isTemp */ false);		smgrimmedsync(smgrRelation);		pfree(btree_metapage);		smgrclose(smgrRelation);		count++;	}//.........这里部分代码省略.........
开发者ID:PivotalBigData,项目名称:incubator-hawq,代码行数:101,


示例15: AggregateCreate

/* * AggregateCreate */voidAggregateCreate(const char *aggName,				Oid aggNamespace,				Oid *aggArgTypes,				int numArgs,				List *aggtransfnName,				List *aggfinalfnName,				List *aggsortopName,				Oid aggTransType,				const char *agginitval){	Relation	aggdesc;	HeapTuple	tup;	bool		nulls[Natts_pg_aggregate];	Datum		values[Natts_pg_aggregate];	Form_pg_proc proc;	Oid			transfn;	Oid			finalfn = InvalidOid;	/* can be omitted */	Oid			sortop = InvalidOid;	/* can be omitted */	bool		hasPolyArg;	bool		hasInternalArg;	Oid			rettype;	Oid			finaltype;	Oid		   *fnArgs;	int			nargs_transfn;	Oid			procOid;	TupleDesc	tupDesc;	int			i;	ObjectAddress myself,				referenced;	/* sanity checks (caller should have caught these) */	if (!aggName)		elog(ERROR, "no aggregate name supplied");	if (!aggtransfnName)		elog(ERROR, "aggregate must have a transition function");	/* check for polymorphic and INTERNAL arguments */	hasPolyArg = false;	hasInternalArg = false;	for (i = 0; i < numArgs; i++)	{		if (IsPolymorphicType(aggArgTypes[i]))			hasPolyArg = true;		else if (aggArgTypes[i] == INTERNALOID)			hasInternalArg = true;	}	/*	 * If transtype is polymorphic, must have polymorphic argument also; else	 * we will have no way to deduce the actual transtype.	 */	if (IsPolymorphicType(aggTransType) && !hasPolyArg)		ereport(ERROR,				(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),				 errmsg("cannot determine transition data type"),				 errdetail("An aggregate using a polymorphic transition type must have at least one polymorphic argument.")));	/* find the transfn */	nargs_transfn = numArgs + 1;	fnArgs = (Oid *) palloc(nargs_transfn * sizeof(Oid));	fnArgs[0] = aggTransType;	memcpy(fnArgs + 1, aggArgTypes, numArgs * sizeof(Oid));	transfn = lookup_agg_function(aggtransfnName, nargs_transfn, fnArgs,								  &rettype);	/*	 * Return type of transfn (possibly after refinement by	 * enforce_generic_type_consistency, if transtype isn't polymorphic) must	 * exactly match declared transtype.	 *	 * In the non-polymorphic-transtype case, it might be okay to allow a	 * rettype that's binary-coercible to transtype, but I'm not quite	 * convinced that it's either safe or useful.  When transtype is	 * polymorphic we *must* demand exact equality.	 */	if (rettype != aggTransType)		ereport(ERROR,				(errcode(ERRCODE_DATATYPE_MISMATCH),				 errmsg("return type of transition function %s is not %s",						NameListToString(aggtransfnName),						format_type_be(aggTransType))));	tup = SearchSysCache1(PROCOID, ObjectIdGetDatum(transfn));	if (!HeapTupleIsValid(tup))		elog(ERROR, "cache lookup failed for function %u", transfn);	proc = (Form_pg_proc) GETSTRUCT(tup);	/*	 * If the transfn is strict and the initval is NULL, make sure first input	 * type and transtype are the same (or at least binary-compatible), so	 * that it's OK to use the first input value as the initial transValue.	 */	if (proc->proisstrict && agginitval == NULL)	{		if (numArgs < 1 ||//.........这里部分代码省略.........
开发者ID:Epictetus,项目名称:postgres,代码行数:101,


示例16: RenameTableSpace

/* * Rename a tablespace */ObjectAddressRenameTableSpace(const char *oldname, const char *newname){	Oid			tspId;	Relation	rel;	ScanKeyData entry[1];	HeapScanDesc scan;	HeapTuple	tup;	HeapTuple	newtuple;	Form_pg_tablespace newform;	ObjectAddress address;	/* Search pg_tablespace */	rel = heap_open(TableSpaceRelationId, RowExclusiveLock);	ScanKeyInit(&entry[0],				Anum_pg_tablespace_spcname,				BTEqualStrategyNumber, F_NAMEEQ,				CStringGetDatum(oldname));	scan = heap_beginscan_catalog(rel, 1, entry);	tup = heap_getnext(scan, ForwardScanDirection);	if (!HeapTupleIsValid(tup))		ereport(ERROR,				(errcode(ERRCODE_UNDEFINED_OBJECT),				 errmsg("tablespace /"%s/" does not exist",						oldname)));	tspId = HeapTupleGetOid(tup);	newtuple = heap_copytuple(tup);	newform = (Form_pg_tablespace) GETSTRUCT(newtuple);	heap_endscan(scan);	/* Must be owner */	if (!pg_tablespace_ownercheck(HeapTupleGetOid(newtuple), GetUserId()))		aclcheck_error(ACLCHECK_NO_PRIV, ACL_KIND_TABLESPACE, oldname);	/* Validate new name */	if (!allowSystemTableMods && IsReservedName(newname))		ereport(ERROR,				(errcode(ERRCODE_RESERVED_NAME),				 errmsg("unacceptable tablespace name /"%s/"", newname),		errdetail("The prefix /"pg_/" is reserved for system tablespaces.")));	/* Make sure the new name doesn't exist */	ScanKeyInit(&entry[0],				Anum_pg_tablespace_spcname,				BTEqualStrategyNumber, F_NAMEEQ,				CStringGetDatum(newname));	scan = heap_beginscan_catalog(rel, 1, entry);	tup = heap_getnext(scan, ForwardScanDirection);	if (HeapTupleIsValid(tup))		ereport(ERROR,				(errcode(ERRCODE_DUPLICATE_OBJECT),				 errmsg("tablespace /"%s/" already exists",						newname)));	heap_endscan(scan);	/* OK, update the entry */	namestrcpy(&(newform->spcname), newname);	simple_heap_update(rel, &newtuple->t_self, newtuple);	CatalogUpdateIndexes(rel, newtuple);	InvokeObjectPostAlterHook(TableSpaceRelationId, tspId, 0);	ObjectAddressSet(address, TableSpaceRelationId, tspId);	heap_close(rel, NoLock);	return address;}
开发者ID:rdterner,项目名称:postgres,代码行数:76,


示例17: TupleDescInitEntry

/* * TupleDescInitEntry *		This function initializes a single attribute structure in *		a previously allocated tuple descriptor. */voidTupleDescInitEntry(TupleDesc desc,				   AttrNumber attributeNumber,				   const char *attributeName,				   Oid oidtypeid,				   int32 typmod,				   int attdim){	HeapTuple	tuple;	Form_pg_type typeForm;	Form_pg_attribute att;	/*	 * sanity checks	 */	AssertArg(PointerIsValid(desc));	AssertArg(attributeNumber >= 1);	AssertArg(attributeNumber <= desc->natts);	/*	 * initialize the attribute fields	 */	att = desc->attrs[attributeNumber - 1];	att->attrelid = 0;			/* dummy value */	/*	 * Note: attributeName can be NULL, because the planner doesn't always	 * fill in valid resname values in targetlists, particularly for resjunk	 * attributes.	 */	if (attributeName != NULL)		namestrcpy(&(att->attname), attributeName);	else		MemSet(NameStr(att->attname), 0, NAMEDATALEN);	att->attstattarget = -1;	att->attcacheoff = -1;	att->atttypmod = typmod;	att->attnum = attributeNumber;	att->attndims = attdim;	att->attnotnull = false;	att->atthasdef = false;	att->attisdropped = false;	att->attislocal = true;	att->attinhcount = 0;	/* attacl and attoptions are not present in tupledescs */	tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(oidtypeid));	if (!HeapTupleIsValid(tuple))		elog(ERROR, "cache lookup failed for type %u", oidtypeid);	typeForm = (Form_pg_type) GETSTRUCT(tuple);	att->atttypid = oidtypeid;	att->attlen = typeForm->typlen;	att->attbyval = typeForm->typbyval;	att->attalign = typeForm->typalign;	att->attstorage = typeForm->typstorage;	ReleaseSysCache(tuple);}
开发者ID:Joe-xXx,项目名称:postgres-old-soon-decommissioned,代码行数:68,


示例18: OperatorUpd

/* * OperatorUpd * *	For a given operator, look up its negator and commutator operators. *	If they are defined, but their negator and commutator fields *	(respectively) are empty, then use the new operator for neg or comm. *	This solves a problem for users who need to insert two new operators *	which are the negator or commutator of each other. */static voidOperatorUpd(Oid baseId, Oid commId, Oid negId){	int			i;	Relation	pg_operator_desc;	HeapTuple	tup;	bool		nulls[Natts_pg_operator];	bool		replaces[Natts_pg_operator];	Datum		values[Natts_pg_operator];	for (i = 0; i < Natts_pg_operator; ++i)	{		values[i] = (Datum) 0;		replaces[i] = false;		nulls[i] = false;	}	/*	 * check and update the commutator & negator, if necessary	 *	 * We need a CommandCounterIncrement here in case of a self-commutator	 * operator: we'll need to update the tuple that we just inserted.	 */	CommandCounterIncrement();	pg_operator_desc = heap_open(OperatorRelationId, RowExclusiveLock);	tup = SearchSysCacheCopy1(OPEROID, ObjectIdGetDatum(commId));	/*	 * if the commutator and negator are the same operator, do one update. XXX	 * this is probably useless code --- I doubt it ever makes sense for	 * commutator and negator to be the same thing...	 */	if (commId == negId)	{		if (HeapTupleIsValid(tup))		{			Form_pg_operator t = (Form_pg_operator) GETSTRUCT(tup);			if (!OidIsValid(t->oprcom) || !OidIsValid(t->oprnegate))			{				if (!OidIsValid(t->oprnegate))				{					values[Anum_pg_operator_oprnegate - 1] = ObjectIdGetDatum(baseId);					replaces[Anum_pg_operator_oprnegate - 1] = true;				}				if (!OidIsValid(t->oprcom))				{					values[Anum_pg_operator_oprcom - 1] = ObjectIdGetDatum(baseId);					replaces[Anum_pg_operator_oprcom - 1] = true;				}				tup = heap_modify_tuple(tup,										RelationGetDescr(pg_operator_desc),										values,										nulls,										replaces);				simple_heap_update(pg_operator_desc, &tup->t_self, tup);				CatalogUpdateIndexes(pg_operator_desc, tup);			}		}		heap_close(pg_operator_desc, RowExclusiveLock);		return;	}	/* if commutator and negator are different, do two updates */	if (HeapTupleIsValid(tup) &&		!(OidIsValid(((Form_pg_operator) GETSTRUCT(tup))->oprcom)))	{		values[Anum_pg_operator_oprcom - 1] = ObjectIdGetDatum(baseId);		replaces[Anum_pg_operator_oprcom - 1] = true;		tup = heap_modify_tuple(tup,								RelationGetDescr(pg_operator_desc),								values,								nulls,								replaces);		simple_heap_update(pg_operator_desc, &tup->t_self, tup);		CatalogUpdateIndexes(pg_operator_desc, tup);		values[Anum_pg_operator_oprcom - 1] = (Datum) NULL;		replaces[Anum_pg_operator_oprcom - 1] = false;//.........这里部分代码省略.........
开发者ID:GisKook,项目名称:Gis,代码行数:101,


示例19: CreateSchemaCommand

/* * CREATE SCHEMA * * Note: caller should pass in location information for the whole * CREATE SCHEMA statement, which in turn we pass down as the location * of the component commands.  This comports with our general plan of * reporting location/len for the whole command even when executing * a subquery. */OidCreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString,					int stmt_location, int stmt_len){	const char *schemaName = stmt->schemaname;	Oid			namespaceId;	OverrideSearchPath *overridePath;	List	   *parsetree_list;	ListCell   *parsetree_item;	Oid			owner_uid;	Oid			saved_uid;	int			save_sec_context;	AclResult	aclresult;	ObjectAddress address;	GetUserIdAndSecContext(&saved_uid, &save_sec_context);	/*	 * Who is supposed to own the new schema?	 */	if (stmt->authrole)		owner_uid = get_rolespec_oid(stmt->authrole, false);	else		owner_uid = saved_uid;	/* fill schema name with the user name if not specified */	if (!schemaName)	{		HeapTuple	tuple;		tuple = SearchSysCache1(AUTHOID, ObjectIdGetDatum(owner_uid));		if (!HeapTupleIsValid(tuple))			elog(ERROR, "cache lookup failed for role %u", owner_uid);		schemaName =			pstrdup(NameStr(((Form_pg_authid) GETSTRUCT(tuple))->rolname));		ReleaseSysCache(tuple);	}	/*	 * To create a schema, must have schema-create privilege on the current	 * database and must be able to become the target role (this does not	 * imply that the target role itself must have create-schema privilege).	 * The latter provision guards against "giveaway" attacks.  Note that a	 * superuser will always have both of these privileges a fortiori.	 */	aclresult = pg_database_aclcheck(MyDatabaseId, saved_uid, ACL_CREATE);	if (aclresult != ACLCHECK_OK)		aclcheck_error(aclresult, ACL_KIND_DATABASE,					   get_database_name(MyDatabaseId));	check_is_member_of_role(saved_uid, owner_uid);	/* Additional check to protect reserved schema names */	if (!allowSystemTableMods && IsReservedName(schemaName))		ereport(ERROR,				(errcode(ERRCODE_RESERVED_NAME),				 errmsg("unacceptable schema name /"%s/"", schemaName),				 errdetail("The prefix /"pg_/" is reserved for system schemas.")));	/*	 * If if_not_exists was given and the schema already exists, bail out.	 * (Note: we needn't check this when not if_not_exists, because	 * NamespaceCreate will complain anyway.)  We could do this before making	 * the permissions checks, but since CREATE TABLE IF NOT EXISTS makes its	 * creation-permission check first, we do likewise.	 */	if (stmt->if_not_exists &&		SearchSysCacheExists1(NAMESPACENAME, PointerGetDatum(schemaName)))	{		ereport(NOTICE,				(errcode(ERRCODE_DUPLICATE_SCHEMA),				 errmsg("schema /"%s/" already exists, skipping",						schemaName)));		return InvalidOid;	}	/*	 * If the requested authorization is different from the current user,	 * temporarily set the current user so that the object(s) will be created	 * with the correct ownership.	 *	 * (The setting will be restored at the end of this routine, or in case of	 * error, transaction abort will clean things up.)	 */	if (saved_uid != owner_uid)		SetUserIdAndSecContext(owner_uid,							   save_sec_context | SECURITY_LOCAL_USERID_CHANGE);	/* Create the schema's namespace */	namespaceId = NamespaceCreate(schemaName, owner_uid, false);//.........这里部分代码省略.........
开发者ID:AmiGanguli,项目名称:postgres,代码行数:101,


示例20: makeOperatorDependencies

/* * Create dependencies for a new operator (either a freshly inserted * complete operator, a new shell operator, or a just-updated shell). * * NB: the OidIsValid tests in this routine are necessary, in case * the given operator is a shell. */static voidmakeOperatorDependencies(HeapTuple tuple){	Form_pg_operator oper = (Form_pg_operator) GETSTRUCT(tuple);	ObjectAddress myself,				referenced;	myself.classId = OperatorRelationId;	myself.objectId = HeapTupleGetOid(tuple);	myself.objectSubId = 0;	/*	 * In case we are updating a shell, delete any existing entries, except	 * for extension membership which should remain the same.	 */	deleteDependencyRecordsFor(myself.classId, myself.objectId, true);	deleteSharedDependencyRecordsFor(myself.classId, myself.objectId, 0);	/* Dependency on namespace */	if (OidIsValid(oper->oprnamespace))	{		referenced.classId = NamespaceRelationId;		referenced.objectId = oper->oprnamespace;		referenced.objectSubId = 0;		recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);	}	/* Dependency on left type */	if (OidIsValid(oper->oprleft))	{		referenced.classId = TypeRelationId;		referenced.objectId = oper->oprleft;		referenced.objectSubId = 0;		recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);	}	/* Dependency on right type */	if (OidIsValid(oper->oprright))	{		referenced.classId = TypeRelationId;		referenced.objectId = oper->oprright;		referenced.objectSubId = 0;		recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);	}	/* Dependency on result type */	if (OidIsValid(oper->oprresult))	{		referenced.classId = TypeRelationId;		referenced.objectId = oper->oprresult;		referenced.objectSubId = 0;		recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);	}	/*	 * NOTE: we do not consider the operator to depend on the associated	 * operators oprcom and oprnegate. We would not want to delete this	 * operator if those go away, but only reset the link fields; which is not	 * a function that the dependency code can presently handle.  (Something	 * could perhaps be done with objectSubId though.)	For now, it's okay to	 * let those links dangle if a referenced operator is removed.	 */	/* Dependency on implementation function */	if (OidIsValid(oper->oprcode))	{		referenced.classId = ProcedureRelationId;		referenced.objectId = oper->oprcode;		referenced.objectSubId = 0;		recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);	}	/* Dependency on restriction selectivity function */	if (OidIsValid(oper->oprrest))	{		referenced.classId = ProcedureRelationId;		referenced.objectId = oper->oprrest;		referenced.objectSubId = 0;		recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);	}	/* Dependency on join selectivity function */	if (OidIsValid(oper->oprjoin))	{		referenced.classId = ProcedureRelationId;		referenced.objectId = oper->oprjoin;		referenced.objectSubId = 0;		recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);	}	/* Dependency on owner */	recordDependencyOnOwner(OperatorRelationId, HeapTupleGetOid(tuple),							oper->oprowner);//.........这里部分代码省略.........
开发者ID:GisKook,项目名称:Gis,代码行数:101,


示例21: ProcedureCreate

//.........这里部分代码省略.........	else		nulls[Anum_pg_proc_proargnames - 1] = true;	if (parameterDefaults != NIL)		values[Anum_pg_proc_proargdefaults - 1] = CStringGetTextDatum(nodeToString(parameterDefaults));	else		nulls[Anum_pg_proc_proargdefaults - 1] = true;	if (trftypes != PointerGetDatum(NULL))		values[Anum_pg_proc_protrftypes - 1] = trftypes;	else		nulls[Anum_pg_proc_protrftypes - 1] = true;	values[Anum_pg_proc_prosrc - 1] = CStringGetTextDatum(prosrc);	if (probin)		values[Anum_pg_proc_probin - 1] = CStringGetTextDatum(probin);	else		nulls[Anum_pg_proc_probin - 1] = true;	if (proconfig != PointerGetDatum(NULL))		values[Anum_pg_proc_proconfig - 1] = proconfig;	else		nulls[Anum_pg_proc_proconfig - 1] = true;	/* proacl will be determined later */	rel = heap_open(ProcedureRelationId, RowExclusiveLock);	tupDesc = RelationGetDescr(rel);	/* Check for pre-existing definition */	oldtup = SearchSysCache3(PROCNAMEARGSNSP,							 PointerGetDatum(procedureName),							 PointerGetDatum(parameterTypes),							 ObjectIdGetDatum(procNamespace));	if (HeapTupleIsValid(oldtup))	{		/* There is one; okay to replace it? */		Form_pg_proc oldproc = (Form_pg_proc) GETSTRUCT(oldtup);		Datum		proargnames;		bool		isnull;		if (!replace)			ereport(ERROR,					(errcode(ERRCODE_DUPLICATE_FUNCTION),					 errmsg("function /"%s/" already exists with same argument types",							procedureName)));		if (!pg_proc_ownercheck(HeapTupleGetOid(oldtup), proowner))			aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_FUNCTION,						   procedureName);		/*		 * Not okay to change the return type of the existing proc, since		 * existing rules, views, etc may depend on the return type.		 */		if (returnType != oldproc->prorettype ||			returnsSet != oldproc->proretset)			ereport(ERROR,					(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),					 errmsg("cannot change return type of existing function"),					 errhint("Use DROP FUNCTION %s first.",							 format_procedure(HeapTupleGetOid(oldtup)))));		/*		 * If it returns RECORD, check for possible change of record type		 * implied by OUT parameters		 */		if (returnType == RECORDOID)		{			TupleDesc	olddesc;			TupleDesc	newdesc;
开发者ID:maksm90,项目名称:postgresql,代码行数:67,


示例22: make_op

/* * make_op() *		Operator expression construction. * * Transform operator expression ensuring type compatibility. * This is where some type conversion happens. * * As with coerce_type, pstate may be NULL if no special unknown-Param * processing is wanted. */Expr *make_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree,		int location){	Oid			ltypeId,				rtypeId;	Operator	tup;	Form_pg_operator opform;	Oid			actual_arg_types[2];	Oid			declared_arg_types[2];	int			nargs;	List	   *args;	Oid			rettype;	OpExpr	   *result;	/* Select the operator */	if (rtree == NULL)	{		/* right operator */		ltypeId = exprType(ltree);		rtypeId = InvalidOid;		tup = right_oper(pstate, opname, ltypeId, false, location);	}	else if (ltree == NULL)	{		/* left operator */		rtypeId = exprType(rtree);		ltypeId = InvalidOid;		tup = left_oper(pstate, opname, rtypeId, false, location);	}	else	{		/* otherwise, binary operator */		ltypeId = exprType(ltree);		rtypeId = exprType(rtree);		tup = oper(pstate, opname, ltypeId, rtypeId, false, location);	}	opform = (Form_pg_operator) GETSTRUCT(tup);	/* Check it's not a shell */	if (!RegProcedureIsValid(opform->oprcode))		ereport(ERROR,				(errcode(ERRCODE_UNDEFINED_FUNCTION),				 errmsg("operator is only a shell: %s",						op_signature_string(opname,											opform->oprkind,											opform->oprleft,											opform->oprright)),				 parser_errposition(pstate, location)));	/* Do typecasting and build the expression tree */	if (rtree == NULL)	{		/* right operator */		args = list_make1(ltree);		actual_arg_types[0] = ltypeId;		declared_arg_types[0] = opform->oprleft;		nargs = 1;	}	else if (ltree == NULL)	{		/* left operator */		args = list_make1(rtree);		actual_arg_types[0] = rtypeId;		declared_arg_types[0] = opform->oprright;		nargs = 1;	}	else	{		/* otherwise, binary operator */		args = list_make2(ltree, rtree);		actual_arg_types[0] = ltypeId;		actual_arg_types[1] = rtypeId;		declared_arg_types[0] = opform->oprleft;		declared_arg_types[1] = opform->oprright;		nargs = 2;	}	/*	 * enforce consistency with polymorphic argument and return types,	 * possibly adjusting return type or declared_arg_types (which will be	 * used as the cast destination by make_fn_arguments)	 */	rettype = enforce_generic_type_consistency(actual_arg_types,											   declared_arg_types,											   nargs,											   opform->oprresult,											   false);//.........这里部分代码省略.........
开发者ID:Epictetus,项目名称:postgres,代码行数:101,


示例23: sepgsql_relation_drop

/* * sepgsql_relation_drop * * It checks privileges to drop the supplied relation. */voidsepgsql_relation_drop(Oid relOid){	ObjectAddress object;	char	   *audit_name;	uint16_t	tclass = 0;	char		relkind;	relkind = get_rel_relkind(relOid);	if (relkind == RELKIND_RELATION)		tclass = SEPG_CLASS_DB_TABLE;	else if (relkind == RELKIND_SEQUENCE)		tclass = SEPG_CLASS_DB_SEQUENCE;	else if (relkind == RELKIND_VIEW)		tclass = SEPG_CLASS_DB_VIEW;	else		return;	/*	 * check db_schema:{remove_name} permission	 */	object.classId = NamespaceRelationId;	object.objectId = get_rel_namespace(relOid);	object.objectSubId = 0;	audit_name = getObjectDescription(&object);	sepgsql_avc_check_perms(&object,							SEPG_CLASS_DB_SCHEMA,							SEPG_DB_SCHEMA__REMOVE_NAME,							audit_name,							true);	pfree(audit_name);	/*	 * check db_table/sequence/view:{drop} permission	 */	object.classId = RelationRelationId;	object.objectId = relOid;	object.objectSubId = 0;	audit_name = getObjectDescription(&object);	sepgsql_avc_check_perms(&object,							tclass,							SEPG_DB_TABLE__DROP,							audit_name,							true);	pfree(audit_name);	/*	 * check db_column:{drop} permission	 */	if (relkind == RELKIND_RELATION)	{		Form_pg_attribute attForm;		CatCList   *attrList;		HeapTuple	atttup;		int			i;		attrList = SearchSysCacheList1(ATTNUM, ObjectIdGetDatum(relOid));		for (i = 0; i < attrList->n_members; i++)		{			atttup = &attrList->members[i]->tuple;			attForm = (Form_pg_attribute) GETSTRUCT(atttup);			if (attForm->attisdropped)				continue;			object.classId = RelationRelationId;			object.objectId = relOid;			object.objectSubId = attForm->attnum;			audit_name = getObjectDescription(&object);			sepgsql_avc_check_perms(&object,									SEPG_CLASS_DB_COLUMN,									SEPG_DB_COLUMN__DROP,									audit_name,									true);			pfree(audit_name);		}		ReleaseCatCacheList(attrList);	}}
开发者ID:ASchurman,项目名称:BufStrat,代码行数:87,


示例24: make_scalar_array_op

/* * make_scalar_array_op() *		Build expression tree for "scalar op ANY/ALL (array)" construct. */Expr *make_scalar_array_op(ParseState *pstate, List *opname,					 bool useOr,					 Node *ltree, Node *rtree,					 int location){	Oid			ltypeId,				rtypeId,				atypeId,				res_atypeId;	Operator	tup;	Form_pg_operator opform;	Oid			actual_arg_types[2];	Oid			declared_arg_types[2];	List	   *args;	Oid			rettype;	ScalarArrayOpExpr *result;	ltypeId = exprType(ltree);	atypeId = exprType(rtree);	/*	 * The right-hand input of the operator will be the element type of the	 * array.  However, if we currently have just an untyped literal on the	 * right, stay with that and hope we can resolve the operator.	 */	if (atypeId == UNKNOWNOID)		rtypeId = UNKNOWNOID;	else	{		rtypeId = get_base_element_type(atypeId);		if (!OidIsValid(rtypeId))			ereport(ERROR,					(errcode(ERRCODE_WRONG_OBJECT_TYPE),				   errmsg("op ANY/ALL (array) requires array on right side"),					 parser_errposition(pstate, location)));	}	/* Now resolve the operator */	tup = oper(pstate, opname, ltypeId, rtypeId, false, location);	opform = (Form_pg_operator) GETSTRUCT(tup);	/* Check it's not a shell */	if (!RegProcedureIsValid(opform->oprcode))		ereport(ERROR,				(errcode(ERRCODE_UNDEFINED_FUNCTION),				 errmsg("operator is only a shell: %s",						op_signature_string(opname,											opform->oprkind,											opform->oprleft,											opform->oprright)),				 parser_errposition(pstate, location)));	args = list_make2(ltree, rtree);	actual_arg_types[0] = ltypeId;	actual_arg_types[1] = rtypeId;	declared_arg_types[0] = opform->oprleft;	declared_arg_types[1] = opform->oprright;	/*	 * enforce consistency with polymorphic argument and return types,	 * possibly adjusting return type or declared_arg_types (which will be	 * used as the cast destination by make_fn_arguments)	 */	rettype = enforce_generic_type_consistency(actual_arg_types,											   declared_arg_types,											   2,											   opform->oprresult,											   false);	/*	 * Check that operator result is boolean	 */	if (rettype != BOOLOID)		ereport(ERROR,				(errcode(ERRCODE_WRONG_OBJECT_TYPE),			 errmsg("op ANY/ALL (array) requires operator to yield boolean"),				 parser_errposition(pstate, location)));	if (get_func_retset(opform->oprcode))		ereport(ERROR,				(errcode(ERRCODE_WRONG_OBJECT_TYPE),		  errmsg("op ANY/ALL (array) requires operator not to return a set"),				 parser_errposition(pstate, location)));	/*	 * Now switch back to the array type on the right, arranging for any	 * needed cast to be applied.  Beware of polymorphic operators here;	 * enforce_generic_type_consistency may or may not have replaced a	 * polymorphic type with a real one.	 */	if (IsPolymorphicType(declared_arg_types[1]))	{		/* assume the actual array type is OK */		res_atypeId = atypeId;	}	else//.........这里部分代码省略.........
开发者ID:Epictetus,项目名称:postgres,代码行数:101,


示例25: hdfs_get_value

Datumhdfs_get_value(hdfs_opt *opt, Oid pgtyp, int pgtypmod, HiveResultSet *rs, int idx, bool *is_null, int len, int col_type){	Datum      value_datum = 0;	Datum      valueDatum = 0;	regproc    typeinput;	HeapTuple  tuple;	int        typemod;	char *value;	/* get the type's output function */	tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(pgtyp));	if (!HeapTupleIsValid(tuple))		elog(ERROR, "cache lookup failed for type %u", pgtyp);	typeinput = ((Form_pg_type)GETSTRUCT(tuple))->typinput;	typemod  = ((Form_pg_type)GETSTRUCT(tuple))->typtypmod;	ReleaseSysCache(tuple);	switch (pgtyp)	{		case BITOID:		case BOOLOID:		case INT2OID:		case INT4OID:		case INT8OID:		case BYTEAOID:		case DATEOID:		case TIMEOID:		case TIMESTAMPOID:		case TIMESTAMPTZOID:		case FLOAT4OID: 		case FLOAT8OID: 		{			char *value;			value = hdfs_get_field_as_cstring(opt, rs, idx, is_null, len);			/* libhive return an empty string for null value */			if (strlen(value) == 0)			{				*is_null = true;			}			else			{				valueDatum = CStringGetDatum((char*)value);				value_datum = OidFunctionCall3(typeinput, valueDatum, ObjectIdGetDatum(pgtyp), Int32GetDatum(typemod));			}		}		break;		case CHAROID:		case NAMEOID:		case TEXTOID:		case BPCHAROID:		case VARCHAROID:		{			switch (col_type)			{				case HDFS_TINYINT:				{					char str[10];					value = hdfs_get_field_as_cstring(opt, rs, idx, is_null, len);					if (strlen(value) == 0)					{						*is_null = true;					}					else					{						sprintf(str, "%d", value[0]);						valueDatum = CStringGetDatum((char*)str);						value_datum = OidFunctionCall3(typeinput, valueDatum, ObjectIdGetDatum(pgtyp), Int32GetDatum(typemod));					}				}				break;				default:				{					value = hdfs_get_field_as_cstring(opt, rs, idx, is_null, len);					valueDatum = CStringGetDatum((char*)value);					value_datum = OidFunctionCall3(typeinput, valueDatum, ObjectIdGetDatum(pgtyp), Int32GetDatum(typemod));				}				break;			}		}		break;		default:			ereport(ERROR, (errcode(ERRCODE_FDW_INVALID_DATA_TYPE),								errmsg("unknown or unsupported PostgreSQL data type"),								errhint("Supported data types are BOOL, INT, DATE, TIME, FLOAT, CHAR, TEXT and VARCHAR : %u", pgtyp)));                        break;	}	return value_datum;}
开发者ID:kashifzeeshan,项目名称:hdfs_fdw,代码行数:92,


示例26: _copyConst

/* ---------------- *	_copyConst * ---------------- */static Const *_copyConst(Const *from){    static Oid 	cached_type;    static bool		cached_typbyval;        Const *newnode = makeNode(Const);        /* ----------------     *	copy remainder of node     * ----------------     */    newnode->consttype = 	from->consttype;    newnode->constlen = 	from->constlen;        /* ----------------     *	XXX super cheesy hack until parser/planner     *  puts in the right values here.     * ----------------     */    if (cached_type != from->consttype) {	HeapTuple	typeTuple;	TypeTupleForm	typeStruct;		/* ----------------	 *   get the type tuple corresponding to the paramList->type,	 *   If this fails, returnValue has been pre-initialized	 *   to "null" so we just return it.	 * ----------------	 */	typeTuple = SearchSysCacheTuple(TYPOID,					ObjectIdGetDatum(from->consttype),					0,0,0);		/* ----------------	 *   get the type length and by-value from the type tuple and	 *   save the information in our one element cache.	 * ----------------	 */	Assert(PointerIsValid(typeTuple));		typeStruct = (TypeTupleForm) GETSTRUCT(typeTuple);	cached_typbyval = (typeStruct)->typbyval ? true : false ;	cached_type = from->consttype;    }        from->constbyval = cached_typbyval;        if (!from->constisnull) {	/* ----------------	 *	copying the Datum in a const node is a bit trickier	 *  because it might be a pointer and it might also be of	 *  variable length...	 * ----------------	 */	if (from->constbyval == true) {	    /* ----------------	     *  passed by value so just copy the datum.	     * ----------------	     */	    newnode->constvalue = 	from->constvalue;	} else {	    /* ----------------	     *  not passed by value. datum contains a pointer.	     * ----------------	     */	    if (from->constlen != -1) {		/* ----------------		 *	fixed length structure		 * ----------------		 */		newnode->constvalue = PointerGetDatum(palloc(from->constlen));		memmove((char*)newnode->constvalue, 			(char*)from->constvalue, from->constlen); 	    } else {		/* ----------------		 *	variable length structure.  here the length is stored		 *  in the first int pointed to by the constval.		 * ----------------		 */		int length;		length = *((int *) from->constvalue);		newnode->constvalue = PointerGetDatum(palloc(length));		memmove((char*)newnode->constvalue,			(char*)from->constvalue, length);	    }	}    }    else {	newnode->constvalue = from->constvalue;    }    newnode->constisnull = 	from->constisnull;    newnode->constbyval = 	from->constbyval;        return newnode;}
开发者ID:jarulraj,项目名称:postgres95,代码行数:100,


示例27: sepgsql_database_post_create

/* * sepgsql_database_post_create * * This routine assigns a default security label on a newly defined * database, and check permission needed for its creation. */voidsepgsql_database_post_create(Oid databaseId, const char *dtemplate){	Relation	rel;	ScanKeyData skey;	SysScanDesc sscan;	HeapTuple	tuple;	char	   *tcontext;	char	   *ncontext;	char		audit_name[NAMEDATALEN + 20];	ObjectAddress object;	Form_pg_database datForm;	/*	 * Oid of the source database is not saved in pg_database catalog, so we	 * collect its identifier using contextual information. If NULL, its	 * default is "template1" according to createdb().	 */	if (!dtemplate)		dtemplate = "template1";	object.classId = DatabaseRelationId;	object.objectId = get_database_oid(dtemplate, false);	object.objectSubId = 0;	tcontext = sepgsql_get_label(object.classId,								 object.objectId,								 object.objectSubId);	/*	 * check db_database:{getattr} permission	 */	snprintf(audit_name, sizeof(audit_name), "database %s", dtemplate);	sepgsql_avc_check_perms_label(tcontext,								  SEPG_CLASS_DB_DATABASE,								  SEPG_DB_DATABASE__GETATTR,								  audit_name,								  true);	/*	 * Compute a default security label of the newly created database based on	 * a pair of security label of client and source database.	 *	 * XXX - uncoming version of libselinux supports to take object name to	 * handle special treatment on default security label.	 */	rel = heap_open(DatabaseRelationId, AccessShareLock);	ScanKeyInit(&skey,				ObjectIdAttributeNumber,				BTEqualStrategyNumber, F_OIDEQ,				ObjectIdGetDatum(databaseId));	sscan = systable_beginscan(rel, DatabaseOidIndexId, true,							   SnapshotSelf, 1, &skey);	tuple = systable_getnext(sscan);	if (!HeapTupleIsValid(tuple))		elog(ERROR, "catalog lookup failed for database %u", databaseId);	datForm = (Form_pg_database) GETSTRUCT(tuple);	ncontext = sepgsql_compute_create(sepgsql_get_client_label(),									  tcontext,									  SEPG_CLASS_DB_DATABASE);	/*	 * check db_database:{create} permission	 */	snprintf(audit_name, sizeof(audit_name),			 "database %s", NameStr(datForm->datname));	sepgsql_avc_check_perms_label(ncontext,								  SEPG_CLASS_DB_DATABASE,								  SEPG_DB_DATABASE__CREATE,								  audit_name,								  true);	systable_endscan(sscan);	heap_close(rel, AccessShareLock);	/*	 * Assign the default security label on the new database	 */	object.classId = DatabaseRelationId;	object.objectId = databaseId;	object.objectSubId = 0;	SetSecurityLabel(&object, SEPGSQL_LABEL_TAG, ncontext);	pfree(ncontext);	pfree(tcontext);}
开发者ID:ASchurman,项目名称:BufStrat,代码行数:97,


示例28: cluster

/*--------------------------------------------------------------------------- * This cluster code allows for clustering multiple tables at once. Because * of this, we cannot just run everything on a single transaction, or we * would be forced to acquire exclusive locks on all the tables being * clustered, simultaneously --- very likely leading to deadlock. * * To solve this we follow a similar strategy to VACUUM code, * clustering each relation in a separate transaction. For this to work, * we need to: *	- provide a separate memory context so that we can pass information in *	  a way that survives across transactions *	- start a new transaction every time a new relation is clustered *	- check for validity of the information on to-be-clustered relations, *	  as someone might have deleted a relation behind our back, or *	  clustered one on a different index *	- end the transaction * * The single-relation case does not have any such overhead. * * We also allow a relation to be specified without index.	In that case, * the indisclustered bit will be looked up, and an ERROR will be thrown * if there is no index with the bit set. *--------------------------------------------------------------------------- */voidcluster(ClusterStmt *stmt, bool isTopLevel){	if (stmt->relation != NULL)	{		/* This is the single-relation case. */		Oid			tableOid,					indexOid = InvalidOid;		Relation	rel;		RelToCluster rvtc;		/* Find and lock the table */		rel = heap_openrv(stmt->relation, AccessExclusiveLock);		tableOid = RelationGetRelid(rel);		/* Check permissions */		if (!pg_class_ownercheck(tableOid, GetUserId()))			aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,						   RelationGetRelationName(rel));		/*		 * Reject clustering a remote temp table ... their local buffer		 * manager is not going to cope.		 */		if (isOtherTempNamespace(RelationGetNamespace(rel)))			ereport(ERROR,					(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),			   errmsg("cannot cluster temporary tables of other sessions")));		if (stmt->indexname == NULL)		{			ListCell   *index;			/* We need to find the index that has indisclustered set. */			foreach(index, RelationGetIndexList(rel))			{				HeapTuple	idxtuple;				Form_pg_index indexForm;				cqContext	*idxcqCtx;				indexOid = lfirst_oid(index);				idxcqCtx = caql_beginscan(						NULL,						cql("SELECT * FROM pg_index "							" WHERE indexrelid = :1 ",							ObjectIdGetDatum(indexOid)));				idxtuple = caql_getnext(idxcqCtx);				if (!HeapTupleIsValid(idxtuple))					elog(ERROR, "cache lookup failed for index %u", indexOid);				indexForm = (Form_pg_index) GETSTRUCT(idxtuple);				if (indexForm->indisclustered)				{					caql_endscan(idxcqCtx);					break;				}				caql_endscan(idxcqCtx);				indexOid = InvalidOid;			}
开发者ID:titati78,项目名称:gpdb,代码行数:87,


示例29: TypeCreateWithOid

//.........这里部分代码省略.........	 * initialize the default value for this type.	 */	if (defaultTypeValue)		values[i] = CStringGetTextDatum(defaultTypeValue);	else		nulls[i] = true;	i++;						/* typdefault */	/*	 * open pg_type and prepare to insert or update a row.	 *	 * NOTE: updating will not work correctly in bootstrap mode; but we don't	 * expect to be overwriting any shell types in bootstrap mode.	 */	pg_type_desc = heap_open(TypeRelationId, RowExclusiveLock);	pcqCtx = caql_addrel(cqclr(&cqc), pg_type_desc);	tup = caql_getfirst(			pcqCtx,			cql("SELECT * FROM pg_type "				" WHERE typname = :1 "				" AND typnamespace = :2 "				" FOR UPDATE ",				CStringGetDatum((char *) typeName),				ObjectIdGetDatum(typeNamespace)));	if (HeapTupleIsValid(tup))	{		/*		 * check that the type is not already defined.	It may exist as a		 * shell type, however.		 */		if (((Form_pg_type) GETSTRUCT(tup))->typisdefined)			ereport(ERROR,					(errcode(ERRCODE_DUPLICATE_OBJECT),					 errmsg("type /"%s/" already exists", typeName)));		/*		 * shell type must have been created by same owner		 */		if (((Form_pg_type) GETSTRUCT(tup))->typowner != ownerId)			aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TYPE, typeName);		/*		 * Okay to update existing shell type tuple		 */		tup = caql_modify_current(pcqCtx,								  values,								  nulls,								  replaces);		caql_update_current(pcqCtx, tup);		/* and Update indexes (implicit) */		typeObjectId = HeapTupleGetOid(tup);		rebuildDeps = true;		/* get rid of shell type's dependencies */	}	else	{		tup = caql_form_tuple(pcqCtx, values, nulls);						 		if (newtypeOid != InvalidOid)		{			elog(DEBUG5," Setting Oid in new pg_type tuple");
开发者ID:ricky-wu,项目名称:gpdb,代码行数:67,


示例30: PersistentBuild_BuildDb

static int64PersistentBuild_BuildDb(	Oid 		dbOid,	bool 		mirrored){	int64				 count = 0;	Relation			 gp_global_sequence;	Relation			 pg_database;	HeapTuple			 tuple;	HeapScanDesc		 scandesc;	Form_pg_database	 form_pg_database;	DatabaseInfo		*info;	Oid					 defaultTablespace;	int					 t;    bool                 collectGpRelationNodeInfo, collectAppendOnlyCatalogSegmentInfo;	/*	 * Turn this on so we don't try to fetch persistence information from	 * gp_releation_node for gp_relation_node and its index until we've done the	 * assignment with PersistentRelation_AddCreated.	 */	gp_before_persistence_work = true;	/* 	 * If the gp_global_sequence table hasn't been populated yet then we need 	 * to populate it before we can procede with building the rest of the 	 * persistent tables. 	 */	gp_global_sequence = heap_open(GpGlobalSequenceRelationId, RowExclusiveLock);	scandesc = heap_beginscan(gp_global_sequence, SnapshotAny, 0, NULL);	tuple = heap_getnext(scandesc, ForwardScanDirection);	if (!HeapTupleIsValid(tuple))	{		TupleDesc		tupDesc;		Datum			values[Natts_gp_global_sequence];		bool			nulls[Natts_gp_global_sequence];		/* Insert N frozen tuples of value 0 */		tupDesc = RelationGetDescr(gp_global_sequence);		MemSet(nulls, false, sizeof(nulls));		values[Anum_gp_global_sequence_sequence_num-1] = Int64GetDatum(0);		tuple = heap_form_tuple(tupDesc, values, nulls);		if (!HeapTupleIsValid(tuple))			elog(ERROR, "failed to build global sequence tuple");				for (t = 0; t < GpGlobalSequence_MaxSequenceTid; t++)			frozen_heap_insert(gp_global_sequence, tuple);	}	heap_endscan(scandesc);	heap_close(gp_global_sequence, RowExclusiveLock);	/* Lookup the information for the current database */	pg_database = heap_open(DatabaseRelationId, AccessShareLock);	/* Fetch a copy of the tuple to scribble on */	tuple = SearchSysCacheCopy(DATABASEOID,							   ObjectIdGetDatum(dbOid),							   0, 0, 0);	if (!HeapTupleIsValid(tuple))		elog(ERROR, "could not find tuple for database %u", dbOid);	form_pg_database = (Form_pg_database) GETSTRUCT(tuple);		defaultTablespace = form_pg_database->dattablespace;	if (Debug_persistent_print)		elog(Persistent_DebugPrintLevel(), 			 "PersistentBuild_BuildDb: dbOid %u, '%s'",			 dbOid,			 form_pg_database->datname.data);	/*	 * Special call here to scan the persistent meta-data structures so we are open for 	 * business and then we can add information.	 */	PersistentFileSysObj_BuildInitScan();    if (gp_upgrade_mode && (Gp_role == GP_ROLE_DISPATCH || Gp_role == GP_ROLE_UTILITY)){        collectGpRelationNodeInfo = false;        collectAppendOnlyCatalogSegmentInfo = false;    }else{        collectGpRelationNodeInfo = true;        collectAppendOnlyCatalogSegmentInfo = true;    }	info = DatabaseInfo_Collect(							dbOid,							defaultTablespace,                             collectGpRelationNodeInfo,                             collectAppendOnlyCatalogSegmentInfo,							/* scanFileSystem */ true);	for (t = 0; t < info->tablespacesCount; t++)	{		Oid				tablespace = info->tablespaces[t];		DbDirNode		dbDirNode;		ItemPointerData persistentTid;		if (tablespace == GLOBALTABLESPACE_OID)//.........这里部分代码省略.........
开发者ID:PivotalBigData,项目名称:incubator-hawq,代码行数:101,



注:本文中的GETSTRUCT函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ GETU32函数代码示例
C++ GETSHORT函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。