mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 17:20:49 +08:00 
			
		
		
		
	- 修复 Pgsql 批量更新使用 NoneParameter 后日期类型的语法 bug;
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
				
			|||||||
using FreeSql.DataAnnotations;
 | 
					using FreeSql.DataAnnotations;
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Linq;
 | 
				
			||||||
using Xunit;
 | 
					using Xunit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace FreeSql.Tests.MySqlConnector
 | 
					namespace FreeSql.Tests.MySqlConnector
 | 
				
			||||||
@@ -180,7 +181,14 @@ namespace FreeSql.Tests.MySqlConnector
 | 
				
			|||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
        public void ExecuteAffrows()
 | 
					        public void ExecuteAffrows()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            var items = new List<Topic>();
 | 
				
			||||||
 | 
					            for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var time = DateTime.Now;
 | 
				
			||||||
 | 
					            var items222 = g.mysql.Select<Topic>().Where(a => a.CreateTime > time).Limit(10).ToList();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            update.SetSource(items.First()).NoneParameter().ExecuteAffrows();
 | 
				
			||||||
 | 
					            update.SetSource(items).NoneParameter().ExecuteAffrows();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
        public void ExecuteUpdated()
 | 
					        public void ExecuteUpdated()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
using FreeSql.DataAnnotations;
 | 
					using FreeSql.DataAnnotations;
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Linq;
 | 
				
			||||||
using Xunit;
 | 
					using Xunit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace FreeSql.Tests.MySql
 | 
					namespace FreeSql.Tests.MySql
 | 
				
			||||||
@@ -181,7 +182,14 @@ namespace FreeSql.Tests.MySql
 | 
				
			|||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
        public void ExecuteAffrows()
 | 
					        public void ExecuteAffrows()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            var items = new List<Topic>();
 | 
				
			||||||
 | 
					            for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var time = DateTime.Now;
 | 
				
			||||||
 | 
					            var items222 = g.mysql.Select<Topic>().Where(a => a.CreateTime > time).Limit(10).ToList();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            update.SetSource(items.First()).NoneParameter().ExecuteAffrows();
 | 
				
			||||||
 | 
					            update.SetSource(items).NoneParameter().ExecuteAffrows();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
        public void ExecuteUpdated()
 | 
					        public void ExecuteUpdated()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
using FreeSql.DataAnnotations;
 | 
					using FreeSql.DataAnnotations;
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Linq;
 | 
				
			||||||
using Xunit;
 | 
					using Xunit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace FreeSql.Tests.PostgreSQL
 | 
					namespace FreeSql.Tests.PostgreSQL
 | 
				
			||||||
@@ -120,7 +121,11 @@ namespace FreeSql.Tests.PostgreSQL
 | 
				
			|||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
        public void ExecuteAffrows()
 | 
					        public void ExecuteAffrows()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            var items = new List<Topic>();
 | 
				
			||||||
 | 
					            for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            update.SetSource(items.First()).NoneParameter().ExecuteAffrows();
 | 
				
			||||||
 | 
					            update.SetSource(items).NoneParameter().ExecuteAffrows();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
        public void ExecuteUpdated()
 | 
					        public void ExecuteUpdated()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,7 @@ using FreeSql.DataAnnotations;
 | 
				
			|||||||
using FreeSql.Tests.DataContext.SqlServer;
 | 
					using FreeSql.Tests.DataContext.SqlServer;
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Linq;
 | 
				
			||||||
using Xunit;
 | 
					using Xunit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace FreeSql.Tests.SqlServer
 | 
					namespace FreeSql.Tests.SqlServer
 | 
				
			||||||
@@ -131,7 +132,14 @@ namespace FreeSql.Tests.SqlServer
 | 
				
			|||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
        public void ExecuteAffrows()
 | 
					        public void ExecuteAffrows()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            var items = new List<Topic>();
 | 
				
			||||||
 | 
					            for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var time = DateTime.Now;
 | 
				
			||||||
 | 
					            var items222 = g.sqlserver.Select<Topic>().Where(a => a.CreateTime > time).Limit(10).ToList();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            update.SetSource(items.First()).NoneParameter().ExecuteAffrows();
 | 
				
			||||||
 | 
					            update.SetSource(items).NoneParameter().ExecuteAffrows();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
        public void ExecuteUpdated()
 | 
					        public void ExecuteUpdated()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
using FreeSql.DataAnnotations;
 | 
					using FreeSql.DataAnnotations;
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Linq;
 | 
				
			||||||
using Xunit;
 | 
					using Xunit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace FreeSql.Tests.Sqlite
 | 
					namespace FreeSql.Tests.Sqlite
 | 
				
			||||||
@@ -124,7 +125,14 @@ namespace FreeSql.Tests.Sqlite
 | 
				
			|||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
        public void ExecuteAffrows()
 | 
					        public void ExecuteAffrows()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            var items = new List<Topic>();
 | 
				
			||||||
 | 
					            for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var time = DateTime.Now;
 | 
				
			||||||
 | 
					            var items222 = g.sqlite.Select<Topic>().Where(a => a.CreateTime > time).Limit(10).ToList();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            update.SetSource(items.First()).NoneParameter().ExecuteAffrows();
 | 
				
			||||||
 | 
					            update.SetSource(items).NoneParameter().ExecuteAffrows();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
        public void ExecuteUpdated()
 | 
					        public void ExecuteUpdated()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -566,6 +566,7 @@ namespace FreeSql.Internal.CommonProvider
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        protected abstract void ToSqlCase(StringBuilder caseWhen, ColumnInfo[] primarys);
 | 
					        protected abstract void ToSqlCase(StringBuilder caseWhen, ColumnInfo[] primarys);
 | 
				
			||||||
        protected abstract void ToSqlWhen(StringBuilder sb, ColumnInfo[] primarys, object d);
 | 
					        protected abstract void ToSqlWhen(StringBuilder sb, ColumnInfo[] primarys, object d);
 | 
				
			||||||
 | 
					        protected virtual void ToSqlCaseWhenEnd(StringBuilder sb, ColumnInfo col) { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public IUpdate<T1> AsTable(Func<string, string> tableRule)
 | 
					        public IUpdate<T1> AsTable(Func<string, string> tableRule)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
@@ -658,7 +659,11 @@ namespace FreeSql.Internal.CommonProvider
 | 
				
			|||||||
                            if (isnull == false) isnull = value == null || value == DBNull.Value;
 | 
					                            if (isnull == false) isnull = value == null || value == DBNull.Value;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        cwsb.Append(" END");
 | 
					                        cwsb.Append(" END");
 | 
				
			||||||
                        if (isnull == false) sb.Append(cwsb.ToString());
 | 
					                        if (isnull == false)
 | 
				
			||||||
 | 
					                        {
 | 
				
			||||||
 | 
					                            ToSqlCaseWhenEnd(cwsb, col);
 | 
				
			||||||
 | 
					                            sb.Append(cwsb.ToString());
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
                        else sb.Append("NULL");
 | 
					                        else sb.Append("NULL");
 | 
				
			||||||
                        cwsb.Clear();
 | 
					                        cwsb.Clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -136,5 +136,14 @@ namespace FreeSql.PostgreSQL.Curd
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            sb.Append(")");
 | 
					            sb.Append(")");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        protected override void ToSqlCaseWhenEnd(StringBuilder sb, ColumnInfo col)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (_noneParameter == false) return;
 | 
				
			||||||
 | 
					            var dbtype = _commonUtils.CodeFirst.GetDbInfo(col.Attribute.MapType)?.dbtype;
 | 
				
			||||||
 | 
					            if (dbtype == null) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            sb.Append("::").Append(dbtype);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user