Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复 UpdateJoin SetIf逻辑判断问题 #1650

Merged
merged 5 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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