From 040f9bdabe7d42f34e0ad55e96353bab04566779 Mon Sep 17 00:00:00 2001 From: 2881099 <2881099@qq.com> Date: Fri, 9 Aug 2024 20:35:06 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BC=98=E5=8C=96=20LIKE=20=E8=A1=A8?= =?UTF-8?q?=E8=BE=BE=E5=BC=8F=E8=A7=A3=E6=9E=90=20#1870=EF=BC=9B=20-=20?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=20OdbcDameng/OdbcKingbaseES=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ZeroDbContext.SelectImpl.cs | 1 - .../ZeroDbContext.cs | 3 - Extensions/FreeSql.Generator/RazorModel.cs | 4 +- FreeSql.DbContext/DbSet/DbSet.cs | 1 - FreeSql.DbContext/DbSet/DbSetAsync.cs | 2 - FreeSql.DbContext/DbSet/DbSetSync.cs | 2 - .../Dameng/Curd/DamengDeleteTest.cs | 106 - ...DamengInsertOrUpdateIfExistsNothingTest.cs | 425 ---- .../Dameng/Curd/DamengInsertOrUpdateTest.cs | 467 ---- .../Dameng/Curd/DamengInsertTest.cs | 278 --- .../Dameng/Curd/DamengSelectTest.cs | 1880 ----------------- .../Dameng/Curd/DamengUpdateTest.cs | 190 -- .../Dameng/DamengAdo/DamengAdoTest.cs | 71 - .../Dameng/DamengAopTest.cs | 40 - .../Dameng/DamengCodeFirstTest.cs | 328 --- .../Dameng/DamengDbFirstTest.cs | 65 - .../Dameng/DamengExpression/ConvertTest.cs | 169 -- .../Dameng/DamengExpression/DateTimeTest.cs | 732 ------- .../Dameng/DamengExpression/MathTest.cs | 156 -- .../Dameng/DamengExpression/OtherTest.cs | 165 -- .../Dameng/DamengExpression/StringTest.cs | 827 -------- .../Dameng/DamengExpression/TimeSpanTest.cs | 293 --- .../Dameng/MapType/BoolNullableTest.cs | 1571 -------------- .../Dameng/MapType/BoolTest.cs | 1105 ---------- .../Dameng/MapType/DateTimeOffSetTest.cs | 54 - .../Dameng/MapType/EnumTest.cs | 261 --- .../Dameng/MapType/ToStringTest.cs | 570 ----- .../KingbaseES/Curd/KingbaseESDeleteTest.cs | 106 - ...aseESInsertOrUpdateIfExistsDoNotingTest.cs | 266 --- .../Curd/KingbaseESInsertOrUpdateTest.cs | 205 -- .../KingbaseES/Curd/KingbaseESInsertTest.cs | 141 -- .../KingbaseES/Curd/KingbaseESSelectTest.cs | 1829 ---------------- .../KingbaseES/Curd/KingbaseESUpdateTest.cs | 190 -- .../KingbaseES/Curd/OnConflictDoUpdateTest.cs | 158 -- .../KingbaseESAdo/KingbaseESAdoTest.cs | 71 - .../KingbaseES/KingbaseESAopTest.cs | 40 - .../KingbaseES/KingbaseESCodeFirstTest.cs | 334 --- .../KingbaseES/KingbaseESDbFirstTest.cs | 64 - .../KingbaseESExpression/ConvertTest.cs | 169 -- .../KingbaseESExpression/DateTimeTest.cs | 732 ------- .../KingbaseESExpression/MathTest.cs | 156 -- .../KingbaseESExpression/OtherTest.cs | 165 -- .../KingbaseESExpression/StringTest.cs | 827 -------- .../KingbaseESExpression/TimeSpanTest.cs | 293 --- .../KingbaseES/MapType/BoolNullableTest.cs | 1571 -------------- .../KingbaseES/MapType/BoolTest.cs | 1105 ---------- .../KingbaseES/MapType/DateTimeOffSetTest.cs | 54 - .../KingbaseES/MapType/EnumTest.cs | 261 --- .../KingbaseES/MapType/ToStringTest.cs | 570 ----- .../FreeSql.Tests.Provider.Odbc/g.cs | 32 - FreeSql/DataType.cs | 27 +- FreeSql/Extensions/FreeSqlGlobalExtensions.cs | 5 - FreeSql/FreeSql.xml | 21 +- FreeSql/FreeSqlBuilder.cs | 10 - FreeSql/Internal/CommonExpression.cs | 3 - .../CommonProvider/InsertOrUpdateProvider.cs | 1 - .../SelectProvider/Select0Provider.cs | 11 +- .../SelectProvider/SelectGroupingProvider.cs | 3 +- .../CommonProvider/UpdateJoinProvider.cs | 3 - .../Internal/CommonProvider/UpdateProvider.cs | 3 - FreeSql/Internal/UtilsExpressionTree.cs | 14 +- .../ClickHouseExpression.cs | 5 +- .../CustomExpression.cs | 11 +- .../MySql/CustomMySqlExpression.cs | 11 +- .../Oracle/CustomOracleExpression.cs | 11 +- .../PostgreSQL/CustomPostgreSQLExpression.cs | 11 +- .../SqlServer/CustomSqlServerExpression.cs | 12 +- .../DamengExpression.cs | 11 +- .../FirebirdExpression.cs | 11 +- .../FreeSql.Provider.GBase/GBaseExpression.cs | 11 +- .../KingbaseESExpression.cs | 11 +- .../MsAccessExpression.cs | 11 +- .../FreeSql.Provider.MySql/MySqlExpression.cs | 11 +- .../Dameng/Curd/OdbcDamengDelete.cs | 26 - .../Dameng/Curd/OdbcDamengInsert.cs | 224 -- .../Dameng/Curd/OdbcDamengInsertOrUpdate.cs | 85 - .../Dameng/Curd/OdbcDamengSelect.cs | 243 --- .../Dameng/Curd/OdbcDamengUpdate.cs | 72 - .../Dameng/OdbcDamengAdo/OdbcDamengAdo.cs | 91 - .../OdbcDamengAdo/OdbcDamengConnectionPool.cs | 250 --- .../Dameng/OdbcDamengCodeFirst.cs | 482 ----- .../Dameng/OdbcDamengDbFirst.cs | 616 ------ .../Dameng/OdbcDamengExpression.cs | 519 ----- .../Dameng/OdbcDamengProvider.cs | 37 - .../Dameng/OdbcDamengUtils.cs | 114 - .../Default/OdbcAdo/OdbcAdo.cs | 1 - .../Default/OdbcExpression.cs | 11 +- .../FreeSqlOdbcGlobalExtensions.cs | 18 - .../KingbaseES/Curd/OdbcKingbaseESDelete.cs | 121 -- .../KingbaseES/Curd/OdbcKingbaseESInsert.cs | 217 -- .../Curd/OdbcKingbaseESInsertOrUpdate.cs | 92 - .../Curd/OdbcKingbaseESOnConflictDoUpdate.cs | 217 -- .../KingbaseES/Curd/OdbcKingbaseESSelect.cs | 222 -- .../KingbaseES/Curd/OdbcKingbaseESUpdate.cs | 189 -- .../OdbcKingbaseESAdo/OdbcKingbaseESAdo.cs | 95 - .../OdbcKingbaseESConnectionPool.cs | 250 --- .../KingbaseES/OdbcKingbaseESCodeFirst.cs | 444 ---- .../KingbaseES/OdbcKingbaseESDbFirst.cs | 535 ----- .../KingbaseES/OdbcKingbaseESExpression.cs | 582 ----- .../KingbaseES/OdbcKingbaseESProvider.cs | 37 - .../KingbaseES/OdbcKingbaseESUtils.cs | 157 -- .../MySql/OdbcMySqlAdo/OdbcMySqlAdo.cs | 1 - .../MySql/OdbcMySqlExpression.cs | 11 +- .../Oracle/OdbcOracleAdo/OdbcOracleAdo.cs | 1 - .../Oracle/OdbcOracleExpression.cs | 11 +- .../OdbcPostgreSQLAdo/OdbcPostgreSQLAdo.cs | 1 - .../PostgreSQL/OdbcPostgreSQLExpression.cs | 11 +- .../OdbcSqlServerAdo/OdbcSqlServerAdo.cs | 1 - .../SqlServer/OdbcSqlServerExpression.cs | 12 +- .../OracleExpression.cs | 11 +- .../PostgreSQLExpression.cs | 11 +- .../QuestDbExpression.cs | 11 +- .../ShenTongExpression.cs | 11 +- .../SqlServerExpression.cs | 13 +- .../SqliteExpression.cs | 11 +- .../FreeSql.Provider.Xugu/XuguExpression.cs | 11 +- 116 files changed, 162 insertions(+), 25246 deletions(-) delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengDeleteTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengInsertOrUpdateIfExistsNothingTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengInsertOrUpdateTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengInsertTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengSelectTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengUpdateTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengAdo/DamengAdoTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengAopTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengCodeFirstTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengDbFirstTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/ConvertTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/DateTimeTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/MathTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/OtherTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/StringTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/TimeSpanTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/MapType/BoolNullableTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/MapType/BoolTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/MapType/DateTimeOffSetTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/MapType/EnumTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/MapType/ToStringTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESDeleteTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESInsertOrUpdateIfExistsDoNotingTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESInsertOrUpdateTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESInsertTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESSelectTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESUpdateTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/OnConflictDoUpdateTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESAdo/KingbaseESAdoTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESAopTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESCodeFirstTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESDbFirstTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/ConvertTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/DateTimeTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/MathTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/OtherTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/StringTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/TimeSpanTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/MapType/BoolNullableTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/MapType/BoolTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/MapType/DateTimeOffSetTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/MapType/EnumTest.cs delete mode 100644 FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/MapType/ToStringTest.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/Dameng/Curd/OdbcDamengDelete.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/Dameng/Curd/OdbcDamengInsert.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/Dameng/Curd/OdbcDamengInsertOrUpdate.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/Dameng/Curd/OdbcDamengSelect.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/Dameng/Curd/OdbcDamengUpdate.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengAdo/OdbcDamengAdo.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengAdo/OdbcDamengConnectionPool.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengCodeFirst.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengDbFirst.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengExpression.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengProvider.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengUtils.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESDelete.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESInsert.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESInsertOrUpdate.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESOnConflictDoUpdate.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESSelect.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESUpdate.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESAdo/OdbcKingbaseESAdo.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESAdo/OdbcKingbaseESConnectionPool.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESCodeFirst.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESDbFirst.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESExpression.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESProvider.cs delete mode 100644 Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESUtils.cs diff --git a/Extensions/FreeSql.Extensions.ZeroEntity/ZeroDbContext.SelectImpl.cs b/Extensions/FreeSql.Extensions.ZeroEntity/ZeroDbContext.SelectImpl.cs index 3f70407bc..aee96eb7a 100644 --- a/Extensions/FreeSql.Extensions.ZeroEntity/ZeroDbContext.SelectImpl.cs +++ b/Extensions/FreeSql.Extensions.ZeroEntity/ZeroDbContext.SelectImpl.cs @@ -750,7 +750,6 @@ public SelectImpl WhereExists(Func q) case DataType.OdbcOracle: case DataType.CustomOracle: case DataType.Dameng: - case DataType.OdbcDameng: case DataType.GBase: query.Limit(-1); break; diff --git a/Extensions/FreeSql.Extensions.ZeroEntity/ZeroDbContext.cs b/Extensions/FreeSql.Extensions.ZeroEntity/ZeroDbContext.cs index 2dbd8540e..550a99108 100644 --- a/Extensions/FreeSql.Extensions.ZeroEntity/ZeroDbContext.cs +++ b/Extensions/FreeSql.Extensions.ZeroEntity/ZeroDbContext.cs @@ -702,7 +702,6 @@ void LocalAdd(TableInfo table, T data, bool isCheck, ColumnInfo[] _tableReturnCo case DataType.OdbcPostgreSQL: case DataType.CustomPostgreSQL: case DataType.KingbaseES: - case DataType.OdbcKingbaseES: case DataType.ShenTong: case DataType.Firebird: //firebird 只支持单条插入 returning if (_tableIdentitys.Length == 1 && _tableReturnColumns.Length == 1) @@ -758,7 +757,6 @@ void LocalAddRange(TableInfo table, IEnumerable data) case DataType.OdbcPostgreSQL: case DataType.CustomPostgreSQL: case DataType.KingbaseES: - case DataType.OdbcKingbaseES: case DataType.ShenTong: var rets = OrmInsert(table).AppendData(data).ExecuteInserted(); _cascadeAffrows += rets.Count; @@ -811,7 +809,6 @@ bool LocalCanAdd(TableInfo table, T data, bool isThrow) case DataType.OdbcPostgreSQL: case DataType.CustomPostgreSQL: case DataType.KingbaseES: - case DataType.OdbcKingbaseES: case DataType.ShenTong: case DataType.ClickHouse: return true; diff --git a/Extensions/FreeSql.Generator/RazorModel.cs b/Extensions/FreeSql.Generator/RazorModel.cs index 7f181fd75..f2bba05c0 100644 --- a/Extensions/FreeSql.Generator/RazorModel.cs +++ b/Extensions/FreeSql.Generator/RazorModel.cs @@ -132,7 +132,6 @@ public string GetColumnAttribute(DbColumnInfo col, bool isInsertValueSql = false case DataType.PostgreSQL: case DataType.OdbcPostgreSQL: case DataType.KingbaseES: - case DataType.OdbcKingbaseES: case DataType.ShenTong: switch (col.DbTypeTextFull.ToLower()) { @@ -157,7 +156,6 @@ public string GetColumnAttribute(DbColumnInfo col, bool isInsertValueSql = false } break; case DataType.Dameng: - case DataType.OdbcDameng: switch (col.DbTypeTextFull.ToLower()) { case "text": sb.Add("StringLength = -2"); break; @@ -245,7 +243,7 @@ public string GetColumnDefaultValue(DbColumnInfo col, bool isInsertValueSql) if ((cstype == typeof(string) && defval.StartsWith("'") && defval.EndsWith("'::character varying") || cstype == typeof(Guid) && defval.StartsWith("'") && defval.EndsWith("'::uuid") ) && (fsql.Ado.DataType == DataType.PostgreSQL || fsql.Ado.DataType == DataType.OdbcPostgreSQL || - fsql.Ado.DataType == DataType.KingbaseES || fsql.Ado.DataType == DataType.OdbcKingbaseES || + fsql.Ado.DataType == DataType.KingbaseES || fsql.Ado.DataType == DataType.ShenTong)) { defval = defval.Substring(1, defval.LastIndexOf("'::") - 1).Replace("''", "'"); diff --git a/FreeSql.DbContext/DbSet/DbSet.cs b/FreeSql.DbContext/DbSet/DbSet.cs index e5548c7c5..5ac51506c 100644 --- a/FreeSql.DbContext/DbSet/DbSet.cs +++ b/FreeSql.DbContext/DbSet/DbSet.cs @@ -354,7 +354,6 @@ bool CanAdd(TEntity data, bool isThrow) case DataType.OdbcPostgreSQL: case DataType.CustomPostgreSQL: case DataType.KingbaseES: - case DataType.OdbcKingbaseES: case DataType.ShenTong: case DataType.ClickHouse: return true; diff --git a/FreeSql.DbContext/DbSet/DbSetAsync.cs b/FreeSql.DbContext/DbSet/DbSetAsync.cs index f9a9534ab..53eee5305 100644 --- a/FreeSql.DbContext/DbSet/DbSetAsync.cs +++ b/FreeSql.DbContext/DbSet/DbSetAsync.cs @@ -46,7 +46,6 @@ async Task AddPrivAsync(TEntity data, bool isCheck, CancellationToken cancellati case DataType.OdbcPostgreSQL: case DataType.CustomPostgreSQL: case DataType.KingbaseES: - case DataType.OdbcKingbaseES: case DataType.ShenTong: case DataType.Firebird: //firebird 只支持单条插入 returning if (_tableIdentitys.Length == 1 && _tableReturnColumns.Length == 1) @@ -115,7 +114,6 @@ async public Task AddRangeAsync(IEnumerable data, CancellationToken can case DataType.OdbcPostgreSQL: case DataType.CustomPostgreSQL: case DataType.KingbaseES: - case DataType.OdbcKingbaseES: case DataType.ShenTong: await DbContextFlushCommandAsync(cancellationToken); var rets = await this.OrmInsert(data).ExecuteInsertedAsync(cancellationToken); diff --git a/FreeSql.DbContext/DbSet/DbSetSync.cs b/FreeSql.DbContext/DbSet/DbSetSync.cs index 49b0f67d6..c0fc29211 100644 --- a/FreeSql.DbContext/DbSet/DbSetSync.cs +++ b/FreeSql.DbContext/DbSet/DbSetSync.cs @@ -45,7 +45,6 @@ void AddPriv(TEntity data, bool isCheck) case DataType.OdbcPostgreSQL: case DataType.CustomPostgreSQL: case DataType.KingbaseES: - case DataType.OdbcKingbaseES: case DataType.ShenTong: case DataType.Firebird: //firebird 只支持单条插入 returning if (_tableIdentitys.Length == 1 && _tableReturnColumns.Length == 1) @@ -118,7 +117,6 @@ public void AddRange(IEnumerable data) case DataType.OdbcPostgreSQL: case DataType.CustomPostgreSQL: case DataType.KingbaseES: - case DataType.OdbcKingbaseES: case DataType.ShenTong: DbContextFlushCommand(); var rets = this.OrmInsert(data).ExecuteInserted(); diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengDeleteTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengDeleteTest.cs deleted file mode 100644 index d83e78eec..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengDeleteTest.cs +++ /dev/null @@ -1,106 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.Dameng -{ - public class DamengDeleteTest - { - - IDelete delete => g.dameng.Delete(); //�������� - - [Table(Name = "tb_topic22211")] - class Topic - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int? Clicks { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - - [Fact] - public void Dywhere() - { - Assert.Null(g.dameng.Delete().ToSql()); - var sql = g.dameng.Delete(new[] { 1, 2 }).ToSql(); - Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" IN (1,2))", sql); - - sql = g.dameng.Delete(new Topic { Id = 1, Title = "test" }).ToSql(); - Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" = 1)", sql); - - sql = g.dameng.Delete(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).ToSql(); - Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" IN (1,2))", sql); - - sql = g.dameng.Delete(new { id = 1 }).ToSql(); - Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" = 1)", sql); - - sql = g.dameng.Delete(new[] { new { Id1 = 1, Id2 = 10 }, new { Id1 = 2, Id2 = 20 } }).ToSql(); - Assert.Equal("DELETE FROM \"MULTIPKTOPIC\" WHERE (\"ID1\" = 1 AND \"ID2\" = 10 OR \"ID1\" = 2 AND \"ID2\" = 20)", sql); - } - class MultiPkTopic - { - [Column(IsPrimary = true)] - public int Id1 { get; set; } - [Column(IsPrimary = true)] - public int Id2 { get; set; } - public int Clicks { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - - [Fact] - public void Where() - { - var sql = delete.Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" = 1)", sql); - - sql = delete.Where("id = :id", new { id = 1 }).ToSql().Replace("\r\n", ""); - Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (id = :id)", sql); - - var item = new Topic { Id = 1, Title = "newtitle" }; - sql = delete.Where(item).ToSql().Replace("\r\n", ""); - Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" = 1)", sql); - - var items = new List(); - for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 }); - - sql = delete.Where(items).ToSql().Replace("\r\n", ""); - Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" IN (1,2,3,4,5,6,7,8,9,10))", sql); - } - [Fact] - public void ExecuteAffrows() - { - - var id = g.dameng.Insert(new Topic { Title = "xxxx", CreateTime = DateTime.Now }).ExecuteIdentity(); - Assert.Equal(1, delete.Where(a => a.Id == id).ExecuteAffrows()); - } - [Fact] - public void ExecuteDeleted() - { - - //var item = g.dameng.Insert(new Topic { Title = "xxxx", CreateTime = DateTime.Now }).ExecuteInserted(); - //Assert.Equal(item[0].Id, delete.Where(a => a.Id == item[0].Id).ExecuteDeleted()[0].Id); - } - - [Fact] - public void AsTable() - { - Assert.Null(g.dameng.Delete().ToSql()); - var sql = g.dameng.Delete(new[] { 1, 2 }).AsTable(a => "TopicAsTable").ToSql(); - Assert.Equal("DELETE FROM \"TOPICASTABLE\" WHERE (\"ID\" IN (1,2))", sql); - - sql = g.dameng.Delete(new Topic { Id = 1, Title = "test" }).AsTable(a => "TopicAsTable").ToSql(); - Assert.Equal("DELETE FROM \"TOPICASTABLE\" WHERE (\"ID\" = 1)", sql); - - sql = g.dameng.Delete(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).AsTable(a => "TopicAsTable").ToSql(); - Assert.Equal("DELETE FROM \"TOPICASTABLE\" WHERE (\"ID\" IN (1,2))", sql); - - sql = g.dameng.Delete(new { id = 1 }).AsTable(a => "TopicAsTable").ToSql(); - Assert.Equal("DELETE FROM \"TOPICASTABLE\" WHERE (\"ID\" = 1)", sql); - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengInsertOrUpdateIfExistsNothingTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengInsertOrUpdateIfExistsNothingTest.cs deleted file mode 100644 index e151e4b23..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengInsertOrUpdateIfExistsNothingTest.cs +++ /dev/null @@ -1,425 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.Dameng -{ - public class DamengInsertOrUpdateIfExistsNothingTest - { - IFreeSql fsql => g.dameng; - - [Fact] - public void InsertOrUpdate_OnlyPrimary() - { - fsql.Delete().Where("1=1").ExecuteAffrows(); - var iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudn01 { id = 1 }); - var sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN01"" t1 -USING (SELECT 1 as ""ID"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"") - values (t2.""ID"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudn01 { id = 1 }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN01"" t1 -USING (SELECT 1 as ""ID"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"") - values (t2.""ID"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudn01 { id = 2 }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN01"" t1 -USING (SELECT 2 as ""ID"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"") - values (t2.""ID"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudn01 { id = 1 }, new tbioudn01 { id = 2 }, new tbioudn01 { id = 3 }, new tbioudn01 { id = 4 } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN01"" t1 -USING (SELECT 1 as ""ID"" FROM dual -UNION ALL - SELECT 2 FROM dual -UNION ALL - SELECT 3 FROM dual -UNION ALL - SELECT 4 FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"") - values (t2.""ID"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudn01 { id = 1 }, new tbioudn01 { id = 2 }, new tbioudn01 { id = 3 }, new tbioudn01 { id = 4 } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN01"" t1 -USING (SELECT 1 as ""ID"" FROM dual -UNION ALL - SELECT 2 FROM dual -UNION ALL - SELECT 3 FROM dual -UNION ALL - SELECT 4 FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"") - values (t2.""ID"")", sql); - iou.ExecuteAffrows(); - } - class tbioudn01 - { - public int id { get; set; } - } - - [Fact] - public void InsertOrUpdate_OnePrimary() - { - fsql.Delete().Where("1=1").ExecuteAffrows(); - var iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudn02 { id = 1, name = "01" }); - var sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN02"" t1 -USING (SELECT 1 as ""ID"", '01' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudn02 { id = 1, name = "011" }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN02"" t1 -USING (SELECT 1 as ""ID"", '011' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudn02 { id = 2, name = "02" }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN02"" t1 -USING (SELECT 2 as ""ID"", '02' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudn02 { id = 1, name = "01" }, new tbioudn02 { id = 2, name = "02" }, new tbioudn02 { id = 3, name = "03" }, new tbioudn02 { id = 4, name = "04" } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN02"" t1 -USING (SELECT 1 as ""ID"", '01' as ""NAME"" FROM dual -UNION ALL - SELECT 2, '02' FROM dual -UNION ALL - SELECT 3, '03' FROM dual -UNION ALL - SELECT 4, '04' FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudn02 { id = 1, name = "001" }, new tbioudn02 { id = 2, name = "002" }, new tbioudn02 { id = 3, name = "003" }, new tbioudn02 { id = 4, name = "004" } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN02"" t1 -USING (SELECT 1 as ""ID"", '001' as ""NAME"" FROM dual -UNION ALL - SELECT 2, '002' FROM dual -UNION ALL - SELECT 3, '003' FROM dual -UNION ALL - SELECT 4, '004' FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - var lst = fsql.Select().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList(); - Assert.Equal(4, lst.Where(a => a.name == "0" + a.id).Count()); - } - class tbioudn02 - { - public int id { get; set; } - public string name { get; set; } - } - [Fact] - public void InsertOrUpdate_OnePrimaryAndIdentity() - { - fsql.Delete().Where("1=1").ExecuteAffrows(); - var iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudn022 { id = 1, name = "01" }); - var sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN022"" t1 -USING (SELECT 1 as ""ID"", '01' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudn022 { id = 1, name = "011" }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN022"" t1 -USING (SELECT 1 as ""ID"", '011' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudn022 { id = 2, name = "02" }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN022"" t1 -USING (SELECT 2 as ""ID"", '02' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudn022 { id = 1, name = "01" }, new tbioudn022 { id = 2, name = "02" }, new tbioudn022 { id = 3, name = "03" }, new tbioudn022 { id = 4, name = "04" } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN022"" t1 -USING (SELECT 1 as ""ID"", '01' as ""NAME"" FROM dual -UNION ALL - SELECT 2, '02' FROM dual -UNION ALL - SELECT 3, '03' FROM dual -UNION ALL - SELECT 4, '04' FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudn022 { id = 1, name = "001" }, new tbioudn022 { id = 2, name = "002" }, new tbioudn022 { id = 3, name = "003" }, new tbioudn022 { id = 4, name = "004" } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN022"" t1 -USING (SELECT 1 as ""ID"", '001' as ""NAME"" FROM dual -UNION ALL - SELECT 2, '002' FROM dual -UNION ALL - SELECT 3, '003' FROM dual -UNION ALL - SELECT 4, '004' FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - var lst = fsql.Select().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList(); - //Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count()); - - //--no primary - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudn022 { name = "01" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDN022""(""NAME"") VALUES('01')", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudn022 { name = "011" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDN022""(""NAME"") VALUES('011')", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudn022 { name = "02" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDN022""(""NAME"") VALUES('02')", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudn022 { name = "01" }, new tbioudn022 { name = "02" }, new tbioudn022 { name = "03" }, new tbioudn022 { name = "04" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT ALL -INTO ""TBIOUDN022""(""NAME"") VALUES('01') -INTO ""TBIOUDN022""(""NAME"") VALUES('02') -INTO ""TBIOUDN022""(""NAME"") VALUES('03') -INTO ""TBIOUDN022""(""NAME"") VALUES('04') - SELECT 1 FROM DUAL", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudn022 { name = "001" }, new tbioudn022 { name = "002" }, new tbioudn022 { name = "003" }, new tbioudn022 { name = "004" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT ALL -INTO ""TBIOUDN022""(""NAME"") VALUES('001') -INTO ""TBIOUDN022""(""NAME"") VALUES('002') -INTO ""TBIOUDN022""(""NAME"") VALUES('003') -INTO ""TBIOUDN022""(""NAME"") VALUES('004') - SELECT 1 FROM DUAL", sql); - iou.ExecuteAffrows(); - - //--no primary and yes - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudn022 { id = 1, name = "100001" }, new tbioudn022 { name = "00001" }, new tbioudn022 { id = 2, name = "100002" }, new tbioudn022 { name = "00002" }, new tbioudn022 { id = 3, name = "100003" }, new tbioudn022 { name = "00003" }, new tbioudn022 { id = 4, name = "100004" }, new tbioudn022 { name = "00004" } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN022"" t1 -USING (SELECT 1 as ""ID"", '100001' as ""NAME"" FROM dual -UNION ALL - SELECT 2, '100002' FROM dual -UNION ALL - SELECT 3, '100003' FROM dual -UNION ALL - SELECT 4, '100004' FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"") - -; - -INSERT ALL -INTO ""TBIOUDN022""(""NAME"") VALUES('00001') -INTO ""TBIOUDN022""(""NAME"") VALUES('00002') -INTO ""TBIOUDN022""(""NAME"") VALUES('00003') -INTO ""TBIOUDN022""(""NAME"") VALUES('00004') - SELECT 1 FROM DUAL", sql); - iou.ExecuteAffrows(); - lst = fsql.Select().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList(); - //Assert.Equal(4, lst.Where(a => a.name == "10000" + a.id).Count()); - } - class tbioudn022 - { - [Column(IsIdentity = true)] - public int id { get; set; } - public string name { get; set; } - } - - [Fact] - public void InsertOrUpdate_TwoPrimary() - { - fsql.Delete().Where("1=1").ExecuteAffrows(); - var iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudn03 { id1 = 1, id2 = "01", name = "01" }); - var sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN03"" t1 -USING (SELECT 1 as ""ID1"", '01' as ""ID2"", '01' as ""NAME"" FROM dual ) t2 ON (t1.""ID1"" = t2.""ID1"" AND t1.""ID2"" = t2.""ID2"") -WHEN NOT MATCHED THEN - insert (""ID1"", ""ID2"", ""NAME"") - values (t2.""ID1"", t2.""ID2"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudn03 { id1 = 1, id2 = "02", name = "011" }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN03"" t1 -USING (SELECT 1 as ""ID1"", '02' as ""ID2"", '011' as ""NAME"" FROM dual ) t2 ON (t1.""ID1"" = t2.""ID1"" AND t1.""ID2"" = t2.""ID2"") -WHEN NOT MATCHED THEN - insert (""ID1"", ""ID2"", ""NAME"") - values (t2.""ID1"", t2.""ID2"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudn03 { id1 = 2, id2 = "02", name = "02" }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN03"" t1 -USING (SELECT 2 as ""ID1"", '02' as ""ID2"", '02' as ""NAME"" FROM dual ) t2 ON (t1.""ID1"" = t2.""ID1"" AND t1.""ID2"" = t2.""ID2"") -WHEN NOT MATCHED THEN - insert (""ID1"", ""ID2"", ""NAME"") - values (t2.""ID1"", t2.""ID2"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudn03 { id1 = 1, id2 = "01", name = "01" }, new tbioudn03 { id1 = 2, id2 = "02", name = "02" }, new tbioudn03 { id1 = 3, id2 = "03", name = "03" }, new tbioudn03 { id1 = 4, id2 = "04", name = "04" } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN03"" t1 -USING (SELECT 1 as ""ID1"", '01' as ""ID2"", '01' as ""NAME"" FROM dual -UNION ALL - SELECT 2, '02', '02' FROM dual -UNION ALL - SELECT 3, '03', '03' FROM dual -UNION ALL - SELECT 4, '04', '04' FROM dual ) t2 ON (t1.""ID1"" = t2.""ID1"" AND t1.""ID2"" = t2.""ID2"") -WHEN NOT MATCHED THEN - insert (""ID1"", ""ID2"", ""NAME"") - values (t2.""ID1"", t2.""ID2"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudn03 { id1 = 1, id2 = "01", name = "001" }, new tbioudn03 { id1 = 2, id2 = "02", name = "002" }, new tbioudn03 { id1 = 3, id2 = "03", name = "003" }, new tbioudn03 { id1 = 4, id2 = "04", name = "004" } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN03"" t1 -USING (SELECT 1 as ""ID1"", '01' as ""ID2"", '001' as ""NAME"" FROM dual -UNION ALL - SELECT 2, '02', '002' FROM dual -UNION ALL - SELECT 3, '03', '003' FROM dual -UNION ALL - SELECT 4, '04', '004' FROM dual ) t2 ON (t1.""ID1"" = t2.""ID1"" AND t1.""ID2"" = t2.""ID2"") -WHEN NOT MATCHED THEN - insert (""ID1"", ""ID2"", ""NAME"") - values (t2.""ID1"", t2.""ID2"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - var lst = fsql.Select().Where(a => a.id1 == 1 && a.id2 == "01" || a.id1 == 2 && a.id2 == "02" || a.id1 == 3 && a.id2 == "03" || a.id1 == 4 && a.id2 == "04").ToList(); - Assert.Equal(4, lst.Where(a => a.name == "0" + a.id1).Count()); - } - class tbioudn03 - { - [Column(IsPrimary = true)] - public int id1 { get; set; } - [Column(IsPrimary = true)] - public string id2 { get; set; } - public string name { get; set; } - } - - [Fact] - public void InsertOrUpdate_OnePrimaryAndVersionAndCanUpdate() - { - fsql.Delete().Where("1=1").ExecuteAffrows(); - var iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudn04 { id = 1, name = "01" }); - var sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN04"" t1 -USING (SELECT 1 as ""ID"", '01' as ""NAME"", 0 as ""VERSION"", systimestamp as ""CREATETIME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"", ""VERSION"", ""CREATETIME"") - values (t2.""ID"", t2.""NAME"", t2.""VERSION"", t2.""CREATETIME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudn04 { id = 1, name = "011" }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN04"" t1 -USING (SELECT 1 as ""ID"", '011' as ""NAME"", 0 as ""VERSION"", systimestamp as ""CREATETIME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"", ""VERSION"", ""CREATETIME"") - values (t2.""ID"", t2.""NAME"", t2.""VERSION"", t2.""CREATETIME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudn04 { id = 2, name = "02" }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN04"" t1 -USING (SELECT 2 as ""ID"", '02' as ""NAME"", 0 as ""VERSION"", systimestamp as ""CREATETIME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"", ""VERSION"", ""CREATETIME"") - values (t2.""ID"", t2.""NAME"", t2.""VERSION"", t2.""CREATETIME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudn04 { id = 1, name = "01" }, new tbioudn04 { id = 2, name = "02" }, new tbioudn04 { id = 3, name = "03" }, new tbioudn04 { id = 4, name = "04" } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN04"" t1 -USING (SELECT 1 as ""ID"", '01' as ""NAME"", 0 as ""VERSION"", systimestamp as ""CREATETIME"" FROM dual -UNION ALL - SELECT 2, '02', 0, systimestamp FROM dual -UNION ALL - SELECT 3, '03', 0, systimestamp FROM dual -UNION ALL - SELECT 4, '04', 0, systimestamp FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"", ""VERSION"", ""CREATETIME"") - values (t2.""ID"", t2.""NAME"", t2.""VERSION"", t2.""CREATETIME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudn04 { id = 1, name = "001" }, new tbioudn04 { id = 2, name = "002" }, new tbioudn04 { id = 3, name = "003" }, new tbioudn04 { id = 4, name = "004" } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOUDN04"" t1 -USING (SELECT 1 as ""ID"", '001' as ""NAME"", 0 as ""VERSION"", systimestamp as ""CREATETIME"" FROM dual -UNION ALL - SELECT 2, '002', 0, systimestamp FROM dual -UNION ALL - SELECT 3, '003', 0, systimestamp FROM dual -UNION ALL - SELECT 4, '004', 0, systimestamp FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"", ""VERSION"", ""CREATETIME"") - values (t2.""ID"", t2.""NAME"", t2.""VERSION"", t2.""CREATETIME"")", sql); - iou.ExecuteAffrows(); - var lst = fsql.Select().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList(); - Assert.Equal(4, lst.Where(a => a.name == "0" + a.id).Count()); - } - class tbioudn04 - { - public int id { get; set; } - public string name { get; set; } - [Column(IsVersion = true)] - public int version { get; set; } - [Column(CanUpdate = false, ServerTime = DateTimeKind.Local)] - public DateTime CreateTime { get; set; } - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengInsertOrUpdateTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengInsertOrUpdateTest.cs deleted file mode 100644 index 41c5cba88..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengInsertOrUpdateTest.cs +++ /dev/null @@ -1,467 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.Dameng -{ - public class DamengInsertOrUpdateTest - { - IFreeSql fsql => g.dameng; - - [Fact] - public void InsertOrUpdate_OnlyPrimary() - { - fsql.Delete().Where("1=1").ExecuteAffrows(); - var iou = fsql.InsertOrUpdate().SetSource(new tbiou01 { id = 1 }); - var sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU01"" t1 -USING (SELECT 1 as ""ID"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"") - values (t2.""ID"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new tbiou01 { id = 1 }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU01"" t1 -USING (SELECT 1 as ""ID"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"") - values (t2.""ID"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new tbiou01 { id = 2 }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU01"" t1 -USING (SELECT 2 as ""ID"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"") - values (t2.""ID"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou01 { id = 1 }, new tbiou01 { id = 2 }, new tbiou01 { id = 3 }, new tbiou01 { id = 4 } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU01"" t1 -USING (SELECT 1 as ""ID"" FROM dual -UNION ALL - SELECT 2 FROM dual -UNION ALL - SELECT 3 FROM dual -UNION ALL - SELECT 4 FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"") - values (t2.""ID"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou01 { id = 1 }, new tbiou01 { id = 2 }, new tbiou01 { id = 3 }, new tbiou01 { id = 4 } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU01"" t1 -USING (SELECT 1 as ""ID"" FROM dual -UNION ALL - SELECT 2 FROM dual -UNION ALL - SELECT 3 FROM dual -UNION ALL - SELECT 4 FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN NOT MATCHED THEN - insert (""ID"") - values (t2.""ID"")", sql); - iou.ExecuteAffrows(); - } - class tbiou01 - { - public int id { get; set; } - } - - [Fact] - public void InsertOrUpdate_OnePrimary() - { - fsql.Delete().Where("1=1").ExecuteAffrows(); - var iou = fsql.InsertOrUpdate().SetSource(new tbiou02 { id = 1, name = "01" }); - var sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU02"" t1 -USING (SELECT 1 as ""ID"", '01' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"" -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new tbiou02 { id = 1, name = "011" }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU02"" t1 -USING (SELECT 1 as ""ID"", '011' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"" -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new tbiou02 { id = 2, name = "02" }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU02"" t1 -USING (SELECT 2 as ""ID"", '02' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"" -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou02 { id = 1, name = "01" }, new tbiou02 { id = 2, name = "02" }, new tbiou02 { id = 3, name = "03" }, new tbiou02 { id = 4, name = "04" } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU02"" t1 -USING (SELECT 1 as ""ID"", '01' as ""NAME"" FROM dual -UNION ALL - SELECT 2, '02' FROM dual -UNION ALL - SELECT 3, '03' FROM dual -UNION ALL - SELECT 4, '04' FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"" -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou02 { id = 1, name = "001" }, new tbiou02 { id = 2, name = "002" }, new tbiou02 { id = 3, name = "003" }, new tbiou02 { id = 4, name = "004" } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU02"" t1 -USING (SELECT 1 as ""ID"", '001' as ""NAME"" FROM dual -UNION ALL - SELECT 2, '002' FROM dual -UNION ALL - SELECT 3, '003' FROM dual -UNION ALL - SELECT 4, '004' FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"" -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - var lst = fsql.Select().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList(); - Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count()); - } - class tbiou02 - { - public int id { get; set; } - public string name { get; set; } - } - [Fact] - public void InsertOrUpdate_OnePrimaryAndIdentity() - { - fsql.Delete().Where("1=1").ExecuteAffrows(); - var iou = fsql.InsertOrUpdate().SetSource(new tbiou022 { id = 1, name = "01" }); - var sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU022"" t1 -USING (SELECT 1 as ""ID"", '01' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"" -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new tbiou022 { id = 1, name = "011" }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU022"" t1 -USING (SELECT 1 as ""ID"", '011' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"" -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new tbiou022 { id = 2, name = "02" }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU022"" t1 -USING (SELECT 2 as ""ID"", '02' as ""NAME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"" -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou022 { id = 1, name = "01" }, new tbiou022 { id = 2, name = "02" }, new tbiou022 { id = 3, name = "03" }, new tbiou022 { id = 4, name = "04" } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU022"" t1 -USING (SELECT 1 as ""ID"", '01' as ""NAME"" FROM dual -UNION ALL - SELECT 2, '02' FROM dual -UNION ALL - SELECT 3, '03' FROM dual -UNION ALL - SELECT 4, '04' FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"" -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou022 { id = 1, name = "001" }, new tbiou022 { id = 2, name = "002" }, new tbiou022 { id = 3, name = "003" }, new tbiou022 { id = 4, name = "004" } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU022"" t1 -USING (SELECT 1 as ""ID"", '001' as ""NAME"" FROM dual -UNION ALL - SELECT 2, '002' FROM dual -UNION ALL - SELECT 3, '003' FROM dual -UNION ALL - SELECT 4, '004' FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"" -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - var lst = fsql.Select().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList(); - //Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count()); - - //--no primary - iou = fsql.InsertOrUpdate().SetSource(new tbiou022 { name = "01" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU022""(""NAME"") VALUES('01')", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new tbiou022 { name = "011" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU022""(""NAME"") VALUES('011')", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new tbiou022 { name = "02" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU022""(""NAME"") VALUES('02')", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou022 { name = "01" }, new tbiou022 { name = "02" }, new tbiou022 { name = "03" }, new tbiou022 { name = "04" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT ALL -INTO ""TBIOU022""(""NAME"") VALUES('01') -INTO ""TBIOU022""(""NAME"") VALUES('02') -INTO ""TBIOU022""(""NAME"") VALUES('03') -INTO ""TBIOU022""(""NAME"") VALUES('04') - SELECT 1 FROM DUAL", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou022 { name = "001" }, new tbiou022 { name = "002" }, new tbiou022 { name = "003" }, new tbiou022 { name = "004" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT ALL -INTO ""TBIOU022""(""NAME"") VALUES('001') -INTO ""TBIOU022""(""NAME"") VALUES('002') -INTO ""TBIOU022""(""NAME"") VALUES('003') -INTO ""TBIOU022""(""NAME"") VALUES('004') - SELECT 1 FROM DUAL", sql); - iou.ExecuteAffrows(); - - //--no primary and yes - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou022 { id = 1, name = "100001" }, new tbiou022 { name = "00001" }, new tbiou022 { id = 2, name = "100002" }, new tbiou022 { name = "00002" }, new tbiou022 { id = 3, name = "100003" }, new tbiou022 { name = "00003" }, new tbiou022 { id = 4, name = "100004" }, new tbiou022 { name = "00004" } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU022"" t1 -USING (SELECT 1 as ""ID"", '100001' as ""NAME"" FROM dual -UNION ALL - SELECT 2, '100002' FROM dual -UNION ALL - SELECT 3, '100003' FROM dual -UNION ALL - SELECT 4, '100004' FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"" -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"") - values (t2.""ID"", t2.""NAME"") - -; - -INSERT ALL -INTO ""TBIOU022""(""NAME"") VALUES('00001') -INTO ""TBIOU022""(""NAME"") VALUES('00002') -INTO ""TBIOU022""(""NAME"") VALUES('00003') -INTO ""TBIOU022""(""NAME"") VALUES('00004') - SELECT 1 FROM DUAL", sql); - iou.ExecuteAffrows(); - lst = fsql.Select().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList(); - //Assert.Equal(4, lst.Where(a => a.name == "10000" + a.id).Count()); - } - class tbiou022 - { - [Column(IsIdentity = true)] - public int id { get; set; } - public string name { get; set; } - } - - [Fact] - public void InsertOrUpdate_TwoPrimary() - { - fsql.Delete().Where("1=1").ExecuteAffrows(); - var iou = fsql.InsertOrUpdate().SetSource(new tbiou03 { id1 = 1, id2 = "01", name = "01" }); - var sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU03"" t1 -USING (SELECT 1 as ""ID1"", '01' as ""ID2"", '01' as ""NAME"" FROM dual ) t2 ON (t1.""ID1"" = t2.""ID1"" AND t1.""ID2"" = t2.""ID2"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"" -WHEN NOT MATCHED THEN - insert (""ID1"", ""ID2"", ""NAME"") - values (t2.""ID1"", t2.""ID2"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new tbiou03 { id1 = 1, id2 = "01", name = "011" }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU03"" t1 -USING (SELECT 1 as ""ID1"", '01' as ""ID2"", '011' as ""NAME"" FROM dual ) t2 ON (t1.""ID1"" = t2.""ID1"" AND t1.""ID2"" = t2.""ID2"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"" -WHEN NOT MATCHED THEN - insert (""ID1"", ""ID2"", ""NAME"") - values (t2.""ID1"", t2.""ID2"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new tbiou03 { id1 = 2, id2 = "02", name = "02" }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU03"" t1 -USING (SELECT 2 as ""ID1"", '02' as ""ID2"", '02' as ""NAME"" FROM dual ) t2 ON (t1.""ID1"" = t2.""ID1"" AND t1.""ID2"" = t2.""ID2"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"" -WHEN NOT MATCHED THEN - insert (""ID1"", ""ID2"", ""NAME"") - values (t2.""ID1"", t2.""ID2"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou03 { id1 = 1, id2 = "01", name = "01" }, new tbiou03 { id1 = 2, id2 = "02", name = "02" }, new tbiou03 { id1 = 3, id2 = "03", name = "03" }, new tbiou03 { id1 = 4, id2 = "04", name = "04" } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU03"" t1 -USING (SELECT 1 as ""ID1"", '01' as ""ID2"", '01' as ""NAME"" FROM dual -UNION ALL - SELECT 2, '02', '02' FROM dual -UNION ALL - SELECT 3, '03', '03' FROM dual -UNION ALL - SELECT 4, '04', '04' FROM dual ) t2 ON (t1.""ID1"" = t2.""ID1"" AND t1.""ID2"" = t2.""ID2"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"" -WHEN NOT MATCHED THEN - insert (""ID1"", ""ID2"", ""NAME"") - values (t2.""ID1"", t2.""ID2"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou03 { id1 = 1, id2 = "01", name = "001" }, new tbiou03 { id1 = 2, id2 = "02", name = "002" }, new tbiou03 { id1 = 3, id2 = "03", name = "003" }, new tbiou03 { id1 = 4, id2 = "04", name = "004" } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU03"" t1 -USING (SELECT 1 as ""ID1"", '01' as ""ID2"", '001' as ""NAME"" FROM dual -UNION ALL - SELECT 2, '02', '002' FROM dual -UNION ALL - SELECT 3, '03', '003' FROM dual -UNION ALL - SELECT 4, '04', '004' FROM dual ) t2 ON (t1.""ID1"" = t2.""ID1"" AND t1.""ID2"" = t2.""ID2"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"" -WHEN NOT MATCHED THEN - insert (""ID1"", ""ID2"", ""NAME"") - values (t2.""ID1"", t2.""ID2"", t2.""NAME"")", sql); - iou.ExecuteAffrows(); - var lst = fsql.Select().Where(a => a.id1 == 1 && a.id2 == "01" || a.id1 == 2 && a.id2 == "02" || a.id1 == 3 && a.id2 == "03" || a.id1 == 4 && a.id2 == "04").ToList(); - Assert.Equal(4, lst.Where(a => a.name == "00" + a.id1).Count()); - } - class tbiou03 - { - [Column(IsPrimary = true)] - public int id1 { get; set; } - [Column(IsPrimary = true)] - public string id2 { get; set; } - public string name { get; set; } - } - - [Fact] - public void InsertOrUpdate_OnePrimaryAndVersionAndCanUpdate() - { - fsql.Delete().Where("1=1").ExecuteAffrows(); - var iou = fsql.InsertOrUpdate().SetSource(new tbiou04 { id = 1, name = "01" }); - var sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU04"" t1 -USING (SELECT 1 as ""ID"", '01' as ""NAME"", 0 as ""VERSION"", systimestamp as ""CREATETIME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"", ""VERSION"" = t1.""VERSION"" + 1 -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"", ""VERSION"", ""CREATETIME"") - values (t2.""ID"", t2.""NAME"", t2.""VERSION"", t2.""CREATETIME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new tbiou04 { id = 1, name = "011" }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU04"" t1 -USING (SELECT 1 as ""ID"", '011' as ""NAME"", 0 as ""VERSION"", systimestamp as ""CREATETIME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"", ""VERSION"" = t1.""VERSION"" + 1 -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"", ""VERSION"", ""CREATETIME"") - values (t2.""ID"", t2.""NAME"", t2.""VERSION"", t2.""CREATETIME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new tbiou04 { id = 2, name = "02" }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU04"" t1 -USING (SELECT 2 as ""ID"", '02' as ""NAME"", 0 as ""VERSION"", systimestamp as ""CREATETIME"" FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"", ""VERSION"" = t1.""VERSION"" + 1 -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"", ""VERSION"", ""CREATETIME"") - values (t2.""ID"", t2.""NAME"", t2.""VERSION"", t2.""CREATETIME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou04 { id = 1, name = "01" }, new tbiou04 { id = 2, name = "02" }, new tbiou04 { id = 3, name = "03" }, new tbiou04 { id = 4, name = "04" } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU04"" t1 -USING (SELECT 1 as ""ID"", '01' as ""NAME"", 0 as ""VERSION"", systimestamp as ""CREATETIME"" FROM dual -UNION ALL - SELECT 2, '02', 0, systimestamp FROM dual -UNION ALL - SELECT 3, '03', 0, systimestamp FROM dual -UNION ALL - SELECT 4, '04', 0, systimestamp FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"", ""VERSION"" = t1.""VERSION"" + 1 -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"", ""VERSION"", ""CREATETIME"") - values (t2.""ID"", t2.""NAME"", t2.""VERSION"", t2.""CREATETIME"")", sql); - iou.ExecuteAffrows(); - - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou04 { id = 1, name = "001" }, new tbiou04 { id = 2, name = "002" }, new tbiou04 { id = 3, name = "003" }, new tbiou04 { id = 4, name = "004" } }); - sql = iou.ToSql(); - Assert.Equal(@"MERGE INTO ""TBIOU04"" t1 -USING (SELECT 1 as ""ID"", '001' as ""NAME"", 0 as ""VERSION"", systimestamp as ""CREATETIME"" FROM dual -UNION ALL - SELECT 2, '002', 0, systimestamp FROM dual -UNION ALL - SELECT 3, '003', 0, systimestamp FROM dual -UNION ALL - SELECT 4, '004', 0, systimestamp FROM dual ) t2 ON (t1.""ID"" = t2.""ID"") -WHEN MATCHED THEN - update set ""NAME"" = t2.""NAME"", ""VERSION"" = t1.""VERSION"" + 1 -WHEN NOT MATCHED THEN - insert (""ID"", ""NAME"", ""VERSION"", ""CREATETIME"") - values (t2.""ID"", t2.""NAME"", t2.""VERSION"", t2.""CREATETIME"")", sql); - iou.ExecuteAffrows(); - var lst = fsql.Select().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList(); - Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count()); - } - class tbiou04 - { - public int id { get; set; } - public string name { get; set; } - [Column(IsVersion = true)] - public int version { get; set; } - [Column(CanUpdate = false, ServerTime = DateTimeKind.Local)] - public DateTime CreateTime { get; set; } - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengInsertTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengInsertTest.cs deleted file mode 100644 index 0c2fedef4..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengInsertTest.cs +++ /dev/null @@ -1,278 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.Dameng -{ - public class DamengInsertTest - { - - IInsert insert => g.dameng.Insert(); //�������� - - [Table(Name = "tb_topic_insert")] - class Topic - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int? Clicks { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - - [Fact] - public void AppendData() - { - var items = new List(); - for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Parse("2019-09-19 22:25:38.697071") }); - - var data = new List(); - var sql = insert.AppendData(items.First()).ToSql(); - Assert.Equal("INSERT INTO \"TB_TOPIC_INSERT\"(\"CLICKS\", \"TITLE\", \"CREATETIME\") VALUES(0, 'newtitle0', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6'))", sql); - data.Add(insert.AppendData(items.First()).ExecuteIdentity()); - - sql = insert.AppendData(items).ToSql(); - Assert.Equal(@"INSERT ALL -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(0, 'newtitle0', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(100, 'newtitle1', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(200, 'newtitle2', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(300, 'newtitle3', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(400, 'newtitle4', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(500, 'newtitle5', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(600, 'newtitle6', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(700, 'newtitle7', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(800, 'newtitle8', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(900, 'newtitle9', to_timestamp('2019-09-19 22:25:38.697071','YYYY-MM-DD HH24:MI:SS.FF6')) - SELECT 1 FROM DUAL", sql); - data.Add(insert.AppendData(items.First()).ExecuteIdentity()); - - sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql(); - Assert.Equal(@"INSERT ALL -INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle0') -INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle1') -INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle2') -INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle3') -INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle4') -INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle5') -INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle6') -INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle7') -INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle8') -INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle9') - SELECT 1 FROM DUAL", sql); - data.Add(insert.AppendData(items.First()).ExecuteIdentity()); - - sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql(); - Assert.Equal(@"INSERT ALL -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(0, 'newtitle0') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(100, 'newtitle1') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(200, 'newtitle2') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(300, 'newtitle3') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(400, 'newtitle4') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(500, 'newtitle5') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(600, 'newtitle6') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(700, 'newtitle7') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(800, 'newtitle8') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(900, 'newtitle9') - SELECT 1 FROM DUAL", sql); - data.Add(insert.AppendData(items.First()).ExecuteIdentity()); - } - - [Fact] - public void InsertColumns() - { - var items = new List(); - for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now }); - - var data = new List(); - var sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql(); - Assert.Equal(@"INSERT ALL -INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle0') -INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle1') -INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle2') -INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle3') -INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle4') -INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle5') -INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle6') -INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle7') -INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle8') -INTO ""TB_TOPIC_INSERT""(""TITLE"") VALUES('newtitle9') - SELECT 1 FROM DUAL", sql); - data.Add(insert.AppendData(items.First()).ExecuteIdentity()); - - sql = insert.AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).ToSql(); - Assert.Equal(@"INSERT ALL -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(0, 'newtitle0') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(100, 'newtitle1') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(200, 'newtitle2') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(300, 'newtitle3') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(400, 'newtitle4') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(500, 'newtitle5') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(600, 'newtitle6') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(700, 'newtitle7') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(800, 'newtitle8') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(900, 'newtitle9') - SELECT 1 FROM DUAL", sql); - data.Add(insert.AppendData(items.First()).ExecuteIdentity()); - } - [Fact] - public void IgnoreColumns() - { - var items = new List(); - for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now }); - - var data = new List(); - var sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql(); - Assert.Equal(@"INSERT ALL -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(0, 'newtitle0') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(100, 'newtitle1') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(200, 'newtitle2') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(300, 'newtitle3') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(400, 'newtitle4') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(500, 'newtitle5') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(600, 'newtitle6') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(700, 'newtitle7') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(800, 'newtitle8') -INTO ""TB_TOPIC_INSERT""(""CLICKS"", ""TITLE"") VALUES(900, 'newtitle9') - SELECT 1 FROM DUAL", sql); - data.Add(insert.AppendData(items.First()).ExecuteIdentity()); - - sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).ToSql(); - Assert.Equal(@"INSERT ALL -INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(0) -INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(100) -INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(200) -INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(300) -INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(400) -INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(500) -INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(600) -INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(700) -INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(800) -INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(900) - SELECT 1 FROM DUAL", sql); - data.Add(insert.AppendData(items.First()).ExecuteIdentity()); - - g.dameng.Delete().Where("1=1").ExecuteAffrows(); - var itemsIgnore = new List(); - for (var a = 0; a < 2072; a++) itemsIgnore.Add(new TopicIgnore { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now }); - g.dameng.Insert().AppendData(itemsIgnore).IgnoreColumns(a => new { a.Title }).ExecuteAffrows(); - Assert.Equal(2072, itemsIgnore.Count); - Assert.Equal(2072, g.dameng.Select().Where(a => a.Title == null).Count()); - } - [Table(Name = "tb_topicICs")] - class TopicIgnore - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int Clicks { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - [Fact] - public void ExecuteAffrows() - { - var items = new List(); - for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now }); - - Assert.Equal(1, insert.AppendData(items.First()).ExecuteAffrows()); - Assert.Equal(10, insert.AppendData(items).ExecuteAffrows()); - } - [Fact] - public void ExecuteIdentity() - { - var items = new List(); - for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now }); - - Assert.NotEqual(0, insert.AppendData(items.First()).ExecuteIdentity()); - } - [Fact] - public void ExecuteInserted() - { - //var items = new List(); - //for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now }); - - //var items2 = insert.AppendData(items).ExecuteInserted(); - } - - [Fact] - public void AsTable() - { - var items = new List(); - for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newTitle{a}", Clicks = a * 100 }); - - var sql = insert.AppendData(items.First()).AsTable(a => "Topic_InsertAsTable").ToSql(); - Assert.Equal("INSERT INTO \"TOPIC_INSERTASTABLE\"(\"CLICKS\", \"TITLE\", \"CREATETIME\") VALUES(0, 'newTitle0', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'))", sql); - - sql = insert.AppendData(items).AsTable(a => "Topic_InsertAsTable").ToSql(); - Assert.Equal(@"INSERT ALL -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(0, 'newTitle0', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(100, 'newTitle1', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(200, 'newTitle2', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(300, 'newTitle3', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(400, 'newTitle4', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(500, 'newTitle5', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(600, 'newTitle6', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(700, 'newTitle7', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(800, 'newTitle8', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(900, 'newTitle9', to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) - SELECT 1 FROM DUAL", sql); - - sql = insert.AppendData(items).IgnoreColumns(a => a.Title).AsTable(a => "Topic_InsertAsTable").ToSql(); - Assert.Equal(@"INSERT ALL -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""CREATETIME"") VALUES(0, to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""CREATETIME"") VALUES(100, to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""CREATETIME"") VALUES(200, to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""CREATETIME"") VALUES(300, to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""CREATETIME"") VALUES(400, to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""CREATETIME"") VALUES(500, to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""CREATETIME"") VALUES(600, to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""CREATETIME"") VALUES(700, to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""CREATETIME"") VALUES(800, to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""CREATETIME"") VALUES(900, to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) - SELECT 1 FROM DUAL", sql); - - sql = insert.AppendData(items).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).AsTable(a => "Topic_InsertAsTable").ToSql(); - Assert.Equal(@"INSERT ALL -INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle0') -INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle1') -INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle2') -INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle3') -INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle4') -INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle5') -INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle6') -INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle7') -INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle8') -INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle9') - SELECT 1 FROM DUAL", sql); - - sql = insert.AppendData(items).InsertColumns(a => a.Title).AsTable(a => "Topic_InsertAsTable").ToSql(); - Assert.Equal(@"INSERT ALL -INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle0') -INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle1') -INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle2') -INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle3') -INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle4') -INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle5') -INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle6') -INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle7') -INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle8') -INTO ""TOPIC_INSERTASTABLE""(""TITLE"") VALUES('newTitle9') - SELECT 1 FROM DUAL", sql); - - sql = insert.AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).AsTable(a => "Topic_InsertAsTable").ToSql(); - Assert.Equal(@"INSERT ALL -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"") VALUES(0, 'newTitle0') -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"") VALUES(100, 'newTitle1') -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"") VALUES(200, 'newTitle2') -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"") VALUES(300, 'newTitle3') -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"") VALUES(400, 'newTitle4') -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"") VALUES(500, 'newTitle5') -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"") VALUES(600, 'newTitle6') -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"") VALUES(700, 'newTitle7') -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"") VALUES(800, 'newTitle8') -INTO ""TOPIC_INSERTASTABLE""(""CLICKS"", ""TITLE"") VALUES(900, 'newTitle9') - SELECT 1 FROM DUAL", sql); - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengSelectTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengSelectTest.cs deleted file mode 100644 index 47a822d3d..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengSelectTest.cs +++ /dev/null @@ -1,1880 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.Dameng -{ - public class DamengSelectTest - { - - ISelect select => g.dameng.Select(); - - [Table(Name = "tb_topic22")] - class Topic - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int Clicks { get; set; } - public int TypeGuid { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - class TestTypeInfo - { - [Column(IsIdentity = true)] - public int Guid { get; set; } - public int ParentId { get; set; } - public TestTypeParentInfo Parent { get; set; } - public string Name { get; set; } - } - class TestTypeParentInfo - { - public int Id { get; set; } - public string Name { get; set; } - - public List Types { get; set; } - } - - class TopicInserts - { - public Guid Id { get; set; } - public int Clicks { get; set; } - public int TypeGuid { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - public partial class Song - { - [Column(IsIdentity = true)] - public int Id { get; set; } - public DateTime? Create_time { get; set; } - public bool? Is_deleted { get; set; } - public string Title { get; set; } - public string Url { get; set; } - - public virtual ICollection Tags { get; set; } - } - public partial class Song_tag - { - public int Song_id { get; set; } - public virtual Song Song { get; set; } - - public int Tag_id { get; set; } - public virtual Tag Tag { get; set; } - } - public partial class Tag - { - [Column(IsIdentity = true)] - public int Id { get; set; } - public int? Parent_id { get; set; } - public virtual Tag Parent { get; set; } - - public decimal? Ddd { get; set; } - public string Name { get; set; } - - public virtual ICollection Songs { get; set; } - public virtual ICollection Tags { get; set; } - } - - [Fact] - public void AsSelect() - { - //OneToOne、ManyToOne - var t0 = g.dameng.Select().Where(a => a.Parent.Parent.Name == "粤语").ToSql(); - //SELECT a.`Id`, a.`Parent_id`, a__Parent.`Id` as3, a__Parent.`Parent_id` as4, a__Parent.`Ddd`, a__Parent.`Name`, a.`Ddd` as7, a.`Name` as8 - //FROM `Tag` a - //LEFT JOIN `Tag` a__Parent ON a__Parent.`Id` = a.`Parent_id` - //LEFT JOIN `Tag` a__Parent__Parent ON a__Parent__Parent.`Id` = a__Parent.`Parent_id` - //WHERE (a__Parent__Parent.`Name` = '粤语') - - //OneToMany - var t1 = g.dameng.Select().Where(a => a.Tags.AsSelect().Any(t => t.Parent.Id == 10)).ToSql(); - //SELECT a.`Id`, a.`Parent_id`, a.`Ddd`, a.`Name` - //FROM `Tag` a - //WHERE (exists(SELECT 1 - // FROM `Tag` t - // LEFT JOIN `Tag` t__Parent ON t__Parent.`Id` = t.`Parent_id` - // WHERE (t__Parent.`Id` = 10) AND (t.`Parent_id` = a.`Id`) - // limit 0,1)) - - //ManyToMany - var t2 = g.dameng.Select().Where(s => s.Tags.AsSelect().Any(t => t.Name == "国语")).ToSql(); - //SELECT a.`Id`, a.`Create_time`, a.`Is_deleted`, a.`Title`, a.`Url` - //FROM `Song` a - //WHERE(exists(SELECT 1 - // FROM `Song_tag` Mt_Ms - // WHERE(Mt_Ms.`Song_id` = a.`Id`) AND(exists(SELECT 1 - // FROM `Tag` t - // WHERE(t.`Name` = '国语') AND(t.`Id` = Mt_Ms.`Tag_id`) - // limit 0, 1)) - // limit 0, 1)) - } - - [Fact] - public void Lazy() - { - var tags = g.dameng.Select().Where(a => a.Parent.Name == "xxx") - .LeftJoin(a => a.Parent_id == a.Parent.Id) - .ToSql(); - - var songs = g.dameng.Select().Limit(10).ToList(); - } - - [Fact] - public void ToDataTable() - { - var items = new List(); - for (var a = 0; a < 11; a++) items.Add(new TopicInserts { Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now }); - - //Assert.Equal(1, g.dameng.Insert().AppendData(items.First()).ExecuteAffrows()); - Assert.Equal(11, g.dameng.Insert().AppendData(items).ExecuteAffrows()); - - //items = Enumerable.Range(0, 9989).Select(a => new TopicInserts { Title = "newtitle" + a, CreateTime = DateTime.Now }).ToList(); - //Assert.Equal(9989, g.dameng.Insert(items).ExecuteAffrows()); - - //var dt1 = select.ToDataTable(); - //var dt2 = select.ToDataTable("id, 111222"); - //var dt3 = select.ToDataTable(a => new { a.Id, a.Type.Name, now = DateTime.Now }); - } - class TestDto - { - public int id { get; set; } - public string name { get; set; } //这是join表的属性 - public int ParentId { get; set; } //这是join表的属性 - } - class TestDto2 - { - public int id { get; set; } - public string name { get; set; } //这是join表的属性 - public int ParentId { get; set; } //这是join表的属性 - - public TestDto2() { } - public TestDto2(int id, string name) - { - this.id = id; - this.name = name; - } - } - [Fact] - public void ToList() - { - - var testDto1 = select.Limit(10).ToList(a => new TestDto { id = a.Id, name = a.Title }); - var testDto2 = select.Limit(10).ToList(a => new TestDto()); - var testDto3 = select.Limit(10).ToList(a => new TestDto { }); - var testDto4 = select.Limit(10).ToList(a => new TestDto() { }); - - var testDto11 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { id = a.Id, name = a.Title }); - var testDto22 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto()); - var testDto33 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { }); - var testDto44 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto() { }); - - var testDto211 = select.Limit(10).ToList(a => new TestDto2(a.Id, a.Title)); - var testDto212 = select.Limit(10).ToList(a => new TestDto2()); - var testDto213 = select.Limit(10).ToList(a => new TestDto2 { }); - var testDto214 = select.Limit(10).ToList(a => new TestDto2() { }); - var testDto215 = select.Limit(10).ToList(); - - var testDto2211 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2(a.Id, a.Title)); - var testDto2222 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2()); - var testDto2233 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2 { }); - var testDto2244 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2() { }); - var testDto2255 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(); - - g.dameng.Insert().AppendData(new TestGuidIdToList()).ExecuteAffrows(); - var testGuidId5 = g.dameng.Select().ToList(); - var testGuidId6 = g.dameng.Select().ToList(a => a.id); - - var t11 = select.Where(a => a.Type.Name.Length > 0).ToList(true); - var t21 = select.Where(a => a.Type.Parent.Name.Length > 0).ToList(true); - - g.dameng.Delete().Where("1=1").ExecuteAffrows(); - var repo = g.dameng.GetRepository(); - repo.DbContextOptions.EnableCascadeSave = true; - repo.Insert(new District - { - Code = "001", - Name = "001_name", - Childs = new List(new[] { - new District{ - Code = "001_01", - Name = "001_01_name" - }, - new District{ - Code = "001_02", - Name = "001_02_name" - } - }) - }); - var ddd = g.dameng.Select().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList(); - Assert.Single(ddd); - Assert.Equal(2, ddd[0].Childs.Count); - } - public class District - { - [Column(IsPrimary = true, StringLength = 6)] - public string Code { get; set; } - - [Column(StringLength = 20, IsNullable = false)] - public string Name { get; set; } - - [Column(StringLength = 6)] - public string ParentCode { get; set; } - - [Navigate(nameof(ParentCode))] - public District Parent { get; set; } - - [Navigate(nameof(ParentCode))] - public List Childs { get; set; } - } - [Fact] - public void ToDictionary() - { - g.dameng.Insert(new Topic { Title = "xxx" }).ExecuteAffrows(); - var testDto1 = select.Limit(10).ToDictionary(a => a.Id); - var testDto2 = select.Limit(10).ToDictionary(a => a.Id, a => new { a.Id, a.Title }); - - var repo = g.dameng.GetRepository(); - var dic = repo.Select.Limit(10).ToDictionary(a => a.Id); - var first = dic.First().Value; - first.Clicks++; - repo.Update(first); - } - class TestGuidIdToList - { - public Guid id { get; set; } - public string title { get; set; } = Guid.NewGuid().ToString(); - } - [Fact] - public void ToOne() - { - var testnotfind = select.Where("1=2").First(a => a.CreateTime); - Assert.Equal(default(DateTime), testnotfind); - } - [Fact] - public void ToSql() - { - } - [Fact] - public void Any() - { - var count = select.Where(a => 1 == 1).Count(); - Assert.False(select.Where(a => 1 == 2).Any()); - Assert.Equal(count > 0, select.Where(a => 1 == 1).Any()); - - var sql2222 = select.Where(a => - select.Where(b => b.Id == a.Id && - select.Where(c => c.Id == b.Id).Where(d => d.Id == a.Id).Where(e => e.Id == b.Id) - //.Offset(a.Id) - .Any() - ).Any(c => c.Id == a.Id + 10) - ); - var sql2222Tolist = sql2222.ToList(); - - var collectionSelect = select.Where(a => - a.Type.Guid == a.TypeGuid && - a.Type.Parent.Id == a.Type.ParentId && - a.Type.Parent.Types.AsSelect().Where(b => b.Name == a.Title).Any(b => b.ParentId == a.Type.Parent.Id) - ); - collectionSelect.ToList(); - } - [Fact] - public void Count() - { - var count = select.Where(a => 1 == 1).Count(); - select.Where(a => 1 == 1).Count(out var count2); - Assert.Equal(count, count2); - Assert.Equal(0, select.Where(a => 1 == 2).Count()); - - var subquery = select.ToSql(a => new - { - all = a, - count = select.Where(b => b.Id > 0 && b.Id == a.Id).Count() - }); - var subqueryList = select.ToList(a => new - { - all = a, - count = select.Where(b => b.Id > 0 && b.Id == a.Id).Count() - }); - } - [Fact] - public void Master() - { - Assert.StartsWith(" SELECT", select.Master().Where(a => 1 == 1).ToSql()); - } - [Fact] - public void From() - { - var query2 = select.From((s, b) => s - .LeftJoin(a => a.TypeGuid == b.Guid) - ); - var sql2 = query2.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON a.\"TYPEGUID\" = b.\"GUID\"", sql2); - query2.ToList(); - - var query3 = select.From((s, b, c) => s - .LeftJoin(a => a.TypeGuid == b.Guid) - .LeftJoin(a => b.ParentId == c.Id) - ); - var sql3 = query3.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON a.\"TYPEGUID\" = b.\"GUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" c ON b.\"PARENTID\" = c.\"ID\"", sql3); - query3.ToList(); - } - [Fact] - public void LeftJoin() - { - //����е�������a.Type��a.Type.Parent ���ǵ������� - var query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid); - var sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\"", sql); - query.ToList(); - - query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx'", sql); - query.ToList(); - - query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql); - query.ToList(); - - //���û�е������� - query = select.LeftJoin((a, b) => b.Guid == a.TypeGuid); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TYPEGUID\"", sql); - query.ToList(); - - query = select.LeftJoin((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TYPEGUID\" AND b.\"NAME\" = 'xxx'", sql); - query.ToList(); - - query = select.LeftJoin((a, a__Type) => a__Type.Guid == a.TypeGuid && a__Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql); - query.ToList(); - - //������� - query = select - .LeftJoin(a => a.Type.Guid == a.TypeGuid) - .LeftJoin(a => a.Type.Parent.Id == a.Type.ParentId); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\"", sql); - query.ToList(); - - query = select - .LeftJoin((a, a__Type) => a__Type.Guid == a.TypeGuid) - .LeftJoin((a, c) => c.Id == a.Type.ParentId); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" c ON c.\"ID\" = a__Type.\"PARENTID\"", sql); - query.ToList(); - - //���û�е�������b��c������ϵ - var query2 = select.From((s, b, c) => s - .LeftJoin(a => a.TypeGuid == b.Guid) - .LeftJoin(a => b.ParentId == c.Id)); - sql = query2.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON a.\"TYPEGUID\" = b.\"GUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" c ON b.\"PARENTID\" = c.\"ID\"", sql); - query2.ToList(); - - //������϶����㲻�� - query = select.LeftJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\""); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\"", sql); - query.ToList(); - - query = select.LeftJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", new { bname = "xxx" }); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", sql); - query.ToList(); - } - [Fact] - public void InnerJoin() - { - //����е�������a.Type��a.Type.Parent ���ǵ������� - var query = select.InnerJoin(a => a.Type.Guid == a.TypeGuid); - var sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\"", sql); - query.ToList(); - - query = select.InnerJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx'", sql); - query.ToList(); - - query = select.InnerJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql); - query.ToList(); - - //���û�е������� - query = select.InnerJoin((a, b) => b.Guid == a.TypeGuid); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TYPEGUID\"", sql); - query.ToList(); - - query = select.InnerJoin((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TYPEGUID\" AND b.\"NAME\" = 'xxx'", sql); - query.ToList(); - - query = select.InnerJoin((a, a__Type) => a__Type.Guid == a.TypeGuid && a__Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql); - query.ToList(); - - //������� - query = select - .InnerJoin(a => a.Type.Guid == a.TypeGuid) - .InnerJoin(a => a.Type.Parent.Id == a.Type.ParentId); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" INNER JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\"", sql); - query.ToList(); - - query = select - .InnerJoin((a, a__Type) => a__Type.Guid == a.TypeGuid) - .InnerJoin((a, c) => c.Id == a.Type.ParentId); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" INNER JOIN \"TESTTYPEPARENTINFO\" c ON c.\"ID\" = a__Type.\"PARENTID\"", sql); - query.ToList(); - - //���û�е�������b��c������ϵ - var query2 = select.From((s, b, c) => s - .InnerJoin(a => a.TypeGuid == b.Guid) - .InnerJoin(a => b.ParentId == c.Id)); - sql = query2.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b ON a.\"TYPEGUID\" = b.\"GUID\" INNER JOIN \"TESTTYPEPARENTINFO\" c ON b.\"PARENTID\" = c.\"ID\"", sql); - query2.ToList(); - - //������϶����㲻�� - query = select.InnerJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\""); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\"", sql); - query.ToList(); - - query = select.InnerJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", new { bname = "xxx" }); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", sql); - query.ToList(); - - } - [Fact] - public void RightJoin() - { - //����е�������a.Type��a.Type.Parent ���ǵ������� - var query = select.RightJoin(a => a.Type.Guid == a.TypeGuid); - var sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\"", sql); - query.ToList(); - - query = select.RightJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx'", sql); - query.ToList(); - - query = select.RightJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql); - query.ToList(); - - //���û�е������� - query = select.RightJoin((a, b) => b.Guid == a.TypeGuid); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TYPEGUID\"", sql); - query.ToList(); - - query = select.RightJoin((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TYPEGUID\" AND b.\"NAME\" = 'xxx'", sql); - query.ToList(); - - query = select.RightJoin((a, a__Type) => a__Type.Guid == a.TypeGuid && a__Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql); - query.ToList(); - - //������� - query = select - .RightJoin(a => a.Type.Guid == a.TypeGuid) - .RightJoin(a => a.Type.Parent.Id == a.Type.ParentId); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" RIGHT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\"", sql); - query.ToList(); - - query = select - .RightJoin((a, a__Type) => a__Type.Guid == a.TypeGuid) - .RightJoin((a, c) => c.Id == a.Type.ParentId); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" RIGHT JOIN \"TESTTYPEPARENTINFO\" c ON c.\"ID\" = a__Type.\"PARENTID\"", sql); - query.ToList(); - - //���û�е�������b��c������ϵ - var query2 = select.From((s, b, c) => s - .RightJoin(a => a.TypeGuid == b.Guid) - .RightJoin(a => b.ParentId == c.Id)); - sql = query2.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b ON a.\"TYPEGUID\" = b.\"GUID\" RIGHT JOIN \"TESTTYPEPARENTINFO\" c ON b.\"PARENTID\" = c.\"ID\"", sql); - query2.ToList(); - - //������϶����㲻�� - query = select.RightJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\""); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\"", sql); - query.ToList(); - - query = select.RightJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", new { bname = "xxx" }); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", sql); - query.ToList(); - - } - [Fact] - public void Where() - { - var sqltmp1 = select.Where(a => a.Id == 0 && (a.Title == "x" || a.Title == "y") && a.Clicks == 1).ToSql(); - var sqltmp2 = select.Where(a => a.Id.Equals(true) && (a.Title.Equals("x") || a.Title.Equals("y")) && a.Clicks.Equals(1)).ToSql(); - var sqltmp3 = select.Where(a => a.Id == 0).Where(a => ((a.Title == "x" && a.Title == "z") || a.Title == "y")).ToSql(); - - var sqltmp4 = select.Where(a => (a.Id - 10) / 2 > 0).ToSql(); - - //����е�������a.Type��a.Type.Parent ���ǵ������� - var query = select.Where(a => a.Id == 10); - var sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10)", sql); - query.ToList(); - - query = select.Where(a => a.Id == 10 && a.Id > 10 || a.Clicks > 100); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE ((a.\"ID\" = 10 AND a.\"ID\" > 10 OR a.\"CLICKS\" > 100))", sql); - query.ToList(); - - query = select.Where(a => a.Id == 10).Where(a => a.Clicks > 100); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10) AND (a.\"CLICKS\" > 100)", sql); - query.ToList(); - - query = select.Where(a => a.Type.Name == "typeTitle"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" WHERE (a__Type.\"NAME\" = 'typeTitle')", sql); - query.ToList(); - - query = select.Where(a => a.Type.Name == "typeTitle" && a.Type.Guid == a.TypeGuid); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" WHERE (a__Type.\"NAME\" = 'typeTitle' AND a__Type.\"GUID\" = a.\"TYPEGUID\")", sql); - query.ToList(); - - query = select.Where(a => a.Type.Parent.Name == "tparent"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"NAME\" = 'tparent')", sql); - query.ToList(); - - //���û�е������ԣ��򵥶������ - query = select.Where((a, b) => b.Guid == a.TypeGuid && b.Name == "typeTitle"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" b WHERE (b.\"GUID\" = a.\"TYPEGUID\" AND b.\"NAME\" = 'typeTitle')", sql); - query.ToList(); - - query = select.Where((a, b) => b.Name == "typeTitle" && b.Guid == a.TypeGuid); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" b WHERE (b.\"NAME\" = 'typeTitle' AND b.\"GUID\" = a.\"TYPEGUID\")", sql); - query.ToList(); - - query = select.Where((a, b, c) => c.Name == "tparent"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEPARENTINFO\" c WHERE (c.\"NAME\" = 'tparent')", sql); - query.ToList(); - - //����һ�� From ��Ķ������ - var query2 = select.From((s, b, c) => s - .Where(a => a.Id == 10 && c.Name == "xxx") - .Where(a => b.ParentId == 20)); - sql = query2.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" b, \"TESTTYPEPARENTINFO\" c WHERE (a.\"ID\" = 10 AND c.\"NAME\" = 'xxx') AND (b.\"PARENTID\" = 20)", sql); - query2.ToList(); - - //������϶����㲻�� - query = select.Where("a.\"CLICKS\" > 100 and a.\"ID\" = :id", new { id = 10 }); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"CLICKS\" > 100 and a.\"ID\" = :id)", sql); - query.ToList(); - } - [Fact] - public void WhereIf() - { - //����е�������a.Type��a.Type.Parent ���ǵ������� - var query = select.WhereIf(true, a => a.Id == 10); - var sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10)", sql); - query.ToList(); - - query = select.WhereIf(true, a => a.Id == 10 && a.Id > 10 || a.Clicks > 100); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE ((a.\"ID\" = 10 AND a.\"ID\" > 10 OR a.\"CLICKS\" > 100))", sql); - query.ToList(); - - query = select.WhereIf(true, a => a.Id == 10).WhereIf(true, a => a.Clicks > 100); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10) AND (a.\"CLICKS\" > 100)", sql); - query.ToList(); - - query = select.WhereIf(true, a => a.Type.Name == "typeTitle"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" WHERE (a__Type.\"NAME\" = 'typeTitle')", sql); - query.ToList(); - - query = select.WhereIf(true, a => a.Type.Name == "typeTitle" && a.Type.Guid == a.TypeGuid); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" WHERE (a__Type.\"NAME\" = 'typeTitle' AND a__Type.\"GUID\" = a.\"TYPEGUID\")", sql); - query.ToList(); - - query = select.WhereIf(true, a => a.Type.Parent.Name == "tparent"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"NAME\" = 'tparent')", sql); - query.ToList(); - - //����һ�� From ��Ķ������ - var query2 = select.From((s, b, c) => s - .WhereIf(true, a => a.Id == 10 && c.Name == "xxx") - .WhereIf(true, a => b.ParentId == 20)); - sql = query2.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" b, \"TESTTYPEPARENTINFO\" c WHERE (a.\"ID\" = 10 AND c.\"NAME\" = 'xxx') AND (b.\"PARENTID\" = 20)", sql); - query2.ToList(); - - //������϶����㲻�� - query = select.WhereIf(true, "a.\"CLICKS\" > 100 and a.\"ID\" = :id", new { id = 10 }); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"CLICKS\" > 100 and a.\"ID\" = :id)", sql); - query.ToList(); - - // ==========================================WhereIf(false) - - //����е�������a.Type��a.Type.Parent ���ǵ������� - query = select.WhereIf(false, a => a.Id == 10); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql); - query.ToList(); - - query = select.WhereIf(false, a => a.Id == 10 && a.Id > 10 || a.Clicks > 100); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql); - query.ToList(); - - query = select.WhereIf(false, a => a.Id == 10).WhereIf(false, a => a.Clicks > 100); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql); - query.ToList(); - - query = select.WhereIf(false, a => a.Type.Name == "typeTitle"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql); - query.ToList(); - - query = select.WhereIf(false, a => a.Type.Name == "typeTitle" && a.Type.Guid == a.TypeGuid); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql); - query.ToList(); - - query = select.WhereIf(false, a => a.Type.Parent.Name == "tparent"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql); - query.ToList(); - - //����һ�� From ��Ķ������ - query2 = select.From((s, b, c) => s - .WhereIf(false, a => a.Id == 10 && c.Name == "xxx") - .WhereIf(false, a => b.ParentId == 20)); - sql = query2.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" b, \"TESTTYPEPARENTINFO\" c", sql); - query2.ToList(); - - //������϶����㲻�� - query = select.WhereIf(false, "a.\"CLICKS\" > 100 and a.\"ID\" = :id", new { id = 10 }); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql); - query.ToList(); - } - [Fact] - public void WhereExists() - { - var sql2222 = select.Where(a => select.Where(b => b.Id == a.Id).Any()).ToList(); - - sql2222 = select.Where(a => - select.Where(b => b.Id == a.Id && select.Where(c => c.Id == b.Id).Where(d => d.Id == a.Id).Where(e => e.Id == b.Id) - - //.Offset(a.Id) - - .Any() - ).Any() - ).ToList(); - } - [Fact] - public void GroupBy() - { - var groupby = select.From((s, b, c) => s - .Where(a => a.Id == 1) - ) - .GroupBy((a, b, c) => new { tt2 = a.Title.Substring(0, 2), mod4 = a.Id % 4 }) - .Having(a => a.Count() > 0 && a.Avg(a.Key.mod4) > 0 && a.Max(a.Key.mod4) > 0) - .Having(a => a.Count() < 300 || a.Avg(a.Key.mod4) < 100) - .OrderBy(a => a.Key.tt2) - .OrderByDescending(a => a.Count()) - .Offset(10) - .Limit(2) - .Count(out var trycount) - .ToList(a => new - { - a.Key.tt2, - cou1 = a.Count(), - cou2 = a.Count(a.Value.Item3.Id), - arg1 = a.Avg(a.Key.mod4), - ccc2 = a.Key.tt2 ?? "now()", - //ccc = Convert.ToDateTime("now()"), partby = Convert.ToDecimal("sum(num) over(PARTITION BY server_id,os,rid,chn order by id desc)") - ccc3 = a.Max(a.Value.Item3.Id) - }); - - var testpid1 = g.dameng.Insert().AppendData(new TestTypeInfo { Name = "Name" + DateTime.Now.ToString("yyyyMMddHHmmss") }).ExecuteIdentity(); - g.dameng.Insert().AppendData(new TestInfo { Title = "Title" + DateTime.Now.ToString("yyyyMMddHHmmss"), CreateTime = DateTime.Now, TypeGuid = (int)testpid1 }).ExecuteAffrows(); - - var fkfjfj = select.GroupBy(a => a.Title) - .ToList(a => a.Sum(a.Value.TypeGuid)); - - var aggsql1 = select - .GroupBy(a => a.Title) - .ToSql(b => new - { - b.Key, - cou = b.Count(), - sum2 = b.Sum(b.Value.TypeGuid) - }); - var aggtolist1 = select - .GroupBy(a => a.Title) - .ToList(b => new - { - b.Key, - cou = b.Count(), - sum2 = b.Sum(b.Value.TypeGuid) - }); - var aggtolist11 = select - .GroupBy(a => a.Title) - .ToDictionary(b => new - { - b.Key, - cou = b.Count(), - sum2 = b.Sum(b.Value.TypeGuid) - }); - - var aggsql2 = select - .GroupBy(a => new { a.Title, yyyy = string.Concat(a.CreateTime.Year, '-', a.CreateTime.Month) }) - .ToSql(b => new - { - b.Key.Title, - b.Key.yyyy, - - cou = b.Count(), - sum2 = b.Sum(b.Value.TypeGuid) - }); - var aggtolist2 = select - .GroupBy(a => new { a.Title, yyyy = string.Concat(a.CreateTime.Year, '-', a.CreateTime.Month) }) - .ToList(b => new - { - b.Key.Title, - b.Key.yyyy, - cou = b.Count(), - sum2 = b.Sum(b.Value.TypeGuid) - }); - var aggtolist22 = select - .GroupBy(a => new { a.Title, yyyy = string.Concat(a.CreateTime.Year, '-', a.CreateTime.Month) }) - .ToDictionary(b => new - { - b.Key.Title, - b.Key.yyyy, - b.Key, - cou = b.Count(), - sum2 = b.Sum(b.Value.TypeGuid) - }); - - var aggsql3 = select - .GroupBy(a => a.Title) - .ToSql(b => new - { - b.Key, - cou = b.Count(), - sum2 = b.Sum(b.Value.TypeGuid), - sum3 = b.Sum(b.Value.Type.Parent.Id) - }); - } - [Fact] - public void ToAggregate() - { - var sql = select.ToAggregate(a => new { sum = a.Sum(a.Key.Id + 11.11), avg = a.Avg(a.Key.Id), count = a.Count(), max = a.Max(a.Key.Id), min = a.Min(a.Key.Id) }); - } - [Fact] - public void OrderBy() - { - var sql = select.Offset(10).OrderBy(a => new Random().NextDouble()).ToList(); - } - [Fact] - public void OrderByRandom() - { - var t1 = select.OrderByRandom().Limit(10).ToSql("1"); - Assert.Equal(@"SELECT t.* FROM (SELECT 1 -FROM ""TB_TOPIC22"" a -ORDER BY dbms_random.value) t WHERE ROWNUM < 11", t1); - var t2 = select.OrderByRandom().Limit(10).ToList(); - } - - [Fact] - public void Skip_Offset() - { - var sql = select.Offset(10).ToList(); - } - [Fact] - public void Take_Limit() - { - var sql = select.Limit(10).ToList(); - } - [Fact] - public void Page() - { - var sql1 = select.Page(1, 10).ToList(); - var sql2 = select.Page(2, 10).ToList(); - var sql3 = select.Page(3, 10).ToList(); - - var sql11 = select.OrderBy(a => new Random().NextDouble()).Page(1, 10).ToList(); - var sql22 = select.OrderBy(a => new Random().NextDouble()).Page(2, 10).ToList(); - var sql33 = select.OrderBy(a => new Random().NextDouble()).Page(3, 10).ToList(); - } - [Fact] - public void Distinct() - { - var t1 = select.Distinct().ToList(a => a.Title); - var t2 = select.Distinct().Limit(10).ToList(a => a.Title); - } - - [Fact] - public void Sum() - { - var subquery = select.ToSql(a => new - { - all = a, - count = (long)select.As("b").Sum(b => b.Id) - }); - Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, nvl((SELECT sum(b.""ID"") - FROM ""TB_TOPIC22"" b), 0) as6 -FROM ""TB_TOPIC22"" a", subquery); - var subqueryList = select.ToList(a => new - { - all = a, - count = (long)select.As("b").Sum(b => b.Id) - }); - } - [Fact] - public void Min() - { - var subquery = select.ToSql(a => new - { - all = a, - min = select.As("b").Min(b => b.Id), - min2 = select.As("b").Min(b => b.CreateTime) - }); - Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, nvl((SELECT min(b.""ID"") - FROM ""TB_TOPIC22"" b), 0) as6, nvl((SELECT min(b.""CREATETIME"") - FROM ""TB_TOPIC22"" b), to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) as7 -FROM ""TB_TOPIC22"" a", subquery); - var subqueryList = select.ToList(a => new - { - all = a, - min = select.As("b").Min(b => b.Id), - min2 = select.As("b").Min(b => b.CreateTime) - }); - } - [Fact] - public void Max() - { - var subquery = select.ToSql(a => new - { - all = a, - max = select.As("b").Max(b => b.Id), - max2 = select.As("b").Max(b => b.CreateTime) - }); - Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, nvl((SELECT max(b.""ID"") - FROM ""TB_TOPIC22"" b), 0) as6, nvl((SELECT max(b.""CREATETIME"") - FROM ""TB_TOPIC22"" b), to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6')) as7 -FROM ""TB_TOPIC22"" a", subquery); - var subqueryList = select.ToList(a => new - { - all = a, - max = select.As("b").Max(b => b.Id), - max2 = select.As("b").Max(b => b.CreateTime) - }); - } - [Fact] - public void Avg() - { - var subquery = select.ToSql(a => new - { - all = a, - count = select.As("b").Avg(b => b.Id) - }); - Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, nvl((SELECT avg(b.""ID"") - FROM ""TB_TOPIC22"" b), 0) as6 -FROM ""TB_TOPIC22"" a", subquery); - var subqueryList = select.ToList(a => new - { - all = a, - count = select.As("b").Avg(b => b.Id) - }); - } - [Fact] - public void WhereIn() - { - var subquery = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToSql(); - Assert.Equal(@"SELECT a.""ID"", a.""CLICKS"", a.""TYPEGUID"", a.""TITLE"", a.""CREATETIME"" -FROM ""TB_TOPIC22"" a -WHERE (((to_char(a.""ID"")) in (SELECT b.""TITLE"" - FROM ""TB_TOPIC22"" b)))", subquery); - var subqueryList = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToList(); - - subquery = select.Where(a => select.As("b").Limit(10).ToList(b => b.Title).Contains(a.Id.ToString())).ToSql(); - Assert.Equal(@"SELECT a.""ID"", a.""CLICKS"", a.""TYPEGUID"", a.""TITLE"", a.""CREATETIME"" -FROM ""TB_TOPIC22"" a -WHERE (((to_char(a.""ID"")) in (SELECT b.""TITLE"" - FROM ""TB_TOPIC22"" b - WHERE ROWNUM < 11)))", subquery); - subqueryList = select.Where(a => select.As("b").Limit(10).ToList(b => b.Title).Contains(a.Id.ToString())).ToList(); - } - [Fact] - public void As() - { - } - - [Fact] - public void AsTable() - { - - var listt = select.AsTable((a, b) => "(select * from tb_topic where clicks > 10)").Page(1, 10).ToList(); - - Func tableRule = (type, oldname) => - { - if (oldname.Length > 16) oldname = oldname.Remove(16); - if (type == typeof(Topic)) return oldname + "_T1"; - else if (type == typeof(TestTypeInfo)) return oldname + "_T2"; - return oldname + "_AT"; - }; - - //����е�������a.Type��a.Type.Parent ���ǵ������� - var query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).AsTable(tableRule); - var sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO_T2\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\"", sql); - - query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").AsTable(tableRule); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO_T2\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx'", sql); - - query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO_T2\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTIN_AT\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql); - - //���û�е������� - query = select.LeftJoin((a, b) => b.Guid == a.TypeGuid).AsTable(tableRule); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO_T2\" b ON b.\"GUID\" = a.\"TYPEGUID\"", sql); - - query = select.LeftJoin((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx").AsTable(tableRule); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO_T2\" b ON b.\"GUID\" = a.\"TYPEGUID\" AND b.\"NAME\" = 'xxx'", sql); - - query = select.LeftJoin((a, a__Type) => a__Type.Guid == a.TypeGuid && a__Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO_T2\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTIN_AT\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql); - - //������� - query = select - .LeftJoin(a => a.Type.Guid == a.TypeGuid) - .LeftJoin(a => a.Type.Parent.Id == a.Type.ParentId).AsTable(tableRule); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO_T2\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" LEFT JOIN \"TESTTYPEPARENTIN_AT\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\"", sql); - - query = select - .LeftJoin((a, a__Type) => a__Type.Guid == a.TypeGuid) - .LeftJoin((a, c) => c.Id == a.Type.ParentId).AsTable(tableRule); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO_T2\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" LEFT JOIN \"TESTTYPEPARENTIN_AT\" c ON c.\"ID\" = a__Type.\"PARENTID\"", sql); - - //���û�е�������b��c������ϵ - var query2 = select.From((s, b, c) => s - .LeftJoin(a => a.TypeGuid == b.Guid) - .LeftJoin(a => b.ParentId == c.Id)).AsTable(tableRule); - sql = query2.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO_T2\" b ON a.\"TYPEGUID\" = b.\"GUID\" LEFT JOIN \"TESTTYPEPARENTIN_AT\" c ON b.\"PARENTID\" = c.\"ID\"", sql); - - //������϶����㲻�� - query = select.LeftJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\"").AsTable(tableRule); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\"", sql); - - query = select.LeftJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", new { bname = "xxx" }).AsTable(tableRule); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = :bname", sql); - - query = select.AsTable((_, old) => old).AsTable((_, old) => old); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT * from (SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a) ftb UNION ALL SELECT * from (SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a) ftb", sql); - query.ToList(); - - query = select.AsTable((_, old) => old).AsTable((_, old) => old); - sql = query.ToSql("count(1) as1").Replace("\r\n", ""); - Assert.Equal("SELECT * from (SELECT count(1) as1 FROM \"TB_TOPIC22\" a) ftb UNION ALL SELECT * from (SELECT count(1) as1 FROM \"TB_TOPIC22\" a) ftb", sql); - query.Count(); - - select.AsTable((_, old) => old).AsTable((_, old) => old).Max(a => a.Id); - select.AsTable((_, old) => old).AsTable((_, old) => old).Min(a => a.Id); - select.AsTable((_, old) => old).AsTable((_, old) => old).Sum(a => a.Id); - select.AsTable((_, old) => old).AsTable((_, old) => old).Avg(a => a.Id); - - var sqlsss = select - .AsTable((type, old) => type == typeof(Topic) ? $"{old}_1" : null) - .AsTable((type, old) => type == typeof(Topic) ? $"{old}_2" : null) - .ToSql(a => new - { - a.Id, - a.Clicks - }, FieldAliasOptions.AsProperty); - - var slsld3 = select - .AsTable((type, old) => type == typeof(Topic) ? $"({sqlsss})" : null) - .Page(1, 20) - .ToList(a => new - { - a.Id, - a.Clicks - }); - } - - public class TiOtmModel1 - { - [Column(IsIdentity = true)] - public int id { get; set; } - public virtual TiOtmModel2 model2 { get; set; } - - public string m1name { get; set; } - } - public class TiOtmModel2 - { - [Column(IsPrimary = true)] - public int model2id { get; set; } - public virtual TiOtmModel1 model1 { get; set; } - - public string m2setting { get; set; } - - public List childs { get; set; } - } - public class TiOtmModel3 - { - [Column(IsIdentity = true)] - public int id { get; set; } - - public int model2111Idaaa { get; set; } - public string title { get; set; } - - public List childs2 { get; set; } - } - public class TiOtmModel4 - { - [Column(IsIdentity = true)] - public int id { get; set; } - - public int model3333Id333 { get; set; } - public string title444 { get; set; } - } - - [Fact] - public void Include_OneToMany() - { - g.dameng.Delete().Where("1=1").ExecuteAffrows(); - g.dameng.Delete().Where("1=1").ExecuteAffrows(); - g.dameng.Delete().Where("1=1").ExecuteAffrows(); - g.dameng.Delete().Where("1=1").ExecuteAffrows(); - - var model1 = new TiOtmModel1 { m1name = DateTime.Now.Second.ToString() }; - model1.id = (int)g.dameng.Insert(model1).ExecuteIdentity(); - var model2 = new TiOtmModel2 { model2id = model1.id, m2setting = DateTime.Now.Second.ToString() }; - g.dameng.Insert(model2).ExecuteAffrows(); - - var model3_1 = new TiOtmModel3 { model2111Idaaa = model1.id, title = "testmodel3__111" }; - model3_1.id = (int)g.dameng.Insert(model3_1).ExecuteIdentity(); - var model3_2 = new TiOtmModel3 { model2111Idaaa = model1.id, title = "testmodel3__222" }; - model3_2.id = (int)g.dameng.Insert(model3_2).ExecuteIdentity(); - var model3_3 = new TiOtmModel3 { model2111Idaaa = model1.id, title = "testmodel3__333" }; - model3_3.id = (int)g.dameng.Insert(model3_2).ExecuteIdentity(); - - var model4s = new[] { - new TiOtmModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__111" }, - new TiOtmModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__222" }, - new TiOtmModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__111" }, - new TiOtmModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__222" }, - new TiOtmModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__333" } - }; - Assert.Equal(5, g.dameng.Insert(model4s).ExecuteAffrows()); - - var t0 = g.dameng.Select() - .IncludeMany(a => a.childs.Where(m3 => m3.model2111Idaaa == a.model2id)) - .Where(a => a.model2id <= model1.id) - .ToList(); - - var t1 = g.dameng.Select() - .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id)) - .Where(a => a.id <= model1.id) - .ToList(); - - var t2 = g.dameng.Select() - .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id), - then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id))) - .Where(a => a.id <= model1.id) - .ToList(); - - var t00 = g.dameng.Select() - .IncludeMany(a => a.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2id)) - .Where(a => a.model2id <= model1.id) - .ToList(); - - var t11 = g.dameng.Select() - .IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id)) - .Where(a => a.id <= model1.id) - .ToList(); - - var t22 = g.dameng.Select() - .IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id), - then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id))) - .Where(a => a.id <= model1.id) - .ToList(); - - //---- Select ---- - - var at0 = g.dameng.Select() - .IncludeMany(a => a.childs.Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TiOtmModel3 { id = m3.id })) - .Where(a => a.model2id <= model1.id) - .ToList(); - - var at1 = g.dameng.Select() - .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TiOtmModel3 { id = m3.id })) - .Where(a => a.id <= model1.id) - .ToList(); - - var at2 = g.dameng.Select() - .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TiOtmModel3 { id = m3.id }), - then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TiOtmModel4 { id = m4.id }))) - .Where(a => a.id <= model1.id) - .ToList(); - - var at00 = g.dameng.Select() - .IncludeMany(a => a.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TiOtmModel3 { id = m3.id })) - .Where(a => a.model2id <= model1.id) - .ToList(); - - var at11 = g.dameng.Select() - .IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TiOtmModel3 { id = m3.id })) - .Where(a => a.id <= model1.id) - .ToList(); - - var at22 = g.dameng.Select() - .IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TiOtmModel3 { id = m3.id }), - then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TiOtmModel4 { id = m4.id }))) - .Where(a => a.id <= model1.id) - .ToList(); - } - - public class TiOtmModel11 - { - [Column(IsIdentity = true)] - public int id { get; set; } - public int model2id { get; set; } - public string m3setting { get; set; } - public TiOtmModel22 model2 { get; set; } - public string m1name { get; set; } - } - - public class TiOtmModel22 - { - [Column(IsIdentity = true)] - public int id { get; set; } - public string m2setting { get; set; } - public string aaa { get; set; } - public string bbb { get; set; } - public List childs { get; set; } - } - public class TiOtmModel33 - { - [Column(IsIdentity = true)] - public int id { get; set; } - public int model2Id { get; set; } - public string title { get; set; } - public string setting { get; set; } - } - [Fact] - public void Include_OneToMany2() - { - g.dameng.Delete().Where("1=1").ExecuteAffrows(); - g.dameng.Delete().Where("1=1").ExecuteAffrows(); - g.dameng.Delete().Where("1=1").ExecuteAffrows(); - - string setting = "x"; - var model2 = new TiOtmModel22 { m2setting = DateTime.Now.Second.ToString(), aaa = "aaa" + DateTime.Now.Second, bbb = "bbb" + DateTime.Now.Second }; - model2.id = (int)g.dameng.Insert(model2).ExecuteIdentity(); - - var model3s = new[] - { - new TiOtmModel33 {model2Id = model2.id, title = "testmodel3__111", setting = setting}, - new TiOtmModel33 {model2Id = model2.id, title = "testmodel3__222", setting = setting}, - new TiOtmModel33 {model2Id = model2.id, title = "testmodel3__333", setting = setting} - }; - Assert.Equal(3, g.dameng.Insert(model3s).ExecuteAffrows()); - - var model1 = new TiOtmModel11 { m1name = DateTime.Now.Second.ToString(), model2id = model2.id, m3setting = setting }; - model1.id = (int)g.dameng.Insert(model1).ExecuteIdentity(); - - var t1 = g.dameng.Select() - .LeftJoin(a => a.model2id == a.model2.id) - .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting)) - .Where(a => a.id <= model1.id) - .ToList(true); - - var t11 = g.dameng.Select() - .LeftJoin(a => a.model2id == a.model2.id) - .IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting)) - .Where(a => a.id <= model1.id) - .ToList(true); - - //---- Select ---- - - var at1 = g.dameng.Select() - .LeftJoin(a => a.model2id == a.model2.id) - .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TiOtmModel33 { title = m3.title })) - .Where(a => a.id <= model1.id) - .ToList(true); - - var at11 = g.dameng.Select() - .LeftJoin(a => a.model2id == a.model2.id) - .IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TiOtmModel33 { title = m3.title })) - .Where(a => a.id <= model1.id) - .ToList(true); - } - - [Fact] - public void Include_OneToChilds() - { - var tag1 = new Tag - { - Ddd = DateTime.Now.Second, - Name = "test_oneToChilds_01_中国" - }; - tag1.Id = (int)g.dameng.Insert(tag1).ExecuteIdentity(); - var tag1_1 = new Tag - { - Parent_id = tag1.Id, - Ddd = DateTime.Now.Second, - Name = "test_oneToChilds_01_北京" - }; - tag1_1.Id = (int)g.dameng.Insert(tag1_1).ExecuteIdentity(); - var tag1_2 = new Tag - { - Parent_id = tag1.Id, - Ddd = DateTime.Now.Second, - Name = "test_oneToChilds_01_上海" - }; - tag1_2.Id = (int)g.dameng.Insert(tag1_2).ExecuteIdentity(); - - var tag2 = new Tag - { - Ddd = DateTime.Now.Second, - Name = "test_oneToChilds_02_美国" - }; - tag2.Id = (int)g.dameng.Insert(tag2).ExecuteIdentity(); - var tag2_1 = new Tag - { - Parent_id = tag2.Id, - Ddd = DateTime.Now.Second, - Name = "test_oneToChilds_02_纽约" - }; - tag2_1.Id = (int)g.dameng.Insert(tag2_1).ExecuteIdentity(); - var tag2_2 = new Tag - { - Parent_id = tag2.Id, - Ddd = DateTime.Now.Second, - Name = "test_oneToChilds_02_华盛顿" - }; - tag2_2.Id = (int)g.dameng.Insert(tag2_2).ExecuteIdentity(); - - var tags0 = g.dameng.Select() - .Include(a => a.Parent) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var tags1 = g.dameng.Select() - .IncludeMany(a => a.Tags) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var tags2 = g.dameng.Select() - .IncludeMany(a => a.Tags, - then => then.Include(a => a.Parent).IncludeMany(a => a.Songs)) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var tags3 = g.dameng.Select() - .IncludeMany(a => a.Tags, - then => then.Include(a => a.Parent).IncludeMany(a => a.Songs).IncludeMany(a => a.Tags)) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var tags11 = g.dameng.Select() - .IncludeMany(a => a.Tags.Take(1)) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs.Take(1)) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var tags22 = g.dameng.Select() - .IncludeMany(a => a.Tags.Take(1), - then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1))) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs.Take(1)) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var tags33 = g.dameng.Select() - .IncludeMany(a => a.Tags.Take(1), - then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1)).IncludeMany(a => a.Tags.Take(1))) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs.Take(1)) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - // --- Select --- - - var atags0 = g.dameng.Select() - .Include(a => a.Parent) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var atags1 = g.dameng.Select() - .IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name })) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var atags2 = g.dameng.Select() - .IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }), - then => then.Include(a => a.Parent).IncludeMany(a => a.Songs)) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var atags3 = g.dameng.Select() - .IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }), - then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var atags11 = g.dameng.Select() - .IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name })) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var atags22 = g.dameng.Select() - .IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }), - then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var atags33 = g.dameng.Select() - .IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }), - then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - } - - [Fact] - public void Include_ManyToMany() - { - - var tag1 = new Tag - { - Ddd = DateTime.Now.Second, - Name = "test_manytoMany_01_中国" - }; - tag1.Id = (int)g.dameng.Insert(tag1).ExecuteIdentity(); - var tag2 = new Tag - { - Ddd = DateTime.Now.Second, - Name = "test_manytoMany_02_美国" - }; - tag2.Id = (int)g.dameng.Insert(tag2).ExecuteIdentity(); - var tag3 = new Tag - { - Ddd = DateTime.Now.Second, - Name = "test_manytoMany_03_日本" - }; - tag3.Id = (int)g.dameng.Insert(tag3).ExecuteIdentity(); - - var song1 = new Song - { - Create_time = DateTime.Now, - Title = "test_manytoMany_01_我是中国人.mp3", - Url = "http://ww.baidu.com/" - }; - song1.Id = (int)g.dameng.Insert(song1).ExecuteIdentity(); - var song2 = new Song - { - Create_time = DateTime.Now, - Title = "test_manytoMany_02_爱你一万年.mp3", - Url = "http://ww.163.com/" - }; - song2.Id = (int)g.dameng.Insert(song2).ExecuteIdentity(); - var song3 = new Song - { - Create_time = DateTime.Now, - Title = "test_manytoMany_03_千年等一回.mp3", - Url = "http://ww.sina.com/" - }; - song3.Id = (int)g.dameng.Insert(song3).ExecuteIdentity(); - - g.dameng.Insert(new Song_tag { Song_id = song1.Id, Tag_id = tag1.Id }).ExecuteAffrows(); - g.dameng.Insert(new Song_tag { Song_id = song2.Id, Tag_id = tag1.Id }).ExecuteAffrows(); - g.dameng.Insert(new Song_tag { Song_id = song3.Id, Tag_id = tag1.Id }).ExecuteAffrows(); - g.dameng.Insert(new Song_tag { Song_id = song1.Id, Tag_id = tag2.Id }).ExecuteAffrows(); - g.dameng.Insert(new Song_tag { Song_id = song3.Id, Tag_id = tag2.Id }).ExecuteAffrows(); - g.dameng.Insert(new Song_tag { Song_id = song3.Id, Tag_id = tag3.Id }).ExecuteAffrows(); - - var songs1 = g.dameng.Select() - .IncludeMany(a => a.Tags) - .Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id) - .ToList(); - Assert.Equal(3, songs1.Count); - Assert.Equal(2, songs1[0].Tags.Count); - Assert.Equal(1, songs1[1].Tags.Count); - Assert.Equal(3, songs1[2].Tags.Count); - - var songs2 = g.dameng.Select() - .IncludeMany(a => a.Tags, - then => then.IncludeMany(t => t.Songs)) - .Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id) - .ToList(); - Assert.Equal(3, songs2.Count); - Assert.Equal(2, songs2[0].Tags.Count); - Assert.Equal(1, songs2[1].Tags.Count); - Assert.Equal(3, songs2[2].Tags.Count); - - var tags3 = g.dameng.Select() - .Include(a => a.Tag.Parent) - .IncludeMany(a => a.Tag.Songs) - .Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id) - .ToList(true); - - - var songs11 = g.dameng.Select() - .IncludeMany(a => a.Tags.Take(1)) - .Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id) - .ToList(); - Assert.Equal(3, songs11.Count); - Assert.Equal(1, songs11[0].Tags.Count); - Assert.Equal(1, songs11[1].Tags.Count); - Assert.Equal(1, songs11[2].Tags.Count); - - var songs22 = g.dameng.Select() - .IncludeMany(a => a.Tags.Take(1), - then => then.IncludeMany(t => t.Songs.Take(1))) - .Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id) - .ToList(); - Assert.Equal(3, songs22.Count); - Assert.Equal(1, songs22[0].Tags.Count); - Assert.Equal(1, songs22[1].Tags.Count); - Assert.Equal(1, songs22[2].Tags.Count); - - var tags33 = g.dameng.Select() - .Include(a => a.Tag.Parent) - .IncludeMany(a => a.Tag.Songs.Take(1)) - .Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id) - .ToList(true); - - // --- Select --- - - new List(new[] { song1, song2, song3 }).IncludeMany(g.dameng, a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name })); - - var asongs1 = g.dameng.Select() - .IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name })) - .Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id) - .ToList(); - Assert.Equal(3, songs1.Count); - Assert.Equal(2, songs1[0].Tags.Count); - Assert.Equal(1, songs1[1].Tags.Count); - Assert.Equal(3, songs1[2].Tags.Count); - - var asongs2 = g.dameng.Select() - .IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }), - then => then.IncludeMany(t => t.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))) - .Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id) - .ToList(); - Assert.Equal(3, songs2.Count); - Assert.Equal(2, songs2[0].Tags.Count); - Assert.Equal(1, songs2[1].Tags.Count); - Assert.Equal(3, songs2[2].Tags.Count); - - var atags3 = g.dameng.Select() - .Include(a => a.Tag.Parent) - .IncludeMany(a => a.Tag.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })) - .Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id) - .ToList(true); - - - var asongs11 = g.dameng.Select() - .IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name })) - .Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id) - .ToList(); - Assert.Equal(3, songs11.Count); - Assert.Equal(1, songs11[0].Tags.Count); - Assert.Equal(1, songs11[1].Tags.Count); - Assert.Equal(1, songs11[2].Tags.Count); - - var asongs22 = g.dameng.Select() - .IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }), - then => then.IncludeMany(t => t.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))) - .Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id) - .ToList(); - Assert.Equal(3, songs22.Count); - Assert.Equal(1, songs22[0].Tags.Count); - Assert.Equal(1, songs22[1].Tags.Count); - Assert.Equal(1, songs22[2].Tags.Count); - - var atags33 = g.dameng.Select() - .Include(a => a.Tag.Parent) - .IncludeMany(a => a.Tag.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })) - .Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id) - .ToList(true); - } - - public class ToDel1Pk - { - [Column(IsIdentity = true)] - public int id { get; set; } - public string name { get; set; } - } - public class ToDel2Pk - { - [Column(IsPrimary = true)] - public Guid pk1 { get; set; } - [Column(IsPrimary = true)] - public string pk2 { get; set; } - public string name { get; set; } - } - public class ToDel3Pk - { - [Column(IsPrimary = true)] - public Guid pk1 { get; set; } - [Column(IsPrimary = true)] - public int pk2 { get; set; } - [Column(IsPrimary = true)] - public string pk3 { get; set; } - public string name { get; set; } - } - [Fact] - public void ToDelete() - { - g.dameng.Select().ToDelete().ExecuteAffrows(); - Assert.Equal(0, g.dameng.Select().Count()); - g.dameng.Insert(new[] { - new ToDel1Pk{ name = "name1"}, - new ToDel1Pk{ name = "name2"}, - new ToDel1Pk{ name = "nick1"}, - new ToDel1Pk{ name = "nick2"}, - new ToDel1Pk{ name = "nick3"} - }).ExecuteAffrows(); - Assert.Equal(2, g.dameng.Select().Where(a => a.name.StartsWith("name")).ToDelete().ExecuteAffrows()); - Assert.Equal(3, g.dameng.Select().Count()); - Assert.Equal(3, g.dameng.Select().Where(a => a.name.StartsWith("nick")).Count()); - - g.dameng.Select().ToDelete().ExecuteAffrows(); - Assert.Equal(0, g.dameng.Select().Count()); - g.dameng.Insert(new[] { - new ToDel2Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = "pk2", name = "name1"}, - new ToDel2Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = "pk2", name = "name2"}, - new ToDel2Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = "pk2", name = "nick1"}, - new ToDel2Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = "pk2", name = "nick2"}, - new ToDel2Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = "pk2", name = "nick3"} - }).ExecuteAffrows(); - Assert.Equal(2, g.dameng.Select().Where(a => a.name.StartsWith("name")).ToDelete().ExecuteAffrows()); - Assert.Equal(3, g.dameng.Select().Count()); - Assert.Equal(3, g.dameng.Select().Where(a => a.name.StartsWith("nick")).Count()); - - g.dameng.Select().ToDelete().ExecuteAffrows(); - Assert.Equal(0, g.dameng.Select().Count()); - g.dameng.Insert(new[] { - new ToDel3Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = 1, pk3 = "pk3", name = "name1"}, - new ToDel3Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = 1, pk3 = "pk3", name = "name2"}, - new ToDel3Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = 1, pk3 = "pk3", name = "nick1"}, - new ToDel3Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = 1, pk3 = "pk3", name = "nick2"}, - new ToDel3Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = 1, pk3 = "pk3", name = "nick3"} - }).ExecuteAffrows(); - Assert.Equal(2, g.dameng.Select().Where(a => a.name.StartsWith("name")).ToDelete().ExecuteAffrows()); - Assert.Equal(3, g.dameng.Select().Count()); - Assert.Equal(3, g.dameng.Select().Where(a => a.name.StartsWith("nick")).Count()); - } - - public class ToUpd1Pk - { - [Column(IsIdentity = true)] - public int id { get; set; } - public string name { get; set; } - } - public class ToUpd2Pk - { - [Column(IsPrimary = true)] - public Guid pk1 { get; set; } - [Column(IsPrimary = true)] - public string pk2 { get; set; } - public string name { get; set; } - } - public class ToUpd3Pk - { - [Column(IsPrimary = true)] - public Guid pk1 { get; set; } - [Column(IsPrimary = true)] - public int pk2 { get; set; } - [Column(IsPrimary = true)] - public string pk3 { get; set; } - public string name { get; set; } - } - [Fact] - public void ToUpdate() - { - g.dameng.Select().ToDelete().ExecuteAffrows(); - Assert.Equal(0, g.dameng.Select().Count()); - g.dameng.Insert(new[] { - new ToUpd1Pk{ name = "name1"}, - new ToUpd1Pk{ name = "name2"}, - new ToUpd1Pk{ name = "nick1"}, - new ToUpd1Pk{ name = "nick2"}, - new ToUpd1Pk{ name = "nick3"} - }).ExecuteAffrows(); - Assert.Equal(2, g.dameng.Select().Where(a => a.name.StartsWith("name")).ToUpdate().Set(a => a.name, "nick?").ExecuteAffrows()); - Assert.Equal(5, g.dameng.Select().Count()); - Assert.Equal(5, g.dameng.Select().Where(a => a.name.StartsWith("nick")).Count()); - - g.dameng.Select().ToDelete().ExecuteAffrows(); - Assert.Equal(0, g.dameng.Select().Count()); - g.dameng.Insert(new[] { - new ToUpd2Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = "pk2", name = "name1"}, - new ToUpd2Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = "pk2", name = "name2"}, - new ToUpd2Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = "pk2", name = "nick1"}, - new ToUpd2Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = "pk2", name = "nick2"}, - new ToUpd2Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = "pk2", name = "nick3"} - }).ExecuteAffrows(); - Assert.Equal(2, g.dameng.Select().Where(a => a.name.StartsWith("name")).ToUpdate().Set(a => a.name, "nick?").ExecuteAffrows()); - Assert.Equal(5, g.dameng.Select().Count()); - Assert.Equal(5, g.dameng.Select().Where(a => a.name.StartsWith("nick")).Count()); - - g.dameng.Select().ToDelete().ExecuteAffrows(); - Assert.Equal(0, g.dameng.Select().Count()); - g.dameng.Insert(new[] { - new ToUpd3Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = 1, pk3 = "pk3", name = "name1"}, - new ToUpd3Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = 1, pk3 = "pk3", name = "name2"}, - new ToUpd3Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = 1, pk3 = "pk3", name = "nick1"}, - new ToUpd3Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = 1, pk3 = "pk3", name = "nick2"}, - new ToUpd3Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = 1, pk3 = "pk3", name = "nick3"} - }).ExecuteAffrows(); - Assert.Equal(2, g.dameng.Select().Where(a => a.name.StartsWith("name")).ToUpdate().Set(a => a.name, "nick?").ExecuteAffrows()); - Assert.Equal(5, g.dameng.Select().Count()); - Assert.Equal(5, g.dameng.Select().Where(a => a.name.StartsWith("nick")).Count()); - } - - [Fact] - public void ForUpdate() - { - var orm = g.dameng; - - Assert.Equal("安全起见,请务必在事务开启之后,再使用 ForUpdate", - Assert.Throws(() => orm.Select().ForUpdate().Limit(1).ToList())?.Message); - - orm.Transaction(() => - { - var sql = orm.Select().ForUpdate().Limit(1).ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"NAME\" FROM \"TOUPD1PK\" a WHERE ROWNUM < 2 for update", sql); - orm.Select().ForUpdate().Limit(1).ToList(); - - sql = orm.Select().ForUpdate(true).Limit(1).ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"NAME\" FROM \"TOUPD1PK\" a WHERE ROWNUM < 2 for update nowait", sql); - orm.Select().ForUpdate(true).Limit(1).ToList(); - }); - } - - [Fact] - public void ToTreeList() - { - var fsql = g.dameng; - fsql.Delete().Where("1=1").ExecuteAffrows(); - var repo = fsql.GetRepository(); - repo.DbContextOptions.EnableCascadeSave = true; - repo.DbContextOptions.NoneParameter = true; - repo.Insert(new VM_District_Child - { - Code = "100000", - Name = "中国", - Childs = new List(new[] { - new VM_District_Child - { - Code = "110000", - Name = "北京", - Childs = new List(new[] { - new VM_District_Child{ Code="110100", Name = "北京市" }, - new VM_District_Child{ Code="110101", Name = "东城区" }, - }) - } - }) - }); - - var t1 = fsql.Select() - .InnerJoin(a => a.ParentCode == a.Parent.Code) - .Where(a => a.Code == "110101") - .ToList(true); - Assert.Single(t1); - Assert.Equal("110101", t1[0].Code); - Assert.NotNull(t1[0].Parent); - Assert.Equal("110000", t1[0].Parent.Code); - - var t2 = fsql.Select() - .InnerJoin(a => a.ParentCode == a.Parent.Code) - .InnerJoin(a => a.Parent.ParentCode == a.Parent.Parent.Code) - .Where(a => a.Code == "110101") - .ToList(true); - Assert.Single(t2); - Assert.Equal("110101", t2[0].Code); - Assert.NotNull(t2[0].Parent); - Assert.Equal("110000", t2[0].Parent.Code); - Assert.NotNull(t2[0].Parent.Parent); - Assert.Equal("100000", t2[0].Parent.Parent.Code); - - var t3 = fsql.Select().ToTreeList(); - Assert.Single(t3); - Assert.Equal("100000", t3[0].Code); - Assert.Single(t3[0].Childs); - Assert.Equal("110000", t3[0].Childs[0].Code); - Assert.Equal(2, t3[0].Childs[0].Childs.Count); - Assert.Equal("110100", t3[0].Childs[0].Childs[0].Code); - Assert.Equal("110101", t3[0].Childs[0].Childs[1].Code); - - t3 = fsql.Select().Where(a => a.Name == "中国").AsTreeCte().OrderBy(a => a.Code).ToTreeList(); - Assert.Single(t3); - Assert.Equal("100000", t3[0].Code); - Assert.Single(t3[0].Childs); - Assert.Equal("110000", t3[0].Childs[0].Code); - Assert.Equal(2, t3[0].Childs[0].Childs.Count); - Assert.Equal("110100", t3[0].Childs[0].Childs[0].Code); - Assert.Equal("110101", t3[0].Childs[0].Childs[1].Code); - - t3 = fsql.Select().Where(a => a.Name == "中国").AsTreeCte().OrderBy(a => a.Code).ToList(); - Assert.Equal(4, t3.Count); - Assert.Equal("100000", t3[0].Code); - Assert.Equal("110000", t3[1].Code); - Assert.Equal("110100", t3[2].Code); - Assert.Equal("110101", t3[3].Code); - - t3 = fsql.Select().Where(a => a.Name == "北京").AsTreeCte().OrderBy(a => a.Code).ToList(); - Assert.Equal(3, t3.Count); - Assert.Equal("110000", t3[0].Code); - Assert.Equal("110100", t3[1].Code); - Assert.Equal("110101", t3[2].Code); - - var t4 = fsql.Select().Where(a => a.Name == "中国").AsTreeCte(a => a.Name).OrderBy(a => a.Code) - .ToList(a => new { item = a, level = Convert.ToInt32("a.cte_level"), path = "a.cte_path" }); - Assert.Equal(4, t4.Count); - Assert.Equal("100000", t4[0].item.Code); - Assert.Equal("110000", t4[1].item.Code); - Assert.Equal("110100", t4[2].item.Code); - Assert.Equal("110101", t4[3].item.Code); - Assert.Equal("中国", t4[0].path); - Assert.Equal("中国 -> 北京", t4[1].path); - Assert.Equal("中国 -> 北京 -> 北京市", t4[2].path); - Assert.Equal("中国 -> 北京 -> 东城区", t4[3].path); - - t4 = fsql.Select().Where(a => a.Name == "中国").AsTreeCte(a => a.Name + "[" + a.Code + "]").OrderBy(a => a.Code) - .ToList(a => new { item = a, level = Convert.ToInt32("a.cte_level"), path = "a.cte_path" }); - Assert.Equal(4, t4.Count); - Assert.Equal("100000", t4[0].item.Code); - Assert.Equal("110000", t4[1].item.Code); - Assert.Equal("110100", t4[2].item.Code); - Assert.Equal("110101", t4[3].item.Code); - Assert.Equal("中国[100000]", t4[0].path); - Assert.Equal("中国[100000] -> 北京[110000]", t4[1].path); - Assert.Equal("中国[100000] -> 北京[110000] -> 北京市[110100]", t4[2].path); - Assert.Equal("中国[100000] -> 北京[110000] -> 东城区[110101]", t4[3].path); - - var select = fsql.Select() - .Where(a => a.Name == "中国") - .AsTreeCte() - //.OrderBy("a.cte_level desc") //递归层级 - ; - // var list = select.ToList(); //自己调试看查到的数据 - select.ToUpdate().Set(a => a.testint, 855).ExecuteAffrows(); - Assert.Equal(855, fsql.Select() - .Where(a => a.Name == "中国") - .AsTreeCte().Distinct().First(a => a.testint)); - - Assert.Equal(4, select.ToDelete().ExecuteAffrows()); - Assert.False(fsql.Select() - .Where(a => a.Name == "中国") - .AsTreeCte().Any()); - } - - [Table(Name = "D_District")] - public class BaseDistrict - { - [Column(IsPrimary = true, StringLength = 6)] - public string Code { get; set; } - - [Column(StringLength = 20, IsNullable = false)] - public string Name { get; set; } - - [Column(StringLength = 6)] - public virtual string ParentCode { get; set; } - - public int testint { get; set; } - } - [Table(Name = "D_District", DisableSyncStructure = true)] - public class VM_District_Child : BaseDistrict - { - public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; } - - [Navigate(nameof(ParentCode))] - public List Childs { get; set; } - } - [Table(Name = "D_District", DisableSyncStructure = true)] - public class VM_District_Parent : BaseDistrict - { - public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; } - - [Navigate(nameof(ParentCode))] - public VM_District_Parent Parent { get; set; } - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengUpdateTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengUpdateTest.cs deleted file mode 100644 index 54b4ac9a4..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/Curd/DamengUpdateTest.cs +++ /dev/null @@ -1,190 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using Xunit; - -namespace FreeSql.Tests.Odbc.Dameng -{ - public class DamengUpdateTest - { - IUpdate update => g.dameng.Update(); - - [Table(Name = "tb_topic")] - class Topic - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int? Clicks { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - - [Fact] - public void Dywhere() - { - Assert.Null(g.dameng.Update().ToSql()); - Assert.Equal("UPDATE \"TB_TOPIC\" SET title='test' \r\nWHERE (\"ID\" IN (1,2))", g.dameng.Update(new[] { 1, 2 }).SetRaw("title='test'").ToSql()); - Assert.Equal("UPDATE \"TB_TOPIC\" SET title='test1' \r\nWHERE (\"ID\" = 1)", g.dameng.Update(new Topic { Id = 1, Title = "test" }).SetRaw("title='test1'").ToSql()); - Assert.Equal("UPDATE \"TB_TOPIC\" SET title='test1' \r\nWHERE (\"ID\" IN (1,2))", g.dameng.Update(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).SetRaw("title='test1'").ToSql()); - Assert.Equal("UPDATE \"TB_TOPIC\" SET title='test1' \r\nWHERE (\"ID\" = 1)", g.dameng.Update(new { id = 1 }).SetRaw("title='test1'").ToSql()); - } - - [Fact] - public void SetSource() - { - var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = NULL, \"TITLE\" = 'newtitle', \"CREATETIME\" = to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') WHERE (\"ID\" = 1)", sql); - - var items = new List(); - for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 }); - items[0].Clicks = null; - - sql = update.SetSource(items).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = CASE \"ID\" WHEN 1 THEN NULL WHEN 2 THEN 100 WHEN 3 THEN 200 WHEN 4 THEN 300 WHEN 5 THEN 400 WHEN 6 THEN 500 WHEN 7 THEN 600 WHEN 8 THEN 700 WHEN 9 THEN 800 WHEN 10 THEN 900 END, \"TITLE\" = CASE \"ID\" WHEN 1 THEN 'newtitle0' WHEN 2 THEN 'newtitle1' WHEN 3 THEN 'newtitle2' WHEN 4 THEN 'newtitle3' WHEN 5 THEN 'newtitle4' WHEN 6 THEN 'newtitle5' WHEN 7 THEN 'newtitle6' WHEN 8 THEN 'newtitle7' WHEN 9 THEN 'newtitle8' WHEN 10 THEN 'newtitle9' END, \"CREATETIME\" = to_timestamp('0001-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') WHERE (\"ID\" IN (1,2,3,4,5,6,7,8,9,10))", sql); - - sql = update.SetSource(items).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"TITLE\" = CASE \"ID\" WHEN 1 THEN 'newtitle0' WHEN 2 THEN 'newtitle1' WHEN 3 THEN 'newtitle2' WHEN 4 THEN 'newtitle3' WHEN 5 THEN 'newtitle4' WHEN 6 THEN 'newtitle5' WHEN 7 THEN 'newtitle6' WHEN 8 THEN 'newtitle7' WHEN 9 THEN 'newtitle8' WHEN 10 THEN 'newtitle9' END WHERE (\"ID\" IN (1,2,3,4,5,6,7,8,9,10))", sql); - - sql = update.SetSource(items).Set(a => a.CreateTime, new DateTime(2020, 1, 1)).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CREATETIME\" = to_timestamp('2020-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') WHERE (\"ID\" IN (1,2,3,4,5,6,7,8,9,10))", sql); - - if (g.dameng.Select().Where(a => a.id1 == 1 && a.id2 == 7).Any() == false) - g.dameng.Insert(new ts_source_mpk { id1 = 1, id2 = 7 }).ExecuteAffrows(); - if (g.dameng.Select().Where(a => a.id1 == 1 && a.id2 == 8).Any() == false) - g.dameng.Insert(new ts_source_mpk { id1 = 1, id2 = 8 }).ExecuteAffrows(); - - sql = g.dameng.Update().SetSource(new[] { - new ts_source_mpk { id1 = 1, id2 = 7, xx = "a1" }, - new ts_source_mpk { id1 = 1, id2 = 8, xx = "b122" } - }).NoneParameter().ToSql().Replace("\r\n", ""); - g.dameng.Update().SetSource(new[] { - new ts_source_mpk { id1 = 1, id2 = 7, xx = "a1" }, - new ts_source_mpk { id1 = 1, id2 = 8, xx = "b122" } - }).NoneParameter().ExecuteAffrows(); - var testlist = g.dameng.Select().ToList(); - } - public class ts_source_mpk - { - [Column(IsPrimary = true)] - public int id1 { get; set; } - [Column(IsPrimary = true)] - public int id2 { get; set; } - public string xx { get; set; } - } - [Fact] - public void SetSourceIgnore() - { - Assert.Equal("UPDATE \"TSSI01\" SET \"TINT\" = 10 WHERE (\"ID\" = '00000000-0000-0000-0000-000000000000')", - g.dameng.Update().NoneParameter() - .SetSourceIgnore(new tssi01 { id = Guid.Empty, tint = 10 }, col => col == null).ToSql().Replace("\r\n", "")); - } - public class tssi01 - { - [Column(CanUpdate = false)] - public Guid id { get; set; } - public int tint { get; set; } - public string title { get; set; } - } - [Fact] - public void IgnoreColumns() - { - var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"TITLE\" = 'newtitle' WHERE (\"ID\" = 1)", sql); - } - [Fact] - public void UpdateColumns() - { - var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).UpdateColumns(a => a.Title).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"TITLE\" = 'newtitle' WHERE (\"ID\" = 1)", sql); - } - [Fact] - public void Set() - { - var sql = update.Where(a => a.Id == 1).Set(a => a.Title, "newtitle").ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"TITLE\" = 'newtitle' WHERE (\"ID\" = 1)", sql); - - sql = update.Where(a => a.Id == 1).Set(a => a.Title, "newtitle").Set(a => a.CreateTime, new DateTime(2020, 1, 1)).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"TITLE\" = 'newtitle', \"CREATETIME\" = to_timestamp('2020-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') WHERE (\"ID\" = 1)", sql); - - sql = update.Set(a => a.Clicks * 10 / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = trunc(nvl(\"CLICKS\", 0) * 10 / 1) WHERE (\"ID\" = 1)", sql); - - sql = update.Set(a => a.Id - 10).Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"ID\" = (\"ID\" - 10) WHERE (\"ID\" = 1)", sql); - - int incrv = 10; - sql = update.Set(a => a.Clicks * incrv / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = trunc(nvl(\"CLICKS\", 0) * 10 / 1) WHERE (\"ID\" = 1)", sql); - - sql = update.Set(a => a.Id - incrv).Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"ID\" = (\"ID\" - 10) WHERE (\"ID\" = 1)", sql); - - sql = update.Set(a => a.Clicks == a.Clicks * 10 / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = trunc(\"CLICKS\" * 10 / 1) WHERE (\"ID\" = 1)", sql); - - var dt2000 = DateTime.Parse("2000-01-01"); - sql = update.Set(a => a.Clicks == (a.CreateTime > dt2000 ? 1 : 2)).Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = case when \"CREATETIME\" > to_timestamp('2000-01-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6') then 1 else 2 end WHERE (\"ID\" = 1)", sql); - - sql = update.Set(a => a.Id == 10).Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"ID\" = 10 WHERE (\"ID\" = 1)", sql); - - sql = update.Set(a => a.Clicks == null).Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = NULL WHERE (\"ID\" = 1)", sql); - } - [Fact] - public void SetRaw() - { - var sql = update.Where(a => a.Id == 1).SetRaw("clicks = clicks + ?", new { incrClick = 1 }).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET clicks = clicks + ? WHERE (\"ID\" = 1)", sql); - } - [Fact] - public void SetDto() - { - var sql = update.SetDto(new { clicks = 1, title = "xxx" }).Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = 1, \"TITLE\" = 'xxx' WHERE (\"ID\" = 1)", sql); - - sql = update.SetDto(new Dictionary { ["clicks"] = 1, ["title"] = "xxx" }).Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = 1, \"TITLE\" = 'xxx' WHERE (\"ID\" = 1)", sql); - } - [Fact] - public void Where() - { - var sql = update.Where(a => a.Id == 1).SetRaw("title='newtitle'").ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET title='newtitle' WHERE (\"ID\" = 1)", sql); - - sql = update.Where("id = ?", new { id = 1 }).SetRaw("title='newtitle'").ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET title='newtitle' WHERE (id = ?)", sql); - - var item = new Topic { Id = 1, Title = "newtitle" }; - sql = update.Where(item).SetRaw("title='newtitle'").ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET title='newtitle' WHERE (\"ID\" = 1)", sql); - - var items = new List(); - for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 }); - sql = update.Where(items).SetRaw("title='newtitle'").ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET title='newtitle' WHERE (\"ID\" IN (1,2,3,4,5,6,7,8,9,10))", sql); - } - [Fact] - public void ExecuteAffrows() - { - - } - [Fact] - public void ExecuteUpdated() - { - - } - - [Fact] - public void AsTable() - { - Assert.Null(g.dameng.Update().ToSql()); - Assert.Equal("UPDATE \"TB_TOPICASTABLE\" SET title='test' \r\nWHERE (\"ID\" IN (1,2))", g.dameng.Update(new[] { 1, 2 }).SetRaw("title='test'").AsTable(a => "tb_topicAsTable").ToSql()); - Assert.Equal("UPDATE \"TB_TOPICASTABLE\" SET title='test1' \r\nWHERE (\"ID\" = 1)", g.dameng.Update(new Topic { Id = 1, Title = "test" }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql()); - Assert.Equal("UPDATE \"TB_TOPICASTABLE\" SET title='test1' \r\nWHERE (\"ID\" IN (1,2))", g.dameng.Update(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql()); - Assert.Equal("UPDATE \"TB_TOPICASTABLE\" SET title='test1' \r\nWHERE (\"ID\" = 1)", g.dameng.Update(new { id = 1 }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql()); - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengAdo/DamengAdoTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengAdo/DamengAdoTest.cs deleted file mode 100644 index 43f8191a8..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengAdo/DamengAdoTest.cs +++ /dev/null @@ -1,71 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using Xunit; - -namespace FreeSql.Tests.Odbc.Dameng -{ - public class DamengAdoTest - { - [Fact] - public void Pool() - { - var t1 = g.dameng.Ado.MasterPool.StatisticsFullily; - } - - [Fact] - public void SlavePools() - { - var t2 = g.dameng.Ado.SlavePools.Count; - } - - [Fact] - public void ExecuteTest() - { - Assert.True(g.dameng.Ado.ExecuteConnectTest()); - } - [Fact] - public void ExecuteReader() - { - - } - [Fact] - public void ExecuteArray() - { - - } - [Fact] - public void ExecuteNonQuery() - { - - } - [Fact] - public void ExecuteScalar() - { - - } - - [Fact] - public void Query() - { - - var t3 = g.dameng.Ado.Query("select * from \"TB_TOPIC\""); - - var t4 = g.dameng.Ado.Query<(int, string, string)>("select * from \"TB_TOPIC\""); - - var t5 = g.dameng.Ado.Query("select * from \"TB_TOPIC\""); - } - - [Fact] - public void QueryMultipline() - { - //var t3 = g.dameng.Ado.Query("select * from \"TB_TOPIC\"; select * from \"TB_TOPIC\"; select * from \"TB_TOPIC\""); - } - - class xxx - { - public int Id { get; set; } - public string Path { get; set; } - public string Title2 { get; set; } - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengAopTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengAopTest.cs deleted file mode 100644 index a297e27c5..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengAopTest.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Text; -using Xunit; - -namespace FreeSql.Tests.Odbc.Dameng -{ - public class DamengAopTest - { - - class TestAuditValue - { - public Guid id { get; set; } - [Now] - public DateTime createtime { get; set; } - } - class NowAttribute: Attribute { } - - [Fact] - public void AuditValue() - { - var date = DateTime.Now.Date; - var item = new TestAuditValue(); - - EventHandler audit = (s, e) => - { - if (e.Property.GetCustomAttribute(false) != null) - e.Value = DateTime.Now.Date; - }; - g.dameng.Aop.AuditValue += audit; - - g.dameng.Insert(item).ExecuteAffrows(); - - g.dameng.Aop.AuditValue -= audit; - - Assert.Equal(item.createtime, date); - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengCodeFirstTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengCodeFirstTest.cs deleted file mode 100644 index 5ec983e90..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengCodeFirstTest.cs +++ /dev/null @@ -1,328 +0,0 @@ -using FreeSql.DataAnnotations; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Xunit; - -namespace FreeSql.Tests.Odbc.Dameng -{ - public class DamengCodeFirstTest - { - [Fact] - public void Test_0String() - { - var fsql = g.dameng; - fsql.Delete().Where("1=1").ExecuteAffrows(); - - Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).ExecuteAffrows()); - Assert.Equal(1, fsql.Insert(new test_0string01 { name = @"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000" }).NoneParameter().ExecuteAffrows()); - - var list = fsql.Select().ToList(); - Assert.Equal(2, list.Count); - Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[0].name); - Assert.Equal(@"1.0000\0.0000\0.0000\0.0000\1.0000\0.0000", list[1].name); - } - class test_0string01 - { - public Guid id { get; set; } - public string name { get; set; } - } - - [Fact] - public void StringLength() - { - var dll = g.dameng.CodeFirst.GetComparisonDDLStatements(); - g.dameng.CodeFirst.SyncStructure(); - } - class TS_SLTB - { - public Guid Id { get; set; } - [Column(StringLength = 50)] - public string Title { get; set; } - - [Column(IsNullable = false, StringLength = 50)] - public string TitleSub { get; set; } - } - - [Fact] - public void 数字表_字段() - { - var sql = g.dameng.CodeFirst.GetComparisonDDLStatements<测试数字表>(); - g.dameng.CodeFirst.SyncStructure<测试数字表>(); - - var item = new 测试数字表 - { - 标题 = "测试标题", - 创建时间 = DateTime.Now - }; - Assert.Equal(1, g.dameng.Insert<测试数字表>().AppendData(item).ExecuteAffrows()); - Assert.NotEqual(Guid.Empty, item.编号); - var item2 = g.dameng.Select<测试数字表>().Where(a => a.编号 == item.编号).First(); - Assert.NotNull(item2); - Assert.Equal(item.编号, item2.编号); - Assert.Equal(item.标题, item2.标题); - - item.标题 = "测试标题更新"; - Assert.Equal(1, g.dameng.Update<测试数字表>().SetSource(item).ExecuteAffrows()); - item2 = g.dameng.Select<测试数字表>().Where(a => a.编号 == item.编号).First(); - Assert.NotNull(item2); - Assert.Equal(item.编号, item2.编号); - Assert.Equal(item.标题, item2.标题); - - item.标题 = "测试标题更新_repo"; - var repo = g.dameng.GetRepository<测试数字表>(); - Assert.Equal(1, repo.Update(item)); - item2 = g.dameng.Select<测试数字表>().Where(a => a.编号 == item.编号).First(); - Assert.NotNull(item2); - Assert.Equal(item.编号, item2.编号); - Assert.Equal(item.标题, item2.标题); - - item.标题 = "测试标题更新_repo22"; - Assert.Equal(1, repo.Update(item)); - item2 = g.dameng.Select<测试数字表>().Where(a => a.编号 == item.编号).First(); - Assert.NotNull(item2); - Assert.Equal(item.编号, item2.编号); - Assert.Equal(item.标题, item2.标题); - } - [Table(Name = "123测试数字表")] - class 测试数字表 - { - [Column(IsPrimary = true, Name = "123编号")] - public Guid 编号 { get; set; } - - [Column(Name = "123标题")] - public string 标题 { get; set; } - - [Column(Name = "123创建时间")] - public DateTime 创建时间 { get; set; } - } - - [Fact] - public void 中文表_字段() - { - var sql = g.dameng.CodeFirst.GetComparisonDDLStatements<测试中文表>(); - g.dameng.CodeFirst.SyncStructure<测试中文表>(); - - var item = new 测试中文表 - { - 标题 = "测试标题", - 创建时间 = DateTime.Now - }; - Assert.Equal(1, g.dameng.Insert<测试中文表>().AppendData(item).ExecuteAffrows()); - Assert.NotEqual(Guid.Empty, item.编号); - var item2 = g.dameng.Select<测试中文表>().Where(a => a.编号 == item.编号).First(); - Assert.NotNull(item2); - Assert.Equal(item.编号, item2.编号); - Assert.Equal(item.标题, item2.标题); - - item.标题 = "测试标题更新"; - Assert.Equal(1, g.dameng.Update<测试中文表>().SetSource(item).ExecuteAffrows()); - item2 = g.dameng.Select<测试中文表>().Where(a => a.编号 == item.编号).First(); - Assert.NotNull(item2); - Assert.Equal(item.编号, item2.编号); - Assert.Equal(item.标题, item2.标题); - - item.标题 = "测试标题更新_repo"; - var repo = g.dameng.GetRepository<测试中文表>(); - Assert.Equal(1, repo.Update(item)); - item2 = g.dameng.Select<测试中文表>().Where(a => a.编号 == item.编号).First(); - Assert.NotNull(item2); - Assert.Equal(item.编号, item2.编号); - Assert.Equal(item.标题, item2.标题); - - item.标题 = "测试标题更新_repo22"; - Assert.Equal(1, repo.Update(item)); - item2 = g.dameng.Select<测试中文表>().Where(a => a.编号 == item.编号).First(); - Assert.NotNull(item2); - Assert.Equal(item.编号, item2.编号); - Assert.Equal(item.标题, item2.标题); - } - class 测试中文表 - { - [Column(IsPrimary = true)] - public Guid 编号 { get; set; } - - public string 标题 { get; set; } - - public DateTime 创建时间 { get; set; } - } - - [Fact] - public void AddUniques() - { - var sql = g.dameng.CodeFirst.GetComparisonDDLStatements(); - g.dameng.CodeFirst.SyncStructure(); - g.dameng.CodeFirst.SyncStructure(typeof(AddUniquesInfo), "AddUniquesInf1"); - } - [Table(Name = "AddUniquesInf", OldName = "AddUniquesInfo2")] - [Index("{tablename}_uk_phone", "phone", true)] - [Index("{tablename}_uk_group_index", "group,index", true)] - [Index("{tablename}_uk_group_index22", "group, index22", true)] - class AddUniquesInfo - { - public Guid id { get; set; } - public string phone { get; set; } - - public string group { get; set; } - public int index { get; set; } - public string index22 { get; set; } - } - [Fact] - public void AddField() - { - var sql = g.dameng.CodeFirst.GetComparisonDDLStatements(); - - var id = g.dameng.Insert().AppendData(new TopicAddField { }).ExecuteIdentity(); - - //var inserted = g.dameng.Insert().AppendData(new TopicAddField { }).ExecuteInserted(); - } - - [Table(Name = "TopicAddField", OldName = "xxxtb.TopicAddField")] - public class TopicAddField - { - [Column(IsIdentity = true)] - public int Id { get; set; } - - public string name { get; set; } - - [Column(DbType = "varchar2(200) not null", OldName = "title")] - public string title2 { get; set; } = "10"; - - [Column(IsIgnore = true)] - public DateTime ct { get; set; } = DateTime.Now; - } - - [Fact] - public void GetComparisonDDLStatements() - { - - var sql = g.dameng.CodeFirst.GetComparisonDDLStatements(); - Assert.True(string.IsNullOrEmpty(sql)); //测试运行两次后 - //sql = g.dameng.CodeFirst.GetComparisonDDLStatements(); - } - - IInsert insert => g.dameng.Insert(); - ISelect select => g.dameng.Select(); - - [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, - BoolNullable = true, - Byte = 255, - ByteNullable = 127, - Bytes = Encoding.UTF8.GetBytes("我是中国人"), - DateTime = DateTime.Now, - DateTimeNullable = DateTime.Now.AddHours(-1), - Decimal = 99.99M, - DecimalNullable = 99.98M, - Double = 999.99, - DoubleNullable = 999.98, - Enum1 = TableAllTypeEnumType1.e5, - Enum1Nullable = TableAllTypeEnumType1.e3, - Enum2 = TableAllTypeEnumType2.f2, - Enum2Nullable = TableAllTypeEnumType2.f3, - Float = 19.99F, - FloatNullable = 19.98F, - Guid = Guid.NewGuid(), - GuidNullable = Guid.NewGuid(), - Int = int.MaxValue, - IntNullable = int.MinValue, - SByte = 100, - SByteNullable = 99, - Short = short.MaxValue, - ShortNullable = short.MinValue, - String = "我是中国人string'\\?!@#$%^&*()_+{}}{~?><<>", - Char = 'X', - TimeSpan = TimeSpan.FromSeconds(999), - TimeSpanNullable = TimeSpan.FromSeconds(60), - UInt = uint.MaxValue, - UIntNullable = uint.MinValue, - ULong = ulong.MaxValue, - ULongNullable = ulong.MinValue, - UShort = ushort.MaxValue, - UShortNullable = ushort.MinValue, - testFielLongNullable = long.MinValue - }; - var sqlPar = insert.AppendData(item2).ToSql(); - var sqlText = insert.AppendData(item2).NoneParameter().ToSql(); - var item3NP = insert.AppendData(item2).NoneParameter().ExecuteIdentity(); - - item2.Id = (int)insert.AppendData(item2).ExecuteIdentity(); - var newitem2 = select.Where(a => a.Id == item2.Id).ToOne(); - Assert.Equal(item2.String, newitem2.String); - Assert.Equal(item2.Char, newitem2.Char); - - item2.Id = (int)insert.NoneParameter().AppendData(item2).ExecuteIdentity(); - newitem2 = select.Where(a => a.Id == item2.Id).ToOne(); - Assert.Equal(item2.String, newitem2.String); - Assert.Equal(item2.Char, newitem2.Char); - - var items = select.ToList(); - var itemstb = select.ToDataTable(); - } - - [Table(Name = "tb_alltype")] - class TableAllType - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - - public string id2 { get; set; } = "id2=10"; - - public bool Bool { get; set; } - public sbyte SByte { get; set; } - public short Short { get; set; } - public int Int { get; set; } - public long Long { get; set; } - public byte Byte { get; set; } - public ushort UShort { get; set; } - public uint UInt { get; set; } - public ulong ULong { get; set; } - public double Double { get; set; } - public float Float { get; set; } - public decimal Decimal { get; set; } - public TimeSpan TimeSpan { get; set; } - public DateTime DateTime { get; set; } - public DateTime DateTimeOffSet { get; set; } - public byte[] Bytes { get; set; } - public string String { get; set; } - public char Char { get; set; } - public Guid Guid { get; set; } - - public bool? BoolNullable { get; set; } - public sbyte? SByteNullable { get; set; } - public short? ShortNullable { get; set; } - public int? IntNullable { get; set; } - public long? testFielLongNullable { get; set; } - public byte? ByteNullable { get; set; } - public ushort? UShortNullable { get; set; } - public uint? UIntNullable { get; set; } - public ulong? ULongNullable { get; set; } - public double? DoubleNullable { get; set; } - public float? FloatNullable { get; set; } - public decimal? DecimalNullable { get; set; } - public TimeSpan? TimeSpanNullable { get; set; } - public DateTime? DateTimeNullable { get; set; } - public DateTime? DateTimeOffSetNullable { get; set; } - public Guid? GuidNullable { get; set; } - - public TableAllTypeEnumType1 Enum1 { get; set; } - public TableAllTypeEnumType1? Enum1Nullable { get; set; } - public TableAllTypeEnumType2 Enum2 { get; set; } - public TableAllTypeEnumType2? Enum2Nullable { get; set; } - } - - public enum TableAllTypeEnumType1 { e1, e2, e3, e5 } - [Flags] public enum TableAllTypeEnumType2 { f1, f2, f3 } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengDbFirstTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengDbFirstTest.cs deleted file mode 100644 index ee4a21196..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengDbFirstTest.cs +++ /dev/null @@ -1,65 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using Xunit; - -namespace FreeSql.Tests.Odbc.Dameng -{ - public class DamengDbFirstTest - { - [Fact] - public void GetDatabases() - { - var t1 = g.dameng.DbFirst.GetDatabases(); - } - - [Fact] - public void GetTablesByDatabase() - { - var t2 = g.dameng.DbFirst.GetTablesByDatabase(); - Assert.True(t2.Count > 0); - //var tb = g.dameng.Ado.ExecuteArray(System.Data.CommandType.Text, "select * from \"tb_dbfirst\""); - } - - [Fact] - public void GetTableByName() - { - var fsql = g.dameng; - var t1 = fsql.DbFirst.GetTableByName("tb_alltype"); - var t2 = fsql.DbFirst.GetTableByName("2user.tb_alltype"); - Assert.NotNull(t1); - Assert.NotNull(t2); - Assert.True(t1.Columns.Count > 0); - Assert.True(t2.Columns.Count > 0); - Assert.Equal(t1.Columns.Count, t2.Columns.Count); - var t3 = fsql.DbFirst.GetTableByName("notexists_tb"); - Assert.Null(t3); - } - - [Fact] - public void ExistsTable() - { - var fsql = g.dameng; - Assert.False(fsql.DbFirst.ExistsTable("test_existstb01")); - Assert.False(fsql.DbFirst.ExistsTable("1user.test_existstb01")); - Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false)); - Assert.False(fsql.DbFirst.ExistsTable("1user.test_existstb01", false)); - fsql.CodeFirst.SyncStructure(typeof(test_existstb01)); - Assert.True(fsql.DbFirst.ExistsTable("test_existstb01")); - Assert.True(fsql.DbFirst.ExistsTable("1user.test_existstb01")); - Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false)); - Assert.False(fsql.DbFirst.ExistsTable("1user.test_existstb01", false)); - fsql.Ado.ExecuteNonQuery("drop table test_existstb01"); - - Assert.False(fsql.DbFirst.ExistsTable("1user.test_existstb01")); - Assert.False(fsql.DbFirst.ExistsTable("1user.test_existstb01", false)); - fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "1user.test_existstb01"); - Assert.True(fsql.DbFirst.ExistsTable("1user.test_existstb01")); - Assert.False(fsql.DbFirst.ExistsTable("1user.test_existstb01", false)); - fsql.Ado.ExecuteNonQuery("drop table \"1USER\".test_existstb01"); - } - class test_existstb01 - { - public Guid id { get; set; } - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/ConvertTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/ConvertTest.cs deleted file mode 100644 index 2c513229a..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/ConvertTest.cs +++ /dev/null @@ -1,169 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.DamengExpression -{ - public class ConvertTest - { - - ISelect select => g.dameng.Select(); - - [Table(Name = "tb_topic")] - class Topic - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int Clicks { get; set; } - public int TypeGuid { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - class TestTypeInfo - { - public int Guid { get; set; } - public int ParentId { get; set; } - public TestTypeParentInfo Parent { get; set; } - public string Name { get; set; } - } - class TestTypeParentInfo - { - public int Id { get; set; } - public string Name { get; set; } - - public List Types { get; set; } - } - - [Fact] - public void ToBoolean() - { - var data = new List(); - //data.Add(select.Where(a => (Convert.ToBoolean(a.Clicks) ? 1 : 0) > 0).ToList()); - //data.Add(select.Where(a => (bool.Parse(a.Clicks.ToString()) ? 1 : 0) > 0).ToList()); - } - [Fact] - public void ToByte() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToByte(a.Clicks % 255) > 0).ToList()); - data.Add(select.Where(a => byte.Parse((a.Clicks % 255).ToString()) > 0).ToList()); - } - [Fact] - public void ToChar() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToChar(a.Clicks) == '1').ToList()); - data.Add(select.Where(a => char.Parse(a.Clicks.ToString()) == '1').ToList()); - } - [Fact] - public void ToDateTime() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToDateTime(a.CreateTime.ToString()).Year > 0).ToList()); - data.Add(select.Where(a => DateTime.Parse(a.CreateTime.ToString()).Year > 0).ToList()); - } - [Fact] - public void ToDecimal() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToDecimal(a.Clicks) > 0).ToList()); - data.Add(select.Where(a => decimal.Parse(a.Clicks.ToString()) > 0).ToList()); - } - [Fact] - public void ToDouble() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToDouble(a.Clicks) > 0).ToList()); - data.Add(select.Where(a => double.Parse(a.Clicks.ToString()) > 0).ToList()); - } - [Fact] - public void ToInt16() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToInt16(a.Clicks) > 0).ToList()); - data.Add(select.Where(a => short.Parse(a.Clicks.ToString()) > 0).ToList()); - } - [Fact] - public void ToInt32() - { - var data = new List(); - data.Add(select.Where(a => (int)a.Clicks > 0).ToList()); - data.Add(select.Where(a => Convert.ToInt32(a.Clicks) > 0).ToList()); - data.Add(select.Where(a => int.Parse(a.Clicks.ToString()) > 0).ToList()); - } - [Fact] - public void ToInt64() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToInt64(a.Clicks) > 0).ToList()); - data.Add(select.Where(a => long.Parse(a.Clicks.ToString()) > 0).ToList()); - } - [Fact] - public void ToSByte() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToSByte(a.Clicks % 128) > 0).ToList()); - data.Add(select.Where(a => sbyte.Parse((a.Clicks % 128).ToString()) > 0).ToList()); - } - [Fact] - public void ToSingle() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToSingle(a.Clicks) > 0).ToList()); - data.Add(select.Where(a => float.Parse(a.Clicks.ToString()) > 0).ToList()); - } - [Fact] - public void this_ToString() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToString(a.Clicks).Equals("")).ToList()); - data.Add(select.Where(a => a.Clicks.ToString().Equals("")).ToList()); - } - [Fact] - public void ToUInt16() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToUInt16(a.Clicks) > 0).ToList()); - data.Add(select.Where(a => ushort.Parse(a.Clicks.ToString()) > 0).ToList()); - } - [Fact] - public void ToUInt32() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToUInt32(a.Clicks) > 0).ToList()); - data.Add(select.Where(a => uint.Parse(a.Clicks.ToString()) > 0).ToList()); - } - [Fact] - public void ToUInt64() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToUInt64(a.Clicks) > 0).ToList()); - data.Add(select.Where(a => ulong.Parse(a.Clicks.ToString()) > 0).ToList()); - } - - [Fact] - public void Guid_Parse() - { - var data = new List(); - data.Add(select.Where(a => Guid.Parse(Guid.Empty.ToString()) == Guid.Empty).ToList()); - } - - [Fact] - public void Guid_NewGuid() - { - var data = new List(); - //data.Add(select.OrderBy(a => Guid.NewGuid()).Limit(10).ToList()); - } - - [Fact] - public void Random() - { - var data = new List(); - data.Add(select.OrderBy(a => new Random().Next()).Limit(10).ToList()); - data.Add(select.OrderBy(a => new Random().NextDouble()).Limit(10).ToList()); - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/DateTimeTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/DateTimeTest.cs deleted file mode 100644 index 18c4ae76d..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/DateTimeTest.cs +++ /dev/null @@ -1,732 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.DamengExpression -{ - public class DateTimeTest - { - - ISelect select => g.dameng.Select(); - - [Table(Name = "tb_topic111333")] - class Topic - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int Clicks { get; set; } - public int TypeGuid { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } = DateTime.Now; - } - [Table(Name = "TestTypeInfo333")] - class TestTypeInfo - { - [Column(IsIdentity = true)] - public int Guid { get; set; } - public int ParentId { get; set; } - public TestTypeParentInfo Parent { get; set; } - public string Name { get; set; } - public DateTime Time { get; set; } = DateTime.Now; - } - [Table(Name = "TestTypeParentInf1")] - class TestTypeParentInfo - { - public int Id { get; set; } - public string Name { get; set; } - - public List Types { get; set; } - public DateTime Time2 { get; set; } = DateTime.Now; - } - - [Fact] - public void this_ToString() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.ToString().Equals(DateTime.Now.ToString())).ToList()); - data.Add(select.Where(a => a.Type.Time.AddYears(1).ToString().Equals(DateTime.Now.ToString())).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).ToString().Equals(DateTime.Now.ToString())).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE ((date_format(a.`CreateTime`, '%Y-%m-%d %H:%i:%s.%f') = now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE ((date_format(date_add(a__Type.`Time`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE ((date_format(date_add(a__Type__Parent.`Time2`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now())) - - g.dameng.Insert(new Topic()).ExecuteAffrows(); - var dtn = DateTime.Parse("2020-1-1 0:0:0"); - var dts = Enumerable.Range(1, 12).Select(a => dtn.AddMonths(a)) - .Concat(Enumerable.Range(1, 31).Select(a => dtn.AddDays(a))) - .Concat(Enumerable.Range(1, 24).Select(a => dtn.AddHours(a))) - .Concat(Enumerable.Range(1, 60).Select(a => dtn.AddMinutes(a))) - .Concat(Enumerable.Range(1, 60).Select(a => dtn.AddSeconds(a))); - foreach (var dt in dts) - { - Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm:ss.ffffff"), select.First(a => dt.ToString())); - Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm:ss"), select.First(a => dt.ToString("yyyy-MM-dd HH:mm:ss"))); - Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm"), select.First(a => dt.ToString("yyyy-MM-dd HH:mm"))); - Assert.Equal(dt.ToString("yyyy-MM-dd HH"), select.First(a => dt.ToString("yyyy-MM-dd HH"))); - Assert.Equal(dt.ToString("yyyy-MM-dd"), select.First(a => dt.ToString("yyyy-MM-dd"))); - Assert.Equal(dt.ToString("yyyy-MM"), select.First(a => dt.ToString("yyyy-MM"))); - Assert.Equal(dt.ToString("yyyyMMddHHmmss"), select.First(a => dt.ToString("yyyyMMddHHmmss"))); - Assert.Equal(dt.ToString("yyyyMMddHHmm"), select.First(a => dt.ToString("yyyyMMddHHmm"))); - Assert.Equal(dt.ToString("yyyyMMddHH"), select.First(a => dt.ToString("yyyyMMddHH"))); - Assert.Equal(dt.ToString("yyyyMMdd"), select.First(a => dt.ToString("yyyyMMdd"))); - Assert.Equal(dt.ToString("yyyyMM"), select.First(a => dt.ToString("yyyyMM"))); - Assert.Equal(dt.ToString("yyyy"), select.First(a => dt.ToString("yyyy"))); - Assert.Equal(dt.ToString("HH:mm:ss"), select.First(a => dt.ToString("HH:mm:ss"))); - Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h"))); - Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s"))); - } - } - [Fact] - public void Now() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Date == DateTime.Now.Date).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(now(), '%Y-%m-%d') as datetime)) - } - [Fact] - public void UtcNow() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Date == DateTime.UtcNow.Date).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(utc_timestamp(), '%Y-%m-%d') as datetime)) - } - [Fact] - public void MinValue() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Date == DateTime.MinValue.Date).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(cast('0001/1/1 0:00:00' as datetime), '%Y-%m-%d') as datetime)) - } - [Fact] - public void MaxValue() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Date == DateTime.MaxValue.Date).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(cast('9999/12/31 23:59:59' as datetime), '%Y-%m-%d') as datetime)) - } - [Fact] - public void Date() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Date == DateTime.Now.Date).ToList()); - //data.Add(select.Where(a => a.Type.Time.Date > DateTime.Now.Date).ToList()); - //data.Add(select.Where(a => a.Type.Parent.Time2.Date > DateTime.Now.Date).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(now(), '%Y-%m-%d') as datetime)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (cast(date_format(a__Type.`Time`, '%Y-%m-%d') as datetime) > cast(date_format(now(), '%Y-%m-%d') as datetime)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (cast(date_format(a__Type__Parent.`Time2`, '%Y-%m-%d') as datetime) > cast(date_format(now(), '%Y-%m-%d') as datetime)); - //data.Add(select.Where(a => DateTime.Now.Subtract(a.CreateTime.Date).TotalSeconds > 0).ToList()); - //data.Add(select.Where(a => DateTime.Now.Subtract(a.Type.Time.Date).TotalSeconds > 0).ToList()); - //data.Add(select.Where(a => DateTime.Now.Subtract(a.Type.Parent.Time2.Date).TotalSeconds > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (((timestampdiff(microsecond, cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime), now())) / 1000000) > 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (((timestampdiff(microsecond, cast(date_format(a__Type.`Time`, '%Y-%m-%d') as datetime), now())) / 1000000) > 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (((timestampdiff(microsecond, cast(date_format(a__Type__Parent.`Time2`, '%Y-%m-%d') as datetime), now())) / 1000000) > 0) - } - [Fact] - public void TimeOfDay() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay == DateTime.Now.TimeOfDay).ToList()); - data.Add(select.Where(a => a.Type.Time.TimeOfDay > DateTime.Now.TimeOfDay).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.TimeOfDay > DateTime.Now.TimeOfDay).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (timestampdiff(microsecond, date_format(now(), '1970-1-1 %H:%i:%s.%f'), now()) + 62135596800000000)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE ((timestampdiff(microsecond, date_format(a__Type.`Time`, '1970-1-1 %H:%i:%s.%f'), a__Type.`Time`) + 62135596800000000) > (timestampdiff(microsecond, date_format(now(), '1970-1-1 %H:%i:%s.%f'), now()) + 62135596800000000)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE ((timestampdiff(microsecond, date_format(a__Type__Parent.`Time2`, '1970-1-1 %H:%i:%s.%f'), a__Type__Parent.`Time2`) + 62135596800000000) > (timestampdiff(microsecond, date_format(now(), '1970-1-1 %H:%i:%s.%f'), now()) + 62135596800000000)) - } - [Fact] - public void DayOfWeek() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.DayOfWeek > DateTime.Now.DayOfWeek).ToList()); - data.Add(select.Where(a => a.Type.Time.DayOfWeek > DateTime.Now.DayOfWeek).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.DayOfWeek > DateTime.Now.DayOfWeek).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE ((dayofweek(a.`CreateTime`) - 1) > (dayofweek(now()) - 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE ((dayofweek(a__Type.`Time`) - 1) > (dayofweek(now()) - 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE ((dayofweek(a__Type__Parent.`Time2`) - 1) > (dayofweek(now()) - 1)) - } - [Fact] - public void Day() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Day > DateTime.Now.Day).ToList()); - data.Add(select.Where(a => a.Type.Time.Day > DateTime.Now.Day).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.Day > DateTime.Now.Day).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (dayofmonth(a.`CreateTime`) > dayofmonth(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (dayofmonth(a__Type.`Time`) > dayofmonth(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (dayofmonth(a__Type__Parent.`Time2`) > dayofmonth(now())) - } - [Fact] - public void DayOfYear() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.DayOfYear > DateTime.Now.DayOfYear).ToList()); - data.Add(select.Where(a => a.Type.Time.DayOfYear > DateTime.Now.DayOfYear).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.DayOfYear > DateTime.Now.DayOfYear).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (dayofyear(a.`CreateTime`) > dayofyear(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (dayofyear(a__Type.`Time`) > dayofyear(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (dayofyear(a__Type__Parent.`Time2`) > dayofyear(now())) - } - [Fact] - public void Month() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Month > DateTime.Now.Month).ToList()); - data.Add(select.Where(a => a.Type.Time.Month > DateTime.Now.Month).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.Month > DateTime.Now.Month).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (month(a.`CreateTime`) > month(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (month(a__Type.`Time`) > month(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (month(a__Type__Parent.`Time2`) > month(now())) - } - [Fact] - public void Year() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Year > DateTime.Now.Year).ToList()); - data.Add(select.Where(a => a.Type.Time.Year > DateTime.Now.Year).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.Year > DateTime.Now.Year).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (year(a.`CreateTime`) > year(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (year(a__Type.`Time`) > year(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (year(a__Type__Parent.`Time2`) > year(now())) - } - [Fact] - public void Hour() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Hour > DateTime.Now.Hour).ToList()); - data.Add(select.Where(a => a.Type.Time.Hour > DateTime.Now.Hour).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.Hour > DateTime.Now.Hour).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (hour(a.`CreateTime`) > hour(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (hour(a__Type.`Time`) > hour(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (hour(a__Type__Parent.`Time2`) > hour(now())) - } - [Fact] - public void Minute() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Minute > DateTime.Now.Minute).ToList()); - data.Add(select.Where(a => a.Type.Time.Minute > DateTime.Now.Minute).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.Minute > DateTime.Now.Minute).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (minute(a.`CreateTime`) > minute(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (minute(a__Type.`Time`) > minute(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (minute(a__Type__Parent.`Time2`) > minute(now())) - } - [Fact] - public void Second() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Second > DateTime.Now.Second).ToList()); - data.Add(select.Where(a => a.Type.Time.Second > DateTime.Now.Second).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.Second > DateTime.Now.Second).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (second(a.`CreateTime`) > second(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (second(a__Type.`Time`) > second(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (second(a__Type__Parent.`Time2`) > second(now())) - } - [Fact] - public void Millisecond() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Millisecond > DateTime.Now.Millisecond).ToList()); - data.Add(select.Where(a => a.Type.Time.Millisecond > DateTime.Now.Millisecond).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.Millisecond > DateTime.Now.Millisecond).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (floor(microsecond(a.`CreateTime`) / 1000) > floor(microsecond(now()) / 1000)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (floor(microsecond(a__Type.`Time`) / 1000) > floor(microsecond(now()) / 1000)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (floor(microsecond(a__Type__Parent.`Time2`) / 1000) > floor(microsecond(now()) / 1000)) - } - [Fact] - public void Ticks() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Ticks > DateTime.Now.Ticks).ToList()); - data.Add(select.Where(a => a.Type.Time.Ticks > DateTime.Now.Ticks).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.Ticks > DateTime.Now.Ticks).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE ((timestampdiff(microsecond, '1970-1-1', a.`CreateTime`) * 10 + 621355968000000000) > (timestampdiff(microsecond, '1970-1-1', now()) * 10 + 621355968000000000)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE ((timestampdiff(microsecond, '1970-1-1', a__Type.`Time`) * 10 + 621355968000000000) > (timestampdiff(microsecond, '1970-1-1', now()) * 10 + 621355968000000000)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE ((timestampdiff(microsecond, '1970-1-1', a__Type__Parent.`Time2`) * 10 + 621355968000000000) > (timestampdiff(microsecond, '1970-1-1', now()) * 10 + 621355968000000000)) - } - [Fact] - public void Add() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Time.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (date_add(a.`CreateTime`, interval ((1 * 86400000000)) microsecond) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (date_add(a__Type.`Time`, interval ((1 * 86400000000)) microsecond) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (date_add(a__Type__Parent.`Time2`, interval ((1 * 86400000000)) microsecond) > now()) - } - [Fact] - public void AddDays() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.AddDays(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Time.AddDays(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddDays(1) > DateTime.Now).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (date_add(a.`CreateTime`, interval (1) day) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (date_add(a__Type.`Time`, interval (1) day) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (date_add(a__Type__Parent.`Time2`, interval (1) day) > now()) - } - [Fact] - public void AddHours() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.AddHours(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Time.AddHours(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddHours(1) > DateTime.Now).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (date_add(a.`CreateTime`, interval (1) hour) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (date_add(a__Type.`Time`, interval (1) hour) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (date_add(a__Type__Parent.`Time2`, interval (1) hour) > now()) - } - [Fact] - public void AddMilliseconds() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.AddMilliseconds(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Time.AddMilliseconds(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddMilliseconds(1) > DateTime.Now).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (date_add(a.`CreateTime`, interval (1) * 1000 microsecond) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (date_add(a__Type.`Time`, interval (1) * 1000 microsecond) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (date_add(a__Type__Parent.`Time2`, interval (1) * 1000 microsecond) > now()) - } - [Fact] - public void AddMinutes() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.AddMinutes(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Time.AddMinutes(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddMinutes(1) > DateTime.Now).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (date_add(a.`CreateTime`, interval (1) minute) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (date_add(a__Type.`Time`, interval (1) minute) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (date_add(a__Type__Parent.`Time2`, interval (1) minute) > now()) - } - [Fact] - public void AddMonths() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.AddMonths(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Time.AddMonths(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddMonths(1) > DateTime.Now).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (date_add(a.`CreateTime`, interval (1) month) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (date_add(a__Type.`Time`, interval (1) month) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (date_add(a__Type__Parent.`Time2`, interval (1) month) > now()) - } - [Fact] - public void AddSeconds() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.AddSeconds(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Time.AddSeconds(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddSeconds(1) > DateTime.Now).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (date_add(a.`CreateTime`, interval (1) second) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (date_add(a__Type.`Time`, interval (1) second) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (date_add(a__Type__Parent.`Time2`, interval (1) second) > now()) - } - [Fact] - public void AddTicks() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.AddTicks(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Time.AddTicks(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddTicks(1) > DateTime.Now).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (date_add(a.`CreateTime`, interval (1) / 10 microsecond) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (date_add(a__Type.`Time`, interval (1) / 10 microsecond) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (date_add(a__Type__Parent.`Time2`, interval (1) / 10 microsecond) > now()) - } - [Fact] - public void AddYears() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.AddYears(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Time.AddYears(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1) > DateTime.Now).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (date_add(a.`CreateTime`, interval (1) year) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (date_add(a__Type.`Time`, interval (1) year) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (date_add(a__Type__Parent.`Time2`, interval (1) year) > now()) - } - [Fact] - public void Subtract() - { - var data = new List(); - //data.Add(select.Where(a => a.CreateTime.Subtract(DateTime.Now).TotalSeconds > 0).ToList()); - //data.Add(select.Where(a => a.Type.Time.Subtract(DateTime.Now).TotalSeconds > 0).ToList()); - //data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(DateTime.Now).TotalSeconds > 0).ToList()); - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a."TITLE", a."CREATETIME" - //FROM "TB_TOPIC111333" a - //WHERE ((extract(day from (systimestamp-a."CREATETIME"))*86400+extract(hour from (systimestamp-a."CREATETIME"))*3600+extract(minute from (systimestamp-a."CREATETIME"))*60+extract(second from (systimestamp-a."CREATETIME"))) > 0) - - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME" - //FROM "TB_TOPIC111333" a - //LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID" - //WHERE ((extract(day from (systimestamp-a__Type."TIME"))*86400+extract(hour from (systimestamp-a__Type."TIME"))*3600+extract(minute from (systimestamp-a__Type."TIME"))*60+extract(second from (systimestamp-a__Type."TIME"))) > 0) - - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME" - //FROM "TB_TOPIC111333" a - //LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID" - //LEFT JOIN "TESTTYPEPARENTINF1" a__Type__Parent ON a__Type__Parent."ID" = a__Type."PARENTID" - //WHERE ((extract(day from (systimestamp-a__Type__Parent."TIME2"))*86400+extract(hour from (systimestamp-a__Type__Parent."TIME2"))*3600+extract(minute from (systimestamp-a__Type__Parent."TIME2"))*60+extract(second from (systimestamp-a__Type__Parent."TIME2"))) > 0) - //data.Add(select.Where(a => a.CreateTime.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList()); - //data.Add(select.Where(a => a.Type.Time.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList()); - //data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList()); - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a."TITLE", a."CREATETIME" - //FROM "TB_TOPIC111333" a - //WHERE ((a."CREATETIME"-numtodsinterval((1)*86400,'second')) > a."CREATETIME") - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME" - - //FROM "TB_TOPIC111333" a - //LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID" - //WHERE ((a__Type."TIME"-numtodsinterval((1)*86400,'second')) > a."CREATETIME") - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME" - - //FROM "TB_TOPIC111333" a - //LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID" - //LEFT JOIN "TESTTYPEPARENTINF1" a__Type__Parent ON a__Type__Parent."ID" = a__Type."PARENTID" - //WHERE ((a__Type__Parent."TIME2"-numtodsinterval((1)*86400,'second')) > a."CREATETIME") - } - [Fact] - public void _ЧͬSubtract() - { - var data = new List(); - //data.Add(select.Where(a => (a.CreateTime - DateTime.Now).TotalSeconds > 0).ToList()); - //data.Add(select.Where(a => (a.Type.Time - DateTime.Now).TotalSeconds > 0).ToList()); - //data.Add(select.Where(a => (a.Type.Parent.Time2 - DateTime.Now).TotalSeconds > 0).ToList()); - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a."TITLE", a."CREATETIME" - //FROM "TB_TOPIC111333" a - //WHERE ((extract(day from (systimestamp-a."CREATETIME"))*86400+extract(hour from (systimestamp-a."CREATETIME"))*3600+extract(minute from (systimestamp-a."CREATETIME"))*60+extract(second from (systimestamp-a."CREATETIME"))) > 0) - - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME" - //FROM "TB_TOPIC111333" a - //LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID" - //WHERE ((extract(day from (systimestamp-a__Type."TIME"))*86400+extract(hour from (systimestamp-a__Type."TIME"))*3600+extract(minute from (systimestamp-a__Type."TIME"))*60+extract(second from (systimestamp-a__Type."TIME"))) > 0) - - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME" - //FROM "TB_TOPIC111333" a - //LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID" - //LEFT JOIN "TESTTYPEPARENTINF1" a__Type__Parent ON a__Type__Parent."ID" = a__Type."PARENTID" - //WHERE ((extract(day from (systimestamp-a__Type__Parent."TIME2"))*86400+extract(hour from (systimestamp-a__Type__Parent."TIME2"))*3600+extract(minute from (systimestamp-a__Type__Parent."TIME2"))*60+extract(second from (systimestamp-a__Type__Parent."TIME2"))) > 0) - //data.Add(select.Where(a => (a.CreateTime - TimeSpan.FromDays(1)) > a.CreateTime).ToList()); - //data.Add(select.Where(a => (a.Type.Time - TimeSpan.FromDays(1)) > a.CreateTime).ToList()); - //data.Add(select.Where(a => (a.Type.Parent.Time2 - TimeSpan.FromDays(1)) > a.CreateTime).ToList()); - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a."TITLE", a."CREATETIME" - //FROM "TB_TOPIC111333" a - //WHERE ((a."CREATETIME"-numtodsinterval((1)*86400,'second')) > a."CREATETIME") - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME" - - //FROM "TB_TOPIC111333" a - //LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID" - //WHERE ((a__Type."TIME"-numtodsinterval((1)*86400,'second')) > a."CREATETIME") - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME" - - //FROM "TB_TOPIC111333" a - //LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID" - //LEFT JOIN "TESTTYPEPARENTINF1" a__Type__Parent ON a__Type__Parent."ID" = a__Type."PARENTID" - //WHERE ((a__Type__Parent."TIME2"-numtodsinterval((1)*86400,'second')) > a."CREATETIME") - } - [Fact] - public void this_Equals() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.AddYears(1).Equals(DateTime.Now)).ToList()); - data.Add(select.Where(a => a.Type.Time.AddYears(1).Equals(DateTime.Now)).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).Equals(DateTime.Now)).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE ((date_add(a.`CreateTime`, interval (1) year) = now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE ((date_add(a__Type.`Time`, interval (1) year) = now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE ((date_add(a__Type__Parent.`Time2`, interval (1) year) = now())) - } - [Fact] - public void DateTime_Compare() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.CompareTo(DateTime.Now) == 0).ToList()); - data.Add(select.Where(a => a.Type.Time.AddYears(1).CompareTo(DateTime.Now) == 0).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).CompareTo(DateTime.Now) == 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (((a.`CreateTime`) - (now())) = 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (((date_add(a__Type.`Time`, interval (1) year)) - (now())) = 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (((date_add(a__Type__Parent.`Time2`, interval (1) year)) - (now())) = 0) - } - [Fact] - public void DateTime_DaysInMonth() - { - var data = new List(); - data.Add(select.Where(a => DateTime.DaysInMonth(a.CreateTime.Year, a.CreateTime.Month) > 30).ToList()); - //data.Add(select.Where(a => DateTime.DaysInMonth(a.Type.Time.Year, a.Type.Time.Month) > 30).ToList()); - //data.Add(select.Where(a => DateTime.DaysInMonth(a.Type.Parent.Time2.Year, a.Type.Parent.Time2.Month) > 30).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (dayofmonth(last_day(concat(year(a.`CreateTime`), month(a.`CreateTime`), '-01'))) > 30); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (dayofmonth(last_day(concat(year(a__Type.`Time`), month(a__Type.`Time`), '-01'))) > 30); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (dayofmonth(last_day(concat(year(a__Type__Parent.`Time2`), month(a__Type__Parent.`Time2`), '-01'))) > 30) - } - [Fact] - public void DateTime_Equals() - { - var data = new List(); - data.Add(select.Where(a => DateTime.Equals(a.CreateTime.AddYears(1), DateTime.Now)).ToList()); - data.Add(select.Where(a => DateTime.Equals(a.Type.Time.AddYears(1), DateTime.Now)).ToList()); - data.Add(select.Where(a => DateTime.Equals(a.Type.Parent.Time2.AddYears(1), DateTime.Now)).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE ((date_add(a.`CreateTime`, interval (1) year) = now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE ((date_add(a__Type.`Time`, interval (1) year) = now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE ((date_add(a__Type__Parent.`Time2`, interval (1) year) = now())) - } - [Fact] - public void DateTime_IsLeapYear() - { - var data = new List(); - data.Add(select.Where(a => DateTime.IsLeapYear(a.CreateTime.Year)).ToList()); - data.Add(select.Where(a => DateTime.IsLeapYear(a.Type.Time.AddYears(1).Year)).ToList()); - data.Add(select.Where(a => DateTime.IsLeapYear(a.Type.Parent.Time2.AddYears(1).Year)).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (((year(a.`CreateTime`)) % 4 = 0 AND (year(a.`CreateTime`)) % 100 <> 0 OR (year(a.`CreateTime`)) % 400 = 0)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (((year(date_add(a__Type.`Time`, interval (1) year))) % 4 = 0 AND (year(date_add(a__Type.`Time`, interval (1) year))) % 100 <> 0 OR (year(date_add(a__Type.`Time`, interval (1) year))) % 400 = 0)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (((year(date_add(a__Type__Parent.`Time2`, interval (1) year))) % 4 = 0 AND (year(date_add(a__Type__Parent.`Time2`, interval (1) year))) % 100 <> 0 OR (year(date_add(a__Type__Parent.`Time2`, interval (1) year))) % 400 = 0)) - } - [Fact] - public void DateTime_Parse() - { - var data = new List(); - data.Add(select.Where(a => DateTime.Parse(a.CreateTime.ToString()) > DateTime.Now).ToList()); - data.Add(select.Where(a => DateTime.Parse(a.Type.Time.AddYears(1).ToString()) > DateTime.Now).ToList()); - data.Add(select.Where(a => DateTime.Parse(a.Type.Parent.Time2.AddYears(1).ToString()) > DateTime.Now).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d %H:%i:%s.%f') as datetime) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (cast(date_format(date_add(a__Type.`Time`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') as datetime) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (cast(date_format(date_add(a__Type__Parent.`Time2`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') as datetime) > now()) - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/MathTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/MathTest.cs deleted file mode 100644 index b5adc9835..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/MathTest.cs +++ /dev/null @@ -1,156 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.DamengExpression -{ - public class MathTest - { - - ISelect select => g.dameng.Select(); - - [Table(Name = "tb_topic")] - class Topic - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int Clicks { get; set; } - public int TypeGuid { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - class TestTypeInfo - { - public int Guid { get; set; } - public int ParentId { get; set; } - public TestTypeParentInfo Parent { get; set; } - public string Name { get; set; } - } - class TestTypeParentInfo - { - public int Id { get; set; } - public string Name { get; set; } - - public List Types { get; set; } - } - - [Fact] - public void PI() - { - var data = new List(); - data.Add(select.Where(a => Math.PI + a.Clicks > 0).ToList()); - } - [Fact] - public void Abs() - { - var data = new List(); - data.Add(select.Where(a => Math.Abs(-a.Clicks) > 0).ToList()); - } - [Fact] - public void Sign() - { - var data = new List(); - data.Add(select.Where(a => Math.Sign(-a.Clicks) > 0).ToList()); - } - [Fact] - public void Floor() - { - var data = new List(); - data.Add(select.Where(a => Math.Floor(a.Clicks + 0.5) == a.Clicks).ToList()); - } - [Fact] - public void Ceiling() - { - var data = new List(); - data.Add(select.Where(a => Math.Ceiling(a.Clicks + 0.5) == a.Clicks + 1).ToList()); - } - [Fact] - public void Round() - { - var data = new List(); - data.Add(select.Where(a => Math.Round(a.Clicks + 0.5) == a.Clicks).ToList()); - data.Add(select.Where(a => Math.Round(a.Clicks + 0.5, 1) > a.Clicks).ToList()); - } - [Fact] - public void Exp() - { - var data = new List(); - data.Add(select.Where(a => Math.Exp(1) == a.Clicks + 1).ToList()); - } - [Fact] - public void Log() - { - var data = new List(); - data.Add(select.Where(a => Math.Log(a.Clicks + 0.5) == a.Clicks + 1).ToList()); - } - [Fact] - public void Log10() - { - var data = new List(); - data.Add(select.Where(a => Math.Log10(a.Clicks + 0.5) == a.Clicks + 1).ToList()); - } - [Fact] - public void Pow() - { - var data = new List(); - data.Add(select.Where(a => Math.Pow(2, a.Clicks % 5) == a.Clicks + 1).ToList()); - } - [Fact] - public void Sqrt() - { - var data = new List(); - data.Add(select.Where(a => Math.Sqrt(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList()); - } - [Fact] - public void Cos() - { - var data = new List(); - data.Add(select.Where(a => Math.Cos(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList()); - } - [Fact] - public void Sin() - { - var data = new List(); - data.Add(select.Where(a => Math.Sin(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList()); - } - [Fact] - public void Tan() - { - var data = new List(); - data.Add(select.Where(a => Math.Tan(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList()); - } - [Fact] - public void Acos() - { - var data = new List(); - //data.Add(select.Where(a => Math.Acos(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList()); - } - [Fact] - public void Asin() - { - var data = new List(); - //data.Add(select.Where(a => Math.Asin(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList()); - } - [Fact] - public void Atan() - { - var data = new List(); - data.Add(select.Where(a => Math.Atan(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList()); - } - [Fact] - public void Atan2() - { - var data = new List(); - //data.Add(select.Where(a => Math.Atan2(2, a.Clicks) == a.Clicks + 1).ToList()); - } - [Fact] - public void Truncate() - { - var data = new List(); - data.Add(select.Where(a => Math.Truncate(a.Clicks * 1.0 / 3) == a.Clicks + 1).ToList()); - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/OtherTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/OtherTest.cs deleted file mode 100644 index c5cdb5671..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/OtherTest.cs +++ /dev/null @@ -1,165 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.DamengExpression -{ - public class OtherTest - { - - ISelect select => g.dameng.Select(); - - public OtherTest() - { - } - - [Fact] - public void Div() - { - var t1 = select.Where(a => a.Int / 3 > 3).Limit(10).ToList(); - var t2 = select.Where(a => a.Long / 3 > 3).Limit(10).ToList(); - var t3 = select.Where(a => a.Short / 3 > 3).Limit(10).ToList(); - - var t4 = select.Where(a => a.Int / 3.0 > 3).Limit(10).ToList(); - var t5 = select.Where(a => a.Long / 3.0 > 3).Limit(10).ToList(); - var t6 = select.Where(a => a.Short / 3.0 > 3).Limit(10).ToList(); - - var t7 = select.Where(a => a.Double / 3 > 3).Limit(10).ToList(); - var t8 = select.Where(a => a.Decimal / 3 > 3).Limit(10).ToList(); - var t9 = select.Where(a => a.Float / 3 > 3).Limit(10).ToList(); - } - - [Fact] - public void Boolean() - { - var t1 = select.Where(a => a.Bool == true).ToList(); - var t2 = select.Where(a => a.Bool != true).ToList(); - var t3 = select.Where(a => a.Bool == false).ToList(); - var t4 = select.Where(a => !a.Bool).ToList(); - var t5 = select.Where(a => a.Bool).ToList(); - var t51 = select.WhereCascade(a => a.Bool).Limit(10).ToList(); - - var t11 = select.Where(a => a.BoolNullable == true).ToList(); - var t22 = select.Where(a => a.BoolNullable != true).ToList(); - var t33 = select.Where(a => a.BoolNullable == false).ToList(); - var t44 = select.Where(a => !a.BoolNullable.Value).ToList(); - var t55 = select.Where(a => a.BoolNullable.Value).ToList(); - - var t111 = select.Where(a => a.Bool == true && a.Id > 0).ToList(); - var t222 = select.Where(a => a.Bool != true && a.Id > 0).ToList(); - var t333 = select.Where(a => a.Bool == false && a.Id > 0).ToList(); - var t444 = select.Where(a => !a.Bool && a.Id > 0).ToList(); - var t555 = select.Where(a => a.Bool && a.Id > 0).ToList(); - - var t1111 = select.Where(a => a.BoolNullable == true && a.Id > 0).ToList(); - var t2222 = select.Where(a => a.BoolNullable != true && a.Id > 0).ToList(); - var t3333 = select.Where(a => a.BoolNullable == false && a.Id > 0).ToList(); - var t4444 = select.Where(a => !a.BoolNullable.Value && a.Id > 0).ToList(); - var t5555 = select.Where(a => a.BoolNullable.Value && a.Id > 0).ToList(); - - var t11111 = select.Where(a => a.Bool == true && a.Id > 0 && a.Bool == true).ToList(); - var t22222 = select.Where(a => a.Bool != true && a.Id > 0 && a.Bool != true).ToList(); - var t33333 = select.Where(a => a.Bool == false && a.Id > 0 && a.Bool == false).ToList(); - var t44444 = select.Where(a => !a.Bool && a.Id > 0 && !a.Bool).ToList(); - var t55555 = select.Where(a => a.Bool && a.Id > 0 && a.Bool).ToList(); - - var t111111 = select.Where(a => a.BoolNullable == true && a.Id > 0 && a.BoolNullable == true).ToList(); - var t222222 = select.Where(a => a.BoolNullable != true && a.Id > 0 && a.BoolNullable != true).ToList(); - var t333333 = select.Where(a => a.BoolNullable == false && a.Id > 0 && a.BoolNullable == false).ToList(); - var t444444 = select.Where(a => !a.BoolNullable.Value && a.Id > 0 && !a.BoolNullable.Value).ToList(); - var t555555 = select.Where(a => a.BoolNullable.Value && a.Id > 0 && a.BoolNullable.Value).ToList(); - } - - [Fact] - public void Array() - { - IEnumerable testlinqlist = new List(new[] { 1, 2, 3 }); - var testlinq = select.Where(a => testlinqlist.Contains(a.Int)).ToList(); - - //in not in - var sql111 = select.Where(a => new[] { 1, 2, 3 }.Contains(a.Int)).ToList(); - //var sql112 = select.Where(a => new[] { 1, 2, 3 }.Contains(a.Int) == false).ToList(); - var sql113 = select.Where(a => !new[] { 1, 2, 3 }.Contains(a.Int)).ToList(); - - var inarray = new[] { 1, 2, 3 }; - var sql1111 = select.Where(a => inarray.Contains(a.Int)).ToList(); - //var sql1122 = select.Where(a => inarray.Contains(a.Int) == false).ToList(); - var sql1133 = select.Where(a => !inarray.Contains(a.Int)).ToList(); - - - //in not in - var sql11111 = select.Where(a => new List() { 1, 2, 3 }.Contains(a.Int)).ToList(); - //var sql11222 = select.Where(a => new List() { 1, 2, 3 }.Contains(a.Int) == false).ToList(); - var sql11333 = select.Where(a => !new List() { 1, 2, 3 }.Contains(a.Int)).ToList(); - - var sql11111a = select.Where(a => new List(new[] { 1, 2, 3 }).Contains(a.Int)).ToList(); - //var sql11222b = select.Where(a => new List(new[] { 1, 2, 3 }).Contains(a.Int) == false).ToList(); - var sql11333c = select.Where(a => !new List(new[] { 1, 2, 3 }).Contains(a.Int)).ToList(); - - var inarray2 = new List() { 1, 2, 3 }; - var sql111111 = select.Where(a => inarray.Contains(a.Int)).ToList(); - //var sql112222 = select.Where(a => inarray.Contains(a.Int) == false).ToList(); - var sql113333 = select.Where(a => !inarray.Contains(a.Int)).ToList(); - - var inarray2n = Enumerable.Range(1, 3333).ToArray(); - var sql1111111 = select.Where(a => inarray2n.Contains(a.Int)).ToList(); - var sql1122222 = select.Where(a => inarray2n.Contains(a.Int) == false).ToList(); - var sql1133333 = select.Where(a => !inarray2n.Contains(a.Int)).ToList(); - } - - [Table(Name = "tb_alltype")] - class TableAllType - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - - public string id2 { get; set; } = "id2=10"; - - public bool Bool { get; set; } - public sbyte SByte { get; set; } - public short Short { get; set; } - public int Int { get; set; } - public long Long { get; set; } - public byte Byte { get; set; } - public ushort UShort { get; set; } - public uint UInt { get; set; } - public ulong ULong { get; set; } - public double Double { get; set; } - public float Float { get; set; } - public decimal Decimal { get; set; } - public TimeSpan TimeSpan { get; set; } - public DateTime DateTime { get; set; } - public DateTime DateTimeOffSet { get; set; } - public byte[] Bytes { get; set; } - public string String { get; set; } - public Guid Guid { get; set; } - - public bool? BoolNullable { get; set; } - public sbyte? SByteNullable { get; set; } - public short? ShortNullable { get; set; } - public int? IntNullable { get; set; } - public long? testFielLongNullable { get; set; } - public byte? ByteNullable { get; set; } - public ushort? UShortNullable { get; set; } - public uint? UIntNullable { get; set; } - public ulong? ULongNullable { get; set; } - public double? DoubleNullable { get; set; } - public float? FloatNullable { get; set; } - public decimal? DecimalNullable { get; set; } - public TimeSpan? TimeSpanNullable { get; set; } - public DateTime? DateTimeNullable { get; set; } - public DateTime? DateTimeOffSetNullable { get; set; } - public Guid? GuidNullable { get; set; } - - public TableAllTypeEnumType1 Enum1 { get; set; } - public TableAllTypeEnumType1? Enum1Nullable { get; set; } - public TableAllTypeEnumType2 Enum2 { get; set; } - public TableAllTypeEnumType2? Enum2Nullable { get; set; } - } - - public enum TableAllTypeEnumType1 { e1, e2, e3, e5 } - [Flags] public enum TableAllTypeEnumType2 { f1, f2, f3 } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/StringTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/StringTest.cs deleted file mode 100644 index 9a8a92c32..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/StringTest.cs +++ /dev/null @@ -1,827 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.DamengExpression -{ - public class StringTest - { - - ISelect select => g.dameng.Select(); - - [Table(Name = "tb_topic")] - class Topic - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int Clicks { get; set; } - public int TypeGuid { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - class TestTypeInfo - { - [Column(IsIdentity = true)] - public int Guid { get; set; } - public int ParentId { get; set; } - public TestTypeParentInfo Parent { get; set; } - public string Name { get; set; } - } - class TestTypeParentInfo - { - public int Id { get; set; } - public string Name { get; set; } - - public List Types { get; set; } - } - class TestEqualsGuid - { - public Guid id { get; set; } - } - - [Fact] - public void Equals__() - { - var list = new List(); - list.Add(select.Where(a => a.Title.Equals("aaa")).ToList()); - list.Add(g.dameng.Select().Where(a => a.id.Equals(Guid.Empty)).ToList()); - } - - [Fact] - public void StringJoin() - { - var fsql = g.dameng; - fsql.Delete().Where("1=1").ExecuteAffrows(); - fsql.Insert(new[] { new StringJoin01 { name = "北京" }, new StringJoin01 { name = "上海" }, new StringJoin01 { name = "深圳" }, }).ExecuteAffrows(); - - var val1 = string.Join(",", fsql.Select().ToList(a => a.name)); - var val2 = fsql.Select().ToList(a => string.Join(",", fsql.Select().As("b").ToList(b => b.name))); - Assert.Equal(val1, val2[0]); - - val1 = string.Join("**", fsql.Select().ToList(a => a.name)); - val2 = fsql.Select().ToList(a => string.Join("**", fsql.Select().As("b").ToList(b => b.name))); - Assert.Equal(val1, val2[0]); - - val1 = string.Join(",", fsql.Select().ToList(a => a.id)); - val2 = fsql.Select().ToList(a => string.Join(",", fsql.Select().As("b").ToList(b => b.id))); - Assert.Equal(val1, val2[0]); - - val1 = string.Join("**", fsql.Select().ToList(a => a.id)); - val2 = fsql.Select().ToList(a => string.Join("**", fsql.Select().As("b").ToList(b => b.id))); - Assert.Equal(val1, val2[0]); - } - class StringJoin01 - { - [Column(IsIdentity = true)] - public int id { get; set; } - public string name { get; set; } - } - - [Fact] - public void First() - { - Assert.Equal('x', select.First(a => "x1".First())); - Assert.Equal('z', select.First(a => "z1".First())); - } - [Fact] - public void FirstOrDefault() - { - Assert.Equal('x', select.First(a => "x1".FirstOrDefault())); - Assert.Equal('z', select.First(a => "z1".FirstOrDefault())); - } - - [Fact] - public void Format() - { - var item = g.dameng.GetRepository().Insert(new Topic { Clicks = 101, Title = "我是中国人101", CreateTime = DateTime.Parse("2020-7-5") }); - var sql = select.WhereDynamic(item).ToSql(a => new - { - str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}", - str2 = string.Format("{0}x{0}z-{1}{2}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title) - }); - Assert.Equal($@"SELECT 'x'||nvl((a.""ID"" + 1), '')||'z-'||nvl(to_char(a.""CREATETIME"",'YYYYMM'), '')||''||nvl(a.""TITLE"", '')||'' as1, ''||nvl((a.""ID"" + 1), '')||'x'||nvl((a.""ID"" + 1), '')||'z-'||nvl(to_char(a.""CREATETIME"",'YYYYMM'), '')||''||nvl(a.""TITLE"", '')||'' as2 -FROM ""TB_TOPIC"" a -WHERE (a.""ID"" = {item.Id})", sql); - - var item2 = select.WhereDynamic(item).First(a => new - { - str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}", - str2 = string.Format("{0}x{0}z-{1}{2}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title) - }); - Assert.NotNull(item2); - Assert.Equal($"x{item.Id + 1}z-{item.CreateTime.ToString("yyyyMM")}{item.Title}", item2.str); - Assert.Equal(string.Format("{0}x{0}z-{1}{2}", item.Id + 1, item.CreateTime.ToString("yyyyMM"), item.Title), item2.str2); - } - - [Fact] - public void Format4() - { - //3个 {} 时,Arguments 解析出来是分开的 - //4个 {} 时,Arguments[1] 只能解析这个出来,然后里面是 NewArray [] - var item = g.dameng.GetRepository().Insert(new Topic { Clicks = 101, Title = "我是中国人101", CreateTime = DateTime.Parse("2020-7-5") }); - var sql = select.WhereDynamic(item).ToSql(a => new - { - str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}{a.Title}", - str2 = string.Format("{0}x{0}z-{1}{2}{3}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title, a.Title) - }); - Assert.Equal($@"SELECT 'x'||nvl((a.""ID"" + 1), '')||'z-'||nvl(to_char(a.""CREATETIME"",'YYYYMM'), '')||''||nvl(a.""TITLE"", '')||''||nvl(a.""TITLE"", '')||'' as1, ''||nvl((a.""ID"" + 1), '')||'x'||nvl((a.""ID"" + 1), '')||'z-'||nvl(to_char(a.""CREATETIME"",'YYYYMM'), '')||''||nvl(a.""TITLE"", '')||''||nvl(a.""TITLE"", '')||'' as2 -FROM ""TB_TOPIC"" a -WHERE (a.""ID"" = {item.Id})", sql); - - var item2 = select.WhereDynamic(item).First(a => new - { - str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}{a.Title}", - str2 = string.Format("{0}x{0}z-{1}{2}{3}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title, a.Title) - }); - Assert.NotNull(item2); - Assert.Equal($"x{item.Id + 1}z-{item.CreateTime.ToString("yyyyMM")}{item.Title}{item.Title}", item2.str); - Assert.Equal(string.Format("{0}x{0}z-{1}{2}{3}", item.Id + 1, item.CreateTime.ToString("yyyyMM"), item.Title, item.Title), item2.str2); - } - - [Fact] - public void Empty() - { - var data = new List(); - data.Add(select.Where(a => (a.Title ?? "") == string.Empty).ToSql()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (ifnull(a.`Title`, '') = '') - } - - [Fact] - public void StartsWith() - { - var list = new List(); - list.Add(select.Where(a => a.Title.StartsWith("aaa")).ToList()); - list.Add(select.Where(a => a.Title.StartsWith(a.Title)).ToList()); - list.Add(select.Where(a => a.Title.StartsWith(a.Title + 1)).ToList()); - list.Add(select.Where(a => a.Title.StartsWith(a.Type.Name)).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((a.`Title`) LIKE '%aaa') - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((a.`Title`) LIKE concat('%', a.`Title`)) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((a.`Title`) LIKE concat('%', concat(a.`Title`, 1))) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE((a.`Title`) LIKE concat('%', a__Type.`Name`)) - list.Add(select.Where(a => (a.Title + "aaa").StartsWith("aaa")).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Title)).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Title + 1)).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Type.Name)).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((concat(a.`Title`, 'aaa')) LIKE '%aaa') - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a.`Title`)) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', concat(a.`Title`, 1))) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a__Type.`Name`)) - } - [Fact] - public void EndsWith() - { - var list = new List(); - list.Add(select.Where(a => a.Title.EndsWith("aaa")).ToList()); - list.Add(select.Where(a => a.Title.EndsWith(a.Title)).ToList()); - list.Add(select.Where(a => a.Title.EndsWith(a.Title + 1)).ToList()); - list.Add(select.Where(a => a.Title.EndsWith(a.Type.Name)).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((a.`Title`) LIKE 'aaa%') - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((a.`Title`) LIKE concat(a.`Title`, '%')) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((a.`Title`) LIKE concat(concat(a.`Title`, 1), '%')) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE((a.`Title`) LIKE concat(a__Type.`Name`, '%')) - list.Add(select.Where(a => (a.Title + "aaa").EndsWith("aaa")).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Title)).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Title + 1)).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Type.Name)).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((concat(a.`Title`, 'aaa')) LIKE 'aaa%') - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((concat(a.`Title`, 'aaa')) LIKE concat(a.`Title`, '%')) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((concat(a.`Title`, 'aaa')) LIKE concat(concat(a.`Title`, 1), '%')) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE((concat(a.`Title`, 'aaa')) LIKE concat(a__Type.`Name`, '%')) - } - [Fact] - public void Contains() - { - var list = new List(); - list.Add(select.Where(a => a.Title.Contains("aaa")).ToList()); - list.Add(select.Where(a => a.Title.Contains(a.Title)).ToList()); - list.Add(select.Where(a => a.Title.Contains(a.Title + 1)).ToList()); - list.Add(select.Where(a => a.Title.Contains(a.Type.Name)).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((a.`Title`) LIKE '%aaa%') - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((a.`Title`) LIKE concat('%', a.`Title`, '%')) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((a.`Title`) LIKE concat('%', a.`Title` +1, '%')) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE((a.`Title`) LIKE concat('%', a__Type.`Name`, '%')) - list.Add(select.Where(a => (a.Title + "aaa").Contains("aaa")).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Title)).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Title + 1)).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Type.Name)).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((concat(a.`Title`, 'aaa')) LIKE '%aaa%') - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a.`Title`, '%')) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', concat(a.`Title`, 1), '%')) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a__Type.`Name`, '%')) - - - list.Add(select.Where(a => a.Title.Contains("%")).ToList()); - list.Add(select.Where(a => a.Title.Contains(a.Title + "%")).ToList()); - list.Add(select.Where(a => a.Title.Contains(a.Title + 1 + "%")).ToList()); - list.Add(select.Where(a => a.Title.Contains(a.Type.Name + "%")).ToList()); - - list.Add(select.Where(a => (a.Title + "aaa").Contains("aaa" + "%")).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Title + "%")).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Title + 1 + "%")).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Type.Name + "%")).ToList()); - } - [Fact] - public void ToLower() - { - var data = new List(); - data.Add(select.Where(a => a.Title.ToLower() == "aaa").ToList()); - data.Add(select.Where(a => a.Title.ToLower() == a.Title).ToList()); - data.Add(select.Where(a => a.Title.ToLower() == (a.Title + 1)).ToList()); - data.Add(select.Where(a => a.Title.ToLower() == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE(lower(a.`Title`) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE(lower(a.`Title`) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE(lower(a.`Title`) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE(lower(a.`Title`) = a__Type.`Name`); - data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == "aaa").ToList()); - data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == a.Title).ToList()); - data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == (a.Title + 1)).ToList()); - data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE(lower(concat(lower(a.`Title`), 'aaa')) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE(lower(concat(lower(a.`Title`), 'aaa')) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE(lower(concat(lower(a.`Title`), 'aaa')) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE(lower(concat(lower(a.`Title`), 'aaa')) = a__Type.`Name`) - } - [Fact] - public void ToUpper() - { - var data = new List(); - data.Add(select.Where(a => a.Title.ToUpper() == "aaa").ToList()); - data.Add(select.Where(a => a.Title.ToUpper() == a.Title).ToList()); - data.Add(select.Where(a => a.Title.ToUpper() == (a.Title + 1)).ToList()); - data.Add(select.Where(a => a.Title.ToUpper() == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (upper(a.`Title`) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (upper(a.`Title`) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (upper(a.`Title`) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (upper(a.`Title`) = a__Type.`Name`); - data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == "aaa").ToList()); - data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == a.Title).ToList()); - data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == (a.Title + 1)).ToList()); - data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (upper(concat(upper(a.`Title`), 'aaa')) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (upper(concat(upper(a.`Title`), 'aaa')) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (upper(concat(upper(a.`Title`), 'aaa')) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (upper(concat(upper(a.`Title`), 'aaa')) = a__Type.`Name`) - } - [Fact] - public void Substring() - { - var data = new List(); - data.Add(select.Where(a => a.Title.Substring(0) == "aaa").ToList()); - data.Add(select.Where(a => a.Title.Substring(0) == a.Title).ToList()); - data.Add(select.Where(a => a.Title.Substring(0) == (a.Title + 1)).ToList()); - data.Add(select.Where(a => a.Title.Substring(0) == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (substr(a.`Title`, 1) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (substr(a.`Title`, 1) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (substr(a.`Title`, 1) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (substr(a.`Title`, 1) = a__Type.`Name`); - data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(a.Title.Length) == "aaa").ToList()); - data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(0, a.Title.Length) == a.Title).ToList()); - data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(0, 3) == (a.Title + 1)).ToList()); - data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(1, 2) == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), char_length(a.`Title`) + 1) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), 1, char_length(a.`Title`)) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), 1, 3) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), 2, 2) = a__Type.`Name`) - } - [Fact] - public void Length() - { - var data = new List(); - data.Add(select.Where(a => a.Title.Length == 0).ToList()); - data.Add(select.Where(a => a.Title.Length == 1).ToList()); - data.Add(select.Where(a => a.Title.Length == a.Title.Length + 1).ToList()); - data.Add(select.Where(a => a.Title.Length == a.Type.Name.Length).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (char_length(a.`Title`) = 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (char_length(a.`Title`) = 1); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (char_length(a.`Title`) = char_length(a.`Title`) + 1); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (char_length(a.`Title`) = char_length(a__Type.`Name`)); - data.Add(select.Where(a => (a.Title + "aaa").Length == 0).ToList()); - data.Add(select.Where(a => (a.Title + "aaa").Length == 1).ToList()); - data.Add(select.Where(a => (a.Title + "aaa").Length == a.Title.Length + 1).ToList()); - data.Add(select.Where(a => (a.Title + "aaa").Length == a.Type.Name.Length).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (char_length(concat(a.`Title`, 'aaa')) = 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (char_length(concat(a.`Title`, 'aaa')) = 1); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (char_length(concat(a.`Title`, 'aaa')) = char_length(a.`Title`) + 1); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (char_length(concat(a.`Title`, 'aaa')) = char_length(a__Type.`Name`)) - } - [Fact] - public void IndexOf() - { - var data = new List(); - data.Add(select.Where(a => a.Title.IndexOf("aaa") == -1).ToList()); - data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == -1).ToList()); - data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == (a.Title.Length + 1)).ToList()); - data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == a.Type.Name.Length + 1).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((locate(a.`Title`, 'aaa') - 1) = -1); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((locate(a.`Title`, 'aaa', 3) - 1) = -1); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((locate(a.`Title`, 'aaa', 3) - 1) = char_length(a.`Title`) + 1); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE ((locate(a.`Title`, 'aaa', 3) - 1) = char_length(a__Type.`Name`) + 1); - data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa") == -1).ToList()); - data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == -1).ToList()); - data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == (a.Title.Length + 1)).ToList()); - data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == a.Type.Name.Length + 1).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa') - 1) = -1); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa', 3) - 1) = -1); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa', 3) - 1) = char_length(a.`Title`) + 1); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa', 3) - 1) = char_length(a__Type.`Name`) + 1) - } - [Fact] - public void PadLeft() - { - var data = new List(); - data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == "aaa").ToList()); - data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == a.Title).ToList()); - data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (lpad(a.`Title`, 10, 'a') = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (lpad(a.`Title`, 10, 'a') = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (lpad(a.`Title`, 10, 'a') = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (lpad(a.`Title`, 10, 'a') = a__Type.`Name`); - data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == "aaa").ToList()); - data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == a.Title).ToList()); - data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a__Type.`Name`) - } - [Fact] - public void PadRight() - { - var data = new List(); - data.Add(select.Where(a => a.Title.PadRight(10, 'a') == "aaa").ToList()); - data.Add(select.Where(a => a.Title.PadRight(10, 'a') == a.Title).ToList()); - data.Add(select.Where(a => a.Title.PadRight(10, 'a') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => a.Title.PadRight(10, 'a') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (rpad(a.`Title`, 10, 'a') = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (rpad(a.`Title`, 10, 'a') = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (rpad(a.`Title`, 10, 'a') = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (rpad(a.`Title`, 10, 'a') = a__Type.`Name`); - data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == "aaa").ToList()); - data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == a.Title).ToList()); - data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a__Type.`Name`) - } - [Fact] - public void Trim() - { - var data = new List(); - data.Add(select.Where(a => a.Title.Trim() == "aaa").ToList()); - data.Add(select.Where(a => a.Title.Trim('a') == a.Title).ToList()); - data.Add(select.Where(a => a.Title.Trim('a', 'b') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => a.Title.Trim('a', 'b', 'c') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim(a.`Title`) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim('a' from a.`Title`) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim('b' from trim('a' from a.`Title`)) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (trim('c' from trim('b' from trim('a' from a.`Title`))) = a__Type.`Name`); - data.Add(select.Where(a => (a.Title.Trim() + "aaa").Trim() == "aaa").ToList()); - data.Add(select.Where(a => (a.Title.Trim('a') + "aaa").Trim('a') == a.Title).ToList()); - data.Add(select.Where(a => (a.Title.Trim('a', 'b') + "aaa").Trim('a', 'b') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => (a.Title.Trim('a', 'b', 'c') + "aaa").Trim('a', 'b', 'c') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim(concat(trim(a.`Title`), 'aaa')) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim('a' from concat(trim('a' from a.`Title`), 'aaa')) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim('b' from trim('a' from concat(trim('b' from trim('a' from a.`Title`)), 'aaa'))) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (trim('c' from trim('b' from trim('a' from concat(trim('c' from trim('b' from trim('a' from a.`Title`))), 'aaa')))) = a__Type.`Name`) - } - [Fact] - public void TrimStart() - { - var data = new List(); - data.Add(select.Where(a => a.Title.TrimStart() == "aaa").ToList()); - data.Add(select.Where(a => a.Title.TrimStart('a') == a.Title).ToList()); - data.Add(select.Where(a => a.Title.TrimStart('a', 'b') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => a.Title.TrimStart('a', 'b', 'c') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (ltrim(a.`Title`) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim(trailing 'a' from trim(leading 'a' from a.`Title`)) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (trim(trailing 'c' from trim(leading 'c' from trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))))) = a__Type.`Name`); - data.Add(select.Where(a => (a.Title.TrimStart() + "aaa").TrimStart() == "aaa").ToList()); - data.Add(select.Where(a => (a.Title.TrimStart('a') + "aaa").TrimStart('a') == a.Title).ToList()); - data.Add(select.Where(a => (a.Title.TrimStart('a', 'b') + "aaa").TrimStart('a', 'b') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => (a.Title.TrimStart('a', 'b', 'c') + "aaa").TrimStart('a', 'b', 'c') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (ltrim(concat(ltrim(a.`Title`), 'aaa')) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim(trailing 'a' from trim(leading 'a' from concat(trim(trailing 'a' from trim(leading 'a' from a.`Title`)), 'aaa'))) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from concat(trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))), 'aaa'))))) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (trim(trailing 'c' from trim(leading 'c' from trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from concat(trim(trailing 'c' from trim(leading 'c' from trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))))), 'aaa'))))))) = a__Type.`Name`) - } - [Fact] - public void TrimEnd() - { - var data = new List(); - data.Add(select.Where(a => a.Title.TrimEnd() == "aaa").ToList()); - data.Add(select.Where(a => a.Title.TrimEnd('a') == a.Title).ToList()); - data.Add(select.Where(a => a.Title.TrimEnd('a', 'b') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => a.Title.TrimEnd('a', 'b', 'c') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (rtrim(a.`Title`) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim(trailing 'a' from a.`Title`) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim(trailing 'b' from trim(trailing 'a' from a.`Title`)) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (trim(trailing 'c' from trim(trailing 'b' from trim(trailing 'a' from a.`Title`))) = a__Type.`Name`); - data.Add(select.Where(a => (a.Title.TrimEnd() + "aaa").TrimEnd() == "aaa").ToList()); - data.Add(select.Where(a => (a.Title.TrimEnd('a') + "aaa").TrimEnd('a') == a.Title).ToList()); - data.Add(select.Where(a => (a.Title.TrimEnd('a', 'b') + "aaa").TrimEnd('a', 'b') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => (a.Title.TrimEnd('a', 'b', 'c') + "aaa").TrimEnd('a', 'b', 'c') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (rtrim(concat(rtrim(a.`Title`), 'aaa')) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim(trailing 'a' from concat(trim(trailing 'a' from a.`Title`), 'aaa')) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim(trailing 'b' from trim(trailing 'a' from concat(trim(trailing 'b' from trim(trailing 'a' from a.`Title`)), 'aaa'))) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (trim(trailing 'c' from trim(trailing 'b' from trim(trailing 'a' from concat(trim(trailing 'c' from trim(trailing 'b' from trim(trailing 'a' from a.`Title`))), 'aaa')))) = a__Type.`Name`) - } - [Fact] - public void Replace() - { - var data = new List(); - data.Add(select.Where(a => a.Title.Replace("a", "b") == "aaa").ToList()); - data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c") == a.Title).ToList()); - data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c").Replace("c", "a") == (a.Title + 1)).ToList()); - data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c").Replace(a.Type.Name, "a") == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (replace(a.`Title`, 'a', 'b') = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (replace(replace(a.`Title`, 'a', 'b'), 'b', 'c') = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), 'c', 'a') = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), a__Type.`Name`, 'a') = a__Type.`Name`); - data.Add(select.Where(a => (a.Title.Replace("a", "b") + "aaa").TrimEnd() == "aaa").ToList()); - data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c") + "aaa").TrimEnd('a') == a.Title).ToList()); - data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c").Replace("c", "a") + "aaa").TrimEnd('a', 'b') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c").Replace(a.Type.Name, "a") + "aaa").TrimEnd('a', 'b', 'c') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (concat(replace(a.`Title`, 'a', 'b'), 'aaa') = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (concat(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), 'aaa') = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (concat(replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), 'c', 'a'), 'aaa') = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (concat(replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), a__Type.`Name`, 'a'), 'aaa') = a__Type.`Name`) - } - [Fact] - public void CompareTo() - { - var data = new List(); - data.Add(select.Where(a => a.Title.CompareTo(a.Title) == 0).ToList()); - data.Add(select.Where(a => a.Title.CompareTo(a.Title) > 0).ToList()); - data.Add(select.Where(a => a.Title.CompareTo(a.Title + 1) == 0).ToList()); - data.Add(select.Where(a => a.Title.CompareTo(a.Title + a.Type.Name) == 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (strcmp(a.`Title`, a.`Title`) = 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (strcmp(a.`Title`, a.`Title`) > 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (strcmp(a.`Title`, concat(a.`Title`, 1)) = 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (strcmp(a.`Title`, concat(a.`Title`, a__Type.`Name`)) = 0); - data.Add(select.Where(a => (a.Title + "aaa").CompareTo("aaa") == 0).ToList()); - data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Title) > 0).ToList()); - data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Title + 1) == 0).ToList()); - data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Type.Name) == 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (strcmp(concat(a.`Title`, 'aaa'), 'aaa') = 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (strcmp(concat(a.`Title`, 'aaa'), a.`Title`) > 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (strcmp(concat(a.`Title`, 'aaa'), concat(a.`Title`, 1)) = 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (strcmp(concat(a.`Title`, 'aaa'), a__Type.`Name`) = 0) - } - - [Fact] - public void string_IsNullOrEmpty() - { - var data = new List(); - data.Add(select.Where(a => string.IsNullOrEmpty(a.Title)).ToList()); - data.Add(select.Where(a => !string.IsNullOrEmpty(a.Title)).ToList()); - } - - [Fact] - public void string_IsNullOrWhiteSpace() - { - var data = new List(); - data.Add(select.Where(a => string.IsNullOrWhiteSpace(a.Title)).ToList()); - data.Add(select.Where(a => !string.IsNullOrWhiteSpace(a.Title)).ToList()); - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/TimeSpanTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/TimeSpanTest.cs deleted file mode 100644 index 0c0b5c17c..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/DamengExpression/TimeSpanTest.cs +++ /dev/null @@ -1,293 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.DamengExpression -{ - public class TimeSpanTest - { - - ISelect select => g.dameng.Select(); - - [Table(Name = "tb_topic")] - class Topic - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int Clicks { get; set; } - public int TypeGuid { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - class TestTypeInfo - { - public int Guid { get; set; } - public int ParentId { get; set; } - public TestTypeParentInfo Parent { get; set; } - public string Name { get; set; } - } - class TestTypeParentInfo - { - public int Id { get; set; } - public string Name { get; set; } - - public List Types { get; set; } - } - [Fact] - public void Zero() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay > TimeSpan.Zero).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) > 0) - } - [Fact] - public void MinValue() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay > TimeSpan.MinValue).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) > -922337203685477580) - } - [Fact] - public void MaxValue() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay < TimeSpan.MaxValue).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) < 922337203685477580) - } - [Fact] - public void Days() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.Days == 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 86400000000) = 0) - } - [Fact] - public void Hours() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.Hours > 0).ToSql()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 3600000000) mod 24 > 0) - } - [Fact] - public void Milliseconds() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.Milliseconds > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 1000 mod 1000) > 0) - } - [Fact] - public void Minutes() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.Minutes > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 60000000 mod 60) > 0) - } - [Fact] - public void Seconds() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.Seconds > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 1000000 mod 60) > 0) - } - [Fact] - public void Ticks() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.Ticks > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) * 10) > 0) - } - [Fact] - public void TotalDays() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalDays > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 86400000000) > 0) - } - [Fact] - public void TotalHours() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalHours > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 3600000000) > 0) - } - [Fact] - public void TotalMilliseconds() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalMilliseconds > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 1000) > 0) - } - [Fact] - public void TotalMinutes() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalMinutes > 0).ToSql()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 60000000) > 0) - } - [Fact] - public void TotalSeconds() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalSeconds > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 1000000) > 0) - } - [Fact] - public void Add() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.Add(TimeSpan.FromDays(1)) > TimeSpan.Zero).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) + (1 * 86400000000)) > 0) - } - [Fact] - public void Subtract() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.Subtract(TimeSpan.FromDays(1)) > TimeSpan.Zero).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) - (1 * 86400000000)) > 0) - } - [Fact] - public void CompareTo() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.CompareTo(TimeSpan.FromDays(1)) > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) - ((1 * 86400000000))) > 0) - } - [Fact] - public void this_Equals() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.Equals(TimeSpan.FromDays(1))).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 86400000000))) - } - [Fact] - public void this_ToString() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.ToString() == "ssss").ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (date_format(date_add(cast('0001/1/1 0:00:00' as datetime), interval (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) microsecond), '%Y-%m-%d %H:%i:%s.%f') = 'ssss') - } - - [Fact] - public void TimeSpan_Compare() - { - var data = new List(); - data.Add(select.Where(a => TimeSpan.Compare(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1)) > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) - ((1 * 86400000000))) > 0) - } - [Fact] - public void TimeSpan_Equals() - { - var data = new List(); - data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1))).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 86400000000))) - } - [Fact] - public void TimeSpan_FromDays() - { - var data = new List(); - data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1))).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 86400000000))) - } - [Fact] - public void TimeSpan_FromHours() - { - var data = new List(); - data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromHours(1))).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 3600000000))) - } - [Fact] - public void TimeSpan_FromMilliseconds() - { - var data = new List(); - data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromMilliseconds(1))).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 1000))) - } - [Fact] - public void TimeSpan_FromMinutes() - { - var data = new List(); - data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromMinutes(1))).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 60000000))) - } - [Fact] - public void TimeSpan_FromSeconds() - { - var data = new List(); - data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromSeconds(1))).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 1000000))) - } - [Fact] - public void TimeSpan_FromTicks() - { - var data = new List(); - data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromTicks(1))).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 / 10))) - } - [Fact] - public void TimeSpan_Parse() - { - var data = new List(); - data.Add(select.Where(a => TimeSpan.Parse(a.CreateTime.TimeOfDay.ToString()) > TimeSpan.Zero).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (cast(date_format(date_add(cast('0001/1/1 0:00:00' as datetime), interval (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) microsecond), '%Y-%m-%d %H:%i:%s.%f') as signed) > 0) - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/MapType/BoolNullableTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/MapType/BoolNullableTest.cs deleted file mode 100644 index d830e0617..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/MapType/BoolNullableTest.cs +++ /dev/null @@ -1,1571 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using Xunit; - -namespace FreeSql.Tests.Odbc.DamengMapType -{ - public class BoolNullableTest - { - class BoolNullableMap - { - public Guid id { get; set; } - [Column(MapType = typeof(bool))] - public bool? tobool { get; set; } = true; - - [Column(MapType = typeof(sbyte))] - public bool? tosbyte { get; set; } = true; - [Column(MapType = typeof(sbyte?))] - public bool? tosbytenullable { get; set; } = true; - - [Column(MapType = typeof(short))] - public bool? toshort { get; set; } = true; - - [Column(MapType = typeof(short?))] - public bool? toshortnullable { get; set; } = true; - - [Column(MapType = typeof(int))] - public bool? toint { get; set; } = true; - - [Column(MapType = typeof(int?))] - public bool? tointnullable { get; set; } = true; - - [Column(MapType = typeof(long))] - public bool? tolong { get; set; } = true; - [Column(MapType = typeof(long?))] - public bool? tolongnullable { get; set; } = true; - - [Column(MapType = typeof(byte))] - public bool? tobyte { get; set; } = true; - [Column(MapType = typeof(byte?))] - public bool? tobytenullable { get; set; } = true; - - [Column(MapType = typeof(ushort))] - public bool? toushort { get; set; } = true; - - [Column(MapType = typeof(ushort?))] - public bool? toushortnullable { get; set; } = true; - - [Column(MapType = typeof(uint))] - public bool? touint { get; set; } = true; - - [Column(MapType = typeof(uint?))] - public bool? touintnullable { get; set; } = true; - - [Column(MapType = typeof(ulong))] - public bool? toulong { get; set; } = true; - [Column(MapType = typeof(ulong?))] - public bool? toulongnullable { get; set; } = true; - - [Column(MapType = typeof(string))] - public bool? tostring { get; set; } = true; - } - [Fact] - public void Bool() - { - //insert - var orm = g.dameng; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tobool == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobool, find.tobool); - Assert.Equal(true, find.tobool); - - item = new BoolNullableMap { tobool = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobool == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobool, find.tobool); - Assert.Equal(false, find.tobool); - - item = new BoolNullableMap { tobool = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tobool == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tobool == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.tobool, find.tobool); - Assert.Equal(false, find.tobool); - - //update all - item.tobool = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobool == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobool, find.tobool); - Assert.Equal(true, find.tobool); - - item.tobool = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobool == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobool, find.tobool); - Assert.Equal(false, find.tobool); - - item.tobool = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tobool == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tobool == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.tobool, find.tobool); - Assert.Equal(false, find.tobool); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobool, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobool == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.tobool); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobool, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobool == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tobool); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobool, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tobool == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tobool == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tobool); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tobool == true).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tobool == null).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tobool == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void SByte() - { - //insert - var orm = g.dameng; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tosbyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbyte, find.tosbyte); - Assert.Equal(true, find.tosbyte); - - item = new BoolNullableMap { tosbyte = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbyte, find.tosbyte); - Assert.Equal(false, find.tosbyte); - - item = new BoolNullableMap { tosbyte = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tosbyte == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.tosbyte, find.tosbyte); - Assert.Equal(false, find.tosbyte); - - //update all - item.tosbyte = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbyte, find.tosbyte); - Assert.Equal(true, find.tosbyte); - - item.tosbyte = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbyte, find.tosbyte); - Assert.Equal(false, find.tosbyte); - - item.tosbyte = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tosbyte == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.tosbyte, find.tosbyte); - Assert.Equal(false, find.tosbyte); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tosbyte, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.tosbyte); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tosbyte, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tosbyte); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tosbyte, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tosbyte == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tosbyte); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tosbyte == true).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tosbyte == null).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tosbyte == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void SByteNullable() - { - //insert - var orm = g.dameng; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbytenullable, find.tosbytenullable); - Assert.Equal(true, find.tosbytenullable); - - item = new BoolNullableMap { tosbytenullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbytenullable, find.tosbytenullable); - Assert.Equal(false, find.tosbytenullable); - - item = new BoolNullableMap { tosbytenullable = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tosbytenullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbytenullable, find.tosbytenullable); - Assert.Null(find.tosbytenullable); - - //update all - item.tosbytenullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbytenullable, find.tosbytenullable); - Assert.Equal(true, find.tosbytenullable); - - item.tosbytenullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbytenullable, find.tosbytenullable); - Assert.Equal(false, find.tosbytenullable); - - item.tosbytenullable = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tosbytenullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbytenullable, find.tosbytenullable); - Assert.Null(find.tosbytenullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tosbytenullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.tosbytenullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tosbytenullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tosbytenullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tosbytenullable, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tosbytenullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.tosbytenullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tosbytenullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tosbytenullable == null).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tosbytenullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void Short() - { - //insert - var orm = g.dameng; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toshort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshort, find.toshort); - Assert.Equal(true, find.toshort); - - item = new BoolNullableMap { toshort = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshort, find.toshort); - Assert.Equal(false, find.toshort); - - item = new BoolNullableMap { toshort = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toshort == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.toshort, find.toshort); - Assert.Equal(false, find.toshort); - - //update all - item.toshort = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshort, find.toshort); - Assert.Equal(true, find.toshort); - - item.toshort = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshort, find.toshort); - Assert.Equal(false, find.toshort); - - item.toshort = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toshort == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.toshort, find.toshort); - Assert.Equal(false, find.toshort); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toshort, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.toshort); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toshort, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toshort); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toshort, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toshort == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toshort); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toshort == true).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toshort == null).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toshort == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void ShortNullable() - { - //insert - var orm = g.dameng; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshortnullable, find.toshortnullable); - Assert.Equal(true, find.toshortnullable); - - item = new BoolNullableMap { toshortnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshortnullable, find.toshortnullable); - Assert.Equal(false, find.toshortnullable); - - item = new BoolNullableMap { toshortnullable = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toshortnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshortnullable, find.toshortnullable); - Assert.Null(find.toshortnullable); - - //update all - item.toshortnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshortnullable, find.toshortnullable); - Assert.Equal(true, find.toshortnullable); - - item.toshortnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshortnullable, find.toshortnullable); - Assert.Equal(false, find.toshortnullable); - - item.toshortnullable = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toshortnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshortnullable, find.toshortnullable); - Assert.Null(find.toshortnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toshortnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.toshortnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toshortnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toshortnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toshortnullable, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toshortnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.toshortnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toshortnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toshortnullable == null).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toshortnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void Int() - { - //insert - var orm = g.dameng; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toint, find.toint); - Assert.Equal(true, find.toint); - - item = new BoolNullableMap { toint = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toint, find.toint); - Assert.Equal(false, find.toint); - - item = new BoolNullableMap { toint = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toint == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.toint, find.toint); - Assert.Equal(false, find.toint); - - //update all - item.toint = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toint, find.toint); - Assert.Equal(true, find.toint); - - item.toint = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toint, find.toint); - Assert.Equal(false, find.toint); - - item.toint = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toint == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.toint, find.toint); - Assert.Equal(false, find.toint); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toint, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.toint); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toint, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toint); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toint, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toint == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toint); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toint == true).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toint == null).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toint == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void IntNullable() - { - //insert - var orm = g.dameng; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tointnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tointnullable, find.tointnullable); - Assert.Equal(true, find.tointnullable); - - item = new BoolNullableMap { tointnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tointnullable, find.tointnullable); - Assert.Equal(false, find.tointnullable); - - item = new BoolNullableMap { tointnullable = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tointnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tointnullable, find.tointnullable); - Assert.Null(find.tointnullable); - - //update all - item.tointnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tointnullable, find.tointnullable); - Assert.Equal(true, find.tointnullable); - - item.tointnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tointnullable, find.tointnullable); - Assert.Equal(false, find.tointnullable); - - item.tointnullable = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tointnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tointnullable, find.tointnullable); - Assert.Null(find.tointnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tointnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.tointnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tointnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tointnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tointnullable, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tointnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.tointnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tointnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tointnullable == null).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tointnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void Long() - { - //insert - var orm = g.dameng; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tolong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolong, find.tolong); - Assert.Equal(true, find.tolong); - - item = new BoolNullableMap { tolong = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolong, find.tolong); - Assert.Equal(false, find.tolong); - - item = new BoolNullableMap { tolong = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tolong == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.tolong, find.tolong); - Assert.Equal(false, find.tolong); - - //update all - item.tolong = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolong, find.tolong); - Assert.Equal(true, find.tolong); - - item.tolong = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolong, find.tolong); - Assert.Equal(false, find.tolong); - - item.tolong = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tolong == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.tolong, find.tolong); - Assert.Equal(false, find.tolong); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tolong, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.tolong); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tolong, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tolong); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tolong, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tolong == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tolong); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tolong == true).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tolong == null).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tolong == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void LongNullable() - { - //insert - var orm = g.dameng; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolongnullable, find.tolongnullable); - Assert.Equal(true, find.tolongnullable); - - item = new BoolNullableMap { tolongnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolongnullable, find.tolongnullable); - Assert.Equal(false, find.tolongnullable); - - item = new BoolNullableMap { tolongnullable = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tolongnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolongnullable, find.tolongnullable); - Assert.Null(find.tolongnullable); - - //update all - item.tolongnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolongnullable, find.tolongnullable); - Assert.Equal(true, find.tolongnullable); - - item.tolongnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolongnullable, find.tolongnullable); - Assert.Equal(false, find.tolongnullable); - - item.tolongnullable = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tolongnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolongnullable, find.tolongnullable); - Assert.Null(find.tolongnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tolongnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.tolongnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tolongnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tolongnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tolongnullable, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tolongnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.tolongnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tolongnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tolongnullable == null).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tolongnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - - [Fact] - public void Byte() - { - //insert - var orm = g.dameng; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tobyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobyte, find.tobyte); - Assert.Equal(true, find.tobyte); - - item = new BoolNullableMap { tobyte = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobyte, find.tobyte); - Assert.Equal(false, find.tobyte); - - item = new BoolNullableMap { tobyte = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tobyte == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.tobyte, find.tobyte); - Assert.Equal(false, find.tobyte); - - //update all - item.tobyte = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobyte, find.tobyte); - Assert.Equal(true, find.tobyte); - - item.tobyte = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobyte, find.tobyte); - Assert.Equal(false, find.tobyte); - - item.tobyte = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tobyte == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.tobyte, find.tobyte); - Assert.Equal(false, find.tobyte); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobyte, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.tobyte); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobyte, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tobyte); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobyte, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tobyte == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tobyte); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tobyte == true).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tobyte == null).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tobyte == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void ByteNullable() - { - //insert - var orm = g.dameng; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobytenullable, find.tobytenullable); - Assert.Equal(true, find.tobytenullable); - - item = new BoolNullableMap { tobytenullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobytenullable, find.tobytenullable); - Assert.Equal(false, find.tobytenullable); - - item = new BoolNullableMap { tobytenullable = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tobytenullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobytenullable, find.tobytenullable); - Assert.Null(find.tobytenullable); - - //update all - item.tobytenullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobytenullable, find.tobytenullable); - Assert.Equal(true, find.tobytenullable); - - item.tobytenullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobytenullable, find.tobytenullable); - Assert.Equal(false, find.tobytenullable); - - item.tobytenullable = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tobytenullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobytenullable, find.tobytenullable); - Assert.Null(find.tobytenullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobytenullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.tobytenullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobytenullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tobytenullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobytenullable, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tobytenullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.tobytenullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tobytenullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tobytenullable == null).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tobytenullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void UShort() - { - //insert - var orm = g.dameng; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toushort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushort, find.toushort); - Assert.Equal(true, find.toushort); - - item = new BoolNullableMap { toushort = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushort, find.toushort); - Assert.Equal(false, find.toushort); - - item = new BoolNullableMap { toushort = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toushort == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.toushort, find.toushort); - Assert.Equal(false, find.toushort); - - //update all - item.toushort = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushort, find.toushort); - Assert.Equal(true, find.toushort); - - item.toushort = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushort, find.toushort); - Assert.Equal(false, find.toushort); - - item.toushort = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toushort == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.toushort, find.toushort); - Assert.Equal(false, find.toushort); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toushort, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.toushort); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toushort, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toushort); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toushort, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toushort == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toushort); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toushort == true).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toushort == null).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toushort == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void UShortNullable() - { - //insert - var orm = g.dameng; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushortnullable, find.toushortnullable); - Assert.Equal(true, find.toushortnullable); - - item = new BoolNullableMap { toushortnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushortnullable, find.toushortnullable); - Assert.Equal(false, find.toushortnullable); - - item = new BoolNullableMap { toushortnullable = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toushortnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushortnullable, find.toushortnullable); - Assert.Null(find.toushortnullable); - - //update all - item.toushortnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushortnullable, find.toushortnullable); - Assert.Equal(true, find.toushortnullable); - - item.toushortnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushortnullable, find.toushortnullable); - Assert.Equal(false, find.toushortnullable); - - item.toushortnullable = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toushortnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushortnullable, find.toushortnullable); - Assert.Null(find.toushortnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toushortnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.toushortnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toushortnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toushortnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toushortnullable, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toushortnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.toushortnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toushortnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toushortnullable == null).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toushortnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void UInt() - { - //insert - var orm = g.dameng; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.touint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touint, find.touint); - Assert.Equal(true, find.touint); - - item = new BoolNullableMap { touint = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touint, find.touint); - Assert.Equal(false, find.touint); - - item = new BoolNullableMap { touint = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.touint == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.touint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.touint, find.touint); - Assert.Equal(false, find.touint); - - //update all - item.touint = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touint, find.touint); - Assert.Equal(true, find.touint); - - item.touint = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touint, find.touint); - Assert.Equal(false, find.touint); - - item.touint = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.touint == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.touint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.touint, find.touint); - Assert.Equal(false, find.touint); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.touint, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.touint); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.touint, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.touint); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.touint, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.touint == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.touint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.touint); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.touint == true).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.touint == null).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.touint == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void UIntNullable() - { - //insert - var orm = g.dameng; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.touintnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touintnullable, find.touintnullable); - Assert.Equal(true, find.touintnullable); - - item = new BoolNullableMap { touintnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touintnullable, find.touintnullable); - Assert.Equal(false, find.touintnullable); - - item = new BoolNullableMap { touintnullable = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.touintnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touintnullable, find.touintnullable); - Assert.Null(find.touintnullable); - - //update all - item.touintnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touintnullable, find.touintnullable); - Assert.Equal(true, find.touintnullable); - - item.touintnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touintnullable, find.touintnullable); - Assert.Equal(false, find.touintnullable); - - item.touintnullable = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.touintnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touintnullable, find.touintnullable); - Assert.Null(find.touintnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.touintnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.touintnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.touintnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.touintnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.touintnullable, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.touintnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.touintnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.touintnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.touintnullable == null).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.touintnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void ULong() - { - //insert - var orm = g.dameng; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toulong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulong, find.toulong); - Assert.Equal(true, find.toulong); - - item = new BoolNullableMap { toulong = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulong, find.toulong); - Assert.Equal(false, find.toulong); - - item = new BoolNullableMap { toulong = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toulong == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.toulong, find.toulong); - Assert.Equal(false, find.toulong); - - //update all - item.toulong = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulong, find.toulong); - Assert.Equal(true, find.toulong); - - item.toulong = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulong, find.toulong); - Assert.Equal(false, find.toulong); - - item.toulong = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toulong == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.toulong, find.toulong); - Assert.Equal(false, find.toulong); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toulong, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.toulong); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toulong, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toulong); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toulong, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toulong == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toulong); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toulong == true).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toulong == null).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toulong == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void ULongNullable() - { - //insert - var orm = g.dameng; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulongnullable, find.toulongnullable); - Assert.Equal(true, find.toulongnullable); - - item = new BoolNullableMap { toulongnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulongnullable, find.toulongnullable); - Assert.Equal(false, find.toulongnullable); - - item = new BoolNullableMap { toulongnullable = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toulongnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulongnullable, find.toulongnullable); - Assert.Null(find.toulongnullable); - - //update all - item.toulongnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulongnullable, find.toulongnullable); - Assert.Equal(true, find.toulongnullable); - - item.toulongnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulongnullable, find.toulongnullable); - Assert.Equal(false, find.toulongnullable); - - item.toulongnullable = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toulongnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulongnullable, find.toulongnullable); - Assert.Null(find.toulongnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toulongnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.toulongnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toulongnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toulongnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toulongnullable, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toulongnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.toulongnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toulongnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toulongnullable == null).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toulongnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - - [Fact] - public void TimeSpan() - { - } - [Fact] - public void TimeSpanNullable() - { - } - [Fact] - public void DateTime() - { - } - [Fact] - public void DateTimeNullable() - { - } - - [Fact] - public void ByteArray() - { - } - [Fact] - public void String() - { - //insert - var orm = g.dameng; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tostring == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tostring, find.tostring); - Assert.Equal(true, find.tostring); - - item = new BoolNullableMap { tostring = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tostring == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tostring, find.tostring); - Assert.Equal(false, find.tostring); - - item = new BoolNullableMap { tostring = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tostring == false).First()); - find = orm.Select().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().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tostring == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tostring, find.tostring); - Assert.Equal(true, find.tostring); - - item.tostring = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tostring == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tostring, find.tostring); - Assert.Equal(false, find.tostring); - - item.tostring = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tostring == false).First()); - find = orm.Select().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().Where(a => a.id == item.id).Set(a => a.tostring, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tostring == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.tostring); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tostring, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tostring == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tostring); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tostring, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tostring == false).First()); - find = orm.Select().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().Where(a => a.id == item.id && a.tostring == true).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tostring == false).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tostring == null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - - [Fact] - public void Guid() - { - } - [Fact] - public void GuidNullable() - { - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/MapType/BoolTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/MapType/BoolTest.cs deleted file mode 100644 index 474935ae7..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/MapType/BoolTest.cs +++ /dev/null @@ -1,1105 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using Xunit; - -namespace FreeSql.Tests.Odbc.DamengMapType -{ - public class BoolTest - { - - class BoolMap - { - public Guid id { get; set; } - [Column(MapType = typeof(bool?))] - public bool toboolnullable { get; set; } = true; - - [Column(MapType = typeof(sbyte))] - public bool tosbyte { get; set; } = true; - [Column(MapType = typeof(sbyte?))] - public bool tosbytenullable { get; set; } = true; - - [Column(MapType = typeof(short))] - public bool toshort { get; set; } = true; - - [Column(MapType = typeof(short?))] - public bool toshortnullable { get; set; } = true; - - [Column(MapType = typeof(int))] - public bool toint { get; set; } = true; - - [Column(MapType = typeof(int?))] - public bool tointnullable { get; set; } = true; - - [Column(MapType = typeof(long))] - public bool tolong { get; set; } = true; - [Column(MapType = typeof(long?))] - public bool tolongnullable { get; set; } = true; - - [Column(MapType = typeof(byte))] - public bool tobyte { get; set; } = true; - [Column(MapType = typeof(byte?))] - public bool tobytenullable { get; set; } = true; - - [Column(MapType = typeof(ushort))] - public bool toushort { get; set; } = true; - - [Column(MapType = typeof(ushort?))] - public bool toushortnullable { get; set; } = true; - - [Column(MapType = typeof(uint))] - public bool touint { get; set; } = true; - - [Column(MapType = typeof(uint?))] - public bool touintnullable { get; set; } = true; - - [Column(MapType = typeof(ulong))] - public bool toulong { get; set; } = true; - [Column(MapType = typeof(ulong?))] - public bool toulongnullable { get; set; } = true; - - [Column(MapType = typeof(string))] - public bool tostring { get; set; } = true; - } - - [Fact] - public void BoolNullable() - { - //insert - var orm = g.dameng; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toboolnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toboolnullable, find.toboolnullable); - Assert.True(find.toboolnullable); - - item = new BoolMap { toboolnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toboolnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toboolnullable, find.toboolnullable); - Assert.False(find.toboolnullable); - - //update all - item.toboolnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toboolnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toboolnullable, find.toboolnullable); - Assert.True(find.toboolnullable); - - item.toboolnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toboolnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toboolnullable, find.toboolnullable); - Assert.False(find.toboolnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toboolnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toboolnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.toboolnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toboolnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toboolnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.toboolnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toboolnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toboolnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void SByte() - { - //insert - var orm = g.dameng; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tosbyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbyte, find.tosbyte); - Assert.True(find.tosbyte); - - item = new BoolMap { tosbyte = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbyte, find.tosbyte); - Assert.False(find.tosbyte); - - //update all - item.tosbyte = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbyte, find.tosbyte); - Assert.True(find.tosbyte); - - item.tosbyte = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbyte, find.tosbyte); - Assert.False(find.tosbyte); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tosbyte, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.tosbyte); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tosbyte, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.tosbyte); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tosbyte == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tosbyte == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void SByteNullable() - { - //insert - var orm = g.dameng; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbytenullable, find.tosbytenullable); - Assert.True(find.tosbytenullable); - - item = new BoolMap { tosbytenullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbytenullable, find.tosbytenullable); - Assert.False(find.tosbytenullable); - - //update all - item.tosbytenullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbytenullable, find.tosbytenullable); - Assert.True(find.tosbytenullable); - - item.tosbytenullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbytenullable, find.tosbytenullable); - Assert.False(find.tosbytenullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tosbytenullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.tosbytenullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tosbytenullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.tosbytenullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tosbytenullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tosbytenullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void Short() - { - //insert - var orm = g.dameng; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toshort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshort, find.toshort); - Assert.True(find.toshort); - - item = new BoolMap { toshort = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshort, find.toshort); - Assert.False(find.toshort); - - //update all - item.toshort = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshort, find.toshort); - Assert.True(find.toshort); - - item.toshort = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshort, find.toshort); - Assert.False(find.toshort); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toshort, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.toshort); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toshort, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.toshort); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toshort == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toshort == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void ShortNullable() - { - //insert - var orm = g.dameng; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshortnullable, find.toshortnullable); - Assert.True(find.toshortnullable); - - item = new BoolMap { toshortnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshortnullable, find.toshortnullable); - Assert.False(find.toshortnullable); - - //update all - item.toshortnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshortnullable, find.toshortnullable); - Assert.True(find.toshortnullable); - - item.toshortnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshortnullable, find.toshortnullable); - Assert.False(find.toshortnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toshortnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.toshortnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toshortnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.toshortnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toshortnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toshortnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void Int() - { - //insert - var orm = g.dameng; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toint, find.toint); - Assert.True(find.toint); - - item = new BoolMap { toint = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toint, find.toint); - Assert.False(find.toint); - - //update all - item.toint = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toint, find.toint); - Assert.True(find.toint); - - item.toint = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toint, find.toint); - Assert.False(find.toint); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toint, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.toint); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toint, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.toint); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toint == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toint == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void IntNullable() - { - //insert - var orm = g.dameng; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tointnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tointnullable, find.tointnullable); - Assert.True(find.tointnullable); - - item = new BoolMap { tointnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tointnullable, find.tointnullable); - Assert.False(find.tointnullable); - - //update all - item.tointnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tointnullable, find.tointnullable); - Assert.True(find.tointnullable); - - item.tointnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tointnullable, find.tointnullable); - Assert.False(find.tointnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tointnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.tointnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tointnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.tointnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tointnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tointnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void Long() - { - //insert - var orm = g.dameng; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tolong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolong, find.tolong); - Assert.True(find.tolong); - - item = new BoolMap { tolong = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolong, find.tolong); - Assert.False(find.tolong); - - //update all - item.tolong = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolong, find.tolong); - Assert.True(find.tolong); - - item.tolong = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolong, find.tolong); - Assert.False(find.tolong); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tolong, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.tolong); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tolong, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.tolong); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tolong == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tolong == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void LongNullable() - { - //insert - var orm = g.dameng; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolongnullable, find.tolongnullable); - Assert.True(find.tolongnullable); - - item = new BoolMap { tolongnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolongnullable, find.tolongnullable); - Assert.False(find.tolongnullable); - - //update all - item.tolongnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolongnullable, find.tolongnullable); - Assert.True(find.tolongnullable); - - item.tolongnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolongnullable, find.tolongnullable); - Assert.False(find.tolongnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tolongnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.tolongnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tolongnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.tolongnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tolongnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tolongnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - - [Fact] - public void Byte() - { - //insert - var orm = g.dameng; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tobyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobyte, find.tobyte); - Assert.True(find.tobyte); - - item = new BoolMap { tobyte = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobyte, find.tobyte); - Assert.False(find.tobyte); - - //update all - item.tobyte = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobyte, find.tobyte); - Assert.True(find.tobyte); - - item.tobyte = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobyte, find.tobyte); - Assert.False(find.tobyte); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobyte, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.tobyte); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobyte, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.tobyte); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tobyte == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tobyte == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void ByteNullable() - { - //insert - var orm = g.dameng; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobytenullable, find.tobytenullable); - Assert.True(find.tobytenullable); - - item = new BoolMap { tobytenullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobytenullable, find.tobytenullable); - Assert.False(find.tobytenullable); - - //update all - item.tobytenullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobytenullable, find.tobytenullable); - Assert.True(find.tobytenullable); - - item.tobytenullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobytenullable, find.tobytenullable); - Assert.False(find.tobytenullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobytenullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.tobytenullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobytenullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.tobytenullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tobytenullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tobytenullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void UShort() - { - //insert - var orm = g.dameng; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toushort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushort, find.toushort); - Assert.True(find.toushort); - - item = new BoolMap { toushort = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushort, find.toushort); - Assert.False(find.toushort); - - //update all - item.toushort = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushort, find.toushort); - Assert.True(find.toushort); - - item.toushort = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushort, find.toushort); - Assert.False(find.toushort); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toushort, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.toushort); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toushort, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.toushort); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toushort == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toushort == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void UShortNullable() - { - //insert - var orm = g.dameng; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushortnullable, find.toushortnullable); - Assert.True(find.toushortnullable); - - item = new BoolMap { toushortnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushortnullable, find.toushortnullable); - Assert.False(find.toushortnullable); - - //update all - item.toushortnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushortnullable, find.toushortnullable); - Assert.True(find.toushortnullable); - - item.toushortnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushortnullable, find.toushortnullable); - Assert.False(find.toushortnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toushortnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.toushortnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toushortnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.toushortnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toushortnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toushortnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void UInt() - { - //insert - var orm = g.dameng; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.touint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touint, find.touint); - Assert.True(find.touint); - - item = new BoolMap { touint = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touint, find.touint); - Assert.False(find.touint); - - //update all - item.touint = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touint, find.touint); - Assert.True(find.touint); - - item.touint = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touint, find.touint); - Assert.False(find.touint); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.touint, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.touint); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.touint, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.touint); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.touint == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.touint == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void UIntNullable() - { - //insert - var orm = g.dameng; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.touintnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touintnullable, find.touintnullable); - Assert.True(find.touintnullable); - - item = new BoolMap { touintnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touintnullable, find.touintnullable); - Assert.False(find.touintnullable); - - //update all - item.touintnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touintnullable, find.touintnullable); - Assert.True(find.touintnullable); - - item.touintnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touintnullable, find.touintnullable); - Assert.False(find.touintnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.touintnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.touintnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.touintnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.touintnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.touintnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.touintnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void ULong() - { - //insert - var orm = g.dameng; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toulong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulong, find.toulong); - Assert.True(find.toulong); - - item = new BoolMap { toulong = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulong, find.toulong); - Assert.False(find.toulong); - - //update all - item.toulong = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulong, find.toulong); - Assert.True(find.toulong); - - item.toulong = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulong, find.toulong); - Assert.False(find.toulong); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toulong, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.toulong); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toulong, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.toulong); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toulong == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toulong == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void ULongNullable() - { - //insert - var orm = g.dameng; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulongnullable, find.toulongnullable); - Assert.True(find.toulongnullable); - - item = new BoolMap { toulongnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulongnullable, find.toulongnullable); - Assert.False(find.toulongnullable); - - //update all - item.toulongnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulongnullable, find.toulongnullable); - Assert.True(find.toulongnullable); - - item.toulongnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulongnullable, find.toulongnullable); - Assert.False(find.toulongnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toulongnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.toulongnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toulongnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.toulongnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toulongnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toulongnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - - [Fact] - public void TimeSpan() - { - } - [Fact] - public void TimeSpanNullable() - { - } - [Fact] - public void DateTime() - { - } - [Fact] - public void DateTimeNullable() - { - } - - [Fact] - public void ByteArray() - { - } - [Fact] - public void String() - { - //insert - var orm = g.dameng; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tostring == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tostring, find.tostring); - Assert.True(find.tostring); - - item = new BoolMap { tostring = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tostring == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tostring, find.tostring); - Assert.False(find.tostring); - - //update all - item.tostring = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tostring == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tostring, find.tostring); - Assert.True(find.tostring); - - item.tostring = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tostring == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tostring, find.tostring); - Assert.False(find.tostring); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tostring, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tostring == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.tostring); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tostring, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tostring == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.tostring); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tostring == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tostring == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - - [Fact] - public void Guid() - { - } - [Fact] - public void GuidNullable() - { - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/MapType/DateTimeOffSetTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/MapType/DateTimeOffSetTest.cs deleted file mode 100644 index 0a31d1920..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/MapType/DateTimeOffSetTest.cs +++ /dev/null @@ -1,54 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Numerics; -using Xunit; - -namespace FreeSql.Tests.Odbc.DamengMapType -{ - public class DateTimeOffSetTest - { - class Dtos_dt - { - public Guid id { get; set; } - - [Column(MapType = typeof(DateTime))] - public DateTimeOffset dtos_to_dt { get; set; } - [Column(MapType = typeof(DateTime))] - public DateTimeOffset? dtofnil_to_dt { get; set; } - } - [Fact] - public void DateTimeToDateTimeOffSet() - { - //insert - var orm = g.dameng; - var item = new Dtos_dt { dtos_to_dt = DateTimeOffset.Now, dtofnil_to_dt = DateTimeOffset.Now }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g")); - Assert.Equal(item.dtofnil_to_dt.Value.ToString("g"), find.dtofnil_to_dt.Value.ToString("g")); - - //update all - item.dtos_to_dt = DateTimeOffset.Now; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g")); - Assert.Equal(item.dtofnil_to_dt.Value.ToString("g"), find.dtofnil_to_dt.Value.ToString("g")); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.dtos_to_dt, item.dtos_to_dt = DateTimeOffset.Now).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g")); - Assert.Equal(item.dtofnil_to_dt.Value.ToString("g"), find.dtofnil_to_dt.Value.ToString("g")); - - //delete - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/MapType/EnumTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/MapType/EnumTest.cs deleted file mode 100644 index a5f708b59..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/MapType/EnumTest.cs +++ /dev/null @@ -1,261 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Numerics; -using Xunit; - -namespace FreeSql.Tests.Odbc.DamengMapType -{ - public class EnumTest - { - class EnumTestMap - { - public Guid id { get; set; } - - [Column(MapType = typeof(string))] - public ToStringMapEnum enum_to_string { get; set; } - [Column(MapType = typeof(string))] - public ToStringMapEnum? enumnullable_to_string { get; set; } - - [Column(MapType = typeof(int))] - public ToStringMapEnum enum_to_int { get; set; } - [Column(MapType = typeof(int?))] - public ToStringMapEnum? enumnullable_to_int { get; set; } - } - public enum ToStringMapEnum { й, abc, } - [Fact] - public void EnumToString() - { - //insert - var orm = g.dameng; - var item = new EnumTestMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.й).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_string, find.enum_to_string); - Assert.Equal(ToStringMapEnum.й, find.enum_to_string); - - item = new EnumTestMap { enum_to_string = ToStringMapEnum.abc }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_string, find.enum_to_string); - Assert.Equal(ToStringMapEnum.abc, find.enum_to_string); - - //update all - item.enum_to_string = ToStringMapEnum.; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_string, find.enum_to_string); - Assert.Equal(ToStringMapEnum., find.enum_to_string); - - item.enum_to_string = ToStringMapEnum.й; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.й).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_string, find.enum_to_string); - Assert.Equal(ToStringMapEnum.й, find.enum_to_string); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(ToStringMapEnum., find.enum_to_string); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.abc).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(ToStringMapEnum.abc, find.enum_to_string); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.й).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void EnumNullableToString() - { - //insert - var orm = g.dameng; - var item = new EnumTestMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().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().AppendData(item).ExecuteAffrows()); - find = orm.Select().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); - Assert.Equal(ToStringMapEnum.й, find.enumnullable_to_string); - - //update all - item.enumnullable_to_string = ToStringMapEnum.; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().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); - Assert.Equal(ToStringMapEnum., find.enumnullable_to_string); - - item.enumnullable_to_string = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.).First()); - find = orm.Select().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().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, ToStringMapEnum.abc).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_string); - - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First()); - find = orm.Select().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().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.й).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.enumnullable_to_string == null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - - [Fact] - public void EnumToInt() - { - //insert - var orm = g.dameng; - var item = new EnumTestMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.й).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_int, find.enum_to_int); - Assert.Equal(ToStringMapEnum.й, find.enum_to_int); - - item = new EnumTestMap { enum_to_int = ToStringMapEnum.abc }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.abc).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_int, find.enum_to_int); - Assert.Equal(ToStringMapEnum.abc, find.enum_to_int); - - //update all - item.enum_to_int = ToStringMapEnum.; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_int, find.enum_to_int); - Assert.Equal(ToStringMapEnum., find.enum_to_int); - - item.enum_to_int = ToStringMapEnum.й; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.й).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_int, find.enum_to_int); - Assert.Equal(ToStringMapEnum.й, find.enum_to_int); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.enum_to_int, ToStringMapEnum.).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(ToStringMapEnum., find.enum_to_int); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.enum_to_int, ToStringMapEnum.abc).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.abc).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(ToStringMapEnum.abc, find.enum_to_int); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.й).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.abc).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void EnumNullableToInt() - { - //insert - var orm = g.dameng; - var item = new EnumTestMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.enumnullable_to_int == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int); - Assert.Null(find.enumnullable_to_int); - - item = new EnumTestMap { enumnullable_to_int = ToStringMapEnum.й }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.й).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int); - Assert.Equal(ToStringMapEnum.й, find.enumnullable_to_int); - - //update all - item.enumnullable_to_int = ToStringMapEnum.; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int); - Assert.Equal(ToStringMapEnum., find.enumnullable_to_int); - - item.enumnullable_to_int = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.).First()); - find = orm.Select().Where(a => a.id == item.id && a.enumnullable_to_int == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int); - Assert.Null(find.enumnullable_to_int); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.enumnullable_to_int, ToStringMapEnum.abc).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.abc).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_int); - - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.enumnullable_to_int, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.abc).First()); - find = orm.Select().Where(a => a.id == item.id && a.enumnullable_to_int == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.enumnullable_to_int); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.й).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.enumnullable_to_int == null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/MapType/ToStringTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/MapType/ToStringTest.cs deleted file mode 100644 index 9642e47a8..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/Dameng/MapType/ToStringTest.cs +++ /dev/null @@ -1,570 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Numerics; -using Xunit; - -namespace FreeSql.Tests.Odbc.DamengMapType -{ - public class ToStringTest - { - class ToStringMap - { - public Guid id { get; set; } - - [Column(MapType = typeof(string))] - public TimeSpan timespan_to_string { get; set; } - [Column(MapType = typeof(string))] - public TimeSpan? timespannullable_to_string { get; set; } - - [Column(MapType = typeof(string))] - public DateTime datetime_to_string { get; set; } - [Column(MapType = typeof(string))] - public DateTime? datetimenullable_to_string { get; set; } - - [Column(MapType = typeof(string))] - public Guid guid_to_string { get; set; } - [Column(MapType = typeof(string))] - public Guid? guidnullable_to_string { get; set; } - - [Column(MapType = typeof(string))] - public ToStringMapEnum enum_to_string { get; set; } - [Column(MapType = typeof(string))] - public ToStringMapEnum? enumnullable_to_string { get; set; } - - [Column(MapType = typeof(string))] - public BigInteger biginteger_to_string { get; set; } - [Column(MapType = typeof(string))] - public BigInteger? bigintegernullable_to_string { get; set; } - } - public enum ToStringMapEnum { й, abc, } - [Fact] - public void Enum1() - { - //insert - var orm = g.dameng; - var item = new ToStringMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.й).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_string, find.enum_to_string); - Assert.Equal(ToStringMapEnum.й, find.enum_to_string); - - item = new ToStringMap { enum_to_string = ToStringMapEnum.abc }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_string, find.enum_to_string); - Assert.Equal(ToStringMapEnum.abc, find.enum_to_string); - - //update all - item.enum_to_string = ToStringMapEnum.; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_string, find.enum_to_string); - Assert.Equal(ToStringMapEnum., find.enum_to_string); - - item.enum_to_string = ToStringMapEnum.й; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.й).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_string, find.enum_to_string); - Assert.Equal(ToStringMapEnum.й, find.enum_to_string); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(ToStringMapEnum., find.enum_to_string); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.abc).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(ToStringMapEnum.abc, find.enum_to_string); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.й).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void EnumNullable() - { - //insert - var orm = g.dameng; - var item = new ToStringMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().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().AppendData(item).ExecuteAffrows()); - find = orm.Select().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); - Assert.Equal(ToStringMapEnum.й, find.enumnullable_to_string); - - //update all - item.enumnullable_to_string = ToStringMapEnum.; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().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); - Assert.Equal(ToStringMapEnum., find.enumnullable_to_string); - - item.enumnullable_to_string = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.).First()); - find = orm.Select().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().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, ToStringMapEnum.abc).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_string); - - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First()); - find = orm.Select().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().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.й).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.enumnullable_to_string == null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void BigInteger1() - { - //insert - var orm = g.dameng; - var item = new ToStringMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.biginteger_to_string == 0).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.biginteger_to_string, find.biginteger_to_string); - Assert.Equal(0, find.biginteger_to_string); - - item = new ToStringMap { biginteger_to_string = 100 }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.biginteger_to_string == 100).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.biginteger_to_string, find.biginteger_to_string); - Assert.Equal(100, find.biginteger_to_string); - - //update all - item.biginteger_to_string = 200; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.biginteger_to_string == 200).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.biginteger_to_string, find.biginteger_to_string); - Assert.Equal(200, find.biginteger_to_string); - - item.biginteger_to_string = 205; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.biginteger_to_string == 205).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.biginteger_to_string, find.biginteger_to_string); - Assert.Equal(205, find.biginteger_to_string); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.biginteger_to_string, 522).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.biginteger_to_string == 522).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(522, find.biginteger_to_string); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.biginteger_to_string, 10005).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.biginteger_to_string == 10005).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(10005, find.biginteger_to_string); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.biginteger_to_string == 522).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.biginteger_to_string == 205).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.biginteger_to_string == 10005).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void BigIntegerNullable() - { - //insert - var orm = g.dameng; - var item = new ToStringMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().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().AppendData(item).ExecuteAffrows()); - find = orm.Select().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); - Assert.Equal(101, find.bigintegernullable_to_string); - - //update all - item.bigintegernullable_to_string = 2004; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - 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().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).First()); - find = orm.Select().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().Where(a => a.id == item.id).Set(a => a.bigintegernullable_to_string, 998).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(998, find.bigintegernullable_to_string); - - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.bigintegernullable_to_string, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).First()); - find = orm.Select().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().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void TimeSpan1() - { - //insert - var orm = g.dameng; - var item = new ToStringMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.timespan_to_string, find.timespan_to_string); - Assert.Equal(TimeSpan.Zero, find.timespan_to_string); - - item = new ToStringMap { timespan_to_string = TimeSpan.FromDays(1) }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.timespan_to_string, find.timespan_to_string); - Assert.Equal(TimeSpan.FromDays(1), find.timespan_to_string); - - //update all - item.timespan_to_string = TimeSpan.FromHours(10); - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.timespan_to_string, find.timespan_to_string); - Assert.Equal(TimeSpan.FromHours(10), find.timespan_to_string); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.timespan_to_string, TimeSpan.FromHours(11)).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(TimeSpan.FromHours(11), find.timespan_to_string); - - //delete - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void TimeSpanNullable() - { - //insert - var orm = g.dameng; - var item = new ToStringMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string); - Assert.Null(find.timespannullable_to_string); - - item = new ToStringMap { timespannullable_to_string = TimeSpan.FromDays(1) }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string); - Assert.Equal(TimeSpan.FromDays(1), find.timespannullable_to_string); - - //update all - item.timespannullable_to_string = TimeSpan.FromHours(10); - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string); - Assert.Equal(TimeSpan.FromHours(10), find.timespannullable_to_string); - - item.timespannullable_to_string = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string); - Assert.Null(find.timespannullable_to_string); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.timespannullable_to_string, TimeSpan.FromHours(11)).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(TimeSpan.FromHours(11), find.timespannullable_to_string); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.timespannullable_to_string, null).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.timespannullable_to_string); - - //delete - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void DateTime1() - { - //insert - var orm = g.dameng; - var item = new ToStringMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.datetime_to_string, find.datetime_to_string); - Assert.Equal(DateTime.MinValue, find.datetime_to_string); - - item = new ToStringMap { datetime_to_string = DateTime.Parse("2000-1-1") }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.datetime_to_string, find.datetime_to_string); - Assert.Equal(DateTime.Parse("2000-1-1"), find.datetime_to_string); - - //update all - item.datetime_to_string = DateTime.Parse("2000-1-11"); - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.datetime_to_string, find.datetime_to_string); - Assert.Equal(DateTime.Parse("2000-1-11"), find.datetime_to_string); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.datetime_to_string, DateTime.Parse("2000-1-12")).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(DateTime.Parse("2000-1-12"), find.datetime_to_string); - - //delete - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void DateTimeNullable() - { - //insert - var orm = g.dameng; - var item = new ToStringMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string); - Assert.Null(find.datetimenullable_to_string); - - item = new ToStringMap { datetimenullable_to_string = DateTime.Parse("2000-1-1") }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string); - Assert.Equal(DateTime.Parse("2000-1-1"), find.datetimenullable_to_string); - - //update all - item.datetimenullable_to_string = DateTime.Parse("2000-1-11"); - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string); - Assert.Equal(DateTime.Parse("2000-1-11"), find.datetimenullable_to_string); - - item.datetimenullable_to_string = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string); - Assert.Null(find.datetimenullable_to_string); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.datetimenullable_to_string, DateTime.Parse("2000-1-12")).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(DateTime.Parse("2000-1-12"), find.datetimenullable_to_string); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.datetimenullable_to_string, null).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.datetimenullable_to_string); - - //delete - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - - [Fact] - public void Guid1() - { - //insert - var orm = g.dameng; - var item = new ToStringMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.guid_to_string == Guid.Empty).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.guid_to_string, find.guid_to_string); - Assert.Equal(Guid.Empty, find.guid_to_string); - - var newid = Guid.NewGuid(); - item = new ToStringMap { guid_to_string = newid }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.guid_to_string == newid).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.guid_to_string, find.guid_to_string); - Assert.Equal(newid, find.guid_to_string); - - //update all - newid = Guid.NewGuid(); - item.guid_to_string = newid; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.guid_to_string == newid).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.guid_to_string, find.guid_to_string); - Assert.Equal(newid, find.guid_to_string); - - //update set - newid = Guid.NewGuid(); - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.guid_to_string, newid).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.guid_to_string == newid).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(newid, find.guid_to_string); - - //delete - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.guid_to_string == newid).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void GuidNullable() - { - //insert - var orm = g.dameng; - var item = new ToStringMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().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 }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().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); - Assert.Equal(newid, find.guidnullable_to_string); - - //update all - newid = Guid.NewGuid(); - item.guidnullable_to_string = newid; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().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); - Assert.Equal(newid, find.guidnullable_to_string); - - item.guidnullable_to_string = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().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().Where(a => a.id == item.id).Set(a => a.guidnullable_to_string, newid).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.guidnullable_to_string == newid).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(newid, find.guidnullable_to_string); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.guidnullable_to_string, null).ExecuteAffrows()); - find = orm.Select().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().Where(a => a.id == item.id && a.guidnullable_to_string == null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESDeleteTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESDeleteTest.cs deleted file mode 100644 index a9f8498e1..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESDeleteTest.cs +++ /dev/null @@ -1,106 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseES -{ - public class KingbaseESDeleteTest - { - - IDelete delete => g.kingbaseES.Delete(); //�������� - - [Table(Name = "tb_topic22211")] - class Topic - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int? Clicks { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - - [Fact] - public void Dywhere() - { - Assert.Null(g.kingbaseES.Delete().ToSql()); - var sql = g.kingbaseES.Delete(new[] { 1, 2 }).ToSql(); - Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" IN (1,2))", sql); - - sql = g.kingbaseES.Delete(new Topic { Id = 1, Title = "test" }).ToSql(); - Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" = 1)", sql); - - sql = g.kingbaseES.Delete(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).ToSql(); - Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" IN (1,2))", sql); - - sql = g.kingbaseES.Delete(new { id = 1 }).ToSql(); - Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" = 1)", sql); - - sql = g.kingbaseES.Delete(new[] { new { Id1 = 1, Id2 = 10 }, new { Id1 = 2, Id2 = 20 } }).ToSql(); - Assert.Equal("DELETE FROM \"MULTIPKTOPIC\" WHERE (\"ID1\" = 1 AND \"ID2\" = 10 OR \"ID1\" = 2 AND \"ID2\" = 20)", sql); - } - class MultiPkTopic - { - [Column(IsPrimary = true)] - public int Id1 { get; set; } - [Column(IsPrimary = true)] - public int Id2 { get; set; } - public int Clicks { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - - [Fact] - public void Where() - { - var sql = delete.Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" = 1)", sql); - - sql = delete.Where("id = :id", new { id = 1 }).ToSql().Replace("\r\n", ""); - Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (id = :id)", sql); - - var item = new Topic { Id = 1, Title = "newtitle" }; - sql = delete.Where(item).ToSql().Replace("\r\n", ""); - Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" = 1)", sql); - - var items = new List(); - for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 }); - - sql = delete.Where(items).ToSql().Replace("\r\n", ""); - Assert.Equal("DELETE FROM \"TB_TOPIC22211\" WHERE (\"ID\" IN (1,2,3,4,5,6,7,8,9,10))", sql); - } - [Fact] - public void ExecuteAffrows() - { - - var id = g.kingbaseES.Insert(new Topic { Title = "xxxx", CreateTime = DateTime.Now }).ExecuteIdentity(); - Assert.Equal(1, delete.Where(a => a.Id == id).ExecuteAffrows()); - } - [Fact] - public void ExecuteDeleted() - { - - //var item = g.kingbaseES.Insert(new Topic { Title = "xxxx", CreateTime = DateTime.Now }).ExecuteInserted(); - //Assert.Equal(item[0].Id, delete.Where(a => a.Id == item[0].Id).ExecuteDeleted()[0].Id); - } - - [Fact] - public void AsTable() - { - Assert.Null(g.kingbaseES.Delete().ToSql()); - var sql = g.kingbaseES.Delete(new[] { 1, 2 }).AsTable(a => "TopicAsTable").ToSql(); - Assert.Equal("DELETE FROM \"TOPICASTABLE\" WHERE (\"ID\" IN (1,2))", sql); - - sql = g.kingbaseES.Delete(new Topic { Id = 1, Title = "test" }).AsTable(a => "TopicAsTable").ToSql(); - Assert.Equal("DELETE FROM \"TOPICASTABLE\" WHERE (\"ID\" = 1)", sql); - - sql = g.kingbaseES.Delete(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).AsTable(a => "TopicAsTable").ToSql(); - Assert.Equal("DELETE FROM \"TOPICASTABLE\" WHERE (\"ID\" IN (1,2))", sql); - - sql = g.kingbaseES.Delete(new { id = 1 }).AsTable(a => "TopicAsTable").ToSql(); - Assert.Equal("DELETE FROM \"TOPICASTABLE\" WHERE (\"ID\" = 1)", sql); - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESInsertOrUpdateIfExistsDoNotingTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESInsertOrUpdateIfExistsDoNotingTest.cs deleted file mode 100644 index 740d3dbee..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESInsertOrUpdateIfExistsDoNotingTest.cs +++ /dev/null @@ -1,266 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseES -{ - public class KingbaseESInsertOrUpdateIfExistsDoNotingTest - { - IFreeSql fsql => g.kingbaseES; - - [Fact] - public void InsertOrUpdate_OnlyPrimary() - { - fsql.Delete().Where("1=1").ExecuteAffrows(); - var iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudb01 { id = 1 }); - var sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB01""(""ID"") VALUES(1) -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudb01 { id = 1 }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB01""(""ID"") VALUES(1) -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(0, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudb01 { id = 2 }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB01""(""ID"") VALUES(2) -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudb01 { id = 1 }, new tbioudb01 { id = 2 }, new tbioudb01 { id = 3 }, new tbioudb01 { id = 4 } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB01""(""ID"") VALUES(1), (2), (3), (4) -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(2, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudb01 { id = 1 }, new tbioudb01 { id = 2 }, new tbioudb01 { id = 3 }, new tbioudb01 { id = 4 } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB01""(""ID"") VALUES(1), (2), (3), (4) -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(0, iou.ExecuteAffrows()); - } - class tbioudb01 - { - public int id { get; set; } - } - - [Fact] - public void InsertOrUpdate_OnePrimary() - { - fsql.Delete().Where("1=1").ExecuteAffrows(); - var iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudb02 { id = 1, name = "01" }); - var sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB02""(""ID"", ""NAME"") VALUES(1, '01') -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudb02 { id = 1, name = "011" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB02""(""ID"", ""NAME"") VALUES(1, '011') -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(0, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudb02 { id = 2, name = "02" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB02""(""ID"", ""NAME"") VALUES(2, '02') -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudb02 { id = 1, name = "01" }, new tbioudb02 { id = 2, name = "02" }, new tbioudb02 { id = 3, name = "03" }, new tbioudb02 { id = 4, name = "04" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB02""(""ID"", ""NAME"") VALUES(1, '01'), (2, '02'), (3, '03'), (4, '04') -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(2, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudb02 { id = 1, name = "001" }, new tbioudb02 { id = 2, name = "002" }, new tbioudb02 { id = 3, name = "003" }, new tbioudb02 { id = 4, name = "004" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB02""(""ID"", ""NAME"") VALUES(1, '001'), (2, '002'), (3, '003'), (4, '004') -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(0, iou.ExecuteAffrows()); - var lst = fsql.Select().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList(); - Assert.Equal(4, lst.Where(a => a.name == "0" + a.id).Count()); - } - class tbioudb02 - { - public int id { get; set; } - public string name { get; set; } - } - [Fact] - public void InsertOrUpdate_OnePrimaryAndIdentity() - { - fsql.Delete().Where("1=1").ExecuteAffrows(); - var iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudb022 { id = 1, name = "01" }); - var sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB022""(""ID"", ""NAME"") VALUES(1, '01') -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudb022 { id = 1, name = "011" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB022""(""ID"", ""NAME"") VALUES(1, '011') -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(0, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudb022 { id = 2, name = "02" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB022""(""ID"", ""NAME"") VALUES(2, '02') -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { id = 1, name = "01" }, new tbioudb022 { id = 2, name = "02" }, new tbioudb022 { id = 3, name = "03" }, new tbioudb022 { id = 4, name = "04" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB022""(""ID"", ""NAME"") VALUES(1, '01'), (2, '02'), (3, '03'), (4, '04') -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(2, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { id = 1, name = "001" }, new tbioudb022 { id = 2, name = "002" }, new tbioudb022 { id = 3, name = "003" }, new tbioudb022 { id = 4, name = "004" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB022""(""ID"", ""NAME"") VALUES(1, '001'), (2, '002'), (3, '003'), (4, '004') -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(0, iou.ExecuteAffrows()); - var lst = fsql.Select().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList(); - Assert.Equal(4, lst.Where(a => a.name == "0" + a.id).Count()); - - //--no primary - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudb022 { name = "01" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB022""(""NAME"") VALUES('01')", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudb022 { name = "011" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB022""(""NAME"") VALUES('011')", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudb022 { name = "02" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB022""(""NAME"") VALUES('02')", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { name = "01" }, new tbioudb022 { name = "02" }, new tbioudb022 { name = "03" }, new tbioudb022 { name = "04" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB022""(""NAME"") VALUES('01'), ('02'), ('03'), ('04')", sql); - Assert.Equal(4, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { name = "001" }, new tbioudb022 { name = "002" }, new tbioudb022 { name = "003" }, new tbioudb022 { name = "004" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB022""(""NAME"") VALUES('001'), ('002'), ('003'), ('004')", sql); - Assert.Equal(4, iou.ExecuteAffrows()); - - //--no primary and yes - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudb022 { id = 1, name = "100001" }, new tbioudb022 { name = "00001" }, new tbioudb022 { id = 2, name = "100002" }, new tbioudb022 { name = "00002" }, new tbioudb022 { id = 3, name = "100003" }, new tbioudb022 { name = "00003" }, new tbioudb022 { id = 4, name = "100004" }, new tbioudb022 { name = "00004" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB022""(""ID"", ""NAME"") VALUES(1, '100001'), (2, '100002'), (3, '100003'), (4, '100004') -ON CONFLICT(""ID"") DO NOTHING - -; - -INSERT INTO ""TBIOUDB022""(""NAME"") VALUES('00001'), ('00002'), ('00003'), ('00004')", sql); - Assert.Equal(4, iou.ExecuteAffrows()); - lst = fsql.Select().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList(); - Assert.Equal(4, lst.Where(a => a.name == "0" + a.id).Count()); - } - class tbioudb022 - { - [Column(IsIdentity = true)] - public int id { get; set; } - public string name { get; set; } - } - - [Fact] - public void InsertOrUpdate_TwoPrimary() - { - fsql.Delete().Where("1=1").ExecuteAffrows(); - var iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudb03 { id1 = 1, id2 = "01", name = "01" }); - var sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB03""(""ID1"", ""ID2"", ""NAME"") VALUES(1, '01', '01') -ON CONFLICT(""ID1"", ""ID2"") DO NOTHING", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudb03 { id1 = 1, id2 = "01", name = "011" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB03""(""ID1"", ""ID2"", ""NAME"") VALUES(1, '01', '011') -ON CONFLICT(""ID1"", ""ID2"") DO NOTHING", sql); - Assert.Equal(0, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudb03 { id1 = 2, id2 = "02", name = "02" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB03""(""ID1"", ""ID2"", ""NAME"") VALUES(2, '02', '02') -ON CONFLICT(""ID1"", ""ID2"") DO NOTHING", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudb03 { id1 = 1, id2 = "01", name = "01" }, new tbioudb03 { id1 = 2, id2 = "02", name = "02" }, new tbioudb03 { id1 = 3, id2 = "03", name = "03" }, new tbioudb03 { id1 = 4, id2 = "04", name = "04" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB03""(""ID1"", ""ID2"", ""NAME"") VALUES(1, '01', '01'), (2, '02', '02'), (3, '03', '03'), (4, '04', '04') -ON CONFLICT(""ID1"", ""ID2"") DO NOTHING", sql); - Assert.Equal(2, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudb03 { id1 = 1, id2 = "01", name = "001" }, new tbioudb03 { id1 = 2, id2 = "02", name = "002" }, new tbioudb03 { id1 = 3, id2 = "03", name = "003" }, new tbioudb03 { id1 = 4, id2 = "04", name = "004" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB03""(""ID1"", ""ID2"", ""NAME"") VALUES(1, '01', '001'), (2, '02', '002'), (3, '03', '003'), (4, '04', '004') -ON CONFLICT(""ID1"", ""ID2"") DO NOTHING", sql); - Assert.Equal(0, iou.ExecuteAffrows()); - var lst = fsql.Select().Where(a => a.id1 == 1 && a.id2 == "01" || a.id1 == 2 && a.id2 == "02" || a.id1 == 3 && a.id2 == "03" || a.id1 == 4 && a.id2 == "04").ToList(); - Assert.Equal(4, lst.Where(a => a.name == "0" + a.id1).Count()); - } - class tbioudb03 - { - [Column(IsPrimary = true)] - public int id1 { get; set; } - [Column(IsPrimary = true)] - public string id2 { get; set; } - public string name { get; set; } - } - - [Fact] - public void InsertOrUpdate_OnePrimaryAndVersionAndCanUpdate() - { - fsql.Delete().Where("1=1").ExecuteAffrows(); - var iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudb04 { id = 1, name = "01" }); - var sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB04""(""ID"", ""NAME"", ""VERSION"", ""CREATETIME"") VALUES(1, '01', 0, current_timestamp) -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudb04 { id = 1, name = "011" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB04""(""ID"", ""NAME"", ""VERSION"", ""CREATETIME"") VALUES(1, '011', 0, current_timestamp) -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(0, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new tbioudb04 { id = 2, name = "02" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB04""(""ID"", ""NAME"", ""VERSION"", ""CREATETIME"") VALUES(2, '02', 0, current_timestamp) -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudb04 { id = 1, name = "01" }, new tbioudb04 { id = 2, name = "02" }, new tbioudb04 { id = 3, name = "03" }, new tbioudb04 { id = 4, name = "04" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB04""(""ID"", ""NAME"", ""VERSION"", ""CREATETIME"") VALUES(1, '01', 0, current_timestamp), (2, '02', 0, current_timestamp), (3, '03', 0, current_timestamp), (4, '04', 0, current_timestamp) -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(2, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().IfExistsDoNothing().SetSource(new[] { new tbioudb04 { id = 1, name = "001" }, new tbioudb04 { id = 2, name = "002" }, new tbioudb04 { id = 3, name = "003" }, new tbioudb04 { id = 4, name = "004" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOUDB04""(""ID"", ""NAME"", ""VERSION"", ""CREATETIME"") VALUES(1, '001', 0, current_timestamp), (2, '002', 0, current_timestamp), (3, '003', 0, current_timestamp), (4, '004', 0, current_timestamp) -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(0, iou.ExecuteAffrows()); - var lst = fsql.Select().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList(); - Assert.Equal(4, lst.Where(a => a.name == "0" + a.id).Count()); - } - class tbioudb04 - { - public int id { get; set; } - public string name { get; set; } - [Column(IsVersion = true)] - public int version { get; set; } - [Column(CanUpdate = false, ServerTime = DateTimeKind.Local)] - public DateTime CreateTime { get; set; } - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESInsertOrUpdateTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESInsertOrUpdateTest.cs deleted file mode 100644 index 971cfe256..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESInsertOrUpdateTest.cs +++ /dev/null @@ -1,205 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseES -{ - public class KingbaseESInsertOrUpdateTest - { - IFreeSql fsql => g.kingbaseES; - - [Fact] - public void InsertOrUpdate_OnlyPrimary() - { - fsql.Delete().Where("1=1").ExecuteAffrows(); - var iou = fsql.InsertOrUpdate().SetSource(new tbiou01 { id = 1 }); - var sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU01""(""ID"") VALUES(1) -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().SetSource(new tbiou01 { id = 1 }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU01""(""ID"") VALUES(1) -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(0, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().SetSource(new tbiou01 { id = 2 }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU01""(""ID"") VALUES(2) -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou01 { id = 1 }, new tbiou01 { id = 2 }, new tbiou01 { id = 3 }, new tbiou01 { id = 4 } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU01""(""ID"") VALUES(1), (2), (3), (4) -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(2, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou01 { id = 1 }, new tbiou01 { id = 2 }, new tbiou01 { id = 3 }, new tbiou01 { id = 4 } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU01""(""ID"") VALUES(1), (2), (3), (4) -ON CONFLICT(""ID"") DO NOTHING", sql); - Assert.Equal(0, iou.ExecuteAffrows()); - } - class tbiou01 - { - public int id { get; set; } - } - - [Fact] - public void InsertOrUpdate_OnePrimary() - { - fsql.Delete().Where("1=1").ExecuteAffrows(); - var iou = fsql.InsertOrUpdate().SetSource(new tbiou02 { id = 1, name = "01" }); - var sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU02""(""ID"", ""NAME"") VALUES(1, '01') -ON CONFLICT(""ID"") DO UPDATE SET -""NAME"" = EXCLUDED.""NAME""", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().SetSource(new tbiou02 { id = 1, name = "011" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU02""(""ID"", ""NAME"") VALUES(1, '011') -ON CONFLICT(""ID"") DO UPDATE SET -""NAME"" = EXCLUDED.""NAME""", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().SetSource(new tbiou02 { id = 2, name = "02" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU02""(""ID"", ""NAME"") VALUES(2, '02') -ON CONFLICT(""ID"") DO UPDATE SET -""NAME"" = EXCLUDED.""NAME""", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou02 { id = 1, name = "01" }, new tbiou02 { id = 2, name = "02" }, new tbiou02 { id = 3, name = "03" }, new tbiou02 { id = 4, name = "04" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU02""(""ID"", ""NAME"") VALUES(1, '01'), (2, '02'), (3, '03'), (4, '04') -ON CONFLICT(""ID"") DO UPDATE SET -""NAME"" = EXCLUDED.""NAME""", sql); - Assert.Equal(4, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou02 { id = 1, name = "001" }, new tbiou02 { id = 2, name = "002" }, new tbiou02 { id = 3, name = "003" }, new tbiou02 { id = 4, name = "004" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU02""(""ID"", ""NAME"") VALUES(1, '001'), (2, '002'), (3, '003'), (4, '004') -ON CONFLICT(""ID"") DO UPDATE SET -""NAME"" = EXCLUDED.""NAME""", sql); - Assert.Equal(4, iou.ExecuteAffrows()); - var lst = fsql.Select().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList(); - Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count()); - } - class tbiou02 - { - public int id { get; set; } - public string name { get; set; } - } - - [Fact] - public void InsertOrUpdate_TwoPrimary() - { - fsql.Delete().Where("1=1").ExecuteAffrows(); - var iou = fsql.InsertOrUpdate().SetSource(new tbiou03 { id1 = 1, id2 = "01", name = "01" }); - var sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU03""(""ID1"", ""ID2"", ""NAME"") VALUES(1, '01', '01') -ON CONFLICT(""ID1"", ""ID2"") DO UPDATE SET -""NAME"" = EXCLUDED.""NAME""", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().SetSource(new tbiou03 { id1 = 1, id2 = "01", name = "011" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU03""(""ID1"", ""ID2"", ""NAME"") VALUES(1, '01', '011') -ON CONFLICT(""ID1"", ""ID2"") DO UPDATE SET -""NAME"" = EXCLUDED.""NAME""", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().SetSource(new tbiou03 { id1 = 2, id2 = "02", name = "02" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU03""(""ID1"", ""ID2"", ""NAME"") VALUES(2, '02', '02') -ON CONFLICT(""ID1"", ""ID2"") DO UPDATE SET -""NAME"" = EXCLUDED.""NAME""", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou03 { id1 = 1, id2 = "01", name = "01" }, new tbiou03 { id1 = 2, id2 = "02", name = "02" }, new tbiou03 { id1 = 3, id2 = "03", name = "03" }, new tbiou03 { id1 = 4, id2 = "04", name = "04" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU03""(""ID1"", ""ID2"", ""NAME"") VALUES(1, '01', '01'), (2, '02', '02'), (3, '03', '03'), (4, '04', '04') -ON CONFLICT(""ID1"", ""ID2"") DO UPDATE SET -""NAME"" = EXCLUDED.""NAME""", sql); - Assert.Equal(4, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou03 { id1 = 1, id2 = "01", name = "001" }, new tbiou03 { id1 = 2, id2 = "02", name = "002" }, new tbiou03 { id1 = 3, id2 = "03", name = "003" }, new tbiou03 { id1 = 4, id2 = "04", name = "004" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU03""(""ID1"", ""ID2"", ""NAME"") VALUES(1, '01', '001'), (2, '02', '002'), (3, '03', '003'), (4, '04', '004') -ON CONFLICT(""ID1"", ""ID2"") DO UPDATE SET -""NAME"" = EXCLUDED.""NAME""", sql); - Assert.Equal(4, iou.ExecuteAffrows()); - var lst = fsql.Select().Where(a => a.id1 == 1 && a.id2 == "01" || a.id1 == 2 && a.id2 == "02" || a.id1 == 3 && a.id2 == "03" || a.id1 == 4 && a.id2 == "04").ToList(); - Assert.Equal(4, lst.Where(a => a.name == "00" + a.id1).Count()); - } - class tbiou03 - { - [Column(IsPrimary = true)] - public int id1 { get; set; } - [Column(IsPrimary = true)] - public string id2 { get; set; } - public string name { get; set; } - } - - [Fact] - public void InsertOrUpdate_OnePrimaryAndVersionAndCanUpdate() - { - fsql.Delete().Where("1=1").ExecuteAffrows(); - var iou = fsql.InsertOrUpdate().SetSource(new tbiou04 { id = 1, name = "01" }); - var sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU04""(""ID"", ""NAME"", ""VERSION"", ""CREATETIME"") VALUES(1, '01', 0, current_timestamp) -ON CONFLICT(""ID"") DO UPDATE SET -""NAME"" = EXCLUDED.""NAME"", -""VERSION"" = ""TBIOU04"".""VERSION"" + 1", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().SetSource(new tbiou04 { id = 1, name = "011" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU04""(""ID"", ""NAME"", ""VERSION"", ""CREATETIME"") VALUES(1, '011', 0, current_timestamp) -ON CONFLICT(""ID"") DO UPDATE SET -""NAME"" = EXCLUDED.""NAME"", -""VERSION"" = ""TBIOU04"".""VERSION"" + 1", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().SetSource(new tbiou04 { id = 2, name = "02" }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU04""(""ID"", ""NAME"", ""VERSION"", ""CREATETIME"") VALUES(2, '02', 0, current_timestamp) -ON CONFLICT(""ID"") DO UPDATE SET -""NAME"" = EXCLUDED.""NAME"", -""VERSION"" = ""TBIOU04"".""VERSION"" + 1", sql); - Assert.Equal(1, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou04 { id = 1, name = "01" }, new tbiou04 { id = 2, name = "02" }, new tbiou04 { id = 3, name = "03" }, new tbiou04 { id = 4, name = "04" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU04""(""ID"", ""NAME"", ""VERSION"", ""CREATETIME"") VALUES(1, '01', 0, current_timestamp), (2, '02', 0, current_timestamp), (3, '03', 0, current_timestamp), (4, '04', 0, current_timestamp) -ON CONFLICT(""ID"") DO UPDATE SET -""NAME"" = EXCLUDED.""NAME"", -""VERSION"" = ""TBIOU04"".""VERSION"" + 1", sql); - Assert.Equal(4, iou.ExecuteAffrows()); - - iou = fsql.InsertOrUpdate().SetSource(new[] { new tbiou04 { id = 1, name = "001" }, new tbiou04 { id = 2, name = "002" }, new tbiou04 { id = 3, name = "003" }, new tbiou04 { id = 4, name = "004" } }); - sql = iou.ToSql(); - Assert.Equal(@"INSERT INTO ""TBIOU04""(""ID"", ""NAME"", ""VERSION"", ""CREATETIME"") VALUES(1, '001', 0, current_timestamp), (2, '002', 0, current_timestamp), (3, '003', 0, current_timestamp), (4, '004', 0, current_timestamp) -ON CONFLICT(""ID"") DO UPDATE SET -""NAME"" = EXCLUDED.""NAME"", -""VERSION"" = ""TBIOU04"".""VERSION"" + 1", sql); - Assert.Equal(4, iou.ExecuteAffrows()); - var lst = fsql.Select().Where(a => new[] { 1, 2, 3, 4 }.Contains(a.id)).ToList(); - Assert.Equal(4, lst.Where(a => a.name == "00" + a.id).Count()); - } - class tbiou04 - { - public int id { get; set; } - public string name { get; set; } - [Column(IsVersion = true)] - public int version { get; set; } - [Column(CanUpdate = false, ServerTime = DateTimeKind.Local)] - public DateTime CreateTime { get; set; } - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESInsertTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESInsertTest.cs deleted file mode 100644 index d6ace67cb..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESInsertTest.cs +++ /dev/null @@ -1,141 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseES -{ - public class KingbaseESInsertTest - { - - IInsert insert => g.kingbaseES.Insert(); - - [Table(Name = "tb_topic_insert")] - class Topic - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int Clicks { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - - [Fact] - public void AppendData() - { - var items = new List(); - for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 }); - - var sql = insert.AppendData(items.First()).ToSql(); - Assert.Equal("INSERT INTO \"TB_TOPIC_INSERT\"(\"CLICKS\", \"TITLE\", \"CREATETIME\") VALUES(0, 'newtitle0', '0001-01-01 00:00:00.000000')", sql); - - sql = insert.AppendData(items).ToSql(); - Assert.Equal("INSERT INTO \"TB_TOPIC_INSERT\"(\"CLICKS\", \"TITLE\", \"CREATETIME\") VALUES(0, 'newtitle0', '0001-01-01 00:00:00.000000'), (100, 'newtitle1', '0001-01-01 00:00:00.000000'), (200, 'newtitle2', '0001-01-01 00:00:00.000000'), (300, 'newtitle3', '0001-01-01 00:00:00.000000'), (400, 'newtitle4', '0001-01-01 00:00:00.000000'), (500, 'newtitle5', '0001-01-01 00:00:00.000000'), (600, 'newtitle6', '0001-01-01 00:00:00.000000'), (700, 'newtitle7', '0001-01-01 00:00:00.000000'), (800, 'newtitle8', '0001-01-01 00:00:00.000000'), (900, 'newtitle9', '0001-01-01 00:00:00.000000')", sql); - - sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql(); - Assert.Equal("INSERT INTO \"TB_TOPIC_INSERT\"(\"TITLE\") VALUES('newtitle0'), ('newtitle1'), ('newtitle2'), ('newtitle3'), ('newtitle4'), ('newtitle5'), ('newtitle6'), ('newtitle7'), ('newtitle8'), ('newtitle9')", sql); - - sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql(); - Assert.Equal("INSERT INTO \"TB_TOPIC_INSERT\"(\"CLICKS\", \"TITLE\") VALUES(0, 'newtitle0'), (100, 'newtitle1'), (200, 'newtitle2'), (300, 'newtitle3'), (400, 'newtitle4'), (500, 'newtitle5'), (600, 'newtitle6'), (700, 'newtitle7'), (800, 'newtitle8'), (900, 'newtitle9')", sql); - } - - [Fact] - public void InsertColumns() - { - var items = new List(); - for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 }); - - var sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql(); - Assert.Equal("INSERT INTO \"TB_TOPIC_INSERT\"(\"TITLE\") VALUES('newtitle0'), ('newtitle1'), ('newtitle2'), ('newtitle3'), ('newtitle4'), ('newtitle5'), ('newtitle6'), ('newtitle7'), ('newtitle8'), ('newtitle9')", sql); - - sql = insert.AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).ToSql(); - Assert.Equal("INSERT INTO \"TB_TOPIC_INSERT\"(\"CLICKS\", \"TITLE\") VALUES(0, 'newtitle0'), (100, 'newtitle1'), (200, 'newtitle2'), (300, 'newtitle3'), (400, 'newtitle4'), (500, 'newtitle5'), (600, 'newtitle6'), (700, 'newtitle7'), (800, 'newtitle8'), (900, 'newtitle9')", sql); - } - [Fact] - public void IgnoreColumns() - { - var items = new List(); - for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 }); - - var sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql(); - Assert.Equal("INSERT INTO \"TB_TOPIC_INSERT\"(\"CLICKS\", \"TITLE\") VALUES(0, 'newtitle0'), (100, 'newtitle1'), (200, 'newtitle2'), (300, 'newtitle3'), (400, 'newtitle4'), (500, 'newtitle5'), (600, 'newtitle6'), (700, 'newtitle7'), (800, 'newtitle8'), (900, 'newtitle9')", sql); - - sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).ToSql(); - Assert.Equal("INSERT INTO \"TB_TOPIC_INSERT\"(\"CLICKS\") VALUES(0), (100), (200), (300), (400), (500), (600), (700), (800), (900)", sql); - - g.kingbaseES.Delete().Where("1=1").ExecuteAffrows(); - var itemsIgnore = new List(); - for (var a = 0; a < 2072; a++) itemsIgnore.Add(new TopicIgnore { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now }); - g.kingbaseES.Insert().AppendData(itemsIgnore).IgnoreColumns(a => new { a.Title }).ExecuteAffrows(); - Assert.Equal(2072, itemsIgnore.Count); - Assert.Equal(2072, g.kingbaseES.Select().Where(a => a.Title == null).Count()); - } - [Table(Name = "tb_topicIgnoreColumns")] - class TopicIgnore - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int Clicks { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - [Fact] - public void ExecuteAffrows() - { - var items = new List(); - for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 }); - - Assert.Equal(1, insert.AppendData(items.First()).ExecuteAffrows()); - Assert.Equal(10, insert.AppendData(items).ExecuteAffrows()); - } - [Fact] - public void ExecuteIdentity() - { - var items = new List(); - for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 }); - - Assert.NotEqual(0, insert.AppendData(items.First()).ExecuteIdentity()); - } - [Fact] - public void ExecuteInserted() - { - var items = new List(); - for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 }); - - insert.AppendData(items.First()).ExecuteInserted(); - } - - [Fact] - public void AsTable() - { - var items = new List(); - for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newTitle{a}", Clicks = a * 100 }); - - var sql = insert.AppendData(items.First()).AsTable(a => "Topic_InsertAsTable").ToSql(); - Assert.Equal("INSERT INTO \"TOPIC_INSERTASTABLE\"(\"CLICKS\", \"TITLE\", \"CREATETIME\") VALUES(0, 'newTitle0', '0001-01-01 00:00:00.000000')", sql); - - sql = insert.AppendData(items).AsTable(a => "Topic_InsertAsTable").ToSql(); - Assert.Equal("INSERT INTO \"TOPIC_INSERTASTABLE\"(\"CLICKS\", \"TITLE\", \"CREATETIME\") VALUES(0, 'newTitle0', '0001-01-01 00:00:00.000000'), (100, 'newTitle1', '0001-01-01 00:00:00.000000'), (200, 'newTitle2', '0001-01-01 00:00:00.000000'), (300, 'newTitle3', '0001-01-01 00:00:00.000000'), (400, 'newTitle4', '0001-01-01 00:00:00.000000'), (500, 'newTitle5', '0001-01-01 00:00:00.000000'), (600, 'newTitle6', '0001-01-01 00:00:00.000000'), (700, 'newTitle7', '0001-01-01 00:00:00.000000'), (800, 'newTitle8', '0001-01-01 00:00:00.000000'), (900, 'newTitle9', '0001-01-01 00:00:00.000000')", sql); - - sql = insert.AppendData(items).InsertColumns(a => a.Title).AsTable(a => "Topic_InsertAsTable").ToSql(); - Assert.Equal("INSERT INTO \"TOPIC_INSERTASTABLE\"(\"TITLE\") VALUES('newTitle0'), ('newTitle1'), ('newTitle2'), ('newTitle3'), ('newTitle4'), ('newTitle5'), ('newTitle6'), ('newTitle7'), ('newTitle8'), ('newTitle9')", sql); - - sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).AsTable(a => "Topic_InsertAsTable").ToSql(); - Assert.Equal("INSERT INTO \"TOPIC_INSERTASTABLE\"(\"CLICKS\", \"TITLE\") VALUES(0, 'newTitle0'), (100, 'newTitle1'), (200, 'newTitle2'), (300, 'newTitle3'), (400, 'newTitle4'), (500, 'newTitle5'), (600, 'newTitle6'), (700, 'newTitle7'), (800, 'newTitle8'), (900, 'newTitle9')", sql); - - sql = insert.AppendData(items).InsertColumns(a => a.Title).AsTable(a => "Topic_InsertAsTable").ToSql(); - Assert.Equal("INSERT INTO \"TOPIC_INSERTASTABLE\"(\"TITLE\") VALUES('newTitle0'), ('newTitle1'), ('newTitle2'), ('newTitle3'), ('newTitle4'), ('newTitle5'), ('newTitle6'), ('newTitle7'), ('newTitle8'), ('newTitle9')", sql); - - sql = insert.AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).AsTable(a => "Topic_InsertAsTable").ToSql(); - Assert.Equal("INSERT INTO \"TOPIC_INSERTASTABLE\"(\"CLICKS\", \"TITLE\") VALUES(0, 'newTitle0'), (100, 'newTitle1'), (200, 'newTitle2'), (300, 'newTitle3'), (400, 'newTitle4'), (500, 'newTitle5'), (600, 'newTitle6'), (700, 'newTitle7'), (800, 'newTitle8'), (900, 'newTitle9')", sql); - - sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).AsTable(a => "Topic_InsertAsTable").ToSql(); - Assert.Equal("INSERT INTO \"TOPIC_INSERTASTABLE\"(\"CLICKS\", \"TITLE\") VALUES(0, 'newTitle0'), (100, 'newTitle1'), (200, 'newTitle2'), (300, 'newTitle3'), (400, 'newTitle4'), (500, 'newTitle5'), (600, 'newTitle6'), (700, 'newTitle7'), (800, 'newTitle8'), (900, 'newTitle9')", sql); - - sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).AsTable(a => "Topic_InsertAsTable").ToSql(); - Assert.Equal("INSERT INTO \"TOPIC_INSERTASTABLE\"(\"CLICKS\") VALUES(0), (100), (200), (300), (400), (500), (600), (700), (800), (900)", sql); - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESSelectTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESSelectTest.cs deleted file mode 100644 index 7a90cbf0c..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESSelectTest.cs +++ /dev/null @@ -1,1829 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseES -{ - public class KingbaseESSelectTest - { - - ISelect select => g.kingbaseES.Select(); - - [Table(Name = "tb_topic22")] - class Topic - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int Clicks { get; set; } - public int TypeGuid { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - class TestTypeInfo - { - [Column(IsIdentity = true)] - public int Guid { get; set; } - public int ParentId { get; set; } - public TestTypeParentInfo Parent { get; set; } - public string Name { get; set; } - } - class TestTypeParentInfo - { - public int Id { get; set; } - public string Name { get; set; } - - public List Types { get; set; } - } - - class TopicInserts - { - public Guid Id { get; set; } - public int Clicks { get; set; } - public int TypeGuid { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - public partial class Song - { - [Column(IsIdentity = true)] - public int Id { get; set; } - public DateTime? Create_time { get; set; } - public bool? Is_deleted { get; set; } - public string Title { get; set; } - public string Url { get; set; } - - public virtual ICollection Tags { get; set; } - } - public partial class Song_tag - { - public int Song_id { get; set; } - public virtual Song Song { get; set; } - - public int Tag_id { get; set; } - public virtual Tag Tag { get; set; } - } - public partial class Tag - { - [Column(IsIdentity = true)] - public int Id { get; set; } - public int? Parent_id { get; set; } - public virtual Tag Parent { get; set; } - - public decimal? Ddd { get; set; } - public string Name { get; set; } - - public virtual ICollection Songs { get; set; } - public virtual ICollection Tags { get; set; } - } - - [Fact] - public void AsSelect() - { - //OneToOne、ManyToOne - var t0 = g.kingbaseES.Select().Where(a => a.Parent.Parent.Name == "粤语").ToSql(); - //SELECT a.`Id`, a.`Parent_id`, a__Parent.`Id` as3, a__Parent.`Parent_id` as4, a__Parent.`Ddd`, a__Parent.`Name`, a.`Ddd` as7, a.`Name` as8 - //FROM `Tag` a - //LEFT JOIN `Tag` a__Parent ON a__Parent.`Id` = a.`Parent_id` - //LEFT JOIN `Tag` a__Parent__Parent ON a__Parent__Parent.`Id` = a__Parent.`Parent_id` - //WHERE (a__Parent__Parent.`Name` = '粤语') - - //OneToMany - var t1 = g.kingbaseES.Select().Where(a => a.Tags.AsSelect().Any(t => t.Parent.Id == 10)).ToSql(); - //SELECT a.`Id`, a.`Parent_id`, a.`Ddd`, a.`Name` - //FROM `Tag` a - //WHERE (exists(SELECT 1 - // FROM `Tag` t - // LEFT JOIN `Tag` t__Parent ON t__Parent.`Id` = t.`Parent_id` - // WHERE (t__Parent.`Id` = 10) AND (t.`Parent_id` = a.`Id`) - // limit 0,1)) - - //ManyToMany - var t2 = g.kingbaseES.Select().Where(s => s.Tags.AsSelect().Any(t => t.Name == "国语")).ToSql(); - //SELECT a.`Id`, a.`Create_time`, a.`Is_deleted`, a.`Title`, a.`Url` - //FROM `Song` a - //WHERE(exists(SELECT 1 - // FROM `Song_tag` Mt_Ms - // WHERE(Mt_Ms.`Song_id` = a.`Id`) AND(exists(SELECT 1 - // FROM `Tag` t - // WHERE(t.`Name` = '国语') AND(t.`Id` = Mt_Ms.`Tag_id`) - // limit 0, 1)) - // limit 0, 1)) - } - - [Fact] - public void Lazy() - { - var tags = g.kingbaseES.Select().Where(a => a.Parent.Name == "xxx") - .LeftJoin(a => a.Parent_id == a.Parent.Id) - .ToSql(); - - var songs = g.kingbaseES.Select().Limit(10).ToList(); - } - - [Fact] - public void ToDataTable() - { - var items = new List(); - for (var a = 0; a < 11; a++) items.Add(new TopicInserts { Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now }); - - //Assert.Equal(1, g.kingbaseES.Insert().AppendData(items.First()).ExecuteAffrows()); - Assert.Equal(11, g.kingbaseES.Insert().AppendData(items).ExecuteAffrows()); - - //items = Enumerable.Range(0, 9989).Select(a => new TopicInserts { Title = "newtitle" + a, CreateTime = DateTime.Now }).ToList(); - //Assert.Equal(9989, g.kingbaseES.Insert(items).ExecuteAffrows()); - - //var dt1 = select.ToDataTable(); - //var dt2 = select.ToDataTable("id, 111222"); - //var dt3 = select.ToDataTable(a => new { a.Id, a.Type.Name, now = DateTime.Now }); - } - class TestDto - { - public int id { get; set; } - public string name { get; set; } //这是join表的属性 - public int ParentId { get; set; } //这是join表的属性 - } - class TestDto2 - { - public int id { get; set; } - public string name { get; set; } //这是join表的属性 - public int ParentId { get; set; } //这是join表的属性 - - public TestDto2() { } - public TestDto2(int id, string name) - { - this.id = id; - this.name = name; - } - } - [Fact] - public void ToList() - { - - var testDto1 = select.Limit(10).ToList(a => new TestDto { id = a.Id, name = a.Title }); - var testDto2 = select.Limit(10).ToList(a => new TestDto()); - var testDto3 = select.Limit(10).ToList(a => new TestDto { }); - var testDto4 = select.Limit(10).ToList(a => new TestDto() { }); - - var testDto11 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { id = a.Id, name = a.Title }); - var testDto22 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto()); - var testDto33 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto { }); - var testDto44 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto() { }); - - var testDto211 = select.Limit(10).ToList(a => new TestDto2(a.Id, a.Title)); - var testDto212 = select.Limit(10).ToList(a => new TestDto2()); - var testDto213 = select.Limit(10).ToList(a => new TestDto2 { }); - var testDto214 = select.Limit(10).ToList(a => new TestDto2() { }); - var testDto215 = select.Limit(10).ToList(); - - var testDto2211 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2(a.Id, a.Title)); - var testDto2222 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2()); - var testDto2233 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2 { }); - var testDto2244 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(a => new TestDto2() { }); - var testDto2255 = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).Limit(10).ToList(); - - g.kingbaseES.Insert().AppendData(new TestGuidIdToList()).ExecuteAffrows(); - var testGuidId5 = g.kingbaseES.Select().ToList(); - var testGuidId6 = g.kingbaseES.Select().ToList(a => a.id); - - var t11 = select.Where(a => a.Type.Name.Length > 0).ToList(true); - var t21 = select.Where(a => a.Type.Parent.Name.Length > 0).ToList(true); - - g.kingbaseES.Delete().Where("1=1").ExecuteAffrows(); - var repo = g.kingbaseES.GetRepository(); - repo.DbContextOptions.EnableCascadeSave = true; - repo.Insert(new District - { - Code = "001", - Name = "001_name", - Childs = new List(new[] { - new District{ - Code = "001_01", - Name = "001_01_name" - }, - new District{ - Code = "001_02", - Name = "001_02_name" - } - }) - }); - var ddd = g.kingbaseES.Select().LeftJoin(d => d.ParentCode == d.Parent.Code).ToTreeList(); - Assert.Single(ddd); - Assert.Equal(2, ddd[0].Childs.Count); - } - public class District - { - [Column(IsPrimary = true, StringLength = 6)] - public string Code { get; set; } - - [Column(StringLength = 20, IsNullable = false)] - public string Name { get; set; } - - [Column(StringLength = 6)] - public string ParentCode { get; set; } - - [Navigate(nameof(ParentCode))] - public District Parent { get; set; } - - [Navigate(nameof(ParentCode))] - public List Childs { get; set; } - } - [Fact] - public void ToDictionary() - { - g.kingbaseES.Insert(new Topic { Title = "xxx" }).ExecuteAffrows(); - var testDto1 = select.Limit(10).ToDictionary(a => a.Id); - var testDto2 = select.Limit(10).ToDictionary(a => a.Id, a => new { a.Id, a.Title }); - - var repo = g.kingbaseES.GetRepository(); - var dic = repo.Select.Limit(10).ToDictionary(a => a.Id); - var first = dic.First().Value; - first.Clicks++; - repo.Update(first); - } - class TestGuidIdToList - { - public Guid id { get; set; } - public string title { get; set; } = Guid.NewGuid().ToString(); - } - [Fact] - public void ToOne() - { - var testnotfind = select.Where("1=2").First(a => a.CreateTime); - Assert.Equal(default(DateTime), testnotfind); - } - [Fact] - public void ToSql() - { - } - [Fact] - public void Any() - { - var count = select.Where(a => 1 == 1).Count(); - Assert.False(select.Where(a => 1 == 2).Any()); - Assert.Equal(count > 0, select.Where(a => 1 == 1).Any()); - - var sql2222 = select.Where(a => - select.Where(b => b.Id == a.Id && - select.Where(c => c.Id == b.Id).Where(d => d.Id == a.Id).Where(e => e.Id == b.Id) - //.Offset(a.Id) - .Any() - ).Any(c => c.Id == a.Id + 10) - ); - var sql2222Tolist = sql2222.ToList(); - - var collectionSelect = select.Where(a => - a.Type.Guid == a.TypeGuid && - a.Type.Parent.Id == a.Type.ParentId && - a.Type.Parent.Types.AsSelect().Where(b => b.Name == a.Title).Any(b => b.ParentId == a.Type.Parent.Id) - ); - collectionSelect.ToList(); - } - [Fact] - public void Count() - { - var count = select.Where(a => 1 == 1).Count(); - select.Where(a => 1 == 1).Count(out var count2); - Assert.Equal(count, count2); - Assert.Equal(0, select.Where(a => 1 == 2).Count()); - - var subquery = select.ToSql(a => new - { - all = a, - count = select.Where(b => b.Id > 0 && b.Id == a.Id).Count() - }); - var subqueryList = select.ToList(a => new - { - all = a, - count = select.Where(b => b.Id > 0 && b.Id == a.Id).Count() - }); - } - [Fact] - public void Master() - { - Assert.StartsWith(" SELECT", select.Master().Where(a => 1 == 1).ToSql()); - } - [Fact] - public void From() - { - var query2 = select.From((s, b) => s - .LeftJoin(a => a.TypeGuid == b.Guid) - ); - var sql2 = query2.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON a.\"TYPEGUID\" = b.\"GUID\"", sql2); - query2.ToList(); - - var query3 = select.From((s, b, c) => s - .LeftJoin(a => a.TypeGuid == b.Guid) - .LeftJoin(a => b.ParentId == c.Id) - ); - var sql3 = query3.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON a.\"TYPEGUID\" = b.\"GUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" c ON b.\"PARENTID\" = c.\"ID\"", sql3); - query3.ToList(); - } - [Fact] - public void LeftJoin() - { - //����е�������a.Type��a.Type.Parent ���ǵ������� - var query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid); - var sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\"", sql); - query.ToList(); - - query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx'", sql); - query.ToList(); - - query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql); - query.ToList(); - - //���û�е������� - query = select.LeftJoin((a, b) => b.Guid == a.TypeGuid); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TYPEGUID\"", sql); - query.ToList(); - - query = select.LeftJoin((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TYPEGUID\" AND b.\"NAME\" = 'xxx'", sql); - query.ToList(); - - query = select.LeftJoin((a, a__Type) => a__Type.Guid == a.TypeGuid && a__Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql); - query.ToList(); - - //������� - query = select - .LeftJoin(a => a.Type.Guid == a.TypeGuid) - .LeftJoin(a => a.Type.Parent.Id == a.Type.ParentId); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\"", sql); - query.ToList(); - - query = select - .LeftJoin((a, a__Type) => a__Type.Guid == a.TypeGuid) - .LeftJoin((a, c) => c.Id == a.Type.ParentId); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" c ON c.\"ID\" = a__Type.\"PARENTID\"", sql); - query.ToList(); - - //���û�е�������b��c������ϵ - var query2 = select.From((s, b, c) => s - .LeftJoin(a => a.TypeGuid == b.Guid) - .LeftJoin(a => b.ParentId == c.Id)); - sql = query2.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b ON a.\"TYPEGUID\" = b.\"GUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" c ON b.\"PARENTID\" = c.\"ID\"", sql); - query2.ToList(); - - //������϶����㲻�� - query = select.LeftJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\""); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\"", sql); - query.ToList(); - } - [Fact] - public void InnerJoin() - { - //����е�������a.Type��a.Type.Parent ���ǵ������� - var query = select.InnerJoin(a => a.Type.Guid == a.TypeGuid); - var sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\"", sql); - query.ToList(); - - query = select.InnerJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx'", sql); - query.ToList(); - - query = select.InnerJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql); - query.ToList(); - - //���û�е������� - query = select.InnerJoin((a, b) => b.Guid == a.TypeGuid); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TYPEGUID\"", sql); - query.ToList(); - - query = select.InnerJoin((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TYPEGUID\" AND b.\"NAME\" = 'xxx'", sql); - query.ToList(); - - query = select.InnerJoin((a, a__Type) => a__Type.Guid == a.TypeGuid && a__Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql); - query.ToList(); - - //������� - query = select - .InnerJoin(a => a.Type.Guid == a.TypeGuid) - .InnerJoin(a => a.Type.Parent.Id == a.Type.ParentId); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" INNER JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\"", sql); - query.ToList(); - - query = select - .InnerJoin((a, a__Type) => a__Type.Guid == a.TypeGuid) - .InnerJoin((a, c) => c.Id == a.Type.ParentId); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" INNER JOIN \"TESTTYPEPARENTINFO\" c ON c.\"ID\" = a__Type.\"PARENTID\"", sql); - query.ToList(); - - //���û�е�������b��c������ϵ - var query2 = select.From((s, b, c) => s - .InnerJoin(a => a.TypeGuid == b.Guid) - .InnerJoin(a => b.ParentId == c.Id)); - sql = query2.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b ON a.\"TYPEGUID\" = b.\"GUID\" INNER JOIN \"TESTTYPEPARENTINFO\" c ON b.\"PARENTID\" = c.\"ID\"", sql); - query2.ToList(); - - //������϶����㲻�� - query = select.InnerJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\""); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a INNER JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\"", sql); - query.ToList(); - } - [Fact] - public void RightJoin() - { - //����е�������a.Type��a.Type.Parent ���ǵ������� - var query = select.RightJoin(a => a.Type.Guid == a.TypeGuid); - var sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\"", sql); - query.ToList(); - - query = select.RightJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx'", sql); - query.ToList(); - - query = select.RightJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql); - query.ToList(); - - //���û�е������� - query = select.RightJoin((a, b) => b.Guid == a.TypeGuid); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TYPEGUID\"", sql); - query.ToList(); - - query = select.RightJoin((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b ON b.\"GUID\" = a.\"TYPEGUID\" AND b.\"NAME\" = 'xxx'", sql); - query.ToList(); - - query = select.RightJoin((a, a__Type) => a__Type.Guid == a.TypeGuid && a__Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql); - query.ToList(); - - //������� - query = select - .RightJoin(a => a.Type.Guid == a.TypeGuid) - .RightJoin(a => a.Type.Parent.Id == a.Type.ParentId); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" RIGHT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\"", sql); - query.ToList(); - - query = select - .RightJoin((a, a__Type) => a__Type.Guid == a.TypeGuid) - .RightJoin((a, c) => c.Id == a.Type.ParentId); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" RIGHT JOIN \"TESTTYPEPARENTINFO\" c ON c.\"ID\" = a__Type.\"PARENTID\"", sql); - query.ToList(); - - //���û�е�������b��c������ϵ - var query2 = select.From((s, b, c) => s - .RightJoin(a => a.TypeGuid == b.Guid) - .RightJoin(a => b.ParentId == c.Id)); - sql = query2.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b ON a.\"TYPEGUID\" = b.\"GUID\" RIGHT JOIN \"TESTTYPEPARENTINFO\" c ON b.\"PARENTID\" = c.\"ID\"", sql); - query2.ToList(); - - //������϶����㲻�� - query = select.RightJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\""); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a RIGHT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\"", sql); - query.ToList(); - } - [Fact] - public void Where() - { - var sqltmp1 = select.Where(a => a.Id == 0 && (a.Title == "x" || a.Title == "y") && a.Clicks == 1).ToSql(); - var sqltmp2 = select.Where(a => a.Id.Equals(true) && (a.Title.Equals("x") || a.Title.Equals("y")) && a.Clicks.Equals(1)).ToSql(); - var sqltmp3 = select.Where(a => a.Id == 0).Where(a => ((a.Title == "x" && a.Title == "z") || a.Title == "y")).ToSql(); - - var sqltmp4 = select.Where(a => (a.Id - 10) / 2 > 0).ToSql(); - - //����е�������a.Type��a.Type.Parent ���ǵ������� - var query = select.Where(a => a.Id == 10); - var sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10)", sql); - query.ToList(); - - query = select.Where(a => a.Id == 10 && a.Id > 10 || a.Clicks > 100); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE ((a.\"ID\" = 10 AND a.\"ID\" > 10 OR a.\"CLICKS\" > 100))", sql); - query.ToList(); - - query = select.Where(a => a.Id == 10).Where(a => a.Clicks > 100); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10) AND (a.\"CLICKS\" > 100)", sql); - query.ToList(); - - query = select.Where(a => a.Type.Name == "typeTitle"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" WHERE (a__Type.\"NAME\" = 'typeTitle')", sql); - query.ToList(); - - query = select.Where(a => a.Type.Name == "typeTitle" && a.Type.Guid == a.TypeGuid); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" WHERE (a__Type.\"NAME\" = 'typeTitle' AND a__Type.\"GUID\" = a.\"TYPEGUID\")", sql); - query.ToList(); - - query = select.Where(a => a.Type.Parent.Name == "tparent"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"NAME\" = 'tparent')", sql); - query.ToList(); - - //���û�е������ԣ��򵥶������ - query = select.Where((a, b) => b.Guid == a.TypeGuid && b.Name == "typeTitle"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" b WHERE (b.\"GUID\" = a.\"TYPEGUID\" AND b.\"NAME\" = 'typeTitle')", sql); - query.ToList(); - - query = select.Where((a, b) => b.Name == "typeTitle" && b.Guid == a.TypeGuid); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" b WHERE (b.\"NAME\" = 'typeTitle' AND b.\"GUID\" = a.\"TYPEGUID\")", sql); - query.ToList(); - - query = select.Where((a, b, c) => c.Name == "tparent"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEPARENTINFO\" c WHERE (c.\"NAME\" = 'tparent')", sql); - query.ToList(); - - //����һ�� From ��Ķ������ - var query2 = select.From((s, b, c) => s - .Where(a => a.Id == 10 && c.Name == "xxx") - .Where(a => b.ParentId == 20)); - sql = query2.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" b, \"TESTTYPEPARENTINFO\" c WHERE (a.\"ID\" = 10 AND c.\"NAME\" = 'xxx') AND (b.\"PARENTID\" = 20)", sql); - query2.ToList(); - } - [Fact] - public void WhereIf() - { - //����е�������a.Type��a.Type.Parent ���ǵ������� - var query = select.WhereIf(true, a => a.Id == 10); - var sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10)", sql); - query.ToList(); - - query = select.WhereIf(true, a => a.Id == 10 && a.Id > 10 || a.Clicks > 100); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE ((a.\"ID\" = 10 AND a.\"ID\" > 10 OR a.\"CLICKS\" > 100))", sql); - query.ToList(); - - query = select.WhereIf(true, a => a.Id == 10).WhereIf(true, a => a.Clicks > 100); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10) AND (a.\"CLICKS\" > 100)", sql); - query.ToList(); - - query = select.WhereIf(true, a => a.Type.Name == "typeTitle"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" WHERE (a__Type.\"NAME\" = 'typeTitle')", sql); - query.ToList(); - - query = select.WhereIf(true, a => a.Type.Name == "typeTitle" && a.Type.Guid == a.TypeGuid); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" WHERE (a__Type.\"NAME\" = 'typeTitle' AND a__Type.\"GUID\" = a.\"TYPEGUID\")", sql); - query.ToList(); - - query = select.WhereIf(true, a => a.Type.Parent.Name == "tparent"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a LEFT JOIN \"TESTTYPEINFO\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" LEFT JOIN \"TESTTYPEPARENTINFO\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"NAME\" = 'tparent')", sql); - query.ToList(); - - //����һ�� From ��Ķ������ - var query2 = select.From((s, b, c) => s - .WhereIf(true, a => a.Id == 10 && c.Name == "xxx") - .WhereIf(true, a => b.ParentId == 20)); - sql = query2.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" b, \"TESTTYPEPARENTINFO\" c WHERE (a.\"ID\" = 10 AND c.\"NAME\" = 'xxx') AND (b.\"PARENTID\" = 20)", sql); - query2.ToList(); - - // ==========================================WhereIf(false) - - //����е�������a.Type��a.Type.Parent ���ǵ������� - query = select.WhereIf(false, a => a.Id == 10); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql); - query.ToList(); - - query = select.WhereIf(false, a => a.Id == 10 && a.Id > 10 || a.Clicks > 100); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql); - query.ToList(); - - query = select.WhereIf(false, a => a.Id == 10).WhereIf(false, a => a.Clicks > 100); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql); - query.ToList(); - - query = select.WhereIf(false, a => a.Type.Name == "typeTitle"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql); - query.ToList(); - - query = select.WhereIf(false, a => a.Type.Name == "typeTitle" && a.Type.Guid == a.TypeGuid); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql); - query.ToList(); - - query = select.WhereIf(false, a => a.Type.Parent.Name == "tparent"); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a", sql); - query.ToList(); - - //����һ�� From ��Ķ������ - query2 = select.From((s, b, c) => s - .WhereIf(false, a => a.Id == 10 && c.Name == "xxx") - .WhereIf(false, a => b.ParentId == 20)); - sql = query2.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a, \"TESTTYPEINFO\" b, \"TESTTYPEPARENTINFO\" c", sql); - query2.ToList(); - } - [Fact] - public void WhereExists() - { - var sql2222 = select.Where(a => select.Where(b => b.Id == a.Id).Any()).ToList(); - - sql2222 = select.Where(a => - select.Where(b => b.Id == a.Id && select.Where(c => c.Id == b.Id).Where(d => d.Id == a.Id).Where(e => e.Id == b.Id) - - //.Offset(a.Id) - - .Any() - ).Any() - ).ToList(); - } - [Fact] - public void GroupBy() - { - var groupby = select.From((s, b, c) => s - .Where(a => a.Id == 1) - ) - .GroupBy((a, b, c) => new { tt2 = a.Title.Substring(0, 2), mod4 = a.Id % 4 }) - .Having(a => a.Count() > 0 && a.Avg(a.Key.mod4) > 0 && a.Max(a.Key.mod4) > 0) - .Having(a => a.Count() < 300 || a.Avg(a.Key.mod4) < 100) - .OrderBy(a => a.Key.tt2) - .OrderByDescending(a => a.Count()) - .Offset(10) - .Limit(2) - .Count(out var trycount) - .ToList(a => new - { - a.Key.tt2, - cou1 = a.Count(), - cou2 = a.Count(a.Value.Item3.Id), - arg1 = a.Avg(a.Key.mod4), - ccc2 = a.Key.tt2 ?? "now()", - //ccc = Convert.ToDateTime("now()"), partby = Convert.ToDecimal("sum(num) over(PARTITION BY server_id,os,rid,chn order by id desc)") - ccc3 = a.Max(a.Value.Item3.Id) - }); - - var testpid1 = g.kingbaseES.Insert().AppendData(new TestTypeInfo { Name = "Name" + DateTime.Now.ToString("yyyyMMddHHmmss") }).ExecuteIdentity(); - g.kingbaseES.Insert().AppendData(new TestInfo { Title = "Title" + DateTime.Now.ToString("yyyyMMddHHmmss"), CreateTime = DateTime.Now, TypeGuid = (int)testpid1 }).ExecuteAffrows(); - - var fkfjfj = select.GroupBy(a => a.Title) - .ToList(a => a.Sum(a.Value.TypeGuid)); - - var aggsql1 = select - .GroupBy(a => a.Title) - .ToSql(b => new - { - b.Key, - cou = b.Count(), - sum2 = b.Sum(b.Value.TypeGuid) - }); - var aggtolist1 = select - .GroupBy(a => a.Title) - .ToList(b => new - { - b.Key, - cou = b.Count(), - sum2 = b.Sum(b.Value.TypeGuid) - }); - var aggtolist11 = select - .GroupBy(a => a.Title) - .ToDictionary(b => new - { - b.Key, - cou = b.Count(), - sum2 = b.Sum(b.Value.TypeGuid) - }); - - var aggsql2 = select - .GroupBy(a => new { a.Title, yyyy = string.Concat(a.CreateTime.Year, '-', a.CreateTime.Month) }) - .ToSql(b => new - { - b.Key.Title, - b.Key.yyyy, - - cou = b.Count(), - sum2 = b.Sum(b.Value.TypeGuid) - }); - var aggtolist2 = select - .GroupBy(a => new { a.Title, yyyy = string.Concat(a.CreateTime.Year, '-', a.CreateTime.Month) }) - .ToList(b => new - { - b.Key.Title, - b.Key.yyyy, - cou = b.Count(), - sum2 = b.Sum(b.Value.TypeGuid) - }); - var aggtolist22 = select - .GroupBy(a => new { a.Title, yyyy = string.Concat(a.CreateTime.Year, '-', a.CreateTime.Month) }) - .ToDictionary(b => new - { - b.Key.Title, - b.Key.yyyy, - b.Key, - cou = b.Count(), - sum2 = b.Sum(b.Value.TypeGuid) - }); - - var aggsql3 = select - .GroupBy(a => a.Title) - .ToSql(b => new - { - b.Key, - cou = b.Count(), - sum2 = b.Sum(b.Value.TypeGuid), - sum3 = b.Sum(b.Value.Type.Parent.Id) - }); - } - [Fact] - public void ToAggregate() - { - var sql = select.ToAggregate(a => new { sum = a.Sum(a.Key.Id + 11.11), avg = a.Avg(a.Key.Id), count = a.Count(), max = a.Max(a.Key.Id), min = a.Min(a.Key.Id) }); - } - [Fact] - public void OrderBy() - { - var sql = select.Offset(10).OrderBy(a => new Random().NextDouble()).ToList(); - } - [Fact] - public void OrderByRandom() - { - var t1 = select.OrderByRandom().Limit(10).ToSql("1"); - Assert.Equal(@"SELECT 1 -FROM ""TB_TOPIC22"" a -ORDER BY random() -limit 10", t1); - var t2 = select.OrderByRandom().Limit(10).ToList(); - } - - [Fact] - public void Skip_Offset() - { - var sql = select.Offset(10).ToList(); - } - [Fact] - public void Take_Limit() - { - var sql = select.Limit(10).ToList(); - } - [Fact] - public void Page() - { - var sql1 = select.Page(1, 10).ToList(); - var sql2 = select.Page(2, 10).ToList(); - var sql3 = select.Page(3, 10).ToList(); - - var sql11 = select.OrderBy(a => new Random().NextDouble()).Page(1, 10).ToList(); - var sql22 = select.OrderBy(a => new Random().NextDouble()).Page(2, 10).ToList(); - var sql33 = select.OrderBy(a => new Random().NextDouble()).Page(3, 10).ToList(); - } - [Fact] - public void Distinct() - { - var t1 = select.Distinct().ToList(a => a.Title); - var t2 = select.Distinct().Limit(10).ToList(a => a.Title); - } - - [Fact] - public void Sum() - { - var subquery = select.ToSql(a => new - { - all = a, - count = (long)select.As("b").Sum(b => b.Id) - }); - Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, coalesce((SELECT sum(b.""ID"") - FROM ""TB_TOPIC22"" b), 0) as6 -FROM ""TB_TOPIC22"" a", subquery); - var subqueryList = select.ToList(a => new - { - all = a, - count = (long)select.As("b").Sum(b => b.Id) - }); - } - [Fact] - public void Min() - { - var subquery = select.ToSql(a => new - { - all = a, - min = select.As("b").Min(b => b.Id), - min2 = select.As("b").Min(b => b.CreateTime) - }); - Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, coalesce((SELECT min(b.""ID"") - FROM ""TB_TOPIC"" b), 0) as6, coalesce((SELECT min(b.""CREATETIME"") - FROM ""TB_TOPIC"" b), '0001-01-01 00:00:00.000000') as7 -FROM ""TB_TOPIC"" a", subquery); - var subqueryList = select.ToList(a => new - { - all = a, - min = select.As("b").Min(b => b.Id), - min2 = select.As("b").Min(b => b.CreateTime) - }); - } - [Fact] - public void Max() - { - var subquery = select.ToSql(a => new - { - all = a, - max = select.As("b").Max(b => b.Id), - max2 = select.As("b").Max(b => b.CreateTime) - }); - Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, coalesce((SELECT max(b.""ID"") - FROM ""TB_TOPIC"" b), 0) as6, coalesce((SELECT max(b.""CREATETIME"") - FROM ""TB_TOPIC"" b), '0001-01-01 00:00:00.000000') as7 -FROM ""TB_TOPIC"" a", subquery); - var subqueryList = select.ToList(a => new - { - all = a, - max = select.As("b").Max(b => b.Id), - max2 = select.As("b").Max(b => b.CreateTime) - }); - } - [Fact] - public void Avg() - { - var subquery = select.ToSql(a => new - { - all = a, - count = select.As("b").Avg(b => b.Id) - }); - Assert.Equal(@"SELECT a.""ID"" as1, a.""CLICKS"" as2, a.""TYPEGUID"" as3, a.""TITLE"" as4, a.""CREATETIME"" as5, coalesce((SELECT avg(b.""ID"") - FROM ""TB_TOPIC22"" b), 0) as6 -FROM ""TB_TOPIC22"" a", subquery); - var subqueryList = select.ToList(a => new - { - all = a, - count = select.As("b").Avg(b => b.Id) - }); - } - [Fact] - public void WhereIn() - { - var subquery = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToSql(); - Assert.Equal(@"SELECT a.""ID"", a.""CLICKS"", a.""TYPEGUID"", a.""TITLE"", a.""CREATETIME"" -FROM ""TB_TOPIC22"" a -WHERE ((((a.""ID"")::text) in (SELECT b.""TITLE"" - FROM ""TB_TOPIC22"" b)))", subquery); - var subqueryList = select.Where(a => select.As("b").ToList(b => b.Title).Contains(a.Id.ToString())).ToList(); - } - [Fact] - public void As() - { - } - - [Fact] - public void AsTable() - { - - var listt = select.AsTable((a, b) => "(select * from tb_topic where clicks > 10)").Page(1, 10).ToList(); - - Func tableRule = (type, oldname) => - { - if (oldname.Length > 16) oldname = oldname.Remove(16); - if (type == typeof(Topic)) return oldname + "_T1"; - else if (type == typeof(TestTypeInfo)) return oldname + "_T2"; - return oldname + "_AT"; - }; - - //����е�������a.Type��a.Type.Parent ���ǵ������� - var query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid).AsTable(tableRule); - var sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO_T2\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\"", sql); - - query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").AsTable(tableRule); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO_T2\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx'", sql); - - query = select.LeftJoin(a => a.Type.Guid == a.TypeGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO_T2\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTIN_AT\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql); - - //���û�е������� - query = select.LeftJoin((a, b) => b.Guid == a.TypeGuid).AsTable(tableRule); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO_T2\" b ON b.\"GUID\" = a.\"TYPEGUID\"", sql); - - query = select.LeftJoin((a, b) => b.Guid == a.TypeGuid && b.Name == "xxx").AsTable(tableRule); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO_T2\" b ON b.\"GUID\" = a.\"TYPEGUID\" AND b.\"NAME\" = 'xxx'", sql); - - query = select.LeftJoin((a, a__Type) => a__Type.Guid == a.TypeGuid && a__Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO_T2\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" AND a__Type.\"NAME\" = 'xxx' LEFT JOIN \"TESTTYPEPARENTIN_AT\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\" WHERE (a__Type__Parent.\"ID\" = 10)", sql); - - //������� - query = select - .LeftJoin(a => a.Type.Guid == a.TypeGuid) - .LeftJoin(a => a.Type.Parent.Id == a.Type.ParentId).AsTable(tableRule); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO_T2\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" LEFT JOIN \"TESTTYPEPARENTIN_AT\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\"", sql); - - query = select - .LeftJoin((a, a__Type) => a__Type.Guid == a.TypeGuid) - .LeftJoin((a, c) => c.Id == a.Type.ParentId).AsTable(tableRule); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO_T2\" a__Type ON a__Type.\"GUID\" = a.\"TYPEGUID\" LEFT JOIN \"TESTTYPEPARENTIN_AT\" c ON c.\"ID\" = a__Type.\"PARENTID\"", sql); - - //���û�е�������b��c������ϵ - var query2 = select.From((s, b, c) => s - .LeftJoin(a => a.TypeGuid == b.Guid) - .LeftJoin(a => b.ParentId == c.Id)).AsTable(tableRule); - sql = query2.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO_T2\" b ON a.\"TYPEGUID\" = b.\"GUID\" LEFT JOIN \"TESTTYPEPARENTIN_AT\" c ON b.\"PARENTID\" = c.\"ID\"", sql); - - //������϶����㲻�� - query = select.LeftJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\"").AsTable(tableRule); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\"", sql); - - query = select.LeftJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = @bname", new { bname = "xxx" }).AsTable(tableRule); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22_T1\" a LEFT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TYPEGUID\" and b.\"NAME\" = @bname", sql); - - query = select.AsTable((_, old) => old).AsTable((_, old) => old); - sql = query.ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT * from (SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a) ftb UNION ALL SELECT * from (SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a) ftb", sql); - query.ToList(); - - query = select.AsTable((_, old) => old).AsTable((_, old) => old); - sql = query.ToSql("count(1) as1").Replace("\r\n", ""); - Assert.Equal("SELECT * from (SELECT count(1) as1 FROM \"TB_TOPIC22\" a) ftb UNION ALL SELECT * from (SELECT count(1) as1 FROM \"TB_TOPIC22\" a) ftb", sql); - query.Count(); - - select.AsTable((_, old) => old).AsTable((_, old) => old).Max(a => a.Id); - select.AsTable((_, old) => old).AsTable((_, old) => old).Min(a => a.Id); - select.AsTable((_, old) => old).AsTable((_, old) => old).Sum(a => a.Id); - select.AsTable((_, old) => old).AsTable((_, old) => old).Avg(a => a.Id); - - var sqlsss = select - .AsTable((type, old) => type == typeof(Topic) ? $"{old}_1" : null) - .AsTable((type, old) => type == typeof(Topic) ? $"{old}_2" : null) - .ToSql(a => new - { - a.Id, - a.Clicks - }, FieldAliasOptions.AsProperty); - - var slsld3 = select - .AsTable((type, old) => type == typeof(Topic) ? $"({sqlsss})" : null) - .Page(1, 20) - .ToList(a => new - { - a.Id, - a.Clicks - }); - } - - public class TiOtmModel1 - { - [Column(IsIdentity = true)] - public int id { get; set; } - public virtual TiOtmModel2 model2 { get; set; } - - public string m1name { get; set; } - } - public class TiOtmModel2 - { - [Column(IsPrimary = true)] - public int model2id { get; set; } - public virtual TiOtmModel1 model1 { get; set; } - - public string m2setting { get; set; } - - public List childs { get; set; } - } - public class TiOtmModel3 - { - [Column(IsIdentity = true)] - public int id { get; set; } - - public int model2111Idaaa { get; set; } - public string title { get; set; } - - public List childs2 { get; set; } - } - public class TiOtmModel4 - { - [Column(IsIdentity = true)] - public int id { get; set; } - - public int model3333Id333 { get; set; } - public string title444 { get; set; } - } - - [Fact] - public void Include_OneToMany() - { - var model1 = new TiOtmModel1 { m1name = DateTime.Now.Second.ToString() }; - model1.id = (int)g.kingbaseES.Insert(model1).ExecuteIdentity(); - var model2 = new TiOtmModel2 { model2id = model1.id, m2setting = DateTime.Now.Second.ToString() }; - g.kingbaseES.Insert(model2).ExecuteAffrows(); - - var model3_1 = new TiOtmModel3 { model2111Idaaa = model1.id, title = "testmodel3__111" }; - model3_1.id = (int)g.kingbaseES.Insert(model3_1).ExecuteIdentity(); - var model3_2 = new TiOtmModel3 { model2111Idaaa = model1.id, title = "testmodel3__222" }; - model3_2.id = (int)g.kingbaseES.Insert(model3_2).ExecuteIdentity(); - var model3_3 = new TiOtmModel3 { model2111Idaaa = model1.id, title = "testmodel3__333" }; - model3_3.id = (int)g.kingbaseES.Insert(model3_2).ExecuteIdentity(); - - var model4s = new[] { - new TiOtmModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__111" }, - new TiOtmModel4{ model3333Id333 = model3_1.id, title444 = "testmodel3_4__222" }, - new TiOtmModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__111" }, - new TiOtmModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__222" }, - new TiOtmModel4{ model3333Id333 = model3_2.id, title444 = "testmodel3_4__333" } - }; - Assert.Equal(5, g.kingbaseES.Insert(model4s).ExecuteAffrows()); - - var t0 = g.kingbaseES.Select() - .IncludeMany(a => a.childs.Where(m3 => m3.model2111Idaaa == a.model2id)) - .Where(a => a.model2id <= model1.id) - .ToList(); - - var t1 = g.kingbaseES.Select() - .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id)) - .Where(a => a.id <= model1.id) - .ToList(); - - var t2 = g.kingbaseES.Select() - .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id), - then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id))) - .Where(a => a.id <= model1.id) - .ToList(); - - var t00 = g.kingbaseES.Select() - .IncludeMany(a => a.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2id)) - .Where(a => a.model2id <= model1.id) - .ToList(); - - var t11 = g.kingbaseES.Select() - .IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id)) - .Where(a => a.id <= model1.id) - .ToList(); - - var t22 = g.kingbaseES.Select() - .IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id), - then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id))) - .Where(a => a.id <= model1.id) - .ToList(); - - //---- Select ---- - - var at0 = g.kingbaseES.Select() - .IncludeMany(a => a.childs.Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TiOtmModel3 { id = m3.id })) - .Where(a => a.model2id <= model1.id) - .ToList(); - - var at1 = g.kingbaseES.Select() - .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TiOtmModel3 { id = m3.id })) - .Where(a => a.id <= model1.id) - .ToList(); - - var at2 = g.kingbaseES.Select() - .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TiOtmModel3 { id = m3.id }), - then => then.IncludeMany(m3 => m3.childs2.Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TiOtmModel4 { id = m4.id }))) - .Where(a => a.id <= model1.id) - .ToList(); - - var at00 = g.kingbaseES.Select() - .IncludeMany(a => a.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2id).Select(m3 => new TiOtmModel3 { id = m3.id })) - .Where(a => a.model2id <= model1.id) - .ToList(); - - var at11 = g.kingbaseES.Select() - .IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TiOtmModel3 { id = m3.id })) - .Where(a => a.id <= model1.id) - .ToList(); - - var at22 = g.kingbaseES.Select() - .IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id).Select(m3 => new TiOtmModel3 { id = m3.id }), - then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id).Select(m4 => new TiOtmModel4 { id = m4.id }))) - .Where(a => a.id <= model1.id) - .ToList(); - } - - public class TiOtmModel11 - { - [Column(IsIdentity = true)] - public int id { get; set; } - public int model2id { get; set; } - public string m3setting { get; set; } - public TiOtmModel22 model2 { get; set; } - public string m1name { get; set; } - } - - public class TiOtmModel22 - { - [Column(IsIdentity = true)] - public int id { get; set; } - public string m2setting { get; set; } - public string aaa { get; set; } - public string bbb { get; set; } - public List childs { get; set; } - } - public class TiOtmModel33 - { - [Column(IsIdentity = true)] - public int id { get; set; } - public int model2Id { get; set; } - public string title { get; set; } - public string setting { get; set; } - } - [Fact] - public void Include_OneToMany2() - { - string setting = "x"; - var model2 = new TiOtmModel22 { m2setting = DateTime.Now.Second.ToString(), aaa = "aaa" + DateTime.Now.Second, bbb = "bbb" + DateTime.Now.Second }; - model2.id = (int)g.kingbaseES.Insert(model2).ExecuteIdentity(); - - var model3s = new[] - { - new TiOtmModel33 {model2Id = model2.id, title = "testmodel3__111", setting = setting}, - new TiOtmModel33 {model2Id = model2.id, title = "testmodel3__222", setting = setting}, - new TiOtmModel33 {model2Id = model2.id, title = "testmodel3__333", setting = setting} - }; - Assert.Equal(3, g.kingbaseES.Insert(model3s).ExecuteAffrows()); - - var model1 = new TiOtmModel11 { m1name = DateTime.Now.Second.ToString(), model2id = model2.id, m3setting = setting }; - model1.id = (int)g.kingbaseES.Insert(model1).ExecuteIdentity(); - - var t1 = g.kingbaseES.Select() - .LeftJoin(a => a.model2id == a.model2.id) - .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting)) - .Where(a => a.id <= model1.id) - .ToList(true); - - var t11 = g.kingbaseES.Select() - .LeftJoin(a => a.model2id == a.model2.id) - .IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting)) - .Where(a => a.id <= model1.id) - .ToList(true); - - //---- Select ---- - - var at1 = g.kingbaseES.Select() - .LeftJoin(a => a.model2id == a.model2.id) - .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TiOtmModel33 { title = m3.title })) - .Where(a => a.id <= model1.id) - .ToList(true); - - var at11 = g.kingbaseES.Select() - .LeftJoin(a => a.model2id == a.model2.id) - .IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting).Select(m3 => new TiOtmModel33 { title = m3.title })) - .Where(a => a.id <= model1.id) - .ToList(true); - } - - [Fact] - public void Include_OneToChilds() - { - var tag1 = new Tag - { - Ddd = DateTime.Now.Second, - Name = "test_oneToChilds_01_中国" - }; - tag1.Id = (int)g.kingbaseES.Insert(tag1).ExecuteIdentity(); - var tag1_1 = new Tag - { - Parent_id = tag1.Id, - Ddd = DateTime.Now.Second, - Name = "test_oneToChilds_01_北京" - }; - tag1_1.Id = (int)g.kingbaseES.Insert(tag1_1).ExecuteIdentity(); - var tag1_2 = new Tag - { - Parent_id = tag1.Id, - Ddd = DateTime.Now.Second, - Name = "test_oneToChilds_01_上海" - }; - tag1_2.Id = (int)g.kingbaseES.Insert(tag1_2).ExecuteIdentity(); - - var tag2 = new Tag - { - Ddd = DateTime.Now.Second, - Name = "test_oneToChilds_02_美国" - }; - tag2.Id = (int)g.kingbaseES.Insert(tag2).ExecuteIdentity(); - var tag2_1 = new Tag - { - Parent_id = tag2.Id, - Ddd = DateTime.Now.Second, - Name = "test_oneToChilds_02_纽约" - }; - tag2_1.Id = (int)g.kingbaseES.Insert(tag2_1).ExecuteIdentity(); - var tag2_2 = new Tag - { - Parent_id = tag2.Id, - Ddd = DateTime.Now.Second, - Name = "test_oneToChilds_02_华盛顿" - }; - tag2_2.Id = (int)g.kingbaseES.Insert(tag2_2).ExecuteIdentity(); - - var tags0 = g.kingbaseES.Select() - .Include(a => a.Parent) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var tags1 = g.kingbaseES.Select() - .IncludeMany(a => a.Tags) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var tags2 = g.kingbaseES.Select() - .IncludeMany(a => a.Tags, - then => then.Include(a => a.Parent).IncludeMany(a => a.Songs)) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var tags3 = g.kingbaseES.Select() - .IncludeMany(a => a.Tags, - then => then.Include(a => a.Parent).IncludeMany(a => a.Songs).IncludeMany(a => a.Tags)) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var tags11 = g.kingbaseES.Select() - .IncludeMany(a => a.Tags.Take(1)) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs.Take(1)) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var tags22 = g.kingbaseES.Select() - .IncludeMany(a => a.Tags.Take(1), - then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1))) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs.Take(1)) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var tags33 = g.kingbaseES.Select() - .IncludeMany(a => a.Tags.Take(1), - then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1)).IncludeMany(a => a.Tags.Take(1))) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs.Take(1)) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - // --- Select --- - - var atags0 = g.kingbaseES.Select() - .Include(a => a.Parent) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var atags1 = g.kingbaseES.Select() - .IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name })) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var atags2 = g.kingbaseES.Select() - .IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }), - then => then.Include(a => a.Parent).IncludeMany(a => a.Songs)) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var atags3 = g.kingbaseES.Select() - .IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }), - then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }))) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var atags11 = g.kingbaseES.Select() - .IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name })) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var atags22 = g.kingbaseES.Select() - .IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }), - then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - - var atags33 = g.kingbaseES.Select() - .IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }), - then => then.Include(a => a.Parent).IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })).IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }))) - .Include(a => a.Parent) - .IncludeMany(a => a.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })) - .Where(a => a.Id == tag1.Id || a.Id == tag2.Id) - .ToList(); - } - - [Fact] - public void Include_ManyToMany() - { - - var tag1 = new Tag - { - Ddd = DateTime.Now.Second, - Name = "test_manytoMany_01_中国" - }; - tag1.Id = (int)g.kingbaseES.Insert(tag1).ExecuteIdentity(); - var tag2 = new Tag - { - Ddd = DateTime.Now.Second, - Name = "test_manytoMany_02_美国" - }; - tag2.Id = (int)g.kingbaseES.Insert(tag2).ExecuteIdentity(); - var tag3 = new Tag - { - Ddd = DateTime.Now.Second, - Name = "test_manytoMany_03_日本" - }; - tag3.Id = (int)g.kingbaseES.Insert(tag3).ExecuteIdentity(); - - var song1 = new Song - { - Create_time = DateTime.Now, - Title = "test_manytoMany_01_我是中国人.mp3", - Url = "http://ww.baidu.com/" - }; - song1.Id = (int)g.kingbaseES.Insert(song1).ExecuteIdentity(); - var song2 = new Song - { - Create_time = DateTime.Now, - Title = "test_manytoMany_02_爱你一万年.mp3", - Url = "http://ww.163.com/" - }; - song2.Id = (int)g.kingbaseES.Insert(song2).ExecuteIdentity(); - var song3 = new Song - { - Create_time = DateTime.Now, - Title = "test_manytoMany_03_千年等一回.mp3", - Url = "http://ww.sina.com/" - }; - song3.Id = (int)g.kingbaseES.Insert(song3).ExecuteIdentity(); - - g.kingbaseES.Insert(new Song_tag { Song_id = song1.Id, Tag_id = tag1.Id }).ExecuteAffrows(); - g.kingbaseES.Insert(new Song_tag { Song_id = song2.Id, Tag_id = tag1.Id }).ExecuteAffrows(); - g.kingbaseES.Insert(new Song_tag { Song_id = song3.Id, Tag_id = tag1.Id }).ExecuteAffrows(); - g.kingbaseES.Insert(new Song_tag { Song_id = song1.Id, Tag_id = tag2.Id }).ExecuteAffrows(); - g.kingbaseES.Insert(new Song_tag { Song_id = song3.Id, Tag_id = tag2.Id }).ExecuteAffrows(); - g.kingbaseES.Insert(new Song_tag { Song_id = song3.Id, Tag_id = tag3.Id }).ExecuteAffrows(); - - var songs1 = g.kingbaseES.Select() - .IncludeMany(a => a.Tags) - .Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id) - .ToList(); - Assert.Equal(3, songs1.Count); - Assert.Equal(2, songs1[0].Tags.Count); - Assert.Equal(1, songs1[1].Tags.Count); - Assert.Equal(3, songs1[2].Tags.Count); - - var songs2 = g.kingbaseES.Select() - .IncludeMany(a => a.Tags, - then => then.IncludeMany(t => t.Songs)) - .Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id) - .ToList(); - Assert.Equal(3, songs2.Count); - Assert.Equal(2, songs2[0].Tags.Count); - Assert.Equal(1, songs2[1].Tags.Count); - Assert.Equal(3, songs2[2].Tags.Count); - - var tags3 = g.kingbaseES.Select() - .Include(a => a.Tag.Parent) - .IncludeMany(a => a.Tag.Songs) - .Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id) - .ToList(true); - - - var songs11 = g.kingbaseES.Select() - .IncludeMany(a => a.Tags.Take(1)) - .Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id) - .ToList(); - Assert.Equal(3, songs11.Count); - Assert.Equal(1, songs11[0].Tags.Count); - Assert.Equal(1, songs11[1].Tags.Count); - Assert.Equal(1, songs11[2].Tags.Count); - - var songs22 = g.kingbaseES.Select() - .IncludeMany(a => a.Tags.Take(1), - then => then.IncludeMany(t => t.Songs.Take(1))) - .Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id) - .ToList(); - Assert.Equal(3, songs22.Count); - Assert.Equal(1, songs22[0].Tags.Count); - Assert.Equal(1, songs22[1].Tags.Count); - Assert.Equal(1, songs22[2].Tags.Count); - - var tags33 = g.kingbaseES.Select() - .Include(a => a.Tag.Parent) - .IncludeMany(a => a.Tag.Songs.Take(1)) - .Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id) - .ToList(true); - - // --- Select --- - - new List(new[] { song1, song2, song3 }).IncludeMany(g.kingbaseES, a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name })); - - var asongs1 = g.kingbaseES.Select() - .IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name })) - .Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id) - .ToList(); - Assert.Equal(3, songs1.Count); - Assert.Equal(2, songs1[0].Tags.Count); - Assert.Equal(1, songs1[1].Tags.Count); - Assert.Equal(3, songs1[2].Tags.Count); - - var asongs2 = g.kingbaseES.Select() - .IncludeMany(a => a.Tags.Select(b => new Tag { Id = b.Id, Name = b.Name }), - then => then.IncludeMany(t => t.Songs.Select(b => new Song { Id = b.Id, Title = b.Title }))) - .Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id) - .ToList(); - Assert.Equal(3, songs2.Count); - Assert.Equal(2, songs2[0].Tags.Count); - Assert.Equal(1, songs2[1].Tags.Count); - Assert.Equal(3, songs2[2].Tags.Count); - - var atags3 = g.kingbaseES.Select() - .Include(a => a.Tag.Parent) - .IncludeMany(a => a.Tag.Songs.Select(b => new Song { Id = b.Id, Title = b.Title })) - .Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id) - .ToList(true); - - - var asongs11 = g.kingbaseES.Select() - .IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name })) - .Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id) - .ToList(); - Assert.Equal(3, songs11.Count); - Assert.Equal(1, songs11[0].Tags.Count); - Assert.Equal(1, songs11[1].Tags.Count); - Assert.Equal(1, songs11[2].Tags.Count); - - var asongs22 = g.kingbaseES.Select() - .IncludeMany(a => a.Tags.Take(1).Select(b => new Tag { Id = b.Id, Name = b.Name }), - then => then.IncludeMany(t => t.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title }))) - .Where(a => a.Id == song1.Id || a.Id == song2.Id || a.Id == song3.Id) - .ToList(); - Assert.Equal(3, songs22.Count); - Assert.Equal(1, songs22[0].Tags.Count); - Assert.Equal(1, songs22[1].Tags.Count); - Assert.Equal(1, songs22[2].Tags.Count); - - var atags33 = g.kingbaseES.Select() - .Include(a => a.Tag.Parent) - .IncludeMany(a => a.Tag.Songs.Take(1).Select(b => new Song { Id = b.Id, Title = b.Title })) - .Where(a => a.Tag.Id == tag1.Id || a.Tag.Id == tag2.Id) - .ToList(true); - } - - public class ToDel1Pk - { - [Column(IsIdentity = true)] - public int id { get; set; } - public string name { get; set; } - } - public class ToDel2Pk - { - [Column(IsPrimary = true)] - public Guid pk1 { get; set; } - [Column(IsPrimary = true)] - public string pk2 { get; set; } - public string name { get; set; } - } - public class ToDel3Pk - { - [Column(IsPrimary = true)] - public Guid pk1 { get; set; } - [Column(IsPrimary = true)] - public int pk2 { get; set; } - [Column(IsPrimary = true)] - public string pk3 { get; set; } - public string name { get; set; } - } - [Fact] - public void ToDelete() - { - g.kingbaseES.Select().ToDelete().ExecuteAffrows(); - Assert.Equal(0, g.kingbaseES.Select().Count()); - g.kingbaseES.Insert(new[] { - new ToDel1Pk{ name = "name1"}, - new ToDel1Pk{ name = "name2"}, - new ToDel1Pk{ name = "nick1"}, - new ToDel1Pk{ name = "nick2"}, - new ToDel1Pk{ name = "nick3"} - }).ExecuteAffrows(); - Assert.Equal(2, g.kingbaseES.Select().Where(a => a.name.StartsWith("name")).ToDelete().ExecuteAffrows()); - Assert.Equal(3, g.kingbaseES.Select().Count()); - Assert.Equal(3, g.kingbaseES.Select().Where(a => a.name.StartsWith("nick")).Count()); - - g.kingbaseES.Select().ToDelete().ExecuteAffrows(); - Assert.Equal(0, g.kingbaseES.Select().Count()); - g.kingbaseES.Insert(new[] { - new ToDel2Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = "pk2", name = "name1"}, - new ToDel2Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = "pk2", name = "name2"}, - new ToDel2Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = "pk2", name = "nick1"}, - new ToDel2Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = "pk2", name = "nick2"}, - new ToDel2Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = "pk2", name = "nick3"} - }).ExecuteAffrows(); - Assert.Equal(2, g.kingbaseES.Select().Where(a => a.name.StartsWith("name")).ToDelete().ExecuteAffrows()); - Assert.Equal(3, g.kingbaseES.Select().Count()); - Assert.Equal(3, g.kingbaseES.Select().Where(a => a.name.StartsWith("nick")).Count()); - - g.kingbaseES.Select().ToDelete().ExecuteAffrows(); - Assert.Equal(0, g.kingbaseES.Select().Count()); - g.kingbaseES.Insert(new[] { - new ToDel3Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = 1, pk3 = "pk3", name = "name1"}, - new ToDel3Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = 1, pk3 = "pk3", name = "name2"}, - new ToDel3Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = 1, pk3 = "pk3", name = "nick1"}, - new ToDel3Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = 1, pk3 = "pk3", name = "nick2"}, - new ToDel3Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = 1, pk3 = "pk3", name = "nick3"} - }).ExecuteAffrows(); - Assert.Equal(2, g.kingbaseES.Select().Where(a => a.name.StartsWith("name")).ToDelete().ExecuteAffrows()); - Assert.Equal(3, g.kingbaseES.Select().Count()); - Assert.Equal(3, g.kingbaseES.Select().Where(a => a.name.StartsWith("nick")).Count()); - } - - public class ToUpd1Pk - { - [Column(IsIdentity = true)] - public int id { get; set; } - public string name { get; set; } - } - public class ToUpd2Pk - { - [Column(IsPrimary = true)] - public Guid pk1 { get; set; } - [Column(IsPrimary = true)] - public string pk2 { get; set; } - public string name { get; set; } - } - public class ToUpd3Pk - { - [Column(IsPrimary = true)] - public Guid pk1 { get; set; } - [Column(IsPrimary = true)] - public int pk2 { get; set; } - [Column(IsPrimary = true)] - public string pk3 { get; set; } - public string name { get; set; } - } - [Fact] - public void ToUpdate() - { - g.kingbaseES.Select().ToDelete().ExecuteAffrows(); - Assert.Equal(0, g.kingbaseES.Select().Count()); - g.kingbaseES.Insert(new[] { - new ToUpd1Pk{ name = "name1"}, - new ToUpd1Pk{ name = "name2"}, - new ToUpd1Pk{ name = "nick1"}, - new ToUpd1Pk{ name = "nick2"}, - new ToUpd1Pk{ name = "nick3"} - }).ExecuteAffrows(); - Assert.Equal(2, g.kingbaseES.Select().Where(a => a.name.StartsWith("name")).ToUpdate().Set(a => a.name, "nick?").ExecuteAffrows()); - Assert.Equal(5, g.kingbaseES.Select().Count()); - Assert.Equal(5, g.kingbaseES.Select().Where(a => a.name.StartsWith("nick")).Count()); - - g.kingbaseES.Select().ToDelete().ExecuteAffrows(); - Assert.Equal(0, g.kingbaseES.Select().Count()); - g.kingbaseES.Insert(new[] { - new ToUpd2Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = "pk2", name = "name1"}, - new ToUpd2Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = "pk2", name = "name2"}, - new ToUpd2Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = "pk2", name = "nick1"}, - new ToUpd2Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = "pk2", name = "nick2"}, - new ToUpd2Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = "pk2", name = "nick3"} - }).ExecuteAffrows(); - Assert.Equal(2, g.kingbaseES.Select().Where(a => a.name.StartsWith("name")).ToUpdate().Set(a => a.name, "nick?").ExecuteAffrows()); - Assert.Equal(5, g.kingbaseES.Select().Count()); - Assert.Equal(5, g.kingbaseES.Select().Where(a => a.name.StartsWith("nick")).Count()); - - g.kingbaseES.Select().ToDelete().ExecuteAffrows(); - Assert.Equal(0, g.kingbaseES.Select().Count()); - g.kingbaseES.Insert(new[] { - new ToUpd3Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = 1, pk3 = "pk3", name = "name1"}, - new ToUpd3Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = 1, pk3 = "pk3", name = "name2"}, - new ToUpd3Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = 1, pk3 = "pk3", name = "nick1"}, - new ToUpd3Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = 1, pk3 = "pk3", name = "nick2"}, - new ToUpd3Pk{ pk1 = FreeUtil.NewMongodbId(), pk2 = 1, pk3 = "pk3", name = "nick3"} - }).ExecuteAffrows(); - Assert.Equal(2, g.kingbaseES.Select().Where(a => a.name.StartsWith("name")).ToUpdate().Set(a => a.name, "nick?").ExecuteAffrows()); - Assert.Equal(5, g.kingbaseES.Select().Count()); - Assert.Equal(5, g.kingbaseES.Select().Where(a => a.name.StartsWith("nick")).Count()); - } - - [Fact] - public void ForUpdate() - { - var orm = g.kingbaseES; - - Assert.Equal("安全起见,请务必在事务开启之后,再使用 ForUpdate", - Assert.Throws(() => orm.Select().ForUpdate().Limit(1).ToList())?.Message); - - orm.Transaction(() => - { - var sql = orm.Select().ForUpdate().Limit(1).ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"NAME\" FROM \"TOUPD1PK\" a limit 1 for update", sql); - orm.Select().ForUpdate().Limit(1).ToList(); - - sql = orm.Select().ForUpdate(true).Limit(1).ToSql().Replace("\r\n", ""); - Assert.Equal("SELECT a.\"ID\", a.\"NAME\" FROM \"TOUPD1PK\" a limit 1 for update nowait", sql); - orm.Select().ForUpdate(true).Limit(1).ToList(); - }); - } - - [Fact] - public void ToTreeList() - { - var fsql = g.kingbaseES; - fsql.Delete().Where("1=1").ExecuteAffrows(); - var repo = fsql.GetRepository(); - repo.DbContextOptions.EnableCascadeSave = true; - repo.DbContextOptions.NoneParameter = true; - repo.Insert(new VM_District_Child - { - Code = "100000", - Name = "中国", - Childs = new List(new[] { - new VM_District_Child - { - Code = "110000", - Name = "北京", - Childs = new List(new[] { - new VM_District_Child{ Code="110100", Name = "北京市" }, - new VM_District_Child{ Code="110101", Name = "东城区" }, - }) - } - }) - }); - - var t1 = fsql.Select() - .InnerJoin(a => a.ParentCode == a.Parent.Code) - .Where(a => a.Code == "110101") - .ToList(true); - Assert.Single(t1); - Assert.Equal("110101", t1[0].Code); - Assert.NotNull(t1[0].Parent); - Assert.Equal("110000", t1[0].Parent.Code); - - var t2 = fsql.Select() - .InnerJoin(a => a.ParentCode == a.Parent.Code) - .InnerJoin(a => a.Parent.ParentCode == a.Parent.Parent.Code) - .Where(a => a.Code == "110101") - .ToList(true); - Assert.Single(t2); - Assert.Equal("110101", t2[0].Code); - Assert.NotNull(t2[0].Parent); - Assert.Equal("110000", t2[0].Parent.Code); - Assert.NotNull(t2[0].Parent.Parent); - Assert.Equal("100000", t2[0].Parent.Parent.Code); - - var t3 = fsql.Select().ToTreeList(); - Assert.Single(t3); - Assert.Equal("100000", t3[0].Code); - Assert.Single(t3[0].Childs); - Assert.Equal("110000", t3[0].Childs[0].Code); - Assert.Equal(2, t3[0].Childs[0].Childs.Count); - Assert.Equal("110100", t3[0].Childs[0].Childs[0].Code); - Assert.Equal("110101", t3[0].Childs[0].Childs[1].Code); - - t3 = fsql.Select().Where(a => a.Name == "中国").AsTreeCte().OrderBy(a => a.Code).ToTreeList(); - Assert.Single(t3); - Assert.Equal("100000", t3[0].Code); - Assert.Single(t3[0].Childs); - Assert.Equal("110000", t3[0].Childs[0].Code); - Assert.Equal(2, t3[0].Childs[0].Childs.Count); - Assert.Equal("110100", t3[0].Childs[0].Childs[0].Code); - Assert.Equal("110101", t3[0].Childs[0].Childs[1].Code); - - t3 = fsql.Select().Where(a => a.Name == "中国").AsTreeCte().OrderBy(a => a.Code).ToList(); - Assert.Equal(4, t3.Count); - Assert.Equal("100000", t3[0].Code); - Assert.Equal("110000", t3[1].Code); - Assert.Equal("110100", t3[2].Code); - Assert.Equal("110101", t3[3].Code); - - t3 = fsql.Select().Where(a => a.Name == "北京").AsTreeCte().OrderBy(a => a.Code).ToList(); - Assert.Equal(3, t3.Count); - Assert.Equal("110000", t3[0].Code); - Assert.Equal("110100", t3[1].Code); - Assert.Equal("110101", t3[2].Code); - - var t4 = fsql.Select().Where(a => a.Name == "中国").AsTreeCte(a => a.Name).OrderBy(a => a.Code) - .ToList(a => new { item = a, level = Convert.ToInt32("a.cte_level"), path = "a.cte_path" }); - Assert.Equal(4, t4.Count); - Assert.Equal("100000", t4[0].item.Code); - Assert.Equal("110000", t4[1].item.Code); - Assert.Equal("110100", t4[2].item.Code); - Assert.Equal("110101", t4[3].item.Code); - Assert.Equal("中国", t4[0].path); - Assert.Equal("中国 -> 北京", t4[1].path); - Assert.Equal("中国 -> 北京 -> 北京市", t4[2].path); - Assert.Equal("中国 -> 北京 -> 东城区", t4[3].path); - - t4 = fsql.Select().Where(a => a.Name == "中国").AsTreeCte(a => a.Name + "[" + a.Code + "]").OrderBy(a => a.Code) - .ToList(a => new { item = a, level = Convert.ToInt32("a.cte_level"), path = "a.cte_path" }); - Assert.Equal(4, t4.Count); - Assert.Equal("100000", t4[0].item.Code); - Assert.Equal("110000", t4[1].item.Code); - Assert.Equal("110100", t4[2].item.Code); - Assert.Equal("110101", t4[3].item.Code); - Assert.Equal("中国[100000]", t4[0].path); - Assert.Equal("中国[100000] -> 北京[110000]", t4[1].path); - Assert.Equal("中国[100000] -> 北京[110000] -> 北京市[110100]", t4[2].path); - Assert.Equal("中国[100000] -> 北京[110000] -> 东城区[110101]", t4[3].path); - - var select = fsql.Select() - .Where(a => a.Name == "中国") - .AsTreeCte() - //.OrderBy("a.cte_level desc") //递归层级 - ; - // var list = select.ToList(); //自己调试看查到的数据 - select.ToUpdate().Set(a => a.testint, 855).ExecuteAffrows(); - Assert.Equal(855, fsql.Select() - .Where(a => a.Name == "中国") - .AsTreeCte().Distinct().First(a => a.testint)); - - Assert.Equal(4, select.ToDelete().ExecuteAffrows()); - Assert.False(fsql.Select() - .Where(a => a.Name == "中国") - .AsTreeCte().Any()); - } - - [Table(Name = "D_District")] - public class BaseDistrict - { - [Column(IsPrimary = true, StringLength = 6)] - public string Code { get; set; } - - [Column(StringLength = 20, IsNullable = false)] - public string Name { get; set; } - - [Column(StringLength = 6)] - public virtual string ParentCode { get; set; } - - public int testint { get; set; } - } - [Table(Name = "D_District", DisableSyncStructure = true)] - public class VM_District_Child : BaseDistrict - { - public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; } - - [Navigate(nameof(ParentCode))] - public List Childs { get; set; } - } - [Table(Name = "D_District", DisableSyncStructure = true)] - public class VM_District_Parent : BaseDistrict - { - public override string ParentCode { get => base.ParentCode; set => base.ParentCode = value; } - - [Navigate(nameof(ParentCode))] - public VM_District_Parent Parent { get; set; } - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESUpdateTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESUpdateTest.cs deleted file mode 100644 index 4690b7447..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/KingbaseESUpdateTest.cs +++ /dev/null @@ -1,190 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseES -{ - public class KingbaseESUpdateTest - { - IUpdate update => g.kingbaseES.Update(); - - [Table(Name = "tb_topic")] - class Topic - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int? Clicks { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - - [Fact] - public void Dywhere() - { - Assert.Null(g.kingbaseES.Update().ToSql()); - Assert.Equal("UPDATE \"TB_TOPIC\" SET title='test' \r\nWHERE (\"ID\" IN (1,2))", g.kingbaseES.Update(new[] { 1, 2 }).SetRaw("title='test'").ToSql()); - Assert.Equal("UPDATE \"TB_TOPIC\" SET title='test1' \r\nWHERE (\"ID\" = 1)", g.kingbaseES.Update(new Topic { Id = 1, Title = "test" }).SetRaw("title='test1'").ToSql()); - Assert.Equal("UPDATE \"TB_TOPIC\" SET title='test1' \r\nWHERE (\"ID\" IN (1,2))", g.kingbaseES.Update(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).SetRaw("title='test1'").ToSql()); - Assert.Equal("UPDATE \"TB_TOPIC\" SET title='test1' \r\nWHERE (\"ID\" = 1)", g.kingbaseES.Update(new { id = 1 }).SetRaw("title='test1'").ToSql()); - } - - [Fact] - public void SetSource() - { - var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = NULL, \"TITLE\" = 'newtitle', \"CREATETIME\" = '0001-01-01 00:00:00.000000' WHERE (\"ID\" = 1)", sql); - - var items = new List(); - for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 }); - items[0].Clicks = null; - - sql = update.SetSource(items).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = CASE \"ID\" WHEN 1 THEN NULL WHEN 2 THEN 100 WHEN 3 THEN 200 WHEN 4 THEN 300 WHEN 5 THEN 400 WHEN 6 THEN 500 WHEN 7 THEN 600 WHEN 8 THEN 700 WHEN 9 THEN 800 WHEN 10 THEN 900 END::int4, \"TITLE\" = CASE \"ID\" WHEN 1 THEN 'newtitle0' WHEN 2 THEN 'newtitle1' WHEN 3 THEN 'newtitle2' WHEN 4 THEN 'newtitle3' WHEN 5 THEN 'newtitle4' WHEN 6 THEN 'newtitle5' WHEN 7 THEN 'newtitle6' WHEN 8 THEN 'newtitle7' WHEN 9 THEN 'newtitle8' WHEN 10 THEN 'newtitle9' END::text, \"CREATETIME\" = CASE \"ID\" WHEN 1 THEN '0001-01-01 00:00:00.000000' WHEN 2 THEN '0001-01-01 00:00:00.000000' WHEN 3 THEN '0001-01-01 00:00:00.000000' WHEN 4 THEN '0001-01-01 00:00:00.000000' WHEN 5 THEN '0001-01-01 00:00:00.000000' WHEN 6 THEN '0001-01-01 00:00:00.000000' WHEN 7 THEN '0001-01-01 00:00:00.000000' WHEN 8 THEN '0001-01-01 00:00:00.000000' WHEN 9 THEN '0001-01-01 00:00:00.000000' WHEN 10 THEN '0001-01-01 00:00:00.000000' END::timestamp WHERE (\"ID\" IN (1,2,3,4,5,6,7,8,9,10))", sql); - - sql = update.SetSource(items).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"TITLE\" = CASE \"ID\" WHEN 1 THEN 'newtitle0' WHEN 2 THEN 'newtitle1' WHEN 3 THEN 'newtitle2' WHEN 4 THEN 'newtitle3' WHEN 5 THEN 'newtitle4' WHEN 6 THEN 'newtitle5' WHEN 7 THEN 'newtitle6' WHEN 8 THEN 'newtitle7' WHEN 9 THEN 'newtitle8' WHEN 10 THEN 'newtitle9' END::text WHERE (\"ID\" IN (1,2,3,4,5,6,7,8,9,10))", sql); - - sql = update.SetSource(items).Set(a => a.CreateTime, new DateTime(2020, 1, 1)).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CREATETIME\" = '2020-01-01 00:00:00.000000' WHERE (\"ID\" IN (1,2,3,4,5,6,7,8,9,10))", sql); - - if (g.kingbaseES.Select().Where(a => a.id1 == 1 && a.id2 == 7).Any() == false) - g.kingbaseES.Insert(new ts_source_mpk { id1 = 1, id2 = 7 }).ExecuteAffrows(); - if (g.kingbaseES.Select().Where(a => a.id1 == 1 && a.id2 == 8).Any() == false) - g.kingbaseES.Insert(new ts_source_mpk { id1 = 1, id2 = 8 }).ExecuteAffrows(); - - sql = g.kingbaseES.Update().SetSource(new[] { - new ts_source_mpk { id1 = 1, id2 = 7, xx = "a1" }, - new ts_source_mpk { id1 = 1, id2 = 8, xx = "b122" } - }).NoneParameter().ToSql().Replace("\r\n", ""); - g.kingbaseES.Update().SetSource(new[] { - new ts_source_mpk { id1 = 1, id2 = 7, xx = "a1" }, - new ts_source_mpk { id1 = 1, id2 = 8, xx = "b122" } - }).NoneParameter().ExecuteAffrows(); - var testlist = g.kingbaseES.Select().ToList(); - } - public class ts_source_mpk - { - [Column(IsPrimary = true)] - public int id1 { get; set; } - [Column(IsPrimary = true)] - public int id2 { get; set; } - public string xx { get; set; } - } - [Fact] - public void SetSourceIgnore() - { - Assert.Equal("UPDATE \"TSSI01\" SET \"TINT\" = 10 WHERE (\"ID\" = '00000000-0000-0000-0000-000000000000')", - g.kingbaseES.Update().NoneParameter() - .SetSourceIgnore(new tssi01 { id = Guid.Empty, tint = 10 }, col => col == null).ToSql().Replace("\r\n", "")); - } - public class tssi01 - { - [Column(CanUpdate = false)] - public Guid id { get; set; } - public int tint { get; set; } - public string title { get; set; } - } - [Fact] - public void IgnoreColumns() - { - var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"TITLE\" = 'newtitle' WHERE (\"ID\" = 1)", sql); - } - [Fact] - public void UpdateColumns() - { - var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).UpdateColumns(a => a.Title).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"TITLE\" = 'newtitle' WHERE (\"ID\" = 1)", sql); - } - [Fact] - public void Set() - { - var sql = update.Where(a => a.Id == 1).Set(a => a.Title, "newtitle").ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"TITLE\" = 'newtitle' WHERE (\"ID\" = 1)", sql); - - sql = update.Where(a => a.Id == 1).Set(a => a.Title, "newtitle").Set(a => a.CreateTime, new DateTime(2020, 1, 1)).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"TITLE\" = 'newtitle', \"CREATETIME\" = '2020-01-01 00:00:00.000000' WHERE (\"ID\" = 1)", sql); - - sql = update.Set(a => a.Clicks * 10 / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = coalesce(\"CLICKS\", 0) * 10 / 1 WHERE (\"ID\" = 1)", sql); - - sql = update.Set(a => a.Id - 10).Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"ID\" = (\"ID\" - 10) WHERE (\"ID\" = 1)", sql); - - int incrv = 10; - sql = update.Set(a => a.Clicks * incrv / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = coalesce(\"CLICKS\", 0) * 10 / 1 WHERE (\"ID\" = 1)", sql); - - sql = update.Set(a => a.Id - incrv).Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"ID\" = (\"ID\" - 10) WHERE (\"ID\" = 1)", sql); - - sql = update.Set(a => a.Clicks == a.Clicks * 10 / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = \"CLICKS\" * 10 / 1 WHERE (\"ID\" = 1)", sql); - - var dt2000 = DateTime.Parse("2000-01-01"); - sql = update.Set(a => a.Clicks == (a.CreateTime > dt2000 ? 1 : 2)).Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = case when \"CREATETIME\" > '2000-01-01 00:00:00.000000' then 1 else 2 end WHERE (\"ID\" = 1)", sql); - - sql = update.Set(a => a.Id == 10).Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"ID\" = 10 WHERE (\"ID\" = 1)", sql); - - sql = update.Set(a => a.Clicks == null).Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = NULL WHERE (\"ID\" = 1)", sql); - } - [Fact] - public void SetRaw() - { - var sql = update.Where(a => a.Id == 1).SetRaw("clicks = clicks + ?", new { incrClick = 1 }).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET clicks = clicks + ? WHERE (\"ID\" = 1)", sql); - } - [Fact] - public void SetDto() - { - var sql = update.SetDto(new { clicks = 1, title = "xxx" }).Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = 1, \"TITLE\" = 'xxx' WHERE (\"ID\" = 1)", sql); - - sql = update.SetDto(new Dictionary { ["clicks"] = 1, ["title"] = "xxx" }).Where(a => a.Id == 1).ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET \"CLICKS\" = 1, \"TITLE\" = 'xxx' WHERE (\"ID\" = 1)", sql); - } - [Fact] - public void Where() - { - var sql = update.Where(a => a.Id == 1).SetRaw("title='newtitle'").ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET title='newtitle' WHERE (\"ID\" = 1)", sql); - - sql = update.Where("id = ?", new { id = 1 }).SetRaw("title='newtitle'").ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET title='newtitle' WHERE (id = ?)", sql); - - var item = new Topic { Id = 1, Title = "newtitle" }; - sql = update.Where(item).SetRaw("title='newtitle'").ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET title='newtitle' WHERE (\"ID\" = 1)", sql); - - var items = new List(); - for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 }); - sql = update.Where(items).SetRaw("title='newtitle'").ToSql().Replace("\r\n", ""); - Assert.Equal("UPDATE \"TB_TOPIC\" SET title='newtitle' WHERE (\"ID\" IN (1,2,3,4,5,6,7,8,9,10))", sql); - } - [Fact] - public void ExecuteAffrows() - { - - } - [Fact] - public void ExecuteUpdated() - { - - } - - [Fact] - public void AsTable() - { - Assert.Null(g.kingbaseES.Update().ToSql()); - Assert.Equal("UPDATE \"TB_TOPICASTABLE\" SET title='test' \r\nWHERE (\"ID\" IN (1,2))", g.kingbaseES.Update(new[] { 1, 2 }).SetRaw("title='test'").AsTable(a => "tb_topicAsTable").ToSql()); - Assert.Equal("UPDATE \"TB_TOPICASTABLE\" SET title='test1' \r\nWHERE (\"ID\" = 1)", g.kingbaseES.Update(new Topic { Id = 1, Title = "test" }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql()); - Assert.Equal("UPDATE \"TB_TOPICASTABLE\" SET title='test1' \r\nWHERE (\"ID\" IN (1,2))", g.kingbaseES.Update(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql()); - Assert.Equal("UPDATE \"TB_TOPICASTABLE\" SET title='test1' \r\nWHERE (\"ID\" = 1)", g.kingbaseES.Update(new { id = 1 }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql()); - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/OnConflictDoUpdateTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/OnConflictDoUpdateTest.cs deleted file mode 100644 index 608f2acc4..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/Curd/OnConflictDoUpdateTest.cs +++ /dev/null @@ -1,158 +0,0 @@ -using FreeSql.DataAnnotations; -using FreeSql.Odbc.KingbaseES; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseES -{ - public class OnConflictDoUpdateTest - { - class TestOnConflictDoUpdateInfo - { - [Column(IsIdentity = true)] - public int id { get; set; } - public string title { get; set; } - public DateTime? time { get; set; } - } - - [Fact] - public void ExecuteAffrows() - { - g.kingbaseES.Delete(new[] { 100, 101, 102 }).ExecuteAffrows(); - var odku1 = new OdbcKingbaseESOnConflictDoUpdate(g.kingbaseES.Insert(new TestOnConflictDoUpdateInfo { id = 100, title = "title-100", time = DateTime.Parse("2000-01-01") }).NoneParameter().InsertIdentity()); - Assert.Equal(@"INSERT INTO ""TESTONCONFLICTDOUPDATEINFO""(""ID"", ""TITLE"", ""TIME"") VALUES(100, 'title-100', '2000-01-01 00:00:00.000000') -ON CONFLICT(""ID"") DO UPDATE SET -""TITLE"" = EXCLUDED.""TITLE"", -""TIME"" = EXCLUDED.""TIME""", odku1.ToSql()); - Assert.Equal(1, odku1.ExecuteAffrows()); - - var odku2 = new OdbcKingbaseESOnConflictDoUpdate(g.kingbaseES.Insert(new[] { - new TestOnConflictDoUpdateInfo { id = 100, title = "title-100", time = DateTime.Parse("2000-01-01") }, - new TestOnConflictDoUpdateInfo { id = 101, title = "title-101", time = DateTime.Parse("2000-01-01") }, - new TestOnConflictDoUpdateInfo { id = 102, title = "title-102", time = DateTime.Parse("2000-01-01") } - }).NoneParameter().InsertIdentity()); - Assert.Equal(@"INSERT INTO ""TESTONCONFLICTDOUPDATEINFO""(""ID"", ""TITLE"", ""TIME"") VALUES(100, 'title-100', '2000-01-01 00:00:00.000000'), (101, 'title-101', '2000-01-01 00:00:00.000000'), (102, 'title-102', '2000-01-01 00:00:00.000000') -ON CONFLICT(""ID"") DO UPDATE SET -""TITLE"" = EXCLUDED.""TITLE"", -""TIME"" = EXCLUDED.""TIME""", odku2.ToSql()); - odku2.ExecuteAffrows(); - } - - [Fact] - public void IgnoreColumns() - { - g.kingbaseES.Delete(new[] { 200, 201, 202 }).ExecuteAffrows(); - var odku1 = new OdbcKingbaseESOnConflictDoUpdate(g.kingbaseES.Insert(new TestOnConflictDoUpdateInfo { id = 200, title = "title-200", time = DateTime.Parse("2000-01-01") }).IgnoreColumns(a => a.time).NoneParameter().InsertIdentity()); - Assert.Equal(@"INSERT INTO ""TESTONCONFLICTDOUPDATEINFO""(""ID"", ""TITLE"") VALUES(200, 'title-200') -ON CONFLICT(""ID"") DO UPDATE SET -""TITLE"" = EXCLUDED.""TITLE"", -""TIME"" = '2000-01-01 00:00:00.000000'", odku1.ToSql()); - Assert.Equal(1, odku1.ExecuteAffrows()); - - var odku2 = new OdbcKingbaseESOnConflictDoUpdate(g.kingbaseES.Insert(new[] { - new TestOnConflictDoUpdateInfo { id = 200, title = "title-200", time = DateTime.Parse("2000-01-01") }, - new TestOnConflictDoUpdateInfo { id = 201, title = "title-201", time = DateTime.Parse("2000-01-01") }, - new TestOnConflictDoUpdateInfo { id = 202, title = "title-202", time = DateTime.Parse("2000-01-01") } - }).IgnoreColumns(a => a.time).NoneParameter().InsertIdentity()); - Assert.Equal(@"INSERT INTO ""TESTONCONFLICTDOUPDATEINFO""(""ID"", ""TITLE"") VALUES(200, 'title-200'), (201, 'title-201'), (202, 'title-202') -ON CONFLICT(""ID"") DO UPDATE SET -""TITLE"" = EXCLUDED.""TITLE"", -""TIME"" = CASE EXCLUDED.""ID"" -WHEN 200 THEN '2000-01-01 00:00:00.000000' -WHEN 201 THEN '2000-01-01 00:00:00.000000' -WHEN 202 THEN '2000-01-01 00:00:00.000000' END::timestamp", odku2.ToSql()); - odku2.ExecuteAffrows(); - - - g.kingbaseES.Delete(new[] { 200, 201, 202 }).ExecuteAffrows(); - odku1 = new OdbcKingbaseESOnConflictDoUpdate(g.kingbaseES.Insert(new TestOnConflictDoUpdateInfo { id = 200, title = "title-200", time = DateTime.Parse("2000-01-01") }).IgnoreColumns(a => a.time).NoneParameter().InsertIdentity()).IgnoreColumns(a => a.title); - Assert.Equal(@"INSERT INTO ""TESTONCONFLICTDOUPDATEINFO""(""ID"", ""TITLE"") VALUES(200, 'title-200') -ON CONFLICT(""ID"") DO UPDATE SET -""TIME"" = '2000-01-01 00:00:00.000000'", odku1.ToSql()); - Assert.Equal(1, odku1.ExecuteAffrows()); - - odku2 = new OdbcKingbaseESOnConflictDoUpdate(g.kingbaseES.Insert(new[] { - new TestOnConflictDoUpdateInfo { id = 200, title = "title-200", time = DateTime.Parse("2000-01-01") }, - new TestOnConflictDoUpdateInfo { id = 201, title = "title-201", time = DateTime.Parse("2000-01-01") }, - new TestOnConflictDoUpdateInfo { id = 202, title = "title-202", time = DateTime.Parse("2000-01-01") } - }).IgnoreColumns(a => a.time).NoneParameter().InsertIdentity()).IgnoreColumns(a => a.title); - Assert.Equal(@"INSERT INTO ""TESTONCONFLICTDOUPDATEINFO""(""ID"", ""TITLE"") VALUES(200, 'title-200'), (201, 'title-201'), (202, 'title-202') -ON CONFLICT(""ID"") DO UPDATE SET -""TIME"" = CASE EXCLUDED.""ID"" -WHEN 200 THEN '2000-01-01 00:00:00.000000' -WHEN 201 THEN '2000-01-01 00:00:00.000000' -WHEN 202 THEN '2000-01-01 00:00:00.000000' END::timestamp", odku2.ToSql()); - odku2.ExecuteAffrows(); - } - - [Fact] - public void UpdateColumns() - { - g.kingbaseES.Delete(new[] { 300, 301, 302 }).ExecuteAffrows(); - var odku1 = new OdbcKingbaseESOnConflictDoUpdate(g.kingbaseES.Insert(new TestOnConflictDoUpdateInfo { id = 300, title = "title-300", time = DateTime.Parse("2000-01-01") }).InsertColumns(a => a.title).NoneParameter().InsertIdentity()); - Assert.Equal(@"INSERT INTO ""TESTONCONFLICTDOUPDATEINFO""(""ID"", ""TITLE"") VALUES(300, 'title-300') -ON CONFLICT(""ID"") DO UPDATE SET -""TITLE"" = EXCLUDED.""TITLE"", -""TIME"" = '2000-01-01 00:00:00.000000'", odku1.ToSql()); - Assert.Equal(1, odku1.ExecuteAffrows()); - - var odku2 = new OdbcKingbaseESOnConflictDoUpdate(g.kingbaseES.Insert(new[] { - new TestOnConflictDoUpdateInfo { id = 300, title = "title-300", time = DateTime.Parse("2000-01-01") }, - new TestOnConflictDoUpdateInfo { id = 301, title = "title-301", time = DateTime.Parse("2000-01-01") }, - new TestOnConflictDoUpdateInfo { id = 302, title = "title-302", time = DateTime.Parse("2000-01-01") } - }).InsertColumns(a => a.title).NoneParameter().InsertIdentity()); - Assert.Equal(@"INSERT INTO ""TESTONCONFLICTDOUPDATEINFO""(""ID"", ""TITLE"") VALUES(300, 'title-300'), (301, 'title-301'), (302, 'title-302') -ON CONFLICT(""ID"") DO UPDATE SET -""TITLE"" = EXCLUDED.""TITLE"", -""TIME"" = CASE EXCLUDED.""ID"" -WHEN 300 THEN '2000-01-01 00:00:00.000000' -WHEN 301 THEN '2000-01-01 00:00:00.000000' -WHEN 302 THEN '2000-01-01 00:00:00.000000' END::timestamp", odku2.ToSql()); - odku2.ExecuteAffrows(); - - - g.kingbaseES.Delete(new[] { 300, 301, 302 }).ExecuteAffrows(); - odku1 = new OdbcKingbaseESOnConflictDoUpdate(g.kingbaseES.Insert(new TestOnConflictDoUpdateInfo { id = 300, title = "title-300", time = DateTime.Parse("2000-01-01") }).InsertColumns(a => a.title).NoneParameter().InsertIdentity()).UpdateColumns(a => a.time); - Assert.Equal(@"INSERT INTO ""TESTONCONFLICTDOUPDATEINFO""(""ID"", ""TITLE"") VALUES(300, 'title-300') -ON CONFLICT(""ID"") DO UPDATE SET -""TIME"" = '2000-01-01 00:00:00.000000'", odku1.ToSql()); - Assert.Equal(1, odku1.ExecuteAffrows()); - - odku2 = new OdbcKingbaseESOnConflictDoUpdate(g.kingbaseES.Insert(new[] { - new TestOnConflictDoUpdateInfo { id = 300, title = "title-300", time = DateTime.Parse("2000-01-01") }, - new TestOnConflictDoUpdateInfo { id = 301, title = "title-301", time = DateTime.Parse("2000-01-01") }, - new TestOnConflictDoUpdateInfo { id = 302, title = "title-302", time = DateTime.Parse("2000-01-01") } - }).InsertColumns(a => a.title).NoneParameter().InsertIdentity()).UpdateColumns(a => a.time); - Assert.Equal(@"INSERT INTO ""TESTONCONFLICTDOUPDATEINFO""(""ID"", ""TITLE"") VALUES(300, 'title-300'), (301, 'title-301'), (302, 'title-302') -ON CONFLICT(""ID"") DO UPDATE SET -""TIME"" = CASE EXCLUDED.""ID"" -WHEN 300 THEN '2000-01-01 00:00:00.000000' -WHEN 301 THEN '2000-01-01 00:00:00.000000' -WHEN 302 THEN '2000-01-01 00:00:00.000000' END::timestamp", odku2.ToSql()); - odku2.ExecuteAffrows(); - } - - [Fact] - public void Set() - { - g.kingbaseES.Delete(new[] { 400, 401, 402 }).ExecuteAffrows(); - var odku1 = new OdbcKingbaseESOnConflictDoUpdate(g.kingbaseES.Insert(new TestOnConflictDoUpdateInfo { id = 400, title = "title-400", time = DateTime.Parse("2000-01-01") }).NoneParameter().InsertIdentity()).Set(a => a.time, DateTime.Parse("2020-1-1")); - Assert.Equal(@"INSERT INTO ""TESTONCONFLICTDOUPDATEINFO""(""ID"", ""TITLE"", ""TIME"") VALUES(400, 'title-400', '2000-01-01 00:00:00.000000') -ON CONFLICT(""ID"") DO UPDATE SET -""TIME"" = '2020-01-01 00:00:00.000000'", odku1.ToSql()); - Assert.Equal(1, odku1.ExecuteAffrows()); - - var odku2 = new OdbcKingbaseESOnConflictDoUpdate(g.kingbaseES.Insert(new[] { - new TestOnConflictDoUpdateInfo { id = 400, title = "title-400", time = DateTime.Parse("2000-01-01") }, - new TestOnConflictDoUpdateInfo { id = 401, title = "title-401", time = DateTime.Parse("2000-01-01") }, - new TestOnConflictDoUpdateInfo { id = 402, title = "title-402", time = DateTime.Parse("2000-01-01") } - }).NoneParameter().InsertIdentity()).Set(a => a.time, DateTime.Parse("2020-1-1")); - Assert.Equal(@"INSERT INTO ""TESTONCONFLICTDOUPDATEINFO""(""ID"", ""TITLE"", ""TIME"") VALUES(400, 'title-400', '2000-01-01 00:00:00.000000'), (401, 'title-401', '2000-01-01 00:00:00.000000'), (402, 'title-402', '2000-01-01 00:00:00.000000') -ON CONFLICT(""ID"") DO UPDATE SET -""TIME"" = '2020-01-01 00:00:00.000000'", odku2.ToSql()); - odku2.ExecuteAffrows(); - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESAdo/KingbaseESAdoTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESAdo/KingbaseESAdoTest.cs deleted file mode 100644 index 6b382d2f0..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESAdo/KingbaseESAdoTest.cs +++ /dev/null @@ -1,71 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseES -{ - public class KingbaseESAdoTest - { - [Fact] - public void Pool() - { - var t1 = g.kingbaseES.Ado.MasterPool.StatisticsFullily; - } - - [Fact] - public void SlavePools() - { - var t2 = g.kingbaseES.Ado.SlavePools.Count; - } - - [Fact] - public void ExecuteTest() - { - Assert.True(g.kingbaseES.Ado.ExecuteConnectTest()); - } - [Fact] - public void ExecuteReader() - { - - } - [Fact] - public void ExecuteArray() - { - - } - [Fact] - public void ExecuteNonQuery() - { - - } - [Fact] - public void ExecuteScalar() - { - - } - - [Fact] - public void Query() - { - - var t3 = g.kingbaseES.Ado.Query("select * from \"TB_TOPIC\""); - - var t4 = g.kingbaseES.Ado.Query<(int, string, string)>("select * from \"TB_TOPIC\""); - - var t5 = g.kingbaseES.Ado.Query("select * from \"TB_TOPIC\""); - } - - [Fact] - public void QueryMultipline() - { - //var t3 = g.kingbaseES.Ado.Query("select * from \"TB_TOPIC\"; select * from \"TB_TOPIC\"; select * from \"TB_TOPIC\""); - } - - class xxx - { - public int Id { get; set; } - public string Path { get; set; } - public string Title2 { get; set; } - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESAopTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESAopTest.cs deleted file mode 100644 index 43d22c41a..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESAopTest.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Text; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseES -{ - public class KingbaseESAopTest - { - - class TestAuditValue - { - public Guid id { get; set; } - [Now] - public DateTime createtime { get; set; } - } - class NowAttribute: Attribute { } - - [Fact] - public void AuditValue() - { - var date = DateTime.Now.Date; - var item = new TestAuditValue(); - - EventHandler audit = (s, e) => - { - if (e.Property.GetCustomAttribute(false) != null) - e.Value = DateTime.Now.Date; - }; - g.kingbaseES.Aop.AuditValue += audit; - - g.kingbaseES.Insert(item).ExecuteAffrows(); - - g.kingbaseES.Aop.AuditValue -= audit; - - Assert.Equal(item.createtime, date); - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESCodeFirstTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESCodeFirstTest.cs deleted file mode 100644 index 2b6f2a611..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESCodeFirstTest.cs +++ /dev/null @@ -1,334 +0,0 @@ -using FreeSql.DataAnnotations; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseES -{ - public class KingbaseESCodeFirstTest - { - [Fact] - public void StringLength() - { - var dll = g.kingbaseES.CodeFirst.GetComparisonDDLStatements(); - g.kingbaseES.CodeFirst.SyncStructure(); - } - class TS_SLTB - { - public Guid Id { get; set; } - [Column(StringLength = 50)] - public string Title { get; set; } - - [Column(IsNullable = false, StringLength = 50)] - public string TitleSub { get; set; } - } - - [Fact] - public void ֱ_ֶ() - { - var sql = g.kingbaseES.CodeFirst.GetComparisonDDLStatements<ֱ>(); - g.kingbaseES.CodeFirst.SyncStructure<ֱ>(); - - var item = new ֱ - { - = "Ա", - ʱ = DateTime.Now - }; - Assert.Equal(1, g.kingbaseES.Insert<ֱ>().AppendData(item).ExecuteAffrows()); - Assert.NotEqual(Guid.Empty, item.); - var item2 = g.kingbaseES.Select<ֱ>().Where(a => a. == item.).First(); - Assert.NotNull(item2); - Assert.Equal(item., item2.); - Assert.Equal(item., item2.); - - item. = "Ա"; - Assert.Equal(1, g.kingbaseES.Update<ֱ>().SetSource(item).ExecuteAffrows()); - item2 = g.kingbaseES.Select<ֱ>().Where(a => a. == item.).First(); - Assert.NotNull(item2); - Assert.Equal(item., item2.); - Assert.Equal(item., item2.); - - item. = "Ա_repo"; - var repo = g.kingbaseES.GetRepository<ֱ>(); - Assert.Equal(1, repo.Update(item)); - item2 = g.kingbaseES.Select<ֱ>().Where(a => a. == item.).First(); - Assert.NotNull(item2); - Assert.Equal(item., item2.); - Assert.Equal(item., item2.); - - item. = "Ա_repo22"; - Assert.Equal(1, repo.Update(item)); - item2 = g.kingbaseES.Select<ֱ>().Where(a => a. == item.).First(); - Assert.NotNull(item2); - Assert.Equal(item., item2.); - Assert.Equal(item., item2.); - } - [Table(Name = "123ֱ")] - class ֱ - { - [Column(IsPrimary = true, Name = "123")] - public Guid { get; set; } - - [Column(Name = "123")] - public string { get; set; } - - [Column(Name = "123ʱ")] - public DateTime ʱ { get; set; } - } - - [Fact] - public void ı_ֶ() - { - var sql = g.kingbaseES.CodeFirst.GetComparisonDDLStatements<ı>(); - g.kingbaseES.CodeFirst.SyncStructure<ı>(); - - var item = new ı - { - = "Ա", - ʱ = DateTime.Now - }; - Assert.Equal(1, g.kingbaseES.Insert<ı>().AppendData(item).ExecuteAffrows()); - Assert.NotEqual(Guid.Empty, item.); - var item2 = g.kingbaseES.Select<ı>().Where(a => a. == item.).First(); - Assert.NotNull(item2); - Assert.Equal(item., item2.); - Assert.Equal(item., item2.); - - item. = "Ա"; - Assert.Equal(1, g.kingbaseES.Update<ı>().SetSource(item).ExecuteAffrows()); - item2 = g.kingbaseES.Select<ı>().Where(a => a. == item.).First(); - Assert.NotNull(item2); - Assert.Equal(item., item2.); - Assert.Equal(item., item2.); - - item. = "Ա_repo"; - var repo = g.kingbaseES.GetRepository<ı>(); - Assert.Equal(1, repo.Update(item)); - item2 = g.kingbaseES.Select<ı>().Where(a => a. == item.).First(); - Assert.NotNull(item2); - Assert.Equal(item., item2.); - Assert.Equal(item., item2.); - - item. = "Ա_repo22"; - Assert.Equal(1, repo.Update(item)); - item2 = g.kingbaseES.Select<ı>().Where(a => a. == item.).First(); - Assert.NotNull(item2); - Assert.Equal(item., item2.); - Assert.Equal(item., item2.); - } - class ı - { - [Column(IsPrimary = true)] - public Guid { get; set; } - - public string { get; set; } - - public DateTime ʱ { get; set; } - } - - [Fact] - public void AddUniques() - { - var sql = g.kingbaseES.CodeFirst.GetComparisonDDLStatements(); - g.kingbaseES.CodeFirst.SyncStructure(); - g.kingbaseES.CodeFirst.SyncStructure(typeof(AddUniquesInfo), "AddUniquesInfo1"); - } - [Table(Name = "AddUniquesInfo", OldName = "AddUniquesInfo2")] - [Index("{tablename}_uk_phone", "phone", true)] - [Index("{tablename}_uk_group_index", "group,index", true)] - [Index("{tablename}_uk_group_index22", "group, index22", true)] - class AddUniquesInfo - { - public Guid id { get; set; } - public string phone { get; set; } - - public string group { get; set; } - public int index { get; set; } - public string index22 { get; set; } - } - [Fact] - public void AddField() - { - var sql = g.kingbaseES.CodeFirst.GetComparisonDDLStatements(); - - var id = g.kingbaseES.Insert().AppendData(new TopicAddField { }).ExecuteIdentity(); - - //var inserted = g.kingbaseES.Insert().AppendData(new TopicAddField { }).ExecuteInserted(); - } - - [Table(Name = "TopicAddField", OldName = "xxxtb.TopicAddField")] - public class TopicAddField - { - [Column(IsIdentity = true)] - public int Id { get; set; } - - public string name { get; set; } - - [Column(DbType = "varchar2(200) not null", OldName = "title")] - public string title2 { get; set; } = "10"; - - [Column(IsIgnore = true)] - public DateTime ct { get; set; } = DateTime.Now; - } - - [Fact] - public void GetComparisonDDLStatements() - { - var sql = g.kingbaseES.CodeFirst.GetComparisonDDLStatements(); - Assert.True(string.IsNullOrEmpty(sql)); //κ - //sql = g.kingbaseES.CodeFirst.GetComparisonDDLStatements(); - } - - IInsert insert => g.kingbaseES.Insert(); - ISelect select => g.kingbaseES.Select(); - - [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, - BoolNullable = true, - Byte = 255, - ByteNullable = 127, - Bytes = Encoding.UTF8.GetBytes("й"), - DateTime = DateTime.Now, - DateTimeNullable = DateTime.Now.AddHours(-1), - Decimal = 99.99M, - DecimalNullable = 99.98M, - Double = 999.99, - DoubleNullable = 999.98, - Enum1 = TableAllTypeEnumType1.e5, - Enum1Nullable = TableAllTypeEnumType1.e3, - Enum2 = TableAllTypeEnumType2.f2, - Enum2Nullable = TableAllTypeEnumType2.f3, - Float = 19.99F, - FloatNullable = 19.98F, - Guid = Guid.NewGuid(), - GuidNullable = Guid.NewGuid(), - Int = int.MaxValue, - IntNullable = int.MinValue, - SByte = 100, - SByteNullable = 99, - Short = short.MaxValue, - ShortNullable = short.MinValue, - String = "йstring'\\?!@#$%^&*()_+{}}{~?><<>", - Char = 'X', - TimeSpan = TimeSpan.FromSeconds(999), - TimeSpanNullable = TimeSpan.FromSeconds(60), - UInt = uint.MaxValue, - UIntNullable = uint.MinValue, - ULong = ulong.MaxValue, - ULongNullable = ulong.MinValue, - UShort = ushort.MaxValue, - UShortNullable = ushort.MinValue, - testFielLongNullable = long.MinValue - }; - var sqlPar = insert.AppendData(item2).ToSql(); - var sqlText = insert.AppendData(item2).NoneParameter().ToSql(); - var item3NP = insert.AppendData(item2).NoneParameter().ExecuteIdentity(); - - item2.Id = (int)insert.AppendData(item2).ExecuteIdentity(); - var newitem21 = select.Where(a => a.Id == item2.Id).First(a => new - { - a.Id, - a.id2, - a.SByte, - a.Short, - a.Int, - a.Long, - a.Byte, - a.UShort, - a.UInt, - a.ULong, - a.Double, - a.Float, - a.Decimal, - a.TimeSpan, - a.DateTimeOffSet, - a.Bytes, - a.String, - a.Char, - a.Guid - }); - var newitem22 = select.Where(a => a.Id == item2.Id).First(a => new - { - a.Id, a.id2, a.SByte, a.Short, a.Int, a.Long, a.Byte, a.UShort, a.UInt, a.ULong, a.Double, a.Float, a.Decimal, a.TimeSpan, a.DateTime, a.DateTimeOffSet, a.Bytes, a.String, a.Char, a.Guid - }); - - var newitem2 = select.Where(a => a.Id == item2.Id).ToOne(); - Assert.Equal(item2.String, newitem2.String); - Assert.Equal(item2.Char, newitem2.Char); - - item2.Id = (int)insert.NoneParameter().AppendData(item2).ExecuteIdentity(); - newitem2 = select.Where(a => a.Id == item2.Id).ToOne(); - Assert.Equal(item2.String, newitem2.String); - Assert.Equal(item2.Char, newitem2.Char); - - var items = select.ToList(); - var itemstb = select.ToDataTable(); - } - - [Table(Name = "tb_alltype")] - class TableAllType - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - - public string id2 { get; set; } = "id2=10"; - - public bool Bool { get; set; } - public sbyte SByte { get; set; } - public short Short { get; set; } - public int Int { get; set; } - public long Long { get; set; } - public byte Byte { get; set; } - public ushort UShort { get; set; } - public uint UInt { get; set; } - public ulong ULong { get; set; } - public double Double { get; set; } - public float Float { get; set; } - public decimal Decimal { get; set; } - public TimeSpan TimeSpan { get; set; } - public DateTime DateTime { get; set; } - public DateTime DateTimeOffSet { get; set; } - public byte[] Bytes { get; set; } - public string String { get; set; } - public char Char { get; set; } - public Guid Guid { get; set; } - - public bool? BoolNullable { get; set; } - public sbyte? SByteNullable { get; set; } - public short? ShortNullable { get; set; } - public int? IntNullable { get; set; } - public long? testFielLongNullable { get; set; } - public byte? ByteNullable { get; set; } - public ushort? UShortNullable { get; set; } - public uint? UIntNullable { get; set; } - public ulong? ULongNullable { get; set; } - public double? DoubleNullable { get; set; } - public float? FloatNullable { get; set; } - public decimal? DecimalNullable { get; set; } - public TimeSpan? TimeSpanNullable { get; set; } - public DateTime? DateTimeNullable { get; set; } - public DateTime? DateTimeOffSetNullable { get; set; } - public Guid? GuidNullable { get; set; } - - public TableAllTypeEnumType1 Enum1 { get; set; } - public TableAllTypeEnumType1? Enum1Nullable { get; set; } - public TableAllTypeEnumType2 Enum2 { get; set; } - public TableAllTypeEnumType2? Enum2Nullable { get; set; } - } - - public enum TableAllTypeEnumType1 { e1, e2, e3, e5 } - [Flags] public enum TableAllTypeEnumType2 { f1, f2, f3 } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESDbFirstTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESDbFirstTest.cs deleted file mode 100644 index cebd3ac13..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESDbFirstTest.cs +++ /dev/null @@ -1,64 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseES -{ - public class KingbaseESDbFirstTest - { - [Fact] - public void GetDatabases() - { - var t1 = g.kingbaseES.DbFirst.GetDatabases(); - } - - [Fact] - public void GetTablesByDatabase() - { - var t2 = g.kingbaseES.DbFirst.GetTablesByDatabase(); - Assert.True(t2.Count > 0); - } - - [Fact] - public void GetTableByName() - { - var fsql = g.kingbaseES; - var t1 = fsql.DbFirst.GetTableByName("tb_alltype"); - var t2 = fsql.DbFirst.GetTableByName("public.tb_alltype"); - Assert.NotNull(t1); - Assert.NotNull(t2); - Assert.True(t1.Columns.Count > 0); - Assert.True(t2.Columns.Count > 0); - Assert.Equal(t1.Columns.Count, t2.Columns.Count); - var t3 = fsql.DbFirst.GetTableByName("notexists_tb"); - Assert.Null(t3); - } - - [Fact] - public void ExistsTable() - { - var fsql = g.kingbaseES; - Assert.False(fsql.DbFirst.ExistsTable("test_existstb01")); - Assert.False(fsql.DbFirst.ExistsTable("public.test_existstb01")); - Assert.False(fsql.DbFirst.ExistsTable("test_existstb01", false)); - Assert.False(fsql.DbFirst.ExistsTable("public.test_existstb01", false)); - fsql.CodeFirst.SyncStructure(typeof(test_existstb01)); - Assert.True(fsql.DbFirst.ExistsTable("test_existstb01")); - Assert.True(fsql.DbFirst.ExistsTable("public.test_existstb01")); - Assert.False(fsql.DbFirst.ExistsTable("Test_existstb01", false)); - Assert.False(fsql.DbFirst.ExistsTable("public.Test_existstb01", false)); - fsql.Ado.ExecuteNonQuery("drop table test_existstb01"); - - Assert.False(fsql.DbFirst.ExistsTable("tbexts.test_existstb01")); - Assert.False(fsql.DbFirst.ExistsTable("tbexts.test_existstb01", false)); - fsql.CodeFirst.SyncStructure(typeof(test_existstb01), "tbexts.test_existstb01"); - Assert.True(fsql.DbFirst.ExistsTable("tbexts.test_existstb01")); - Assert.False(fsql.DbFirst.ExistsTable("tbexts.Test_existstb01", false)); - fsql.Ado.ExecuteNonQuery("drop table \"TBEXTS\".test_existstb01"); - } - class test_existstb01 - { - public Guid id { get; set; } - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/ConvertTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/ConvertTest.cs deleted file mode 100644 index b14da23a7..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/ConvertTest.cs +++ /dev/null @@ -1,169 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseESExpression -{ - public class ConvertTest - { - - ISelect select => g.kingbaseES.Select(); - - [Table(Name = "tb_topic")] - class Topic - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int Clicks { get; set; } - public int TypeGuid { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - class TestTypeInfo - { - public int Guid { get; set; } - public int ParentId { get; set; } - public TestTypeParentInfo Parent { get; set; } - public string Name { get; set; } - } - class TestTypeParentInfo - { - public int Id { get; set; } - public string Name { get; set; } - - public List Types { get; set; } - } - - [Fact] - public void ToBoolean() - { - var data = new List(); - //data.Add(select.Where(a => (Convert.ToBoolean(a.Clicks) ? 1 : 0) > 0).ToList()); - //data.Add(select.Where(a => (bool.Parse(a.Clicks.ToString()) ? 1 : 0) > 0).ToList()); - } - [Fact] - public void ToByte() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToByte(a.Clicks % 255) > 0).ToList()); - data.Add(select.Where(a => byte.Parse((a.Clicks % 255).ToString()) > 0).ToList()); - } - [Fact] - public void ToChar() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToChar(a.Clicks) == '1').ToList()); - data.Add(select.Where(a => char.Parse(a.Clicks.ToString()) == '1').ToList()); - } - [Fact] - public void ToDateTime() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToDateTime(a.CreateTime.ToString()).Year > 0).ToList()); - data.Add(select.Where(a => DateTime.Parse(a.CreateTime.ToString()).Year > 0).ToList()); - } - [Fact] - public void ToDecimal() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToDecimal(a.Clicks) > 0).ToList()); - data.Add(select.Where(a => decimal.Parse(a.Clicks.ToString()) > 0).ToList()); - } - [Fact] - public void ToDouble() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToDouble(a.Clicks) > 0).ToList()); - data.Add(select.Where(a => double.Parse(a.Clicks.ToString()) > 0).ToList()); - } - [Fact] - public void ToInt16() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToInt16(a.Clicks) > 0).ToList()); - data.Add(select.Where(a => short.Parse(a.Clicks.ToString()) > 0).ToList()); - } - [Fact] - public void ToInt32() - { - var data = new List(); - data.Add(select.Where(a => (int)a.Clicks > 0).ToList()); - data.Add(select.Where(a => Convert.ToInt32(a.Clicks) > 0).ToList()); - data.Add(select.Where(a => int.Parse(a.Clicks.ToString()) > 0).ToList()); - } - [Fact] - public void ToInt64() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToInt64(a.Clicks) > 0).ToList()); - data.Add(select.Where(a => long.Parse(a.Clicks.ToString()) > 0).ToList()); - } - [Fact] - public void ToSByte() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToSByte(a.Clicks % 128) > 0).ToList()); - data.Add(select.Where(a => sbyte.Parse((a.Clicks % 128).ToString()) > 0).ToList()); - } - [Fact] - public void ToSingle() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToSingle(a.Clicks) > 0).ToList()); - data.Add(select.Where(a => float.Parse(a.Clicks.ToString()) > 0).ToList()); - } - [Fact] - public void this_ToString() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToString(a.Clicks).Equals("")).ToList()); - data.Add(select.Where(a => a.Clicks.ToString().Equals("")).ToList()); - } - [Fact] - public void ToUInt16() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToUInt16(a.Clicks) > 0).ToList()); - data.Add(select.Where(a => ushort.Parse(a.Clicks.ToString()) > 0).ToList()); - } - [Fact] - public void ToUInt32() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToUInt32(a.Clicks) > 0).ToList()); - data.Add(select.Where(a => uint.Parse(a.Clicks.ToString()) > 0).ToList()); - } - [Fact] - public void ToUInt64() - { - var data = new List(); - data.Add(select.Where(a => Convert.ToUInt64(a.Clicks) > 0).ToList()); - data.Add(select.Where(a => ulong.Parse(a.Clicks.ToString()) > 0).ToList()); - } - - [Fact] - public void Guid_Parse() - { - var data = new List(); - data.Add(select.Where(a => Guid.Parse(Guid.Empty.ToString()) == Guid.Empty).ToList()); - } - - [Fact] - public void Guid_NewGuid() - { - var data = new List(); - //data.Add(select.OrderBy(a => Guid.NewGuid()).Limit(10).ToList()); - } - - [Fact] - public void Random() - { - var data = new List(); - data.Add(select.Where(a => new Random().Next() > a.Clicks).Limit(10).ToList()); - data.Add(select.Where(a => new Random().NextDouble() > a.Clicks).Limit(10).ToList()); - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/DateTimeTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/DateTimeTest.cs deleted file mode 100644 index 8856f9464..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/DateTimeTest.cs +++ /dev/null @@ -1,732 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseESExpression -{ - public class DateTimeTest - { - - ISelect select => g.kingbaseES.Select(); - - [Table(Name = "tb_topic111333")] - class Topic - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int Clicks { get; set; } - public int TypeGuid { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } = DateTime.Now; - } - [Table(Name = "TestTypeInfo333")] - class TestTypeInfo - { - [Column(IsIdentity = true)] - public int Guid { get; set; } - public int ParentId { get; set; } - public TestTypeParentInfo Parent { get; set; } - public string Name { get; set; } - public DateTime Time { get; set; } = DateTime.Now; - } - [Table(Name = "TestTypeParentInf1")] - class TestTypeParentInfo - { - public int Id { get; set; } - public string Name { get; set; } - - public List Types { get; set; } - public DateTime Time2 { get; set; } = DateTime.Now; - } - - [Fact] - public void this_ToString() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.ToString().Equals(DateTime.Now.ToString())).ToList()); - data.Add(select.Where(a => a.Type.Time.AddYears(1).ToString().Equals(DateTime.Now.ToString())).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).ToString().Equals(DateTime.Now.ToString())).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE ((date_format(a.`CreateTime`, '%Y-%m-%d %H:%i:%s.%f') = now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE ((date_format(date_add(a__Type.`Time`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE ((date_format(date_add(a__Type__Parent.`Time2`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now())) - - g.kingbaseES.Insert(new Topic()).ExecuteAffrows(); - var dtn = DateTime.Parse("2020-1-1 0:0:0"); - var dts = Enumerable.Range(1, 12).Select(a => dtn.AddMonths(a)) - .Concat(Enumerable.Range(1, 31).Select(a => dtn.AddDays(a))) - .Concat(Enumerable.Range(1, 24).Select(a => dtn.AddHours(a))) - .Concat(Enumerable.Range(1, 60).Select(a => dtn.AddMinutes(a))) - .Concat(Enumerable.Range(1, 60).Select(a => dtn.AddSeconds(a))); - foreach (var dt in dts) - { - Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm:ss.ffffff"), select.First(a => dt.ToString())); - Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm:ss"), select.First(a => dt.ToString("yyyy-MM-dd HH:mm:ss"))); - Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm"), select.First(a => dt.ToString("yyyy-MM-dd HH:mm"))); - Assert.Equal(dt.ToString("yyyy-MM-dd HH"), select.First(a => dt.ToString("yyyy-MM-dd HH"))); - Assert.Equal(dt.ToString("yyyy-MM-dd"), select.First(a => dt.ToString("yyyy-MM-dd"))); - Assert.Equal(dt.ToString("yyyy-MM"), select.First(a => dt.ToString("yyyy-MM"))); - Assert.Equal(dt.ToString("yyyyMMddHHmmss"), select.First(a => dt.ToString("yyyyMMddHHmmss"))); - Assert.Equal(dt.ToString("yyyyMMddHHmm"), select.First(a => dt.ToString("yyyyMMddHHmm"))); - Assert.Equal(dt.ToString("yyyyMMddHH"), select.First(a => dt.ToString("yyyyMMddHH"))); - Assert.Equal(dt.ToString("yyyyMMdd"), select.First(a => dt.ToString("yyyyMMdd"))); - Assert.Equal(dt.ToString("yyyyMM"), select.First(a => dt.ToString("yyyyMM"))); - Assert.Equal(dt.ToString("yyyy"), select.First(a => dt.ToString("yyyy"))); - Assert.Equal(dt.ToString("HH:mm:ss"), select.First(a => dt.ToString("HH:mm:ss"))); - Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h"))); - Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s"))); - } - } - [Fact] - public void Now() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Date == DateTime.Now.Date).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(now(), '%Y-%m-%d') as datetime)) - } - [Fact] - public void UtcNow() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Date == DateTime.UtcNow.Date).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(utc_timestamp(), '%Y-%m-%d') as datetime)) - } - [Fact] - public void MinValue() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Date == DateTime.MinValue.Date).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(cast('0001/1/1 0:00:00' as datetime), '%Y-%m-%d') as datetime)) - } - [Fact] - public void MaxValue() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Date == DateTime.MaxValue.Date).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(cast('9999/12/31 23:59:59' as datetime), '%Y-%m-%d') as datetime)) - } - [Fact] - public void Date() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Date == DateTime.Now.Date).ToList()); - //data.Add(select.Where(a => a.Type.Time.Date > DateTime.Now.Date).ToList()); - //data.Add(select.Where(a => a.Type.Parent.Time2.Date > DateTime.Now.Date).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime) = cast(date_format(now(), '%Y-%m-%d') as datetime)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (cast(date_format(a__Type.`Time`, '%Y-%m-%d') as datetime) > cast(date_format(now(), '%Y-%m-%d') as datetime)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (cast(date_format(a__Type__Parent.`Time2`, '%Y-%m-%d') as datetime) > cast(date_format(now(), '%Y-%m-%d') as datetime)); - //data.Add(select.Where(a => DateTime.Now.Subtract(a.CreateTime.Date).TotalSeconds > 0).ToList()); - //data.Add(select.Where(a => DateTime.Now.Subtract(a.Type.Time.Date).TotalSeconds > 0).ToList()); - //data.Add(select.Where(a => DateTime.Now.Subtract(a.Type.Parent.Time2.Date).TotalSeconds > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (((timestampdiff(microsecond, cast(date_format(a.`CreateTime`, '%Y-%m-%d') as datetime), now())) / 1000000) > 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (((timestampdiff(microsecond, cast(date_format(a__Type.`Time`, '%Y-%m-%d') as datetime), now())) / 1000000) > 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (((timestampdiff(microsecond, cast(date_format(a__Type__Parent.`Time2`, '%Y-%m-%d') as datetime), now())) / 1000000) > 0) - } - [Fact] - public void TimeOfDay() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay == DateTime.Now.TimeOfDay).ToList()); - data.Add(select.Where(a => a.Type.Time.TimeOfDay > DateTime.Now.TimeOfDay).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.TimeOfDay > DateTime.Now.TimeOfDay).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (timestampdiff(microsecond, date_format(now(), '1970-1-1 %H:%i:%s.%f'), now()) + 62135596800000000)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE ((timestampdiff(microsecond, date_format(a__Type.`Time`, '1970-1-1 %H:%i:%s.%f'), a__Type.`Time`) + 62135596800000000) > (timestampdiff(microsecond, date_format(now(), '1970-1-1 %H:%i:%s.%f'), now()) + 62135596800000000)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE ((timestampdiff(microsecond, date_format(a__Type__Parent.`Time2`, '1970-1-1 %H:%i:%s.%f'), a__Type__Parent.`Time2`) + 62135596800000000) > (timestampdiff(microsecond, date_format(now(), '1970-1-1 %H:%i:%s.%f'), now()) + 62135596800000000)) - } - [Fact] - public void DayOfWeek() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.DayOfWeek > DateTime.Now.DayOfWeek).ToList()); - data.Add(select.Where(a => a.Type.Time.DayOfWeek > DateTime.Now.DayOfWeek).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.DayOfWeek > DateTime.Now.DayOfWeek).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE ((dayofweek(a.`CreateTime`) - 1) > (dayofweek(now()) - 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE ((dayofweek(a__Type.`Time`) - 1) > (dayofweek(now()) - 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE ((dayofweek(a__Type__Parent.`Time2`) - 1) > (dayofweek(now()) - 1)) - } - [Fact] - public void Day() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Day > DateTime.Now.Day).ToList()); - data.Add(select.Where(a => a.Type.Time.Day > DateTime.Now.Day).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.Day > DateTime.Now.Day).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (dayofmonth(a.`CreateTime`) > dayofmonth(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (dayofmonth(a__Type.`Time`) > dayofmonth(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (dayofmonth(a__Type__Parent.`Time2`) > dayofmonth(now())) - } - [Fact] - public void DayOfYear() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.DayOfYear > DateTime.Now.DayOfYear).ToList()); - data.Add(select.Where(a => a.Type.Time.DayOfYear > DateTime.Now.DayOfYear).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.DayOfYear > DateTime.Now.DayOfYear).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (dayofyear(a.`CreateTime`) > dayofyear(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (dayofyear(a__Type.`Time`) > dayofyear(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (dayofyear(a__Type__Parent.`Time2`) > dayofyear(now())) - } - [Fact] - public void Month() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Month > DateTime.Now.Month).ToList()); - data.Add(select.Where(a => a.Type.Time.Month > DateTime.Now.Month).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.Month > DateTime.Now.Month).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (month(a.`CreateTime`) > month(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (month(a__Type.`Time`) > month(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (month(a__Type__Parent.`Time2`) > month(now())) - } - [Fact] - public void Year() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Year > DateTime.Now.Year).ToList()); - data.Add(select.Where(a => a.Type.Time.Year > DateTime.Now.Year).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.Year > DateTime.Now.Year).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (year(a.`CreateTime`) > year(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (year(a__Type.`Time`) > year(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (year(a__Type__Parent.`Time2`) > year(now())) - } - [Fact] - public void Hour() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Hour > DateTime.Now.Hour).ToList()); - data.Add(select.Where(a => a.Type.Time.Hour > DateTime.Now.Hour).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.Hour > DateTime.Now.Hour).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (hour(a.`CreateTime`) > hour(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (hour(a__Type.`Time`) > hour(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (hour(a__Type__Parent.`Time2`) > hour(now())) - } - [Fact] - public void Minute() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Minute > DateTime.Now.Minute).ToList()); - data.Add(select.Where(a => a.Type.Time.Minute > DateTime.Now.Minute).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.Minute > DateTime.Now.Minute).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (minute(a.`CreateTime`) > minute(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (minute(a__Type.`Time`) > minute(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (minute(a__Type__Parent.`Time2`) > minute(now())) - } - [Fact] - public void Second() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Second > DateTime.Now.Second).ToList()); - data.Add(select.Where(a => a.Type.Time.Second > DateTime.Now.Second).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.Second > DateTime.Now.Second).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (second(a.`CreateTime`) > second(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (second(a__Type.`Time`) > second(now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (second(a__Type__Parent.`Time2`) > second(now())) - } - [Fact] - public void Millisecond() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Millisecond > DateTime.Now.Millisecond).ToList()); - data.Add(select.Where(a => a.Type.Time.Millisecond > DateTime.Now.Millisecond).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.Millisecond > DateTime.Now.Millisecond).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (floor(microsecond(a.`CreateTime`) / 1000) > floor(microsecond(now()) / 1000)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (floor(microsecond(a__Type.`Time`) / 1000) > floor(microsecond(now()) / 1000)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (floor(microsecond(a__Type__Parent.`Time2`) / 1000) > floor(microsecond(now()) / 1000)) - } - [Fact] - public void Ticks() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Ticks > DateTime.Now.Ticks).ToList()); - data.Add(select.Where(a => a.Type.Time.Ticks > DateTime.Now.Ticks).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.Ticks > DateTime.Now.Ticks).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE ((timestampdiff(microsecond, '1970-1-1', a.`CreateTime`) * 10 + 621355968000000000) > (timestampdiff(microsecond, '1970-1-1', now()) * 10 + 621355968000000000)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE ((timestampdiff(microsecond, '1970-1-1', a__Type.`Time`) * 10 + 621355968000000000) > (timestampdiff(microsecond, '1970-1-1', now()) * 10 + 621355968000000000)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE ((timestampdiff(microsecond, '1970-1-1', a__Type__Parent.`Time2`) * 10 + 621355968000000000) > (timestampdiff(microsecond, '1970-1-1', now()) * 10 + 621355968000000000)) - } - [Fact] - public void Add() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Time.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.Add(TimeSpan.FromDays(1)) > DateTime.Now).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (date_add(a.`CreateTime`, interval ((1 * 86400000000)) microsecond) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (date_add(a__Type.`Time`, interval ((1 * 86400000000)) microsecond) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (date_add(a__Type__Parent.`Time2`, interval ((1 * 86400000000)) microsecond) > now()) - } - [Fact] - public void AddDays() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.AddDays(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Time.AddDays(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddDays(1) > DateTime.Now).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (date_add(a.`CreateTime`, interval (1) day) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (date_add(a__Type.`Time`, interval (1) day) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (date_add(a__Type__Parent.`Time2`, interval (1) day) > now()) - } - [Fact] - public void AddHours() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.AddHours(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Time.AddHours(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddHours(1) > DateTime.Now).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (date_add(a.`CreateTime`, interval (1) hour) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (date_add(a__Type.`Time`, interval (1) hour) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (date_add(a__Type__Parent.`Time2`, interval (1) hour) > now()) - } - [Fact] - public void AddMilliseconds() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.AddMilliseconds(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Time.AddMilliseconds(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddMilliseconds(1) > DateTime.Now).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (date_add(a.`CreateTime`, interval (1) * 1000 microsecond) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (date_add(a__Type.`Time`, interval (1) * 1000 microsecond) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (date_add(a__Type__Parent.`Time2`, interval (1) * 1000 microsecond) > now()) - } - [Fact] - public void AddMinutes() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.AddMinutes(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Time.AddMinutes(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddMinutes(1) > DateTime.Now).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (date_add(a.`CreateTime`, interval (1) minute) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (date_add(a__Type.`Time`, interval (1) minute) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (date_add(a__Type__Parent.`Time2`, interval (1) minute) > now()) - } - [Fact] - public void AddMonths() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.AddMonths(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Time.AddMonths(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddMonths(1) > DateTime.Now).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (date_add(a.`CreateTime`, interval (1) month) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (date_add(a__Type.`Time`, interval (1) month) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (date_add(a__Type__Parent.`Time2`, interval (1) month) > now()) - } - [Fact] - public void AddSeconds() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.AddSeconds(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Time.AddSeconds(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddSeconds(1) > DateTime.Now).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (date_add(a.`CreateTime`, interval (1) second) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (date_add(a__Type.`Time`, interval (1) second) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (date_add(a__Type__Parent.`Time2`, interval (1) second) > now()) - } - [Fact] - public void AddTicks() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.AddTicks(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Time.AddTicks(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddTicks(1) > DateTime.Now).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (date_add(a.`CreateTime`, interval (1) / 10 microsecond) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (date_add(a__Type.`Time`, interval (1) / 10 microsecond) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (date_add(a__Type__Parent.`Time2`, interval (1) / 10 microsecond) > now()) - } - [Fact] - public void AddYears() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.AddYears(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Time.AddYears(1) > DateTime.Now).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1) > DateTime.Now).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (date_add(a.`CreateTime`, interval (1) year) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (date_add(a__Type.`Time`, interval (1) year) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (date_add(a__Type__Parent.`Time2`, interval (1) year) > now()) - } - [Fact] - public void Subtract() - { - var data = new List(); - //data.Add(select.Where(a => a.CreateTime.Subtract(DateTime.Now).TotalSeconds > 0).ToList()); - //data.Add(select.Where(a => a.Type.Time.Subtract(DateTime.Now).TotalSeconds > 0).ToList()); - //data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(DateTime.Now).TotalSeconds > 0).ToList()); - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a."TITLE", a."CREATETIME" - //FROM "TB_TOPIC111333" a - //WHERE ((extract(day from (systimestamp-a."CREATETIME"))*86400+extract(hour from (systimestamp-a."CREATETIME"))*3600+extract(minute from (systimestamp-a."CREATETIME"))*60+extract(second from (systimestamp-a."CREATETIME"))) > 0) - - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME" - //FROM "TB_TOPIC111333" a - //LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID" - //WHERE ((extract(day from (systimestamp-a__Type."TIME"))*86400+extract(hour from (systimestamp-a__Type."TIME"))*3600+extract(minute from (systimestamp-a__Type."TIME"))*60+extract(second from (systimestamp-a__Type."TIME"))) > 0) - - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME" - //FROM "TB_TOPIC111333" a - //LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID" - //LEFT JOIN "TESTTYPEPARENTINF1" a__Type__Parent ON a__Type__Parent."ID" = a__Type."PARENTID" - //WHERE ((extract(day from (systimestamp-a__Type__Parent."TIME2"))*86400+extract(hour from (systimestamp-a__Type__Parent."TIME2"))*3600+extract(minute from (systimestamp-a__Type__Parent."TIME2"))*60+extract(second from (systimestamp-a__Type__Parent."TIME2"))) > 0) - //data.Add(select.Where(a => a.CreateTime.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList()); - //data.Add(select.Where(a => a.Type.Time.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList()); - //data.Add(select.Where(a => a.Type.Parent.Time2.Subtract(TimeSpan.FromDays(1)) > a.CreateTime).ToList()); - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a."TITLE", a."CREATETIME" - //FROM "TB_TOPIC111333" a - //WHERE ((a."CREATETIME"-numtodsinterval((1)*86400,'second')) > a."CREATETIME") - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME" - - //FROM "TB_TOPIC111333" a - //LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID" - //WHERE ((a__Type."TIME"-numtodsinterval((1)*86400,'second')) > a."CREATETIME") - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME" - - //FROM "TB_TOPIC111333" a - //LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID" - //LEFT JOIN "TESTTYPEPARENTINF1" a__Type__Parent ON a__Type__Parent."ID" = a__Type."PARENTID" - //WHERE ((a__Type__Parent."TIME2"-numtodsinterval((1)*86400,'second')) > a."CREATETIME") - } - [Fact] - public void _ЧͬSubtract() - { - var data = new List(); - //data.Add(select.Where(a => (a.CreateTime - DateTime.Now).TotalSeconds > 0).ToList()); - //data.Add(select.Where(a => (a.Type.Time - DateTime.Now).TotalSeconds > 0).ToList()); - //data.Add(select.Where(a => (a.Type.Parent.Time2 - DateTime.Now).TotalSeconds > 0).ToList()); - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a."TITLE", a."CREATETIME" - //FROM "TB_TOPIC111333" a - //WHERE ((extract(day from (systimestamp-a."CREATETIME"))*86400+extract(hour from (systimestamp-a."CREATETIME"))*3600+extract(minute from (systimestamp-a."CREATETIME"))*60+extract(second from (systimestamp-a."CREATETIME"))) > 0) - - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME" - //FROM "TB_TOPIC111333" a - //LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID" - //WHERE ((extract(day from (systimestamp-a__Type."TIME"))*86400+extract(hour from (systimestamp-a__Type."TIME"))*3600+extract(minute from (systimestamp-a__Type."TIME"))*60+extract(second from (systimestamp-a__Type."TIME"))) > 0) - - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME" - //FROM "TB_TOPIC111333" a - //LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID" - //LEFT JOIN "TESTTYPEPARENTINF1" a__Type__Parent ON a__Type__Parent."ID" = a__Type."PARENTID" - //WHERE ((extract(day from (systimestamp-a__Type__Parent."TIME2"))*86400+extract(hour from (systimestamp-a__Type__Parent."TIME2"))*3600+extract(minute from (systimestamp-a__Type__Parent."TIME2"))*60+extract(second from (systimestamp-a__Type__Parent."TIME2"))) > 0) - //data.Add(select.Where(a => (a.CreateTime - TimeSpan.FromDays(1)) > a.CreateTime).ToList()); - //data.Add(select.Where(a => (a.Type.Time - TimeSpan.FromDays(1)) > a.CreateTime).ToList()); - //data.Add(select.Where(a => (a.Type.Parent.Time2 - TimeSpan.FromDays(1)) > a.CreateTime).ToList()); - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a."TITLE", a."CREATETIME" - //FROM "TB_TOPIC111333" a - //WHERE ((a."CREATETIME"-numtodsinterval((1)*86400,'second')) > a."CREATETIME") - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME" - - //FROM "TB_TOPIC111333" a - //LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID" - //WHERE ((a__Type."TIME"-numtodsinterval((1)*86400,'second')) > a."CREATETIME") - //SELECT a."ID", a."CLICKS", a."TYPEGUID", a__Type."GUID", a__Type."PARENTID", a__Type."NAME", a__Type."TIME", a."TITLE", a."CREATETIME" - - //FROM "TB_TOPIC111333" a - //LEFT JOIN "TESTTYPEINFO333" a__Type ON a__Type."GUID" = a."TYPEGUID" - //LEFT JOIN "TESTTYPEPARENTINF1" a__Type__Parent ON a__Type__Parent."ID" = a__Type."PARENTID" - //WHERE ((a__Type__Parent."TIME2"-numtodsinterval((1)*86400,'second')) > a."CREATETIME") - } - [Fact] - public void this_Equals() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.AddYears(1).Equals(DateTime.Now)).ToList()); - data.Add(select.Where(a => a.Type.Time.AddYears(1).Equals(DateTime.Now)).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).Equals(DateTime.Now)).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE ((date_add(a.`CreateTime`, interval (1) year) = now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE ((date_add(a__Type.`Time`, interval (1) year) = now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE ((date_add(a__Type__Parent.`Time2`, interval (1) year) = now())) - } - [Fact] - public void DateTime_Compare() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.CompareTo(DateTime.Now) == 0).ToList()); - data.Add(select.Where(a => a.Type.Time.AddYears(1).CompareTo(DateTime.Now) == 0).ToList()); - data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).CompareTo(DateTime.Now) == 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (((a.`CreateTime`) - (now())) = 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (((date_add(a__Type.`Time`, interval (1) year)) - (now())) = 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (((date_add(a__Type__Parent.`Time2`, interval (1) year)) - (now())) = 0) - } - [Fact] - public void DateTime_DaysInMonth() - { - var data = new List(); - data.Add(select.Where(a => DateTime.DaysInMonth(a.CreateTime.Year, a.CreateTime.Month) > 30).ToList()); - //data.Add(select.Where(a => DateTime.DaysInMonth(a.Type.Time.Year, a.Type.Time.Month) > 30).ToList()); - //data.Add(select.Where(a => DateTime.DaysInMonth(a.Type.Parent.Time2.Year, a.Type.Parent.Time2.Month) > 30).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (dayofmonth(last_day(concat(year(a.`CreateTime`), month(a.`CreateTime`), '-01'))) > 30); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (dayofmonth(last_day(concat(year(a__Type.`Time`), month(a__Type.`Time`), '-01'))) > 30); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (dayofmonth(last_day(concat(year(a__Type__Parent.`Time2`), month(a__Type__Parent.`Time2`), '-01'))) > 30) - } - [Fact] - public void DateTime_Equals() - { - var data = new List(); - data.Add(select.Where(a => DateTime.Equals(a.CreateTime.AddYears(1), DateTime.Now)).ToList()); - data.Add(select.Where(a => DateTime.Equals(a.Type.Time.AddYears(1), DateTime.Now)).ToList()); - data.Add(select.Where(a => DateTime.Equals(a.Type.Parent.Time2.AddYears(1), DateTime.Now)).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE ((date_add(a.`CreateTime`, interval (1) year) = now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE ((date_add(a__Type.`Time`, interval (1) year) = now())); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE ((date_add(a__Type__Parent.`Time2`, interval (1) year) = now())) - } - [Fact] - public void DateTime_IsLeapYear() - { - var data = new List(); - data.Add(select.Where(a => DateTime.IsLeapYear(a.CreateTime.Year)).ToList()); - data.Add(select.Where(a => DateTime.IsLeapYear(a.Type.Time.AddYears(1).Year)).ToList()); - data.Add(select.Where(a => DateTime.IsLeapYear(a.Type.Parent.Time2.AddYears(1).Year)).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (((year(a.`CreateTime`)) % 4 = 0 AND (year(a.`CreateTime`)) % 100 <> 0 OR (year(a.`CreateTime`)) % 400 = 0)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (((year(date_add(a__Type.`Time`, interval (1) year))) % 4 = 0 AND (year(date_add(a__Type.`Time`, interval (1) year))) % 100 <> 0 OR (year(date_add(a__Type.`Time`, interval (1) year))) % 400 = 0)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (((year(date_add(a__Type__Parent.`Time2`, interval (1) year))) % 4 = 0 AND (year(date_add(a__Type__Parent.`Time2`, interval (1) year))) % 100 <> 0 OR (year(date_add(a__Type__Parent.`Time2`, interval (1) year))) % 400 = 0)) - } - [Fact] - public void DateTime_Parse() - { - var data = new List(); - data.Add(select.Where(a => DateTime.Parse(a.CreateTime.ToString()) > DateTime.Now).ToList()); - data.Add(select.Where(a => DateTime.Parse(a.Type.Time.AddYears(1).ToString()) > DateTime.Now).ToList()); - data.Add(select.Where(a => DateTime.Parse(a.Type.Parent.Time2.AddYears(1).ToString()) > DateTime.Now).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic111333` a - //WHERE (cast(date_format(a.`CreateTime`, '%Y-%m-%d %H:%i:%s.%f') as datetime) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type - //WHERE (cast(date_format(date_add(a__Type.`Time`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') as datetime) > now()); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9 - //FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent - //WHERE (cast(date_format(date_add(a__Type__Parent.`Time2`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') as datetime) > now()) - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/MathTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/MathTest.cs deleted file mode 100644 index f803f792a..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/MathTest.cs +++ /dev/null @@ -1,156 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseESExpression -{ - public class MathTest - { - - ISelect select => g.kingbaseES.Select(); - - [Table(Name = "tb_topic")] - class Topic - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int Clicks { get; set; } - public int TypeGuid { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - class TestTypeInfo - { - public int Guid { get; set; } - public int ParentId { get; set; } - public TestTypeParentInfo Parent { get; set; } - public string Name { get; set; } - } - class TestTypeParentInfo - { - public int Id { get; set; } - public string Name { get; set; } - - public List Types { get; set; } - } - - [Fact] - public void PI() - { - var data = new List(); - data.Add(select.Where(a => Math.PI + a.Clicks > 0).ToList()); - } - [Fact] - public void Abs() - { - var data = new List(); - data.Add(select.Where(a => Math.Abs(-a.Clicks) > 0).ToList()); - } - [Fact] - public void Sign() - { - var data = new List(); - data.Add(select.Where(a => Math.Sign(-a.Clicks) > 0).ToList()); - } - [Fact] - public void Floor() - { - var data = new List(); - data.Add(select.Where(a => Math.Floor(a.Clicks + 0.5) == a.Clicks).ToList()); - } - [Fact] - public void Ceiling() - { - var data = new List(); - data.Add(select.Where(a => Math.Ceiling(a.Clicks + 0.5) == a.Clicks + 1).ToList()); - } - [Fact] - public void Round() - { - var data = new List(); - data.Add(select.Where(a => Math.Round(a.Clicks + 0.5) == a.Clicks).ToList()); - data.Add(select.Where(a => Math.Round(a.Clicks + 0.5, 1) > a.Clicks).ToList()); - } - [Fact] - public void Exp() - { - var data = new List(); - data.Add(select.Where(a => Math.Exp(1) == a.Clicks + 1).ToList()); - } - [Fact] - public void Log() - { - var data = new List(); - data.Add(select.Where(a => Math.Log(a.Clicks + 0.5) == a.Clicks + 1).ToList()); - } - [Fact] - public void Log10() - { - var data = new List(); - data.Add(select.Where(a => Math.Log10(a.Clicks + 0.5) == a.Clicks + 1).ToList()); - } - [Fact] - public void Pow() - { - var data = new List(); - data.Add(select.Where(a => Math.Pow(2, a.Clicks % 5) == a.Clicks + 1).ToList()); - } - [Fact] - public void Sqrt() - { - var data = new List(); - data.Add(select.Where(a => Math.Sqrt(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList()); - } - [Fact] - public void Cos() - { - var data = new List(); - data.Add(select.Where(a => Math.Cos(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList()); - } - [Fact] - public void Sin() - { - var data = new List(); - data.Add(select.Where(a => Math.Sin(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList()); - } - [Fact] - public void Tan() - { - var data = new List(); - data.Add(select.Where(a => Math.Tan(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList()); - } - [Fact] - public void Acos() - { - var data = new List(); - //data.Add(select.Where(a => Math.Acos(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList()); - } - [Fact] - public void Asin() - { - var data = new List(); - //data.Add(select.Where(a => Math.Asin(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList()); - } - [Fact] - public void Atan() - { - var data = new List(); - data.Add(select.Where(a => Math.Atan(Math.Pow(2, a.Clicks % 5)) == a.Clicks + 1).ToList()); - } - [Fact] - public void Atan2() - { - var data = new List(); - //data.Add(select.Where(a => Math.Atan2(2, a.Clicks) == a.Clicks + 1).ToList()); - } - [Fact] - public void Truncate() - { - var data = new List(); - data.Add(select.Where(a => Math.Truncate(a.Clicks * 1.0 / 3) == a.Clicks + 1).ToList()); - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/OtherTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/OtherTest.cs deleted file mode 100644 index f84ff2b4d..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/OtherTest.cs +++ /dev/null @@ -1,165 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseESExpression -{ - public class OtherTest - { - - ISelect select => g.kingbaseES.Select(); - - public OtherTest() - { - } - - [Fact] - public void Div() - { - var t1 = select.Where(a => a.Int / 3 > 3).Limit(10).ToList(); - var t2 = select.Where(a => a.Long / 3 > 3).Limit(10).ToList(); - var t3 = select.Where(a => a.Short / 3 > 3).Limit(10).ToList(); - - var t4 = select.Where(a => a.Int / 3.0 > 3).Limit(10).ToList(); - var t5 = select.Where(a => a.Long / 3.0 > 3).Limit(10).ToList(); - var t6 = select.Where(a => a.Short / 3.0 > 3).Limit(10).ToList(); - - var t7 = select.Where(a => a.Double / 3 > 3).Limit(10).ToList(); - var t8 = select.Where(a => a.Decimal / 3 > 3).Limit(10).ToList(); - var t9 = select.Where(a => a.Float / 3 > 3).Limit(10).ToList(); - } - - [Fact] - public void Boolean() - { - var t1 = select.Where(a => a.Bool == true).ToList(); - var t2 = select.Where(a => a.Bool != true).ToList(); - var t3 = select.Where(a => a.Bool == false).ToList(); - var t4 = select.Where(a => !a.Bool).ToList(); - var t5 = select.Where(a => a.Bool).ToList(); - var t51 = select.WhereCascade(a => a.Bool).Limit(10).ToList(); - - var t11 = select.Where(a => a.BoolNullable == true).ToList(); - var t22 = select.Where(a => a.BoolNullable != true).ToList(); - var t33 = select.Where(a => a.BoolNullable == false).ToList(); - var t44 = select.Where(a => !a.BoolNullable.Value).ToList(); - var t55 = select.Where(a => a.BoolNullable.Value).ToList(); - - var t111 = select.Where(a => a.Bool == true && a.Id > 0).ToList(); - var t222 = select.Where(a => a.Bool != true && a.Id > 0).ToList(); - var t333 = select.Where(a => a.Bool == false && a.Id > 0).ToList(); - var t444 = select.Where(a => !a.Bool && a.Id > 0).ToList(); - var t555 = select.Where(a => a.Bool && a.Id > 0).ToList(); - - var t1111 = select.Where(a => a.BoolNullable == true && a.Id > 0).ToList(); - var t2222 = select.Where(a => a.BoolNullable != true && a.Id > 0).ToList(); - var t3333 = select.Where(a => a.BoolNullable == false && a.Id > 0).ToList(); - var t4444 = select.Where(a => !a.BoolNullable.Value && a.Id > 0).ToList(); - var t5555 = select.Where(a => a.BoolNullable.Value && a.Id > 0).ToList(); - - var t11111 = select.Where(a => a.Bool == true && a.Id > 0 && a.Bool == true).ToList(); - var t22222 = select.Where(a => a.Bool != true && a.Id > 0 && a.Bool != true).ToList(); - var t33333 = select.Where(a => a.Bool == false && a.Id > 0 && a.Bool == false).ToList(); - var t44444 = select.Where(a => !a.Bool && a.Id > 0 && !a.Bool).ToList(); - var t55555 = select.Where(a => a.Bool && a.Id > 0 && a.Bool).ToList(); - - var t111111 = select.Where(a => a.BoolNullable == true && a.Id > 0 && a.BoolNullable == true).ToList(); - var t222222 = select.Where(a => a.BoolNullable != true && a.Id > 0 && a.BoolNullable != true).ToList(); - var t333333 = select.Where(a => a.BoolNullable == false && a.Id > 0 && a.BoolNullable == false).ToList(); - var t444444 = select.Where(a => !a.BoolNullable.Value && a.Id > 0 && !a.BoolNullable.Value).ToList(); - var t555555 = select.Where(a => a.BoolNullable.Value && a.Id > 0 && a.BoolNullable.Value).ToList(); - } - - [Fact] - public void Array() - { - IEnumerable testlinqlist = new List(new[] { 1, 2, 3 }); - var testlinq = select.Where(a => testlinqlist.Contains(a.Int)).ToList(); - - //in not in - var sql111 = select.Where(a => new[] { 1, 2, 3 }.Contains(a.Int)).ToList(); - //var sql112 = select.Where(a => new[] { 1, 2, 3 }.Contains(a.Int) == false).ToList(); - var sql113 = select.Where(a => !new[] { 1, 2, 3 }.Contains(a.Int)).ToList(); - - var inarray = new[] { 1, 2, 3 }; - var sql1111 = select.Where(a => inarray.Contains(a.Int)).ToList(); - //var sql1122 = select.Where(a => inarray.Contains(a.Int) == false).ToList(); - var sql1133 = select.Where(a => !inarray.Contains(a.Int)).ToList(); - - - //in not in - var sql11111 = select.Where(a => new List() { 1, 2, 3 }.Contains(a.Int)).ToList(); - //var sql11222 = select.Where(a => new List() { 1, 2, 3 }.Contains(a.Int) == false).ToList(); - var sql11333 = select.Where(a => !new List() { 1, 2, 3 }.Contains(a.Int)).ToList(); - - var sql11111a = select.Where(a => new List(new[] { 1, 2, 3 }).Contains(a.Int)).ToList(); - //var sql11222b = select.Where(a => new List(new[] { 1, 2, 3 }).Contains(a.Int) == false).ToList(); - var sql11333c = select.Where(a => !new List(new[] { 1, 2, 3 }).Contains(a.Int)).ToList(); - - var inarray2 = new List() { 1, 2, 3 }; - var sql111111 = select.Where(a => inarray.Contains(a.Int)).ToList(); - //var sql112222 = select.Where(a => inarray.Contains(a.Int) == false).ToList(); - var sql113333 = select.Where(a => !inarray.Contains(a.Int)).ToList(); - - var inarray2n = Enumerable.Range(1, 3333).ToArray(); - var sql1111111 = select.Where(a => inarray2n.Contains(a.Int)).ToList(); - var sql1122222 = select.Where(a => inarray2n.Contains(a.Int) == false).ToList(); - var sql1133333 = select.Where(a => !inarray2n.Contains(a.Int)).ToList(); - } - - [Table(Name = "tb_alltype")] - class TableAllType - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - - public string id2 { get; set; } = "id2=10"; - - public bool Bool { get; set; } - public sbyte SByte { get; set; } - public short Short { get; set; } - public int Int { get; set; } - public long Long { get; set; } - public byte Byte { get; set; } - public ushort UShort { get; set; } - public uint UInt { get; set; } - public ulong ULong { get; set; } - public double Double { get; set; } - public float Float { get; set; } - public decimal Decimal { get; set; } - public TimeSpan TimeSpan { get; set; } - public DateTime DateTime { get; set; } - public DateTime DateTimeOffSet { get; set; } - public byte[] Bytes { get; set; } - public string String { get; set; } - public Guid Guid { get; set; } - - public bool? BoolNullable { get; set; } - public sbyte? SByteNullable { get; set; } - public short? ShortNullable { get; set; } - public int? IntNullable { get; set; } - public long? testFielLongNullable { get; set; } - public byte? ByteNullable { get; set; } - public ushort? UShortNullable { get; set; } - public uint? UIntNullable { get; set; } - public ulong? ULongNullable { get; set; } - public double? DoubleNullable { get; set; } - public float? FloatNullable { get; set; } - public decimal? DecimalNullable { get; set; } - public TimeSpan? TimeSpanNullable { get; set; } - public DateTime? DateTimeNullable { get; set; } - public DateTime? DateTimeOffSetNullable { get; set; } - public Guid? GuidNullable { get; set; } - - public TableAllTypeEnumType1 Enum1 { get; set; } - public TableAllTypeEnumType1? Enum1Nullable { get; set; } - public TableAllTypeEnumType2 Enum2 { get; set; } - public TableAllTypeEnumType2? Enum2Nullable { get; set; } - } - - public enum TableAllTypeEnumType1 { e1, e2, e3, e5 } - [Flags] public enum TableAllTypeEnumType2 { f1, f2, f3 } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/StringTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/StringTest.cs deleted file mode 100644 index 50bcc7205..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/StringTest.cs +++ /dev/null @@ -1,827 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseESExpression -{ - public class StringTest - { - - ISelect select => g.kingbaseES.Select(); - - [Table(Name = "tb_topic")] - class Topic - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int Clicks { get; set; } - public int TypeGuid { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - class TestTypeInfo - { - [Column(IsIdentity = true)] - public int Guid { get; set; } - public int ParentId { get; set; } - public TestTypeParentInfo Parent { get; set; } - public string Name { get; set; } - } - class TestTypeParentInfo - { - public int Id { get; set; } - public string Name { get; set; } - - public List Types { get; set; } - } - class TestEqualsGuid - { - public Guid id { get; set; } - } - - [Fact] - public void Equals__() - { - var list = new List(); - list.Add(select.Where(a => a.Title.Equals("aaa")).ToList()); - list.Add(g.kingbaseES.Select().Where(a => a.id.Equals(Guid.Empty)).ToList()); - } - - [Fact] - public void StringJoin() - { - var fsql = g.kingbaseES; - fsql.Delete().Where("1=1").ExecuteAffrows(); - fsql.Insert(new[] { new StringJoin01 { name = "北京" }, new StringJoin01 { name = "上海" }, new StringJoin01 { name = "深圳" }, }).ExecuteAffrows(); - - var val1 = string.Join(",", fsql.Select().ToList(a => a.name)); - var val2 = fsql.Select().ToList(a => string.Join(",", fsql.Select().As("b").ToList(b => b.name))); - Assert.Equal(val1, val2[0]); - - val1 = string.Join("**", fsql.Select().ToList(a => a.name)); - val2 = fsql.Select().ToList(a => string.Join("**", fsql.Select().As("b").ToList(b => b.name))); - Assert.Equal(val1, val2[0]); - - val1 = string.Join(",", fsql.Select().ToList(a => a.id)); - val2 = fsql.Select().ToList(a => string.Join(",", fsql.Select().As("b").ToList(b => b.id))); - Assert.Equal(val1, val2[0]); - - val1 = string.Join("**", fsql.Select().ToList(a => a.id)); - val2 = fsql.Select().ToList(a => string.Join("**", fsql.Select().As("b").ToList(b => b.id))); - Assert.Equal(val1, val2[0]); - } - class StringJoin01 - { - [Column(IsIdentity = true)] - public int id { get; set; } - public string name { get; set; } - } - - [Fact] - public void First() - { - Assert.Equal('x', select.First(a => "x1".First())); - Assert.Equal('z', select.First(a => "z1".First())); - } - [Fact] - public void FirstOrDefault() - { - Assert.Equal('x', select.First(a => "x1".FirstOrDefault())); - Assert.Equal('z', select.First(a => "z1".FirstOrDefault())); - } - - [Fact] - public void Format() - { - var item = g.kingbaseES.GetRepository().Insert(new Topic { Clicks = 101, Title = "我是中国人101", CreateTime = DateTime.Parse("2020-7-5") }); - var sql = select.WhereDynamic(item).ToSql(a => new - { - str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}", - str2 = string.Format("{0}x{0}z-{1}{2}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title) - }); - Assert.Equal($@"SELECT 'x'||coalesce(((a.""ID"" + 1))::text, '')||'z-'||coalesce(to_char((a.""CREATETIME"")::timestamp,'YYYYMM'), '')||''||coalesce(a.""TITLE"", '')||'' as1, ''||coalesce(((a.""ID"" + 1))::text, '')||'x'||coalesce(((a.""ID"" + 1))::text, '')||'z-'||coalesce(to_char((a.""CREATETIME"")::timestamp,'YYYYMM'), '')||''||coalesce(a.""TITLE"", '')||'' as2 -FROM ""TB_TOPIC"" a -WHERE (a.""ID"" = {item.Id})", sql); - - var item2 = select.WhereDynamic(item).First(a => new - { - str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}", - str2 = string.Format("{0}x{0}z-{1}{2}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title) - }); - Assert.NotNull(item2); - Assert.Equal($"x{item.Id + 1}z-{item.CreateTime.ToString("yyyyMM")}{item.Title}", item2.str); - Assert.Equal(string.Format("{0}x{0}z-{1}{2}", item.Id + 1, item.CreateTime.ToString("yyyyMM"), item.Title), item2.str2); - } - - [Fact] - public void Format4() - { - //3个 {} 时,Arguments 解析出来是分开的 - //4个 {} 时,Arguments[1] 只能解析这个出来,然后里面是 NewArray [] - var item = g.kingbaseES.GetRepository().Insert(new Topic { Clicks = 101, Title = "我是中国人101", CreateTime = DateTime.Parse("2020-7-5") }); - var sql = select.WhereDynamic(item).ToSql(a => new - { - str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}{a.Title}", - str2 = string.Format("{0}x{0}z-{1}{2}{3}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title, a.Title) - }); - Assert.Equal($@"SELECT 'x'||coalesce(((a.""ID"" + 1))::text, '')||'z-'||coalesce(to_char((a.""CREATETIME"")::timestamp,'YYYYMM'), '')||''||coalesce(a.""TITLE"", '')||''||coalesce(a.""TITLE"", '')||'' as1, ''||coalesce(((a.""ID"" + 1))::text, '')||'x'||coalesce(((a.""ID"" + 1))::text, '')||'z-'||coalesce(to_char((a.""CREATETIME"")::timestamp,'YYYYMM'), '')||''||coalesce(a.""TITLE"", '')||''||coalesce(a.""TITLE"", '')||'' as2 -FROM ""TB_TOPIC"" a -WHERE (a.""ID"" = {item.Id})", sql); - - var item2 = select.WhereDynamic(item).First(a => new - { - str = $"x{a.Id + 1}z-{a.CreateTime.ToString("yyyyMM")}{a.Title}{a.Title}", - str2 = string.Format("{0}x{0}z-{1}{2}{3}", a.Id + 1, a.CreateTime.ToString("yyyyMM"), a.Title, a.Title) - }); - Assert.NotNull(item2); - Assert.Equal($"x{item.Id + 1}z-{item.CreateTime.ToString("yyyyMM")}{item.Title}{item.Title}", item2.str); - Assert.Equal(string.Format("{0}x{0}z-{1}{2}{3}", item.Id + 1, item.CreateTime.ToString("yyyyMM"), item.Title, item.Title), item2.str2); - } - - [Fact] - public void Empty() - { - var data = new List(); - data.Add(select.Where(a => (a.Title ?? "") == string.Empty).ToSql()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (ifnull(a.`Title`, '') = '') - } - - [Fact] - public void StartsWith() - { - var list = new List(); - list.Add(select.Where(a => a.Title.StartsWith("aaa")).ToList()); - list.Add(select.Where(a => a.Title.StartsWith(a.Title)).ToList()); - list.Add(select.Where(a => a.Title.StartsWith(a.Title + 1)).ToList()); - list.Add(select.Where(a => a.Title.StartsWith(a.Type.Name)).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((a.`Title`) LIKE '%aaa') - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((a.`Title`) LIKE concat('%', a.`Title`)) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((a.`Title`) LIKE concat('%', concat(a.`Title`, 1))) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE((a.`Title`) LIKE concat('%', a__Type.`Name`)) - list.Add(select.Where(a => (a.Title + "aaa").StartsWith("aaa")).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Title)).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Title + 1)).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").StartsWith(a.Type.Name)).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((concat(a.`Title`, 'aaa')) LIKE '%aaa') - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a.`Title`)) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', concat(a.`Title`, 1))) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a__Type.`Name`)) - } - [Fact] - public void EndsWith() - { - var list = new List(); - list.Add(select.Where(a => a.Title.EndsWith("aaa")).ToList()); - list.Add(select.Where(a => a.Title.EndsWith(a.Title)).ToList()); - list.Add(select.Where(a => a.Title.EndsWith(a.Title + 1)).ToList()); - list.Add(select.Where(a => a.Title.EndsWith(a.Type.Name)).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((a.`Title`) LIKE 'aaa%') - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((a.`Title`) LIKE concat(a.`Title`, '%')) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((a.`Title`) LIKE concat(concat(a.`Title`, 1), '%')) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE((a.`Title`) LIKE concat(a__Type.`Name`, '%')) - list.Add(select.Where(a => (a.Title + "aaa").EndsWith("aaa")).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Title)).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Title + 1)).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").EndsWith(a.Type.Name)).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((concat(a.`Title`, 'aaa')) LIKE 'aaa%') - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((concat(a.`Title`, 'aaa')) LIKE concat(a.`Title`, '%')) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((concat(a.`Title`, 'aaa')) LIKE concat(concat(a.`Title`, 1), '%')) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE((concat(a.`Title`, 'aaa')) LIKE concat(a__Type.`Name`, '%')) - } - [Fact] - public void Contains() - { - var list = new List(); - list.Add(select.Where(a => a.Title.Contains("aaa")).ToList()); - list.Add(select.Where(a => a.Title.Contains(a.Title)).ToList()); - list.Add(select.Where(a => a.Title.Contains(a.Title + 1)).ToList()); - list.Add(select.Where(a => a.Title.Contains(a.Type.Name)).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((a.`Title`) LIKE '%aaa%') - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((a.`Title`) LIKE concat('%', a.`Title`, '%')) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((a.`Title`) LIKE concat('%', a.`Title` +1, '%')) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE((a.`Title`) LIKE concat('%', a__Type.`Name`, '%')) - list.Add(select.Where(a => (a.Title + "aaa").Contains("aaa")).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Title)).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Title + 1)).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Type.Name)).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((concat(a.`Title`, 'aaa')) LIKE '%aaa%') - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a.`Title`, '%')) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', concat(a.`Title`, 1), '%')) - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE((concat(a.`Title`, 'aaa')) LIKE concat('%', a__Type.`Name`, '%')) - - - list.Add(select.Where(a => a.Title.Contains("%")).ToList()); - list.Add(select.Where(a => a.Title.Contains(a.Title + "%")).ToList()); - list.Add(select.Where(a => a.Title.Contains(a.Title + 1 + "%")).ToList()); - list.Add(select.Where(a => a.Title.Contains(a.Type.Name + "%")).ToList()); - - list.Add(select.Where(a => (a.Title + "aaa").Contains("aaa" + "%")).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Title + "%")).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Title + 1 + "%")).ToList()); - list.Add(select.Where(a => (a.Title + "aaa").Contains(a.Type.Name + "%")).ToList()); - } - [Fact] - public void ToLower() - { - var data = new List(); - data.Add(select.Where(a => a.Title.ToLower() == "aaa").ToList()); - data.Add(select.Where(a => a.Title.ToLower() == a.Title).ToList()); - data.Add(select.Where(a => a.Title.ToLower() == (a.Title + 1)).ToList()); - data.Add(select.Where(a => a.Title.ToLower() == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE(lower(a.`Title`) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE(lower(a.`Title`) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE(lower(a.`Title`) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE(lower(a.`Title`) = a__Type.`Name`); - data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == "aaa").ToList()); - data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == a.Title).ToList()); - data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == (a.Title + 1)).ToList()); - data.Add(select.Where(a => (a.Title.ToLower() + "aaa").ToLower() == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE(lower(concat(lower(a.`Title`), 'aaa')) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE(lower(concat(lower(a.`Title`), 'aaa')) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE(lower(concat(lower(a.`Title`), 'aaa')) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE(lower(concat(lower(a.`Title`), 'aaa')) = a__Type.`Name`) - } - [Fact] - public void ToUpper() - { - var data = new List(); - data.Add(select.Where(a => a.Title.ToUpper() == "aaa").ToList()); - data.Add(select.Where(a => a.Title.ToUpper() == a.Title).ToList()); - data.Add(select.Where(a => a.Title.ToUpper() == (a.Title + 1)).ToList()); - data.Add(select.Where(a => a.Title.ToUpper() == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (upper(a.`Title`) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (upper(a.`Title`) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (upper(a.`Title`) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (upper(a.`Title`) = a__Type.`Name`); - data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == "aaa").ToList()); - data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == a.Title).ToList()); - data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == (a.Title + 1)).ToList()); - data.Add(select.Where(a => (a.Title.ToUpper() + "aaa").ToUpper() == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (upper(concat(upper(a.`Title`), 'aaa')) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (upper(concat(upper(a.`Title`), 'aaa')) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (upper(concat(upper(a.`Title`), 'aaa')) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (upper(concat(upper(a.`Title`), 'aaa')) = a__Type.`Name`) - } - [Fact] - public void Substring() - { - var data = new List(); - data.Add(select.Where(a => a.Title.Substring(0) == "aaa").ToList()); - data.Add(select.Where(a => a.Title.Substring(0) == a.Title).ToList()); - data.Add(select.Where(a => a.Title.Substring(0) == (a.Title + 1)).ToList()); - data.Add(select.Where(a => a.Title.Substring(0) == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (substr(a.`Title`, 1) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (substr(a.`Title`, 1) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (substr(a.`Title`, 1) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (substr(a.`Title`, 1) = a__Type.`Name`); - data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(a.Title.Length) == "aaa").ToList()); - data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(0, a.Title.Length) == a.Title).ToList()); - data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(0, 3) == (a.Title + 1)).ToList()); - data.Add(select.Where(a => (a.Title.Substring(0) + "aaa").Substring(1, 2) == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), char_length(a.`Title`) + 1) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), 1, char_length(a.`Title`)) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), 1, 3) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (substr(concat(substr(a.`Title`, 1), 'aaa'), 2, 2) = a__Type.`Name`) - } - [Fact] - public void Length() - { - var data = new List(); - data.Add(select.Where(a => a.Title.Length == 0).ToList()); - data.Add(select.Where(a => a.Title.Length == 1).ToList()); - data.Add(select.Where(a => a.Title.Length == a.Title.Length + 1).ToList()); - data.Add(select.Where(a => a.Title.Length == a.Type.Name.Length).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (char_length(a.`Title`) = 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (char_length(a.`Title`) = 1); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (char_length(a.`Title`) = char_length(a.`Title`) + 1); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (char_length(a.`Title`) = char_length(a__Type.`Name`)); - data.Add(select.Where(a => (a.Title + "aaa").Length == 0).ToList()); - data.Add(select.Where(a => (a.Title + "aaa").Length == 1).ToList()); - data.Add(select.Where(a => (a.Title + "aaa").Length == a.Title.Length + 1).ToList()); - data.Add(select.Where(a => (a.Title + "aaa").Length == a.Type.Name.Length).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (char_length(concat(a.`Title`, 'aaa')) = 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (char_length(concat(a.`Title`, 'aaa')) = 1); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (char_length(concat(a.`Title`, 'aaa')) = char_length(a.`Title`) + 1); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (char_length(concat(a.`Title`, 'aaa')) = char_length(a__Type.`Name`)) - } - [Fact] - public void IndexOf() - { - var data = new List(); - data.Add(select.Where(a => a.Title.IndexOf("aaa") == -1).ToList()); - data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == -1).ToList()); - data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == (a.Title.Length + 1)).ToList()); - data.Add(select.Where(a => a.Title.IndexOf("aaa", 2) == a.Type.Name.Length + 1).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((locate(a.`Title`, 'aaa') - 1) = -1); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((locate(a.`Title`, 'aaa', 3) - 1) = -1); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((locate(a.`Title`, 'aaa', 3) - 1) = char_length(a.`Title`) + 1); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE ((locate(a.`Title`, 'aaa', 3) - 1) = char_length(a__Type.`Name`) + 1); - data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa") == -1).ToList()); - data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == -1).ToList()); - data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == (a.Title.Length + 1)).ToList()); - data.Add(select.Where(a => (a.Title + "aaa").IndexOf("aaa", 2) == a.Type.Name.Length + 1).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa') - 1) = -1); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa', 3) - 1) = -1); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa', 3) - 1) = char_length(a.`Title`) + 1); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE ((locate(concat(a.`Title`, 'aaa'), 'aaa', 3) - 1) = char_length(a__Type.`Name`) + 1) - } - [Fact] - public void PadLeft() - { - var data = new List(); - data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == "aaa").ToList()); - data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == a.Title).ToList()); - data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (lpad(a.`Title`, 10, 'a') = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (lpad(a.`Title`, 10, 'a') = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (lpad(a.`Title`, 10, 'a') = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (lpad(a.`Title`, 10, 'a') = a__Type.`Name`); - data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == "aaa").ToList()); - data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == a.Title).ToList()); - data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a__Type.`Name`) - } - [Fact] - public void PadRight() - { - var data = new List(); - data.Add(select.Where(a => a.Title.PadRight(10, 'a') == "aaa").ToList()); - data.Add(select.Where(a => a.Title.PadRight(10, 'a') == a.Title).ToList()); - data.Add(select.Where(a => a.Title.PadRight(10, 'a') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => a.Title.PadRight(10, 'a') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (rpad(a.`Title`, 10, 'a') = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (rpad(a.`Title`, 10, 'a') = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (rpad(a.`Title`, 10, 'a') = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (rpad(a.`Title`, 10, 'a') = a__Type.`Name`); - data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == "aaa").ToList()); - data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == a.Title).ToList()); - data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a__Type.`Name`) - } - [Fact] - public void Trim() - { - var data = new List(); - data.Add(select.Where(a => a.Title.Trim() == "aaa").ToList()); - data.Add(select.Where(a => a.Title.Trim('a') == a.Title).ToList()); - data.Add(select.Where(a => a.Title.Trim('a', 'b') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => a.Title.Trim('a', 'b', 'c') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim(a.`Title`) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim('a' from a.`Title`) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim('b' from trim('a' from a.`Title`)) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (trim('c' from trim('b' from trim('a' from a.`Title`))) = a__Type.`Name`); - data.Add(select.Where(a => (a.Title.Trim() + "aaa").Trim() == "aaa").ToList()); - data.Add(select.Where(a => (a.Title.Trim('a') + "aaa").Trim('a') == a.Title).ToList()); - data.Add(select.Where(a => (a.Title.Trim('a', 'b') + "aaa").Trim('a', 'b') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => (a.Title.Trim('a', 'b', 'c') + "aaa").Trim('a', 'b', 'c') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim(concat(trim(a.`Title`), 'aaa')) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim('a' from concat(trim('a' from a.`Title`), 'aaa')) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim('b' from trim('a' from concat(trim('b' from trim('a' from a.`Title`)), 'aaa'))) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (trim('c' from trim('b' from trim('a' from concat(trim('c' from trim('b' from trim('a' from a.`Title`))), 'aaa')))) = a__Type.`Name`) - } - [Fact] - public void TrimStart() - { - var data = new List(); - data.Add(select.Where(a => a.Title.TrimStart() == "aaa").ToList()); - data.Add(select.Where(a => a.Title.TrimStart('a') == a.Title).ToList()); - data.Add(select.Where(a => a.Title.TrimStart('a', 'b') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => a.Title.TrimStart('a', 'b', 'c') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (ltrim(a.`Title`) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim(trailing 'a' from trim(leading 'a' from a.`Title`)) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (trim(trailing 'c' from trim(leading 'c' from trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))))) = a__Type.`Name`); - data.Add(select.Where(a => (a.Title.TrimStart() + "aaa").TrimStart() == "aaa").ToList()); - data.Add(select.Where(a => (a.Title.TrimStart('a') + "aaa").TrimStart('a') == a.Title).ToList()); - data.Add(select.Where(a => (a.Title.TrimStart('a', 'b') + "aaa").TrimStart('a', 'b') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => (a.Title.TrimStart('a', 'b', 'c') + "aaa").TrimStart('a', 'b', 'c') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (ltrim(concat(ltrim(a.`Title`), 'aaa')) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim(trailing 'a' from trim(leading 'a' from concat(trim(trailing 'a' from trim(leading 'a' from a.`Title`)), 'aaa'))) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from concat(trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))), 'aaa'))))) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (trim(trailing 'c' from trim(leading 'c' from trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from concat(trim(trailing 'c' from trim(leading 'c' from trim(trailing 'b' from trim(leading 'b' from trim(trailing 'a' from trim(leading 'a' from a.`Title`)))))), 'aaa'))))))) = a__Type.`Name`) - } - [Fact] - public void TrimEnd() - { - var data = new List(); - data.Add(select.Where(a => a.Title.TrimEnd() == "aaa").ToList()); - data.Add(select.Where(a => a.Title.TrimEnd('a') == a.Title).ToList()); - data.Add(select.Where(a => a.Title.TrimEnd('a', 'b') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => a.Title.TrimEnd('a', 'b', 'c') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (rtrim(a.`Title`) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim(trailing 'a' from a.`Title`) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim(trailing 'b' from trim(trailing 'a' from a.`Title`)) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (trim(trailing 'c' from trim(trailing 'b' from trim(trailing 'a' from a.`Title`))) = a__Type.`Name`); - data.Add(select.Where(a => (a.Title.TrimEnd() + "aaa").TrimEnd() == "aaa").ToList()); - data.Add(select.Where(a => (a.Title.TrimEnd('a') + "aaa").TrimEnd('a') == a.Title).ToList()); - data.Add(select.Where(a => (a.Title.TrimEnd('a', 'b') + "aaa").TrimEnd('a', 'b') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => (a.Title.TrimEnd('a', 'b', 'c') + "aaa").TrimEnd('a', 'b', 'c') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (rtrim(concat(rtrim(a.`Title`), 'aaa')) = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim(trailing 'a' from concat(trim(trailing 'a' from a.`Title`), 'aaa')) = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (trim(trailing 'b' from trim(trailing 'a' from concat(trim(trailing 'b' from trim(trailing 'a' from a.`Title`)), 'aaa'))) = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (trim(trailing 'c' from trim(trailing 'b' from trim(trailing 'a' from concat(trim(trailing 'c' from trim(trailing 'b' from trim(trailing 'a' from a.`Title`))), 'aaa')))) = a__Type.`Name`) - } - [Fact] - public void Replace() - { - var data = new List(); - data.Add(select.Where(a => a.Title.Replace("a", "b") == "aaa").ToList()); - data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c") == a.Title).ToList()); - data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c").Replace("c", "a") == (a.Title + 1)).ToList()); - data.Add(select.Where(a => a.Title.Replace("a", "b").Replace("b", "c").Replace(a.Type.Name, "a") == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (replace(a.`Title`, 'a', 'b') = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (replace(replace(a.`Title`, 'a', 'b'), 'b', 'c') = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), 'c', 'a') = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), a__Type.`Name`, 'a') = a__Type.`Name`); - data.Add(select.Where(a => (a.Title.Replace("a", "b") + "aaa").TrimEnd() == "aaa").ToList()); - data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c") + "aaa").TrimEnd('a') == a.Title).ToList()); - data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c").Replace("c", "a") + "aaa").TrimEnd('a', 'b') == (a.Title + 1)).ToList()); - data.Add(select.Where(a => (a.Title.Replace("a", "b").Replace("b", "c").Replace(a.Type.Name, "a") + "aaa").TrimEnd('a', 'b', 'c') == a.Type.Name).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (concat(replace(a.`Title`, 'a', 'b'), 'aaa') = 'aaa'); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (concat(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), 'aaa') = a.`Title`); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (concat(replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), 'c', 'a'), 'aaa') = concat(a.`Title`, 1)); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (concat(replace(replace(replace(a.`Title`, 'a', 'b'), 'b', 'c'), a__Type.`Name`, 'a'), 'aaa') = a__Type.`Name`) - } - [Fact] - public void CompareTo() - { - var data = new List(); - data.Add(select.Where(a => a.Title.CompareTo(a.Title) == 0).ToList()); - data.Add(select.Where(a => a.Title.CompareTo(a.Title) > 0).ToList()); - data.Add(select.Where(a => a.Title.CompareTo(a.Title + 1) == 0).ToList()); - data.Add(select.Where(a => a.Title.CompareTo(a.Title + a.Type.Name) == 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (strcmp(a.`Title`, a.`Title`) = 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (strcmp(a.`Title`, a.`Title`) > 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (strcmp(a.`Title`, concat(a.`Title`, 1)) = 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (strcmp(a.`Title`, concat(a.`Title`, a__Type.`Name`)) = 0); - data.Add(select.Where(a => (a.Title + "aaa").CompareTo("aaa") == 0).ToList()); - data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Title) > 0).ToList()); - data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Title + 1) == 0).ToList()); - data.Add(select.Where(a => (a.Title + "aaa").CompareTo(a.Type.Name) == 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (strcmp(concat(a.`Title`, 'aaa'), 'aaa') = 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (strcmp(concat(a.`Title`, 'aaa'), a.`Title`) > 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (strcmp(concat(a.`Title`, 'aaa'), concat(a.`Title`, 1)) = 0); - - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a.`Title` as7, a.`CreateTime` as8 - //FROM `tb_topic` a, `TestTypeInfo` a__Type - //WHERE (strcmp(concat(a.`Title`, 'aaa'), a__Type.`Name`) = 0) - } - - [Fact] - public void string_IsNullOrEmpty() - { - var data = new List(); - data.Add(select.Where(a => string.IsNullOrEmpty(a.Title)).ToList()); - data.Add(select.Where(a => !string.IsNullOrEmpty(a.Title)).ToList()); - } - - [Fact] - public void string_IsNullOrWhiteSpace() - { - var data = new List(); - data.Add(select.Where(a => string.IsNullOrWhiteSpace(a.Title)).ToList()); - data.Add(select.Where(a => !string.IsNullOrWhiteSpace(a.Title)).ToList()); - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/TimeSpanTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/TimeSpanTest.cs deleted file mode 100644 index c21162ff4..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/KingbaseESExpression/TimeSpanTest.cs +++ /dev/null @@ -1,293 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseESExpression -{ - public class TimeSpanTest - { - - ISelect select => g.kingbaseES.Select(); - - [Table(Name = "tb_topic")] - class Topic - { - [Column(IsIdentity = true, IsPrimary = true)] - public int Id { get; set; } - public int Clicks { get; set; } - public int TypeGuid { get; set; } - public TestTypeInfo Type { get; set; } - public string Title { get; set; } - public DateTime CreateTime { get; set; } - } - class TestTypeInfo - { - public int Guid { get; set; } - public int ParentId { get; set; } - public TestTypeParentInfo Parent { get; set; } - public string Name { get; set; } - } - class TestTypeParentInfo - { - public int Id { get; set; } - public string Name { get; set; } - - public List Types { get; set; } - } - [Fact] - public void Zero() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay > TimeSpan.Zero).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) > 0) - } - [Fact] - public void MinValue() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay > TimeSpan.MinValue).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) > -922337203685477580) - } - [Fact] - public void MaxValue() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay < TimeSpan.MaxValue).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) < 922337203685477580) - } - [Fact] - public void Days() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.Days == 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 86400000000) = 0) - } - [Fact] - public void Hours() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.Hours > 0).ToSql()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 3600000000) mod 24 > 0) - } - [Fact] - public void Milliseconds() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.Milliseconds > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 1000 mod 1000) > 0) - } - [Fact] - public void Minutes() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.Minutes > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 60000000 mod 60) > 0) - } - [Fact] - public void Seconds() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.Seconds > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) div 1000000 mod 60) > 0) - } - [Fact] - public void Ticks() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.Ticks > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) * 10) > 0) - } - [Fact] - public void TotalDays() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalDays > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 86400000000) > 0) - } - [Fact] - public void TotalHours() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalHours > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 3600000000) > 0) - } - [Fact] - public void TotalMilliseconds() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalMilliseconds > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 1000) > 0) - } - [Fact] - public void TotalMinutes() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalMinutes > 0).ToSql()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 60000000) > 0) - } - [Fact] - public void TotalSeconds() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.TotalSeconds > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) / 1000000) > 0) - } - [Fact] - public void Add() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.Add(TimeSpan.FromDays(1)) > TimeSpan.Zero).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) + (1 * 86400000000)) > 0) - } - [Fact] - public void Subtract() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.Subtract(TimeSpan.FromDays(1)) > TimeSpan.Zero).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) - (1 * 86400000000)) > 0) - } - [Fact] - public void CompareTo() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.CompareTo(TimeSpan.FromDays(1)) > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) - ((1 * 86400000000))) > 0) - } - [Fact] - public void this_Equals() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.Equals(TimeSpan.FromDays(1))).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 86400000000))) - } - [Fact] - public void this_ToString() - { - var data = new List(); - data.Add(select.Where(a => a.CreateTime.TimeOfDay.ToString() == "ssss").ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (date_format(date_add(cast('0001/1/1 0:00:00' as datetime), interval (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) microsecond), '%Y-%m-%d %H:%i:%s.%f') = 'ssss') - } - - [Fact] - public void TimeSpan_Compare() - { - var data = new List(); - data.Add(select.Where(a => TimeSpan.Compare(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1)) > 0).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) - ((1 * 86400000000))) > 0) - } - [Fact] - public void TimeSpan_Equals() - { - var data = new List(); - data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1))).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 86400000000))) - } - [Fact] - public void TimeSpan_FromDays() - { - var data = new List(); - data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromDays(1))).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 86400000000))) - } - [Fact] - public void TimeSpan_FromHours() - { - var data = new List(); - data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromHours(1))).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 3600000000))) - } - [Fact] - public void TimeSpan_FromMilliseconds() - { - var data = new List(); - data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromMilliseconds(1))).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 1000))) - } - [Fact] - public void TimeSpan_FromMinutes() - { - var data = new List(); - data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromMinutes(1))).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 60000000))) - } - [Fact] - public void TimeSpan_FromSeconds() - { - var data = new List(); - data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromSeconds(1))).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 * 1000000))) - } - [Fact] - public void TimeSpan_FromTicks() - { - var data = new List(); - data.Add(select.Where(a => TimeSpan.Equals(a.CreateTime.TimeOfDay, TimeSpan.FromTicks(1))).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE ((timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000) = (1 / 10))) - } - [Fact] - public void TimeSpan_Parse() - { - var data = new List(); - data.Add(select.Where(a => TimeSpan.Parse(a.CreateTime.TimeOfDay.ToString()) > TimeSpan.Zero).ToList()); - //SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5 - //FROM `tb_topic` a - //WHERE (cast(date_format(date_add(cast('0001/1/1 0:00:00' as datetime), interval (timestampdiff(microsecond, date_format(a.`CreateTime`, '1970-1-1 %H:%i:%s.%f'), a.`CreateTime`) + 62135596800000000)) microsecond), '%Y-%m-%d %H:%i:%s.%f') as signed) > 0) - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/MapType/BoolNullableTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/MapType/BoolNullableTest.cs deleted file mode 100644 index 0f5935f70..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/MapType/BoolNullableTest.cs +++ /dev/null @@ -1,1571 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseESMapType -{ - public class BoolNullableTest - { - class BoolNullableMap - { - public Guid id { get; set; } - [Column(MapType = typeof(bool))] - public bool? tobool { get; set; } = true; - - [Column(MapType = typeof(sbyte))] - public bool? tosbyte { get; set; } = true; - [Column(MapType = typeof(sbyte?))] - public bool? tosbytenullable { get; set; } = true; - - [Column(MapType = typeof(short))] - public bool? toshort { get; set; } = true; - - [Column(MapType = typeof(short?))] - public bool? toshortnullable { get; set; } = true; - - [Column(MapType = typeof(int))] - public bool? toint { get; set; } = true; - - [Column(MapType = typeof(int?))] - public bool? tointnullable { get; set; } = true; - - [Column(MapType = typeof(long))] - public bool? tolong { get; set; } = true; - [Column(MapType = typeof(long?))] - public bool? tolongnullable { get; set; } = true; - - [Column(MapType = typeof(byte))] - public bool? tobyte { get; set; } = true; - [Column(MapType = typeof(byte?))] - public bool? tobytenullable { get; set; } = true; - - [Column(MapType = typeof(ushort))] - public bool? toushort { get; set; } = true; - - [Column(MapType = typeof(ushort?))] - public bool? toushortnullable { get; set; } = true; - - [Column(MapType = typeof(uint))] - public bool? touint { get; set; } = true; - - [Column(MapType = typeof(uint?))] - public bool? touintnullable { get; set; } = true; - - [Column(MapType = typeof(ulong))] - public bool? toulong { get; set; } = true; - [Column(MapType = typeof(ulong?))] - public bool? toulongnullable { get; set; } = true; - - [Column(MapType = typeof(string))] - public bool? tostring { get; set; } = true; - } - [Fact] - public void Bool() - { - //insert - var orm = g.kingbaseES; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tobool == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobool, find.tobool); - Assert.Equal(true, find.tobool); - - item = new BoolNullableMap { tobool = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobool == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobool, find.tobool); - Assert.Equal(false, find.tobool); - - item = new BoolNullableMap { tobool = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tobool == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tobool == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.tobool, find.tobool); - Assert.Equal(false, find.tobool); - - //update all - item.tobool = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobool == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobool, find.tobool); - Assert.Equal(true, find.tobool); - - item.tobool = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobool == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobool, find.tobool); - Assert.Equal(false, find.tobool); - - item.tobool = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tobool == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tobool == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.tobool, find.tobool); - Assert.Equal(false, find.tobool); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobool, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobool == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.tobool); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobool, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobool == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tobool); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobool, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tobool == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tobool == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tobool); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tobool == true).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tobool == null).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tobool == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void SByte() - { - //insert - var orm = g.kingbaseES; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tosbyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbyte, find.tosbyte); - Assert.Equal(true, find.tosbyte); - - item = new BoolNullableMap { tosbyte = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbyte, find.tosbyte); - Assert.Equal(false, find.tosbyte); - - item = new BoolNullableMap { tosbyte = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tosbyte == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.tosbyte, find.tosbyte); - Assert.Equal(false, find.tosbyte); - - //update all - item.tosbyte = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbyte, find.tosbyte); - Assert.Equal(true, find.tosbyte); - - item.tosbyte = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbyte, find.tosbyte); - Assert.Equal(false, find.tosbyte); - - item.tosbyte = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tosbyte == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.tosbyte, find.tosbyte); - Assert.Equal(false, find.tosbyte); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tosbyte, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.tosbyte); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tosbyte, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tosbyte); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tosbyte, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tosbyte == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tosbyte); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tosbyte == true).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tosbyte == null).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tosbyte == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void SByteNullable() - { - //insert - var orm = g.kingbaseES; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbytenullable, find.tosbytenullable); - Assert.Equal(true, find.tosbytenullable); - - item = new BoolNullableMap { tosbytenullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbytenullable, find.tosbytenullable); - Assert.Equal(false, find.tosbytenullable); - - item = new BoolNullableMap { tosbytenullable = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tosbytenullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbytenullable, find.tosbytenullable); - Assert.Null(find.tosbytenullable); - - //update all - item.tosbytenullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbytenullable, find.tosbytenullable); - Assert.Equal(true, find.tosbytenullable); - - item.tosbytenullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbytenullable, find.tosbytenullable); - Assert.Equal(false, find.tosbytenullable); - - item.tosbytenullable = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tosbytenullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbytenullable, find.tosbytenullable); - Assert.Null(find.tosbytenullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tosbytenullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.tosbytenullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tosbytenullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tosbytenullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tosbytenullable, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tosbytenullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.tosbytenullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tosbytenullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tosbytenullable == null).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tosbytenullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void Short() - { - //insert - var orm = g.kingbaseES; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toshort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshort, find.toshort); - Assert.Equal(true, find.toshort); - - item = new BoolNullableMap { toshort = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshort, find.toshort); - Assert.Equal(false, find.toshort); - - item = new BoolNullableMap { toshort = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toshort == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.toshort, find.toshort); - Assert.Equal(false, find.toshort); - - //update all - item.toshort = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshort, find.toshort); - Assert.Equal(true, find.toshort); - - item.toshort = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshort, find.toshort); - Assert.Equal(false, find.toshort); - - item.toshort = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toshort == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.toshort, find.toshort); - Assert.Equal(false, find.toshort); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toshort, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.toshort); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toshort, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toshort); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toshort, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toshort == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toshort); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toshort == true).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toshort == null).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toshort == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void ShortNullable() - { - //insert - var orm = g.kingbaseES; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshortnullable, find.toshortnullable); - Assert.Equal(true, find.toshortnullable); - - item = new BoolNullableMap { toshortnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshortnullable, find.toshortnullable); - Assert.Equal(false, find.toshortnullable); - - item = new BoolNullableMap { toshortnullable = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toshortnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshortnullable, find.toshortnullable); - Assert.Null(find.toshortnullable); - - //update all - item.toshortnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshortnullable, find.toshortnullable); - Assert.Equal(true, find.toshortnullable); - - item.toshortnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshortnullable, find.toshortnullable); - Assert.Equal(false, find.toshortnullable); - - item.toshortnullable = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toshortnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshortnullable, find.toshortnullable); - Assert.Null(find.toshortnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toshortnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.toshortnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toshortnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toshortnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toshortnullable, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toshortnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.toshortnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toshortnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toshortnullable == null).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toshortnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void Int() - { - //insert - var orm = g.kingbaseES; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toint, find.toint); - Assert.Equal(true, find.toint); - - item = new BoolNullableMap { toint = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toint, find.toint); - Assert.Equal(false, find.toint); - - item = new BoolNullableMap { toint = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toint == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.toint, find.toint); - Assert.Equal(false, find.toint); - - //update all - item.toint = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toint, find.toint); - Assert.Equal(true, find.toint); - - item.toint = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toint, find.toint); - Assert.Equal(false, find.toint); - - item.toint = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toint == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.toint, find.toint); - Assert.Equal(false, find.toint); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toint, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.toint); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toint, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toint); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toint, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toint == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toint); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toint == true).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toint == null).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toint == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void IntNullable() - { - //insert - var orm = g.kingbaseES; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tointnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tointnullable, find.tointnullable); - Assert.Equal(true, find.tointnullable); - - item = new BoolNullableMap { tointnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tointnullable, find.tointnullable); - Assert.Equal(false, find.tointnullable); - - item = new BoolNullableMap { tointnullable = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tointnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tointnullable, find.tointnullable); - Assert.Null(find.tointnullable); - - //update all - item.tointnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tointnullable, find.tointnullable); - Assert.Equal(true, find.tointnullable); - - item.tointnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tointnullable, find.tointnullable); - Assert.Equal(false, find.tointnullable); - - item.tointnullable = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tointnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tointnullable, find.tointnullable); - Assert.Null(find.tointnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tointnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.tointnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tointnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tointnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tointnullable, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tointnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.tointnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tointnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tointnullable == null).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tointnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void Long() - { - //insert - var orm = g.kingbaseES; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tolong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolong, find.tolong); - Assert.Equal(true, find.tolong); - - item = new BoolNullableMap { tolong = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolong, find.tolong); - Assert.Equal(false, find.tolong); - - item = new BoolNullableMap { tolong = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tolong == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.tolong, find.tolong); - Assert.Equal(false, find.tolong); - - //update all - item.tolong = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolong, find.tolong); - Assert.Equal(true, find.tolong); - - item.tolong = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolong, find.tolong); - Assert.Equal(false, find.tolong); - - item.tolong = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tolong == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.tolong, find.tolong); - Assert.Equal(false, find.tolong); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tolong, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.tolong); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tolong, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tolong); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tolong, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tolong == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tolong); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tolong == true).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tolong == null).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tolong == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void LongNullable() - { - //insert - var orm = g.kingbaseES; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolongnullable, find.tolongnullable); - Assert.Equal(true, find.tolongnullable); - - item = new BoolNullableMap { tolongnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolongnullable, find.tolongnullable); - Assert.Equal(false, find.tolongnullable); - - item = new BoolNullableMap { tolongnullable = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tolongnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolongnullable, find.tolongnullable); - Assert.Null(find.tolongnullable); - - //update all - item.tolongnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolongnullable, find.tolongnullable); - Assert.Equal(true, find.tolongnullable); - - item.tolongnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolongnullable, find.tolongnullable); - Assert.Equal(false, find.tolongnullable); - - item.tolongnullable = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tolongnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolongnullable, find.tolongnullable); - Assert.Null(find.tolongnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tolongnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.tolongnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tolongnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tolongnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tolongnullable, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tolongnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.tolongnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tolongnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tolongnullable == null).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tolongnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - - [Fact] - public void Byte() - { - //insert - var orm = g.kingbaseES; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tobyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobyte, find.tobyte); - Assert.Equal(true, find.tobyte); - - item = new BoolNullableMap { tobyte = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobyte, find.tobyte); - Assert.Equal(false, find.tobyte); - - item = new BoolNullableMap { tobyte = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tobyte == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.tobyte, find.tobyte); - Assert.Equal(false, find.tobyte); - - //update all - item.tobyte = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobyte, find.tobyte); - Assert.Equal(true, find.tobyte); - - item.tobyte = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobyte, find.tobyte); - Assert.Equal(false, find.tobyte); - - item.tobyte = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tobyte == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.tobyte, find.tobyte); - Assert.Equal(false, find.tobyte); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobyte, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.tobyte); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobyte, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tobyte); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobyte, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tobyte == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tobyte); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tobyte == true).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tobyte == null).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tobyte == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void ByteNullable() - { - //insert - var orm = g.kingbaseES; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobytenullable, find.tobytenullable); - Assert.Equal(true, find.tobytenullable); - - item = new BoolNullableMap { tobytenullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobytenullable, find.tobytenullable); - Assert.Equal(false, find.tobytenullable); - - item = new BoolNullableMap { tobytenullable = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tobytenullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobytenullable, find.tobytenullable); - Assert.Null(find.tobytenullable); - - //update all - item.tobytenullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobytenullable, find.tobytenullable); - Assert.Equal(true, find.tobytenullable); - - item.tobytenullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobytenullable, find.tobytenullable); - Assert.Equal(false, find.tobytenullable); - - item.tobytenullable = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tobytenullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobytenullable, find.tobytenullable); - Assert.Null(find.tobytenullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobytenullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.tobytenullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobytenullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tobytenullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobytenullable, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tobytenullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.tobytenullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tobytenullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tobytenullable == null).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tobytenullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void UShort() - { - //insert - var orm = g.kingbaseES; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toushort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushort, find.toushort); - Assert.Equal(true, find.toushort); - - item = new BoolNullableMap { toushort = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushort, find.toushort); - Assert.Equal(false, find.toushort); - - item = new BoolNullableMap { toushort = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toushort == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.toushort, find.toushort); - Assert.Equal(false, find.toushort); - - //update all - item.toushort = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushort, find.toushort); - Assert.Equal(true, find.toushort); - - item.toushort = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushort, find.toushort); - Assert.Equal(false, find.toushort); - - item.toushort = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toushort == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.toushort, find.toushort); - Assert.Equal(false, find.toushort); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toushort, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.toushort); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toushort, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toushort); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toushort, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toushort == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toushort); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toushort == true).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toushort == null).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toushort == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void UShortNullable() - { - //insert - var orm = g.kingbaseES; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushortnullable, find.toushortnullable); - Assert.Equal(true, find.toushortnullable); - - item = new BoolNullableMap { toushortnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushortnullable, find.toushortnullable); - Assert.Equal(false, find.toushortnullable); - - item = new BoolNullableMap { toushortnullable = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toushortnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushortnullable, find.toushortnullable); - Assert.Null(find.toushortnullable); - - //update all - item.toushortnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushortnullable, find.toushortnullable); - Assert.Equal(true, find.toushortnullable); - - item.toushortnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushortnullable, find.toushortnullable); - Assert.Equal(false, find.toushortnullable); - - item.toushortnullable = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toushortnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushortnullable, find.toushortnullable); - Assert.Null(find.toushortnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toushortnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.toushortnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toushortnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toushortnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toushortnullable, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toushortnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.toushortnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toushortnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toushortnullable == null).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toushortnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void UInt() - { - //insert - var orm = g.kingbaseES; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.touint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touint, find.touint); - Assert.Equal(true, find.touint); - - item = new BoolNullableMap { touint = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touint, find.touint); - Assert.Equal(false, find.touint); - - item = new BoolNullableMap { touint = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.touint == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.touint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.touint, find.touint); - Assert.Equal(false, find.touint); - - //update all - item.touint = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touint, find.touint); - Assert.Equal(true, find.touint); - - item.touint = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touint, find.touint); - Assert.Equal(false, find.touint); - - item.touint = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.touint == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.touint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.touint, find.touint); - Assert.Equal(false, find.touint); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.touint, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.touint); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.touint, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.touint); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.touint, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.touint == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.touint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.touint); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.touint == true).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.touint == null).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.touint == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void UIntNullable() - { - //insert - var orm = g.kingbaseES; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.touintnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touintnullable, find.touintnullable); - Assert.Equal(true, find.touintnullable); - - item = new BoolNullableMap { touintnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touintnullable, find.touintnullable); - Assert.Equal(false, find.touintnullable); - - item = new BoolNullableMap { touintnullable = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.touintnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touintnullable, find.touintnullable); - Assert.Null(find.touintnullable); - - //update all - item.touintnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touintnullable, find.touintnullable); - Assert.Equal(true, find.touintnullable); - - item.touintnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touintnullable, find.touintnullable); - Assert.Equal(false, find.touintnullable); - - item.touintnullable = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.touintnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touintnullable, find.touintnullable); - Assert.Null(find.touintnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.touintnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.touintnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.touintnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.touintnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.touintnullable, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.touintnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.touintnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.touintnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.touintnullable == null).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.touintnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void ULong() - { - //insert - var orm = g.kingbaseES; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toulong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulong, find.toulong); - Assert.Equal(true, find.toulong); - - item = new BoolNullableMap { toulong = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulong, find.toulong); - Assert.Equal(false, find.toulong); - - item = new BoolNullableMap { toulong = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toulong == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.toulong, find.toulong); - Assert.Equal(false, find.toulong); - - //update all - item.toulong = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulong, find.toulong); - Assert.Equal(true, find.toulong); - - item.toulong = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulong, find.toulong); - Assert.Equal(false, find.toulong); - - item.toulong = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toulong == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.NotEqual(item.toulong, find.toulong); - Assert.Equal(false, find.toulong); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toulong, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.toulong); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toulong, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toulong); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toulong, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toulong == null).First()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toulong); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toulong == true).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toulong == null).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toulong == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void ULongNullable() - { - //insert - var orm = g.kingbaseES; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulongnullable, find.toulongnullable); - Assert.Equal(true, find.toulongnullable); - - item = new BoolNullableMap { toulongnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulongnullable, find.toulongnullable); - Assert.Equal(false, find.toulongnullable); - - item = new BoolNullableMap { toulongnullable = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toulongnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulongnullable, find.toulongnullable); - Assert.Null(find.toulongnullable); - - //update all - item.toulongnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulongnullable, find.toulongnullable); - Assert.Equal(true, find.toulongnullable); - - item.toulongnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulongnullable, find.toulongnullable); - Assert.Equal(false, find.toulongnullable); - - item.toulongnullable = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toulongnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulongnullable, find.toulongnullable); - Assert.Null(find.toulongnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toulongnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.toulongnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toulongnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.toulongnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toulongnullable, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.toulongnullable == false).First()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.toulongnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toulongnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toulongnullable == null).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toulongnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - - [Fact] - public void TimeSpan() - { - } - [Fact] - public void TimeSpanNullable() - { - } - [Fact] - public void DateTime() - { - } - [Fact] - public void DateTimeNullable() - { - } - - [Fact] - public void ByteArray() - { - } - [Fact] - public void String() - { - //insert - var orm = g.kingbaseES; - var item = new BoolNullableMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tostring == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tostring, find.tostring); - Assert.Equal(true, find.tostring); - - item = new BoolNullableMap { tostring = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tostring == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tostring, find.tostring); - Assert.Equal(false, find.tostring); - - item = new BoolNullableMap { tostring = null }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tostring == false).First()); - find = orm.Select().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().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tostring == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tostring, find.tostring); - Assert.Equal(true, find.tostring); - - item.tostring = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tostring == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tostring, find.tostring); - Assert.Equal(false, find.tostring); - - item.tostring = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tostring == false).First()); - find = orm.Select().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().Where(a => a.id == item.id).Set(a => a.tostring, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tostring == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(true, find.tostring); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tostring, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tostring == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(false, find.tostring); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tostring, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.tostring == false).First()); - find = orm.Select().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().Where(a => a.id == item.id && a.tostring == true).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tostring == false).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tostring == null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - - [Fact] - public void Guid() - { - } - [Fact] - public void GuidNullable() - { - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/MapType/BoolTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/MapType/BoolTest.cs deleted file mode 100644 index 76a274422..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/MapType/BoolTest.cs +++ /dev/null @@ -1,1105 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseESMapType -{ - public class BoolTest - { - - class BoolMap - { - public Guid id { get; set; } - [Column(MapType = typeof(bool?))] - public bool toboolnullable { get; set; } = true; - - [Column(MapType = typeof(sbyte))] - public bool tosbyte { get; set; } = true; - [Column(MapType = typeof(sbyte?))] - public bool tosbytenullable { get; set; } = true; - - [Column(MapType = typeof(short))] - public bool toshort { get; set; } = true; - - [Column(MapType = typeof(short?))] - public bool toshortnullable { get; set; } = true; - - [Column(MapType = typeof(int))] - public bool toint { get; set; } = true; - - [Column(MapType = typeof(int?))] - public bool tointnullable { get; set; } = true; - - [Column(MapType = typeof(long))] - public bool tolong { get; set; } = true; - [Column(MapType = typeof(long?))] - public bool tolongnullable { get; set; } = true; - - [Column(MapType = typeof(byte))] - public bool tobyte { get; set; } = true; - [Column(MapType = typeof(byte?))] - public bool tobytenullable { get; set; } = true; - - [Column(MapType = typeof(ushort))] - public bool toushort { get; set; } = true; - - [Column(MapType = typeof(ushort?))] - public bool toushortnullable { get; set; } = true; - - [Column(MapType = typeof(uint))] - public bool touint { get; set; } = true; - - [Column(MapType = typeof(uint?))] - public bool touintnullable { get; set; } = true; - - [Column(MapType = typeof(ulong))] - public bool toulong { get; set; } = true; - [Column(MapType = typeof(ulong?))] - public bool toulongnullable { get; set; } = true; - - [Column(MapType = typeof(string))] - public bool tostring { get; set; } = true; - } - - [Fact] - public void BoolNullable() - { - //insert - var orm = g.kingbaseES; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toboolnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toboolnullable, find.toboolnullable); - Assert.True(find.toboolnullable); - - item = new BoolMap { toboolnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toboolnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toboolnullable, find.toboolnullable); - Assert.False(find.toboolnullable); - - //update all - item.toboolnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toboolnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toboolnullable, find.toboolnullable); - Assert.True(find.toboolnullable); - - item.toboolnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toboolnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toboolnullable, find.toboolnullable); - Assert.False(find.toboolnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toboolnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toboolnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.toboolnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toboolnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toboolnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.toboolnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toboolnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toboolnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void SByte() - { - //insert - var orm = g.kingbaseES; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tosbyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbyte, find.tosbyte); - Assert.True(find.tosbyte); - - item = new BoolMap { tosbyte = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbyte, find.tosbyte); - Assert.False(find.tosbyte); - - //update all - item.tosbyte = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbyte, find.tosbyte); - Assert.True(find.tosbyte); - - item.tosbyte = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbyte, find.tosbyte); - Assert.False(find.tosbyte); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tosbyte, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.tosbyte); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tosbyte, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.tosbyte); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tosbyte == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tosbyte == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void SByteNullable() - { - //insert - var orm = g.kingbaseES; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbytenullable, find.tosbytenullable); - Assert.True(find.tosbytenullable); - - item = new BoolMap { tosbytenullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbytenullable, find.tosbytenullable); - Assert.False(find.tosbytenullable); - - //update all - item.tosbytenullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbytenullable, find.tosbytenullable); - Assert.True(find.tosbytenullable); - - item.tosbytenullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tosbytenullable, find.tosbytenullable); - Assert.False(find.tosbytenullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tosbytenullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.tosbytenullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tosbytenullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tosbytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.tosbytenullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tosbytenullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tosbytenullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void Short() - { - //insert - var orm = g.kingbaseES; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toshort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshort, find.toshort); - Assert.True(find.toshort); - - item = new BoolMap { toshort = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshort, find.toshort); - Assert.False(find.toshort); - - //update all - item.toshort = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshort, find.toshort); - Assert.True(find.toshort); - - item.toshort = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshort, find.toshort); - Assert.False(find.toshort); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toshort, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.toshort); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toshort, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.toshort); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toshort == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toshort == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void ShortNullable() - { - //insert - var orm = g.kingbaseES; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshortnullable, find.toshortnullable); - Assert.True(find.toshortnullable); - - item = new BoolMap { toshortnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshortnullable, find.toshortnullable); - Assert.False(find.toshortnullable); - - //update all - item.toshortnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshortnullable, find.toshortnullable); - Assert.True(find.toshortnullable); - - item.toshortnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toshortnullable, find.toshortnullable); - Assert.False(find.toshortnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toshortnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.toshortnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toshortnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toshortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.toshortnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toshortnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toshortnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void Int() - { - //insert - var orm = g.kingbaseES; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toint, find.toint); - Assert.True(find.toint); - - item = new BoolMap { toint = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toint, find.toint); - Assert.False(find.toint); - - //update all - item.toint = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toint, find.toint); - Assert.True(find.toint); - - item.toint = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toint, find.toint); - Assert.False(find.toint); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toint, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.toint); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toint, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.toint); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toint == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toint == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void IntNullable() - { - //insert - var orm = g.kingbaseES; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tointnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tointnullable, find.tointnullable); - Assert.True(find.tointnullable); - - item = new BoolMap { tointnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tointnullable, find.tointnullable); - Assert.False(find.tointnullable); - - //update all - item.tointnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tointnullable, find.tointnullable); - Assert.True(find.tointnullable); - - item.tointnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tointnullable, find.tointnullable); - Assert.False(find.tointnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tointnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.tointnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tointnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tointnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.tointnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tointnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tointnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void Long() - { - //insert - var orm = g.kingbaseES; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tolong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolong, find.tolong); - Assert.True(find.tolong); - - item = new BoolMap { tolong = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolong, find.tolong); - Assert.False(find.tolong); - - //update all - item.tolong = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolong, find.tolong); - Assert.True(find.tolong); - - item.tolong = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolong, find.tolong); - Assert.False(find.tolong); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tolong, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.tolong); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tolong, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.tolong); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tolong == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tolong == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void LongNullable() - { - //insert - var orm = g.kingbaseES; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolongnullable, find.tolongnullable); - Assert.True(find.tolongnullable); - - item = new BoolMap { tolongnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolongnullable, find.tolongnullable); - Assert.False(find.tolongnullable); - - //update all - item.tolongnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolongnullable, find.tolongnullable); - Assert.True(find.tolongnullable); - - item.tolongnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tolongnullable, find.tolongnullable); - Assert.False(find.tolongnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tolongnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.tolongnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tolongnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tolongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.tolongnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tolongnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tolongnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - - [Fact] - public void Byte() - { - //insert - var orm = g.kingbaseES; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tobyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobyte, find.tobyte); - Assert.True(find.tobyte); - - item = new BoolMap { tobyte = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobyte, find.tobyte); - Assert.False(find.tobyte); - - //update all - item.tobyte = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobyte, find.tobyte); - Assert.True(find.tobyte); - - item.tobyte = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobyte, find.tobyte); - Assert.False(find.tobyte); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobyte, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.tobyte); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobyte, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobyte == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.tobyte); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tobyte == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tobyte == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void ByteNullable() - { - //insert - var orm = g.kingbaseES; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobytenullable, find.tobytenullable); - Assert.True(find.tobytenullable); - - item = new BoolMap { tobytenullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobytenullable, find.tobytenullable); - Assert.False(find.tobytenullable); - - //update all - item.tobytenullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobytenullable, find.tobytenullable); - Assert.True(find.tobytenullable); - - item.tobytenullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tobytenullable, find.tobytenullable); - Assert.False(find.tobytenullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobytenullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.tobytenullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tobytenullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tobytenullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.tobytenullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tobytenullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tobytenullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void UShort() - { - //insert - var orm = g.kingbaseES; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toushort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushort, find.toushort); - Assert.True(find.toushort); - - item = new BoolMap { toushort = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushort, find.toushort); - Assert.False(find.toushort); - - //update all - item.toushort = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushort, find.toushort); - Assert.True(find.toushort); - - item.toushort = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushort, find.toushort); - Assert.False(find.toushort); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toushort, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.toushort); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toushort, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushort == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.toushort); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toushort == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toushort == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void UShortNullable() - { - //insert - var orm = g.kingbaseES; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushortnullable, find.toushortnullable); - Assert.True(find.toushortnullable); - - item = new BoolMap { toushortnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushortnullable, find.toushortnullable); - Assert.False(find.toushortnullable); - - //update all - item.toushortnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushortnullable, find.toushortnullable); - Assert.True(find.toushortnullable); - - item.toushortnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toushortnullable, find.toushortnullable); - Assert.False(find.toushortnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toushortnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.toushortnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toushortnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toushortnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.toushortnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toushortnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toushortnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void UInt() - { - //insert - var orm = g.kingbaseES; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.touint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touint, find.touint); - Assert.True(find.touint); - - item = new BoolMap { touint = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touint, find.touint); - Assert.False(find.touint); - - //update all - item.touint = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touint, find.touint); - Assert.True(find.touint); - - item.touint = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touint, find.touint); - Assert.False(find.touint); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.touint, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touint == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.touint); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.touint, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touint == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.touint); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.touint == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.touint == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void UIntNullable() - { - //insert - var orm = g.kingbaseES; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.touintnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touintnullable, find.touintnullable); - Assert.True(find.touintnullable); - - item = new BoolMap { touintnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touintnullable, find.touintnullable); - Assert.False(find.touintnullable); - - //update all - item.touintnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touintnullable, find.touintnullable); - Assert.True(find.touintnullable); - - item.touintnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.touintnullable, find.touintnullable); - Assert.False(find.touintnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.touintnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.touintnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.touintnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.touintnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.touintnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.touintnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.touintnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void ULong() - { - //insert - var orm = g.kingbaseES; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toulong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulong, find.toulong); - Assert.True(find.toulong); - - item = new BoolMap { toulong = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulong, find.toulong); - Assert.False(find.toulong); - - //update all - item.toulong = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulong, find.toulong); - Assert.True(find.toulong); - - item.toulong = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulong, find.toulong); - Assert.False(find.toulong); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toulong, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.toulong); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toulong, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulong == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.toulong); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toulong == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toulong == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void ULongNullable() - { - //insert - var orm = g.kingbaseES; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulongnullable, find.toulongnullable); - Assert.True(find.toulongnullable); - - item = new BoolMap { toulongnullable = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulongnullable, find.toulongnullable); - Assert.False(find.toulongnullable); - - //update all - item.toulongnullable = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulongnullable, find.toulongnullable); - Assert.True(find.toulongnullable); - - item.toulongnullable = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.toulongnullable, find.toulongnullable); - Assert.False(find.toulongnullable); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toulongnullable, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.toulongnullable); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.toulongnullable, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.toulongnullable == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.toulongnullable); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.toulongnullable == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.toulongnullable == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - - [Fact] - public void TimeSpan() - { - } - [Fact] - public void TimeSpanNullable() - { - } - [Fact] - public void DateTime() - { - } - [Fact] - public void DateTimeNullable() - { - } - - [Fact] - public void ByteArray() - { - } - [Fact] - public void String() - { - //insert - var orm = g.kingbaseES; - var item = new BoolMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.tostring == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tostring, find.tostring); - Assert.True(find.tostring); - - item = new BoolMap { tostring = false }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tostring == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tostring, find.tostring); - Assert.False(find.tostring); - - //update all - item.tostring = true; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tostring == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tostring, find.tostring); - Assert.True(find.tostring); - - item.tostring = false; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tostring == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.tostring, find.tostring); - Assert.False(find.tostring); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tostring, true).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tostring == true).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.True(find.tostring); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.tostring, false).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.tostring == false).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.False(find.tostring); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.tostring == true).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.tostring == false).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - - [Fact] - public void Guid() - { - } - [Fact] - public void GuidNullable() - { - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/MapType/DateTimeOffSetTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/MapType/DateTimeOffSetTest.cs deleted file mode 100644 index 92efffe6e..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/MapType/DateTimeOffSetTest.cs +++ /dev/null @@ -1,54 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Numerics; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseESMapType -{ - public class DateTimeOffSetTest - { - class Dtos_dt - { - public Guid id { get; set; } - - [Column(MapType = typeof(DateTime))] - public DateTimeOffset dtos_to_dt { get; set; } - [Column(MapType = typeof(DateTime))] - public DateTimeOffset? dtofnil_to_dt { get; set; } - } - [Fact] - public void DateTimeToDateTimeOffSet() - { - //insert - var orm = g.kingbaseES; - var item = new Dtos_dt { dtos_to_dt = DateTimeOffset.Now, dtofnil_to_dt = DateTimeOffset.Now }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g")); - Assert.Equal(item.dtofnil_to_dt.Value.ToString("g"), find.dtofnil_to_dt.Value.ToString("g")); - - //update all - item.dtos_to_dt = DateTimeOffset.Now; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g")); - Assert.Equal(item.dtofnil_to_dt.Value.ToString("g"), find.dtofnil_to_dt.Value.ToString("g")); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.dtos_to_dt, item.dtos_to_dt = DateTimeOffset.Now).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.dtos_to_dt.ToString("g"), find.dtos_to_dt.ToString("g")); - Assert.Equal(item.dtofnil_to_dt.Value.ToString("g"), find.dtofnil_to_dt.Value.ToString("g")); - - //delete - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/MapType/EnumTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/MapType/EnumTest.cs deleted file mode 100644 index 97e2fddc5..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/MapType/EnumTest.cs +++ /dev/null @@ -1,261 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Numerics; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseESMapType -{ - public class EnumTest - { - class EnumTestMap - { - public Guid id { get; set; } - - [Column(MapType = typeof(string))] - public ToStringMapEnum enum_to_string { get; set; } - [Column(MapType = typeof(string))] - public ToStringMapEnum? enumnullable_to_string { get; set; } - - [Column(MapType = typeof(int))] - public ToStringMapEnum enum_to_int { get; set; } - [Column(MapType = typeof(int?))] - public ToStringMapEnum? enumnullable_to_int { get; set; } - } - public enum ToStringMapEnum { й, abc, } - [Fact] - public void EnumToString() - { - //insert - var orm = g.kingbaseES; - var item = new EnumTestMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.й).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_string, find.enum_to_string); - Assert.Equal(ToStringMapEnum.й, find.enum_to_string); - - item = new EnumTestMap { enum_to_string = ToStringMapEnum.abc }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_string, find.enum_to_string); - Assert.Equal(ToStringMapEnum.abc, find.enum_to_string); - - //update all - item.enum_to_string = ToStringMapEnum.; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_string, find.enum_to_string); - Assert.Equal(ToStringMapEnum., find.enum_to_string); - - item.enum_to_string = ToStringMapEnum.й; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.й).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_string, find.enum_to_string); - Assert.Equal(ToStringMapEnum.й, find.enum_to_string); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(ToStringMapEnum., find.enum_to_string); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.abc).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(ToStringMapEnum.abc, find.enum_to_string); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.й).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void EnumNullableToString() - { - //insert - var orm = g.kingbaseES; - var item = new EnumTestMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().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().AppendData(item).ExecuteAffrows()); - find = orm.Select().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); - Assert.Equal(ToStringMapEnum.й, find.enumnullable_to_string); - - //update all - item.enumnullable_to_string = ToStringMapEnum.; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().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); - Assert.Equal(ToStringMapEnum., find.enumnullable_to_string); - - item.enumnullable_to_string = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.).First()); - find = orm.Select().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().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, ToStringMapEnum.abc).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_string); - - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First()); - find = orm.Select().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().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.й).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.enumnullable_to_string == null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - - [Fact] - public void EnumToInt() - { - //insert - var orm = g.kingbaseES; - var item = new EnumTestMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.й).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_int, find.enum_to_int); - Assert.Equal(ToStringMapEnum.й, find.enum_to_int); - - item = new EnumTestMap { enum_to_int = ToStringMapEnum.abc }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.abc).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_int, find.enum_to_int); - Assert.Equal(ToStringMapEnum.abc, find.enum_to_int); - - //update all - item.enum_to_int = ToStringMapEnum.; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_int, find.enum_to_int); - Assert.Equal(ToStringMapEnum., find.enum_to_int); - - item.enum_to_int = ToStringMapEnum.й; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.й).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_int, find.enum_to_int); - Assert.Equal(ToStringMapEnum.й, find.enum_to_int); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.enum_to_int, ToStringMapEnum.).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(ToStringMapEnum., find.enum_to_int); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.enum_to_int, ToStringMapEnum.abc).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.abc).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(ToStringMapEnum.abc, find.enum_to_int); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.й).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.abc).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void EnumNullableToInt() - { - //insert - var orm = g.kingbaseES; - var item = new EnumTestMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.enumnullable_to_int == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int); - Assert.Null(find.enumnullable_to_int); - - item = new EnumTestMap { enumnullable_to_int = ToStringMapEnum.й }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.й).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int); - Assert.Equal(ToStringMapEnum.й, find.enumnullable_to_int); - - //update all - item.enumnullable_to_int = ToStringMapEnum.; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int); - Assert.Equal(ToStringMapEnum., find.enumnullable_to_int); - - item.enumnullable_to_int = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.).First()); - find = orm.Select().Where(a => a.id == item.id && a.enumnullable_to_int == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int); - Assert.Null(find.enumnullable_to_int); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.enumnullable_to_int, ToStringMapEnum.abc).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.abc).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_int); - - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.enumnullable_to_int, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.abc).First()); - find = orm.Select().Where(a => a.id == item.id && a.enumnullable_to_int == null).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.enumnullable_to_int); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.й).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.enumnullable_to_int == null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/MapType/ToStringTest.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/MapType/ToStringTest.cs deleted file mode 100644 index 332eabf70..000000000 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/KingbaseES/MapType/ToStringTest.cs +++ /dev/null @@ -1,570 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Numerics; -using Xunit; - -namespace FreeSql.Tests.Odbc.KingbaseESMapType -{ - public class ToStringTest - { - class ToStringMap - { - public Guid id { get; set; } - - [Column(MapType = typeof(string))] - public TimeSpan timespan_to_string { get; set; } - [Column(MapType = typeof(string))] - public TimeSpan? timespannullable_to_string { get; set; } - - [Column(MapType = typeof(string))] - public DateTime datetime_to_string { get; set; } - [Column(MapType = typeof(string))] - public DateTime? datetimenullable_to_string { get; set; } - - [Column(MapType = typeof(string))] - public Guid guid_to_string { get; set; } - [Column(MapType = typeof(string))] - public Guid? guidnullable_to_string { get; set; } - - [Column(MapType = typeof(string))] - public ToStringMapEnum enum_to_string { get; set; } - [Column(MapType = typeof(string))] - public ToStringMapEnum? enumnullable_to_string { get; set; } - - [Column(MapType = typeof(string))] - public BigInteger biginteger_to_string { get; set; } - [Column(MapType = typeof(string))] - public BigInteger? bigintegernullable_to_string { get; set; } - } - public enum ToStringMapEnum { й, abc, } - [Fact] - public void Enum1() - { - //insert - var orm = g.kingbaseES; - var item = new ToStringMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.й).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_string, find.enum_to_string); - Assert.Equal(ToStringMapEnum.й, find.enum_to_string); - - item = new ToStringMap { enum_to_string = ToStringMapEnum.abc }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_string, find.enum_to_string); - Assert.Equal(ToStringMapEnum.abc, find.enum_to_string); - - //update all - item.enum_to_string = ToStringMapEnum.; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_string, find.enum_to_string); - Assert.Equal(ToStringMapEnum., find.enum_to_string); - - item.enum_to_string = ToStringMapEnum.й; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.й).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.enum_to_string, find.enum_to_string); - Assert.Equal(ToStringMapEnum.й, find.enum_to_string); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(ToStringMapEnum., find.enum_to_string); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.abc).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(ToStringMapEnum.abc, find.enum_to_string); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.й).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void EnumNullable() - { - //insert - var orm = g.kingbaseES; - var item = new ToStringMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().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().AppendData(item).ExecuteAffrows()); - find = orm.Select().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); - Assert.Equal(ToStringMapEnum.й, find.enumnullable_to_string); - - //update all - item.enumnullable_to_string = ToStringMapEnum.; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().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); - Assert.Equal(ToStringMapEnum., find.enumnullable_to_string); - - item.enumnullable_to_string = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.).First()); - find = orm.Select().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().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, ToStringMapEnum.abc).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(ToStringMapEnum.abc, find.enumnullable_to_string); - - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.enumnullable_to_string, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.abc).First()); - find = orm.Select().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().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.й).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.enumnullable_to_string == null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void BigInteger1() - { - //insert - var orm = g.kingbaseES; - var item = new ToStringMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.biginteger_to_string == 0).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.biginteger_to_string, find.biginteger_to_string); - Assert.Equal(0, find.biginteger_to_string); - - item = new ToStringMap { biginteger_to_string = 100 }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.biginteger_to_string == 100).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.biginteger_to_string, find.biginteger_to_string); - Assert.Equal(100, find.biginteger_to_string); - - //update all - item.biginteger_to_string = 200; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.biginteger_to_string == 200).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.biginteger_to_string, find.biginteger_to_string); - Assert.Equal(200, find.biginteger_to_string); - - item.biginteger_to_string = 205; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.biginteger_to_string == 205).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.biginteger_to_string, find.biginteger_to_string); - Assert.Equal(205, find.biginteger_to_string); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.biginteger_to_string, 522).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.biginteger_to_string == 522).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(522, find.biginteger_to_string); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.biginteger_to_string, 10005).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.biginteger_to_string == 10005).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(10005, find.biginteger_to_string); - - //delete - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.biginteger_to_string == 522).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.biginteger_to_string == 205).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.biginteger_to_string == 10005).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void BigIntegerNullable() - { - //insert - var orm = g.kingbaseES; - var item = new ToStringMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().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().AppendData(item).ExecuteAffrows()); - find = orm.Select().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); - Assert.Equal(101, find.bigintegernullable_to_string); - - //update all - item.bigintegernullable_to_string = 2004; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - 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().SetSource(item).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).First()); - find = orm.Select().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().Where(a => a.id == item.id).Set(a => a.bigintegernullable_to_string, 998).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(998, find.bigintegernullable_to_string); - - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.bigintegernullable_to_string, null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).First()); - find = orm.Select().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().Where(a => a.id == item.id && a.bigintegernullable_to_string == 998).ExecuteAffrows()); - Assert.Equal(0, orm.Delete().Where(a => a.id == item.id && a.bigintegernullable_to_string == 2004).ExecuteAffrows()); - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.bigintegernullable_to_string == null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void TimeSpan1() - { - //insert - var orm = g.kingbaseES; - var item = new ToStringMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.timespan_to_string, find.timespan_to_string); - Assert.Equal(TimeSpan.Zero, find.timespan_to_string); - - item = new ToStringMap { timespan_to_string = TimeSpan.FromDays(1) }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.timespan_to_string, find.timespan_to_string); - Assert.Equal(TimeSpan.FromDays(1), find.timespan_to_string); - - //update all - item.timespan_to_string = TimeSpan.FromHours(10); - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.timespan_to_string, find.timespan_to_string); - Assert.Equal(TimeSpan.FromHours(10), find.timespan_to_string); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.timespan_to_string, TimeSpan.FromHours(11)).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(TimeSpan.FromHours(11), find.timespan_to_string); - - //delete - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void TimeSpanNullable() - { - //insert - var orm = g.kingbaseES; - var item = new ToStringMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string); - Assert.Null(find.timespannullable_to_string); - - item = new ToStringMap { timespannullable_to_string = TimeSpan.FromDays(1) }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string); - Assert.Equal(TimeSpan.FromDays(1), find.timespannullable_to_string); - - //update all - item.timespannullable_to_string = TimeSpan.FromHours(10); - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string); - Assert.Equal(TimeSpan.FromHours(10), find.timespannullable_to_string); - - item.timespannullable_to_string = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.timespannullable_to_string, find.timespannullable_to_string); - Assert.Null(find.timespannullable_to_string); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.timespannullable_to_string, TimeSpan.FromHours(11)).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(TimeSpan.FromHours(11), find.timespannullable_to_string); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.timespannullable_to_string, null).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.timespannullable_to_string); - - //delete - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void DateTime1() - { - //insert - var orm = g.kingbaseES; - var item = new ToStringMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.datetime_to_string, find.datetime_to_string); - Assert.Equal(DateTime.MinValue, find.datetime_to_string); - - item = new ToStringMap { datetime_to_string = DateTime.Parse("2000-1-1") }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.datetime_to_string, find.datetime_to_string); - Assert.Equal(DateTime.Parse("2000-1-1"), find.datetime_to_string); - - //update all - item.datetime_to_string = DateTime.Parse("2000-1-11"); - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.datetime_to_string, find.datetime_to_string); - Assert.Equal(DateTime.Parse("2000-1-11"), find.datetime_to_string); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.datetime_to_string, DateTime.Parse("2000-1-12")).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(DateTime.Parse("2000-1-12"), find.datetime_to_string); - - //delete - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void DateTimeNullable() - { - //insert - var orm = g.kingbaseES; - var item = new ToStringMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string); - Assert.Null(find.datetimenullable_to_string); - - item = new ToStringMap { datetimenullable_to_string = DateTime.Parse("2000-1-1") }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string); - Assert.Equal(DateTime.Parse("2000-1-1"), find.datetimenullable_to_string); - - //update all - item.datetimenullable_to_string = DateTime.Parse("2000-1-11"); - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string); - Assert.Equal(DateTime.Parse("2000-1-11"), find.datetimenullable_to_string); - - item.datetimenullable_to_string = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.datetimenullable_to_string, find.datetimenullable_to_string); - Assert.Null(find.datetimenullable_to_string); - - //update set - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.datetimenullable_to_string, DateTime.Parse("2000-1-12")).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(DateTime.Parse("2000-1-12"), find.datetimenullable_to_string); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.datetimenullable_to_string, null).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Null(find.datetimenullable_to_string); - - //delete - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - - [Fact] - public void Guid1() - { - //insert - var orm = g.kingbaseES; - var item = new ToStringMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().Where(a => a.id == item.id && a.guid_to_string == Guid.Empty).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.guid_to_string, find.guid_to_string); - Assert.Equal(Guid.Empty, find.guid_to_string); - - var newid = Guid.NewGuid(); - item = new ToStringMap { guid_to_string = newid }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.guid_to_string == newid).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.guid_to_string, find.guid_to_string); - Assert.Equal(newid, find.guid_to_string); - - //update all - newid = Guid.NewGuid(); - item.guid_to_string = newid; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.guid_to_string == newid).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(item.guid_to_string, find.guid_to_string); - Assert.Equal(newid, find.guid_to_string); - - //update set - newid = Guid.NewGuid(); - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.guid_to_string, newid).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.guid_to_string == newid).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(newid, find.guid_to_string); - - //delete - Assert.Equal(1, orm.Delete().Where(a => a.id == item.id && a.guid_to_string == newid).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - [Fact] - public void GuidNullable() - { - //insert - var orm = g.kingbaseES; - var item = new ToStringMap { }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - var find = orm.Select().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 }; - Assert.Equal(1, orm.Insert().AppendData(item).ExecuteAffrows()); - find = orm.Select().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); - Assert.Equal(newid, find.guidnullable_to_string); - - //update all - newid = Guid.NewGuid(); - item.guidnullable_to_string = newid; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().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); - Assert.Equal(newid, find.guidnullable_to_string); - - item.guidnullable_to_string = null; - Assert.Equal(1, orm.Update().SetSource(item).ExecuteAffrows()); - find = orm.Select().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().Where(a => a.id == item.id).Set(a => a.guidnullable_to_string, newid).ExecuteAffrows()); - find = orm.Select().Where(a => a.id == item.id && a.guidnullable_to_string == newid).First(); - Assert.NotNull(find); - Assert.Equal(item.id, find.id); - Assert.Equal(newid, find.guidnullable_to_string); - - Assert.Equal(1, orm.Update().Where(a => a.id == item.id).Set(a => a.guidnullable_to_string, null).ExecuteAffrows()); - find = orm.Select().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().Where(a => a.id == item.id && a.guidnullable_to_string == null).ExecuteAffrows()); - Assert.Null(orm.Select().Where(a => a.id == item.id).First()); - } - } -} diff --git a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/g.cs b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/g.cs index 42ce0a72d..963266779 100644 --- a/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/g.cs +++ b/FreeSql.Tests/FreeSql.Tests.Provider.Odbc/g.cs @@ -70,37 +70,5 @@ public class g .Build()); public static IFreeSql odbc => odbcLazy.Value; - static Lazy damemgLazy = new Lazy(() => new FreeSql.FreeSqlBuilder() - .UseConnectionString(FreeSql.DataType.OdbcDameng, "Driver={DM8 ODBC DRIVER};Server=127.0.0.1:5236;Persist Security Info=False;Trusted_Connection=Yes;UID=1user;PWD=123456789") - //.UseConnectionFactory(FreeSql.DataType.OdbcDameng, () => new System.Data.Odbc.OdbcConnection("Driver={DM8 ODBC DRIVER};Server=127.0.0.1:5236;Persist Security Info=False;Trusted_Connection=Yes;UID=1user;PWD=123456789")) - .UseAutoSyncStructure(true) - .UseLazyLoading(true) - .UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper) - //.UseNoneCommandParameter(true) - - .UseMonitorCommand( - cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象,在执行前 - (cmd, traceLog) => Console.WriteLine(traceLog)) - .Build()); - public static IFreeSql dameng => damemgLazy.Value; - - static Lazy kingbaseESLazy = new Lazy(() => new FreeSql.FreeSqlBuilder() - .UseConnectionString(FreeSql.DataType.OdbcKingbaseES, "Driver={KingbaseES 8.2 ODBC Driver ANSI};Server=127.0.0.1;Port=54321;UID=USER2;PWD=123456789;database=TEST") - //.UseConnectionFactory(FreeSql.DataType.OdbcKingbaseES, () => new System.Data.Odbc.OdbcConnection("Driver={KingbaseES 8.2 ODBC Driver ANSI};Server=127.0.0.1;Port=54321;UID=USER2;PWD=123456789;database=TEST")) - .UseAutoSyncStructure(true) - .UseLazyLoading(true) - .UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper) - //.UseNoneCommandParameter(true) - - .UseMonitorCommand( - cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象,在执行前 - (cmd, traceLog) => Console.WriteLine(traceLog)) - .Build()); - public static IFreeSql kingbaseES => kingbaseESLazy.Value; - - - //启动神舟通用数据库 /etc/init.d/oscardb_OSRDBd start - //SYSDBA 密码 szoscar55 - } diff --git a/FreeSql/DataType.cs b/FreeSql/DataType.cs index d3d4a7f33..990227748 100644 --- a/FreeSql/DataType.cs +++ b/FreeSql/DataType.cs @@ -11,40 +11,28 @@ public enum DataType { OdbcOracle, OdbcSqlServer, OdbcMySql, OdbcPostgreSQL, /// - /// 通用的 Odbc 实现,只能做基本的 Crud 操作 - /// 不支持实体结构迁移、不支持分页(只能 Take 查询) - /// - /// 通用实现为了让用户自己适配更多的数据库,比如连接 mssql 2000、db2 等数据库 - /// 默认适配 SqlServer,可以继承后重新适配 FreeSql.Odbc.Default.OdbcAdapter,最好去看下代码 - /// - /// 适配新的 OdbcAdapter,请在 FreeSqlBuilder.Build 之后调用 IFreeSql.SetOdbcAdapter 方法设置 + /// 通用的 Odbc 访问数据库 https://freesql.net/guide/freesql-provider-odbc.html /// - Odbc, + Odbc = 9, - /// - /// 武汉达梦数据库有限公司,基于 Odbc 的实现 - /// - OdbcDameng, + //OdbcDameng, /// /// Microsoft Office Access 是由微软发布的关联式数据库管理系统 /// - MsAccess, + MsAccess = 11, /// /// 武汉达梦数据库有限公司,基于 DmProvider.dll 的实现 /// Dameng, - /// - /// 北京人大金仓信息技术股份有限公司,基于 Odbc 的实现 - /// - OdbcKingbaseES, + //OdbcKingbaseES, /// /// 天津神舟通用数据技术有限公司,基于 System.Data.OscarClient.dll 的实现 /// - ShenTong, + ShenTong = 14, /// /// 北京人大金仓信息技术股份有限公司,基于 Kdbndp.dll 的实现 @@ -57,8 +45,7 @@ public enum DataType { Firebird, /// - /// 自定义适配器,访问任何数据库 - /// 注意:该类型不提供 DbFirst/CodeFirst 功能 + /// 自定义适配器,访问任何数据库 https://freesql.net/guide/freesql-provider-custom.html /// Custom, diff --git a/FreeSql/Extensions/FreeSqlGlobalExtensions.cs b/FreeSql/Extensions/FreeSqlGlobalExtensions.cs index 7aafee877..423fe7b05 100644 --- a/FreeSql/Extensions/FreeSqlGlobalExtensions.cs +++ b/FreeSql/Extensions/FreeSqlGlobalExtensions.cs @@ -744,7 +744,6 @@ WHERE @cte_ids IS NOT NULL case DataType.OdbcPostgreSQL: case DataType.CustomPostgreSQL: case DataType.KingbaseES: - case DataType.OdbcKingbaseES: case DataType.ShenTong: //神通测试未通过 case DataType.SqlServer: case DataType.OdbcSqlServer: @@ -841,7 +840,6 @@ WHERE @cte_ids IS NOT NULL case DataType.OdbcPostgreSQL: case DataType.CustomPostgreSQL: case DataType.KingbaseES: - case DataType.OdbcKingbaseES: case DataType.ShenTong: //神通测试未通过 case DataType.MySql: case DataType.OdbcMySql: @@ -857,7 +855,6 @@ WHERE @cte_ids IS NOT NULL case DataType.OdbcOracle: case DataType.CustomOracle: case DataType.Dameng: //递归 WITH 子句必须具有列别名列表 - case DataType.OdbcDameng: case DataType.GBase: nsselsb.Append($"(cte_level, {(pathSelector == null ? "" : "cte_path, ")}{sql2Field.Replace("wct2.", "")})"); break; @@ -899,14 +896,12 @@ public static TSelect OrderByRandom(this ISelect0 that case DataType.OdbcPostgreSQL: case DataType.CustomPostgreSQL: case DataType.KingbaseES: - case DataType.OdbcKingbaseES: case DataType.ShenTong: return that.OrderBy("random()"); case DataType.Oracle: case DataType.OdbcOracle: case DataType.CustomOracle: case DataType.Dameng: - case DataType.OdbcDameng: return that.OrderBy("dbms_random.value"); case DataType.Sqlite: return that.OrderBy("random()"); diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml index a656490ce..44d4f9e4a 100644 --- a/FreeSql/FreeSql.xml +++ b/FreeSql/FreeSql.xml @@ -695,18 +695,7 @@ - 通用的 Odbc 实现,只能做基本的 Crud 操作 - 不支持实体结构迁移、不支持分页(只能 Take 查询) - - 通用实现为了让用户自己适配更多的数据库,比如连接 mssql 2000、db2 等数据库 - 默认适配 SqlServer,可以继承后重新适配 FreeSql.Odbc.Default.OdbcAdapter,最好去看下代码 - - 适配新的 OdbcAdapter,请在 FreeSqlBuilder.Build 之后调用 IFreeSql.SetOdbcAdapter 方法设置 - - - - - 武汉达梦数据库有限公司,基于 Odbc 的实现 + 通用的 Odbc 访问数据库 https://freesql.net/guide/freesql-provider-odbc.html @@ -719,11 +708,6 @@ 武汉达梦数据库有限公司,基于 DmProvider.dll 的实现 - - - 北京人大金仓信息技术股份有限公司,基于 Odbc 的实现 - - 天津神舟通用数据技术有限公司,基于 System.Data.OscarClient.dll 的实现 @@ -741,8 +725,7 @@ - 自定义适配器,访问任何数据库 - 注意:该类型不提供 DbFirst/CodeFirst 功能 + 自定义适配器,访问任何数据库 https://freesql.net/guide/freesql-provider-custom.html diff --git a/FreeSql/FreeSqlBuilder.cs b/FreeSql/FreeSqlBuilder.cs index e3ff2c429..a83589e2a 100644 --- a/FreeSql/FreeSqlBuilder.cs +++ b/FreeSql/FreeSqlBuilder.cs @@ -306,11 +306,6 @@ public IFreeSql Build() if (type == null) throwNotFind("FreeSql.Provider.Odbc.dll", "FreeSql.Odbc.Default.OdbcProvider<>"); break; - case DataType.OdbcDameng: - type = Type.GetType("FreeSql.Odbc.Dameng.OdbcDamengProvider`1,FreeSql.Provider.Odbc")?.MakeGenericType(typeof(TMark)); - if (type == null) throwNotFind("FreeSql.Provider.Odbc.dll", "FreeSql.Odbc.Dameng.OdbcDamengProvider<>"); - break; - case DataType.MsAccess: type = Type.GetType("FreeSql.MsAccess.MsAccessProvider`1,FreeSql.Provider.MsAccess")?.MakeGenericType(typeof(TMark)); if (type == null) throwNotFind("FreeSql.Provider.MsAccess.dll", "FreeSql.MsAccess.MsAccessProvider<>"); @@ -321,11 +316,6 @@ public IFreeSql Build() if (type == null) throwNotFind("FreeSql.Provider.Dameng.dll", "FreeSql.Dameng.DamengProvider<>"); break; - case DataType.OdbcKingbaseES: - type = Type.GetType("FreeSql.Odbc.KingbaseES.OdbcKingbaseESProvider`1,FreeSql.Provider.Odbc")?.MakeGenericType(typeof(TMark)); - if (type == null) throwNotFind("FreeSql.Provider.Odbc.dll", "FreeSql.Odbc.KingbaseES.OdbcKingbaseESProvider<>"); - break; - case DataType.ShenTong: type = Type.GetType("FreeSql.ShenTong.ShenTongProvider`1,FreeSql.Provider.ShenTong")?.MakeGenericType(typeof(TMark)); if (type == null) throwNotFind("FreeSql.Provider.ShenTong.dll", "FreeSql.ShenTong.ShenTongProvider<>"); diff --git a/FreeSql/Internal/CommonExpression.cs b/FreeSql/Internal/CommonExpression.cs index a1a32b6c4..d09230fa5 100644 --- a/FreeSql/Internal/CommonExpression.cs +++ b/FreeSql/Internal/CommonExpression.cs @@ -1333,7 +1333,6 @@ public string ExpressionLambdaToSql(Expression exp, ExpTSC tsc) case DataType.OdbcOracle: case DataType.CustomOracle: case DataType.Dameng: - case DataType.OdbcDameng: case DataType.GBase: break; default: @@ -2726,7 +2725,6 @@ void LocalSetSelectProviderAlias(string alias) case DataType.OdbcOracle: case DataType.CustomOracle: case DataType.Dameng: - case DataType.OdbcDameng: case DataType.GBase: break; default: @@ -2849,7 +2847,6 @@ void LocalInitSelectProvider() case DataType.OdbcOracle: case DataType.CustomOracle: case DataType.Dameng: - case DataType.OdbcDameng: case DataType.GBase: break; default: diff --git a/FreeSql/Internal/CommonProvider/InsertOrUpdateProvider.cs b/FreeSql/Internal/CommonProvider/InsertOrUpdateProvider.cs index c16a798b3..c33929429 100644 --- a/FreeSql/Internal/CommonProvider/InsertOrUpdateProvider.cs +++ b/FreeSql/Internal/CommonProvider/InsertOrUpdateProvider.cs @@ -305,7 +305,6 @@ public void WriteSourceSelectUnionAll(List source, StringBuilder sb, List ToDelete() } switch (_orm.Ado.DataType) { - case DataType.Dameng: - case DataType.OdbcDameng: //达梦不能这样 + case DataType.Dameng: //达梦不能这样 case DataType.Oracle: case DataType.OdbcOracle: case DataType.CustomOracle: @@ -845,8 +843,7 @@ public IUpdate ToUpdate() } switch (_orm.Ado.DataType) { - case DataType.Dameng: - case DataType.OdbcDameng: //达梦不能这样 + case DataType.Dameng: //达梦不能这样 case DataType.Oracle: case DataType.OdbcOracle: case DataType.CustomOracle: @@ -1294,14 +1291,12 @@ public TSelect ForUpdate(bool noawait = false) case DataType.OdbcPostgreSQL: case DataType.CustomPostgreSQL: case DataType.KingbaseES: - case DataType.OdbcKingbaseES: _tosqlAppendContent = $"{_tosqlAppendContent} for update{(noawait ? " nowait" : "")}"; break; case DataType.Oracle: case DataType.OdbcOracle: case DataType.CustomOracle: case DataType.Dameng: - case DataType.OdbcDameng: _tosqlAppendContent = $"{_tosqlAppendContent} for update{(noawait ? " nowait" : "")}"; break; case DataType.Sqlite: diff --git a/FreeSql/Internal/CommonProvider/SelectProvider/SelectGroupingProvider.cs b/FreeSql/Internal/CommonProvider/SelectProvider/SelectGroupingProvider.cs index 178b49d35..d8cbf5f5a 100644 --- a/FreeSql/Internal/CommonProvider/SelectProvider/SelectGroupingProvider.cs +++ b/FreeSql/Internal/CommonProvider/SelectProvider/SelectGroupingProvider.cs @@ -205,8 +205,7 @@ public string InternalToSql(string field) case DataType.Oracle: case DataType.OdbcOracle: case DataType.CustomOracle: - case DataType.Dameng: - case DataType.OdbcDameng: //Oracle、Dameng 分组时,嵌套分页 + case DataType.Dameng: //Oracle、Dameng 分组时,嵌套分页 case DataType.GBase: isNestedPageSql = true; break; diff --git a/FreeSql/Internal/CommonProvider/UpdateJoinProvider.cs b/FreeSql/Internal/CommonProvider/UpdateJoinProvider.cs index e7a390223..7e3f40fbc 100644 --- a/FreeSql/Internal/CommonProvider/UpdateJoinProvider.cs +++ b/FreeSql/Internal/CommonProvider/UpdateJoinProvider.cs @@ -80,14 +80,12 @@ public void ValidateDataType(Action InterceptSqlServer, Action InterceptMySql, A case DataType.OdbcPostgreSQL: case DataType.CustomPostgreSQL: case DataType.KingbaseES: - case DataType.OdbcKingbaseES: case DataType.ShenTong: InterceptPostgreSQL?.Invoke(); break; case DataType.Oracle: case DataType.OdbcOracle: case DataType.CustomOracle: case DataType.Dameng: - case DataType.OdbcDameng: case DataType.Firebird: InterceptMergeInto?.Invoke(); break; case DataType.GBase: @@ -216,7 +214,6 @@ public IUpdateJoin SetIf(bool condition, Expression> case DataType.OdbcPostgreSQL: case DataType.CustomPostgreSQL: case DataType.KingbaseES: - case DataType.OdbcKingbaseES: case DataType.ShenTong: break; default: diff --git a/FreeSql/Internal/CommonProvider/UpdateProvider.cs b/FreeSql/Internal/CommonProvider/UpdateProvider.cs index 2e7c1366c..003dae8bc 100644 --- a/FreeSql/Internal/CommonProvider/UpdateProvider.cs +++ b/FreeSql/Internal/CommonProvider/UpdateProvider.cs @@ -84,7 +84,6 @@ public static int ExecuteBulkCommand(List _source, ColumnInfo[] _tempPri case DataType.OdbcOracle: case DataType.CustomOracle: case DataType.Dameng: - case DataType.OdbcDameng: return fsql.Ado.CommandFluent(state.Item2).WithConnection(connection).WithTransaction(transaction).ExecuteNonQuery(); } var affrows = fsql.Ado.CommandFluent(state.Item2 + ";\r\n" + state.Item3).WithConnection(connection).WithTransaction(transaction).ExecuteNonQuery(); @@ -146,7 +145,6 @@ async public static Task ExecuteBulkCommandAsync(List _source, Colu case DataType.OdbcOracle: case DataType.CustomOracle: case DataType.Dameng: - case DataType.OdbcDameng: return await fsql.Ado.CommandFluent(state.Item2).WithConnection(connection).WithTransaction(transaction).ExecuteNonQueryAsync(); } var affrows = await fsql.Ado.CommandFluent(state.Item2 + ";\r\n" + state.Item3).WithConnection(connection).WithTransaction(transaction).ExecuteNonQueryAsync(); @@ -1198,7 +1196,6 @@ public virtual void ToSqlExtension110(StringBuilder sb, bool isAsTableSplited) case DataType.OdbcPostgreSQL: case DataType.CustomPostgreSQL: case DataType.KingbaseES: - case DataType.OdbcKingbaseES: case DataType.ShenTong: vcvalue = $"{_tableAlias}.{vcname}"; //set name = b.name break; diff --git a/FreeSql/Internal/UtilsExpressionTree.cs b/FreeSql/Internal/UtilsExpressionTree.cs index fe755cc38..402f99629 100644 --- a/FreeSql/Internal/UtilsExpressionTree.cs +++ b/FreeSql/Internal/UtilsExpressionTree.cs @@ -393,7 +393,6 @@ public static ColumnInfo ColumnAttributeToInfo(TableInfo trytb, object entityDef case DataType.OdbcPostgreSQL: case DataType.CustomPostgreSQL: case DataType.KingbaseES: - case DataType.OdbcKingbaseES: case DataType.ShenTong: if (strlen < 0) colattr.DbType = $"TEXT{strNotNull}"; else colattr.DbType = Regex.Replace(colattr.DbType, charPattern, m => @@ -411,7 +410,6 @@ public static ColumnInfo ColumnAttributeToInfo(TableInfo trytb, object entityDef replaceCounter++ == 0 ? $"{m.Groups[1].Value}({strlen})" : m.Groups[0].Value); break; case DataType.OdbcOracle: - case DataType.OdbcDameng: if (strlen < 0) colattr.DbType = Regex.Replace(colattr.DbType, charPattern, m => replaceCounter++ == 0 ? $"{m.Groups[1].Value}(4000)" : m.Groups[0].Value); //ODBC 不支持 NCLOB else colattr.DbType = Regex.Replace(colattr.DbType, charPattern, m => @@ -467,19 +465,15 @@ public static ColumnInfo ColumnAttributeToInfo(TableInfo trytb, object entityDef case DataType.OdbcPostgreSQL: case DataType.CustomPostgreSQL: case DataType.KingbaseES: - case DataType.OdbcKingbaseES: case DataType.ShenTong: //驱动引发的异常:“System.Data.OscarClient.OscarException”(位于 System.Data.OscarClient.dll 中) colattr.DbType = $"BYTEA{strNotNull}"; //变长二进制串 break; case DataType.Oracle: - case DataType.CustomOracle: - colattr.DbType = $"BLOB{strNotNull}"; - break; - case DataType.Dameng: - colattr.DbType = $"BLOB{strNotNull}"; - break; case DataType.OdbcOracle: - case DataType.OdbcDameng: + case DataType.CustomOracle: + colattr.DbType = $"BLOB{strNotNull}"; + break; + case DataType.Dameng: colattr.DbType = $"BLOB{strNotNull}"; break; case DataType.Sqlite: diff --git a/Providers/FreeSql.Provider.ClickHouse/ClickHouseExpression.cs b/Providers/FreeSql.Provider.ClickHouse/ClickHouseExpression.cs index 1e52e21e1..cf6e896e4 100644 --- a/Providers/FreeSql.Provider.ClickHouse/ClickHouseExpression.cs +++ b/Providers/FreeSql.Provider.ClickHouse/ClickHouseExpression.cs @@ -331,10 +331,11 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (exp.Method.Name == "StartsWith") return $"positionCaseInsensitive({left}, {args0Value}) = 1"; - if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"concat('%', {args0Value})")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"concat('%', {args0Value})")}"; return $"positionCaseInsensitive({left}, {args0Value}) > 0"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; diff --git a/Providers/FreeSql.Provider.Custom/CustomExpression.cs b/Providers/FreeSql.Provider.Custom/CustomExpression.cs index e784e6d79..8417152c7 100644 --- a/Providers/FreeSql.Provider.Custom/CustomExpression.cs +++ b/Providers/FreeSql.Provider.Custom/CustomExpression.cs @@ -259,12 +259,13 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; - if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({_common.StringConcat(new string[] { args0Value, "'%'" }, new[] { typeof(int), typeof(string) })})")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"({_common.StringConcat(new string[] { "'%'", args0Value }, new[] { typeof(string), typeof(int) })})")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) LIKE ({_common.StringConcat(new string[] { "'%'", args0Value, "'%'" }, new[] { typeof(string), typeof(int), typeof(string)})})"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({_common.StringConcat(new string[] { args0Value, "'%'" }, new[] { typeof(int), typeof(string) })})")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"({_common.StringConcat(new string[] { "'%'", args0Value }, new[] { typeof(string), typeof(int) })})")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} LIKE ({_common.StringConcat(new string[] { "'%'", args0Value, "'%'" }, new[] { typeof(string), typeof(int), typeof(string)})})"; case "ToLower": return _utils.Adapter.LambdaString_ToLower(left); case "ToUpper": return _utils.Adapter.LambdaString_ToUpper(left); case "Substring": diff --git a/Providers/FreeSql.Provider.Custom/MySql/CustomMySqlExpression.cs b/Providers/FreeSql.Provider.Custom/MySql/CustomMySqlExpression.cs index ba6446690..415431477 100644 --- a/Providers/FreeSql.Provider.Custom/MySql/CustomMySqlExpression.cs +++ b/Providers/FreeSql.Provider.Custom/MySql/CustomMySqlExpression.cs @@ -282,18 +282,19 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"locate({args0Value}, {left}) = 1"; if (exp.Method.Name == "EndsWith") return $"locate({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1"; return $"locate({args0Value}, {left}) > 0"; } - if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"concat({args0Value}, '%')")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"concat('%', {args0Value})")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) LIKE concat('%', {args0Value}, '%')"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"concat({args0Value}, '%')")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"concat('%', {args0Value})")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} LIKE concat('%', {args0Value}, '%')"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring": diff --git a/Providers/FreeSql.Provider.Custom/Oracle/CustomOracleExpression.cs b/Providers/FreeSql.Provider.Custom/Oracle/CustomOracleExpression.cs index 529507ddb..bbd85d90c 100644 --- a/Providers/FreeSql.Provider.Custom/Oracle/CustomOracleExpression.cs +++ b/Providers/FreeSql.Provider.Custom/Oracle/CustomOracleExpression.cs @@ -285,18 +285,19 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1"; if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1"; return $"instr({left}, {args0Value}, 1, 1) > 0"; } - if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) LIKE ('%'||to_char({args0Value})||'%')"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} LIKE ('%'||to_char({args0Value})||'%')"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring": diff --git a/Providers/FreeSql.Provider.Custom/PostgreSQL/CustomPostgreSQLExpression.cs b/Providers/FreeSql.Provider.Custom/PostgreSQL/CustomPostgreSQLExpression.cs index 73395ee74..345800885 100644 --- a/Providers/FreeSql.Provider.Custom/PostgreSQL/CustomPostgreSQLExpression.cs +++ b/Providers/FreeSql.Provider.Custom/PostgreSQL/CustomPostgreSQLExpression.cs @@ -374,8 +374,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1"; @@ -388,10 +389,10 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (exp.Arguments[1].Type == typeof(bool) || exp.Arguments[1].Type == typeof(StringComparison)) likeOpt = "ILIKE"; } - if (exp.Method.Name == "StartsWith") return $"({left}) {likeOpt} {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(({args0Value})::text || '%')")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) {likeOpt} {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%' || ({args0Value})::text)")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) {likeOpt} {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) {likeOpt} ('%' || ({args0Value})::text || '%')"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} {likeOpt} {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(({args0Value})::text || '%')")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} {likeOpt} {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%' || ({args0Value})::text)")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} {likeOpt} {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} {likeOpt} ('%' || ({args0Value})::text || '%')"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring": diff --git a/Providers/FreeSql.Provider.Custom/SqlServer/CustomSqlServerExpression.cs b/Providers/FreeSql.Provider.Custom/SqlServer/CustomSqlServerExpression.cs index c35a139c0..4b8d8358d 100644 --- a/Providers/FreeSql.Provider.Custom/SqlServer/CustomSqlServerExpression.cs +++ b/Providers/FreeSql.Provider.Custom/SqlServer/CustomSqlServerExpression.cs @@ -305,18 +305,20 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"charindex({args0Value}, {left}) = 1"; if (exp.Method.Name == "EndsWith") return $"charindex({args0Value}, {left}) = len({left})-len({args0Value})+1"; return $"charindex({args0Value}, {left}) > 0"; } - if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(cast({args0Value} as nvarchar(max))+'%')")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'+cast({args0Value} as nvarchar(max)))")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) LIKE ('%'+cast({args0Value} as nvarchar(max))+'%')"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(cast({args0Value} as nvarchar(max))+'%')")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'+cast({args0Value} as nvarchar(max)))")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + if (args0Value.StartsWith("N'") && args0Value.EndsWith("'")) return $"{leftLike} LIKE {args0Value.Insert(2, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} LIKE ('%'+cast({args0Value} as nvarchar(max))+'%')"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring": diff --git a/Providers/FreeSql.Provider.Dameng/DamengExpression.cs b/Providers/FreeSql.Provider.Dameng/DamengExpression.cs index 0aaca5a6b..31a537569 100644 --- a/Providers/FreeSql.Provider.Dameng/DamengExpression.cs +++ b/Providers/FreeSql.Provider.Dameng/DamengExpression.cs @@ -285,18 +285,19 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1"; if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1"; return $"instr({left}, {args0Value}, 1, 1) > 0"; } - if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) LIKE ('%'||to_char({args0Value})||'%')"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} LIKE ('%'||to_char({args0Value})||'%')"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring": diff --git a/Providers/FreeSql.Provider.Firebird/FirebirdExpression.cs b/Providers/FreeSql.Provider.Firebird/FirebirdExpression.cs index ecae94e28..547a5167d 100644 --- a/Providers/FreeSql.Provider.Firebird/FirebirdExpression.cs +++ b/Providers/FreeSql.Provider.Firebird/FirebirdExpression.cs @@ -272,18 +272,19 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"position({args0Value}, {left}) = 1"; if (exp.Method.Name == "EndsWith") return $"position({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1"; return $"position({args0Value}, {left}) > 0"; } - if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({args0Value})||'%'")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"'%'||({args0Value})")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) CONTAINING {args0Value}"; - return $"({left}) CONTAINING ({args0Value})"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({args0Value})||'%'")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"'%'||({args0Value})")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} CONTAINING {args0Value}"; + return $"{leftLike} CONTAINING ({args0Value})"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring": diff --git a/Providers/FreeSql.Provider.GBase/GBaseExpression.cs b/Providers/FreeSql.Provider.GBase/GBaseExpression.cs index 3812e755d..2474701e1 100644 --- a/Providers/FreeSql.Provider.GBase/GBaseExpression.cs +++ b/Providers/FreeSql.Provider.GBase/GBaseExpression.cs @@ -272,18 +272,19 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"instr({args0Value}, {left}) = 1"; if (exp.Method.Name == "EndsWith") return $"instr({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1"; return $"instr({args0Value}, {left}) > 0"; } - if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({args0Value})||'%'")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"'%'||({args0Value})")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) LIKE ('%'||cast({args0Value} as varchar(8000))||'%')"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({args0Value})||'%'")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"'%'||({args0Value})")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} LIKE ('%'||cast({args0Value} as varchar(8000))||'%')"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring": diff --git a/Providers/FreeSql.Provider.KingbaseES/KingbaseESExpression.cs b/Providers/FreeSql.Provider.KingbaseES/KingbaseESExpression.cs index 1ce0cca4f..bfeab3819 100644 --- a/Providers/FreeSql.Provider.KingbaseES/KingbaseESExpression.cs +++ b/Providers/FreeSql.Provider.KingbaseES/KingbaseESExpression.cs @@ -352,8 +352,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1"; @@ -366,10 +367,10 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (exp.Arguments[1].Type == typeof(bool) || exp.Arguments[1].Type == typeof(StringComparison)) likeOpt = "ILIKE"; } - if (exp.Method.Name == "StartsWith") return $"({left}) {likeOpt} {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(({args0Value})::text || '%')")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) {likeOpt} {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%' || ({args0Value})::text)")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) {likeOpt} {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) {likeOpt} ('%' || ({args0Value})::text || '%')"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} {likeOpt} {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(({args0Value})::text || '%')")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} {likeOpt} {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%' || ({args0Value})::text)")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} {likeOpt} {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} {likeOpt} ('%' || ({args0Value})::text || '%')"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring": diff --git a/Providers/FreeSql.Provider.MsAccess/MsAccessExpression.cs b/Providers/FreeSql.Provider.MsAccess/MsAccessExpression.cs index e1a12130c..0b0b3ee4d 100644 --- a/Providers/FreeSql.Provider.MsAccess/MsAccessExpression.cs +++ b/Providers/FreeSql.Provider.MsAccess/MsAccessExpression.cs @@ -246,18 +246,19 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}) = 1"; if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}) = len({left})-len({args0Value})+1"; return $"instr({left}, {args0Value}) > 0"; } - if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({args0Value}+'%')")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'+{args0Value})")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) LIKE ('%'+{args0Value}+'%')"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({args0Value}+'%')")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'+{args0Value})")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} LIKE ('%'+{args0Value}+'%')"; case "ToLower": return $"lcase({left})"; case "ToUpper": return $"ucase({left})"; case "Substring": diff --git a/Providers/FreeSql.Provider.MySql/MySqlExpression.cs b/Providers/FreeSql.Provider.MySql/MySqlExpression.cs index d353ee499..289ff2187 100644 --- a/Providers/FreeSql.Provider.MySql/MySqlExpression.cs +++ b/Providers/FreeSql.Provider.MySql/MySqlExpression.cs @@ -284,18 +284,19 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"locate({args0Value}, {left}) = 1"; if (exp.Method.Name == "EndsWith") return $"locate({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1"; return $"locate({args0Value}, {left}) > 0"; } - if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"concat({args0Value}, '%')")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"concat('%', {args0Value})")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) LIKE concat('%', {args0Value}, '%')"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"concat({args0Value}, '%')")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"concat('%', {args0Value})")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} LIKE concat('%', {args0Value}, '%')"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring": diff --git a/Providers/FreeSql.Provider.Odbc/Dameng/Curd/OdbcDamengDelete.cs b/Providers/FreeSql.Provider.Odbc/Dameng/Curd/OdbcDamengDelete.cs deleted file mode 100644 index 53fea915e..000000000 --- a/Providers/FreeSql.Provider.Odbc/Dameng/Curd/OdbcDamengDelete.cs +++ /dev/null @@ -1,26 +0,0 @@ -using FreeSql.Internal; -using System; -using System.Collections.Generic; -using System.Data; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace FreeSql.Odbc.Dameng -{ - - class OdbcDamengDelete : Internal.CommonProvider.DeleteProvider - { - public OdbcDamengDelete(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) - : base(orm, commonUtils, commonExpression, dywhere) - { - } - - public override List ExecuteDeleted() => throw new NotImplementedException($"FreeSql.Odbc.Dameng {CoreStrings.S_Not_Implemented_Feature}"); - -#if net40 -#else - public override Task> ExecuteDeletedAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException($"FreeSql.Odbc.Dameng {CoreStrings.S_Not_Implemented_Feature}"); -#endif - } -} diff --git a/Providers/FreeSql.Provider.Odbc/Dameng/Curd/OdbcDamengInsert.cs b/Providers/FreeSql.Provider.Odbc/Dameng/Curd/OdbcDamengInsert.cs deleted file mode 100644 index d99322147..000000000 --- a/Providers/FreeSql.Provider.Odbc/Dameng/Curd/OdbcDamengInsert.cs +++ /dev/null @@ -1,224 +0,0 @@ -using FreeSql.Internal; -using FreeSql.Internal.Model; -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace FreeSql.Odbc.Dameng -{ - - class OdbcDamengInsert : Internal.CommonProvider.InsertProvider where T1 : class - { - public OdbcDamengInsert(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression) - : base(orm, commonUtils, commonExpression) - { - } - - public override int ExecuteAffrows() => base.SplitExecuteAffrows(_batchValuesLimit > 0 ? _batchValuesLimit : 500, _batchParameterLimit > 0 ? _batchParameterLimit : 999); - public override long ExecuteIdentity() => base.SplitExecuteIdentity(_batchValuesLimit > 0 ? _batchValuesLimit : 500, _batchParameterLimit > 0 ? _batchParameterLimit : 999); - public override List ExecuteInserted() => base.SplitExecuteInserted(_batchValuesLimit > 0 ? _batchValuesLimit : 500, _batchParameterLimit > 0 ? _batchParameterLimit : 999); - - public override string ToSql() - { - if (_source == null || _source.Any() == false) return null; - var sb = new StringBuilder(); - sb.Append("INSERT "); - if (_source.Count > 1) sb.Append("ALL"); - - _identCol = null; - var sbtb = new StringBuilder(); - sbtb.Append("INTO "); - sbtb.Append(_commonUtils.QuoteSqlName(TableRuleInvoke())).Append("("); - var colidx = 0; - foreach (var col in _table.Columns.Values) - { - if (col.Attribute.IsIdentity) _identCol = col; - if (col.Attribute.IsIdentity && _insertIdentity == false && string.IsNullOrEmpty(col.DbInsertValue)) continue; - if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name)) continue; - - if (colidx > 0) sbtb.Append(", "); - sbtb.Append(_commonUtils.QuoteSqlName(col.Attribute.Name)); - ++colidx; - } - sbtb.Append(") "); - - _params = _noneParameter ? new DbParameter[0] : new DbParameter[colidx * _source.Count]; - var specialParams = new List(); - var didx = 0; - foreach (var d in _source) - { - if (_source.Count > 1) sb.Append("\r\n"); - sb.Append(sbtb); - sb.Append("VALUES"); - sb.Append("("); - var colidx2 = 0; - foreach (var col in _table.Columns.Values) - { - if (col.Attribute.IsIdentity && _insertIdentity == false && string.IsNullOrEmpty(col.DbInsertValue)) continue; - if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name)) continue; - - if (colidx2 > 0) sb.Append(", "); - if (string.IsNullOrEmpty(col.DbInsertValue) == false && _ignoreInsertValueSql.ContainsKey(col.Attribute.Name) == false) - sb.Append(col.DbInsertValue); - else - { - object val = col.GetDbValue(d); - if (val == null && col.Attribute.IsNullable == false) val = col.CsType == typeof(string) ? "" : Utils.GetDataReaderValue(col.CsType.NullableTypeOrThis(), null);//#384 - - var colsql = _noneParameter ? _commonUtils.GetNoneParamaterSqlValue(specialParams, _noneParameterFlag, col, col.Attribute.MapType, val) : - _commonUtils.QuoteWriteParamterAdapter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"{col.CsName}_{didx}")); - sb.Append(_commonUtils.RewriteColumn(col, colsql)); - if (_noneParameter == false) - _params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}_{didx}", col, col.Attribute.MapType, val); - } - ++colidx2; - } - sb.Append(")"); - ++didx; - } - if (_noneParameter && specialParams.Any()) _params = specialParams.ToArray(); - if (_source.Count > 1) sb.Append("\r\n SELECT 1 FROM DUAL"); - return sb.ToString(); - } - - ColumnInfo _identCol; - protected override long RawExecuteIdentity() - { - var sql = this.ToSql(); - if (string.IsNullOrEmpty(sql)) return 0; - - long ret = 0; - Exception exception = null; - Aop.CurdBeforeEventArgs before = null; - - if (_identCol == null || _source.Count > 1) - { - before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, sql, _params); - _orm.Aop.CurdBeforeHandler?.Invoke(this, before); - try - { - ret = _orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, _commandTimeout, _params); - } - catch (Exception ex) - { - exception = ex; - throw ex; - } - finally - { - var after = new Aop.CurdAfterEventArgs(before, exception, ret); - _orm.Aop.CurdAfterHandler?.Invoke(this, after); - } - return 0; - } - var identColName = _commonUtils.QuoteSqlName(_identCol.Attribute.Name); - var identParam = _commonUtils.AppendParamter(null, $"{_identCol.CsName}99", _identCol, _identCol.Attribute.MapType, 0); - identParam.Direction = ParameterDirection.Output; - sql = $"{sql} RETURNING {identColName} INTO {identParam.ParameterName}"; - var dbParms = _params.Concat(new[] { identParam }).ToArray(); - before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, sql, dbParms); - _orm.Aop.CurdBeforeHandler?.Invoke(this, before); - try - { - _orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms); - long.TryParse(string.Concat(identParam.Value), out ret); - } - catch (Exception ex) - { - exception = ex; - throw ex; - } - finally - { - var after = new Aop.CurdAfterEventArgs(before, exception, ret); - _orm.Aop.CurdAfterHandler?.Invoke(this, after); - } - return ret; - } - - protected override List RawExecuteInserted() - { - var sql = this.ToSql(); - if (string.IsNullOrEmpty(sql)) return new List(); - - var ret = _source.ToList(); - this.RawExecuteAffrows(); - return ret; - } - -#if net40 -#else - public override Task ExecuteAffrowsAsync(CancellationToken cancellationToken = default) => base.SplitExecuteAffrowsAsync(_batchValuesLimit > 0 ? _batchValuesLimit : 500, _batchParameterLimit > 0 ? _batchParameterLimit : 999, cancellationToken); - public override Task ExecuteIdentityAsync(CancellationToken cancellationToken = default) => base.SplitExecuteIdentityAsync(_batchValuesLimit > 0 ? _batchValuesLimit : 500, _batchParameterLimit > 0 ? _batchParameterLimit : 999, cancellationToken); - public override Task> ExecuteInsertedAsync(CancellationToken cancellationToken = default) => base.SplitExecuteInsertedAsync(_batchValuesLimit > 0 ? _batchValuesLimit : 500, _batchParameterLimit > 0 ? _batchParameterLimit : 999, cancellationToken); - - async protected override Task RawExecuteIdentityAsync(CancellationToken cancellationToken = default) - { - var sql = this.ToSql(); - if (string.IsNullOrEmpty(sql)) return 0; - - long ret = 0; - Exception exception = null; - Aop.CurdBeforeEventArgs before = null; - - if (_identCol == null || _source.Count > 1) - { - before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, sql, _params); - _orm.Aop.CurdBeforeHandler?.Invoke(this, before); - try - { - ret = await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _commandTimeout, _params, cancellationToken); - } - catch (Exception ex) - { - exception = ex; - throw ex; - } - finally - { - var after = new Aop.CurdAfterEventArgs(before, exception, ret); - _orm.Aop.CurdAfterHandler?.Invoke(this, after); - } - return 0; - } - var identColName = _commonUtils.QuoteSqlName(_identCol.Attribute.Name); - var identParam = _commonUtils.AppendParamter(null, $"{_identCol.CsName}99", _identCol, _identCol.Attribute.MapType, 0); - identParam.Direction = ParameterDirection.Output; - sql = $"{sql} RETURNING {identColName} INTO {identParam.ParameterName}"; - var dbParms = _params.Concat(new[] { identParam }).ToArray(); - before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, sql, dbParms); - _orm.Aop.CurdBeforeHandler?.Invoke(this, before); - try - { - await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken); - long.TryParse(string.Concat(identParam.Value), out ret); - } - catch (Exception ex) - { - exception = ex; - throw ex; - } - finally - { - var after = new Aop.CurdAfterEventArgs(before, exception, ret); - _orm.Aop.CurdAfterHandler?.Invoke(this, after); - } - return ret; - } - async protected override Task> RawExecuteInsertedAsync(CancellationToken cancellationToken = default) - { - var sql = this.ToSql(); - if (string.IsNullOrEmpty(sql)) return new List(); - - var ret = _source.ToList(); - await this.RawExecuteAffrowsAsync(cancellationToken); - return ret; - } -#endif - } -} diff --git a/Providers/FreeSql.Provider.Odbc/Dameng/Curd/OdbcDamengInsertOrUpdate.cs b/Providers/FreeSql.Provider.Odbc/Dameng/Curd/OdbcDamengInsertOrUpdate.cs deleted file mode 100644 index 5f1debb78..000000000 --- a/Providers/FreeSql.Provider.Odbc/Dameng/Curd/OdbcDamengInsertOrUpdate.cs +++ /dev/null @@ -1,85 +0,0 @@ -using FreeSql.Internal; -using System; -using System.Collections.Generic; -using System.Data.Common; -using System.Linq; -using System.Text; - -namespace FreeSql.Odbc.Dameng -{ - - class OdbcDamengInsertOrUpdate : Internal.CommonProvider.InsertOrUpdateProvider where T1 : class - { - public OdbcDamengInsertOrUpdate(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression) - : base(orm, commonUtils, commonExpression) - { - } - - public override string ToSql() - { - var dbParams = new List(); - if (_sourceSql != null) return getMergeSql(null); - if (_source?.Any() != true) return null; - - var sqls = new string[2]; - var ds = SplitSourceByIdentityValueIsNull(_source); - if (ds.Item1.Any()) sqls[0] = string.Join("\r\n\r\n;\r\n\r\n", ds.Item1.Select(a => getMergeSql(a))); - if (ds.Item2.Any()) sqls[1] = string.Join("\r\n\r\n;\r\n\r\n", ds.Item2.Select(a => getInsertSql(a))); - _params = dbParams.ToArray(); - if (ds.Item2.Any() == false) return sqls[0]; - if (ds.Item1.Any() == false) return sqls[1]; - return string.Join("\r\n\r\n;\r\n\r\n", sqls); - - string getMergeSql(List data) - { - if (_tempPrimarys.Any() == false) throw new Exception(CoreStrings.InsertOrUpdate_Must_Primary_Key(_table.CsName)); - - var tempPrimaryIsIdentity = _tempPrimarys.Any(b => b.Attribute.IsIdentity); - var sb = new StringBuilder().Append("MERGE INTO ").Append(_commonUtils.QuoteSqlName(TableRuleInvoke())).Append(" t1 \r\nUSING ("); - WriteSourceSelectUnionAll(data, sb, dbParams); - sb.Append(" ) t2 ON (").Append(string.Join(" AND ", _tempPrimarys.Select(a => $"t1.{_commonUtils.QuoteSqlName(a.Attribute.Name)} = t2.{_commonUtils.QuoteSqlName(a.Attribute.Name)}"))).Append(") \r\n"); - - var cols = _table.Columns.Values.Where(a => _updateSetDict.ContainsKey(a.Attribute.Name) || - _tempPrimarys.Contains(a) == false && a.Attribute.CanUpdate == true && a.Attribute.IsIdentity == false && _updateIgnore.ContainsKey(a.Attribute.Name) == false); - if (_doNothing == false && cols.Any()) - sb.Append("WHEN MATCHED THEN \r\n") - .Append(" update set ").Append(string.Join(", ", cols.Select(a => - { - if (_updateSetDict.TryGetValue(a.Attribute.Name, out var valsql)) - return $"{_commonUtils.QuoteSqlName(a.Attribute.Name)} = {valsql}"; - return a.Attribute.IsVersion && a.Attribute.MapType != typeof(byte[]) ? - $"{_commonUtils.QuoteSqlName(a.Attribute.Name)} = t1.{_commonUtils.QuoteSqlName(a.Attribute.Name)} + 1" : - $"{_commonUtils.QuoteSqlName(a.Attribute.Name)} = t2.{_commonUtils.QuoteSqlName(a.Attribute.Name)}"; - }))).Append(" \r\n"); - - cols = _table.Columns.Values.Where(a => a.Attribute.CanInsert == true); - if (tempPrimaryIsIdentity == false) cols = cols.Where(a => a.Attribute.IsIdentity == false || string.IsNullOrEmpty(a.DbInsertValue) == false); - if (cols.Any()) - sb.Append("WHEN NOT MATCHED THEN \r\n") - .Append(" insert (").Append(string.Join(", ", cols.Select(a => _commonUtils.QuoteSqlName(a.Attribute.Name)))).Append(") \r\n") - .Append(" values (").Append(string.Join(", ", cols.Select(a => - { - //InsertValueSql = "seq.nextval" - if (tempPrimaryIsIdentity == false && a.Attribute.IsIdentity && string.IsNullOrEmpty(a.DbInsertValue) == false) return a.DbInsertValue; - return $"t2.{_commonUtils.QuoteSqlName(a.Attribute.Name)}"; - }))).Append(")"); - - return sb.ToString(); - } - string getInsertSql(List data) - { - var insert = _orm.Insert() - .AsTable(_tableRule).AsType(_table.Type) - .WithConnection(_connection) - .WithTransaction(_transaction) - .NoneParameter(true) as Internal.CommonProvider.InsertProvider; - insert._source = data; - insert._table = _table; - var sql = insert.ToSql(); - if (string.IsNullOrEmpty(sql)) return null; - if (insert._params?.Any() == true) dbParams.AddRange(insert._params); - return sql; - } - } - } -} \ No newline at end of file diff --git a/Providers/FreeSql.Provider.Odbc/Dameng/Curd/OdbcDamengSelect.cs b/Providers/FreeSql.Provider.Odbc/Dameng/Curd/OdbcDamengSelect.cs deleted file mode 100644 index 1dc9c3a03..000000000 --- a/Providers/FreeSql.Provider.Odbc/Dameng/Curd/OdbcDamengSelect.cs +++ /dev/null @@ -1,243 +0,0 @@ -using FreeSql.Internal; -using FreeSql.Internal.Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Text; - -namespace FreeSql.Odbc.Dameng -{ - - class OdbcDamengSelect : FreeSql.Internal.CommonProvider.Select1Provider - { - - internal static string ToSqlStatic(CommonUtils _commonUtils, CommonExpression _commonExpression, string _select, bool _distinct, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List _tables, List> tbUnions, Func _aliasRule, string _tosqlAppendContent, List _whereGlobalFilter, IFreeSql _orm) - { - if (_orm.CodeFirst.IsAutoSyncStructure) - _orm.CodeFirst.SyncStructure(_tables.Select(a => a.Table.Type).ToArray()); - - if (_whereGlobalFilter.Any()) - foreach (var tb in _tables.Where(a => a.Type != SelectTableInfoType.Parent)) - { - tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereGlobalFilter.Where(a => a.Before == false), true); - tb.CascadeBefore = _commonExpression.GetWhereCascadeSql(tb, _whereGlobalFilter.Where(a => a.Before == true), true); - } - - var sb = new StringBuilder(); - var sbunion = new StringBuilder(); - var sbnav = new StringBuilder(); - var tbUnionsGt0 = tbUnions.Count > 1; - for (var tbUnionsIdx = 0; tbUnionsIdx < tbUnions.Count; tbUnionsIdx++) - { - if (tbUnionsIdx > 0) sb.Append("\r\n \r\nUNION ALL\r\n \r\n"); - var tbUnion = tbUnions[tbUnionsIdx]; - - sbunion.Append(_select); - if (_distinct) sbunion.Append("DISTINCT "); - var tbsjoin = _tables.Where(a => a.Type != SelectTableInfoType.From).ToArray(); - var tbsfrom = _tables.Where(a => a.Type == SelectTableInfoType.From).ToArray(); - - var isRownum = string.IsNullOrEmpty(_orderby) && _skip > 0; - if (isRownum && field == "*") sbunion.Append(tbsfrom[0].Alias).Append("."); //#1519 bug - sbunion.Append(field); - if (isRownum) sbunion.Append(", ROWNUM AS \"__rownum__\""); - sbunion.Append(" \r\nFROM "); - for (var a = 0; a < tbsfrom.Length; a++) - { - sbunion.Append(_commonUtils.QuoteSqlName(tbUnion[tbsfrom[a].Table.Type])).Append(" ").Append(_aliasRule?.Invoke(tbsfrom[a].Table.Type, tbsfrom[a].Alias) ?? tbsfrom[a].Alias); - if (tbsjoin.Length > 0) - { - //如果存在 join 查询,则处理 from t1, t2 改为 from t1 inner join t2 on 1 = 1 - for (var b = 1; b < tbsfrom.Length; b++) - { - sbunion.Append(" \r\nLEFT JOIN ").Append(_commonUtils.QuoteSqlName(tbUnion[tbsfrom[b].Table.Type])).Append(" ").Append(_aliasRule?.Invoke(tbsfrom[b].Table.Type, tbsfrom[b].Alias) ?? tbsfrom[b].Alias); - - if (string.IsNullOrEmpty(tbsfrom[b].NavigateCondition) && - string.IsNullOrEmpty(tbsfrom[b].On) && - string.IsNullOrEmpty(tbsfrom[b].Cascade) && - string.IsNullOrEmpty(tbsfrom[b].CascadeBefore)) sbunion.Append(" ON 1 = 1"); - else sbunion.Append(" ON ").Append(string.Join(" AND ", new[] - { - tbsfrom[b].CascadeBefore, - tbsfrom[b].NavigateCondition ?? tbsfrom[b].On, - tbsfrom[b].Cascade - }.Where(onSql => string.IsNullOrEmpty(onSql) == false))); - } - break; - } - else - { - if (a > 0 && !string.IsNullOrEmpty(tbsfrom[a].CascadeBefore)) sbnav.Append(" AND ").Append(tbsfrom[a].CascadeBefore); - if (!string.IsNullOrEmpty(tbsfrom[a].NavigateCondition)) sbnav.Append(" AND (").Append(tbsfrom[a].NavigateCondition).Append(")"); - if (!string.IsNullOrEmpty(tbsfrom[a].On)) sbnav.Append(" AND (").Append(tbsfrom[a].On).Append(")"); - if (a > 0 && !string.IsNullOrEmpty(tbsfrom[a].Cascade)) sbnav.Append(" AND ").Append(tbsfrom[a].Cascade); - } - if (a < tbsfrom.Length - 1) sbunion.Append(", "); - } - foreach (var tb in tbsjoin) - { - switch (tb.Type) - { - case SelectTableInfoType.Parent: - case SelectTableInfoType.RawJoin: - continue; - case SelectTableInfoType.LeftJoin: - sbunion.Append(" \r\nLEFT JOIN "); - break; - case SelectTableInfoType.InnerJoin: - sbunion.Append(" \r\nINNER JOIN "); - break; - case SelectTableInfoType.RightJoin: - sbunion.Append(" \r\nRIGHT JOIN "); - break; - } - sbunion.Append(_commonUtils.QuoteSqlName(tbUnion[tb.Table.Type])).Append(" ").Append(_aliasRule?.Invoke(tb.Table.Type, tb.Alias) ?? tb.Alias) - .Append(" ON ").Append(string.Join(" AND ", new[] - { - tb.CascadeBefore, - tb.On ?? tb.NavigateCondition, - tb.Cascade - }.Where(onSql => string.IsNullOrEmpty(onSql) == false))); - if (!string.IsNullOrEmpty(tb.On) && !string.IsNullOrEmpty(tb.NavigateCondition)) sbnav.Append(" AND (").Append(tb.NavigateCondition).Append(")"); - } - if (_join.Length > 0) sbunion.Append(_join); - - if (!string.IsNullOrEmpty(_tables[0].CascadeBefore)) sbnav.Append(" AND ").Append(_tables[0].CascadeBefore); - sbnav.Append(_where); - if (!string.IsNullOrEmpty(_tables[0].Cascade)) sbnav.Append(" AND ").Append(_tables[0].Cascade); - - if (string.IsNullOrEmpty(_orderby) && (_skip > 0 || _limit > 0)) - sbnav.Append(" AND ROWNUM < ").Append(_skip + _limit + 1); - if (sbnav.Length > 0) - sbunion.Append(" \r\nWHERE ").Append(sbnav.Remove(0, 5)); - if (string.IsNullOrEmpty(_groupby) == false) - { - sbunion.Append(_groupby); - if (string.IsNullOrEmpty(_having) == false) - sbunion.Append(" \r\nHAVING ").Append(_having.Substring(5)); - } - sbunion.Append(_orderby); - - if (string.IsNullOrEmpty(_orderby)) - { - if (_skip > 0) - sbunion.Insert(0, $"{_select}t.* FROM (").Append(") t WHERE t.\"__rownum__\" > ").Append(_skip); - } - else - { - if (_skip > 0 && _limit > 0) sbunion.Insert(0, $"{_select}t.* FROM (SELECT rt.*, ROWNUM AS \"__rownum__\" FROM (").Append(") rt WHERE ROWNUM < ").Append(_skip + _limit + 1).Append(") t WHERE t.\"__rownum__\" > ").Append(_skip); - else if (_skip > 0) sbunion.Insert(0, $"{_select}t.* FROM (").Append(") t WHERE ROWNUM > ").Append(_skip); - else if (_limit > 0) sbunion.Insert(0, $"{_select}t.* FROM (").Append(") t WHERE ROWNUM < ").Append(_limit + 1); - } - - if (tbUnionsGt0) sbunion.Insert(0, $"{_select}* from (").Append(") ftb"); - sb.Append(sbunion); - sbnav.Clear(); - sbunion.Clear(); - } - var sql = sb.Append(_tosqlAppendContent).ToString(); - - var aliasGreater30 = 0; - foreach (var tb in _tables) - if (tb.Alias.Length > 30) sql = sql.Replace(tb.Alias, $"than30_{aliasGreater30++}"); - - return sql; - } - - public OdbcDamengSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override ISelect From(Expression, T2, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcDamengSelect(_orm, _commonUtils, _commonExpression, null); OdbcDamengSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcDamengSelect(_orm, _commonUtils, _commonExpression, null); OdbcDamengSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcDamengSelect(_orm, _commonUtils, _commonExpression, null); OdbcDamengSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcDamengSelect(_orm, _commonUtils, _commonExpression, null); OdbcDamengSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, T6, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcDamengSelect(_orm, _commonUtils, _commonExpression, null); OdbcDamengSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, T6, T7, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcDamengSelect(_orm, _commonUtils, _commonExpression, null); OdbcDamengSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, T6, T7, T8, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcDamengSelect(_orm, _commonUtils, _commonExpression, null); OdbcDamengSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, T6, T7, T8, T9, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcDamengSelect(_orm, _commonUtils, _commonExpression, null); OdbcDamengSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, T6, T7, T8, T9, T10, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcDamengSelect(_orm, _commonUtils, _commonExpression, null); OdbcDamengSelect.CopyData(this, ret, exp?.Parameters); return ret; } - - public override ISelect From(Expression, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcDamengSelect(_orm, _commonUtils, _commonExpression, null); OdbcDamengSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcDamengSelect(_orm, _commonUtils, _commonExpression, null); OdbcDamengSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcDamengSelect(_orm, _commonUtils, _commonExpression, null); OdbcDamengSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcDamengSelect(_orm, _commonUtils, _commonExpression, null); OdbcDamengSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcDamengSelect(_orm, _commonUtils, _commonExpression, null); OdbcDamengSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcDamengSelect(_orm, _commonUtils, _commonExpression, null); OdbcDamengSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override string ToSql(string field = null) => ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcDamengSelect : FreeSql.Internal.CommonProvider.Select2Provider where T2 : class - { - public OdbcDamengSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcDamengSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcDamengSelect : FreeSql.Internal.CommonProvider.Select3Provider where T2 : class where T3 : class - { - public OdbcDamengSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcDamengSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcDamengSelect : FreeSql.Internal.CommonProvider.Select4Provider where T2 : class where T3 : class where T4 : class - { - public OdbcDamengSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcDamengSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcDamengSelect : FreeSql.Internal.CommonProvider.Select5Provider where T2 : class where T3 : class where T4 : class where T5 : class - { - public OdbcDamengSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcDamengSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcDamengSelect : FreeSql.Internal.CommonProvider.Select6Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class - { - public OdbcDamengSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcDamengSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcDamengSelect : FreeSql.Internal.CommonProvider.Select7Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class - { - public OdbcDamengSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcDamengSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcDamengSelect : FreeSql.Internal.CommonProvider.Select8Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class - { - public OdbcDamengSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcDamengSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcDamengSelect : FreeSql.Internal.CommonProvider.Select9Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class - { - public OdbcDamengSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcDamengSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcDamengSelect : FreeSql.Internal.CommonProvider.Select10Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class - { - public OdbcDamengSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcDamengSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - - class OdbcDamengSelect : FreeSql.Internal.CommonProvider.Select11Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class - { - public OdbcDamengSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcDamengSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcDamengSelect : FreeSql.Internal.CommonProvider.Select12Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class - { - public OdbcDamengSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcDamengSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcDamengSelect : FreeSql.Internal.CommonProvider.Select13Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class where T13 : class - { - public OdbcDamengSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcDamengSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcDamengSelect : FreeSql.Internal.CommonProvider.Select14Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class where T13 : class where T14 : class - { - public OdbcDamengSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcDamengSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcDamengSelect : FreeSql.Internal.CommonProvider.Select15Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class where T13 : class where T14 : class where T15 : class - { - public OdbcDamengSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcDamengSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcDamengSelect : FreeSql.Internal.CommonProvider.Select16Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class where T13 : class where T14 : class where T15 : class where T16 : class - { - public OdbcDamengSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcDamengSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } -} diff --git a/Providers/FreeSql.Provider.Odbc/Dameng/Curd/OdbcDamengUpdate.cs b/Providers/FreeSql.Provider.Odbc/Dameng/Curd/OdbcDamengUpdate.cs deleted file mode 100644 index 2f4bfc946..000000000 --- a/Providers/FreeSql.Provider.Odbc/Dameng/Curd/OdbcDamengUpdate.cs +++ /dev/null @@ -1,72 +0,0 @@ -using FreeSql.Internal; -using FreeSql.Internal.Model; -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace FreeSql.Odbc.Dameng -{ - - class OdbcDamengUpdate : Internal.CommonProvider.UpdateProvider - { - - public OdbcDamengUpdate(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) - : base(orm, commonUtils, commonExpression, dywhere) - { - } - - public override int ExecuteAffrows() => base.SplitExecuteAffrows(_batchRowsLimit > 0 ? _batchRowsLimit : 200, _batchParameterLimit > 0 ? _batchParameterLimit : 999); - protected override List ExecuteUpdated(IEnumerable columns) => base.SplitExecuteUpdated(_batchRowsLimit > 0 ? _batchRowsLimit : 200, _batchParameterLimit > 0 ? _batchParameterLimit : 999, columns); - - protected override List RawExecuteUpdated(IEnumerable columns) => throw new NotImplementedException($"FreeSql.Odbc.Dameng {CoreStrings.S_Not_Implemented_Feature}"); - - protected override void ToSqlCase(StringBuilder caseWhen, ColumnInfo[] primarys) - { - if (primarys.Length == 1) - { - var pk = primarys.First(); - caseWhen.Append(_commonUtils.RereadColumn(pk, _commonUtils.QuoteSqlName(pk.Attribute.Name))); - return; - } - caseWhen.Append("("); - var pkidx = 0; - foreach (var pk in primarys) - { - if (pkidx > 0) caseWhen.Append(" || '+' || "); - caseWhen.Append(_commonUtils.RereadColumn(pk, _commonUtils.QuoteSqlName(pk.Attribute.Name))); - ++pkidx; - } - caseWhen.Append(")"); - } - - protected override void ToSqlWhen(StringBuilder sb, ColumnInfo[] primarys, object d) - { - if (primarys.Length == 1) - { - sb.Append(_commonUtils.FormatSql("{0}", primarys[0].GetDbValue(d))); - return; - } - sb.Append("("); - var pkidx = 0; - foreach (var pk in primarys) - { - if (pkidx > 0) sb.Append(" || '+' || "); - sb.Append(_commonUtils.FormatSql("{0}", pk.GetDbValue(d))); - ++pkidx; - } - sb.Append(")"); - } - -#if net40 -#else - public override Task ExecuteAffrowsAsync(CancellationToken cancellationToken = default) => base.SplitExecuteAffrowsAsync(_batchRowsLimit > 0 ? _batchRowsLimit : 200, _batchParameterLimit > 0 ? _batchParameterLimit : 999, cancellationToken); - protected override Task> ExecuteUpdatedAsync(IEnumerable columns, CancellationToken cancellationToken = default) => base.SplitExecuteUpdatedAsync(_batchRowsLimit > 0 ? _batchRowsLimit : 200, _batchParameterLimit > 0 ? _batchParameterLimit : 999, columns, cancellationToken); - - protected override Task> RawExecuteUpdatedAsync(IEnumerable columns, CancellationToken cancellationToken = default) => throw new NotImplementedException($"FreeSql.Odbc.Dameng {CoreStrings.S_Not_Implemented_Feature}"); -#endif - } -} diff --git a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengAdo/OdbcDamengAdo.cs b/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengAdo/OdbcDamengAdo.cs deleted file mode 100644 index 7ed10e9ee..000000000 --- a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengAdo/OdbcDamengAdo.cs +++ /dev/null @@ -1,91 +0,0 @@ -using FreeSql.Internal; -using FreeSql.Internal.CommonProvider; -using FreeSql.Internal.Model; -using FreeSql.Internal.ObjectPool; -using System; -using System.Collections; -using System.Data.Common; -using System.Data.Odbc; -using System.Linq; -using System.Text; -using System.Threading; - -namespace FreeSql.Odbc.Dameng -{ - class OdbcDamengAdo : FreeSql.Internal.CommonProvider.AdoProvider - { - public OdbcDamengAdo() : base(DataType.OdbcDameng, null, null) { } - public OdbcDamengAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings, Func connectionFactory) : base(DataType.OdbcDameng, masterConnectionString, slaveConnectionStrings) - { - base._util = util; - if (connectionFactory != null) - { - var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.OdbcDameng, connectionFactory); - ConnectionString = pool.TestConnection?.ConnectionString; - MasterPool = pool; - return; - } - - var isAdoPool = masterConnectionString?.StartsWith("AdoConnectionPool,") ?? false; - if (isAdoPool) masterConnectionString = masterConnectionString.Substring("AdoConnectionPool,".Length); - if (!string.IsNullOrEmpty(masterConnectionString)) - MasterPool = isAdoPool ? - new DbConnectionStringPool(base.DataType, CoreStrings.S_MasterDatabase, () => new OdbcConnection(masterConnectionString)) as IObjectPool : - new OdbcDamengConnectionPool(CoreStrings.S_MasterDatabase, masterConnectionString, null, null); - - slaveConnectionStrings?.ToList().ForEach(slaveConnectionString => - { - var slavePool = isAdoPool ? - new DbConnectionStringPool(base.DataType, $"{CoreStrings.S_SlaveDatabase}{SlavePools.Count + 1}", () => new OdbcConnection(slaveConnectionString)) as IObjectPool : - new OdbcDamengConnectionPool($"{CoreStrings.S_SlaveDatabase}{SlavePools.Count + 1}", slaveConnectionString, () => Interlocked.Decrement(ref slaveUnavailables), () => Interlocked.Increment(ref slaveUnavailables)); - SlavePools.Add(slavePool); - }); - } - public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn) - { - if (param == null) return "NULL"; - if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false)) - param = Utils.GetDataReaderValue(mapType, param); - - if (param is byte[]) - return $"hextoraw('{CommonUtils.BytesSqlRaw(param as byte[])}')"; - else if (param is bool || param is bool?) - return (bool)param ? 1 : 0; - else if (param is string) - return string.Concat("'", param.ToString().Replace("'", "''"), "'"); - else if (param is char) - return string.Concat("'", param.ToString().Replace("'", "''").Replace('\0', ' '), "'"); - else if (param is Enum) - return AddslashesTypeHandler(param.GetType(), param) ?? ((Enum)param).ToInt64(); - else if (decimal.TryParse(string.Concat(param), out var trydec)) - return param; - - else if (param is DateTime) - return AddslashesTypeHandler(typeof(DateTime), param) ?? string.Concat("to_timestamp('", ((DateTime)param).ToString("yyyy-MM-dd HH:mm:ss.ffffff"), "','YYYY-MM-DD HH24:MI:SS.FF6')"); - else if (param is DateTime?) - return AddslashesTypeHandler(typeof(DateTime?), param) ?? string.Concat("to_timestamp('", ((DateTime)param).ToString("yyyy-MM-dd HH:mm:ss.ffffff"), "','YYYY-MM-DD HH24:MI:SS.FF6')"); - - else if (param is TimeSpan || param is TimeSpan?) - return $"numtodsinterval({((TimeSpan)param).Ticks * 1.0 / 10000000},'second')"; - else if (param is IEnumerable) - return AddslashesIEnumerable(param, mapType, mapColumn); - - return string.Concat("'", param.ToString().Replace("'", "''"), "'"); - //if (param is string) return string.Concat('N', nparms[a]); - } - - public override DbCommand CreateCommand() - { - return new OdbcCommand(); - } - - public override void ReturnConnection(IObjectPool pool, Object conn, Exception ex) - { - var rawPool = pool as OdbcDamengConnectionPool; - if (rawPool != null) rawPool.Return(conn, ex); - else pool.Return(conn); - } - - public override DbParameter[] GetDbParamtersByObject(string sql, object obj) => _util.GetDbParamtersByObject(sql, obj); - } -} diff --git a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengAdo/OdbcDamengConnectionPool.cs b/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengAdo/OdbcDamengConnectionPool.cs deleted file mode 100644 index 9f8dd75a3..000000000 --- a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengAdo/OdbcDamengConnectionPool.cs +++ /dev/null @@ -1,250 +0,0 @@ -using FreeSql.Internal.ObjectPool; -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Data.Odbc; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; - -namespace FreeSql.Odbc.Dameng -{ - - class OdbcDamengConnectionPool : ObjectPool - { - - internal Action availableHandler; - internal Action unavailableHandler; - internal string UserId { get; set; } - - public OdbcDamengConnectionPool(string name, string connectionString, Action availableHandler, Action unavailableHandler) : base(null) - { - this.UserId = OdbcDamengConnectionPool.GetUserId(connectionString); - - this.availableHandler = availableHandler; - this.unavailableHandler = unavailableHandler; - var policy = new OdbcDamengConnectionPoolPolicy - { - _pool = this, - Name = name - }; - this.Policy = policy; - policy.ConnectionString = connectionString; - } - - public static string GetUserId(string connectionString) - { - var userIdMatch = Regex.Match(connectionString, @"(User\s+Id|Uid|User)\s*=\s*([^;]+)", RegexOptions.IgnoreCase); - if (userIdMatch.Success == false) throw new Exception(@"从 ConnectionString 中无法匹配 (User\s+Id|Uid|User)\s*=\s*([^;]+)"); - return userIdMatch.Groups[2].Value.Trim().ToUpper(); - } - - public void Return(Object obj, Exception exception, bool isRecreate = false) - { - if (exception != null && exception is OdbcException) - { - if (obj.Value.Ping() == false) - base.SetUnavailable(exception, obj.LastGetTimeCopy); - } - base.Return(obj, isRecreate); - } - } - - class OdbcDamengConnectionPoolPolicy : IPolicy - { - - internal OdbcDamengConnectionPool _pool; - public string Name { get; set; } = $"Dameng OdbcConnection {CoreStrings.S_ObjectPool}"; - public int PoolSize { get; set; } = 100; - public TimeSpan SyncGetTimeout { get; set; } = TimeSpan.FromSeconds(10); - public TimeSpan IdleTimeout { get; set; } = TimeSpan.FromSeconds(20); - public int AsyncGetCapacity { get; set; } = 10000; - public bool IsThrowGetTimeoutException { get; set; } = true; - public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 2; - public int Weight { get; set; } = 1; - - static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); - private string _connectionString; - public string ConnectionString - { - get => _connectionString; - set - { - _connectionString = value ?? ""; - - var minPoolSize = 0; - var pattern = @"Min\s*pool\s*size\s*=\s*(\d+)"; - var m = Regex.Match(_connectionString, pattern, RegexOptions.IgnoreCase); - if (m.Success) - { - minPoolSize = int.Parse(m.Groups[1].Value); - _connectionString = Regex.Replace(_connectionString, pattern, "", RegexOptions.IgnoreCase); - } - - pattern = @"Max\s*pool\s*size\s*=\s*(\d+)"; - m = Regex.Match(_connectionString, pattern, RegexOptions.IgnoreCase); - if (m.Success == false || int.TryParse(m.Groups[1].Value, out var poolsize) == false || poolsize <= 0) poolsize = Math.Max(100, minPoolSize); - var connStrIncr = dicConnStrIncr.AddOrUpdate(_connectionString, 1, (oldkey, oldval) => Math.Min(5, oldval + 1)); - PoolSize = poolsize + connStrIncr; - _connectionString = m.Success ? - Regex.Replace(_connectionString, pattern, $"Max pool size={PoolSize}", RegexOptions.IgnoreCase) : - $"{_connectionString};Max pool size={PoolSize}"; - - pattern = @"Connection\s*LifeTime\s*=\s*(\d+)"; - m = Regex.Match(_connectionString, pattern, RegexOptions.IgnoreCase); - if (m.Success) - { - IdleTimeout = TimeSpan.FromSeconds(int.Parse(m.Groups[1].Value)); - _connectionString = Regex.Replace(_connectionString, pattern, "", RegexOptions.IgnoreCase); - } - - FreeSql.Internal.CommonUtils.PrevReheatConnectionPool(_pool, minPoolSize); - } - } - - public bool OnCheckAvailable(Object obj) - { - if (obj.Value == null) return false; - if (obj.Value.State == ConnectionState.Closed) obj.Value.Open(); - return obj.Value.Ping(true); - } - - public DbConnection OnCreate() - { - var conn = new OdbcConnection(_connectionString); - return conn; - } - - public void OnDestroy(DbConnection obj) - { - if (obj.State != ConnectionState.Closed) obj.Close(); - obj.Dispose(); - } - - public void OnGet(Object obj) - { - - if (_pool.IsAvailable) - { - if (obj.Value == null) - { - _pool.SetUnavailable(new Exception(CoreStrings.S_ConnectionStringError), obj.LastGetTimeCopy); - throw new Exception(CoreStrings.S_ConnectionStringError_Check(this.Name)); - } - - if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) - { - - try - { - obj.Value.Open(); - } - catch (Exception ex) - { - if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) - throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); - throw ex; - } - } - } - } - -#if net40 -#else - async public Task OnGetAsync(Object obj) - { - - if (_pool.IsAvailable) - { - if (obj.Value == null) - { - _pool.SetUnavailable(new Exception(CoreStrings.S_ConnectionStringError), obj.LastGetTimeCopy); - throw new Exception(CoreStrings.S_ConnectionStringError_Check(this.Name)); - } - - if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) - { - - try - { - await obj.Value.OpenAsync(); - } - catch (Exception ex) - { - if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) - throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); - throw ex; - } - } - } - } -#endif - - public void OnGetTimeout() - { - - } - - public void OnReturn(Object obj) - { - //if (obj?.Value != null && obj.Value.State != ConnectionState.Closed) try { obj.Value.Close(); } catch { } - } - - public void OnAvailable() - { - _pool.availableHandler?.Invoke(); - } - - public void OnUnavailable() - { - _pool.unavailableHandler?.Invoke(); - } - } - - static class DbConnectionExtensions - { - - static DbCommand PingCommand(DbConnection conn) - { - var cmd = conn.CreateCommand(); - cmd.CommandTimeout = 5; - cmd.CommandText = "select 1 from dual"; - return cmd; - } - public static bool Ping(this DbConnection that, bool isThrow = false) - { - try - { - PingCommand(that).ExecuteNonQuery(); - return true; - } - catch - { - if (that.State != ConnectionState.Closed) try { that.Close(); } catch { } - if (isThrow) throw; - return false; - } - } - -#if net40 -#else - async public static Task PingAsync(this DbConnection that, bool isThrow = false) - { - try - { - await PingCommand(that).ExecuteNonQueryAsync(); - return true; - } - catch - { - if (that.State != ConnectionState.Closed) try { that.Close(); } catch { } - if (isThrow) throw; - return false; - } - } -#endif - } -} diff --git a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengCodeFirst.cs b/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengCodeFirst.cs deleted file mode 100644 index 3e52077dd..000000000 --- a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengCodeFirst.cs +++ /dev/null @@ -1,482 +0,0 @@ -using FreeSql.DataAnnotations; -using FreeSql.Internal; -using FreeSql.Internal.Model; -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Odbc; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Text.RegularExpressions; - -namespace FreeSql.Odbc.Dameng -{ - - class OdbcDamengCodeFirst : Internal.CommonProvider.CodeFirstProvider - { - public override bool IsNoneCommandParameter { get => true; set => base.IsNoneCommandParameter = true; } - public OdbcDamengCodeFirst(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression) : base(orm, commonUtils, commonExpression) { } - - static object _dicCsToDbLock = new object(); - static Dictionary> _dicCsToDb = new Dictionary>() { - { typeof(bool).FullName, CsToDb.New(OdbcType.Bit, "number","number(1) NOT NULL", null, false, false) },{ typeof(bool?).FullName, CsToDb.New(OdbcType.Bit, "number","number(1) NULL", null, true, null) }, - - { typeof(sbyte).FullName, CsToDb.New(OdbcType.SmallInt, "number", "number(4) NOT NULL", false, false, 0) },{ typeof(sbyte?).FullName, CsToDb.New(OdbcType.SmallInt, "number", "number(4) NULL", false, true, null) }, - { typeof(short).FullName, CsToDb.New(OdbcType.SmallInt, "number","number(6) NOT NULL", false, false, 0) },{ typeof(short?).FullName, CsToDb.New(OdbcType.SmallInt, "number", "number(6) NULL", false, true, null) }, - { typeof(int).FullName, CsToDb.New(OdbcType.Int, "number", "number(11) NOT NULL", false, false, 0) },{ typeof(int?).FullName, CsToDb.New(OdbcType.Int, "number", "number(11) NULL", false, true, null) }, - { typeof(long).FullName, CsToDb.New(OdbcType.BigInt, "number","number(21) NOT NULL", false, false, 0) },{ typeof(long?).FullName, CsToDb.New(OdbcType.BigInt, "number","number(21) NULL", false, true, null) }, - - { typeof(byte).FullName, CsToDb.New(OdbcType.TinyInt, "number","number(3) NOT NULL", true, false, 0) },{ typeof(byte?).FullName, CsToDb.New(OdbcType.TinyInt, "number","number(3) NULL", true, true, null) }, - { typeof(ushort).FullName, CsToDb.New(OdbcType.Int, "number","number(5) NOT NULL", true, false, 0) },{ typeof(ushort?).FullName, CsToDb.New(OdbcType.Int, "number", "number(5) NULL", true, true, null) }, - { typeof(uint).FullName, CsToDb.New(OdbcType.BigInt, "number", "number(10) NOT NULL", true, false, 0) },{ typeof(uint?).FullName, CsToDb.New(OdbcType.BigInt, "number", "number(10) NULL", true, true, null) }, - { typeof(ulong).FullName, CsToDb.New(OdbcType.Decimal, "number", "number(20) NOT NULL", true, false, 0) },{ typeof(ulong?).FullName, CsToDb.New(OdbcType.Decimal, "number", "number(20) NULL", true, true, null) }, - - { typeof(double).FullName, CsToDb.New(OdbcType.Double, "double", "double NOT NULL", false, false, 0) },{ typeof(double?).FullName, CsToDb.New(OdbcType.Double, "double", "double NULL", false, true, null) }, - { typeof(float).FullName, CsToDb.New(OdbcType.Real, "real","real NOT NULL", false, false, 0) },{ typeof(float?).FullName, CsToDb.New(OdbcType.Real, "real","real NULL", false, true, null) }, - { typeof(decimal).FullName, CsToDb.New(OdbcType.Decimal, "number", "number(10,2) NOT NULL", false, false, 0) },{ typeof(decimal?).FullName, CsToDb.New(OdbcType.Decimal, "number", "number(10,2) NULL", false, true, null) }, - - //达梦8 ODBC 不支持 TimeSpan - //{ typeof(TimeSpan).FullName, CsToDb.NewInfo(OdbcType.Time, "interval day to second","interval day(2) to second(6) NOT NULL", false, false, 0) },{ typeof(TimeSpan?).FullName, (OdbcType.Time, "interval day to second", "interval day(2) to second(6) NULL",false, true, null) }, - { typeof(DateTime).FullName, CsToDb.New(OdbcType.DateTime, "timestamp", "timestamp(6) NOT NULL", false, false, new DateTime(1970,1,1)) },{ typeof(DateTime?).FullName, CsToDb.New(OdbcType.DateTime, "timestamp", "timestamp(6) NULL", false, true, null) }, - { typeof(DateTimeOffset).FullName, CsToDb.New(OdbcType.DateTime, "timestamp", "timestamp(6) NOT NULL", false, false, new DateTime(1970,1,1)) },{ typeof(DateTimeOffset?).FullName, CsToDb.New(OdbcType.DateTime, "timestamp", "timestamp(6) NULL", false, true, null) }, - - { typeof(byte[]).FullName, CsToDb.New(OdbcType.VarBinary, "blob", "blob NULL", false, null, new byte[0]) }, - { typeof(string).FullName, CsToDb.New(OdbcType.NVarChar, "nvarchar2", "nvarchar2(255) NULL", false, null, "") }, - { typeof(char).FullName, CsToDb.New(OdbcType.Char, "char", "char(1) NULL", false, null, '\0') }, - - { typeof(Guid).FullName, CsToDb.New(OdbcType.Char, "char", "char(36) NOT NULL", false, false, Guid.Empty) },{ typeof(Guid?).FullName, CsToDb.New(OdbcType.Char, "char", "char(36) NULL", false, true, null) }, - }; - - public override DbInfoResult GetDbInfo(Type type) - { - if (_dicCsToDb.TryGetValue(type.FullName, out var trydc)) return new DbInfoResult((int)trydc.type, trydc.dbtype, trydc.dbtypeFull, trydc.isnullable, trydc.defaultValue); - if (type.IsArray) return null; - var enumType = type.IsEnum ? type : null; - if (enumType == null && type.IsNullableType()) - { - var genericTypes = type.GetGenericArguments(); - if (genericTypes.Length == 1 && genericTypes.First().IsEnum) enumType = genericTypes.First(); - } - if (enumType != null) - { - var newItem = enumType.GetCustomAttributes(typeof(FlagsAttribute), false).Any() ? - CsToDb.New(OdbcType.Int, "number", $"number(32){(type.IsEnum ? " NOT NULL" : "")}", false, type.IsEnum ? false : true, enumType.CreateInstanceGetDefaultValue()) : - CsToDb.New(OdbcType.BigInt, "number", $"number(16){(type.IsEnum ? " NOT NULL" : "")}", false, type.IsEnum ? false : true, enumType.CreateInstanceGetDefaultValue()); - if (_dicCsToDb.ContainsKey(type.FullName) == false) - { - lock (_dicCsToDbLock) - { - if (_dicCsToDb.ContainsKey(type.FullName) == false) - _dicCsToDb.Add(type.FullName, newItem); - } - } - return new DbInfoResult((int)newItem.type, newItem.dbtype, newItem.dbtypeFull, newItem.isnullable, newItem.defaultValue); - } - return null; - } - - protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects) - { - var userId = (_orm.Ado.MasterPool as OdbcDamengConnectionPool)?.UserId; - if (string.IsNullOrEmpty(userId)) - using (var conn = _orm.Ado.MasterPool.Get()) - { - userId = OdbcDamengConnectionPool.GetUserId(conn.Value.ConnectionString); - } - var seqcols = new List>(); //序列:列,表,自增 - var seqnameDel = new List(); //要删除的序列+触发器 - - var sb = new StringBuilder(); - var sbDeclare = new StringBuilder(); - foreach (var obj in objects) - { - if (sb.Length > 0) sb.Append("\r\n"); - var tb = obj.tableSchema; - if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName)); - if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName)); - var tbname = _commonUtils.SplitTableName(tb.DbName); - if (tbname?.Length == 1) tbname = new[] { userId, tbname[0] }; - - var tboldname = _commonUtils.SplitTableName(tb.DbOldName); //旧表名 - if (tboldname?.Length == 1) tboldname = new[] { userId, tboldname[0] }; - var primaryKeyName = (obj.tableSchema.Type.GetCustomAttributes(typeof(OraclePrimaryKeyNameAttribute), false)?.FirstOrDefault() as OraclePrimaryKeyNameAttribute)?.Name; - if (string.IsNullOrEmpty(obj.tableName) == false) - { - var tbtmpname = _commonUtils.SplitTableName(obj.tableName); - if (tbtmpname?.Length == 1) tbtmpname = new[] { userId, tbtmpname[0] }; - if (tbname[0] != tbtmpname[0] || tbname[1] != tbtmpname[1]) - { - tbname = tbtmpname; - tboldname = null; - primaryKeyName = null; - } - } - //codefirst 不支持表名中带 . - - if (string.Compare(tbname[0], userId) != 0 && _orm.Ado.ExecuteScalar(CommandType.Text, _commonUtils.FormatSql(" select 1 from sys.dba_users where username={0}", tbname[0])) == null) //创建数据库 - throw new NotImplementedException(CoreStrings.S_Dameng_NotSupport_TablespaceSchemas(tbname[0])); - - var sbalter = new StringBuilder(); - var istmpatler = false; //创建临时表,导入数据,删除旧表,修改 - if (_orm.Ado.ExecuteScalar(CommandType.Text, _commonUtils.FormatSql(" select 1 from all_tab_comments where owner={0} and table_name={1}", tbname)) == null) - { //表不存在 - if (tboldname != null) - { - if (_orm.Ado.ExecuteScalar(CommandType.Text, _commonUtils.FormatSql(" select 1 from all_tab_comments where owner={0} and table_name={1}", tboldname)) == null) - //模式或表不存在 - tboldname = null; - } - if (tboldname == null) - { - //创建表 - var createTableName = _commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}"); - sb.Append("execute immediate 'CREATE TABLE ").Append(createTableName).Append(" ( "); - foreach (var tbcol in tb.ColumnsByPosition) - { - sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ").Append(tbcol.Attribute.DbType).Append(","); - if (tbcol.Attribute.IsIdentity == true) seqcols.Add(NativeTuple.Create(tbcol, tbname, true)); - } - if (tb.Primarys.Any()) - { - var pkname = primaryKeyName ?? $"{tbname[0]}_{tbname[1]}_pk1"; - 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("),"); - } - sb.Remove(sb.Length - 1, 1); - sb.Append("\r\n) LOGGING ';\r\n"); - //创建表的索引 - foreach (var uk in tb.Indexes) - { - sb.Append("execute immediate 'CREATE "); - if (uk.IsUnique) sb.Append("UNIQUE "); - sb.Append("INDEX ").Append(_commonUtils.QuoteSqlName(ReplaceIndexName(uk.Name, tbname[1]))).Append(" ON ").Append(createTableName).Append("("); - foreach (var tbcol in uk.Columns) - { - sb.Append(_commonUtils.QuoteSqlName(tbcol.Column.Attribute.Name)); - if (tbcol.IsDesc) sb.Append(" DESC"); - sb.Append(", "); - } - sb.Remove(sb.Length - 2, 2).Append(")';\r\n"); - } - //备注 - foreach (var tbcol in tb.ColumnsByPosition) - { - if (string.IsNullOrEmpty(tbcol.Comment) == false) - sb.Append("execute immediate 'COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment).Replace("'", "''")).Append("';\r\n"); - } - if (string.IsNullOrEmpty(tb.Comment) == false) - sb.Append("execute immediate 'COMMENT ON TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tb.Comment).Replace("'", "''")).Append("';\r\n"); - continue; - } - //如果新表,旧表在一个模式下,直接修改表名 - if (string.Compare(tbname[0], tboldname[0], true) == 0) - sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tboldname[0]}.{tboldname[1]}")).Append(" RENAME TO ").Append(_commonUtils.QuoteSqlName($"{tbname[1]}")).Append("';\r\n"); - else - { - //如果新表,旧表不在一起,创建新表,导入数据,删除旧表 - istmpatler = true; - } - } - else - tboldname = null; //如果新表已经存在,不走改表名逻辑 - - //对比字段,只可以修改类型、增加字段、有限的修改字段名;保证安全不删除字段 - var sql = _commonUtils.FormatSql($@" -select -a.column_name, -a.data_type, -a.data_length, -a.data_precision, -a.data_scale, -a.char_used, -case when a.nullable = 'N' then 0 else 1 end, -nvl((select 1 from user_sequences where upper(sequence_name)=upper('{Utils.GetCsName((tboldname ?? tbname).Last())}_seq_'||a.column_name) and rownum < 2), 0), -nvl((select 1 from user_triggers where upper(trigger_name)=upper('{Utils.GetCsName((tboldname ?? tbname).Last())}_seq_'||a.column_name||'TI') and rownum < 2), 0), -b.comments -from all_tab_columns a -left join all_col_comments b on b.owner = a.owner and b.table_name = a.table_name and b.column_name = a.column_name -where a.owner={{0}} and a.table_name={{1}}", tboldname ?? tbname); - var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); - var tbstruct = ds.ToDictionary(a => string.Concat(a[0]), a => - { - var sqlType = GetDamengSqlTypeFullName(a); - return new - { - column = string.Concat(a[0]), - sqlType, - is_nullable = string.Concat(a[6]) == "1", - is_identity = string.Concat(a[7]) == "1" && string.Concat(a[8]) == "1", - comment = string.Concat(a[9]) - }; - }, StringComparer.CurrentCultureIgnoreCase); - - if (istmpatler == false) - { - foreach (var tbcol in tb.ColumnsByPosition) - { - var dbtypeNoneNotNull = Regex.Replace(tbcol.Attribute.DbType, @"NOT\s+NULL", "NULL"); - if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) || - string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol)) - { - var isCommentChanged = tbstructcol.comment != (tbcol.Comment ?? ""); - if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false) - { - istmpatler = true; - if (istmpatler && tbcol.Attribute.DbType.StartsWith("varchar", StringComparison.CurrentCultureIgnoreCase) && tbstructcol.sqlType.StartsWith("varchar2", StringComparison.CurrentCultureIgnoreCase) - && Regex.Match(tbcol.Attribute.DbType, @"\(\d+").Groups[0].Value == Regex.Match(tbstructcol.sqlType, @"\(\d+").Groups[0].Value) - istmpatler = false; - if (istmpatler && Regex.IsMatch(tbcol.Attribute.DbType, @"\(\d+") == false && Regex.IsMatch(tbstructcol.sqlType, @"\(\d+") - && string.Compare(tbcol.Attribute.DbType, Regex.Replace(tbstructcol.sqlType, @"\([^\)]+\)", ""), StringComparison.CurrentCultureIgnoreCase) == 0) - istmpatler = false; - if (istmpatler) break; - } - //sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" MODIFY (").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" ").Append(dbtypeNoneNotNull).Append(")';\r\n"); - if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable) - { - if (tbcol.Attribute.IsNullable == false) - sbalter.Append("execute immediate 'UPDATE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" SET ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" = ").Append(tbcol.DbDefaultValue.Replace("'", "''")).Append(" WHERE ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" IS NULL';\r\n"); - sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" MODIFY ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" ").Append(tbcol.Attribute.IsNullable == true ? "" : "NOT").Append(" NULL';\r\n"); - } - if (string.Compare(tbstructcol.column, tbcol.Attribute.OldName, true) == 0) - { - if (tbstructcol.is_identity) - seqnameDel.Add(Utils.GetCsName($"{tbname[1]}_seq_{tbstructcol.column}")); - //修改列名 - sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" RENAME COLUMN ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" TO ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append("';\r\n"); - if (tbcol.Attribute.IsIdentity) - seqcols.Add(NativeTuple.Create(tbcol, tbname, tbcol.Attribute.IsIdentity == true)); - } - else if (tbcol.Attribute.IsIdentity != tbstructcol.is_identity) - seqcols.Add(NativeTuple.Create(tbcol, tbname, tbcol.Attribute.IsIdentity == true)); - if (isCommentChanged) - sbalter.Append("execute immediate 'COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment ?? "").Replace("'", "''")).Append("';\r\n"); - continue; - } - //添加列 - sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ADD (").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ").Append(dbtypeNoneNotNull).Append(")';\r\n"); - if (tbcol.Attribute.IsNullable == false) - { - sbalter.Append("execute immediate 'UPDATE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" SET ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" = ").Append(tbcol.DbDefaultValue.Replace("'", "''")).Append("';\r\n"); - sbalter.Append("execute immediate 'ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" MODIFY ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" NOT NULL';\r\n"); - } - if (tbcol.Attribute.IsIdentity == true) seqcols.Add(NativeTuple.Create(tbcol, tbname, tbcol.Attribute.IsIdentity == true)); - if (string.IsNullOrEmpty(tbcol.Comment) == false) sbalter.Append("execute immediate 'COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment ?? "").Replace("'", "''")).Append("';\r\n"); - } - } - if (istmpatler == false) - { - var dsuksql = _commonUtils.FormatSql(@" -select -c.column_name, -a.index_name, -case when c.descend = 'DESC' then 1 else 0 end, -case when a.uniqueness = 'UNIQUE' then 1 else 0 end -from all_indexes a, -all_ind_columns c -where a.index_name = c.index_name -and a.table_owner = c.table_owner -and a.table_name = c.table_name -and a.owner in ({0}) and a.table_name in ({1}) -and not exists(select 1 from all_constraints where index_name = a.index_name and constraint_type = 'P')", tboldname ?? tbname); - var dsuk = _orm.Ado.ExecuteArray(CommandType.Text, dsuksql).Select(a => new[] { string.Concat(a[0]).Trim('"'), string.Concat(a[1]), string.Concat(a[2]), string.Concat(a[3]) }).ToArray(); - foreach (var uk in tb.Indexes) - { - if (string.IsNullOrEmpty(uk.Name) || uk.Columns.Any() == false) continue; - var ukname = ReplaceIndexName(uk.Name, tbname[1]); - var dsukfind1 = dsuk.Where(a => string.Compare(a[1], ukname, true) == 0).ToArray(); - if (dsukfind1.Any() == false || dsukfind1.Length != uk.Columns.Length || dsukfind1.Where(a => uk.Columns.Where(b => (a[3] == "1") == uk.IsUnique && string.Compare(b.Column.Attribute.Name, a[0], true) == 0 && (a[2] == "1") == b.IsDesc).Any()).Count() != uk.Columns.Length) - { - if (dsukfind1.Any()) sbalter.Append("execute immediate 'DROP INDEX ").Append(_commonUtils.QuoteSqlName(ukname)).Append("';\r\n"); - sbalter.Append("execute immediate 'CREATE "); - if (uk.IsUnique) sbalter.Append("UNIQUE "); - sbalter.Append("INDEX ").Append(_commonUtils.QuoteSqlName(ukname)).Append(" ON ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append("("); - foreach (var tbcol in uk.Columns) - { - sbalter.Append(_commonUtils.QuoteSqlName(tbcol.Column.Attribute.Name)); - if (tbcol.IsDesc) sbalter.Append(" DESC"); - sbalter.Append(", "); - } - sbalter.Remove(sbalter.Length - 2, 2).Append(")';\r\n"); - } - } - } - if (istmpatler == false) - { - var dbcomment = string.Concat(_orm.Ado.ExecuteScalar(CommandType.Text, _commonUtils.FormatSql(@" select comments from all_tab_comments where owner = {0} and table_name = {1} and table_type = 'TABLE'", tbname[0], tbname[1]))); - if (dbcomment != (tb.Comment ?? "")) - sb.Append("execute immediate 'COMMENT ON TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tb.Comment).Replace("'", "''")).Append("';\r\n"); - - sb.Append(sbalter); - 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(_commonUtils.QuoteSqlName(oldpk)).Append("';\r\n"); - //执行失败(语句1) 试图删除聚集主键 - - //创建临时表,数据导进临时表,然后删除原表,将临时表改名为原表名 - var tablename = tboldname == null ? _commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}") : _commonUtils.QuoteSqlName($"{tboldname[0]}.{tboldname[1]}"); - var tmptablename = _commonUtils.QuoteSqlName($"{tbname[0]}.FTmp_{tbname[1]}"); - //创建临时表 - sb.Append("execute immediate 'CREATE TABLE ").Append(tmptablename).Append(" ( "); - foreach (var tbcol in tb.ColumnsByPosition) - { - sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ").Append(tbcol.Attribute.DbType).Append(","); - if (tbcol.Attribute.IsIdentity == true) seqcols.Add(NativeTuple.Create(tbcol, tbname, true)); - } - if (tb.Primarys.Any()) - { - 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("),"); - } - sb.Remove(sb.Length - 1, 1); - sb.Append("\r\n) LOGGING ';\r\n"); - //备注 - foreach (var tbcol in tb.ColumnsByPosition) - { - if (string.IsNullOrEmpty(tbcol.Comment) == false) - sb.Append("execute immediate 'COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.FTmp_{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment).Replace("'", "''")).Append("';\r\n"); - } - if (string.IsNullOrEmpty(tb.Comment) == false) - sb.Append("execute immediate 'COMMENT ON TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.FTmp_{tbname[1]}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tb.Comment).Replace("'", "''")).Append("';\r\n"); - - sb.Append("execute immediate 'INSERT INTO ").Append(tmptablename).Append(" ("); - foreach (var tbcol in tb.ColumnsByPosition) - sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", "); - sb.Remove(sb.Length - 2, 2).Append(")\r\nSELECT "); - foreach (var tbcol in tb.ColumnsByPosition) - { - var insertvalue = "NULL"; - if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) || - string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol)) - { - insertvalue = _commonUtils.QuoteSqlName(tbstructcol.column); - if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false) - { - var dbtypeNoneNotNull = Regex.Replace(tbcol.Attribute.DbType, @"(NOT\s+)?NULL", ""); - insertvalue = $"cast({insertvalue} as {dbtypeNoneNotNull})"; - } - if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable) - insertvalue = $"nvl({insertvalue},{tbcol.DbDefaultValue})"; - } - else if (tbcol.Attribute.IsNullable == false) - insertvalue = tbcol.DbDefaultValue; - sb.Append(insertvalue.Replace("'", "''")).Append(", "); - } - sb.Remove(sb.Length - 2, 2).Append(" FROM ").Append(tablename).Append("';\r\n"); - sb.Append("execute immediate 'DROP TABLE ").Append(tablename).Append("';\r\n"); - sb.Append("execute immediate 'ALTER TABLE ").Append(tmptablename).Append(" RENAME TO ").Append(_commonUtils.QuoteSqlName($"{tbname[1]}")).Append("';\r\n"); - //创建表的索引 - foreach (var uk in tb.Indexes) - { - sb.Append("execute immediate 'CREATE "); - if (uk.IsUnique) sb.Append("UNIQUE "); - sb.Append("INDEX ").Append(_commonUtils.QuoteSqlName(ReplaceIndexName(uk.Name, tbname[1]))).Append(" ON ").Append(tablename).Append("("); - foreach (var tbcol in uk.Columns) - { - sb.Append(_commonUtils.QuoteSqlName(tbcol.Column.Attribute.Name)); - if (tbcol.IsDesc) sb.Append(" DESC"); - sb.Append(", "); - } - sb.Remove(sb.Length - 2, 2).Append(")';\r\n"); - } - } - Dictionary dicDeclare = new Dictionary(); - Action dropSequence = seqname => - { - if (dicDeclare.ContainsKey(seqname) == false) - { - sbDeclare.Append("\r\nIS").Append(seqname).Append(" NUMBER; \r\n"); - dicDeclare.Add(seqname, true); - } - sb.Append("IS").Append(seqname).Append(" := 0; \r\n") - .Append(" select count(1) into IS").Append(seqname).Append(_commonUtils.FormatSql(" from user_sequences where sequence_name={0}; \r\n", seqname)) - .Append("if IS").Append(seqname).Append(" > 0 then \r\n") - .Append(" execute immediate 'DROP SEQUENCE ").Append(_commonUtils.QuoteSqlName(seqname)).Append("';\r\n") - .Append("end if; \r\n"); - }; - Action dropTrigger = tiggerName => - { - if (dicDeclare.ContainsKey(tiggerName) == false) - { - sbDeclare.Append("\r\nIS").Append(tiggerName).Append(" NUMBER; \r\n"); - dicDeclare.Add(tiggerName, true); - } - sb.Append("IS").Append(tiggerName).Append(" := 0; \r\n") - .Append(" select count(1) into IS").Append(tiggerName).Append(_commonUtils.FormatSql(" from user_triggers where trigger_name={0}; \r\n", tiggerName)) - .Append("if IS").Append(tiggerName).Append(" > 0 then \r\n") - .Append(" execute immediate 'DROP TRIGGER ").Append(_commonUtils.QuoteSqlName(tiggerName)).Append("';\r\n") - .Append("end if; \r\n"); - }; - foreach (var seqname in seqnameDel) - { - dropSequence(seqname); - dropTrigger(seqname + "TI"); - } - foreach (var seqcol in seqcols) - { - var tbname = seqcol.Item2; - var seqname = Utils.GetCsName($"{tbname[1]}_seq_{seqcol.Item1.Attribute.Name}").ToUpper(); - var tiggerName = seqname + "TI"; - var tbname2 = _commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}"); - var colname2 = _commonUtils.QuoteSqlName(seqcol.Item1.Attribute.Name); - dropSequence(seqname); - if (seqcol.Item3) - { - var startWith = _orm.Ado.ExecuteScalar(CommandType.Text, _commonUtils.FormatSql(" select 1 from all_tab_columns where owner={0} and table_name={1} and column_name={2}", tbname[0], tbname[1], seqcol.Item1.Attribute.Name)) == null ? 1 : - _orm.Ado.ExecuteScalar(CommandType.Text, $" select nvl(max({colname2})+1,1) from {tbname2}"); - sb.Append("execute immediate 'CREATE SEQUENCE ").Append(_commonUtils.QuoteSqlName(seqname)).Append(" start with ").Append(startWith).Append("';\r\n"); - sb.Append("execute immediate 'CREATE OR REPLACE TRIGGER ").Append(_commonUtils.QuoteSqlName(tiggerName)) - .Append(" \r\nbefore insert on ").Append(tbname2) - .Append(" \r\nfor each row \r\nbegin\r\nselect ").Append(_commonUtils.QuoteSqlName(seqname)) - .Append(".nextval into :new.").Append(colname2).Append(" from dual;\r\nend;';\r\n"); - } - else - dropTrigger(tiggerName); - } - if (sbDeclare.Length > 0) sbDeclare.Insert(0, "declare "); - return sb.Length == 0 ? null : sb.Insert(0, "BEGIN \r\n").Insert(0, sbDeclare.ToString()).Append("END;").ToString(); - } - - internal static string GetDamengSqlTypeFullName(object[] row) - { - var a = row; - var sqlType = string.Concat(a[1]).ToUpper(); - var data_length = long.Parse(string.Concat(a[2])); - long.TryParse(string.Concat(a[3]), out var data_precision); - long.TryParse(string.Concat(a[4]), out var data_scale); - //var char_used = string.Concat(a[5]); - if (sqlType.StartsWith("INTERVAL DAY TO SECOND")) - sqlType = $"INTERVAL DAY({(data_scale - 1536) / 16}) TO SECOND({(data_scale - 1536) % 16})"; - else if (Regex.IsMatch(sqlType, @"INTERVAL YEAR\(\d+\) TO MONTH", RegexOptions.IgnoreCase)) - { - } - else if (sqlType.StartsWith("TIMESTAMP", StringComparison.CurrentCultureIgnoreCase)) - sqlType += data_scale <= 0 ? "" : $"({data_scale})"; - else if (sqlType.StartsWith("BLOB")) - { - } - else if (sqlType.StartsWith("RAW")) - { - } - else if (sqlType.StartsWith("LONG RAW")) - { - } - else if (sqlType == "REAL" || sqlType == "DOUBLE" || sqlType == "FLOAT") - { - } - else if (data_precision > 0 && data_scale > 0) - sqlType += $"({data_precision},{data_scale})"; - else if (data_precision > 0) - sqlType += $"({data_precision})"; - else - sqlType += $"({data_length})"; - return sqlType; - } - } -} \ No newline at end of file diff --git a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengDbFirst.cs b/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengDbFirst.cs deleted file mode 100644 index 68e2f2a36..000000000 --- a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengDbFirst.cs +++ /dev/null @@ -1,616 +0,0 @@ -using FreeSql.DatabaseModel; -using FreeSql.Internal; -using FreeSql.Internal.Model; -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Data; -using System.Data.Odbc; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; - -namespace FreeSql.Odbc.Dameng -{ - class OdbcDamengDbFirst : IDbFirst - { - IFreeSql _orm; - protected CommonUtils _commonUtils; - protected CommonExpression _commonExpression; - public OdbcDamengDbFirst(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression) - { - _orm = orm; - _commonUtils = commonUtils; - _commonExpression = commonExpression; - } - - public int GetDbType(DbColumnInfo column) => (int)GetSqlDbType(column); - OdbcType GetSqlDbType(DbColumnInfo column) - { - var dbfull = column.DbTypeTextFull?.ToLower(); - switch (dbfull) - { - case "number(1)": return OdbcType.Bit; - - case "number(4)": return OdbcType.SmallInt; - case "number(6)": return OdbcType.SmallInt; - case "number(11)": return OdbcType.Int; - case "number(21)": return OdbcType.BigInt; - - case "number(3)": return OdbcType.TinyInt; - case "number(5)": return OdbcType.SmallInt; - case "number(10)": return OdbcType.BigInt; - case "number(20)": return OdbcType.Decimal; - - case "float(126)": return OdbcType.Double; - case "float(63)": return OdbcType.Real; - case "number(10,2)": return OdbcType.Decimal; - - case "interval day(2) to second(6)": return OdbcType.Time; - case "timestamp(6)": return OdbcType.DateTime; - case "timestamp(6) with local time zone": return OdbcType.DateTime; - - case "blob": return OdbcType.VarBinary; - case "nvarchar2(255)": return OdbcType.NVarChar; - - case "char(36)": return OdbcType.Char; - } - if (dbfull?.StartsWith("datetime(") == true) - { - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["timestamp(6)"]); - return OdbcType.DateTime; - } - switch (column.DbTypeText?.ToLower()) - { - case "bit": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["number(1)"]); - return OdbcType.Bit; - case "smallint": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["number(4)"]); - return OdbcType.SmallInt; - case "byte": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["number(3)"]); - return OdbcType.TinyInt; - case "tinyint": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["number(3)"]); - return OdbcType.TinyInt; - case "int": - case "integer": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["number(11)"]); - return OdbcType.Int; - case "bigint": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["number(21)"]); - return OdbcType.Int; - case "dec": - case "decimal": - case "numeric": - case "number": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["number(10,2)"]); - return OdbcType.Decimal; - case "time": - case "interval day to second": - case "interval year to month": - case "interval year": - case "interval month": - case "interval day": - case "interval day to hour": - case "interval day to minute": - case "interval hour": - case "interval hour to minute": - case "interval hour to second": - case "interval minute": - case "interval minute to second": - case "interval second": - case "time with time zone": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["interval day(2) to second(6)"]); - return OdbcType.Time; - case "date": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["date"]); - return OdbcType.DateTime; - case "timestamp": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["timestamp(6)"]); - return OdbcType.DateTime; - case "timestamp with local time zone": - case "timestamp with time zone": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["timestamp(6) with local time zone"]); - return OdbcType.DateTime; - case "binary": - case "varbinary": - case "blob": - case "image": - case "longvarbinary": - case "bfile": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["blob"]); - return OdbcType.VarBinary; - case "nvarchar2": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]); - return OdbcType.NVarChar; - case "varchar": - case "varchar2": - case "text": - case "longvarchar": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]); - return OdbcType.NVarChar; - case "character": - case "char": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]); - return OdbcType.Char; - case "nchar": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]); - return OdbcType.NChar; - case "clob": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]); - return OdbcType.NVarChar; - case "nclob": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]); - return OdbcType.NVarChar; - case "raw": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["blob"]); - return OdbcType.VarBinary; - case "long raw": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["blob"]); - return OdbcType.VarBinary; - case "real": - case "binary_float": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["float(63)"]); - return OdbcType.Real; - case "double": - case "float": - case "double precision": - case "binary_double": - _dicDbToCs.TryAdd(dbfull, _dicDbToCs["float(126)"]); - return OdbcType.Double; - case "rowid": - default: - if (dbfull != null) _dicDbToCs.TryAdd(dbfull, _dicDbToCs["nvarchar2(255)"]); - return OdbcType.NVarChar; - } - throw new NotImplementedException(CoreStrings.S_TypeMappingNotImplemented(column.DbTypeTextFull)); - } - - static ConcurrentDictionary _dicDbToCs = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); - static OdbcDamengDbFirst() - { - var defaultDbToCs = new Dictionary() { - { "number(1)", new DbToCs("(bool?)", "{0} == \"1\"", "{0} == true ? \"1\" : \"0\"", "bool?", typeof(bool), typeof(bool?), "{0}.Value", "GetBoolean") }, - - { "number(4)", new DbToCs("(sbyte?)", "sbyte.Parse({0})", "{0}.ToString()", "sbyte?", typeof(sbyte), typeof(sbyte?), "{0}.Value", "GetInt16") }, - { "number(6)", new DbToCs("(short?)", "short.Parse({0})", "{0}.ToString()", "short?", typeof(short), typeof(short?), "{0}.Value", "GetInt16") }, - { "number(11)", new DbToCs("(int?)", "int.Parse({0})", "{0}.ToString()", "int?", typeof(int), typeof(int?), "{0}.Value", "GetInt32") }, - { "number(21)", new DbToCs("(long?)", "long.Parse({0})", "{0}.ToString()", "long?", typeof(long), typeof(long?), "{0}.Value", "GetInt64") }, - - { "number(3)", new DbToCs("(byte?)", "byte.Parse({0})", "{0}.ToString()", "byte?", typeof(byte), typeof(byte?), "{0}.Value", "GetByte") }, - { "number(5)", new DbToCs("(ushort?)", "ushort.Parse({0})", "{0}.ToString()", "ushort?", typeof(ushort), typeof(ushort?), "{0}.Value", "GetInt32") }, - { "number(10)", new DbToCs("(uint?)", "uint.Parse({0})", "{0}.ToString()", "uint?", typeof(uint), typeof(uint?), "{0}.Value", "GetInt64") }, - { "number(20)", new DbToCs("(ulong?)", "ulong.Parse({0})", "{0}.ToString()", "ulong?", typeof(ulong), typeof(ulong?), "{0}.Value", "GetDecimal") }, - - { "float(126)", new DbToCs("(double?)", "double.Parse({0})", "{0}.ToString()", "double?", typeof(double), typeof(double?), "{0}.Value", "GetDouble") }, - { "float(63)", new DbToCs("(float?)", "float.Parse({0})", "{0}.ToString()", "float?", typeof(float), typeof(float?), "{0}.Value", "GetFloat") }, - { "number(10,2)", new DbToCs("(decimal?)", "decimal.Parse({0})", "{0}.ToString()", "decimal?", typeof(decimal), typeof(decimal?), "{0}.Value", "GetDecimal") }, - - { "interval day(2) to second(6)", new DbToCs("(TimeSpan?)", "TimeSpan.Parse(double.Parse({0}))", "{0}.Ticks.ToString()", "TimeSpan?", typeof(TimeSpan), typeof(TimeSpan?), "{0}.Value", "GetValue") }, - { "date", new DbToCs("(DateTime?)", "new DateTime(long.Parse({0}))", "{0}.Ticks.ToString()", "DateTime?", typeof(DateTime), typeof(DateTime?), "{0}.Value", "GetValue") }, - { "timestamp(6)", new DbToCs("(DateTime?)", "new DateTime(long.Parse({0}))", "{0}.Ticks.ToString()", "DateTime?", typeof(DateTime), typeof(DateTime?), "{0}.Value", "GetValue") }, - { "timestamp(6) with local time zone", new DbToCs("(DateTime?)", "new DateTime(long.Parse({0}))", "{0}.Ticks.ToString()", "DateTime?", typeof(DateTime), typeof(DateTime?), "{0}.Value", "GetValue") }, - - { "blob", new DbToCs("(byte[])", "Convert.FromBase64String({0})", "Convert.ToBase64String({0})", "byte[]", typeof(byte[]), typeof(byte[]), "{0}", "GetValue") }, - - { "nvarchar2(255)", new DbToCs("", "{0}.Replace(StringifySplit, \"|\")", "{0}.Replace(\"|\", StringifySplit)", "string", typeof(string), typeof(string), "{0}", "GetString") }, - { "char(36 char)", new DbToCs("(Guid?)", "Guid.Parse({0})", "{0}.ToString()", "Guid?", typeof(Guid), typeof(Guid?), "{0}.Value", "GetGuid") }, - }; - foreach (var kv in defaultDbToCs) - _dicDbToCs.TryAdd(kv.Key, kv.Value); - } - - - public string GetCsConvert(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbTypeTextFull, out var trydc) ? (column.IsNullable ? trydc.csConvert : trydc.csConvert.Replace("?", "")) : null; - public string GetCsParse(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbTypeTextFull, out var trydc) ? trydc.csParse : null; - public string GetCsStringify(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbTypeTextFull, out var trydc) ? trydc.csStringify : null; - public string GetCsType(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbTypeTextFull, out var trydc) ? (column.IsNullable ? trydc.csType : trydc.csType.Replace("?", "")) : null; - public Type GetCsTypeInfo(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbTypeTextFull, out var trydc) ? trydc.csTypeInfo : null; - public string GetCsTypeValue(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbTypeTextFull, out var trydc) ? trydc.csTypeValue : null; - public string GetDataReaderMethod(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbTypeTextFull, out var trydc) ? trydc.dataReaderMethod : null; - - public List GetDatabases() - { - var sql = @" select username from all_users"; - var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); - return ds.Select(a => a.FirstOrDefault()?.ToString()).ToList(); - } - - public bool ExistsTable(string name, bool ignoreCase) - { - if (string.IsNullOrEmpty(name)) return false; - var tbname = _commonUtils.SplitTableName(name); - if (tbname?.Length == 1) - { - var userId = (_orm.Ado.MasterPool as OdbcDamengConnectionPool)?.UserId; - if (string.IsNullOrEmpty(userId)) - using (var conn = _orm.Ado.MasterPool.Get()) - { - userId = OdbcDamengConnectionPool.GetUserId(conn.Value.ConnectionString); - } - tbname = new[] { userId, tbname[0] }; - } - if (ignoreCase) tbname = tbname.Select(a => a.ToLower()).ToArray(); - var sql = $" select 1 from all_tab_comments where {(ignoreCase ? "lower(owner)" : "owner")}={_commonUtils.FormatSql("{0}", tbname[0])} and {(ignoreCase ? "lower(table_name)" : "table_name")}={_commonUtils.FormatSql("{0}", tbname[1])}"; - return string.Concat(_orm.Ado.ExecuteScalar(CommandType.Text, sql)) == "1"; - } - - public DbTableInfo GetTableByName(string name, bool ignoreCase = true) => GetTables(null, name, ignoreCase)?.FirstOrDefault(); - public List GetTablesByDatabase(params string[] database) => GetTables(database, null, false); - - public List GetTables(string[] database, string tablename, bool ignoreCase) - { - var loc1 = new List(); - var loc2 = new Dictionary(); - var loc3 = new Dictionary>(); - string[] tbname = null; - if (string.IsNullOrEmpty(tablename) == false) - { - tbname = _commonUtils.SplitTableName(tablename); - if (tbname?.Length == 1) - { - var userUsers = _orm.Ado.ExecuteScalar(" select username from user_users")?.ToString(); - if (string.IsNullOrEmpty(userUsers)) return loc1; - tbname = new[] { userUsers, tbname[0] }; - } - if (ignoreCase) tbname = tbname.Select(a => a.ToLower()).ToArray(); - database = new[] { tbname[0] }; - } - else if (database == null || database.Any() == false) - { - var userUsers = _orm.Ado.ExecuteScalar(" select username from user_users")?.ToString(); - if (string.IsNullOrEmpty(userUsers)) return loc1; - database = new[] { userUsers }; - } - - var databaseIn = string.Join(",", database.Select(a => _commonUtils.FormatSql("{0}", a))); - var sql = $@" -select -a.owner || '.' || a.table_name, -a.owner, -a.table_name, -b.comments, -'TABLE' -from all_tables a -left join all_tab_comments b on b.owner = a.owner and b.table_name = a.table_name and b.table_type = 'TABLE' -where {(ignoreCase ? "lower(a.owner)" : "a.owner")} in ({databaseIn}){(tbname == null ? "" : $" and {(ignoreCase ? "lower(a.table_name)" : "a.table_name")}={_commonUtils.FormatSql("{0}", tbname[1])}")} - -UNION ALL - -select -a.owner || '.' || a.view_name, -a.owner, -a.view_name, -b.comments, -'VIEW' AS tp -from all_views a -left join all_tab_comments b on b.owner = a.owner and b.table_name = a.view_name and b.table_type = 'VIEW' -where {(ignoreCase ? "lower(a.owner)" : "a.owner")} in ({databaseIn}){(tbname == null ? "" : $" and {(ignoreCase ? "lower(a.view_name)" : "a.view_name")}={_commonUtils.FormatSql("{0}", tbname[1])}")}"; - var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); - if (ds == null) return loc1; - - var loc6 = new List(); - var loc66 = new List(); - var loc6_1000 = new List(); - var loc66_1000 = new List(); - foreach (var row in ds) - { - var table_id = string.Concat(row[0]); - var schema = string.Concat(row[1]); - var table = string.Concat(row[2]); - var comment = string.Concat(row[3]); - var type = string.Concat(row[4]) == "VIEW" ? DbTableType.VIEW : DbTableType.TABLE; - if (database.Length == 1) - { - table_id = table_id.Substring(table_id.IndexOf('.') + 1); - schema = ""; - } - loc2.Add(table_id, new DbTableInfo { Id = table_id, Schema = schema, Name = table, Comment = comment, Type = type }); - loc3.Add(table_id, new Dictionary()); - switch (type) - { - case DbTableType.TABLE: - case DbTableType.VIEW: - loc6_1000.Add(table.Replace("'", "''")); - if (loc6_1000.Count >= 999) - { - loc6.Add(loc6_1000.ToArray()); - loc6_1000.Clear(); - } - break; - case DbTableType.StoreProcedure: - loc66_1000.Add(table.Replace("'", "''")); - if (loc66_1000.Count >= 999) - { - loc66.Add(loc66_1000.ToArray()); - loc66_1000.Clear(); - } - break; - } - } - if (loc6_1000.Count > 0) loc6.Add(loc6_1000.ToArray()); - if (loc66_1000.Count > 0) loc66.Add(loc66_1000.ToArray()); - - if (loc6.Count == 0) return loc1; - var loc8 = new StringBuilder().Append("("); - for (var loc8idx = 0; loc8idx < loc6.Count; loc8idx++) - { - if (loc8idx > 0) loc8.Append(" OR "); - loc8.Append("a.table_name in ("); - for (var loc8idx2 = 0; loc8idx2 < loc6[loc8idx].Length; loc8idx2++) - { - if (loc8idx2 > 0) loc8.Append(","); - loc8.Append($"'{loc6[loc8idx][loc8idx2]}'"); - } - loc8.Append(")"); - } - loc8.Append(")"); - - sql = $@" -select -a.owner || '.' || a.table_name, -a.column_name, -a.data_type, -a.data_length, -a.data_precision, -a.data_scale, -a.char_used, -case when a.nullable = 'N' then 0 else 1 end, -nvl((select 1 from user_sequences where upper(sequence_name)=upper(a.table_name||'_seq_'||a.column_name) and rownum < 2), 0), -b.comments, -a.data_default -from all_tab_cols a -left join all_col_comments b on b.owner = a.owner and b.table_name = a.table_name and b.column_name = a.column_name -where {(ignoreCase ? "lower(a.owner)" : "a.owner")} in ({databaseIn}) and {loc8} -"; - ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); - if (ds == null) return loc1; - - var ds2 = new List(); - foreach (var row in ds) - { - var ds2item = new object[9]; - ds2item[0] = row[0]; - ds2item[1] = row[1]; - ds2item[2] = Regex.Replace(string.Concat(row[2]), @"\(\d+\)", ""); - ds2item[4] = OdbcDamengCodeFirst.GetDamengSqlTypeFullName(new object[] { row[1], row[2], row[3], row[4], row[5], row[6] }); - ds2item[5] = string.Concat(row[7]); - ds2item[6] = string.Concat(row[8]); - ds2item[7] = string.Concat(row[9]); - ds2item[8] = string.Concat(row[10]); - ds2.Add(ds2item); - } - var position = 0; - foreach (var row in ds2) - { - string table_id = string.Concat(row[0]); - string column = string.Concat(row[1]); - string type = string.Concat(row[2]); - //long max_length = long.Parse(string.Concat(row[3])); - string sqlType = string.Concat(row[4]); - var m_len = Regex.Match(sqlType, @"\w+\((\d+)"); - int max_length = m_len.Success ? int.Parse(m_len.Groups[1].Value) : -1; - bool is_nullable = string.Concat(row[5]) == "1"; - bool is_identity = string.Concat(row[6]) == "1"; - string comment = string.Concat(row[7]); - string defaultValue = string.Concat(row[8]); - if (max_length == 0) max_length = -1; - if (database.Length == 1) - { - table_id = table_id.Substring(table_id.IndexOf('.') + 1); - } - loc3[table_id].Add(column, new DbColumnInfo - { - Name = column, - MaxLength = max_length, - IsIdentity = is_identity, - IsNullable = is_nullable, - IsPrimary = false, - DbTypeText = type, - DbTypeTextFull = sqlType, - Table = loc2[table_id], - Comment = comment, - DefaultValue = defaultValue, - Position = ++position - }); - loc3[table_id][column].DbType = this.GetDbType(loc3[table_id][column]); - loc3[table_id][column].CsType = this.GetCsTypeInfo(loc3[table_id][column]); - } - - sql = $@" -select -a.table_owner || '.' || a.table_name, -c.column_name, -c.index_name, -case when a.uniqueness = 'UNIQUE' then 1 else 0 end, -case when exists(select 1 from all_constraints where index_name = a.index_name and constraint_type = 'P') then 1 else 0 end, -0, -case when c.descend = 'DESC' then 1 else 0 end, -c.column_position -from all_indexes a, -all_ind_columns c -where a.index_name = c.index_name -and a.table_owner = c.table_owner -and a.table_name = c.table_name -and {(ignoreCase ? "lower(a.table_owner)" : "a.table_owner")} in ({databaseIn}) and {loc8} -"; - ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); - if (ds == null) return loc1; - - var indexColumns = new Dictionary>(); - var uniqueColumns = new Dictionary>(); - foreach (var row in ds) - { - string table_id = string.Concat(row[0]); - string column = string.Concat(row[1]).Trim('"'); - string index_id = string.Concat(row[2]); - bool is_unique = string.Concat(row[3]) == "1"; - bool is_primary_key = string.Concat(row[4]) == "1"; - bool is_clustered = string.Concat(row[5]) == "1"; - bool is_desc = string.Concat(row[6]) == "1"; - if (database.Length == 1) - table_id = table_id.Substring(table_id.IndexOf('.') + 1); - if (loc3.ContainsKey(table_id) == false || loc3[table_id].ContainsKey(column) == false) continue; - var loc9 = loc3[table_id][column]; - if (loc9.IsPrimary == false && is_primary_key) loc9.IsPrimary = is_primary_key; - if (is_primary_key) continue; - - Dictionary loc10 = null; - DbIndexInfo loc11 = null; - if (!indexColumns.TryGetValue(table_id, out loc10)) - indexColumns.Add(table_id, loc10 = new Dictionary()); - if (!loc10.TryGetValue(index_id, out loc11)) - loc10.Add(index_id, loc11 = new DbIndexInfo()); - loc11.Columns.Add(new DbIndexColumnInfo { Column = loc9, IsDesc = is_desc }); - if (is_unique && !is_primary_key) - { - if (!uniqueColumns.TryGetValue(table_id, out loc10)) - uniqueColumns.Add(table_id, loc10 = new Dictionary()); - if (!loc10.TryGetValue(index_id, out loc11)) - loc10.Add(index_id, loc11 = new DbIndexInfo()); - loc11.Columns.Add(new DbIndexColumnInfo { Column = loc9, IsDesc = is_desc }); - } - } - foreach (string table_id in indexColumns.Keys) - { - foreach (var column in indexColumns[table_id]) - loc2[table_id].IndexesDict.Add(column.Key, column.Value); - } - foreach (string table_id in uniqueColumns.Keys) - { - foreach (var column in uniqueColumns[table_id]) - { - column.Value.Columns.Sort((c1, c2) => c1.Column.Name.CompareTo(c2.Column.Name)); - loc2[table_id].UniquesDict.Add(column.Key, column.Value); - } - } - - if (tbname == null) - { - sql = $@" -select -a.owner || '.' || a.table_name, -c.column_name, -c.constraint_name, -b.owner || '.' || b.table_name, -1, -d.column_name - --- a.owner 外键拥有者, --- a.table_name 外键表, --- c.column_name 外键列, --- b.owner 主键拥有者, --- b.table_name 主键表, --- d.column_name 主键列, --- c.constraint_name 外键名, --- d.constraint_name 主键名 - -from -all_constraints a, -all_constraints b, -all_cons_columns c, --外键表 -all_cons_columns d --主键表 -where -a.r_constraint_name = b.constraint_name -and a.constraint_type = 'R' -and b.constraint_type = 'P' -and a.r_owner = b.owner -and a.constraint_name = c.constraint_name -and b.constraint_name = d.constraint_name -and a.owner = c.owner -and a.table_name = c.table_name -and b.owner = d.owner -and b.table_name = d.table_name -and {(ignoreCase ? "lower(a.owner)" : "a.owner")} in ({databaseIn}) and {loc8} -"; - ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); - if (ds == null) return loc1; - - var fkColumns = new Dictionary>(); - foreach (var row in ds) - { - string table_id = string.Concat(row[0]); - string column = string.Concat(row[1]); - string fk_id = string.Concat(row[2]); - string ref_table_id = string.Concat(row[3]); - bool is_foreign_key = string.Concat(row[4]) == "1"; - string referenced_column = string.Concat(row[5]); - if (database.Length == 1) - { - table_id = table_id.Substring(table_id.IndexOf('.') + 1); - ref_table_id = ref_table_id.Substring(ref_table_id.IndexOf('.') + 1); - } - if (loc3.ContainsKey(table_id) == false || loc3[table_id].ContainsKey(column) == false) continue; - var loc9 = loc3[table_id][column]; - if (loc2.ContainsKey(ref_table_id) == false) continue; - var loc10 = loc2[ref_table_id]; - var loc11 = loc3[ref_table_id][referenced_column]; - - Dictionary loc12 = null; - DbForeignInfo loc13 = null; - if (!fkColumns.TryGetValue(table_id, out loc12)) - fkColumns.Add(table_id, loc12 = new Dictionary()); - if (!loc12.TryGetValue(fk_id, out loc13)) - loc12.Add(fk_id, loc13 = new DbForeignInfo { Table = loc2[table_id], ReferencedTable = loc10 }); - loc13.Columns.Add(loc9); - loc13.ReferencedColumns.Add(loc11); - } - foreach (var table_id in fkColumns.Keys) - foreach (var fk in fkColumns[table_id]) - loc2[table_id].ForeignsDict.Add(fk.Key, fk.Value); - } - - foreach (var table_id in loc3.Keys) - { - foreach (var loc5 in loc3[table_id].Values) - { - loc2[table_id].Columns.Add(loc5); - if (loc5.IsIdentity) loc2[table_id].Identitys.Add(loc5); - if (loc5.IsPrimary) loc2[table_id].Primarys.Add(loc5); - } - } - foreach (var loc4 in loc2.Values) - { - //if (loc4.Primarys.Count == 0 && loc4.UniquesDict.Count > 0) - //{ - // foreach (var loc5 in loc4.UniquesDict.First().Value.Columns) - // { - // loc5.Column.IsPrimary = true; - // loc4.Primarys.Add(loc5.Column); - // } - //} - loc4.Primarys.Sort((c1, c2) => c1.Name.CompareTo(c2.Name)); - loc4.Columns.Sort((c1, c2) => - { - int compare = c2.IsPrimary.CompareTo(c1.IsPrimary); - if (compare == 0) - { - bool b1 = loc4.ForeignsDict.Values.Where(fk => fk.Columns.Where(c3 => c3.Name == c1.Name).Any()).Any(); - bool b2 = loc4.ForeignsDict.Values.Where(fk => fk.Columns.Where(c3 => c3.Name == c2.Name).Any()).Any(); - compare = b2.CompareTo(b1); - } - if (compare == 0) compare = c1.Name.CompareTo(c2.Name); - return compare; - }); - loc1.Add(loc4); - } - loc1.Sort((t1, t2) => - { - var ret = t1.Schema.CompareTo(t2.Schema); - if (ret == 0) ret = t1.Name.CompareTo(t2.Name); - return ret; - }); - - loc2.Clear(); - loc3.Clear(); - return loc1; - } - - public List GetEnumsByDatabase(params string[] database) - { - return new List(); - } - } -} \ No newline at end of file diff --git a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengExpression.cs b/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengExpression.cs deleted file mode 100644 index 16cc73238..000000000 --- a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengExpression.cs +++ /dev/null @@ -1,519 +0,0 @@ -using FreeSql.Internal; -using System; -using System.Collections; -using System.Linq; -using System.Linq.Expressions; -using System.Text; -using System.Text.RegularExpressions; - -namespace FreeSql.Odbc.Dameng -{ - class OdbcDamengExpression : CommonExpression - { - - public OdbcDamengExpression(CommonUtils common) : base(common) { } - - public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) - { - Func getExp = exparg => ExpressionLambdaToSql(exparg, tsc); - switch (exp.NodeType) - { - case ExpressionType.ArrayLength: - var arrOper = (exp as UnaryExpression)?.Operand; - if (arrOper.Type == typeof(byte[])) return $"lengthb({getExp(arrOper)})"; - break; - case ExpressionType.Convert: - var operandExp = (exp as UnaryExpression)?.Operand; - var gentype = exp.Type.NullableTypeOrThis(); - if (gentype != operandExp.Type.NullableTypeOrThis()) - { - switch (exp.Type.NullableTypeOrThis().ToString()) - { - //case "System.Boolean": return $"({getExp(operandExp)} not in ('0','false'))"; - case "System.Byte": return $"cast({getExp(operandExp)} as number)"; - case "System.Char": return $"substr(to_char({getExp(operandExp)}), 1, 1)"; - case "System.DateTime": return $"to_timestamp({getExp(operandExp)},'YYYY-MM-DD HH24:MI:SS.FF6')"; - case "System.Decimal": return $"cast({getExp(operandExp)} as number)"; - case "System.Double": return $"cast({getExp(operandExp)} as number)"; - case "System.Int16": - case "System.Int32": - case "System.Int64": - case "System.SByte": return $"cast({getExp(operandExp)} as number)"; - case "System.Single": return $"cast({getExp(operandExp)} as number)"; - case "System.String": return $"to_char({getExp(operandExp)})"; - case "System.UInt16": - case "System.UInt32": - case "System.UInt64": return $"cast({getExp(operandExp)} as number)"; - case "System.Guid": - if (tsc.mapType == typeof(byte[])) return $"hextoraw({getExp(operandExp)})"; - return $"to_char({getExp(operandExp)})"; - } - } - break; - case ExpressionType.Call: - var callExp = exp as MethodCallExpression; - - switch (callExp.Method.Name) - { - case "Parse": - case "TryParse": - switch (callExp.Method.DeclaringType.NullableTypeOrThis().ToString()) - { - //case "System.Boolean": return $"({getExp(callExp.Arguments[0])} not in ('0','false'))"; - case "System.Byte": return $"cast({getExp(callExp.Arguments[0])} as number)"; - case "System.Char": return $"substr(to_char({getExp(callExp.Arguments[0])}), 1, 1)"; - case "System.DateTime": return $"to_timestamp({getExp(callExp.Arguments[0])},'YYYY-MM-DD HH24:MI:SS.FF6')"; - case "System.Decimal": return $"cast({getExp(callExp.Arguments[0])} as number)"; - case "System.Double": return $"cast({getExp(callExp.Arguments[0])} as number)"; - case "System.Int16": - case "System.Int32": - case "System.Int64": - case "System.SByte": return $"cast({getExp(callExp.Arguments[0])} as number)"; - case "System.Single": return $"cast({getExp(callExp.Arguments[0])} as number)"; - case "System.UInt16": - case "System.UInt32": - case "System.UInt64": return $"cast({getExp(callExp.Arguments[0])} as number)"; - case "System.Guid": - if (tsc.mapType == typeof(byte[])) return $"hextoraw({getExp(callExp.Arguments[0])})"; - return $"to_char({getExp(callExp.Arguments[0])})"; - } - return null; - case "NewGuid": - return null; - case "Next": - if (callExp.Object?.Type == typeof(Random)) return "cast(dbms_random.value*1000000000 as number)"; - return null; - case "NextDouble": - if (callExp.Object?.Type == typeof(Random)) return "dbms_random.value"; - return null; - case "Random": - if (callExp.Method.DeclaringType.IsNumberType()) return "dbms_random.value"; - return null; - case "ToString": - if (callExp.Object != null) - { - if (callExp.Object.Type.NullableTypeOrThis().IsEnum) - { - tsc.SetMapColumnTmp(null); - var oldMapType = tsc.SetMapTypeReturnOld(typeof(string)); - var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); - tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); - return enumStr; - } - var value = ExpressionGetValue(callExp.Object, out var success); - if (success) return formatSql(value, typeof(string), null, null); - return callExp.Arguments.Count == 0 ? $"to_char({getExp(callExp.Object)})" : null; - } - return null; - } - - var objExp = callExp.Object; - var objType = objExp?.Type; - if (objType?.FullName == "System.Byte[]") return null; - - var argIndex = 0; - if (objType == null && callExp.Method.DeclaringType == typeof(Enumerable)) - { - objExp = callExp.Arguments.FirstOrDefault(); - objType = objExp?.Type; - argIndex++; - - if (objType == typeof(string)) - { - switch (callExp.Method.Name) - { - case "First": - case "FirstOrDefault": - return $"substr({getExp(callExp.Arguments[0])}, 1, 1)"; - } - } - } - if (objType == null) objType = callExp.Method.DeclaringType; - if (objType != null || objType.IsArrayOrList()) - { - if (argIndex >= callExp.Arguments.Count) break; - tsc.SetMapColumnTmp(null); - var args1 = getExp(callExp.Arguments[argIndex]); - var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp); - var oldDbParams = objExp?.NodeType == ExpressionType.MemberAccess ? tsc.SetDbParamsReturnOld(null) : null; //#900 UseGenerateCommandParameterWithLambda(true) 子查询 bug、以及 #1173 参数化 bug - tsc.isNotSetMapColumnTmp = true; - var left = objExp == null ? null : getExp(objExp); - tsc.isNotSetMapColumnTmp = false; - tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); - if (oldDbParams != null) tsc.SetDbParamsReturnOld(oldDbParams); - switch (callExp.Method.Name) - { - case "Contains": - //判断 in //在各大 Provider AdoProvider 中已约定,500元素分割, 3空格\r\n4空格 - return $"(({args1}) in {left.Replace(", \r\n \r\n", $") \r\n OR ({args1}) in (")})"; - } - } - break; - case ExpressionType.NewArrayInit: - var arrExp = exp as NewArrayExpression; - var arrSb = new StringBuilder(); - arrSb.Append("("); - for (var a = 0; a < arrExp.Expressions.Count; a++) - { - if (a > 0) arrSb.Append(","); - if (a % 500 == 499) arrSb.Append(" \r\n \r\n"); //500元素分割, 3空格\r\n4空格 - arrSb.Append(getExp(arrExp.Expressions[a])); - } - if (arrSb.Length == 1) arrSb.Append("NULL"); - return arrSb.Append(")").ToString(); - case ExpressionType.ListInit: - var listExp = exp as ListInitExpression; - var listSb = new StringBuilder(); - listSb.Append("("); - for (var a = 0; a < listExp.Initializers.Count; a++) - { - if (listExp.Initializers[a].Arguments.Any() == false) continue; - if (a > 0) listSb.Append(","); - listSb.Append(getExp(listExp.Initializers[a].Arguments.FirstOrDefault())); - } - if (listSb.Length == 1) listSb.Append("NULL"); - return listSb.Append(")").ToString(); - case ExpressionType.New: - var newExp = exp as NewExpression; - if (typeof(IList).IsAssignableFrom(newExp.Type)) - { - if (newExp.Arguments.Count == 0) return "(NULL)"; - if (typeof(IEnumerable).IsAssignableFrom(newExp.Arguments[0].Type) == false) return "(NULL)"; - return getExp(newExp.Arguments[0]); - } - return null; - } - return null; - } - - public override string ExpressionLambdaToSqlMemberAccessString(MemberExpression exp, ExpTSC tsc) - { - if (exp.Expression == null) - { - switch (exp.Member.Name) - { - case "Empty": return "''"; - } - return null; - } - var left = ExpressionLambdaToSql(exp.Expression, tsc); - switch (exp.Member.Name) - { - case "Length": return $"length({left})"; - } - return null; - } - public override string ExpressionLambdaToSqlMemberAccessDateTime(MemberExpression exp, ExpTSC tsc) - { - if (exp.Expression == null) - { - switch (exp.Member.Name) - { - case "Now": return _common.Now; - case "UtcNow": return _common.NowUtc; - case "Today": return "trunc(systimestamp)"; - case "MinValue": return "to_timestamp('0001-01-01 00:00:00','YYYY-MM-DD HH24:MI:SS.FF6')"; - case "MaxValue": return "to_timestamp('9999-12-31 23:59:59','YYYY-MM-DD HH24:MI:SS.FF6')"; - } - return null; - } - var left = ExpressionLambdaToSql(exp.Expression, tsc); - switch (exp.Member.Name) - { - case "Date": return $"trunc({left})"; - case "TimeOfDay": return $"(cast({left} as timestamp with time zone)-trunc({left}))"; - case "DayOfWeek": return $"case when to_char({left},'D')='7' then 0 else cast(to_char({left},'D') as number) end"; - case "Day": return $"cast(to_char({left},'DD') as number)"; - case "DayOfYear": return $"cast(to_char({left},'DDD') as number)"; - case "Month": return $"cast(to_char({left},'MM') as number)"; - case "Year": return $"cast(to_char({left},'YYYY') as number)"; - case "Hour": return $"cast(to_char({left},'HH24') as number)"; - case "Minute": return $"cast(to_char({left},'MI') as number)"; - case "Second": return $"cast(to_char({left},'SS') as number)"; - case "Millisecond": return $"cast(to_char({left},'FF3') as number)"; - case "Ticks": return $"cast(to_char({left},'FF7') as number)"; - } - return null; - } - - public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, ExpTSC tsc) - { - Func getExp = exparg => ExpressionLambdaToSql(exparg, tsc); - if (exp.Object == null) - { - switch (exp.Method.Name) - { - case "IsNullOrEmpty": - var arg1 = getExp(exp.Arguments[0]); - return $"({arg1} is null or {arg1} = '')"; - case "IsNullOrWhiteSpace": - var arg2 = getExp(exp.Arguments[0]); - return $"({arg2} is null or {arg2} = '' or ltrim({arg2}) = '')"; - case "Concat": - if (exp.Arguments.Count == 1 && exp.Arguments[0].NodeType == ExpressionType.NewArrayInit && exp.Arguments[0] is NewArrayExpression concatNewArrExp) - return _common.StringConcat(concatNewArrExp.Expressions.Select(a => getExp(a)).ToArray(), null); - return _common.StringConcat(exp.Arguments.Select(a => getExp(a)).ToArray(), null); - case "Format": - if (exp.Arguments[0].NodeType != ExpressionType.Constant) throw new Exception(CoreStrings.Not_Implemented_Expression_ParameterUseConstant(exp,exp.Arguments[0])); - var expArgsHack = exp.Arguments.Count == 2 && exp.Arguments[1].NodeType == ExpressionType.NewArrayInit ? - (exp.Arguments[1] as NewArrayExpression).Expressions : exp.Arguments.Where((a, z) => z > 0); - //3个 {} 时,Arguments 解析出来是分开的 - //4个 {} 时,Arguments[1] 只能解析这个出来,然后里面是 NewArray [] - var expArgs = expArgsHack.Select(a => $"'||{_common.IsNull(ExpressionLambdaToSql(a, tsc), "''")}||'").ToArray(); - return string.Format(ExpressionLambdaToSql(exp.Arguments[0], tsc), expArgs); - case "Join": - if (exp.IsStringJoin(out var tolistObjectExp, out var toListMethod, out var toListArgs1)) - { - var newToListArgs0 = Expression.Call(tolistObjectExp, toListMethod, - Expression.Lambda( - Expression.Call( - typeof(SqlExtExtensions).GetMethod("StringJoinOracleGroupConcat"), - Expression.Convert(toListArgs1.Body, typeof(object)), - Expression.Convert(exp.Arguments[0], typeof(object))), - toListArgs1.Parameters)); - var newToListSql = getExp(newToListArgs0); - return newToListSql; - } - break; - } - } - else - { - var left = getExp(exp.Object); - switch (exp.Method.Name) - { - case "StartsWith": - case "EndsWith": - case "Contains": - var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; - if (args0Value.Contains("%")) - { - if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1"; - if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1"; - return $"instr({left}, {args0Value}, 1, 1) > 0"; - } - if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) LIKE ('%'||to_char({args0Value})||'%')"; - case "ToLower": return $"lower({left})"; - case "ToUpper": return $"upper({left})"; - case "Substring": - var substrArgs1 = getExp(exp.Arguments[0]); - if (long.TryParse(substrArgs1, out var testtrylng1)) substrArgs1 = (testtrylng1 + 1).ToString(); - else substrArgs1 += "+1"; - if (exp.Arguments.Count == 1) return $"substr({left}, {substrArgs1})"; - return $"substr({left}, {substrArgs1}, {getExp(exp.Arguments[1])})"; - case "IndexOf": - var indexOfFindStr = getExp(exp.Arguments[0]); - if (exp.Arguments.Count > 1 && exp.Arguments[1].Type.FullName == "System.Int32") - { - var locateArgs1 = getExp(exp.Arguments[1]); - if (long.TryParse(locateArgs1, out var testtrylng2)) locateArgs1 = (testtrylng2 + 1).ToString(); - else locateArgs1 += "+1"; - return $"(instr({left}, {indexOfFindStr}, {locateArgs1}, 1)-1)"; - } - return $"(instr({left}, {indexOfFindStr}, 1, 1))-1"; - case "PadLeft": - if (exp.Arguments.Count == 1) return $"lpad({left}, {getExp(exp.Arguments[0])}, ' ')"; - return $"lpad({left}, {getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})"; - case "PadRight": - if (exp.Arguments.Count == 1) return $"rpad({left}, {getExp(exp.Arguments[0])}, ' ')"; - return $"rpad({left}, {getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})"; - case "Trim": - case "TrimStart": - case "TrimEnd": - if (exp.Arguments.Count == 0) - { - if (exp.Method.Name == "Trim") return $"trim({left})"; - if (exp.Method.Name == "TrimStart") return $"ltrim({left})"; - if (exp.Method.Name == "TrimEnd") return $"rtrim({left})"; - } - foreach (var argsTrim02 in exp.Arguments) - { - var argsTrim01s = new[] { argsTrim02 }; - if (argsTrim02.NodeType == ExpressionType.NewArrayInit) - { - var arritem = argsTrim02 as NewArrayExpression; - argsTrim01s = arritem.Expressions.ToArray(); - } - foreach (var argsTrim01 in argsTrim01s) - { - if (exp.Method.Name == "Trim") left = $"trim(both {getExp(argsTrim01)} from {left})"; - if (exp.Method.Name == "TrimStart") left = $"ltrim({left},{getExp(argsTrim01)})"; - if (exp.Method.Name == "TrimEnd") left = $"rtrim({left},{getExp(argsTrim01)})"; - } - } - return left; - case "Replace": return $"replace({left}, {getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})"; - case "CompareTo": return $"case when {left} = {getExp(exp.Arguments[0])} then 0 when {left} > {getExp(exp.Arguments[0])} then 1 else -1 end"; - case "Equals": return $"({left} = {getExp(exp.Arguments[0])})"; - } - } - return null; - } - public override string ExpressionLambdaToSqlCallMath(MethodCallExpression exp, ExpTSC tsc) - { - Func getExp = exparg => ExpressionLambdaToSql(exparg, tsc); - switch (exp.Method.Name) - { - case "Abs": return $"abs({getExp(exp.Arguments[0])})"; - case "Sign": return $"sign({getExp(exp.Arguments[0])})"; - case "Floor": return $"floor({getExp(exp.Arguments[0])})"; - case "Ceiling": return $"ceil({getExp(exp.Arguments[0])})"; - case "Round": - if (exp.Arguments.Count > 1 && exp.Arguments[1].Type.FullName == "System.Int32") return $"round({getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})"; - return $"round({getExp(exp.Arguments[0])})"; - case "Exp": return $"exp({getExp(exp.Arguments[0])})"; - case "Log": - if (exp.Arguments.Count > 1) return $"log({getExp(exp.Arguments[1])},{getExp(exp.Arguments[0])})"; - return $"log(2.7182818284590451,{getExp(exp.Arguments[0])})"; - case "Log10": return $"log(10,{getExp(exp.Arguments[0])})"; - case "Pow": return $"power({getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})"; - case "Sqrt": return $"sqrt({getExp(exp.Arguments[0])})"; - case "Cos": return $"cos({getExp(exp.Arguments[0])})"; - case "Sin": return $"sin({getExp(exp.Arguments[0])})"; - case "Tan": return $"tan({getExp(exp.Arguments[0])})"; - case "Acos": return $"acos({getExp(exp.Arguments[0])})"; - case "Asin": return $"asin({getExp(exp.Arguments[0])})"; - case "Atan": return $"atan({getExp(exp.Arguments[0])})"; - //case "Atan2": return $"atan2({getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})"; - case "Truncate": return $"trunc({getExp(exp.Arguments[0])}, 0)"; - } - return null; - } - public override string ExpressionLambdaToSqlCallDateTime(MethodCallExpression exp, ExpTSC tsc) - { - Func getExp = exparg => ExpressionLambdaToSql(exparg, tsc); - if (exp.Object == null) - { - switch (exp.Method.Name) - { - case "Compare": return $"extract(day from ({getExp(exp.Arguments[0])}-({getExp(exp.Arguments[1])})))"; - case "DaysInMonth": return $"cast(to_char(last_day(to_date(({getExp(exp.Arguments[0])})||'-'||({getExp(exp.Arguments[1])})||'-01','yyyy-mm-dd')),'DD') as number)"; - case "Equals": return $"({getExp(exp.Arguments[0])} = {getExp(exp.Arguments[1])})"; - - case "IsLeapYear": - var isLeapYearArgs1 = getExp(exp.Arguments[0]); - return $"(mod({isLeapYearArgs1},4)=0 AND mod({isLeapYearArgs1},100)<>0 OR mod({isLeapYearArgs1},400)=0)"; - - case "Parse": return $"to_timestamp({getExp(exp.Arguments[0])},'YYYY-MM-DD HH24:MI:SS.FF6')"; - case "ParseExact": - case "TryParse": - case "TryParseExact": return $"to_timestamp({getExp(exp.Arguments[0])},'YYYY-MM-DD HH24:MI:SS.FF6')"; - } - } - else - { - var left = getExp(exp.Object); - var args1 = exp.Arguments.Count == 0 ? null : getExp(exp.Arguments[0]); - switch (exp.Method.Name) - { - case "AddDays": return $"({left}+{args1})"; - case "AddHours": return $"({left}+({args1})/24)"; - case "AddMilliseconds": return $"({left}+({args1})/86400000)"; - case "AddMinutes": return $"({left}+({args1})/1440)"; - case "AddMonths": return $"add_months({left},{args1})"; - case "AddSeconds": return $"({left}+({args1})/86400)"; - case "AddTicks": return $"({left}+({args1})/864000000000)"; - case "AddYears": return $"add_months({left},({args1})*12)"; - case "Subtract": - switch ((exp.Arguments[0].Type.IsNullableType() ? exp.Arguments[0].Type.GetGenericArguments().FirstOrDefault() : exp.Arguments[0].Type).FullName) - { - case "System.DateTime": return $"(cast({left} as timestamp with time zone)-{args1})"; - case "System.TimeSpan": return $"({left}-{args1})"; - } - break; - case "Equals": return $"({left} = {args1})"; - case "CompareTo": return $"extract(day from ({left}-({args1})))"; - case "ToString": - if (left.StartsWith("'") || left.EndsWith("'")) left = $"to_timestamp({left},'YYYY-MM-DD HH24:MI:SS.FF6')"; - if (exp.Arguments.Count == 0) return $"to_char({left},'YYYY-MM-DD HH24:MI:SS.FF6')"; - switch (args1) - { - case "'yyyy-MM-dd HH:mm:ss'": return $"to_char({left},'YYYY-MM-DD HH24:MI:SS')"; - case "'yyyy-MM-dd HH:mm'": return $"to_char({left},'YYYY-MM-DD HH24:MI')"; - case "'yyyy-MM-dd HH'": return $"to_char({left},'YYYY-MM-DD HH24')"; - case "'yyyy-MM-dd'": return $"to_char({left},'YYYY-MM-DD')"; - case "'yyyy-MM'": return $"to_char({left},'YYYY-MM')"; - case "'yyyyMMddHHmmss'": return $"to_char({left},'YYYYMMDDHH24MISS')"; - case "'yyyyMMddHHmm'": return $"to_char({left},'YYYYMMDDHH24MI')"; - case "'yyyyMMddHH'": return $"to_char({left},'YYYYMMDDHH24')"; - case "'yyyyMMdd'": return $"to_char({left},'YYYYMMDD')"; - case "'yyyyMM'": return $"to_char({left},'YYYYMM')"; - case "'yyyy'": return $"to_char({left},'YYYY')"; - case "'HH:mm:ss'": return $"to_char({left},'HH24:MI:SS')"; - } - args1 = Regex.Replace(args1, "(yyyy|yy|MM|dd|HH|hh|mm|ss|tt)", m => - { - switch (m.Groups[1].Value) - { - case "yyyy": return "YYYY"; - case "yy": return "YY"; - case "MM": return "%_a1"; - case "dd": return "%_a2"; - case "HH": return "%_a3"; - case "mm": return "%_a4"; - case "ss": return "SS"; - case "tt": return "%_a5"; - } - return m.Groups[0].Value; - }); - var argsFinds = new[] { "YYYY", "YY", "%_a1", "%_a2", "%_a3", "%_a4", "SS", "%_a5" }; - var argsSpts = Regex.Split(args1, "(M|d|H|hh|h|m|s|t)"); - for (var a = 0; a < argsSpts.Length; a++) - { - switch (argsSpts[a]) - { - case "M": argsSpts[a] = $"ltrim(to_char({left},'MM'),'0')"; break; - case "d": argsSpts[a] = $"case when substr(to_char({left},'DD'),1,1) = '0' then substr(to_char({left},'DD'),2,1) else to_char({left},'DD') end"; break; - case "H": argsSpts[a] = $"case when substr(to_char({left},'HH24'),1,1) = '0' then substr(to_char({left},'HH24'),2,1) else to_char({left},'HH24') end"; break; - case "hh": argsSpts[a] = $"case mod(cast(case when substr(to_char({left},'HH24'),1,1) = '0' then substr(to_char({left},'HH24'),2,1) else to_char({left},'HH24') end as number),12) when 0 then '12' when 1 then '01' when 2 then '02' when 3 then '03' when 4 then '04' when 5 then '05' when 6 then '06' when 7 then '07' when 8 then '08' when 9 then '09' when 10 then '10' when 11 then '11' end"; break; - case "h": argsSpts[a] = $"case mod(cast(case when substr(to_char({left},'HH24'),1,1) = '0' then substr(to_char({left},'HH24'),2,1) else to_char({left},'HH24') end as number),12) when 0 then '12' when 1 then '1' when 2 then '2' when 3 then '3' when 4 then '4' when 5 then '5' when 6 then '6' when 7 then '7' when 8 then '8' when 9 then '9' when 10 then '10' when 11 then '11' end"; break; - case "m": argsSpts[a] = $"case when substr(to_char({left},'MI'),1,1) = '0' then substr(to_char({left},'MI'),2,1) else to_char({left},'MI') end"; break; - case "s": argsSpts[a] = $"case when substr(to_char({left},'SS'),1,1) = '0' then substr(to_char({left},'SS'),2,1) else to_char({left},'SS') end"; break; - case "t": argsSpts[a] = $"rtrim(to_char({left},'AM'),'M')"; break; - default: - var argsSptsA = argsSpts[a]; - if (argsSptsA.StartsWith("'")) argsSptsA = argsSptsA.Substring(1); - if (argsSptsA.EndsWith("'")) argsSptsA = argsSptsA.Remove(argsSptsA.Length - 1); - argsSpts[a] = argsFinds.Any(m => argsSptsA.Contains(m)) ? $"to_char({left},'{argsSptsA}')" : $"'{argsSptsA}'"; - break; - //达梦 to_char(to_timestamp('2020-02-01 00:00:00.000000','YYYY-MM-DD HH24:MI:SS.FF6'),' ') 无效 - } - } - if (argsSpts.Length > 0) args1 = $"({string.Join(" || ", argsSpts.Where(a => a != "''"))})"; - return args1.Replace("%_a1", "MM").Replace("%_a2", "DD").Replace("%_a3", "HH24").Replace("%_a4", "MI").Replace("%_a5", "AM"); - } - } - return null; - } - public override string ExpressionLambdaToSqlCallConvert(MethodCallExpression exp, ExpTSC tsc) - { - Func getExp = exparg => ExpressionLambdaToSql(exparg, tsc); - if (exp.Object == null) - { - switch (exp.Method.Name) - { - //case "ToBoolean": return $"({getExp(exp.Arguments[0])} not in ('0','false'))"; - case "ToByte": return $"cast({getExp(exp.Arguments[0])} as number)"; - case "ToChar": return $"substr(to_char({getExp(exp.Arguments[0])}), 1, 1)"; - case "ToDateTime": return $"to_timestamp({getExp(exp.Arguments[0])},'YYYY-MM-DD HH24:MI:SS.FF6')"; - case "ToDecimal": return $"cast({getExp(exp.Arguments[0])} as number)"; - case "ToDouble": return $"cast({getExp(exp.Arguments[0])} as number)"; - case "ToInt16": - case "ToInt32": - case "ToInt64": - case "ToSByte": return $"cast({getExp(exp.Arguments[0])} as number)"; - case "ToSingle": return $"cast({getExp(exp.Arguments[0])} as number)"; - case "ToString": return $"to_char({getExp(exp.Arguments[0])})"; - case "ToUInt16": - case "ToUInt32": - case "ToUInt64": return $"cast({getExp(exp.Arguments[0])} as number)"; - } - } - return null; - } - } -} diff --git a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengProvider.cs b/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengProvider.cs deleted file mode 100644 index 7d3bae6c7..000000000 --- a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengProvider.cs +++ /dev/null @@ -1,37 +0,0 @@ -using FreeSql.Internal.CommonProvider; -using System; -using System.Data.Common; -using System.Threading; - -namespace FreeSql.Odbc.Dameng -{ - - public class OdbcDamengProvider : BaseDbProvider, IFreeSql - { - public override ISelect CreateSelectProvider(object dywhere) => new OdbcDamengSelect(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); - public override IInsert CreateInsertProvider() => new OdbcDamengInsert(this, this.InternalCommonUtils, this.InternalCommonExpression); - public override IUpdate CreateUpdateProvider(object dywhere) => new OdbcDamengUpdate(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); - public override IDelete CreateDeleteProvider(object dywhere) => new OdbcDamengDelete(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); - public override IInsertOrUpdate CreateInsertOrUpdateProvider() => new OdbcDamengInsertOrUpdate(this, this.InternalCommonUtils, this.InternalCommonExpression); - - public OdbcDamengProvider(string masterConnectionString, string[] slaveConnectionString, Func connectionFactory = null) - { - this.InternalCommonUtils = new OdbcDamengUtils(this); - this.InternalCommonExpression = new OdbcDamengExpression(this.InternalCommonUtils); - - this.Ado = new OdbcDamengAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString, connectionFactory); - this.Aop = new AopProvider(); - - this.DbFirst = new OdbcDamengDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression); - this.CodeFirst = new OdbcDamengCodeFirst(this, this.InternalCommonUtils, this.InternalCommonExpression); - } - - ~OdbcDamengProvider() => this.Dispose(); - int _disposeCounter; - public override void Dispose() - { - if (Interlocked.Increment(ref _disposeCounter) != 1) return; - (this.Ado as AdoProvider)?.Dispose(); - } - } -} diff --git a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengUtils.cs b/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengUtils.cs deleted file mode 100644 index 862decf29..000000000 --- a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengUtils.cs +++ /dev/null @@ -1,114 +0,0 @@ -using FreeSql.Internal; -using FreeSql.Internal.Model; -using System; -using System.Collections.Generic; -using System.Data.Common; -using System.Data.Odbc; -using System.Globalization; - -namespace FreeSql.Odbc.Dameng -{ - - class OdbcDamengUtils : CommonUtils - { - public OdbcDamengUtils(IFreeSql orm) : base(orm) - { - } - - public override DbParameter AppendParamter(List _params, string parameterName, ColumnInfo col, Type type, object value) - { - if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}"; - var dbtype = (OdbcType?)_orm.CodeFirst.GetDbInfo(type)?.type; - switch (dbtype) - { - case OdbcType.Bit: - if (value == null) value = null; - else value = (bool)value == true ? 1 : 0; - dbtype = OdbcType.Int; - break; - - case OdbcType.Char: - case OdbcType.NChar: - case OdbcType.VarChar: - case OdbcType.NVarChar: - case OdbcType.Text: - case OdbcType.NText: - value = string.Concat(value); - break; - } - var ret = new OdbcParameter { ParameterName = QuoteParamterName(parameterName) }; - if (dbtype != null) ret.OdbcType = dbtype.Value; - ret.Value = value; - _params?.Add(ret); - return ret; - } - - public override DbParameter[] GetDbParamtersByObject(string sql, object obj) => - Utils.GetDbParamtersByObject(sql, obj, null, (name, type, value) => - { - var dbtype = (OdbcType?)_orm.CodeFirst.GetDbInfo(type)?.type; - switch (dbtype) - { - case OdbcType.Bit: - if (value == null) value = null; - else value = (bool)value == true ? 1 : 0; - dbtype = OdbcType.Int; - break; - - case OdbcType.Char: - case OdbcType.NChar: - case OdbcType.VarChar: - case OdbcType.NVarChar: - case OdbcType.Text: - case OdbcType.NText: - value = string.Concat(value); - break; - } - var ret = new OdbcParameter { ParameterName = $":{name}" }; - if (dbtype != null) ret.OdbcType = dbtype.Value; - ret.Value = value; - return ret; - }); - - public override string FormatSql(string sql, params object[] args) => sql?.FormatOdbcDameng(args); - public override string QuoteSqlNameAdapter(params string[] name) - { - if (name.Length == 1) - { - var nametrim = name[0].Trim(); - if (nametrim.StartsWith("(") && nametrim.EndsWith(")")) - return nametrim; //原生SQL - if (nametrim.StartsWith("\"") && nametrim.EndsWith("\"")) - return nametrim; - return $"\"{nametrim.Replace(".", "\".\"")}\""; - } - return $"\"{string.Join("\".\"", name)}\""; - } - public override string TrimQuoteSqlName(string name) - { - var nametrim = name.Trim(); - if (nametrim.StartsWith("(") && nametrim.EndsWith(")")) - return nametrim; //原生SQL - return $"{nametrim.Trim('"').Replace("\".\"", ".").Replace(".\"", ".")}"; - } - public override string[] SplitTableName(string name) => GetSplitTableNames(name, '"', '"', 2); - public override string QuoteParamterName(string name) => $":{name}"; - public override string IsNull(string sql, object value) => $"nvl({sql}, {value})"; - public override string StringConcat(string[] objs, Type[] types) => $"{string.Join(" || ", objs)}"; - public override string Mod(string left, string right, Type leftType, Type rightType) => $"mod({left}, {right})"; - public override string Div(string left, string right, Type leftType, Type rightType) => $"trunc({left} / {right})"; - public override string Now => "systimestamp"; - public override string NowUtc => "getutcdate"; - - public override string QuoteWriteParamterAdapter(Type type, string paramterName) => paramterName; - protected override string QuoteReadColumnAdapter(Type type, Type mapType, string columnName) => columnName; - - public override string GetNoneParamaterSqlValue(List specialParams, string specialParamFlag, ColumnInfo col, Type type, object value) - { - if (value == null) return "NULL"; - if (type.IsNumberType()) return string.Format(CultureInfo.InvariantCulture, "{0}", value); - if (type == typeof(byte[])) return $"hextoraw('{CommonUtils.BytesSqlRaw(value as byte[])}')"; - return FormatSql("{0}", value, 1); - } - } -} diff --git a/Providers/FreeSql.Provider.Odbc/Default/OdbcAdo/OdbcAdo.cs b/Providers/FreeSql.Provider.Odbc/Default/OdbcAdo/OdbcAdo.cs index 4500a5ea6..8875e6549 100644 --- a/Providers/FreeSql.Provider.Odbc/Default/OdbcAdo/OdbcAdo.cs +++ b/Providers/FreeSql.Provider.Odbc/Default/OdbcAdo/OdbcAdo.cs @@ -2,7 +2,6 @@ using FreeSql.Internal.CommonProvider; using FreeSql.Internal.Model; using FreeSql.Internal.ObjectPool; -using FreeSql.Odbc.Dameng; using System; using System.Collections; using System.Data.Common; diff --git a/Providers/FreeSql.Provider.Odbc/Default/OdbcExpression.cs b/Providers/FreeSql.Provider.Odbc/Default/OdbcExpression.cs index bc3337faf..0678406f6 100644 --- a/Providers/FreeSql.Provider.Odbc/Default/OdbcExpression.cs +++ b/Providers/FreeSql.Provider.Odbc/Default/OdbcExpression.cs @@ -260,12 +260,13 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; - if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({_common.StringConcat(new string[] { args0Value, "'%'" }, new[] { typeof(int), typeof(string) })})")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"({_common.StringConcat(new string[] { "'%'", args0Value }, new[] { typeof(string), typeof(int) })})")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) LIKE ({_common.StringConcat(new string[] { "'%'", args0Value, "'%'" }, new[] { typeof(string), typeof(int), typeof(string)})})"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({_common.StringConcat(new string[] { args0Value, "'%'" }, new[] { typeof(int), typeof(string) })})")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"({_common.StringConcat(new string[] { "'%'", args0Value }, new[] { typeof(string), typeof(int) })})")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} LIKE ({_common.StringConcat(new string[] { "'%'", args0Value, "'%'" }, new[] { typeof(string), typeof(int), typeof(string) })})"; case "ToLower": return _utils.Adapter.LambdaString_ToLower(left); case "ToUpper": return _utils.Adapter.LambdaString_ToUpper(left); case "Substring": diff --git a/Providers/FreeSql.Provider.Odbc/FreeSqlOdbcGlobalExtensions.cs b/Providers/FreeSql.Provider.Odbc/FreeSqlOdbcGlobalExtensions.cs index 8459646cb..9025fcc50 100644 --- a/Providers/FreeSql.Provider.Odbc/FreeSqlOdbcGlobalExtensions.cs +++ b/Providers/FreeSql.Provider.Odbc/FreeSqlOdbcGlobalExtensions.cs @@ -36,22 +36,4 @@ /// internal static string FormatOdbcPostgreSQL(this string that, params object[] args) => _odbcPostgreSQLAdo.Addslashes(that, args); static FreeSql.Odbc.PostgreSQL.OdbcPostgreSQLAdo _odbcPostgreSQLAdo = new FreeSql.Odbc.PostgreSQL.OdbcPostgreSQLAdo(); - - /// - /// 特殊处理类似 string.Format 的使用方法,防止注入,以及 IS NULL 转换 - /// - /// - /// - /// - internal static string FormatOdbcDameng(this string that, params object[] args) => _odbcDamengAdo.Addslashes(that, args); - static FreeSql.Odbc.Dameng.OdbcDamengAdo _odbcDamengAdo = new FreeSql.Odbc.Dameng.OdbcDamengAdo(); - - /// - /// 特殊处理类似 string.Format 的使用方法,防止注入,以及 IS NULL 转换 - /// - /// - /// - /// - internal static string FormatOdbcKingbaseES(this string that, params object[] args) => _odbcKingbaseESAdo.Addslashes(that, args); - static FreeSql.Odbc.KingbaseES.OdbcKingbaseESAdo _odbcKingbaseESAdo = new FreeSql.Odbc.KingbaseES.OdbcKingbaseESAdo(); } diff --git a/Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESDelete.cs b/Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESDelete.cs deleted file mode 100644 index e4a381b96..000000000 --- a/Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESDelete.cs +++ /dev/null @@ -1,121 +0,0 @@ -using FreeSql.Internal; -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace FreeSql.Odbc.KingbaseES -{ - - class OdbcKingbaseESDelete : Internal.CommonProvider.DeleteProvider - { - public OdbcKingbaseESDelete(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) - : base(orm, commonUtils, commonExpression, dywhere) - { - } - - public override List ExecuteDeleted() - { - var ret = new List(); - DbParameter[] dbParms = null; - StringBuilder sbret = null; - ToSqlFetch(sb => - { - if (dbParms == null) - { - dbParms = _params.ToArray(); - sbret = new StringBuilder(); - sbret.Append(" RETURNING "); - - var colidx = 0; - foreach (var col in _table.Columns.Values) - { - if (colidx > 0) sbret.Append(", "); - sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName)); - ++colidx; - } - } - var sql = sb.Append(sbret).ToString(); - var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms); - _orm.Aop.CurdBeforeHandler?.Invoke(this, before); - - Exception exception = null; - try - { - ret.AddRange(_orm.Ado.Query(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms)); - } - catch (Exception ex) - { - exception = ex; - throw ex; - } - finally - { - var after = new Aop.CurdAfterEventArgs(before, exception, ret); - _orm.Aop.CurdAfterHandler?.Invoke(this, after); - } - }); - if (dbParms != null) - { - this.ClearData(); - sbret.Clear(); - } - return ret; - } - -#if net40 -#else - async public override Task> ExecuteDeletedAsync(CancellationToken cancellationToken = default) - { - var ret = new List(); - DbParameter[] dbParms = null; - StringBuilder sbret = null; - await ToSqlFetchAsync(async sb => - { - if (dbParms == null) - { - dbParms = _params.ToArray(); - sbret = new StringBuilder(); - sbret.Append(" RETURNING "); - - var colidx = 0; - foreach (var col in _table.Columns.Values) - { - if (colidx > 0) sbret.Append(", "); - sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName)); - ++colidx; - } - } - var sql = sb.Append(sbret).ToString(); - var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms); - _orm.Aop.CurdBeforeHandler?.Invoke(this, before); - - Exception exception = null; - try - { - ret.AddRange(await _orm.Ado.QueryAsync(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken)); - } - catch (Exception ex) - { - exception = ex; - throw ex; - } - finally - { - var after = new Aop.CurdAfterEventArgs(before, exception, ret); - _orm.Aop.CurdAfterHandler?.Invoke(this, after); - } - }); - if (dbParms != null) - { - this.ClearData(); - sbret.Clear(); - } - return ret; - } -#endif - } -} diff --git a/Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESInsert.cs b/Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESInsert.cs deleted file mode 100644 index 9055d486d..000000000 --- a/Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESInsert.cs +++ /dev/null @@ -1,217 +0,0 @@ -using FreeSql.Internal; -using FreeSql.Internal.Model; -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace FreeSql.Odbc.KingbaseES -{ - - class OdbcKingbaseESInsert : Internal.CommonProvider.InsertProvider where T1 : class - { - public OdbcKingbaseESInsert(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression) - : base(orm, commonUtils, commonExpression) - { - } - - internal IFreeSql InternalOrm => _orm; - internal TableInfo InternalTable => _table; - internal DbParameter[] InternalParams => _params; - internal DbConnection InternalConnection => _connection; - internal DbTransaction InternalTransaction => _transaction; - internal CommonUtils InternalCommonUtils => _commonUtils; - internal CommonExpression InternalCommonExpression => _commonExpression; - internal List InternalSource => _source; - internal Dictionary InternalIgnore => _ignore; - internal void InternalClearData() => ClearData(); - - public override int ExecuteAffrows() => base.SplitExecuteAffrows(_batchValuesLimit > 0 ? _batchValuesLimit : 5000, _batchParameterLimit > 0 ? _batchParameterLimit : 3000); - public override long ExecuteIdentity() => base.SplitExecuteIdentity(_batchValuesLimit > 0 ? _batchValuesLimit : 5000, _batchParameterLimit > 0 ? _batchParameterLimit : 3000); - public override List ExecuteInserted() => base.SplitExecuteInserted(_batchValuesLimit > 0 ? _batchValuesLimit : 5000, _batchParameterLimit > 0 ? _batchParameterLimit : 3000); - - protected override long RawExecuteIdentity() - { - var sql = this.ToSql(); - if (string.IsNullOrEmpty(sql)) return 0; - - long ret = 0; - Exception exception = null; - Aop.CurdBeforeEventArgs before = null; - - var identCols = _table.Columns.Where(a => a.Value.Attribute.IsIdentity == true); - if (identCols.Any() == false) - { - before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, sql, _params); - _orm.Aop.CurdBeforeHandler?.Invoke(this, before); - try - { - ret = _orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, _commandTimeout, _params); - } - catch (Exception ex) - { - exception = ex; - throw ex; - } - finally - { - var after = new Aop.CurdAfterEventArgs(before, exception, ret); - _orm.Aop.CurdAfterHandler?.Invoke(this, after); - } - return 0; - } - sql = string.Concat(sql, " RETURNING ", _commonUtils.QuoteSqlName(identCols.First().Value.Attribute.Name)); - before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, sql, _params); - _orm.Aop.CurdBeforeHandler?.Invoke(this, before); - try - { - long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(_connection, _transaction, CommandType.Text, sql, _commandTimeout, _params)), out ret); - } - catch (Exception ex) - { - exception = ex; - throw ex; - } - finally - { - var after = new Aop.CurdAfterEventArgs(before, exception, ret); - _orm.Aop.CurdAfterHandler?.Invoke(this, after); - } - return ret; - } - - protected override List RawExecuteInserted() - { - var sql = this.ToSql(); - if (string.IsNullOrEmpty(sql)) return new List(); - - var sb = new StringBuilder(); - sb.Append(sql).Append(" RETURNING "); - - var colidx = 0; - foreach (var col in _table.Columns.Values) - { - if (colidx > 0) sb.Append(", "); - sb.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName)); - ++colidx; - } - sql = sb.ToString(); - var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, sql, _params); - _orm.Aop.CurdBeforeHandler?.Invoke(this, before); - var ret = new List(); - Exception exception = null; - try - { - ret = _orm.Ado.Query(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, _params); - } - catch (Exception ex) - { - exception = ex; - throw ex; - } - finally - { - var after = new Aop.CurdAfterEventArgs(before, exception, ret); - _orm.Aop.CurdAfterHandler?.Invoke(this, after); - } - return ret; - } - -#if net40 -#else - public override Task ExecuteAffrowsAsync(CancellationToken cancellationToken = default) => base.SplitExecuteAffrowsAsync(_batchValuesLimit > 0 ? _batchValuesLimit : 5000, _batchParameterLimit > 0 ? _batchParameterLimit : 3000, cancellationToken); - public override Task ExecuteIdentityAsync(CancellationToken cancellationToken = default) => base.SplitExecuteIdentityAsync(_batchValuesLimit > 0 ? _batchValuesLimit : 5000, _batchParameterLimit > 0 ? _batchParameterLimit : 3000, cancellationToken); - public override Task> ExecuteInsertedAsync(CancellationToken cancellationToken = default) => base.SplitExecuteInsertedAsync(_batchValuesLimit > 0 ? _batchValuesLimit : 5000, _batchParameterLimit > 0 ? _batchParameterLimit : 3000, cancellationToken); - - async protected override Task RawExecuteIdentityAsync(CancellationToken cancellationToken = default) - { - var sql = this.ToSql(); - if (string.IsNullOrEmpty(sql)) return 0; - - long ret = 0; - Exception exception = null; - Aop.CurdBeforeEventArgs before = null; - - var identCols = _table.Columns.Where(a => a.Value.Attribute.IsIdentity == true); - if (identCols.Any() == false) - { - before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, sql, _params); - _orm.Aop.CurdBeforeHandler?.Invoke(this, before); - try - { - ret = await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _commandTimeout, _params, cancellationToken); - } - catch (Exception ex) - { - exception = ex; - throw ex; - } - finally - { - var after = new Aop.CurdAfterEventArgs(before, exception, ret); - _orm.Aop.CurdAfterHandler?.Invoke(this, after); - } - return 0; - } - sql = string.Concat(sql, " RETURNING ", _commonUtils.QuoteSqlName(identCols.First().Value.Attribute.Name)); - before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, sql, _params); - _orm.Aop.CurdBeforeHandler?.Invoke(this, before); - try - { - long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_connection, _transaction, CommandType.Text, sql, _commandTimeout, _params, cancellationToken)), out ret); - } - catch (Exception ex) - { - exception = ex; - throw ex; - } - finally - { - var after = new Aop.CurdAfterEventArgs(before, exception, ret); - _orm.Aop.CurdAfterHandler?.Invoke(this, after); - } - return ret; - } - async protected override Task> RawExecuteInsertedAsync(CancellationToken cancellationToken = default) - { - var sql = this.ToSql(); - if (string.IsNullOrEmpty(sql)) return new List(); - - var sb = new StringBuilder(); - sb.Append(sql).Append(" RETURNING "); - - var colidx = 0; - foreach (var col in _table.Columns.Values) - { - if (colidx > 0) sb.Append(", "); - sb.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName)); - ++colidx; - } - sql = sb.ToString(); - var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Insert, sql, _params); - _orm.Aop.CurdBeforeHandler?.Invoke(this, before); - var ret = new List(); - Exception exception = null; - try - { - ret = await _orm.Ado.QueryAsync(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, _params, cancellationToken); - } - catch (Exception ex) - { - exception = ex; - throw ex; - } - finally - { - var after = new Aop.CurdAfterEventArgs(before, exception, ret); - _orm.Aop.CurdAfterHandler?.Invoke(this, after); - } - return ret; - } -#endif - } -} diff --git a/Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESInsertOrUpdate.cs b/Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESInsertOrUpdate.cs deleted file mode 100644 index d5bb85659..000000000 --- a/Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESInsertOrUpdate.cs +++ /dev/null @@ -1,92 +0,0 @@ -using FreeSql.Internal; -using System; -using System.Collections.Generic; -using System.Data.Common; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; - -namespace FreeSql.Odbc.KingbaseES -{ - - class OdbcKingbaseESInsertOrUpdate : Internal.CommonProvider.InsertOrUpdateProvider where T1 : class - { - public OdbcKingbaseESInsertOrUpdate(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression) - : base(orm, commonUtils, commonExpression) - { - } - - public override string ToSql() - { - var dbParams = new List(); - if (_sourceSql != null) - { - var data = new List(); - data.Add((T1)_table.Type.CreateInstanceGetDefaultValue()); - var sql = getInsertSql(data, false, false); - var sb = new StringBuilder(); - sb.Append(sql.Substring(0, sql.IndexOf(") VALUES"))); - sb.Append(") \r\n"); - WriteSourceSelectUnionAll(null, sb, null); - sb.Append(sql.Substring(sql.IndexOf("\r\nON CONFLICT(") + 2)); - return sb.ToString(); - } - if (_source?.Any() != true) return null; - - var sqls = new string[2]; - var ds = SplitSourceByIdentityValueIsNull(_source); - if (ds.Item1.Any()) sqls[0] = string.Join("\r\n\r\n;\r\n\r\n", ds.Item1.Select(a => getInsertSql(a, false, true))); - if (ds.Item2.Any()) sqls[1] = string.Join("\r\n\r\n;\r\n\r\n", ds.Item2.Select(a => getInsertSql(a, true, true))); - _params = dbParams.ToArray(); - if (ds.Item2.Any() == false) return sqls[0]; - if (ds.Item1.Any() == false) return sqls[1]; - return string.Join("\r\n\r\n;\r\n\r\n", sqls); - - string getInsertSql(List data, bool flagInsert, bool noneParameter) - { - var insert = _orm.Insert() - .AsTable(_tableRule).AsType(_table.Type) - .WithConnection(_connection) - .WithTransaction(_transaction) - .NoneParameter(noneParameter) as Internal.CommonProvider.InsertProvider; - insert._source = data; - insert._table = _table; - insert._noneParameterFlag = flagInsert ? "cuc" : "cu"; - - string sql = ""; - if (IdentityColumn != null && flagInsert) sql = insert.ToSql(); - else - { - var ocdu = new OdbcKingbaseESOnConflictDoUpdate(insert.InsertIdentity()); - ocdu._tempPrimarys = _tempPrimarys; - var cols = _table.Columns.Values.Where(a => _updateSetDict.ContainsKey(a.Attribute.Name) || - _tempPrimarys.Contains(a) == false && a.Attribute.CanUpdate == true && a.Attribute.IsIdentity == false && _updateIgnore.ContainsKey(a.Attribute.Name) == false); - ocdu.UpdateColumns(cols.Select(a => a.Attribute.Name).ToArray()); - if (_doNothing == true || cols.Any() == false) - ocdu.DoNothing(); - sql = ocdu.ToSql(); - - if (_updateSetDict.Any()) - { - var findregex = new Regex("(t1|t2)." + _commonUtils.QuoteSqlName("test").Replace("test", "(\\w+)")); - var tableName = _commonUtils.QuoteSqlName(TableRuleInvoke()); - foreach (var usd in _updateSetDict) - { - var field = _commonUtils.QuoteSqlName(usd.Key); - var findsql = $"{field} = EXCLUDED.{field}"; - var usdval = findregex.Replace(usd.Value, m => - { - if (m.Groups[1].Value == "t1") return $"{tableName}.{_commonUtils.QuoteSqlName(m.Groups[2].Value)}"; - return $"EXCLUDED.{_commonUtils.QuoteSqlName(m.Groups[2].Value)}"; - }); - sql = sql.Replace(findsql, $"{field} = {usdval}"); - } - } - } - if (string.IsNullOrEmpty(sql)) return null; - if (insert._params?.Any() == true) dbParams.AddRange(insert._params); - return sql; - } - } - } -} \ No newline at end of file diff --git a/Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESOnConflictDoUpdate.cs b/Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESOnConflictDoUpdate.cs deleted file mode 100644 index c676190d4..000000000 --- a/Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESOnConflictDoUpdate.cs +++ /dev/null @@ -1,217 +0,0 @@ -using FreeSql.Aop; -using FreeSql.Internal.Model; -using System; -using System.Collections.Generic; -using System.Data; -using System.Linq; -using System.Linq.Expressions; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace FreeSql.Odbc.KingbaseES -{ - public class OdbcKingbaseESOnConflictDoUpdate where T1 : class - { - internal OdbcKingbaseESInsert _pgsqlInsert; - internal OdbcKingbaseESUpdate _pgsqlUpdatePriv; - internal OdbcKingbaseESUpdate _pgsqlUpdate => _pgsqlUpdatePriv ?? - (_pgsqlUpdatePriv = new OdbcKingbaseESUpdate(_pgsqlInsert.InternalOrm, _pgsqlInsert.InternalCommonUtils, _pgsqlInsert.InternalCommonExpression, null) { InternalTableAlias = "EXCLUDED" } - .NoneParameter().SetSource(_pgsqlInsert.InternalSource) as OdbcKingbaseESUpdate); - internal ColumnInfo[] _tempPrimarys; - bool _doNothing; - - public OdbcKingbaseESOnConflictDoUpdate(IInsert insert, Expression> columns = null) - { - _pgsqlInsert = insert as OdbcKingbaseESInsert; - if (_pgsqlInsert == null) throw new Exception(CoreStrings.S_Features_Unique("OnConflictDoUpdate", "Odbc/KingbaseES")); - if (_pgsqlInsert._noneParameterFlag == "c") _pgsqlInsert._noneParameterFlag = "cu"; - - if (columns != null) - { - var colsList = new List(); - var cols = _pgsqlInsert.InternalCommonExpression.ExpressionSelectColumns_MemberAccess_New_NewArrayInit(null, null, columns?.Body, false, null).ToDictionary(a => a, a => true); - foreach (var col in _pgsqlInsert.InternalTable.Columns.Values) - if (cols.ContainsKey(col.Attribute.Name)) - colsList.Add(col); - _tempPrimarys = colsList.ToArray(); - } - if (_tempPrimarys == null || _tempPrimarys.Any() == false) - _tempPrimarys = _pgsqlInsert.InternalTable.Primarys; - if (_tempPrimarys.Any() == false) throw new Exception(CoreStrings.S_OnConflictDoUpdate_MustIsPrimary); - } - - protected void ClearData() - { - _pgsqlInsert.InternalClearData(); - _pgsqlUpdatePriv = null; - } - - public OdbcKingbaseESOnConflictDoUpdate IgnoreColumns(Expression> columns) - { - _pgsqlUpdate.IgnoreColumns(columns); - return this; - } - public OdbcKingbaseESOnConflictDoUpdate UpdateColumns(Expression> columns) - { - _pgsqlUpdate.UpdateColumns(columns); - return this; - } - public OdbcKingbaseESOnConflictDoUpdate IgnoreColumns(string[] columns) - { - _pgsqlUpdate.IgnoreColumns(columns); - return this; - } - public OdbcKingbaseESOnConflictDoUpdate UpdateColumns(string[] columns) - { - _pgsqlUpdate.UpdateColumns(columns); - return this; - } - - public OdbcKingbaseESOnConflictDoUpdate Set(Expression> column, TMember value) - { - _pgsqlUpdate.Set(column, value); - return this; - } - //由于表达式解析问题,ON CONFLICT("id") DO UPDATE SET 需要指定表别名,如 Set(a => a.Clicks + 1) 解析会失败 - //暂时不开放这个功能,如有需要使用 SetRaw("click = t.click + 1") 替代该操作 - //public OnConflictDoUpdate Set(Expression> exp) - //{ - // _pgsqlUpdate.Set(exp); - // return this; - //} - public OdbcKingbaseESOnConflictDoUpdate SetRaw(string sql) - { - _pgsqlUpdate.SetRaw(sql); - return this; - } - - public OdbcKingbaseESOnConflictDoUpdate DoNothing() - { - _doNothing = true; - return this; - } - - public string ToSql() - { - var sb = new StringBuilder(); - sb.Append(_pgsqlInsert.ToSql()).Append("\r\nON CONFLICT("); - for (var a = 0; a < _tempPrimarys.Length; a++) - { - if (a > 0) sb.Append(", "); - sb.Append(_pgsqlInsert.InternalCommonUtils.QuoteSqlName(_tempPrimarys[a].Attribute.Name)); - } - if (_doNothing) - { - sb.Append(") DO NOTHING"); - } - else - { - sb.Append(") DO UPDATE SET\r\n"); - - if (_pgsqlUpdate._tempPrimarys.Any() == false) _pgsqlUpdate._tempPrimarys = _tempPrimarys; - var sbSetEmpty = _pgsqlUpdate.InternalSbSet.Length == 0; - var sbSetIncrEmpty = _pgsqlUpdate.InternalSbSetIncr.Length == 0; - if (sbSetEmpty == false || sbSetIncrEmpty == false) - { - if (sbSetEmpty == false) sb.Append(_pgsqlUpdate.InternalSbSet.ToString().Substring(2)); - if (sbSetIncrEmpty == false) sb.Append(sbSetEmpty ? _pgsqlUpdate.InternalSbSetIncr.ToString().Substring(2) : _pgsqlUpdate.InternalSbSetIncr.ToString()); - } - else - { - var colidx = 0; - foreach (var col in _pgsqlInsert.InternalTable.Columns.Values) - { - if (col.Attribute.IsPrimary || _pgsqlUpdate.InternalIgnore.ContainsKey(col.Attribute.Name)) continue; - - if (colidx > 0) sb.Append(", \r\n"); - - if (col.Attribute.IsVersion == true && col.Attribute.MapType != typeof(byte[])) - { - var field = _pgsqlInsert.InternalCommonUtils.QuoteSqlName(col.Attribute.Name); - sb.Append(field).Append(" = ").Append(_pgsqlInsert.InternalCommonUtils.QuoteSqlName(_pgsqlInsert.InternalTable.DbName)).Append(".").Append(field).Append(" + 1"); - } - else if (_pgsqlInsert.InternalIgnore.ContainsKey(col.Attribute.Name)) - { - if (string.IsNullOrEmpty(col.DbUpdateValue) == false) - { - sb.Append(_pgsqlInsert.InternalCommonUtils.QuoteSqlName(col.Attribute.Name)).Append(" = ").Append(col.DbUpdateValue); - } - else - { - var caseWhen = _pgsqlUpdate.InternalWhereCaseSource(col.CsName, sqlval => sqlval).Trim(); - sb.Append(caseWhen); - if (caseWhen.EndsWith(" END")) _pgsqlUpdate.InternalToSqlCaseWhenEnd(sb, col); - } - } - else - { - var field = _pgsqlInsert.InternalCommonUtils.QuoteSqlName(col.Attribute.Name); - sb.Append(field).Append(" = EXCLUDED.").Append(field); - } - ++colidx; - } - } - } - - return sb.ToString(); - } - - public long ExecuteAffrows() - { - var sql = this.ToSql(); - if (string.IsNullOrEmpty(sql)) return 0; - - var before = new CurdBeforeEventArgs(_pgsqlInsert.InternalTable.Type, _pgsqlInsert.InternalTable, CurdType.Insert, sql, _pgsqlInsert.InternalParams); - _pgsqlInsert.InternalOrm.Aop.CurdBeforeHandler?.Invoke(_pgsqlInsert, before); - long ret = 0; - Exception exception = null; - try - { - ret = _pgsqlInsert.InternalOrm.Ado.ExecuteNonQuery(_pgsqlInsert.InternalConnection, _pgsqlInsert.InternalTransaction, CommandType.Text, sql, _pgsqlInsert._commandTimeout, _pgsqlInsert.InternalParams); - } - catch (Exception ex) - { - exception = ex; - throw ex; - } - finally - { - var after = new CurdAfterEventArgs(before, exception, ret); - _pgsqlInsert.InternalOrm.Aop.CurdAfterHandler?.Invoke(_pgsqlInsert, after); - ClearData(); - } - return ret; - } - -#if net40 -#else - async public Task ExecuteAffrowsAsync(CancellationToken cancellationToken = default) - { - var sql = this.ToSql(); - if (string.IsNullOrEmpty(sql)) return 0; - - var before = new CurdBeforeEventArgs(_pgsqlInsert.InternalTable.Type, _pgsqlInsert.InternalTable, CurdType.Insert, sql, _pgsqlInsert.InternalParams); - _pgsqlInsert.InternalOrm.Aop.CurdBeforeHandler?.Invoke(_pgsqlInsert, before); - long ret = 0; - Exception exception = null; - try - { - ret = await _pgsqlInsert.InternalOrm.Ado.ExecuteNonQueryAsync(_pgsqlInsert.InternalConnection, _pgsqlInsert.InternalTransaction, CommandType.Text, sql, _pgsqlInsert._commandTimeout, _pgsqlInsert.InternalParams, cancellationToken); - } - catch (Exception ex) - { - exception = ex; - throw ex; - } - finally - { - var after = new CurdAfterEventArgs(before, exception, ret); - _pgsqlInsert.InternalOrm.Aop.CurdAfterHandler?.Invoke(_pgsqlInsert, after); - ClearData(); - } - return ret; - } -#endif - } -} diff --git a/Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESSelect.cs b/Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESSelect.cs deleted file mode 100644 index 4a4de8844..000000000 --- a/Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESSelect.cs +++ /dev/null @@ -1,222 +0,0 @@ -using FreeSql.Internal; -using FreeSql.Internal.Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Text; - -namespace FreeSql.Odbc.KingbaseES -{ - - class OdbcKingbaseESSelect : FreeSql.Internal.CommonProvider.Select1Provider - { - - internal static string ToSqlStatic(CommonUtils _commonUtils, CommonExpression _commonExpression, string _select, bool _distinct, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List _tables, List> tbUnions, Func _aliasRule, string _tosqlAppendContent, List _whereGlobalFilter, IFreeSql _orm) - { - if (_orm.CodeFirst.IsAutoSyncStructure) - _orm.CodeFirst.SyncStructure(_tables.Select(a => a.Table.Type).ToArray()); - - if (_whereGlobalFilter.Any()) - foreach (var tb in _tables.Where(a => a.Type != SelectTableInfoType.Parent)) - { - tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereGlobalFilter.Where(a => a.Before == false), true); - tb.CascadeBefore = _commonExpression.GetWhereCascadeSql(tb, _whereGlobalFilter.Where(a => a.Before == true), true); - } - - var sb = new StringBuilder(); - var tbUnionsGt0 = tbUnions.Count > 1; - for (var tbUnionsIdx = 0; tbUnionsIdx < tbUnions.Count; tbUnionsIdx++) - { - if (tbUnionsIdx > 0) sb.Append("\r\n \r\nUNION ALL\r\n \r\n"); - if (tbUnionsGt0) sb.Append(_select).Append(" * from ("); - var tbUnion = tbUnions[tbUnionsIdx]; - - var sbnav = new StringBuilder(); - sb.Append(_select); - if (_distinct) sb.Append("DISTINCT "); - sb.Append(field).Append(" \r\nFROM "); - var tbsjoin = _tables.Where(a => a.Type != SelectTableInfoType.From).ToArray(); - var tbsfrom = _tables.Where(a => a.Type == SelectTableInfoType.From).ToArray(); - for (var a = 0; a < tbsfrom.Length; a++) - { - sb.Append(_commonUtils.QuoteSqlName(tbUnion[tbsfrom[a].Table.Type])).Append(" ").Append(_aliasRule?.Invoke(tbsfrom[a].Table.Type, tbsfrom[a].Alias) ?? tbsfrom[a].Alias); - if (tbsjoin.Length > 0) - { - //如果存在 join 查询,则处理 from t1, t2 改为 from t1 inner join t2 on 1 = 1 - for (var b = 1; b < tbsfrom.Length; b++) - { - sb.Append(" \r\nLEFT JOIN ").Append(_commonUtils.QuoteSqlName(tbUnion[tbsfrom[b].Table.Type])).Append(" ").Append(_aliasRule?.Invoke(tbsfrom[b].Table.Type, tbsfrom[b].Alias) ?? tbsfrom[b].Alias); - - if (string.IsNullOrEmpty(tbsfrom[b].NavigateCondition) && - string.IsNullOrEmpty(tbsfrom[b].On) && - string.IsNullOrEmpty(tbsfrom[b].Cascade) && - string.IsNullOrEmpty(tbsfrom[b].CascadeBefore)) sb.Append(" ON 1 = 1"); - else sb.Append(" ON ").Append(string.Join(" AND ", new[] - { - tbsfrom[b].CascadeBefore, - tbsfrom[b].NavigateCondition ?? tbsfrom[b].On, - tbsfrom[b].Cascade - }.Where(sql => string.IsNullOrEmpty(sql) == false))); - } - break; - } - else - { - if (a > 0 && !string.IsNullOrEmpty(tbsfrom[a].CascadeBefore)) sbnav.Append(" AND ").Append(tbsfrom[a].CascadeBefore); - if (!string.IsNullOrEmpty(tbsfrom[a].NavigateCondition)) sbnav.Append(" AND (").Append(tbsfrom[a].NavigateCondition).Append(")"); - if (!string.IsNullOrEmpty(tbsfrom[a].On)) sbnav.Append(" AND (").Append(tbsfrom[a].On).Append(")"); - if (a > 0 && !string.IsNullOrEmpty(tbsfrom[a].Cascade)) sbnav.Append(" AND ").Append(tbsfrom[a].Cascade); - } - if (a < tbsfrom.Length - 1) sb.Append(", "); - } - foreach (var tb in tbsjoin) - { - switch (tb.Type) - { - case SelectTableInfoType.Parent: - case SelectTableInfoType.RawJoin: - continue; - case SelectTableInfoType.LeftJoin: - sb.Append(" \r\nLEFT JOIN "); - break; - case SelectTableInfoType.InnerJoin: - sb.Append(" \r\nINNER JOIN "); - break; - case SelectTableInfoType.RightJoin: - sb.Append(" \r\nRIGHT JOIN "); - break; - } - sb.Append(_commonUtils.QuoteSqlName(tbUnion[tb.Table.Type])).Append(" ").Append(_aliasRule?.Invoke(tb.Table.Type, tb.Alias) ?? tb.Alias) - .Append(" ON ").Append(string.Join(" AND ", new[] - { - tb.CascadeBefore, - tb.On ?? tb.NavigateCondition, - tb.Cascade - }.Where(sql => string.IsNullOrEmpty(sql) == false))); - if (!string.IsNullOrEmpty(tb.On) && !string.IsNullOrEmpty(tb.NavigateCondition)) sbnav.Append(" AND (").Append(tb.NavigateCondition).Append(")"); - } - if (_join.Length > 0) sb.Append(_join); - - if (!string.IsNullOrEmpty(_tables[0].CascadeBefore)) sbnav.Append(" AND ").Append(_tables[0].CascadeBefore); - sbnav.Append(_where); - if (!string.IsNullOrEmpty(_tables[0].Cascade)) sbnav.Append(" AND ").Append(_tables[0].Cascade); - - if (sbnav.Length > 0) - { - sb.Append(" \r\nWHERE ").Append(sbnav.Remove(0, 5)); - } - if (string.IsNullOrEmpty(_groupby) == false) - { - sb.Append(_groupby); - if (string.IsNullOrEmpty(_having) == false) - sb.Append(" \r\nHAVING ").Append(_having.Substring(5)); - } - sb.Append(_orderby); - if (_limit > 0) - sb.Append(" \r\nlimit ").Append(_limit); - if (_skip > 0) - sb.Append(" \r\noffset ").Append(_skip); - - sbnav.Clear(); - if (tbUnionsGt0) sb.Append(") ftb"); - } - return sb.Append(_tosqlAppendContent).ToString(); - } - - public OdbcKingbaseESSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override ISelect From(Expression, T2, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcKingbaseESSelect(_orm, _commonUtils, _commonExpression, null); OdbcKingbaseESSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcKingbaseESSelect(_orm, _commonUtils, _commonExpression, null); OdbcKingbaseESSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcKingbaseESSelect(_orm, _commonUtils, _commonExpression, null); OdbcKingbaseESSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcKingbaseESSelect(_orm, _commonUtils, _commonExpression, null); OdbcKingbaseESSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, T6, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcKingbaseESSelect(_orm, _commonUtils, _commonExpression, null); OdbcKingbaseESSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, T6, T7, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcKingbaseESSelect(_orm, _commonUtils, _commonExpression, null); OdbcKingbaseESSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, T6, T7, T8, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcKingbaseESSelect(_orm, _commonUtils, _commonExpression, null); OdbcKingbaseESSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, T6, T7, T8, T9, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcKingbaseESSelect(_orm, _commonUtils, _commonExpression, null); OdbcKingbaseESSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, T6, T7, T8, T9, T10, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcKingbaseESSelect(_orm, _commonUtils, _commonExpression, null); OdbcKingbaseESSelect.CopyData(this, ret, exp?.Parameters); return ret; } - - public override ISelect From(Expression, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcKingbaseESSelect(_orm, _commonUtils, _commonExpression, null); OdbcKingbaseESSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcKingbaseESSelect(_orm, _commonUtils, _commonExpression, null); OdbcKingbaseESSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcKingbaseESSelect(_orm, _commonUtils, _commonExpression, null); OdbcKingbaseESSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcKingbaseESSelect(_orm, _commonUtils, _commonExpression, null); OdbcKingbaseESSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcKingbaseESSelect(_orm, _commonUtils, _commonExpression, null); OdbcKingbaseESSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override ISelect From(Expression, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, ISelectFromExpression>> exp) { this.InternalFrom(exp); var ret = new OdbcKingbaseESSelect(_orm, _commonUtils, _commonExpression, null); OdbcKingbaseESSelect.CopyData(this, ret, exp?.Parameters); return ret; } - public override string ToSql(string field = null) => ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcKingbaseESSelect : FreeSql.Internal.CommonProvider.Select2Provider where T2 : class - { - public OdbcKingbaseESSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcKingbaseESSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcKingbaseESSelect : FreeSql.Internal.CommonProvider.Select3Provider where T2 : class where T3 : class - { - public OdbcKingbaseESSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcKingbaseESSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcKingbaseESSelect : FreeSql.Internal.CommonProvider.Select4Provider where T2 : class where T3 : class where T4 : class - { - public OdbcKingbaseESSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcKingbaseESSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcKingbaseESSelect : FreeSql.Internal.CommonProvider.Select5Provider where T2 : class where T3 : class where T4 : class where T5 : class - { - public OdbcKingbaseESSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcKingbaseESSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcKingbaseESSelect : FreeSql.Internal.CommonProvider.Select6Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class - { - public OdbcKingbaseESSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcKingbaseESSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcKingbaseESSelect : FreeSql.Internal.CommonProvider.Select7Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class - { - public OdbcKingbaseESSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcKingbaseESSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcKingbaseESSelect : FreeSql.Internal.CommonProvider.Select8Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class - { - public OdbcKingbaseESSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcKingbaseESSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcKingbaseESSelect : FreeSql.Internal.CommonProvider.Select9Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class - { - public OdbcKingbaseESSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcKingbaseESSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcKingbaseESSelect : FreeSql.Internal.CommonProvider.Select10Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class - { - public OdbcKingbaseESSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcKingbaseESSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - - class OdbcKingbaseESSelect : FreeSql.Internal.CommonProvider.Select11Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class - { - public OdbcKingbaseESSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcKingbaseESSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcKingbaseESSelect : FreeSql.Internal.CommonProvider.Select12Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class - { - public OdbcKingbaseESSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcKingbaseESSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcKingbaseESSelect : FreeSql.Internal.CommonProvider.Select13Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class where T13 : class - { - public OdbcKingbaseESSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcKingbaseESSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcKingbaseESSelect : FreeSql.Internal.CommonProvider.Select14Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class where T13 : class where T14 : class - { - public OdbcKingbaseESSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcKingbaseESSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcKingbaseESSelect : FreeSql.Internal.CommonProvider.Select15Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class where T13 : class where T14 : class where T15 : class - { - public OdbcKingbaseESSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcKingbaseESSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } - class OdbcKingbaseESSelect : FreeSql.Internal.CommonProvider.Select16Provider where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class where T13 : class where T14 : class where T15 : class where T16 : class - { - public OdbcKingbaseESSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { } - public override string ToSql(string field = null) => OdbcKingbaseESSelect.ToSqlStatic(_commonUtils, _commonExpression, _select, _distinct, field ?? this.GetAllFieldExpressionTreeLevel2().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, this.GetTableRuleUnions(), _aliasRule, _tosqlAppendContent, _whereGlobalFilter, _orm); - } -} diff --git a/Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESUpdate.cs b/Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESUpdate.cs deleted file mode 100644 index 7bb71ddfa..000000000 --- a/Providers/FreeSql.Provider.Odbc/KingbaseES/Curd/OdbcKingbaseESUpdate.cs +++ /dev/null @@ -1,189 +0,0 @@ -using FreeSql.Internal; -using FreeSql.Internal.Model; -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace FreeSql.Odbc.KingbaseES -{ - - class OdbcKingbaseESUpdate : Internal.CommonProvider.UpdateProvider - { - - public OdbcKingbaseESUpdate(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) - : base(orm, commonUtils, commonExpression, dywhere) - { - } - - internal string InternalTableAlias { get; set; } - internal StringBuilder InternalSbSet => _set; - internal StringBuilder InternalSbSetIncr => _setIncr; - internal Dictionary InternalIgnore => _ignore; - internal void InternalResetSource(List source) => _source = source; - internal string InternalWhereCaseSource(string CsName, Func thenValue) => WhereCaseSource(CsName, thenValue); - internal void InternalToSqlCaseWhenEnd(StringBuilder sb, ColumnInfo col) => ToSqlCaseWhenEnd(sb, col); - - public override int ExecuteAffrows() => base.SplitExecuteAffrows(_batchRowsLimit > 0 ? _batchRowsLimit : 500, _batchParameterLimit > 0 ? _batchParameterLimit : 3000); - protected override List ExecuteUpdated(IEnumerable columns) => base.SplitExecuteUpdated(_batchRowsLimit > 0 ? _batchRowsLimit : 500, _batchParameterLimit > 0 ? _batchParameterLimit : 3000, columns); - - protected override List RawExecuteUpdated(IEnumerable columns) - { - var ret = new List(); - DbParameter[] dbParms = null; - StringBuilder sbret = null; - ToSqlFetch(sb => - { - if (dbParms == null) - { - dbParms = _params.Concat(_paramsSource).ToArray(); - sbret = new StringBuilder(); - sbret.Append(" RETURNING "); - - var colidx = 0; - foreach (var col in columns) - { - if (colidx > 0) sbret.Append(", "); - sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName)); - ++colidx; - } - } - var sql = sb.Append(sbret).ToString(); - var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Update, sql, dbParms); - _orm.Aop.CurdBeforeHandler?.Invoke(this, before); - - Exception exception = null; - try - { - var queryType = typeof(TReturn) == typeof(T1) ? (_table.TypeLazy ?? _table.Type) : null; - var rettmp = _orm.Ado.Query(queryType, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms); - ValidateVersionAndThrow(rettmp.Count, sql, dbParms); - ret.AddRange(rettmp); - } - catch (Exception ex) - { - exception = ex; - throw; - } - finally - { - var after = new Aop.CurdAfterEventArgs(before, exception, ret); - _orm.Aop.CurdAfterHandler?.Invoke(this, after); - } - }); - sbret?.Clear(); - return ret; - } - - protected override void ToSqlCase(StringBuilder caseWhen, ColumnInfo[] primarys) - { - if (primarys.Length == 1) - { - var pk = primarys.First(); - if (string.IsNullOrEmpty(InternalTableAlias) == false) caseWhen.Append(InternalTableAlias).Append("."); - caseWhen.Append(_commonUtils.RereadColumn(pk, _commonUtils.QuoteSqlName(pk.Attribute.Name))); - return; - } - caseWhen.Append("("); - var pkidx = 0; - foreach (var pk in primarys) - { - if (pkidx > 0) caseWhen.Append(" || '+' || "); - if (string.IsNullOrEmpty(InternalTableAlias) == false) caseWhen.Append(InternalTableAlias).Append("."); - caseWhen.Append(_commonUtils.RereadColumn(pk, _commonUtils.QuoteSqlName(pk.Attribute.Name))).Append("::text"); - ++pkidx; - } - caseWhen.Append(")"); - } - - protected override void ToSqlWhen(StringBuilder sb, ColumnInfo[] primarys, object d) - { - if (primarys.Length == 1) - { - sb.Append(_commonUtils.FormatSql("{0}", primarys[0].GetDbValue(d))); - return; - } - sb.Append("("); - var pkidx = 0; - foreach (var pk in primarys) - { - if (pkidx > 0) sb.Append(" || '+' || "); - sb.Append(_commonUtils.FormatSql("{0}", pk.GetDbValue(d))).Append("::text"); - ++pkidx; - } - sb.Append(")"); - } - - protected override void ToSqlCaseWhenEnd(StringBuilder sb, ColumnInfo col) - { - if (_noneParameter == false) return; - if (col.Attribute.MapType == typeof(string)) - { - sb.Append("::text"); - return; - } - var dbtype = _commonUtils.CodeFirst.GetDbInfo(col.Attribute.MapType)?.dbtype; - if (dbtype == null) return; - - sb.Append("::").Append(dbtype); - } - -#if net40 -#else - public override Task ExecuteAffrowsAsync(CancellationToken cancellationToken = default) => base.SplitExecuteAffrowsAsync(_batchRowsLimit > 0 ? _batchRowsLimit : 500, _batchParameterLimit > 0 ? _batchParameterLimit : 3000, cancellationToken); - protected override Task> ExecuteUpdatedAsync(IEnumerable columns, CancellationToken cancellationToken = default) => base.SplitExecuteUpdatedAsync(_batchRowsLimit > 0 ? _batchRowsLimit : 500, _batchParameterLimit > 0 ? _batchParameterLimit : 3000, columns, cancellationToken); - - async protected override Task> RawExecuteUpdatedAsync(IEnumerable columns, CancellationToken cancellationToken = default) - { - var ret = new List(); - DbParameter[] dbParms = null; - StringBuilder sbret = null; - await ToSqlFetchAsync(async sb => - { - if (dbParms == null) - { - dbParms = _params.Concat(_paramsSource).ToArray(); - sbret = new StringBuilder(); - sbret.Append(" RETURNING "); - - var colidx = 0; - foreach (var col in columns) - { - if (colidx > 0) sbret.Append(", "); - sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName)); - ++colidx; - } - } - var sql = sb.Append(sbret).ToString(); - var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Update, sql, dbParms); - _orm.Aop.CurdBeforeHandler?.Invoke(this, before); - - Exception exception = null; - try - { - var queryType = typeof(TReturn) == typeof(T1) ? (_table.TypeLazy ?? _table.Type) : null; - var rettmp = await _orm.Ado.QueryAsync(queryType, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken); - ValidateVersionAndThrow(rettmp.Count, sql, dbParms); - ret.AddRange(rettmp); - } - catch (Exception ex) - { - exception = ex; - throw; - } - finally - { - var after = new Aop.CurdAfterEventArgs(before, exception, ret); - _orm.Aop.CurdAfterHandler?.Invoke(this, after); - } - }); - sbret?.Clear(); - return ret; - } -#endif - } -} diff --git a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESAdo/OdbcKingbaseESAdo.cs b/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESAdo/OdbcKingbaseESAdo.cs deleted file mode 100644 index 415f17ad3..000000000 --- a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESAdo/OdbcKingbaseESAdo.cs +++ /dev/null @@ -1,95 +0,0 @@ -using FreeSql.Internal; -using FreeSql.Internal.CommonProvider; -using FreeSql.Internal.Model; -using FreeSql.Internal.ObjectPool; -using FreeSql.Odbc.Dameng; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Data.Common; -using System.Data.Odbc; -using System.Linq; -using System.Text; -using System.Threading; - -namespace FreeSql.Odbc.KingbaseES -{ - class OdbcKingbaseESAdo : FreeSql.Internal.CommonProvider.AdoProvider - { - public OdbcKingbaseESAdo() : base(DataType.OdbcKingbaseES, null, null) { } - public OdbcKingbaseESAdo(CommonUtils util, string masterConnectionString, string[] slaveConnectionStrings, Func connectionFactory) : base(DataType.OdbcKingbaseES, masterConnectionString, slaveConnectionStrings) - { - base._util = util; - if (connectionFactory != null) - { - var pool = new FreeSql.Internal.CommonProvider.DbConnectionPool(DataType.OdbcKingbaseES, connectionFactory); - ConnectionString = pool.TestConnection?.ConnectionString; - MasterPool = pool; - return; - } - - var isAdoPool = masterConnectionString?.StartsWith("AdoConnectionPool,") ?? false; - if (isAdoPool) masterConnectionString = masterConnectionString.Substring("AdoConnectionPool,".Length); - if (!string.IsNullOrEmpty(masterConnectionString)) - MasterPool = isAdoPool ? - new DbConnectionStringPool(base.DataType, CoreStrings.S_MasterDatabase, () => new OdbcConnection(masterConnectionString)) as IObjectPool : - new OdbcKingbaseESConnectionPool(CoreStrings.S_MasterDatabase, masterConnectionString, null, null); - - slaveConnectionStrings?.ToList().ForEach(slaveConnectionString => - { - var slavePool = isAdoPool ? - new DbConnectionStringPool(base.DataType, $"{CoreStrings.S_SlaveDatabase}{SlavePools.Count + 1}", () => new OdbcConnection(slaveConnectionString)) as IObjectPool : - new OdbcKingbaseESConnectionPool($"{CoreStrings.S_SlaveDatabase}{SlavePools.Count + 1}", slaveConnectionString, () => Interlocked.Decrement(ref slaveUnavailables), () => Interlocked.Increment(ref slaveUnavailables)); - SlavePools.Add(slavePool); - }); - } - public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn) - { - if (param == null) return "NULL"; - if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false)) - param = Utils.GetDataReaderValue(mapType, param); - - if (param is bool || param is bool?) - return (bool)param ? "'t'" : "'f'"; - else if (param is string) - return string.Concat("'", param.ToString().Replace("'", "''"), "'"); - else if (param is char) - return string.Concat("'", param.ToString().Replace("'", "''").Replace('\0', ' '), "'"); - else if (param is Enum) - return AddslashesTypeHandler(param.GetType(), param) ?? ((Enum)param).ToInt64(); - else if (decimal.TryParse(string.Concat(param), out var trydec)) - return param; - - else if (param is DateTime) - return AddslashesTypeHandler(typeof(DateTime), param) ?? string.Concat("'", ((DateTime)param).ToString("yyyy-MM-dd HH:mm:ss.ffffff"), "'"); - else if (param is DateTime?) - return AddslashesTypeHandler(typeof(DateTime?), param) ?? string.Concat("'", ((DateTime)param).ToString("yyyy-MM-dd HH:mm:ss.ffffff"), "'"); - - else if (param is TimeSpan || param is TimeSpan?) - { - var ts = (TimeSpan)param; - return $"'{Math.Min(24, (int)Math.Floor(ts.TotalHours))}:{ts.Minutes}:{ts.Seconds}'"; - } - else if (param is byte[]) - return $"'\\x{CommonUtils.BytesSqlRaw(param as byte[])}'"; - else if (param is IEnumerable) - return AddslashesIEnumerable(param, mapType, mapColumn); - - return string.Concat("'", param.ToString().Replace("'", "''"), "'"); - } - - public override DbCommand CreateCommand() - { - return new OdbcCommand(); - } - - public override void ReturnConnection(IObjectPool pool, Object conn, Exception ex) - { - var rawPool = pool as OdbcKingbaseESConnectionPool; - if (rawPool != null) rawPool.Return(conn, ex); - else pool.Return(conn); - } - - public override DbParameter[] GetDbParamtersByObject(string sql, object obj) => _util.GetDbParamtersByObject(sql, obj); - } -} diff --git a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESAdo/OdbcKingbaseESConnectionPool.cs b/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESAdo/OdbcKingbaseESConnectionPool.cs deleted file mode 100644 index 9884b4b35..000000000 --- a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESAdo/OdbcKingbaseESConnectionPool.cs +++ /dev/null @@ -1,250 +0,0 @@ -using FreeSql.Internal.ObjectPool; -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Data.Odbc; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; - -namespace FreeSql.Odbc.KingbaseES -{ - - class OdbcKingbaseESConnectionPool : ObjectPool - { - - internal Action availableHandler; - internal Action unavailableHandler; - internal string UserId { get; set; } - - public OdbcKingbaseESConnectionPool(string name, string connectionString, Action availableHandler, Action unavailableHandler) : base(null) - { - this.UserId = OdbcKingbaseESConnectionPool.GetUserId(connectionString); - - this.availableHandler = availableHandler; - this.unavailableHandler = unavailableHandler; - var policy = new OdbcKingbaseESConnectionPoolPolicy - { - _pool = this, - Name = name - }; - this.Policy = policy; - policy.ConnectionString = connectionString; - } - - public static string GetUserId(string connectionString) - { - var userIdMatch = Regex.Match(connectionString, @"(User\s+Id|Uid)\s*=\s*([^;]+)", RegexOptions.IgnoreCase); - if (userIdMatch.Success == false) throw new Exception(@"从 ConnectionString 中无法匹配 (User\s+Id|Uid)\s*=\s*([^;]+)"); - return userIdMatch.Groups[2].Value.Trim().ToUpper(); - } - - public void Return(Object obj, Exception exception, bool isRecreate = false) - { - if (exception != null && exception is OdbcException) - { - if (obj.Value.Ping() == false) - base.SetUnavailable(exception, obj.LastGetTimeCopy); - } - base.Return(obj, isRecreate); - } - } - - class OdbcKingbaseESConnectionPoolPolicy : IPolicy - { - - internal OdbcKingbaseESConnectionPool _pool; - public string Name { get; set; } = $"KingbaseES OdbcConnection {CoreStrings.S_ObjectPool}"; - public int PoolSize { get; set; } = 100; - public TimeSpan SyncGetTimeout { get; set; } = TimeSpan.FromSeconds(10); - public TimeSpan IdleTimeout { get; set; } = TimeSpan.FromSeconds(20); - public int AsyncGetCapacity { get; set; } = 10000; - public bool IsThrowGetTimeoutException { get; set; } = true; - public bool IsAutoDisposeWithSystem { get; set; } = true; - public int CheckAvailableInterval { get; set; } = 2; - public int Weight { get; set; } = 1; - - static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); - private string _connectionString; - public string ConnectionString - { - get => _connectionString; - set - { - _connectionString = value ?? ""; - - var minPoolSize = 0; - var pattern = @"Min\s*pool\s*size\s*=\s*(\d+)"; - var m = Regex.Match(_connectionString, pattern, RegexOptions.IgnoreCase); - if (m.Success) - { - minPoolSize = int.Parse(m.Groups[1].Value); - _connectionString = Regex.Replace(_connectionString, pattern, "", RegexOptions.IgnoreCase); - } - - pattern = @"Max\s*pool\s*size\s*=\s*(\d+)"; - m = Regex.Match(_connectionString, pattern, RegexOptions.IgnoreCase); - if (m.Success == false || int.TryParse(m.Groups[1].Value, out var poolsize) == false || poolsize <= 0) poolsize = Math.Max(100, minPoolSize); - var connStrIncr = dicConnStrIncr.AddOrUpdate(_connectionString, 1, (oldkey, oldval) => Math.Min(5, oldval + 1)); - PoolSize = poolsize + connStrIncr; - _connectionString = m.Success ? - Regex.Replace(_connectionString, pattern, $"Max pool size={PoolSize}", RegexOptions.IgnoreCase) : - $"{_connectionString};Max pool size={PoolSize}"; - - pattern = @"Connection\s*LifeTime\s*=\s*(\d+)"; - m = Regex.Match(_connectionString, pattern, RegexOptions.IgnoreCase); - if (m.Success) - { - IdleTimeout = TimeSpan.FromSeconds(int.Parse(m.Groups[1].Value)); - _connectionString = Regex.Replace(_connectionString, pattern, "", RegexOptions.IgnoreCase); - } - - FreeSql.Internal.CommonUtils.PrevReheatConnectionPool(_pool, minPoolSize); - } - } - - public bool OnCheckAvailable(Object obj) - { - if (obj.Value == null) return false; - if (obj.Value.State == ConnectionState.Closed) obj.Value.Open(); - return obj.Value.Ping(true); - } - - public DbConnection OnCreate() - { - var conn = new OdbcConnection(_connectionString); - return conn; - } - - public void OnDestroy(DbConnection obj) - { - if (obj.State != ConnectionState.Closed) obj.Close(); - obj.Dispose(); - } - - public void OnGet(Object obj) - { - - if (_pool.IsAvailable) - { - if (obj.Value == null) - { - _pool.SetUnavailable(new Exception(CoreStrings.S_ConnectionStringError), obj.LastGetTimeCopy); - throw new Exception(CoreStrings.S_ConnectionStringError_Check(this.Name)); - } - - if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && obj.Value.Ping() == false) - { - - try - { - obj.Value.Open(); - } - catch (Exception ex) - { - if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) - throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); - throw ex; - } - } - } - } - -#if net40 -#else - async public Task OnGetAsync(Object obj) - { - - if (_pool.IsAvailable) - { - if (obj.Value == null) - { - _pool.SetUnavailable(new Exception(CoreStrings.S_ConnectionStringError), obj.LastGetTimeCopy); - throw new Exception(CoreStrings.S_ConnectionStringError_Check(this.Name)); - } - - if (obj.Value.State != ConnectionState.Open || DateTime.Now.Subtract(obj.LastReturnTime).TotalSeconds > 60 && (await obj.Value.PingAsync()) == false) - { - - try - { - await obj.Value.OpenAsync(); - } - catch (Exception ex) - { - if (_pool.SetUnavailable(ex, obj.LastGetTimeCopy) == true) - throw new Exception($"【{this.Name}】Block access and wait for recovery: {ex.Message}"); - throw ex; - } - } - } - } -#endif - - public void OnGetTimeout() - { - - } - - public void OnReturn(Object obj) - { - //if (obj?.Value != null && obj.Value.State != ConnectionState.Closed) try { obj.Value.Close(); } catch { } - } - - public void OnAvailable() - { - _pool.availableHandler?.Invoke(); - } - - public void OnUnavailable() - { - _pool.unavailableHandler?.Invoke(); - } - } - - static class DbConnectionExtensions - { - - static DbCommand PingCommand(DbConnection conn) - { - var cmd = conn.CreateCommand(); - cmd.CommandTimeout = 5; - cmd.CommandText = "select 1 from dual"; - return cmd; - } - public static bool Ping(this DbConnection that, bool isThrow = false) - { - try - { - PingCommand(that).ExecuteNonQuery(); - return true; - } - catch - { - if (that.State != ConnectionState.Closed) try { that.Close(); } catch { } - if (isThrow) throw; - return false; - } - } - -#if net40 -#else - async public static Task PingAsync(this DbConnection that, bool isThrow = false) - { - try - { - await PingCommand(that).ExecuteNonQueryAsync(); - return true; - } - catch - { - if (that.State != ConnectionState.Closed) try { that.Close(); } catch { } - if (isThrow) throw; - return false; - } - } -#endif - } -} diff --git a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESCodeFirst.cs b/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESCodeFirst.cs deleted file mode 100644 index 1d261ffad..000000000 --- a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESCodeFirst.cs +++ /dev/null @@ -1,444 +0,0 @@ -using FreeSql.DataAnnotations; -using FreeSql.Internal; -using FreeSql.Internal.Model; -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Odbc; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Text.RegularExpressions; - -namespace FreeSql.Odbc.KingbaseES -{ - - class OdbcKingbaseESCodeFirst : Internal.CommonProvider.CodeFirstProvider - { - public override bool IsNoneCommandParameter { get => true; set => base.IsNoneCommandParameter = true; } - public OdbcKingbaseESCodeFirst(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression) : base(orm, commonUtils, commonExpression) { } - - static object _dicCsToDbLock = new object(); - static Dictionary> _dicCsToDb = new Dictionary>() { - { typeof(sbyte).FullName, CsToDb.New(OdbcType.TinyInt, "tinyint","tinyint NOT NULL", false, false, 0) },{ typeof(sbyte?).FullName, CsToDb.New(OdbcType.TinyInt, "tinyint", "tinyint", false, true, null) }, - { typeof(short).FullName, CsToDb.New(OdbcType.SmallInt, "int2","int2 NOT NULL", false, false, 0) },{ typeof(short?).FullName, CsToDb.New(OdbcType.SmallInt, "int2", "int2", false, true, null) }, - { typeof(int).FullName, CsToDb.New(OdbcType.Int, "int4","int4 NOT NULL", false, false, 0) },{ typeof(int?).FullName, CsToDb.New(OdbcType.Int, "int4", "int4", false, true, null) }, - { typeof(long).FullName, CsToDb.New(OdbcType.BigInt, "int8","int8 NOT NULL", false, false, 0) },{ typeof(long?).FullName, CsToDb.New(OdbcType.BigInt, "int8", "int8", false, true, null) }, - - { typeof(byte).FullName, CsToDb.New(OdbcType.SmallInt, "int2","int2 NOT NULL", false, false, 0) },{ typeof(byte?).FullName, CsToDb.New(OdbcType.SmallInt, "int2", "int2", false, true, null) }, - { typeof(ushort).FullName, CsToDb.New(OdbcType.Int, "int4","int4 NOT NULL", false, false, 0) },{ typeof(ushort?).FullName, CsToDb.New(OdbcType.Int, "int4", "int4", false, true, null) }, - { typeof(uint).FullName, CsToDb.New(OdbcType.BigInt, "int8","int8 NOT NULL", false, false, 0) },{ typeof(uint?).FullName, CsToDb.New(OdbcType.BigInt, "int8", "int8", false, true, null) }, - { typeof(ulong).FullName, CsToDb.New(OdbcType.Numeric, "numeric","numeric(20,0) NOT NULL", false, false, 0) },{ typeof(ulong?).FullName, CsToDb.New(OdbcType.Numeric, "numeric", "numeric(20,0)", false, true, null) }, - - { typeof(float).FullName, CsToDb.New(OdbcType.Real, "float4","float4 NOT NULL", false, false, 0) },{ typeof(float?).FullName, CsToDb.New(OdbcType.Real, "float4", "float4", false, true, null) }, - { typeof(double).FullName, CsToDb.New(OdbcType.Double, "float8","float8 NOT NULL", false, false, 0) },{ typeof(double?).FullName, CsToDb.New(OdbcType.Double, "float8", "float8", false, true, null) }, - { typeof(decimal).FullName, CsToDb.New(OdbcType.Numeric, "numeric", "numeric(10,2) NOT NULL", false, false, 0) },{ typeof(decimal?).FullName, CsToDb.New(OdbcType.Numeric, "numeric", "numeric(10,2)", false, true, null) }, - - { typeof(string).FullName, CsToDb.New(OdbcType.VarChar, "varchar", "varchar(255)", false, null, "") }, - { typeof(char).FullName, CsToDb.New(OdbcType.Char, "bpchar", "bpchar(1) NULL", false, null, '\0') }, - - { typeof(TimeSpan).FullName, CsToDb.New(OdbcType.Time, "time","time NOT NULL", false, false, 0) },{ typeof(TimeSpan?).FullName, CsToDb.New(OdbcType.Time, "time", "time",false, true, null) }, - { typeof(DateTime).FullName, CsToDb.New(OdbcType.DateTime, "timestamp", "timestamp NOT NULL", false, false, new DateTime(1970,1,1)) },{ typeof(DateTime?).FullName, CsToDb.New(OdbcType.DateTime, "timestamp", "timestamp", false, true, null) }, - - { typeof(bool).FullName, CsToDb.New(OdbcType.Bit, "bool","bool NOT NULL", null, false, false) },{ typeof(bool?).FullName, CsToDb.New(OdbcType.Bit, "bool","bool", null, true, null) }, - { typeof(Byte[]).FullName, CsToDb.New(OdbcType.VarBinary, "bytea", "bytea", false, null, new byte[0]) }, - - { typeof(Guid).FullName, CsToDb.New(OdbcType.UniqueIdentifier, "uuid", "uuid NOT NULL", false, false, Guid.Empty) },{ typeof(Guid?).FullName, CsToDb.New(OdbcType.UniqueIdentifier, "uuid", "uuid", false, true, null) }, - }; - - public override DbInfoResult GetDbInfo(Type type) - { - if (_dicCsToDb.TryGetValue(type.FullName, out var trydc)) return new DbInfoResult((int)trydc.type, trydc.dbtype, trydc.dbtypeFull, trydc.isnullable, trydc.defaultValue); - if (type.IsArray) return null; - var enumType = type.IsEnum ? type : null; - if (enumType == null && type.IsNullableType()) - { - var genericTypes = type.GetGenericArguments(); - if (genericTypes.Length == 1 && genericTypes.First().IsEnum) enumType = genericTypes.First(); - } - if (enumType != null) - { - var newItem = enumType.GetCustomAttributes(typeof(FlagsAttribute), false).Any() ? - CsToDb.New(OdbcType.BigInt, "int8", $"int8{(type.IsEnum ? " NOT NULL" : "")}", false, type.IsEnum ? false : true, enumType.CreateInstanceGetDefaultValue()) : - CsToDb.New(OdbcType.Int, "int4", $"int4{(type.IsEnum ? " NOT NULL" : "")}", false, type.IsEnum ? false : true, enumType.CreateInstanceGetDefaultValue()); - if (_dicCsToDb.ContainsKey(type.FullName) == false) - { - lock (_dicCsToDbLock) - { - if (_dicCsToDb.ContainsKey(type.FullName) == false) - _dicCsToDb.Add(type.FullName, newItem); - } - } - return new DbInfoResult((int)newItem.type, newItem.dbtype, newItem.dbtypeFull, newItem.isnullable, newItem.defaultValue); - } - return null; - } - - public bool? _isSysV8R3 = null; - object _isSysV8R3Lock = new object(); - public void InitIsSysV8R3() - { - if (_isSysV8R3 == null) - lock (_isSysV8R3Lock) - if (_isSysV8R3 == null) - { - try - { - _orm.Ado.ExecuteNonQuery(" select 1"); - } - catch - { - return; - } - try - { - _orm.Ado.ExecuteNonQuery(" select 1 from sys_tables limit 1"); - _isSysV8R3 = true; - } - catch //42P01: 关系 "sys_tables" 不存在 - { - _isSysV8R3 = false; - } - } - } - - protected override string GetComparisonDDLStatements(params TypeSchemaAndName[] objects) - { - InitIsSysV8R3(); - var pg_ = _isSysV8R3 == true ? "sys_" : "pg_"; - var public_ = _isSysV8R3 == true ? "PUBLIC" : "public"; - var sb = new StringBuilder(); - var seqcols = new List>(); //序列 - - foreach (var obj in objects) - { - if (sb.Length > 0) sb.Append("\r\n"); - var tb = obj.tableSchema; - if (tb == null) throw new Exception(CoreStrings.S_Type_IsNot_Migrable(obj.tableSchema.Type.FullName)); - if (tb.Columns.Any() == false) throw new Exception(CoreStrings.S_Type_IsNot_Migrable_0Attributes(obj.tableSchema.Type.FullName)); - var tbname = _commonUtils.SplitTableName(tb.DbName); - if (tbname?.Length == 1) tbname = new[] { public_, tbname[0] }; - - var tboldname = _commonUtils.SplitTableName(tb.DbOldName); //旧表名 - if (tboldname?.Length == 1) tboldname = new[] { public_, tboldname[0] }; - if (string.IsNullOrEmpty(obj.tableName) == false) - { - var tbtmpname = _commonUtils.SplitTableName(obj.tableName); - if (tbtmpname?.Length == 1) tbtmpname = new[] { public_, tbtmpname[0] }; - if (tbname[0] != tbtmpname[0] || tbname[1] != tbtmpname[1]) - { - tbname = tbtmpname; - tboldname = null; - } - } - //codefirst 不支持表名、模式名、数据库名中带 . - - if (string.Compare(tbname[0], public_, true) != 0 && _orm.Ado.ExecuteScalar(CommandType.Text, _commonUtils.FormatSql($" select 1 from {pg_}namespace where nspname={{0}}", tbname[0])) == null) //创建模式 - sb.Append("CREATE SCHEMA IF NOT EXISTS ").Append(tbname[0]).Append(";\r\n"); - - var sbalter = new StringBuilder(); - var istmpatler = false; //创建临时表,导入数据,删除旧表,修改 - if (_orm.Ado.ExecuteScalar(CommandType.Text, string.Format($" select 1 from {pg_}tables a inner join {pg_}namespace b on b.nspname = a.schemaname where b.nspname || '.' || a.tablename = '{{0}}.{{1}}'", tbname)) == null) - { //表不存在 - if (tboldname != null) - { - if (_orm.Ado.ExecuteScalar(CommandType.Text, string.Format($" select 1 from {pg_}tables a inner join {pg_}namespace b on b.nspname = a.schemaname where b.nspname || '.' || a.tablename = '{{0}}.{{1}}'", tboldname)) == null) - //旧表不存在 - tboldname = null; - } - if (tboldname == null) - { - //创建表 - var createTableName = _commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}"); - sb.Append("CREATE TABLE IF NOT EXISTS ").Append(createTableName).Append(" ( "); - foreach (var tbcol in tb.ColumnsByPosition) - { - sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ").Append(tbcol.Attribute.DbType).Append(","); - if (tbcol.Attribute.IsIdentity == true) seqcols.Add(NativeTuple.Create(tbcol, tbname, true)); - } - if (tb.Primarys.Any()) - { - var pkname = $"{tbname[0]}_{tbname[1]}_PKEY"; - 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("),"); - } - sb.Remove(sb.Length - 1, 1); - sb.Append("\r\n) WITH (OIDS=FALSE);\r\n"); - //创建表的索引 - foreach (var uk in tb.Indexes) - { - sb.Append("CREATE "); - if (uk.IsUnique) sb.Append("UNIQUE "); - sb.Append("INDEX ").Append(_commonUtils.QuoteSqlName(ReplaceIndexName(uk.Name, tbname[1]))).Append(" ON ").Append(createTableName).Append("("); - foreach (var tbcol in uk.Columns) - { - sb.Append(_commonUtils.QuoteSqlName(tbcol.Column.Attribute.Name)); - if (tbcol.IsDesc) sb.Append(" DESC"); - sb.Append(", "); - } - sb.Remove(sb.Length - 2, 2).Append(");\r\n"); - } - //备注 - foreach (var tbcol in tb.ColumnsByPosition) - { - if (string.IsNullOrEmpty(tbcol.Comment) == false) - sb.Append("COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment)).Append(";\r\n"); - } - if (string.IsNullOrEmpty(tb.Comment) == false) - sb.Append("COMMENT ON TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tb.Comment)).Append(";\r\n"); - continue; - } - //如果新表,旧表在一个数据库和模式下,直接修改表名 - if (string.Compare(tbname[0], tboldname[0], true) == 0) - sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tboldname[0]}.{tboldname[1]}")).Append(" RENAME TO ").Append(_commonUtils.QuoteSqlName($"{tbname[1]}")).Append(";\r\n"); - else - { - //如果新表,旧表不在一起,创建新表,导入数据,删除旧表 - istmpatler = true; - } - } - else - tboldname = null; //如果新表已经存在,不走改表名逻辑 - - //对比字段,只可以修改类型、增加字段、有限的修改字段名;保证安全不删除字段 - var sql = _commonUtils.FormatSql($@" -select -a.attname, -t.typname, -case when a.atttypmod > 0 and a.atttypmod < 32767 then a.atttypmod - 4 else a.attlen end len, -case when t.typelem > 0 and t.typinput::varchar = 'ARRAY_IN' then t2.typname else t.typname end, -case when a.attnotnull then '0' else '1' end as is_nullable, ---e.adsrc, -(select {pg_}get_expr(adbin, adrelid) from {pg_}attrdef where adrelid = e.adrelid limit 1) is_identity, -a.attndims, -d.description as comment -from {pg_}class c -inner join {pg_}attribute a on a.attnum > 0 and a.attrelid = c.oid -inner join {pg_}type t on t.oid = a.atttypid -left join {pg_}type t2 on t2.oid = t.typelem -left join {pg_}description d on d.objoid = a.attrelid and d.objsubid = a.attnum -left join {pg_}attrdef e on e.adrelid = a.attrelid and e.adnum = a.attnum -inner join {pg_}namespace ns on ns.oid = c.relnamespace -inner join {pg_}namespace ns2 on ns2.oid = t.typnamespace -where ns.nspname = {{0}} and c.relname = {{1}}", tboldname ?? tbname); - var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); - var tbstruct = ds.ToDictionary(a => string.Concat(a[0]), a => - { - var attndims = int.Parse(string.Concat(a[6])); - var type = string.Concat(a[1]); - var sqlType = string.Concat(a[3]); - var max_length = long.Parse(string.Concat(a[2])); - switch (sqlType.ToLower()) - { - case "bool": case "name": case "bit": case "varbit": case "bpchar": case "varchar": case "bytea": case "text": case "uuid": break; - default: max_length *= 8; break; - } - if (type.StartsWith("_")) - { - type = type.Substring(1); - if (attndims == 0) attndims++; - } - if (sqlType.StartsWith("_")) sqlType = sqlType.Substring(1); - return new - { - column = string.Concat(a[0]), - sqlType = string.Concat(sqlType), - max_length = long.Parse(string.Concat(a[2])), - is_nullable = string.Concat(a[4]) == "1", - is_identity = string.Concat(a[5]).StartsWith(@"NEXTVAL('") && (string.Concat(a[5]).EndsWith(@"'::REGCLASS)") || string.Concat(a[5]).EndsWith(@"')")), - attndims, - comment = string.Concat(a[7]) - }; - }, StringComparer.CurrentCultureIgnoreCase); - - if (istmpatler == false) - { - foreach (var tbcol in tb.ColumnsByPosition) - { - if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) || - string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol)) - { - var isCommentChanged = tbstructcol.comment != (tbcol.Comment ?? ""); - var sqlTypeSize = tbstructcol.sqlType; - if (sqlTypeSize.Contains("(") == false) - { - switch (sqlTypeSize.ToLower()) - { - case "bit": - case "varbit": - case "bpchar": - case "varchar": - sqlTypeSize = $"{sqlTypeSize}({tbstructcol.max_length})"; break; - } - } - if (tbcol.Attribute.DbType.StartsWith(sqlTypeSize, StringComparison.CurrentCultureIgnoreCase) == false || - tbcol.Attribute.DbType.Contains("[]") != (tbstructcol.attndims > 0)) - sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ALTER COLUMN ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" TYPE ").Append(tbcol.Attribute.DbType.Split(' ').First()).Append(";\r\n"); - if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable) - { - if (tbcol.Attribute.IsNullable != true || tbcol.Attribute.IsNullable == true && tbcol.Attribute.IsPrimary == false) - { - if (tbcol.Attribute.IsNullable == false) - sbalter.Append("UPDATE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" SET ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" = ").Append(tbcol.DbDefaultValue).Append(" WHERE ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" IS NULL;\r\n"); - sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ALTER COLUMN ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" ").Append(tbcol.Attribute.IsNullable == true ? "DROP" : "SET").Append(" NOT NULL;\r\n"); - } - } - if (tbcol.Attribute.IsIdentity != tbstructcol.is_identity) - seqcols.Add(NativeTuple.Create(tbcol, tbname, tbcol.Attribute.IsIdentity == true)); - if (string.Compare(tbstructcol.column, tbcol.Attribute.OldName, true) == 0) - //修改列名 - sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" RENAME COLUMN ").Append(_commonUtils.QuoteSqlName(tbstructcol.column)).Append(" TO ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(";\r\n"); - if (isCommentChanged) - sbalter.Append("COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment)).Append(";\r\n"); - continue; - } - //添加列 - sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ADD COLUMN ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ").Append(tbcol.Attribute.DbType.Split(' ').First()).Append(";\r\n"); - sbalter.Append("UPDATE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" SET ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" = ").Append(tbcol.DbDefaultValue).Append(";\r\n"); - if (tbcol.Attribute.IsNullable == false) sbalter.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" ALTER COLUMN ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" SET NOT NULL;\r\n"); - if (tbcol.Attribute.IsIdentity == true) seqcols.Add(NativeTuple.Create(tbcol, tbname, tbcol.Attribute.IsIdentity == true)); - if (string.IsNullOrEmpty(tbcol.Comment) == false) sbalter.Append("COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment)).Append(";\r\n"); - } - var dsuksql = _commonUtils.FormatSql($@" -select -c.attname, -b.relname, -case when {pg_}index_column_has_property(b.oid, c.attnum, 'desc') = 't' then 1 else 0 end IsDesc, -case when indisunique = 't' then 1 else 0 end IsUnique -from {pg_}index a -inner join {pg_}class b on b.oid = a.indexrelid -inner join {pg_}attribute c on c.attnum > 0 and c.attrelid = b.oid -inner join {pg_}namespace ns on ns.oid = b.relnamespace -inner join {pg_}class d on d.oid = a.indrelid -where ns.nspname in ({{0}}) and d.relname in ({{1}}) and a.indisprimary = 'f'", tboldname ?? tbname); - var dsuk = _orm.Ado.ExecuteArray(CommandType.Text, dsuksql).Select(a => new[] { string.Concat(a[0]), string.Concat(a[1]), string.Concat(a[2]), string.Concat(a[3]) }); - foreach (var uk in tb.Indexes) - { - if (string.IsNullOrEmpty(uk.Name) || uk.Columns.Any() == false) continue; - var ukname = ReplaceIndexName(uk.Name, tbname[1]); - var dsukfind1 = dsuk.Where(a => string.Compare(a[1], ukname, true) == 0).ToArray(); - if (dsukfind1.Any() == false || dsukfind1.Length != uk.Columns.Length || dsukfind1.Where(a => uk.Columns.Where(b => (a[3] == "1") == uk.IsUnique && string.Compare(b.Column.Attribute.Name, a[0], true) == 0 && (a[2] == "1") == b.IsDesc).Any()).Count() != uk.Columns.Length) - { - if (dsukfind1.Any()) sbalter.Append("DROP INDEX ").Append(_commonUtils.QuoteSqlName(ukname)).Append(";\r\n"); - sbalter.Append("CREATE "); - if (uk.IsUnique) sbalter.Append("UNIQUE "); - sbalter.Append("INDEX ").Append(_commonUtils.QuoteSqlName(ukname)).Append(" ON ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append("("); - foreach (var tbcol in uk.Columns) - { - sbalter.Append(_commonUtils.QuoteSqlName(tbcol.Column.Attribute.Name)); - if (tbcol.IsDesc) sbalter.Append(" DESC"); - sbalter.Append(", "); - } - sbalter.Remove(sbalter.Length - 2, 2).Append(");\r\n"); - } - } - } - if (istmpatler == false) - { - var dbcomment = string.Concat(_orm.Ado.ExecuteScalar(CommandType.Text, _commonUtils.FormatSql($@" select -d.description -from {pg_}class a -inner join {pg_}namespace b on b.oid = a.relnamespace -left join {pg_}description d on d.objoid = a.oid and objsubid = 0 -where upper(b.nspname) not in ('SYS_CATALOG', 'INFORMATION_SCHEMA', 'TOPOLOGY', 'SYSAUDIT', 'SYSLOGICAL', 'SYS_TEMP_1', 'SYS_TOAST', 'SYS_TOAST_TEMP_1', 'XLOG_RECORD_READ') and a.relkind in ('r') and b.nspname = {{0}} and a.relname = {{1}} -and upper(b.nspname || '.' || a.relname) not in ('PUBLIC.GEOGRAPHY_COLUMNS','PUBLIC.GEOMETRY_COLUMNS','PUBLIC.RASTER_COLUMNS','PUBLIC.RASTER_OVERVIEWS')", tbname[0], tbname[1]))); - if (dbcomment != (tb.Comment ?? "")) - sbalter.Append("COMMENT ON TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tb.Comment)).Append(";\r\n"); - - sb.Append(sbalter); - continue; - } - var oldpk = _orm.Ado.ExecuteScalar(CommandType.Text, _commonUtils.FormatSql($@" select {pg_}constraint.conname as pk_name from {pg_}constraint -inner join {pg_}class on {pg_}constraint.conrelid = {pg_}class.oid -inner join {pg_}namespace on {pg_}namespace.oid = {pg_}class.relnamespace -where {pg_}namespace.nspname={{0}} and {pg_}class.relname={{1}} and {pg_}constraint.contype='p' -", tbname))?.ToString(); - if (string.IsNullOrEmpty(oldpk) == false) - sb.Append("ALTER TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}")).Append(" DROP CONSTRAINT ").Append(oldpk).Append(";\r\n"); - - //创建临时表,数据导进临时表,然后删除原表,将临时表改名为原表名 - var tablename = tboldname == null ? _commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}") : _commonUtils.QuoteSqlName($"{tboldname[0]}.{tboldname[1]}"); - var tmptablename = _commonUtils.QuoteSqlName($"{tbname[0]}.FTmp_{tbname[1]}"); - //创建临时表 - sb.Append("CREATE TABLE IF NOT EXISTS ").Append(tmptablename).Append(" ( "); - foreach (var tbcol in tb.ColumnsByPosition) - { - sb.Append(" \r\n ").Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(" ").Append(tbcol.Attribute.DbType).Append(","); - if (tbcol.Attribute.IsIdentity == true) seqcols.Add(NativeTuple.Create(tbcol, tbname, true)); - } - if (tb.Primarys.Any()) - { - var pkname = $"{tbname[0]}_{tbname[1]}_pkey"; - 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("),"); - } - sb.Remove(sb.Length - 1, 1); - sb.Append("\r\n) WITH (OIDS=FALSE);\r\n"); - //备注 - foreach (var tbcol in tb.ColumnsByPosition) - { - if (string.IsNullOrEmpty(tbcol.Comment) == false) - sb.Append("COMMENT ON COLUMN ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.FTmp_{tbname[1]}.{tbcol.Attribute.Name}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tbcol.Comment)).Append(";\r\n"); - } - if (string.IsNullOrEmpty(tb.Comment) == false) - sb.Append("COMMENT ON TABLE ").Append(_commonUtils.QuoteSqlName($"{tbname[0]}.FTmp_{tbname[1]}")).Append(" IS ").Append(_commonUtils.FormatSql("{0}", tb.Comment)).Append(";\r\n"); - - sb.Append("INSERT INTO ").Append(tmptablename).Append(" ("); - foreach (var tbcol in tb.ColumnsByPosition) - sb.Append(_commonUtils.QuoteSqlName(tbcol.Attribute.Name)).Append(", "); - sb.Remove(sb.Length - 2, 2).Append(")\r\nSELECT "); - foreach (var tbcol in tb.ColumnsByPosition) - { - var insertvalue = "NULL"; - if (tbstruct.TryGetValue(tbcol.Attribute.Name, out var tbstructcol) || - string.IsNullOrEmpty(tbcol.Attribute.OldName) == false && tbstruct.TryGetValue(tbcol.Attribute.OldName, out tbstructcol)) - { - insertvalue = _commonUtils.QuoteSqlName(tbstructcol.column); - if (tbcol.Attribute.DbType.StartsWith(tbstructcol.sqlType, StringComparison.CurrentCultureIgnoreCase) == false) - insertvalue = $"cast({insertvalue} as {tbcol.Attribute.DbType.Split(' ').First()})"; - if (tbcol.Attribute.IsNullable != tbstructcol.is_nullable) - insertvalue = $"coalesce({insertvalue},{tbcol.DbDefaultValue})"; - } - else if (tbcol.Attribute.IsNullable == false) - insertvalue = tbcol.DbDefaultValue; - sb.Append(insertvalue).Append(", "); - } - sb.Remove(sb.Length - 2, 2).Append(" FROM ").Append(tablename).Append(";\r\n"); - sb.Append("DROP TABLE ").Append(tablename).Append(";\r\n"); - sb.Append("ALTER TABLE ").Append(tmptablename).Append(" RENAME TO ").Append(_commonUtils.QuoteSqlName(tbname[1])).Append(";\r\n"); - //创建表的索引 - foreach (var uk in tb.Indexes) - { - sb.Append("CREATE "); - if (uk.IsUnique) sb.Append("UNIQUE "); - sb.Append("INDEX ").Append(_commonUtils.QuoteSqlName(ReplaceIndexName(uk.Name, tbname[1]))).Append(" ON ").Append(tablename).Append("("); - foreach (var tbcol in uk.Columns) - { - sb.Append(_commonUtils.QuoteSqlName(tbcol.Column.Attribute.Name)); - if (tbcol.IsDesc) sb.Append(" DESC"); - sb.Append(", "); - } - sb.Remove(sb.Length - 2, 2).Append(");\r\n"); - } - } - foreach (var seqcol in seqcols) - { - var tbname = seqcol.Item2; - var seqname = Utils.GetCsName($"{tbname[0]}.{tbname[1]}_{seqcol.Item1.Attribute.Name}_seq").ToUpper(); ; - var tbname2 = _commonUtils.QuoteSqlName($"{tbname[0]}.{tbname[1]}"); - var colname2 = _commonUtils.QuoteSqlName(seqcol.Item1.Attribute.Name); - sb.Append("ALTER TABLE ").Append(tbname2).Append(" ALTER COLUMN ").Append(colname2).Append(" SET DEFAULT null;\r\n"); - sb.Append("DROP SEQUENCE IF EXISTS ").Append(seqname).Append(";\r\n"); - if (seqcol.Item3) - { - sb.Append("CREATE SEQUENCE ").Append(seqname).Append(";\r\n"); - sb.Append("ALTER TABLE ").Append(tbname2).Append(" ALTER COLUMN ").Append(colname2).Append(" SET DEFAULT NEXTVAL('").Append(seqname).Append("'::REGCLASS);\r\n"); - sb.Append(" SELECT case when max(").Append(colname2).Append(") is null then 0 else setval('").Append(seqname).Append("', max(").Append(colname2).Append(")) end FROM ").Append(tbname2).Append(";\r\n"); - } - } - return sb.Length == 0 ? null : sb.ToString(); - } - } -} \ No newline at end of file diff --git a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESDbFirst.cs b/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESDbFirst.cs deleted file mode 100644 index 1f20cc6aa..000000000 --- a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESDbFirst.cs +++ /dev/null @@ -1,535 +0,0 @@ -using FreeSql.DatabaseModel; -using FreeSql.Internal; -using FreeSql.Internal.Model; -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Data.Odbc; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; - -namespace FreeSql.Odbc.KingbaseES -{ - class OdbcKingbaseESDbFirst : IDbFirst - { - IFreeSql _orm; - protected CommonUtils _commonUtils; - protected CommonExpression _commonExpression; - public OdbcKingbaseESDbFirst(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression) - { - _orm = orm; - _commonUtils = commonUtils; - _commonExpression = commonExpression; - } - - public int GetDbType(DbColumnInfo column) => (int)GetSqlDbType(column); - OdbcType GetSqlDbType(DbColumnInfo column) - { - var dbtype = column.DbTypeText; - var isarray = dbtype?.EndsWith("[]") == true; - if (isarray) dbtype = dbtype.Remove(dbtype.Length - 2); - var ret = OdbcType.VarChar; - switch (dbtype?.ToLower().TrimStart('_')) - { - case "tinyint": ret = OdbcType.TinyInt; break; - case "int2": ret = OdbcType.SmallInt; break; - case "int4": ret = OdbcType.Int; break; - case "int8": ret = OdbcType.BigInt; break; - case "numeric": ret = OdbcType.Numeric; break; - case "float4": ret = OdbcType.Real; break; - case "float8": ret = OdbcType.Double; break; - case "money": ret = OdbcType.Numeric; break; - - case "char": ret = column.MaxLength == 36 ? OdbcType.UniqueIdentifier : OdbcType.Char; break; - case "bpchar": ret = OdbcType.Char; break; - case "varchar": ret = OdbcType.VarChar; break; - case "text": ret = OdbcType.Text; break; - - case "timestamp": ret = OdbcType.Timestamp; break; - case "timestamptz": ret = OdbcType.Timestamp; break; - case "date": ret = OdbcType.Date; break; - case "time": ret = OdbcType.Time; break; - case "timetz": ret = OdbcType.Time; break; - case "interval": ret = OdbcType.Time; break; - - case "bool": ret = OdbcType.Bit; break; - case "blob": ret = OdbcType.VarBinary; break; - case "bytea": ret = OdbcType.VarBinary; break; - case "bit": ret = OdbcType.Bit; break; - case "varbit": ret = OdbcType.VarBinary; break; - - case "uuid": ret = OdbcType.UniqueIdentifier; break; - } - return ret; - } - - static ConcurrentDictionary _dicDbToCs = new ConcurrentDictionary(); - static OdbcKingbaseESDbFirst() - { - var defaultDbToCs = new Dictionary() { - { (int)OdbcType.TinyInt, new DbToCs("(sbyte?)", "sbyte.Parse({0})", "{0}.ToString()", "sbyte?", typeof(short), typeof(short?), "{0}.Value", "GetInt16") }, - { (int)OdbcType.SmallInt, new DbToCs("(short?)", "short.Parse({0})", "{0}.ToString()", "short?", typeof(int), typeof(int?), "{0}.Value", "GetInt16") }, - { (int)OdbcType.Int, new DbToCs("(int?)", "int.Parse({0})", "{0}.ToString()", "int?", typeof(long), typeof(long?), "{0}.Value", "GetInt32") }, - { (int)OdbcType.BigInt, new DbToCs("(long?)", "long.Parse({0})", "{0}.ToString()", "long?", typeof(long), typeof(long?), "{0}.Value", "GetInt64") }, - { (int)OdbcType.Real, new DbToCs("(float?)", "float.Parse({0})", "{0}.ToString()", "float?", typeof(float), typeof(float?), "{0}.Value", "GetFloat") }, - { (int)OdbcType.Double, new DbToCs("(double?)", "double.Parse({0})", "{0}.ToString()", "double?", typeof(double), typeof(double?), "{0}.Value", "GetDouble") }, - { (int)OdbcType.Numeric, new DbToCs("(decimal?)", "decimal.Parse({0})", "{0}.ToString()", "decimal?", typeof(decimal), typeof(decimal?), "{0}.Value", "GetDecimal") }, - - { (int)OdbcType.Char, new DbToCs("", "{0}.Replace(StringifySplit, \"|\")", "{0}.Replace(\"|\", StringifySplit)", "string", typeof(string), typeof(string), "{0}", "GetString") }, - { (int)OdbcType.VarChar, new DbToCs("", "{0}.Replace(StringifySplit, \"|\")", "{0}.Replace(\"|\", StringifySplit)", "string", typeof(string), typeof(string), "{0}", "GetString") }, - { (int)OdbcType.Text, new DbToCs("", "{0}.Replace(StringifySplit, \"|\")", "{0}.Replace(\"|\", StringifySplit)", "string", typeof(string), typeof(string), "{0}", "GetString") }, - - { (int)OdbcType.DateTime, new DbToCs("(DateTime?)", "new DateTime(long.Parse({0}))", "{0}.Ticks.ToString()", "DateTime?", typeof(DateTime), typeof(DateTime?), "{0}.Value", "GetDateTime") }, - { (int)OdbcType.Date, new DbToCs("(DateTime?)", "new DateTime(long.Parse({0}))", "{0}.Ticks.ToString()", "DateTime?", typeof(DateTime), typeof(DateTime?), "{0}.Value", "GetDateTime") }, - { (int)OdbcType.Time, new DbToCs("(TimeSpan?)", "TimeSpan.Parse(double.Parse({0}))", "{0}.Ticks.ToString()", "TimeSpan?", typeof(TimeSpan), typeof(TimeSpan?), "{0}.Value", "GetValue") }, - - { (int)OdbcType.Bit, new DbToCs("(bool?)", "{0} == \"1\"", "{0} == true ? \"1\" : \"0\"", "bool?", typeof(bool), typeof(bool?), "{0}.Value", "GetBoolean") }, - { (int)OdbcType.VarBinary, new DbToCs("(byte[])", "Convert.FromBase64String({0})", "Convert.ToBase64String({0})", "byte[]", typeof(byte[]), typeof(byte[]), "{0}", "GetValue") }, - - { (int)OdbcType.UniqueIdentifier, new DbToCs("(Guid?)", "Guid.Parse({0})", "{0}.ToString()", "Guid", typeof(Guid), typeof(Guid?), "{0}", "GetString") }, - }; - foreach (var kv in defaultDbToCs) - _dicDbToCs.TryAdd(kv.Key, kv.Value); - } - - public string GetCsConvert(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbType, out var trydc) ? (column.IsNullable ? trydc.csConvert : trydc.csConvert.Replace("?", "")) : null; - public string GetCsParse(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbType, out var trydc) ? trydc.csParse : null; - public string GetCsStringify(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbType, out var trydc) ? trydc.csStringify : null; - public string GetCsType(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbType, out var trydc) ? (column.IsNullable ? trydc.csType : trydc.csType.Replace("?", "")) : null; - public Type GetCsTypeInfo(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbType, out var trydc) ? trydc.csTypeInfo : null; - public string GetCsTypeValue(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbType, out var trydc) ? trydc.csTypeValue : null; - public string GetDataReaderMethod(DbColumnInfo column) => _dicDbToCs.TryGetValue(column.DbType, out var trydc) ? trydc.dataReaderMethod : null; - - string getpg_() - { - var codefirstProvider = _orm.CodeFirst as OdbcKingbaseESCodeFirst; - codefirstProvider.InitIsSysV8R3(); - return codefirstProvider._isSysV8R3 == true ? "sys_" : "pg_"; - } - - public List GetDatabases() - { - var pg_ = getpg_(); - var sql = $@" select datname from {pg_}database where datname not in ('TEMPLATE1', 'TEMPLATE0', 'TEMPLATE2')"; - var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); - return ds.Select(a => a.FirstOrDefault()?.ToString()).ToList(); - } - - public bool ExistsTable(string name, bool ignoreCase) - { - if (string.IsNullOrEmpty(name)) return false; - var pg_ = getpg_(); - var tbname = _commonUtils.SplitTableName(name); - if (tbname?.Length == 1) tbname = new[] { "public", tbname[0] }; - if (ignoreCase) tbname = tbname.Select(a => a.ToLower()).ToArray(); - var sql = $" select 1 from {pg_}tables a inner join {pg_}namespace b on b.nspname = a.schemaname where {(ignoreCase ? "lower(b.nspname)" : "b.nspname")}={_commonUtils.FormatSql("{0}", tbname[0])} and {(ignoreCase ? "lower(a.tablename)" : "a.tablename")}={_commonUtils.FormatSql("{0}", tbname[1])}"; - return string.Concat(_orm.Ado.ExecuteScalar(CommandType.Text, sql)) == "1"; - } - - public DbTableInfo GetTableByName(string name, bool ignoreCase = true) => GetTables(null, name, ignoreCase)?.FirstOrDefault(); - public List GetTablesByDatabase(params string[] database) => GetTables(database, null, false); - - public List GetTables(string[] database, string tablename, bool ignoreCase) - { - var pg_ = getpg_(); - var olddatabase = ""; - using (var conn = _orm.Ado.MasterPool.Get(TimeSpan.FromSeconds(5))) - { - olddatabase = conn.Value.Database; - } - string[] tbname = null; - string[] dbs = database == null || database.Any() == false ? new[] { olddatabase } : database; - if (string.IsNullOrEmpty(tablename) == false) - { - tbname = _commonUtils.SplitTableName(tablename); - if (tbname?.Length == 1) tbname = new[] { "public", tbname[0] }; - if (ignoreCase) tbname = tbname.Select(a => a.ToLower()).ToArray(); - dbs = new[] { olddatabase }; - } - - var tables = new List(); - foreach (var db in dbs) - { - if (string.IsNullOrEmpty(db) || string.Compare(db, olddatabase, true) != 0) continue; - - var loc1 = new List(); - var loc2 = new Dictionary(); - var loc3 = new Dictionary>(); - - var sql = $@" -{(tbname == null ? "" : $"select * from (")}select -b.nspname || '.' || a.tablename, -a.schemaname, -a.tablename , -d.description, -'TABLE' -from {pg_}tables a -inner join {pg_}namespace b on b.nspname = a.schemaname -inner join {pg_}class c on c.relnamespace = b.oid and c.relname = a.tablename -left join {pg_}description d on d.objoid = c.oid and objsubid = 0 -where upper(a.schemaname) not in ('SYS_CATALOG', 'INFORMATION_SCHEMA', 'TOPOLOGY', 'SYSAUDIT', 'SYSLOGICAL', 'SYS_TEMP_1', 'SYS_TOAST', 'SYS_TOAST_TEMP_1', 'XLOG_RECORD_READ') -and upper(b.nspname || '.' || a.tablename) not in ('PUBLIC.SPATIAL_REF_SYS') - -union all - -select -b.nspname || '.' || a.relname, -b.nspname, -a.relname, -d.description, -'VIEW' -from {pg_}class a -inner join {pg_}namespace b on b.oid = a.relnamespace -left join {pg_}description d on d.objoid = a.oid and objsubid = 0 -where upper(b.nspname) not in ('SYS_CATALOG', 'INFORMATION_SCHEMA', 'TOPOLOGY', 'SYSAUDIT', 'SYSLOGICAL', 'SYS_TEMP_1', 'SYS_TOAST', 'SYS_TOAST_TEMP_1', 'XLOG_RECORD_READ') and a.relkind in ('m','v') -and upper(b.nspname || '.' || a.relname) not in ('PUBLIC.GEOGRAPHY_COLUMNS','PUBLIC.GEOMETRY_COLUMNS','PUBLIC.RASTER_COLUMNS','PUBLIC.RASTER_OVERVIEWS') -{(tbname == null ? "" : $") ft_dbf where {(ignoreCase ? "lower(schemaname)" : "schemaname")}={_commonUtils.FormatSql("{0}", tbname[0])} and {(ignoreCase ? "lower(tablename)" : "tablename")}={_commonUtils.FormatSql("{0}", tbname[1])}")}"; - var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); - if (ds == null) return loc1; - - var loc6 = new List(); - var loc66 = new List(); - var loc6_1000 = new List(); - var loc66_1000 = new List(); - foreach (object[] row in ds) - { - var object_id = string.Concat(row[0]); - var owner = string.Concat(row[1]); - var table = string.Concat(row[2]); - var comment = string.Concat(row[3]); - Enum.TryParse(string.Concat(row[4]), out var type); - loc2.Add(object_id, new DbTableInfo { Id = object_id.ToString(), Schema = owner, Name = table, Comment = comment, Type = type }); - loc3.Add(object_id, new Dictionary()); - switch (type) - { - case DbTableType.VIEW: - case DbTableType.TABLE: - loc6_1000.Add(object_id); - if (loc6_1000.Count >= 500) - { - loc6.Add(loc6_1000.ToArray()); - loc6_1000.Clear(); - } - break; - case DbTableType.StoreProcedure: - loc66_1000.Add(object_id); - if (loc66_1000.Count >= 500) - { - loc66.Add(loc66_1000.ToArray()); - loc66_1000.Clear(); - } - break; - } - } - if (loc6_1000.Count > 0) loc6.Add(loc6_1000.ToArray()); - if (loc66_1000.Count > 0) loc66.Add(loc66_1000.ToArray()); - - if (loc6.Count == 0) return loc1; - var loc8 = new StringBuilder().Append("("); - for (var loc8idx = 0; loc8idx < loc6.Count; loc8idx++) - { - if (loc8idx > 0) loc8.Append(" OR "); - loc8.Append("a.table_name in ("); - for (var loc8idx2 = 0; loc8idx2 < loc6[loc8idx].Length; loc8idx2++) - { - if (loc8idx2 > 0) loc8.Append(","); - loc8.Append($"'{loc6[loc8idx][loc8idx2]}'"); - } - loc8.Append(")"); - } - loc8.Append(")"); - - sql = $@" -select -ns.nspname || '.' || c.relname as id, -a.attname, -t.typname, -case when a.atttypmod > 0 and a.atttypmod < 32767 then a.atttypmod - 4 else a.attlen end len, -case when t.typelem = 0 then t.typname else t2.typname end, -case when a.attnotnull then 0 else 1 end as is_nullable, ---e.adsrc as is_identity, pg12以下 -(select {pg_}get_expr(adbin, adrelid) from {pg_}attrdef where adrelid = e.adrelid and adnum = e.adnum limit 1) is_identity, -d.description as comment, -a.attndims, -case when t.typelem = 0 then t.typtype else t2.typtype end, -ns2.nspname, -a.attnum -from {pg_}class c -inner join {pg_}attribute a on a.attnum > 0 and a.attrelid = c.oid -inner join {pg_}type t on t.oid = a.atttypid -left join {pg_}type t2 on t2.oid = t.typelem -left join {pg_}description d on d.objoid = a.attrelid and d.objsubid = a.attnum -left join {pg_}attrdef e on e.adrelid = a.attrelid and e.adnum = a.attnum -inner join {pg_}namespace ns on ns.oid = c.relnamespace -inner join {pg_}namespace ns2 on ns2.oid = t.typnamespace -where {loc8.ToString().Replace("a.table_name", "ns.nspname || '.' || c.relname")}"; - ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); - if (ds == null) return loc1; - - foreach (object[] row in ds) - { - var object_id = string.Concat(row[0]); - var column = string.Concat(row[1]); - var type = string.Concat(row[2]); - var max_length = int.Parse(string.Concat(row[3])); - var sqlType = string.Concat(row[4]); - var is_nullable = string.Concat(row[5]) == "1"; - var is_identity = string.Concat(row[6]).StartsWith(@"NEXTVAL('") && (string.Concat(row[6]).EndsWith(@"'::REGCLASS)") || string.Concat(row[6]).EndsWith(@"')")); - var comment = string.Concat(row[7]); - var defaultValue = string.Concat(row[6]); - int attndims = int.Parse(string.Concat(row[8])); - string typtype = string.Concat(row[9]); - string owner = string.Concat(row[10]); - int attnum = int.Parse(string.Concat(row[11])); - switch (sqlType.ToLower()) - { - case "bool": case "name": case "bit": case "varbit": case "bpchar": case "varchar": case "bytea": case "text": case "uuid": break; - default: max_length *= 8; break; - } - if (max_length <= 0) max_length = -1; - if (type.StartsWith("_")) - { - type = type.Substring(1); - if (attndims == 0) attndims++; - } - if (sqlType.StartsWith("_")) sqlType = sqlType.Substring(1); - if (max_length > 0) - { - switch (sqlType.ToLower()) - { - //case "numeric": sqlType += $"({max_length})"; break; - case "bpchar": case "varchar": case "bytea": case "bit": case "varbit": sqlType += $"({max_length})"; break; - } - } - if (attndims > 0) type += "[]"; - - loc3[object_id].Add(column, new DbColumnInfo - { - Name = column, - MaxLength = max_length, - IsIdentity = is_identity, - IsNullable = is_nullable, - IsPrimary = false, - DbTypeText = type, - DbTypeTextFull = sqlType, - Table = loc2[object_id], - Comment = comment, - DefaultValue = defaultValue, - Position = attnum - }); - loc3[object_id][column].DbType = this.GetDbType(loc3[object_id][column]); - loc3[object_id][column].CsType = this.GetCsTypeInfo(loc3[object_id][column]); - } - - sql = $@" -select -ns.nspname || '.' || d.relname as table_id, -c.attname, -b.relname as index_id, -case when a.indisunique then 1 else 0 end IsUnique, -case when a.indisprimary then 1 else 0 end IsPrimary, -case when a.indisclustered then 0 else 1 end IsClustered, -case when {pg_}index_column_has_property(b.oid, c.attnum, 'desc') = 't' then 1 else 0 end IsDesc, -a.indkey::text, -c.attnum -from {pg_}index a -inner join {pg_}class b on b.oid = a.indexrelid -inner join {pg_}attribute c on c.attnum > 0 and c.attrelid = b.oid -inner join {pg_}namespace ns on ns.oid = b.relnamespace -inner join {pg_}class d on d.oid = a.indrelid -where {loc8.ToString().Replace("a.table_name", "ns.nspname || '.' || d.relname")} -"; - ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); - if (ds == null) return loc1; - - var indexColumns = new Dictionary>(); - var uniqueColumns = new Dictionary>(); - foreach (object[] row in ds) - { - var object_id = string.Concat(row[0]); - var column = string.Concat(row[1]); - var index_id = string.Concat(row[2]); - var is_unique = string.Concat(row[3]) == "1"; - var is_primary_key = string.Concat(row[4]) == "1"; - var is_clustered = string.Concat(row[5]) == "1"; - var is_desc = string.Concat(row[6]) == "1"; - var inkey = string.Concat(row[7]).Split(' '); - var attnum = int.Parse(string.Concat(row[8])); - attnum = int.Parse(inkey[attnum - 1]); - //foreach (string tc in loc3[object_id].Keys) - //{ - // if (loc3[object_id][tc].DbTypeText.EndsWith("[]")) - // { - // column = tc; - // break; - // } - //} - if (loc3.ContainsKey(object_id) == false || loc3[object_id].ContainsKey(column) == false) continue; - var loc9 = loc3[object_id][column]; - if (loc9.IsPrimary == false && is_primary_key) loc9.IsPrimary = is_primary_key; - - Dictionary loc10 = null; - DbIndexInfo loc11 = null; - if (!indexColumns.TryGetValue(object_id, out loc10)) - indexColumns.Add(object_id, loc10 = new Dictionary()); - if (!loc10.TryGetValue(index_id, out loc11)) - loc10.Add(index_id, loc11 = new DbIndexInfo()); - loc11.Columns.Add(new DbIndexColumnInfo { Column = loc9, IsDesc = is_desc }); - if (is_unique && !is_primary_key) - { - if (!uniqueColumns.TryGetValue(object_id, out loc10)) - uniqueColumns.Add(object_id, loc10 = new Dictionary()); - if (!loc10.TryGetValue(index_id, out loc11)) - loc10.Add(index_id, loc11 = new DbIndexInfo()); - loc11.Columns.Add(new DbIndexColumnInfo { Column = loc9, IsDesc = is_desc }); - } - } - foreach (var object_id in indexColumns.Keys) - { - foreach (var column in indexColumns[object_id]) - loc2[object_id].IndexesDict.Add(column.Key, column.Value); - } - foreach (var object_id in uniqueColumns.Keys) - { - foreach (var column in uniqueColumns[object_id]) - { - column.Value.Columns.Sort((c1, c2) => c1.Column.Name.CompareTo(c2.Column.Name)); - loc2[object_id].UniquesDict.Add(column.Key, column.Value); - } - } - - if (tbname == null) - { - sql = $@" -select -ns.nspname || '.' || b.relname as table_id, -array(select attname from {pg_}attribute where attrelid = a.conrelid and attnum = any(a.conkey)) as column_name, -a.conname as FKId, -ns2.nspname || '.' || c.relname as ref_table_id, -1 as IsForeignKey, -array(select attname from {pg_}attribute where attrelid = a.confrelid and attnum = any(a.confkey)) as ref_column, -null ref_sln, -null ref_table -from {pg_}constraint a -inner join {pg_}class b on b.oid = a.conrelid -inner join {pg_}class c on c.oid = a.confrelid -inner join {pg_}namespace ns on ns.oid = b.relnamespace -inner join {pg_}namespace ns2 on ns2.oid = c.relnamespace -where {loc8.ToString().Replace("a.table_name", "ns.nspname || '.' || b.relname")} -"; - ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); - if (ds == null) return loc1; - - var fkColumns = new Dictionary>(); - foreach (object[] row in ds) - { - var table_id = string.Concat(row[0]); - var column = row[1] as string[]; - var fk_id = string.Concat(row[2]); - var ref_table_id = string.Concat(row[3]); - var is_foreign_key = string.Concat(row[4]) == "1"; - var referenced_column = row[5] as string[]; - var referenced_db = string.Concat(row[6]); - var referenced_table = string.Concat(row[7]); - - if (loc2.ContainsKey(ref_table_id) == false) continue; - - Dictionary loc12 = null; - DbForeignInfo loc13 = null; - if (!fkColumns.TryGetValue(table_id, out loc12)) - fkColumns.Add(table_id, loc12 = new Dictionary()); - if (!loc12.TryGetValue(fk_id, out loc13)) - loc12.Add(fk_id, loc13 = new DbForeignInfo { Table = loc2[table_id], ReferencedTable = loc2[ref_table_id] }); - - for (int a = 0; a < column.Length; a++) - { - loc13.Columns.Add(loc3[table_id][column[a]]); - loc13.ReferencedColumns.Add(loc3[ref_table_id][referenced_column[a]]); - } - } - foreach (var table_id in fkColumns.Keys) - foreach (var fk in fkColumns[table_id]) - loc2[table_id].ForeignsDict.Add(fk.Key, fk.Value); - } - - foreach (var table_id in loc3.Keys) - { - foreach (var loc5 in loc3[table_id].Values) - { - loc2[table_id].Columns.Add(loc5); - if (loc5.IsIdentity) loc2[table_id].Identitys.Add(loc5); - if (loc5.IsPrimary) loc2[table_id].Primarys.Add(loc5); - } - } - foreach (var loc4 in loc2.Values) - { - //if (loc4.Primarys.Count == 0 && loc4.UniquesDict.Count > 0) - //{ - // foreach (var loc5 in loc4.UniquesDict.First().Value.Columns) - // { - // loc5.Column.IsPrimary = true; - // loc4.Primarys.Add(loc5.Column); - // } - //} - loc4.Primarys.Sort((c1, c2) => c1.Name.CompareTo(c2.Name)); - loc4.Columns.Sort((c1, c2) => - { - int compare = c2.IsPrimary.CompareTo(c1.IsPrimary); - if (compare == 0) - { - bool b1 = loc4.ForeignsDict.Values.Where(fk => fk.Columns.Where(c3 => c3.Name == c1.Name).Any()).Any(); - bool b2 = loc4.ForeignsDict.Values.Where(fk => fk.Columns.Where(c3 => c3.Name == c2.Name).Any()).Any(); - compare = b2.CompareTo(b1); - } - if (compare == 0) compare = c1.Name.CompareTo(c2.Name); - return compare; - }); - loc1.Add(loc4); - } - loc1.Sort((t1, t2) => - { - var ret = t1.Schema.CompareTo(t2.Schema); - if (ret == 0) ret = t1.Name.CompareTo(t2.Name); - return ret; - }); - - loc2.Clear(); - loc3.Clear(); - tables.AddRange(loc1); - } - return tables; - } - - public class GetEnumsByDatabaseQueryInfo - { - public string name { get; set; } - public string label { get; set; } - } - public List GetEnumsByDatabase(params string[] database) - { - var pg_ = getpg_(); - if (database == null || database.Length == 0) return new List(); - var drs = _orm.Ado.Query(CommandType.Text, _commonUtils.FormatSql($@" -select -ns.nspname || '.' || a.typname AS name, -b.enumlabel AS label -from {pg_}type a -inner join {pg_}enum b on b.enumtypid = a.oid -inner join {pg_}namespace ns on ns.oid = a.typnamespace -where a.typtype = 'e' and ns.nspname in (SELECT schema_name FROM information_schema.schemata where catalog_name in {{0}})", database)); - var ret = new Dictionary>(); - foreach (var dr in drs) - { - if (ret.TryGetValue(dr.name, out var labels) == false) ret.Add(dr.name, labels = new Dictionary()); - var key = dr.label; - if (Regex.IsMatch(key, @"^[\u0391-\uFFE5a-zA-Z_\$][\u0391-\uFFE5a-zA-Z_\$\d]*$") == false) - key = $"Unkown{ret[dr.name].Count + 1}"; - if (labels.ContainsKey(key) == false) labels.Add(key, dr.label); - } - return ret.Select(a => new DbEnumInfo { Name = a.Key, Labels = a.Value }).ToList(); - } - } -} \ No newline at end of file diff --git a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESExpression.cs b/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESExpression.cs deleted file mode 100644 index 22c8054fe..000000000 --- a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESExpression.cs +++ /dev/null @@ -1,582 +0,0 @@ -using FreeSql.Internal; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; -using System.Text; -using System.Text.RegularExpressions; - -namespace FreeSql.Odbc.KingbaseES -{ - class OdbcKingbaseESExpression : CommonExpression - { - - public OdbcKingbaseESExpression(CommonUtils common) : base(common) { } - - public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) - { - Func getExp = exparg => ExpressionLambdaToSql(exparg, tsc); - switch (exp.NodeType) - { - case ExpressionType.ArrayLength: - var arrOper = (exp as UnaryExpression)?.Operand; - var arrOperExp = getExp(arrOper); - if (arrOperExp.StartsWith("(") || arrOperExp.EndsWith(")")) return $"array_length(array[{arrOperExp.TrimStart('(').TrimEnd(')')}],1)"; - if (arrOper.Type == typeof(byte[])) return $"octet_length({getExp(arrOper)})"; - return $"case when {arrOperExp} is null then 0 else array_length({arrOperExp},1) end"; - case ExpressionType.Convert: - var operandExp = (exp as UnaryExpression)?.Operand; - var gentype = exp.Type.NullableTypeOrThis(); - if (gentype != operandExp.Type.NullableTypeOrThis()) - { - switch (exp.Type.NullableTypeOrThis().ToString()) - { - case "System.Boolean": return $"(({getExp(operandExp)})::varchar not in ('0','false','f','no'))"; - case "System.Byte": return $"({getExp(operandExp)})::int2"; - case "System.Char": return $"substr(({getExp(operandExp)})::char, 1, 1)"; - case "System.DateTime": return ExpressionConstDateTime(operandExp) ?? $"({getExp(operandExp)})::timestamp"; - case "System.Decimal": return $"({getExp(operandExp)})::numeric"; - case "System.Double": return $"({getExp(operandExp)})::float8"; - case "System.Int16": return $"({getExp(operandExp)})::int2"; - case "System.Int32": return $"({getExp(operandExp)})::int4"; - case "System.Int64": return $"({getExp(operandExp)})::int8"; - case "System.SByte": return $"({getExp(operandExp)})::int2"; - case "System.Single": return $"({getExp(operandExp)})::float4"; - case "System.String": return $"({getExp(operandExp)})::text"; - case "System.UInt16": return $"({getExp(operandExp)})::int2"; - case "System.UInt32": return $"({getExp(operandExp)})::int4"; - case "System.UInt64": return $"({getExp(operandExp)})::int8"; - case "System.Guid": return $"({getExp(operandExp)})::uuid"; - } - } - break; - case ExpressionType.Call: - var callExp = exp as MethodCallExpression; - - switch (callExp.Method.Name) - { - case "Parse": - case "TryParse": - switch (callExp.Method.DeclaringType.NullableTypeOrThis().ToString()) - { - case "System.Boolean": return $"(({getExp(callExp.Arguments[0])})::varchar not in ('0','false','f','no'))"; - case "System.Byte": return $"({getExp(callExp.Arguments[0])})::int2"; - case "System.Char": return $"substr(({getExp(callExp.Arguments[0])})::char, 1, 1)"; - case "System.DateTime": return ExpressionConstDateTime(callExp.Arguments[0]) ?? $"({getExp(callExp.Arguments[0])})::timestamp"; - case "System.Decimal": return $"({getExp(callExp.Arguments[0])})::numeric"; - case "System.Double": return $"({getExp(callExp.Arguments[0])})::float8"; - case "System.Int16": return $"({getExp(callExp.Arguments[0])})::int2"; - case "System.Int32": return $"({getExp(callExp.Arguments[0])})::int4"; - case "System.Int64": return $"({getExp(callExp.Arguments[0])})::int8"; - case "System.SByte": return $"({getExp(callExp.Arguments[0])})::int2"; - case "System.Single": return $"({getExp(callExp.Arguments[0])})::float4"; - case "System.UInt16": return $"({getExp(callExp.Arguments[0])})::int2"; - case "System.UInt32": return $"({getExp(callExp.Arguments[0])})::int4"; - case "System.UInt64": return $"({getExp(callExp.Arguments[0])})::int8"; - case "System.Guid": return $"({getExp(callExp.Arguments[0])})::uuid"; - } - break; - case "NewGuid": - return null; - case "Next": - if (callExp.Object?.Type == typeof(Random)) return "(random()*1000000000)::int4"; - return null; - case "NextDouble": - if (callExp.Object?.Type == typeof(Random)) return "random()"; - return null; - case "Random": - if (callExp.Method.DeclaringType.IsNumberType()) return "random()"; - return null; - case "ToString": - if (callExp.Object != null) - { - if (callExp.Object.Type.NullableTypeOrThis().IsEnum) - { - tsc.SetMapColumnTmp(null); - var oldMapType = tsc.SetMapTypeReturnOld(typeof(string)); - var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); - tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); - return enumStr; - } - var value = ExpressionGetValue(callExp.Object, out var success); - if (success) return formatSql(value, typeof(string), null, null); - return callExp.Arguments.Count == 0 ? $"({getExp(callExp.Object)})::text" : null; - } - return null; - } - - var objExp = callExp.Object; - var objType = objExp?.Type; - if (objType?.FullName == "System.Byte[]") return null; - - var argIndex = 0; - if (objType == null && callExp.Method.DeclaringType == typeof(Enumerable)) - { - objExp = callExp.Arguments.FirstOrDefault(); - objType = objExp?.Type; - argIndex++; - - if (objType == typeof(string)) - { - switch (callExp.Method.Name) - { - case "First": - case "FirstOrDefault": - return $"substr({getExp(callExp.Arguments[0])}, 1, 1)"; - } - } - } - if (objType == null) objType = callExp.Method.DeclaringType; - if (objType != null || objType.IsArrayOrList()) - { - string left = null; - if (objType == typeof(Dictionary)) - { - left = objExp == null ? null : getExp(objExp); - switch (callExp.Method.Name) - { - case "get_Item": return $"{left}->{getExp(callExp.Arguments[argIndex])}"; - case "Contains": - var right = getExp(callExp.Arguments[argIndex]); - return $"({left} @> ({right}))"; - case "ContainsKey": return $"({left} ? {getExp(callExp.Arguments[argIndex])})"; - case "Concat": return $"({left} || {getExp(callExp.Arguments[argIndex])})"; - case "GetLength": - case "GetLongLength": - case "Count": return $"case when {left} is null then 0 else array_length(akeys({left}),1) end"; - case "Keys": return $"akeys({left})"; - case "Values": return $"avals({left})"; - } - } - switch (callExp.Method.Name) - { - case "Any": - left = objExp == null ? null : getExp(objExp); - if (left.StartsWith("(") || left.EndsWith(")")) left = $"array[{left.TrimStart('(').TrimEnd(')')}]"; - return $"(case when {left} is null then 0 else array_length({left},1) end > 0)"; - case "Contains": - tsc.SetMapColumnTmp(null); - var args1 = getExp(callExp.Arguments[argIndex]); - var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp); - var oldDbParams = objExp?.NodeType == ExpressionType.MemberAccess ? tsc.SetDbParamsReturnOld(null) : null; //#900 UseGenerateCommandParameterWithLambda(true) 子查询 bug、以及 #1173 参数化 bug - tsc.isNotSetMapColumnTmp = true; - left = objExp == null ? null : getExp(objExp); - tsc.isNotSetMapColumnTmp = false; - tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); - if (oldDbParams != null) tsc.SetDbParamsReturnOld(oldDbParams); - //判断 in 或 array @> array - if (left.StartsWith("array[") && left.EndsWith("]")) - return $"({args1}) in ({left.Substring(6, left.Length - 7)})"; - if (left.StartsWith("(") && left.EndsWith(")")) //在各大 Provider AdoProvider 中已约定,500元素分割, 3空格\r\n4空格 - return $"(({args1}) in {left.Replace(", \r\n \r\n", $") \r\n OR ({args1}) in (")})"; - if (args1.StartsWith("(") && args1.EndsWith(")")) args1 = $"array[{args1.TrimStart('(').TrimEnd(')')}]"; - else args1 = $"array[{args1}]"; - if (objExp != null) - { - var dbinfo = _common._orm.CodeFirst.GetDbInfo(objExp.Type); - if (dbinfo != null) args1 = $"{args1}::{dbinfo.dbtype}"; - } - return $"({left} @> {args1})"; - case "Concat": - left = objExp == null ? null : getExp(objExp); - if (left.StartsWith("(") || left.EndsWith(")")) left = $"array[{left.TrimStart('(').TrimEnd(')')}]"; - var right2 = getExp(callExp.Arguments[argIndex]); - if (right2.StartsWith("(") || right2.EndsWith(")")) right2 = $"array[{right2.TrimStart('(').TrimEnd(')')}]"; - return $"({left} || {right2})"; - case "GetLength": - case "GetLongLength": - case "Length": - case "Count": - left = objExp == null ? null : getExp(objExp); - if (left.StartsWith("(") || left.EndsWith(")")) left = $"array[{left.TrimStart('(').TrimEnd(')')}]"; - return $"case when {left} is null then 0 else array_length({left},1) end"; - } - } - break; - case ExpressionType.MemberAccess: - var memExp = exp as MemberExpression; - var memParentExp = memExp.Expression?.Type; - if (memParentExp?.FullName == "System.Byte[]") return null; - if (memParentExp != null) - { - if (memParentExp.IsArray == true) - { - var left = getExp(memExp.Expression); - if (left.StartsWith("(") || left.EndsWith(")")) left = $"array[{left.TrimStart('(').TrimEnd(')')}]"; - switch (memExp.Member.Name) - { - case "Length": - case "Count": return $"case when {left} is null then 0 else array_length({left},1) end"; - } - } - } - break; - case ExpressionType.NewArrayInit: - var arrExp = exp as NewArrayExpression; - var arrSb = new StringBuilder(); - arrSb.Append("array["); - for (var a = 0; a < arrExp.Expressions.Count; a++) - { - if (a > 0) arrSb.Append(","); - arrSb.Append(getExp(arrExp.Expressions[a])); - } - if (arrSb.Length == 1) arrSb.Append("NULL"); - return arrSb.Append("]").ToString(); - case ExpressionType.ListInit: - var listExp = exp as ListInitExpression; - var listSb = new StringBuilder(); - listSb.Append("("); - for (var a = 0; a < listExp.Initializers.Count; a++) - { - if (listExp.Initializers[a].Arguments.Any() == false) continue; - if (a > 0) listSb.Append(","); - listSb.Append(getExp(listExp.Initializers[a].Arguments.FirstOrDefault())); - } - if (listSb.Length == 1) listSb.Append("NULL"); - return listSb.Append(")").ToString(); - case ExpressionType.New: - var newExp = exp as NewExpression; - if (typeof(IList).IsAssignableFrom(newExp.Type)) - { - if (newExp.Arguments.Count == 0) return "(NULL)"; - if (typeof(IEnumerable).IsAssignableFrom(newExp.Arguments[0].Type) == false) return "(NULL)"; - return getExp(newExp.Arguments[0]); - } - return null; - } - return null; - } - - public override string ExpressionLambdaToSqlMemberAccessString(MemberExpression exp, ExpTSC tsc) - { - if (exp.Expression == null) - { - switch (exp.Member.Name) - { - case "Empty": return "''"; - } - return null; - } - var left = ExpressionLambdaToSql(exp.Expression, tsc); - switch (exp.Member.Name) - { - case "Length": return $"char_length({left})"; - } - return null; - } - public override string ExpressionLambdaToSqlMemberAccessDateTime(MemberExpression exp, ExpTSC tsc) - { - if (exp.Expression == null) - { - switch (exp.Member.Name) - { - case "Now": return _common.Now; - case "UtcNow": return _common.NowUtc; - case "Today": return "current_date"; - case "MinValue": return "'0001/1/1 0:00:00'::timestamp"; - case "MaxValue": return "'9999/12/31 23:59:59'::timestamp"; - } - return null; - } - var left = ExpressionLambdaToSql(exp.Expression, tsc); - switch (exp.Member.Name) - { - case "Date": return $"({left})::date"; - case "TimeOfDay": return $"(extract(epoch from ({left})::time)*1000000)"; - case "DayOfWeek": return $"extract(dow from ({left})::timestamp)"; - case "Day": return $"extract(day from ({left})::timestamp)"; - case "DayOfYear": return $"extract(doy from ({left})::timestamp)"; - case "Month": return $"extract(month from ({left})::timestamp)"; - case "Year": return $"extract(year from ({left})::timestamp)"; - case "Hour": return $"extract(hour from ({left})::timestamp)"; - case "Minute": return $"extract(minute from ({left})::timestamp)"; - case "Second": return $"extract(second from ({left})::timestamp)"; - case "Millisecond": return $"(extract(milliseconds from ({left})::timestamp)-extract(second from ({left})::timestamp)*1000)"; - case "Ticks": return $"(extract(epoch from ({left})::timestamp)*10000000+621355968000000000)"; - } - return null; - } - - public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, ExpTSC tsc) - { - Func getExp = exparg => ExpressionLambdaToSql(exparg, tsc); - if (exp.Object == null) - { - switch (exp.Method.Name) - { - case "IsNullOrEmpty": - var arg1 = getExp(exp.Arguments[0]); - return $"({arg1} is null or {arg1} = '')"; - case "IsNullOrWhiteSpace": - var arg2 = getExp(exp.Arguments[0]); - return $"({arg2} is null or {arg2} = '' or ltrim({arg2}) = '')"; - case "Concat": - if (exp.Arguments.Count == 1 && exp.Arguments[0].NodeType == ExpressionType.NewArrayInit && exp.Arguments[0] is NewArrayExpression concatNewArrExp) - return _common.StringConcat(concatNewArrExp.Expressions.Select(a => getExp(a)).ToArray(), null); - return _common.StringConcat(exp.Arguments.Select(a => getExp(a)).ToArray(), null); - case "Format": - if (exp.Arguments[0].NodeType != ExpressionType.Constant) throw new Exception(CoreStrings.Not_Implemented_Expression_ParameterUseConstant(exp,exp.Arguments[0])); - var expArgsHack = exp.Arguments.Count == 2 && exp.Arguments[1].NodeType == ExpressionType.NewArrayInit ? - (exp.Arguments[1] as NewArrayExpression).Expressions : exp.Arguments.Where((a, z) => z > 0); - //3个 {} 时,Arguments 解析出来是分开的 - //4个 {} 时,Arguments[1] 只能解析这个出来,然后里面是 NewArray [] - var expArgs = expArgsHack.Select(a => - { - var atype = (a as UnaryExpression)?.Operand.Type.NullableTypeOrThis() ?? a.Type.NullableTypeOrThis(); - if (atype == typeof(string)) return $"'||{_common.IsNull(ExpressionLambdaToSql(a, tsc), "''")}||'"; - return $"'||{_common.IsNull($"({ExpressionLambdaToSql(a, tsc)})::text", "''")}||'"; - }).ToArray(); - return string.Format(ExpressionLambdaToSql(exp.Arguments[0], tsc), expArgs); - case "Join": - if (exp.IsStringJoin(out var tolistObjectExp, out var toListMethod, out var toListArgs1)) - { - var newToListArgs0 = Expression.Call(tolistObjectExp, toListMethod, - Expression.Lambda( - Expression.Call( - typeof(SqlExtExtensions).GetMethod("StringJoinPgsqlGroupConcat"), - Expression.Convert(toListArgs1.Body, typeof(object)), - Expression.Convert(exp.Arguments[0], typeof(object))), - toListArgs1.Parameters)); - var newToListSql = getExp(newToListArgs0); - return newToListSql; - } - break; - } - } - else - { - var left = getExp(exp.Object); - switch (exp.Method.Name) - { - case "StartsWith": - case "EndsWith": - case "Contains": - var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; - if (args0Value.Contains("%")) - { - if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1"; - if (exp.Method.Name == "EndsWith") return $"strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1"; - return $"strpos({left}, {args0Value}) > 0"; - } - var likeOpt = "LIKE"; - if (exp.Arguments.Count > 1) - { - if (exp.Arguments[1].Type == typeof(bool) || - exp.Arguments[1].Type == typeof(StringComparison)) likeOpt = "ILIKE"; - } - if (exp.Method.Name == "StartsWith") return $"({left}) {likeOpt} {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(({args0Value})::text || '%')")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) {likeOpt} {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%' || ({args0Value})::text)")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) {likeOpt} {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) {likeOpt} ('%' || ({args0Value})::text || '%')"; - case "ToLower": return $"lower({left})"; - case "ToUpper": return $"upper({left})"; - case "Substring": - var substrArgs1 = getExp(exp.Arguments[0]); - if (long.TryParse(substrArgs1, out var testtrylng1)) substrArgs1 = (testtrylng1 + 1).ToString(); - else substrArgs1 += "+1"; - if (exp.Arguments.Count == 1) return $"substr({left}, {substrArgs1})"; - return $"substr({left}, {substrArgs1}, {getExp(exp.Arguments[1])})"; - case "IndexOf": return $"(strpos({left}, {getExp(exp.Arguments[0])})-1)"; - case "PadLeft": - if (exp.Arguments.Count == 1) return $"lpad({left}, {getExp(exp.Arguments[0])})"; - return $"lpad({left}, {getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})"; - case "PadRight": - if (exp.Arguments.Count == 1) return $"rpad({left}, {getExp(exp.Arguments[0])})"; - return $"rpad({left}, {getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})"; - case "Trim": - case "TrimStart": - case "TrimEnd": - if (exp.Arguments.Count == 0) - { - if (exp.Method.Name == "Trim") return $"trim({left})"; - if (exp.Method.Name == "TrimStart") return $"ltrim({left})"; - if (exp.Method.Name == "TrimEnd") return $"rtrim({left})"; - } - foreach (var argsTrim02 in exp.Arguments) - { - var argsTrim01s = new[] { argsTrim02 }; - if (argsTrim02.NodeType == ExpressionType.NewArrayInit) - { - var arritem = argsTrim02 as NewArrayExpression; - argsTrim01s = arritem.Expressions.ToArray(); - } - foreach (var argsTrim01 in argsTrim01s) - { - if (exp.Method.Name == "Trim") left = $"trim(both {getExp(argsTrim01)} from {left})"; - if (exp.Method.Name == "TrimStart") left = $"ltrim({left},{getExp(argsTrim01)})"; - if (exp.Method.Name == "TrimEnd") left = $"rtrim({left},{getExp(argsTrim01)})"; - } - } - return left; - case "Replace": return $"replace({left}, {getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})"; - case "CompareTo": return $"case when {left} = {getExp(exp.Arguments[0])} then 0 when {left} > {getExp(exp.Arguments[0])} then 1 else -1 end"; - case "Equals": return $"({left} = ({getExp(exp.Arguments[0])})::text)"; - } - } - return null; - } - public override string ExpressionLambdaToSqlCallMath(MethodCallExpression exp, ExpTSC tsc) - { - Func getExp = exparg => ExpressionLambdaToSql(exparg, tsc); - switch (exp.Method.Name) - { - case "Abs": return $"abs({getExp(exp.Arguments[0])})"; - case "Sign": return $"sign({getExp(exp.Arguments[0])})"; - case "Floor": return $"floor({getExp(exp.Arguments[0])})"; - case "Ceiling": return $"ceiling({getExp(exp.Arguments[0])})"; - case "Round": - if (exp.Arguments.Count > 1 && exp.Arguments[1].Type.FullName == "System.Int32") return $"round({getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})"; - return $"round({getExp(exp.Arguments[0])})"; - case "Exp": return $"exp({getExp(exp.Arguments[0])})"; - case "Log": - if (exp.Arguments.Count > 1) return $"log({getExp(exp.Arguments[1])},{getExp(exp.Arguments[0])})"; - return $"log(2.7182818284590451,{getExp(exp.Arguments[0])})"; - case "Log10": return $"log({getExp(exp.Arguments[0])})"; - case "Pow": return $"pow({getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})"; - case "Sqrt": return $"sqrt({getExp(exp.Arguments[0])})"; - case "Cos": return $"cos({getExp(exp.Arguments[0])})"; - case "Sin": return $"sin({getExp(exp.Arguments[0])})"; - case "Tan": return $"tan({getExp(exp.Arguments[0])})"; - case "Acos": return $"acos({getExp(exp.Arguments[0])})"; - case "Asin": return $"asin({getExp(exp.Arguments[0])})"; - case "Atan": return $"atan({getExp(exp.Arguments[0])})"; - case "Atan2": return $"atan2({getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})"; - case "Truncate": return $"trunc({getExp(exp.Arguments[0])}, 0)"; - } - return null; - } - public override string ExpressionLambdaToSqlCallDateTime(MethodCallExpression exp, ExpTSC tsc) - { - Func getExp = exparg => ExpressionLambdaToSql(exparg, tsc); - if (exp.Object == null) - { - switch (exp.Method.Name) - { - case "Compare": return $"extract(epoch from ({getExp(exp.Arguments[0])})::timestamp-({getExp(exp.Arguments[1])})::timestamp)"; - case "DaysInMonth": return $"extract(day from ({getExp(exp.Arguments[0])} || '-' || {getExp(exp.Arguments[1])} || '-01')::timestamp+'1 month'::interval-'1 day'::interval)"; - case "Equals": return $"(({getExp(exp.Arguments[0])})::timestamp = ({getExp(exp.Arguments[1])})::timestamp)"; - - case "IsLeapYear": - var isLeapYearArgs1 = getExp(exp.Arguments[0]); - return $"(({isLeapYearArgs1})::int8%4=0 AND ({isLeapYearArgs1})::int8%100<>0 OR ({isLeapYearArgs1})::int8%400=0)"; - - case "Parse": return ExpressionConstDateTime(exp.Arguments[0]) ?? $"({getExp(exp.Arguments[0])})::timestamp"; - case "ParseExact": - case "TryParse": - case "TryParseExact": return ExpressionConstDateTime(exp.Arguments[0]) ?? $"({getExp(exp.Arguments[0])})::timestamp"; - } - } - else - { - var left = getExp(exp.Object); - var args1 = exp.Arguments.Count == 0 ? null : getExp(exp.Arguments[0]); - switch (exp.Method.Name) - { - case "AddDays": return $"(({left})::timestamp+(({args1})||' day')::interval)"; - case "AddHours": return $"(({left})::timestamp+(({args1})||' hour')::interval)"; - case "AddMilliseconds": return $"(({left})::timestamp+(({args1})||' milliseconds')::interval)"; - case "AddMinutes": return $"(({left})::timestamp+(({args1})||' minute')::interval)"; - case "AddMonths": return $"(({left})::timestamp+(({args1})||' month')::interval)"; - case "AddSeconds": return $"(({left})::timestamp+(({args1})||' second')::interval)"; - case "AddTicks": return $"(({left})::timestamp+(({args1})/10||' microseconds')::interval)"; - case "AddYears": return $"(({left})::timestamp+(({args1})||' year')::interval)"; - case "Subtract": - switch ((exp.Arguments[0].Type.IsNullableType() ? exp.Arguments[0].Type.GetGenericArguments().FirstOrDefault() : exp.Arguments[0].Type).FullName) - { - case "System.DateTime": return $"(extract(epoch from ({left})::timestamp-({args1})::timestamp)*1000000)"; - case "System.TimeSpan": return $"(({left})::timestamp-((({args1})/1000)||' milliseconds')::interval)"; - } - break; - case "Equals": return $"({left} = ({args1})::timestamp)"; - case "CompareTo": return $"extract(epoch from ({left})::timestamp-({args1})::timestamp)"; - case "ToString": - if (left.EndsWith("::timestamp") == false) left = $"({left})::timestamp"; - if (exp.Arguments.Count == 0) return $"to_char({left},'YYYY-MM-DD HH24:MI:SS.US')"; - switch (args1) - { - case "'yyyy-MM-dd HH:mm:ss'": return $"to_char({left},'YYYY-MM-DD HH24:MI:SS')"; - case "'yyyy-MM-dd HH:mm'": return $"to_char({left},'YYYY-MM-DD HH24:MI')"; - case "'yyyy-MM-dd HH'": return $"to_char({left},'YYYY-MM-DD HH24')"; - case "'yyyy-MM-dd'": return $"to_char({left},'YYYY-MM-DD')"; - case "'yyyy-MM'": return $"to_char({left},'YYYY-MM')"; - case "'yyyyMMddHHmmss'": return $"to_char({left},'YYYYMMDDHH24MISS')"; - case "'yyyyMMddHHmm'": return $"to_char({left},'YYYYMMDDHH24MI')"; - case "'yyyyMMddHH'": return $"to_char({left},'YYYYMMDDHH24')"; - case "'yyyyMMdd'": return $"to_char({left},'YYYYMMDD')"; - case "'yyyyMM'": return $"to_char({left},'YYYYMM')"; - case "'yyyy'": return $"to_char({left},'YYYY')"; - case "'HH:mm:ss'": return $"to_char({left},'HH24:MI:SS')"; - } - args1 = Regex.Replace(args1, "(yyyy|yy|MM|dd|HH|hh|mm|ss|tt)", m => - { - switch (m.Groups[1].Value) - { - case "yyyy": return $"YYYY"; - case "yy": return $"YY"; - case "MM": return $"%_a1"; - case "dd": return $"%_a2"; - case "HH": return $"%_a3"; - case "hh": return $"%_a4"; - case "mm": return $"%_a5"; - case "ss": return $"SS"; - case "tt": return $"%_a6"; - } - return m.Groups[0].Value; - }); - var argsFinds = new[] { "YYYY", "YY", "%_a1", "%_a2", "%_a3", "%_a4", "%_a5", "SS", "%_a6" }; - var argsSpts = Regex.Split(args1, "(M|d|H|h|m|s|t)"); - for (var a = 0; a < argsSpts.Length; a++) - { - switch (argsSpts[a]) - { - case "M": argsSpts[a] = $"ltrim(to_char({left},'MM'),'0')"; break; - case "d": argsSpts[a] = $"case when substr(to_char({left},'DD'),1,1) = '0' then substr(to_char({left},'DD'),2,1) else to_char({left},'DD') end"; break; - case "H": argsSpts[a] = $"case when substr(to_char({left},'HH24'),1,1) = '0' then substr(to_char({left},'HH24'),2,1) else to_char({left},'HH24') end"; break; - case "h": argsSpts[a] = $"case when substr(to_char({left},'HH12'),1,1) = '0' then substr(to_char({left},'HH12'),2,1) else to_char({left},'HH12') end"; break; - case "m": argsSpts[a] = $"case when substr(to_char({left},'MI'),1,1) = '0' then substr(to_char({left},'MI'),2,1) else to_char({left},'MI') end"; break; - case "s": argsSpts[a] = $"case when substr(to_char({left},'SS'),1,1) = '0' then substr(to_char({left},'SS'),2,1) else to_char({left},'SS') end"; break; - case "t": argsSpts[a] = $"rtrim(to_char({left},'AM'),'M')"; break; - default: - var argsSptsA = argsSpts[a]; - if (argsSptsA.StartsWith("'")) argsSptsA = argsSptsA.Substring(1); - if (argsSptsA.EndsWith("'")) argsSptsA = argsSptsA.Remove(argsSptsA.Length - 1); - argsSpts[a] = argsFinds.Any(m => argsSptsA.Contains(m)) ? $"to_char({left},'{argsSptsA}')" : $"'{argsSptsA}'"; - break; - } - } - if (argsSpts.Length > 0) args1 = $"({string.Join(" || ", argsSpts.Where(a => a != "''"))})"; - return args1.Replace("%_a1", "MM").Replace("%_a2", "DD").Replace("%_a3", "HH24").Replace("%_a4", "HH12").Replace("%_a5", "MI").Replace("%_a6", "AM"); - } - } - return null; - } - public override string ExpressionLambdaToSqlCallConvert(MethodCallExpression exp, ExpTSC tsc) - { - Func getExp = exparg => ExpressionLambdaToSql(exparg, tsc); - if (exp.Object == null) - { - switch (exp.Method.Name) - { - case "ToBoolean": return $"(({getExp(exp.Arguments[0])})::varchar not in ('0','false','f','no'))"; - case "ToByte": return $"({getExp(exp.Arguments[0])})::int2"; - case "ToChar": return $"substr(({getExp(exp.Arguments[0])})::char, 1, 1)"; - case "ToDateTime": return ExpressionConstDateTime(exp.Arguments[0]) ?? $"({getExp(exp.Arguments[0])})::timestamp"; - case "ToDecimal": return $"({getExp(exp.Arguments[0])})::numeric"; - case "ToDouble": return $"({getExp(exp.Arguments[0])})::float8"; - case "ToInt16": return $"({getExp(exp.Arguments[0])})::int2"; - case "ToInt32": return $"({getExp(exp.Arguments[0])})::int4"; - case "ToInt64": return $"({getExp(exp.Arguments[0])})::int8"; - case "ToSByte": return $"({getExp(exp.Arguments[0])})::int2"; - case "ToSingle": return $"({getExp(exp.Arguments[0])})::float4"; - case "ToString": return $"({getExp(exp.Arguments[0])})::text"; - case "ToUInt16": return $"({getExp(exp.Arguments[0])})::int2"; - case "ToUInt32": return $"({getExp(exp.Arguments[0])})::int4"; - case "ToUInt64": return $"({getExp(exp.Arguments[0])})::int8"; - } - } - return null; - } - } -} diff --git a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESProvider.cs b/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESProvider.cs deleted file mode 100644 index 86d5d77d5..000000000 --- a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESProvider.cs +++ /dev/null @@ -1,37 +0,0 @@ -using FreeSql.Internal.CommonProvider; -using System; -using System.Data.Common; -using System.Threading; - -namespace FreeSql.Odbc.KingbaseES -{ - - public class OdbcKingbaseESProvider : BaseDbProvider, IFreeSql - { - public override ISelect CreateSelectProvider(object dywhere) => new OdbcKingbaseESSelect(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); - public override IInsert CreateInsertProvider() => new OdbcKingbaseESInsert(this, this.InternalCommonUtils, this.InternalCommonExpression); - public override IUpdate CreateUpdateProvider(object dywhere) => new OdbcKingbaseESUpdate(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); - public override IDelete CreateDeleteProvider(object dywhere) => new OdbcKingbaseESDelete(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); - public override IInsertOrUpdate CreateInsertOrUpdateProvider() => new OdbcKingbaseESInsertOrUpdate(this, this.InternalCommonUtils, this.InternalCommonExpression); - - public OdbcKingbaseESProvider(string masterConnectionString, string[] slaveConnectionString, Func connectionFactory = null) - { - this.InternalCommonUtils = new OdbcKingbaseESUtils(this); - this.InternalCommonExpression = new OdbcKingbaseESExpression(this.InternalCommonUtils); - - this.Ado = new OdbcKingbaseESAdo(this.InternalCommonUtils, masterConnectionString, slaveConnectionString, connectionFactory); - this.Aop = new AopProvider(); - - this.DbFirst = new OdbcKingbaseESDbFirst(this, this.InternalCommonUtils, this.InternalCommonExpression); - this.CodeFirst = new OdbcKingbaseESCodeFirst(this, this.InternalCommonUtils, this.InternalCommonExpression); - } - - ~OdbcKingbaseESProvider() => this.Dispose(); - int _disposeCounter; - public override void Dispose() - { - if (Interlocked.Increment(ref _disposeCounter) != 1) return; - (this.Ado as AdoProvider)?.Dispose(); - } - } -} diff --git a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESUtils.cs b/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESUtils.cs deleted file mode 100644 index 84374921e..000000000 --- a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESUtils.cs +++ /dev/null @@ -1,157 +0,0 @@ -using FreeSql.Internal; -using FreeSql.Internal.Model; -using System; -using System.Collections.Generic; -using System.Data.Common; -using System.Data.Odbc; -using System.Globalization; -using System.Linq; -using System.Text; - -namespace FreeSql.Odbc.KingbaseES -{ - - class OdbcKingbaseESUtils : CommonUtils - { - public OdbcKingbaseESUtils(IFreeSql orm) : base(orm) - { - } - - static Array getParamterArrayValue(Type arrayType, object value, object defaultValue) - { - var valueArr = value as Array; - var len = valueArr.GetLength(0); - var ret = Array.CreateInstance(arrayType, len); - for (var a = 0; a < len; a++) - { - var item = valueArr.GetValue(a); - ret.SetValue(item == null ? defaultValue : getParamterValue(item.GetType(), item, 1), a); - } - return ret; - } - static Dictionary> dicGetParamterValue = new Dictionary> { - { typeof(uint).FullName, a => long.Parse(string.Concat(a)) }, { typeof(uint[]).FullName, a => getParamterArrayValue(typeof(long), a, 0) }, { typeof(uint?[]).FullName, a => getParamterArrayValue(typeof(long?), a, null) }, - { typeof(ulong).FullName, a => decimal.Parse(string.Concat(a)) }, { typeof(ulong[]).FullName, a => getParamterArrayValue(typeof(decimal), a, 0) }, { typeof(ulong?[]).FullName, a => getParamterArrayValue(typeof(decimal?), a, null) }, - { typeof(ushort).FullName, a => int.Parse(string.Concat(a)) }, { typeof(ushort[]).FullName, a => getParamterArrayValue(typeof(int), a, 0) }, { typeof(ushort?[]).FullName, a => getParamterArrayValue(typeof(int?), a, null) }, - { typeof(byte).FullName, a => short.Parse(string.Concat(a)) }, { typeof(byte[]).FullName, a => getParamterArrayValue(typeof(short), a, 0) }, { typeof(byte?[]).FullName, a => getParamterArrayValue(typeof(short?), a, null) }, - { typeof(sbyte).FullName, a => short.Parse(string.Concat(a)) }, { typeof(sbyte[]).FullName, a => getParamterArrayValue(typeof(short), a, 0) }, { typeof(sbyte?[]).FullName, a => getParamterArrayValue(typeof(short?), a, null) }, - { typeof(char).FullName, a => string.Concat(a).Replace('\0', ' ').ToCharArray().FirstOrDefault() }, - }; - static object getParamterValue(Type type, object value, int level = 0) - { - if (type.FullName == "System.Byte[]") return value; - if (type.IsArray && level == 0) - { - var elementType = type.GetElementType(); - Type enumType = null; - if (elementType.IsEnum) enumType = elementType; - else if (elementType.IsNullableType()) - { - var genericTypesFirst = elementType.GetGenericArguments().First(); - if (genericTypesFirst.IsEnum) enumType = genericTypesFirst; - } - if (enumType != null) return enumType.GetCustomAttributes(typeof(FlagsAttribute), false).Any() ? - getParamterArrayValue(typeof(long), value, elementType.IsEnum ? null : enumType.CreateInstanceGetDefaultValue()) : - getParamterArrayValue(typeof(int), value, elementType.IsEnum ? null : enumType.CreateInstanceGetDefaultValue()); - return dicGetParamterValue.TryGetValue(type.FullName, out var trydicarr) ? trydicarr(value) : value; - } - if (type.IsNullableType()) type = type.GetGenericArguments().First(); - if (type.IsEnum) return (int)value; - if (dicGetParamterValue.TryGetValue(type.FullName, out var trydic)) return trydic(value); - return value; - } - - public override DbParameter AppendParamter(List _params, string parameterName, ColumnInfo col, Type type, object value) - { - if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}"; - if (value != null) value = getParamterValue(type, value); - var ret = new OdbcParameter { ParameterName = QuoteParamterName(parameterName), Value = value }; - //if (value.GetType().IsEnum || value.GetType().GenericTypeArguments.FirstOrDefault()?.IsEnum == true) { - // ret.DataTypeName = ""; - //} else { - var tp = _orm.CodeFirst.GetDbInfo(type)?.type; - if (tp != null) ret.OdbcType = (OdbcType)tp.Value; - //} - _params?.Add(ret); - return ret; - } - - public override DbParameter[] GetDbParamtersByObject(string sql, object obj) => - Utils.GetDbParamtersByObject(sql, obj, null, (name, type, value) => - { - if (value != null) value = getParamterValue(type, value); - var ret = new OdbcParameter { ParameterName = $"@{name.ToUpper()}", Value = value }; - //if (value.GetType().IsEnum || value.GetType().GenericTypeArguments.FirstOrDefault()?.IsEnum == true) { - // ret.DataTypeName = ""; - //} else { - var tp = _orm.CodeFirst.GetDbInfo(type)?.type; - if (tp != null) ret.OdbcType = (OdbcType)tp.Value; - //} - return ret; - }); - - public override string FormatSql(string sql, params object[] args) => sql?.FormatOdbcKingbaseES(args); - public override string QuoteSqlNameAdapter(params string[] name) - { - if (name.Length == 1) - { - var nametrim = name[0].Trim(); - if (nametrim.StartsWith("(") && nametrim.EndsWith(")")) - return nametrim; //原生SQL - if (nametrim.StartsWith("\"") && nametrim.EndsWith("\"")) - return nametrim; - return $"\"{nametrim.Replace(".", "\".\"")}\""; - } - return $"\"{string.Join("\".\"", name)}\""; - } - public override string TrimQuoteSqlName(string name) - { - var nametrim = name.Trim(); - if (nametrim.StartsWith("(") && nametrim.EndsWith(")")) - return nametrim; //原生SQL - return $"{nametrim.Trim('"').Replace("\".\"", ".").Replace(".\"", ".")}"; - } - public override string[] SplitTableName(string name) => GetSplitTableNames(name, '"', '"', 2); - public override string QuoteParamterName(string name) => $"@{name.ToUpper()}"; - public override string IsNull(string sql, object value) => $"coalesce({sql}, {value})"; - public override string StringConcat(string[] objs, Type[] types) => $"{string.Join(" || ", objs.Select((a, b) => b == 0 ? $"{a}::text" : a))}"; //First ::text - public override string Mod(string left, string right, Type leftType, Type rightType) => $"{left} % {right}"; - public override string Div(string left, string right, Type leftType, Type rightType) => $"{left} / {right}"; - public override string Now => "current_timestamp"; - public override string NowUtc => "(current_timestamp at time zone 'UTC')"; - - public override string QuoteWriteParamterAdapter(Type type, string paramterName) => paramterName; - protected override string QuoteReadColumnAdapter(Type type, Type mapType, string columnName) => columnName; - - public override string GetNoneParamaterSqlValue(List specialParams, string specialParamFlag, ColumnInfo col, Type type, object value) - { - if (value == null) return "NULL"; - if (type.IsNumberType()) return string.Format(CultureInfo.InvariantCulture, "{0}", value); - value = getParamterValue(type, value); - var type2 = value.GetType(); - if (type2 == typeof(byte[])) return $"'\\x{CommonUtils.BytesSqlRaw(value as byte[])}'"; - if (value is Array) - { - var valueArr = value as Array; - var eleType = type2.GetElementType(); - var len = valueArr.GetLength(0); - var sb = new StringBuilder().Append("ARRAY["); - for (var a = 0; a < len; a++) - { - var item = valueArr.GetValue(a); - if (a > 0) sb.Append(","); - sb.Append(GetNoneParamaterSqlValue(specialParams, specialParamFlag, col, eleType, item)); - } - sb.Append("]"); - var dbinfo = _orm.CodeFirst.GetDbInfo(type); - if (dbinfo != null) sb.Append("::").Append(dbinfo.dbtype); - return sb.ToString(); - } - else if (dicGetParamterValue.ContainsKey(type2.FullName)) - { - value = string.Concat(value); - } - return FormatSql("{0}", value, 1); - } - } -} diff --git a/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlAdo/OdbcMySqlAdo.cs b/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlAdo/OdbcMySqlAdo.cs index 62839fd6a..9cce6250d 100644 --- a/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlAdo/OdbcMySqlAdo.cs +++ b/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlAdo/OdbcMySqlAdo.cs @@ -2,7 +2,6 @@ using FreeSql.Internal.CommonProvider; using FreeSql.Internal.Model; using FreeSql.Internal.ObjectPool; -using FreeSql.Odbc.Dameng; using System; using System.Collections; using System.Data.Common; diff --git a/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlExpression.cs b/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlExpression.cs index ddb2c5cb5..6f91eb841 100644 --- a/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlExpression.cs +++ b/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlExpression.cs @@ -282,18 +282,19 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"locate({args0Value}, {left}) = 1"; if (exp.Method.Name == "EndsWith") return $"locate({args0Value}, {left}) = char_length({left})-char_length({args0Value})+1"; return $"locate({args0Value}, {left}) > 0"; } - if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"concat({args0Value}, '%')")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"concat('%', {args0Value})")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) LIKE concat('%', {args0Value}, '%')"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"concat({args0Value}, '%')")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"concat('%', {args0Value})")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} LIKE concat('%', {args0Value}, '%')"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring": diff --git a/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleAdo/OdbcOracleAdo.cs b/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleAdo/OdbcOracleAdo.cs index 126ff26df..789f96f4a 100644 --- a/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleAdo/OdbcOracleAdo.cs +++ b/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleAdo/OdbcOracleAdo.cs @@ -2,7 +2,6 @@ using FreeSql.Internal.CommonProvider; using FreeSql.Internal.Model; using FreeSql.Internal.ObjectPool; -using FreeSql.Odbc.Dameng; using System; using System.Collections; using System.Data.Common; diff --git a/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleExpression.cs b/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleExpression.cs index b2d41ff6b..d06cf0721 100644 --- a/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleExpression.cs +++ b/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleExpression.cs @@ -285,18 +285,19 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1"; if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1"; return $"instr({left}, {args0Value}, 1, 1) > 0"; } - if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) LIKE ('%'||to_char({args0Value})||'%')"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} LIKE ('%'||to_char({args0Value})||'%')"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring": diff --git a/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLAdo/OdbcPostgreSQLAdo.cs b/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLAdo/OdbcPostgreSQLAdo.cs index 2340cd15e..d1052f7b0 100644 --- a/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLAdo/OdbcPostgreSQLAdo.cs +++ b/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLAdo/OdbcPostgreSQLAdo.cs @@ -2,7 +2,6 @@ using FreeSql.Internal.CommonProvider; using FreeSql.Internal.Model; using FreeSql.Internal.ObjectPool; -using FreeSql.Odbc.Dameng; using System; using System.Collections; using System.Collections.Generic; diff --git a/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLExpression.cs b/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLExpression.cs index 523ac2e02..4c8abe477 100644 --- a/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLExpression.cs +++ b/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLExpression.cs @@ -374,8 +374,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1"; @@ -388,10 +389,10 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (exp.Arguments[1].Type == typeof(bool) || exp.Arguments[1].Type == typeof(StringComparison)) likeOpt = "ILIKE"; } - if (exp.Method.Name == "StartsWith") return $"({left}) {likeOpt} {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(({args0Value})::text || '%')")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) {likeOpt} {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%' || ({args0Value})::text)")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) {likeOpt} {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) {likeOpt} ('%' || ({args0Value})::text || '%')"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} {likeOpt} {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(({args0Value})::text || '%')")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} {likeOpt} {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%' || ({args0Value})::text)")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} {likeOpt} {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} {likeOpt} ('%' || ({args0Value})::text || '%')"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring": diff --git a/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerAdo/OdbcSqlServerAdo.cs b/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerAdo/OdbcSqlServerAdo.cs index 1f8643768..e1aa4038a 100644 --- a/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerAdo/OdbcSqlServerAdo.cs +++ b/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerAdo/OdbcSqlServerAdo.cs @@ -2,7 +2,6 @@ using FreeSql.Internal.CommonProvider; using FreeSql.Internal.Model; using FreeSql.Internal.ObjectPool; -using FreeSql.Odbc.Dameng; using System; using System.Collections; using System.Data.Common; diff --git a/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerExpression.cs b/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerExpression.cs index 9eeac59f7..db978b32d 100644 --- a/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerExpression.cs +++ b/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerExpression.cs @@ -305,18 +305,20 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"charindex({args0Value}, {left}) = 1"; if (exp.Method.Name == "EndsWith") return $"charindex({args0Value}, {left}) = len({left})-len({args0Value})+1"; return $"charindex({args0Value}, {left}) > 0"; } - if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(cast({args0Value} as nvarchar(max))+'%')")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'+cast({args0Value} as nvarchar(max)))")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) LIKE ('%'+cast({args0Value} as nvarchar(max))+'%')"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(cast({args0Value} as nvarchar(max))+'%')")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'+cast({args0Value} as nvarchar(max)))")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + if (args0Value.StartsWith("N'") && args0Value.EndsWith("'")) return $"{leftLike} LIKE {args0Value.Insert(2, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} LIKE ('%'+cast({args0Value} as nvarchar(max))+'%')"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring": diff --git a/Providers/FreeSql.Provider.Oracle/OracleExpression.cs b/Providers/FreeSql.Provider.Oracle/OracleExpression.cs index 474f9ee53..1da65fb41 100644 --- a/Providers/FreeSql.Provider.Oracle/OracleExpression.cs +++ b/Providers/FreeSql.Provider.Oracle/OracleExpression.cs @@ -285,18 +285,19 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}, 1, 1) = 1"; if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}, 1, 1) = length({left})-length({args0Value})+1"; return $"instr({left}, {args0Value}, 1, 1) > 0"; } - if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) LIKE ('%'||to_char({args0Value})||'%')"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(to_char({args0Value})||'%')")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'||to_char({args0Value}))")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} LIKE ('%'||to_char({args0Value})||'%')"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring": diff --git a/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLExpression.cs b/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLExpression.cs index ea19d1822..cfc84ec79 100644 --- a/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLExpression.cs +++ b/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLExpression.cs @@ -405,8 +405,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1"; @@ -419,10 +420,10 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (exp.Arguments[1].Type == typeof(bool) || exp.Arguments[1].Type == typeof(StringComparison)) likeOpt = "ILIKE"; } - if (exp.Method.Name == "StartsWith") return $"({left}) {likeOpt} {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(({args0Value})::text || '%')")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) {likeOpt} {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%' || ({args0Value})::text)")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) {likeOpt} {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) {likeOpt} ('%' || ({args0Value})::text || '%')"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} {likeOpt} {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(({args0Value})::text || '%')")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} {likeOpt} {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%' || ({args0Value})::text)")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} {likeOpt} {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} {likeOpt} ('%' || ({args0Value})::text || '%')"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring": diff --git a/Providers/FreeSql.Provider.QuestDb/QuestDbExpression.cs b/Providers/FreeSql.Provider.QuestDb/QuestDbExpression.cs index edd41371e..ce3cd9c42 100644 --- a/Providers/FreeSql.Provider.QuestDb/QuestDbExpression.cs +++ b/Providers/FreeSql.Provider.QuestDb/QuestDbExpression.cs @@ -308,8 +308,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1"; @@ -324,11 +325,11 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, } if (exp.Method.Name == "StartsWith") - return $"({left}) {likeOpt} {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(cast({args0Value} as string) || '%')")}"; + return $"{leftLike} {likeOpt} {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(cast({args0Value} as string) || '%')")}"; if (exp.Method.Name == "EndsWith") - return $"({left}) {likeOpt} {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%' || cast({args0Value} as string))")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) {likeOpt} {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) {likeOpt} ('%' || cast({args0Value} as string) || '%')"; + return $"{leftLike} {likeOpt} {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%' || cast({args0Value} as string))")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} {likeOpt} {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} {likeOpt} ('%' || cast({args0Value} as string) || '%')"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring": diff --git a/Providers/FreeSql.Provider.ShenTong/ShenTongExpression.cs b/Providers/FreeSql.Provider.ShenTong/ShenTongExpression.cs index 862f3b2ba..a1cec6aa8 100644 --- a/Providers/FreeSql.Provider.ShenTong/ShenTongExpression.cs +++ b/Providers/FreeSql.Provider.ShenTong/ShenTongExpression.cs @@ -329,8 +329,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1"; @@ -343,10 +344,10 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (exp.Arguments[1].Type == typeof(bool) || exp.Arguments[1].Type == typeof(StringComparison)) likeOpt = "ILIKE"; } - if (exp.Method.Name == "StartsWith") return $"({left}) {likeOpt} {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(({args0Value})::text || '%')")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) {likeOpt} {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%' || ({args0Value})::text)")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) {likeOpt} {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) {likeOpt} ('%' || ({args0Value})::text || '%')"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} {likeOpt} {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(({args0Value})::text || '%')")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} {likeOpt} {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%' || ({args0Value})::text)")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} {likeOpt} {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} {likeOpt} ('%' || ({args0Value})::text || '%')"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring": diff --git a/Providers/FreeSql.Provider.SqlServer/SqlServerExpression.cs b/Providers/FreeSql.Provider.SqlServer/SqlServerExpression.cs index 230fdcd74..72fdd1df4 100644 --- a/Providers/FreeSql.Provider.SqlServer/SqlServerExpression.cs +++ b/Providers/FreeSql.Provider.SqlServer/SqlServerExpression.cs @@ -304,19 +304,20 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"charindex({args0Value}, {left}) = 1"; if (exp.Method.Name == "EndsWith") return $"charindex({args0Value}, {left}) = len({left})-len({args0Value})+1"; return $"charindex({args0Value}, {left}) > 0"; } - if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(cast({args0Value} as nvarchar(max))+'%')")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'+cast({args0Value} as nvarchar(max)))")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - if (args0Value.StartsWith("N'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(2, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) LIKE ('%'+cast({args0Value} as nvarchar(max))+'%')"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(cast({args0Value} as nvarchar(max))+'%')")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%'+cast({args0Value} as nvarchar(max)))")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + if (args0Value.StartsWith("N'") && args0Value.EndsWith("'")) return $"{leftLike} LIKE {args0Value.Insert(2, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} LIKE ('%'+cast({args0Value} as nvarchar(max))+'%')"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring": diff --git a/Providers/FreeSql.Provider.Sqlite/SqliteExpression.cs b/Providers/FreeSql.Provider.Sqlite/SqliteExpression.cs index dc9057645..b6f12b1ce 100644 --- a/Providers/FreeSql.Provider.Sqlite/SqliteExpression.cs +++ b/Providers/FreeSql.Provider.Sqlite/SqliteExpression.cs @@ -281,18 +281,19 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"instr({left}, {args0Value}) = 1"; if (exp.Method.Name == "EndsWith") return $"instr({left}, {args0Value}) = length({left})-length({args0Value})+1"; return $"instr({left}, {args0Value}) > 0"; } - if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({args0Value})||'%'")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"'%'||({args0Value})")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) LIKE '%'||({args0Value})||'%'"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"({args0Value})||'%'")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} LIKE {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"'%'||({args0Value})")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} LIKE '%'||({args0Value})||'%'"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring": diff --git a/Providers/FreeSql.Provider.Xugu/XuguExpression.cs b/Providers/FreeSql.Provider.Xugu/XuguExpression.cs index cb5641854..070fde1c1 100644 --- a/Providers/FreeSql.Provider.Xugu/XuguExpression.cs +++ b/Providers/FreeSql.Provider.Xugu/XuguExpression.cs @@ -330,8 +330,9 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, case "StartsWith": case "EndsWith": case "Contains": + var leftLike = exp.Object.NodeType == ExpressionType.MemberAccess ? left : $"({left})"; var args0Value = getExp(exp.Arguments[0]); - if (args0Value == "NULL") return $"({left}) IS NULL"; + if (args0Value == "NULL") return $"{leftLike} IS NULL"; if (args0Value.Contains("%")) { if (exp.Method.Name == "StartsWith") return $"strpos({left}, {args0Value}) = 1"; @@ -344,10 +345,10 @@ public override string ExpressionLambdaToSqlCallString(MethodCallExpression exp, if (exp.Arguments[1].Type == typeof(bool) || exp.Arguments[1].Type == typeof(StringComparison)) likeOpt = "ILIKE"; } - if (exp.Method.Name == "StartsWith") return $"({left}) {likeOpt} {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(cast({args0Value} as varchar) || '%')")}"; - if (exp.Method.Name == "EndsWith") return $"({left}) {likeOpt} {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%' || cast({args0Value} as varchar))")}"; - if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) {likeOpt} {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; - return $"({left}) {likeOpt} ('%' || cast({args0Value} as varchar) || '%')"; + if (exp.Method.Name == "StartsWith") return $"{leftLike} {likeOpt} {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"(cast({args0Value} as varchar) || '%')")}"; + if (exp.Method.Name == "EndsWith") return $"{leftLike} {likeOpt} {(args0Value.StartsWith("'") ? args0Value.Insert(1, "%") : $"('%' || cast({args0Value} as varchar))")}"; + if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"{leftLike} {likeOpt} {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}"; + return $"{leftLike} {likeOpt} ('%' || cast({args0Value} as varchar) || '%')"; case "ToLower": return $"lower({left})"; case "ToUpper": return $"upper({left})"; case "Substring":