MCPcopy Create free account
hub / github.com/apache/cloudberry / SendQuery

Function SendQuery

src/bin/psql/common.c:1189–1457  ·  view source on GitHub ↗

* SendQuery: send the query string to the backend * (and print out results) * * Note: This is the "front door" way to send a query. That is, use it to * send queries actually entered by the user. These queries will be subject to * single step mode. * To send "back door" queries (generated by slash commands, etc.) in a * controlled way, use PSQLexec(). * * Returns true if the query execute

Source from the content-addressed store, hash-verified

1187 * Returns true if the query executed successfully, false otherwise.
1188 */
1189bool
1190SendQuery(const char *query)
1191{
1192 PGresult *results;
1193 PGTransactionStatusType transaction_status;
1194 double elapsed_msec = 0;
1195 bool OK = false;
1196 int i;
1197 bool on_error_rollback_savepoint = false;
1198 static bool on_error_rollback_warning = false;
1199
1200 if (!pset.db)
1201 {
1202 pg_log_error("You are currently not connected to a database.");
1203 goto sendquery_cleanup;
1204 }
1205
1206 if (pset.singlestep)
1207 {
1208 char buf[3];
1209
1210 fflush(stderr);
1211 printf(_("***(Single step mode: verify command)*******************************************\n"
1212 "%s\n"
1213 "***(press return to proceed or enter x and return to cancel)********************\n"),
1214 query);
1215 fflush(stdout);
1216 if (fgets(buf, sizeof(buf), stdin) != NULL)
1217 if (buf[0] == 'x')
1218 goto sendquery_cleanup;
1219 if (cancel_pressed)
1220 goto sendquery_cleanup;
1221 }
1222 else if (pset.echo == PSQL_ECHO_QUERIES)
1223 {
1224 puts(query);
1225 fflush(stdout);
1226 }
1227
1228 if (pset.logfile)
1229 {
1230 fprintf(pset.logfile,
1231 _("********* QUERY **********\n"
1232 "%s\n"
1233 "**************************\n\n"), query);
1234 fflush(pset.logfile);
1235 }
1236
1237 SetCancelConn(pset.db);
1238
1239 transaction_status = PQtransactionStatus(pset.db);
1240
1241 if (transaction_status == PQTRANS_IDLE &&
1242 !pset.autocommit &&
1243 !command_no_begin(query))
1244 {
1245 results = PQexec(pset.db, "BEGIN");
1246 if (PQresultStatus(results) != PGRES_COMMAND_OK)

Callers 4

mainFunction · 0.85
do_copyFunction · 0.85
ExecQueryTuplesFunction · 0.85
MainLoopFunction · 0.85

Calls 15

SetCancelConnFunction · 0.85
PQtransactionStatusFunction · 0.85
command_no_beginFunction · 0.85
PQexecFunction · 0.85
PQresultStatusFunction · 0.85
PQerrorMessageFunction · 0.85
ClearOrSaveResultFunction · 0.85
ResetCancelConnFunction · 0.85
formatPGVersionNumberFunction · 0.85
DescribeQueryFunction · 0.85
is_select_commandFunction · 0.85
ProcessResultFunction · 0.85

Tested by

no test coverage detected