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

Debug Query as SQL string. #155

Merged
merged 3 commits into from
Sep 24, 2024
Merged

Debug Query as SQL string. #155

merged 3 commits into from
Sep 24, 2024

Conversation

pravic
Copy link
Contributor

@pravic pravic commented Sep 18, 2024

Summary

Allow to print the current SQL query, whether it's bound or not. Useful for logging and diagnostics.

Note: I chose Debug over Display because the latter is too implicit and somebody might accidentally pass a query into a string.

Albeit, something like fn Query::into_string(self) -> String can be useful on its own - as a poor man's query builder:

let q = client.query("SELECT id from system.users WHERE name = ?");
let q = q.bind("default");

// store the query string for later 
let query_string = q.into_string(); // returns `q.sql.finish()` inernally

// then execute it:
client.query(&query_string).fetch();

closes #146

Checklist

Delete items not relevant to your PR:

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided so that we can include it in CHANGELOG later
  • For significant changes, documentation in README and https://github.com/ClickHouse/clickhouse-docs was updated with further explanations or tutorials
  • conflicts with Query parser: encode ?? as ? #154, this PR needs to be rebased on top of that

Allow to print the current SQL query,
whether it's bound or not.

Useful for logging and diagnostics.
Allow to print the current SQL query,
whether it's bound or not.

Useful for logging and diagnostics.
serprex
serprex previously approved these changes Sep 19, 2024
src/query.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@loyd loyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only misleading Debug impl, all other changes are fine

@CLAassistant
Copy link

CLAassistant commented Sep 20, 2024

CLA assistant check
All committers have signed the CLA.

`Debug` for `Query` isn't a good idea.
@loyd loyd merged commit 75ce343 into ClickHouse:main Sep 24, 2024
6 checks passed
@loyd
Copy link
Collaborator

loyd commented Sep 24, 2024

@pravic, thanks for your contribution!

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.

Implement std::fmt::Display for Query
4 participants