Thread: Bug #465: Program terminates with "Broken pipe" after PQexec (...)
Bug #465: Program terminates with "Broken pipe" after PQexec (...)
From
pgsql-bugs@postgresql.org
Date:
Roland Baum, MD-SOFT (roland.baum@md-soft.net) reports a bug with a severity of 1 The lower the number the more severe it is. Short Description Program terminates with "Broken pipe" after PQexec (...) Long Description A self-written program terminates after a 2nd PQexec (...). The programm makes a connection to the PostgreSQL-DB before any query is send. The query-function is a authentication in the database. but, after the 2nd call of PQexec (..) in the authenification-function, the programm terminates with a "broken pipe". The mashine, the program & DB runs, is a RedHat Linux from Cobalt (now: Sun). The _same_ code runs under a SuSE-Linux with Postgres and C++ PERFECT and i have no idea, where the problem is! about the program: the software is written in C++ and uses POSIX-threads under Linux. there are a some permantent server-threads, which make the queries to the DB... the program links via -lpq . we hope for a fast answer (please, excuse my bad english :-)) ) r. Sample Code #include <stdarg.h> #include <string> #include <pgsql/libpq-fe.h> int authenticated (const char* host, const char* name, const char* sid) { // Connect to DB PGconn* conn; host=""; if (host != "") { conn = PQsetdbLogin (host, "5432", NULL, "pts/1", "netcom", "postgres", ""); } else { conn = PQsetdbLogin(NULL, "5432", NULL, NULL, "mdcomm", "postgres", ""); } if (PQstatus(conn) == CONNECTION_BAD) { return (-1); } string query; PGresult* queryresult; // build the query query = "SELECT * FROM isconnected, commuser WHERE nick=lower('"; query += name; query += "') AND sid='"; query += sid; query += "' AND commuser.uid=isconnected.uid"; // execute the query // on this call, the programm dies with "broken pipe" queryresult = PQexec(conn, query.c_str()); // if the user exists, the result contains the data if (isconnected == true) { query = "SELECT chatrechte FROM commuser, chatuser WHERE nick=lower('"; query += name; query += "') AND commuser.uid=chatuser.uid"; queryresult = PQexec (conn, query.c_str()); query = PQgetvalue (queryresult, 0, PQfnumber (queryresult, "chatrechte")); // convert string to int int wert = atoi(query.c_str()); PQfinish(conn); return wert; } else { PQfinish(conn); return -1; } No file was uploaded with this report