zeroshade commented on code in PR #4424:
URL: https://github.com/apache/arrow-adbc/pull/4424#discussion_r3461049235
##########
c/driver/postgresql/connection.cc:
##########
@@ -489,6 +489,26 @@ AdbcStatusCode PostgresConnection::Commit(struct
AdbcError* error) {
return ADBC_STATUS_OK;
}
+AdbcStatusCode PostgresConnection::EnsureTransaction(struct AdbcError* error) {
+ if (autocommit_) {
+ return ADBC_STATUS_OK;
+ }
+ auto txstatus = PQtransactionStatus(conn_);
+ if (txstatus == PQTRANS_ACTIVE || txstatus == PQTRANS_INTRANS) {
+ return ADBC_STATUS_OK;
+ }
+
+ PGresult* result = PQexec(conn_, "BEGIN TRANSACTION");
+ if (PQresultStatus(result) != PGRES_COMMAND_OK) {
+ InternalAdbcSetError(error, "%s%s",
+ "[libpq] Failed to begin transaction: ",
PQerrorMessage(conn_));
+ PQclear(result);
+ return ADBC_STATUS_IO;
+ }
+ PQclear(result);
+ return ADBC_STATUS_OK;
+}
Review Comment:
can we add a comment why we aren't handling the other states?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]