* Given a string that is supposed to be a SQL-compatible type declaration, * such as "int4" or "integer" or "character varying(32)", parse * the string and return the result as a TypeName. * If the string cannot be parsed as a type, an error is raised. */
| 730 | * If the string cannot be parsed as a type, an error is raised. |
| 731 | */ |
| 732 | TypeName * |
| 733 | typeStringToTypeName(const char *str) |
| 734 | { |
| 735 | List *raw_parsetree_list; |
| 736 | TypeName *typeName; |
| 737 | ErrorContextCallback ptserrcontext; |
| 738 | |
| 739 | /* make sure we give useful error for empty input */ |
| 740 | if (strspn(str, " \t\n\r\f") == strlen(str)) |
| 741 | goto fail; |
| 742 | |
| 743 | /* |
| 744 | * Setup error traceback support in case of ereport() during parse |
| 745 | */ |
| 746 | ptserrcontext.callback = pts_error_callback; |
| 747 | ptserrcontext.arg = unconstify(char *, str); |
| 748 | ptserrcontext.previous = error_context_stack; |
| 749 | error_context_stack = &ptserrcontext; |
| 750 | |
| 751 | raw_parsetree_list = raw_parser(str, RAW_PARSE_TYPE_NAME); |
| 752 | |
| 753 | error_context_stack = ptserrcontext.previous; |
| 754 | |
| 755 | /* We should get back exactly one TypeName node. */ |
| 756 | Assert(list_length(raw_parsetree_list) == 1); |
| 757 | typeName = linitial_node(TypeName, raw_parsetree_list); |
| 758 | |
| 759 | /* The grammar allows SETOF in TypeName, but we don't want that here. */ |
| 760 | if (typeName->setof) |
| 761 | goto fail; |
| 762 | |
| 763 | return typeName; |
| 764 | |
| 765 | fail: |
| 766 | ereport(ERROR, |
| 767 | (errcode(ERRCODE_SYNTAX_ERROR), |
| 768 | errmsg("invalid type name \"%s\"", str))); |
| 769 | return NULL; /* keep compiler quiet */ |
| 770 | } |
| 771 | |
| 772 | /* |
| 773 | * Given a string that is supposed to be a SQL-compatible type declaration, |
no test coverage detected