PostgreSQL Source Code  git master
query_utils.c File Reference
#include "postgres_fe.h"
#include "common/logging.h"
#include "fe_utils/cancel.h"
#include "fe_utils/query_utils.h"
Include dependency graph for query_utils.c:

Go to the source code of this file.

Functions

PGresultexecuteQuery (PGconn *conn, const char *query, bool echo)
 
void executeCommand (PGconn *conn, const char *query, bool echo)
 
bool executeMaintenanceCommand (PGconn *conn, const char *query, bool echo)
 

Function Documentation

◆ executeCommand()

void executeCommand ( PGconn conn,
const char *  query,
bool  echo 
)

Definition at line 47 of file query_utils.c.

48 {
49  PGresult *res;
50 
51  if (echo)
52  printf("%s\n", query);
53 
54  res = PQexec(conn, query);
55  if (!res ||
57  {
58  pg_log_error("query failed: %s", PQerrorMessage(conn));
59  pg_log_error_detail("Query was: %s", query);
60  PQfinish(conn);
61  exit(1);
62  }
63 
64  PQclear(res);
65 }
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6908
void PQfinish(PGconn *conn)
Definition: fe-connect.c:4261
ExecStatusType PQresultStatus(const PGresult *res)
Definition: fe-exec.c:3270
void PQclear(PGresult *res)
Definition: fe-exec.c:718
PGresult * PQexec(PGconn *conn, const char *query)
Definition: fe-exec.c:2273
@ PGRES_COMMAND_OK
Definition: libpq-fe.h:97
exit(1)
#define pg_log_error(...)
Definition: logging.h:106
#define pg_log_error_detail(...)
Definition: logging.h:109
#define printf(...)
Definition: port.h:231
PGconn * conn
Definition: streamutil.c:54

References conn, exit(), pg_log_error, pg_log_error_detail, PGRES_COMMAND_OK, PQclear(), PQerrorMessage(), PQexec(), PQfinish(), PQresultStatus(), printf, and res.

◆ executeMaintenanceCommand()

bool executeMaintenanceCommand ( PGconn conn,
const char *  query,
bool  echo 
)

Definition at line 74 of file query_utils.c.

75 {
76  PGresult *res;
77  bool r;
78 
79  if (echo)
80  printf("%s\n", query);
81 
83  res = PQexec(conn, query);
85 
87 
88  if (res)
89  PQclear(res);
90 
91  return r;
92 }
void ResetCancelConn(void)
Definition: cancel.c:107
void SetCancelConn(PGconn *conn)
Definition: cancel.c:77

References conn, PGRES_COMMAND_OK, PQclear(), PQexec(), PQresultStatus(), printf, res, ResetCancelConn(), and SetCancelConn().

Referenced by cluster_one_database(), and run_reindex_command().

◆ executeQuery()

PGresult* executeQuery ( PGconn conn,
const char *  query,
bool  echo 
)

Definition at line 22 of file query_utils.c.

23 {
24  PGresult *res;
25 
26  if (echo)
27  printf("%s\n", query);
28 
29  res = PQexec(conn, query);
30  if (!res ||
32  {
33  pg_log_error("query failed: %s", PQerrorMessage(conn));
34  pg_log_error_detail("Query was: %s", query);
35  PQfinish(conn);
36  exit(1);
37  }
38 
39  return res;
40 }
@ PGRES_TUPLES_OK
Definition: libpq-fe.h:100

References conn, exit(), pg_log_error, pg_log_error_detail, PGRES_TUPLES_OK, PQerrorMessage(), PQexec(), PQfinish(), PQresultStatus(), printf, and res.