| 588 | } |
| 589 | |
| 590 | static void |
| 591 | bind_array(FunctionCallInfo fcinfo, int index1, int index2) |
| 592 | { |
| 593 | CursorData *c; |
| 594 | VariableData *var; |
| 595 | char *varname, *varname_downcase; |
| 596 | Oid valtype; |
| 597 | Oid elementtype; |
| 598 | |
| 599 | c = get_cursor(fcinfo, true); |
| 600 | |
| 601 | if (PG_ARGISNULL(1)) |
| 602 | ereport(ERROR, |
| 603 | (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), |
| 604 | errmsg("name of bind variable is NULL"))); |
| 605 | |
| 606 | varname = text_to_cstring(PG_GETARG_TEXT_P(1)); |
| 607 | if (*varname == ':') |
| 608 | varname += 1; |
| 609 | |
| 610 | varname_downcase = downcase_identifier(varname, (int) strlen(varname), false, true); |
| 611 | var = get_var(c, varname_downcase, -1, false); |
| 612 | |
| 613 | valtype = get_fn_expr_argtype(fcinfo->flinfo, 2); |
| 614 | if (valtype == RECORDOID) |
| 615 | ereport(ERROR, |
| 616 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 617 | errmsg("cannot to bind a value of record type"))); |
| 618 | |
| 619 | valtype = getBaseType(valtype); |
| 620 | elementtype = get_element_type(valtype); |
| 621 | |
| 622 | if (!OidIsValid(elementtype)) |
| 623 | ereport(ERROR, |
| 624 | (errcode(ERRCODE_DATATYPE_MISMATCH), |
| 625 | errmsg("value is not a array"))); |
| 626 | |
| 627 | if (var->typoid != InvalidOid) |
| 628 | { |
| 629 | if (!var->typbyval && !var->isnull) |
| 630 | { |
| 631 | pfree(DatumGetPointer(var->value)); |
| 632 | var->value = (Datum) 0; |
| 633 | } |
| 634 | |
| 635 | var->isnull = true; |
| 636 | } |
| 637 | |
| 638 | var->is_array = true; |
| 639 | var->typoid = valtype; |
| 640 | var->typelemid = elementtype; |
| 641 | |
| 642 | get_typlenbyval(elementtype, &var->typelemlen, &var->typelembyval); |
| 643 | |
| 644 | if (!PG_ARGISNULL(2)) |
| 645 | { |
| 646 | MemoryContext oldcxt; |
| 647 |
no test coverage detected