Skip to content

Add QueryBuilder::addComment() to attach SQL comments to generated queries - #7345

Open
jdecool wants to merge 1 commit into
doctrine:4.5.xfrom
jdecool:4.5.x-query-tag
Open

Add QueryBuilder::addComment() to attach SQL comments to generated queries#7345
jdecool wants to merge 1 commit into
doctrine:4.5.xfrom
jdecool:4.5.x-query-tag

Conversation

@jdecool

@jdecool jdecool commented Apr 7, 2026

Copy link
Copy Markdown
Q A
Type feature
Fixed issues

Summary

This implementation adds an addComment() method to the QueryBuilder class, which allows attaching SQL comments to generated queries for debugging, logging, and analysis purposes.

Comments are emitted as standard SQL comments preceding the statement, so they show up in slow query logs and query analysis tools alongside the statement they belong to.

It's a similar concept to EF Core Query Tags

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

There hasn't been any activity on this pull request in the past 90 days, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.
If you want to continue working on it, please leave a comment.

@github-actions github-actions Bot added the Stale label Aug 7, 2026
@jdecool

jdecool commented Aug 7, 2026

Copy link
Copy Markdown
Author

Keep it open.

What do you think about this feature @derrabus ?

@derrabus

derrabus commented Aug 7, 2026

Copy link
Copy Markdown
Member

There's already #7083, although the author is not responding anymore.

My problem with your version is the wording: SQL has no concept named "tags". There are comments and I'm fine adding an abstraction for comments to the query builder.

@jdecool

jdecool commented Aug 8, 2026

Copy link
Copy Markdown
Author

Thanks for your answer.

I will update this PR if #7083 be closed for inactivity.

@jdecool jdecool changed the title Add tagWith() method to QueryBuilder for SQL comment tags Add addComment() method to QueryBuilder for SQL comment tags Aug 11, 2026
@jdecool

jdecool commented Aug 15, 2026

Copy link
Copy Markdown
Author

@derrabus #7083 has just been closed.

Can this PR be reconsidered ?

@derrabus derrabus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What happens if I pass a string with a line feed to the builder?

Also, please add funktional tests that show me that a query constructed this way ist still understood by the database.

Comment thread tests/Query/QueryBuilderTest.php Outdated
@jdecool
jdecool force-pushed the 4.5.x-query-tag branch 2 times, most recently from 00c9c1a to 19f2bfb Compare August 15, 2026 08:04
@jdecool

jdecool commented Aug 15, 2026

Copy link
Copy Markdown
Author

I've updated the PR.

It should fixed the CI.

I've also updated the code to allow multiline comment

@greg0ire

Copy link
Copy Markdown
Member

My problem with your version is the wording: SQL has no concept named "tags". There are comments and I'm fine adding an abstraction for comments to the query builder.

The MR title and description wording should probably be changed as well.

greg0ire
greg0ire previously approved these changes Aug 15, 2026
@jdecool jdecool changed the title Add addComment() method to QueryBuilder for SQL comment tags Add QueryBuilder::addComment() to attach SQL comments to generated queries Aug 15, 2026
This implementation adds a addComment() method to the QueryBuilder class,
which allows adding SQL comment tags to generated queries for debugging,
logging, and analysis purposes.
@jdecool

jdecool commented Sep 5, 2026

Copy link
Copy Markdown
Author

@derrabus this PR has just been updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants