* Build a RECFIELD datum for the named field of the specified record variable * * If there's already such a datum, just return it; we don't need duplicates. */
| 2061 | * If there's already such a datum, just return it; we don't need duplicates. |
| 2062 | */ |
| 2063 | PLpgSQL_recfield * |
| 2064 | plpgsql_build_recfield(PLpgSQL_rec *rec, const char *fldname) |
| 2065 | { |
| 2066 | PLpgSQL_recfield *recfield; |
| 2067 | int i; |
| 2068 | |
| 2069 | /* search for an existing datum referencing this field */ |
| 2070 | i = rec->firstfield; |
| 2071 | while (i >= 0) |
| 2072 | { |
| 2073 | PLpgSQL_recfield *fld = (PLpgSQL_recfield *) plpgsql_Datums[i]; |
| 2074 | |
| 2075 | Assert(fld->dtype == PLPGSQL_DTYPE_RECFIELD && |
| 2076 | fld->recparentno == rec->dno); |
| 2077 | if (strcmp(fld->fieldname, fldname) == 0) |
| 2078 | return fld; |
| 2079 | i = fld->nextfield; |
| 2080 | } |
| 2081 | |
| 2082 | /* nope, so make a new one */ |
| 2083 | recfield = palloc0(sizeof(PLpgSQL_recfield)); |
| 2084 | recfield->dtype = PLPGSQL_DTYPE_RECFIELD; |
| 2085 | recfield->fieldname = pstrdup(fldname); |
| 2086 | recfield->recparentno = rec->dno; |
| 2087 | recfield->rectupledescid = INVALID_TUPLEDESC_IDENTIFIER; |
| 2088 | |
| 2089 | plpgsql_adddatum((PLpgSQL_datum *) recfield); |
| 2090 | |
| 2091 | /* now we can link it into the parent's chain */ |
| 2092 | recfield->nextfield = rec->firstfield; |
| 2093 | rec->firstfield = recfield->dno; |
| 2094 | |
| 2095 | return recfield; |
| 2096 | } |
| 2097 | |
| 2098 | /* |
| 2099 | * plpgsql_build_datatype |
no test coverage detected