Skip to content

Commit

Permalink
优化代码:xml节点大小写不敏感
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzhiyuan committed May 15, 2024
1 parent 1a9d338 commit 847458d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/NuClear.Dapper.UnitTest/OrderSqlResource.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using NuClear.Dapper.SqlResources;
using NuClear.Dapper.SqlResources;
using System;

namespace NuClear.Dapper.UnitTest
{
Expand Down
2 changes: 1 addition & 1 deletion src/NuClear.Dapper.UnitTest/OrderSqlResource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
SELECT * FROM dbo.NoteItems ni WITH(NOLOCK) INNER JOIN dbo.OrderOutStockNote o WITH(NOLOCK) ON ni.OrderOutStockNote_Id = o.Id AND o.City_Id=@CityId AND o.AuditState=9 AND o.IsDeleted =0 AND o.UserStatus = 0 AND (YEAR(o.BusinessTime)=@Year AND MONTH(o.BusinessTime)=@Month)<if test="SaleMode != null"><if test="SaleMode == 99"> AND ni.SaleMode IN (1,3,9)</if><if test="SaleMode != 99"> @SaleMode=ni.SaleMode</if></if><if test="SettlementType != null"> AND @SettlementType = ni.SettlementType</if><if test="FinancialBusinessType != null"> AND @FinancialBusinessType=o.FinancialBusinessType</if><if test="StoreHouseId != null and StoreHouseId != '' "> AND @StoreHouseId=o.StoreHouse_Id</if><if test="StoreHouseIds != null and StoreHouseIds.Length > 0 "> AND o.StoreHouse_Id in @StoreHouseIds</if> OPTION(RECOMPILE)
</QueryPagedSaleProfitByMonth>
<SelectByChoose>
select * from Orders o with(nolock) where 1 = 1<choose><when test="Id != null and id != ''"> and Id = @Id</when><when test="NoteNo != null and NoteNo != ''"> and NoteNo = @NoteNo</when><otherwise> and BusinessTime >= '2022-8-1'</otherwise></choose>
select * from Orders o with(nolock) where 1 = 1<Choose><when test="Id != null and id != ''"> and Id = @Id</when><when test="NoteNo != null and NoteNo != ''"> and NoteNo = @NoteNo</when><otherwise> and BusinessTime >= '2022-8-1'</otherwise></Choose>
</SelectByChoose>
<SelectByChooseAndIf>
select * from Orders o with(nolock) where 1 = 1<choose><when test="Id != null and id != ''"> and Id = @Id</when><when test="NoteNo != null and NoteNo != ''"> and noteno=@NoteNo<if test="SelectHiden != 1"> and UserStatus = 1</if></when><otherwise> and BusinessTime >= '2022-8-1'</otherwise></choose>
Expand Down
10 changes: 7 additions & 3 deletions src/NuClear.Dapper/SqlResources/Scripting/XElementExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ static XElementExtensions()

internal static INodeHandler GetNodeHandler(string nodeName)
{
return _nodeHandlerMap[nodeName];
if (_nodeHandlerMap.TryGetValue(nodeName, out var handler))
{
return handler;
}
throw new SqlParseException($"不识别的ElementName:{nodeName}");
}

private static void InitNodeHandlerMap()
Expand All @@ -37,13 +41,13 @@ public static MixedSqlNode ParseDynamicTags(this XElement node)
XNode child = children[i];
if (child.NodeType == System.Xml.XmlNodeType.Text || child.NodeType == System.Xml.XmlNodeType.CDATA)
{
TextSqlNode textSqlNode = new TextSqlNode(((System.Xml.Linq.XText)child).Value);
TextSqlNode textSqlNode = new TextSqlNode(((XText)child).Value);
contents.Add(textSqlNode);
}
else if (child.NodeType == System.Xml.XmlNodeType.Element)
{
var elementNode = XElement.Parse(child.ToString());
var nodeName = elementNode.Name.ToString();
var nodeName = elementNode.Name.ToString().ToLower();
INodeHandler handler = GetNodeHandler(nodeName) ?? throw new SqlParseException($"不识别的ElementName:{nodeName}!");
handler.HandleNode(elementNode, contents);
}
Expand Down

0 comments on commit 847458d

Please sign in to comment.