* fixedwidth_in * each time this function is called, it builds one tuple from the input data buffer */
| 622 | * each time this function is called, it builds one tuple from the input data buffer |
| 623 | */ |
| 624 | Datum |
| 625 | fixedwidth_in(PG_FUNCTION_ARGS) |
| 626 | { |
| 627 | HeapTuple tuple; |
| 628 | TupleDesc tupdesc; |
| 629 | MemoryContext m, oldcontext; |
| 630 | format_t *myData; |
| 631 | char *data_buf; |
| 632 | int ncolumns = 0; |
| 633 | int data_cur; |
| 634 | int data_len; |
| 635 | bool saw_eof; |
| 636 | bool eof_is_lf; |
| 637 | ListCell *curIdx; |
| 638 | ListCell *curSize; |
| 639 | ListCell *cur_null_with_blanks = NULL; |
| 640 | int remaining; |
| 641 | int field_size; |
| 642 | int row_size; |
| 643 | char *nullval; |
| 644 | int idx; |
| 645 | char *null_val_with_blanks; |
| 646 | static FormatConfig format_in_config; |
| 647 | |
| 648 | /* Must be called via the external table format manager */ |
| 649 | if (!CALLED_AS_FORMATTER(fcinfo)) |
| 650 | ereport(ERROR, |
| 651 | (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION), |
| 652 | errmsg("fixedwidth_in: not called by format manager"))); |
| 653 | |
| 654 | tupdesc = FORMATTER_GET_TUPDESC(fcinfo); |
| 655 | |
| 656 | /* Get our internal description of the formatter */ |
| 657 | ncolumns = tupdesc->natts; |
| 658 | myData = (format_t *) FORMATTER_GET_USER_CTX(fcinfo); |
| 659 | |
| 660 | if (myData == NULL) |
| 661 | { |
| 662 | init_format_in_config(&format_in_config, ncolumns, tupdesc, fcinfo); |
| 663 | init_format_t(&myData, ncolumns, fcinfo); |
| 664 | } |
| 665 | |
| 666 | /* start clean */ |
| 667 | MemSet(myData->values, 0, ncolumns * sizeof(Datum)); |
| 668 | MemSet(myData->nulls, true, ncolumns * sizeof(bool)); |
| 669 | |
| 670 | /* get our input data buf and number of valid bytes in it */ |
| 671 | data_buf = FORMATTER_GET_DATABUF(fcinfo); |
| 672 | data_len = FORMATTER_GET_DATALEN(fcinfo); |
| 673 | data_cur = FORMATTER_GET_DATACURSOR(fcinfo); |
| 674 | saw_eof = FORMATTER_GET_SAW_EOF(fcinfo); |
| 675 | |
| 676 | eof_is_lf = (format_in_config.line_delimiter[0] == '\n' ? true : false); |
| 677 | |
| 678 | /* ======================================================================= |
| 679 | * MAIN FORMATTING CODE |
| 680 | * ======================================================================= */ |
| 681 | /* |
nothing calls this directly
no test coverage detected