mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 优化 MySql StringLength/MaxLength -2 产生 LongText 映射;
This commit is contained in:
parent
926d8353c1
commit
b9948f4508
@ -125,6 +125,13 @@
|
||||
清空状态数据
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:FreeSql.DbSet`1.RemoveAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
|
||||
<summary>
|
||||
根据 lambda 条件删除数据
|
||||
</summary>
|
||||
<param name="predicate"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSql.DbSet`1.Add(`0)">
|
||||
<summary>
|
||||
添加
|
||||
@ -479,5 +486,14 @@
|
||||
<param name="that"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
||||
<summary>
|
||||
批量注入 Repository,可以参考代码自行调整
|
||||
</summary>
|
||||
<param name="services"></param>
|
||||
<param name="globalDataFilter"></param>
|
||||
<param name="assemblies"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
@ -10,6 +10,94 @@ namespace FreeSql.Tests.MySqlConnector
|
||||
{
|
||||
public class MySqlCodeFirstTest
|
||||
{
|
||||
[Fact]
|
||||
public void Text_StringLength_1()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 1000).Select(a => "我是中国人"));
|
||||
|
||||
var item1 = new TS_TEXT02 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.mysql.Select<TS_TEXT02>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(str1, item2.Data);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_TEXT02 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
class TS_TEXT02
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(StringLength = -1)]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Text()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 1000).Select(a => "我是中国人"));
|
||||
|
||||
var item1 = new TS_TEXT01 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.mysql.Select<TS_TEXT01>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(str1, item2.Data);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_TEXT01 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
class TS_TEXT01
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(DbType = "text")]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Text_StringLength_2()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||
|
||||
var item1 = new TS_TEXT04 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.mysql.Select<TS_TEXT04>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(str1, item2.Data);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_TEXT04 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
class TS_TEXT04
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(StringLength = -2)]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LongText()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||
|
||||
var item1 = new TS_TEXT03 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.mysql.Select<TS_TEXT03>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(str1, item2.Data);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_TEXT03 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
class TS_TEXT03
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(DbType = "longtext")]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StringLength()
|
||||
{
|
||||
|
@ -9,7 +9,7 @@ namespace FreeSql.Tests.Dameng
|
||||
public class DamengInsertTest
|
||||
{
|
||||
|
||||
IInsert<Topic> insert => g.dameng.Insert<Topic>(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
IInsert<Topic> insert => g.dameng.Insert<Topic>().NoneParameter();
|
||||
|
||||
[Table(Name = "tb_topic_insert")]
|
||||
class Topic
|
||||
|
@ -7,7 +7,7 @@ namespace FreeSql.Tests.Dameng
|
||||
{
|
||||
public class DamengUpdateTest
|
||||
{
|
||||
IUpdate<Topic> update => g.dameng.Update<Topic>();
|
||||
IUpdate<Topic> update => g.dameng.Update<Topic>().NoneParameter();
|
||||
|
||||
[Table(Name = "tb_topic")]
|
||||
class Topic
|
||||
|
@ -10,6 +10,74 @@ namespace FreeSql.Tests.Dameng
|
||||
{
|
||||
public class DamengCodeFirstTest
|
||||
{
|
||||
[Fact]
|
||||
public void Text_StringLength_1()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||
|
||||
var item1 = new TS_TEXT02 { Data = str1 };
|
||||
Assert.Equal(1, g.dameng.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.dameng.Select<TS_TEXT02>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(str1, item2.Data);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_TEXT02 { Data = str1 };
|
||||
Assert.Equal(1, g.dameng.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
class TS_TEXT02
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(StringLength = -1)]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Text()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||
|
||||
var item1 = new TS_TEXT01 { Data = str1 };
|
||||
Assert.Equal(1, g.dameng.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.dameng.Select<TS_TEXT01>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(str1, item2.Data);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_TEXT01 { Data = str1 };
|
||||
Assert.Equal(1, g.dameng.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
class TS_TEXT01
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(DbType = "text")]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void Blob()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||
var data1 = Encoding.UTF8.GetBytes(str1);
|
||||
|
||||
var item1 = new TS_BLB01 { Data = data1 };
|
||||
Assert.Equal(1, g.dameng.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.dameng.Select<TS_BLB01>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(item1.Data.Length, item2.Data.Length);
|
||||
|
||||
var str2 = Encoding.UTF8.GetString(item2.Data);
|
||||
Assert.Equal(str1, str2);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_BLB01 { Data = data1 };
|
||||
Assert.Throws<Exception>(() => g.dameng.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
//DmException: 字符串截断
|
||||
}
|
||||
class TS_BLB01
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public byte[] Data { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void StringLength()
|
||||
{
|
||||
@ -238,11 +306,6 @@ namespace FreeSql.Tests.Dameng
|
||||
[Fact]
|
||||
public void CurdAllField()
|
||||
{
|
||||
var item = new TableAllType { };
|
||||
item.Id = (int)insert.AppendData(item).ExecuteIdentity();
|
||||
|
||||
var newitem = select.Where(a => a.Id == item.Id).ToOne();
|
||||
|
||||
var item2 = new TableAllType
|
||||
{
|
||||
Bool = true,
|
||||
|
@ -1497,15 +1497,6 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.tostring, find.tostring);
|
||||
Assert.Equal(false, find.tostring);
|
||||
|
||||
item = new BoolNullableMap { tostring = null };
|
||||
Assert.Equal(1, orm.Insert<BoolNullableMap>().AppendData(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == false).First());
|
||||
find = orm.Select<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.tostring, find.tostring);
|
||||
Assert.Null(find.tostring);
|
||||
|
||||
//update all
|
||||
item.tostring = true;
|
||||
Assert.Equal(1, orm.Update<BoolNullableMap>().SetSource(item).ExecuteAffrows());
|
||||
@ -1523,15 +1514,6 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.tostring, find.tostring);
|
||||
Assert.Equal(false, find.tostring);
|
||||
|
||||
item.tostring = null;
|
||||
Assert.Equal(1, orm.Update<BoolNullableMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == false).First());
|
||||
find = orm.Select<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.tostring, find.tostring);
|
||||
Assert.Null(find.tostring);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<BoolNullableMap>().Where(a => a.id == item.id).Set(a => a.tostring, true).ExecuteAffrows());
|
||||
find = orm.Select<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == true).First();
|
||||
@ -1545,17 +1527,9 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(false, find.tostring);
|
||||
|
||||
Assert.Equal(1, orm.Update<BoolNullableMap>().Where(a => a.id == item.id).Set(a => a.tostring, null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == false).First());
|
||||
find = orm.Select<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.tostring);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == true).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == false).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == null).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<BoolNullableMap>().Where(a => a.id == item.id && a.tostring == false).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<BoolNullableMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
|
||||
|
@ -84,17 +84,9 @@ namespace FreeSql.Tests.DamengMapType
|
||||
{
|
||||
//insert
|
||||
var orm = g.dameng;
|
||||
var item = new EnumTestMap { };
|
||||
var item = new EnumTestMap { enumnullable_to_string = ToStringMapEnum.中国人 };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
item = new EnumTestMap { enumnullable_to_string = ToStringMapEnum.ÖйúÈË };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.ÖйúÈË).First();
|
||||
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
@ -109,15 +101,6 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Equal(ToStringMapEnum.Ïã¸Û, find.enumnullable_to_string);
|
||||
|
||||
item.enumnullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.Ïã¸Û).First());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First();
|
||||
@ -125,19 +108,10 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_string);
|
||||
|
||||
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.ÖйúÈË).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.Ïã¸Û).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
|
||||
Assert.NotNull(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -99,17 +99,9 @@ namespace FreeSql.Tests.DamengMapType
|
||||
{
|
||||
//insert
|
||||
var orm = g.dameng;
|
||||
var item = new ToStringMap { };
|
||||
var item = new ToStringMap { enumnullable_to_string = ToStringMapEnum.ÖйúÈË };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
item = new ToStringMap { enumnullable_to_string = ToStringMapEnum.ÖйúÈË };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.ÖйúÈË).First();
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.ÖйúÈË).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
@ -124,15 +116,6 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Equal(ToStringMapEnum.Ïã¸Û, find.enumnullable_to_string);
|
||||
|
||||
item.enumnullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.Ïã¸Û).First());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First();
|
||||
@ -140,19 +123,10 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_string);
|
||||
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.ÖйúÈË).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.Ïã¸Û).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
Assert.NotNull(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
public void BigInteger1()
|
||||
@ -216,17 +190,9 @@ namespace FreeSql.Tests.DamengMapType
|
||||
{
|
||||
//insert
|
||||
var orm = g.dameng;
|
||||
var item = new ToStringMap { };
|
||||
var item = new ToStringMap { bigintegernullable_to_string = 101 };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
|
||||
Assert.Null(find.bigintegernullable_to_string);
|
||||
|
||||
item = new ToStringMap { bigintegernullable_to_string = 101 };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 101).First();
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 101).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
|
||||
@ -241,15 +207,6 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
|
||||
Assert.Equal(2004, find.bigintegernullable_to_string);
|
||||
|
||||
item.bigintegernullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).First());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.bigintegernullable_to_string, find.bigintegernullable_to_string);
|
||||
Assert.Null(find.bigintegernullable_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.bigintegernullable_to_string, 998).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).First();
|
||||
@ -257,18 +214,9 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(998, find.bigintegernullable_to_string);
|
||||
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.bigintegernullable_to_string, null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).First());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.bigintegernullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
[Fact]
|
||||
@ -513,18 +461,10 @@ namespace FreeSql.Tests.DamengMapType
|
||||
{
|
||||
//insert
|
||||
var orm = g.dameng;
|
||||
var item = new ToStringMap { };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
|
||||
Assert.Null(find.guidnullable_to_string);
|
||||
|
||||
var newid = Guid.NewGuid();
|
||||
item = new ToStringMap { guidnullable_to_string = newid };
|
||||
var item = new ToStringMap { guidnullable_to_string = newid };
|
||||
Assert.Equal(1, orm.Insert<ToStringMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == newid).First();
|
||||
var find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == newid).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
|
||||
@ -540,14 +480,6 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
|
||||
Assert.Equal(newid, find.guidnullable_to_string);
|
||||
|
||||
item.guidnullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.guidnullable_to_string, find.guidnullable_to_string);
|
||||
Assert.Null(find.guidnullable_to_string);
|
||||
|
||||
//update set
|
||||
newid = Guid.NewGuid();
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.guidnullable_to_string, newid).ExecuteAffrows());
|
||||
@ -556,14 +488,8 @@ namespace FreeSql.Tests.DamengMapType
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(newid, find.guidnullable_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<ToStringMap>().Where(a => a.id == item.id).Set(a => a.guidnullable_to_string, null).ExecuteAffrows());
|
||||
find = orm.Select<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Null(find.guidnullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id && a.guidnullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<ToStringMap>().Where(a => a.id == item.id).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<ToStringMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,94 @@ namespace FreeSql.Tests.MySql
|
||||
{
|
||||
public class MySqlCodeFirstTest
|
||||
{
|
||||
[Fact]
|
||||
public void Text_StringLength_1()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 1000).Select(a => "我是中国人"));
|
||||
|
||||
var item1 = new TS_TEXT02 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.mysql.Select<TS_TEXT02>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(str1, item2.Data);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_TEXT02 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
class TS_TEXT02
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(StringLength = -1)]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Text()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 1000).Select(a => "我是中国人"));
|
||||
|
||||
var item1 = new TS_TEXT01 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.mysql.Select<TS_TEXT01>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(str1, item2.Data);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_TEXT01 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
class TS_TEXT01
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(DbType = "text")]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Text_StringLength_2()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||
|
||||
var item1 = new TS_TEXT04 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.mysql.Select<TS_TEXT04>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(str1, item2.Data);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_TEXT04 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
class TS_TEXT04
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(StringLength = -2)]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LongText()
|
||||
{
|
||||
var str1 = string.Join(",", Enumerable.Range(0, 10000).Select(a => "我是中国人"));
|
||||
|
||||
var item1 = new TS_TEXT03 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).ExecuteAffrows());
|
||||
|
||||
var item2 = g.mysql.Select<TS_TEXT03>().Where(a => a.Id == item1.Id).First();
|
||||
Assert.Equal(str1, item2.Data);
|
||||
|
||||
//NoneParameter
|
||||
item1 = new TS_TEXT03 { Data = str1 };
|
||||
Assert.Equal(1, g.mysql.Insert(item1).NoneParameter().ExecuteAffrows());
|
||||
}
|
||||
class TS_TEXT03
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
[Column(DbType = "longtext")]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StringLength()
|
||||
{
|
||||
|
@ -89,11 +89,11 @@ namespace FreeSql.DataAnnotations
|
||||
/// Oracle -> nvarchar2(100)<para></para>
|
||||
/// Sqlite -> nvarchar(100)<para></para>
|
||||
/// ---<para></para>
|
||||
/// StringLength = -1 时,对应 DbType:<para></para>
|
||||
/// MySql -> text<para></para>
|
||||
/// StringLength < 0 时,对应 DbType:<para></para>
|
||||
/// MySql -> text (StringLength = -2 时,对应 DbType longtext)<para></para>
|
||||
/// SqlServer -> nvarchar(max)<para></para>
|
||||
/// PostgreSQL -> text<para></para>
|
||||
/// Oracle -> nvarchar2(4000)<para></para>
|
||||
/// Oracle -> nclob<para></para>
|
||||
/// Sqlite -> text<para></para>
|
||||
/// </summary>
|
||||
public int StringLength { get => _StringLength ?? 0; set => _StringLength = value; }
|
||||
|
@ -90,11 +90,11 @@
|
||||
Oracle -> nvarchar2(100)<para></para>
|
||||
Sqlite -> nvarchar(100)<para></para>
|
||||
---<para></para>
|
||||
StringLength = -1 时,对应 DbType:<para></para>
|
||||
MySql -> text<para></para>
|
||||
StringLength < 0 时,对应 DbType:<para></para>
|
||||
MySql -> text (StringLength = -2 时,对应 DbType longtext)<para></para>
|
||||
SqlServer -> nvarchar(max)<para></para>
|
||||
PostgreSQL -> text<para></para>
|
||||
Oracle -> nvarchar2(4000)<para></para>
|
||||
Oracle -> nclob<para></para>
|
||||
Sqlite -> text<para></para>
|
||||
</summary>
|
||||
</member>
|
||||
|
@ -1218,12 +1218,12 @@ namespace FreeSql.Internal.CommonProvider
|
||||
break;
|
||||
case DataType.Oracle:
|
||||
case DataType.OdbcOracle:
|
||||
case DataType.Dameng:
|
||||
case DataType.OdbcDameng:
|
||||
_tosqlAppendContent = $" for update{(noawait ? " nowait" : "")}";
|
||||
break;
|
||||
case DataType.Sqlite:
|
||||
break;
|
||||
case DataType.OdbcDameng:
|
||||
case DataType.Dameng:
|
||||
case DataType.OdbcKingbaseES:
|
||||
_tosqlAppendContent = $" for update{(noawait ? " nowait" : "")}";
|
||||
break;
|
||||
|
@ -232,7 +232,8 @@ namespace FreeSql.Internal
|
||||
{
|
||||
case DataType.MySql:
|
||||
case DataType.OdbcMySql:
|
||||
if (strlen < 0) colattr.DbType = "TEXT";
|
||||
if (strlen == -2) colattr.DbType = "LONGTEXT";
|
||||
else if (strlen < 0) colattr.DbType = "TEXT";
|
||||
else colattr.DbType = Regex.Replace(colattr.DbType, charPatten, $"$1({strlen})");
|
||||
break;
|
||||
case DataType.SqlServer:
|
||||
@ -250,9 +251,13 @@ namespace FreeSql.Internal
|
||||
if (strlen < 0) colattr.DbType = "NCLOB"; //v1.3.2+ https://github.com/dotnetcore/FreeSql/issues/259
|
||||
else colattr.DbType = Regex.Replace(colattr.DbType, charPatten, $"$1({strlen})");
|
||||
break;
|
||||
case DataType.Dameng:
|
||||
if (strlen < 0) colattr.DbType = "TEXT";
|
||||
else colattr.DbType = Regex.Replace(colattr.DbType, charPatten, $"$1({strlen})");
|
||||
break;
|
||||
case DataType.OdbcOracle:
|
||||
case DataType.OdbcDameng:
|
||||
if (strlen < 0) colattr.DbType = Regex.Replace(colattr.DbType, charPatten, $"$1(4000)");
|
||||
if (strlen < 0) colattr.DbType = Regex.Replace(colattr.DbType, charPatten, $"$1(4000)"); //ODBC 不支持 NCLOB
|
||||
else colattr.DbType = Regex.Replace(colattr.DbType, charPatten, $"$1({strlen})");
|
||||
break;
|
||||
case DataType.Sqlite:
|
||||
|
@ -15,7 +15,6 @@ namespace FreeSql.Dameng
|
||||
|
||||
class DamengCodeFirst : Internal.CommonProvider.CodeFirstProvider
|
||||
{
|
||||
public override bool IsNoneCommandParameter { get => true; set => base.IsNoneCommandParameter = true; }
|
||||
public DamengCodeFirst(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression) : base(orm, commonUtils, commonExpression) { }
|
||||
|
||||
static object _dicCsToDbLock = new object();
|
||||
@ -310,8 +309,9 @@ and not exists(select 1 from all_constraints where index_name = a.index_name and
|
||||
continue;
|
||||
}
|
||||
var oldpk = _orm.Ado.ExecuteScalar(CommandType.Text, _commonUtils.FormatSql(@" select constraint_name from user_constraints where owner={0} and table_name={1} and constraint_type='P'", tbname))?.ToString();
|
||||
if (string.IsNullOrEmpty(oldpk) == false)
|
||||
sb.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" DROP CONSTRAINT ").Append(oldpk).Append("';\r\n");
|
||||
//if (string.IsNullOrEmpty(oldpk) == false)
|
||||
// sb.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" DROP CONSTRAINT ").Append(_commonUtils.QuoteSqlName(oldpk)).Append("';\r\n");
|
||||
//执行失败(语句1) 试图删除聚集主键
|
||||
|
||||
//创建临时表,数据导进临时表,然后删除原表,将临时表改名为原表名
|
||||
var tablename = tboldname == null ? _commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}") : _commonUtils.QuoteSqlName($"{tboldname[0]}.{tboldname[1]}");
|
||||
@ -325,7 +325,8 @@ and not exists(select 1 from all_constraints where index_name = a.index_name and
|
||||
}
|
||||
if (tb.Primarys.Any())
|
||||
{
|
||||
var pkname = primaryKeyName ?? $"{tbname[0]}_{tbname[1]}_pk2";
|
||||
var pkname = primaryKeyName ?? $"{tbname[0]}_{tbname[1]}_pk1";
|
||||
if (string.IsNullOrEmpty(oldpk) == false && oldpk == pkname) pkname = $"{pkname}1";
|
||||
sb.Append(" \r\n CONSTRAINT ").Append(_commonUtils.QuoteSqlName(pkname)).Append(" PRIMARY KEY (");
|
||||
foreach (var tbcol in tb.Primarys) sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
|
||||
sb.Remove(sb.Length - 2, 2).Append("),");
|
||||
@ -457,6 +458,15 @@ and not exists(select 1 from all_constraints where index_name = a.index_name and
|
||||
else if (sqlType.StartsWith("BLOB"))
|
||||
{
|
||||
}
|
||||
else if (sqlType.StartsWith("CLOB"))
|
||||
{
|
||||
}
|
||||
else if (sqlType.StartsWith("NCLOB"))
|
||||
{
|
||||
}
|
||||
else if (sqlType.StartsWith("TEXT"))
|
||||
{
|
||||
}
|
||||
else if (sqlType == "REAL" || sqlType == "DOUBLE" || sqlType == "FLOAT")
|
||||
{
|
||||
}
|
||||
|
@ -310,8 +310,9 @@ and not exists(select 1 from all_constraints where index_name = a.index_name and
|
||||
continue;
|
||||
}
|
||||
var oldpk = _orm.Ado.ExecuteScalar(CommandType.Text, _commonUtils.FormatSql(@" select constraint_name from user_constraints where owner={0} and table_name={1} and constraint_type='P'", tbname))?.ToString();
|
||||
if (string.IsNullOrEmpty(oldpk) == false)
|
||||
sb.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" DROP CONSTRAINT ").Append(oldpk).Append("';\r\n");
|
||||
//if (string.IsNullOrEmpty(oldpk) == false)
|
||||
// sb.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" DROP CONSTRAINT ").Append(_commonUtils.QuoteSqlName(oldpk)).Append("';\r\n");
|
||||
//执行失败(语句1) 试图删除聚集主键
|
||||
|
||||
//创建临时表,数据导进临时表,然后删除原表,将临时表改名为原表名
|
||||
var tablename = tboldname == null ? _commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}") : _commonUtils.QuoteSqlName($"{tboldname[0]}.{tboldname[1]}");
|
||||
@ -325,7 +326,8 @@ and not exists(select 1 from all_constraints where index_name = a.index_name and
|
||||
}
|
||||
if (tb.Primarys.Any())
|
||||
{
|
||||
var pkname = primaryKeyName ?? $"{tbname[0]}_{tbname[1]}_pk2";
|
||||
var pkname = primaryKeyName ?? $"{tbname[0]}_{tbname[1]}_pk1";
|
||||
if (string.IsNullOrEmpty(oldpk) == false && oldpk == pkname) pkname = $"{pkname}1";
|
||||
sb.Append(" \r\n CONSTRAINT ").Append(_commonUtils.QuoteSqlName(pkname)).Append(" PRIMARY KEY (");
|
||||
foreach (var tbcol in tb.Primarys) sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", ");
|
||||
sb.Remove(sb.Length - 2, 2).Append("),");
|
||||
|
@ -309,7 +309,7 @@ and not exists(select 1 from all_constraints where constraint_name = a.index_nam
|
||||
}
|
||||
var oldpk = _orm.Ado.ExecuteScalar(CommandType.Text, _commonUtils.FormatSql(@" select constraint_name from user_constraints where owner={0} and table_name={1} and constraint_type='P'", tbname))?.ToString();
|
||||
if (string.IsNullOrEmpty(oldpk) == false)
|
||||
sb.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" DROP CONSTRAINT ").Append(oldpk).Append("';\r\n");
|
||||
sb.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" DROP CONSTRAINT ").Append(_commonUtils.QuoteSqlName(oldpk)).Append("';\r\n");
|
||||
|
||||
//创建临时表,数据导进临时表,然后删除原表,将临时表改名为原表名
|
||||
var tablename = tboldname == null ? _commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}") : _commonUtils.QuoteSqlName($"{tboldname[0]}.{tboldname[1]}");
|
||||
|
@ -310,7 +310,7 @@ and not exists(select 1 from all_constraints where constraint_name = a.index_nam
|
||||
}
|
||||
var oldpk = _orm.Ado.ExecuteScalar(CommandType.Text, _commonUtils.FormatSql(@" select constraint_name from user_constraints where owner={0} and table_name={1} and constraint_type='P'", tbname))?.ToString();
|
||||
if (string.IsNullOrEmpty(oldpk) == false)
|
||||
sb.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" DROP CONSTRAINT ").Append(oldpk).Append("';\r\n");
|
||||
sb.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" DROP CONSTRAINT ").Append(_commonUtils.QuoteSqlName(oldpk)).Append("';\r\n");
|
||||
|
||||
//创建临时表,数据导进临时表,然后删除原表,将临时表改名为原表名
|
||||
var tablename = tboldname == null ? _commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}") : _commonUtils.QuoteSqlName($"{tboldname[0]}.{tboldname[1]}");
|
||||
|
Loading…
x
Reference in New Issue
Block a user