Skip to content

Commit

Permalink
Merge pull request #1650 from d4ilys/master
Browse files Browse the repository at this point in the history
修复 UpdateJoin SetIf逻辑判断问题
  • Loading branch information
2881099 authored Oct 27, 2023
2 parents 16e5f8b + 5b05824 commit 98c761e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions FreeSql/Internal/CommonProvider/UpdateJoinProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public IUpdateJoin<T1, T2> WhereIf(bool condition, Expression<Func<T1, T2, bool>
public IUpdateJoin<T1, T2> Set(Expression<Func<T1, T2, bool>> exp) => SetIf(true, exp);
public IUpdateJoin<T1, T2> SetIf(bool condition, Expression<Func<T1, T2, bool>> exp)
{
if (condition == false) return this;
var body = exp?.Body;
var nodeType = body?.NodeType;
if (nodeType == ExpressionType.Convert)
Expand Down
22 changes: 13 additions & 9 deletions Providers/FreeSql.Provider.QuestDb/QuestDbGlobalExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ private static List<string> SplitByLine(string text)
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="that"></param>
/// <param name="dateFormat">导入时,时间格式 默认:yyyy/M/d H:mm:ss</param>
/// <returns></returns>
public static async Task<int> ExecuteBulkCopyAsync<T>(this IInsert<T> that) where T : class
public static async Task<int> ExecuteBulkCopyAsync<T>(this IInsert<T> that,string dateFormat = "yyyy/M/d H:mm:ss") where T : class
{
//思路:通过提供的RestAPI imp,实现快速复制
if (string.IsNullOrWhiteSpace(RestAPIExtension.BaseUrl))
Expand All @@ -180,7 +181,7 @@ public static async Task<int> ExecuteBulkCopyAsync<T>(this IInsert<T> that) wher
{
{ "name", d.Name },
{ "type", d.DbTypeText },
{ "pattern", "yyyy/M/d H:mm:ss" }
{ "pattern", dateFormat}
});
}
else
Expand All @@ -197,7 +198,7 @@ public static async Task<int> ExecuteBulkCopyAsync<T>(this IInsert<T> that) wher
using (var writer = new StreamWriter(filePath))
using (var csv = new CsvWriter(writer, CultureInfo.CurrentCulture))
{
csv.WriteRecords(insert._source);
await csv.WriteRecordsAsync(insert._source);
}

var httpContent = new MultipartFormDataContent(boundary);
Expand All @@ -213,7 +214,6 @@ public static async Task<int> ExecuteBulkCopyAsync<T>(this IInsert<T> that) wher
await client.PostAsync($"{RestAPIExtension.BaseUrl}/imp?name={name}", httpContent);
var readAsStringAsync = await httpResponseMessage.Content.ReadAsStringAsync();
var splitByLine = SplitByLine(readAsStringAsync);
//Console.WriteLine(readAsStringAsync);
foreach (var s in splitByLine)
{
if (s.Contains("Rows"))
Expand All @@ -236,7 +236,10 @@ public static async Task<int> ExecuteBulkCopyAsync<T>(this IInsert<T> that) wher
{
File.Delete(filePath);
}
catch { }
catch
{
// ignored
}
}

return result;
Expand All @@ -246,11 +249,12 @@ public static async Task<int> ExecuteBulkCopyAsync<T>(this IInsert<T> that) wher
/// 批量快速插入
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="that"></param>
/// <param name="insert"></param>
/// <param name="dateFormat">导入时,时间格式 默认:yyyy/M/d H:mm:ss</param>
/// <returns></returns>
public static int ExecuteBulkCopy<T>(this IInsert<T> insert) where T : class
public static int ExecuteBulkCopy<T>(this IInsert<T> insert,string dateFormat = "yyyy/M/d H:mm:ss") where T : class
{
return ExecuteBulkCopyAsync(insert).ConfigureAwait(false).GetAwaiter().GetResult();
return ExecuteBulkCopyAsync(insert,dateFormat).ConfigureAwait(false).GetAwaiter().GetResult();
}
}

Expand Down Expand Up @@ -340,7 +344,7 @@ internal static FreeSqlBuilder UseQuestDbRestAPI(FreeSqlBuilder buider, string h
var base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{username}:{password}"));
authorization = $"Basic {base64}";
}
//RESTAPI需要无参数
//RestApi需要无参数
buider.UseNoneCommandParameter(true);
return buider;
}
Expand Down

0 comments on commit 98c761e

Please sign in to comment.