PostgreSQL Bugs

Collected from the PG bugs email list.

Bug ID16051
PG Version12.0
OSMacos 10.15
Opened2019-10-11 22:42:06+00
Reported byLibpq does not fetch first result in table
StatusNew

Body of first available message related to this bug follows.

The following bug has been logged on the website:

Bug reference:      16051
Logged by:          Libpq does not fetch first result in table
Email address:      (redacted)
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!

Messages

DateAuthorSubject
2019-10-11 22:42:06+00PG Bug reporting formBUG #16051: PQgetvalue(res,0,0) is null, PQgetlength(res,0,0) is 10
2019-10-12 03:30:49+00Tom LaneRe: BUG #16051: PQgetvalue(res,0,0) is null, PQgetlength(res,0,0) is 10
2019-10-12 08:42:52+00Bart SminkRe: BUG #16051: PQgetvalue(res,0,0) is null, PQgetlength(res,0,0) is 10
2019-10-12 14:17:12+00Andrew GierthRe: BUG #16051: PQgetvalue(res,0,0) is null, PQgetlength(res,0,0) is 10
2019-10-12 14:17:37+00Tom LaneRe: BUG #16051: PQgetvalue(res,0,0) is null, PQgetlength(res,0,0) is 10