Skip to content

Commit

Permalink
Fixes SqlServeer sql case sensitive. #1389
Browse files Browse the repository at this point in the history
  • Loading branch information
yang-xiaodong committed Aug 16, 2023
1 parent 0d8e935 commit 18ba337
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/DotNetCore.CAP.SqlServer/IMonitoringApi.SqlServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,19 @@ public async Task<PagedQueryResult<MessageDto>> GetMessagesAsync(MessageQueryDto
{
var tableName = queryDto.MessageType == MessageType.Publish ? _pubName : _recName;
var where = string.Empty;
if (!string.IsNullOrEmpty(queryDto.StatusName)) where += " and statusname=@StatusName";
if (!string.IsNullOrEmpty(queryDto.StatusName)) where += " AND [StatusName]=@StatusName";

if (!string.IsNullOrEmpty(queryDto.Name)) where += " and name=@Name";
if (!string.IsNullOrEmpty(queryDto.Name)) where += " AND [Name]=@Name";

if (!string.IsNullOrEmpty(queryDto.Group)) where += " and [group]=@Group";
if (!string.IsNullOrEmpty(queryDto.Group)) where += " AND [Group]=@Group";

if (!string.IsNullOrEmpty(queryDto.Content)) where += " and content like @Content";
if (!string.IsNullOrEmpty(queryDto.Content)) where += " AND [Content] LIKE @Content";

var sqlQuery2008 =
$@"select * from
(SELECT t.*, ROW_NUMBER() OVER(order by t.Added desc) AS row_number
from {tableName} as t
where 1=1 {where}) as tbl
where tbl.row_number between @offset and @offset + @limit";
$@"SELECT * FROM (SELECT p.*, ROW_NUMBER() OVER(ORDER BY p.Added DESC) AS RowNum FROM {tableName} as p WHERE 1=1 {where}) as tbl WHERE tbl.RowNum BETWEEN @Offset AND @Offset + @Limit";

var sqlQuery =
$"select * from {tableName} where 1=1 {where} order by Added desc offset @Offset rows fetch next @Limit rows only";
$"SELECT * FROM {tableName} WHERE 1=1 {where} ORDER BY Added DESC OFFSET @Offset ROWS FETCH NEXT @Limit ROWS ONLY";

object[] sqlParams =
{
Expand All @@ -118,7 +114,7 @@ public async Task<PagedQueryResult<MessageDto>> GetMessagesAsync(MessageQueryDto
var connection = new SqlConnection(_options.ConnectionString);
await using var _ = connection.ConfigureAwait(false);

var count = await connection.ExecuteScalarAsync<int>($"select count(1) from {tableName} where 1=1 {where}",
var count = await connection.ExecuteScalarAsync<int>($"SELECT COUNT(1) FROM {tableName} WHERE 1=1 {where}",
new SqlParameter("@StatusName", queryDto.StatusName ?? string.Empty),
new SqlParameter("@Group", queryDto.Group ?? string.Empty),
new SqlParameter("@Name", queryDto.Name ?? string.Empty),
Expand Down

0 comments on commit 18ba337

Please sign in to comment.