* CREATE PROCEDURE dbms_sql.describe_columns(c int, OUT col_cnt int, OUT desc_t dbms_sql.desc_rec[]) * * Returns an array of column's descriptions. Attention, the typid are related to PostgreSQL type * system. */
| 2108 | * system. |
| 2109 | */ |
| 2110 | Datum |
| 2111 | dbms_sql_describe_columns(PG_FUNCTION_ARGS) |
| 2112 | { |
| 2113 | CursorData *c; |
| 2114 | Datum values[13]; |
| 2115 | bool nulls[13]; |
| 2116 | TupleDesc tupdesc; |
| 2117 | TupleDesc desc_rec_tupdesc; |
| 2118 | TupleDesc cursor_tupdesc; |
| 2119 | HeapTuple tuple; |
| 2120 | Oid arraytypid; |
| 2121 | Oid desc_rec_typid; |
| 2122 | Oid *types = NULL; |
| 2123 | ArrayBuildState *abuilder; |
| 2124 | SPIPlanPtr plan; |
| 2125 | CachedPlanSource *plansource = NULL; |
| 2126 | int ncolumns = 0; |
| 2127 | int rc; |
| 2128 | int i = 0; |
| 2129 | bool nonatomic; |
| 2130 | MemoryContext callercxt = CurrentMemoryContext; |
| 2131 | |
| 2132 | if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) |
| 2133 | elog(ERROR, "return type must be a row type"); |
| 2134 | |
| 2135 | arraytypid = TupleDescAttr(tupdesc, 1)->atttypid; |
| 2136 | desc_rec_typid = get_element_type(arraytypid); |
| 2137 | |
| 2138 | if (!OidIsValid(desc_rec_typid)) |
| 2139 | elog(ERROR, "second output field must be an array"); |
| 2140 | |
| 2141 | desc_rec_tupdesc = lookup_rowtype_tupdesc_copy(desc_rec_typid, -1); |
| 2142 | |
| 2143 | abuilder = initArrayResult(desc_rec_typid, callercxt, true); |
| 2144 | |
| 2145 | c = get_cursor(fcinfo, true); |
| 2146 | |
| 2147 | if (c->variables) |
| 2148 | { |
| 2149 | ListCell *lc; |
| 2150 | |
| 2151 | types = palloc(sizeof(Oid) * c->nvariables); |
| 2152 | i = 0; |
| 2153 | |
| 2154 | foreach(lc, c->variables) |
| 2155 | { |
| 2156 | VariableData *var = (VariableData *) lfirst(lc); |
| 2157 | |
| 2158 | if (var->typoid == InvalidOid) |
| 2159 | ereport(ERROR, |
| 2160 | (errcode(ERRCODE_UNDEFINED_PARAMETER), |
| 2161 | errmsg("variable \"%s\" has not a value", var->refname))); |
| 2162 | |
| 2163 | types[i++] = var->is_array ? var->typelemid : var->typoid; |
| 2164 | } |
| 2165 | } |
| 2166 | |
| 2167 | /* |
no test coverage detected