mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
完成 sqlite codefirst curd expression 开发与测试
This commit is contained in:
parent
40f6e53edd
commit
27bc603d46
@ -66,7 +66,7 @@ namespace FreeSql.Tests.MySql {
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ExecuteDeleted() {
|
public void ExecuteDeleted() {
|
||||||
|
|
||||||
delete.Where(a => a.Id > 0).ExecuteDeleted();
|
//delete.Where(a => a.Id > 0).ExecuteDeleted();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ namespace FreeSql.Tests.MySql {
|
|||||||
var items = new List<Topic>();
|
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 });
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ namespace FreeSql.Tests.Oracle {
|
|||||||
|
|
||||||
IInsert<Topic> insert => g.oracle.Insert<Topic>(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
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 {
|
class Topic {
|
||||||
[Column(IsIdentity = true, IsPrimary = true)]
|
[Column(IsIdentity = true, IsPrimary = true)]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
@ -26,51 +26,51 @@ namespace FreeSql.Tests.Oracle {
|
|||||||
|
|
||||||
var data = new List<object>();
|
var data = new List<object>();
|
||||||
var sql = insert.AppendData(items.First()).ToSql();
|
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());
|
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
||||||
|
|
||||||
sql = insert.AppendData(items).ToSql();
|
sql = insert.AppendData(items).ToSql();
|
||||||
Assert.Equal(@"INSERT ALL
|
Assert.Equal(@"INSERT ALL
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks0, :Title0, :CreateTime0)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks0, :Title0, :CreateTime0)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks1, :Title1, :CreateTime1)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks1, :Title1, :CreateTime1)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks2, :Title2, :CreateTime2)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks2, :Title2, :CreateTime2)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks3, :Title3, :CreateTime3)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks3, :Title3, :CreateTime3)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks4, :Title4, :CreateTime4)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks4, :Title4, :CreateTime4)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks5, :Title5, :CreateTime5)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks5, :Title5, :CreateTime5)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks6, :Title6, :CreateTime6)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks6, :Title6, :CreateTime6)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks7, :Title7, :CreateTime7)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks7, :Title7, :CreateTime7)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"", ""CreateTime"") VALUES(:Clicks8, :Title8, :CreateTime8)
|
INTO ""tb_topic_insert""(""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(:Clicks9, :Title9, :CreateTime9)
|
||||||
SELECT 1 FROM DUAL", sql);
|
SELECT 1 FROM DUAL", sql);
|
||||||
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
||||||
|
|
||||||
sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
|
sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
|
||||||
Assert.Equal(@"INSERT ALL
|
Assert.Equal(@"INSERT ALL
|
||||||
INTO ""tb_topic""(""Title"") VALUES(:Title0)
|
INTO ""tb_topic_insert""(""Title"") VALUES(:Title0)
|
||||||
INTO ""tb_topic""(""Title"") VALUES(:Title1)
|
INTO ""tb_topic_insert""(""Title"") VALUES(:Title1)
|
||||||
INTO ""tb_topic""(""Title"") VALUES(:Title2)
|
INTO ""tb_topic_insert""(""Title"") VALUES(:Title2)
|
||||||
INTO ""tb_topic""(""Title"") VALUES(:Title3)
|
INTO ""tb_topic_insert""(""Title"") VALUES(:Title3)
|
||||||
INTO ""tb_topic""(""Title"") VALUES(:Title4)
|
INTO ""tb_topic_insert""(""Title"") VALUES(:Title4)
|
||||||
INTO ""tb_topic""(""Title"") VALUES(:Title5)
|
INTO ""tb_topic_insert""(""Title"") VALUES(:Title5)
|
||||||
INTO ""tb_topic""(""Title"") VALUES(:Title6)
|
INTO ""tb_topic_insert""(""Title"") VALUES(:Title6)
|
||||||
INTO ""tb_topic""(""Title"") VALUES(:Title7)
|
INTO ""tb_topic_insert""(""Title"") VALUES(:Title7)
|
||||||
INTO ""tb_topic""(""Title"") VALUES(:Title8)
|
INTO ""tb_topic_insert""(""Title"") VALUES(:Title8)
|
||||||
INTO ""tb_topic""(""Title"") VALUES(:Title9)
|
INTO ""tb_topic_insert""(""Title"") VALUES(:Title9)
|
||||||
SELECT 1 FROM DUAL", sql);
|
SELECT 1 FROM DUAL", sql);
|
||||||
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
||||||
|
|
||||||
sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql();
|
sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql();
|
||||||
Assert.Equal(@"INSERT ALL
|
Assert.Equal(@"INSERT ALL
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks0, :Title0)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks0, :Title0)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks1, :Title1)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks1, :Title1)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks2, :Title2)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks2, :Title2)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks3, :Title3)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks3, :Title3)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks4, :Title4)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks4, :Title4)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks5, :Title5)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks5, :Title5)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks6, :Title6)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks6, :Title6)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks7, :Title7)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks7, :Title7)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks8, :Title8)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks8, :Title8)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks9, :Title9)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks9, :Title9)
|
||||||
SELECT 1 FROM DUAL", sql);
|
SELECT 1 FROM DUAL", sql);
|
||||||
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
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 data = new List<object>();
|
||||||
var sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
|
var sql = insert.AppendData(items).InsertColumns(a => a.Title).ToSql();
|
||||||
Assert.Equal(@"INSERT ALL
|
Assert.Equal(@"INSERT ALL
|
||||||
INTO ""tb_topic""(""Title"") VALUES(:Title0)
|
INTO ""tb_topic_insert""(""Title"") VALUES(:Title0)
|
||||||
INTO ""tb_topic""(""Title"") VALUES(:Title1)
|
INTO ""tb_topic_insert""(""Title"") VALUES(:Title1)
|
||||||
INTO ""tb_topic""(""Title"") VALUES(:Title2)
|
INTO ""tb_topic_insert""(""Title"") VALUES(:Title2)
|
||||||
INTO ""tb_topic""(""Title"") VALUES(:Title3)
|
INTO ""tb_topic_insert""(""Title"") VALUES(:Title3)
|
||||||
INTO ""tb_topic""(""Title"") VALUES(:Title4)
|
INTO ""tb_topic_insert""(""Title"") VALUES(:Title4)
|
||||||
INTO ""tb_topic""(""Title"") VALUES(:Title5)
|
INTO ""tb_topic_insert""(""Title"") VALUES(:Title5)
|
||||||
INTO ""tb_topic""(""Title"") VALUES(:Title6)
|
INTO ""tb_topic_insert""(""Title"") VALUES(:Title6)
|
||||||
INTO ""tb_topic""(""Title"") VALUES(:Title7)
|
INTO ""tb_topic_insert""(""Title"") VALUES(:Title7)
|
||||||
INTO ""tb_topic""(""Title"") VALUES(:Title8)
|
INTO ""tb_topic_insert""(""Title"") VALUES(:Title8)
|
||||||
INTO ""tb_topic""(""Title"") VALUES(:Title9)
|
INTO ""tb_topic_insert""(""Title"") VALUES(:Title9)
|
||||||
SELECT 1 FROM DUAL", sql);
|
SELECT 1 FROM DUAL", sql);
|
||||||
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
||||||
|
|
||||||
sql = insert.AppendData(items).InsertColumns(a =>new { a.Title, a.Clicks }).ToSql();
|
sql = insert.AppendData(items).InsertColumns(a =>new { a.Title, a.Clicks }).ToSql();
|
||||||
Assert.Equal(@"INSERT ALL
|
Assert.Equal(@"INSERT ALL
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks0, :Title0)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks0, :Title0)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks1, :Title1)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks1, :Title1)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks2, :Title2)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks2, :Title2)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks3, :Title3)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks3, :Title3)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks4, :Title4)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks4, :Title4)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks5, :Title5)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks5, :Title5)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks6, :Title6)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks6, :Title6)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks7, :Title7)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks7, :Title7)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks8, :Title8)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks8, :Title8)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks9, :Title9)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks9, :Title9)
|
||||||
SELECT 1 FROM DUAL", sql);
|
SELECT 1 FROM DUAL", sql);
|
||||||
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
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 data = new List<object>();
|
||||||
var sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql();
|
var sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).ToSql();
|
||||||
Assert.Equal(@"INSERT ALL
|
Assert.Equal(@"INSERT ALL
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks0, :Title0)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks0, :Title0)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks1, :Title1)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks1, :Title1)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks2, :Title2)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks2, :Title2)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks3, :Title3)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks3, :Title3)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks4, :Title4)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks4, :Title4)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks5, :Title5)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks5, :Title5)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks6, :Title6)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks6, :Title6)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks7, :Title7)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks7, :Title7)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks8, :Title8)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks8, :Title8)
|
||||||
INTO ""tb_topic""(""Clicks"", ""Title"") VALUES(:Clicks9, :Title9)
|
INTO ""tb_topic_insert""(""Clicks"", ""Title"") VALUES(:Clicks9, :Title9)
|
||||||
SELECT 1 FROM DUAL", sql);
|
SELECT 1 FROM DUAL", sql);
|
||||||
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
||||||
|
|
||||||
sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).ToSql();
|
sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).ToSql();
|
||||||
Assert.Equal(@"INSERT ALL
|
Assert.Equal(@"INSERT ALL
|
||||||
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks0)
|
INTO ""tb_topic_insert""(""Clicks"") VALUES(:Clicks0)
|
||||||
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks1)
|
INTO ""tb_topic_insert""(""Clicks"") VALUES(:Clicks1)
|
||||||
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks2)
|
INTO ""tb_topic_insert""(""Clicks"") VALUES(:Clicks2)
|
||||||
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks3)
|
INTO ""tb_topic_insert""(""Clicks"") VALUES(:Clicks3)
|
||||||
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks4)
|
INTO ""tb_topic_insert""(""Clicks"") VALUES(:Clicks4)
|
||||||
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks5)
|
INTO ""tb_topic_insert""(""Clicks"") VALUES(:Clicks5)
|
||||||
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks6)
|
INTO ""tb_topic_insert""(""Clicks"") VALUES(:Clicks6)
|
||||||
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks7)
|
INTO ""tb_topic_insert""(""Clicks"") VALUES(:Clicks7)
|
||||||
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks8)
|
INTO ""tb_topic_insert""(""Clicks"") VALUES(:Clicks8)
|
||||||
INTO ""tb_topic""(""Clicks"") VALUES(:Clicks9)
|
INTO ""tb_topic_insert""(""Clicks"") VALUES(:Clicks9)
|
||||||
SELECT 1 FROM DUAL", sql);
|
SELECT 1 FROM DUAL", sql);
|
||||||
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
data.Add(insert.AppendData(items.First()).ExecuteIdentity());
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,10 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace FreeSql.Tests.Sqlite3 {
|
namespace FreeSql.Tests.Sqlite {
|
||||||
public class SqliteDeleteTest {
|
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")]
|
[Table(Name = "tb_topic22211")]
|
||||||
class Topic {
|
class Topic {
|
||||||
@ -21,17 +21,17 @@ namespace FreeSql.Tests.Sqlite3 {
|
|||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Dywhere() {
|
public void Dywhere() {
|
||||||
Assert.Null(g.sqlite3.Delete<Topic>().ToSql());
|
Assert.Null(g.sqlite.Delete<Topic>().ToSql());
|
||||||
var sql = g.sqlite3.Delete<Topic>(new[] { 1, 2 }).ToSql();
|
var sql = g.sqlite.Delete<Topic>(new[] { 1, 2 }).ToSql();
|
||||||
Assert.Equal("DELETE FROM \"tb_topic22211\" WHERE (\"Id\" = 1 OR \"Id\" = 2)", sql);
|
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);
|
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);
|
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);
|
Assert.Equal("DELETE FROM \"tb_topic22211\" WHERE (\"Id\" = 1)", sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,13 +60,13 @@ namespace FreeSql.Tests.Sqlite3 {
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ExecuteAffrows() {
|
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());
|
Assert.Equal(1, delete.Where(a => a.Id == id).ExecuteAffrows());
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ExecuteDeleted() {
|
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);
|
//Assert.Equal(item[0].Id, delete.Where(a => a.Id == item[0].Id).ExecuteDeleted()[0].Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
81
FreeSql.Tests/Sqlite/Curd/SqliteInsertTest.cs
Normal file
81
FreeSql.Tests/Sqlite/Curd/SqliteInsertTest.cs
Normal 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() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,10 +4,10 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace FreeSql.Tests.Sqlite3 {
|
namespace FreeSql.Tests.Sqlite {
|
||||||
public class SqliteSelectTest {
|
public class SqliteSelectTest {
|
||||||
|
|
||||||
ISelect<Topic> select => g.sqlite3.Select<Topic>();
|
ISelect<Topic> select => g.sqlite.Select<Topic>();
|
||||||
|
|
||||||
[Table(Name = "tb_topic22")]
|
[Table(Name = "tb_topic22")]
|
||||||
class Topic {
|
class Topic {
|
||||||
@ -61,10 +61,10 @@ namespace FreeSql.Tests.Sqlite3 {
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Caching() {
|
public void Caching() {
|
||||||
var result1 = select.Where(a => 1 == 1).Caching(20, "testcaching").ToList();
|
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);
|
Assert.NotNull(testcaching1);
|
||||||
var result2 = select.Where(a => 1 == 1).Caching(20, "testcaching").ToList();
|
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.NotNull(testcaching2);
|
||||||
Assert.Equal(result1.Count, result1.Count);
|
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);
|
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.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", "");
|
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();
|
query.ToList();
|
||||||
}
|
}
|
||||||
[Fact]
|
[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);
|
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.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", "");
|
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();
|
query.ToList();
|
||||||
|
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RightJoin() {
|
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>
|
////<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 query = select.RightJoin(a => a.Type.Guid == a.TestTypeInfoGuid);
|
||||||
var sql = query.ToSql().Replace("\r\n", "");
|
//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);
|
//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.ToList();
|
||||||
|
|
||||||
query = select.RightJoin(a => a.Type.Guid == a.TestTypeInfoGuid && a.Type.Name == "xxx");
|
//query = select.RightJoin(a => a.Type.Guid == a.TestTypeInfoGuid && a.Type.Name == "xxx");
|
||||||
sql = query.ToSql().Replace("\r\n", "");
|
//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);
|
//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.ToList();
|
||||||
|
|
||||||
query = select.RightJoin(a => a.Type.Guid == a.TestTypeInfoGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
//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", "");
|
//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);
|
//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.ToList();
|
||||||
|
|
||||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
////<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid);
|
//query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid);
|
||||||
sql = query.ToSql().Replace("\r\n", "");
|
//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);
|
//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.ToList();
|
||||||
|
|
||||||
query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid && b.Name == "xxx");
|
//query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid && b.Name == "xxx");
|
||||||
sql = query.ToSql().Replace("\r\n", "");
|
//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);
|
//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.ToList();
|
||||||
|
|
||||||
query = select.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10);
|
//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", "");
|
//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);
|
//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.ToList();
|
||||||
|
|
||||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
////<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
query = select
|
//query = select
|
||||||
.RightJoin(a => a.Type.Guid == a.TestTypeInfoGuid)
|
// .RightJoin(a => a.Type.Guid == a.TestTypeInfoGuid)
|
||||||
.RightJoin(a => a.Type.Parent.Id == a.Type.ParentId);
|
// .RightJoin(a => a.Type.Parent.Id == a.Type.ParentId);
|
||||||
sql = query.ToSql().Replace("\r\n", "");
|
//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);
|
//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.ToList();
|
||||||
|
|
||||||
query = select
|
//query = select
|
||||||
.RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid)
|
// .RightJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid)
|
||||||
.RightJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId);
|
// .RightJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId);
|
||||||
sql = query.ToSql().Replace("\r\n", "");
|
//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);
|
//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.ToList();
|
||||||
|
|
||||||
//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
|
////<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
|
//var query2 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
|
||||||
.RightJoin(a => a.TestTypeInfoGuid == b.Guid)
|
// .RightJoin(a => a.TestTypeInfoGuid == b.Guid)
|
||||||
.RightJoin(a => b.ParentId == c.Id));
|
// .RightJoin(a => b.ParentId == c.Id));
|
||||||
sql = query2.ToSql().Replace("\r\n", "");
|
//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);
|
//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();
|
//query2.ToList();
|
||||||
|
|
||||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
////<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
||||||
query = select.RightJoin("\"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\"");
|
//query = select.RightJoin("\"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\"");
|
||||||
sql = query.ToSql().Replace("\r\n", "");
|
//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);
|
//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.ToList();
|
||||||
|
|
||||||
query = select.RightJoin("\"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\" and b.\"Name\" = :bname", new { bname = "xxx" });
|
//query = select.RightJoin("\"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\" and b.\"Name\" = @bname", new { bname = "xxx" });
|
||||||
sql = query.ToSql().Replace("\r\n", "");
|
//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);
|
//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.ToList();
|
||||||
|
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -343,9 +343,9 @@ namespace FreeSql.Tests.Sqlite3 {
|
|||||||
query2.ToList();
|
query2.ToList();
|
||||||
|
|
||||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
//<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", "");
|
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();
|
query.ToList();
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -390,9 +390,9 @@ namespace FreeSql.Tests.Sqlite3 {
|
|||||||
query2.ToList();
|
query2.ToList();
|
||||||
|
|
||||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
//<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", "");
|
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();
|
query.ToList();
|
||||||
|
|
||||||
// ==========================================WhereIf(false)
|
// ==========================================WhereIf(false)
|
||||||
@ -437,7 +437,7 @@ namespace FreeSql.Tests.Sqlite3 {
|
|||||||
query2.ToList();
|
query2.ToList();
|
||||||
|
|
||||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
|
//<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", "");
|
sql = query.ToSql().Replace("\r\n", "");
|
||||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a", sql);
|
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a", sql);
|
||||||
query.ToList();
|
query.ToList();
|
@ -3,9 +3,9 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace FreeSql.Tests.Sqlite3 {
|
namespace FreeSql.Tests.Sqlite {
|
||||||
public class SqliteUpdateTest {
|
public class SqliteUpdateTest {
|
||||||
IUpdate<Topic> update => g.sqlite3.Update<Topic>();
|
IUpdate<Topic> update => g.sqlite.Update<Topic>();
|
||||||
|
|
||||||
[Table(Name = "tb_topic")]
|
[Table(Name = "tb_topic")]
|
||||||
class Topic {
|
class Topic {
|
||||||
@ -19,52 +19,52 @@ namespace FreeSql.Tests.Sqlite3 {
|
|||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Dywhere() {
|
public void Dywhere() {
|
||||||
Assert.Null(g.sqlite3.Update<Topic>().ToSql());
|
Assert.Null(g.sqlite.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='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.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)", 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.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 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.sqlite3.Update<Topic>(new { id = 1 }).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]
|
[Fact]
|
||||||
public void SetSource() {
|
public void SetSource() {
|
||||||
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).ToSql().Replace("\r\n", "");
|
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>();
|
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 });
|
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", "");
|
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", "");
|
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", "");
|
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]
|
[Fact]
|
||||||
public void IgnoreColumns() {
|
public void IgnoreColumns() {
|
||||||
var sql = update.SetSource(new Topic { Id = 1, Title = "newtitle" }).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ToSql().Replace("\r\n", "");
|
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]
|
[Fact]
|
||||||
public void Set() {
|
public void Set() {
|
||||||
var sql = update.Where(a => a.Id == 1).Set(a => a.Title, "newtitle").ToSql().Replace("\r\n", "");
|
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", "");
|
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", "");
|
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", "");
|
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);
|
Assert.Equal("UPDATE \"tb_topic\" SET \"Id\" = \"Id\" - 10 WHERE (\"Id\" = 1)", sql);
|
||||||
|
|
||||||
int incrv = 10;
|
int incrv = 10;
|
||||||
sql = update.Set(a => a.Clicks * incrv / 1).Where(a => a.Id == 1).ToSql().Replace("\r\n", "");
|
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", "");
|
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);
|
Assert.Equal("UPDATE \"tb_topic\" SET \"Id\" = \"Id\" - 10 WHERE (\"Id\" = 1)", sql);
|
@ -2,21 +2,21 @@ using FreeSql.DataAnnotations;
|
|||||||
using System;
|
using System;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace FreeSql.Tests.Sqlite3 {
|
namespace FreeSql.Tests.Sqlite {
|
||||||
public class SqliteAdoTest {
|
public class SqliteAdoTest {
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Pool() {
|
public void Pool() {
|
||||||
var t1 = g.sqlite3.Ado.MasterPool.StatisticsFullily;
|
var t1 = g.sqlite.Ado.MasterPool.StatisticsFullily;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void SlavePools() {
|
public void SlavePools() {
|
||||||
var t2 = g.sqlite3.Ado.SlavePools.Count;
|
var t2 = g.sqlite.Ado.SlavePools.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void IsTracePerformance() {
|
public void IsTracePerformance() {
|
||||||
Assert.True(g.sqlite3.Ado.IsTracePerformance);
|
Assert.True(g.sqlite.Ado.IsTracePerformance);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -38,11 +38,11 @@ namespace FreeSql.Tests.Sqlite3 {
|
|||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Query() {
|
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 {
|
class xxx {
|
@ -6,16 +6,16 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace FreeSql.Tests.Sqlite3 {
|
namespace FreeSql.Tests.Sqlite {
|
||||||
public class SqliteCodeFirstTest {
|
public class SqliteCodeFirstTest {
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void AddField() {
|
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")]
|
[Table(Name = "xxxtb.TopicAddField", OldName = "TopicAddField")]
|
||||||
@ -32,62 +32,58 @@ namespace FreeSql.Tests.Sqlite3 {
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void GetComparisonDDLStatements() {
|
public void GetComparisonDDLStatements() {
|
||||||
|
|
||||||
var sql = g.sqlite3.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
var sql = g.sqlite.CodeFirst.GetComparisonDDLStatements<TableAllType>();
|
||||||
if (string.IsNullOrEmpty(sql) == false) {
|
if (string.IsNullOrEmpty(sql) == false) {
|
||||||
Assert.Equal(@"CREATE TABLE IF NOT EXISTS `cccddd`.`tb_alltype` (
|
Assert.Equal(@"CREATE TABLE IF NOT EXISTS ""main"".""tb_alltype"" (
|
||||||
`Id` INT(11) NOT NULL AUTO_INCREMENT,
|
""Id"" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
`Bool` BIT(1) NOT NULL,
|
""Bool"" BOOLEAN NOT NULL,
|
||||||
`SByte` TINYINT(3) NOT NULL,
|
""SByte"" SMALLINT NOT NULL,
|
||||||
`Short` SMALLINT(6) NOT NULL,
|
""Short"" SMALLINT NOT NULL,
|
||||||
`Int` INT(11) NOT NULL,
|
""Int"" INTEGER NOT NULL,
|
||||||
`Long` BIGINT(20) NOT NULL,
|
""Long"" INTEGER NOT NULL,
|
||||||
`Byte` TINYINT(3) UNSIGNED NOT NULL,
|
""Byte"" INT2 NOT NULL,
|
||||||
`UShort` SMALLINT(5) UNSIGNED NOT NULL,
|
""UShort"" UNSIGNED NOT NULL,
|
||||||
`UInt` INT(10) UNSIGNED NOT NULL,
|
""UInt"" DECIMAL(10,0) NOT NULL,
|
||||||
`ULong` BIGINT(20) UNSIGNED NOT NULL,
|
""ULong"" DECIMAL(21,0) NOT NULL,
|
||||||
`Double` DOUBLE NOT NULL,
|
""Double"" DOUBLE NOT NULL,
|
||||||
`Float` FLOAT NOT NULL,
|
""Float"" FLOAT NOT NULL,
|
||||||
`Decimal` DECIMAL(10,2) NOT NULL,
|
""Decimal"" DECIMAL(10,2) NOT NULL,
|
||||||
`TimeSpan` TIME NOT NULL,
|
""TimeSpan"" BIGINT NOT NULL,
|
||||||
`DateTime` DATETIME NOT NULL,
|
""DateTime"" DATETIME NOT NULL,
|
||||||
`Bytes` VARBINARY(255),
|
""DateTimeOffSet"" DATETIME NOT NULL,
|
||||||
`String` VARCHAR(255),
|
""Bytes"" BLOB,
|
||||||
`Guid` VARCHAR(36),
|
""String"" NVARCHAR(255),
|
||||||
`BoolNullable` BIT(1),
|
""Guid"" CHARACTER(36) NOT NULL,
|
||||||
`SByteNullable` TINYINT(3),
|
""BoolNullable"" BOOLEAN,
|
||||||
`ShortNullable` SMALLINT(6),
|
""SByteNullable"" SMALLINT,
|
||||||
`IntNullable` INT(11),
|
""ShortNullable"" SMALLINT,
|
||||||
`testFielLongNullable` BIGINT(20),
|
""IntNullable"" INTEGER,
|
||||||
`ByteNullable` TINYINT(3) UNSIGNED,
|
""testFielLongNullable"" INTEGER,
|
||||||
`UShortNullable` SMALLINT(5) UNSIGNED,
|
""ByteNullable"" INT2,
|
||||||
`UIntNullable` INT(10) UNSIGNED,
|
""UShortNullable"" UNSIGNED,
|
||||||
`ULongNullable` BIGINT(20) UNSIGNED,
|
""UIntNullable"" DECIMAL(10,0),
|
||||||
`DoubleNullable` DOUBLE,
|
""ULongNullable"" DECIMAL(21,0),
|
||||||
`FloatNullable` FLOAT,
|
""DoubleNullable"" DOUBLE,
|
||||||
`DecimalNullable` DECIMAL(10,2),
|
""FloatNullable"" FLOAT,
|
||||||
`TimeSpanNullable` TIME,
|
""DecimalNullable"" DECIMAL(10,2),
|
||||||
`DateTimeNullable` DATETIME,
|
""TimeSpanNullable"" BIGINT,
|
||||||
`GuidNullable` VARCHAR(36),
|
""DateTimeNullable"" DATETIME,
|
||||||
`Point` POINT,
|
""DateTimeOffSetNullable"" DATETIME,
|
||||||
`LineString` LINESTRING,
|
""GuidNullable"" CHARACTER(36),
|
||||||
`Polygon` POLYGON,
|
""Enum1"" MEDIUMINT NOT NULL,
|
||||||
`MultiPoint` MULTIPOINT,
|
""Enum1Nullable"" MEDIUMINT,
|
||||||
`MultiLineString` MULTILINESTRING,
|
""Enum2"" BIGINT NOT NULL,
|
||||||
`MultiPolygon` MULTIPOLYGON,
|
""Enum2Nullable"" BIGINT
|
||||||
`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;
|
|
||||||
", sql);
|
", sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
//sql = g.sqlite3.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
//sql = g.Sqlite.CodeFirst.GetComparisonDDLStatements<Tb_alltype>();
|
||||||
}
|
}
|
||||||
|
|
||||||
IInsert<TableAllType> insert => g.sqlite3.Insert<TableAllType>();
|
IInsert<TableAllType> insert => g.sqlite.Insert<TableAllType>();
|
||||||
ISelect<TableAllType> select => g.sqlite3.Select<TableAllType>();
|
ISelect<TableAllType> select => g.sqlite.Select<TableAllType>();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CurdAllField() {
|
public void CurdAllField() {
|
@ -4,10 +4,10 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace FreeSql.Tests.Sqlite3Expression {
|
namespace FreeSql.Tests.SqliteExpression {
|
||||||
public class ConvertTest {
|
public class ConvertTest {
|
||||||
|
|
||||||
ISelect<Topic> select => g.sqlite3.Select<Topic>();
|
ISelect<Topic> select => g.sqlite.Select<Topic>();
|
||||||
|
|
||||||
[Table(Name = "tb_topic")]
|
[Table(Name = "tb_topic")]
|
||||||
class Topic {
|
class Topic {
|
@ -4,10 +4,10 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace FreeSql.Tests.Sqlite3Expression {
|
namespace FreeSql.Tests.SqliteExpression {
|
||||||
public class DateTimeTest {
|
public class DateTimeTest {
|
||||||
|
|
||||||
ISelect<Topic> select => g.sqlite3.Select<Topic>();
|
ISelect<Topic> select => g.sqlite.Select<Topic>();
|
||||||
|
|
||||||
[Table(Name = "tb_topic111333")]
|
[Table(Name = "tb_topic111333")]
|
||||||
class Topic {
|
class Topic {
|
@ -4,10 +4,10 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace FreeSql.Tests.Sqlite3Expression {
|
namespace FreeSql.Tests.SqliteExpression {
|
||||||
public class MathTest {
|
public class MathTest {
|
||||||
|
|
||||||
ISelect<Topic> select => g.sqlite3.Select<Topic>();
|
ISelect<Topic> select => g.sqlite.Select<Topic>();
|
||||||
|
|
||||||
[Table(Name = "tb_topic")]
|
[Table(Name = "tb_topic")]
|
||||||
class Topic {
|
class Topic {
|
||||||
@ -126,7 +126,7 @@ namespace FreeSql.Tests.Sqlite3Expression {
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Truncate() {
|
public void Truncate() {
|
||||||
var data = new List<object>();
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,10 +3,10 @@ using System;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace FreeSql.Tests.Sqlite3Expression {
|
namespace FreeSql.Tests.SqliteExpression {
|
||||||
public class OtherTest {
|
public class OtherTest {
|
||||||
|
|
||||||
ISelect<TableAllType> select => g.sqlite3.Select<TableAllType>();
|
ISelect<TableAllType> select => g.sqlite.Select<TableAllType>();
|
||||||
|
|
||||||
public OtherTest() {
|
public OtherTest() {
|
||||||
}
|
}
|
@ -4,10 +4,10 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace FreeSql.Tests.Sqlite3Expression {
|
namespace FreeSql.Tests.SqliteExpression {
|
||||||
public class StringTest {
|
public class StringTest {
|
||||||
|
|
||||||
ISelect<Topic> select => g.sqlite3.Select<Topic>();
|
ISelect<Topic> select => g.sqlite.Select<Topic>();
|
||||||
|
|
||||||
[Table(Name = "tb_topic")]
|
[Table(Name = "tb_topic")]
|
||||||
class Topic {
|
class Topic {
|
||||||
@ -379,87 +379,87 @@ namespace FreeSql.Tests.Sqlite3Expression {
|
|||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void PadLeft() {
|
public void PadLeft() {
|
||||||
var data = new List<object>();
|
//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') == "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).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.Title + 1)).ToList());
|
||||||
data.Add(select.Where(a => a.Title.PadLeft(10, 'a') == a.Type.Name).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
|
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
//FROM `tb_topic` a
|
////FROM `tb_topic` a
|
||||||
//WHERE (lpad(a.`Title`, 10, 'a') = 'aaa');
|
////WHERE (lpad(a.`Title`, 10, 'a') = 'aaa');
|
||||||
|
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
//FROM `tb_topic` a
|
////FROM `tb_topic` a
|
||||||
//WHERE (lpad(a.`Title`, 10, 'a') = a.`Title`);
|
////WHERE (lpad(a.`Title`, 10, 'a') = a.`Title`);
|
||||||
|
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
//FROM `tb_topic` a
|
////FROM `tb_topic` a
|
||||||
//WHERE (lpad(a.`Title`, 10, 'a') = concat(a.`Title`, 1));
|
////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
|
////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
|
////FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
//WHERE (lpad(a.`Title`, 10, 'a') = a__Type.`Name`);
|
////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') == "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).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.Title + 1)).ToList());
|
||||||
data.Add(select.Where(a => (a.Title.PadLeft(10, 'a') + "aaa").PadLeft(20, 'b') == a.Type.Name).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
|
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
//FROM `tb_topic` a
|
////FROM `tb_topic` a
|
||||||
//WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = 'aaa');
|
////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
|
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
//FROM `tb_topic` a
|
////FROM `tb_topic` a
|
||||||
//WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a.`Title`);
|
////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
|
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
//FROM `tb_topic` a
|
////FROM `tb_topic` a
|
||||||
//WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = concat(a.`Title`, 1));
|
////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
|
////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
|
////FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
//WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a__Type.`Name`)
|
////WHERE (lpad(concat(lpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a__Type.`Name`)
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void PadRight() {
|
public void PadRight() {
|
||||||
var data = new List<object>();
|
//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') == "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).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.Title + 1)).ToList());
|
||||||
data.Add(select.Where(a => a.Title.PadRight(10, 'a') == a.Type.Name).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
|
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
//FROM `tb_topic` a
|
////FROM `tb_topic` a
|
||||||
//WHERE (rpad(a.`Title`, 10, 'a') = 'aaa');
|
////WHERE (rpad(a.`Title`, 10, 'a') = 'aaa');
|
||||||
|
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
//FROM `tb_topic` a
|
////FROM `tb_topic` a
|
||||||
//WHERE (rpad(a.`Title`, 10, 'a') = a.`Title`);
|
////WHERE (rpad(a.`Title`, 10, 'a') = a.`Title`);
|
||||||
|
|
||||||
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
//FROM `tb_topic` a
|
////FROM `tb_topic` a
|
||||||
//WHERE (rpad(a.`Title`, 10, 'a') = concat(a.`Title`, 1));
|
////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
|
////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
|
////FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
//WHERE (rpad(a.`Title`, 10, 'a') = a__Type.`Name`);
|
////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') == "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).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.Title + 1)).ToList());
|
||||||
data.Add(select.Where(a => (a.Title.PadRight(10, 'a') + "aaa").PadRight(20, 'b') == a.Type.Name).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
|
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
//FROM `tb_topic` a
|
////FROM `tb_topic` a
|
||||||
//WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = 'aaa');
|
////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
|
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
//FROM `tb_topic` a
|
////FROM `tb_topic` a
|
||||||
//WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a.`Title`);
|
////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
|
////SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5
|
||||||
//FROM `tb_topic` a
|
////FROM `tb_topic` a
|
||||||
//WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = concat(a.`Title`, 1));
|
////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
|
////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
|
////FROM `tb_topic` a, `TestTypeInfo` a__Type
|
||||||
//WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a__Type.`Name`)
|
////WHERE (rpad(concat(rpad(a.`Title`, 10, 'a'), 'aaa'), 20, 'b') = a__Type.`Name`)
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Trim() {
|
public void Trim() {
|
@ -4,10 +4,10 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace FreeSql.Tests.Sqlite3Expression {
|
namespace FreeSql.Tests.SqliteExpression {
|
||||||
public class TimeSpanTest {
|
public class TimeSpanTest {
|
||||||
|
|
||||||
ISelect<Topic> select => g.sqlite3.Select<Topic>();
|
ISelect<Topic> select => g.sqlite.Select<Topic>();
|
||||||
|
|
||||||
[Table(Name = "tb_topic")]
|
[Table(Name = "tb_topic")]
|
||||||
class Topic {
|
class Topic {
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -34,8 +34,8 @@ public class g {
|
|||||||
.UseAutoSyncStructure(true)
|
.UseAutoSyncStructure(true)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
public static IFreeSql sqlite3 = new FreeSql.FreeSqlBuilder()
|
public static IFreeSql sqlite = new FreeSql.FreeSqlBuilder()
|
||||||
.UseConnectionString(FreeSql.DataType.Sqlite3, @"Data Source=|DataDirectory|\document.db;Attachs=xxxtb.db;Pooling=true;Max Pool Size=10")
|
.UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\document.db;Attachs=xxxtb.db;Pooling=true;Max Pool Size=10")
|
||||||
.UseAutoSyncStructure(true)
|
.UseAutoSyncStructure(true)
|
||||||
.Build();
|
.Build();
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
/// <param name="args"></param>
|
/// <param name="args"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string FormatSqlite (this string that, params object[] args) => _sqliteAdo.Addslashes(that, args);
|
public static string FormatSqlite (this string that, params object[] args) => _sqliteAdo.Addslashes(that, args);
|
||||||
static FreeSql.Sqlite3.SqliteAdo _sqliteAdo = new FreeSql.Sqlite3.SqliteAdo();
|
static FreeSql.Sqlite.SqliteAdo _sqliteAdo = new FreeSql.Sqlite.SqliteAdo();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace System.Runtime.CompilerServices {
|
namespace System.Runtime.CompilerServices {
|
||||||
|
@ -93,7 +93,7 @@ namespace FreeSql {
|
|||||||
case DataType.SqlServer: ret = new SqlServer.SqlServerProvider(_cache, _logger, _masterConnectionString, _slaveConnectionString); break;
|
case DataType.SqlServer: ret = new SqlServer.SqlServerProvider(_cache, _logger, _masterConnectionString, _slaveConnectionString); break;
|
||||||
case DataType.PostgreSQL: ret = new PostgreSQL.PostgreSQLProvider(_cache, _logger, _masterConnectionString, _slaveConnectionString); break;
|
case DataType.PostgreSQL: ret = new PostgreSQL.PostgreSQLProvider(_cache, _logger, _masterConnectionString, _slaveConnectionString); break;
|
||||||
case DataType.Oracle: ret = new Oracle.OracleProvider(_cache, _logger, _masterConnectionString, _slaveConnectionString); break;
|
case DataType.Oracle: ret = new Oracle.OracleProvider(_cache, _logger, _masterConnectionString, _slaveConnectionString); break;
|
||||||
case DataType.Sqlite3: ret = new Sqlite3.SqliteProvider(_cache, _logger, _masterConnectionString, _slaveConnectionString); break;
|
case DataType.Sqlite: ret = new Sqlite.SqliteProvider(_cache, _logger, _masterConnectionString, _slaveConnectionString); break;
|
||||||
}
|
}
|
||||||
if (ret != null) {
|
if (ret != null) {
|
||||||
ret.CodeFirst.IsAutoSyncStructure = _isAutoSyncStructure;
|
ret.CodeFirst.IsAutoSyncStructure = _isAutoSyncStructure;
|
||||||
@ -106,5 +106,5 @@ namespace FreeSql {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum DataType { MySql, SqlServer, PostgreSQL, Oracle, Sqlite3 }
|
public enum DataType { MySql, SqlServer, PostgreSQL, Oracle, Sqlite }
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,7 @@ namespace FreeSql.Internal {
|
|||||||
case "Npgsql.LegacyPostgis.PostgisGeometry": return value;
|
case "Npgsql.LegacyPostgis.PostgisGeometry": return value;
|
||||||
}
|
}
|
||||||
if (type != value.GetType()) {
|
if (type != value.GetType()) {
|
||||||
if (type.FullName == "System.TimeSpan") return TimeSpan.FromMilliseconds(double.Parse(value.ToString()));
|
if (type.FullName == "System.TimeSpan") return TimeSpan.FromSeconds(double.Parse(value.ToString()));
|
||||||
return Convert.ChangeType(value, type);
|
return Convert.ChangeType(value, type);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
@ -137,7 +137,8 @@ data_precision,
|
|||||||
data_scale,
|
data_scale,
|
||||||
char_used,
|
char_used,
|
||||||
case when nullable = 'Y' then 1 else 0 end,
|
case when nullable = 'Y' then 1 else 0 end,
|
||||||
nvl((select 1 from user_sequences where sequence_name='{Utils.GetCsName((tboldname ?? tbname).Last())}_seq_'||all_tab_columns.column_name), 0)
|
nvl((select 1 from user_sequences where sequence_name='{Utils.GetCsName((tboldname ?? tbname).Last())}_seq_'||all_tab_columns.column_name), 0),
|
||||||
|
nvl((select 1 from user_triggers where trigger_name='{Utils.GetCsName((tboldname ?? tbname).Last())}_seq_'||all_tab_columns.column_name||'TI'), 0)
|
||||||
from all_tab_columns
|
from all_tab_columns
|
||||||
where owner={{0}} and table_name={{1}}".FormatOracleSQL(tboldname ?? tbname);
|
where owner={{0}} and table_name={{1}}".FormatOracleSQL(tboldname ?? tbname);
|
||||||
var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
|
var ds = _orm.Ado.ExecuteArray(CommandType.Text, sql);
|
||||||
@ -167,7 +168,7 @@ where owner={{0}} and table_name={{1}}".FormatOracleSQL(tboldname ?? tbname);
|
|||||||
column = string.Concat(a[0]),
|
column = string.Concat(a[0]),
|
||||||
sqlType,
|
sqlType,
|
||||||
is_nullable = string.Concat(a[6]) == "1",
|
is_nullable = string.Concat(a[6]) == "1",
|
||||||
is_identity = string.Concat(a[7]) == "1"
|
is_identity = string.Concat(a[7]) == "1" && string.Concat(a[8]) == "1"
|
||||||
};
|
};
|
||||||
}, StringComparer.CurrentCultureIgnoreCase);
|
}, StringComparer.CurrentCultureIgnoreCase);
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ using System.Data;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace FreeSql.Sqlite3.Curd {
|
namespace FreeSql.Sqlite.Curd {
|
||||||
|
|
||||||
class SqliteDelete<T1> : Internal.CommonProvider.DeleteProvider<T1> where T1 : class {
|
class SqliteDelete<T1> : Internal.CommonProvider.DeleteProvider<T1> where T1 : class {
|
||||||
public SqliteDelete(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere)
|
public SqliteDelete(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere)
|
@ -5,7 +5,7 @@ using System.Data;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace FreeSql.Sqlite3.Curd {
|
namespace FreeSql.Sqlite.Curd {
|
||||||
|
|
||||||
class SqliteInsert<T1> : Internal.CommonProvider.InsertProvider<T1> where T1 : class {
|
class SqliteInsert<T1> : Internal.CommonProvider.InsertProvider<T1> where T1 : class {
|
||||||
public SqliteInsert(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression)
|
public SqliteInsert(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression)
|
@ -6,7 +6,7 @@ using System.Linq;
|
|||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace FreeSql.Sqlite3.Curd {
|
namespace FreeSql.Sqlite.Curd {
|
||||||
|
|
||||||
class SqliteSelect<T1> : FreeSql.Internal.CommonProvider.Select1Provider<T1> where T1 : class {
|
class SqliteSelect<T1> : FreeSql.Internal.CommonProvider.Select1Provider<T1> where T1 : class {
|
||||||
|
|
@ -7,7 +7,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace FreeSql.Sqlite3.Curd {
|
namespace FreeSql.Sqlite.Curd {
|
||||||
|
|
||||||
class SqliteUpdate<T1> : Internal.CommonProvider.UpdateProvider<T1> where T1 : class {
|
class SqliteUpdate<T1> : Internal.CommonProvider.UpdateProvider<T1> where T1 : class {
|
||||||
|
|
@ -8,7 +8,7 @@ using System.Data.SQLite;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace FreeSql.Sqlite3 {
|
namespace FreeSql.Sqlite {
|
||||||
class SqliteAdo : FreeSql.Internal.CommonProvider.AdoProvider {
|
class SqliteAdo : FreeSql.Internal.CommonProvider.AdoProvider {
|
||||||
CommonUtils _util;
|
CommonUtils _util;
|
||||||
|
|
@ -9,7 +9,7 @@ using System.Text;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace FreeSql.Sqlite3 {
|
namespace FreeSql.Sqlite {
|
||||||
|
|
||||||
class SqliteConnectionPool : ObjectPool<DbConnection> {
|
class SqliteConnectionPool : ObjectPool<DbConnection> {
|
||||||
|
|
@ -9,7 +9,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace FreeSql.Sqlite3 {
|
namespace FreeSql.Sqlite {
|
||||||
|
|
||||||
class SqliteCodeFirst : ICodeFirst {
|
class SqliteCodeFirst : ICodeFirst {
|
||||||
IFreeSql _orm;
|
IFreeSql _orm;
|
||||||
@ -127,11 +127,11 @@ namespace FreeSql.Sqlite3 {
|
|||||||
|
|
||||||
//对比字段,只可以修改类型、增加字段、有限的修改字段名;保证安全不删除字段
|
//对比字段,只可以修改类型、增加字段、有限的修改字段名;保证安全不删除字段
|
||||||
var tbtmp = tboldname ?? tbname;
|
var tbtmp = tboldname ?? tbname;
|
||||||
var dsql = _orm.Ado.ExecuteScalar(CommandType.Text, $" select 1 from {tbtmp[0]}.sqlite_master where type='table' and name='{tbtmp[1]}'")?.ToString();
|
var dsql = _orm.Ado.ExecuteScalar(CommandType.Text, $" select sql from {tbtmp[0]}.sqlite_master where type='table' and name='{tbtmp[1]}'")?.ToString();
|
||||||
var ds = _orm.Ado.ExecuteArray(CommandType.Text, $"PRAGMA {_commonUtils.QuoteSqlName(tbtmp[0])}.table_info({_commonUtils.QuoteSqlName(tbtmp[1])})");
|
var ds = _orm.Ado.ExecuteArray(CommandType.Text, $"PRAGMA {_commonUtils.QuoteSqlName(tbtmp[0])}.table_info({_commonUtils.QuoteSqlName(tbtmp[1])})");
|
||||||
var tbstruct = ds.ToDictionary(a => string.Concat(a[1]), a => {
|
var tbstruct = ds.ToDictionary(a => string.Concat(a[1]), a => {
|
||||||
var is_identity = false;
|
var is_identity = false;
|
||||||
var dsqlIdx = dsql?.IndexOf($"\"{a[0]}\" ");
|
var dsqlIdx = dsql?.IndexOf($"\"{a[1]}\" ");
|
||||||
if (dsqlIdx > 0) {
|
if (dsqlIdx > 0) {
|
||||||
var dsqlLastIdx = dsql.IndexOf('\n', dsqlIdx.Value);
|
var dsqlLastIdx = dsql.IndexOf('\n', dsqlIdx.Value);
|
||||||
if (dsqlLastIdx > 0) is_identity = dsql.Substring(dsqlIdx.Value, dsqlLastIdx - dsqlIdx.Value).Contains("AUTOINCREMENT");
|
if (dsqlLastIdx > 0) is_identity = dsql.Substring(dsqlIdx.Value, dsqlLastIdx - dsqlIdx.Value).Contains("AUTOINCREMENT");
|
@ -7,7 +7,7 @@ using System.Data;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace FreeSql.Sqlite3 {
|
namespace FreeSql.Sqlite {
|
||||||
class SqliteDbFirst : IDbFirst {
|
class SqliteDbFirst : IDbFirst {
|
||||||
IFreeSql _orm;
|
IFreeSql _orm;
|
||||||
protected CommonUtils _commonUtils;
|
protected CommonUtils _commonUtils;
|
@ -6,7 +6,7 @@ using System.Linq;
|
|||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace FreeSql.Sqlite3 {
|
namespace FreeSql.Sqlite {
|
||||||
class SqliteExpression : CommonExpression {
|
class SqliteExpression : CommonExpression {
|
||||||
|
|
||||||
public SqliteExpression(CommonUtils common) : base(common) { }
|
public SqliteExpression(CommonUtils common) : base(common) { }
|
||||||
@ -60,35 +60,35 @@ namespace FreeSql.Sqlite3 {
|
|||||||
}
|
}
|
||||||
var left = ExpressionLambdaToSql(exp.Expression, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName);
|
var left = ExpressionLambdaToSql(exp.Expression, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName);
|
||||||
switch (exp.Member.Name) {
|
switch (exp.Member.Name) {
|
||||||
case "Length": return $"char_length({left})";
|
case "Length": return $"length({left})";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
internal override string ExpressionLambdaToSqlMemberAccessDateTime(MemberExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, Func<Expression[], string> getSelectGroupingMapString, SelectTableInfoType tbtype, bool isQuoteName) {
|
internal override string ExpressionLambdaToSqlMemberAccessDateTime(MemberExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, Func<Expression[], string> getSelectGroupingMapString, SelectTableInfoType tbtype, bool isQuoteName) {
|
||||||
if (exp.Expression == null) {
|
if (exp.Expression == null) {
|
||||||
switch (exp.Member.Name) {
|
switch (exp.Member.Name) {
|
||||||
case "Now": return "now()";
|
case "Now": return "datetime(current_timestamp,'localtime')";
|
||||||
case "UtcNow": return "utc_timestamp()";
|
case "UtcNow": return "current_timestamp";
|
||||||
case "Today": return "curdate()";
|
case "Today": return "date(current_timestamp,'localtime')";
|
||||||
case "MinValue": return "cast('0001/1/1 0:00:00' as datetime)";
|
case "MinValue": return "datetime('0001-01-01 00:00:00.000')";
|
||||||
case "MaxValue": return "cast('9999/12/31 23:59:59' as datetime)";
|
case "MaxValue": return "datetime('9999-12-31 23:59:59.999')";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var left = ExpressionLambdaToSql(exp.Expression, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName);
|
var left = ExpressionLambdaToSql(exp.Expression, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName);
|
||||||
switch (exp.Member.Name) {
|
switch (exp.Member.Name) {
|
||||||
case "Date": return $"cast(date_format({left},'%Y-%m-%d') as datetime)";
|
case "Date": return $"date({left})";
|
||||||
case "TimeOfDay": return $"timestampdiff(microsecond, date_format({left},'%Y-%m-%d'), {left})";
|
case "TimeOfDay": return $"strftime('%s',{left})";
|
||||||
case "DayOfWeek": return $"(dayofweek({left})-1)";
|
case "DayOfWeek": return $"strftime('%w',{left})";
|
||||||
case "Day": return $"dayofmonth({left})";
|
case "Day": return $"strftime('%d',{left})";
|
||||||
case "DayOfYear": return $"dayofyear({left})";
|
case "DayOfYear": return $"strftime('%j',{left})";
|
||||||
case "Month": return $"month({left})";
|
case "Month": return $"strftime('%m',{left})";
|
||||||
case "Year": return $"year({left})";
|
case "Year": return $"strftime('%Y',{left})";
|
||||||
case "Hour": return $"hour({left})";
|
case "Hour": return $"strftime('%H',{left})";
|
||||||
case "Minute": return $"minute({left})";
|
case "Minute": return $"strftime('%M',{left})";
|
||||||
case "Second": return $"second({left})";
|
case "Second": return $"strftime('%S',{left})";
|
||||||
case "Millisecond": return $"floor(microsecond({left})/1000)";
|
case "Millisecond": return $"(strftime('%f',{left})-strftime('%S',{left}))";
|
||||||
case "Ticks": return $"(timestampdiff(microsecond, '0001-1-1', {left})*10)";
|
case "Ticks": return $"(strftime('%s',{left})*10000000+621355968000000000)";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -96,24 +96,24 @@ namespace FreeSql.Sqlite3 {
|
|||||||
if (exp.Expression == null) {
|
if (exp.Expression == null) {
|
||||||
switch (exp.Member.Name) {
|
switch (exp.Member.Name) {
|
||||||
case "Zero": return "0";
|
case "Zero": return "0";
|
||||||
case "MinValue": return "-922337203685477580"; //微秒 Ticks / 10
|
case "MinValue": return "-922337203685.477580"; //秒 Ticks / 1000,000,0
|
||||||
case "MaxValue": return "922337203685477580";
|
case "MaxValue": return "922337203685.477580";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var left = ExpressionLambdaToSql(exp.Expression, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName);
|
var left = ExpressionLambdaToSql(exp.Expression, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName);
|
||||||
switch (exp.Member.Name) {
|
switch (exp.Member.Name) {
|
||||||
case "Days": return $"(({left}) div {(long)1000000 * 60 * 60 * 24})";
|
case "Days": return $"floor(({left})/{60 * 60 * 24})";
|
||||||
case "Hours": return $"(({left}) div {(long)1000000 * 60 * 60} mod 24)";
|
case "Hours": return $"floor(({left})/{60 * 60}%24)";
|
||||||
case "Milliseconds": return $"(({left}) div 1000 mod 1000)";
|
case "Milliseconds": return $"(cast({left} as bigint)*1000)";
|
||||||
case "Minutes": return $"(({left}) div {(long)1000000 * 60} mod 60)";
|
case "Minutes": return $"floor(({left})/60%60)";
|
||||||
case "Seconds": return $"(({left}) div 1000000 mod 60)";
|
case "Seconds": return $"(({left})%60)";
|
||||||
case "Ticks": return $"(({left}) * 10)";
|
case "Ticks": return $"(cast({left} as bigint)*10000000)";
|
||||||
case "TotalDays": return $"(({left}) / {(long)1000000 * 60 * 60 * 24})";
|
case "TotalDays": return $"(({left})/{60 * 60 * 24})";
|
||||||
case "TotalHours": return $"(({left}) / {(long)1000000 * 60 * 60})";
|
case "TotalHours": return $"(({left})/{60 * 60})";
|
||||||
case "TotalMilliseconds": return $"(({left}) / 1000)";
|
case "TotalMilliseconds": return $"(cast({left} as bigint)*1000)";
|
||||||
case "TotalMinutes": return $"(({left}) / {(long)1000000 * 60})";
|
case "TotalMinutes": return $"(({left})/60)";
|
||||||
case "TotalSeconds": return $"(({left}) / 1000000)";
|
case "TotalSeconds": return $"({left})";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -134,10 +134,10 @@ namespace FreeSql.Sqlite3 {
|
|||||||
case "Contains":
|
case "Contains":
|
||||||
var args0Value = getExp(exp.Arguments[0]);
|
var args0Value = getExp(exp.Arguments[0]);
|
||||||
if (args0Value == "NULL") return $"({left}) IS NULL";
|
if (args0Value == "NULL") return $"({left}) IS NULL";
|
||||||
if (exp.Method.Name == "StartsWith") return $"({left}) LIKE {(args0Value.EndsWith("'") ? args0Value.Insert(args0Value.Length - 1, "%") : $"concat({args0Value}, '%')")}";
|
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, "%") : $"concat('%', {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, "%")}";
|
if (args0Value.StartsWith("'") && args0Value.EndsWith("'")) return $"({left}) LIKE {args0Value.Insert(1, "%").Insert(args0Value.Length, "%")}";
|
||||||
return $"({left}) LIKE concat('%', {args0Value}, '%')";
|
return $"({left}) LIKE '%'||({args0Value})||'%'";
|
||||||
case "ToLower": return $"lower({left})";
|
case "ToLower": return $"lower({left})";
|
||||||
case "ToUpper": return $"upper({left})";
|
case "ToUpper": return $"upper({left})";
|
||||||
case "Substring":
|
case "Substring":
|
||||||
@ -148,13 +148,13 @@ namespace FreeSql.Sqlite3 {
|
|||||||
return $"substr({left}, {substrArgs1}, {getExp(exp.Arguments[1])})";
|
return $"substr({left}, {substrArgs1}, {getExp(exp.Arguments[1])})";
|
||||||
case "IndexOf":
|
case "IndexOf":
|
||||||
var indexOfFindStr = getExp(exp.Arguments[0]);
|
var indexOfFindStr = getExp(exp.Arguments[0]);
|
||||||
if (exp.Arguments.Count > 1 && exp.Arguments[1].Type.FullName == "System.Int32") {
|
//if (exp.Arguments.Count > 1 && exp.Arguments[1].Type.FullName == "System.Int32") {
|
||||||
var locateArgs1 = getExp(exp.Arguments[1]);
|
// var locateArgs1 = getExp(exp.Arguments[1]);
|
||||||
if (long.TryParse(locateArgs1, out var testtrylng2)) locateArgs1 = (testtrylng2 + 1).ToString();
|
// if (long.TryParse(locateArgs1, out var testtrylng2)) locateArgs1 = (testtrylng2 + 1).ToString();
|
||||||
else locateArgs1 += "+1";
|
// else locateArgs1 += "+1";
|
||||||
return $"(locate({left}, {indexOfFindStr}, {locateArgs1})-1)";
|
// return $"(instr({left}, {indexOfFindStr}, {locateArgs1})-1)";
|
||||||
}
|
//}
|
||||||
return $"(locate({left}, {indexOfFindStr})-1)";
|
return $"(instr({left}, {indexOfFindStr})-1)";
|
||||||
case "PadLeft":
|
case "PadLeft":
|
||||||
if (exp.Arguments.Count == 1) return $"lpad({left}, {getExp(exp.Arguments[0])})";
|
if (exp.Arguments.Count == 1) return $"lpad({left}, {getExp(exp.Arguments[0])})";
|
||||||
return $"lpad({left}, {getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})";
|
return $"lpad({left}, {getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})";
|
||||||
@ -169,6 +169,8 @@ namespace FreeSql.Sqlite3 {
|
|||||||
if (exp.Method.Name == "TrimStart") return $"ltrim({left})";
|
if (exp.Method.Name == "TrimStart") return $"ltrim({left})";
|
||||||
if (exp.Method.Name == "TrimEnd") return $"rtrim({left})";
|
if (exp.Method.Name == "TrimEnd") return $"rtrim({left})";
|
||||||
}
|
}
|
||||||
|
var trimArg1 = "";
|
||||||
|
var trimArg2 = "";
|
||||||
foreach (var argsTrim02 in exp.Arguments) {
|
foreach (var argsTrim02 in exp.Arguments) {
|
||||||
var argsTrim01s = new[] { argsTrim02 };
|
var argsTrim01s = new[] { argsTrim02 };
|
||||||
if (argsTrim02.NodeType == ExpressionType.NewArrayInit) {
|
if (argsTrim02.NodeType == ExpressionType.NewArrayInit) {
|
||||||
@ -176,18 +178,21 @@ namespace FreeSql.Sqlite3 {
|
|||||||
argsTrim01s = arritem.Expressions.ToArray();
|
argsTrim01s = arritem.Expressions.ToArray();
|
||||||
}
|
}
|
||||||
foreach (var argsTrim01 in argsTrim01s) {
|
foreach (var argsTrim01 in argsTrim01s) {
|
||||||
if (exp.Method.Name == "Trim") left = $"trim({getExp(argsTrim01)} from {left})";
|
var trimChr = getExp(argsTrim01).Trim('\'');
|
||||||
if (exp.Method.Name == "TrimStart") left = $"trim(leading {getExp(argsTrim01)} from {left})";
|
if (trimChr.Length == 1) trimArg1 += trimChr;
|
||||||
if (exp.Method.Name == "TrimEnd") left = $"trim(trailing {getExp(argsTrim01)} from {left})";
|
else trimArg2 += $" || ({trimChr})";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (exp.Method.Name == "Trim") left = $"trim({left}, {_common.FormatSql("{0}", trimArg1)}{trimArg2})";
|
||||||
|
if (exp.Method.Name == "TrimStart") left = $"ltrim({left}, {_common.FormatSql("{0}", trimArg1)}{trimArg2})";
|
||||||
|
if (exp.Method.Name == "TrimEnd") left = $"rtrim({left}, {_common.FormatSql("{0}", trimArg1)}{trimArg2})";
|
||||||
return left;
|
return left;
|
||||||
case "Replace": return $"replace({left}, {getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})";
|
case "Replace": return $"replace({left}, {getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})";
|
||||||
case "CompareTo": return $"strcmp({left}, {getExp(exp.Arguments[0])})";
|
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])})";
|
case "Equals": return $"({left} = {getExp(exp.Arguments[0])})";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Exception($"MySqlExpression 未现实函数表达式 {exp} 解析");
|
throw new Exception($"SqliteExpression 未现实函数表达式 {exp} 解析");
|
||||||
}
|
}
|
||||||
internal override string ExpressionLambdaToSqlCallMath(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, Func<Expression[], string> getSelectGroupingMapString, SelectTableInfoType tbtype, bool isQuoteName) {
|
internal override string ExpressionLambdaToSqlCallMath(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, Func<Expression[], string> getSelectGroupingMapString, SelectTableInfoType tbtype, bool isQuoteName) {
|
||||||
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName);
|
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName);
|
||||||
@ -202,7 +207,7 @@ namespace FreeSql.Sqlite3 {
|
|||||||
case "Exp": return $"exp({getExp(exp.Arguments[0])})";
|
case "Exp": return $"exp({getExp(exp.Arguments[0])})";
|
||||||
case "Log": return $"log({getExp(exp.Arguments[0])})";
|
case "Log": return $"log({getExp(exp.Arguments[0])})";
|
||||||
case "Log10": return $"log10({getExp(exp.Arguments[0])})";
|
case "Log10": return $"log10({getExp(exp.Arguments[0])})";
|
||||||
case "Pow": return $"pow({getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})";
|
case "Pow": return $"power({getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})";
|
||||||
case "Sqrt": return $"sqrt({getExp(exp.Arguments[0])})";
|
case "Sqrt": return $"sqrt({getExp(exp.Arguments[0])})";
|
||||||
case "Cos": return $"cos({getExp(exp.Arguments[0])})";
|
case "Cos": return $"cos({getExp(exp.Arguments[0])})";
|
||||||
case "Sin": return $"sin({getExp(exp.Arguments[0])})";
|
case "Sin": return $"sin({getExp(exp.Arguments[0])})";
|
||||||
@ -211,52 +216,52 @@ namespace FreeSql.Sqlite3 {
|
|||||||
case "Asin": return $"asin({getExp(exp.Arguments[0])})";
|
case "Asin": return $"asin({getExp(exp.Arguments[0])})";
|
||||||
case "Atan": return $"atan({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 "Atan2": return $"atan2({getExp(exp.Arguments[0])}, {getExp(exp.Arguments[1])})";
|
||||||
case "Truncate": return $"truncate({getExp(exp.Arguments[0])}, 0)";
|
//case "Truncate": return $"truncate({getExp(exp.Arguments[0])}, 0)";
|
||||||
}
|
}
|
||||||
throw new Exception($"MySqlExpression 未现实函数表达式 {exp} 解析");
|
throw new Exception($"SqliteExpression 未现实函数表达式 {exp} 解析");
|
||||||
}
|
}
|
||||||
internal override string ExpressionLambdaToSqlCallDateTime(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, Func<Expression[], string> getSelectGroupingMapString, SelectTableInfoType tbtype, bool isQuoteName) {
|
internal override string ExpressionLambdaToSqlCallDateTime(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, Func<Expression[], string> getSelectGroupingMapString, SelectTableInfoType tbtype, bool isQuoteName) {
|
||||||
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName);
|
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName);
|
||||||
if (exp.Object == null) {
|
if (exp.Object == null) {
|
||||||
switch (exp.Method.Name) {
|
switch (exp.Method.Name) {
|
||||||
case "Compare": return $"({getExp(exp.Arguments[0])} - ({getExp(exp.Arguments[1])}))";
|
case "Compare": return $"(strftime('%s',{getExp(exp.Arguments[0])}) -strftime('%s',{getExp(exp.Arguments[1])}))";
|
||||||
case "DaysInMonth": return $"dayofmonth(last_day(concat({getExp(exp.Arguments[0])}, '-', {getExp(exp.Arguments[1])}, '-01')))";
|
case "DaysInMonth": return $"strftime('%d',date({getExp(exp.Arguments[0])}||'-01-01',{getExp(exp.Arguments[1])}||' months','-1 days'))";
|
||||||
case "Equals": return $"({getExp(exp.Arguments[0])} = {getExp(exp.Arguments[1])})";
|
case "Equals": return $"({getExp(exp.Arguments[0])} = {getExp(exp.Arguments[1])})";
|
||||||
|
|
||||||
case "IsLeapYear":
|
case "IsLeapYear":
|
||||||
var isLeapYearArgs1 = getExp(exp.Arguments[0]);
|
var isLeapYearArgs1 = getExp(exp.Arguments[0]);
|
||||||
return $"(({isLeapYearArgs1})%4=0 AND ({isLeapYearArgs1})%100<>0 OR ({isLeapYearArgs1})%400=0)";
|
return $"(({isLeapYearArgs1})%4=0 AND ({isLeapYearArgs1})%100<>0 OR ({isLeapYearArgs1})%400=0)";
|
||||||
|
|
||||||
case "Parse": return $"cast({getExp(exp.Arguments[0])} as datetime)";
|
case "Parse": return $"datetime({getExp(exp.Arguments[0])})";
|
||||||
case "ParseExact":
|
case "ParseExact":
|
||||||
case "TryParse":
|
case "TryParse":
|
||||||
case "TryParseExact": return $"cast({getExp(exp.Arguments[0])} as datetime)";
|
case "TryParseExact": return $"datetime({getExp(exp.Arguments[0])})";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var left = getExp(exp.Object);
|
var left = getExp(exp.Object);
|
||||||
var args1 = exp.Arguments.Count == 0 ? null : getExp(exp.Arguments[0]);
|
var args1 = exp.Arguments.Count == 0 ? null : getExp(exp.Arguments[0]);
|
||||||
switch (exp.Method.Name) {
|
switch (exp.Method.Name) {
|
||||||
case "Add": return $"date_add({left}, interval ({args1}) microsecond)";
|
case "Add": return $"datetime({left},({args1})||' seconds')";
|
||||||
case "AddDays": return $"date_add({left}, interval ({args1}) day)";
|
case "AddDays": return $"datetime({left},({args1})||' days')";
|
||||||
case "AddHours": return $"date_add({left}, interval ({args1}) hour)";
|
case "AddHours": return $"datetime({left},({args1})||' hours')";
|
||||||
case "AddMilliseconds": return $"date_add({left}, interval ({args1})*1000 microsecond)";
|
case "AddMilliseconds": return $"datetime({left},(({args1})/1000)||' seconds')";
|
||||||
case "AddMinutes": return $"date_add({left}, interval ({args1}) minute)";
|
case "AddMinutes": return $"datetime({left},({args1})||' seconds')";
|
||||||
case "AddMonths": return $"date_add({left}, interval ({args1}) month)";
|
case "AddMonths": return $"datetime({left},({args1})||' months')";
|
||||||
case "AddSeconds": return $"date_add({left}, interval ({args1}) second)";
|
case "AddSeconds": return $"datetime({left},({args1})||' seconds')";
|
||||||
case "AddTicks": return $"date_add({left}, interval ({args1})/10 microsecond)";
|
case "AddTicks": return $"datetime({left},(({args1})/10000000)||' seconds')";
|
||||||
case "AddYears": return $"date_add({left}, interval ({args1}) year)";
|
case "AddYears": return $"datetime({left},({args1})||' years')";
|
||||||
case "Subtract":
|
case "Subtract":
|
||||||
if (exp.Arguments[0].Type.FullName == "System.DateTime" || exp.Arguments[0].Type.GenericTypeArguments.FirstOrDefault()?.FullName == "System.DateTime")
|
if (exp.Arguments[0].Type.FullName == "System.DateTime" || exp.Arguments[0].Type.GenericTypeArguments.FirstOrDefault()?.FullName == "System.DateTime")
|
||||||
return $"timestampdiff(microsecond, {args1}, {left})";
|
return $"(strftime('%s',{left})-strftime('%s',{args1}))";
|
||||||
if (exp.Arguments[0].Type.FullName == "System.TimeSpan" || exp.Arguments[0].Type.GenericTypeArguments.FirstOrDefault()?.FullName == "System.TimeSpan")
|
if (exp.Arguments[0].Type.FullName == "System.TimeSpan" || exp.Arguments[0].Type.GenericTypeArguments.FirstOrDefault()?.FullName == "System.TimeSpan")
|
||||||
return $"date_sub({left}, interval ({args1}) microsecond)";
|
return $"datetime({left},(-{args1})||' seconds')";
|
||||||
break;
|
break;
|
||||||
case "Equals": return $"({left} = {getExp(exp.Arguments[0])})";
|
case "Equals": return $"({left} = {getExp(exp.Arguments[0])})";
|
||||||
case "CompareTo": return $"(({left}) - ({getExp(exp.Arguments[0])}))";
|
case "CompareTo": return $"(strftime('%s',{left})-strftime('%s',{args1}))";
|
||||||
case "ToString": return $"date_format({left}, '%Y-%m-%d %H:%i:%s.%f')";
|
case "ToString": return $"strftime('%Y-%m-%d %H:%M.%f',{left})";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Exception($"MySqlExpression 未现实函数表达式 {exp} 解析");
|
throw new Exception($"SqliteExpression 未现实函数表达式 {exp} 解析");
|
||||||
}
|
}
|
||||||
internal override string ExpressionLambdaToSqlCallTimeSpan(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, Func<Expression[], string> getSelectGroupingMapString, SelectTableInfoType tbtype, bool isQuoteName) {
|
internal override string ExpressionLambdaToSqlCallTimeSpan(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, Func<Expression[], string> getSelectGroupingMapString, SelectTableInfoType tbtype, bool isQuoteName) {
|
||||||
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName);
|
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName);
|
||||||
@ -264,16 +269,16 @@ namespace FreeSql.Sqlite3 {
|
|||||||
switch (exp.Method.Name) {
|
switch (exp.Method.Name) {
|
||||||
case "Compare": return $"({getExp(exp.Arguments[0])}-({getExp(exp.Arguments[1])}))";
|
case "Compare": return $"({getExp(exp.Arguments[0])}-({getExp(exp.Arguments[1])}))";
|
||||||
case "Equals": return $"({getExp(exp.Arguments[0])} = {getExp(exp.Arguments[1])})";
|
case "Equals": return $"({getExp(exp.Arguments[0])} = {getExp(exp.Arguments[1])})";
|
||||||
case "FromDays": return $"(({getExp(exp.Arguments[0])})*{(long)1000000 * 60 * 60 * 24})";
|
case "FromDays": return $"(({getExp(exp.Arguments[0])})*{60 * 60 * 24})";
|
||||||
case "FromHours": return $"(({getExp(exp.Arguments[0])})*{(long)1000000 * 60 * 60})";
|
case "FromHours": return $"(({getExp(exp.Arguments[0])})*{60 * 60})";
|
||||||
case "FromMilliseconds": return $"(({getExp(exp.Arguments[0])})*1000)";
|
case "FromMilliseconds": return $"(({getExp(exp.Arguments[0])})/1000)";
|
||||||
case "FromMinutes": return $"(({getExp(exp.Arguments[0])})*{(long)1000000 * 60})";
|
case "FromMinutes": return $"(({getExp(exp.Arguments[0])})*60)";
|
||||||
case "FromSeconds": return $"(({getExp(exp.Arguments[0])})*1000000)";
|
case "FromSeconds": return $"(({getExp(exp.Arguments[0])}))";
|
||||||
case "FromTicks": return $"(({getExp(exp.Arguments[0])})/10)";
|
case "FromTicks": return $"(({getExp(exp.Arguments[0])})/10000000)";
|
||||||
case "Parse": return $"cast({getExp(exp.Arguments[0])} as signed)";
|
case "Parse": return $"cast({getExp(exp.Arguments[0])} as bigint)";
|
||||||
case "ParseExact":
|
case "ParseExact":
|
||||||
case "TryParse":
|
case "TryParse":
|
||||||
case "TryParseExact": return $"cast({getExp(exp.Arguments[0])} as signed)";
|
case "TryParseExact": return $"cast({getExp(exp.Arguments[0])} as bigint)";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var left = getExp(exp.Object);
|
var left = getExp(exp.Object);
|
||||||
@ -283,33 +288,33 @@ namespace FreeSql.Sqlite3 {
|
|||||||
case "Subtract": return $"({left}-({args1}))";
|
case "Subtract": return $"({left}-({args1}))";
|
||||||
case "Equals": return $"({left} = {getExp(exp.Arguments[0])})";
|
case "Equals": return $"({left} = {getExp(exp.Arguments[0])})";
|
||||||
case "CompareTo": return $"({left}-({getExp(exp.Arguments[0])}))";
|
case "CompareTo": return $"({left}-({getExp(exp.Arguments[0])}))";
|
||||||
case "ToString": return $"cast({left} as char)";
|
case "ToString": return $"cast({left} as character)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Exception($"MySqlExpression 未现实函数表达式 {exp} 解析");
|
throw new Exception($"SqliteExpression 未现实函数表达式 {exp} 解析");
|
||||||
}
|
}
|
||||||
internal override string ExpressionLambdaToSqlCallConvert(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, Func<Expression[], string> getSelectGroupingMapString, SelectTableInfoType tbtype, bool isQuoteName) {
|
internal override string ExpressionLambdaToSqlCallConvert(MethodCallExpression exp, List<SelectTableInfo> _tables, List<SelectColumnInfo> _selectColumnMap, Func<Expression[], string> getSelectGroupingMapString, SelectTableInfoType tbtype, bool isQuoteName) {
|
||||||
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName);
|
Func<Expression, string> getExp = exparg => ExpressionLambdaToSql(exparg, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName);
|
||||||
if (exp.Object == null) {
|
if (exp.Object == null) {
|
||||||
switch (exp.Method.Name) {
|
switch (exp.Method.Name) {
|
||||||
case "ToBoolean": return $"({getExp(exp.Arguments[0])} not in ('0','false'))";
|
case "ToBoolean": return $"({getExp(exp.Arguments[0])} not in ('0','false'))";
|
||||||
case "ToByte": return $"cast({getExp(exp.Arguments[0])} as unsigned)";
|
case "ToByte": return $"cast({getExp(exp.Arguments[0])} as int2)";
|
||||||
case "ToChar": return $"substr(cast({getExp(exp.Arguments[0])} as char), 1, 1)";
|
case "ToChar": return $"substr(cast({getExp(exp.Arguments[0])} as character), 1, 1)";
|
||||||
case "ToDateTime": return $"cast({getExp(exp.Arguments[0])} as datetime)";
|
case "ToDateTime": return $"datetime({getExp(exp.Arguments[0])})";
|
||||||
case "ToDecimal": return $"cast({getExp(exp.Arguments[0])} as decimal(36,18))";
|
case "ToDecimal": return $"cast({getExp(exp.Arguments[0])} as decimal(36,18))";
|
||||||
case "ToDouble": return $"cast({getExp(exp.Arguments[0])} as decimal(32,16))";
|
case "ToDouble": return $"cast({getExp(exp.Arguments[0])} as double)";
|
||||||
case "ToInt16":
|
case "ToInt16":
|
||||||
case "ToInt32":
|
case "ToInt32":
|
||||||
case "ToInt64":
|
case "ToInt64":
|
||||||
case "ToSByte": return $"cast({getExp(exp.Arguments[0])} as signed)";
|
case "ToSByte": return $"cast({getExp(exp.Arguments[0])} as smallint)";
|
||||||
case "ToSingle": return $"cast({getExp(exp.Arguments[0])} as decimal(14,7))";
|
case "ToSingle": return $"cast({getExp(exp.Arguments[0])} as float)";
|
||||||
case "ToString": return $"cast({getExp(exp.Arguments[0])} as char)";
|
case "ToString": return $"cast({getExp(exp.Arguments[0])} as character)";
|
||||||
case "ToUInt16":
|
case "ToUInt16": return $"cast({getExp(exp.Arguments[0])} as unsigned)";
|
||||||
case "ToUInt32":
|
case "ToUInt32": return $"cast({getExp(exp.Arguments[0])} as decimal(10,0))";
|
||||||
case "ToUInt64": return $"cast({getExp(exp.Arguments[0])} as unsigned)";
|
case "ToUInt64": return $"cast({getExp(exp.Arguments[0])} as decimal(21,0))";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Exception($"MySqlExpression 未现实函数表达式 {exp} 解析");
|
throw new Exception($"SqliteExpression 未现实函数表达式 {exp} 解析");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
using FreeSql.Internal;
|
using FreeSql.Internal;
|
||||||
using FreeSql.Internal.CommonProvider;
|
using FreeSql.Internal.CommonProvider;
|
||||||
using FreeSql.Sqlite3.Curd;
|
using FreeSql.Sqlite.Curd;
|
||||||
using Microsoft.Extensions.Caching.Distributed;
|
using Microsoft.Extensions.Caching.Distributed;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
@ -8,7 +8,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
|
|
||||||
namespace FreeSql.Sqlite3 {
|
namespace FreeSql.Sqlite {
|
||||||
|
|
||||||
class SqliteProvider : IFreeSql {
|
class SqliteProvider : IFreeSql {
|
||||||
|
|
@ -6,7 +6,7 @@ using System.Data;
|
|||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Data.SQLite;
|
using System.Data.SQLite;
|
||||||
|
|
||||||
namespace FreeSql.Sqlite3 {
|
namespace FreeSql.Sqlite {
|
||||||
|
|
||||||
class SqliteUtils : CommonUtils {
|
class SqliteUtils : CommonUtils {
|
||||||
IFreeSql _orm;
|
IFreeSql _orm;
|
||||||
@ -18,10 +18,17 @@ namespace FreeSql.Sqlite3 {
|
|||||||
if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}";
|
if (string.IsNullOrEmpty(parameterName)) parameterName = $"p_{_params?.Count}";
|
||||||
else if (_orm.CodeFirst.IsSyncStructureToLower) parameterName = parameterName.ToLower();
|
else if (_orm.CodeFirst.IsSyncStructureToLower) parameterName = parameterName.ToLower();
|
||||||
var dbtype = (DbType)_orm.CodeFirst.GetDbInfo(type)?.type;
|
var dbtype = (DbType)_orm.CodeFirst.GetDbInfo(type)?.type;
|
||||||
if (dbtype == DbType.Time) {
|
switch (dbtype) {
|
||||||
if (value == null) value = null;
|
case DbType.Guid:
|
||||||
else value = ((TimeSpan)value).Ticks / 10000;
|
if (value == null) value = null;
|
||||||
dbtype = DbType.Int64;
|
else value = ((Guid)value).ToString();
|
||||||
|
dbtype = DbType.String;
|
||||||
|
break;
|
||||||
|
case DbType.Time:
|
||||||
|
if (value == null) value = null;
|
||||||
|
else value = ((TimeSpan)value).Ticks / 10000;
|
||||||
|
dbtype = DbType.Int64;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
var ret = new SQLiteParameter { ParameterName = $"@{parameterName}", DbType = dbtype, Value = value };
|
var ret = new SQLiteParameter { ParameterName = $"@{parameterName}", DbType = dbtype, Value = value };
|
||||||
_params?.Add(ret);
|
_params?.Add(ret);
|
||||||
@ -31,10 +38,17 @@ namespace FreeSql.Sqlite3 {
|
|||||||
internal override DbParameter[] GetDbParamtersByObject(string sql, object obj) =>
|
internal override DbParameter[] GetDbParamtersByObject(string sql, object obj) =>
|
||||||
Utils.GetDbParamtersByObject<SQLiteParameter>(sql, obj, "@", (name, type, value) => {
|
Utils.GetDbParamtersByObject<SQLiteParameter>(sql, obj, "@", (name, type, value) => {
|
||||||
var dbtype = (DbType)_orm.CodeFirst.GetDbInfo(type)?.type;
|
var dbtype = (DbType)_orm.CodeFirst.GetDbInfo(type)?.type;
|
||||||
if (dbtype == DbType.Time) {
|
switch (dbtype) {
|
||||||
if (value == null) value = null;
|
case DbType.Guid:
|
||||||
else value = ((TimeSpan)value).Ticks / 10000;
|
if (value == null) value = null;
|
||||||
dbtype = DbType.Int64;
|
else value = ((Guid)value).ToString();
|
||||||
|
dbtype = DbType.String;
|
||||||
|
break;
|
||||||
|
case DbType.Time:
|
||||||
|
if (value == null) value = null;
|
||||||
|
else value = ((TimeSpan)value).Ticks / 10000;
|
||||||
|
dbtype = DbType.Int64;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
var ret = new SQLiteParameter { ParameterName = $"@{name}", DbType = dbtype, Value = value };
|
var ret = new SQLiteParameter { ParameterName = $"@{name}", DbType = dbtype, Value = value };
|
||||||
return ret;
|
return ret;
|
@ -4,7 +4,7 @@ FreeSql 是轻量化、可扩展和跨平台版的 .NETStandard 数据访问技
|
|||||||
|
|
||||||
FreeSql 可用作对象关系映射程序 (O/RM),以便于开发人员能够使用 .NETStandard 对象来处理数据库,不必经常编写大部分数据访问代码。
|
FreeSql 可用作对象关系映射程序 (O/RM),以便于开发人员能够使用 .NETStandard 对象来处理数据库,不必经常编写大部分数据访问代码。
|
||||||
|
|
||||||
FreeSql 支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite3 数据库技术实现。
|
FreeSql 支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库技术实现。
|
||||||
|
|
||||||
FreeSql 打造 .NETCore 最方便的 ORM,dbfirst codefirst混合使用,codefirst模式下的开发阶段,建好实体不用执行任何操作即能创建表和修改字段,dbfirst模式下提供api+模板自定义生成代码,作者提供了3种模板,您可以持续关注或者参与给出宝贵意见,QQ群:4336577。
|
FreeSql 打造 .NETCore 最方便的 ORM,dbfirst codefirst混合使用,codefirst模式下的开发阶段,建好实体不用执行任何操作即能创建表和修改字段,dbfirst模式下提供api+模板自定义生成代码,作者提供了3种模板,您可以持续关注或者参与给出宝贵意见,QQ群:4336577。
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user