Skip to content

Commit 9bd6e83

Browse files
committed
- 优化 GBase 数据库存储过程参数化的执行;#965
1 parent 6826dec commit 9bd6e83

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Providers/FreeSql.Provider.GBase/FreeSql.Provider.GBase.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<Version>2.8.100-preview1013</Version>
5+
<Version>2.6.100</Version>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<Authors>FreeSql;GBase</Authors>
88
<Description>FreeSql 数据库实现,基于 南大通用 8.0</Description>

Providers/FreeSql.Provider.GBase/GBaseProvider.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using FreeSql.GBase.Curd;
22
using FreeSql.Internal.CommonProvider;
33
using System;
4+
using System.Data;
45
using System.Data.Common;
56
using System.IO;
7+
using System.Linq;
68
using System.Text;
79
using System.Threading;
810

@@ -28,6 +30,26 @@ public GBaseProvider(string masterConnectionString, string[] slaveConnectionStri
2830
this.DbFirst = new GBaseDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
2931
this.CodeFirst = new GBaseCodeFirst(this, this.InternalCommonUtils, this.InternalCommonExpression);
3032

33+
this.Aop.CommandBefore += (_, e) =>
34+
{
35+
if (e.Command.CommandType == CommandType.StoredProcedure)
36+
{
37+
if (e.Command.CommandText.Trim().StartsWith("{call ", StringComparison.OrdinalIgnoreCase) == false)
38+
{
39+
var args = string.Join(", ", Enumerable.Range(0, e.Command.Parameters.Count)
40+
.Select(a => "?"));
41+
var cmdText = $"{{call {e.Command.CommandText}({args})}}";
42+
43+
foreach (DbParameter parameter in e.Command.Parameters)
44+
{
45+
if (parameter.DbType == DbType.String && parameter.Size <= 0)
46+
parameter.Size = 255;
47+
}
48+
e.Command.CommandText = cmdText;
49+
}
50+
}
51+
};
52+
3153
this.Aop.AuditDataReader += (_, e) =>
3254
{
3355
var dbtype = e.DataReader.GetDataTypeName(e.Index);

0 commit comments

Comments
 (0)