mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
- 增加 pgsql numeric -> BigInteger 映射;#1100
This commit is contained in:
@ -14,10 +14,12 @@ using System.Data.SQLite;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -158,8 +160,11 @@ namespace base_entity
|
||||
public string Title { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
|
||||
|
||||
class tuint256tb_01
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public BigInteger Number { get; set; }
|
||||
}
|
||||
class CommandTimeoutCascade : IDisposable
|
||||
{
|
||||
public static AsyncLocal<int> _asyncLocalTimeout = new AsyncLocal<int>();
|
||||
@ -177,7 +182,7 @@ namespace base_entity
|
||||
//.UseSlave("data source=test1.db", "data source=test2.db", "data source=test3.db", "data source=test4.db")
|
||||
//.UseSlaveWeight(10, 1, 1, 5)
|
||||
|
||||
|
||||
|
||||
//.UseConnectionString(FreeSql.DataType.Firebird, @"database=localhost:D:\fbdata\EXAMPLES.fdb;user=sysdba;password=123456;max pool size=5")
|
||||
|
||||
|
||||
@ -185,8 +190,8 @@ namespace base_entity
|
||||
|
||||
//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3;TrustServerCertificate=true")
|
||||
|
||||
//.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=192.168.164.10;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=2")
|
||||
//.UseNameConvert(FreeSql.Internal.NameConvertType.ToLower)
|
||||
.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=192.168.164.10;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=2")
|
||||
.UseNameConvert(FreeSql.Internal.NameConvertType.ToLower)
|
||||
|
||||
//.UseConnectionString(FreeSql.DataType.Oracle, "user id=user1;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=2")
|
||||
//.UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper)
|
||||
@ -211,6 +216,56 @@ namespace base_entity
|
||||
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
|
||||
#endregion
|
||||
|
||||
if (fsql.Ado.DataType == DataType.PostgreSQL)
|
||||
{
|
||||
fsql.CodeFirst.IsNoneCommandParameter = false;
|
||||
fsql.Aop.AuditDataReader += (_, e) =>
|
||||
{
|
||||
var dbtype = e.DataReader.GetDataTypeName(e.Index);
|
||||
var m = Regex.Match(dbtype, @"numeric\((\d+)\)", RegexOptions.IgnoreCase);
|
||||
if (m.Success && int.Parse(m.Groups[1].Value) > 19)
|
||||
e.Value = e.DataReader.GetFieldValue<BigInteger>(e.Index); //否则会报溢出错误
|
||||
};
|
||||
|
||||
var num = BigInteger.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819968");
|
||||
fsql.Delete<tuint256tb_01>().Where("1=1").ExecuteAffrows();
|
||||
if (1 != fsql.Insert(new tuint256tb_01()).ExecuteAffrows()) throw new Exception("not equal");
|
||||
var find = fsql.Select<tuint256tb_01>().ToList();
|
||||
if (find.Count != 1) throw new Exception("not single");
|
||||
if ("0" != find[0].Number.ToString()) throw new Exception("not equal");
|
||||
var item = new tuint256tb_01 { Number = num };
|
||||
if (1 != fsql.Insert(item).ExecuteAffrows()) throw new Exception("not equal");
|
||||
find = fsql.Select<tuint256tb_01>().Where(a => a.Id == item.Id).ToList();
|
||||
if (find.Count != 1) throw new Exception("not single");
|
||||
if (item.Number != find[0].Number) throw new Exception("not equal");
|
||||
num = num - 1;
|
||||
item.Number = num;
|
||||
if (1 != fsql.Update<tuint256tb_01>().SetSource(item).ExecuteAffrows()) throw new Exception("not equal");
|
||||
find = fsql.Select<tuint256tb_01>().Where(a => a.Id == item.Id).ToList();
|
||||
if (find.Count != 1) throw new Exception("not single");
|
||||
if ("57896044618658097711785492504343953926634992332820282019728792003956564819967" != find[0].Number.ToString()) throw new Exception("not equal");
|
||||
|
||||
num = BigInteger.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819968");
|
||||
fsql.Delete<tuint256tb_01>().Where("1=1").ExecuteAffrows();
|
||||
if (1 != fsql.Insert(new tuint256tb_01()).NoneParameter().ExecuteAffrows()) throw new Exception("not equal");
|
||||
find = fsql.Select<tuint256tb_01>().ToList();
|
||||
if (find.Count != 1) throw new Exception("not single");
|
||||
if ("0" != find[0].Number.ToString()) throw new Exception("not equal");
|
||||
item = new tuint256tb_01 { Number = num };
|
||||
if (1 != fsql.Insert(item).NoneParameter().ExecuteAffrows()) throw new Exception("not equal");
|
||||
find = fsql.Select<tuint256tb_01>().Where(a => a.Id == item.Id).ToList();
|
||||
if (find.Count != 1) throw new Exception("not single");
|
||||
if (item.Number != find[0].Number) throw new Exception("not equal");
|
||||
num = num - 1;
|
||||
item.Number = num;
|
||||
if (1 != fsql.Update<tuint256tb_01>().NoneParameter().SetSource(item).ExecuteAffrows()) throw new Exception("not equal");
|
||||
find = fsql.Select<tuint256tb_01>().Where(a => a.Id == item.Id).ToList();
|
||||
if (find.Count != 1) throw new Exception("not single");
|
||||
if ("57896044618658097711785492504343953926634992332820282019728792003956564819967" != find[0].Number.ToString()) throw new Exception("not equal");
|
||||
}
|
||||
|
||||
|
||||
|
||||
fsql.Aop.CommandBefore += (_, e) =>
|
||||
{
|
||||
if (CommandTimeoutCascade._asyncLocalTimeout.Value > 0)
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="Npgsql.NetTopologySuite" Version="6.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Reference in New Issue
Block a user