* CREATE PROCEDURE dbms_sql.define_column(c int, col int, value "any", column_size int DEFAULT -1); */
| 748 | * CREATE PROCEDURE dbms_sql.define_column(c int, col int, value "any", column_size int DEFAULT -1); |
| 749 | */ |
| 750 | Datum |
| 751 | dbms_sql_define_column(PG_FUNCTION_ARGS) |
| 752 | { |
| 753 | CursorData *c; |
| 754 | ColumnData *col; |
| 755 | Oid valtype; |
| 756 | Oid basetype; |
| 757 | int position; |
| 758 | int colsize; |
| 759 | TYPCATEGORY category; |
| 760 | bool ispreferred; |
| 761 | |
| 762 | c = get_cursor(fcinfo, true); |
| 763 | |
| 764 | if (PG_ARGISNULL(1)) |
| 765 | ereport(ERROR, |
| 766 | (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), |
| 767 | errmsg("column position (number) is NULL"))); |
| 768 | |
| 769 | position = PG_GETARG_INT32(1); |
| 770 | col = get_col(c, position, true); |
| 771 | |
| 772 | valtype = get_fn_expr_argtype(fcinfo->flinfo, 2); |
| 773 | if (valtype == RECORDOID) |
| 774 | ereport(ERROR, |
| 775 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 776 | errmsg("cannot to define a column of record type"))); |
| 777 | |
| 778 | if (valtype == UNKNOWNOID) |
| 779 | valtype = TEXTOID; |
| 780 | |
| 781 | basetype = getBaseType(valtype); |
| 782 | |
| 783 | if (col->typoid != InvalidOid) |
| 784 | ereport(ERROR, |
| 785 | (errcode(ERRCODE_DUPLICATE_COLUMN), |
| 786 | errmsg("column is defined already"))); |
| 787 | |
| 788 | col->typoid = valtype; |
| 789 | |
| 790 | if (PG_ARGISNULL(3)) |
| 791 | ereport(ERROR, |
| 792 | (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), |
| 793 | errmsg("column_size is NULL"))); |
| 794 | |
| 795 | colsize = PG_GETARG_INT32(3); |
| 796 | |
| 797 | get_type_category_preferred(basetype, &category, &ispreferred); |
| 798 | col->typisstr = category == TYPCATEGORY_STRING; |
| 799 | col->typmod = (col->typisstr && colsize != -1) ? colsize + 4 : -1; |
| 800 | |
| 801 | get_typlenbyval(basetype, &col->typlen, &col->typbyval); |
| 802 | |
| 803 | col->rowcount = 1; |
| 804 | |
| 805 | return (Datum) 0; |
| 806 | } |
| 807 |
nothing calls this directly
no test coverage detected