Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot execute multi-statement queries #46

Closed
begelundmuller opened this issue Oct 12, 2022 · 5 comments · Fixed by #47
Closed

Cannot execute multi-statement queries #46

begelundmuller opened this issue Oct 12, 2022 · 5 comments · Fixed by #47

Comments

@begelundmuller
Copy link
Contributor

begelundmuller commented Oct 12, 2022

This didn't take long, but I encountered a bug with the refactored bindings. Seems like prepared statements can't be used for multi-statement queries.

Executing a query that contains multiple statements, such as:

_, err = db.Exec("INSTALL 'json'; LOAD 'json';")
if err != nil {
	fmt.Printf("error: %v", err.Error())
}

Outputs the following error:

error: Invalid Error: Cannot prepare multiple statements at once!

I don't know how other DB drivers deal with this, but one idea is to only use prepared statements for queries that have args? (Not sure if that has its own caveats.)

begelundmuller added a commit to begelundmuller/go-duckdb that referenced this issue Oct 12, 2022
@marcboeker
Copy link
Owner

Thanks for reporting this. I've tested multiple statements with other DuckDB drivers (Rust, Python).
The Python driver uses a very clever way of splitting a string of multiple statements into single statements and executing them one by one. They make use of the ExtractStatements method in the C++ API.
Maybe we can leverage this?

Until we have a fix, I would suggest to merge your quick fix. Could you please open a PR?

@begelundmuller
Copy link
Contributor Author

Yeah, I noticed the ExtractStatements method in the Python driver as well, unfortunately I was not able to find it in the C API. If you can't find it, do you think it makes sense to request DuckDB to add it?

I submitted a PR for my fix, but please beware that I put it together very quickly, so please double-check it before merging.

@marcboeker
Copy link
Owner

Thanks, I've tested and merged the PR.
I think we should request the ExtractStatements method for the C API, as this would be a cleaner solution. I'll ask them tomorrow.

@marcboeker
Copy link
Owner

I've reopened this and requested an ExtractStatements function for the C API. See duckdb/duckdb#4977

@marcboeker
Copy link
Owner

I think we can close this.

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 a pull request may close this issue.

2 participants