-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Fix for 15256 - bad generated SQL for DefaultValue with line breaks. #20304
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
Also apply the fix to |
@AndriySvyryd My mistake - I shouldn't have been applying it to |
I wonder if that assumption actually says anything about us trying to indent the SQL. Users may be totally unaware of. Even if a valid SQL passed in, our indented new line can break it. |
b8cfcde
to
e02787e
Compare
e02787e
to
285027f
Compare
@smitpatel I think the remark about indentation was a red-herring. The problem really was we would generate something like this: CREATE TABLE [TestEntity] (
[Id] int NOT NULL IDENTITY,
[Name] nvarchar(max) NULL DEFAULT (Do not
do
this
) And that's invalid SQL - so users of that would definitely notice. Now we'll generate something like this: CREATE TABLE [TestEntity] (
[Id] int NOT NULL IDENTITY,
[Name] nvarchar(max) NULL DEFAULT CONCAT(N'Do not', CHAR (13), CHAR(10), N'do', CHAR (13), CHAR(10), N'this')
) which is valid. |
@lajones Ok, but what do |
@AndriySvyryd - they would produce bad SQL but that's the user's responsibility. The difference is that for There are an infinite number of ways that a user could pass invalid SQL to For instance, we cannot put single quotes around everything (like we do for strings passed to |
SELECT TOP(1) a.Column
From table as a
Where a.text = N'abc
def
ghi
end'; A valid SQL. If you indent it, gives you incorrect results. |
OK. Agreed. This PR fixes the problem for But I agree it does not address the issue for |
Also note - a user of SELECT TOP(1) a.Column
From table as a
Where a.text = CONCAT(N'abc', CHAR(13), CHAR(10), N' def', CHAR(13), CHAR(10), N' ghi', CHAR(13), CHAR(10), N'end'); which also makes clear their expectations of how newlines are stored in the database. But a user of |
@smitpatel This is only an issue with idempotent scripts, so I'm not really worried about the I only feel obligated to fix the cases where we generate bad SQL for a literal value that the user correctly provided. Because in these cases, there isn't a good workaround. |
@bricelam - I am not referring to |
At least file an issue to track this |
@bricelam @AndriySvyryd @smitpatel I'm happy to file the new issue to look into |
@AndriySvyryd I filed #20391 to track that issue. |
@smitpatel @AndriySvyryd @bricelam Given that we have an issue tracking SQL cases, is there anything left to do here? If not, can someone sign off? |
Many thanks to @lauxjpn and in particular his update to the MySql provider for inspiration on this. |
Fix for #15256 - bad SQL was generated for DefaultValue with line breaks.