pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: bartsmink@gmail.com
Subject: BUG #16051: PQgetvalue(res,0,0) is null, PQgetlength(res,0,0) is 10
Date: Fri, 11 Oct 2019 22:42:06 +0000
Message-ID: <16051-cf9069d07dd1df16@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      16051
Logged by:          Libpq does not fetch first result in table
Email address:      bartsmink@gmail.com
PostgreSQL version: 12.0
Operating system:   Macos 10.15
Description:        

Hi,

I'm running unit tests in doctest and cannot make a simple test succeed. The
code is below:

SUBCASE("TEST first column first row value is stored in db"){
        res = PQexec(conn, "CREATE TABLE \"Schema1\".testdata\
        (\
            \"Time\" decimal,\
            \"RAW\" bytea,\
            \"EPC\" bytea,\
            \"RSSI\" bytea,\
            \"PC\" bytea);\
            ALTER TABLE \"Schema1\".testdata\
            OWNER to sab24;"
        );
        CHECK(PQresultStatus(res) == PGRES_COMMAND_OK);
        if (PQresultStatus(res) != PGRES_COMMAND_OK){
            fprintf(stderr, "CREATE TABLE FAILED: %s",
PQerrorMessage(conn));
            PQclear(res);
        } 
        res = PQexec(conn, "INSERT INTO \"Schema1\".testdata values(1234,
'abc', 'abc', 'abc', 'abc');");
        CHECK(PQresultStatus(res) == PGRES_COMMAND_OK);
        if (PQresultStatus(res) != PGRES_COMMAND_OK){
            fprintf(stderr, "CREATE TABLE FAILED: %s",
PQerrorMessage(conn));
            PQclear(res);
        } 

        res = PQexecParams(conn, 
        "SELECT * FROM testdata;",
        0,
        NULL,
        NULL,
        NULL,
        NULL,
        1);

        CHECK(PQresultStatus(res) == PGRES_TUPLES_OK);
        if (PQresultStatus(res) != PGRES_TUPLES_OK){
            fprintf(stderr, "SELECT TABLE FAILED: %s",
PQerrorMessage(conn));
            PQclear(res);
        } 
        else{
            std::cout << "value is: " << PQgetvalue(res, 0,0) << " length
is: " << PQgetlength(res,0,0) << std::endl;
            REQUIRE(strcmp(PQgetvalue(res, 0,0), "1234") == 0);
        }
    }



Output is:


value is:  length is: 10
===============================================================================
../tests/dbPostgres.cpp:39:
TEST CASE:  Database related tests
  TEST first column first row value is stored in db

../tests/dbPostgres.cpp:242: FATAL ERROR: REQUIRE( strcmp(PQgetvalue(res,
0,0), "1234") == 0 ) is NOT correct!
  values: REQUIRE( -49 == 0 )

===============================================================================
[doctest] test cases:      2 |      1 passed |      1 failed |      0
skipped
[doctest] assertions:     32 |     31 passed |      1 failed |
[doctest] Status: FAILURE!



view thread (5+ messages)  latest in thread

Message-ID: <16051-cf9069d07dd1df16@postgresql.org>
Permalink:  ../16051-cf9069d07dd1df16@postgresql.org/
Also on:    postgresql.org/message-id/16051-cf9069d07dd1df16@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, bartsmink@gmail.com
  Subject: Re: BUG #16051: PQgetvalue(res,0,0) is null, PQgetlength(res,0,0) is 10
  In-Reply-To: <16051-cf9069d07dd1df16@postgresql.org>
  References: <16051-cf9069d07dd1df16@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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