* ExecQueryTuples: assuming query result is OK, execute each query * result field as a SQL statement * * Returns true if successful, false otherwise. */
| 823 | * Returns true if successful, false otherwise. |
| 824 | */ |
| 825 | static bool |
| 826 | ExecQueryTuples(const PGresult *result) |
| 827 | { |
| 828 | bool success = true; |
| 829 | int nrows = PQntuples(result); |
| 830 | int ncolumns = PQnfields(result); |
| 831 | int r, |
| 832 | c; |
| 833 | |
| 834 | /* |
| 835 | * We must turn off gexec_flag to avoid infinite recursion. Note that |
| 836 | * this allows ExecQueryUsingCursor to be applied to the individual query |
| 837 | * results. SendQuery prevents it from being applied when fetching the |
| 838 | * queries-to-execute, because it can't handle recursion either. |
| 839 | */ |
| 840 | pset.gexec_flag = false; |
| 841 | |
| 842 | for (r = 0; r < nrows; r++) |
| 843 | { |
| 844 | for (c = 0; c < ncolumns; c++) |
| 845 | { |
| 846 | if (!PQgetisnull(result, r, c)) |
| 847 | { |
| 848 | const char *query = PQgetvalue(result, r, c); |
| 849 | |
| 850 | /* Abandon execution if cancel_pressed */ |
| 851 | if (cancel_pressed) |
| 852 | goto loop_exit; |
| 853 | |
| 854 | /* |
| 855 | * ECHO_ALL mode should echo these queries, but SendQuery |
| 856 | * assumes that MainLoop did that, so we have to do it here. |
| 857 | */ |
| 858 | if (pset.echo == PSQL_ECHO_ALL && !pset.singlestep) |
| 859 | { |
| 860 | puts(query); |
| 861 | fflush(stdout); |
| 862 | } |
| 863 | |
| 864 | if (!SendQuery(query)) |
| 865 | { |
| 866 | /* Error - abandon execution if ON_ERROR_STOP */ |
| 867 | success = false; |
| 868 | if (pset.on_error_stop) |
| 869 | goto loop_exit; |
| 870 | } |
| 871 | } |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | loop_exit: |
| 876 | |
| 877 | /* |
| 878 | * Restore state. We know gexec_flag was on, else we'd not be here. (We |
| 879 | * also know it'll get turned off at end of command, but that's not ours |
| 880 | * to do here.) |
| 881 | */ |
| 882 | pset.gexec_flag = true; |
no test coverage detected