/* * Does a libpq built WITHOUT the patch accept the rich 'Z' message? * * Build once against any libpq, then swap the library at run time with * LD_LIBRARY_PATH. It exercises the three libpq paths that read * ReadyForQuery: simple query, extended query (PQexecParams) and fast-path * (PQfn, through lo_creat). Every message is traced with PQtrace(). * * old_libpq_client "" * * Exit status: 0 = all steps OK, 1 = some step failed, 2 = could not connect. */ #include #include #include "libpq-fe.h" #include "libpq/libpq-fs.h" static int step(PGconn *conn, const char *label, PGresult *res) { ExecStatusType st = res ? PQresultStatus(res) : PGRES_FATAL_ERROR; int ok = (st == PGRES_TUPLES_OK || st == PGRES_COMMAND_OK); printf(" %-28s %s conn=%s txstatus=%d value=%s error=%s\n", label, ok ? "OK " : "FAIL", PQstatus(conn) == CONNECTION_OK ? "OK" : "BAD", PQtransactionStatus(conn), (ok && st == PGRES_TUPLES_OK && PQntuples(res) > 0) ? PQgetvalue(res, 0, 0) : "-", ok ? "-" : PQerrorMessage(conn)); PQclear(res); return ok; } int main(int argc, char **argv) { PGconn *conn; FILE *trace; const char *params[1] = {"7"}; Oid lo; int failures = 0; if (argc != 3) { fprintf(stderr, "usage: %s \"\" \n", argv[0]); return 2; } printf(" libpq version=%d\n", PQlibVersion()); conn = PQconnectdb(argv[1]); if (PQstatus(conn) != CONNECTION_OK) { printf(" CONNECT FAILED: %s\n", PQerrorMessage(conn)); return 2; } printf(" connect OK ready_for_query_message=%s\n", PQparameterStatus(conn, "ready_for_query_message") ? PQparameterStatus(conn, "ready_for_query_message") : "(not reported)"); trace = fopen(argv[2], "w"); PQtrace(conn, trace); failures += !step(conn, "simple: SELECT 1", PQexec(conn, "SELECT 1")); failures += !step(conn, "simple: SELECT 2", PQexec(conn, "SELECT 2")); failures += !step(conn, "extended: SELECT $1", PQexecParams(conn, "SELECT $1::int", 1, NULL, params, NULL, NULL, 0)); failures += !step(conn, "BEGIN", PQexec(conn, "BEGIN")); lo = lo_creat(conn, INV_READ | INV_WRITE); printf(" %-28s %s oid=%u error=%s\n", "fast-path: lo_creat (PQfn)", lo ? "OK " : "FAIL", lo, lo ? "-" : PQerrorMessage(conn)); failures += !lo; failures += !step(conn, "COMMIT", PQexec(conn, "COMMIT")); failures += !step(conn, "simple: SELECT 3", PQexec(conn, "SELECT 3")); printf(" RESULT: %d failures, final conn=%s\n", failures, PQstatus(conn) == CONNECTION_OK ? "OK" : "BAD"); PQfinish(conn); fclose(trace); return failures ? 1 : 0; }