* getObjectDescription: build an object description for messages * * The result is a palloc'd string. NULL is returned for an undefined * object if missing_ok is true, else an error is generated. */
| 3062 | * object if missing_ok is true, else an error is generated. |
| 3063 | */ |
| 3064 | char * |
| 3065 | getObjectDescription(const ObjectAddress *object, bool missing_ok) |
| 3066 | { |
| 3067 | StringInfoData buffer; |
| 3068 | |
| 3069 | initStringInfo(&buffer); |
| 3070 | |
| 3071 | switch (getObjectClass(object)) |
| 3072 | { |
| 3073 | case OCLASS_CLASS: |
| 3074 | if (object->objectSubId == 0) |
| 3075 | getRelationDescription(&buffer, object->objectId, missing_ok); |
| 3076 | else |
| 3077 | { |
| 3078 | /* column, not whole relation */ |
| 3079 | StringInfoData rel; |
| 3080 | char *attname = get_attname(object->objectId, |
| 3081 | object->objectSubId, |
| 3082 | missing_ok); |
| 3083 | |
| 3084 | if (!attname) |
| 3085 | break; |
| 3086 | |
| 3087 | initStringInfo(&rel); |
| 3088 | getRelationDescription(&rel, object->objectId, missing_ok); |
| 3089 | /* translator: second %s is, e.g., "table %s" */ |
| 3090 | appendStringInfo(&buffer, _("column %s of %s"), |
| 3091 | attname, rel.data); |
| 3092 | pfree(rel.data); |
| 3093 | } |
| 3094 | break; |
| 3095 | |
| 3096 | case OCLASS_PROC: |
| 3097 | { |
| 3098 | bits16 flags = FORMAT_PROC_INVALID_AS_NULL; |
| 3099 | char *proname = format_procedure_extended(object->objectId, |
| 3100 | flags); |
| 3101 | |
| 3102 | if (proname == NULL) |
| 3103 | break; |
| 3104 | |
| 3105 | appendStringInfo(&buffer, _("function %s"), proname); |
| 3106 | break; |
| 3107 | } |
| 3108 | |
| 3109 | case OCLASS_TYPE: |
| 3110 | { |
| 3111 | bits16 flags = FORMAT_TYPE_INVALID_AS_NULL; |
| 3112 | char *typname = format_type_extended(object->objectId, -1, |
| 3113 | flags); |
| 3114 | |
| 3115 | if (typname == NULL) |
| 3116 | break; |
| 3117 | |
| 3118 | appendStringInfo(&buffer, _("type %s"), typname); |
| 3119 | break; |
| 3120 | } |
| 3121 |
no test coverage detected