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

Function main

src/test/examples/testlibpq2.c:50–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50int
51main(int argc, char **argv)
52{
53 const char *conninfo;
54 PGconn *conn;
55 PGresult *res;
56 PGnotify *notify;
57 int nnotifies;
58
59 /*
60 * If the user supplies a parameter on the command line, use it as the
61 * conninfo string; otherwise default to setting dbname=postgres and using
62 * environment variables or defaults for all other connection parameters.
63 */
64 if (argc > 1)
65 conninfo = argv[1];
66 else
67 conninfo = "dbname = postgres";
68
69 /* Make a connection to the database */
70 conn = PQconnectdb(conninfo);
71
72 /* Check to see that the backend connection was successfully made */
73 if (PQstatus(conn) != CONNECTION_OK)
74 {
75 fprintf(stderr, "%s", PQerrorMessage(conn));
76 exit_nicely(conn);
77 }
78
79 /* Set always-secure search path, so malicious users can't take control. */
80 res = PQexec(conn,
81 "SELECT pg_catalog.set_config('search_path', '', false)");
82 if (PQresultStatus(res) != PGRES_TUPLES_OK)
83 {
84 fprintf(stderr, "SET failed: %s", PQerrorMessage(conn));
85 PQclear(res);
86 exit_nicely(conn);
87 }
88
89 /*
90 * Should PQclear PGresult whenever it is no longer needed to avoid memory
91 * leaks
92 */
93 PQclear(res);
94
95 /*
96 * Issue LISTEN command to enable notifications from the rule's NOTIFY.
97 */
98 res = PQexec(conn, "LISTEN TBL2");
99 if (PQresultStatus(res) != PGRES_COMMAND_OK)
100 {
101 fprintf(stderr, "LISTEN command failed: %s", PQerrorMessage(conn));
102 PQclear(res);
103 exit_nicely(conn);
104 }
105 PQclear(res);
106
107 /* Quit after four notifies are received. */

Callers

nothing calls this directly

Calls 12

PQconnectdbFunction · 0.85
PQstatusFunction · 0.85
PQerrorMessageFunction · 0.85
PQexecFunction · 0.85
PQresultStatusFunction · 0.85
PQclearFunction · 0.85
PQsocketFunction · 0.85
PQconsumeInputFunction · 0.85
PQnotifiesFunction · 0.85
PQfreememFunction · 0.85
PQfinishFunction · 0.85
exit_nicelyFunction · 0.70

Tested by

no test coverage detected