| 2580 | |
| 2581 | |
| 2582 | Datum |
| 2583 | cursor_to_xml(PG_FUNCTION_ARGS) |
| 2584 | { |
| 2585 | char *name = text_to_cstring(PG_GETARG_TEXT_PP(0)); |
| 2586 | int32 count = PG_GETARG_INT32(1); |
| 2587 | bool nulls = PG_GETARG_BOOL(2); |
| 2588 | bool tableforest = PG_GETARG_BOOL(3); |
| 2589 | const char *targetns = text_to_cstring(PG_GETARG_TEXT_PP(4)); |
| 2590 | |
| 2591 | StringInfoData result; |
| 2592 | Portal portal; |
| 2593 | uint64 i; |
| 2594 | |
| 2595 | initStringInfo(&result); |
| 2596 | |
| 2597 | if (!tableforest) |
| 2598 | { |
| 2599 | xmldata_root_element_start(&result, "table", NULL, targetns, true); |
| 2600 | appendStringInfoChar(&result, '\n'); |
| 2601 | } |
| 2602 | |
| 2603 | SPI_connect(); |
| 2604 | portal = SPI_cursor_find(name); |
| 2605 | if (portal == NULL) |
| 2606 | ereport(ERROR, |
| 2607 | (errcode(ERRCODE_UNDEFINED_CURSOR), |
| 2608 | errmsg("cursor \"%s\" does not exist", name))); |
| 2609 | |
| 2610 | SPI_cursor_fetch(portal, true, count); |
| 2611 | for (i = 0; i < SPI_processed; i++) |
| 2612 | SPI_sql_row_to_xmlelement(i, &result, NULL, nulls, |
| 2613 | tableforest, targetns, true); |
| 2614 | |
| 2615 | SPI_finish(); |
| 2616 | |
| 2617 | if (!tableforest) |
| 2618 | xmldata_root_element_end(&result, "table"); |
| 2619 | |
| 2620 | PG_RETURN_XML_P(stringinfo_to_xmltype(&result)); |
| 2621 | } |
| 2622 | |
| 2623 | |
| 2624 | /* |
nothing calls this directly
no test coverage detected