完成 sqlite codefirst curd expression 开发与测试

This commit is contained in:
28810
2019-01-09 15:50:43 +08:00
parent 40f6e53edd
commit 27bc603d46
33 changed files with 523 additions and 599 deletions

View File

@ -66,7 +66,7 @@ namespace FreeSql.Tests.MySql {
[Fact]
public void ExecuteDeleted() {
delete.Where(a => a.Id > 0).ExecuteDeleted();
//delete.Where(a => a.Id > 0).ExecuteDeleted();
}
}
}

View File

@ -79,7 +79,7 @@ namespace FreeSql.Tests.MySql {
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
insert.AppendData(items.First()).ExecuteInserted();
//insert.AppendData(items.First()).ExecuteInserted();
}
}
}

View File

@ -9,7 +9,7 @@ namespace FreeSql.Tests.Oracle {
IInsert<Topic> insert => g.oracle.Insert<Topic>(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
[Table(Name = "tb_topic")]
[Table(Name = "tb_topic_insert")]
class Topic {
[Column(IsIdentity = true, IsPrimary = true)]
public int Id { get; set; }
@ -26,51 +26,51 @@ namespace FreeSql.Tests.Oracle {
var data = new List<object>();
var sql = insert.AppendData(items.First()).ToSql();
Assert.Equal("INSERT INTO \"tb_topic\"(\"Clicks\", \"Title\", \"CreateTime\") VALUES(:Clicks0, :Title0, :CreateTime0)", sql);
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"Clicks\", \"Title\", \"CreateTime\") VALUES(:Clicks0, :Title0, :CreateTime0)", sql);
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
sql = insert.AppendData(items).ToSql();
Assert.Equal(@"INSERT ALL
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks0, :Title0, :CreateTime0)
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks1, :Title1, :CreateTime1)
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks2, :Title2, :CreateTime2)
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks3, :Title3, :CreateTime3)
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks4, :Title4, :CreateTime4)
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks5, :Title5, :CreateTime5)
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks6, :Title6, :CreateTime6)
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks7, :Title7, :CreateTime7)
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks8, :Title8, :CreateTime8)
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks9, :Title9, :CreateTime9)
INTO ""tb_topic_insert""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks0, :Title0, :CreateTime0)
INTO ""tb_topic_insert""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks1, :Title1, :CreateTime1)
INTO ""tb_topic_insert""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks2, :Title2, :CreateTime2)
INTO ""tb_topic_insert""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks3, :Title3, :CreateTime3)
INTO ""tb_topic_insert""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks4, :Title4, :CreateTime4)
INTO ""tb_topic_insert""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks5, :Title5, :CreateTime5)
INTO ""tb_topic_insert""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks6, :Title6, :CreateTime6)
INTO ""tb_topic_insert""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks7, :Title7, :CreateTime7)
INTO ""tb_topic_insert""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks8, :Title8, :CreateTime8)
INTO ""tb_topic_insert""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks9, :Title9, :CreateTime9)
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""(""Title"") VALUES(:Title0)
INTO ""tb_topic""(""Title"") VALUES(:Title1)
INTO ""tb_topic""(""Title"") VALUES(:Title2)
INTO ""tb_topic""(""Title"") VALUES(:Title3)
INTO ""tb_topic""(""Title"") VALUES(:Title4)
INTO ""tb_topic""(""Title"") VALUES(:Title5)
INTO ""tb_topic""(""Title"") VALUES(:Title6)
INTO ""tb_topic""(""Title"") VALUES(:Title7)
INTO ""tb_topic""(""Title"") VALUES(:Title8)
INTO ""tb_topic""(""Title"") VALUES(:Title9)
INTO ""tb_topic_insert""(""Title"") VALUES(:Title0)
INTO ""tb_topic_insert""(""Title"") VALUES(:Title1)
INTO ""tb_topic_insert""(""Title"") VALUES(:Title2)
INTO ""tb_topic_insert""(""Title"") VALUES(:Title3)
INTO ""tb_topic_insert""(""Title"") VALUES(:Title4)
INTO ""tb_topic_insert""(""Title"") VALUES(:Title5)
INTO ""tb_topic_insert""(""Title"") VALUES(:Title6)
INTO ""tb_topic_insert""(""Title"") VALUES(:Title7)
INTO ""tb_topic_insert""(""Title"") VALUES(:Title8)
INTO ""tb_topic_insert""(""Title"") VALUES(:Title9)
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""(""Clicks"", ""Title"") VALUES(:Clicks0, :Title0)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks1, :Title1)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks2, :Title2)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks3, :Title3)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks4, :Title4)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks5, :Title5)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks6, :Title6)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks7, :Title7)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks8, :Title8)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks9, :Title9)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks0, :Title0)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks1, :Title1)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks2, :Title2)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks3, :Title3)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks4, :Title4)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks5, :Title5)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks6, :Title6)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks7, :Title7)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks8, :Title8)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks9, :Title9)
SELECT 1 FROM DUAL", sql);
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
}
@ -83,31 +83,31 @@ INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks9, :Title9)
var data = new List<object>();
var sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
Assert.Equal(@"INSERT ALL
INTO ""tb_topic""(""Title"") VALUES(:Title0)
INTO ""tb_topic""(""Title"") VALUES(:Title1)
INTO ""tb_topic""(""Title"") VALUES(:Title2)
INTO ""tb_topic""(""Title"") VALUES(:Title3)
INTO ""tb_topic""(""Title"") VALUES(:Title4)
INTO ""tb_topic""(""Title"") VALUES(:Title5)
INTO ""tb_topic""(""Title"") VALUES(:Title6)
INTO ""tb_topic""(""Title"") VALUES(:Title7)
INTO ""tb_topic""(""Title"") VALUES(:Title8)
INTO ""tb_topic""(""Title"") VALUES(:Title9)
INTO ""tb_topic_insert""(""Title"") VALUES(:Title0)
INTO ""tb_topic_insert""(""Title"") VALUES(:Title1)
INTO ""tb_topic_insert""(""Title"") VALUES(:Title2)
INTO ""tb_topic_insert""(""Title"") VALUES(:Title3)
INTO ""tb_topic_insert""(""Title"") VALUES(:Title4)
INTO ""tb_topic_insert""(""Title"") VALUES(:Title5)
INTO ""tb_topic_insert""(""Title"") VALUES(:Title6)
INTO ""tb_topic_insert""(""Title"") VALUES(:Title7)
INTO ""tb_topic_insert""(""Title"") VALUES(:Title8)
INTO ""tb_topic_insert""(""Title"") VALUES(:Title9)
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""(""Clicks"", ""Title"") VALUES(:Clicks0, :Title0)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks1, :Title1)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks2, :Title2)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks3, :Title3)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks4, :Title4)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks5, :Title5)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks6, :Title6)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks7, :Title7)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks8, :Title8)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks9, :Title9)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks0, :Title0)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks1, :Title1)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks2, :Title2)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks3, :Title3)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks4, :Title4)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks5, :Title5)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks6, :Title6)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks7, :Title7)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks8, :Title8)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks9, :Title9)
SELECT 1 FROM DUAL", sql);
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
}
@ -119,31 +119,31 @@ INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks9, :Title9)
var data = new List<object>();
var sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql();
Assert.Equal(@"INSERT ALL
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks0, :Title0)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks1, :Title1)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks2, :Title2)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks3, :Title3)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks4, :Title4)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks5, :Title5)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks6, :Title6)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks7, :Title7)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks8, :Title8)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks9, :Title9)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks0, :Title0)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks1, :Title1)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks2, :Title2)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks3, :Title3)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks4, :Title4)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks5, :Title5)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks6, :Title6)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks7, :Title7)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks8, :Title8)
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks9, :Title9)
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""(""Clicks"") VALUES(:Clicks0)
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks1)
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks2)
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks3)
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks4)
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks5)
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks6)
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks7)
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks8)
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks9)
INTO ""tb_topic_insert""(""Clicks"") VALUES(:Clicks0)
INTO ""tb_topic_insert""(""Clicks"") VALUES(:Clicks1)
INTO ""tb_topic_insert""(""Clicks"") VALUES(:Clicks2)
INTO ""tb_topic_insert""(""Clicks"") VALUES(:Clicks3)
INTO ""tb_topic_insert""(""Clicks"") VALUES(:Clicks4)
INTO ""tb_topic_insert""(""Clicks"") VALUES(:Clicks5)
INTO ""tb_topic_insert""(""Clicks"") VALUES(:Clicks6)
INTO ""tb_topic_insert""(""Clicks"") VALUES(:Clicks7)
INTO ""tb_topic_insert""(""Clicks"") VALUES(:Clicks8)
INTO ""tb_topic_insert""(""Clicks"") VALUES(:Clicks9)
SELECT 1 FROM DUAL", sql);
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
}

View File

@ -4,10 +4,10 @@ using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.Sqlite3 {
namespace FreeSql.Tests.Sqlite {
public class SqliteDeleteTest {
IDelete<Topic> delete => g.sqlite3.Delete<Topic>(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
IDelete<Topic> delete => g.sqlite.Delete<Topic>(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
[Table(Name = "tb_topic22211")]
class Topic {
@ -21,17 +21,17 @@ namespace FreeSql.Tests.Sqlite3 {
[Fact]
public void Dywhere() {
Assert.Null(g.sqlite3.Delete<Topic>().ToSql());
var sql = g.sqlite3.Delete<Topic>(new[] { 1, 2 }).ToSql();
Assert.Null(g.sqlite.Delete<Topic>().ToSql());
var sql = g.sqlite.Delete<Topic>(new[] { 1, 2 }).ToSql();
Assert.Equal("DELETE FROM \"tb_topic22211\" WHERE (\"Id\" = 1 OR \"Id\" = 2)", sql);
sql = g.sqlite3.Delete<Topic>(new Topic { Id = 1, Title = "test" }).ToSql();
sql = g.sqlite.Delete<Topic>(new Topic { Id = 1, Title = "test" }).ToSql();
Assert.Equal("DELETE FROM \"tb_topic22211\" WHERE (\"Id\" = 1)", sql);
sql = g.sqlite3.Delete<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).ToSql();
sql = g.sqlite.Delete<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).ToSql();
Assert.Equal("DELETE FROM \"tb_topic22211\" WHERE (\"Id\" = 1 OR \"Id\" = 2)", sql);
sql = g.sqlite3.Delete<Topic>(new { id = 1 }).ToSql();
sql = g.sqlite.Delete<Topic>(new { id = 1 }).ToSql();
Assert.Equal("DELETE FROM \"tb_topic22211\" WHERE (\"Id\" = 1)", sql);
}
@ -60,13 +60,13 @@ namespace FreeSql.Tests.Sqlite3 {
[Fact]
public void ExecuteAffrows() {
var id = g.sqlite3.Insert<Topic>(new Topic { Title = "xxxx", CreateTime = DateTime.Now }).ExecuteIdentity();
var id = g.sqlite.Insert<Topic>(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.sqlite3.Insert<Topic>(new Topic { Title = "xxxx", CreateTime = DateTime.Now }).ExecuteInserted();
//var item = g.Sqlite.Insert<Topic>(new Topic { Title = "xxxx", CreateTime = DateTime.Now }).ExecuteInserted();
//Assert.Equal(item[0].Id, delete.Where(a => a.Id == item[0].Id).ExecuteDeleted()[0].Id);
}
}

View File

@ -0,0 +1,81 @@
using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.Sqlite {
public class SqliteInsertTest {
IInsert<Topic> insert => g.sqlite.Insert<Topic>();
[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<Topic>();
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(@Clicks0, @Title0, @CreateTime0)", sql);
sql = insert.AppendData(items).ToSql();
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"Clicks\", \"Title\", \"CreateTime\") VALUES(@Clicks0, @Title0, @CreateTime0), (@Clicks1, @Title1, @CreateTime1), (@Clicks2, @Title2, @CreateTime2), (@Clicks3, @Title3, @CreateTime3), (@Clicks4, @Title4, @CreateTime4), (@Clicks5, @Title5, @CreateTime5), (@Clicks6, @Title6, @CreateTime6), (@Clicks7, @Title7, @CreateTime7), (@Clicks8, @Title8, @CreateTime8), (@Clicks9, @Title9, @CreateTime9)", sql);
sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"Title\") VALUES(@Title0), (@Title1), (@Title2), (@Title3), (@Title4), (@Title5), (@Title6), (@Title7), (@Title8), (@Title9)", sql);
sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql();
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"Clicks\", \"Title\") VALUES(@Clicks0, @Title0), (@Clicks1, @Title1), (@Clicks2, @Title2), (@Clicks3, @Title3), (@Clicks4, @Title4), (@Clicks5, @Title5), (@Clicks6, @Title6), (@Clicks7, @Title7), (@Clicks8, @Title8), (@Clicks9, @Title9)", sql);
}
[Fact]
public void InsertColumns() {
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newTitle{a}", Clicks = a * 100 });
var sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"Title\") VALUES(@Title0), (@Title1), (@Title2), (@Title3), (@Title4), (@Title5), (@Title6), (@Title7), (@Title8), (@Title9)", sql);
sql = insert.AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).ToSql();
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"Clicks\", \"Title\") VALUES(@Clicks0, @Title0), (@Clicks1, @Title1), (@Clicks2, @Title2), (@Clicks3, @Title3), (@Clicks4, @Title4), (@Clicks5, @Title5), (@Clicks6, @Title6), (@Clicks7, @Title7), (@Clicks8, @Title8), (@Clicks9, @Title9)", sql);
}
[Fact]
public void IgnoreColumns() {
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newTitle{a}", Clicks = a * 100 });
var sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql();
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"Clicks\", \"Title\") VALUES(@Clicks0, @Title0), (@Clicks1, @Title1), (@Clicks2, @Title2), (@Clicks3, @Title3), (@Clicks4, @Title4), (@Clicks5, @Title5), (@Clicks6, @Title6), (@Clicks7, @Title7), (@Clicks8, @Title8), (@Clicks9, @Title9)", sql);
sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).ToSql();
Assert.Equal("INSERT INTO \"tb_topic_insert\"(\"Clicks\") VALUES(@Clicks0), (@Clicks1), (@Clicks2), (@Clicks3), (@Clicks4), (@Clicks5), (@Clicks6), (@Clicks7), (@Clicks8), (@Clicks9)", sql);
}
[Fact]
public void ExecuteAffrows() {
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newTitle{a}", Clicks = a * 100 });
Assert.Equal(1, insert.AppendData(items.First()).ExecuteAffrows());
Assert.Equal(10, insert.AppendData(items).ExecuteAffrows());
}
[Fact]
public void ExecuteIdentity() {
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newTitle{a}", Clicks = a * 100 });
Assert.NotEqual(0, insert.AppendData(items.First()).ExecuteIdentity());
}
[Fact]
public void ExecuteInserted() {
}
}
}

View File

@ -4,10 +4,10 @@ using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.Sqlite3 {
namespace FreeSql.Tests.Sqlite {
public class SqliteSelectTest {
ISelect<Topic> select => g.sqlite3.Select<Topic>();
ISelect<Topic> select => g.sqlite.Select<Topic>();
[Table(Name = "tb_topic22")]
class Topic {
@ -61,10 +61,10 @@ namespace FreeSql.Tests.Sqlite3 {
[Fact]
public void Caching() {
var result1 = select.Where(a => 1 == 1).Caching(20, "testcaching").ToList();
var testcaching1 = g.sqlite3.Cache.Get("testcaching");
var testcaching1 = g.sqlite.Cache.Get("testcaching");
Assert.NotNull(testcaching1);
var result2 = select.Where(a => 1 == 1).Caching(20, "testcaching").ToList();
var testcaching2 = g.sqlite3.Cache.Get("testcaching");
var testcaching2 = g.sqlite.Cache.Get("testcaching");
Assert.NotNull(testcaching2);
Assert.Equal(result1.Count, result1.Count);
}
@ -142,9 +142,9 @@ namespace FreeSql.Tests.Sqlite3 {
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\"", sql);
query.ToList();
query = select.LeftJoin("\"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\" and b.\"Name\" = :bname", new { bname = "xxx" });
query = select.LeftJoin("\"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\" and b.\"Name\" = @bname", new { bname = "xxx" });
sql = query.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\" and b.\"Name\" = :bname", sql);
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\" and b.\"Name\" = @bname", sql);
query.ToList();
}
[Fact]
@ -210,79 +210,79 @@ namespace FreeSql.Tests.Sqlite3 {
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a INNER JOIN \"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\"", sql);
query.ToList();
query = select.InnerJoin("\"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\" and b.\"Name\" = :bname", new { bname = "xxx" });
query = select.InnerJoin("\"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\" and b.\"Name\" = @bname", new { bname = "xxx" });
sql = query.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a INNER JOIN \"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\" and b.\"Name\" = :bname", sql);
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a INNER JOIN \"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\" and b.\"Name\" = @bname", sql);
query.ToList();
}
[Fact]
public void RightJoin() {
//<2F><><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a.Type<70><65>a.Type.Parent <20><><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var query = select.RightJoin(a => a.Type.Guid == a.TestTypeInfoGuid);
var sql = query.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", 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.\"TestTypeInfoGuid\"", sql);
query.ToList();
////<2F><><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a.Type<70><65>a.Type.Parent <20><><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//var query = select.RightJoin(a => a.Type.Guid == a.TestTypeInfoGuid);
//var sql = query.ToSql().Replace("\r\n", "");
//Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", 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.\"TestTypeInfoGuid\"", sql);
//query.ToList();
query = select.RightJoin(a => a.Type.Guid == a.TestTypeInfoGuid && a.Type.Name == "xxx");
sql = query.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", 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.\"TestTypeInfoGuid\" AND a__Type.\"Name\" = 'xxx'", sql);
query.ToList();
//query = select.RightJoin(a => a.Type.Guid == a.TestTypeInfoGuid && a.Type.Name == "xxx");
//sql = query.ToSql().Replace("\r\n", "");
//Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", 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.\"TestTypeInfoGuid\" AND a__Type.\"Name\" = 'xxx'", sql);
//query.ToList();
query = select.RightJoin(a => a.Type.Guid == a.TestTypeInfoGuid && 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.\"TestTypeInfoGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeParentInfo\" a__Type__Parent ON 1 = 1 RIGHT JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TestTypeInfoGuid\" AND a__Type.\"Name\" = 'xxx' WHERE (a__Type__Parent.\"Id\" = 10)", sql);
query.ToList();
//query = select.RightJoin(a => a.Type.Guid == a.TestTypeInfoGuid && 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.\"TestTypeInfoGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeParentInfo\" a__Type__Parent ON 1 = 1 RIGHT JOIN \"TestTypeInfo\" a__Type ON a__Type.\"Guid\" = a.\"TestTypeInfoGuid\" AND a__Type.\"Name\" = 'xxx' WHERE (a__Type__Parent.\"Id\" = 10)", sql);
//query.ToList();
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid);
sql = query.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", b.\"Guid\", b.\"ParentId\", b.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a RIGHT JOIN \"TestTypeInfo\" b ON b.\"Guid\" = a.\"TestTypeInfoGuid\"", sql);
query.ToList();
////<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid);
//sql = query.ToSql().Replace("\r\n", "");
//Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", b.\"Guid\", b.\"ParentId\", b.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a RIGHT JOIN \"TestTypeInfo\" b ON b.\"Guid\" = a.\"TestTypeInfoGuid\"", sql);
//query.ToList();
query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid && b.Name == "xxx");
sql = query.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", b.\"Guid\", b.\"ParentId\", b.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a RIGHT JOIN \"TestTypeInfo\" b ON b.\"Guid\" = a.\"TestTypeInfoGuid\" AND b.\"Name\" = 'xxx'", sql);
query.ToList();
//query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid && b.Name == "xxx");
//sql = query.ToSql().Replace("\r\n", "");
//Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", b.\"Guid\", b.\"ParentId\", b.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a RIGHT JOIN \"TestTypeInfo\" b ON b.\"Guid\" = a.\"TestTypeInfoGuid\" AND b.\"Name\" = 'xxx'", sql);
//query.ToList();
query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
sql = query.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", b.\"Guid\", b.\"ParentId\", b.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeParentInfo\" b__Parent ON 1 = 1 RIGHT JOIN \"TestTypeInfo\" b ON b.\"Guid\" = a.\"TestTypeInfoGuid\" AND b.\"Name\" = 'xxx' WHERE (b__Parent.\"Id\" = 10)", sql);
query.ToList();
//query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
//sql = query.ToSql().Replace("\r\n", "");
//Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", b.\"Guid\", b.\"ParentId\", b.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a LEFT JOIN \"TestTypeParentInfo\" b__Parent ON 1 = 1 RIGHT JOIN \"TestTypeInfo\" b ON b.\"Guid\" = a.\"TestTypeInfoGuid\" AND b.\"Name\" = 'xxx' WHERE (b__Parent.\"Id\" = 10)", sql);
//query.ToList();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
query = select
.RightJoin(a => a.Type.Guid == a.TestTypeInfoGuid)
.RightJoin(a => a.Type.Parent.Id == a.Type.ParentId);
sql = query.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", 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.\"TestTypeInfoGuid\" RIGHT JOIN \"TestTypeParentInfo\" a__Type__Parent ON a__Type__Parent.\"Id\" = a__Type.\"ParentId\"", sql);
query.ToList();
////<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//query = select
// .RightJoin(a => a.Type.Guid == a.TestTypeInfoGuid)
// .RightJoin(a => a.Type.Parent.Id == a.Type.ParentId);
//sql = query.ToSql().Replace("\r\n", "");
//Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", 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.\"TestTypeInfoGuid\" RIGHT JOIN \"TestTypeParentInfo\" a__Type__Parent ON a__Type__Parent.\"Id\" = a__Type.\"ParentId\"", sql);
//query.ToList();
query = select
.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid)
.RightJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId);
sql = query.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", b.\"Guid\", b.\"ParentId\", b.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a RIGHT JOIN \"TestTypeInfo\" b ON b.\"Guid\" = a.\"TestTypeInfoGuid\" RIGHT JOIN \"TestTypeParentInfo\" c ON c.\"Id\" = b.\"ParentId\"", sql);
query.ToList();
//query = select
// .RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid)
// .RightJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId);
//sql = query.ToSql().Replace("\r\n", "");
//Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", b.\"Guid\", b.\"ParentId\", b.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a RIGHT JOIN \"TestTypeInfo\" b ON b.\"Guid\" = a.\"TestTypeInfoGuid\" RIGHT JOIN \"TestTypeParentInfo\" c ON c.\"Id\" = b.\"ParentId\"", sql);
//query.ToList();
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
var query2 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
.RightJoin(a => a.TestTypeInfoGuid == b.Guid)
.RightJoin(a => b.ParentId == c.Id));
sql = query2.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", b.\"Guid\", b.\"ParentId\", b.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a RIGHT JOIN \"TestTypeInfo\" b ON a.\"TestTypeInfoGuid\" = b.\"Guid\" RIGHT JOIN \"TestTypeParentInfo\" c ON b.\"ParentId\" = c.\"Id\"", sql);
query2.ToList();
////<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
//var query2 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
// .RightJoin(a => a.TestTypeInfoGuid == b.Guid)
// .RightJoin(a => b.ParentId == c.Id));
//sql = query2.ToSql().Replace("\r\n", "");
//Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", b.\"Guid\", b.\"ParentId\", b.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a RIGHT JOIN \"TestTypeInfo\" b ON a.\"TestTypeInfoGuid\" = b.\"Guid\" RIGHT JOIN \"TestTypeParentInfo\" c ON b.\"ParentId\" = c.\"Id\"", sql);
//query2.ToList();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><E3B2BB>
query = select.RightJoin("\"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\"");
sql = query.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a RIGHT JOIN \"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\"", sql);
query.ToList();
////<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><E3B2BB>
//query = select.RightJoin("\"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\"");
//sql = query.ToSql().Replace("\r\n", "");
//Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a RIGHT JOIN \"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\"", sql);
//query.ToList();
query = select.RightJoin("\"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\" and b.\"Name\" = :bname", new { bname = "xxx" });
sql = query.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a RIGHT JOIN \"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\" and b.\"Name\" = :bname", sql);
query.ToList();
//query = select.RightJoin("\"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\" and b.\"Name\" = @bname", new { bname = "xxx" });
//sql = query.ToSql().Replace("\r\n", "");
//Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a RIGHT JOIN \"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\" and b.\"Name\" = @bname", sql);
//query.ToList();
}
[Fact]
@ -343,9 +343,9 @@ namespace FreeSql.Tests.Sqlite3 {
query2.ToList();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><E3B2BB>
query = select.Where("a.\"Clicks\" > 100 and a.\"Id\" = :id", new { id = 10 });
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.\"TestTypeInfoGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a WHERE (a.\"Clicks\" > 100 and a.\"Id\" = :id)", sql);
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a WHERE (a.\"Clicks\" > 100 and a.\"Id\" = @id)", sql);
query.ToList();
}
[Fact]
@ -390,9 +390,9 @@ namespace FreeSql.Tests.Sqlite3 {
query2.ToList();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><E3B2BB>
query = select.WhereIf(true, "a.\"Clicks\" > 100 and a.\"Id\" = :id", new { id = 10 });
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.\"TestTypeInfoGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a WHERE (a.\"Clicks\" > 100 and a.\"Id\" = :id)", sql);
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a WHERE (a.\"Clicks\" > 100 and a.\"Id\" = @id)", sql);
query.ToList();
// ==========================================WhereIf(false)
@ -437,7 +437,7 @@ namespace FreeSql.Tests.Sqlite3 {
query2.ToList();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><E3B2BB>
query = select.WhereIf(false, "a.\"Clicks\" > 100 and a.\"Id\" = :id", new { id = 10 });
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.\"TestTypeInfoGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a", sql);
query.ToList();

View File

@ -3,9 +3,9 @@ using System;
using System.Collections.Generic;
using Xunit;
namespace FreeSql.Tests.Sqlite3 {
namespace FreeSql.Tests.Sqlite {
public class SqliteUpdateTest {
IUpdate<Topic> update => g.sqlite3.Update<Topic>();
IUpdate<Topic> update => g.sqlite.Update<Topic>();
[Table(Name = "tb_topic")]
class Topic {
@ -19,52 +19,52 @@ namespace FreeSql.Tests.Sqlite3 {
[Fact]
public void Dywhere() {
Assert.Null(g.sqlite3.Update<Topic>().ToSql());
Assert.Equal("UPDATE \"tb_topic\" SET title='test' \r\nWHERE (\"Id\" = 1 OR \"Id\" = 2)", g.sqlite3.Update<Topic>(new[] { 1, 2 }).SetRaw("title='test'").ToSql());
Assert.Equal("UPDATE \"tb_topic\" SET title='test1' \r\nWHERE (\"Id\" = 1)", g.sqlite3.Update<Topic>(new Topic { Id = 1, Title = "test" }).SetRaw("title='test1'").ToSql());
Assert.Equal("UPDATE \"tb_topic\" SET title='test1' \r\nWHERE (\"Id\" = 1 OR \"Id\" = 2)", g.sqlite3.Update<Topic>(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.sqlite3.Update<Topic>(new { id = 1 }).SetRaw("title='test1'").ToSql());
Assert.Null(g.sqlite.Update<Topic>().ToSql());
Assert.Equal("UPDATE \"tb_topic\" SET title='test' \r\nWHERE (\"Id\" = 1 OR \"Id\" = 2)", g.sqlite.Update<Topic>(new[] { 1, 2 }).SetRaw("title='test'").ToSql());
Assert.Equal("UPDATE \"tb_topic\" SET title='test1' \r\nWHERE (\"Id\" = 1)", g.sqlite.Update<Topic>(new Topic { Id = 1, Title = "test" }).SetRaw("title='test1'").ToSql());
Assert.Equal("UPDATE \"tb_topic\" SET title='test1' \r\nWHERE (\"Id\" = 1 OR \"Id\" = 2)", g.sqlite.Update<Topic>(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.sqlite.Update<Topic>(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\" = :p_0, \"Title\" = :p_1, \"CreateTime\" = :p_2 WHERE (\"Id\" = 1)", sql);
Assert.Equal("UPDATE \"tb_topic\" SET \"Clicks\" = @p_0, \"Title\" = @p_1, \"CreateTime\" = @p_2 WHERE (\"Id\" = 1)", sql);
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
sql = update.SetSource(items).ToSql().Replace("\r\n", "");
Assert.Equal("UPDATE \"tb_topic\" SET \"Clicks\" = CASE \"Id\" WHEN 1 THEN :p_0 WHEN 2 THEN :p_1 WHEN 3 THEN :p_2 WHEN 4 THEN :p_3 WHEN 5 THEN :p_4 WHEN 6 THEN :p_5 WHEN 7 THEN :p_6 WHEN 8 THEN :p_7 WHEN 9 THEN :p_8 WHEN 10 THEN :p_9 END, \"Title\" = CASE \"Id\" WHEN 1 THEN :p_10 WHEN 2 THEN :p_11 WHEN 3 THEN :p_12 WHEN 4 THEN :p_13 WHEN 5 THEN :p_14 WHEN 6 THEN :p_15 WHEN 7 THEN :p_16 WHEN 8 THEN :p_17 WHEN 9 THEN :p_18 WHEN 10 THEN :p_19 END, \"CreateTime\" = CASE \"Id\" WHEN 1 THEN :p_20 WHEN 2 THEN :p_21 WHEN 3 THEN :p_22 WHEN 4 THEN :p_23 WHEN 5 THEN :p_24 WHEN 6 THEN :p_25 WHEN 7 THEN :p_26 WHEN 8 THEN :p_27 WHEN 9 THEN :p_28 WHEN 10 THEN :p_29 END WHERE (\"Id\" IN (1,2,3,4,5,6,7,8,9,10))", sql);
Assert.Equal("UPDATE \"tb_topic\" SET \"Clicks\" = CASE \"Id\" WHEN 1 THEN @p_0 WHEN 2 THEN @p_1 WHEN 3 THEN @p_2 WHEN 4 THEN @p_3 WHEN 5 THEN @p_4 WHEN 6 THEN @p_5 WHEN 7 THEN @p_6 WHEN 8 THEN @p_7 WHEN 9 THEN @p_8 WHEN 10 THEN @p_9 END, \"Title\" = CASE \"Id\" WHEN 1 THEN @p_10 WHEN 2 THEN @p_11 WHEN 3 THEN @p_12 WHEN 4 THEN @p_13 WHEN 5 THEN @p_14 WHEN 6 THEN @p_15 WHEN 7 THEN @p_16 WHEN 8 THEN @p_17 WHEN 9 THEN @p_18 WHEN 10 THEN @p_19 END, \"CreateTime\" = CASE \"Id\" WHEN 1 THEN @p_20 WHEN 2 THEN @p_21 WHEN 3 THEN @p_22 WHEN 4 THEN @p_23 WHEN 5 THEN @p_24 WHEN 6 THEN @p_25 WHEN 7 THEN @p_26 WHEN 8 THEN @p_27 WHEN 9 THEN @p_28 WHEN 10 THEN @p_29 END 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 :p_0 WHEN 2 THEN :p_1 WHEN 3 THEN :p_2 WHEN 4 THEN :p_3 WHEN 5 THEN :p_4 WHEN 6 THEN :p_5 WHEN 7 THEN :p_6 WHEN 8 THEN :p_7 WHEN 9 THEN :p_8 WHEN 10 THEN :p_9 END WHERE (\"Id\" IN (1,2,3,4,5,6,7,8,9,10))", sql);
Assert.Equal("UPDATE \"tb_topic\" SET \"Title\" = CASE \"Id\" WHEN 1 THEN @p_0 WHEN 2 THEN @p_1 WHEN 3 THEN @p_2 WHEN 4 THEN @p_3 WHEN 5 THEN @p_4 WHEN 6 THEN @p_5 WHEN 7 THEN @p_6 WHEN 8 THEN @p_7 WHEN 9 THEN @p_8 WHEN 10 THEN @p_9 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\" = :p_0 WHERE (\"Id\" IN (1,2,3,4,5,6,7,8,9,10))", sql);
Assert.Equal("UPDATE \"tb_topic\" SET \"CreateTime\" = @p_0 WHERE (\"Id\" IN (1,2,3,4,5,6,7,8,9,10))", sql);
}
[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\" = :p_0 WHERE (\"Id\" = 1)", sql);
Assert.Equal("UPDATE \"tb_topic\" SET \"Title\" = @p_0 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\" = :p_0 WHERE (\"Id\" = 1)", sql);
Assert.Equal("UPDATE \"tb_topic\" SET \"Title\" = @p_0 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\" = :p_0, \"CreateTime\" = :p_1 WHERE (\"Id\" = 1)", sql);
Assert.Equal("UPDATE \"tb_topic\" SET \"Title\" = @p_0, \"CreateTime\" = @p_1 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\" = nvl(\"Clicks\", 0) * 10 / 1 WHERE (\"Id\" = 1)", sql);
Assert.Equal("UPDATE \"tb_topic\" SET \"Clicks\" = ifnull(\"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\" = nvl(\"Clicks\", 0) * 10 / 1 WHERE (\"Id\" = 1)", sql);
Assert.Equal("UPDATE \"tb_topic\" SET \"Clicks\" = ifnull(\"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);

View File

@ -2,21 +2,21 @@ using FreeSql.DataAnnotations;
using System;
using Xunit;
namespace FreeSql.Tests.Sqlite3 {
namespace FreeSql.Tests.Sqlite {
public class SqliteAdoTest {
[Fact]
public void Pool() {
var t1 = g.sqlite3.Ado.MasterPool.StatisticsFullily;
var t1 = g.sqlite.Ado.MasterPool.StatisticsFullily;
}
[Fact]
public void SlavePools() {
var t2 = g.sqlite3.Ado.SlavePools.Count;
var t2 = g.sqlite.Ado.SlavePools.Count;
}
[Fact]
public void IsTracePerformance() {
Assert.True(g.sqlite3.Ado.IsTracePerformance);
Assert.True(g.sqlite.Ado.IsTracePerformance);
}
[Fact]
@ -38,11 +38,11 @@ namespace FreeSql.Tests.Sqlite3 {
[Fact]
public void Query() {
var t3 = g.sqlite3.Ado.Query<xxx>("select * from \"song\"");
var t3 = g.sqlite.Ado.Query<xxx>("select * from \"song\"");
var t4 = g.sqlite3.Ado.Query<(int, string, string)>("select * from \"song\"");
var t4 = g.sqlite.Ado.Query<(int, string, string)>("select * from \"song\"");
var t5 = g.sqlite3.Ado.Query<dynamic>("select * from \"song\"");
var t5 = g.sqlite.Ado.Query<dynamic>("select * from \"song\"");
}
class xxx {

View File

@ -6,16 +6,16 @@ using System.Linq;
using System.Text;
using Xunit;
namespace FreeSql.Tests.Sqlite3 {
namespace FreeSql.Tests.Sqlite {
public class SqliteCodeFirstTest {
[Fact]
public void AddField() {
var sql = g.sqlite3.CodeFirst.GetComparisonDDLStatements<TopicAddField>();
var sql = g.sqlite.CodeFirst.GetComparisonDDLStatements<TopicAddField>();
var id = g.sqlite3.Insert<TopicAddField>().AppendData(new TopicAddField { }).ExecuteIdentity();
var id = g.sqlite.Insert<TopicAddField>().AppendData(new TopicAddField { }).ExecuteIdentity();
//var inserted = g.sqlite3.Insert<TopicAddField>().AppendData(new TopicAddField { }).ExecuteInserted();
//var inserted = g.Sqlite.Insert<TopicAddField>().AppendData(new TopicAddField { }).ExecuteInserted();
}
[Table(Name = "xxxtb.TopicAddField", OldName = "TopicAddField")]
@ -32,62 +32,58 @@ namespace FreeSql.Tests.Sqlite3 {
[Fact]
public void GetComparisonDDLStatements() {
var sql = g.sqlite3.CodeFirst.GetComparisonDDLStatements<TableAllType>();
var sql = g.sqlite.CodeFirst.GetComparisonDDLStatements<TableAllType>();
if (string.IsNullOrEmpty(sql) == false) {
Assert.Equal(@"CREATE TABLE IF NOT EXISTS `cccddd`.`tb_alltype` (
`Id` INT(11) NOT NULL AUTO_INCREMENT,
`Bool` BIT(1) NOT NULL,
`SByte` TINYINT(3) NOT NULL,
`Short` SMALLINT(6) NOT NULL,
`Int` INT(11) NOT NULL,
`Long` BIGINT(20) NOT NULL,
`Byte` TINYINT(3) UNSIGNED NOT NULL,
`UShort` SMALLINT(5) UNSIGNED NOT NULL,
`UInt` INT(10) UNSIGNED NOT NULL,
`ULong` BIGINT(20) UNSIGNED NOT NULL,
`Double` DOUBLE NOT NULL,
`Float` FLOAT NOT NULL,
`Decimal` DECIMAL(10,2) NOT NULL,
`TimeSpan` TIME NOT NULL,
`DateTime` DATETIME NOT NULL,
`Bytes` VARBINARY(255),
`String` VARCHAR(255),
`Guid` VARCHAR(36),
`BoolNullable` BIT(1),
`SByteNullable` TINYINT(3),
`ShortNullable` SMALLINT(6),
`IntNullable` INT(11),
`testFielLongNullable` BIGINT(20),
`ByteNullable` TINYINT(3) UNSIGNED,
`UShortNullable` SMALLINT(5) UNSIGNED,
`UIntNullable` INT(10) UNSIGNED,
`ULongNullable` BIGINT(20) UNSIGNED,
`DoubleNullable` DOUBLE,
`FloatNullable` FLOAT,
`DecimalNullable` DECIMAL(10,2),
`TimeSpanNullable` TIME,
`DateTimeNullable` DATETIME,
`GuidNullable` VARCHAR(36),
`Point` POINT,
`LineString` LINESTRING,
`Polygon` POLYGON,
`MultiPoint` MULTIPOINT,
`MultiLineString` MULTILINESTRING,
`MultiPolygon` MULTIPOLYGON,
`Enum1` ENUM('E1','E2','E3') NOT NULL,
`Enum1Nullable` ENUM('E1','E2','E3'),
`Enum2` SET('F1','F2','F3') NOT NULL,
`Enum2Nullable` SET('F1','F2','F3'),
PRIMARY KEY (`Id`)
) Engine=InnoDB CHARACTER SET utf8;
Assert.Equal(@"CREATE TABLE IF NOT EXISTS ""main"".""tb_alltype"" (
""Id"" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
""Bool"" BOOLEAN NOT NULL,
""SByte"" SMALLINT NOT NULL,
""Short"" SMALLINT NOT NULL,
""Int"" INTEGER NOT NULL,
""Long"" INTEGER NOT NULL,
""Byte"" INT2 NOT NULL,
""UShort"" UNSIGNED NOT NULL,
""UInt"" DECIMAL(10,0) NOT NULL,
""ULong"" DECIMAL(21,0) NOT NULL,
""Double"" DOUBLE NOT NULL,
""Float"" FLOAT NOT NULL,
""Decimal"" DECIMAL(10,2) NOT NULL,
""TimeSpan"" BIGINT NOT NULL,
""DateTime"" DATETIME NOT NULL,
""DateTimeOffSet"" DATETIME NOT NULL,
""Bytes"" BLOB,
""String"" NVARCHAR(255),
""Guid"" CHARACTER(36) NOT NULL,
""BoolNullable"" BOOLEAN,
""SByteNullable"" SMALLINT,
""ShortNullable"" SMALLINT,
""IntNullable"" INTEGER,
""testFielLongNullable"" INTEGER,
""ByteNullable"" INT2,
""UShortNullable"" UNSIGNED,
""UIntNullable"" DECIMAL(10,0),
""ULongNullable"" DECIMAL(21,0),
""DoubleNullable"" DOUBLE,
""FloatNullable"" FLOAT,
""DecimalNullable"" DECIMAL(10,2),
""TimeSpanNullable"" BIGINT,
""DateTimeNullable"" DATETIME,
""DateTimeOffSetNullable"" DATETIME,
""GuidNullable"" CHARACTER(36),
""Enum1"" MEDIUMINT NOT NULL,
""Enum1Nullable"" MEDIUMINT,
""Enum2"" BIGINT NOT NULL,
""Enum2Nullable"" BIGINT
)
;
", sql);
}
//sql = g.sqlite3.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
//sql = g.Sqlite.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
}
IInsert<TableAllType> insert => g.sqlite3.Insert<TableAllType>();
ISelect<TableAllType> select => g.sqlite3.Select<TableAllType>();
IInsert<TableAllType> insert => g.sqlite.Insert<TableAllType>();
ISelect<TableAllType> select => g.sqlite.Select<TableAllType>();
[Fact]
public void CurdAllField() {

View File

@ -4,10 +4,10 @@ using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.Sqlite3Expression {
namespace FreeSql.Tests.SqliteExpression {
public class ConvertTest {
ISelect<Topic> select => g.sqlite3.Select<Topic>();
ISelect<Topic> select => g.sqlite.Select<Topic>();
[Table(Name = "tb_topic")]
class Topic {

View File

@ -4,10 +4,10 @@ using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.Sqlite3Expression {
namespace FreeSql.Tests.SqliteExpression {
public class DateTimeTest {
ISelect<Topic> select => g.sqlite3.Select<Topic>();
ISelect<Topic> select => g.sqlite.Select<Topic>();
[Table(Name = "tb_topic111333")]
class Topic {

View File

@ -4,10 +4,10 @@ using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.Sqlite3Expression {
namespace FreeSql.Tests.SqliteExpression {
public class MathTest {
ISelect<Topic> select => g.sqlite3.Select<Topic>();
ISelect<Topic> select => g.sqlite.Select<Topic>();
[Table(Name = "tb_topic")]
class Topic {
@ -126,7 +126,7 @@ namespace FreeSql.Tests.Sqlite3Expression {
[Fact]
public void Truncate() {
var data = new List<object>();
data.Add(select.Where(a => Math.Truncate(a.Clicks * 1.0 / 3) == a.Clicks + 1).ToList());
//data.Add(select.Where(a => Math.Truncate(a.Clicks * 1.0 / 3) == a.Clicks + 1).ToList());
}
}
}

View File

@ -3,10 +3,10 @@ using System;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.Sqlite3Expression {
namespace FreeSql.Tests.SqliteExpression {
public class OtherTest {
ISelect<TableAllType> select => g.sqlite3.Select<TableAllType>();
ISelect<TableAllType> select => g.sqlite.Select<TableAllType>();
public OtherTest() {
}

View File

@ -4,10 +4,10 @@ using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.Sqlite3Expression {
namespace FreeSql.Tests.SqliteExpression {
public class StringTest {
ISelect<Topic> select => g.sqlite3.Select<Topic>();
ISelect<Topic> select => g.sqlite.Select<Topic>();
[Table(Name = "tb_topic")]
class Topic {
@ -379,87 +379,87 @@ namespace FreeSql.Tests.Sqlite3Expression {
}
[Fact]
public void PadLeft() {
var data = new List<object>();
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.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (lpad(a.`Title`, 10, 'a') = 'aaa');
//var data = new List<object>();
//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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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`)
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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<object>();
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.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic` a
//WHERE (rpad(a.`Title`, 10, 'a') = 'aaa');
//var data = new List<object>();
//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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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.`TestTypeInfoGuid` 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`)
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` 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() {

View File

@ -4,10 +4,10 @@ using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.Sqlite3Expression {
namespace FreeSql.Tests.SqliteExpression {
public class TimeSpanTest {
ISelect<Topic> select => g.sqlite3.Select<Topic>();
ISelect<Topic> select => g.sqlite.Select<Topic>();
[Table(Name = "tb_topic")]
class Topic {

View File

@ -1,173 +0,0 @@
using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.Sqlite3 {
public class SqliteInsertTest {
IInsert<Topic> insert => g.sqlite3.Insert<Topic>(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
[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 AppendData() {
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
var data = new List<object>();
var sql = insert.AppendData(items.First()).ToSql();
Assert.Equal("INSERT INTO \"tb_topic\"(\"Clicks\", \"Title\", \"CreateTime\") VALUES(:Clicks0, :Title0, :CreateTime0)", sql);
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
sql = insert.AppendData(items).ToSql();
Assert.Equal(@"INSERT ALL
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks0, :Title0, :CreateTime0)
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks1, :Title1, :CreateTime1)
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks2, :Title2, :CreateTime2)
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks3, :Title3, :CreateTime3)
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks4, :Title4, :CreateTime4)
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks5, :Title5, :CreateTime5)
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks6, :Title6, :CreateTime6)
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks7, :Title7, :CreateTime7)
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks8, :Title8, :CreateTime8)
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks9, :Title9, :CreateTime9)
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""(""Title"") VALUES(:Title0)
INTO ""tb_topic""(""Title"") VALUES(:Title1)
INTO ""tb_topic""(""Title"") VALUES(:Title2)
INTO ""tb_topic""(""Title"") VALUES(:Title3)
INTO ""tb_topic""(""Title"") VALUES(:Title4)
INTO ""tb_topic""(""Title"") VALUES(:Title5)
INTO ""tb_topic""(""Title"") VALUES(:Title6)
INTO ""tb_topic""(""Title"") VALUES(:Title7)
INTO ""tb_topic""(""Title"") VALUES(:Title8)
INTO ""tb_topic""(""Title"") VALUES(:Title9)
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""(""Clicks"", ""Title"") VALUES(:Clicks0, :Title0)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks1, :Title1)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks2, :Title2)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks3, :Title3)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks4, :Title4)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks5, :Title5)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks6, :Title6)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks7, :Title7)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks8, :Title8)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks9, :Title9)
SELECT 1 FROM DUAL", sql);
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
}
[Fact]
public void InsertColumns() {
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
var data = new List<object>();
var sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
Assert.Equal(@"INSERT ALL
INTO ""tb_topic""(""Title"") VALUES(:Title0)
INTO ""tb_topic""(""Title"") VALUES(:Title1)
INTO ""tb_topic""(""Title"") VALUES(:Title2)
INTO ""tb_topic""(""Title"") VALUES(:Title3)
INTO ""tb_topic""(""Title"") VALUES(:Title4)
INTO ""tb_topic""(""Title"") VALUES(:Title5)
INTO ""tb_topic""(""Title"") VALUES(:Title6)
INTO ""tb_topic""(""Title"") VALUES(:Title7)
INTO ""tb_topic""(""Title"") VALUES(:Title8)
INTO ""tb_topic""(""Title"") VALUES(:Title9)
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""(""Clicks"", ""Title"") VALUES(:Clicks0, :Title0)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks1, :Title1)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks2, :Title2)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks3, :Title3)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks4, :Title4)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks5, :Title5)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks6, :Title6)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks7, :Title7)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks8, :Title8)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks9, :Title9)
SELECT 1 FROM DUAL", sql);
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
}
[Fact]
public void IgnoreColumns() {
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
var data = new List<object>();
var sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql();
Assert.Equal(@"INSERT ALL
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks0, :Title0)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks1, :Title1)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks2, :Title2)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks3, :Title3)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks4, :Title4)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks5, :Title5)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks6, :Title6)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks7, :Title7)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks8, :Title8)
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks9, :Title9)
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""(""Clicks"") VALUES(:Clicks0)
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks1)
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks2)
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks3)
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks4)
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks5)
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks6)
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks7)
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks8)
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks9)
SELECT 1 FROM DUAL", sql);
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
}
[Fact]
public void ExecuteAffrows() {
var items = new List<Topic>();
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, 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<Topic>();
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<Topic>();
//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();
}
}
}

View File

@ -34,8 +34,8 @@ public class g {
.UseAutoSyncStructure(true)
.Build();
public static IFreeSql sqlite3 = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.Sqlite3, @"Data Source=|DataDirectory|\document.db;Attachs=xxxtb.db;Pooling=true;Max Pool Size=10")
public static IFreeSql sqlite = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\document.db;Attachs=xxxtb.db;Pooling=true;Max Pool Size=10")
.UseAutoSyncStructure(true)
.Build();
}