#include <stdio.h>
#include <stdlib.h>
#include "libpq-fe.h"
Go to the source code of this file.
◆ check_prepare_conn()
static void check_prepare_conn |
( |
PGconn * |
conn, |
|
|
const char * |
dbName |
|
) |
| |
|
static |
Definition at line 25 of file testlibpq4.c.
26{
28
29
31 {
33 exit(1);
34 }
35
36
38 "SELECT pg_catalog.set_config('search_path', '', false)");
40 {
43 exit(1);
44 }
46}
#define fprintf(file, fmt, msg)
ConnStatusType PQstatus(const PGconn *conn)
char * PQerrorMessage(const PGconn *conn)
ExecStatusType PQresultStatus(const PGresult *res)
void PQclear(PGresult *res)
PGresult * PQexec(PGconn *conn, const char *query)
References conn, CONNECTION_OK, fprintf, PGRES_TUPLES_OK, PQclear(), PQerrorMessage(), PQexec(), PQresultStatus(), and PQstatus().
Referenced by main().
◆ exit_nicely()
Definition at line 15 of file testlibpq4.c.
16{
17 if (conn1)
19 if (conn2)
21 exit(1);
22}
void PQfinish(PGconn *conn)
References PQfinish().
Referenced by main().
◆ main()
int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Definition at line 49 of file testlibpq4.c.
50{
53 *pgoptions;
54 char *dbName1,
55 *dbName2;
56 char *tblName;
57 int nFields;
60
62 *conn2;
63
64
65
66
68
69 if (argc != 4)
70 {
71 fprintf(stderr,
"usage: %s tableName dbName1 dbName2\n", argv[0]);
72 fprintf(stderr,
" compares two tables in two databases\n");
73 exit(1);
74 }
75 tblName = argv[1];
76 dbName1 = argv[2];
77 dbName2 = argv[3];
78
79
80
81
82
83
84
85
88 pgoptions = NULL;
89
90
91
94
97
98
99 res1 =
PQexec(conn1,
"BEGIN");
101 {
102 fprintf(stderr,
"BEGIN command failed\n");
105 }
106
107
108
109
110
112
113
114
115
116 res1 =
PQexec(conn1,
"DECLARE myportal CURSOR FOR select * from pg_database");
118 {
119 fprintf(stderr,
"DECLARE CURSOR command failed\n");
122 }
124
125 res1 =
PQexec(conn1,
"FETCH ALL in myportal");
127 {
128 fprintf(stderr,
"FETCH ALL command didn't return tuples properly\n");
131 }
132
133
135 for (
i = 0;
i < nFields;
i++)
138
139
141 {
142 for (
j = 0;
j < nFields;
j++)
145 }
146
148
149
150 res1 =
PQexec(conn1,
"CLOSE myportal");
152
153
154 res1 =
PQexec(conn1,
"END");
156
157
160
161
162 return 0;
163}
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
int PQntuples(const PGresult *res)
char * PQfname(const PGresult *res, int field_num)
int PQnfields(const PGresult *res)
#define PQsetdb(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME)
static const char * pghost
static const char * pgport
static void exit_nicely(PGconn *conn1, PGconn *conn2)
static void check_prepare_conn(PGconn *conn, const char *dbName)
References check_prepare_conn(), exit_nicely(), fprintf, i, j, pghost, pgport, PGRES_COMMAND_OK, PGRES_TUPLES_OK, PQclear(), PQexec(), PQfinish(), PQfname(), PQgetvalue(), PQnfields(), PQntuples(), PQresultStatus(), PQsetdb, and printf.