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!