Skip to content

Commit

Permalink
- 修复 PgCopy DateTime 映射 date 失败的情况;
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Dec 16, 2024
1 parent 13cfbf2 commit d2cbc28
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions Providers/FreeSql.Provider.PostgreSQL/PostgreSQLExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
Expand Down Expand Up @@ -208,10 +207,12 @@ public static void ExecutePgCopy<T>(this IInsert<T> that) where T : class
var trycol = insert._table.Columns[col.ColumnName];
var tp = insert._orm.CodeFirst.GetDbInfo(trycol.Attribute.MapType)?.type;
if (tp != null) npgsqlDbType = (NpgsqlDbType)tp.Value;
if (npgsqlDbType.HasValue && npgsqlDbType != NpgsqlDbType.Unknown)
writer.Write(item[col.ColumnName], npgsqlDbType.Value);
else
if (npgsqlDbType == null || npgsqlDbType == NpgsqlDbType.Unknown)
writer.Write(item[col.ColumnName]);
else if (npgsqlDbType == NpgsqlDbType.Date && item[col.ColumnName] != null && (item[col.ColumnName] is DateTime || item[col.ColumnName] is DateTime?))
writer.Write(((DateTime)item[col.ColumnName]).ToString("yyyy-MM-dd"), npgsqlDbType.Value);
else
writer.Write(item[col.ColumnName], npgsqlDbType.Value);
}
//writer.WriteRow(item.ItemArray); #1532
}
Expand Down Expand Up @@ -307,10 +308,12 @@ async public static Task ExecutePgCopyAsync<T>(this IInsert<T> that, Cancellatio
var trycol = insert._table.Columns[col.ColumnName];
var tp = insert._orm.CodeFirst.GetDbInfo(trycol.Attribute.MapType)?.type;
if (tp != null) npgsqlDbType = (NpgsqlDbType)tp.Value;
if (npgsqlDbType.HasValue && npgsqlDbType != NpgsqlDbType.Unknown)
await writer.WriteAsync(item[col.ColumnName], npgsqlDbType.Value, cancellationToken);
else
if (npgsqlDbType == null || npgsqlDbType == NpgsqlDbType.Unknown)
await writer.WriteAsync(item[col.ColumnName], cancellationToken);
else if (npgsqlDbType == NpgsqlDbType.Date && item[col.ColumnName] != null && (item[col.ColumnName] is DateTime || item[col.ColumnName] is DateTime?))
await writer.WriteAsync(((DateTime)item[col.ColumnName]).ToString("yyyy-MM-dd"), npgsqlDbType.Value, cancellationToken);
else
await writer.WriteAsync(item[col.ColumnName], npgsqlDbType.Value, cancellationToken);
}
//await writer.WriteRowAsync(cancellationToken, item.ItemArray); #1532
}
Expand Down

0 comments on commit d2cbc28

Please sign in to comment.