PostgreSQL Source Code  git master
query_utils.h File Reference
#include "postgres_fe.h"
#include "libpq-fe.h"
Include dependency graph for query_utils.h:
This graph shows which files directly or indirectly include this file:

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:7200
void PQfinish(PGconn *conn)
Definition: fe-connect.c:4879
ExecStatusType PQresultStatus(const PGresult *res)
Definition: fe-exec.c:3411
PGresult * PQexec(PGconn *conn, const char *query)
Definition: fe-exec.c:2262
@ PGRES_COMMAND_OK
Definition: libpq-fe.h:120
exit(1)
#define pg_log_error(...)
Definition: logging.h:106
#define pg_log_error_detail(...)
Definition: logging.h:109
#define printf(...)
Definition: port.h:244
PGconn * conn
Definition: streamutil.c:53

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  PQclear(res);
89 
90  return r;
91 }
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:123

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