pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Crash when using PQgetvalue
3+ messages / 3 participants
[nested] [flat]

* Crash when using PQgetvalue
@ 2018-06-04 15:26 PG Doc comments form <noreply@postgresql.org>
  2018-06-04 23:57 ` Re: Crash when using PQgetvalue Craig Ringer <craig@2ndquadrant.com>
  0 siblings, 1 reply; 3+ messages in thread

From: PG Doc comments form @ 2018-06-04 15:26 UTC (permalink / raw)
  To: pgsql-docs@lists.postgresql.org; +Cc: duncan.reitboeck@gmail.com

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/9.5/static/libpq.html
Description:

Hello,

I am not sure if I am doing something wrong or there is a bug in the code
but I am getting a strange issue. When I try to run the following code I get
a crash when attempting to accessing the values using PQgetvalue. 

I was able to print off all the column names using PQfname. If I replace
PQgetvalue with PQgetlength the correct rows, fields and lengths are
printed. Checking PQgetisnull displayed the value as not null. I also did a
few checks using PQstatus and PQresultStatus to make sure the connection or
result set didn't mess up somehow in the middle of the code.

  PGconn *con;
  PGresult *pg_result;
  
  int i = 0;
  int j = 0;
  int cols = 0;
  int rows = 0;
  
  con = PQconnectdb("host=localhost user=postgres password=test
dbname=test");
  
  if(PQstatus(con) != CONNECTION_OK)
  {
    printf("Could not connect to PostgreSQL database!");
    fflush(stdout);
  }
  else
  {
    g_print("Connected.\n");
    
    pg_result = PQexec(con, "SELECT * FROM test");   
          
    if(PQresultStatus(pg_result) == PGRES_TUPLES_OK)
    {
      rows = PQntuples(pg_result);
      cols = PQnfields(pg_result);

      for(i = 0; i < rows; ++i)
      {
        for(j = 0; j < cols; ++j)
        {
          printf("Row: %d - Col: %d = %s\n", i, j, PQgetvalue(pg_result, i,
j)); //This is where the crash occurs. Also happens if not attempting to
print and simply getting the value or calling the function.
          fflush(stdout);
        }
      }
    }
    PQclear(pg_result);
    PQfinish(con);
    con = NULL;
  }


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Crash when using PQgetvalue
  2018-06-04 15:26 Crash when using PQgetvalue PG Doc comments form <noreply@postgresql.org>
@ 2018-06-04 23:57 ` Craig Ringer <craig@2ndquadrant.com>
  2018-06-05 00:22   ` Re: Crash when using PQgetvalue Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Craig Ringer @ 2018-06-04 23:57 UTC (permalink / raw)
  To: duncan.reitboeck@gmail.com; pgsql-docs@lists.postgresql.org

On 4 June 2018 at 23:26, PG Doc comments form <noreply@postgresql.org>
wrote:

> The following documentation comment has been logged on the website:
>
> Page: https://www.postgresql.org/docs/9.5/static/libpq.html
> Description:
>
> Hello,
>
> I am not sure if I am doing something wrong or there is a bug in the code
> but I am getting a strange issue. When I try to run the following code I
> get
> a crash when attempting to accessing the values using PQgetvalue.


This isn't really a comment on the documentation. Please ask for help on
the pgsql-general mailing list, Stack Overflow, or suitable forums.

You should provide a backtrace of the crash from a debugger when you do so.

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Crash when using PQgetvalue
  2018-06-04 15:26 Crash when using PQgetvalue PG Doc comments form <noreply@postgresql.org>
  2018-06-04 23:57 ` Re: Crash when using PQgetvalue Craig Ringer <craig@2ndquadrant.com>
@ 2018-06-05 00:22   ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2018-06-05 00:22 UTC (permalink / raw)
  To: Craig Ringer <craig@2ndquadrant.com>; +Cc: duncan.reitboeck@gmail.com; pgsql-docs@lists.postgresql.org

Craig Ringer <craig@2ndquadrant.com> writes:
> On 4 June 2018 at 23:26, PG Doc comments form <noreply@postgresql.org>
>> I am not sure if I am doing something wrong or there is a bug in the code
>> but I am getting a strange issue. When I try to run the following code I
>> get a crash when attempting to accessing the values using PQgetvalue.

> This isn't really a comment on the documentation.

Indeed.  The submitter did file a bug a bit later, and we dealt with it
over there.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2018-06-05 00:22 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-06-04 15:26 Crash when using PQgetvalue PG Doc comments form <noreply@postgresql.org>
2018-06-04 23:57 ` Craig Ringer <craig@2ndquadrant.com>
2018-06-05 00:22   ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox