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 render SQL queries containing binary strings #91

Open
ostrolucky opened this issue Jul 21, 2023 · 4 comments
Open

Cannot render SQL queries containing binary strings #91

ostrolucky opened this issue Jul 21, 2023 · 4 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@ostrolucky
Copy link
Member

At the moment, even though valid, these kind of queries would crash doctrine-bundle + twig

$connection->executeQuery("SELECT {$connection->quote((new \Symfony\Component\Uid\Ulid())->toBinary())}");

We are running all of these queries through this formatter, so I think formatter should do something about these, eg. detect non-utf8 parts and replace them with something.

Original issue was doctrine/DoctrineBundle#1315, I'm moving it here

@gargoyle
Copy link

I hit this error because we have binary values in our db queries.

The exception was thrown in Resources/views/Collector/db.html.twig where the formatted query or runnable query contents are added to the "Copy" buttons data-clipboard-text attribute which has to be escaped. Eg...

<button class="btn btn-sm hidden" data-clipboard-text="{{ query.sql|doctrine_format_sql(highlight = false)|e('html_attr') }}">Copy</button>

By adding a convert_encoding('UTF-8//TRANSLIT//IGNORE', 'UTF-8') filter before the escape attempt, it fixed the issue and the contents of the clipboard were as expected.

Our project is using version 2.7.2 of the bundle, and the offending lines in db.html.twig were 219 and 226.

Sorry, I don't have time to test this in more depth and do a PR. But I hope this helps.

@Nexotap
Copy link

Nexotap commented Feb 6, 2024

Just wanted to mention.
I'm having the same problem while using Uuids in entities. The solution from @gargoyle seems to work for me as well.

I'm using version 2.11.1 of the bundle. In db.html.twig I had to modify line 287 and 294.

I'm terrible at PR's so I better dont do it. Last time it took me a few days to do one correctly with lots of help. Anyway, hopefully my input helped a bit.

Looking forward to a fix for this.

@mvorisek
Copy link
Contributor

mvorisek commented Jun 4, 2024

This library handles binary strings perfectly.

However, no transformation of non-printable characters is done and can be done ATM, as this library is DB vendor-independent and no unified grammar to escape/encode string literal exists.

So the only solution is to introduce DB specific formatters.

@Nexotap
Copy link

Nexotap commented Jul 26, 2024

Completely overseen this thread.
You're right @mvorisek. I completely agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants