* Build a row-variable data structure given the component variables. * Include a rowtupdesc, since we will need to materialize the row result. */
| 1994 | * Include a rowtupdesc, since we will need to materialize the row result. |
| 1995 | */ |
| 1996 | static PLpgSQL_row * |
| 1997 | build_row_from_vars(PLpgSQL_variable **vars, int numvars) |
| 1998 | { |
| 1999 | PLpgSQL_row *row; |
| 2000 | int i; |
| 2001 | |
| 2002 | row = palloc0(sizeof(PLpgSQL_row)); |
| 2003 | row->dtype = PLPGSQL_DTYPE_ROW; |
| 2004 | row->refname = "(unnamed row)"; |
| 2005 | row->lineno = -1; |
| 2006 | row->rowtupdesc = CreateTemplateTupleDesc(numvars); |
| 2007 | row->nfields = numvars; |
| 2008 | row->fieldnames = palloc(numvars * sizeof(char *)); |
| 2009 | row->varnos = palloc(numvars * sizeof(int)); |
| 2010 | |
| 2011 | for (i = 0; i < numvars; i++) |
| 2012 | { |
| 2013 | PLpgSQL_variable *var = vars[i]; |
| 2014 | Oid typoid; |
| 2015 | int32 typmod; |
| 2016 | Oid typcoll; |
| 2017 | |
| 2018 | /* Member vars of a row should never be const */ |
| 2019 | Assert(!var->isconst); |
| 2020 | |
| 2021 | switch (var->dtype) |
| 2022 | { |
| 2023 | case PLPGSQL_DTYPE_VAR: |
| 2024 | case PLPGSQL_DTYPE_PROMISE: |
| 2025 | typoid = ((PLpgSQL_var *) var)->datatype->typoid; |
| 2026 | typmod = ((PLpgSQL_var *) var)->datatype->atttypmod; |
| 2027 | typcoll = ((PLpgSQL_var *) var)->datatype->collation; |
| 2028 | break; |
| 2029 | |
| 2030 | case PLPGSQL_DTYPE_REC: |
| 2031 | /* shouldn't need to revalidate rectypeid already... */ |
| 2032 | typoid = ((PLpgSQL_rec *) var)->rectypeid; |
| 2033 | typmod = -1; /* don't know typmod, if it's used at all */ |
| 2034 | typcoll = InvalidOid; /* composite types have no collation */ |
| 2035 | break; |
| 2036 | |
| 2037 | default: |
| 2038 | elog(ERROR, "unrecognized dtype: %d", var->dtype); |
| 2039 | typoid = InvalidOid; /* keep compiler quiet */ |
| 2040 | typmod = 0; |
| 2041 | typcoll = InvalidOid; |
| 2042 | break; |
| 2043 | } |
| 2044 | |
| 2045 | row->fieldnames[i] = var->refname; |
| 2046 | row->varnos[i] = var->dno; |
| 2047 | |
| 2048 | TupleDescInitEntry(row->rowtupdesc, i + 1, |
| 2049 | var->refname, |
| 2050 | typoid, typmod, |
| 2051 | 0); |
| 2052 | TupleDescInitEntryCollation(row->rowtupdesc, i + 1, typcoll); |
| 2053 | } |
no test coverage detected