Skip site navigation (1) Skip section navigation (2)

PQtrace doesn't work

From: "W(dot) van den Akker" <listsrv(at)wilsoft(dot)nl>
To: pgsql <pgsql-general(at)postgresql(dot)org>
Subject: PQtrace doesn't work
Date: 2004-01-29 14:25:35
Message-ID: 401917DF.5030001@wilsoft.nl (view raw or flat)
Thread:
Lists: pgsql-general
Hello,

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 v7.3.4. When I comment the 
line the program runs fine.

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();     
}



In response to

Responses

pgsql-general by date

Next:From: Barbara LindseyDate: 2004-01-29 14:52:56
Subject: Grant question
Previous:From: Dave SmithDate: 2004-01-29 13:51:50
Subject: A strange Vacuum error ...

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group