Re: PQtrace doesn't work

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: "W(dot) van den Akker" <listsrv(at)wilsoft(dot)nl>
Cc: pgsql <pgsql-general(at)postgresql(dot)org>
Subject: Re: PQtrace doesn't work
Date: 2005-09-23 02:24:02
Message-ID: 200509230224.j8N2O2h21677@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

W. van den Akker wrote:
> Hello,
>
> I've send this message also on 29-1-2004 and have since no solution for
> this problem .. >:o .
> I have a little test program (see at the end of the message).
> The program crashes when PQTrace is called (instruction xxxx referenced
> memory at "0x00000010", the
> memory could not be written" (obvious ... ). I use the library
> libpqdll.lib and postgresql v8.0.1, but also happens
> in 7.4.9.
> Running under W2000 sp4, VC++ 6 SP5. If compiling under Linux then there
> is no problem. Obvious there is
> something wrong with the use under windows
>
> If I comment traceoption all works fine.

Looking at the code, the only thing I see done by PQtrace are some calls
to fprintf to that file descriptor, like this:

fe-misc.c: fprintf(conn->Pfdebug, libpq_gettext("To backend> Msg %c\n"),

Hard to imagine what would fail there, unless libpq_gettext() doesn't
work, but you are probably not use NLS, so it would be a noop:

#define libpq_gettext(x) (x)

Can you send us a backtrace of the failure from VC++? We don't have too
many internals guys using that setup, but the backtrace should suggest a
cause.

---------------------------------------------------------------------------

>
> Any ideas?
>
> gr,
>
> Willem.
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <libpq-fe.h>
> #include <winsock.h>
>
> void main ()
> {
> int nFields;
> int i, j;
>
> PGconn *conn;
> PGresult *res;
>
> char *pghost = "linux";
> char *dbName = "some_db";
>
> FILE *debug;
>
> WSADATA wsadata;
> WSAStartup(0x0101, &wsadata);
>
>
> conn = PQsetdbLogin (pghost, NULL, NULL, NULL, dbName, "user","");
>
> if (PQstatus(conn) == CONNECTION_BAD)
> {
> printf ("Connection to database %s is failed\n", dbName);
> printf ("%s", PQerrorMessage (conn));
> PQfinish (conn);
> exit (1);
> }
>
> debug = fopen ("trace.out", "w");
> --->> PQtrace (conn, debug);
>
> res = PQexec (conn, "BEGIN");
> if (!res || PQresultStatus (res) != PGRES_COMMAND_OK)
> {
> printf ("BEGIN command failed\n");
> PQclear (res);
> PQfinish (conn);
> exit (1);
> }
>
> PQclear (res);
>
> res = PQexec (conn, "DECLARE mycursor CURSOR FOR select sum(id) from
> relaties");
> if (!res || PQresultStatus (res) != PGRES_COMMAND_OK)
> {
> printf ("DECLARE CURSOR command failed\n");
> PQclear (res);
> PQfinish (conn);
> exit (1);
> }
>
> PQclear (res);
> res = PQexec (conn, "FETCH ALL in mycursor");
> if (!res || PQresultStatus (res) != PGRES_TUPLES_OK)
> {
> printf ("FETCH ALL command didn't return tuples properly\n");
> PQclear (res);
> PQfinish (conn);
> exit (1);
> }
>
> nFields = PQnfields (res);
> for (i = 0; i < nFields; i++)
> printf ("%-15s", PQfname (res, i));
>
> printf ("\n\n");
>
> for (i = 0; i < PQntuples (res); i++)
> {
> for (j = 0; j < nFields; j++)
> printf ("%-15s", PQgetvalue (res, i, j));
> printf ("\n");
> }
>
> PQclear (res);
>
> res = PQexec (conn, "CLOSE mycursor");
> PQclear (res);
>
> res = PQexec (conn, "COMMIT");
> PQclear (res);
> PQfinish (conn);
>
> fclose (debug);
>
> WSACleanup();
> }
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruno Wolff III 2005-09-23 02:52:51 Re: array_dims array_lower/upper distance
Previous Message vishal saberwal 2005-09-23 00:28:58 Re: Getting the amount of overlap when using OVERLAPS