Skip to content

Use QueryLocation and GetParameterCount - #575

Merged
evertlammerts merged 1 commit into
duckdb:mainfrom
evertlammerts:fix_main
Jul 30, 2026
Merged

Use QueryLocation and GetParameterCount#575
evertlammerts merged 1 commit into
duckdb:mainfrom
evertlammerts:fix_main

Conversation

@evertlammerts

Copy link
Copy Markdown
Member

Fixes latest build issues introduced by duckdb/duckdb#24159 and duckdb/duckdb#24273.

Note that duckdb core's debug build is broken again due to missing imports.

Supersedes #573

@smvv

smvv commented Jul 30, 2026

Copy link
Copy Markdown
Member

@evertlammerts i think we need a compile-time compatibility layer:

diff --git a/src/pystatement.cpp b/src/pystatement.cpp
index 71d85de..77adea5 100644
--- a/src/pystatement.cpp
+++ b/src/pystatement.cpp
@@ -4,6 +4,25 @@ namespace duckdb {
 
 enum class ExpectedResultType : uint8_t { QUERY_RESULT, NOTHING, CHANGED_ROWS, UNKNOWN };
 
+static idx_t StatementLocationOffset(idx_t location) {
+       return location;
+}
+
+template <class LOCATION>
+static auto StatementLocationOffset(const LOCATION &location) -> decltype(location.offset) {
+       return location.offset;
+}
+
+template <class STATEMENT>
+static auto StatementLength(const STATEMENT &statement, int) -> decltype(statement.stmt_length) {
+       return statement.stmt_length;
+}
+
+template <class STATEMENT>
+static auto StatementLength(const STATEMENT &statement, long) -> decltype(statement.stmt_location.length) {
+       return statement.stmt_location.length;
+}
+
 static void InitializeReadOnlyProperties(nb::class_<DuckDBPyStatement> &m) {
        m.def_prop_ro("type", &DuckDBPyStatement::Type, "Get the type of the statement.")
            .def_prop_ro("query", &DuckDBPyStatement::Query, "Get the query equivalent to this statement.")
@@ -28,8 +47,7 @@ unique_ptr<SQLStatement> DuckDBPyStatement::GetStatement() {
 }
 
 string DuckDBPyStatement::Query() const {
-       auto &loc = statement->stmt_location;
-       return statement->query.substr(loc.offset, loc.length);
+       return statement->query.substr(StatementLocationOffset(statement->stmt_location), StatementLength(*statement, 0));
 }
 
 nb::set DuckDBPyStatement::NamedParameters() const {

because loc.offset, loc.length is a non-class type:

      /home/runner/work/_temp/setup-uv-cache/sdists-v9/path/c76f0a5a5d63061e/yeuNApnSr0b1lb94L9muS/src/src/pystatement.cpp:
      In member function ‘std::string duckdb::DuckDBPyStatement::Query()
      const’:
      /home/runner/work/_temp/setup-uv-cache/sdists-v9/path/c76f0a5a5d63061e/yeuNApnSr0b1lb94L9muS/src/src/pystatement.cpp:32:44:
      error: request for member ‘offset’ in ‘loc’, which is of non-class type
      ‘long unsigned int’
         32 |         return statement->query.substr(loc.offset, loc.length);
            |                                            ^~~~~~
      /home/runner/work/_temp/setup-uv-cache/sdists-v9/path/c76f0a5a5d63061e/yeuNApnSr0b1lb94L9muS/src/src/pystatement.cpp:32:56:
      error: request for member ‘length’ in ‘loc’, which is of non-class typelong unsigned int32 |         return statement->query.substr(loc.offset, loc.length);
            |                                                        ^~~~~~

unless we bump the duckdb submodule also in this PR (which I was not able to do)?

I've added more context on discord in a DM.

@evertlammerts

Copy link
Copy Markdown
Member Author

The submodule bump refusal is a bug I introduced last week in an attempt to prevent PRs from secretly including a submodule change, which I realize now is in the wrong place. For now we can just bump the submodule manually int hese cases (which I just did). I'll fix this when I'm back.

@evertlammerts
evertlammerts merged commit 4941f87 into duckdb:main Jul 30, 2026
13 checks passed
@evertlammerts
evertlammerts deleted the fix_main branch July 30, 2026 10:42
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