-
Notifications
You must be signed in to change notification settings - Fork 127
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
rewrite sql where empty array parameter. #698
Conversation
The above syntax has been tested in databases:
|
@@ -3083,7 +3083,8 @@ internal static IEnumerable<Field> GetQualifiedFields<TEntity>(IEnumerable<Field | |||
var items = values is IEnumerable<object> ? (IEnumerable<object>)values : values.WithType<object>(); | |||
if (items.Any() != true) | |||
{ | |||
return commandText; | |||
var parameter = parameterName.AsParameter(dbSetting); | |||
return commandText.Replace(parameter, string.Concat("(select ", parameter, " where 1 = 0)")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small comment, let us make all the SQL statement UPPERCASE like SELECT * FROM Table WHERE 1 = 0;
.
Thank you for this PR, you are really maturing and expanding the capability of this ORM. 🛩️ This PR is great and we need to update the documentation here, feel free to put it there, otherwise, I can also put it there soon. Please continue to do this and I am happy to really shout you out in Twitter and to any other social media if you have an account there! |
A small question from me 😄, why did not you just make a little hack here? -- @normal = new[] { 1, 2 }
-- @empty = @emptyA = @emptyB = new int[0]
where id in (@normal) --> where id in (@normal0, @normal1)
where id in (@empty) --> where 1 = 0 // Only if all the passed parameters are null or empty
where id in (@empty, @normal) --> where id in (@normal0, @normal1) // ignoring the empty
where id in (@emptyA, @emptyB) --> where 1 = 0 // Only if all the passed parameters are null or empty Just a small thoughts. But TBH, the code change you made is very minimal, so it will merge it in a while. |
I have pushed a commit to change uppercase. |
Because such a processing method will be very simple, just replace |
That makes sense and based on your changes, it is very minimal. Thanks for your contributions as always. |
Code
Exception
Command watch
command.CommandText = "SELECT * FROM [sc].[IdentityTable] WHERE ColumnInt IN (@ColumnInt);"
command.Parameters (count = 0)
Revise
When the parameter is an empty set, replace @arg with (select @arg where 1 = 0).
And set a DbNull parameter in command.Parameters.
Example