* plpgsql_build_variable - build a datum-array entry of a given * datatype * * The returned struct may be a PLpgSQL_var or PLpgSQL_rec * depending on the given datatype, and is allocated via * palloc. The struct is automatically added to the current datum * array, and optionally to the current namespace. */
| 1904 | * array, and optionally to the current namespace. |
| 1905 | */ |
| 1906 | PLpgSQL_variable * |
| 1907 | plpgsql_build_variable(const char *refname, int lineno, PLpgSQL_type *dtype, |
| 1908 | bool add2namespace) |
| 1909 | { |
| 1910 | PLpgSQL_variable *result; |
| 1911 | |
| 1912 | switch (dtype->ttype) |
| 1913 | { |
| 1914 | case PLPGSQL_TTYPE_SCALAR: |
| 1915 | { |
| 1916 | /* Ordinary scalar datatype */ |
| 1917 | PLpgSQL_var *var; |
| 1918 | |
| 1919 | var = palloc0(sizeof(PLpgSQL_var)); |
| 1920 | var->dtype = PLPGSQL_DTYPE_VAR; |
| 1921 | var->refname = pstrdup(refname); |
| 1922 | var->lineno = lineno; |
| 1923 | var->datatype = dtype; |
| 1924 | /* other fields are left as 0, might be changed by caller */ |
| 1925 | |
| 1926 | /* preset to NULL */ |
| 1927 | var->value = 0; |
| 1928 | var->isnull = true; |
| 1929 | var->freeval = false; |
| 1930 | |
| 1931 | plpgsql_adddatum((PLpgSQL_datum *) var); |
| 1932 | if (add2namespace) |
| 1933 | plpgsql_ns_additem(PLPGSQL_NSTYPE_VAR, |
| 1934 | var->dno, |
| 1935 | refname); |
| 1936 | result = (PLpgSQL_variable *) var; |
| 1937 | break; |
| 1938 | } |
| 1939 | case PLPGSQL_TTYPE_REC: |
| 1940 | { |
| 1941 | /* Composite type -- build a record variable */ |
| 1942 | PLpgSQL_rec *rec; |
| 1943 | |
| 1944 | rec = plpgsql_build_record(refname, lineno, |
| 1945 | dtype, dtype->typoid, |
| 1946 | add2namespace); |
| 1947 | result = (PLpgSQL_variable *) rec; |
| 1948 | break; |
| 1949 | } |
| 1950 | case PLPGSQL_TTYPE_PSEUDO: |
| 1951 | ereport(ERROR, |
| 1952 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 1953 | errmsg("variable \"%s\" has pseudo-type %s", |
| 1954 | refname, format_type_be(dtype->typoid)))); |
| 1955 | result = NULL; /* keep compiler quiet */ |
| 1956 | break; |
| 1957 | default: |
| 1958 | elog(ERROR, "unrecognized ttype: %d", dtype->ttype); |
| 1959 | result = NULL; /* keep compiler quiet */ |
| 1960 | break; |
| 1961 | } |
| 1962 | |
| 1963 | return result; |
no test coverage detected