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

Incorrect NOLOCK position in queries where there is no table alias #8783

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Orchard/Data/NoLockInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,13 @@ private string AddNoLockHints(string query, IEnumerable<string> tableNames) {
if (tableIndex == fromIndex + 1
|| parts[tableIndex - 1].Equals(",")) {

parts.Insert(tableIndex + 2, "WITH(NOLOCK)");
if (parts[tableIndex+1].Equals("where", StringComparison.OrdinalIgnoreCase)) {
BenedekFarkas marked this conversation as resolved.
Show resolved Hide resolved
// There is no alias in the query, so we add "WITH(NOLOCK)" immediately after table name but before the "where" clause.
parts.Insert(tableIndex + 1, "WITH(NOLOCK)");
} else {
// We add "WITH(NOLOCK)" after the table alias
BenedekFarkas marked this conversation as resolved.
Show resolved Hide resolved
parts.Insert(tableIndex + 2, "WITH(NOLOCK)");
}
} else {
// probably doing a join, so edit the next "on" and make it
// "WITH (NOLOCK) on"
Expand Down