Skip to content

Commit b91fe2c

Browse files
2881028810
authored andcommitted
- 修复 Firebird Embedded 版本系统表 isidentity_type 兼容问题;
1 parent 0783b43 commit b91fe2c

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

Providers/FreeSql.Provider.Firebird/FirebirdAdo/FirebirdAdo.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,29 @@ public FirebirdAdo(CommonUtils util, string masterConnectionString, string[] sla
3535
}
3636
}
3737
}
38+
39+
public bool IsFirebird2_5 => ServerVersion.Contains("Firebird 2.5");
40+
public string ServerVersion
41+
{
42+
get
43+
{
44+
if (string.IsNullOrEmpty(_serverVersion) && MasterPool != null)
45+
using (var conn = MasterPool.Get())
46+
{
47+
try
48+
{
49+
_serverVersion = conn.Value.ServerVersion;
50+
}
51+
catch
52+
{
53+
_serverVersion = "3.0.0";
54+
}
55+
}
56+
return _serverVersion;
57+
}
58+
}
59+
string _serverVersion;
60+
3861
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
3962
{
4063
if (param == null) return "NULL";

Providers/FreeSql.Provider.Firebird/FirebirdCodeFirst.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ protected override string GetComparisonDDLStatements(params TypeAndName[] object
160160
tboldname = null; //如果新表已经存在,不走改表名逻辑
161161

162162
//对比字段,只可以修改类型、增加字段、有限的修改字段名;保证安全不删除字段
163-
var sql = _commonUtils.FormatSql(@"
163+
var sql = _commonUtils.FormatSql($@"
164164
select
165165
trim(a.rdb$field_name),
166166
case
@@ -176,12 +176,12 @@ protected override string GetComparisonDDLStatements(params TypeAndName[] object
176176
coalesce((select ' SUB_TYPE ' || rdb$type from rdb$types where b.rdb$field_type = 261 and rdb$type = b.rdb$field_sub_type and rdb$field_name = 'RDB$FIELD_SUB_TYPE' rows 1),'')
177177
end || trim(case when b.rdb$dimensions = 1 then '[]' else '' end),
178178
case when a.rdb$null_flag = 1 then 0 else 1 end,
179-
case when a.rdb$identity_type = 1 then 1 else 0 end,
179+
{((_orm.Ado as FirebirdAdo)?.IsFirebird2_5 == true ? "0" : "case when a.rdb$identity_type = 1 then 1 else 0 end")},
180180
a.rdb$description
181181
from rdb$relation_fields a
182182
inner join rdb$fields b on b.rdb$field_name = a.rdb$field_source
183183
inner join rdb$relations d on d.rdb$relation_name = a.rdb$relation_name
184-
where a.rdb$system_flag = 0 and trim(d.rdb$relation_name) = {0}
184+
where a.rdb$system_flag = 0 and trim(d.rdb$relation_name) = {{0}}
185185
order by a.rdb$relation_name, a.rdb$field_position", tboldname ?? tbname);
186186
var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
187187
var tbstruct = ds.ToDictionary(a => string.Concat(a[0]), a =>

Providers/FreeSql.Provider.Firebird/FirebirdDbFirst.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ from rdb$relations
196196
}
197197
loc8.Append(")");
198198

199-
sql = string.Format(@"
199+
sql = $@"
200200
select
201201
trim(d.rdb$relation_name),
202202
trim(a.rdb$field_name),
@@ -226,15 +226,15 @@ from rdb$relations
226226
coalesce((select ' SUB_TYPE ' || rdb$type from rdb$types where b.rdb$field_type = 261 and rdb$type = b.rdb$field_sub_type and rdb$field_name = 'RDB$FIELD_SUB_TYPE' rows 1),'')
227227
end || trim(case when b.rdb$dimensions = 1 then '[]' else '' end),
228228
case when a.rdb$null_flag = 1 then 0 else 1 end,
229-
case when a.rdb$identity_type = 1 then 1 else 0 end,
229+
{((_orm.Ado as FirebirdAdo)?.IsFirebird2_5 == true ? "0" : "case when a.rdb$identity_type = 1 then 1 else 0 end")},
230230
a.rdb$description,
231231
a.rdb$default_value
232232
from rdb$relation_fields a
233233
inner join rdb$fields b on b.rdb$field_name = a.rdb$field_source
234234
inner join rdb$relations d on d.rdb$relation_name = a.rdb$relation_name
235-
where a.rdb$system_flag = 0 and {0}
235+
where a.rdb$system_flag = 0 and {loc8}
236236
order by a.rdb$relation_name, a.rdb$field_position
237-
", loc8);
237+
";
238238
ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
239239
if (ds == null) return loc1;
240240

0 commit comments

Comments
 (0)