You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by li...@apache.org on 2023/12/20 14:58:23 UTC
(arrow-adbc) branch main updated: feat(c/driver/postgresql): set rows_affected appropriately (#1384)
This is an automated email from the ASF dual-hosted git repository.
lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git
The following commit(s) were added to refs/heads/main by this push:
new 95897540 feat(c/driver/postgresql): set rows_affected appropriately (#1384)
95897540 is described below
commit 95897540f7582699e99da26f99cde8f825ca828f
Author: David Li <li...@gmail.com>
AuthorDate: Wed Dec 20 09:58:17 2023 -0500
feat(c/driver/postgresql): set rows_affected appropriately (#1384)
Fixes #1226.
---
c/driver/postgresql/postgresql_test.cc | 6 ------
c/driver/postgresql/statement.cc | 13 ++++++++++++-
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/c/driver/postgresql/postgresql_test.cc b/c/driver/postgresql/postgresql_test.cc
index e1f95a49..5e04b455 100644
--- a/c/driver/postgresql/postgresql_test.cc
+++ b/c/driver/postgresql/postgresql_test.cc
@@ -824,12 +824,6 @@ class PostgresStatementTest : public ::testing::Test,
void TestSqlPrepareErrorParamCountMismatch() { GTEST_SKIP() << "Not yet implemented"; }
void TestSqlPrepareGetParameterSchema() { GTEST_SKIP() << "Not yet implemented"; }
void TestSqlPrepareSelectParams() { GTEST_SKIP() << "Not yet implemented"; }
- void TestSqlQueryRowsAffectedDelete() {
- GTEST_SKIP() << "Cannot query rows affected in delete (not implemented)";
- }
- void TestSqlQueryRowsAffectedDeleteStream() {
- GTEST_SKIP() << "Cannot query rows affected in delete stream (not implemented)";
- }
void TestConcurrentStatements() {
// TODO: refactor driver so that we read all the data as soon as
diff --git a/c/driver/postgresql/statement.cc b/c/driver/postgresql/statement.cc
index 6f1bb9bd..656e1876 100644
--- a/c/driver/postgresql/statement.cc
+++ b/c/driver/postgresql/statement.cc
@@ -1306,7 +1306,18 @@ AdbcStatusCode PostgresStatement::ExecuteUpdateQuery(int64_t* rows_affected,
PQclear(result);
return code;
}
- if (rows_affected) *rows_affected = PQntuples(reader_.result_);
+ if (rows_affected) {
+ if (status == PGRES_TUPLES_OK) {
+ *rows_affected = PQntuples(reader_.result_);
+ } else {
+ // In theory, PQcmdTuples would work here, but experimentally it gives
+ // an empty string even for a DELETE. (Also, why does it return a
+ // string...) Possibly, it doesn't work because we use PQexecPrepared
+ // but the docstring is careful to specify it works on an EXECUTE of a
+ // prepared statement.
+ *rows_affected = -1;
+ }
+ }
PQclear(result);
return ADBC_STATUS_OK;
}