Skip to content

Commit 98c761e

Browse files
authored
Merge pull request #1650 from d4ilys/master
修复 UpdateJoin SetIf逻辑判断问题
2 parents 16e5f8b + 5b05824 commit 98c761e

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

FreeSql/Internal/CommonProvider/UpdateJoinProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public IUpdateJoin<T1, T2> WhereIf(bool condition, Expression<Func<T1, T2, bool>
169169
public IUpdateJoin<T1, T2> Set(Expression<Func<T1, T2, bool>> exp) => SetIf(true, exp);
170170
public IUpdateJoin<T1, T2> SetIf(bool condition, Expression<Func<T1, T2, bool>> exp)
171171
{
172+
if (condition == false) return this;
172173
var body = exp?.Body;
173174
var nodeType = body?.NodeType;
174175
if (nodeType == ExpressionType.Convert)

Providers/FreeSql.Provider.QuestDb/QuestDbGlobalExtensions.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ private static List<string> SplitByLine(string text)
154154
/// </summary>
155155
/// <typeparam name="T"></typeparam>
156156
/// <param name="that"></param>
157+
/// <param name="dateFormat">导入时,时间格式 默认:yyyy/M/d H:mm:ss</param>
157158
/// <returns></returns>
158-
public static async Task<int> ExecuteBulkCopyAsync<T>(this IInsert<T> that) where T : class
159+
public static async Task<int> ExecuteBulkCopyAsync<T>(this IInsert<T> that,string dateFormat = "yyyy/M/d H:mm:ss") where T : class
159160
{
160161
//思路:通过提供的RestAPI imp,实现快速复制
161162
if (string.IsNullOrWhiteSpace(RestAPIExtension.BaseUrl))
@@ -180,7 +181,7 @@ public static async Task<int> ExecuteBulkCopyAsync<T>(this IInsert<T> that) wher
180181
{
181182
{ "name", d.Name },
182183
{ "type", d.DbTypeText },
183-
{ "pattern", "yyyy/M/d H:mm:ss" }
184+
{ "pattern", dateFormat}
184185
});
185186
}
186187
else
@@ -197,7 +198,7 @@ public static async Task<int> ExecuteBulkCopyAsync<T>(this IInsert<T> that) wher
197198
using (var writer = new StreamWriter(filePath))
198199
using (var csv = new CsvWriter(writer, CultureInfo.CurrentCulture))
199200
{
200-
csv.WriteRecords(insert._source);
201+
await csv.WriteRecordsAsync(insert._source);
201202
}
202203

203204
var httpContent = new MultipartFormDataContent(boundary);
@@ -213,7 +214,6 @@ public static async Task<int> ExecuteBulkCopyAsync<T>(this IInsert<T> that) wher
213214
await client.PostAsync($"{RestAPIExtension.BaseUrl}/imp?name={name}", httpContent);
214215
var readAsStringAsync = await httpResponseMessage.Content.ReadAsStringAsync();
215216
var splitByLine = SplitByLine(readAsStringAsync);
216-
//Console.WriteLine(readAsStringAsync);
217217
foreach (var s in splitByLine)
218218
{
219219
if (s.Contains("Rows"))
@@ -236,7 +236,10 @@ public static async Task<int> ExecuteBulkCopyAsync<T>(this IInsert<T> that) wher
236236
{
237237
File.Delete(filePath);
238238
}
239-
catch { }
239+
catch
240+
{
241+
// ignored
242+
}
240243
}
241244

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

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

0 commit comments

Comments
 (0)