Skip to content

Conversation

staticlibs
Copy link
Contributor

This change fixes the copy constructor of the SetVariableStatement by adding there a call to the superclass copy constructor. Previously this constructor was using non-copy constructor of the superclass and thus was failing to copy named_param_map field (and some other fields).

When the postgres_scanner extension is loaded the result of the Prepare() call for queries like SET VARIABLE v = ? was gettng an empty named_param_map field and the execution of this statement was failing with:

Binder Error: Parameter/argument count mismatch for prepared statement. Expected 0, got 1

Testing: new test is added that uses CanRequestRebind() API to check the code path on which SQLStatement's copy constructor is invoked.

Fixes: duckdb/duckdb-java#294

This change fixes the copy constructor of the `SetVariableStatement` by
adding there a call to the superclass copy constructor. Previously this
constructor was using non-copy constructor of the superclass and thus
was failing to copy `named_param_map` field (and some other fields).

When the `postgres_scanner` extension is loaded the result of the
`Prepare()` call for queries like `SET VARIABLE v = ?` was gettng an
empty `named_param_map` field and the execution of this statement was
failing with:

> Binder Error: Parameter/argument count mismatch for prepared statement. Expected 0, got 1

Testing: new test is added that uses `CanRequestRebind()` API to check
the code path on which `SQLStatement`'s copy constructor is invoked.

Fixes: duckdb/duckdb-java#294
@staticlibs staticlibs force-pushed the set_variable_stmt_fix branch from ecaee4a to 42eb1f2 Compare June 30, 2025 22:26
@duckdb-draftbot duckdb-draftbot marked this pull request as draft June 30, 2025 22:26
@staticlibs staticlibs marked this pull request as ready for review June 30, 2025 22:27
@Mytherin Mytherin merged commit 8a648b4 into duckdb:v1.3-ossivalis Jul 1, 2025
51 checks passed
@Mytherin
Copy link
Collaborator

Mytherin commented Jul 1, 2025

Thanks!

github-actions bot pushed a commit to duckdb/duckdb-r that referenced this pull request Jul 1, 2025
Fix copy constructor in SetVariableStatement (duckdb/duckdb#18101)
OSX.yml: Move from using debug builds to release + DDEBUG + FORCE_ASSERT (duckdb/duckdb#18102)
github-actions bot added a commit to duckdb/duckdb-r that referenced this pull request Jul 1, 2025
Fix copy constructor in SetVariableStatement (duckdb/duckdb#18101)
OSX.yml: Move from using debug builds to release + DDEBUG + FORCE_ASSERT (duckdb/duckdb#18102)

Co-authored-by: krlmlr <krlmlr@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants