Skip to content

Commit

Permalink
- 修复 GBase serial8/bigserial 自增回填的问题;#1919
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Nov 12, 2024
1 parent ce4a77f commit 233990d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Providers/FreeSql.Provider.GBase/Curd/GBaseInsert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ protected override long RawExecuteIdentity()
var sql = this.ToSql();
if (string.IsNullOrEmpty(sql)) return 0;

var identityType = _table.Primarys.Where(a => a.Attribute.IsIdentity).FirstOrDefault()?.CsType.NullableTypeOrThis();
var identityCol = _table.Primarys.Where(a => a.Attribute.IsIdentity).FirstOrDefault();
var identityType = identityCol?.Attribute.MapType.NullableTypeOrThis();
var identitySql = "";
if (identityType != null)
{
if (identityType == typeof(int) || identityType == typeof(uint)) identitySql = "SELECT dbinfo('sqlca.sqlerrd1') FROM dual";
else if (identityType == typeof(long) || identityType == typeof(ulong)) identitySql = "SELECT dbinfo('serial8') FROM dual";
else if (identityType == typeof(long) || identityType == typeof(ulong)) identitySql =
identityCol.Attribute.DbType.IndexOf("bigserial", StringComparison.OrdinalIgnoreCase) != -1 ?
"SELECT dbinfo('bigserial') FROM dual" : "SELECT dbinfo('serial8') FROM dual";
}
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, string.Concat(sql, $"; {identitySql};"), _params);
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
Expand Down Expand Up @@ -102,12 +105,15 @@ async protected override Task<long> RawExecuteIdentityAsync(CancellationToken ca
var sql = this.ToSql();
if (string.IsNullOrEmpty(sql)) return 0;

var identityType = _table.Primarys.Where(a => a.Attribute.IsIdentity).FirstOrDefault()?.CsType.NullableTypeOrThis();
var identityCol = _table.Primarys.Where(a => a.Attribute.IsIdentity).FirstOrDefault();
var identityType = identityCol?.Attribute.MapType.NullableTypeOrThis();
var identitySql = "";
if (identityType != null)
{
if (identityType == typeof(int) || identityType == typeof(uint)) identitySql = "SELECT dbinfo('sqlca.sqlerrd1') FROM dual";
else if (identityType == typeof(long) || identityType == typeof(ulong)) identitySql = "SELECT dbinfo('serial8') FROM dual";
else if (identityType == typeof(long) || identityType == typeof(ulong)) identitySql =
identityCol.Attribute.DbType.IndexOf("bigserial", StringComparison.OrdinalIgnoreCase) != -1 ?
"SELECT dbinfo('bigserial') FROM dual" : "SELECT dbinfo('serial8') FROM dual";
}
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, string.Concat(sql, $"; {identitySql};"), _params);
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
Expand Down

0 comments on commit 233990d

Please sign in to comment.