-
Notifications
You must be signed in to change notification settings - Fork 90
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
Add string escape for values #9
base: master
Are you sure you want to change the base?
Add string escape for values #9
Conversation
If the value in the database is null it should also be null when inserting it again. Before an empty string was generated and this can lead to problems with indexes and constraints. A combined unique index like locale,uri where the uri is optional would throw an duplicate Error when you insert multiple values like this: 'de_ch','' 'de_ch','' The correct way to insert these: 'de_ch',null 'de_ch',null And will not throw any errors.
Hi and thank you for the PR. Are there other special characters apart from single and double quotes that should be escaped? Finally would you mind rebasing this pull request on master and removing the commit from #11 as I have already merged it. |
I found these information in the documentation from MySQL: https://dev.mysql.com/doc/refman/8.0/en/string-literals.html |
So, for example, do newlines work currently or will we need to escape them as well? |
For newlines the query runs fine. INSERT INTO test VALUES ('Newline Test MySQL should handle these cases correctly. But I don't know if tools and co. could choke on that. The safe approach here would be to escape the listed sequences in https://dev.mysql.com/doc/refman/8.0/en/string-literals.html The question is if you want to use your own function or somehow use the built in query generator. But as your quick look suggests this will be trickier or not possible at all. |
If this is possible (or becomes in the future) I would prefer to use the built in query generator. But for now lets just extend your |
Any updates on this PR? 🙇 |
Anything on this PR? |
This will escape the strings for single and double quotes.
Especially single quotes can lead to SQL errors and injections.