Skip to content

Commit

Permalink
fix python tests back (they always call prepare)
Browse files Browse the repository at this point in the history
  • Loading branch information
paleolimbot committed Jul 24, 2024
1 parent 23a1d0f commit a375c63
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
14 changes: 8 additions & 6 deletions c/driver/postgresql/statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1167,12 +1167,14 @@ AdbcStatusCode PostgresStatement::ExecuteQuery(struct ArrowArrayStream* stream,
return ExecuteBind(stream, rows_affected, error);
}

// If we have been requested to prepare the query but there are no parameters to bind,
// use the PqResultArrayReader to handle the execution of the query. We don't currently
// issue an explicit PGprepare(); however, this is the path we would need to take when
// we do implement this (because preparing a query that includes COPY is not supported).
// Also take this path if no output is requested (e.g., a CREATE or UPDATE).
if (!stream || prepared_) {
// Check if we have been explicitly requested to avoid COPY
// (make less of a hack before merging)
size_t use_copy = 0;
GetOption(ADBC_POSTGRESQL_OPTION_USE_COPY, nullptr, &use_copy, nullptr);

// If we have been requested to avoid COPY or there is no output requested,
// execute using the PqResultArrayReader.
if (!stream || !use_copy) {
PqResultArrayReader reader(connection_->conn(), type_resolver_, query_);
RAISE_ADBC(reader.ToArrayStream(rows_affected, stream, error));
return ADBC_STATUS_OK;
Expand Down
3 changes: 3 additions & 0 deletions c/driver/postgresql/statement.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#define ADBC_POSTGRESQL_OPTION_BATCH_SIZE_HINT_BYTES \
"adbc.postgresql.batch_size_hint_bytes"

#define ADBC_POSTGRESQL_OPTION_USE_COPY \
"adbc.postgresql.batch_size_hint_bytes"

namespace adbcpq {
class PostgresConnection;
class PostgresStatement;
Expand Down
2 changes: 1 addition & 1 deletion python/adbc_driver_postgresql/tests/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_query_execute_schema(postgres: dbapi.Connection) -> None:
def test_query_invalid(postgres: dbapi.Connection) -> None:
with postgres.cursor() as cur:
with pytest.raises(
postgres.ProgrammingError, match="Failed to execute query"
postgres.ProgrammingError, match="Failed to prepare query"
) as excinfo:
cur.execute("SELECT * FROM tabledoesnotexist")

Expand Down
4 changes: 2 additions & 2 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a375c63

Please sign in to comment.