Send a SQL command, using the chosen querymode */
| 2871 | |
| 2872 | /* Send a SQL command, using the chosen querymode */ |
| 2873 | static bool |
| 2874 | sendCommand(CState *st, Command *command) |
| 2875 | { |
| 2876 | int r; |
| 2877 | |
| 2878 | if (querymode == QUERY_SIMPLE) |
| 2879 | { |
| 2880 | char *sql; |
| 2881 | |
| 2882 | sql = pg_strdup(command->argv[0]); |
| 2883 | sql = assignVariables(st, sql); |
| 2884 | |
| 2885 | pg_log_debug("client %d sending %s", st->id, sql); |
| 2886 | r = PQsendQuery(st->con, sql); |
| 2887 | free(sql); |
| 2888 | } |
| 2889 | else if (querymode == QUERY_EXTENDED) |
| 2890 | { |
| 2891 | const char *sql = command->argv[0]; |
| 2892 | const char *params[MAX_ARGS]; |
| 2893 | |
| 2894 | getQueryParams(st, command, params); |
| 2895 | |
| 2896 | pg_log_debug("client %d sending %s", st->id, sql); |
| 2897 | r = PQsendQueryParams(st->con, sql, command->argc - 1, |
| 2898 | NULL, params, NULL, NULL, 0); |
| 2899 | } |
| 2900 | else if (querymode == QUERY_PREPARED) |
| 2901 | { |
| 2902 | char name[MAX_PREPARE_NAME]; |
| 2903 | const char *params[MAX_ARGS]; |
| 2904 | |
| 2905 | if (!st->prepared[st->use_file]) |
| 2906 | { |
| 2907 | int j; |
| 2908 | Command **commands = sql_script[st->use_file].commands; |
| 2909 | |
| 2910 | for (j = 0; commands[j] != NULL; j++) |
| 2911 | { |
| 2912 | PGresult *res; |
| 2913 | char name[MAX_PREPARE_NAME]; |
| 2914 | |
| 2915 | if (commands[j]->type != SQL_COMMAND) |
| 2916 | continue; |
| 2917 | preparedStatementName(name, st->use_file, j); |
| 2918 | if (PQpipelineStatus(st->con) == PQ_PIPELINE_OFF) |
| 2919 | { |
| 2920 | res = PQprepare(st->con, name, |
| 2921 | commands[j]->argv[0], commands[j]->argc - 1, NULL); |
| 2922 | if (PQresultStatus(res) != PGRES_COMMAND_OK) |
| 2923 | pg_log_error("%s", PQerrorMessage(st->con)); |
| 2924 | PQclear(res); |
| 2925 | } |
| 2926 | else |
| 2927 | { |
| 2928 | /* |
| 2929 | * In pipeline mode, we use asynchronous functions. If a |
| 2930 | * server-side error occurs, it will be processed later |
no test coverage detected