Thread: C++ code - PGRES_TUPLES_OK is not returned when DELETE performed

C++ code - PGRES_TUPLES_OK is not returned when DELETE performed

From
Yan Cheng CHEOK
Date:
I realize for the following code :

PGconn *connection = this->connection.getConnection();
PGresult *res = PQexec(connection, "DELETE FROM measurement_statistic WHERE fk_lot_id = 47");

// status always false??
const bool status = (PQresultStatus(res) == PGRES_TUPLES_OK);

status will always remain false, although the actual row in database had been delete.

I execute the above statement (DELETE FROM measurement_statistic WHERE fk_lot_id = 47) through pgadmin. It works fine.

May I know why PGRES_TUPLES_OK is not being returned when I use DELETE? When I try to execute SELECT statement,
PGRES_TUPLES_OKcan be returned. 

Thanks and Regards
Yan Cheng CHEOK




Re: C++ code - PGRES_TUPLES_OK is not returned when DELETE performed

From
Dmitriy Igrishin
Date:
Hey Yan Cheng,

The status of command is PGRES_COMMAND_OK only when performed
command was not returns data, e.g. DELETE (without RETURNING clause),
BEGIN, COMMIT etc.
The status PGRES_TUPLES_OK only when performed command was
SELECT, SHOW or UPDATE / DELETE with RETURNING clause and etc.

2010/12/15 Yan Cheng CHEOK <yccheok@yahoo.com>
I realize for the following code :

PGconn *connection = this->connection.getConnection();
PGresult *res = PQexec(connection, "DELETE FROM measurement_statistic WHERE fk_lot_id = 47");

// status always false??
const bool status = (PQresultStatus(res) == PGRES_TUPLES_OK);

status will always remain false, although the actual row in database had been delete.

I execute the above statement (DELETE FROM measurement_statistic WHERE fk_lot_id = 47) through pgadmin. It works fine.

May I know why PGRES_TUPLES_OK is not being returned when I use DELETE? When I try to execute SELECT statement, PGRES_TUPLES_OK can be returned.

Thanks and Regards
Yan Cheng CHEOK




--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



--
// Dmitriy.