* TupleDescGetAttInMetadata - Build an AttInMetadata structure based on the * supplied TupleDesc. AttInMetadata can be used in conjunction with C strings * to produce a properly formed tuple. */
| 2100 | * to produce a properly formed tuple. |
| 2101 | */ |
| 2102 | AttInMetadata * |
| 2103 | TupleDescGetAttInMetadata(TupleDesc tupdesc) |
| 2104 | { |
| 2105 | int natts = tupdesc->natts; |
| 2106 | int i; |
| 2107 | Oid atttypeid; |
| 2108 | Oid attinfuncid; |
| 2109 | FmgrInfo *attinfuncinfo; |
| 2110 | Oid *attioparams; |
| 2111 | int32 *atttypmods; |
| 2112 | AttInMetadata *attinmeta; |
| 2113 | |
| 2114 | attinmeta = (AttInMetadata *) palloc(sizeof(AttInMetadata)); |
| 2115 | |
| 2116 | /* "Bless" the tupledesc so that we can make rowtype datums with it */ |
| 2117 | attinmeta->tupdesc = BlessTupleDesc(tupdesc); |
| 2118 | |
| 2119 | /* |
| 2120 | * Gather info needed later to call the "in" function for each attribute |
| 2121 | */ |
| 2122 | attinfuncinfo = (FmgrInfo *) palloc0(natts * sizeof(FmgrInfo)); |
| 2123 | attioparams = (Oid *) palloc0(natts * sizeof(Oid)); |
| 2124 | atttypmods = (int32 *) palloc0(natts * sizeof(int32)); |
| 2125 | |
| 2126 | for (i = 0; i < natts; i++) |
| 2127 | { |
| 2128 | Form_pg_attribute att = TupleDescAttr(tupdesc, i); |
| 2129 | |
| 2130 | /* Ignore dropped attributes */ |
| 2131 | if (!att->attisdropped) |
| 2132 | { |
| 2133 | atttypeid = att->atttypid; |
| 2134 | getTypeInputInfo(atttypeid, &attinfuncid, &attioparams[i]); |
| 2135 | fmgr_info(attinfuncid, &attinfuncinfo[i]); |
| 2136 | atttypmods[i] = att->atttypmod; |
| 2137 | } |
| 2138 | } |
| 2139 | attinmeta->attinfuncs = attinfuncinfo; |
| 2140 | attinmeta->attioparams = attioparams; |
| 2141 | attinmeta->atttypmods = atttypmods; |
| 2142 | |
| 2143 | return attinmeta; |
| 2144 | } |
| 2145 | |
| 2146 | /* |
| 2147 | * BuildTupleFromCStrings - build a HeapTuple given user data in C string form. |