| 552 | |
| 553 | |
| 554 | Datum |
| 555 | fixedwidth_out(PG_FUNCTION_ARGS) |
| 556 | { |
| 557 | TupleDesc tupdesc; |
| 558 | MemoryContext m, oldcontext; |
| 559 | int ncolumns = 0; |
| 560 | format_t *myData; |
| 561 | char *data; |
| 562 | int datlen = 0; |
| 563 | ListCell *curIdx; |
| 564 | ListCell *curSize; |
| 565 | int field_size; |
| 566 | char *mapped_val; |
| 567 | char *mapped_val_with_blanks; |
| 568 | bool isnull; |
| 569 | Datum value; |
| 570 | int idx; |
| 571 | static FormatConfig format_out_config; |
| 572 | |
| 573 | /* Must be called via the external table format manager */ |
| 574 | if (!CALLED_AS_FORMATTER(fcinfo)) |
| 575 | ereport(ERROR, |
| 576 | (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), |
| 577 | errmsg("fixedwidth_out: not called by format manager"))); |
| 578 | |
| 579 | tupdesc = FORMATTER_GET_TUPDESC(fcinfo); |
| 580 | get_tuple_info(tupdesc, &ncolumns, &myData, &data, fcinfo, &format_out_config); |
| 581 | |
| 582 | /* ======================================================================= |
| 583 | * MAIN FORMATTING CODE |
| 584 | * ======================================================================= */ |
| 585 | m = FORMATTER_GET_PER_ROW_MEM_CTX(fcinfo); |
| 586 | oldcontext = MemoryContextSwitchTo(m); |
| 587 | |
| 588 | forboth(curIdx, format_out_config.fldIndexes, curSize, format_out_config.fldSizes) |
| 589 | { |
| 590 | field_size = lfirst_int(curSize); |
| 591 | idx = lfirst_int(curIdx) - 1; |
| 592 | isnull = myData->nulls[idx]; |
| 593 | value = myData->values[idx]; |
| 594 | |
| 595 | if ( isnull ) |
| 596 | { |
| 597 | mapped_val_with_blanks = make_val_with_blanks(fcinfo, format_out_config.null_value, field_size, &(myData->one_field)); |
| 598 | } |
| 599 | else |
| 600 | { |
| 601 | mapped_val = OutputFunctionCall(&format_out_config.conv_functions[idx], value); |
| 602 | mapped_val_with_blanks = make_val_with_blanks(fcinfo, mapped_val, field_size, &(myData->one_field)); |
| 603 | } |
| 604 | |
| 605 | memcpy(&data[datlen], mapped_val_with_blanks, field_size); |
| 606 | datlen += field_size; |
| 607 | } |
| 608 | |
| 609 | memcpy(&data[datlen], format_out_config.line_delimiter, format_out_config.line_delimiter_length); |
| 610 | datlen += format_out_config.line_delimiter_length; |
| 611 |
nothing calls this directly
no test coverage detected