mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-09 18:00:56 +08:00
- 修复 Lambda .Contains 通配符解析为非 Like 问题;
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.Duckdb
|
||||
@@ -20,9 +22,21 @@ namespace FreeSql.Tests.Duckdb
|
||||
Assert.True(fsql.Ado.ExecuteConnectTest());
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteReader()
|
||||
public void ExecuteDataTable()
|
||||
{
|
||||
var dataTable = fsql.Ado.ExecuteDataTable("select * from tbiou04");
|
||||
|
||||
using (var duck = new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.DuckDB, "DataSource=D:\\WeChat Files\\WeChat Files\\q2881099\\FileStorage\\File\\2025-05")
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseMonitorCommand(
|
||||
cmd => Trace.WriteLine("\r\n线程" + Thread.CurrentThread.ManagedThreadId + ": " + cmd.CommandText) //监听SQL命令对象,在执行前
|
||||
, (cmd, traceLog) => Console.WriteLine(traceLog)
|
||||
)
|
||||
.Build())
|
||||
{
|
||||
var dataTable2 = fsql.Ado.ExecuteDataTable("select * from db_db");
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void ExecuteArray()
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
@@ -285,7 +285,7 @@ namespace FreeSql.Custom.MySql
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"locate({args0Value}, {left}) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"locate({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1";
|
||||
|
||||
@@ -288,7 +288,7 @@ namespace FreeSql.Custom.Oracle
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1";
|
||||
|
||||
@@ -377,7 +377,7 @@ namespace FreeSql.Custom.PostgreSQL
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1";
|
||||
|
||||
@@ -308,7 +308,7 @@ namespace FreeSql.Custom.SqlServer
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"charindex({args0Value}, {left}) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"charindex({args0Value}, {left}) = len({left})-len({args0Value})+1";
|
||||
|
||||
@@ -288,7 +288,7 @@ namespace FreeSql.Dameng
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1";
|
||||
|
||||
@@ -354,7 +354,7 @@ namespace FreeSql.Duckdb
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (exp.Method.Name == "StartsWith") return $"{left} ^@ ({args0Value})";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = length({left})-length({args0Value})+1";
|
||||
return $"strpos({left}, {args0Value}) > 0";
|
||||
|
||||
@@ -275,7 +275,7 @@ namespace FreeSql.Firebird
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"position({args0Value}, {left}) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"position({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1";
|
||||
|
||||
@@ -275,7 +275,7 @@ namespace FreeSql.GBase
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1";
|
||||
|
||||
@@ -408,7 +408,7 @@ namespace FreeSql.KingbaseES
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1";
|
||||
|
||||
@@ -249,7 +249,7 @@ namespace FreeSql.MsAccess
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}) = len({left})-len({args0Value})+1";
|
||||
|
||||
@@ -287,7 +287,7 @@ namespace FreeSql.MySql
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"locate({args0Value}, {left}) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"locate({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1";
|
||||
|
||||
@@ -285,7 +285,7 @@ namespace FreeSql.Odbc.MySql
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"locate({args0Value}, {left}) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"locate({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1";
|
||||
|
||||
@@ -288,7 +288,7 @@ namespace FreeSql.Odbc.Oracle
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1";
|
||||
|
||||
@@ -377,7 +377,7 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1";
|
||||
|
||||
@@ -308,7 +308,7 @@ namespace FreeSql.Odbc.SqlServer
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"charindex({args0Value}, {left}) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"charindex({args0Value}, {left}) = len({left})-len({args0Value})+1";
|
||||
|
||||
@@ -288,7 +288,7 @@ namespace FreeSql.Oracle
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1";
|
||||
|
||||
@@ -408,7 +408,7 @@ namespace FreeSql.PostgreSQL
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1";
|
||||
|
||||
@@ -311,7 +311,7 @@ namespace FreeSql.QuestDb
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = length({left})-length({args0Value})+1";
|
||||
|
||||
@@ -332,7 +332,7 @@ namespace FreeSql.ShenTong
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1";
|
||||
|
||||
@@ -307,7 +307,7 @@ namespace FreeSql.SqlServer
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"charindex({args0Value}, {left}) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"charindex({args0Value}, {left}) = len({left})-len({args0Value})+1";
|
||||
|
||||
@@ -284,7 +284,7 @@ namespace FreeSql.Sqlite
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}) = length({left})-length({args0Value})+1";
|
||||
|
||||
@@ -354,7 +354,7 @@ namespace FreeSql.TDengine
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (exp.Method.Name == "StartsWith") return $"{left} ^@ ({args0Value})";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = length({left})-length({args0Value})+1";
|
||||
return $"strpos({left}, {args0Value}) > 0";
|
||||
|
||||
@@ -333,7 +333,7 @@ namespace FreeSql.Xugu
|
||||
var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})";
|
||||
var args0Value = getExp(exp.Arguments[0]);
|
||||
if (args0Value == "NULL") return $"{leftLike} IS NULL";
|
||||
if (args0Value.Contains("%"))
|
||||
if (new[] { '%', '_', '[', ']', '*' }.Any(wildcard => args0Value.Contains(wildcard)))
|
||||
{
|
||||
if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1";
|
||||
if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1";
|
||||
|
||||
Reference in New Issue
Block a user