?? namespace.c
字號:
* an extra argument for the index AM OID. */OidOpclassnameGetOpcid(Oid amid, const char *opcname){ Oid opcid; List *lptr; recomputeNamespacePath(); foreach(lptr, namespaceSearchPath) { Oid namespaceId = lfirsto(lptr); opcid = GetSysCacheOid(CLAAMNAMENSP, ObjectIdGetDatum(amid), PointerGetDatum(opcname), ObjectIdGetDatum(namespaceId), 0); if (OidIsValid(opcid)) return opcid; } /* Not found in path */ return InvalidOid;}/* * OpclassIsVisible * Determine whether an opclass (identified by OID) is visible in the * current search path. Visible means "would be found by searching * for the unqualified opclass name". */boolOpclassIsVisible(Oid opcid){ HeapTuple opctup; Form_pg_opclass opcform; Oid opcnamespace; bool visible; opctup = SearchSysCache(CLAOID, ObjectIdGetDatum(opcid), 0, 0, 0); if (!HeapTupleIsValid(opctup)) elog(ERROR, "cache lookup failed for opclass %u", opcid); opcform = (Form_pg_opclass) GETSTRUCT(opctup); recomputeNamespacePath(); /* * Quick check: if it ain't in the path at all, it ain't visible. * Items in the system namespace are surely in the path and so we * needn't even do oidMember() for them. */ opcnamespace = opcform->opcnamespace; if (opcnamespace != PG_CATALOG_NAMESPACE && !oidMember(opcnamespace, namespaceSearchPath)) visible = false; else { /* * If it is in the path, it might still not be visible; it could * be hidden by another opclass of the same name earlier in the * path. So we must do a slow check to see if this opclass would * be found by OpclassnameGetOpcid. */ char *opcname = NameStr(opcform->opcname); visible = (OpclassnameGetOpcid(opcform->opcamid, opcname) == opcid); } ReleaseSysCache(opctup); return visible;}/* * ConversionGetConid * Try to resolve an unqualified conversion name. * Returns OID if conversion found in search path, else InvalidOid. * * This is essentially the same as RelnameGetRelid. */OidConversionGetConid(const char *conname){ Oid conid; List *lptr; recomputeNamespacePath(); foreach(lptr, namespaceSearchPath) { Oid namespaceId = lfirsto(lptr); conid = GetSysCacheOid(CONNAMENSP, PointerGetDatum(conname), ObjectIdGetDatum(namespaceId), 0, 0); if (OidIsValid(conid)) return conid; } /* Not found in path */ return InvalidOid;}/* * ConversionIsVisible * Determine whether a conversion (identified by OID) is visible in the * current search path. Visible means "would be found by searching * for the unqualified conversion name". */boolConversionIsVisible(Oid conid){ HeapTuple contup; Form_pg_conversion conform; Oid connamespace; bool visible; contup = SearchSysCache(CONOID, ObjectIdGetDatum(conid), 0, 0, 0); if (!HeapTupleIsValid(contup)) elog(ERROR, "cache lookup failed for conversion %u", conid); conform = (Form_pg_conversion) GETSTRUCT(contup); recomputeNamespacePath(); /* * Quick check: if it ain't in the path at all, it ain't visible. * Items in the system namespace are surely in the path and so we * needn't even do oidMember() for them. */ connamespace = conform->connamespace; if (connamespace != PG_CATALOG_NAMESPACE && !oidMember(connamespace, namespaceSearchPath)) visible = false; else { /* * If it is in the path, it might still not be visible; it could * be hidden by another conversion of the same name earlier in the * path. So we must do a slow check to see if this conversion * would be found by ConversionGetConid. */ char *conname = NameStr(conform->conname); visible = (ConversionGetConid(conname) == conid); } ReleaseSysCache(contup); return visible;}/* * DeconstructQualifiedName * Given a possibly-qualified name expressed as a list of String nodes, * extract the schema name and object name. * * *nspname_p is set to NULL if there is no explicit schema name. */voidDeconstructQualifiedName(List *names, char **nspname_p, char **objname_p){ char *catalogname; char *schemaname = NULL; char *objname = NULL; switch (length(names)) { case 1: objname = strVal(lfirst(names)); break; case 2: schemaname = strVal(lfirst(names)); objname = strVal(lsecond(names)); break; case 3: catalogname = strVal(lfirst(names)); schemaname = strVal(lsecond(names)); objname = strVal(lthird(names)); /* * We check the catalog name and then ignore it. */ if (strcmp(catalogname, get_database_name(MyDatabaseId)) != 0) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cross-database references are not implemented"))); break; default: ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("improper qualified name (too many dotted names): %s", NameListToString(names)))); break; } *nspname_p = schemaname; *objname_p = objname;}/* * LookupExplicitNamespace * Process an explicitly-specified schema name: look up the schema * and verify we have USAGE (lookup) rights in it. * * Returns the namespace OID. Raises ereport if any problem. */OidLookupExplicitNamespace(const char *nspname){ Oid namespaceId; AclResult aclresult; namespaceId = GetSysCacheOid(NAMESPACENAME, CStringGetDatum(nspname), 0, 0, 0); if (!OidIsValid(namespaceId)) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_SCHEMA), errmsg("schema \"%s\" does not exist", nspname))); aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_USAGE); if (aclresult != ACLCHECK_OK) aclcheck_error(aclresult, ACL_KIND_NAMESPACE, nspname); return namespaceId;}/* * QualifiedNameGetCreationNamespace * Given a possibly-qualified name for an object (in List-of-Values * format), determine what namespace the object should be created in. * Also extract and return the object name (last component of list). * * This is *not* used for tables. Hence, the TEMP table namespace is * never selected as the creation target. */OidQualifiedNameGetCreationNamespace(List *names, char **objname_p){ char *schemaname; char *objname; Oid namespaceId; /* deconstruct the name list */ DeconstructQualifiedName(names, &schemaname, &objname); if (schemaname) { /* use exact schema given */ namespaceId = GetSysCacheOid(NAMESPACENAME, CStringGetDatum(schemaname), 0, 0, 0); if (!OidIsValid(namespaceId)) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_SCHEMA), errmsg("schema \"%s\" does not exist", schemaname))); /* we do not check for USAGE rights here! */ } else { /* use the default creation namespace */ recomputeNamespacePath(); namespaceId = defaultCreationNamespace; if (!OidIsValid(namespaceId)) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_SCHEMA), errmsg("no schema has been selected to create in"))); } /* Note: callers will check for CREATE rights when appropriate */ *objname_p = objname; return namespaceId;}/* * makeRangeVarFromNameList * Utility routine to convert a qualified-name list into RangeVar form. */RangeVar *makeRangeVarFromNameList(List *names){ RangeVar *rel = makeRangeVar(NULL, NULL); switch (length(names)) { case 1: rel->relname = strVal(lfirst(names)); break; case 2: rel->schemaname = strVal(lfirst(names)); rel->relname = strVal(lsecond(names)); break; case 3: rel->catalogname = strVal(lfirst(names)); rel->schemaname = strVal(lsecond(names)); rel->relname = strVal(lthird(names)); break; default: ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("improper relation name (too many dotted names): %s", NameListToString(names)))); break; } return rel;}/* * NameListToString * Utility routine to convert a qualified-name list into a string. * * This is used primarily to form error messages, and so we do not quote * the list elements, for the sake of legibility. */char *NameListToString(List *names){ StringInfoData string; List *l; initStringInfo(&string); foreach(l, names) { if (l != names) appendStringInfoChar(&string, '.'); appendStringInfoString(&string, strVal(lfirst(l))); } return string.data;}/* * NameListToQuotedString * Utility routine to convert a qualified-name list into a string. * * Same as above except that names will be double-quoted where necessary, * so the string could be re-parsed (eg, by textToQualifiedNameList). */char *NameListToQuotedString(List *names){ StringInfoData string; List *l; initStringInfo(&string); foreach(l, names) { if (l != names) appendStringInfoChar(&string, '.'); appendStringInfoString(&string, quote_identifier(strVal(lfirst(l)))); } return string.data;}/* * isTempNamespace - is the given namespace my temporary-table namespace? */boolisTempNamespace(Oid namespaceId){ if (OidIsValid(myTempNamespace) && myTempNamespace == namespaceId) return true; return false;}/* * isOtherTempNamespace - is the given namespace some other backend's * temporary-table namespace? */boolisOtherTempNamespace(Oid namespaceId){ bool result; char *nspname; /* If it's my own temp namespace, say "false" */ if (isTempNamespace(namespaceId)) return false; /* Else, if the namespace name starts with "pg_temp_", say "true" */ nspname = get_namespace_name(namespaceId); if (!nspname) return false; /* no such namespace? */ result = (strncmp(nspname, "pg_temp_", 8) == 0); pfree(nspname); return result;}/* * PushSpecialNamespace - push a "special" namespace onto the front of the * search path. * * This is a slightly messy hack intended only for support of CREATE SCHEMA. * Although the API is defined to allow a stack of pushed namespaces, we * presently only support one at a time. * * The pushed namespace will be removed from the search path at end of * transaction, whether commit or abort. */voidPushSpecialNamespace(Oid namespaceId){ Assert(!OidIsValid(mySpecialNamespace)); mySpecialNamespace = namespaceId; namespaceSearchPathValid = false;}/* * PopSpecialNamespace - remove previously pushed special namespace. */voidPopSpecialNamespace(Oid namespaceId){ Assert(mySpecialNamespace == namespaceId); mySpecialNamespace = InvalidOid; namespaceSearchPathValid = false;}/* * FindConversionByName - find a conversion by possibly qualified name */OidFindConversionByName(List *name){ char *schemaname; char *conversion_name; Oid namespaceId; Oid conoid; List *lptr; /* deconstruct the name list */ DeconstructQualifiedName(name, &schemaname, &conversion_name); if (schemaname) { /* use exact schema given */ namespaceId = LookupExplicitNamespace(schemaname); return FindConversion(conversion_name, namespaceId); } else { /* search for it in search path */ recomputeNamespacePath(); foreach(lptr, namespaceSearchPath) { namespaceId = lfirsto(lptr); conoid = FindConversion(conversion_name, namespaceId); if (OidIsValid(conoid)) return conoid; } } /* Not found in path */ return InvalidOid;}/* * FindDefaultConversionProc - find default encoding conversion proc */OidFindDefaultConversionProc(int4 for_encoding, int4 to_encoding){ Oid proc; List *lptr; recomputeNamespacePath(); foreach(lptr, namespaceSearchPath) { Oid namespaceId = lfirsto(lptr);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -