* Executes the Insert query and returns the total count of processed results. */
| 1561 | * Executes the Insert query and returns the total count of processed results. |
| 1562 | */ |
| 1563 | static uint64_t |
| 1564 | RunInsertQuery(Query *insertQuery, ParamListInfo paramListInfo) |
| 1565 | { |
| 1566 | uint64_t numRowsProcessed = 0; |
| 1567 | |
| 1568 | int cursorOptions = CURSOR_OPT_NO_SCROLL | CURSOR_OPT_BINARY; |
| 1569 | Portal queryPortal = CreateNewPortal(); |
| 1570 | queryPortal->visible = false; |
| 1571 | queryPortal->cursorOptions = cursorOptions; |
| 1572 | |
| 1573 | PlannedStmt *queryPlan = pg_plan_query(insertQuery, NULL, cursorOptions, |
| 1574 | paramListInfo); |
| 1575 | |
| 1576 | /* Set the plan in the cursor for this iteration */ |
| 1577 | PortalDefineQuery(queryPortal, NULL, "", |
| 1578 | CMDTAG_SELECT, |
| 1579 | list_make1(queryPlan), |
| 1580 | NULL); |
| 1581 | |
| 1582 | /* Trigger execution (Start the ExecEngine etc.) */ |
| 1583 | PortalStart(queryPortal, paramListInfo, 0, GetActiveSnapshot()); |
| 1584 | |
| 1585 | if (SPI_connect() != SPI_OK_CONNECT) |
| 1586 | { |
| 1587 | ereport(ERROR, (errmsg("could not connect to SPI manager"))); |
| 1588 | } |
| 1589 | |
| 1590 | /* run through everything but load no results. */ |
| 1591 | SPI_cursor_move(queryPortal, true, FETCH_ALL); |
| 1592 | |
| 1593 | numRowsProcessed = SPI_processed; |
| 1594 | SPI_cursor_close(queryPortal); |
| 1595 | |
| 1596 | if (SPI_finish() != SPI_OK_FINISH) |
| 1597 | { |
| 1598 | ereport(ERROR, (errmsg("could not complete SPI query"))); |
| 1599 | } |
| 1600 | |
| 1601 | return numRowsProcessed; |
| 1602 | } |
| 1603 | |
| 1604 | |
| 1605 | /* |
no outgoing calls
no test coverage detected