mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
- 增加 ISelect.ToDataTable 系列方法;
- 增加 无参数化命令执行,便于调试;
This commit is contained in:
parent
aa2040a629
commit
1fa6c9bfc4
@ -5,6 +5,7 @@ using System.Collections.Concurrent;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Data;
|
||||||
|
|
||||||
public static class FreeSqlRepositoryIFreeSqlExtenssions {
|
public static class FreeSqlRepositoryIFreeSqlExtenssions {
|
||||||
|
|
||||||
|
@ -85,10 +85,23 @@ namespace FreeSql.Tests.MySql {
|
|||||||
.ToSql();
|
.ToSql();
|
||||||
|
|
||||||
var songs = g.mysql.Select<Song>().Limit(10).ToList();
|
var songs = g.mysql.Select<Song>().Limit(10).ToList();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ToDataTable() {
|
||||||
|
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, g.mysql.Insert<Topic>().AppendData(items.First()).ExecuteAffrows());
|
||||||
|
Assert.Equal(10, g.mysql.Insert<Topic>().AppendData(items).ExecuteAffrows());
|
||||||
|
|
||||||
|
items = Enumerable.Range(0, 9989).Select(a => new Topic { Title = "newtitle" + a, CreateTime = DateTime.Now }).ToList();
|
||||||
|
Assert.Equal(9989, g.mysql.Insert<Topic>(items).ExecuteAffrows());
|
||||||
|
|
||||||
|
var dt1 = select.Limit(10).ToDataTable();
|
||||||
|
var dt2 = select.Limit(10).ToDataTable("id, 111222");
|
||||||
|
var dt3 = select.Limit(10).ToDataTable(a => new { a.Id, a.Type.Name, now = DateTime.Now });
|
||||||
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToList() {
|
public void ToList() {
|
||||||
var t0 = select.Limit(50).ToList();
|
var t0 = select.Limit(50).ToList();
|
||||||
|
@ -32,6 +32,21 @@ namespace FreeSql.Tests.Oracle {
|
|||||||
public List<TestTypeInfo> Types { get; set; }
|
public List<TestTypeInfo> Types { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ToDataTable() {
|
||||||
|
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, g.oracle.Insert<Topic>().AppendData(items.First()).ExecuteAffrows());
|
||||||
|
Assert.Equal(10, g.oracle.Insert<Topic>().AppendData(items).ExecuteAffrows());
|
||||||
|
|
||||||
|
items = Enumerable.Range(0, 9989).Select(a => new Topic { Title = "newtitle" + a, CreateTime = DateTime.Now }).ToList();
|
||||||
|
Assert.Equal(9989, g.oracle.Insert<Topic>(items).ExecuteAffrows());
|
||||||
|
|
||||||
|
var dt1 = select.Limit(10).ToDataTable();
|
||||||
|
var dt2 = select.Limit(10).ToDataTable("id, 111222");
|
||||||
|
var dt3 = select.Limit(10).ToDataTable(a => new { a.Id, a.Type.Name, now = DateTime.Now });
|
||||||
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToList() {
|
public void ToList() {
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,21 @@ namespace FreeSql.Tests.SqlServer {
|
|||||||
public List<TestTypeInfo> Types { get; set; }
|
public List<TestTypeInfo> Types { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ToDataTable() {
|
||||||
|
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.Single(g.sqlserver.Insert<Topic>().AppendData(items.First()).ExecuteInserted());
|
||||||
|
Assert.Equal(10, g.sqlserver.Insert<Topic>().AppendData(items).ExecuteInserted().Count);
|
||||||
|
|
||||||
|
//items = Enumerable.Range(0, 9989).Select(a => new Topic { Title = "newtitle" + a, CreateTime = DateTime.Now }).ToList();
|
||||||
|
//Assert.Equal(9989, g.sqlserver.Insert<Topic>(items).ExecuteAffrows());
|
||||||
|
|
||||||
|
var dt1 = select.Limit(10).ToDataTable();
|
||||||
|
var dt2 = select.Limit(10).ToDataTable("id, getdate()");
|
||||||
|
var dt3 = select.Limit(10).ToDataTable(a => new { a.Id, a.Type.Name, now = DateTime.Now });
|
||||||
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToList() {
|
public void ToList() {
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ namespace FreeSql.Tests.SqlServer {
|
|||||||
testFieldBoolNullable = true,
|
testFieldBoolNullable = true,
|
||||||
testFieldByte = byte.MaxValue,
|
testFieldByte = byte.MaxValue,
|
||||||
testFieldByteNullable = byte.MinValue,
|
testFieldByteNullable = byte.MinValue,
|
||||||
testFieldBytes = Encoding.UTF8.GetBytes("我是中国人"),
|
testFieldBytes = Encoding.GetEncoding("gb2312").GetBytes("我是中国人"),
|
||||||
testFieldDateTime = DateTime.Now,
|
testFieldDateTime = DateTime.Now,
|
||||||
testFieldDateTimeNullable = DateTime.Now.AddHours(1),
|
testFieldDateTimeNullable = DateTime.Now.AddHours(1),
|
||||||
testFieldDateTimeNullableOffset = new DateTimeOffset(DateTime.Now.AddHours(1), TimeSpan.FromHours(8)),
|
testFieldDateTimeNullableOffset = new DateTimeOffset(DateTime.Now.AddHours(1), TimeSpan.FromHours(8)),
|
||||||
|
@ -73,6 +73,21 @@ namespace FreeSql.Tests.Sqlite {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ToDataTable() {
|
||||||
|
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, g.sqlite.Insert<Topic>().AppendData(items.First()).ExecuteAffrows());
|
||||||
|
Assert.Equal(10, g.sqlite.Insert<Topic>().AppendData(items).ExecuteAffrows());
|
||||||
|
|
||||||
|
items = Enumerable.Range(0, 9989).Select(a => new Topic { Title = "newtitle" + a, CreateTime = DateTime.Now }).ToList();
|
||||||
|
Assert.Equal(9989, g.sqlite.Insert<Topic>(items).ExecuteAffrows());
|
||||||
|
|
||||||
|
var dt1 = select.Limit(10).ToDataTable();
|
||||||
|
var dt2 = select.Limit(10).ToDataTable("id, 111222");
|
||||||
|
var dt3 = select.Limit(10).ToDataTable(a => new { a.Id, a.Type.Name, now = DateTime.Now });
|
||||||
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToList() {
|
public void ToList() {
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,9 @@ using System.Text;
|
|||||||
|
|
||||||
public class g {
|
public class g {
|
||||||
|
|
||||||
public static IFreeSql mysql = new FreeSql.FreeSqlBuilder()
|
static Lazy<IFreeSql> mysqlLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||||
.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10")
|
.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10")
|
||||||
.UseAutoSyncStructure(true)
|
.UseAutoSyncStructure(true)
|
||||||
|
|
||||||
.UseMonitorCommand(
|
.UseMonitorCommand(
|
||||||
cmd => {
|
cmd => {
|
||||||
Trace.WriteLine(cmd.CommandText);
|
Trace.WriteLine(cmd.CommandText);
|
||||||
@ -18,31 +17,36 @@ public class g {
|
|||||||
Console.WriteLine(traceLog);
|
Console.WriteLine(traceLog);
|
||||||
}) //监听SQL命令对象,在执行后
|
}) //监听SQL命令对象,在执行后
|
||||||
.UseLazyLoading(true)
|
.UseLazyLoading(true)
|
||||||
.Build();
|
.Build());
|
||||||
|
public static IFreeSql mysql => mysqlLazy.Value;
|
||||||
|
|
||||||
public static IFreeSql sqlserver = new FreeSql.FreeSqlBuilder()
|
static Lazy<IFreeSql> sqlserverLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||||
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=cms;Pooling=true;Max Pool Size=10")
|
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=cms;Pooling=true;Max Pool Size=10")
|
||||||
.UseAutoSyncStructure(true)
|
.UseAutoSyncStructure(true)
|
||||||
.UseLazyLoading(true)
|
.UseLazyLoading(true)
|
||||||
.Build();
|
.Build());
|
||||||
|
public static IFreeSql sqlserver => sqlserverLazy.Value;
|
||||||
|
|
||||||
public static IFreeSql pgsql = new FreeSql.FreeSqlBuilder()
|
static Lazy<IFreeSql> pgsqlLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||||
.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=192.168.164.10;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=10")
|
.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=192.168.164.10;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=10")
|
||||||
.UseAutoSyncStructure(true)
|
.UseAutoSyncStructure(true)
|
||||||
.UseSyncStructureToLower(true)
|
.UseSyncStructureToLower(true)
|
||||||
.UseLazyLoading(true)
|
.UseLazyLoading(true)
|
||||||
.Build();
|
.Build());
|
||||||
|
public static IFreeSql pgsql => pgsqlLazy.Value;
|
||||||
|
|
||||||
public static IFreeSql oracle = new FreeSql.FreeSqlBuilder()
|
static Lazy<IFreeSql> oracleLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||||
.UseConnectionString(FreeSql.DataType.Oracle, "user id=user1;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=10")
|
.UseConnectionString(FreeSql.DataType.Oracle, "user id=user1;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=10")
|
||||||
.UseAutoSyncStructure(true)
|
.UseAutoSyncStructure(true)
|
||||||
.UseLazyLoading(true)
|
.UseLazyLoading(true)
|
||||||
.UseSyncStructureToUpper(true)
|
.UseSyncStructureToUpper(true)
|
||||||
.Build();
|
.Build());
|
||||||
|
public static IFreeSql oracle = oracleLazy.Value;
|
||||||
|
|
||||||
public static IFreeSql sqlite = new FreeSql.FreeSqlBuilder()
|
static Lazy<IFreeSql> sqliteLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||||
.UseConnectionString(FreeSql.DataType.Sqlite, @"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)
|
||||||
.UseLazyLoading(true)
|
.UseLazyLoading(true)
|
||||||
.Build();
|
.Build());
|
||||||
|
public static IFreeSql sqlite = sqliteLazy.Value;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
using System;
|
namespace FreeSql.DataAnnotations {
|
||||||
|
|
||||||
namespace FreeSql.DataAnnotations {
|
|
||||||
public class ColumnFluent {
|
public class ColumnFluent {
|
||||||
|
|
||||||
public ColumnFluent(ColumnAttribute column) {
|
public ColumnFluent(ColumnAttribute column) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Concurrent;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace FreeSql.DatabaseModel {
|
namespace FreeSql.DatabaseModel {
|
||||||
public class DbColumnInfo {
|
public class DbColumnInfo {
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace FreeSql.DatabaseModel {
|
namespace FreeSql.DatabaseModel {
|
||||||
public class DbTableInfo {
|
public class DbTableInfo {
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace FreeSql.DatabaseModel {
|
namespace FreeSql.DatabaseModel {
|
||||||
public class DbEnumInfo {
|
public class DbEnumInfo {
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace FreeSql.DatabaseModel {
|
namespace FreeSql.DatabaseModel {
|
||||||
public class DbForeignInfo {
|
public class DbForeignInfo {
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace FreeSql.DatabaseModel {
|
namespace FreeSql.DatabaseModel {
|
||||||
public class DbTypeInfo {
|
public class DbTypeInfo {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
@ -43,10 +44,12 @@ public static class FreeSqlGlobalExtensions {
|
|||||||
return 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin((radLat1 - radLat2) / 2), 2) + Math.Cos(radLat1) * Math.Cos(radLat2) * Math.Pow(Math.Sin((radLng1 - radLng2) / 2), 2))) * 6378137;
|
return 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin((radLat1 - radLat2) / 2), 2) + Math.Cos(radLat1) * Math.Cos(radLat2) * Math.Pow(Math.Sin((radLng1 - radLng2) / 2), 2))) * 6378137;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ConcurrentDictionary<Type, FieldInfo[]> _dicGetFields = new ConcurrentDictionary<Type, FieldInfo[]>();
|
||||||
public static object GetEnum<T>(this IDataReader dr, int index) {
|
public static object GetEnum<T>(this IDataReader dr, int index) {
|
||||||
string value = dr.GetString(index);
|
var value = dr.GetString(index);
|
||||||
Type t = typeof(T);
|
var t = typeof(T);
|
||||||
foreach (var f in t.GetFields())
|
var fs = _dicGetFields.GetOrAdd(t, t2 => t2.GetFields());
|
||||||
|
foreach (var f in fs)
|
||||||
if (f.GetCustomAttribute<DescriptionAttribute>()?.Description == value || f.Name == value) return Enum.Parse(t, f.Name, true);
|
if (f.GetCustomAttribute<DescriptionAttribute>()?.Description == value || f.Name == value) return Enum.Parse(t, f.Name, true);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -60,10 +63,11 @@ public static class FreeSqlGlobalExtensions {
|
|||||||
return Convert.ToInt64(item);
|
return Convert.ToInt64(item);
|
||||||
}
|
}
|
||||||
public static IEnumerable<T> ToSet<T>(this long value) {
|
public static IEnumerable<T> ToSet<T>(this long value) {
|
||||||
List<T> ret = new List<T>();
|
var ret = new List<T>();
|
||||||
if (value == 0) return ret;
|
if (value == 0) return ret;
|
||||||
Type t = typeof(T);
|
var t = typeof(T);
|
||||||
foreach (FieldInfo f in t.GetFields()) {
|
var fs = _dicGetFields.GetOrAdd(t, t2 => t2.GetFields());
|
||||||
|
foreach (var f in fs) {
|
||||||
if (f.FieldType != t) continue;
|
if (f.FieldType != t) continue;
|
||||||
object o = Enum.Parse(t, f.Name, true);
|
object o = Enum.Parse(t, f.Name, true);
|
||||||
long v = (long)o;
|
long v = (long)o;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -15,6 +16,13 @@ namespace FreeSql {
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
TSelect WithTransaction(DbTransaction transaction);
|
TSelect WithTransaction(DbTransaction transaction);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行SQL查询,返回 DataTable
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
DataTable ToDataTable(string field = null);
|
||||||
|
Task<DataTable> ToDataTableAsync(string field = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 执行SQL查询,返回 T1 实体所有字段的记录,记录不存在时返回 Count 为 0 的列表
|
/// 执行SQL查询,返回 T1 实体所有字段的记录,记录不存在时返回 Count 为 0 的列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -14,6 +15,13 @@ namespace FreeSql {
|
|||||||
bool Any(Expression<Func<T1, bool>> exp);
|
bool Any(Expression<Func<T1, bool>> exp);
|
||||||
Task<bool> AnyAsync(Expression<Func<T1, bool>> exp);
|
Task<bool> AnyAsync(Expression<Func<T1, bool>> exp);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行SQL查询,返回 DataTable
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
DataTable ToDataTable<TReturn>(Expression<Func<T1, TReturn>> select);
|
||||||
|
Task<DataTable> ToDataTableAsync<TReturn>(Expression<Func<T1, TReturn>> select);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 执行SQL查询,返回指定字段的记录,记录不存在时返回 Count 为 0 的列表
|
/// 执行SQL查询,返回指定字段的记录,记录不存在时返回 Count 为 0 的列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -9,6 +10,9 @@ namespace FreeSql {
|
|||||||
bool Any(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool>> exp);
|
bool Any(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool>> exp);
|
||||||
Task<bool> AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool>> exp);
|
Task<bool> AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool>> exp);
|
||||||
|
|
||||||
|
DataTable ToDataTable<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TReturn>> select);
|
||||||
|
Task<DataTable> ToDataTableAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TReturn>> select);
|
||||||
|
|
||||||
List<TReturn> ToList<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TReturn>> select);
|
List<TReturn> ToList<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TReturn>> select);
|
||||||
Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TReturn>> select);
|
Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TReturn>> select);
|
||||||
string ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TReturn>> select);
|
string ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TReturn>> select);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -9,6 +10,9 @@ namespace FreeSql {
|
|||||||
bool Any(Expression<Func<T1, T2, T3, bool>> exp);
|
bool Any(Expression<Func<T1, T2, T3, bool>> exp);
|
||||||
Task<bool> AnyAsync(Expression<Func<T1, T2, T3, bool>> exp);
|
Task<bool> AnyAsync(Expression<Func<T1, T2, T3, bool>> exp);
|
||||||
|
|
||||||
|
DataTable ToDataTable<TReturn>(Expression<Func<T1, T2, T3, TReturn>> select);
|
||||||
|
Task<DataTable> ToDataTableAsync<TReturn>(Expression<Func<T1, T2, T3, TReturn>> select);
|
||||||
|
|
||||||
List<TReturn> ToList<TReturn>(Expression<Func<T1, T2, T3, TReturn>> select);
|
List<TReturn> ToList<TReturn>(Expression<Func<T1, T2, T3, TReturn>> select);
|
||||||
Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<T1, T2, T3, TReturn>> select);
|
Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<T1, T2, T3, TReturn>> select);
|
||||||
string ToSql<TReturn>(Expression<Func<T1, T2, T3, TReturn>> select);
|
string ToSql<TReturn>(Expression<Func<T1, T2, T3, TReturn>> select);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -9,6 +10,9 @@ namespace FreeSql {
|
|||||||
bool Any(Expression<Func<T1, T2, T3, T4, bool>> exp);
|
bool Any(Expression<Func<T1, T2, T3, T4, bool>> exp);
|
||||||
Task<bool> AnyAsync(Expression<Func<T1, T2, T3, T4, bool>> exp);
|
Task<bool> AnyAsync(Expression<Func<T1, T2, T3, T4, bool>> exp);
|
||||||
|
|
||||||
|
DataTable ToDataTable<TReturn>(Expression<Func<T1, T2, T3, T4, TReturn>> select);
|
||||||
|
Task<DataTable> ToDataTableAsync<TReturn>(Expression<Func<T1, T2, T3, T4, TReturn>> select);
|
||||||
|
|
||||||
List<TReturn> ToList<TReturn>(Expression<Func<T1, T2, T3, T4, TReturn>> select);
|
List<TReturn> ToList<TReturn>(Expression<Func<T1, T2, T3, T4, TReturn>> select);
|
||||||
Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, TReturn>> select);
|
Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, TReturn>> select);
|
||||||
string ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, TReturn>> select);
|
string ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, TReturn>> select);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -9,6 +10,9 @@ namespace FreeSql {
|
|||||||
bool Any(Expression<Func<T1, T2, T3, T4, T5, bool>> exp);
|
bool Any(Expression<Func<T1, T2, T3, T4, T5, bool>> exp);
|
||||||
Task<bool> AnyAsync(Expression<Func<T1, T2, T3, T4, T5, bool>> exp);
|
Task<bool> AnyAsync(Expression<Func<T1, T2, T3, T4, T5, bool>> exp);
|
||||||
|
|
||||||
|
DataTable ToDataTable<TReturn>(Expression<Func<T1, T2, T3, T4, T5, TReturn>> select);
|
||||||
|
Task<DataTable> ToDataTableAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, TReturn>> select);
|
||||||
|
|
||||||
List<TReturn> ToList<TReturn>(Expression<Func<T1, T2, T3, T4, T5, TReturn>> select);
|
List<TReturn> ToList<TReturn>(Expression<Func<T1, T2, T3, T4, T5, TReturn>> select);
|
||||||
Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, TReturn>> select);
|
Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, TReturn>> select);
|
||||||
string ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, TReturn>> select);
|
string ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, TReturn>> select);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -9,6 +10,9 @@ namespace FreeSql {
|
|||||||
bool Any(Expression<Func<T1, T2, T3, T4, T5, T6, bool>> exp);
|
bool Any(Expression<Func<T1, T2, T3, T4, T5, T6, bool>> exp);
|
||||||
Task<bool> AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, bool>> exp);
|
Task<bool> AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, bool>> exp);
|
||||||
|
|
||||||
|
DataTable ToDataTable<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, TReturn>> select);
|
||||||
|
Task<DataTable> ToDataTableAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, TReturn>> select);
|
||||||
|
|
||||||
List<TReturn> ToList<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, TReturn>> select);
|
List<TReturn> ToList<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, TReturn>> select);
|
||||||
Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, TReturn>> select);
|
Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, TReturn>> select);
|
||||||
string ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, TReturn>> select);
|
string ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, TReturn>> select);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -9,6 +10,9 @@ namespace FreeSql {
|
|||||||
bool Any(Expression<Func<T1, T2, T3, T4, T5, T6, T7, bool>> exp);
|
bool Any(Expression<Func<T1, T2, T3, T4, T5, T6, T7, bool>> exp);
|
||||||
Task<bool> AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, T7, bool>> exp);
|
Task<bool> AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, T7, bool>> exp);
|
||||||
|
|
||||||
|
DataTable ToDataTable<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, TReturn>> select);
|
||||||
|
Task<DataTable> ToDataTableAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, TReturn>> select);
|
||||||
|
|
||||||
List<TReturn> ToList<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, TReturn>> select);
|
List<TReturn> ToList<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, TReturn>> select);
|
||||||
Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, TReturn>> select);
|
Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, TReturn>> select);
|
||||||
string ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, TReturn>> select);
|
string ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, TReturn>> select);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -9,6 +10,9 @@ namespace FreeSql {
|
|||||||
bool Any(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, bool>> exp);
|
bool Any(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, bool>> exp);
|
||||||
Task<bool> AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, bool>> exp);
|
Task<bool> AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, bool>> exp);
|
||||||
|
|
||||||
|
DataTable ToDataTable<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, TReturn>> select);
|
||||||
|
Task<DataTable> ToDataTableAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, TReturn>> select);
|
||||||
|
|
||||||
List<TReturn> ToList<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, TReturn>> select);
|
List<TReturn> ToList<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, TReturn>> select);
|
||||||
Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, TReturn>> select);
|
Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, TReturn>> select);
|
||||||
string ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, TReturn>> select);
|
string ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, TReturn>> select);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -9,6 +10,9 @@ namespace FreeSql {
|
|||||||
bool Any(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, bool>> exp);
|
bool Any(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, bool>> exp);
|
||||||
Task<bool> AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, bool>> exp);
|
Task<bool> AnyAsync(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, bool>> exp);
|
||||||
|
|
||||||
|
DataTable ToDataTable<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>> select);
|
||||||
|
Task<DataTable> ToDataTableAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>> select);
|
||||||
|
|
||||||
List<TReturn> ToList<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>> select);
|
List<TReturn> ToList<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>> select);
|
||||||
Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>> select);
|
Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>> select);
|
||||||
string ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>> select);
|
string ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>> select);
|
||||||
|
@ -81,7 +81,9 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
++colidx;
|
++colidx;
|
||||||
}
|
}
|
||||||
sb.Append(") VALUES");
|
sb.Append(") VALUES");
|
||||||
_params = new DbParameter[colidx * _source.Count];
|
//_params = new DbParameter[colidx * _source.Count];
|
||||||
|
_params = new DbParameter[0];
|
||||||
|
//_params = new DbParameter[colidx * 5]; //批量添加第5行起,不使用参数化
|
||||||
var didx = 0;
|
var didx = 0;
|
||||||
foreach (var d in _source) {
|
foreach (var d in _source) {
|
||||||
if (didx > 0) sb.Append(", ");
|
if (didx > 0) sb.Append(", ");
|
||||||
@ -90,14 +92,18 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
foreach (var col in _table.Columns.Values)
|
foreach (var col in _table.Columns.Values)
|
||||||
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name) == false) {
|
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name) == false) {
|
||||||
if (colidx2 > 0) sb.Append(", ");
|
if (colidx2 > 0) sb.Append(", ");
|
||||||
sb.Append(_commonUtils.QuoteWriteParamter(col.CsType, $"{_commonUtils.QuoteParamterName(col.CsName)}{didx}"));
|
|
||||||
object val = null;
|
object val = null;
|
||||||
if (_table.Properties.TryGetValue(col.CsName, out var tryp)) {
|
if (_table.Properties.TryGetValue(col.CsName, out var tryp)) {
|
||||||
val = tryp.GetValue(d);
|
val = tryp.GetValue(d);
|
||||||
if (col.Attribute.IsPrimary && (col.CsType == typeof(Guid) || col.CsType == typeof(Guid?))
|
if (col.Attribute.IsPrimary && (col.CsType == typeof(Guid) || col.CsType == typeof(Guid?))
|
||||||
&& (val == null || (Guid)val == Guid.Empty)) tryp.SetValue(d, val = FreeUtil.NewMongodbId());
|
&& (val == null || (Guid)val == Guid.Empty)) tryp.SetValue(d, val = FreeUtil.NewMongodbId());
|
||||||
}
|
}
|
||||||
_params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}{didx}", col.CsType, val);
|
//if (didx >= 5)
|
||||||
|
sb.Append(_commonUtils.GetNoneParamaterSqlValue(col.CsType, val));
|
||||||
|
//else {
|
||||||
|
// sb.Append(_commonUtils.QuoteWriteParamter(col.CsType, $"{_commonUtils.QuoteParamterName(col.CsName)}{didx}"));
|
||||||
|
// _params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}{didx}", col.CsType, val);
|
||||||
|
//}
|
||||||
++colidx2;
|
++colidx2;
|
||||||
}
|
}
|
||||||
sb.Append(")");
|
sb.Append(")");
|
||||||
|
@ -152,6 +152,21 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
}
|
}
|
||||||
public TSelect Take(int limit) => this.Limit(limit) as TSelect;
|
public TSelect Take(int limit) => this.Limit(limit) as TSelect;
|
||||||
|
|
||||||
|
public DataTable ToDataTable(string field = null) {
|
||||||
|
var sql = this.ToSql(field);
|
||||||
|
if (_cache.seconds > 0 && string.IsNullOrEmpty(_cache.key)) _cache.key = sql;
|
||||||
|
|
||||||
|
return _orm.Cache.Shell(_cache.key, _cache.seconds, () =>
|
||||||
|
_orm.Ado.ExecuteDataTable(_transaction, CommandType.Text, sql, _params.ToArray()));
|
||||||
|
}
|
||||||
|
public Task<DataTable> ToDataTableAsync(string field = null) {
|
||||||
|
var sql = this.ToSql(field);
|
||||||
|
if (_cache.seconds > 0 && string.IsNullOrEmpty(_cache.key)) _cache.key = sql;
|
||||||
|
|
||||||
|
return _orm.Cache.ShellAsync(_cache.key, _cache.seconds, () =>
|
||||||
|
_orm.Ado.ExecuteDataTableAsync(_transaction, CommandType.Text, sql, _params.ToArray()));
|
||||||
|
}
|
||||||
|
|
||||||
public List<TTuple> ToList<TTuple>(string field) {
|
public List<TTuple> ToList<TTuple>(string field) {
|
||||||
var sql = this.ToSql(field);
|
var sql = this.ToSql(field);
|
||||||
if (_cache.seconds > 0 && string.IsNullOrEmpty(_cache.key)) _cache.key = sql;
|
if (_cache.seconds > 0 && string.IsNullOrEmpty(_cache.key)) _cache.key = sql;
|
||||||
@ -472,6 +487,9 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
return this.ToSql(af.field);
|
return this.ToSql(af.field);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected DataTable InternalToDataTable(Expression select) => _orm.Ado.ExecuteDataTable(_transaction, CommandType.Text, this.InternalToSql<int>(select), _params.ToArray());
|
||||||
|
protected Task<DataTable> InternalToDataTableAsync(Expression select) => _orm.Ado.ExecuteDataTableAsync(_transaction, CommandType.Text, this.InternalToSql<int>(select), _params.ToArray());
|
||||||
|
|
||||||
protected TReturn InternalToAggregate<TReturn>(Expression select) {
|
protected TReturn InternalToAggregate<TReturn>(Expression select) {
|
||||||
var map = new ReadAnonymousTypeInfo();
|
var map = new ReadAnonymousTypeInfo();
|
||||||
var field = new StringBuilder();
|
var field = new StringBuilder();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -51,6 +52,10 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
|
|
||||||
Task<List<TReturn>> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>.ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TReturn>> select) => this.InternalToListAsync<TReturn>(select?.Body);
|
Task<List<TReturn>> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>.ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TReturn>> select) => this.InternalToListAsync<TReturn>(select?.Body);
|
||||||
|
|
||||||
|
DataTable ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>.ToDataTable<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TReturn>> select) => this.InternalToDataTable(select?.Body);
|
||||||
|
|
||||||
|
Task<DataTable> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>.ToDataTableAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TReturn>> select) => this.InternalToDataTableAsync(select?.Body);
|
||||||
|
|
||||||
string ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TReturn>> select) => this.InternalToSql<TReturn>(select?.Body);
|
string ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TReturn>> select) => this.InternalToSql<TReturn>(select?.Body);
|
||||||
|
|
||||||
ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>.Where(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool>> exp) => this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null));
|
ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>.Where(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool>> exp) => this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null));
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using FreeSql.Internal.Model;
|
using FreeSql.Internal.Model;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -99,6 +100,10 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
|
|
||||||
public Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<T1, TReturn>> select) => this.InternalToListAsync<TReturn>(select?.Body);
|
public Task<List<TReturn>> ToListAsync<TReturn>(Expression<Func<T1, TReturn>> select) => this.InternalToListAsync<TReturn>(select?.Body);
|
||||||
|
|
||||||
|
public DataTable ToDataTable<TReturn>(Expression<Func<T1, TReturn>> select) => this.InternalToDataTable(select?.Body);
|
||||||
|
|
||||||
|
public Task<DataTable> ToDataTableAsync<TReturn>(Expression<Func<T1, TReturn>> select) => this.InternalToDataTableAsync(select?.Body);
|
||||||
|
|
||||||
public string ToSql<TReturn>(Expression<Func<T1, TReturn>> select) => this.InternalToSql<TReturn>(select?.Body);
|
public string ToSql<TReturn>(Expression<Func<T1, TReturn>> select) => this.InternalToSql<TReturn>(select?.Body);
|
||||||
|
|
||||||
public TReturn ToAggregate<TReturn>(Expression<Func<ISelectGroupingAggregate<T1>, TReturn>> select) => this.InternalToAggregate<TReturn>(select?.Body);
|
public TReturn ToAggregate<TReturn>(Expression<Func<ISelectGroupingAggregate<T1>, TReturn>> select) => this.InternalToAggregate<TReturn>(select?.Body);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -44,6 +45,10 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
|
|
||||||
Task<List<TReturn>> ISelect<T1, T2, T3>.ToListAsync<TReturn>(Expression<Func<T1, T2, T3, TReturn>> select) => this.InternalToListAsync<TReturn>(select?.Body);
|
Task<List<TReturn>> ISelect<T1, T2, T3>.ToListAsync<TReturn>(Expression<Func<T1, T2, T3, TReturn>> select) => this.InternalToListAsync<TReturn>(select?.Body);
|
||||||
|
|
||||||
|
DataTable ISelect<T1, T2, T3>.ToDataTable<TReturn>(Expression<Func<T1, T2, T3, TReturn>> select) => this.InternalToDataTable(select?.Body);
|
||||||
|
|
||||||
|
Task<DataTable> ISelect<T1, T2, T3>.ToDataTableAsync<TReturn>(Expression<Func<T1, T2, T3, TReturn>> select) => this.InternalToDataTableAsync(select?.Body);
|
||||||
|
|
||||||
string ISelect<T1, T2, T3>.ToSql<TReturn>(Expression<Func<T1, T2, T3, TReturn>> select) => this.InternalToSql<TReturn>(select?.Body);
|
string ISelect<T1, T2, T3>.ToSql<TReturn>(Expression<Func<T1, T2, T3, TReturn>> select) => this.InternalToSql<TReturn>(select?.Body);
|
||||||
|
|
||||||
ISelect<T1, T2, T3> ISelect<T1, T2, T3>.Where(Expression<Func<T1, T2, T3, bool>> exp) => this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null));
|
ISelect<T1, T2, T3> ISelect<T1, T2, T3>.Where(Expression<Func<T1, T2, T3, bool>> exp) => this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null));
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -45,6 +46,10 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
|
|
||||||
Task<List<TReturn>> ISelect<T1, T2, T3, T4>.ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, TReturn>> select) => this.InternalToListAsync<TReturn>(select?.Body);
|
Task<List<TReturn>> ISelect<T1, T2, T3, T4>.ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, TReturn>> select) => this.InternalToListAsync<TReturn>(select?.Body);
|
||||||
|
|
||||||
|
DataTable ISelect<T1, T2, T3, T4>.ToDataTable<TReturn>(Expression<Func<T1, T2, T3, T4, TReturn>> select) => this.InternalToDataTable(select?.Body);
|
||||||
|
|
||||||
|
Task<DataTable> ISelect<T1, T2, T3, T4>.ToDataTableAsync<TReturn>(Expression<Func<T1, T2, T3, T4, TReturn>> select) => this.InternalToDataTableAsync(select?.Body);
|
||||||
|
|
||||||
string ISelect<T1, T2, T3, T4>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, TReturn>> select) => this.InternalToSql<TReturn>(select?.Body);
|
string ISelect<T1, T2, T3, T4>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, TReturn>> select) => this.InternalToSql<TReturn>(select?.Body);
|
||||||
|
|
||||||
ISelect<T1, T2, T3, T4> ISelect<T1, T2, T3, T4>.Where(Expression<Func<T1, T2, T3, T4, bool>> exp) => this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null));
|
ISelect<T1, T2, T3, T4> ISelect<T1, T2, T3, T4>.Where(Expression<Func<T1, T2, T3, T4, bool>> exp) => this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null));
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -46,6 +47,10 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
|
|
||||||
Task<List<TReturn>> ISelect<T1, T2, T3, T4, T5>.ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, TReturn>> select) => this.InternalToListAsync<TReturn>(select?.Body);
|
Task<List<TReturn>> ISelect<T1, T2, T3, T4, T5>.ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, TReturn>> select) => this.InternalToListAsync<TReturn>(select?.Body);
|
||||||
|
|
||||||
|
DataTable ISelect<T1, T2, T3, T4, T5>.ToDataTable<TReturn>(Expression<Func<T1, T2, T3, T4, T5, TReturn>> select) => this.InternalToDataTable(select?.Body);
|
||||||
|
|
||||||
|
Task<DataTable> ISelect<T1, T2, T3, T4, T5>.ToDataTableAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, TReturn>> select) => this.InternalToDataTableAsync(select?.Body);
|
||||||
|
|
||||||
string ISelect<T1, T2, T3, T4, T5>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, TReturn>> select) => this.InternalToSql<TReturn>(select?.Body);
|
string ISelect<T1, T2, T3, T4, T5>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, TReturn>> select) => this.InternalToSql<TReturn>(select?.Body);
|
||||||
|
|
||||||
ISelect<T1, T2, T3, T4, T5> ISelect<T1, T2, T3, T4, T5>.Where(Expression<Func<T1, T2, T3, T4, T5, bool>> exp) => this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null));
|
ISelect<T1, T2, T3, T4, T5> ISelect<T1, T2, T3, T4, T5>.Where(Expression<Func<T1, T2, T3, T4, T5, bool>> exp) => this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null));
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -47,6 +48,10 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
|
|
||||||
Task<List<TReturn>> ISelect<T1, T2, T3, T4, T5, T6>.ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, TReturn>> select) => this.InternalToListAsync<TReturn>(select?.Body);
|
Task<List<TReturn>> ISelect<T1, T2, T3, T4, T5, T6>.ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, TReturn>> select) => this.InternalToListAsync<TReturn>(select?.Body);
|
||||||
|
|
||||||
|
DataTable ISelect<T1, T2, T3, T4, T5, T6>.ToDataTable<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, TReturn>> select) => this.InternalToDataTable(select?.Body);
|
||||||
|
|
||||||
|
Task<DataTable> ISelect<T1, T2, T3, T4, T5, T6>.ToDataTableAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, TReturn>> select) => this.InternalToDataTableAsync(select?.Body);
|
||||||
|
|
||||||
string ISelect<T1, T2, T3, T4, T5, T6>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, TReturn>> select) => this.InternalToSql<TReturn>(select?.Body);
|
string ISelect<T1, T2, T3, T4, T5, T6>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, TReturn>> select) => this.InternalToSql<TReturn>(select?.Body);
|
||||||
|
|
||||||
ISelect<T1, T2, T3, T4, T5, T6> ISelect<T1, T2, T3, T4, T5, T6>.Where(Expression<Func<T1, T2, T3, T4, T5, T6, bool>> exp) => this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null));
|
ISelect<T1, T2, T3, T4, T5, T6> ISelect<T1, T2, T3, T4, T5, T6>.Where(Expression<Func<T1, T2, T3, T4, T5, T6, bool>> exp) => this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null));
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -48,6 +49,10 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
|
|
||||||
Task<List<TReturn>> ISelect<T1, T2, T3, T4, T5, T6, T7>.ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, TReturn>> select) => this.InternalToListAsync<TReturn>(select?.Body);
|
Task<List<TReturn>> ISelect<T1, T2, T3, T4, T5, T6, T7>.ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, TReturn>> select) => this.InternalToListAsync<TReturn>(select?.Body);
|
||||||
|
|
||||||
|
DataTable ISelect<T1, T2, T3, T4, T5, T6, T7>.ToDataTable<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, TReturn>> select) => this.InternalToDataTable(select?.Body);
|
||||||
|
|
||||||
|
Task<DataTable> ISelect<T1, T2, T3, T4, T5, T6, T7>.ToDataTableAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, TReturn>> select) => this.InternalToDataTableAsync(select?.Body);
|
||||||
|
|
||||||
string ISelect<T1, T2, T3, T4, T5, T6, T7>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, TReturn>> select) => this.InternalToSql<TReturn>(select?.Body);
|
string ISelect<T1, T2, T3, T4, T5, T6, T7>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, TReturn>> select) => this.InternalToSql<TReturn>(select?.Body);
|
||||||
|
|
||||||
ISelect<T1, T2, T3, T4, T5, T6, T7> ISelect<T1, T2, T3, T4, T5, T6, T7>.Where(Expression<Func<T1, T2, T3, T4, T5, T6, T7, bool>> exp) => this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null));
|
ISelect<T1, T2, T3, T4, T5, T6, T7> ISelect<T1, T2, T3, T4, T5, T6, T7>.Where(Expression<Func<T1, T2, T3, T4, T5, T6, T7, bool>> exp) => this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null));
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -49,6 +50,10 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
|
|
||||||
Task<List<TReturn>> ISelect<T1, T2, T3, T4, T5, T6, T7, T8>.ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, TReturn>> select) => this.InternalToListAsync<TReturn>(select?.Body);
|
Task<List<TReturn>> ISelect<T1, T2, T3, T4, T5, T6, T7, T8>.ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, TReturn>> select) => this.InternalToListAsync<TReturn>(select?.Body);
|
||||||
|
|
||||||
|
DataTable ISelect<T1, T2, T3, T4, T5, T6, T7, T8>.ToDataTable<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, TReturn>> select) => this.InternalToDataTable(select?.Body);
|
||||||
|
|
||||||
|
Task<DataTable> ISelect<T1, T2, T3, T4, T5, T6, T7, T8>.ToDataTableAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, TReturn>> select) => this.InternalToDataTableAsync(select?.Body);
|
||||||
|
|
||||||
string ISelect<T1, T2, T3, T4, T5, T6, T7, T8>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, TReturn>> select) => this.InternalToSql<TReturn>(select?.Body);
|
string ISelect<T1, T2, T3, T4, T5, T6, T7, T8>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, TReturn>> select) => this.InternalToSql<TReturn>(select?.Body);
|
||||||
|
|
||||||
ISelect<T1, T2, T3, T4, T5, T6, T7, T8> ISelect<T1, T2, T3, T4, T5, T6, T7, T8>.Where(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, bool>> exp) => this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null));
|
ISelect<T1, T2, T3, T4, T5, T6, T7, T8> ISelect<T1, T2, T3, T4, T5, T6, T7, T8>.Where(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, bool>> exp) => this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null));
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -50,6 +51,10 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
|
|
||||||
Task<List<TReturn>> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>> select) => this.InternalToListAsync<TReturn>(select?.Body);
|
Task<List<TReturn>> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.ToListAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>> select) => this.InternalToListAsync<TReturn>(select?.Body);
|
||||||
|
|
||||||
|
DataTable ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.ToDataTable<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>> select) => this.InternalToDataTable(select?.Body);
|
||||||
|
|
||||||
|
Task<DataTable> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.ToDataTableAsync<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>> select) => this.InternalToDataTableAsync(select?.Body);
|
||||||
|
|
||||||
string ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>> select) => this.InternalToSql<TReturn>(select?.Body);
|
string ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.ToSql<TReturn>(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TReturn>> select) => this.InternalToSql<TReturn>(select?.Body);
|
||||||
|
|
||||||
ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.Where(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, bool>> exp) => this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null));
|
ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>.Where(Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, bool>> exp) => this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp?.Body, null));
|
||||||
|
@ -13,6 +13,7 @@ using System.Text;
|
|||||||
namespace FreeSql.Internal {
|
namespace FreeSql.Internal {
|
||||||
internal abstract class CommonUtils {
|
internal abstract class CommonUtils {
|
||||||
|
|
||||||
|
internal abstract string GetNoneParamaterSqlValue(Type type, object value);
|
||||||
internal abstract DbParameter[] GetDbParamtersByObject(string sql, object obj);
|
internal abstract DbParameter[] GetDbParamtersByObject(string sql, object obj);
|
||||||
internal abstract DbParameter AppendParamter(List<DbParameter> _params, string parameterName, Type type, object value);
|
internal abstract DbParameter AppendParamter(List<DbParameter> _params, string parameterName, Type type, object value);
|
||||||
internal abstract string FormatSql(string sql, params object[] args);
|
internal abstract string FormatSql(string sql, params object[] args);
|
||||||
|
@ -31,19 +31,15 @@ namespace FreeSql.MySql {
|
|||||||
else if (param is string)
|
else if (param is string)
|
||||||
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
|
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
|
||||||
else if (param is Enum)
|
else if (param is Enum)
|
||||||
return ((Enum)param).ToInt64();
|
return string.Concat("'", param.ToString().Replace("'", "''"), "'"); //((Enum)param).ToInt64();
|
||||||
else if (decimal.TryParse(string.Concat(param), out var trydec))
|
else if (decimal.TryParse(string.Concat(param), out var trydec))
|
||||||
return param;
|
return param;
|
||||||
else if (param is DateTime)
|
else if (param is DateTime || param is DateTime?)
|
||||||
return string.Concat("'", ((DateTime)param).ToString("yyyy-MM-dd HH:mm:ss"), "'");
|
return string.Concat("'", ((DateTime)param).ToString("yyyy-MM-dd HH:mm:ss"), "'");
|
||||||
else if (param is DateTime?)
|
else if (param is TimeSpan || param is TimeSpan?)
|
||||||
return string.Concat("'", (param as DateTime?).Value.ToString("yyyy-MM-dd HH:mm:ss"), "'");
|
|
||||||
else if (param is TimeSpan)
|
|
||||||
return ((TimeSpan)param).Ticks / 10;
|
return ((TimeSpan)param).Ticks / 10;
|
||||||
else if (param is TimeSpan?)
|
|
||||||
return (param as TimeSpan?).Value.Ticks / 10;
|
|
||||||
else if (param is MygisGeometry)
|
else if (param is MygisGeometry)
|
||||||
return (param as MygisGeometry).AsText();
|
return string.Concat("ST_GeomFromText('", (param as MygisGeometry).AsText().Replace("'", "''"), "')");
|
||||||
else if (param is IEnumerable) {
|
else if (param is IEnumerable) {
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
var ie = param as IEnumerable;
|
var ie = param as IEnumerable;
|
||||||
|
@ -4,6 +4,7 @@ using MySql.Data.MySqlClient;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace FreeSql.MySql {
|
namespace FreeSql.MySql {
|
||||||
|
|
||||||
@ -70,6 +71,24 @@ namespace FreeSql.MySql {
|
|||||||
}
|
}
|
||||||
return columnName;
|
return columnName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal override string GetNoneParamaterSqlValue(Type type, object value) {
|
||||||
|
if (value == null) return "NULL";
|
||||||
|
if (type == typeof(byte[])) {
|
||||||
|
var bytes = value as byte[];
|
||||||
|
var sb = new StringBuilder().Append("0x");
|
||||||
|
foreach (var vc in bytes) {
|
||||||
|
if (vc < 10) sb.Append("0");
|
||||||
|
sb.Append(vc.ToString("X"));
|
||||||
|
}
|
||||||
|
return sb.ToString(); //val = Encoding.UTF8.GetString(val as byte[]);
|
||||||
|
} else if (type == typeof(TimeSpan) || type == typeof(TimeSpan?)) {
|
||||||
|
var ts = (TimeSpan)value;
|
||||||
|
value = $"{Math.Floor(ts.TotalHours)}:{ts.Minutes}:{ts.Seconds}";
|
||||||
|
}
|
||||||
|
return FormatSql("{0}", value, 1);
|
||||||
|
}
|
||||||
|
|
||||||
internal override string DbName => "MySql";
|
internal override string DbName => "MySql";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,9 @@ namespace FreeSql.Oracle.Curd {
|
|||||||
}
|
}
|
||||||
sbtb.Append(") ");
|
sbtb.Append(") ");
|
||||||
|
|
||||||
_params = new DbParameter[colidx * _source.Count];
|
//_params = new DbParameter[colidx * _source.Count];
|
||||||
|
_params = new DbParameter[0];
|
||||||
|
//_params = new DbParameter[colidx * 5]; //批量添加第5行起,不使用参数化
|
||||||
var didx = 0;
|
var didx = 0;
|
||||||
foreach (var d in _source) {
|
foreach (var d in _source) {
|
||||||
if (_source.Count > 1) sb.Append("\r\n");
|
if (_source.Count > 1) sb.Append("\r\n");
|
||||||
@ -51,21 +53,25 @@ namespace FreeSql.Oracle.Curd {
|
|||||||
foreach (var col in _table.Columns.Values) {
|
foreach (var col in _table.Columns.Values) {
|
||||||
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name) == false) {
|
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name) == false) {
|
||||||
if (colidx2 > 0) sb.Append(", ");
|
if (colidx2 > 0) sb.Append(", ");
|
||||||
sb.Append(_commonUtils.QuoteWriteParamter(col.CsType, $"{_commonUtils.QuoteParamterName(col.CsName)}{didx}"));
|
|
||||||
object val = null;
|
object val = null;
|
||||||
if (_table.Properties.TryGetValue(col.CsName, out var tryp)) {
|
if (_table.Properties.TryGetValue(col.CsName, out var tryp)) {
|
||||||
val = tryp.GetValue(d);
|
val = tryp.GetValue(d);
|
||||||
if (col.Attribute.IsPrimary && (col.CsType == typeof(Guid) || col.CsType == typeof(Guid?))
|
if (col.Attribute.IsPrimary && (col.CsType == typeof(Guid) || col.CsType == typeof(Guid?))
|
||||||
&& (val == null || (Guid)val == Guid.Empty)) tryp.SetValue(d, val = FreeUtil.NewMongodbId());
|
&& (val == null || (Guid)val == Guid.Empty)) tryp.SetValue(d, val = FreeUtil.NewMongodbId());
|
||||||
}
|
}
|
||||||
_params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}{didx}", col.CsType, val);
|
//if (didx >= 5)
|
||||||
|
sb.Append(_commonUtils.GetNoneParamaterSqlValue(col.CsType, val));
|
||||||
|
//else {
|
||||||
|
// sb.Append(_commonUtils.QuoteWriteParamter(col.CsType, $"{_commonUtils.QuoteParamterName(col.CsName)}{didx}"));
|
||||||
|
// _params[didx * colidx + colidx2] = _commonUtils.AppendParamter(null, $"{col.CsName}{didx}", col.CsType, val);
|
||||||
|
//}
|
||||||
++colidx2;
|
++colidx2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.Append(")");
|
sb.Append(")");
|
||||||
++didx;
|
++didx;
|
||||||
}
|
}
|
||||||
if (_source.Count > 1) sb.Append("\r\n SELECT 1 FROM DUAL");
|
//if (_source.Count > 1) sb.Append("\r\n SELECT 1 FROM DUAL");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,14 +34,10 @@ namespace FreeSql.Oracle {
|
|||||||
return ((Enum)param).ToInt64();
|
return ((Enum)param).ToInt64();
|
||||||
else if (decimal.TryParse(string.Concat(param), out var trydec))
|
else if (decimal.TryParse(string.Concat(param), out var trydec))
|
||||||
return param;
|
return param;
|
||||||
else if (param is DateTime)
|
else if (param is DateTime || param is DateTime?)
|
||||||
return string.Concat("to_timestamp('", ((DateTime)param).ToString("yyyy-MM-dd HH:mm:ss.ffffff"), "','YYYY-MM-DD HH24:MI:SS.FF6)");
|
return string.Concat("to_timestamp('", ((DateTime)param).ToString("yyyy-MM-dd HH:mm:ss.ffffff"), "','YYYY-MM-DD HH24:MI:SS.FF6')");
|
||||||
else if (param is DateTime?)
|
else if (param is TimeSpan || param is TimeSpan?)
|
||||||
return string.Concat("to_timestamp('", (param as DateTime?).Value.ToString("yyyy-MM-dd HH:mm:ss.ffffff"), "','YYYY-MM-DD HH24:MI:SS.FF6)");
|
|
||||||
else if (param is TimeSpan)
|
|
||||||
return $"numtodsinterval({((TimeSpan)param).Ticks * 1.0 / 10000000},'second')";
|
return $"numtodsinterval({((TimeSpan)param).Ticks * 1.0 / 10000000},'second')";
|
||||||
else if (param is TimeSpan?)
|
|
||||||
return $"numtodsinterval({(param as TimeSpan?).Value.Ticks * 1.0 / 10000000},'second')";
|
|
||||||
else if (param is IEnumerable) {
|
else if (param is IEnumerable) {
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
var ie = param as IEnumerable;
|
var ie = param as IEnumerable;
|
||||||
|
@ -4,6 +4,7 @@ using Oracle.ManagedDataAccess.Client;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace FreeSql.Oracle {
|
namespace FreeSql.Oracle {
|
||||||
|
|
||||||
@ -46,6 +47,21 @@ namespace FreeSql.Oracle {
|
|||||||
|
|
||||||
internal override string QuoteWriteParamter(Type type, string paramterName) => paramterName;
|
internal override string QuoteWriteParamter(Type type, string paramterName) => paramterName;
|
||||||
internal override string QuoteReadColumn(Type type, string columnName) => columnName;
|
internal override string QuoteReadColumn(Type type, string columnName) => columnName;
|
||||||
|
|
||||||
|
internal override string GetNoneParamaterSqlValue(Type type, object value) {
|
||||||
|
if (value == null) return "NULL";
|
||||||
|
if (type == typeof(byte[])) {
|
||||||
|
var bytes = value as byte[];
|
||||||
|
var sb = new StringBuilder().Append("rawtohex('0x");
|
||||||
|
foreach (var vc in bytes) {
|
||||||
|
if (vc < 10) sb.Append("0");
|
||||||
|
sb.Append(vc.ToString("X"));
|
||||||
|
}
|
||||||
|
return sb.Append("')").ToString();
|
||||||
|
}
|
||||||
|
return FormatSql("{0}", value, 1);
|
||||||
|
}
|
||||||
|
|
||||||
internal override string DbName => "Oracle";
|
internal override string DbName => "Oracle";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,14 +36,10 @@ namespace FreeSql.PostgreSQL {
|
|||||||
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
|
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
|
||||||
else if (decimal.TryParse(string.Concat(param), out var trydec))
|
else if (decimal.TryParse(string.Concat(param), out var trydec))
|
||||||
return param;
|
return param;
|
||||||
else if (param is DateTime)
|
else if (param is DateTime || param is DateTime?)
|
||||||
return string.Concat("'", ((DateTime)param).ToString("yyyy-MM-dd HH:mm:ss.ffffff"), "'");
|
return string.Concat("'", ((DateTime)param).ToString("yyyy-MM-dd HH:mm:ss.ffffff"), "'");
|
||||||
else if (param is DateTime?)
|
else if (param is TimeSpan || param is TimeSpan?)
|
||||||
return string.Concat("'", (param as DateTime?).Value.ToString("yyyy-MM-dd HH:mm:ss.ffffff"), "'");
|
|
||||||
else if (param is TimeSpan)
|
|
||||||
return ((TimeSpan)param).Ticks / 10;
|
return ((TimeSpan)param).Ticks / 10;
|
||||||
else if (param is TimeSpan?)
|
|
||||||
return (param as TimeSpan?).Value.Ticks / 10;
|
|
||||||
else if (param is JToken || param is JObject || param is JArray)
|
else if (param is JToken || param is JObject || param is JArray)
|
||||||
return string.Concat("'", param.ToString().Replace("'", "''"), "'::jsonb");
|
return string.Concat("'", param.ToString().Replace("'", "''"), "'::jsonb");
|
||||||
else if ((isdic = param is Dictionary<string, string>) ||
|
else if ((isdic = param is Dictionary<string, string>) ||
|
||||||
|
@ -7,6 +7,7 @@ using System.Collections.Generic;
|
|||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace FreeSql.PostgreSQL {
|
namespace FreeSql.PostgreSQL {
|
||||||
|
|
||||||
@ -102,6 +103,26 @@ namespace FreeSql.PostgreSQL {
|
|||||||
|
|
||||||
internal override string QuoteWriteParamter(Type type, string paramterName) => paramterName;
|
internal override string QuoteWriteParamter(Type type, string paramterName) => paramterName;
|
||||||
internal override string QuoteReadColumn(Type type, string columnName) => columnName;
|
internal override string QuoteReadColumn(Type type, string columnName) => columnName;
|
||||||
|
|
||||||
|
internal override string GetNoneParamaterSqlValue(Type type, object value) {
|
||||||
|
if (value == null) return "NULL";
|
||||||
|
value = getParamterValue(type, value);
|
||||||
|
var type2 = value.GetType();
|
||||||
|
if (type2 == typeof(byte[])) {
|
||||||
|
var bytes = value as byte[];
|
||||||
|
var sb = new StringBuilder().Append("E'\\x");
|
||||||
|
foreach (var vc in bytes) {
|
||||||
|
if (vc < 10) sb.Append("0");
|
||||||
|
sb.Append(vc.ToString("X"));
|
||||||
|
}
|
||||||
|
return sb.Append("'").ToString(); //val = Encoding.UTF8.GetString(val as byte[]);
|
||||||
|
} else if (type2 == typeof(TimeSpan) || type2 == typeof(TimeSpan?)) {
|
||||||
|
var ts = (TimeSpan)value;
|
||||||
|
value = $"{ts.Hours}:{ts.Minutes}:{ts.Seconds}";
|
||||||
|
}
|
||||||
|
return FormatSql("{0}", value, 1);
|
||||||
|
}
|
||||||
|
|
||||||
internal override string DbName => "PostgreSQL";
|
internal override string DbName => "PostgreSQL";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
using FreeSql.Internal;
|
using FreeSql.Internal;
|
||||||
|
using SafeObjectPool;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -14,267 +14,84 @@ namespace FreeSql.SqlServer.Curd {
|
|||||||
: base(orm, commonUtils, commonExpression) {
|
: base(orm, commonUtils, commonExpression) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int ExecuteAffrows() {
|
|
||||||
var sql = this.ToSql2100();
|
|
||||||
switch (sql.Count) {
|
|
||||||
case 0: return 0;
|
|
||||||
case 1: return _orm.Ado.ExecuteNonQuery(_transaction, CommandType.Text, sql[0].Item1, sql[0].Item2);
|
|
||||||
default:
|
|
||||||
var affrows = 0;
|
|
||||||
if (_transaction == null) {
|
|
||||||
using (var conn = _orm.Ado.MasterPool.Get()) {
|
|
||||||
var tran = conn.Value.BeginTransaction();
|
|
||||||
try {
|
|
||||||
foreach (var s in sql)
|
|
||||||
affrows += _orm.Ado.ExecuteNonQuery(tran, CommandType.Text, s.Item1, s.Item2);
|
|
||||||
tran.Commit();
|
|
||||||
} catch {
|
|
||||||
tran.Rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
foreach (var s in sql)
|
|
||||||
affrows += _orm.Ado.ExecuteNonQuery(_transaction, CommandType.Text, s.Item1, s.Item2);
|
|
||||||
}
|
|
||||||
return affrows;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async public override Task<int> ExecuteAffrowsAsync() {
|
|
||||||
var sql = this.ToSql2100();
|
|
||||||
switch (sql.Count) {
|
|
||||||
case 0: return 0;
|
|
||||||
case 1: return await _orm.Ado.ExecuteNonQueryAsync(_transaction, CommandType.Text, sql[0].Item1, sql[0].Item2);
|
|
||||||
default:
|
|
||||||
var affrows = 0;
|
|
||||||
if (_transaction == null) {
|
|
||||||
using (var conn = await _orm.Ado.MasterPool.GetAsync()) {
|
|
||||||
var tran = conn.Value.BeginTransaction();
|
|
||||||
try {
|
|
||||||
foreach (var s in sql)
|
|
||||||
affrows += await _orm.Ado.ExecuteNonQueryAsync(tran, CommandType.Text, s.Item1, s.Item2);
|
|
||||||
tran.Commit();
|
|
||||||
} catch {
|
|
||||||
tran.Rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
foreach (var s in sql)
|
|
||||||
affrows += await _orm.Ado.ExecuteNonQueryAsync(_transaction, CommandType.Text, s.Item1, s.Item2);
|
|
||||||
}
|
|
||||||
return affrows;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override long ExecuteIdentity() {
|
public override long ExecuteIdentity() {
|
||||||
var sql = this.ToSql2100();
|
//if (_source?.Count > 999) {
|
||||||
switch (sql.Count) {
|
// List<IInsert<T1>> inserts = new List<IInsert<T1>>();
|
||||||
case 0: return 0;
|
// var idx = 0;
|
||||||
case 1:
|
// while (idx < _source.Count) {
|
||||||
if (string.IsNullOrEmpty(sql[0].Item1)) return 0;
|
// var count = Math.Min(_source.Count, idx + 999) - idx;
|
||||||
return long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(_transaction, CommandType.Text, string.Concat(sql[0].Item1, "; SELECT SCOPE_IDENTITY();"), sql[0].Item2)), out var trylng) ? trylng : 0;
|
// var insert = _orm.Insert<T1>().AppendData(_source.GetRange(idx, count));
|
||||||
default:
|
// _
|
||||||
long ret = 0;
|
// inserts.Add(insert);
|
||||||
if (_transaction == null) {
|
// idx += 999;
|
||||||
using (var conn = _orm.Ado.MasterPool.Get()) {
|
// }
|
||||||
var tran = conn.Value.BeginTransaction();
|
// Object<DbConnection> conn = null;
|
||||||
try {
|
// var trans = _transaction;
|
||||||
for (var a = 0; a < sql.Count; a++) {
|
// if (_transaction == null) {
|
||||||
var s = sql[a];
|
// conn = _orm.Ado.MasterPool.Get();
|
||||||
if (a < sql.Count - 1) _orm.Ado.ExecuteNonQuery(tran, CommandType.Text, s.Item1, s.Item2);
|
// trans = conn.Value.BeginTransaction();
|
||||||
else ret = long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(tran, CommandType.Text, string.Concat(s.Item1, "; SELECT SCOPE_IDENTITY();"), s.Item2)), out trylng) ? trylng : 0;
|
// }
|
||||||
}
|
// try {
|
||||||
tran.Commit();
|
// for (var a = 0; a < inserts.Count; a++) {
|
||||||
} catch {
|
// inserts[a].WithTransaction(trans)
|
||||||
tran.Rollback();
|
// }
|
||||||
}
|
// if (_transaction == null) trans.Commit();
|
||||||
}
|
// } catch {
|
||||||
} else {
|
// if (_transaction == null) trans.Rollback();
|
||||||
for (var a = 0; a < sql.Count; a++) {
|
// throw;
|
||||||
var s = sql[a];
|
// }
|
||||||
if (a < sql.Count - 1) _orm.Ado.ExecuteNonQuery(_transaction, CommandType.Text, s.Item1, s.Item2);
|
//}
|
||||||
else ret = long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(_transaction, CommandType.Text, string.Concat(s.Item1, "; SELECT SCOPE_IDENTITY();"), s.Item2)), out trylng) ? trylng : 0;
|
var sql = this.ToSql();
|
||||||
}
|
if (string.IsNullOrEmpty(sql)) return 0;
|
||||||
}
|
|
||||||
return ret;
|
return long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(_transaction, CommandType.Text, string.Concat(sql, "; SELECT SCOPE_IDENTITY();"), _params)), out var trylng) ? trylng : 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
async public override Task<long> ExecuteIdentityAsync() {
|
async public override Task<long> ExecuteIdentityAsync() {
|
||||||
var sql = this.ToSql2100();
|
var sql = this.ToSql();
|
||||||
switch (sql.Count) {
|
if (string.IsNullOrEmpty(sql)) return 0;
|
||||||
case 0: return 0;
|
|
||||||
case 1:
|
return long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_transaction, CommandType.Text, string.Concat(sql, "; SELECT SCOPE_IDENTITY();"), _params)), out var trylng) ? trylng : 0;
|
||||||
if (string.IsNullOrEmpty(sql[0].Item1)) return 0;
|
|
||||||
return long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_transaction, CommandType.Text, string.Concat(sql[0].Item1, "; SELECT SCOPE_IDENTITY();"), sql[0].Item2)), out var trylng) ? trylng : 0;
|
|
||||||
default:
|
|
||||||
long ret = 0;
|
|
||||||
if (_transaction == null) {
|
|
||||||
using (var conn = await _orm.Ado.MasterPool.GetAsync()) {
|
|
||||||
var tran = conn.Value.BeginTransaction();
|
|
||||||
try {
|
|
||||||
for (var a = 0; a < sql.Count; a++) {
|
|
||||||
var s = sql[a];
|
|
||||||
if (a < sql.Count - 1) await _orm.Ado.ExecuteNonQueryAsync(tran, CommandType.Text, s.Item1, s.Item2);
|
|
||||||
else ret = long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(tran, CommandType.Text, string.Concat(s.Item1, "; SELECT SCOPE_IDENTITY();"), s.Item2)), out trylng) ? trylng : 0;
|
|
||||||
}
|
|
||||||
tran.Commit();
|
|
||||||
} catch {
|
|
||||||
tran.Rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (var a = 0; a < sql.Count; a++) {
|
|
||||||
var s = sql[a];
|
|
||||||
if (a < sql.Count - 1) await _orm.Ado.ExecuteNonQueryAsync(_transaction, CommandType.Text, s.Item1, s.Item2);
|
|
||||||
else ret = long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_transaction, CommandType.Text, string.Concat(s.Item1, "; SELECT SCOPE_IDENTITY();"), s.Item2)), out trylng) ? trylng : 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override List<T1> ExecuteInserted() {
|
public override List<T1> ExecuteInserted() {
|
||||||
string output = null;
|
var sql = this.ToSql();
|
||||||
Func<string, string> getOutputSql = oldsql => {
|
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
||||||
if (string.IsNullOrEmpty(output)) {
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append(" OUTPUT ");
|
|
||||||
var colidx = 0;
|
|
||||||
foreach (var col in _table.Columns.Values) {
|
|
||||||
if (colidx > 0) sb.Append(", ");
|
|
||||||
sb.Append(_commonUtils.QuoteReadColumn(col.CsType, $"INSERTED.{_commonUtils.QuoteSqlName(col.Attribute.Name)}")).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
output = sb.ToString();
|
|
||||||
}
|
|
||||||
var validx = oldsql.IndexOf(") VALUES");
|
|
||||||
if (validx == -1) throw new ArgumentException("找不到 VALUES");
|
|
||||||
var newsql = new StringBuilder().Append(output);
|
|
||||||
newsql.Insert(0, oldsql.Substring(0, validx + 1));
|
|
||||||
newsql.Append(oldsql.Substring(validx + 1));
|
|
||||||
return newsql.ToString();
|
|
||||||
};
|
|
||||||
|
|
||||||
var sql = this.ToSql2100();
|
var sb = new StringBuilder();
|
||||||
switch (sql.Count) {
|
sb.Append(" OUTPUT ");
|
||||||
case 0: return new List<T1>();
|
var colidx = 0;
|
||||||
case 1:
|
foreach (var col in _table.Columns.Values) {
|
||||||
if (string.IsNullOrEmpty(sql[0].Item1)) return new List<T1>();
|
if (colidx > 0) sb.Append(", ");
|
||||||
return _orm.Ado.Query<T1>(_transaction, CommandType.Text, getOutputSql(sql[0].Item1), sql[0].Item2);
|
sb.Append(_commonUtils.QuoteReadColumn(col.CsType, $"INSERTED.{_commonUtils.QuoteSqlName(col.Attribute.Name)}")).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
default:
|
++colidx;
|
||||||
var ret = new List<T1>();
|
|
||||||
if (_transaction == null) {
|
|
||||||
using (var conn = _orm.Ado.MasterPool.Get()) {
|
|
||||||
var tran = conn.Value.BeginTransaction();
|
|
||||||
try {
|
|
||||||
foreach (var s in sql)
|
|
||||||
ret.AddRange(_orm.Ado.Query<T1>(tran, CommandType.Text, getOutputSql(s.Item1), s.Item2));
|
|
||||||
tran.Commit();
|
|
||||||
} catch {
|
|
||||||
tran.Rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
foreach (var s in sql)
|
|
||||||
ret.AddRange(_orm.Ado.Query<T1>(_transaction, CommandType.Text, getOutputSql(s.Item1), s.Item2));
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var validx = sql.IndexOf(") VALUES");
|
||||||
|
if (validx == -1) throw new ArgumentException("找不到 VALUES");
|
||||||
|
sb.Insert(0, sql.Substring(0, validx + 1));
|
||||||
|
sb.Append(sql.Substring(validx + 1));
|
||||||
|
|
||||||
|
return _orm.Ado.Query<T1>(_transaction, CommandType.Text, sb.ToString(), _params);
|
||||||
}
|
}
|
||||||
async public override Task<List<T1>> ExecuteInsertedAsync() {
|
async public override Task<List<T1>> ExecuteInsertedAsync() {
|
||||||
string output = null;
|
var sql = this.ToSql();
|
||||||
Func<string, string> getOutputSql = oldsql => {
|
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
||||||
if (string.IsNullOrEmpty(output)) {
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append(" OUTPUT ");
|
|
||||||
var colidx = 0;
|
|
||||||
foreach (var col in _table.Columns.Values) {
|
|
||||||
if (colidx > 0) sb.Append(", ");
|
|
||||||
sb.Append(_commonUtils.QuoteReadColumn(col.CsType, $"INSERTED.{_commonUtils.QuoteSqlName(col.Attribute.Name)}")).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
output = sb.ToString();
|
|
||||||
}
|
|
||||||
var validx = oldsql.IndexOf(") VALUES");
|
|
||||||
if (validx == -1) throw new ArgumentException("找不到 VALUES");
|
|
||||||
var newsql = new StringBuilder().Append(output);
|
|
||||||
newsql.Insert(0, oldsql.Substring(0, validx + 1));
|
|
||||||
newsql.Append(oldsql.Substring(validx + 1));
|
|
||||||
return oldsql;
|
|
||||||
};
|
|
||||||
|
|
||||||
var sql = this.ToSql2100();
|
var sb = new StringBuilder();
|
||||||
switch (sql.Count) {
|
sb.Append(" OUTPUT ");
|
||||||
case 0: return new List<T1>();
|
|
||||||
case 1:
|
|
||||||
if (string.IsNullOrEmpty(sql[0].Item1)) return new List<T1>();
|
|
||||||
return await _orm.Ado.QueryAsync<T1>(_transaction, CommandType.Text, getOutputSql(sql[0].Item1), sql[0].Item2);
|
|
||||||
default:
|
|
||||||
var ret = new List<T1>();
|
|
||||||
if (_transaction == null) {
|
|
||||||
using (var conn = await _orm.Ado.MasterPool.GetAsync()) {
|
|
||||||
var tran = conn.Value.BeginTransaction();
|
|
||||||
try {
|
|
||||||
foreach (var s in sql)
|
|
||||||
ret.AddRange(await _orm.Ado.QueryAsync<T1>(tran, CommandType.Text, getOutputSql(s.Item1), s.Item2));
|
|
||||||
tran.Commit();
|
|
||||||
} catch {
|
|
||||||
tran.Rollback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
foreach (var s in sql)
|
|
||||||
ret.AddRange(await _orm.Ado.QueryAsync<T1>(_transaction, CommandType.Text, getOutputSql(s.Item1), s.Item2));
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<(string, DbParameter[])> ToSql2100() { //传入的请求具有过多的参数。该服务器支持最多 2100 个参数。请减少参数的数目,然后重新发送该请求。
|
|
||||||
if (_source == null || _source.Any() == false) return new List<(string, DbParameter[])>();
|
|
||||||
var ret = new List<(string, DbParameter[])>();
|
|
||||||
var sbhead = new StringBuilder();
|
|
||||||
sbhead.Append("INSERT INTO ").Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(_table.DbName) ?? _table.DbName)).Append("(");
|
|
||||||
var colidx = 0;
|
var colidx = 0;
|
||||||
foreach (var col in _table.Columns.Values)
|
foreach (var col in _table.Columns.Values) {
|
||||||
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name) == false) {
|
if (colidx > 0) sb.Append(", ");
|
||||||
if (colidx > 0) sbhead.Append(", ");
|
sb.Append(_commonUtils.QuoteReadColumn(col.CsType, $"INSERTED.{_commonUtils.QuoteSqlName(col.Attribute.Name)}")).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
sbhead.Append(_commonUtils.QuoteSqlName(col.Attribute.Name));
|
++colidx;
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
sbhead.Append(") VALUES");
|
|
||||||
var sbh = sbhead.ToString();
|
|
||||||
|
|
||||||
var sbsql = new StringBuilder().Append(sbh);
|
|
||||||
var sbsqlParams = new List<DbParameter>();
|
|
||||||
var didx = 0;
|
|
||||||
foreach (var d in _source) {
|
|
||||||
if ((didx + 1) * colidx >= 2100) {
|
|
||||||
ret.Add((sbsql.ToString(), sbsqlParams.ToArray()));
|
|
||||||
sbsql.Clear().Append(sbh);
|
|
||||||
sbsqlParams.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sbsqlParams.Count > 0) sbsql.Append(", ");
|
|
||||||
sbsql.Append("(");
|
|
||||||
var colidx2 = 0;
|
|
||||||
foreach (var col in _table.Columns.Values)
|
|
||||||
if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name) == false) {
|
|
||||||
if (colidx2 > 0) sbsql.Append(", ");
|
|
||||||
sbsql.Append(_commonUtils.QuoteWriteParamter(col.CsType, $"{_commonUtils.QuoteParamterName(col.CsName)}{didx}"));
|
|
||||||
object val = null;
|
|
||||||
if (_table.Properties.TryGetValue(col.CsName, out var tryp)) {
|
|
||||||
val = tryp.GetValue(d);
|
|
||||||
if (col.Attribute.IsPrimary && (col.CsType == typeof(Guid) || col.CsType == typeof(Guid?))
|
|
||||||
&& (val == null || (Guid)val == Guid.Empty)) tryp.SetValue(d, val = FreeUtil.NewMongodbId());
|
|
||||||
}
|
|
||||||
sbsqlParams.Add(_commonUtils.AppendParamter(null, $"{col.CsName}{didx}", col.CsType, val));
|
|
||||||
++colidx2;
|
|
||||||
}
|
|
||||||
sbsql.Append(")");
|
|
||||||
++didx;
|
|
||||||
}
|
}
|
||||||
ret.Add((sbsql.ToString(), sbsqlParams.ToArray()));
|
|
||||||
return ret;
|
var validx = sql.IndexOf(") VALUES");
|
||||||
|
if (validx == -1) throw new ArgumentException("找不到 VALUES");
|
||||||
|
sb.Insert(0, sql.Substring(0, validx + 1));
|
||||||
|
sb.Append(sql.Substring(validx + 1));
|
||||||
|
|
||||||
|
return await _orm.Ado.QueryAsync<T1>(_transaction, CommandType.Text, sb.ToString(), _params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
281
FreeSql/SqlServer/Curd/SqlServerInsert2100.cs
Normal file
281
FreeSql/SqlServer/Curd/SqlServerInsert2100.cs
Normal file
@ -0,0 +1,281 @@
|
|||||||
|
//using FreeSql.Internal;
|
||||||
|
//using System;
|
||||||
|
//using System.Collections.Generic;
|
||||||
|
//using System.Data;
|
||||||
|
//using System.Data.Common;
|
||||||
|
//using System.Linq;
|
||||||
|
//using System.Text;
|
||||||
|
//using System.Threading.Tasks;
|
||||||
|
|
||||||
|
//namespace FreeSql.SqlServer.Curd {
|
||||||
|
|
||||||
|
// class SqlServerInsert<T1> : Internal.CommonProvider.InsertProvider<T1> where T1 : class {
|
||||||
|
// public SqlServerInsert(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression)
|
||||||
|
// : base(orm, commonUtils, commonExpression) {
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public override int ExecuteAffrows() {
|
||||||
|
// var sql = this.ToSql2100();
|
||||||
|
// switch (sql.Count) {
|
||||||
|
// case 0: return 0;
|
||||||
|
// case 1: return _orm.Ado.ExecuteNonQuery(_transaction, CommandType.Text, sql[0].Item1, sql[0].Item2);
|
||||||
|
// default:
|
||||||
|
// var affrows = 0;
|
||||||
|
// if (_transaction == null) {
|
||||||
|
// using (var conn = _orm.Ado.MasterPool.Get()) {
|
||||||
|
// var tran = conn.Value.BeginTransaction();
|
||||||
|
// try {
|
||||||
|
// foreach (var s in sql)
|
||||||
|
// affrows += _orm.Ado.ExecuteNonQuery(tran, CommandType.Text, s.Item1, s.Item2);
|
||||||
|
// tran.Commit();
|
||||||
|
// } catch {
|
||||||
|
// tran.Rollback();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// foreach (var s in sql)
|
||||||
|
// affrows += _orm.Ado.ExecuteNonQuery(_transaction, CommandType.Text, s.Item1, s.Item2);
|
||||||
|
// }
|
||||||
|
// return affrows;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// async public override Task<int> ExecuteAffrowsAsync() {
|
||||||
|
// var sql = this.ToSql2100();
|
||||||
|
// switch (sql.Count) {
|
||||||
|
// case 0: return 0;
|
||||||
|
// case 1: return await _orm.Ado.ExecuteNonQueryAsync(_transaction, CommandType.Text, sql[0].Item1, sql[0].Item2);
|
||||||
|
// default:
|
||||||
|
// var affrows = 0;
|
||||||
|
// if (_transaction == null) {
|
||||||
|
// using (var conn = await _orm.Ado.MasterPool.GetAsync()) {
|
||||||
|
// var tran = conn.Value.BeginTransaction();
|
||||||
|
// try {
|
||||||
|
// foreach (var s in sql)
|
||||||
|
// affrows += await _orm.Ado.ExecuteNonQueryAsync(tran, CommandType.Text, s.Item1, s.Item2);
|
||||||
|
// tran.Commit();
|
||||||
|
// } catch {
|
||||||
|
// tran.Rollback();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// foreach (var s in sql)
|
||||||
|
// affrows += await _orm.Ado.ExecuteNonQueryAsync(_transaction, CommandType.Text, s.Item1, s.Item2);
|
||||||
|
// }
|
||||||
|
// return affrows;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public override long ExecuteIdentity() {
|
||||||
|
// var sql = this.ToSql2100();
|
||||||
|
// switch (sql.Count) {
|
||||||
|
// case 0: return 0;
|
||||||
|
// case 1:
|
||||||
|
// if (string.IsNullOrEmpty(sql[0].Item1)) return 0;
|
||||||
|
// return long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(_transaction, CommandType.Text, string.Concat(sql[0].Item1, "; SELECT SCOPE_IDENTITY();"), sql[0].Item2)), out var trylng) ? trylng : 0;
|
||||||
|
// default:
|
||||||
|
// long ret = 0;
|
||||||
|
// if (_transaction == null) {
|
||||||
|
// using (var conn = _orm.Ado.MasterPool.Get()) {
|
||||||
|
// var tran = conn.Value.BeginTransaction();
|
||||||
|
// try {
|
||||||
|
// for (var a = 0; a < sql.Count; a++) {
|
||||||
|
// var s = sql[a];
|
||||||
|
// if (a < sql.Count - 1) _orm.Ado.ExecuteNonQuery(tran, CommandType.Text, s.Item1, s.Item2);
|
||||||
|
// else ret = long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(tran, CommandType.Text, string.Concat(s.Item1, "; SELECT SCOPE_IDENTITY();"), s.Item2)), out trylng) ? trylng : 0;
|
||||||
|
// }
|
||||||
|
// tran.Commit();
|
||||||
|
// } catch {
|
||||||
|
// tran.Rollback();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// for (var a = 0; a < sql.Count; a++) {
|
||||||
|
// var s = sql[a];
|
||||||
|
// if (a < sql.Count - 1) _orm.Ado.ExecuteNonQuery(_transaction, CommandType.Text, s.Item1, s.Item2);
|
||||||
|
// else ret = long.TryParse(string.Concat(_orm.Ado.ExecuteScalar(_transaction, CommandType.Text, string.Concat(s.Item1, "; SELECT SCOPE_IDENTITY();"), s.Item2)), out trylng) ? trylng : 0;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return ret;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// async public override Task<long> ExecuteIdentityAsync() {
|
||||||
|
// var sql = this.ToSql2100();
|
||||||
|
// switch (sql.Count) {
|
||||||
|
// case 0: return 0;
|
||||||
|
// case 1:
|
||||||
|
// if (string.IsNullOrEmpty(sql[0].Item1)) return 0;
|
||||||
|
// return long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_transaction, CommandType.Text, string.Concat(sql[0].Item1, "; SELECT SCOPE_IDENTITY();"), sql[0].Item2)), out var trylng) ? trylng : 0;
|
||||||
|
// default:
|
||||||
|
// long ret = 0;
|
||||||
|
// if (_transaction == null) {
|
||||||
|
// using (var conn = await _orm.Ado.MasterPool.GetAsync()) {
|
||||||
|
// var tran = conn.Value.BeginTransaction();
|
||||||
|
// try {
|
||||||
|
// for (var a = 0; a < sql.Count; a++) {
|
||||||
|
// var s = sql[a];
|
||||||
|
// if (a < sql.Count - 1) await _orm.Ado.ExecuteNonQueryAsync(tran, CommandType.Text, s.Item1, s.Item2);
|
||||||
|
// else ret = long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(tran, CommandType.Text, string.Concat(s.Item1, "; SELECT SCOPE_IDENTITY();"), s.Item2)), out trylng) ? trylng : 0;
|
||||||
|
// }
|
||||||
|
// tran.Commit();
|
||||||
|
// } catch {
|
||||||
|
// tran.Rollback();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// for (var a = 0; a < sql.Count; a++) {
|
||||||
|
// var s = sql[a];
|
||||||
|
// if (a < sql.Count - 1) await _orm.Ado.ExecuteNonQueryAsync(_transaction, CommandType.Text, s.Item1, s.Item2);
|
||||||
|
// else ret = long.TryParse(string.Concat(await _orm.Ado.ExecuteScalarAsync(_transaction, CommandType.Text, string.Concat(s.Item1, "; SELECT SCOPE_IDENTITY();"), s.Item2)), out trylng) ? trylng : 0;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return ret;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public override List<T1> ExecuteInserted() {
|
||||||
|
// string output = null;
|
||||||
|
// Func<string, string> getOutputSql = oldsql => {
|
||||||
|
// if (string.IsNullOrEmpty(output)) {
|
||||||
|
// var sb = new StringBuilder();
|
||||||
|
// sb.Append(" OUTPUT ");
|
||||||
|
// var colidx = 0;
|
||||||
|
// foreach (var col in _table.Columns.Values) {
|
||||||
|
// if (colidx > 0) sb.Append(", ");
|
||||||
|
// sb.Append(_commonUtils.QuoteReadColumn(col.CsType, $"INSERTED.{_commonUtils.QuoteSqlName(col.Attribute.Name)}")).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
// ++colidx;
|
||||||
|
// }
|
||||||
|
// output = sb.ToString();
|
||||||
|
// }
|
||||||
|
// var validx = oldsql.IndexOf(") VALUES");
|
||||||
|
// if (validx == -1) throw new ArgumentException("找不到 VALUES");
|
||||||
|
// var newsql = new StringBuilder().Append(output);
|
||||||
|
// newsql.Insert(0, oldsql.Substring(0, validx + 1));
|
||||||
|
// newsql.Append(oldsql.Substring(validx + 1));
|
||||||
|
// return newsql.ToString();
|
||||||
|
// };
|
||||||
|
|
||||||
|
// var sql = this.ToSql2100();
|
||||||
|
// switch (sql.Count) {
|
||||||
|
// case 0: return new List<T1>();
|
||||||
|
// case 1:
|
||||||
|
// if (string.IsNullOrEmpty(sql[0].Item1)) return new List<T1>();
|
||||||
|
// return _orm.Ado.Query<T1>(_transaction, CommandType.Text, getOutputSql(sql[0].Item1), sql[0].Item2);
|
||||||
|
// default:
|
||||||
|
// var ret = new List<T1>();
|
||||||
|
// if (_transaction == null) {
|
||||||
|
// using (var conn = _orm.Ado.MasterPool.Get()) {
|
||||||
|
// var tran = conn.Value.BeginTransaction();
|
||||||
|
// try {
|
||||||
|
// foreach (var s in sql)
|
||||||
|
// ret.AddRange(_orm.Ado.Query<T1>(tran, CommandType.Text, getOutputSql(s.Item1), s.Item2));
|
||||||
|
// tran.Commit();
|
||||||
|
// } catch {
|
||||||
|
// tran.Rollback();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// foreach (var s in sql)
|
||||||
|
// ret.AddRange(_orm.Ado.Query<T1>(_transaction, CommandType.Text, getOutputSql(s.Item1), s.Item2));
|
||||||
|
// }
|
||||||
|
// return ret;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// async public override Task<List<T1>> ExecuteInsertedAsync() {
|
||||||
|
// string output = null;
|
||||||
|
// Func<string, string> getOutputSql = oldsql => {
|
||||||
|
// if (string.IsNullOrEmpty(output)) {
|
||||||
|
// var sb = new StringBuilder();
|
||||||
|
// sb.Append(" OUTPUT ");
|
||||||
|
// var colidx = 0;
|
||||||
|
// foreach (var col in _table.Columns.Values) {
|
||||||
|
// if (colidx > 0) sb.Append(", ");
|
||||||
|
// sb.Append(_commonUtils.QuoteReadColumn(col.CsType, $"INSERTED.{_commonUtils.QuoteSqlName(col.Attribute.Name)}")).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
// ++colidx;
|
||||||
|
// }
|
||||||
|
// output = sb.ToString();
|
||||||
|
// }
|
||||||
|
// var validx = oldsql.IndexOf(") VALUES");
|
||||||
|
// if (validx == -1) throw new ArgumentException("找不到 VALUES");
|
||||||
|
// var newsql = new StringBuilder().Append(output);
|
||||||
|
// newsql.Insert(0, oldsql.Substring(0, validx + 1));
|
||||||
|
// newsql.Append(oldsql.Substring(validx + 1));
|
||||||
|
// return oldsql;
|
||||||
|
// };
|
||||||
|
|
||||||
|
// var sql = this.ToSql2100();
|
||||||
|
// switch (sql.Count) {
|
||||||
|
// case 0: return new List<T1>();
|
||||||
|
// case 1:
|
||||||
|
// if (string.IsNullOrEmpty(sql[0].Item1)) return new List<T1>();
|
||||||
|
// return await _orm.Ado.QueryAsync<T1>(_transaction, CommandType.Text, getOutputSql(sql[0].Item1), sql[0].Item2);
|
||||||
|
// default:
|
||||||
|
// var ret = new List<T1>();
|
||||||
|
// if (_transaction == null) {
|
||||||
|
// using (var conn = await _orm.Ado.MasterPool.GetAsync()) {
|
||||||
|
// var tran = conn.Value.BeginTransaction();
|
||||||
|
// try {
|
||||||
|
// foreach (var s in sql)
|
||||||
|
// ret.AddRange(await _orm.Ado.QueryAsync<T1>(tran, CommandType.Text, getOutputSql(s.Item1), s.Item2));
|
||||||
|
// tran.Commit();
|
||||||
|
// } catch {
|
||||||
|
// tran.Rollback();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// foreach (var s in sql)
|
||||||
|
// ret.AddRange(await _orm.Ado.QueryAsync<T1>(_transaction, CommandType.Text, getOutputSql(s.Item1), s.Item2));
|
||||||
|
// }
|
||||||
|
// return ret;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public List<(string, DbParameter[])> ToSql2100() { //传入的请求具有过多的参数。该服务器支持最多 2100 个参数。请减少参数的数目,然后重新发送该请求。
|
||||||
|
// if (_source == null || _source.Any() == false) return new List<(string, DbParameter[])>();
|
||||||
|
// var ret = new List<(string, DbParameter[])>();
|
||||||
|
// var sbhead = new StringBuilder();
|
||||||
|
// sbhead.Append("INSERT INTO ").Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(_table.DbName) ?? _table.DbName)).Append("(");
|
||||||
|
// var colidx = 0;
|
||||||
|
// foreach (var col in _table.Columns.Values)
|
||||||
|
// if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name) == false) {
|
||||||
|
// if (colidx > 0) sbhead.Append(", ");
|
||||||
|
// sbhead.Append(_commonUtils.QuoteSqlName(col.Attribute.Name));
|
||||||
|
// ++colidx;
|
||||||
|
// }
|
||||||
|
// sbhead.Append(") VALUES");
|
||||||
|
// var sbh = sbhead.ToString();
|
||||||
|
|
||||||
|
// var sbsql = new StringBuilder().Append(sbh);
|
||||||
|
// var sbsqlParams = new List<DbParameter>();
|
||||||
|
// var didx = 0;
|
||||||
|
// foreach (var d in _source) {
|
||||||
|
// if ((didx + 1) * colidx >= 2100) {
|
||||||
|
// ret.Add((sbsql.ToString(), sbsqlParams.ToArray()));
|
||||||
|
// sbsql.Clear().Append(sbh);
|
||||||
|
// sbsqlParams.Clear();
|
||||||
|
// didx = 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (sbsqlParams.Count > 0) sbsql.Append(", ");
|
||||||
|
// sbsql.Append("(");
|
||||||
|
// var colidx2 = 0;
|
||||||
|
// foreach (var col in _table.Columns.Values)
|
||||||
|
// if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name) == false) {
|
||||||
|
// if (colidx2 > 0) sbsql.Append(", ");
|
||||||
|
// sbsql.Append(_commonUtils.QuoteWriteParamter(col.CsType, $"{_commonUtils.QuoteParamterName(col.CsName)}{didx}"));
|
||||||
|
// object val = null;
|
||||||
|
// if (_table.Properties.TryGetValue(col.CsName, out var tryp)) {
|
||||||
|
// val = tryp.GetValue(d);
|
||||||
|
// if (col.Attribute.IsPrimary && (col.CsType == typeof(Guid) || col.CsType == typeof(Guid?))
|
||||||
|
// && (val == null || (Guid)val == Guid.Empty)) tryp.SetValue(d, val = FreeUtil.NewMongodbId());
|
||||||
|
// }
|
||||||
|
// sbsqlParams.Add(_commonUtils.AppendParamter(null, $"{col.CsName}{didx}", col.CsType, val));
|
||||||
|
// ++colidx2;
|
||||||
|
// }
|
||||||
|
// sbsql.Append(")");
|
||||||
|
// ++didx;
|
||||||
|
// }
|
||||||
|
// ret.Add((sbsql.ToString(), sbsqlParams.ToArray()));
|
||||||
|
// return ret;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
@ -28,18 +28,21 @@ namespace FreeSql.SqlServer {
|
|||||||
if (param == null) return "NULL";
|
if (param == null) return "NULL";
|
||||||
if (param is bool || param is bool?)
|
if (param is bool || param is bool?)
|
||||||
return (bool)param ? 1 : 0;
|
return (bool)param ? 1 : 0;
|
||||||
else if (param is string || param is Enum)
|
else if (param is string)
|
||||||
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
|
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
|
||||||
|
else if (param is Enum)
|
||||||
|
return ((Enum)param).ToInt64();
|
||||||
else if (decimal.TryParse(string.Concat(param), out var trydec))
|
else if (decimal.TryParse(string.Concat(param), out var trydec))
|
||||||
return param;
|
return param;
|
||||||
else if (param is DateTime)
|
else if (param is DateTime || param is DateTime?) {
|
||||||
|
if (param.Equals(DateTime.MinValue) == true) param = new DateTime(1970, 1, 1);
|
||||||
return string.Concat("'", ((DateTime)param).ToString("yyyy-MM-dd HH:mm:ss.fff"), "'");
|
return string.Concat("'", ((DateTime)param).ToString("yyyy-MM-dd HH:mm:ss.fff"), "'");
|
||||||
else if (param is DateTime?)
|
} else if (param is DateTimeOffset || param is DateTimeOffset?) {
|
||||||
return string.Concat("'", (param as DateTime?).Value.ToString("yyyy-MM-dd HH:mm:ss.fff"), "'");
|
if (param.Equals(DateTimeOffset.MinValue) == true) param = new DateTimeOffset(new DateTime(1970, 1, 1), TimeSpan.Zero);
|
||||||
else if (param is TimeSpan)
|
return string.Concat("'", ((DateTimeOffset)param).ToString("yyyy-MM-dd HH:mm:ss.fff zzzz"), "'");
|
||||||
|
}
|
||||||
|
else if (param is TimeSpan || param is TimeSpan?)
|
||||||
return ((TimeSpan)param).TotalSeconds;
|
return ((TimeSpan)param).TotalSeconds;
|
||||||
else if (param is TimeSpan?)
|
|
||||||
return (param as TimeSpan?).Value.TotalSeconds;
|
|
||||||
else if (param is IEnumerable) {
|
else if (param is IEnumerable) {
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
var ie = param as IEnumerable;
|
var ie = param as IEnumerable;
|
||||||
|
@ -4,6 +4,8 @@ using System.Collections.Generic;
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace FreeSql.SqlServer {
|
namespace FreeSql.SqlServer {
|
||||||
|
|
||||||
@ -42,6 +44,24 @@ namespace FreeSql.SqlServer {
|
|||||||
|
|
||||||
internal override string QuoteWriteParamter(Type type, string paramterName) => paramterName;
|
internal override string QuoteWriteParamter(Type type, string paramterName) => paramterName;
|
||||||
internal override string QuoteReadColumn(Type type, string columnName) => columnName;
|
internal override string QuoteReadColumn(Type type, string columnName) => columnName;
|
||||||
|
|
||||||
|
internal override string GetNoneParamaterSqlValue(Type type, object value) {
|
||||||
|
if (value == null) return "NULL";
|
||||||
|
if (type == typeof(byte[])) {
|
||||||
|
var bytes = value as byte[];
|
||||||
|
var sb = new StringBuilder().Append("0x");
|
||||||
|
foreach (var vc in bytes) {
|
||||||
|
if (vc < 10) sb.Append("0");
|
||||||
|
sb.Append(vc.ToString("X"));
|
||||||
|
}
|
||||||
|
return sb.ToString();
|
||||||
|
} else if (type == typeof(TimeSpan) || type == typeof(TimeSpan?)) {
|
||||||
|
var ts = (TimeSpan)value;
|
||||||
|
value = $"{ts.Hours}:{ts.Minutes}:{ts.Seconds}.{ts.Milliseconds}";
|
||||||
|
}
|
||||||
|
return FormatSql("{0}", value, 1);
|
||||||
|
}
|
||||||
|
|
||||||
internal override string DbName => "SqlServer";
|
internal override string DbName => "SqlServer";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,16 +34,10 @@ namespace FreeSql.Sqlite {
|
|||||||
return ((Enum)param).ToInt64();
|
return ((Enum)param).ToInt64();
|
||||||
else if (decimal.TryParse(string.Concat(param), out var trydec))
|
else if (decimal.TryParse(string.Concat(param), out var trydec))
|
||||||
return param;
|
return param;
|
||||||
else if (param is DateTime)
|
else if (param is DateTime || param is DateTime?)
|
||||||
return string.Concat("'", ((DateTime)param).ToString("yyyy-MM-dd HH:mm:ss"), "'");
|
return string.Concat("'", ((DateTime)param).ToString("yyyy-MM-dd HH:mm:ss"), "'");
|
||||||
else if (param is DateTime?)
|
else if (param is TimeSpan || param is TimeSpan?)
|
||||||
return string.Concat("'", (param as DateTime?).Value.ToString("yyyy-MM-dd HH:mm:ss"), "'");
|
|
||||||
else if (param is TimeSpan)
|
|
||||||
return ((TimeSpan)param).Ticks / 10000;
|
return ((TimeSpan)param).Ticks / 10000;
|
||||||
else if (param is TimeSpan?)
|
|
||||||
return (param as TimeSpan?).Value.Ticks / 10000;
|
|
||||||
else if (param is MygisGeometry)
|
|
||||||
return (param as MygisGeometry).AsText();
|
|
||||||
else if (param is IEnumerable) {
|
else if (param is IEnumerable) {
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
var ie = param as IEnumerable;
|
var ie = param as IEnumerable;
|
||||||
|
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Data.SQLite;
|
using System.Data.SQLite;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace FreeSql.Sqlite {
|
namespace FreeSql.Sqlite {
|
||||||
|
|
||||||
@ -61,6 +62,13 @@ namespace FreeSql.Sqlite {
|
|||||||
|
|
||||||
internal override string QuoteWriteParamter(Type type, string paramterName) => paramterName;
|
internal override string QuoteWriteParamter(Type type, string paramterName) => paramterName;
|
||||||
internal override string QuoteReadColumn(Type type, string columnName) => columnName;
|
internal override string QuoteReadColumn(Type type, string columnName) => columnName;
|
||||||
|
|
||||||
|
internal override string GetNoneParamaterSqlValue(Type type, object value) {
|
||||||
|
if (value == null) return "NULL";
|
||||||
|
if (type == typeof(byte[])) value = Encoding.UTF8.GetString(value as byte[]);
|
||||||
|
return FormatSql("{0}", value, 1);
|
||||||
|
}
|
||||||
|
|
||||||
internal override string DbName => "Sqlite";
|
internal override string DbName => "Sqlite";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user