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

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

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

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

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

示例1: ValidateProtocolFunction

/* * ValidateProtocolFunction -- common code for finding readfn, writefn or validatorfn */static OidValidateProtocolFunction(List *fnName, ExtPtcFuncType fntype){	Oid			fnOid;	bool		retset;	bool        retstrict;	bool        retordered;	Oid		   *true_oid_array;	Oid 	    actual_rettype;	Oid			desired_rettype;	FuncDetailCode fdresult;	AclResult	aclresult;	Oid 		inputTypes[1] = {InvalidOid}; /* dummy */	int			nargs = 0; /* true for all 3 function types at the moment */	int			nvargs;		if (fntype == EXTPTC_FUNC_VALIDATOR)		desired_rettype = VOIDOID;	else		desired_rettype = INT4OID;	/*	 * func_get_detail looks up the function in the catalogs, does	 * disambiguation for polymorphic functions, handles inheritance, and	 * returns the funcid and type and set or singleton status of the	 * function's return value.  it also returns the true argument types to	 * the function.	 */	fdresult = func_get_detail(fnName, NIL, nargs, inputTypes, false, false,							   &fnOid, &actual_rettype, &retset, &retstrict,							   &retordered, &nvargs, &true_oid_array, NULL);	/* only valid case is a normal function not returning a set */	if (fdresult != FUNCDETAIL_NORMAL || !OidIsValid(fnOid))		ereport(ERROR,				(errcode(ERRCODE_UNDEFINED_FUNCTION),				 errmsg("function %s does not exist",						func_signature_string(fnName, nargs, inputTypes))));		if (retset)		ereport(ERROR,				(errcode(ERRCODE_DATATYPE_MISMATCH),				 errmsg("Invalid protocol function"),				 errdetail("Protocol functions cannot return sets.")));			if (actual_rettype != desired_rettype)		ereport(ERROR,				(errcode(ERRCODE_DATATYPE_MISMATCH),				 errmsg("%s protocol function %s must return %s",						func_type_to_name(fntype),						func_signature_string(fnName, nargs, inputTypes),						(fntype == EXTPTC_FUNC_VALIDATOR ? "void" : "an integer"))));		if (func_volatile(fnOid) == PROVOLATILE_IMMUTABLE)		ereport(ERROR,				(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),				 errmsg("%s protocol function %s is declared IMMUTABLE",						func_type_to_name(fntype),						func_signature_string(fnName, nargs, inputTypes)),				 errhint("PROTOCOL functions must be declared STABLE or VOLATILE")));		/* Check protocol creator has permission to call the function */	aclresult = pg_proc_aclcheck(fnOid, GetUserId(), ACL_EXECUTE);	if (aclresult != ACLCHECK_OK)		aclcheck_error(aclresult, ACL_KIND_PROC, get_func_name(fnOid));	return fnOid;}
开发者ID:AnLingm,项目名称:gpdb,代码行数:72,


示例2: CreateConversionCommand

/* * CREATE CONVERSION */ObjectAddressCreateConversionCommand(CreateConversionStmt *stmt){	Oid			namespaceId;	char	   *conversion_name;	AclResult	aclresult;	int			from_encoding;	int			to_encoding;	Oid			funcoid;	const char *from_encoding_name = stmt->for_encoding_name;	const char *to_encoding_name = stmt->to_encoding_name;	List	   *func_name = stmt->func_name;	static const Oid funcargs[] = {INT4OID, INT4OID, CSTRINGOID, INTERNALOID, INT4OID};	char		result[1];	/* Convert list of names to a name and namespace */	namespaceId = QualifiedNameGetCreationNamespace(stmt->conversion_name,													&conversion_name);	/* Check we have creation rights in target namespace */	aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_CREATE);	if (aclresult != ACLCHECK_OK)		aclcheck_error(aclresult, ACL_KIND_NAMESPACE,					   get_namespace_name(namespaceId));	/* Check the encoding names */	from_encoding = pg_char_to_encoding(from_encoding_name);	if (from_encoding < 0)		ereport(ERROR,				(errcode(ERRCODE_UNDEFINED_OBJECT),				 errmsg("source encoding /"%s/" does not exist",						from_encoding_name)));	to_encoding = pg_char_to_encoding(to_encoding_name);	if (to_encoding < 0)		ereport(ERROR,				(errcode(ERRCODE_UNDEFINED_OBJECT),				 errmsg("destination encoding /"%s/" does not exist",						to_encoding_name)));	/*	 * Check the existence of the conversion function. Function name could be	 * a qualified name.	 */	funcoid = LookupFuncName(func_name, sizeof(funcargs) / sizeof(Oid),							 funcargs, false);	/* Check it returns VOID, else it's probably the wrong function */	if (get_func_rettype(funcoid) != VOIDOID)		ereport(ERROR,				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),				 errmsg("encoding conversion function %s must return type %s",						NameListToString(func_name), "void")));	/* Check we have EXECUTE rights for the function */	aclresult = pg_proc_aclcheck(funcoid, GetUserId(), ACL_EXECUTE);	if (aclresult != ACLCHECK_OK)		aclcheck_error(aclresult, ACL_KIND_PROC,					   NameListToString(func_name));	/*	 * Check that the conversion function is suitable for the requested source	 * and target encodings. We do that by calling the function with an empty	 * string; the conversion function should throw an error if it can't	 * perform the requested conversion.	 */	OidFunctionCall5(funcoid,					 Int32GetDatum(from_encoding),					 Int32GetDatum(to_encoding),					 CStringGetDatum(""),					 CStringGetDatum(result),					 Int32GetDatum(0));	/*	 * All seem ok, go ahead (possible failure would be a duplicate conversion	 * name)	 */	return ConversionCreate(conversion_name, namespaceId, GetUserId(),							from_encoding, to_encoding, funcoid, stmt->def);}
开发者ID:0x0FFF,项目名称:postgres,代码行数:83,


示例3: pg_stat_get_activity

//.........这里部分代码省略.........		{			/* Get specific pid slot */			beentry = pgstat_fetch_stat_beentry(*(int *) (funcctx->user_fctx));		}		else		{			/* Get the next one in the list */			beentry = pgstat_fetch_stat_beentry(funcctx->call_cntr + 1);		/* 1-based index */		}		if (!beentry)		{			int			i;			for (i = 0; i < sizeof(nulls) / sizeof(nulls[0]); i++)				nulls[i] = true;			nulls[4] = false;			values[4] = CStringGetTextDatum("<backend information not available>");			tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);			SRF_RETURN_NEXT(funcctx, HeapTupleGetDatum(tuple));		}		/* Values available to all callers */		values[0] = ObjectIdGetDatum(beentry->st_databaseid);		values[1] = Int32GetDatum(beentry->st_procpid);		values[2] = ObjectIdGetDatum(beentry->st_userid);		if (beentry->st_appname)			values[3] = CStringGetTextDatum(beentry->st_appname);		else			nulls[3] = true;		/* Values only available to same user or superuser */		if (superuser() || beentry->st_userid == GetUserId())		{			if (*(beentry->st_activity) == '/0')			{				values[4] = CStringGetTextDatum("<command string not enabled>");			}			else			{				values[4] = CStringGetTextDatum(beentry->st_activity);			}			values[5] = BoolGetDatum(beentry->st_waiting);			if (beentry->st_xact_start_timestamp != 0)				values[6] = TimestampTzGetDatum(beentry->st_xact_start_timestamp);			else				nulls[6] = true;			if (beentry->st_activity_start_timestamp != 0)				values[7] = TimestampTzGetDatum(beentry->st_activity_start_timestamp);			else				nulls[7] = true;			if (beentry->st_proc_start_timestamp != 0)				values[8] = TimestampTzGetDatum(beentry->st_proc_start_timestamp);			else				nulls[8] = true;			/* A zeroed client addr means we don't know */			memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));			if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,					   sizeof(zero_clientaddr) == 0))			{
开发者ID:BALDELab,项目名称:incubator-hawq,代码行数:67,


示例4: FinishPreparedTransaction

/* * FinishPreparedTransaction: execute COMMIT PREPARED or ROLLBACK PREPARED */voidFinishPreparedTransaction(const char *gid, bool isCommit){	GlobalTransaction gxact;	TransactionId xid;	char	   *buf;	char	   *bufptr;	TwoPhaseFileHeader *hdr;	TransactionId latestXid;	TransactionId *children;	RelFileNode *commitrels;	RelFileNode *abortrels;	RelFileNode *delrels;	int			ndelrels;	int			i;	/*	 * Validate the GID, and lock the GXACT to ensure that two backends do not	 * try to commit the same GID at once.	 */	gxact = LockGXact(gid, GetUserId());	xid = gxact->proc.xid;	/*	 * Read and validate the state file	 */	buf = ReadTwoPhaseFile(xid);	if (buf == NULL)		ereport(ERROR,				(errcode(ERRCODE_DATA_CORRUPTED),				 errmsg("two-phase state file for transaction %u is corrupt",						xid)));	/*	 * Disassemble the header area	 */	hdr = (TwoPhaseFileHeader *) buf;	Assert(TransactionIdEquals(hdr->xid, xid));	bufptr = buf + MAXALIGN(sizeof(TwoPhaseFileHeader));	children = (TransactionId *) bufptr;	bufptr += MAXALIGN(hdr->nsubxacts * sizeof(TransactionId));	commitrels = (RelFileNode *) bufptr;	bufptr += MAXALIGN(hdr->ncommitrels * sizeof(RelFileNode));	abortrels = (RelFileNode *) bufptr;	bufptr += MAXALIGN(hdr->nabortrels * sizeof(RelFileNode));	/* compute latestXid among all children */	latestXid = TransactionIdLatest(xid, hdr->nsubxacts, children);	/*	 * The order of operations here is critical: make the XLOG entry for	 * commit or abort, then mark the transaction committed or aborted in	 * pg_clog, then remove its PGPROC from the global ProcArray (which means	 * TransactionIdIsInProgress will stop saying the prepared xact is in	 * progress), then run the post-commit or post-abort callbacks. The	 * callbacks will release the locks the transaction held.	 */	if (isCommit)		RecordTransactionCommitPrepared(xid,										hdr->nsubxacts, children,										hdr->ncommitrels, commitrels);	else		RecordTransactionAbortPrepared(xid,									   hdr->nsubxacts, children,									   hdr->nabortrels, abortrels);	ProcArrayRemove(&gxact->proc, latestXid);	/*	 * In case we fail while running the callbacks, mark the gxact invalid so	 * no one else will try to commit/rollback, and so it can be recycled	 * properly later.	It is still locked by our XID so it won't go away yet.	 *	 * (We assume it's safe to do this without taking TwoPhaseStateLock.)	 */	gxact->valid = false;	/*	 * We have to remove any files that were supposed to be dropped. For	 * consistency with the regular xact.c code paths, must do this before	 * releasing locks, so do it before running the callbacks.	 *	 * NB: this code knows that we couldn't be dropping any temp rels ...	 */	if (isCommit)	{		delrels = commitrels;		ndelrels = hdr->ncommitrels;	}	else	{		delrels = abortrels;		ndelrels = hdr->nabortrels;	}	for (i = 0; i < ndelrels; i++)	{		SMgrRelation srel = smgropen(delrels[i]);//.........这里部分代码省略.........
开发者ID:Khalefa,项目名称:VLDB12Demo,代码行数:101,


示例5: NumToStr

void pgUser::ShowDependents(frmMain *form, ctlListView *referencedBy, const wxString &where){    form->StartMsg(_(" Retrieving user owned objects"));    referencedBy->ClearAll();    referencedBy->AddColumn(_("Type"), 60);    referencedBy->AddColumn(_("Database"), 80);    referencedBy->AddColumn(_("Name"), 300);    wxString uid = NumToStr(GetUserId());    wxString sysoid = NumToStr(GetConnection()->GetLastSystemOID());    wxArrayString dblist;    pgSet *set;    if (GetConnection()->BackendMinimumVersion(7, 5))        set = GetConnection()->ExecuteSet(                  wxT("SELECT 'd' as type, datname, datallowconn, datdba/n")                  wxT("  FROM pg_database db/n")                  wxT("UNION/n")                  wxT("SELECT 'M', spcname, null, null/n")                  wxT("  FROM pg_tablespace where spcowner=") + uid + wxT("/n")                  wxT(" ORDER BY 1, 2"));    else        set = GetConnection()->ExecuteSet(                  wxT("SELECT 'd' as type, datname, datallowconn, datdba/n")                  wxT("  FROM pg_database db"));    if (set)    {        while (!set->Eof())        {            wxString name = set->GetVal(wxT("datname"));            if (set->GetVal(wxT("type")) == wxT("d"))            {                if (set->GetBool(wxT("datallowconn")))                    dblist.Add(name);                if (GetUserId() == set->GetLong(wxT("datdba")))                    referencedBy->AppendItem(databaseFactory.GetIconId(), _("Database"), name);            }            else                referencedBy->AppendItem(tablespaceFactory.GetIconId(), _("Tablespace"), wxEmptyString, name);            set->MoveNext();        }        delete set;    }    FillOwned(form->GetBrowser(), referencedBy, dblist,              wxT("SELECT cl.relkind, COALESCE(cin.nspname, cln.nspname) as nspname, COALESCE(ci.relname, cl.relname) as relname, cl.relname as indname/n")              wxT("  FROM pg_class cl/n")              wxT("  JOIN pg_namespace cln ON cl.relnamespace=cln.oid/n")              wxT("  LEFT OUTER JOIN pg_index ind ON ind.indexrelid=cl.oid/n")              wxT("  LEFT OUTER JOIN pg_class ci ON ind.indrelid=ci.oid/n")              wxT("  LEFT OUTER JOIN pg_namespace cin ON ci.relnamespace=cin.oid/n")              wxT(" WHERE cl.relowner = ") + uid + wxT(" AND cl.oid > ") + sysoid + wxT("/n")              wxT("UNION ALL/n")              wxT("SELECT 'n', null, nspname, null/n")              wxT("  FROM pg_namespace nsp WHERE nspowner = ") + uid + wxT(" AND nsp.oid > ") + sysoid + wxT("/n")              wxT("UNION ALL/n")              wxT("SELECT CASE WHEN typtype='d' THEN 'd' ELSE 'y' END, null, typname, null/n")              wxT("  FROM pg_type ty WHERE typowner = ") + uid + wxT(" AND ty.oid > ") + sysoid + wxT("/n")              wxT("UNION ALL/n")              wxT("SELECT 'C', null, conname, null/n")              wxT("  FROM pg_conversion co WHERE conowner = ") + uid + wxT(" AND co.oid > ") + sysoid + wxT("/n")              wxT("UNION ALL/n")              wxT("SELECT CASE WHEN prorettype=") + NumToStr(PGOID_TYPE_TRIGGER) + wxT(" THEN 'T' ELSE 'p' END, null, proname, null/n")              wxT("  FROM pg_proc pr WHERE proowner = ") + uid + wxT(" AND pr.oid > ") + sysoid + wxT("/n")              wxT("UNION ALL/n")              wxT("SELECT 'o', null, oprname || '('::text || ")              wxT("COALESCE(tl.typname, ''::text) || ")              wxT("CASE WHEN tl.oid IS NOT NULL AND tr.oid IS NOT NULL THEN ','::text END || ")              wxT("COALESCE(tr.typname, ''::text) || ')'::text, null/n")              wxT("  FROM pg_operator op/n")              wxT("  LEFT JOIN pg_type tl ON tl.oid=op.oprleft/n")              wxT("  LEFT JOIN pg_type tr ON tr.oid=op.oprright/n")              wxT(" WHERE oprowner = ") + uid + wxT(" AND op.oid > ") + sysoid + wxT("/n")              wxT(" ORDER BY 1,2,3"));    form->EndMsg(set != 0);}
开发者ID:zr40,项目名称:pgadmin3-light,代码行数:81,


示例6: pg_stat_statements

/* * Retrieve statement statistics. */Datumpg_stat_statements(PG_FUNCTION_ARGS){	ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;	TupleDesc	tupdesc;	Tuplestorestate *tupstore;	MemoryContext per_query_ctx;	MemoryContext oldcontext;	Oid			userid = GetUserId();	bool		is_superuser = superuser();	HASH_SEQ_STATUS hash_seq;	pgssEntry  *entry;	if (!pgss || !pgss_hash)		ereport(ERROR,				(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),				 errmsg("pg_stat_statements must be loaded via shared_preload_libraries")));	/* check to see if caller supports us returning a tuplestore */	if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))		ereport(ERROR,				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),				 errmsg("set-valued function called in context that cannot accept a set")));	if (!(rsinfo->allowedModes & SFRM_Materialize))		ereport(ERROR,				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),				 errmsg("materialize mode required, but it is not " /						"allowed in this context")));	/* Build a tuple descriptor for our result type */	if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)		elog(ERROR, "return type must be a row type");	per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;	oldcontext = MemoryContextSwitchTo(per_query_ctx);	tupstore = tuplestore_begin_heap(true, false, work_mem);	rsinfo->returnMode = SFRM_Materialize;	rsinfo->setResult = tupstore;	rsinfo->setDesc = tupdesc;	MemoryContextSwitchTo(oldcontext);	LWLockAcquire(pgss->lock, LW_SHARED);	hash_seq_init(&hash_seq, pgss_hash);	while ((entry = hash_seq_search(&hash_seq)) != NULL)	{		Datum		values[PG_STAT_STATEMENTS_COLS];		bool		nulls[PG_STAT_STATEMENTS_COLS];		int			i = 0;		Counters	tmp;		memset(values, 0, sizeof(values));		memset(nulls, 0, sizeof(nulls));		values[i++] = ObjectIdGetDatum(entry->key.userid);		values[i++] = ObjectIdGetDatum(entry->key.dbid);		if (is_superuser || entry->key.userid == userid)		{			char	   *qstr;			qstr = (char *)				pg_do_encoding_conversion((unsigned char *) entry->query,										  entry->key.query_len,										  entry->key.encoding,										  GetDatabaseEncoding());			values[i++] = CStringGetTextDatum(qstr);			if (qstr != entry->query)				pfree(qstr);		}		else			values[i++] = CStringGetTextDatum("<insufficient privilege>");		/* copy counters to a local variable to keep locking time short */		{			volatile pgssEntry *e = (volatile pgssEntry *) entry;			SpinLockAcquire(&e->mutex);			tmp = e->counters;			SpinLockRelease(&e->mutex);		}		values[i++] = Int64GetDatumFast(tmp.calls);		values[i++] = Float8GetDatumFast(tmp.total_time);		values[i++] = Int64GetDatumFast(tmp.rows);		values[i++] = Int64GetDatumFast(tmp.shared_blks_hit);		values[i++] = Int64GetDatumFast(tmp.shared_blks_read);		values[i++] = Int64GetDatumFast(tmp.shared_blks_written);		values[i++] = Int64GetDatumFast(tmp.local_blks_hit);		values[i++] = Int64GetDatumFast(tmp.local_blks_read);		values[i++] = Int64GetDatumFast(tmp.local_blks_written);		values[i++] = Int64GetDatumFast(tmp.temp_blks_read);		values[i++] = Int64GetDatumFast(tmp.temp_blks_written);		Assert(i == PG_STAT_STATEMENTS_COLS);//.........这里部分代码省略.........
开发者ID:badalex,项目名称:postgresql-scratchpad,代码行数:101,


示例7: DefineAggregate

/* *	DefineAggregate * * "oldstyle" signals the old (pre-8.2) style where the aggregate input type * is specified by a BASETYPE element in the parameters.  Otherwise, * "args" is a pair, whose first element is a list of FunctionParameter structs * defining the agg's arguments (both direct and aggregated), and whose second * element is an Integer node with the number of direct args, or -1 if this * isn't an ordered-set aggregate. * "parameters" is a list of DefElem representing the agg's definition clauses. */ObjectAddressDefineAggregate(List *name, List *args, bool oldstyle, List *parameters,				const char *queryString){	char	   *aggName;	Oid			aggNamespace;	AclResult	aclresult;	char		aggKind = AGGKIND_NORMAL;	List	   *transfuncName = NIL;	List	   *finalfuncName = NIL;	List	   *combinefuncName = NIL;	List	   *serialfuncName = NIL;	List	   *deserialfuncName = NIL;	List	   *mtransfuncName = NIL;	List	   *minvtransfuncName = NIL;	List	   *mfinalfuncName = NIL;	bool		finalfuncExtraArgs = false;	bool		mfinalfuncExtraArgs = false;	List	   *sortoperatorName = NIL;	TypeName   *baseType = NULL;	TypeName   *transType = NULL;	TypeName   *mtransType = NULL;	int32		transSpace = 0;	int32		mtransSpace = 0;	char	   *initval = NULL;	char	   *minitval = NULL;	char	   *parallel = NULL;	int			numArgs;	int			numDirectArgs = 0;	oidvector  *parameterTypes;	ArrayType  *allParameterTypes;	ArrayType  *parameterModes;	ArrayType  *parameterNames;	List	   *parameterDefaults;	Oid			variadicArgType;	Oid			transTypeId;	Oid			mtransTypeId = InvalidOid;	char		transTypeType;	char		mtransTypeType = 0;	char		proparallel = PROPARALLEL_UNSAFE;	ListCell   *pl;	/* Convert list of names to a name and namespace */	aggNamespace = QualifiedNameGetCreationNamespace(name, &aggName);	/* Check we have creation rights in target namespace */	aclresult = pg_namespace_aclcheck(aggNamespace, GetUserId(), ACL_CREATE);	if (aclresult != ACLCHECK_OK)		aclcheck_error(aclresult, ACL_KIND_NAMESPACE,					   get_namespace_name(aggNamespace));	/* Deconstruct the output of the aggr_args grammar production */	if (!oldstyle)	{		Assert(list_length(args) == 2);		numDirectArgs = intVal(lsecond(args));		if (numDirectArgs >= 0)			aggKind = AGGKIND_ORDERED_SET;		else			numDirectArgs = 0;		args = (List *) linitial(args);	}	/* Examine aggregate's definition clauses */	foreach(pl, parameters)	{		DefElem    *defel = (DefElem *) lfirst(pl);		/*		 * sfunc1, stype1, and initcond1 are accepted as obsolete spellings		 * for sfunc, stype, initcond.		 */		if (pg_strcasecmp(defel->defname, "sfunc") == 0)			transfuncName = defGetQualifiedName(defel);		else if (pg_strcasecmp(defel->defname, "sfunc1") == 0)			transfuncName = defGetQualifiedName(defel);		else if (pg_strcasecmp(defel->defname, "finalfunc") == 0)			finalfuncName = defGetQualifiedName(defel);		else if (pg_strcasecmp(defel->defname, "combinefunc") == 0)			combinefuncName = defGetQualifiedName(defel);		else if (pg_strcasecmp(defel->defname, "serialfunc") == 0)			serialfuncName = defGetQualifiedName(defel);		else if (pg_strcasecmp(defel->defname, "deserialfunc") == 0)			deserialfuncName = defGetQualifiedName(defel);		else if (pg_strcasecmp(defel->defname, "msfunc") == 0)			mtransfuncName = defGetQualifiedName(defel);		else if (pg_strcasecmp(defel->defname, "minvfunc") == 0)			minvtransfuncName = defGetQualifiedName(defel);		else if (pg_strcasecmp(defel->defname, "mfinalfunc") == 0)//.........这里部分代码省略.........
开发者ID:0x0FFF,项目名称:postgres,代码行数:101,


示例8: DropTableSpace

/* * Drop a table space * * Be careful to check that the tablespace is empty. */voidDropTableSpace(DropTableSpaceStmt *stmt){#ifdef HAVE_SYMLINK	char	   *tablespacename = stmt->tablespacename;	HeapScanDesc scandesc;	Relation	rel;	HeapTuple	tuple;	ScanKeyData entry[1];	Oid			tablespaceoid;	/*	 * Find the target tuple	 */	rel = heap_open(TableSpaceRelationId, RowExclusiveLock);	ScanKeyInit(&entry[0],				Anum_pg_tablespace_spcname,				BTEqualStrategyNumber, F_NAMEEQ,				CStringGetDatum(tablespacename));	scandesc = heap_beginscan_catalog(rel, 1, entry);	tuple = heap_getnext(scandesc, ForwardScanDirection);	if (!HeapTupleIsValid(tuple))	{		if (!stmt->missing_ok)		{			ereport(ERROR,					(errcode(ERRCODE_UNDEFINED_OBJECT),					 errmsg("tablespace /"%s/" does not exist",							tablespacename)));		}		else		{			ereport(NOTICE,					(errmsg("tablespace /"%s/" does not exist, skipping",							tablespacename)));			/* XXX I assume I need one or both of these next two calls */			heap_endscan(scandesc);			heap_close(rel, NoLock);		}		return;	}	tablespaceoid = HeapTupleGetOid(tuple);	/* Must be tablespace owner */	if (!pg_tablespace_ownercheck(tablespaceoid, GetUserId()))		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TABLESPACE,					   tablespacename);	/* Disallow drop of the standard tablespaces, even by superuser */	if (tablespaceoid == GLOBALTABLESPACE_OID ||		tablespaceoid == DEFAULTTABLESPACE_OID)		aclcheck_error(ACLCHECK_NO_PRIV, ACL_KIND_TABLESPACE,					   tablespacename);	/* DROP hook for the tablespace being removed */	InvokeObjectDropHook(TableSpaceRelationId, tablespaceoid, 0);	/*	 * Remove the pg_tablespace tuple (this will roll back if we fail below)	 */	simple_heap_delete(rel, &tuple->t_self);	heap_endscan(scandesc);	/*	 * Remove any comments or security labels on this tablespace.	 */	DeleteSharedComments(tablespaceoid, TableSpaceRelationId);	DeleteSharedSecurityLabel(tablespaceoid, TableSpaceRelationId);	/*	 * Remove dependency on owner.	 */	deleteSharedDependencyRecordsFor(TableSpaceRelationId, tablespaceoid, 0);	/*	 * Acquire TablespaceCreateLock to ensure that no TablespaceCreateDbspace	 * is running concurrently.	 */	LWLockAcquire(TablespaceCreateLock, LW_EXCLUSIVE);	/*	 * Try to remove the physical infrastructure.	 */	if (!destroy_tablespace_directories(tablespaceoid, false))	{		/*		 * Not all files deleted?  However, there can be lingering empty files		 * in the directories, left behind by for example DROP TABLE, that		 * have been scheduled for deletion at next checkpoint (see comments		 * in mdunlink() for details).  We could just delete them immediately,		 * but we can't tell them apart from important data files that we//.........这里部分代码省略.........
开发者ID:HyukjinKwon,项目名称:pipelinedb,代码行数:101,


示例9: 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:HyukjinKwon,项目名称:pipelinedb,代码行数:76,


示例10: check_temp_tablespaces

/* check_hook: validate new temp_tablespaces */boolcheck_temp_tablespaces(char **newval, void **extra, GucSource source){	char	   *rawname;	List	   *namelist;	/* Need a modifiable copy of string */	rawname = pstrdup(*newval);	/* Parse string into list of identifiers */	if (!SplitIdentifierString(rawname, ',', &namelist))	{		/* syntax error in name list */		GUC_check_errdetail("List syntax is invalid.");		pfree(rawname);		list_free(namelist);		return false;	}	/*	 * If we aren't inside a transaction, we cannot do database access so	 * cannot verify the individual names.  Must accept the list on faith.	 * Fortunately, there's then also no need to pass the data to fd.c.	 */	if (IsTransactionState())	{		temp_tablespaces_extra *myextra;		Oid		   *tblSpcs;		int			numSpcs;		ListCell   *l;		/* temporary workspace until we are done verifying the list */		tblSpcs = (Oid *) palloc(list_length(namelist) * sizeof(Oid));		numSpcs = 0;		foreach(l, namelist)		{			char	   *curname = (char *) lfirst(l);			Oid			curoid;			AclResult	aclresult;			/* Allow an empty string (signifying database default) */			if (curname[0] == '/0')			{				tblSpcs[numSpcs++] = InvalidOid;				continue;			}			/*			 * In an interactive SET command, we ereport for bad info.  When			 * source == PGC_S_TEST, don't throw a hard error for a			 * nonexistent tablespace, only a NOTICE.  See comments in guc.h.			 */			curoid = get_tablespace_oid(curname, source <= PGC_S_TEST);			if (curoid == InvalidOid)			{				if (source == PGC_S_TEST)					ereport(NOTICE,							(errcode(ERRCODE_UNDEFINED_OBJECT),							 errmsg("tablespace /"%s/" does not exist",									curname)));				continue;			}			/*			 * Allow explicit specification of database's default tablespace			 * in temp_tablespaces without triggering permissions checks.			 */			if (curoid == MyDatabaseTableSpace)			{				tblSpcs[numSpcs++] = InvalidOid;				continue;			}			/* Check permissions, similarly complaining only if interactive */			aclresult = pg_tablespace_aclcheck(curoid, GetUserId(),											   ACL_CREATE);			if (aclresult != ACLCHECK_OK)			{				if (source >= PGC_S_INTERACTIVE)					aclcheck_error(aclresult, ACL_KIND_TABLESPACE, curname);				continue;			}			tblSpcs[numSpcs++] = curoid;		}		/* Now prepare an "extra" struct for assign_temp_tablespaces */		myextra = malloc(offsetof(temp_tablespaces_extra, tblSpcs) +						 numSpcs * sizeof(Oid));		if (!myextra)			return false;		myextra->numSpcs = numSpcs;		memcpy(myextra->tblSpcs, tblSpcs, numSpcs * sizeof(Oid));		*extra = (void *) myextra;		pfree(tblSpcs);	}
开发者ID:HyukjinKwon,项目名称:pipelinedb,代码行数:98,


示例11: CreateTableSpace

/* * Create a table space * * Only superusers can create a tablespace. This seems a reasonable restriction * since we're determining the system layout and, anyway, we probably have * root if we're doing this kind of activity */OidCreateTableSpace(CreateTableSpaceStmt *stmt){#ifdef HAVE_SYMLINK	Relation	rel;	Datum		values[Natts_pg_tablespace];	bool		nulls[Natts_pg_tablespace];	HeapTuple	tuple;	Oid			tablespaceoid;	char	   *location;	Oid			ownerId;	Datum		newOptions;	/* Must be super user */	if (!superuser())		ereport(ERROR,				(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),				 errmsg("permission denied to create tablespace /"%s/"",						stmt->tablespacename),				 errhint("Must be superuser to create a tablespace.")));	/* However, the eventual owner of the tablespace need not be */	if (stmt->owner)		ownerId = get_rolespec_oid(stmt->owner, false);	else		ownerId = GetUserId();	/* Unix-ify the offered path, and strip any trailing slashes */	location = pstrdup(stmt->location);	canonicalize_path(location);	/* disallow quotes, else CREATE DATABASE would be at risk */	if (strchr(location, '/''))		ereport(ERROR,				(errcode(ERRCODE_INVALID_NAME),				 errmsg("tablespace location cannot contain single quotes")));	/*	 * Allowing relative paths seems risky	 *	 * this also helps us ensure that location is not empty or whitespace	 */	if (!is_absolute_path(location))		ereport(ERROR,				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),				 errmsg("tablespace location must be an absolute path")));	/*	 * Check that location isn't too long. Remember that we're going to append	 * 'PG_XXX/<dboid>/<relid>_<fork>.<nnn>'.  FYI, we never actually	 * reference the whole path here, but mkdir() uses the first two parts.	 */	if (strlen(location) + 1 + strlen(TABLESPACE_VERSION_DIRECTORY) + 1 +	  OIDCHARS + 1 + OIDCHARS + 1 + FORKNAMECHARS + 1 + OIDCHARS > MAXPGPATH)		ereport(ERROR,				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),				 errmsg("tablespace location /"%s/" is too long",						location)));	/* Warn if the tablespace is in the data directory. */	if (path_is_prefix_of_path(DataDir, location))		ereport(WARNING,				(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),				 errmsg("tablespace location should not be inside the data directory")));	/*	 * Disallow creation of tablespaces named "pg_xxx"; we reserve this	 * namespace for system purposes.	 */	if (!allowSystemTableMods && IsReservedName(stmt->tablespacename))		ereport(ERROR,				(errcode(ERRCODE_RESERVED_NAME),				 errmsg("unacceptable tablespace name /"%s/"",						stmt->tablespacename),		errdetail("The prefix /"pg_/" is reserved for system tablespaces.")));	/*	 * Check that there is no other tablespace by this name.  (The unique	 * index would catch this anyway, but might as well give a friendlier	 * message.)	 */	if (OidIsValid(get_tablespace_oid(stmt->tablespacename, true)))		ereport(ERROR,				(errcode(ERRCODE_DUPLICATE_OBJECT),				 errmsg("tablespace /"%s/" already exists",						stmt->tablespacename)));	/*	 * Insert tuple into pg_tablespace.  The purpose of doing this first is to	 * lock the proposed tablename against other would-be creators. The	 * insertion will roll back if we find problems below.	 */	rel = heap_open(TableSpaceRelationId, RowExclusiveLock);//.........这里部分代码省略.........
开发者ID:HyukjinKwon,项目名称:pipelinedb,代码行数:101,


示例12: lookup_agg_function

/* * lookup_agg_function * common code for finding aggregate support functions * * fnName: possibly-schema-qualified function name * nargs, input_types: expected function argument types * variadicArgType: type of variadic argument if any, else InvalidOid * * Returns OID of function, and stores its return type into *rettype * * NB: must not scribble on input_types[], as we may re-use those */static Oidlookup_agg_function(List *fnName,					int nargs,					Oid *input_types,					Oid variadicArgType,					Oid *rettype){	Oid			fnOid;	bool		retset;	int			nvargs;	Oid			vatype;	Oid		   *true_oid_array;	FuncDetailCode fdresult;	AclResult	aclresult;	int			i;	/*	 * func_get_detail looks up the function in the catalogs, does	 * disambiguation for polymorphic functions, handles inheritance, and	 * returns the funcid and type and set or singleton status of the	 * function's return value.  it also returns the true argument types to	 * the function.	 */	fdresult = func_get_detail(fnName, NIL, NIL,							   nargs, input_types, false, false,							   &fnOid, rettype, &retset,							   &nvargs, &vatype,							   &true_oid_array, NULL);	/* only valid case is a normal function not returning a set */	if (fdresult != FUNCDETAIL_NORMAL || !OidIsValid(fnOid))		ereport(ERROR,				(errcode(ERRCODE_UNDEFINED_FUNCTION),				 errmsg("function %s does not exist",						func_signature_string(fnName, nargs,											  NIL, input_types))));	if (retset)		ereport(ERROR,				(errcode(ERRCODE_DATATYPE_MISMATCH),				 errmsg("function %s returns a set",						func_signature_string(fnName, nargs,											  NIL, input_types))));	/*	 * If the agg is declared to take VARIADIC ANY, the underlying functions	 * had better be declared that way too, else they may receive too many	 * parameters; but func_get_detail would have been happy with plain ANY.	 * (Probably nothing very bad would happen, but it wouldn't work as the	 * user expects.)  Other combinations should work without any special	 * pushups, given that we told func_get_detail not to expand VARIADIC.	 */	if (variadicArgType == ANYOID && vatype != ANYOID)		ereport(ERROR,				(errcode(ERRCODE_DATATYPE_MISMATCH),				 errmsg("function %s must accept VARIADIC ANY to be used in this aggregate",						func_signature_string(fnName, nargs,											  NIL, input_types))));	/*	 * If there are any polymorphic types involved, enforce consistency, and	 * possibly refine the result type.  It's OK if the result is still	 * polymorphic at this point, though.	 */	*rettype = enforce_generic_type_consistency(input_types,												true_oid_array,												nargs,												*rettype,												true);	/*	 * func_get_detail will find functions requiring run-time argument type	 * coercion, but nodeAgg.c isn't prepared to deal with that	 */	for (i = 0; i < nargs; i++)	{		if (!IsBinaryCoercible(input_types[i], true_oid_array[i]))			ereport(ERROR,					(errcode(ERRCODE_DATATYPE_MISMATCH),					 errmsg("function %s requires run-time type coercion",							func_signature_string(fnName, nargs,												  NIL, true_oid_array))));	}	/* Check aggregate creator has permission to call the function */	aclresult = pg_proc_aclcheck(fnOid, GetUserId(), ACL_EXECUTE);	if (aclresult != ACLCHECK_OK)		aclcheck_error(aclresult, OBJECT_FUNCTION, get_func_name(fnOid));//.........这里部分代码省略.........
开发者ID:adityavs,项目名称:postgres,代码行数:101,


示例13: AggregateCreate

//.........这里部分代码省略.........		else		{			/*			 * If no finalfn, aggregate result type is type of the state value			 */			rettype = aggmTransType;		}		Assert(OidIsValid(rettype));		if (rettype != finaltype)			ereport(ERROR,					(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),					 errmsg("moving-aggregate implementation returns type %s, but plain implementation returns type %s",							format_type_be(aggmTransType),							format_type_be(aggTransType))));	}	/* handle sortop, if supplied */	if (aggsortopName)	{		if (numArgs != 1)			ereport(ERROR,					(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),					 errmsg("sort operator can only be specified for single-argument aggregates")));		sortop = LookupOperName(NULL, aggsortopName,								aggArgTypes[0], aggArgTypes[0],								false, -1);	}	/*	 * permission checks on used types	 */	for (i = 0; i < numArgs; i++)	{		aclresult = pg_type_aclcheck(aggArgTypes[i], GetUserId(), ACL_USAGE);		if (aclresult != ACLCHECK_OK)			aclcheck_error_type(aclresult, aggArgTypes[i]);	}	aclresult = pg_type_aclcheck(aggTransType, GetUserId(), ACL_USAGE);	if (aclresult != ACLCHECK_OK)		aclcheck_error_type(aclresult, aggTransType);	if (OidIsValid(aggmTransType))	{		aclresult = pg_type_aclcheck(aggmTransType, GetUserId(), ACL_USAGE);		if (aclresult != ACLCHECK_OK)			aclcheck_error_type(aclresult, aggmTransType);	}	aclresult = pg_type_aclcheck(finaltype, GetUserId(), ACL_USAGE);	if (aclresult != ACLCHECK_OK)		aclcheck_error_type(aclresult, finaltype);	/*	 * Everything looks okay.  Try to create the pg_proc entry for the	 * aggregate.  (This could fail if there's already a conflicting entry.)	 */	myself = ProcedureCreate(aggName,							 aggNamespace,							 false, /* no replacement */							 false, /* doesn't return a set */							 finaltype, /* returnType */							 GetUserId(),	/* proowner */							 INTERNALlanguageId,	/* languageObjectId */
开发者ID:adityavs,项目名称:postgres,代码行数:67,


示例14: ExtProtocolCreateWithOid

/* * ExtProtocolCreateWithOid */OidExtProtocolCreateWithOid(const char		*protocolName,					     List			*readfuncName,					     List			*writefuncName,					     List			*validatorfuncName,					   					     Oid			 protOid,					     bool			 trusted){	Relation	rel;	HeapTuple	tup;	bool		nulls[Natts_pg_extprotocol];	Datum		values[Natts_pg_extprotocol];	Oid			readfn = InvalidOid;	Oid			writefn = InvalidOid;	Oid			validatorfn = InvalidOid;	NameData	prtname;	int			i;	ObjectAddress myself,				referenced;	Oid 		ownerId = GetUserId();	cqContext	cqc;	cqContext	cqc2;	cqContext  *pcqCtx;	/* sanity checks (caller should have caught these) */	if (!protocolName)		elog(ERROR, "no protocol name supplied");	if (!readfuncName && !writefuncName)		elog(ERROR, "protocol must have at least one of readfunc or writefunc");	/*	 * Until we add system protocols to pg_extprotocol, make sure no	 * protocols with the same name are created.	 */	if (strcasecmp(protocolName, "file") == 0 ||		strcasecmp(protocolName, "http") == 0 ||		strcasecmp(protocolName, "gpfdist") == 0 ||		strcasecmp(protocolName, "gpfdists") == 0)	{		ereport(ERROR,				(errcode(ERRCODE_RESERVED_NAME),				 errmsg("protocol /"%s/" already exists",						 protocolName),				 errhint("pick a different protocol name")));	}	rel = heap_open(ExtprotocolRelationId, RowExclusiveLock);	pcqCtx = caql_beginscan(			caql_addrel(cqclr(&cqc), rel),			cql("INSERT INTO pg_extprotocol",				NULL));	/* make sure there is no existing protocol of same name */	if (caql_getcount(				caql_addrel(cqclr(&cqc2), rel),				cql("SELECT COUNT(*) FROM pg_extprotocol "					" WHERE ptcname = :1 ",					CStringGetDatum((char *) protocolName))))	{		ereport(ERROR,				(errcode(ERRCODE_DUPLICATE_OBJECT),				 errmsg("protocol /"%s/" already exists", 						protocolName)));	}	/*	 * function checks: if supplied, check existence and correct signature in the catalog	 */		if (readfuncName)		readfn = ValidateProtocolFunction(readfuncName, EXTPTC_FUNC_READER);	if (writefuncName)		writefn = ValidateProtocolFunction(writefuncName, EXTPTC_FUNC_WRITER);					if (validatorfuncName)		validatorfn = ValidateProtocolFunction(validatorfuncName, EXTPTC_FUNC_VALIDATOR);	/*	 * Everything looks okay.  Try to create the pg_extprotocol entry for the	 * protocol.  (This could fail if there's already a conflicting entry.)	 */	/* initialize nulls and values */	for (i = 0; i < Natts_pg_extprotocol; i++)	{		nulls[i] = false;		values[i] = (Datum) 0;	}	namestrcpy(&prtname, protocolName);	values[Anum_pg_extprotocol_ptcname - 1] = NameGetDatum(&prtname);	values[Anum_pg_extprotocol_ptcreadfn - 1] = ObjectIdGetDatum(readfn);	values[Anum_pg_extprotocol_ptcwritefn - 1] = ObjectIdGetDatum(writefn);	values[Anum_pg_extprotocol_ptcvalidatorfn - 1] = ObjectIdGetDatum(validatorfn);	values[Anum_pg_extprotocol_ptcowner - 1] = ObjectIdGetDatum(ownerId);//.........这里部分代码省略.........
开发者ID:AnLingm,项目名称:gpdb,代码行数:101,


示例15: BuildDescForRelation

/* * BuildDescForRelation * * Given a relation schema (list of ColumnDef nodes), build a TupleDesc. * * Note: the default assumption is no OIDs; caller may modify the returned * TupleDesc if it wants OIDs.  Also, tdtypeid will need to be filled in * later on. */TupleDescBuildDescForRelation(List *schema){	int			natts;	AttrNumber	attnum;	ListCell   *l;	TupleDesc	desc;	bool		has_not_null;	char	   *attname;	Oid			atttypid;	int32		atttypmod;	Oid			attcollation;	int			attdim;	/*	 * allocate a new tuple descriptor	 */	natts = list_length(schema);	desc = CreateTemplateTupleDesc(natts, false);	has_not_null = false;	attnum = 0;	foreach(l, schema)	{		ColumnDef  *entry = lfirst(l);		AclResult	aclresult;		/*		 * for each entry in the list, get the name and type information from		 * the list and have TupleDescInitEntry fill in the attribute		 * information we need.		 */		attnum++;		attname = entry->colname;		typenameTypeIdAndMod(NULL, entry->typeName, &atttypid, &atttypmod);		aclresult = pg_type_aclcheck(atttypid, GetUserId(), ACL_USAGE);		if (aclresult != ACLCHECK_OK)			aclcheck_error_type(aclresult, atttypid);		attcollation = GetColumnDefCollation(NULL, entry, atttypid);		attdim = list_length(entry->typeName->arrayBounds);		if (entry->typeName->setof)			ereport(ERROR,					(errcode(ERRCODE_INVALID_TABLE_DEFINITION),					 errmsg("column /"%s/" cannot be declared SETOF",							attname)));		TupleDescInitEntry(desc, attnum, attname,						   atttypid, atttypmod, attdim);		/* Override TupleDescInitEntry's settings as requested */		TupleDescInitEntryCollation(desc, attnum, attcollation);		if (entry->storage)			desc->attrs[attnum - 1]->attstorage = entry->storage;		/* Fill in additional stuff not handled by TupleDescInitEntry */		desc->attrs[attnum - 1]->attnotnull = entry->is_not_null;		has_not_null |= entry->is_not_null;		desc->attrs[attnum - 1]->attislocal = entry->is_local;		desc->attrs[attnum - 1]->attinhcount = entry->inhcount;	}
开发者ID:adam8157,项目名称:gpdb,代码行数:74,


示例16: AlterTableSpaceOptions

/* * Alter table space options */OidAlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt){	Relation	rel;	ScanKeyData entry[1];	HeapScanDesc scandesc;	HeapTuple	tup;	Oid			tablespaceoid;	Datum		datum;	Datum		newOptions;	Datum		repl_val[Natts_pg_tablespace];	bool		isnull;	bool		repl_null[Natts_pg_tablespace];	bool		repl_repl[Natts_pg_tablespace];	HeapTuple	newtuple;	/* Search pg_tablespace */	rel = heap_open(TableSpaceRelationId, RowExclusiveLock);	ScanKeyInit(&entry[0],				Anum_pg_tablespace_spcname,				BTEqualStrategyNumber, F_NAMEEQ,				CStringGetDatum(stmt->tablespacename));	scandesc = heap_beginscan_catalog(rel, 1, entry);	tup = heap_getnext(scandesc, ForwardScanDirection);	if (!HeapTupleIsValid(tup))		ereport(ERROR,				(errcode(ERRCODE_UNDEFINED_OBJECT),				 errmsg("tablespace /"%s/" does not exist",						stmt->tablespacename)));	tablespaceoid = HeapTupleGetOid(tup);	/* Must be owner of the existing object */	if (!pg_tablespace_ownercheck(HeapTupleGetOid(tup), GetUserId()))		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TABLESPACE,					   stmt->tablespacename);	/* Generate new proposed spcoptions (text array) */	datum = heap_getattr(tup, Anum_pg_tablespace_spcoptions,						 RelationGetDescr(rel), &isnull);	newOptions = transformRelOptions(isnull ? (Datum) 0 : datum,									 stmt->options, NULL, NULL, false,									 stmt->isReset);	(void) tablespace_reloptions(newOptions, true);	/* Build new tuple. */	memset(repl_null, false, sizeof(repl_null));	memset(repl_repl, false, sizeof(repl_repl));	if (newOptions != (Datum) 0)		repl_val[Anum_pg_tablespace_spcoptions - 1] = newOptions;	else		repl_null[Anum_pg_tablespace_spcoptions - 1] = true;	repl_repl[Anum_pg_tablespace_spcoptions - 1] = true;	newtuple = heap_modify_tuple(tup, RelationGetDescr(rel), repl_val,								 repl_null, repl_repl);	/* Update system catalog. */	simple_heap_update(rel, &newtuple->t_self, newtuple);	CatalogUpdateIndexes(rel, newtuple);	InvokeObjectPostAlterHook(TableSpaceRelationId, HeapTupleGetOid(tup), 0);	heap_freetuple(newtuple);	/* Conclude heap scan. */	heap_endscan(scandesc);	heap_close(rel, NoLock);	return tablespaceoid;}
开发者ID:HyukjinKwon,项目名称:pipelinedb,代码行数:74,


示例17: pgss_store

/* * Store some statistics for a statement. */static voidpgss_store(const char *query, double total_time, uint64 rows,		   const BufferUsage *bufusage){	pgssHashKey key;	double		usage;	pgssEntry  *entry;	Assert(query != NULL);	/* Safety check... */	if (!pgss || !pgss_hash)		return;	/* Set up key for hashtable search */	key.userid = GetUserId();	key.dbid = MyDatabaseId;	key.encoding = GetDatabaseEncoding();	key.query_len = strlen(query);	if (key.query_len >= pgss->query_size)		key.query_len = pg_encoding_mbcliplen(key.encoding,											  query,											  key.query_len,											  pgss->query_size - 1);	key.query_ptr = query;	usage = USAGE_EXEC(duration);	/* Lookup the hash table entry with shared lock. */	LWLockAcquire(pgss->lock, LW_SHARED);	entry = (pgssEntry *) hash_search(pgss_hash, &key, HASH_FIND, NULL);	if (!entry)	{		/* Must acquire exclusive lock to add a new entry. */		LWLockRelease(pgss->lock);		LWLockAcquire(pgss->lock, LW_EXCLUSIVE);		entry = entry_alloc(&key);	}	/* Grab the spinlock while updating the counters. */	{		volatile pgssEntry *e = (volatile pgssEntry *) entry;		SpinLockAcquire(&e->mutex);		e->counters.calls += 1;		e->counters.total_time += total_time;		e->counters.rows += rows;		e->counters.shared_blks_hit += bufusage->shared_blks_hit;		e->counters.shared_blks_read += bufusage->shared_blks_read;		e->counters.shared_blks_written += bufusage->shared_blks_written;		e->counters.local_blks_hit += bufusage->local_blks_hit;		e->counters.local_blks_read += bufusage->local_blks_read;		e->counters.local_blks_written += bufusage->local_blks_written;		e->counters.temp_blks_read += bufusage->temp_blks_read;		e->counters.temp_blks_written += bufusage->temp_blks_written;		e->counters.usage += usage;		SpinLockRelease(&e->mutex);	}	LWLockRelease(pgss->lock);}
开发者ID:badalex,项目名称:postgresql-scratchpad,代码行数:65,


示例18: calculate_tablespace_size

/* * Calculate total size of tablespace. Returns -1 if the tablespace directory * cannot be found. */static int64calculate_tablespace_size(Oid tblspcOid){	char		tblspcPath[MAXPGPATH];	char		pathname[MAXPGPATH];	int64		totalsize = 0;	DIR		   *dirdesc;	struct dirent *direntry;	AclResult	aclresult;	/*	 * User must have CREATE privilege for target tablespace, either	 * explicitly granted or implicitly because it is default for current	 * database.	 */	if (tblspcOid != MyDatabaseTableSpace)	{		aclresult = pg_tablespace_aclcheck(tblspcOid, GetUserId(), ACL_CREATE);		if (aclresult != ACLCHECK_OK)			aclcheck_error(aclresult, ACL_KIND_TABLESPACE,						   get_tablespace_name(tblspcOid));	}	if (tblspcOid == DEFAULTTABLESPACE_OID)		snprintf(tblspcPath, MAXPGPATH, "base");	else if (tblspcOid == GLOBALTABLESPACE_OID)		snprintf(tblspcPath, MAXPGPATH, "global");	else		snprintf(tblspcPath, MAXPGPATH, "pg_tblspc/%u/%s", tblspcOid,				 TABLESPACE_VERSION_DIRECTORY);	dirdesc = AllocateDir(tblspcPath);	if (!dirdesc)		return -1;	while ((direntry = ReadDir(dirdesc, tblspcPath)) != NULL)	{		struct stat fst;		CHECK_FOR_INTERRUPTS();		if (strcmp(direntry->d_name, ".") == 0 ||			strcmp(direntry->d_name, "..") == 0)			continue;		snprintf(pathname, MAXPGPATH, "%s/%s", tblspcPath, direntry->d_name);		if (stat(pathname, &fst) < 0)		{			if (errno == ENOENT)				continue;			else				ereport(ERROR,						(errcode_for_file_access(),						 errmsg("could not stat file /"%s/": %m", pathname)));		}		if (S_ISDIR(fst.st_mode))			totalsize += db_dir_size(pathname);		totalsize += fst.st_size;	}	FreeDir(dirdesc);	return totalsize;}
开发者ID:Richard2ndQuadrant,项目名称:postgres,代码行数:72,


示例19: superuser

/* * The Postgres user running this command has Postgres superuser privileges */boolsuperuser(void){	return superuser_arg(GetUserId());}
开发者ID:Epictetus,项目名称:postgres,代码行数:8,


示例20: DefineAggregate

/* *	DefineAggregate * * "oldstyle" signals the old (pre-8.2) style where the aggregate input type * is specified by a BASETYPE element in the parameters.  Otherwise, * "args" defines the input type(s). */voidDefineAggregate(List *name, List *args, bool oldstyle, List *parameters, 				Oid newOid, bool ordered){	char	   *aggName;	Oid			aggNamespace;	AclResult	aclresult;	List	   *transfuncName = NIL;	List	   *prelimfuncName = NIL; /* MPP */	List	   *finalfuncName = NIL;	List	   *sortoperatorName = NIL;	TypeName   *baseType = NULL;	TypeName   *transType = NULL;	char	   *initval = NULL;	Oid		   *aggArgTypes;	int			numArgs;	Oid			transTypeId;	ListCell   *pl;	Oid			aggOid;	/* Convert list of names to a name and namespace */	aggNamespace = QualifiedNameGetCreationNamespace(name, &aggName);	/* Check we have creation rights in target namespace */	aclresult = pg_namespace_aclcheck(aggNamespace, GetUserId(), ACL_CREATE);	if (aclresult != ACLCHECK_OK)		aclcheck_error(aclresult, ACL_KIND_NAMESPACE,					   get_namespace_name(aggNamespace));	foreach(pl, parameters)	{		DefElem    *defel = (DefElem *) lfirst(pl);		/*		 * sfunc1, stype1, and initcond1 are accepted as obsolete spellings		 * for sfunc, stype, initcond.		 */		if (pg_strcasecmp(defel->defname, "sfunc") == 0)			transfuncName = defGetQualifiedName(defel);		else if (pg_strcasecmp(defel->defname, "sfunc1") == 0)			transfuncName = defGetQualifiedName(defel);		else if (pg_strcasecmp(defel->defname, "finalfunc") == 0)			finalfuncName = defGetQualifiedName(defel);		else if (pg_strcasecmp(defel->defname, "sortop") == 0)			sortoperatorName = defGetQualifiedName(defel);		else if (pg_strcasecmp(defel->defname, "basetype") == 0)			baseType = defGetTypeName(defel);		else if (pg_strcasecmp(defel->defname, "stype") == 0)			transType = defGetTypeName(defel);		else if (pg_strcasecmp(defel->defname, "stype1") == 0)			transType = defGetTypeName(defel);		else if (pg_strcasecmp(defel->defname, "initcond") == 0)			initval = defGetString(defel);		else if (pg_strcasecmp(defel->defname, "initcond1") == 0)			initval = defGetString(defel);		else if (pg_strcasecmp(defel->defname, "prefunc") == 0) /* MPP */			prelimfuncName = defGetQualifiedName(defel);		else			ereport(WARNING,					(errcode(ERRCODE_SYNTAX_ERROR),					 errmsg("aggregate attribute /"%s/" not recognized",							defel->defname)));	}
开发者ID:chrishajas,项目名称:gpdb,代码行数:70,


示例21: CommentObject

/* * CommentObject -- * * This routine is used to add the associated comment into * pg_description for the object specified by the given SQL command. */OidCommentObject(CommentStmt *stmt){	ObjectAddress address;	Relation	relation;	/*	 * When loading a dump, we may see a COMMENT ON DATABASE for the old name	 * of the database.  Erroring out would prevent pg_restore from completing	 * (which is really pg_restore's fault, but for now we will work around	 * the problem here).  Consensus is that the best fix is to treat wrong	 * database name as a WARNING not an ERROR; hence, the following special	 * case.  (If the length of stmt->objname is not 1, get_object_address	 * will throw an error below; that's OK.)	 */	if (stmt->objtype == OBJECT_DATABASE && list_length(stmt->objname) == 1)	{		char	   *database = strVal(linitial(stmt->objname));		if (!OidIsValid(get_database_oid(database, true)))		{			ereport(WARNING,					(errcode(ERRCODE_UNDEFINED_DATABASE),					 errmsg("database /"%s/" does not exist", database)));			return InvalidOid;		}	}	/*	 * Translate the parser representation that identifies this object into an	 * ObjectAddress.  get_object_address() will throw an error if the object	 * does not exist, and will also acquire a lock on the target to guard	 * against concurrent DROP operations.	 */	address = get_object_address(stmt->objtype, stmt->objname, stmt->objargs,								 &relation, ShareUpdateExclusiveLock, false);	/* Require ownership of the target object. */	check_object_ownership(GetUserId(), stmt->objtype, address,						   stmt->objname, stmt->objargs, relation);	/* Perform other integrity checks as needed. */	switch (stmt->objtype)	{		case OBJECT_COLUMN:			/*			 * Allow comments only on columns of tables, views, composite			 * types, and foreign tables (which are the only relkinds for			 * which pg_dump will dump per-column comments).  In particular we			 * wish to disallow comments on index columns, because the naming			 * of an index's columns may change across PG versions, so dumping			 * per-column comments could create reload failures.			 */			if (relation->rd_rel->relkind != RELKIND_RELATION &&				relation->rd_rel->relkind != RELKIND_VIEW &&				relation->rd_rel->relkind != RELKIND_COMPOSITE_TYPE &&				relation->rd_rel->relkind != RELKIND_FOREIGN_TABLE)				ereport(ERROR,						(errcode(ERRCODE_WRONG_OBJECT_TYPE),						 errmsg("/"%s/" is not a table, view, composite type, or foreign table",								RelationGetRelationName(relation))));			break;		default:			break;	}	/*	 * Databases, tablespaces, and roles are cluster-wide objects, so any	 * comments on those objects are recorded in the shared pg_shdescription	 * catalog.  Comments on all other objects are recorded in pg_description.	 */	if (stmt->objtype == OBJECT_DATABASE || stmt->objtype == OBJECT_TABLESPACE		|| stmt->objtype == OBJECT_ROLE)		CreateSharedComments(address.objectId, address.classId, stmt->comment);	else		CreateComments(address.objectId, address.classId, address.objectSubId,					   stmt->comment);	/*	 * If get_object_address() opened the relation for us, we close it to keep	 * the reference count correct - but we retain any locks acquired by	 * get_object_address() until commit time, to guard against concurrent	 * activity.	 */	if (relation != NULL)		relation_close(relation, NoLock);	return address.objectId;}
开发者ID:bwright,项目名称:postgres,代码行数:96,


示例22: DefineOperator

/* * DefineOperator *		this function extracts all the information from the *		parameter list generated by the parser and then has *		OperatorCreate() do all the actual work. * * 'parameters' is a list of DefElem */ObjectAddressDefineOperator(List *names, List *parameters){	char	   *oprName;	Oid			oprNamespace;	AclResult	aclresult;	bool		canMerge = false;		/* operator merges */	bool		canHash = false;	/* operator hashes */	List	   *functionName = NIL;		/* function for operator */	TypeName   *typeName1 = NULL;		/* first type name */	TypeName   *typeName2 = NULL;		/* second type name */	Oid			typeId1 = InvalidOid;	/* types converted to OID */	Oid			typeId2 = InvalidOid;	Oid			rettype;	List	   *commutatorName = NIL;	/* optional commutator operator name */	List	   *negatorName = NIL;		/* optional negator operator name */	List	   *restrictionName = NIL;	/* optional restrict. sel. procedure */	List	   *joinName = NIL; /* optional join sel. procedure */	Oid			functionOid;	/* functions converted to OID */	Oid			restrictionOid;	Oid			joinOid;	Oid			typeId[2];		/* to hold left and right arg */	int			nargs;	ListCell   *pl;	/* Convert list of names to a name and namespace */	oprNamespace = QualifiedNameGetCreationNamespace(names, &oprName);	/* Check we have creation rights in target namespace */	aclresult = pg_namespace_aclcheck(oprNamespace, GetUserId(), ACL_CREATE);	if (aclresult != ACLCHECK_OK)		aclcheck_error(aclresult, ACL_KIND_NAMESPACE,					   get_namespace_name(oprNamespace));	/*	 * loop over the definition list and extract the information we need.	 */	foreach(pl, parameters)	{		DefElem    *defel = (DefElem *) lfirst(pl);		if (pg_strcasecmp(defel->defname, "leftarg") == 0)		{			typeName1 = defGetTypeName(defel);			if (typeName1->setof)				ereport(ERROR,						(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),					errmsg("SETOF type not allowed for operator argument")));		}		else if (pg_strcasecmp(defel->defname, "rightarg") == 0)		{			typeName2 = defGetTypeName(defel);			if (typeName2->setof)				ereport(ERROR,						(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),					errmsg("SETOF type not allowed for operator argument")));		}		else if (pg_strcasecmp(defel->defname, "procedure") == 0)			functionName = defGetQualifiedName(defel);		else if (pg_strcasecmp(defel->defname, "commutator") == 0)			commutatorName = defGetQualifiedName(defel);		else if (pg_strcasecmp(defel->defname, "negator") == 0)			negatorName = defGetQualifiedName(defel);		else if (pg_strcasecmp(defel->defname, "restrict") == 0)			restrictionName = defGetQualifiedName(defel);		else if (pg_strcasecmp(defel->defname, "join") == 0)			joinName = defGetQualifiedName(defel);		else if (pg_strcasecmp(defel->defname, "hashes") == 0)			canHash = defGetBoolean(defel);		else if (pg_strcasecmp(defel->defname, "merges") == 0)			canMerge = defGetBoolean(defel);		/* These obsolete options are taken as meaning canMerge */		else if (pg_strcasecmp(defel->defname, "sort1") == 0)			canMerge = true;		else if (pg_strcasecmp(defel->defname, "sort2") == 0)			canMerge = true;		else if (pg_strcasecmp(defel->defname, "ltcmp") == 0)			canMerge = true;		else if (pg_strcasecmp(defel->defname, "gtcmp") == 0)			canMerge = true;		else		{			/* WARNING, not ERROR, for historical backwards-compatibility */			ereport(WARNING,					(errcode(ERRCODE_SYNTAX_ERROR),					 errmsg("operator attribute /"%s/" not recognized",							defel->defname)));		}	}
开发者ID:dreamsxin,项目名称:postgresql-1,代码行数:97,


示例23: timetravel

Datum							/* have to return HeapTuple to Executor */timetravel(PG_FUNCTION_ARGS){	TriggerData *trigdata = (TriggerData *) fcinfo->context;	Trigger    *trigger;		/* to get trigger name */	int			argc;	char	  **args;			/* arguments */	int			attnum[MaxAttrNum];		/* fnumbers of start/stop columns */	Datum		oldtimeon,				oldtimeoff;	Datum		newtimeon,				newtimeoff,				newuser,				nulltext;	Datum	   *cvals;			/* column values */	char	   *cnulls;			/* column nulls */	char	   *relname;		/* triggered relation name */	Relation	rel;			/* triggered relation */	HeapTuple	trigtuple;	HeapTuple	newtuple = NULL;	HeapTuple	rettuple;	TupleDesc	tupdesc;		/* tuple description */	int			natts;			/* # of attributes */	EPlan	   *plan;			/* prepared plan */	char		ident[2 * NAMEDATALEN];	bool		isnull;			/* to know is some column NULL or not */	bool		isinsert = false;	int			ret;	int			i;	/*	 * Some checks first...	 */	/* Called by trigger manager ? */	if (!CALLED_AS_TRIGGER(fcinfo))		elog(ERROR, "timetravel: not fired by trigger manager");	/* Should be called for ROW trigger */	if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))		elog(ERROR, "timetravel: must be fired for row");	/* Should be called BEFORE */	if (!TRIGGER_FIRED_BEFORE(trigdata->tg_event))		elog(ERROR, "timetravel: must be fired before event");	/* INSERT ? */	if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))		isinsert = true;	if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))		newtuple = trigdata->tg_newtuple;	trigtuple = trigdata->tg_trigtuple;	rel = trigdata->tg_relation;	relname = SPI_getrelname(rel);	/* check if TT is OFF for this relation */	if (0 == findTTStatus(relname))	{		/* OFF - nothing to do */		pfree(relname);		return PointerGetDatum((newtuple != NULL) ? newtuple : trigtuple);	}	trigger = trigdata->tg_trigger;	argc = trigger->tgnargs;	if (argc != MinAttrNum && argc != MaxAttrNum)		elog(ERROR, "timetravel (%s): invalid (!= %d or %d) number of arguments %d",			 relname, MinAttrNum, MaxAttrNum, trigger->tgnargs);	args = trigger->tgargs;	tupdesc = rel->rd_att;	natts = tupdesc->natts;	for (i = 0; i < MinAttrNum; i++)	{		attnum[i] = SPI_fnumber(tupdesc, args[i]);		if (attnum[i] < 0)			elog(ERROR, "timetravel (%s): there is no attribute %s", relname, args[i]);		if (SPI_gettypeid(tupdesc, attnum[i]) != ABSTIMEOID)			elog(ERROR, "timetravel (%s): attribute %s must be of abstime type",				 relname, args[i]);	}	for (; i < argc; i++)	{		attnum[i] = SPI_fnumber(tupdesc, args[i]);		if (attnum[i] < 0)			elog(ERROR, "timetravel (%s): there is no attribute %s", relname, args[i]);		if (SPI_gettypeid(tupdesc, attnum[i]) != TEXTOID)			elog(ERROR, "timetravel (%s): attribute %s must be of text type",				 relname, args[i]);	}	/* create fields containing name */	newuser = CStringGetTextDatum(GetUserNameFromId(GetUserId()));	nulltext = (Datum) NULL;//.........这里部分代码省略.........
开发者ID:ASchurman,项目名称:BufStrat,代码行数:101,


示例24: OperatorShellMake

/* * OperatorShellMake *		Make a "shell" entry for a not-yet-existing operator. */static OidOperatorShellMake(const char *operatorName,				  Oid operatorNamespace,				  Oid leftTypeId,				  Oid rightTypeId){	Relation	pg_operator_desc;	Oid			operatorObjectId;	int			i;	HeapTuple	tup;	Datum		values[Natts_pg_operator];	bool		nulls[Natts_pg_operator];	NameData	oname;	TupleDesc	tupDesc;	/*	 * validate operator name	 */	if (!validOperatorName(operatorName))		ereport(ERROR,				(errcode(ERRCODE_INVALID_NAME),				 errmsg("/"%s/" is not a valid operator name",						operatorName)));	/*	 * initialize our *nulls and *values arrays	 */	for (i = 0; i < Natts_pg_operator; ++i)	{		nulls[i] = false;		values[i] = (Datum) NULL;		/* redundant, but safe */	}	/*	 * initialize values[] with the operator name and input data types. Note	 * that oprcode is set to InvalidOid, indicating it's a shell.	 */	namestrcpy(&oname, operatorName);	values[Anum_pg_operator_oprname - 1] = NameGetDatum(&oname);	values[Anum_pg_operator_oprnamespace - 1] = ObjectIdGetDatum(operatorNamespace);	values[Anum_pg_operator_oprowner - 1] = ObjectIdGetDatum(GetUserId());	values[Anum_pg_operator_oprkind - 1] = CharGetDatum(leftTypeId ? (rightTypeId ? 'b' : 'r') : 'l');	values[Anum_pg_operator_oprcanmerge - 1] = BoolGetDatum(false);	values[Anum_pg_operator_oprcanhash - 1] = BoolGetDatum(false);	values[Anum_pg_operator_oprleft - 1] = ObjectIdGetDatum(leftTypeId);	values[Anum_pg_operator_oprright - 1] = ObjectIdGetDatum(rightTypeId);	values[Anum_pg_operator_oprresult - 1] = ObjectIdGetDatum(InvalidOid);	values[Anum_pg_operator_oprcom - 1] = ObjectIdGetDatum(InvalidOid);	values[Anum_pg_operator_oprnegate - 1] = ObjectIdGetDatum(InvalidOid);	values[Anum_pg_operator_oprcode - 1] = ObjectIdGetDatum(InvalidOid);	values[Anum_pg_operator_oprrest - 1] = ObjectIdGetDatum(InvalidOid);	values[Anum_pg_operator_oprjoin - 1] = ObjectIdGetDatum(InvalidOid);	/*	 * open pg_operator	 */	pg_operator_desc = heap_open(OperatorRelationId, RowExclusiveLock);	tupDesc = pg_operator_desc->rd_att;	/*	 * create a new operator tuple	 */	tup = heap_form_tuple(tupDesc, values, nulls);	/*	 * insert our "shell" operator tuple	 */	operatorObjectId = CatalogTupleInsert(pg_operator_desc, tup);	/* Add dependencies for the entry */	makeOperatorDependencies(tup, false);	heap_freetuple(tup);	/* Post creation hook for new shell operator */	InvokeObjectPostCreateHook(OperatorRelationId, operatorObjectId, 0);	/*	 * Make sure the tuple is visible for subsequent lookups/updates.	 */	CommandCounterIncrement();	/*	 * close the operator relation and return the oid.	 */	heap_close(pg_operator_desc, RowExclusiveLock);	return operatorObjectId;}
开发者ID:dreamsxin,项目名称:postgresql-1,代码行数:93,


示例25: wxT

pgObject *pgUser::Refresh(ctlTree *browser, const wxTreeItemId item){    pgObject *user = 0;    pgCollection *coll = browser->GetParentCollection(item);    if (coll)        user = userFactory.CreateObjects(coll, 0, wxT("/n WHERE usesysid=") + NumToStr(GetUserId()));    return user;}
开发者ID:zr40,项目名称:pgadmin3-light,代码行数:9,


示例26: OperatorCreate

//.........这里部分代码省略.........					 errmsg("only boolean operators can have restriction selectivity")));		if (OidIsValid(joinId))			ereport(ERROR,					(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),				errmsg("only boolean operators can have join selectivity")));		if (canMerge)			ereport(ERROR,					(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),					 errmsg("only boolean operators can merge join")));		if (canHash)			ereport(ERROR,					(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),					 errmsg("only boolean operators can hash")));	}	operatorObjectId = OperatorGet(operatorName,								   operatorNamespace,								   leftTypeId,								   rightTypeId,								   &operatorAlreadyDefined);	if (operatorAlreadyDefined)		ereport(ERROR,				(errcode(ERRCODE_DUPLICATE_FUNCTION),				 errmsg("operator %s already exists",						operatorName)));	/*	 * At this point, if operatorObjectId is not InvalidOid then we are	 * filling in a previously-created shell.  Insist that the user own any	 * such shell.	 */	if (OidIsValid(operatorObjectId) &&		!pg_oper_ownercheck(operatorObjectId, GetUserId()))		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_OPER,					   operatorName);	/*	 * Set up the other operators.  If they do not currently exist, create	 * shells in order to get ObjectId's.	 */	if (commutatorName)	{		/* commutator has reversed arg types */		commutatorId = get_other_operator(commutatorName,										  rightTypeId, leftTypeId,										  operatorName, operatorNamespace,										  leftTypeId, rightTypeId,										  true);		/* Permission check: must own other operator */		if (OidIsValid(commutatorId) &&			!pg_oper_ownercheck(commutatorId, GetUserId()))			aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_OPER,						   NameListToString(commutatorName));		/*		 * self-linkage to this operator; will fix below. Note that only		 * self-linkage for commutation makes sense.		 */		if (!OidIsValid(commutatorId))			selfCommutator = true;	}	else		commutatorId = InvalidOid;
开发者ID:dreamsxin,项目名称:postgresql-1,代码行数:67,


示例27: 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:AnLingm,项目名称:gpdb,代码行数:67,


示例28: DefineQueryRewrite

/* * DefineQueryRewrite *		Create a rule * * This is essentially the same as DefineRule() except that the rule's * action and qual have already been passed through parse analysis. */ObjectAddressDefineQueryRewrite(char *rulename,				   Oid event_relid,				   Node *event_qual,				   CmdType event_type,				   bool is_instead,				   bool replace,				   List *action){	Relation	event_relation;	ListCell   *l;	Query	   *query;	bool		RelisBecomingView = false;	Oid			ruleId = InvalidOid;	ObjectAddress address;	/*	 * If we are installing an ON SELECT rule, we had better grab	 * AccessExclusiveLock to ensure no SELECTs are currently running on the	 * event relation. For other types of rules, it would be sufficient to	 * grab ShareRowExclusiveLock to lock out insert/update/delete actions and	 * to ensure that we lock out current CREATE RULE statements; but because	 * of race conditions in access to catalog entries, we can't do that yet.	 *	 * Note that this lock level should match the one used in DefineRule.	 */	event_relation = heap_open(event_relid, AccessExclusiveLock);	/*	 * Verify relation is of a type that rules can sensibly be applied to.	 * Internal callers can target materialized views, but transformRuleStmt()	 * blocks them for users.  Don't mention them in the error message.	 */	if (event_relation->rd_rel->relkind != RELKIND_RELATION &&		event_relation->rd_rel->relkind != RELKIND_MATVIEW &&		event_relation->rd_rel->relkind != RELKIND_VIEW)		ereport(ERROR,				(errcode(ERRCODE_WRONG_OBJECT_TYPE),				 errmsg("/"%s/" is not a table or view",						RelationGetRelationName(event_relation))));	if (!allowSystemTableMods && IsSystemRelation(event_relation))		ereport(ERROR,				(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),				 errmsg("permission denied: /"%s/" is a system catalog",						RelationGetRelationName(event_relation))));	/*	 * Check user has permission to apply rules to this relation.	 */	if (!pg_class_ownercheck(event_relid, GetUserId()))		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,					   RelationGetRelationName(event_relation));	/*	 * No rule actions that modify OLD or NEW	 */	foreach(l, action)	{		query = (Query *) lfirst(l);		if (query->resultRelation == 0)			continue;		/* Don't be fooled by INSERT/SELECT */		if (query != getInsertSelectQuery(query, NULL))			continue;		if (query->resultRelation == PRS2_OLD_VARNO)			ereport(ERROR,					(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),					 errmsg("rule actions on OLD are not implemented"),					 errhint("Use views or triggers instead.")));		if (query->resultRelation == PRS2_NEW_VARNO)			ereport(ERROR,					(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),					 errmsg("rule actions on NEW are not implemented"),					 errhint("Use triggers instead.")));	}
开发者ID:ArgenBarbie,项目名称:postgresql-9.5.0,代码行数:83,


示例29: 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 autovacuum worker processes either.	 */	if (IsUnderPostmaster && !IsAutoVacuumProcess())	{		/*		 * 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:qiuyesuifeng,项目名称:gpdb,代码行数:101,


示例30: errmsg

					(errcode(ERRCODE_INVALID_PARAMETER_VALUE),					 errmsg("security label provider /"%s/" is not loaded",							stmt->provider)));	}	/*	 * Translate the parser representation which identifies this object into	 * an ObjectAddress. get_object_address() will throw an error if the	 * object does not exist, and will also acquire a lock on the target to	 * guard against concurrent modifications.	 */	address = get_object_address(stmt->objtype, stmt->objname, stmt->objargs,								 &relation, ShareUpdateExclusiveLock, false);	/* Require ownership of the target object. */	check_object_ownership(GetUserId(), stmt->objtype, address,						   stmt->objname, stmt->objargs, relation);	/* Perform other integrity checks as needed. */	switch (stmt->objtype)	{		case OBJECT_COLUMN:			/*			 * Allow security labels only on columns of tables, views,			 * materialized views, composite types, and foreign tables (which			 * are the only relkinds for which pg_dump will dump labels).			 */			if (relation->rd_rel->relkind != RELKIND_RELATION &&				relation->rd_rel->relkind != RELKIND_VIEW &&				relation->rd_rel->relkind != RELKIND_MATVIEW &&
开发者ID:0x0FFF,项目名称:postgres,代码行数:31,



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


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