mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
- 增加 [Table(AsTable = xx)] 分表特性,完成分表插入/删除;
This commit is contained in:
parent
8c022b3e0a
commit
f73c02d8d1
@ -99,6 +99,14 @@ namespace base_entity
|
|||||||
public B B { get; set; }
|
public B B { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Table(Name = "as_table_log_{yyyyMMdd}", AsTable = "createtime=2022-1-1(1 month)")]
|
||||||
|
class AsTableLog
|
||||||
|
{
|
||||||
|
public Guid id { get; set; }
|
||||||
|
public string msg { get; set; }
|
||||||
|
public DateTime createtime { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
#region 初始化 IFreeSql
|
#region 初始化 IFreeSql
|
||||||
@ -141,6 +149,24 @@ namespace base_entity
|
|||||||
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
|
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
var sqlatb = fsql.Insert(new[]
|
||||||
|
{
|
||||||
|
new AsTableLog{ msg = "msg01", createtime = DateTime.Parse("2022-1-1 13:00:11") },
|
||||||
|
new AsTableLog{ msg = "msg02", createtime = DateTime.Parse("2022-1-2 14:00:12") },
|
||||||
|
new AsTableLog{ msg = "msg03", createtime = DateTime.Parse("2022-2-2 15:00:13") },
|
||||||
|
new AsTableLog{ msg = "msg04", createtime = DateTime.Parse("2022-2-8 15:00:13") },
|
||||||
|
new AsTableLog{ msg = "msg05", createtime = DateTime.Parse("2022-3-8 15:00:13") },
|
||||||
|
new AsTableLog{ msg = "msg06", createtime = DateTime.Parse("2022-4-8 15:00:13") },
|
||||||
|
new AsTableLog{ msg = "msg07", createtime = DateTime.Parse("2022-6-8 15:00:13") }
|
||||||
|
}).NoneParameter();
|
||||||
|
var sqlat = sqlatb.ToSql();
|
||||||
|
var sqlatr = sqlatb.ExecuteAffrows();
|
||||||
|
|
||||||
|
var sqlatc = fsql.Delete<AsTableLog>().Where(a => a.id == Guid.NewGuid() && a.createtime.Between(DateTime.Parse("2022-3-1"), DateTime.Parse("2022-5-1")));
|
||||||
|
var sqlatca = sqlatc.ToSql();
|
||||||
|
var sqlatcr = sqlatc.ExecuteAffrows();
|
||||||
|
|
||||||
|
|
||||||
fsql.Aop.AuditValue += new EventHandler<FreeSql.Aop.AuditValueEventArgs>((_, e) =>
|
fsql.Aop.AuditValue += new EventHandler<FreeSql.Aop.AuditValueEventArgs>((_, e) =>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
using System;
|
using FreeSql.Internal;
|
||||||
|
using FreeSql.Internal.Model;
|
||||||
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Linq.Expressions;
|
using System.Collections.Generic;
|
||||||
|
using System.Data.Common;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace FreeSql.DataAnnotations
|
namespace FreeSql.DataAnnotations
|
||||||
{
|
{
|
||||||
@ -26,5 +31,312 @@ namespace FreeSql.DataAnnotations
|
|||||||
internal ConcurrentDictionary<string, ColumnAttribute> _columns { get; } = new ConcurrentDictionary<string, ColumnAttribute>(StringComparer.CurrentCultureIgnoreCase);
|
internal ConcurrentDictionary<string, ColumnAttribute> _columns { get; } = new ConcurrentDictionary<string, ColumnAttribute>(StringComparer.CurrentCultureIgnoreCase);
|
||||||
internal ConcurrentDictionary<string, NavigateAttribute> _navigates { get; } = new ConcurrentDictionary<string, NavigateAttribute>(StringComparer.CurrentCultureIgnoreCase);
|
internal ConcurrentDictionary<string, NavigateAttribute> _navigates { get; } = new ConcurrentDictionary<string, NavigateAttribute>(StringComparer.CurrentCultureIgnoreCase);
|
||||||
internal ConcurrentDictionary<string, IndexAttribute> _indexs { get; } = new ConcurrentDictionary<string, IndexAttribute>(StringComparer.CurrentCultureIgnoreCase);
|
internal ConcurrentDictionary<string, IndexAttribute> _indexs { get; } = new ConcurrentDictionary<string, IndexAttribute>(StringComparer.CurrentCultureIgnoreCase);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 格式:属性名=开始时间(递增)<para></para>
|
||||||
|
/// 按年分表:[Table(Name = "log_{yyyy}", AsTable = "create_time=2022-1-1(1 year)")]<para></para>
|
||||||
|
/// 按月分表:[Table(Name = "log_{yyyyMM}", AsTable = "create_time=2022-5-1(1 month)")]<para></para>
|
||||||
|
/// 按日分表:[Table(Name = "log_{yyyyMMdd}", AsTable = "create_time=2022-5-1(5 day)")]<para></para>
|
||||||
|
/// 按时分表:[Table(Name = "log_{yyyyMMddHH}", AsTable = "create_time=2022-5-1(6 hour)")]<para></para>
|
||||||
|
/// </summary>
|
||||||
|
public string AsTable { get; set; }
|
||||||
|
|
||||||
|
internal void ParseAsTable(TableInfo tb)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(AsTable) == false)
|
||||||
|
{
|
||||||
|
var atm = Regex.Match(AsTable, @"([\w_\d]+)\s*=\s*(\d\d\d\d)\s*\-\s*(\d\d?)\s*\-\s*(\d\d?)\s*\((\d+)\s*(year|month|day|hour)\)", RegexOptions.IgnoreCase);
|
||||||
|
if (atm.Success == false)
|
||||||
|
throw new Exception($"[Table(AsTable = \"{AsTable}\")] 特性值格式错误");
|
||||||
|
|
||||||
|
tb.AsTableColumn = tb.Columns.TryGetValue(atm.Groups[1].Value, out var trycol) ? trycol :
|
||||||
|
tb.ColumnsByCs.TryGetValue(atm.Groups[1].Value, out trycol) ? trycol : throw new Exception($"[Table(AsTable = xx)] 设置的属性名 {atm.Groups[1].Value} 不存在");
|
||||||
|
int.TryParse(atm.Groups[5].Value, out var atm5);
|
||||||
|
string atm6 = atm.Groups[6].Value.ToLower();
|
||||||
|
tb.AsTableImpl = new DateTimeAsTableImpl(Name, DateTime.Parse($"{atm.Groups[2].Value}-{atm.Groups[3].Value}-{atm.Groups[4].Value}"), dt =>
|
||||||
|
{
|
||||||
|
switch (atm6)
|
||||||
|
{
|
||||||
|
case "year": return dt.AddYears(atm5);
|
||||||
|
case "month": return dt.AddMonths(atm5);
|
||||||
|
case "day": return dt.AddDays(atm5);
|
||||||
|
case "hour": return dt.AddHours(atm5);
|
||||||
|
}
|
||||||
|
throw new NotImplementedException($"AsTable 未实现的功能 {AsTable}");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IAsTable
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 所有分表名
|
||||||
|
/// </summary>
|
||||||
|
ICollection<string> AllTables { get; }
|
||||||
|
string GetTableNameByColumnValue(object columnValue, bool autoExpand = false);
|
||||||
|
ICollection<string> GetTableNamesByColumnValueRange(object columnValue1, object columnValue2);
|
||||||
|
ICollection<string> GetTableNamesBySqlWhere(string sqlWhere, List<DbParameter> dbParams, TableInfo table, CommonUtils commonUtils);
|
||||||
|
}
|
||||||
|
class DateTimeAsTableImpl : IAsTable
|
||||||
|
{
|
||||||
|
readonly List<string> _allTables = new List<string>();
|
||||||
|
readonly List<DateTime> _allTablesTime = new List<DateTime>();
|
||||||
|
readonly DateTime _beginTime;
|
||||||
|
DateTime _lastTime;
|
||||||
|
Func<DateTime, DateTime> _nextTimeFunc;
|
||||||
|
string _tableName;
|
||||||
|
Match _tableNameFormat;
|
||||||
|
static Regex _regTableNameFormat = new Regex(@"\{([^\\}]+)\}");
|
||||||
|
|
||||||
|
public DateTimeAsTableImpl(string tableName, DateTime beginTime, Func<DateTime, DateTime> nextTimeFunc)
|
||||||
|
{
|
||||||
|
if (nextTimeFunc == null) throw new ArgumentException($"nextTimeFunc 不可以为 null");
|
||||||
|
beginTime = beginTime.Date; //日期部分作为开始
|
||||||
|
_beginTime = beginTime;
|
||||||
|
_nextTimeFunc = nextTimeFunc;
|
||||||
|
_tableName = tableName;
|
||||||
|
_tableNameFormat = _regTableNameFormat.Match(tableName);
|
||||||
|
if (string.IsNullOrEmpty(_tableNameFormat.Groups[1].Value)) throw new ArgumentException("tableName 格式错误,示例:“log_{yyyyMMdd}”");
|
||||||
|
ExpandTable(beginTime, DateTime.Now);
|
||||||
|
}
|
||||||
|
|
||||||
|
int GetTimestamp(DateTime dt) => (int)dt.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
|
||||||
|
void ExpandTable(DateTime beginTime, DateTime endTime)
|
||||||
|
{
|
||||||
|
if (beginTime > endTime) endTime = _nextTimeFunc(beginTime);
|
||||||
|
while (beginTime < endTime)
|
||||||
|
{
|
||||||
|
var dtstr = beginTime.ToString(_tableNameFormat.Groups[1].Value);
|
||||||
|
var name = _tableName.Replace(_tableNameFormat.Groups[0].Value, dtstr);
|
||||||
|
if (_allTables.Contains(name)) throw new ArgumentException($"tableName:{_tableName} 生成了相同的分表名");
|
||||||
|
_allTables.Insert(0, name);
|
||||||
|
_allTablesTime.Insert(0, beginTime);
|
||||||
|
_lastTime = beginTime;
|
||||||
|
beginTime = _nextTimeFunc(beginTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DateTime ParseColumnValue(object columnValue)
|
||||||
|
{
|
||||||
|
if (columnValue == null) throw new Exception($"分表字段值不能为 null");
|
||||||
|
DateTime dt;
|
||||||
|
if (columnValue is DateTime || columnValue is DateTime?)
|
||||||
|
dt = (DateTime)columnValue;
|
||||||
|
else if (columnValue is string)
|
||||||
|
{
|
||||||
|
if (DateTime.TryParse(string.Concat(columnValue), out dt) == false) throw new Exception($"分表字段值 \"{columnValue}\" 不能转化成 DateTime");
|
||||||
|
}
|
||||||
|
else if (columnValue is int || columnValue is long)
|
||||||
|
{
|
||||||
|
dt = new DateTime(1970, 1, 1).AddSeconds((double)columnValue);
|
||||||
|
}
|
||||||
|
else throw new Exception($"分表字段值 \"{columnValue}\" 不能转化成 DateTime");
|
||||||
|
return dt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetTableNameByColumnValue(object columnValue, bool autoExpand = false)
|
||||||
|
{
|
||||||
|
var dt = ParseColumnValue(columnValue);
|
||||||
|
if (dt < _allTablesTime.Last()) throw new Exception($"分表字段值 \"{dt.ToString("yyyy-MM-dd HH:mm:ss")}\" 不能小于 \"{_beginTime.ToString("yyyy-MM-dd HH:mm:ss")} \"");
|
||||||
|
var tmpTime = _nextTimeFunc(_lastTime);
|
||||||
|
if (dt > tmpTime && autoExpand)
|
||||||
|
{
|
||||||
|
// 自动建表
|
||||||
|
ExpandTable(tmpTime, _nextTimeFunc(dt));
|
||||||
|
}
|
||||||
|
for (var a = 0; a < _allTables.Count; a++)
|
||||||
|
if (dt >= _allTablesTime[a])
|
||||||
|
return _allTables[a];
|
||||||
|
throw new Exception($"分表字段值 \"{dt.ToString("yyyy-MM-dd HH:mm:ss")}\" 未匹配到分表名");
|
||||||
|
}
|
||||||
|
public ICollection<string> GetTableNamesByColumnValueRange(object columnValue1, object columnValue2)
|
||||||
|
{
|
||||||
|
var dt1 = ParseColumnValue(columnValue1);
|
||||||
|
var dt2 = ParseColumnValue(columnValue2);
|
||||||
|
if (dt1 > dt2) return new string[0];
|
||||||
|
|
||||||
|
int dt1idx = 0, dt2idx = 0;
|
||||||
|
if (dt1 < _allTablesTime.Last()) dt1idx = _allTablesTime.Count - 1;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (var a = _allTablesTime.Count - 2; a > -1; a--)
|
||||||
|
{
|
||||||
|
if (dt1 < _allTablesTime[a])
|
||||||
|
{
|
||||||
|
dt1idx = a + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dt2 > _allTablesTime.First()) dt2idx = 0;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (var a = 0; a < _allTablesTime.Count; a++)
|
||||||
|
{
|
||||||
|
if (dt2 >= _allTablesTime[a])
|
||||||
|
{
|
||||||
|
dt2idx = a;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dt2idx == -1) return new string[0];
|
||||||
|
|
||||||
|
if (dt1idx == _allTables.Count - 1 && dt2idx == 0) return _allTables;
|
||||||
|
var names = _allTables.GetRange(dt2idx, dt1idx - dt2idx + 1);
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
static readonly ConcurrentDictionary<string, Regex[]> _dicRegSqlWhereDateTimes = new ConcurrentDictionary<string, Regex[]>();
|
||||||
|
static Regex[] GetRegSqlWhereDateTimes(string columnName, string quoteParameterName)
|
||||||
|
{
|
||||||
|
return _dicRegSqlWhereDateTimes.GetOrAdd($"{columnName},{quoteParameterName}", cn =>
|
||||||
|
{
|
||||||
|
cn = columnName.Replace(@"\[", @"\\[").Replace(@"\]", @"\\]");
|
||||||
|
return new[]
|
||||||
|
{
|
||||||
|
new Regex($@"({cn}\s*(<|<=|>|>=|=|between)\s*)(datetime|cdate|to_date)\(('[^']+')\)", RegexOptions.IgnoreCase),
|
||||||
|
new Regex($@"({cn}\s*(<|<=|>|>=|=|between)(\s*))to_timestamp\(('[^']+')\s*,\s*'YYYY-MM-DD[^']+'\)", RegexOptions.IgnoreCase),
|
||||||
|
new Regex($@"({cn}\s*(<|<=|>|>=|=|between)(\s*))cast\(('[^']+') as (datetime|timestamp)\)", RegexOptions.IgnoreCase),
|
||||||
|
new Regex($@"({cn}\s*(<|<=|>|>=|=|between)(\s*))('[^']+')::(datetime|timestamp)", RegexOptions.IgnoreCase),
|
||||||
|
new Regex($@"({cn}\s*(between)\s+'[^']+'\s+and\s+)(datetime|cdate|to_date)\(('[^']+')\)", RegexOptions.IgnoreCase),
|
||||||
|
new Regex($@"({cn}\s*(between)\s+'[^']+'\s+and(\s+))to_timestamp\(('[^']+')\s*,\s*'YYYY-MM-DD[^']+'\)", RegexOptions.IgnoreCase),
|
||||||
|
new Regex($@"({cn}\s*(between)\s+'[^']+'\s+and(\s+))cast\(('[^']+') as (datetime|timestamp)\)", RegexOptions.IgnoreCase),
|
||||||
|
new Regex($@"({cn}\s*(between)\s+'[^']+'\s+and(\s+))('[^']+')::(datetime|timestamp)", RegexOptions.IgnoreCase),
|
||||||
|
|
||||||
|
new Regex($@"({cn}\s*(<|<=|>|>=|=)\s*)(datetime|cdate|to_date)\(({quoteParameterName}[\w_]+)\)", RegexOptions.IgnoreCase),
|
||||||
|
new Regex($@"({cn}\s*(<|<=|>|>=|=)(\s*))to_timestamp\(({quoteParameterName}[\w_]+)\s*,\s*'YYYY-MM-DD[^']+'\)", RegexOptions.IgnoreCase),
|
||||||
|
new Regex($@"({cn}\s*(<|<=|>|>=|=)(\s*))cast\(({quoteParameterName}[^w_]+) as (datetime|timestamp)\)", RegexOptions.IgnoreCase),
|
||||||
|
new Regex($@"({cn}\s*(<|<=|>|>=|=)(\s*))({quoteParameterName}[^w_]+)::(datetime|timestamp)", RegexOptions.IgnoreCase),
|
||||||
|
new Regex($@"({cn}\s*(between)\s+{quoteParameterName}[\w_]+\s+and\s+)(datetime|cdate|to_date)\(({quoteParameterName}[\w_]+)\)", RegexOptions.IgnoreCase),
|
||||||
|
new Regex($@"({cn}\s*(between)\s+{quoteParameterName}[\w_]+\s+and(\s+))to_timestamp\(({quoteParameterName}[\w_]+)\s*,\s*'YYYY-MM-DD[^']+'\)", RegexOptions.IgnoreCase),
|
||||||
|
new Regex($@"({cn}\s*(between)\s+{quoteParameterName}[\w_]+\s+and(\s+))cast\(({quoteParameterName}[^w_]+) as (datetime|timestamp)\)", RegexOptions.IgnoreCase),
|
||||||
|
new Regex($@"({cn}\s*(between)\s+{quoteParameterName}[\w_]+\s+and(\s+))({quoteParameterName}[^w_]+)::(datetime|timestamp)", RegexOptions.IgnoreCase),
|
||||||
|
|
||||||
|
|
||||||
|
new Regex($@"{cn}\s*between\s*'([^']+)'\s*and\s*'([^']+)'", RegexOptions.IgnoreCase),
|
||||||
|
new Regex($@"{cn}\s*between\s*{quoteParameterName}([\w_]+)\s*and\s*{quoteParameterName}([\w_]+)", RegexOptions.IgnoreCase),
|
||||||
|
|
||||||
|
new Regex($@"{cn}\s*(<|<=|>|>=)\s*'([^']+)'\s*and\s*{cn}\s*(<|<=|>|>=)\s*'([^']+)'", RegexOptions.IgnoreCase),
|
||||||
|
new Regex($@"{cn}\s*(<|<=|>|>=)\s*{quoteParameterName}([\w_]+)\s*and\s*{cn}\s*(<|<=|>|>=)\s*{quoteParameterName}([\w_]+)", RegexOptions.IgnoreCase),
|
||||||
|
|
||||||
|
new Regex($@"{cn}\s*(<|<=|>|>=)\s*'([^']+)'", RegexOptions.IgnoreCase),
|
||||||
|
new Regex($@"{cn}\s*(<|<=|>|>=)\s*{quoteParameterName}([\w_]+)", RegexOptions.IgnoreCase),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 可以匹配以下条件(支持参数化):<para></para>
|
||||||
|
/// `field` BETWEEN '2022-01-01 00:00:00' AND '2022-03-01 00:00:00'<para></para>
|
||||||
|
/// `field` > '2022-01-01 00:00:00' AND `field` < '2022-03-01 00:00:00'<para></para>
|
||||||
|
/// `field` > '2022-01-01 00:00:00' AND `field` <= '2022-03-01 00:00:00'<para></para>
|
||||||
|
/// `field` >= '2022-01-01 00:00:00' AND `field` < '2022-03-01 00:00:00'<para></para>
|
||||||
|
/// `field` >= '2022-01-01 00:00:00' AND `field` <= '2022-03-01 00:00:00'<para></para>
|
||||||
|
/// `field` > '2022-01-01 00:00:00'<para></para>
|
||||||
|
/// `field` >= '2022-01-01 00:00:00'<para></para>
|
||||||
|
/// `field` < '2022-01-01 00:00:00'<para></para>
|
||||||
|
/// `field` <= '2022-01-01 00:00:00'<para></para>
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="Exception"></exception>
|
||||||
|
public ICollection<string> GetTableNamesBySqlWhere(string sqlWhere, List<DbParameter> dbParams, TableInfo table, CommonUtils commonUtils)
|
||||||
|
{
|
||||||
|
var quoteParameterName = commonUtils.QuoteParamterName("");
|
||||||
|
var quoteParameterNameCharArray = quoteParameterName.ToCharArray();
|
||||||
|
var regs = GetRegSqlWhereDateTimes(commonUtils.QuoteSqlName(table.AsTableColumn.Attribute.Name), quoteParameterName);
|
||||||
|
for (var a = 0; a < 16; a++) sqlWhere = regs[a].Replace(sqlWhere, "$1$4");
|
||||||
|
|
||||||
|
var m = regs[16].Match(sqlWhere);
|
||||||
|
if (m.Success) return GetTableNamesByColumnValueRange(m.Groups[1].Value, m.Groups[2].Value);
|
||||||
|
m = m = regs[17].Match(sqlWhere);
|
||||||
|
if (m.Success)
|
||||||
|
{
|
||||||
|
var val1 = dbParams.Where(a => a.ParameterName.Trim(quoteParameterNameCharArray) == m.Groups[2].Value).FirstOrDefault();
|
||||||
|
var val2 = dbParams.Where(a => a.ParameterName.Trim(quoteParameterNameCharArray) == m.Groups[4].Value).FirstOrDefault();
|
||||||
|
if (val1 == null || val2 == null) throw new Exception($"未能解析分表字段值 {sqlWhere}");
|
||||||
|
return GetTableNamesByColumnValueRange(val1, val2);
|
||||||
|
}
|
||||||
|
m = m = regs[18].Match(sqlWhere);
|
||||||
|
if (m.Success) return LocalGetTables(m.Groups[1].Value, m.Groups[3].Value, ParseColumnValue(m.Groups[2].Value), ParseColumnValue(m.Groups[4].Value));
|
||||||
|
m = regs[19].Match(sqlWhere);
|
||||||
|
if (m.Success)
|
||||||
|
{
|
||||||
|
var val1 = dbParams.Where(a => a.ParameterName.Trim(quoteParameterNameCharArray) == m.Groups[2].Value).FirstOrDefault();
|
||||||
|
var val2 = dbParams.Where(a => a.ParameterName.Trim(quoteParameterNameCharArray) == m.Groups[4].Value).FirstOrDefault();
|
||||||
|
if (val1 == null || val2 == null) throw new Exception($"未能解析分表字段值 {sqlWhere}");
|
||||||
|
return LocalGetTables(m.Groups[1].Value, m.Groups[3].Value, ParseColumnValue(val1), ParseColumnValue(val2));
|
||||||
|
}
|
||||||
|
m = regs[20].Match(sqlWhere);
|
||||||
|
if (m.Success) return LocalGetTables2(m.Groups[1].Value, ParseColumnValue(m.Groups[2].Value));
|
||||||
|
m = regs[21].Match(sqlWhere);
|
||||||
|
if (m.Success)
|
||||||
|
{
|
||||||
|
var val1 = dbParams.Where(a => a.ParameterName.Trim(quoteParameterNameCharArray) == m.Groups[2].Value).FirstOrDefault();
|
||||||
|
if (val1 == null) throw new Exception($"未能解析分表字段值 {sqlWhere}");
|
||||||
|
return LocalGetTables2(m.Groups[1].Value, ParseColumnValue(val1));
|
||||||
|
}
|
||||||
|
return _allTables;
|
||||||
|
|
||||||
|
ICollection<string> LocalGetTables(string opt1, string opt2, DateTime val1, DateTime val2)
|
||||||
|
{
|
||||||
|
switch (opt1)
|
||||||
|
{
|
||||||
|
case "<":
|
||||||
|
case "<=":
|
||||||
|
if (opt1 == "<") val1 = val1.AddSeconds(-1);
|
||||||
|
switch (opt2)
|
||||||
|
{
|
||||||
|
case "<":
|
||||||
|
val2 = val2.AddSeconds(-1);
|
||||||
|
return GetTableNamesByColumnValueRange(_beginTime, val1 > val2 ? val2 : val1);
|
||||||
|
case "<=":
|
||||||
|
return GetTableNamesByColumnValueRange(_beginTime, val1 > val2 ? val2 : val1);
|
||||||
|
case ">":
|
||||||
|
val2 = val2.AddSeconds(1);
|
||||||
|
return GetTableNamesByColumnValueRange(val2, val1);
|
||||||
|
case ">=":
|
||||||
|
return GetTableNamesByColumnValueRange(val2, val1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ">":
|
||||||
|
case ">=":
|
||||||
|
if (opt1 == ">") val1 = val1.AddSeconds(1);
|
||||||
|
switch (opt2)
|
||||||
|
{
|
||||||
|
case "<":
|
||||||
|
val2 = val2.AddSeconds(-1);
|
||||||
|
return GetTableNamesByColumnValueRange(val1, val2);
|
||||||
|
case "<=":
|
||||||
|
return GetTableNamesByColumnValueRange(val1, val2);
|
||||||
|
case ">":
|
||||||
|
val2 = val2.AddSeconds(1);
|
||||||
|
return GetTableNamesByColumnValueRange(val1 > val2 ? val1 : val2, _lastTime);
|
||||||
|
case ">=":
|
||||||
|
return GetTableNamesByColumnValueRange(val1 > val2 ? val1 : val2, _lastTime);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return _allTables;
|
||||||
|
}
|
||||||
|
ICollection<string> LocalGetTables2(string opt, DateTime val1)
|
||||||
|
{
|
||||||
|
switch (m.Groups[1].Value)
|
||||||
|
{
|
||||||
|
case "<":
|
||||||
|
val1 = val1.AddSeconds(-1);
|
||||||
|
return GetTableNamesByColumnValueRange(_beginTime, val1);
|
||||||
|
case "<=":
|
||||||
|
return GetTableNamesByColumnValueRange(_beginTime, val1);
|
||||||
|
case ">":
|
||||||
|
val1 = val1.AddSeconds(1);
|
||||||
|
return GetTableNamesByColumnValueRange(val1, _lastTime);
|
||||||
|
case ">=":
|
||||||
|
return GetTableNamesByColumnValueRange(val1, _lastTime);
|
||||||
|
}
|
||||||
|
return _allTables;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ICollection<string> AllTables => _allTables;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -397,6 +397,36 @@
|
|||||||
禁用 CodeFirst 同步结构迁移
|
禁用 CodeFirst 同步结构迁移
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="P:FreeSql.DataAnnotations.TableAttribute.AsTable">
|
||||||
|
<summary>
|
||||||
|
格式:属性名=开始时间(递增)<para></para>
|
||||||
|
按年分表:[Table(Name = "log_{yyyy}", AsTable = "create_time=2022-1-1(1 year)")]<para></para>
|
||||||
|
按月分表:[Table(Name = "log_{yyyyMM}", AsTable = "create_time=2022-5-1(1 month)")]<para></para>
|
||||||
|
按日分表:[Table(Name = "log_{yyyyMMdd}", AsTable = "create_time=2022-5-1(5 day)")]<para></para>
|
||||||
|
按时分表:[Table(Name = "log_{yyyyMMddHH}", AsTable = "create_time=2022-5-1(6 hour)")]<para></para>
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:FreeSql.DataAnnotations.IAsTable.AllTables">
|
||||||
|
<summary>
|
||||||
|
所有分表名
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="M:FreeSql.DataAnnotations.DateTimeAsTableImpl.GetTableNamesBySqlWhere(System.String,System.Collections.Generic.List{System.Data.Common.DbParameter},FreeSql.Internal.Model.TableInfo,FreeSql.Internal.CommonUtils)">
|
||||||
|
<summary>
|
||||||
|
可以匹配以下条件(支持参数化):<para></para>
|
||||||
|
`field` BETWEEN '2022-01-01 00:00:00' AND '2022-03-01 00:00:00'<para></para>
|
||||||
|
`field` > '2022-01-01 00:00:00' AND `field` < '2022-03-01 00:00:00'<para></para>
|
||||||
|
`field` > '2022-01-01 00:00:00' AND `field` <= '2022-03-01 00:00:00'<para></para>
|
||||||
|
`field` >= '2022-01-01 00:00:00' AND `field` < '2022-03-01 00:00:00'<para></para>
|
||||||
|
`field` >= '2022-01-01 00:00:00' AND `field` <= '2022-03-01 00:00:00'<para></para>
|
||||||
|
`field` > '2022-01-01 00:00:00'<para></para>
|
||||||
|
`field` >= '2022-01-01 00:00:00'<para></para>
|
||||||
|
`field` < '2022-01-01 00:00:00'<para></para>
|
||||||
|
`field` <= '2022-01-01 00:00:00'<para></para>
|
||||||
|
</summary>
|
||||||
|
<returns></returns>
|
||||||
|
<exception cref="T:System.Exception"></exception>
|
||||||
|
</member>
|
||||||
<member name="M:FreeSql.DataAnnotations.TableFluent.Name(System.String)">
|
<member name="M:FreeSql.DataAnnotations.TableFluent.Name(System.String)">
|
||||||
<summary>
|
<summary>
|
||||||
数据库表名
|
数据库表名
|
||||||
|
@ -95,7 +95,9 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
{
|
{
|
||||||
if (objects == null) return;
|
if (objects == null) return;
|
||||||
var syncObjects = objects.Where(a => a.entityType != null && a.entityType != typeof(object) && _dicSycedGetOrAdd(a.entityType).ContainsKey(GetTableNameLowerOrUpper(a.tableName)) == false && GetTableByEntity(a.entityType)?.DisableSyncStructure == false)
|
var syncObjects = objects.Where(a => a.entityType != null && a.entityType != typeof(object) && _dicSycedGetOrAdd(a.entityType).ContainsKey(GetTableNameLowerOrUpper(a.tableName)) == false && GetTableByEntity(a.entityType)?.DisableSyncStructure == false)
|
||||||
.Select(a => new TypeAndName(a.entityType, GetTableNameLowerOrUpper(a.tableName))).ToArray();
|
.Select(a => new TypeAndName(a.entityType, GetTableNameLowerOrUpper(a.tableName)))
|
||||||
|
.Where(a => !(string.IsNullOrEmpty(a.tableName) == true && GetTableByEntity(a.entityType)?.AsTableImpl != null))
|
||||||
|
.ToArray();
|
||||||
if (syncObjects.Any() == false) return;
|
if (syncObjects.Any() == false) return;
|
||||||
var before = new Aop.SyncStructureBeforeEventArgs(syncObjects.Select(a => a.entityType).ToArray());
|
var before = new Aop.SyncStructureBeforeEventArgs(syncObjects.Select(a => a.entityType).ToArray());
|
||||||
_orm.Aop.SyncStructureBeforeHandler?.Invoke(this, before);
|
_orm.Aop.SyncStructureBeforeHandler?.Invoke(this, before);
|
||||||
|
@ -10,8 +10,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace FreeSql.Internal.CommonProvider
|
namespace FreeSql.Internal.CommonProvider
|
||||||
{
|
{
|
||||||
|
public abstract partial class DeleteProvider
|
||||||
public abstract partial class DeleteProvider<T1> : IDelete<T1>
|
|
||||||
{
|
{
|
||||||
public IFreeSql _orm;
|
public IFreeSql _orm;
|
||||||
public CommonUtils _commonUtils;
|
public CommonUtils _commonUtils;
|
||||||
@ -26,7 +25,10 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
public DbConnection _connection;
|
public DbConnection _connection;
|
||||||
public int _commandTimeout = 0;
|
public int _commandTimeout = 0;
|
||||||
public Action<StringBuilder> _interceptSql;
|
public Action<StringBuilder> _interceptSql;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract partial class DeleteProvider<T1> : DeleteProvider, IDelete<T1>
|
||||||
|
{
|
||||||
public DeleteProvider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere)
|
public DeleteProvider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere)
|
||||||
{
|
{
|
||||||
_orm = orm;
|
_orm = orm;
|
||||||
@ -66,28 +68,32 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
|
|
||||||
public int ExecuteAffrows()
|
public int ExecuteAffrows()
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return 0;
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var affrows = 0;
|
var affrows = 0;
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
ToSqlFetch(sb =>
|
||||||
{
|
{
|
||||||
affrows = _orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms);
|
if (dbParms == null) dbParms = _params.ToArray();
|
||||||
}
|
var sql = sb.ToString();
|
||||||
catch (Exception ex)
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
{
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
exception = ex;
|
|
||||||
throw;
|
Exception exception = null;
|
||||||
}
|
try
|
||||||
finally
|
{
|
||||||
{
|
affrows += _orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms);
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, affrows);
|
}
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
this.ClearData();
|
exception = ex;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, affrows);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null) this.ClearData();
|
||||||
return affrows;
|
return affrows;
|
||||||
}
|
}
|
||||||
public abstract List<T1> ExecuteDeleted();
|
public abstract List<T1> ExecuteDeleted();
|
||||||
@ -165,16 +171,77 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
public virtual string ToSql()
|
public virtual string ToSql()
|
||||||
{
|
{
|
||||||
if (_whereTimes <= 0) return null;
|
if (_whereTimes <= 0) return null;
|
||||||
var sb = new StringBuilder().Append("DELETE FROM ").Append(_commonUtils.QuoteSqlName(TableRuleInvoke())).Append(" WHERE ").Append(_where);
|
var sb = new StringBuilder();
|
||||||
|
ToSqlFetch(sql =>
|
||||||
|
{
|
||||||
|
sb.Append(sql).Append("\r\n\r\n;\r\n\r\n");
|
||||||
|
});
|
||||||
|
if (sb.Length > 0) sb.Remove(sb.Length - 9, 9);
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ToSqlFetch(Action<StringBuilder> fetch)
|
||||||
|
{
|
||||||
|
if (_whereTimes <= 0) return;
|
||||||
|
var newwhere = new StringBuilder().Append(" WHERE ").Append(_where);
|
||||||
|
|
||||||
if (_whereGlobalFilter.Any())
|
if (_whereGlobalFilter.Any())
|
||||||
{
|
{
|
||||||
var globalFilterCondi = _commonExpression.GetWhereCascadeSql(new SelectTableInfo { Table = _table }, _whereGlobalFilter, false);
|
var globalFilterCondi = _commonExpression.GetWhereCascadeSql(new SelectTableInfo { Table = _table }, _whereGlobalFilter, false);
|
||||||
if (string.IsNullOrEmpty(globalFilterCondi) == false)
|
if (string.IsNullOrEmpty(globalFilterCondi) == false)
|
||||||
sb.Append(" AND ").Append(globalFilterCondi);
|
newwhere.Append(" AND ").Append(globalFilterCondi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
if (_table.AsTableImpl != null)
|
||||||
|
{
|
||||||
|
var names = _table.AsTableImpl.GetTableNamesBySqlWhere(newwhere.ToString(), _params, _table, _commonUtils);
|
||||||
|
foreach (var name in names)
|
||||||
|
{
|
||||||
|
_tableRule = old => name;
|
||||||
|
sb.Clear().Append("DELETE FROM ").Append(_commonUtils.QuoteSqlName(TableRuleInvoke())).Append(newwhere);
|
||||||
|
_interceptSql?.Invoke(sb);
|
||||||
|
fetch(sb);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Insert(0, _commonUtils.QuoteSqlName(TableRuleInvoke())).Insert(0, "DELETE FROM ");
|
||||||
_interceptSql?.Invoke(sb);
|
_interceptSql?.Invoke(sb);
|
||||||
return sb.ToString();
|
fetch(sb);
|
||||||
}
|
}
|
||||||
|
#if net40
|
||||||
|
#else
|
||||||
|
async public Task ToSqlFetchAsync(Func<StringBuilder, Task> fetchAsync)
|
||||||
|
{
|
||||||
|
if (_whereTimes <= 0) return;
|
||||||
|
var newwhere = new StringBuilder().Append(" WHERE ").Append(_where);
|
||||||
|
|
||||||
|
if (_whereGlobalFilter.Any())
|
||||||
|
{
|
||||||
|
var globalFilterCondi = _commonExpression.GetWhereCascadeSql(new SelectTableInfo { Table = _table }, _whereGlobalFilter, false);
|
||||||
|
if (string.IsNullOrEmpty(globalFilterCondi) == false)
|
||||||
|
newwhere.Append(" AND ").Append(globalFilterCondi);
|
||||||
|
}
|
||||||
|
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
if (_table.AsTableImpl != null)
|
||||||
|
{
|
||||||
|
var names = _table.AsTableImpl.GetTableNamesBySqlWhere(newwhere.ToString(), _params, _table, _commonUtils);
|
||||||
|
foreach (var name in names)
|
||||||
|
{
|
||||||
|
_tableRule = old => name;
|
||||||
|
sb.Clear().Append("DELETE FROM ").Append(_commonUtils.QuoteSqlName(TableRuleInvoke())).Append(newwhere);
|
||||||
|
_interceptSql?.Invoke(sb);
|
||||||
|
await fetchAsync(sb);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Insert(0, _commonUtils.QuoteSqlName(TableRuleInvoke())).Insert(0, "DELETE FROM ");
|
||||||
|
_interceptSql?.Invoke(sb);
|
||||||
|
await fetchAsync(sb);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,28 +16,32 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
#else
|
#else
|
||||||
async public Task<int> ExecuteAffrowsAsync(CancellationToken cancellationToken = default)
|
async public Task<int> ExecuteAffrowsAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return 0;
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var affrows = 0;
|
var affrows = 0;
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
await ToSqlFetchAsync(async sb =>
|
||||||
{
|
{
|
||||||
affrows = await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken);
|
if (dbParms == null) dbParms = _params.ToArray();
|
||||||
}
|
var sql = sb.ToString();
|
||||||
catch (Exception ex)
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
{
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
exception = ex;
|
|
||||||
throw;
|
Exception exception = null;
|
||||||
}
|
try
|
||||||
finally
|
{
|
||||||
{
|
affrows += await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken);
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, affrows);
|
}
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
this.ClearData();
|
exception = ex;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, affrows);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null) this.ClearData();
|
||||||
return affrows;
|
return affrows;
|
||||||
}
|
}
|
||||||
public abstract Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default);
|
public abstract Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default);
|
||||||
|
@ -14,12 +14,11 @@ using System.Collections;
|
|||||||
namespace FreeSql.Internal.CommonProvider
|
namespace FreeSql.Internal.CommonProvider
|
||||||
{
|
{
|
||||||
|
|
||||||
public abstract partial class InsertProvider<T1> : IInsert<T1> where T1 : class
|
public abstract partial class InsertProvider
|
||||||
{
|
{
|
||||||
public IFreeSql _orm;
|
public IFreeSql _orm;
|
||||||
public CommonUtils _commonUtils;
|
public CommonUtils _commonUtils;
|
||||||
public CommonExpression _commonExpression;
|
public CommonExpression _commonExpression;
|
||||||
public List<T1> _source = new List<T1>();
|
|
||||||
public Dictionary<string, bool> _ignore = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase);
|
public Dictionary<string, bool> _ignore = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase);
|
||||||
public Dictionary<string, bool> _auditValueChangedDict = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase);
|
public Dictionary<string, bool> _auditValueChangedDict = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase);
|
||||||
public TableInfo _table;
|
public TableInfo _table;
|
||||||
@ -28,11 +27,17 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
public bool _noneParameter, _insertIdentity;
|
public bool _noneParameter, _insertIdentity;
|
||||||
public int _batchValuesLimit, _batchParameterLimit;
|
public int _batchValuesLimit, _batchParameterLimit;
|
||||||
public bool _batchAutoTransaction = true;
|
public bool _batchAutoTransaction = true;
|
||||||
public Action<BatchProgressStatus<T1>> _batchProgress;
|
|
||||||
public DbParameter[] _params;
|
public DbParameter[] _params;
|
||||||
public DbTransaction _transaction;
|
public DbTransaction _transaction;
|
||||||
public DbConnection _connection;
|
public DbConnection _connection;
|
||||||
public int _commandTimeout = 0;
|
public int _commandTimeout = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract partial class InsertProvider<T1> : InsertProvider, IInsert<T1> where T1 : class
|
||||||
|
{
|
||||||
|
public List<T1> _source = new List<T1>();
|
||||||
|
internal List<T1> _sourceOld;
|
||||||
|
public Action<BatchProgressStatus<T1>> _batchProgress;
|
||||||
|
|
||||||
public InsertProvider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression)
|
public InsertProvider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression)
|
||||||
{
|
{
|
||||||
@ -43,6 +48,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
_noneParameter = _orm.CodeFirst.IsNoneCommandParameter;
|
_noneParameter = _orm.CodeFirst.IsNoneCommandParameter;
|
||||||
if (_orm.CodeFirst.IsAutoSyncStructure && typeof(T1) != typeof(object)) _orm.CodeFirst.SyncStructure<T1>();
|
if (_orm.CodeFirst.IsAutoSyncStructure && typeof(T1) != typeof(object)) _orm.CodeFirst.SyncStructure<T1>();
|
||||||
IgnoreCanInsert();
|
IgnoreCanInsert();
|
||||||
|
_sourceOld = _source;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -62,6 +68,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
_batchProgress = null;
|
_batchProgress = null;
|
||||||
_insertIdentity = false;
|
_insertIdentity = false;
|
||||||
_source.Clear();
|
_source.Clear();
|
||||||
|
_sourceOld = _source;
|
||||||
_ignore.Clear();
|
_ignore.Clear();
|
||||||
_auditValueChangedDict.Clear();
|
_auditValueChangedDict.Clear();
|
||||||
_params = null;
|
_params = null;
|
||||||
@ -189,7 +196,7 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region 参数化数据限制,或values数量限制
|
#region 参数化数据限制,或values数量限制
|
||||||
protected List<T1>[] SplitSource(int valuesLimit, int parameterLimit)
|
protected List<T1>[] SplitSource(int valuesLimit, int parameterLimit, bool isAsTableSplited = false)
|
||||||
{
|
{
|
||||||
valuesLimit = valuesLimit - 1;
|
valuesLimit = valuesLimit - 1;
|
||||||
parameterLimit = parameterLimit - 1;
|
parameterLimit = parameterLimit - 1;
|
||||||
@ -198,6 +205,28 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
if (_source == null || _source.Any() == false) return new List<T1>[0];
|
if (_source == null || _source.Any() == false) return new List<T1>[0];
|
||||||
if (_source.Count == 1) return new[] { _source };
|
if (_source.Count == 1) return new[] { _source };
|
||||||
|
|
||||||
|
if (_table.AsTableImpl != null && isAsTableSplited == false)
|
||||||
|
{
|
||||||
|
var atarr = _source.Select(a => new
|
||||||
|
{
|
||||||
|
item = a,
|
||||||
|
splitKey = _table.AsTableImpl.GetTableNameByColumnValue(_table.AsTableColumn.GetValue(a), true)
|
||||||
|
}).GroupBy(a => a.splitKey, a => a.item).ToArray();
|
||||||
|
if (atarr.Length > 1)
|
||||||
|
{
|
||||||
|
var oldSource = _source;
|
||||||
|
var arrret = new List<List<T1>>();
|
||||||
|
foreach (var item in atarr)
|
||||||
|
{
|
||||||
|
_source = item.ToList();
|
||||||
|
var itemret = SplitSource(valuesLimit + 1, parameterLimit + 1, true);
|
||||||
|
arrret.AddRange(itemret);
|
||||||
|
}
|
||||||
|
_source = oldSource;
|
||||||
|
return arrret.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var takeMax = valuesLimit;
|
var takeMax = valuesLimit;
|
||||||
if (_noneParameter == false)
|
if (_noneParameter == false)
|
||||||
{
|
{
|
||||||
@ -510,8 +539,8 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
protected string TableRuleInvoke()
|
protected string TableRuleInvoke()
|
||||||
{
|
{
|
||||||
var tbname = _table?.DbName ?? "";
|
var tbname = _table?.DbName ?? "";
|
||||||
if (_tableRule == null) return tbname;
|
if (_tableRule == null && _table.AsTableImpl == null) return tbname;
|
||||||
var newname = _tableRule(tbname);
|
var newname = _table.AsTableImpl?.GetTableNameByColumnValue(_source.Any() ? _table.AsTableColumn.GetValue(_source.FirstOrDefault()) : DateTime.Now) ?? _tableRule(tbname);
|
||||||
if (newname == tbname) return tbname;
|
if (newname == tbname) return tbname;
|
||||||
if (string.IsNullOrEmpty(newname)) return tbname;
|
if (string.IsNullOrEmpty(newname)) return tbname;
|
||||||
if (_orm.CodeFirst.IsSyncStructureToLower) newname = newname.ToLower();
|
if (_orm.CodeFirst.IsSyncStructureToLower) newname = newname.ToLower();
|
||||||
@ -540,14 +569,38 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual string ToSql() => ToSqlValuesOrSelectUnionAllExtension102(true, null, null);
|
public virtual string ToSql() => ToSqlValuesOrSelectUnionAllExtension103(true, null, null, false);
|
||||||
|
|
||||||
public string ToSqlValuesOrSelectUnionAll(bool isValues = true) => ToSqlValuesOrSelectUnionAllExtension102(isValues, null, null);
|
public string ToSqlValuesOrSelectUnionAll(bool isValues = true) => ToSqlValuesOrSelectUnionAllExtension103(isValues, null, null, false);
|
||||||
public string ToSqlValuesOrSelectUnionAllExtension101(bool isValues, Action<object, int, StringBuilder> onrow) => ToSqlValuesOrSelectUnionAllExtension102(isValues, null, onrow);
|
public string ToSqlValuesOrSelectUnionAllExtension101(bool isValues, Action<object, int, StringBuilder> onrow) => ToSqlValuesOrSelectUnionAllExtension103(isValues, null, onrow, false);
|
||||||
public string ToSqlValuesOrSelectUnionAllExtension102(bool isValues, Action<object, int, StringBuilder> onrowPre, Action<object, int, StringBuilder> onrow)
|
public string ToSqlValuesOrSelectUnionAllExtension102(bool isValues, Action<object, int, StringBuilder> onrowPre, Action<object, int, StringBuilder> onrow) => ToSqlValuesOrSelectUnionAllExtension103(isValues, null, onrow, false);
|
||||||
|
string ToSqlValuesOrSelectUnionAllExtension103(bool isValues, Action<object, int, StringBuilder> onrowPre, Action<object, int, StringBuilder> onrow, bool isAsTableSplited)
|
||||||
{
|
{
|
||||||
if (_source == null || _source.Any() == false) return null;
|
if (_source == null || _source.Any() == false) return null;
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
|
|
||||||
|
if (_table.AsTableImpl != null && isAsTableSplited == false && _source == _sourceOld)
|
||||||
|
{
|
||||||
|
var atarr = _source.Select(a => new
|
||||||
|
{
|
||||||
|
item = a,
|
||||||
|
splitKey = _table.AsTableImpl.GetTableNameByColumnValue(_table.AsTableColumn.GetValue(a), true)
|
||||||
|
}).GroupBy(a => a.splitKey, a => a.item).ToArray();
|
||||||
|
if (atarr.Length > 1)
|
||||||
|
{
|
||||||
|
var oldSource = _source;
|
||||||
|
var arrret = new List<List<T1>>();
|
||||||
|
foreach (var item in atarr)
|
||||||
|
{
|
||||||
|
_source = item.ToList();
|
||||||
|
sb.Append(ToSqlValuesOrSelectUnionAllExtension103(isValues, onrowPre, onrow, true)).Append("\r\n\r\n;\r\n\r\n");
|
||||||
|
}
|
||||||
|
_source = oldSource;
|
||||||
|
if (sb.Length > 0) sb.Remove(sb.Length - 9, 9);
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sb.Append("INSERT INTO ").Append(_commonUtils.QuoteSqlName(TableRuleInvoke())).Append('(');
|
sb.Append("INSERT INTO ").Append(_commonUtils.QuoteSqlName(TableRuleInvoke())).Append('(');
|
||||||
var colidx = 0;
|
var colidx = 0;
|
||||||
foreach (var col in _table.Columns.Values)
|
foreach (var col in _table.Columns.Values)
|
||||||
|
@ -125,7 +125,9 @@ namespace FreeSql.Internal
|
|||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(trytb.Name)) attr.Name = trytb.Name;
|
if (!string.IsNullOrEmpty(trytb.Name)) attr.Name = trytb.Name;
|
||||||
if (!string.IsNullOrEmpty(trytb.OldName)) attr.OldName = trytb.OldName;
|
if (!string.IsNullOrEmpty(trytb.OldName)) attr.OldName = trytb.OldName;
|
||||||
if (trytb._DisableSyncStructure != null) attr._DisableSyncStructure = trytb.DisableSyncStructure;
|
if (trytb._DisableSyncStructure != null) attr._DisableSyncStructure = trytb.DisableSyncStructure;
|
||||||
|
if (!string.IsNullOrEmpty(trytb.AsTable)) attr.AsTable = trytb.AsTable;
|
||||||
|
|
||||||
}
|
}
|
||||||
var attrs = type.GetCustomAttributes(typeof(TableAttribute), false);
|
var attrs = type.GetCustomAttributes(typeof(TableAttribute), false);
|
||||||
foreach (var tryattrobj in attrs)
|
foreach (var tryattrobj in attrs)
|
||||||
@ -135,10 +137,12 @@ namespace FreeSql.Internal
|
|||||||
if (!string.IsNullOrEmpty(tryattr.Name)) attr.Name = tryattr.Name;
|
if (!string.IsNullOrEmpty(tryattr.Name)) attr.Name = tryattr.Name;
|
||||||
if (!string.IsNullOrEmpty(tryattr.OldName)) attr.OldName = tryattr.OldName;
|
if (!string.IsNullOrEmpty(tryattr.OldName)) attr.OldName = tryattr.OldName;
|
||||||
if (tryattr._DisableSyncStructure != null) attr._DisableSyncStructure = tryattr.DisableSyncStructure;
|
if (tryattr._DisableSyncStructure != null) attr._DisableSyncStructure = tryattr.DisableSyncStructure;
|
||||||
|
if (!string.IsNullOrEmpty(tryattr.AsTable)) attr.AsTable = tryattr.AsTable;
|
||||||
}
|
}
|
||||||
if (!string.IsNullOrEmpty(attr.Name)) return attr;
|
if (!string.IsNullOrEmpty(attr.Name)) return attr;
|
||||||
if (!string.IsNullOrEmpty(attr.OldName)) return attr;
|
if (!string.IsNullOrEmpty(attr.OldName)) return attr;
|
||||||
if (attr._DisableSyncStructure != null) return attr;
|
if (attr._DisableSyncStructure != null) return attr;
|
||||||
|
if (!string.IsNullOrEmpty(attr.AsTable)) return attr;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public ColumnAttribute GetEntityColumnAttribute(Type type, PropertyInfo proto)
|
public ColumnAttribute GetEntityColumnAttribute(Type type, PropertyInfo proto)
|
||||||
|
@ -27,6 +27,8 @@ namespace FreeSql.Internal.Model
|
|||||||
public bool IsRereadSql { get; internal set; }
|
public bool IsRereadSql { get; internal set; }
|
||||||
public bool IsDictionaryType { get; internal set; }
|
public bool IsDictionaryType { get; internal set; }
|
||||||
|
|
||||||
|
public IAsTable AsTableImpl { get; internal set; }
|
||||||
|
public ColumnInfo AsTableColumn { get; internal set; }
|
||||||
public ColumnInfo VersionColumn { get; set; }
|
public ColumnInfo VersionColumn { get; set; }
|
||||||
|
|
||||||
ConcurrentDictionary<string, TableRef> _refs { get; } = new ConcurrentDictionary<string, TableRef>(StringComparer.CurrentCultureIgnoreCase);
|
ConcurrentDictionary<string, TableRef> _refs { get; } = new ConcurrentDictionary<string, TableRef>(StringComparer.CurrentCultureIgnoreCase);
|
||||||
|
@ -393,6 +393,7 @@ namespace FreeSql.Internal
|
|||||||
if (trytb.VersionColumn.Attribute.MapType.IsNullableType() || trytb.VersionColumn.Attribute.MapType.IsNumberType() == false && trytb.VersionColumn.Attribute.MapType != typeof(byte[]))
|
if (trytb.VersionColumn.Attribute.MapType.IsNullableType() || trytb.VersionColumn.Attribute.MapType.IsNumberType() == false && trytb.VersionColumn.Attribute.MapType != typeof(byte[]))
|
||||||
throw new Exception($"属性{trytb.VersionColumn.CsName} 被标注为行锁(乐观锁)(IsVersion),但其必须为数字类型 或者 byte[],并且不可为 Nullable");
|
throw new Exception($"属性{trytb.VersionColumn.CsName} 被标注为行锁(乐观锁)(IsVersion),但其必须为数字类型 或者 byte[],并且不可为 Nullable");
|
||||||
}
|
}
|
||||||
|
tbattr?.ParseAsTable(trytb);
|
||||||
|
|
||||||
var indexesDict = new Dictionary<string, IndexInfo>(StringComparer.CurrentCultureIgnoreCase);
|
var indexesDict = new Dictionary<string, IndexInfo>(StringComparer.CurrentCultureIgnoreCase);
|
||||||
//从数据库查找主键、自增、索引
|
//从数据库查找主键、自增、索引
|
||||||
|
@ -16,20 +16,16 @@ namespace FreeSql.ClickHouse.Curd
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override List<T1> ExecuteDeleted()
|
public override List<T1> ExecuteDeleted() => throw new NotImplementedException("FreeSql.Provider.ClickHouse 未实现该功能");
|
||||||
{
|
|
||||||
throw new NotImplementedException("FreeSql.ClickHouse.Curd 暂未实现");
|
|
||||||
}
|
|
||||||
public override string ToSql()
|
public override string ToSql()
|
||||||
{
|
{
|
||||||
return base.ToSql().Replace("DELETE FROM", "ALTER TABLE").Replace("WHERE", "DELETE WHERE");
|
return base.ToSql().Replace("DELETE FROM ", "ALTER TABLE ").Replace(" WHERE ", " DELETE WHERE ");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if net40
|
#if net40
|
||||||
#else
|
#else
|
||||||
public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException("FreeSql.Provider.ClickHouse 未实现该功能");
|
||||||
{
|
|
||||||
throw new NotImplementedException("FreeSql.ClickHouse.Curd 暂未实现");
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,17 +16,11 @@ namespace FreeSql.Dameng.Curd
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override List<T1> ExecuteDeleted()
|
public override List<T1> ExecuteDeleted() => throw new NotImplementedException("FreeSql.Provider.Dameng 未实现该功能");
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if net40
|
#if net40
|
||||||
#else
|
#else
|
||||||
public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException("FreeSql.Provider.Dameng 未实现该功能");
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -18,40 +19,50 @@ namespace FreeSql.Firebird.Curd
|
|||||||
|
|
||||||
public override List<T1> ExecuteDeleted()
|
public override List<T1> ExecuteDeleted()
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append(sql).Append(" RETURNING ");
|
|
||||||
|
|
||||||
var colidx = 0;
|
|
||||||
foreach (var col in _table.Columns.Values)
|
|
||||||
{
|
|
||||||
if (colidx > 0) sb.Append(", ");
|
|
||||||
sb.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
sql = sb.ToString();
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
StringBuilder sbret = null;
|
||||||
|
ToSqlFetch(sb =>
|
||||||
{
|
{
|
||||||
ret = _orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms);
|
if (dbParms == null)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
dbParms = _params.ToArray();
|
||||||
|
sbret = new StringBuilder();
|
||||||
|
sbret.Append(" RETURNING ");
|
||||||
|
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sbret.Append(", ");
|
||||||
|
sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sql = sb.Append(sbret).ToString();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.TypeLazy ?? _table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
|
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.AddRange(_orm.Ado.Query<T1>(_connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null)
|
||||||
{
|
{
|
||||||
exception = ex;
|
this.ClearData();
|
||||||
throw ex;
|
sbret.Clear();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
|
||||||
}
|
|
||||||
this.ClearData();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,40 +70,50 @@ namespace FreeSql.Firebird.Curd
|
|||||||
#else
|
#else
|
||||||
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append(sql).Append(" RETURNING ");
|
|
||||||
|
|
||||||
var colidx = 0;
|
|
||||||
foreach (var col in _table.Columns.Values)
|
|
||||||
{
|
|
||||||
if (colidx > 0) sb.Append(", ");
|
|
||||||
sb.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
sql = sb.ToString();
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
StringBuilder sbret = null;
|
||||||
|
await ToSqlFetchAsync(async sb =>
|
||||||
{
|
{
|
||||||
ret = await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken);
|
if (dbParms == null)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
dbParms = _params.ToArray();
|
||||||
|
sbret = new StringBuilder();
|
||||||
|
sbret.Append(" RETURNING ");
|
||||||
|
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sbret.Append(", ");
|
||||||
|
sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sql = sb.Append(sbret).ToString();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.TypeLazy ?? _table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
|
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.AddRange(await _orm.Ado.QueryAsync<T1>(_connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null)
|
||||||
{
|
{
|
||||||
exception = ex;
|
this.ClearData();
|
||||||
throw ex;
|
sbret.Clear();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
|
||||||
}
|
|
||||||
this.ClearData();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -16,17 +16,11 @@ namespace FreeSql.GBase.Curd
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override List<T1> ExecuteDeleted()
|
public override List<T1> ExecuteDeleted() => throw new NotImplementedException("FreeSql.Provider.GBase 未实现该功能");
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if net40
|
#if net40
|
||||||
#else
|
#else
|
||||||
public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException("FreeSql.Provider.GBase 未实现该功能");
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -18,40 +19,50 @@ namespace FreeSql.KingbaseES
|
|||||||
|
|
||||||
public override List<T1> ExecuteDeleted()
|
public override List<T1> ExecuteDeleted()
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append(sql).Append(" RETURNING ");
|
|
||||||
|
|
||||||
var colidx = 0;
|
|
||||||
foreach (var col in _table.Columns.Values)
|
|
||||||
{
|
|
||||||
if (colidx > 0) sb.Append(", ");
|
|
||||||
sb.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
sql = sb.ToString();
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
StringBuilder sbret = null;
|
||||||
|
ToSqlFetch(sb =>
|
||||||
{
|
{
|
||||||
ret = _orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms);
|
if (dbParms == null)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
dbParms = _params.ToArray();
|
||||||
|
sbret = new StringBuilder();
|
||||||
|
sbret.Append(" RETURNING ");
|
||||||
|
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sbret.Append(", ");
|
||||||
|
sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sql = sb.Append(sbret).ToString();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
|
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.AddRange(_orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null)
|
||||||
{
|
{
|
||||||
exception = ex;
|
this.ClearData();
|
||||||
throw ex;
|
sbret.Clear();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
|
||||||
}
|
|
||||||
this.ClearData();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,40 +70,50 @@ namespace FreeSql.KingbaseES
|
|||||||
#else
|
#else
|
||||||
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append(sql).Append(" RETURNING ");
|
|
||||||
|
|
||||||
var colidx = 0;
|
|
||||||
foreach (var col in _table.Columns.Values)
|
|
||||||
{
|
|
||||||
if (colidx > 0) sb.Append(", ");
|
|
||||||
sb.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
sql = sb.ToString();
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
StringBuilder sbret = null;
|
||||||
|
await ToSqlFetchAsync(async sb =>
|
||||||
{
|
{
|
||||||
ret = await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken);
|
if (dbParms == null)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
dbParms = _params.ToArray();
|
||||||
|
sbret = new StringBuilder();
|
||||||
|
sbret.Append(" RETURNING ");
|
||||||
|
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sbret.Append(", ");
|
||||||
|
sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sql = sb.Append(sbret).ToString();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
|
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.AddRange(await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null)
|
||||||
{
|
{
|
||||||
exception = ex;
|
this.ClearData();
|
||||||
throw ex;
|
sbret.Clear();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
|
||||||
}
|
|
||||||
this.ClearData();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -16,17 +16,11 @@ namespace FreeSql.MsAccess.Curd
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override List<T1> ExecuteDeleted()
|
public override List<T1> ExecuteDeleted() => throw new NotImplementedException("FreeSql.Provider.MsAccess 未实现该功能");
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if net40
|
#if net40
|
||||||
#else
|
#else
|
||||||
public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException("FreeSql.Provider.MsAccess 未实现该功能");
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -18,40 +19,50 @@ namespace FreeSql.MySql.Curd
|
|||||||
|
|
||||||
public override List<T1> ExecuteDeleted()
|
public override List<T1> ExecuteDeleted()
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append(sql).Append(" RETURNING ");
|
|
||||||
|
|
||||||
var colidx = 0;
|
|
||||||
foreach (var col in _table.Columns.Values)
|
|
||||||
{
|
|
||||||
if (colidx > 0) sb.Append(", ");
|
|
||||||
sb.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
sql = sb.ToString();
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
StringBuilder sbret = null;
|
||||||
|
ToSqlFetch(sb =>
|
||||||
{
|
{
|
||||||
ret = _orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms);
|
if (dbParms == null)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
dbParms = _params.ToArray();
|
||||||
|
sbret = new StringBuilder();
|
||||||
|
sbret.Append(" RETURNING ");
|
||||||
|
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sbret.Append(", ");
|
||||||
|
sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sql = sb.Append(sbret).ToString();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
|
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.AddRange(_orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null)
|
||||||
{
|
{
|
||||||
exception = ex;
|
this.ClearData();
|
||||||
throw;
|
sbret.Clear();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
|
||||||
}
|
|
||||||
this.ClearData();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,40 +70,50 @@ namespace FreeSql.MySql.Curd
|
|||||||
#else
|
#else
|
||||||
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append(sql).Append(" RETURNING ");
|
|
||||||
|
|
||||||
var colidx = 0;
|
|
||||||
foreach (var col in _table.Columns.Values)
|
|
||||||
{
|
|
||||||
if (colidx > 0) sb.Append(", ");
|
|
||||||
sb.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
sql = sb.ToString();
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
StringBuilder sbret = null;
|
||||||
|
await ToSqlFetchAsync(async sb =>
|
||||||
{
|
{
|
||||||
ret = await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken);
|
if (dbParms == null)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
dbParms = _params.ToArray();
|
||||||
|
sbret = new StringBuilder();
|
||||||
|
sbret.Append(" RETURNING ");
|
||||||
|
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sbret.Append(", ");
|
||||||
|
sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sql = sb.Append(sbret).ToString();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
|
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.AddRange(await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null)
|
||||||
{
|
{
|
||||||
exception = ex;
|
this.ClearData();
|
||||||
throw;
|
sbret.Clear();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
|
||||||
}
|
|
||||||
this.ClearData();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -16,17 +16,11 @@ namespace FreeSql.Odbc.Dameng
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override List<T1> ExecuteDeleted()
|
public override List<T1> ExecuteDeleted() => throw new NotImplementedException("FreeSql.Odbc.Dameng 未实现该功能");
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if net40
|
#if net40
|
||||||
#else
|
#else
|
||||||
public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException("FreeSql.Odbc.Dameng 未实现该功能");
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -18,40 +19,50 @@ namespace FreeSql.Odbc.KingbaseES
|
|||||||
|
|
||||||
public override List<T1> ExecuteDeleted()
|
public override List<T1> ExecuteDeleted()
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append(sql).Append(" RETURNING ");
|
|
||||||
|
|
||||||
var colidx = 0;
|
|
||||||
foreach (var col in _table.Columns.Values)
|
|
||||||
{
|
|
||||||
if (colidx > 0) sb.Append(", ");
|
|
||||||
sb.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
sql = sb.ToString();
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
StringBuilder sbret = null;
|
||||||
|
ToSqlFetch(sb =>
|
||||||
{
|
{
|
||||||
ret = _orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms);
|
if (dbParms == null)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
dbParms = _params.ToArray();
|
||||||
|
sbret = new StringBuilder();
|
||||||
|
sbret.Append(" RETURNING ");
|
||||||
|
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sbret.Append(", ");
|
||||||
|
sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sql = sb.Append(sbret).ToString();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
|
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.AddRange(_orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null)
|
||||||
{
|
{
|
||||||
exception = ex;
|
this.ClearData();
|
||||||
throw ex;
|
sbret.Clear();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
|
||||||
}
|
|
||||||
this.ClearData();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,40 +70,50 @@ namespace FreeSql.Odbc.KingbaseES
|
|||||||
#else
|
#else
|
||||||
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append(sql).Append(" RETURNING ");
|
|
||||||
|
|
||||||
var colidx = 0;
|
|
||||||
foreach (var col in _table.Columns.Values)
|
|
||||||
{
|
|
||||||
if (colidx > 0) sb.Append(", ");
|
|
||||||
sb.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
sql = sb.ToString();
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
StringBuilder sbret = null;
|
||||||
|
await ToSqlFetchAsync(async sb =>
|
||||||
{
|
{
|
||||||
ret = await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken);
|
if (dbParms == null)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
dbParms = _params.ToArray();
|
||||||
|
sbret = new StringBuilder();
|
||||||
|
sbret.Append(" RETURNING ");
|
||||||
|
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sbret.Append(", ");
|
||||||
|
sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sql = sb.Append(sbret).ToString();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
|
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.AddRange(await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null)
|
||||||
{
|
{
|
||||||
exception = ex;
|
this.ClearData();
|
||||||
throw ex;
|
sbret.Clear();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
|
||||||
}
|
|
||||||
this.ClearData();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -18,40 +19,50 @@ namespace FreeSql.Odbc.MySql
|
|||||||
|
|
||||||
public override List<T1> ExecuteDeleted()
|
public override List<T1> ExecuteDeleted()
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append(sql).Append(" RETURNING ");
|
|
||||||
|
|
||||||
var colidx = 0;
|
|
||||||
foreach (var col in _table.Columns.Values)
|
|
||||||
{
|
|
||||||
if (colidx > 0) sb.Append(", ");
|
|
||||||
sb.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
sql = sb.ToString();
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
StringBuilder sbret = null;
|
||||||
|
ToSqlFetch(sb =>
|
||||||
{
|
{
|
||||||
ret = _orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms);
|
if (dbParms == null)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
dbParms = _params.ToArray();
|
||||||
|
sbret = new StringBuilder();
|
||||||
|
sbret.Append(" RETURNING ");
|
||||||
|
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sbret.Append(", ");
|
||||||
|
sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sql = sb.Append(sbret).ToString();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
|
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.AddRange(_orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null)
|
||||||
{
|
{
|
||||||
exception = ex;
|
this.ClearData();
|
||||||
throw ex;
|
sbret.Clear();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
|
||||||
}
|
|
||||||
this.ClearData();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,40 +70,50 @@ namespace FreeSql.Odbc.MySql
|
|||||||
#else
|
#else
|
||||||
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append(sql).Append(" RETURNING ");
|
|
||||||
|
|
||||||
var colidx = 0;
|
|
||||||
foreach (var col in _table.Columns.Values)
|
|
||||||
{
|
|
||||||
if (colidx > 0) sb.Append(", ");
|
|
||||||
sb.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
sql = sb.ToString();
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
StringBuilder sbret = null;
|
||||||
|
await ToSqlFetchAsync(async sb =>
|
||||||
{
|
{
|
||||||
ret = await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken);
|
if (dbParms == null)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
dbParms = _params.ToArray();
|
||||||
|
sbret = new StringBuilder();
|
||||||
|
sbret.Append(" RETURNING ");
|
||||||
|
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sbret.Append(", ");
|
||||||
|
sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sql = sb.Append(sbret).ToString();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
|
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.AddRange(await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null)
|
||||||
{
|
{
|
||||||
exception = ex;
|
this.ClearData();
|
||||||
throw ex;
|
sbret.Clear();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
|
||||||
}
|
|
||||||
this.ClearData();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -16,17 +16,11 @@ namespace FreeSql.Odbc.Oracle
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override List<T1> ExecuteDeleted()
|
public override List<T1> ExecuteDeleted() => throw new NotImplementedException("FreeSql.Odbc.Oracle 未实现该功能");
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if net40
|
#if net40
|
||||||
#else
|
#else
|
||||||
public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException("FreeSql.Odbc.Oracle 未实现该功能");
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -18,40 +19,50 @@ namespace FreeSql.Odbc.PostgreSQL
|
|||||||
|
|
||||||
public override List<T1> ExecuteDeleted()
|
public override List<T1> ExecuteDeleted()
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append(sql).Append(" RETURNING ");
|
|
||||||
|
|
||||||
var colidx = 0;
|
|
||||||
foreach (var col in _table.Columns.Values)
|
|
||||||
{
|
|
||||||
if (colidx > 0) sb.Append(", ");
|
|
||||||
sb.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
sql = sb.ToString();
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
StringBuilder sbret = null;
|
||||||
|
ToSqlFetch(sb =>
|
||||||
{
|
{
|
||||||
ret = _orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms);
|
if (dbParms == null)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
dbParms = _params.ToArray();
|
||||||
|
sbret = new StringBuilder();
|
||||||
|
sbret.Append(" RETURNING ");
|
||||||
|
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sbret.Append(", ");
|
||||||
|
sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sql = sb.Append(sbret).ToString();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
|
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.AddRange(_orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null)
|
||||||
{
|
{
|
||||||
exception = ex;
|
this.ClearData();
|
||||||
throw ex;
|
sbret.Clear();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
|
||||||
}
|
|
||||||
this.ClearData();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,40 +70,50 @@ namespace FreeSql.Odbc.PostgreSQL
|
|||||||
#else
|
#else
|
||||||
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append(sql).Append(" RETURNING ");
|
|
||||||
|
|
||||||
var colidx = 0;
|
|
||||||
foreach (var col in _table.Columns.Values)
|
|
||||||
{
|
|
||||||
if (colidx > 0) sb.Append(", ");
|
|
||||||
sb.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
sql = sb.ToString();
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
StringBuilder sbret = null;
|
||||||
|
await ToSqlFetchAsync(async sb =>
|
||||||
{
|
{
|
||||||
ret = await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken);
|
if (dbParms == null)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
dbParms = _params.ToArray();
|
||||||
|
sbret = new StringBuilder();
|
||||||
|
sbret.Append(" RETURNING ");
|
||||||
|
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sbret.Append(", ");
|
||||||
|
sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sql = sb.Append(sbret).ToString();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
|
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.AddRange(await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null)
|
||||||
{
|
{
|
||||||
exception = ex;
|
this.ClearData();
|
||||||
throw ex;
|
sbret.Clear();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
|
||||||
}
|
|
||||||
this.ClearData();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -18,45 +19,56 @@ namespace FreeSql.Odbc.SqlServer
|
|||||||
|
|
||||||
public override List<T1> ExecuteDeleted()
|
public override List<T1> ExecuteDeleted()
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
|
||||||
|
|
||||||
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.RereadColumn(col, $"DELETED.{_commonUtils.QuoteSqlName(col.Attribute.Name)}")).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
|
|
||||||
var validx = sql.IndexOf(" WHERE ");
|
|
||||||
if (validx == -1) throw new ArgumentException("找不到 WHERE ");
|
|
||||||
sb.Insert(0, sql.Substring(0, validx));
|
|
||||||
sb.Append(sql.Substring(validx));
|
|
||||||
|
|
||||||
sql = sb.ToString();
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
StringBuilder sbret = null;
|
||||||
|
ToSqlFetch(sb =>
|
||||||
{
|
{
|
||||||
ret = _orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms);
|
if (dbParms == null)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
dbParms = _params.ToArray();
|
||||||
|
sbret = new StringBuilder();
|
||||||
|
sbret.Append(" OUTPUT ");
|
||||||
|
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sbret.Append(", ");
|
||||||
|
sbret.Append(_commonUtils.RereadColumn(col, $"DELETED.{_commonUtils.QuoteSqlName(col.Attribute.Name)}")).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sql = sb.ToString();
|
||||||
|
var validx = sql.IndexOf(" WHERE ");
|
||||||
|
if (validx == -1) throw new ArgumentException("找不到 WHERE ");
|
||||||
|
sb.Clear().Append(sql.Substring(0, validx))
|
||||||
|
.Append(sbret)
|
||||||
|
.Append(sql.Substring(validx));
|
||||||
|
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
|
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.AddRange(_orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null)
|
||||||
{
|
{
|
||||||
exception = ex;
|
this.ClearData();
|
||||||
throw ex;
|
sbret.Clear();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
|
||||||
}
|
|
||||||
this.ClearData();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,45 +76,56 @@ namespace FreeSql.Odbc.SqlServer
|
|||||||
#else
|
#else
|
||||||
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
|
||||||
|
|
||||||
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.RereadColumn(col, $"DELETED.{_commonUtils.QuoteSqlName(col.Attribute.Name)}")).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
|
|
||||||
var validx = sql.IndexOf(" WHERE ");
|
|
||||||
if (validx == -1) throw new ArgumentException("找不到 WHERE ");
|
|
||||||
sb.Insert(0, sql.Substring(0, validx));
|
|
||||||
sb.Append(sql.Substring(validx));
|
|
||||||
|
|
||||||
sql = sb.ToString();
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
StringBuilder sbret = null;
|
||||||
|
await ToSqlFetchAsync(async sb =>
|
||||||
{
|
{
|
||||||
ret = await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken);
|
if (dbParms == null)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
dbParms = _params.ToArray();
|
||||||
|
sbret = new StringBuilder();
|
||||||
|
sbret.Append(" OUTPUT ");
|
||||||
|
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sbret.Append(", ");
|
||||||
|
sbret.Append(_commonUtils.RereadColumn(col, $"DELETED.{_commonUtils.QuoteSqlName(col.Attribute.Name)}")).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sql = sb.ToString();
|
||||||
|
var validx = sql.IndexOf(" WHERE ");
|
||||||
|
if (validx == -1) throw new ArgumentException("找不到 WHERE ");
|
||||||
|
sb.Clear().Append(sql.Substring(0, validx))
|
||||||
|
.Append(sbret)
|
||||||
|
.Append(sql.Substring(validx));
|
||||||
|
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
|
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.AddRange(await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null)
|
||||||
{
|
{
|
||||||
exception = ex;
|
this.ClearData();
|
||||||
throw ex;
|
sbret.Clear();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
|
||||||
}
|
|
||||||
this.ClearData();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -16,17 +16,11 @@ namespace FreeSql.Oracle.Curd
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override List<T1> ExecuteDeleted()
|
public override List<T1> ExecuteDeleted() => throw new NotImplementedException("FreeSql.Provider.Oracle 未实现该功能");
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if net40
|
#if net40
|
||||||
#else
|
#else
|
||||||
public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException("FreeSql.Provider.Oracle 未实现该功能");
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -18,40 +19,50 @@ namespace FreeSql.PostgreSQL.Curd
|
|||||||
|
|
||||||
public override List<T1> ExecuteDeleted()
|
public override List<T1> ExecuteDeleted()
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append(sql).Append(" RETURNING ");
|
|
||||||
|
|
||||||
var colidx = 0;
|
|
||||||
foreach (var col in _table.Columns.Values)
|
|
||||||
{
|
|
||||||
if (colidx > 0) sb.Append(", ");
|
|
||||||
sb.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
sql = sb.ToString();
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
StringBuilder sbret = null;
|
||||||
|
ToSqlFetch(sb =>
|
||||||
{
|
{
|
||||||
ret = _orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms);
|
if (dbParms == null)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
dbParms = _params.ToArray();
|
||||||
|
sbret = new StringBuilder();
|
||||||
|
sbret.Append(" RETURNING ");
|
||||||
|
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sbret.Append(", ");
|
||||||
|
sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sql = sb.Append(sbret).ToString();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
|
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.AddRange(_orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null)
|
||||||
{
|
{
|
||||||
exception = ex;
|
this.ClearData();
|
||||||
throw ex;
|
sbret.Clear();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
|
||||||
}
|
|
||||||
this.ClearData();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,40 +70,50 @@ namespace FreeSql.PostgreSQL.Curd
|
|||||||
#else
|
#else
|
||||||
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append(sql).Append(" RETURNING ");
|
|
||||||
|
|
||||||
var colidx = 0;
|
|
||||||
foreach (var col in _table.Columns.Values)
|
|
||||||
{
|
|
||||||
if (colidx > 0) sb.Append(", ");
|
|
||||||
sb.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
sql = sb.ToString();
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
StringBuilder sbret = null;
|
||||||
|
await ToSqlFetchAsync(async sb =>
|
||||||
{
|
{
|
||||||
ret = await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken);
|
if (dbParms == null)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
dbParms = _params.ToArray();
|
||||||
|
sbret = new StringBuilder();
|
||||||
|
sbret.Append(" RETURNING ");
|
||||||
|
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sbret.Append(", ");
|
||||||
|
sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sql = sb.Append(sbret).ToString();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
|
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.AddRange(await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null)
|
||||||
{
|
{
|
||||||
exception = ex;
|
this.ClearData();
|
||||||
throw ex;
|
sbret.Clear();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
|
||||||
}
|
|
||||||
this.ClearData();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -18,40 +19,50 @@ namespace FreeSql.ShenTong.Curd
|
|||||||
|
|
||||||
public override List<T1> ExecuteDeleted()
|
public override List<T1> ExecuteDeleted()
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append(sql).Append(" RETURNING ");
|
|
||||||
|
|
||||||
var colidx = 0;
|
|
||||||
foreach (var col in _table.Columns.Values)
|
|
||||||
{
|
|
||||||
if (colidx > 0) sb.Append(", ");
|
|
||||||
sb.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
sql = sb.ToString();
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
StringBuilder sbret = null;
|
||||||
|
ToSqlFetch(sb =>
|
||||||
{
|
{
|
||||||
ret = _orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms);
|
if (dbParms == null)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
dbParms = _params.ToArray();
|
||||||
|
sbret = new StringBuilder();
|
||||||
|
sbret.Append(" RETURNING ");
|
||||||
|
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sbret.Append(", ");
|
||||||
|
sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sql = sb.Append(sbret).ToString();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
|
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.AddRange(_orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null)
|
||||||
{
|
{
|
||||||
exception = ex;
|
this.ClearData();
|
||||||
throw ex;
|
sbret.Clear();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
|
||||||
}
|
|
||||||
this.ClearData();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,40 +70,50 @@ namespace FreeSql.ShenTong.Curd
|
|||||||
#else
|
#else
|
||||||
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.Append(sql).Append(" RETURNING ");
|
|
||||||
|
|
||||||
var colidx = 0;
|
|
||||||
foreach (var col in _table.Columns.Values)
|
|
||||||
{
|
|
||||||
if (colidx > 0) sb.Append(", ");
|
|
||||||
sb.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
sql = sb.ToString();
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
StringBuilder sbret = null;
|
||||||
|
await ToSqlFetchAsync(async sb =>
|
||||||
{
|
{
|
||||||
ret = await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken);
|
if (dbParms == null)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
dbParms = _params.ToArray();
|
||||||
|
sbret = new StringBuilder();
|
||||||
|
sbret.Append(" RETURNING ");
|
||||||
|
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sbret.Append(", ");
|
||||||
|
sbret.Append(_commonUtils.RereadColumn(col, _commonUtils.QuoteSqlName(col.Attribute.Name))).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sql = sb.Append(sbret).ToString();
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
|
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.AddRange(await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null)
|
||||||
{
|
{
|
||||||
exception = ex;
|
this.ClearData();
|
||||||
throw ex;
|
sbret.Clear();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
|
||||||
}
|
|
||||||
this.ClearData();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Data.Common;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -18,45 +19,56 @@ namespace FreeSql.SqlServer.Curd
|
|||||||
|
|
||||||
public override List<T1> ExecuteDeleted()
|
public override List<T1> ExecuteDeleted()
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
|
||||||
|
|
||||||
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.RereadColumn(col, $"DELETED.{_commonUtils.QuoteSqlName(col.Attribute.Name)}")).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
|
|
||||||
var validx = sql.IndexOf(" WHERE ");
|
|
||||||
if (validx == -1) throw new ArgumentException("找不到 WHERE ");
|
|
||||||
sb.Insert(0, sql.Substring(0, validx));
|
|
||||||
sb.Append(sql.Substring(validx));
|
|
||||||
|
|
||||||
sql = sb.ToString();
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
StringBuilder sbret = null;
|
||||||
|
ToSqlFetch(sb =>
|
||||||
{
|
{
|
||||||
ret = _orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms);
|
if (dbParms == null)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
dbParms = _params.ToArray();
|
||||||
|
sbret = new StringBuilder();
|
||||||
|
sbret.Append(" OUTPUT ");
|
||||||
|
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sbret.Append(", ");
|
||||||
|
sbret.Append(_commonUtils.RereadColumn(col, $"DELETED.{_commonUtils.QuoteSqlName(col.Attribute.Name)}")).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sql = sb.ToString();
|
||||||
|
var validx = sql.IndexOf(" WHERE ");
|
||||||
|
if (validx == -1) throw new ArgumentException("找不到 WHERE ");
|
||||||
|
sb.Clear().Append(sql.Substring(0, validx))
|
||||||
|
.Append(sbret)
|
||||||
|
.Append(sql.Substring(validx));
|
||||||
|
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
|
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.AddRange(_orm.Ado.Query<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null)
|
||||||
{
|
{
|
||||||
exception = ex;
|
this.ClearData();
|
||||||
throw;
|
sbret.Clear();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
|
||||||
}
|
|
||||||
this.ClearData();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,45 +76,56 @@ namespace FreeSql.SqlServer.Curd
|
|||||||
#else
|
#else
|
||||||
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
async public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var sql = this.ToSql();
|
|
||||||
if (string.IsNullOrEmpty(sql)) return new List<T1>();
|
|
||||||
|
|
||||||
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.RereadColumn(col, $"DELETED.{_commonUtils.QuoteSqlName(col.Attribute.Name)}")).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
|
||||||
++colidx;
|
|
||||||
}
|
|
||||||
|
|
||||||
var validx = sql.IndexOf(" WHERE ");
|
|
||||||
if (validx == -1) throw new ArgumentException("找不到 WHERE ");
|
|
||||||
sb.Insert(0, sql.Substring(0, validx));
|
|
||||||
sb.Append(sql.Substring(validx));
|
|
||||||
|
|
||||||
sql = sb.ToString();
|
|
||||||
var dbParms = _params.ToArray();
|
|
||||||
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
|
||||||
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
|
||||||
var ret = new List<T1>();
|
var ret = new List<T1>();
|
||||||
Exception exception = null;
|
DbParameter[] dbParms = null;
|
||||||
try
|
StringBuilder sbret = null;
|
||||||
|
await ToSqlFetchAsync(async sb =>
|
||||||
{
|
{
|
||||||
ret = await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken);
|
if (dbParms == null)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
dbParms = _params.ToArray();
|
||||||
|
sbret = new StringBuilder();
|
||||||
|
sbret.Append(" OUTPUT ");
|
||||||
|
|
||||||
|
var colidx = 0;
|
||||||
|
foreach (var col in _table.Columns.Values)
|
||||||
|
{
|
||||||
|
if (colidx > 0) sbret.Append(", ");
|
||||||
|
sbret.Append(_commonUtils.RereadColumn(col, $"DELETED.{_commonUtils.QuoteSqlName(col.Attribute.Name)}")).Append(" as ").Append(_commonUtils.QuoteSqlName(col.CsName));
|
||||||
|
++colidx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var sql = sb.ToString();
|
||||||
|
var validx = sql.IndexOf(" WHERE ");
|
||||||
|
if (validx == -1) throw new ArgumentException("找不到 WHERE ");
|
||||||
|
sb.Clear().Append(sql.Substring(0, validx))
|
||||||
|
.Append(sbret)
|
||||||
|
.Append(sql.Substring(validx));
|
||||||
|
|
||||||
|
var before = new Aop.CurdBeforeEventArgs(_table.Type, _table, Aop.CurdType.Delete, sql, dbParms);
|
||||||
|
_orm.Aop.CurdBeforeHandler?.Invoke(this, before);
|
||||||
|
|
||||||
|
Exception exception = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.AddRange(await _orm.Ado.QueryAsync<T1>(_table.TypeLazy ?? _table.Type, _connection, _transaction, CommandType.Text, sql, _commandTimeout, dbParms, cancellationToken));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
exception = ex;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
||||||
|
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dbParms != null)
|
||||||
{
|
{
|
||||||
exception = ex;
|
this.ClearData();
|
||||||
throw;
|
sbret.Clear();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
var after = new Aop.CurdAfterEventArgs(before, exception, ret);
|
|
||||||
_orm.Aop.CurdAfterHandler?.Invoke(this, after);
|
|
||||||
}
|
|
||||||
this.ClearData();
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -16,17 +16,11 @@ namespace FreeSql.Sqlite.Curd
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override List<T1> ExecuteDeleted()
|
public override List<T1> ExecuteDeleted() => throw new NotImplementedException("FreeSql.Provider.Sqlite 未实现该功能");
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if net40
|
#if net40
|
||||||
#else
|
#else
|
||||||
public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default)
|
public override Task<List<T1>> ExecuteDeletedAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException("FreeSql.Provider.Sqlite 未实现该功能");
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user